Skip to content

Commit

Permalink
Adding Slac Simulator (#859)
Browse files Browse the repository at this point in the history
* adds slac simulator

Signed-off-by: MarzellT <[email protected]>

* updates codeowners file

Signed-off-by: MarzellT <[email protected]>

* changes loop_interval_ms variable to constexpr

Signed-off-by: MarzellT <[email protected]>

* removes doc files and changes namespace definitions

Signed-off-by: MarzellT <[email protected]>

* changes the config files to make use of the new SlacSimulator

Signed-off-by: MarzellT <[email protected]>

* Initialize car_simulation in init() instead of ready() to ensure it's initialized early enough

Otherwise publishes from other modules can happen before its initialization triggering segfaults

Signed-off-by: Kai-Uwe Hermann <[email protected]>

* Removed config options that were not used

Signed-off-by: Kai-Uwe Hermann <[email protected]>

* Move SlacSimulator into simulation directory

Signed-off-by: Kai-Uwe Hermann <[email protected]>

---------

Signed-off-by: MarzellT <[email protected]>
Signed-off-by: Kai-Uwe Hermann <[email protected]>
Co-authored-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
MarzellT and hikinggrass authored Sep 24, 2024
1 parent 17555a7 commit 65aa57b
Show file tree
Hide file tree
Showing 26 changed files with 456 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-dc-sae-v2g.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ active_modules:
config_module:
connector_id: 1
slac:
module: JsSlacSimulator
module: SlacSimulator
imd:
module: IMDSimulator
config_implementation:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-dc-sae-v2h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ active_modules:
config_module:
connector_id: 1
slac:
module: JsSlacSimulator
module: SlacSimulator
imd:
module: IMDSimulator
config_implementation:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-dc-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ active_modules:
config_module:
connector_id: 1
slac:
module: JsSlacSimulator
module: SlacSimulator
imd:
config_implementation:
main:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ active_modules:
config_module:
connector_id: 1
slac:
module: JsSlacSimulator
module: SlacSimulator
imd:
config_implementation:
main:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-energy-management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ active_modules:
config_module:
connector_id: 2
slac:
module: JsSlacSimulator
module: SlacSimulator
ev_manager_1:
module: EvManager
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-ocpp-custom-extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ active_modules:
config_module:
connector_id: 2
slac:
module: JsSlacSimulator
module: SlacSimulator
ev_manager_1:
module: EvManager
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-ocpp-pnc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ active_modules:
config_module:
connector_id: 2
slac:
module: JsSlacSimulator
module: SlacSimulator
ev_manager_1:
module: EvManager
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ active_modules:
config_module:
connector_id: 2
slac:
module: JsSlacSimulator
module: SlacSimulator
ev_manager_1:
module: EvManager
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-ocpp201-pnc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ active_modules:
config_module:
connector_id: 2
slac:
module: JsSlacSimulator
module: SlacSimulator
ev_manager_1:
module: EvManager
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-ocpp201.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ active_modules:
config_module:
connector_id: 2
slac:
module: JsSlacSimulator
module: SlacSimulator
ev_manager_1:
module: EvManager
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-two-evse-dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ active_modules:
config_module:
connector_id: 2
slac_1:
module: JsSlacSimulator
module: SlacSimulator
powersupply_dc:
module: DCSupplySimulator
imd:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-two-evse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ active_modules:
config_module:
connector_id: 2
slac:
module: JsSlacSimulator
module: SlacSimulator
ev_manager_1:
module: EvManager
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ active_modules:
nid: pionix!
number_of_sounds: 10
connections: {}
module: JsSlacSimulator
module: SlacSimulator
token_provider:
config_implementation:
main:
Expand Down
4 changes: 2 additions & 2 deletions modules/EvManager/main/car_simulatorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ void car_simulatorImpl::init() {
register_all_commands();
subscribe_to_variables_on_init();

car_simulation = std::make_unique<CarSimulation>(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<CarSimulation>(mod->r_ev_board_support, mod->r_ev, mod->r_slac);

setup_ev_parameters();

if (mod->config.auto_enable) {
Expand Down
1 change: 1 addition & 0 deletions modules/simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ev_add_module(IMDSimulator)
ev_add_module(JsEvManager)
ev_add_module(JsSlacSimulator)
ev_add_module(JsYetiSimulator)
ev_add_module(SlacSimulator)
26 changes: 26 additions & 0 deletions modules/simulation/SlacSimulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions modules/simulation/SlacSimulator/SlacSimulator.cpp
Original file line number Diff line number Diff line change
@@ -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<evse::slacImpl&>(*p_evse);
auto& ev = dynamic_cast<ev::ev_slacImpl&>(*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
67 changes: 67 additions & 0 deletions modules/simulation/SlacSimulator/SlacSimulator.hpp
Original file line number Diff line number Diff line change
@@ -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 <generated/interfaces/ev_slac/Implementation.hpp>
#include <generated/interfaces/slac/Implementation.hpp>

// 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<slacImplBase> p_evse,
std::unique_ptr<ev_slacImplBase> 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<slacImplBase> p_evse;
const std::unique_ptr<ev_slacImplBase> 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
44 changes: 44 additions & 0 deletions modules/simulation/SlacSimulator/ev/ev_slacImpl.cpp
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp
Original file line number Diff line number Diff line change
@@ -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 <generated/interfaces/ev_slac/Implementation.hpp>

#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<SlacSimulator>& 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<SlacSimulator>& 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
Loading

0 comments on commit 65aa57b

Please sign in to comment.