Skip to content

Commit 73a2a88

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 73a2a88

File tree

9 files changed

+40
-16
lines changed

9 files changed

+40
-16
lines changed

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/EVSE/EvseManager/EvseManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,10 +1266,10 @@ void EvseManager::ready() {
12661266
}
12671267

12681268
if (slac_enabled) {
1269-
r_slac[0]->subscribe_state([this](const std::string& s) {
1270-
session_log.evse(true, fmt::format("SLAC {}", s));
1269+
r_slac[0]->subscribe_state([this](const types::slac::State s) {
1270+
session_log.evse(true, fmt::format("SLAC {}", types::slac::state_to_string(s)));
12711271
// Notify charger whether matching was started (or is done) or not
1272-
if (s == "UNMATCHED") {
1272+
if (s == types::slac::State::UNMATCHED) {
12731273
charger->set_matching_started(false);
12741274
slac_unmatched = true;
12751275
} else {

modules/EVSE/EvseSlac/main/slacImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void slacImpl::run() {
6565

6666
callbacks.signal_dlink_ready = [this](bool value) { publish_dlink_ready(value); };
6767

68-
callbacks.signal_state = [this](const std::string& value) { publish_state(value); };
68+
callbacks.signal_state = [this](const std::string& value) { publish_state(types::slac::string_to_state(value)); };
6969

7070
callbacks.signal_error_routine_request = [this]() { publish_request_error_routine(nullptr); };
7171

modules/Simulation/SlacSimulator/evse/slacImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void slacImpl::init() {
1212
}
1313

1414
void slacImpl::ready() {
15-
publish_state(state_to_string(state));
15+
publish_state(types::slac::string_to_state(state_to_string(state)));
1616
}
1717

1818
void slacImpl::handle_reset(bool& enable) {
@@ -42,15 +42,15 @@ void slacImpl::handle_dlink_pause() {
4242
void slacImpl::set_state_to_unmatched() {
4343
if (state != State::UNMATCHED) {
4444
state = State::UNMATCHED;
45-
publish_state(state_to_string(state));
45+
publish_state(types::slac::string_to_state(state_to_string(state)));
4646
publish_dlink_ready(false);
4747
}
4848
}
4949

5050
void slacImpl::set_state_to_matching() {
5151
state = State::MATCHING;
5252
mod->cntmatching = 0;
53-
publish_state(state_to_string(state));
53+
publish_state(types::slac::string_to_state(state_to_string(state)));
5454
}
5555

5656
State slacImpl::get_state() const {
@@ -59,7 +59,7 @@ State slacImpl::get_state() const {
5959

6060
void slacImpl::set_state_matched() {
6161
state = State::MATCHED;
62-
publish_state(state_to_string(state));
62+
publish_state(types::slac::string_to_state(state_to_string(state)));
6363
publish_dlink_ready(true);
6464
};
6565
} // namespace evse

types/slac.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description: SLAC shared types
2+
types:
3+
State:
4+
description: SLAC state enum
5+
type: string
6+
enum:
7+
- UNMATCHED
8+
- MATCHING
9+
- MATCHED

0 commit comments

Comments
 (0)