Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMDSimulator: Add C++ simulation module #498

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -57,7 +57,7 @@ active_modules:
slac:
module: JsSlacSimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator:
module: JsCarSimulator
config_module:
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 @@ -57,7 +57,7 @@ active_modules:
slac:
module: JsSlacSimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator:
module: JsCarSimulator
config_module:
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 @@ -54,7 +54,7 @@ active_modules:
slac:
module: JsSlacSimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator:
module: JsCarSimulator
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 @@ -78,7 +78,7 @@ active_modules:
powersupply_dc:
module: JsDCSupplySimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator_1:
module: JsCarSimulator
config_module:
Expand Down
2 changes: 1 addition & 1 deletion modules/simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ev_add_module(DCSupplySimulator)
ev_add_module(IMDSimulator)
ev_add_module(JsCarSimulator)
ev_add_module(JsDCSupplySimulator)
ev_add_module(JsIMDSimulator)
ev_add_module(JsSlacSimulator)
ev_add_module(JsYetiSimulator)
21 changes: 21 additions & 0 deletions modules/simulation/IMDSimulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# 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
"main/isolation_monitorImpl.cpp"
)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
15 changes: 15 additions & 0 deletions modules/simulation/IMDSimulator/IMDSimulator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "IMDSimulator.hpp"

namespace module {

void IMDSimulator::init() {
invoke_init(*p_main);
}

void IMDSimulator::ready() {
invoke_ready(*p_main);
}

} // namespace module
58 changes: 58 additions & 0 deletions modules/simulation/IMDSimulator/IMDSimulator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef IMDSIMULATOR_HPP
#define IMDSIMULATOR_HPP

//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//

#include "ld-ev.hpp"

// headers for provided interface implementations
#include <generated/interfaces/isolation_monitor/Implementation.hpp>

// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1

namespace module {

struct Conf {};

class IMDSimulator : public Everest::ModuleBase {
public:
IMDSimulator() = delete;
IMDSimulator(const ModuleInfo& info, std::unique_ptr<isolation_monitorImplBase> p_main, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), config(config){};

const std::unique_ptr<isolation_monitorImplBase> p_main;
const Conf& config;

// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// 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
// 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 // IMDSIMULATOR_HPP
55 changes: 55 additions & 0 deletions modules/simulation/IMDSimulator/main/isolation_monitorImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023 chargebyte GmbH
// Copyright (C) 2023 Contributors to EVerest
#include "isolation_monitorImpl.hpp"
#include <chrono>
#include <thread>
namespace module {
namespace main {

void isolation_monitorImpl::init() {
this->isolation_monitoring_active = false;
this->isolation_measurement.resistance_F_Ohm = this->config.resistance_F_Ohm;
this->config_interval = this->config.interval;

this->isolation_measurement_thread_handle = std::thread(&isolation_monitorImpl::isolation_measurement_worker, this);
}

void isolation_monitorImpl::ready() {
}

isolation_monitorImpl::~isolation_monitorImpl() {
}

void isolation_monitorImpl::handle_start() {
if (this->isolation_monitoring_active == false) {
this->isolation_monitoring_active = true;
EVLOG_info << "Started simulated isolation monitoring with " << this->config_interval << " ms interval";
}
};

void isolation_monitorImpl::isolation_measurement_worker() {
while (true) {
if (this->isolation_measurement_thread_handle.shouldExit()) {
break;
}

if (this->isolation_monitoring_active == true) {
this->mod->p_main->publish_IsolationMeasurement(this->isolation_measurement);
EVLOG_debug << "Simulated isolation measurement finished";
std::this_thread::sleep_for(std::chrono::milliseconds(this->config_interval - this->LOOP_SLEEP_MS));
}

std::this_thread::sleep_for(std::chrono::milliseconds(this->LOOP_SLEEP_MS));
}
}

void isolation_monitorImpl::handle_stop() {
if (this->isolation_monitoring_active == true) {
EVLOG_info << "Stopped simulated isolation monitoring";
this->isolation_monitoring_active = false;
}
};

} // namespace main
} // namespace module
77 changes: 77 additions & 0 deletions modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023 chargebyte GmbH
// Copyright (C) 2023 Contributors to EVerest
#ifndef MAIN_ISOLATION_MONITOR_IMPL_HPP
#define MAIN_ISOLATION_MONITOR_IMPL_HPP

//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//

#include <generated/interfaces/isolation_monitor/Implementation.hpp>

#include "../IMDSimulator.hpp"

// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
#include <atomic>
#include <mutex>
#include <utils/thread.hpp>
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1

namespace module {
namespace main {

struct Conf {
double resistance_F_Ohm;

Check notice on line 27 in modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp#L27

struct member 'Conf::resistance_F_Ohm' is never used.
int interval;

Check notice on line 28 in modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp#L28

struct member 'Conf::interval' is never used.
};

class isolation_monitorImpl : public isolation_monitorImplBase {
public:
isolation_monitorImpl() = delete;
isolation_monitorImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<IMDSimulator>& mod, Conf& config) :

Check warning on line 34 in modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp#L34

Member variable 'isolation_monitorImpl::config_interval' is not initialized in the constructor.
isolation_monitorImplBase(ev, "main"), mod(mod), config(config){};
~isolation_monitorImpl();

// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1

protected:
// command handler functions (virtual)
virtual void handle_start() override;
virtual void handle_stop() override;

// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1

private:
const Everest::PtrContainer<IMDSimulator>& mod;
const Conf& config;

virtual void init() override;
virtual void ready() override;

// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
types::isolation_monitor::IsolationMeasurement isolation_measurement;
std::atomic<bool> isolation_monitoring_active;
int config_interval;

Check notice on line 62 in modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp#L62

class member 'isolation_monitorImpl::config_interval' is never used.
static constexpr int LOOP_SLEEP_MS{20};

Check notice on line 63 in modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/simulation/IMDSimulator/main/isolation_monitorImpl.hpp#L63

class member 'isolation_monitorImpl::LOOP_SLEEP_MS' is never used.

Everest::Thread isolation_measurement_thread_handle;
void isolation_measurement_worker(void);
// 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 main
} // namespace module

#endif // MAIN_ISOLATION_MONITOR_IMPL_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ provides:
description: Measurement update interval in milliseconds
type: integer
default: 1000
enable_external_mqtt: true
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Fabian Hartung (chargebyte GmbH)
- Cornelius Claussen (Pionix GmbH)
Empty file.
39 changes: 0 additions & 39 deletions modules/simulation/JsIMDSimulator/index.js

This file was deleted.