Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
Signed-off-by: MarzellT <tobias.marzell@pionix.de>
  • Loading branch information
MarzellT committed Jan 15, 2025
1 parent 5a040ae commit 3e0c2a3
Show file tree
Hide file tree
Showing 16 changed files with 966 additions and 543 deletions.
610 changes: 596 additions & 14 deletions modules/YetiSimulator/YetiSimulator.cpp

Large diffs are not rendered by default.

48 changes: 36 additions & 12 deletions modules/YetiSimulator/YetiSimulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
#include "util/error_handler.hpp"
#include "util/mqtt_handler.hpp"
#include "util/simulator.hpp"
#include "util/state.hpp"
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1

Expand Down Expand Up @@ -58,15 +58,15 @@ class YetiSimulator : public Everest::ModuleBase {

// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
void clear_data();
Everest::MqttProvider& get_mqtt();
state::ModuleState& get_module_state();
void reset_module_state();
Everest::MqttProvider& get_mqtt() const;
state::ModuleState& get_module_state() const;
const ModuleInfo& get_info() const;
evse_board_supportImplBase& get_board_support();
ev_board_supportImplBase& get_ev_board_support();
powermeterImplBase& get_powermeter();
ac_rcdImplBase& get_ac_rcd();
connector_lockImplBase& get_connector_lock();
evse_board_supportImplBase& get_board_support() const;
ev_board_supportImplBase& get_ev_board_support() const;
powermeterImplBase& get_powermeter() const;
ac_rcdImplBase& get_ac_rcd() const;
connector_lockImplBase& get_connector_lock() const;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1

protected:
Expand All @@ -75,14 +75,32 @@ class YetiSimulator : public Everest::ModuleBase {
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1

private:
friend class LdEverest;
friend struct LdEverest;
void init();
void ready();

// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
void run_telemetry_slow();
void run_telemetry_fast();
void run_telemetry_slow() const;
void run_telemetry_fast() const;
void start_simulation(int sleep_time_ms);
[[noreturn]] void run_simulation(int sleep_time_ms) const;
void simulation_step() const;
void check_error_rcd() const;
void read_from_car() const;
void simulation_statemachine() const;
void add_noise() const;
void simulate_powermeter() const;
void publish_ev_board_support() const;
void publish_powermeter() const;
void publish_telemetry() const;
void publish_keepalive() const;
void drawPower(int l1, int l2, int l3, int n) const;
static void clear_disconnect_errors(ErrorHandler& error_handler, const evse_board_supportImplBase& board_support);
void powerOn(evse_board_supportImplBase& board_support) const;
void powerOff(evse_board_supportImplBase& board_support) const;
void reset_powermeter() const;
[[nodiscard]] types::board_support_common::ProximityPilot read_pp_ampacity() const;

std::unique_ptr<state::ModuleState> module_state;
std::unique_ptr<MqttHandler> mqtt_handler;
Expand All @@ -92,6 +110,12 @@ class YetiSimulator : public Everest::ModuleBase {

// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
types::powermeter::Powermeter power_meter_external(const state::PowermeterData& powermeter_data);
double duty_cycle_to_amps(double dc);
bool is_voltage_in_range(const double voltage, double center);
void publish_event(evse_board_supportImplBase& board_support, state::State event);
static types::board_support_common::BspEvent event_to_enum(state::State event);
static std::string event_to_string(state::State state);
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1

} // namespace module
58 changes: 31 additions & 27 deletions modules/YetiSimulator/board_support/evse_board_supportImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@
// Copyright Pionix GmbH and Contributors to EVerest

#include "evse_board_supportImpl.hpp"
#include "util/state.hpp"

namespace module {
namespace board_support {
namespace module::board_support {

void evse_board_supportImpl::init() {
}

void evse_board_supportImpl::ready() {
const auto capabilities = types::evse_board_support::HardwareCapabilities{
.max_current_A_import = 32.0,
.min_current_A_import = 6.0,
.max_phase_count_import = 3,
.min_phase_count_import = 1,
.max_current_A_export = 16.0,
.min_current_A_export = 0.0,
.max_phase_count_export = 3,
.min_phase_count_export = 1,
.supports_changing_phases_during_charging = true,
.connector_type = types::evse_board_support::Connector_type::IEC62196Type2Cable};
publish_capabilities(capabilities);
const auto default_capabilities = set_default_capabilities();
publish_capabilities(default_capabilities);
}

void evse_board_supportImpl::handle_enable(bool& value) {
Expand Down Expand Up @@ -61,35 +51,38 @@ void evse_board_supportImpl::handle_ac_switch_three_phases_while_charging(bool&
module_state.use_three_phases_confirmed = value;
}

void evse_board_supportImpl::handle_evse_replug(int& value) {
void evse_board_supportImpl::handle_evse_replug(int& _) {
EVLOG_error << "Replugging not supported";
}

types::board_support_common::ProximityPilot evse_board_supportImpl::handle_ac_read_pp_ampacity() {
using types::board_support_common::Ampacity;
const auto pp_resistor = mod->get_module_state().simulation_data.pp_resistor;

if (pp_resistor < 80 || pp_resistor > 2460) {
if (pp_resistor < 80 or pp_resistor > 2460) {
EVLOG_error << "PP resistor value " << pp_resistor << " Ohm seems to be outside the allowed range.";
return {.ampacity = Ampacity::None};
} else if (pp_resistor > 936 && pp_resistor <= 2460) {
}
if (pp_resistor > 936 && pp_resistor <= 2460) {
return {.ampacity = Ampacity::A_13};
} else if (pp_resistor > 308 && pp_resistor <= 936) {
}
if (pp_resistor > 308 && pp_resistor <= 936) {
return {.ampacity = Ampacity::A_20};
} else if (pp_resistor > 140 && pp_resistor <= 308) {
}
if (pp_resistor > 140 && pp_resistor <= 308) {
return {.ampacity = Ampacity::A_32};
} else if (pp_resistor > 80 && pp_resistor <= 140) {
}
if (pp_resistor > 80 && pp_resistor <= 140) {
return {.ampacity = Ampacity::A_63_3ph_70_1ph};
} else {
return {.ampacity = Ampacity::None};
}
return {.ampacity = Ampacity::None};
}

void evse_board_supportImpl::handle_ac_set_overcurrent_limit_A(double& value) {
// TODO: intentional?
}

void evse_board_supportImpl::pwm_on(double dutycycle) {
void evse_board_supportImpl::pwm_on(const double dutycycle) const {
auto& module_state = mod->get_module_state();

if (dutycycle > 0.0) {
Expand All @@ -101,21 +94,32 @@ void evse_board_supportImpl::pwm_on(double dutycycle) {
}
}

void evse_board_supportImpl::pwm_off() {
void evse_board_supportImpl::pwm_off() const {
auto& module_state = mod->get_module_state();

module_state.pwm_duty_cycle = 1.0;
module_state.pwm_running = false;
module_state.pwm_error_f = false;
}

void evse_board_supportImpl::pwm_f() {
void evse_board_supportImpl::pwm_f() const {
auto& module_state = mod->get_module_state();

module_state.pwm_duty_cycle = 1.0;
module_state.pwm_running = false;
module_state.pwm_error_f = true;
}

} // namespace board_support
} // namespace module
types::evse_board_support::HardwareCapabilities set_default_capabilities() {
return {.max_current_A_import = 32.0,
.min_current_A_import = 6.0,
.max_phase_count_import = 3,
.min_phase_count_import = 1,
.max_current_A_export = 16.0,
.min_current_A_export = 0.0,
.max_phase_count_export = 3,
.min_phase_count_export = 1,
.supports_changing_phases_during_charging = true,
.connector_type = types::evse_board_support::Connector_type::IEC62196Type2Cable};
}
} // namespace module::board_support
10 changes: 5 additions & 5 deletions modules/YetiSimulator/board_support/evse_board_supportImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
// template version 3
//

#include <YetiSimulator.hpp>
#include <generated/interfaces/evse_board_support/Implementation.hpp>

#include "../YetiSimulator.hpp"

// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
Expand All @@ -28,7 +27,7 @@ class evse_board_supportImpl : public evse_board_supportImplBase {

// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
void pwm_off();
void pwm_off() const;
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1

protected:
Expand Down Expand Up @@ -56,13 +55,14 @@ class evse_board_supportImpl : public evse_board_supportImplBase {

// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
void pwm_on(double dutycycle);
void pwm_f();
void pwm_on(double dutycycle) const;
void pwm_f() const;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1
// insert other definitions here
types::evse_board_support::HardwareCapabilities set_default_capabilities();
// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1

} // namespace board_support
Expand Down
7 changes: 3 additions & 4 deletions modules/YetiSimulator/connector_lock/connector_lockImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright Pionix GmbH and Contributors to EVerest

#include "connector_lockImpl.hpp"
#include <everest/logging.hpp>

namespace module {
namespace connector_lock {
namespace module::connector_lock {

void connector_lockImpl::init() {
}
Expand All @@ -20,5 +20,4 @@ void connector_lockImpl::handle_unlock() {
EVLOG_info << "Unlock connector";
}

} // namespace connector_lock
} // namespace module
} // namespace module::connector_lock
16 changes: 7 additions & 9 deletions modules/YetiSimulator/connector_lock/connector_lockImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1

namespace module {
namespace connector_lock {
namespace module::connector_lock {

struct Conf {};

class connector_lockImpl : public connector_lockImplBase {
public:
connector_lockImpl() = delete;
connector_lockImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<YetiSimulator>& mod, Conf& config) :
connector_lockImplBase(ev, "connector_lock"), mod(mod), config(config){};
connector_lockImplBase(ev, "connector_lock"), mod(mod), config(config) {};

// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1

protected:
// command handler functions (virtual)
virtual void handle_lock() override;
virtual void handle_unlock() override;
void handle_lock() override;
void handle_unlock() override;

// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
Expand All @@ -43,8 +42,8 @@ class connector_lockImpl : public connector_lockImplBase {
const Everest::PtrContainer<YetiSimulator>& mod;
const Conf& config;

virtual void init() override;
virtual void ready() override;
void init() override;
void ready() override;

// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
Expand All @@ -55,5 +54,4 @@ class connector_lockImpl : public connector_lockImplBase {
// insert other definitions here
// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1

} // namespace connector_lock
} // namespace module
} // namespace module::connector_lock
21 changes: 10 additions & 11 deletions modules/YetiSimulator/ev_board_support/ev_board_supportImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright Pionix GmbH and Contributors to EVerest

#include "ev_board_supportImpl.hpp"
#include <everest/logging.hpp>

namespace module {
namespace ev_board_support {
namespace module::ev_board_support {

void ev_board_supportImpl::init() {
}
Expand All @@ -14,9 +14,9 @@ void ev_board_supportImpl::ready() {

void ev_board_supportImpl::handle_enable(bool& value) {
auto& module_state = mod->get_module_state();
if (module_state.simulation_enabled && !value) {
if (module_state.simulation_enabled and not value) {
publish_bsp_event({types::board_support_common::Event::A});
mod->clear_data();
mod->reset_module_state();
}
module_state.simulation_enabled = value;
}
Expand All @@ -27,23 +27,23 @@ void ev_board_supportImpl::handle_set_cp_state(types::ev_board_support::EvCpStat

switch (cp_state) {
case EvCpState::A:
simdata_setting.cp_voltage = 12.0;
simdata_setting.cp_voltage = cp_voltage_a;
break;
case EvCpState::B:
simdata_setting.cp_voltage = 9.0;
simdata_setting.cp_voltage = cp_voltage_b;
break;
case EvCpState::C:
simdata_setting.cp_voltage = 6.0;
simdata_setting.cp_voltage = cp_voltage_c;
break;
case EvCpState::D:
simdata_setting.cp_voltage = 3.0;
simdata_setting.cp_voltage = cp_voltage_d;
break;
case EvCpState::E:
simdata_setting.error_e = true;
break;
default:
break;
};
}
}

void ev_board_supportImpl::handle_allow_power_on(bool& value) {
Expand Down Expand Up @@ -78,5 +78,4 @@ void ev_board_supportImpl::handle_set_rcd_error(double& rcd_current_mA) {
simdata_setting.rcd_current = rcd_current_mA;
}

} // namespace ev_board_support
} // namespace module
} // namespace module::ev_board_support
Loading

0 comments on commit 3e0c2a3

Please sign in to comment.