Skip to content

Commit baa7a17

Browse files
committed
temp commit
Signed-off-by: MarzellT <tobias.marzell@pionix.de>
1 parent 5a040ae commit baa7a17

16 files changed

+965
-543
lines changed

modules/YetiSimulator/YetiSimulator.cpp

Lines changed: 596 additions & 14 deletions
Large diffs are not rendered by default.

modules/YetiSimulator/YetiSimulator.hpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
2020
// insert your custom include headers here
21+
#include "util/error_handler.hpp"
2122
#include "util/mqtt_handler.hpp"
22-
#include "util/simulator.hpp"
2323
#include "util/state.hpp"
2424
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
2525

@@ -58,15 +58,15 @@ class YetiSimulator : public Everest::ModuleBase {
5858

5959
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
6060
// insert your public definitions here
61-
void clear_data();
62-
Everest::MqttProvider& get_mqtt();
63-
state::ModuleState& get_module_state();
61+
void reset_module_state();
62+
Everest::MqttProvider& get_mqtt() const;
63+
state::ModuleState& get_module_state() const;
6464
const ModuleInfo& get_info() const;
65-
evse_board_supportImplBase& get_board_support();
66-
ev_board_supportImplBase& get_ev_board_support();
67-
powermeterImplBase& get_powermeter();
68-
ac_rcdImplBase& get_ac_rcd();
69-
connector_lockImplBase& get_connector_lock();
65+
evse_board_supportImplBase& get_board_support() const;
66+
ev_board_supportImplBase& get_ev_board_support() const;
67+
powermeterImplBase& get_powermeter() const;
68+
ac_rcdImplBase& get_ac_rcd() const;
69+
connector_lockImplBase& get_connector_lock() const;
7070
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
7171

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

7777
private:
78-
friend class LdEverest;
78+
friend struct LdEverest;
7979
void init();
8080
void ready();
8181

8282
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
8383
// insert your private definitions here
84-
void run_telemetry_slow();
85-
void run_telemetry_fast();
84+
void run_telemetry_slow() const;
85+
void run_telemetry_fast() const;
86+
void start_simulation(int sleep_time_ms);
87+
[[noreturn]] void run_simulation(int sleep_time_ms) const;
88+
void simulation_step() const;
89+
void check_error_rcd() const;
90+
void read_from_car() const;
91+
void simulation_statemachine() const;
92+
void add_noise() const;
93+
void simulate_powermeter() const;
94+
void publish_ev_board_support() const;
95+
void publish_powermeter() const;
96+
void publish_telemetry() const;
97+
void publish_keepalive() const;
98+
void drawPower(int l1, int l2, int l3, int n) const;
99+
static void clear_disconnect_errors(ErrorHandler& error_handler, const evse_board_supportImplBase& board_support);
100+
void powerOn(evse_board_supportImplBase& board_support) const;
101+
void powerOff(evse_board_supportImplBase& board_support) const;
102+
void reset_powermeter() const;
103+
[[nodiscard]] types::board_support_common::ProximityPilot read_pp_ampacity() const;
86104

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

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

97121
} // namespace module

modules/YetiSimulator/board_support/evse_board_supportImpl.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,16 @@
22
// Copyright Pionix GmbH and Contributors to EVerest
33

44
#include "evse_board_supportImpl.hpp"
5+
#include "util/state.hpp"
56

6-
namespace module {
7-
namespace board_support {
7+
namespace module::board_support {
88

99
void evse_board_supportImpl::init() {
1010
}
1111

1212
void evse_board_supportImpl::ready() {
13-
const auto capabilities = types::evse_board_support::HardwareCapabilities{
14-
.max_current_A_import = 32.0,
15-
.min_current_A_import = 6.0,
16-
.max_phase_count_import = 3,
17-
.min_phase_count_import = 1,
18-
.max_current_A_export = 16.0,
19-
.min_current_A_export = 0.0,
20-
.max_phase_count_export = 3,
21-
.min_phase_count_export = 1,
22-
.supports_changing_phases_during_charging = true,
23-
.connector_type = types::evse_board_support::Connector_type::IEC62196Type2Cable};
24-
publish_capabilities(capabilities);
13+
const auto default_capabilities = set_default_capabilities();
14+
publish_capabilities(default_capabilities);
2515
}
2616

2717
void evse_board_supportImpl::handle_enable(bool& value) {
@@ -61,35 +51,38 @@ void evse_board_supportImpl::handle_ac_switch_three_phases_while_charging(bool&
6151
module_state.use_three_phases_confirmed = value;
6252
}
6353

64-
void evse_board_supportImpl::handle_evse_replug(int& value) {
54+
void evse_board_supportImpl::handle_evse_replug(int& _) {
6555
EVLOG_error << "Replugging not supported";
6656
}
6757

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

72-
if (pp_resistor < 80 || pp_resistor > 2460) {
62+
if (pp_resistor < 80 or pp_resistor > 2460) {
7363
EVLOG_error << "PP resistor value " << pp_resistor << " Ohm seems to be outside the allowed range.";
7464
return {.ampacity = Ampacity::None};
75-
} else if (pp_resistor > 936 && pp_resistor <= 2460) {
65+
}
66+
if (pp_resistor > 936 && pp_resistor <= 2460) {
7667
return {.ampacity = Ampacity::A_13};
77-
} else if (pp_resistor > 308 && pp_resistor <= 936) {
68+
}
69+
if (pp_resistor > 308 && pp_resistor <= 936) {
7870
return {.ampacity = Ampacity::A_20};
79-
} else if (pp_resistor > 140 && pp_resistor <= 308) {
71+
}
72+
if (pp_resistor > 140 && pp_resistor <= 308) {
8073
return {.ampacity = Ampacity::A_32};
81-
} else if (pp_resistor > 80 && pp_resistor <= 140) {
74+
}
75+
if (pp_resistor > 80 && pp_resistor <= 140) {
8276
return {.ampacity = Ampacity::A_63_3ph_70_1ph};
83-
} else {
84-
return {.ampacity = Ampacity::None};
8577
}
78+
return {.ampacity = Ampacity::None};
8679
}
8780

8881
void evse_board_supportImpl::handle_ac_set_overcurrent_limit_A(double& value) {
8982
// TODO: intentional?
9083
}
9184

92-
void evse_board_supportImpl::pwm_on(double dutycycle) {
85+
void evse_board_supportImpl::pwm_on(const double dutycycle) const {
9386
auto& module_state = mod->get_module_state();
9487

9588
if (dutycycle > 0.0) {
@@ -101,21 +94,32 @@ void evse_board_supportImpl::pwm_on(double dutycycle) {
10194
}
10295
}
10396

104-
void evse_board_supportImpl::pwm_off() {
97+
void evse_board_supportImpl::pwm_off() const {
10598
auto& module_state = mod->get_module_state();
10699

107100
module_state.pwm_duty_cycle = 1.0;
108101
module_state.pwm_running = false;
109102
module_state.pwm_error_f = false;
110103
}
111104

112-
void evse_board_supportImpl::pwm_f() {
105+
void evse_board_supportImpl::pwm_f() const {
113106
auto& module_state = mod->get_module_state();
114107

115108
module_state.pwm_duty_cycle = 1.0;
116109
module_state.pwm_running = false;
117110
module_state.pwm_error_f = true;
118111
}
119112

120-
} // namespace board_support
121-
} // namespace module
113+
types::evse_board_support::HardwareCapabilities set_default_capabilities() {
114+
return {.max_current_A_import = 32.0,
115+
.min_current_A_import = 6.0,
116+
.max_phase_count_import = 3,
117+
.min_phase_count_import = 1,
118+
.max_current_A_export = 16.0,
119+
.min_current_A_export = 0.0,
120+
.max_phase_count_export = 3,
121+
.min_phase_count_export = 1,
122+
.supports_changing_phases_during_charging = true,
123+
.connector_type = types::evse_board_support::Connector_type::IEC62196Type2Cable};
124+
}
125+
} // namespace module::board_support

modules/YetiSimulator/board_support/evse_board_supportImpl.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
// template version 3
88
//
99

10+
#include <YetiSimulator.hpp>
1011
#include <generated/interfaces/evse_board_support/Implementation.hpp>
1112

12-
#include "../YetiSimulator.hpp"
13-
1413
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
1514
// insert your custom include headers here
1615
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
@@ -28,7 +27,7 @@ class evse_board_supportImpl : public evse_board_supportImplBase {
2827

2928
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
3029
// insert your public definitions here
31-
void pwm_off();
30+
void pwm_off() const;
3231
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
3332

3433
protected:
@@ -56,13 +55,14 @@ class evse_board_supportImpl : public evse_board_supportImplBase {
5655

5756
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
5857
// insert your private definitions here
59-
void pwm_on(double dutycycle);
60-
void pwm_f();
58+
void pwm_on(double dutycycle) const;
59+
void pwm_f() const;
6160
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
6261
};
6362

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

6868
} // namespace board_support

modules/YetiSimulator/connector_lock/connector_lockImpl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Copyright Pionix GmbH and Contributors to EVerest
33

44
#include "connector_lockImpl.hpp"
5+
#include <everest/logging.hpp>
56

6-
namespace module {
7-
namespace connector_lock {
7+
namespace module::connector_lock {
88

99
void connector_lockImpl::init() {
1010
}
@@ -20,5 +20,4 @@ void connector_lockImpl::handle_unlock() {
2020
EVLOG_info << "Unlock connector";
2121
}
2222

23-
} // namespace connector_lock
24-
} // namespace module
23+
} // namespace module::connector_lock

modules/YetiSimulator/connector_lock/connector_lockImpl.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,24 @@
1515
// insert your custom include headers here
1616
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
1717

18-
namespace module {
19-
namespace connector_lock {
18+
namespace module::connector_lock {
2019

2120
struct Conf {};
2221

2322
class connector_lockImpl : public connector_lockImplBase {
2423
public:
2524
connector_lockImpl() = delete;
2625
connector_lockImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<YetiSimulator>& mod, Conf& config) :
27-
connector_lockImplBase(ev, "connector_lock"), mod(mod), config(config){};
26+
connector_lockImplBase(ev, "connector_lock"), mod(mod), config(config) {};
2827

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

3332
protected:
3433
// command handler functions (virtual)
35-
virtual void handle_lock() override;
36-
virtual void handle_unlock() override;
34+
void handle_lock() override;
35+
void handle_unlock() override;
3736

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

46-
virtual void init() override;
47-
virtual void ready() override;
45+
void init() override;
46+
void ready() override;
4847

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

58-
} // namespace connector_lock
59-
} // namespace module
57+
} // namespace module::connector_lock

modules/YetiSimulator/ev_board_support/ev_board_supportImpl.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Copyright Pionix GmbH and Contributors to EVerest
33

44
#include "ev_board_supportImpl.hpp"
5+
#include <everest/logging.hpp>
56

6-
namespace module {
7-
namespace ev_board_support {
7+
namespace module::ev_board_support {
88

99
void ev_board_supportImpl::init() {
1010
}
@@ -14,9 +14,9 @@ void ev_board_supportImpl::ready() {
1414

1515
void ev_board_supportImpl::handle_enable(bool& value) {
1616
auto& module_state = mod->get_module_state();
17-
if (module_state.simulation_enabled && !value) {
17+
if (module_state.simulation_enabled and not value) {
1818
publish_bsp_event({types::board_support_common::Event::A});
19-
mod->clear_data();
19+
mod->reset_module_state();
2020
}
2121
module_state.simulation_enabled = value;
2222
}
@@ -27,23 +27,23 @@ void ev_board_supportImpl::handle_set_cp_state(types::ev_board_support::EvCpStat
2727

2828
switch (cp_state) {
2929
case EvCpState::A:
30-
simdata_setting.cp_voltage = 12.0;
30+
simdata_setting.cp_voltage = cp_voltage_a;
3131
break;
3232
case EvCpState::B:
33-
simdata_setting.cp_voltage = 9.0;
33+
simdata_setting.cp_voltage = cp_voltage_b;
3434
break;
3535
case EvCpState::C:
36-
simdata_setting.cp_voltage = 6.0;
36+
simdata_setting.cp_voltage = cp_voltage_c;
3737
break;
3838
case EvCpState::D:
39-
simdata_setting.cp_voltage = 3.0;
39+
simdata_setting.cp_voltage = cp_voltage_d;
4040
break;
4141
case EvCpState::E:
4242
simdata_setting.error_e = true;
4343
break;
4444
default:
4545
break;
46-
};
46+
}
4747
}
4848

4949
void ev_board_supportImpl::handle_allow_power_on(bool& value) {
@@ -78,5 +78,4 @@ void ev_board_supportImpl::handle_set_rcd_error(double& rcd_current_mA) {
7878
simdata_setting.rcd_current = rcd_current_mA;
7979
}
8080

81-
} // namespace ev_board_support
82-
} // namespace module
81+
} // namespace module::ev_board_support

0 commit comments

Comments
 (0)