Skip to content

Commit 830958f

Browse files
committed
Update SLAC state handling.
Added types/slac.yaml to fix #1323 - The SLAC interface uses the unsupported inline enum declaration Updated everything to work with the new types. Signed-off-by: ThatsLucas <lucasmailpro9@gmail.com>
1 parent 3a34627 commit 830958f

File tree

23 files changed

+86
-90
lines changed

23 files changed

+86
-90
lines changed

interfaces/ev_slac.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ vars:
1313
state:
1414
description: Provides the state enum.
1515
type: string
16-
enum:
17-
- UNMATCHED
18-
- MATCHING
19-
- MATCHED
16+
$ref: /slac#/State
2017
dlink_ready:
2118
description: >-
2219
Inform higher layers about a change in data link status. Emits true

interfaces/slac.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ vars:
2020
state:
2121
description: Provides the state enum.
2222
type: string
23-
enum:
24-
- UNMATCHED
25-
- MATCHING
26-
- MATCHED
23+
$ref: /slac#/State
2724
dlink_ready:
2825
description: >-
2926
Inform higher layers about a change in data link status. Emits true

lib/everest/everest_api_types/tests/expected_interfaces_file_hashes.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ interfaces/over_voltage_monitor.yaml,e900756a2058fca6c24434ac153c34afdf109ad582c
1515
interfaces/power_supply_DC.yaml,7cc64002367143c4898589610739acd80063962e97a1456f66897b0856f916b3
1616
interfaces/powermeter.yaml,e976a19789e0e9dee51a4682821399b8e5e546e0f8770571044e8757bd5f6eb9
1717
interfaces/session_cost.yaml,4afd6dd67938dbc50e3d92751b27313cdcc083fb016998236d32f329df0ac806
18-
interfaces/slac.yaml,ab465ca66e2f4a4be70128228126f8a17338e9f127afaad87c638ddd1df8db44
18+
interfaces/slac.yaml,973bb6d035e7ada95a0a589e0c1453000d37f637cecac53af5c12afe73be05e7
1919
interfaces/system.yaml,4a5eb3f88d7934c3b7d0945aed369e4a6d95028a2c97d4e3090a0f73c1e0dcaf
2020
interfaces/uk_random_delay.yaml,1c2f75ba15d4d5f9a2b1eb4d48ef98a0ba1747deaf9341c8ca610f6fda7c99c1

lib/everest/everest_api_types/tests/expected_types_file_hashes.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ types/money.yaml,4a7001c50216fcf96caac4fe16db17e23ce5149d000be1de4ac1f0135f5bdb0
1616
types/ocpp.yaml,2181f239b0366de85189dbe6cc210ad6b3ab7b6bdeb9ea8aad20fe4410b93bd7
1717
types/power_supply_DC.yaml,eaf73bbd55ca202d8a7723f3f80e3b194a9a698e02aa280e17c87ed4ab3fc772
1818
types/powermeter.yaml,37cae475b16778b7eca641fcee4ecc6c71391d0072ff5c16e11a8a7d7ea9e632
19+
types/slac.yaml,67cef1d0e02e189b64b3e4afb6e5d8e0a152143a19266aefbc313c3f723da330
1920
types/session_cost.yaml,3abb02f95f2e99488f51eefa82a82aaf77d16269bd3cf58d7234ab21d494c3b9
2021
types/system.yaml,75240df8ffe248055e7cab6b5df97dc8d9b8805e557f95b65a200e385218c665
2122
types/temperature.yaml,4c0af04b3cece98f1309779c69dd61f3895c5cc7e0274a1c4d681155141d2cc4

modules/API/slac_API/slac_API.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ namespace API_types_ext = ev_API_types::slac;
1515
namespace API_generic = ev_API_types::generic;
1616
using ev_API::deserialize;
1717

18+
namespace {
19+
20+
types::slac::State to_internal_state(API_types_ext::State state) {
21+
switch (state) {
22+
case API_types_ext::State::UNMATCHED:
23+
return types::slac::State::UNMATCHED;
24+
case API_types_ext::State::MATCHING:
25+
return types::slac::State::MATCHING;
26+
case API_types_ext::State::MATCHED:
27+
return types::slac::State::MATCHED;
28+
}
29+
30+
throw std::out_of_range("Unknown API slac::State value");
31+
}
32+
33+
} // namespace
34+
1835
void slac_API::init() {
1936
invoke_init(*p_main);
2037

@@ -60,7 +77,7 @@ void slac_API::generate_api_var_state() {
6077
subscribe_api_topic("state", [=](const std::string& data) {
6178
API_types_ext::State val;
6279
if (deserialize(data, val)) {
63-
p_main->publish_state(serialize(val));
80+
p_main->publish_state(to_internal_state(val));
6481
return true;
6582
}
6683
return false;

modules/BringUp/BUSlac/BUSlac.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ void BUSlac::init() {
1717
void BUSlac::ready() {
1818
auto screen = ScreenInteractive::Fullscreen();
1919

20-
r_slac->subscribe_state([this, &screen](const std::string& new_state) {
20+
r_slac->subscribe_state([this, &screen](const types::slac::State new_state) {
2121
{
2222
std::scoped_lock lock(data_mutex);
23-
state = new_state;
23+
state = types::slac::state_to_string(new_state);
2424
}
2525
screen.PostEvent(Event::Custom);
2626
});

modules/EV/EvManager/main/car_simulation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void CarSimulation::state_machine() {
2222
r_ev_board_support->call_allow_power_on(false);
2323
// Wait for physical plugin (ev BSP sees state A on CP and not Disconnected)
2424

25-
sim_data.slac_state = "UNMATCHED";
25+
sim_data.slac_state = types::slac::State::UNMATCHED;
2626
if (!r_ev.empty()) {
2727
r_ev[0]->call_stop_charging();
2828
}
@@ -245,16 +245,16 @@ bool CarSimulation::rcd_current(const CmdArguments& arguments) {
245245
bool CarSimulation::iso_wait_slac_matched(const CmdArguments& arguments) {
246246
sim_data.state = SimState::PLUGGED_IN;
247247

248-
if (sim_data.slac_state == "UNMATCHED") {
248+
if (sim_data.slac_state == types::slac::State::UNMATCHED) {
249249
EVLOG_debug << "Slac UNMATCHED";
250250
if (!r_slac.empty()) {
251251
EVLOG_debug << "Slac trigger matching";
252252
r_slac[0]->call_reset();
253253
r_slac[0]->call_trigger_matching();
254-
sim_data.slac_state = "TRIGGERED";
254+
sim_data.slac_state = types::slac::State::MATCHING;
255255
}
256256
}
257-
if (sim_data.slac_state == "MATCHED") {
257+
if (sim_data.slac_state == types::slac::State::MATCHED) {
258258
EVLOG_debug << "Slac Matched";
259259
return true;
260260
}

modules/EV/EvManager/main/car_simulation.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ class CarSimulation {
7474
sim_data.pwm_duty_cycle = pwm_duty_cycle;
7575
}
7676

77-
void set_slac_state(std::string slac_state) {
78-
sim_data.slac_state = std::move(slac_state);
77+
void set_slac_state(const std::string& slac_state) {
78+
try {
79+
sim_data.slac_state = types::slac::string_to_state(slac_state);
80+
} catch (const std::exception& e) {
81+
EVLOG_error << fmt::format("Tried to set unknown SLAC state '{}'. Error: {}", slac_state, e.what());
82+
}
83+
}
84+
85+
void set_slac_state(types::slac::State slac_state) {
86+
sim_data.slac_state = slac_state;
7987
}
8088

8189
void set_iso_pwr_ready(bool iso_pwr_ready) {

modules/EV/EvManager/main/car_simulatorImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ void car_simulatorImpl::subscribe_to_variables_on_init() {
344344
// subscribe slac_state
345345
if (!mod->r_slac.empty()) {
346346
const auto& slac = mod->r_slac.at(0);
347-
slac->subscribe_state([this](const auto& state) { car_simulation->set_slac_state(state); });
347+
slac->subscribe_state(
348+
[this](const auto& state) { car_simulation->set_slac_state(types::slac::state_to_string(state)); });
348349
}
349350

350351
// subscribe ev events

modules/EV/EvManager/main/simulation_data.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "command_registry.hpp"
77
#include "simulation_command.hpp"
88
#include <generated/types/board_support_common.hpp>
9+
#include <generated/types/slac.hpp>
910
#include <optional>
1011
#include <queue>
1112
#include <string>
@@ -36,7 +37,7 @@ struct SimulationData {
3637

3738
SimState state{SimState::UNPLUGGED};
3839
SimState last_state{SimState::UNDEFINED};
39-
std::string slac_state{"UNMATCHED"};
40+
types::slac::State slac_state{types::slac::State::UNMATCHED};
4041
std::optional<size_t> sleep_ticks_left{};
4142

4243
bool v2g_finished{false};

0 commit comments

Comments
 (0)