Skip to content

Commit f3fb931

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 f3fb931

File tree

26 files changed

+128
-89
lines changed

26 files changed

+128
-89
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/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ target_sources(everest_api_types
9292

9393
src/everest_api_types/slac/codec.cpp
9494
src/everest_api_types/slac/json_codec.cpp
95+
src/everest_api_types/slac/wrapper.cpp
9596

9697
src/everest_api_types/system/codec.cpp
9798
src/everest_api_types/system/json_codec.cpp
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest
3+
4+
#include <everest_api_types/slac/API.hpp>
5+
#pragma GCC diagnostic push
6+
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
7+
#pragma GCC diagnostic ignored "-Wunused-function"
8+
#include "generated/types/slac.hpp"
9+
#pragma GCC diagnostic pop
10+
11+
namespace everest::lib::API::V1_0::types::slac {
12+
13+
using SlacState_Internal = ::types::slac::State;
14+
using SlacState_External = State;
15+
16+
SlacState_Internal to_internal_api(SlacState_External const& val);
17+
SlacState_External to_external_api(SlacState_Internal const& val);
18+
19+
} // namespace everest::lib::API::V1_0::types::slac
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest
3+
4+
#include "slac/wrapper.hpp"
5+
#include "slac/codec.hpp"
6+
#include <stdexcept>
7+
#include <string>
8+
9+
namespace everest::lib::API::V1_0::types::slac {
10+
11+
SlacState_Internal to_internal_api(SlacState_External const& val) {
12+
using SrcT = SlacState_External;
13+
using TarT = SlacState_Internal;
14+
switch (val) {
15+
case SrcT::UNMATCHED:
16+
return TarT::UNMATCHED;
17+
case SrcT::MATCHING:
18+
return TarT::MATCHING;
19+
case SrcT::MATCHED:
20+
return TarT::MATCHED;
21+
}
22+
throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::slac::SlacState_External");
23+
}
24+
25+
SlacState_External to_external_api(SlacState_Internal const& val) {
26+
using SrcT = SlacState_Internal;
27+
using TarT = SlacState_External;
28+
switch (val) {
29+
case SrcT::UNMATCHED:
30+
return TarT::UNMATCHED;
31+
case SrcT::MATCHING:
32+
return TarT::MATCHING;
33+
case SrcT::MATCHED:
34+
return TarT::MATCHED;
35+
}
36+
throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::slac::SlacState_Internal");
37+
}
38+
39+
} // namespace everest::lib::API::V1_0::types::slac

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <everest_api_types/generic/string.hpp>
77
#include <everest_api_types/slac/API.hpp>
88
#include <everest_api_types/slac/codec.hpp>
9+
#include <everest_api_types/slac/wrapper.hpp>
910
#include <everest_api_types/utilities/codec.hpp>
1011

1112
namespace module {
@@ -60,7 +61,7 @@ void slac_API::generate_api_var_state() {
6061
subscribe_api_topic("state", [=](const std::string& data) {
6162
API_types_ext::State val;
6263
if (deserialize(data, val)) {
63-
p_main->publish_state(serialize(val));
64+
p_main->publish_state(to_internal_api(val));
6465
return true;
6566
}
6667
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
}

0 commit comments

Comments
 (0)