diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index d43ddb76b..696a567f5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -32,6 +32,7 @@ /modules/Setup @hikinggrass @corneliusclaussen @pietfried /modules/YetiDriver @corneliusclaussen @hikinggrass /modules/simulation/ @SebaLukas @pietfried @hikinggrass +/modules/SlacSimulator/ @SebaLukas @pietfried @corneliusclaussen @MarzellT /modules/rust_examples/ @SirVer @golovasteek @dorezyuk **/Cargo.toml @SirVer @golovasteek @dorezyuk **/Cargo.lock @SirVer @golovasteek @dorezyuk diff --git a/config/config-sil-dc-sae-v2g.yaml b/config/config-sil-dc-sae-v2g.yaml index 1c75e8556..b7591ed3c 100644 --- a/config/config-sil-dc-sae-v2g.yaml +++ b/config/config-sil-dc-sae-v2g.yaml @@ -53,7 +53,7 @@ active_modules: config_module: connector_id: 1 slac: - module: JsSlacSimulator + module: SlacSimulator imd: module: IMDSimulator config_implementation: diff --git a/config/config-sil-dc-sae-v2h.yaml b/config/config-sil-dc-sae-v2h.yaml index bc81ea96b..fe2f9e11a 100644 --- a/config/config-sil-dc-sae-v2h.yaml +++ b/config/config-sil-dc-sae-v2h.yaml @@ -53,7 +53,7 @@ active_modules: config_module: connector_id: 1 slac: - module: JsSlacSimulator + module: SlacSimulator imd: module: IMDSimulator config_implementation: diff --git a/config/config-sil-dc-tls.yaml b/config/config-sil-dc-tls.yaml index d5cdafa79..7645821b2 100644 --- a/config/config-sil-dc-tls.yaml +++ b/config/config-sil-dc-tls.yaml @@ -54,7 +54,7 @@ active_modules: config_module: connector_id: 1 slac: - module: JsSlacSimulator + module: SlacSimulator imd: config_implementation: main: diff --git a/config/config-sil-dc.yaml b/config/config-sil-dc.yaml index 00877a484..9770bdd19 100644 --- a/config/config-sil-dc.yaml +++ b/config/config-sil-dc.yaml @@ -51,7 +51,7 @@ active_modules: config_module: connector_id: 1 slac: - module: JsSlacSimulator + module: SlacSimulator imd: config_implementation: main: diff --git a/config/config-sil-energy-management.yaml b/config/config-sil-energy-management.yaml index 01c698048..199f8b5e8 100644 --- a/config/config-sil-energy-management.yaml +++ b/config/config-sil-energy-management.yaml @@ -68,7 +68,7 @@ active_modules: config_module: connector_id: 2 slac: - module: JsSlacSimulator + module: SlacSimulator ev_manager_1: module: EvManager config_module: diff --git a/config/config-sil-ocpp-custom-extension.yaml b/config/config-sil-ocpp-custom-extension.yaml index ada1fb338..0a13a162e 100644 --- a/config/config-sil-ocpp-custom-extension.yaml +++ b/config/config-sil-ocpp-custom-extension.yaml @@ -74,7 +74,7 @@ active_modules: config_module: connector_id: 2 slac: - module: JsSlacSimulator + module: SlacSimulator ev_manager_1: module: EvManager config_module: diff --git a/config/config-sil-ocpp-pnc.yaml b/config/config-sil-ocpp-pnc.yaml index dc5fed3ce..9771903a6 100644 --- a/config/config-sil-ocpp-pnc.yaml +++ b/config/config-sil-ocpp-pnc.yaml @@ -77,7 +77,7 @@ active_modules: config_module: connector_id: 2 slac: - module: JsSlacSimulator + module: SlacSimulator ev_manager_1: module: EvManager config_module: diff --git a/config/config-sil-ocpp.yaml b/config/config-sil-ocpp.yaml index 4a07f5256..7ad065089 100644 --- a/config/config-sil-ocpp.yaml +++ b/config/config-sil-ocpp.yaml @@ -83,7 +83,7 @@ active_modules: config_module: connector_id: 2 slac: - module: JsSlacSimulator + module: SlacSimulator ev_manager_1: module: EvManager config_module: diff --git a/config/config-sil-ocpp201-pnc.yaml b/config/config-sil-ocpp201-pnc.yaml index dd9643822..834e353bf 100644 --- a/config/config-sil-ocpp201-pnc.yaml +++ b/config/config-sil-ocpp201-pnc.yaml @@ -77,7 +77,7 @@ active_modules: config_module: connector_id: 2 slac: - module: JsSlacSimulator + module: SlacSimulator ev_manager_1: module: EvManager config_module: diff --git a/config/config-sil-ocpp201.yaml b/config/config-sil-ocpp201.yaml index f9471d17b..93ba79bb1 100644 --- a/config/config-sil-ocpp201.yaml +++ b/config/config-sil-ocpp201.yaml @@ -76,7 +76,7 @@ active_modules: config_module: connector_id: 2 slac: - module: JsSlacSimulator + module: SlacSimulator ev_manager_1: module: EvManager config_module: diff --git a/config/config-sil-two-evse-dc.yaml b/config/config-sil-two-evse-dc.yaml index d2246f493..01be2f551 100644 --- a/config/config-sil-two-evse-dc.yaml +++ b/config/config-sil-two-evse-dc.yaml @@ -70,7 +70,7 @@ active_modules: config_module: connector_id: 2 slac_1: - module: JsSlacSimulator + module: SlacSimulator powersupply_dc: module: DCSupplySimulator imd: diff --git a/config/config-sil-two-evse.yaml b/config/config-sil-two-evse.yaml index 3d00dbc6a..a0c511c64 100644 --- a/config/config-sil-two-evse.yaml +++ b/config/config-sil-two-evse.yaml @@ -64,7 +64,7 @@ active_modules: config_module: connector_id: 2 slac: - module: JsSlacSimulator + module: SlacSimulator ev_manager_1: module: EvManager config_module: diff --git a/config/config-sil.yaml b/config/config-sil.yaml index aa1ebf36a..a3f115656 100644 --- a/config/config-sil.yaml +++ b/config/config-sil.yaml @@ -162,7 +162,7 @@ active_modules: nid: pionix! number_of_sounds: 10 connections: {} - module: JsSlacSimulator + module: SlacSimulator token_provider: config_implementation: main: diff --git a/modules/EvManager/main/car_simulatorImpl.cpp b/modules/EvManager/main/car_simulatorImpl.cpp index e42ed0780..3a13c2702 100644 --- a/modules/EvManager/main/car_simulatorImpl.cpp +++ b/modules/EvManager/main/car_simulatorImpl.cpp @@ -13,14 +13,14 @@ void car_simulatorImpl::init() { register_all_commands(); subscribe_to_variables_on_init(); + car_simulation = std::make_unique(mod->r_ev_board_support, mod->r_ev, mod->r_slac); + std::thread(&car_simulatorImpl::run, this).detach(); } void car_simulatorImpl::ready() { subscribe_to_external_mqtt(); - car_simulation = std::make_unique(mod->r_ev_board_support, mod->r_ev, mod->r_slac); - setup_ev_parameters(); if (mod->config.auto_enable) { diff --git a/modules/simulation/CMakeLists.txt b/modules/simulation/CMakeLists.txt index 937ec4e7a..bea913458 100644 --- a/modules/simulation/CMakeLists.txt +++ b/modules/simulation/CMakeLists.txt @@ -3,3 +3,4 @@ ev_add_module(IMDSimulator) ev_add_module(JsEvManager) ev_add_module(JsSlacSimulator) ev_add_module(JsYetiSimulator) +ev_add_module(SlacSimulator) diff --git a/modules/simulation/SlacSimulator/CMakeLists.txt b/modules/simulation/SlacSimulator/CMakeLists.txt new file mode 100644 index 000000000..7a884c9d5 --- /dev/null +++ b/modules/simulation/SlacSimulator/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# AUTO GENERATED - MARKED REGIONS WILL BE KEPT +# template version 3 +# + +# module setup: +# - ${MODULE_NAME}: module name +ev_setup_cpp_module() + +# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 +# insert your custom targets and additional config variables here +# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 + +target_sources(${MODULE_NAME} + PRIVATE + "evse/slacImpl.cpp" + "ev/ev_slacImpl.cpp" +) + +# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 +# insert other things like install cmds etc here +target_sources(${MODULE_NAME} + PRIVATE + "util/state.cpp" +) +# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 diff --git a/modules/simulation/SlacSimulator/SlacSimulator.cpp b/modules/simulation/SlacSimulator/SlacSimulator.cpp new file mode 100644 index 000000000..4314fbf22 --- /dev/null +++ b/modules/simulation/SlacSimulator/SlacSimulator.cpp @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest +#include "SlacSimulator.hpp" +#include "ev/ev_slacImpl.hpp" +#include "evse/slacImpl.hpp" + +namespace module { + +using util::State; + +void SlacSimulator::init() { + invoke_init(*p_evse); + invoke_init(*p_ev); +} + +void SlacSimulator::ready() { + invoke_ready(*p_evse); + invoke_ready(*p_ev); + + std::thread(&SlacSimulator::run, this).detach(); +} + +void SlacSimulator::run() { + auto& evse = dynamic_cast(*p_evse); + auto& ev = dynamic_cast(*p_ev); + while (true) { + cntmatching++; + if (ev.get_state() == State::MATCHING && evse.get_state() == State::MATCHING && cntmatching > 2 * 4) { + ev.set_state_matched(); + evse.set_state_matched(); + } + std::this_thread::sleep_for(std::chrono::milliseconds(loop_interval_ms)); + } +}; + +} // namespace module diff --git a/modules/simulation/SlacSimulator/SlacSimulator.hpp b/modules/simulation/SlacSimulator/SlacSimulator.hpp new file mode 100644 index 000000000..5febf5a65 --- /dev/null +++ b/modules/simulation/SlacSimulator/SlacSimulator.hpp @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest +#ifndef SLAC_SIMULATOR_HPP +#define SLAC_SIMULATOR_HPP + +// +// AUTO GENERATED - MARKED REGIONS WILL BE KEPT +// template version 2 +// + +#include "ld-ev.hpp" + +// headers for provided interface implementations +#include +#include + +// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1 +// insert your custom include headers here +#include "util/state.hpp" +// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1 + +namespace module { + +struct Conf {}; + +class SlacSimulator : public Everest::ModuleBase { +public: + SlacSimulator() = delete; + SlacSimulator(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, std::unique_ptr p_evse, + std::unique_ptr p_ev, Conf& config) : + ModuleBase(info), mqtt(mqtt_provider), p_evse(std::move(p_evse)), p_ev(std::move(p_ev)), config(config){}; + + Everest::MqttProvider& mqtt; + const std::unique_ptr p_evse; + const std::unique_ptr p_ev; + const Conf& config; + + // ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1 + // insert your public definitions here + std::size_t cntmatching{0}; + // ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1 + +protected: + // ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1 + // insert your protected definitions here + // ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1 + +private: + friend class LdEverest; + void init(); + void ready(); + + // ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1 + // insert your private definitions here + void run(); + + static constexpr size_t loop_interval_ms{250}; + // ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1 +}; + +// ev@087e516b-124c-48df-94fb-109508c7cda9:v1 +// insert other definitions here +// ev@087e516b-124c-48df-94fb-109508c7cda9:v1 + +} // namespace module + +#endif // SLAC_SIMULATOR_HPP diff --git a/modules/simulation/SlacSimulator/ev/ev_slacImpl.cpp b/modules/simulation/SlacSimulator/ev/ev_slacImpl.cpp new file mode 100644 index 000000000..bf6f34f92 --- /dev/null +++ b/modules/simulation/SlacSimulator/ev/ev_slacImpl.cpp @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest + +#include "ev_slacImpl.hpp" + +namespace module { +namespace ev { + +using util::State; + +void ev_slacImpl::init() { +} + +void ev_slacImpl::ready() { + publish_state(state_to_string(state)); +} + +void ev_slacImpl::handle_reset() { + if (state != State::UNMATCHED) { + state = State::UNMATCHED; + publish_state(state_to_string(state)); + publish_dlink_ready(false); + } +} + +bool ev_slacImpl::handle_trigger_matching() { + state = State::MATCHING; + mod->cntmatching = 0; + publish_state(state_to_string(state)); + return true; +} + +State ev_slacImpl::get_state() const { + return state; +} + +void ev_slacImpl::set_state_matched() { + state = State::MATCHED; + publish_state(state_to_string(state)); + publish_dlink_ready(true); +} + +} // namespace ev +} // namespace module diff --git a/modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp b/modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp new file mode 100644 index 000000000..a7569576f --- /dev/null +++ b/modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest +#ifndef EV_EV_SLAC_IMPL_HPP +#define EV_EV_SLAC_IMPL_HPP + +// +// AUTO GENERATED - MARKED REGIONS WILL BE KEPT +// template version 3 +// + +#include + +#include "../SlacSimulator.hpp" + +// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1 +// insert your custom include headers here +#include "../util/state.hpp" +// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1 + +namespace module { +namespace ev { + +struct Conf {}; + +class ev_slacImpl : public ev_slacImplBase { +public: + ev_slacImpl() = delete; + ev_slacImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer& mod, Conf& config) : + ev_slacImplBase(ev, "ev"), mod(mod), config(config){}; + + // ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1 + // insert your public definitions here + util::State get_state() const; + void set_state_matched(); + // ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1 + +protected: + // command handler functions (virtual) + virtual void handle_reset() override; + virtual bool handle_trigger_matching() override; + + // ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1 + // insert your protected definitions here + // ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1 + +private: + const Everest::PtrContainer& mod; + const Conf& config; + + virtual void init() override; + virtual void ready() override; + + // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 + // insert your private definitions here + util::State state; + // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 +}; + +// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1 +// insert other definitions here +// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1 + +} // namespace ev +} // namespace module + +#endif // EV_EV_SLAC_IMPL_HPP diff --git a/modules/simulation/SlacSimulator/evse/slacImpl.cpp b/modules/simulation/SlacSimulator/evse/slacImpl.cpp new file mode 100644 index 000000000..fe469ca9a --- /dev/null +++ b/modules/simulation/SlacSimulator/evse/slacImpl.cpp @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest + +#include "slacImpl.hpp" + +namespace module { +namespace evse { + +using util::State; + +void slacImpl::init() { +} + +void slacImpl::ready() { + publish_state(state_to_string(state)); +} + +void slacImpl::handle_reset(bool& enable) { + set_state_to_unmatched(); +} + +bool slacImpl::handle_enter_bcd() { + set_state_to_matching(); + return true; +} + +bool slacImpl::handle_leave_bcd() { + set_state_to_unmatched(); + return true; +} + +bool slacImpl::handle_dlink_terminate() { + set_state_to_unmatched(); + return true; +} + +bool slacImpl::handle_dlink_error() { + set_state_to_unmatched(); + return true; +} + +bool slacImpl::handle_dlink_pause() { + return true; +} + +void slacImpl::set_state_to_unmatched() { + if (state != State::UNMATCHED) { + state = State::UNMATCHED; + publish_state(state_to_string(state)); + publish_dlink_ready(false); + } +} + +void slacImpl::set_state_to_matching() { + state = State::MATCHING; + mod->cntmatching = 0; + publish_state(state_to_string(state)); +} + +State slacImpl::get_state() const { + return state; +} + +void slacImpl::set_state_matched() { + state = State::MATCHED; + publish_state(state_to_string(state)); + publish_dlink_ready(true); +}; +} // namespace evse +} // namespace module diff --git a/modules/simulation/SlacSimulator/evse/slacImpl.hpp b/modules/simulation/SlacSimulator/evse/slacImpl.hpp new file mode 100644 index 000000000..1de2d0116 --- /dev/null +++ b/modules/simulation/SlacSimulator/evse/slacImpl.hpp @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest +#ifndef EVSE_SLAC_IMPL_HPP +#define EVSE_SLAC_IMPL_HPP + +// +// AUTO GENERATED - MARKED REGIONS WILL BE KEPT +// template version 3 +// + +#include + +#include "../SlacSimulator.hpp" + +// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1 +// insert your custom include headers here +#include "../util/state.hpp" +// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1 + +namespace module { +namespace evse { + +struct Conf {}; + +class slacImpl : public slacImplBase { +public: + slacImpl() = delete; + slacImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer& mod, Conf& config) : + slacImplBase(ev, "evse"), mod(mod), config(config){}; + + // ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1 + // insert your public definitions here + util::State get_state() const; + void set_state_matched(); + // ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1 + +protected: + // command handler functions (virtual) + virtual void handle_reset(bool& enable) override; + virtual bool handle_enter_bcd() override; + virtual bool handle_leave_bcd() override; + virtual bool handle_dlink_terminate() override; + virtual bool handle_dlink_error() override; + virtual bool handle_dlink_pause() override; + + // ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1 + // insert your protected definitions here + // ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1 + +private: + const Everest::PtrContainer& mod; + const Conf& config; + + virtual void init() override; + virtual void ready() override; + + // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 + // insert your private definitions here + void set_state_to_unmatched(); + void set_state_to_matching(); + + util::State state; + // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 +}; + +// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1 +// insert other definitions here +// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1 + +} // namespace evse +} // namespace module + +#endif // EVSE_SLAC_IMPL_HPP diff --git a/modules/simulation/SlacSimulator/manifest.yaml b/modules/simulation/SlacSimulator/manifest.yaml new file mode 100644 index 000000000..fc71af47e --- /dev/null +++ b/modules/simulation/SlacSimulator/manifest.yaml @@ -0,0 +1,14 @@ +description: SIL Implementation of SLAC data link negotiation according to ISO15118-3. +provides: + evse: + interface: slac + description: SLAC interface implementation for EVSE side + ev: + interface: ev_slac + description: SLAC interface implementation for EV side +enable_external_mqtt: true +metadata: + license: https://opensource.org/licenses/Apache-2.0 + authors: + - Cornelius Claussen (Pionix GmbH) + - Tobias Marzell (Pionix GmbH) diff --git a/modules/simulation/SlacSimulator/util/state.cpp b/modules/simulation/SlacSimulator/util/state.cpp new file mode 100644 index 000000000..31299521e --- /dev/null +++ b/modules/simulation/SlacSimulator/util/state.cpp @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest +#include "state.hpp" +#include + +namespace module::util { + +std::string state_to_string(State state) { + switch (state) { + case State::UNMATCHED: + return "UNMATCHED"; + case State::MATCHING: + return "MATCHING"; + case State::MATCHED: + return "MATCHED"; + default: + return ""; + } +} + +} // namespace module::util diff --git a/modules/simulation/SlacSimulator/util/state.hpp b/modules/simulation/SlacSimulator/util/state.hpp new file mode 100644 index 000000000..5ab23b03a --- /dev/null +++ b/modules/simulation/SlacSimulator/util/state.hpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest + +#ifndef UTIL_STATE_HPP +#define UTIL_STATE_HPP + +#include +#include + +namespace module::util { + +enum class State : uint8_t { + UNMATCHED = 0, + MATCHING = 1, + MATCHED = 2, +}; + +std::string state_to_string(State state); + +} // namespace module::util + +#endif