Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
5
tools/EVerest-main/modules/Simulation/CMakeLists.txt
Normal file
5
tools/EVerest-main/modules/Simulation/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
ev_add_module(DCSupplySimulator)
|
||||
ev_add_module(IMDSimulator)
|
||||
ev_add_module(OVMSimulator)
|
||||
ev_add_module(SlacSimulator)
|
||||
ev_add_module(YetiSimulator)
|
||||
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# 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
|
||||
# needed for std::scoped_lock
|
||||
target_compile_features(${MODULE_NAME} PUBLIC cxx_std_17)
|
||||
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
|
||||
|
||||
target_sources(${MODULE_NAME}
|
||||
PRIVATE
|
||||
"main/power_supply_DCImpl.cpp"
|
||||
"powermeter/powermeterImpl.cpp"
|
||||
)
|
||||
|
||||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
|
||||
# insert other things like install cmds etc here
|
||||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
|
||||
@@ -0,0 +1,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright chargebyte GmbH
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "DCSupplySimulator.hpp"
|
||||
|
||||
namespace module {
|
||||
|
||||
void DCSupplySimulator::init() {
|
||||
invoke_init(*p_main);
|
||||
invoke_init(*p_powermeter);
|
||||
}
|
||||
|
||||
void DCSupplySimulator::ready() {
|
||||
invoke_ready(*p_main);
|
||||
invoke_ready(*p_powermeter);
|
||||
}
|
||||
|
||||
} // namespace module
|
||||
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright chargebyte GmbH and Contributors to EVerest
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef DCSUPPLY_SIMULATOR_HPP
|
||||
#define DCSUPPLY_SIMULATOR_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 2
|
||||
//
|
||||
|
||||
#include "ld-ev.hpp"
|
||||
|
||||
// headers for provided interface implementations
|
||||
#include <generated/interfaces/power_supply_DC/Implementation.hpp>
|
||||
#include <generated/interfaces/powermeter/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 DCSupplySimulator : public Everest::ModuleBase {
|
||||
public:
|
||||
DCSupplySimulator() = delete;
|
||||
DCSupplySimulator(const ModuleInfo& info, std::unique_ptr<power_supply_DCImplBase> p_main,
|
||||
std::unique_ptr<powermeterImplBase> p_powermeter, Conf& config) :
|
||||
ModuleBase(info), p_main(std::move(p_main)), p_powermeter(std::move(p_powermeter)), config(config){};
|
||||
|
||||
const std::unique_ptr<power_supply_DCImplBase> p_main;
|
||||
const std::unique_ptr<powermeterImplBase> p_powermeter;
|
||||
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 // DCSUPPLY_SIMULATOR_HPP
|
||||
@@ -0,0 +1,165 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright chargebyte GmbH
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
|
||||
#include "power_supply_DCImpl.hpp"
|
||||
|
||||
namespace module {
|
||||
namespace main {
|
||||
|
||||
void power_supply_DCImpl::init() {
|
||||
connector_voltage = 0.0;
|
||||
connector_current = 0.0;
|
||||
energy_import_total = 0.0;
|
||||
energy_export_total = 0.0;
|
||||
|
||||
power_supply_thread_handle = std::thread(&power_supply_DCImpl::power_supply_worker, this);
|
||||
}
|
||||
|
||||
static auto get_capabilities_from_config(const Conf& config) {
|
||||
types::power_supply_DC::Capabilities cap;
|
||||
|
||||
cap.bidirectional = config.bidirectional;
|
||||
cap.current_regulation_tolerance_A = 2.0f;
|
||||
cap.peak_current_ripple_A = 2.0f;
|
||||
cap.max_export_voltage_V = static_cast<float>(config.max_voltage);
|
||||
cap.min_export_voltage_V = static_cast<float>(config.min_voltage);
|
||||
cap.max_export_current_A = static_cast<float>(config.max_current);
|
||||
cap.min_export_current_A = static_cast<float>(config.min_current);
|
||||
cap.max_export_power_W = static_cast<float>(config.max_power);
|
||||
cap.nominal_max_export_voltage_V = static_cast<float>(config.nominal_max_voltage);
|
||||
cap.nominal_min_export_voltage_V = static_cast<float>(config.nominal_min_voltage);
|
||||
cap.nominal_max_export_current_A = static_cast<float>(config.nominal_max_current);
|
||||
cap.nominal_min_export_current_A = static_cast<float>(config.nominal_min_current);
|
||||
cap.nominal_max_export_power_W = static_cast<float>(config.nominal_max_export_power);
|
||||
cap.max_import_voltage_V = static_cast<float>(config.max_voltage);
|
||||
cap.min_import_voltage_V = static_cast<float>(config.min_voltage);
|
||||
cap.max_import_current_A = static_cast<float>(config.max_current);
|
||||
cap.min_import_current_A = static_cast<float>(config.min_current);
|
||||
cap.max_import_power_W = static_cast<float>(config.max_power);
|
||||
cap.nominal_max_import_voltage_V = static_cast<float>(config.nominal_max_voltage);
|
||||
cap.nominal_min_import_voltage_V = static_cast<float>(config.nominal_min_voltage);
|
||||
cap.nominal_max_import_current_A = static_cast<float>(config.nominal_max_current);
|
||||
cap.nominal_min_import_current_A = static_cast<float>(config.nominal_min_current);
|
||||
cap.nominal_max_import_power_W = static_cast<float>(config.nominal_max_import_power);
|
||||
cap.conversion_efficiency_import = 0.85f;
|
||||
cap.conversion_efficiency_export = 0.9f;
|
||||
|
||||
return cap;
|
||||
}
|
||||
|
||||
void power_supply_DCImpl::ready() {
|
||||
publish_capabilities(get_capabilities_from_config(config));
|
||||
}
|
||||
|
||||
void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& _mode,
|
||||
types::power_supply_DC::ChargingPhase& phase) {
|
||||
mode = _mode;
|
||||
|
||||
EVLOG_info << "Set mode: " << types::power_supply_DC::mode_to_string(mode)
|
||||
<< " ChargingPhase: " << types::power_supply_DC::charging_phase_to_string(phase);
|
||||
|
||||
std::scoped_lock access_lock(power_supply_values_mutex);
|
||||
if ((mode == types::power_supply_DC::Mode::Off) || (mode == types::power_supply_DC::Mode::Fault)) {
|
||||
connector_voltage = 0.0;
|
||||
connector_current = 0.0;
|
||||
} else if (mode == types::power_supply_DC::Mode::Export) {
|
||||
connector_voltage = settings_connector_export_voltage;
|
||||
connector_current = settings_connector_max_export_current;
|
||||
} else if (mode == types::power_supply_DC::Mode::Import) {
|
||||
connector_voltage = settings_connector_import_voltage;
|
||||
connector_current = settings_connector_max_import_current;
|
||||
}
|
||||
|
||||
mod->p_main->publish_mode(mode);
|
||||
}
|
||||
|
||||
void power_supply_DCImpl::clampVoltageCurrent(double& voltage, double& current) {
|
||||
voltage = voltage < config.min_voltage ? config.min_voltage
|
||||
: voltage > config.max_voltage ? config.max_voltage
|
||||
: voltage;
|
||||
|
||||
current = current < config.min_current ? config.min_current
|
||||
: current > config.max_current ? config.max_current
|
||||
: current;
|
||||
}
|
||||
|
||||
void power_supply_DCImpl::handle_setExportVoltageCurrent(double& voltage, double& current) {
|
||||
double temp_voltage = voltage;
|
||||
double temp_current = current;
|
||||
|
||||
clampVoltageCurrent(temp_voltage, temp_current);
|
||||
|
||||
std::scoped_lock access_lock(power_supply_values_mutex);
|
||||
settings_connector_export_voltage = temp_voltage;
|
||||
settings_connector_max_export_current = temp_current;
|
||||
|
||||
if (mode == types::power_supply_DC::Mode::Export) {
|
||||
connector_voltage = settings_connector_export_voltage;
|
||||
connector_current = settings_connector_max_export_current;
|
||||
}
|
||||
}
|
||||
|
||||
void power_supply_DCImpl::handle_setImportVoltageCurrent(double& voltage, double& current) {
|
||||
double temp_voltage = voltage;
|
||||
double temp_current = current;
|
||||
|
||||
clampVoltageCurrent(temp_voltage, temp_current);
|
||||
|
||||
std::scoped_lock access_lock(power_supply_values_mutex);
|
||||
settings_connector_import_voltage = temp_voltage;
|
||||
settings_connector_max_import_current = temp_current;
|
||||
|
||||
if (mode == types::power_supply_DC::Mode::Import) {
|
||||
connector_voltage = settings_connector_import_voltage;
|
||||
connector_current = -settings_connector_max_import_current;
|
||||
}
|
||||
}
|
||||
|
||||
types::powermeter::Powermeter power_supply_DCImpl::power_meter_external() {
|
||||
types::powermeter::Powermeter powermeter;
|
||||
|
||||
powermeter.timestamp = Everest::Date::to_rfc3339(date::utc_clock::now());
|
||||
powermeter.meter_id = "DC_POWERMETER";
|
||||
|
||||
if (connector_current > 0) {
|
||||
energy_import_total += (connector_voltage * connector_current * LOOP_SLEEP_MS / 1000) / 3600;
|
||||
}
|
||||
if (connector_current < 0) {
|
||||
energy_export_total += (connector_voltage * -connector_current * LOOP_SLEEP_MS / 1000) / 3600;
|
||||
}
|
||||
|
||||
powermeter.energy_Wh_import = {static_cast<float>(energy_import_total)};
|
||||
powermeter.energy_Wh_export = {static_cast<float>(energy_export_total)};
|
||||
|
||||
powermeter.power_W = {static_cast<float>(connector_current * connector_voltage)};
|
||||
powermeter.current_A = {static_cast<float>(connector_current)};
|
||||
powermeter.voltage_V = {static_cast<float>(connector_voltage)};
|
||||
|
||||
return powermeter;
|
||||
}
|
||||
|
||||
void power_supply_DCImpl::power_supply_worker(void) {
|
||||
types::power_supply_DC::VoltageCurrent voltage_current;
|
||||
|
||||
while (true) {
|
||||
if (power_supply_thread_handle.shouldExit()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// set interval for publishing
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(LOOP_SLEEP_MS));
|
||||
|
||||
std::scoped_lock access_lock(power_supply_values_mutex);
|
||||
voltage_current.voltage_V = static_cast<float>(connector_voltage);
|
||||
voltage_current.current_A = static_cast<float>(connector_current);
|
||||
|
||||
mod->p_main->publish_voltage_current(voltage_current);
|
||||
mod->p_powermeter->publish_powermeter(power_meter_external());
|
||||
}
|
||||
}
|
||||
} // namespace main
|
||||
} // namespace module
|
||||
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright chargebyte GmbH and Contributors to EVerest
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef MAIN_POWER_SUPPLY_DC_IMPL_HPP
|
||||
#define MAIN_POWER_SUPPLY_DC_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/power_supply_DC/Implementation.hpp>
|
||||
|
||||
#include "../DCSupplySimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
#include <mutex>
|
||||
#include <utils/thread.hpp>
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace main {
|
||||
|
||||
struct Conf {
|
||||
bool bidirectional;
|
||||
double max_power;
|
||||
double nominal_max_export_power;
|
||||
double nominal_max_import_power;
|
||||
double min_voltage;
|
||||
double max_voltage;
|
||||
double nominal_min_voltage;
|
||||
double nominal_max_voltage;
|
||||
double min_current;
|
||||
double max_current;
|
||||
double nominal_min_current;
|
||||
double nominal_max_current;
|
||||
};
|
||||
|
||||
class power_supply_DCImpl : public power_supply_DCImplBase {
|
||||
public:
|
||||
power_supply_DCImpl() = delete;
|
||||
power_supply_DCImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<DCSupplySimulator>& mod, Conf& config) :
|
||||
power_supply_DCImplBase(ev, "main"), mod(mod), config(config){};
|
||||
|
||||
// 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_setMode(types::power_supply_DC::Mode& mode,
|
||||
types::power_supply_DC::ChargingPhase& phase) override;
|
||||
virtual void handle_setExportVoltageCurrent(double& voltage, double& current) override;
|
||||
virtual void handle_setImportVoltageCurrent(double& voltage, double& current) override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<DCSupplySimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
double settings_connector_export_voltage{0.0};
|
||||
double settings_connector_import_voltage{0.0};
|
||||
double settings_connector_max_export_current{0.0};
|
||||
double settings_connector_max_import_current{0.0};
|
||||
types::power_supply_DC::Mode mode{types::power_supply_DC::Mode::Off};
|
||||
double connector_voltage{0.0};
|
||||
double connector_current{0.0};
|
||||
double energy_import_total{0.0};
|
||||
double energy_export_total{0.0};
|
||||
std::mutex power_supply_values_mutex;
|
||||
Everest::Thread power_supply_thread_handle;
|
||||
types::powermeter::Powermeter power_meter_external();
|
||||
void power_supply_worker(void);
|
||||
|
||||
static constexpr int LOOP_SLEEP_MS{500};
|
||||
void clampVoltageCurrent(double& voltage, double& current);
|
||||
// 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_POWER_SUPPLY_DC_IMPL_HPP
|
||||
@@ -0,0 +1,64 @@
|
||||
description: Implementation of a programmable power supply for DC charging
|
||||
provides:
|
||||
main:
|
||||
interface: power_supply_DC
|
||||
description: Main interface for the power supply
|
||||
config:
|
||||
bidirectional:
|
||||
description: Set to true for bidirectional supply
|
||||
type: boolean
|
||||
default: true
|
||||
max_power:
|
||||
description: Max supported power in watt
|
||||
type: number
|
||||
default: 150000
|
||||
nominal_max_export_power:
|
||||
description: Nominal max export power in watt
|
||||
type: number
|
||||
default: 150000
|
||||
nominal_max_import_power:
|
||||
description: Nominal max import power in watt
|
||||
type: number
|
||||
default: 150000
|
||||
min_voltage:
|
||||
description: Min supported voltage
|
||||
type: number
|
||||
default: 200.0
|
||||
max_voltage:
|
||||
description: Max supported voltage
|
||||
type: number
|
||||
default: 900.0
|
||||
nominal_min_voltage:
|
||||
description: Nominal min supported voltage
|
||||
type: number
|
||||
default: 200.0
|
||||
nominal_max_voltage:
|
||||
description: Nominal max supported voltage
|
||||
type: number
|
||||
default: 900.0
|
||||
min_current:
|
||||
description: Min supported current
|
||||
type: number
|
||||
default: 1.0
|
||||
max_current:
|
||||
description: Max supported current
|
||||
type: number
|
||||
default: 200.0
|
||||
nominal_min_current:
|
||||
description: Nominal min supported current
|
||||
type: number
|
||||
default: 1.0
|
||||
nominal_max_current:
|
||||
description: Nominal max supported current
|
||||
type: number
|
||||
default: 200.0
|
||||
powermeter:
|
||||
interface: powermeter
|
||||
description: Power meter interface for simulation
|
||||
metadata:
|
||||
license: https://opensource.org/licenses/Apache-2.0
|
||||
authors:
|
||||
- Cornelius Claussen (Pionix GmbH)
|
||||
- Fabian Hartung (chargebyte GmbH)
|
||||
- Mohannad Oraby (chargebyte GmbH)
|
||||
- Sebastian Lukas (Pionix GmbH)
|
||||
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "powermeterImpl.hpp"
|
||||
|
||||
namespace module {
|
||||
namespace powermeter {
|
||||
|
||||
void powermeterImpl::init() {
|
||||
}
|
||||
|
||||
void powermeterImpl::ready() {
|
||||
}
|
||||
|
||||
types::powermeter::TransactionStartResponse
|
||||
powermeterImpl::handle_start_transaction(types::powermeter::TransactionReq& value) {
|
||||
return {types::powermeter::TransactionRequestStatus::NOT_SUPPORTED,
|
||||
"DcSupplySimulator does not support start transaction request."};
|
||||
}
|
||||
|
||||
types::powermeter::TransactionStopResponse powermeterImpl::handle_stop_transaction(std::string& transaction_id) {
|
||||
return {types::powermeter::TransactionRequestStatus::NOT_SUPPORTED,
|
||||
{},
|
||||
{},
|
||||
"DcSupplySimulator does not support stop transaction request."};
|
||||
}
|
||||
|
||||
} // namespace powermeter
|
||||
} // namespace module
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef POWERMETER_POWERMETER_IMPL_HPP
|
||||
#define POWERMETER_POWERMETER_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/powermeter/Implementation.hpp>
|
||||
|
||||
#include "../DCSupplySimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace powermeter {
|
||||
|
||||
struct Conf {};
|
||||
|
||||
class powermeterImpl : public powermeterImplBase {
|
||||
public:
|
||||
powermeterImpl() = delete;
|
||||
powermeterImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<DCSupplySimulator>& mod, Conf& config) :
|
||||
powermeterImplBase(ev, "powermeter"), mod(mod), config(config){};
|
||||
|
||||
// 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 types::powermeter::TransactionStartResponse
|
||||
handle_start_transaction(types::powermeter::TransactionReq& value) override;
|
||||
virtual types::powermeter::TransactionStopResponse handle_stop_transaction(std::string& transaction_id) override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<DCSupplySimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
// 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 powermeter
|
||||
} // namespace module
|
||||
|
||||
#endif // POWERMETER_POWERMETER_IMPL_HPP
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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, Everest::MqttProvider& mqtt_provider,
|
||||
std::unique_ptr<isolation_monitorImplBase> p_main, Conf& config) :
|
||||
ModuleBase(info), mqtt(mqtt_provider), p_main(std::move(p_main)), config(config){};
|
||||
|
||||
Everest::MqttProvider& mqtt;
|
||||
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
|
||||
@@ -0,0 +1,15 @@
|
||||
.. _everest_modules_handwritten_IMDSimulator:
|
||||
|
||||
.. ############
|
||||
.. IMDSimulator
|
||||
.. ############
|
||||
|
||||
External MQTT Control
|
||||
=====================
|
||||
|
||||
The IMDSimulator module supports setting the simulated isolation resistance via MQTT.
|
||||
To set the resistance, publish an integer value (in Ohms) to the following topic:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
everest_api/<module_id>/cmd/set_resistance
|
||||
@@ -0,0 +1,75 @@
|
||||
// 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);
|
||||
|
||||
const std::string RESISTANCE_TOPIC = "everest_api/" + this->mod->info.id + "/cmd/set_resistance";
|
||||
this->mod->mqtt.subscribe(RESISTANCE_TOPIC, [this](const std::string& resistance_ohm) {
|
||||
try {
|
||||
int32_t _resistance_ohm = std::stoi(resistance_ohm);
|
||||
EVLOG_info << "Setting simulated isolation resistance to " << _resistance_ohm << " Ohm via MQTT";
|
||||
this->isolation_measurement.resistance_F_Ohm = _resistance_ohm;
|
||||
} catch (const std::invalid_argument& e) {
|
||||
EVLOG_error << "Failed to set isolation resistance via MQTT, invalid value: " << resistance_ohm;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void isolation_monitorImpl::ready() {
|
||||
}
|
||||
|
||||
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::handle_start_self_test(double& test_voltage_V) {
|
||||
selftest_running_countdown = 3 * 1000 / LOOP_SLEEP_MS;
|
||||
}
|
||||
|
||||
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_isolation_measurement(this->isolation_measurement);
|
||||
EVLOG_debug << "Simulated isolation measurement finished";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(this->config_interval - this->LOOP_SLEEP_MS));
|
||||
}
|
||||
|
||||
if (this->selftest_running_countdown > 0) {
|
||||
this->selftest_running_countdown--;
|
||||
if (this->selftest_running_countdown == 0) {
|
||||
this->mod->p_main->publish_self_test_result(config.selftest_success);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -0,0 +1,81 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright (C) 2023 chargebyte GmbH
|
||||
// Copyright (C) 2023 Contributors to EVerest
|
||||
// Copyright (C) 2024 Pionix GmbH
|
||||
#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;
|
||||
int interval;
|
||||
bool selftest_success;
|
||||
};
|
||||
|
||||
class isolation_monitorImpl : public isolation_monitorImplBase {
|
||||
public:
|
||||
isolation_monitorImpl() = delete;
|
||||
isolation_monitorImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<IMDSimulator>& mod, Conf& config) :
|
||||
isolation_monitorImplBase(ev, "main"), mod(mod), config(config){};
|
||||
|
||||
// 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;
|
||||
virtual void handle_start_self_test(double& test_voltage_V) 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;
|
||||
static constexpr int LOOP_SLEEP_MS{20};
|
||||
|
||||
Everest::Thread isolation_measurement_thread_handle;
|
||||
void isolation_measurement_worker(void);
|
||||
|
||||
std::atomic_int selftest_running_countdown{0};
|
||||
// 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
|
||||
@@ -0,0 +1,24 @@
|
||||
description: SIL Implementation of an Isolation Monitoring Device (IMD) for DC charging
|
||||
provides:
|
||||
main:
|
||||
interface: isolation_monitor
|
||||
description: Main interface for the IMD
|
||||
config:
|
||||
resistance_F_Ohm:
|
||||
description: Resistance to return for the simulated measurements in Ohm
|
||||
type: number
|
||||
default: 900000
|
||||
interval:
|
||||
description: Measurement update interval in milliseconds
|
||||
type: integer
|
||||
default: 1000
|
||||
selftest_success:
|
||||
description: Set to true for successful self testing, false for fault
|
||||
type: boolean
|
||||
default: true
|
||||
enable_external_mqtt: true
|
||||
metadata:
|
||||
license: https://opensource.org/licenses/Apache-2.0
|
||||
authors:
|
||||
- Fabian Hartung (chargebyte GmbH)
|
||||
- Cornelius Claussen (Pionix GmbH)
|
||||
@@ -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/over_voltage_monitorImpl.cpp"
|
||||
)
|
||||
|
||||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
|
||||
# insert other things like install cmds etc here
|
||||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
|
||||
@@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include "OVMSimulator.hpp"
|
||||
|
||||
namespace module {
|
||||
|
||||
void OVMSimulator::init() {
|
||||
invoke_init(*p_main);
|
||||
}
|
||||
|
||||
void OVMSimulator::ready() {
|
||||
invoke_ready(*p_main);
|
||||
}
|
||||
|
||||
} // namespace module
|
||||
@@ -0,0 +1,69 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef OVMSIMULATOR_HPP
|
||||
#define OVMSIMULATOR_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 2
|
||||
//
|
||||
|
||||
#include "ld-ev.hpp"
|
||||
|
||||
// headers for provided interface implementations
|
||||
#include <generated/interfaces/over_voltage_monitor/Implementation.hpp>
|
||||
|
||||
// headers for required interface implementations
|
||||
#include <generated/interfaces/power_supply_DC/Interface.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 OVMSimulator : public Everest::ModuleBase {
|
||||
public:
|
||||
OVMSimulator() = delete;
|
||||
OVMSimulator(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider,
|
||||
std::unique_ptr<over_voltage_monitorImplBase> p_main,
|
||||
std::vector<std::unique_ptr<power_supply_DCIntf>> r_power_supply, Conf& config) :
|
||||
ModuleBase(info),
|
||||
mqtt(mqtt_provider),
|
||||
p_main(std::move(p_main)),
|
||||
r_power_supply(std::move(r_power_supply)),
|
||||
config(config){};
|
||||
|
||||
Everest::MqttProvider& mqtt;
|
||||
const std::unique_ptr<over_voltage_monitorImplBase> p_main;
|
||||
const std::vector<std::unique_ptr<power_supply_DCIntf>> r_power_supply;
|
||||
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 // OVMSIMULATOR_HPP
|
||||
@@ -0,0 +1,93 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "over_voltage_monitorImpl.hpp"
|
||||
|
||||
namespace module {
|
||||
namespace main {
|
||||
|
||||
void over_voltage_monitorImpl::init() {
|
||||
over_voltage_monitoring_active = false;
|
||||
over_voltage_monitorImpl_thread_handle =
|
||||
std::thread(&over_voltage_monitorImpl::over_voltage_monitorImpl_worker, this);
|
||||
const std::string OVER_VOLTAGE_TOPIC = "everest_api/" + this->mod->info.id + "/cmd/set_over_voltage_measurement_V";
|
||||
EVLOG_info << "Can control the over voltage measurement values over the topic: " << OVER_VOLTAGE_TOPIC
|
||||
<< " via MQTT";
|
||||
this->mod->mqtt.subscribe(OVER_VOLTAGE_TOPIC, [this](const std::string& over_voltage_measurement_V) {
|
||||
try {
|
||||
EVLOG_info << "Setting simulated over voltage measurement to " << over_voltage_measurement_V
|
||||
<< " V via MQTT";
|
||||
voltage_measurement_V = std::stof(over_voltage_measurement_V);
|
||||
} catch (const std::invalid_argument& e) {
|
||||
EVLOG_error << "Failed to set over voltage measurement via MQTT, invalid value: "
|
||||
<< over_voltage_measurement_V;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void over_voltage_monitorImpl::ready() {
|
||||
if (!this->mod->r_power_supply.empty() && this->mod->r_power_supply[0]) {
|
||||
this->mod->r_power_supply[0]->subscribe_voltage_current(
|
||||
[this](types::power_supply_DC::VoltageCurrent measurement) {
|
||||
this->voltage_measurement_V = static_cast<float>(measurement.voltage_V);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void over_voltage_monitorImpl::handle_set_limits(double& emergency_over_voltage_limit_V,
|
||||
double& error_over_voltage_limit_V) {
|
||||
error_threshold = error_over_voltage_limit_V;
|
||||
emergency_threshold = emergency_over_voltage_limit_V;
|
||||
}
|
||||
|
||||
void over_voltage_monitorImpl::handle_start() {
|
||||
EVLOG_info << "Over voltage monitoring: starting with " << emergency_threshold << " (emergency) and "
|
||||
<< error_threshold << "(error)";
|
||||
over_voltage_monitoring_active = true;
|
||||
if (config.simulate_error_shutdown) {
|
||||
std::thread([this]() {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(config.simulate_error_delay));
|
||||
auto err = error_factory->create_error("over_voltage_monitor/MREC5OverVoltage", "",
|
||||
"Simulated Over voltage error shutdown occurred.",
|
||||
Everest::error::Severity::Medium);
|
||||
raise_error(err);
|
||||
}).detach();
|
||||
}
|
||||
|
||||
if (config.simulate_emergency_shutdown) {
|
||||
std::thread([this]() {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(config.simulate_error_delay));
|
||||
auto err = error_factory->create_error("over_voltage_monitor/MREC5OverVoltage", "",
|
||||
"Simulated Over voltage emergency shutdown occurred.",
|
||||
Everest::error::Severity::High);
|
||||
raise_error(err);
|
||||
}).detach();
|
||||
}
|
||||
}
|
||||
|
||||
void over_voltage_monitorImpl::over_voltage_monitorImpl_worker() {
|
||||
while (true) {
|
||||
if (this->over_voltage_monitorImpl_thread_handle.shouldExit()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->over_voltage_monitoring_active == true) {
|
||||
this->mod->p_main->publish_voltage_measurement_V(this->voltage_measurement_V);
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(this->LOOP_SLEEP_MS));
|
||||
}
|
||||
}
|
||||
|
||||
void over_voltage_monitorImpl::handle_stop() {
|
||||
EVLOG_info << "Over voltage monitoring: stopped.";
|
||||
over_voltage_monitoring_active = false;
|
||||
}
|
||||
|
||||
void over_voltage_monitorImpl::handle_reset_over_voltage_error() {
|
||||
EVLOG_info << "Over voltage monitoring: reset";
|
||||
clear_all_errors_of_impl("over_voltage_monitor/MREC5OverVoltage");
|
||||
}
|
||||
|
||||
} // namespace main
|
||||
} // namespace module
|
||||
@@ -0,0 +1,78 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef MAIN_OVER_VOLTAGE_MONITOR_IMPL_HPP
|
||||
#define MAIN_OVER_VOLTAGE_MONITOR_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/over_voltage_monitor/Implementation.hpp>
|
||||
|
||||
#include "../OVMSimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
#include <atomic>
|
||||
#include <utils/thread.hpp>
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace main {
|
||||
|
||||
struct Conf {
|
||||
bool simulate_error_shutdown;
|
||||
bool simulate_emergency_shutdown;
|
||||
int simulate_error_delay;
|
||||
};
|
||||
|
||||
class over_voltage_monitorImpl : public over_voltage_monitorImplBase {
|
||||
public:
|
||||
over_voltage_monitorImpl() = delete;
|
||||
over_voltage_monitorImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<OVMSimulator>& mod, Conf& config) :
|
||||
over_voltage_monitorImplBase(ev, "main"), mod(mod), config(config){};
|
||||
|
||||
// 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_set_limits(double& emergency_over_voltage_limit_V, double& error_over_voltage_limit_V) override;
|
||||
virtual void handle_start() override;
|
||||
virtual void handle_stop() override;
|
||||
virtual void handle_reset_over_voltage_error() override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<OVMSimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
double error_threshold{0.};
|
||||
double emergency_threshold{0.};
|
||||
|
||||
static constexpr int LOOP_SLEEP_MS{20};
|
||||
std::atomic<bool> over_voltage_monitoring_active;
|
||||
float voltage_measurement_V{0.0f};
|
||||
Everest::Thread over_voltage_monitorImpl_thread_handle;
|
||||
void over_voltage_monitorImpl_worker();
|
||||
// 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_OVER_VOLTAGE_MONITOR_IMPL_HPP
|
||||
@@ -0,0 +1,28 @@
|
||||
description: SIL Implementation of an Over voltage monitor for DC charging
|
||||
provides:
|
||||
main:
|
||||
interface: over_voltage_monitor
|
||||
description: Main interface for the OVM
|
||||
config:
|
||||
simulate_error_shutdown:
|
||||
description: Set to true to simulate an error shutdown during charging
|
||||
type: boolean
|
||||
default: false
|
||||
simulate_emergency_shutdown:
|
||||
description: Set to true to simulate an emergency shutdown during charging
|
||||
type: boolean
|
||||
default: false
|
||||
simulate_error_delay:
|
||||
description: Simulate over voltage error N seconds after start of charging
|
||||
type: integer
|
||||
default: 5
|
||||
requires:
|
||||
power_supply:
|
||||
interface: power_supply_DC
|
||||
min_connections: 0
|
||||
max_connections: 1
|
||||
enable_external_mqtt: true
|
||||
metadata:
|
||||
license: https://opensource.org/licenses/Apache-2.0
|
||||
authors:
|
||||
- Cornelius Claussen (Pionix GmbH)
|
||||
1
tools/EVerest-main/modules/Simulation/README.md
Normal file
1
tools/EVerest-main/modules/Simulation/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Simulation modules
|
||||
@@ -0,0 +1,9 @@
|
||||
load("//modules:module.bzl", "cc_everest_module")
|
||||
|
||||
cc_everest_module(
|
||||
name = "SlacSimulator",
|
||||
impls = [
|
||||
"ev",
|
||||
"evse",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# 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
|
||||
target_compile_options(${MODULE_NAME}
|
||||
PRIVATE
|
||||
-Wimplicit-fallthrough
|
||||
-Werror=switch-enum
|
||||
)
|
||||
# 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
|
||||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
|
||||
@@ -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 State = types::slac::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
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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
|
||||
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
|
||||
|
||||
namespace module {
|
||||
|
||||
struct Conf {};
|
||||
|
||||
class SlacSimulator : public Everest::ModuleBase {
|
||||
public:
|
||||
SlacSimulator() = delete;
|
||||
SlacSimulator(const ModuleInfo& info, std::unique_ptr<slacImplBase> p_evse, std::unique_ptr<ev_slacImplBase> p_ev,
|
||||
Conf& config) :
|
||||
ModuleBase(info), p_evse(std::move(p_evse)), p_ev(std::move(p_ev)), config(config){};
|
||||
|
||||
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
|
||||
@@ -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 types::slac::State;
|
||||
|
||||
void ev_slacImpl::init() {
|
||||
}
|
||||
|
||||
void ev_slacImpl::ready() {
|
||||
publish_state(state);
|
||||
}
|
||||
|
||||
void ev_slacImpl::handle_reset() {
|
||||
if (state != State::UNMATCHED) {
|
||||
state = State::UNMATCHED;
|
||||
publish_state(state);
|
||||
publish_dlink_ready(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool ev_slacImpl::handle_trigger_matching() {
|
||||
state = State::MATCHING;
|
||||
mod->cntmatching = 0;
|
||||
publish_state(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
State ev_slacImpl::get_state() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
void ev_slacImpl::set_state_matched() {
|
||||
state = State::MATCHED;
|
||||
publish_state(state);
|
||||
publish_dlink_ready(true);
|
||||
}
|
||||
|
||||
} // namespace ev
|
||||
} // namespace module
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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
|
||||
// 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
|
||||
types::slac::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
|
||||
types::slac::State state{types::slac::State::UNMATCHED};
|
||||
// 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
|
||||
@@ -0,0 +1,66 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "slacImpl.hpp"
|
||||
|
||||
namespace module {
|
||||
namespace evse {
|
||||
|
||||
using types::slac::State;
|
||||
|
||||
void slacImpl::init() {
|
||||
}
|
||||
|
||||
void slacImpl::ready() {
|
||||
publish_state(state);
|
||||
}
|
||||
|
||||
void slacImpl::handle_reset(bool& enable) {
|
||||
set_state_to_unmatched();
|
||||
}
|
||||
|
||||
void slacImpl::handle_enter_bcd() {
|
||||
set_state_to_matching();
|
||||
}
|
||||
|
||||
void slacImpl::handle_leave_bcd() {
|
||||
set_state_to_unmatched();
|
||||
}
|
||||
|
||||
void slacImpl::handle_dlink_terminate() {
|
||||
set_state_to_unmatched();
|
||||
}
|
||||
|
||||
void slacImpl::handle_dlink_error() {
|
||||
set_state_to_unmatched();
|
||||
}
|
||||
|
||||
void slacImpl::handle_dlink_pause() {
|
||||
// No action needed for D-LINK_PAUSE in simulation
|
||||
}
|
||||
|
||||
void slacImpl::set_state_to_unmatched() {
|
||||
if (state != State::UNMATCHED) {
|
||||
state = State::UNMATCHED;
|
||||
publish_state(state);
|
||||
publish_dlink_ready(false);
|
||||
}
|
||||
}
|
||||
|
||||
void slacImpl::set_state_to_matching() {
|
||||
state = State::MATCHING;
|
||||
mod->cntmatching = 0;
|
||||
publish_state(state);
|
||||
}
|
||||
|
||||
State slacImpl::get_state() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
void slacImpl::set_state_matched() {
|
||||
state = State::MATCHED;
|
||||
publish_state(state);
|
||||
publish_dlink_ready(true);
|
||||
};
|
||||
} // namespace evse
|
||||
} // namespace module
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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 <generated/interfaces/slac/Implementation.hpp>
|
||||
|
||||
#include "../SlacSimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
// 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<SlacSimulator>& mod, Conf& config) :
|
||||
slacImplBase(ev, "evse"), mod(mod), config(config){};
|
||||
|
||||
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
|
||||
// insert your public definitions here
|
||||
types::slac::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 void handle_enter_bcd() override;
|
||||
virtual void handle_leave_bcd() override;
|
||||
virtual void handle_dlink_terminate() override;
|
||||
virtual void handle_dlink_error() override;
|
||||
virtual void 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<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
|
||||
void set_state_to_unmatched();
|
||||
void set_state_to_matching();
|
||||
|
||||
types::slac::State state{types::slac::State::UNMATCHED};
|
||||
// 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
|
||||
@@ -0,0 +1,13 @@
|
||||
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
|
||||
metadata:
|
||||
license: https://opensource.org/licenses/Apache-2.0
|
||||
authors:
|
||||
- Cornelius Claussen (Pionix GmbH)
|
||||
- Tobias Marzell (Pionix GmbH)
|
||||
@@ -0,0 +1,13 @@
|
||||
load("//modules:module.bzl", "cc_everest_module")
|
||||
|
||||
cc_everest_module(
|
||||
name = "YetiSimulator",
|
||||
impls = [
|
||||
"board_support",
|
||||
"connector_lock",
|
||||
"ev_board_support",
|
||||
"powermeter",
|
||||
"rcd",
|
||||
"util",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# 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
|
||||
"powermeter/powermeterImpl.cpp"
|
||||
"board_support/evse_board_supportImpl.cpp"
|
||||
"ev_board_support/ev_board_supportImpl.cpp"
|
||||
"rcd/ac_rcdImpl.cpp"
|
||||
"connector_lock/connector_lockImpl.cpp"
|
||||
)
|
||||
|
||||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
|
||||
# insert other things like install cmds etc here
|
||||
target_sources(${MODULE_NAME}
|
||||
PRIVATE
|
||||
"util/state.cpp"
|
||||
"util/errors.cpp"
|
||||
"util/util.cpp"
|
||||
)
|
||||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
|
||||
@@ -0,0 +1,760 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#include "board_support/evse_board_supportImpl.hpp"
|
||||
#include "util/state.hpp"
|
||||
#include "util/util.hpp"
|
||||
|
||||
#include "util/errors.hpp"
|
||||
|
||||
namespace module {
|
||||
|
||||
namespace {
|
||||
|
||||
types::powermeter::Powermeter power_meter_external(const state::PowermeterData& powermeter_data) {
|
||||
const auto current_iso_time_string = util::get_current_iso_time_string();
|
||||
const auto& [time_stamp, import_totalWattHr, export_totalWattHr, wattL1, vrmsL1, irmsL1, import_wattHrL1,
|
||||
export_wattHrL1, tempL1, freqL1, wattL2, vrmsL2, irmsL2, import_wattHrL2, export_wattHrL2, tempL2,
|
||||
freqL2, wattL3, vrmsL3, irmsL3, import_wattHrL3, export_wattHrL3, tempL3, freqL3, irmsN] =
|
||||
powermeter_data;
|
||||
|
||||
const std::vector<types::temperature::Temperature> temperatures = {
|
||||
{static_cast<float>(powermeter_data.tempL1), std::nullopt, "Body"}};
|
||||
|
||||
return {current_iso_time_string, // timestamp
|
||||
{
|
||||
static_cast<float>(import_totalWattHr),
|
||||
static_cast<float>(import_wattHrL1),
|
||||
static_cast<float>(import_wattHrL2),
|
||||
static_cast<float>(import_wattHrL3),
|
||||
}, // energy_Wh_import
|
||||
"YETI_POWERMETER", // meter_id
|
||||
false, // phase_seq_error
|
||||
std::make_optional<types::units::Energy>({
|
||||
static_cast<float>(export_totalWattHr),
|
||||
static_cast<float>(export_wattHrL1),
|
||||
static_cast<float>(export_wattHrL2),
|
||||
static_cast<float>(export_wattHrL3),
|
||||
}), // energy_Wh_export
|
||||
types::units::Power{
|
||||
static_cast<float>(wattL1 + wattL2 + wattL3),
|
||||
static_cast<float>(wattL1),
|
||||
static_cast<float>(wattL2),
|
||||
static_cast<float>(wattL3),
|
||||
}, // power_W
|
||||
types::units::Voltage{std::nullopt, vrmsL1, vrmsL2, vrmsL3}, // voltage_V
|
||||
std::nullopt, // VAR
|
||||
types::units::Current{std::nullopt, irmsL1, irmsL2, irmsL3, irmsN}, // current_A
|
||||
types::units::Frequency{static_cast<float>(freqL1), static_cast<float>(freqL2),
|
||||
static_cast<float>(freqL3)}, // frequency_Hz
|
||||
std::nullopt, // energy_Wh_import_signed
|
||||
std::nullopt, // energy_Wh_export_signed
|
||||
std::nullopt, // power_W_signed
|
||||
std::nullopt, // voltage_V_signed
|
||||
std::nullopt, // VAR_signed
|
||||
std::nullopt, // current_A_signed
|
||||
std::nullopt, // frequency_Hz_signed
|
||||
std::nullopt, // signed_meter_value
|
||||
temperatures}; // temperatures
|
||||
}
|
||||
|
||||
double duty_cycle_to_amps(const double dc) {
|
||||
if (dc < 8.0 / 100.0)
|
||||
return 0;
|
||||
if (dc < 85.0 / 100.0)
|
||||
return dc * 100.0 * 0.6;
|
||||
if (dc < 96.0 / 100.0)
|
||||
return (dc * 100.0 - 64) * 2.5;
|
||||
if (dc < 97.0 / 100.0)
|
||||
return 80;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool is_voltage_in_range(const double voltage, const double center) {
|
||||
constexpr auto interval = 1.1;
|
||||
return voltage > center - interval and voltage < center + interval;
|
||||
}
|
||||
|
||||
std::string event_to_string(state::State state) {
|
||||
using state::State;
|
||||
|
||||
switch (state) {
|
||||
case State::STATE_A:
|
||||
return "A";
|
||||
case State::STATE_B:
|
||||
return "B";
|
||||
case State::STATE_C:
|
||||
return "C";
|
||||
case State::STATE_D:
|
||||
return "D";
|
||||
case State::STATE_E:
|
||||
return "E";
|
||||
case State::STATE_F:
|
||||
return "F";
|
||||
case State::STATE_DISABLED:
|
||||
return "F";
|
||||
case State::Event_PowerOn:
|
||||
return "PowerOn";
|
||||
case State::Event_PowerOff:
|
||||
return "PowerOff";
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
types::board_support_common::BspEvent event_to_enum(state::State event) {
|
||||
using state::State;
|
||||
using types::board_support_common::Event;
|
||||
|
||||
switch (event) {
|
||||
case State::STATE_A:
|
||||
return {Event::A};
|
||||
case State::STATE_B:
|
||||
return {Event::B};
|
||||
case State::STATE_C:
|
||||
return {Event::C};
|
||||
case State::STATE_D:
|
||||
return {Event::D};
|
||||
case State::STATE_E:
|
||||
return {Event::E};
|
||||
case State::STATE_F:
|
||||
return {Event::F};
|
||||
case State::STATE_DISABLED:
|
||||
return {Event::F};
|
||||
case State::Event_PowerOn:
|
||||
return {Event::PowerOn};
|
||||
case State::Event_PowerOff:
|
||||
return {Event::PowerOff};
|
||||
default:
|
||||
EVLOG_error << "Invalid event : " << event_to_string(event);
|
||||
return {Event::F};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void YetiSimulator::init() {
|
||||
invoke_init(*p_powermeter);
|
||||
invoke_init(*p_board_support);
|
||||
invoke_init(*p_ev_board_support);
|
||||
invoke_init(*p_rcd);
|
||||
invoke_init(*p_connector_lock);
|
||||
|
||||
reset_module_state();
|
||||
|
||||
mqtt.subscribe(
|
||||
"everest_external/nodered/" + std::to_string(config.connector_id) + "/carsim/error",
|
||||
[this](const std::string& payload) {
|
||||
const auto [raise, error_definition] = parse_error_type(payload);
|
||||
|
||||
if (not error_definition.has_value()) {
|
||||
return;
|
||||
}
|
||||
if (error_definition->error_target == ErrorTarget::BoardSupport) {
|
||||
const auto error =
|
||||
p_board_support->error_factory->create_error(error_definition->type, error_definition->sub_type,
|
||||
error_definition->message, error_definition->severity);
|
||||
forward_error(p_board_support, error, raise);
|
||||
} else if (error_definition->error_target == ErrorTarget::ConnectorLock) {
|
||||
const auto error = p_connector_lock->error_factory->create_error(
|
||||
error_definition->type, error_definition->sub_type, error_definition->message,
|
||||
error_definition->severity);
|
||||
} else if (error_definition->error_target == ErrorTarget::Rcd) {
|
||||
const auto error =
|
||||
p_rcd->error_factory->create_error(error_definition->type, error_definition->sub_type,
|
||||
error_definition->message, error_definition->severity);
|
||||
} else if (error_definition->error_target == ErrorTarget::Powermeter) {
|
||||
const auto error =
|
||||
p_powermeter->error_factory->create_error(error_definition->type, error_definition->sub_type,
|
||||
error_definition->message, error_definition->severity);
|
||||
forward_error(p_powermeter, error, raise);
|
||||
} else {
|
||||
EVLOG_error << "No known ErrorTarget";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void YetiSimulator::ready() {
|
||||
invoke_ready(*p_powermeter);
|
||||
invoke_ready(*p_board_support);
|
||||
invoke_ready(*p_ev_board_support);
|
||||
invoke_ready(*p_rcd);
|
||||
invoke_ready(*p_connector_lock);
|
||||
|
||||
module_state->pubCnt = 0;
|
||||
|
||||
std::thread(&YetiSimulator::run_simulation, this, 250).detach();
|
||||
|
||||
if (info.telemetry_enabled) {
|
||||
std::thread(&YetiSimulator::run_telemetry_slow, this).detach();
|
||||
std::thread(&YetiSimulator::run_telemetry_fast, this).detach();
|
||||
}
|
||||
}
|
||||
|
||||
void YetiSimulator::run_telemetry_slow() const {
|
||||
|
||||
while (true) {
|
||||
const auto current_iso_time_string = util::get_current_iso_time_string();
|
||||
|
||||
auto& p_p_c_v = module_state->telemetry_data.power_path_controller_version;
|
||||
p_p_c_v.timestamp = current_iso_time_string;
|
||||
|
||||
telemetry.publish("livedata", "power_path_controller_version",
|
||||
{{"timestamp", p_p_c_v.timestamp},
|
||||
{"type", p_p_c_v.type},
|
||||
{"hardware_version", p_p_c_v.hardware_version},
|
||||
{"software_version", p_p_c_v.software_version},
|
||||
{"date_manufactured", p_p_c_v.date_manufactured},
|
||||
{"operating_time_h", p_p_c_v.operating_time_h},
|
||||
{"operating_time_warning", p_p_c_v.operating_time_h_warning},
|
||||
{"operating_time_error", p_p_c_v.operating_time_h_error},
|
||||
{"error", p_p_c_v.error}});
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{15000});
|
||||
}
|
||||
}
|
||||
|
||||
void YetiSimulator::run_telemetry_fast() const {
|
||||
|
||||
while (true) {
|
||||
const auto current_iso_time_string = util::get_current_iso_time_string();
|
||||
auto& p_p_c = module_state->telemetry_data.power_path_controller;
|
||||
p_p_c.timestamp = current_iso_time_string;
|
||||
p_p_c.cp_voltage_high = module_state->pwm_voltage_hi;
|
||||
p_p_c.cp_voltage_low = module_state->pwm_voltage_lo;
|
||||
p_p_c.cp_pwm_duty_cycle = module_state->pwm_duty_cycle * 100.0;
|
||||
p_p_c.cp_state = state_to_string(*module_state);
|
||||
|
||||
p_p_c.temperature_controller = module_state->powermeter_data.tempL1;
|
||||
p_p_c.temperature_car_connector = module_state->powermeter_data.tempL1 * 2.0;
|
||||
p_p_c.watchdog_reset_count = 0;
|
||||
p_p_c.error = false;
|
||||
|
||||
auto& p_s = module_state->telemetry_data.power_switch;
|
||||
p_s.timestamp = current_iso_time_string;
|
||||
p_s.is_on = module_state->relais_on;
|
||||
p_s.time_to_switch_on_ms = 110;
|
||||
p_s.time_to_switch_off_ms = 100;
|
||||
p_s.temperature_C = 20;
|
||||
p_s.error = false;
|
||||
p_s.error_over_current = false;
|
||||
|
||||
auto& rcd = module_state->telemetry_data.rcd;
|
||||
rcd.timestamp = current_iso_time_string;
|
||||
rcd.current_mA = module_state->simulation_data.rcd_current;
|
||||
|
||||
telemetry.publish("livedata", "power_path_controller",
|
||||
{{"timestamp", p_p_c.timestamp},
|
||||
{"type", p_p_c.type},
|
||||
{"cp_voltage_high", p_p_c.cp_voltage_high},
|
||||
{"cp_voltage_low", p_p_c.cp_voltage_low},
|
||||
{"cp_pwm_duty_cycle", p_p_c.cp_pwm_duty_cycle},
|
||||
{"cp_state", p_p_c.cp_state},
|
||||
{"pp_ohm", p_p_c.pp_ohm},
|
||||
{"supply_voltage_12V", p_p_c.supply_voltage_12V},
|
||||
{"supply_voltage_minus_12V", p_p_c.supply_voltage_minus_12V},
|
||||
{"temperature_controller", p_p_c.temperature_controller},
|
||||
{"temperature_car_connector", p_p_c.temperature_car_connector},
|
||||
{"watchdog_reset_count", p_p_c.watchdog_reset_count},
|
||||
{"error", p_p_c.error}});
|
||||
telemetry.publish("livedata", "power_switch",
|
||||
{{"timestamp", p_s.timestamp},
|
||||
{"type", p_s.type},
|
||||
{"switching_count", p_s.switching_count},
|
||||
{"switching_count_warning", p_s.switching_count_warning},
|
||||
{"switching_count_error", p_s.switching_count_error},
|
||||
{"is_on", p_s.is_on},
|
||||
{"time_to_switch_on_ms", p_s.time_to_switch_on_ms},
|
||||
{"time_to_switch_off_ms", p_s.time_to_switch_off_ms},
|
||||
{"temperature_C", p_s.temperature_C},
|
||||
{"error", p_s.error},
|
||||
{"error_over_current", p_s.error_over_current}});
|
||||
telemetry.publish("livedata", "rcd",
|
||||
{{"timestamp", rcd.timestamp},
|
||||
{"type", rcd.type},
|
||||
{"enabled", rcd.enabled},
|
||||
{"current_mA", rcd.current_mA},
|
||||
{"triggered", rcd.triggered},
|
||||
{"error", rcd.error}});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{1000});
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void YetiSimulator::run_simulation(const int sleep_time_ms) {
|
||||
while (true) {
|
||||
if (module_state->simulation_enabled) {
|
||||
simulation_step();
|
||||
}
|
||||
|
||||
module_state->pubCnt++;
|
||||
switch (module_state->pubCnt) {
|
||||
case 1:
|
||||
publish_powermeter();
|
||||
publish_telemetry();
|
||||
break;
|
||||
case 3:
|
||||
publish_keepalive();
|
||||
break;
|
||||
default:
|
||||
module_state->pubCnt = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{sleep_time_ms});
|
||||
}
|
||||
}
|
||||
|
||||
void YetiSimulator::simulation_step() {
|
||||
check_error_rcd();
|
||||
read_from_car();
|
||||
simulation_statemachine();
|
||||
add_noise();
|
||||
simulate_powermeter();
|
||||
publish_ev_board_support();
|
||||
}
|
||||
|
||||
void YetiSimulator::check_error_rcd() {
|
||||
using Everest::error::Severity;
|
||||
|
||||
const auto rcd_error = error_definitions::ac_rcd_DC;
|
||||
|
||||
if (module_state->simulation_data.rcd_current > 5.0) {
|
||||
if (not p_rcd->error_state_monitor->is_error_active(rcd_error.type, rcd_error.sub_type)) {
|
||||
const auto error = p_rcd->error_factory->create_error(rcd_error.type, rcd_error.sub_type, rcd_error.message,
|
||||
Severity::High);
|
||||
p_rcd->raise_error(error);
|
||||
}
|
||||
} else {
|
||||
if (p_rcd->error_state_monitor->is_error_active(rcd_error.type, rcd_error.sub_type)) {
|
||||
p_rcd->clear_error(rcd_error.type, rcd_error.sub_type);
|
||||
}
|
||||
}
|
||||
p_rcd->publish_rcd_current_mA(module_state->simulation_data.rcd_current);
|
||||
}
|
||||
|
||||
void YetiSimulator::read_from_car() {
|
||||
|
||||
const auto diode_fault = error_definitions::evse_board_support_DiodeFault;
|
||||
|
||||
double amps{0.0};
|
||||
|
||||
// 5% dutycycle: Getting current from HLC
|
||||
if (module_state->pwm_duty_cycle >= 0.03 and module_state->pwm_duty_cycle <= 0.07) {
|
||||
amps = module_state->ev_max_current;
|
||||
} else if (module_state->ev_max_current == 0.0) { // Basic charging: only pwm dutycycle
|
||||
amps = duty_cycle_to_amps(module_state->pwm_duty_cycle);
|
||||
} else { // Nominal dutycycle: Smallest amp between hlc and pwm dutycycle, ev_max_current can be negative
|
||||
amps = std::min(duty_cycle_to_amps(module_state->pwm_duty_cycle), std::fabs(module_state->ev_max_current));
|
||||
if (module_state->ev_max_current < 0) {
|
||||
amps = -amps;
|
||||
}
|
||||
}
|
||||
|
||||
const auto amps1 = (module_state->relais_on and module_state->ev_phases > 0) ? amps : 0.0;
|
||||
const auto amps2 =
|
||||
(module_state->relais_on and module_state->ev_phases > 1 and module_state->use_three_phases_confirmed) ? amps
|
||||
: 0.0;
|
||||
const auto amps3 =
|
||||
(module_state->relais_on and module_state->ev_phases > 2 and module_state->use_three_phases_confirmed) ? amps
|
||||
: 0.0;
|
||||
|
||||
if (module_state->pwm_running) {
|
||||
module_state->pwm_voltage_hi = module_state->simulation_data.cp_voltage;
|
||||
module_state->pwm_voltage_lo = -12.0;
|
||||
} else {
|
||||
module_state->pwm_voltage_hi = module_state->simulation_data.cp_voltage;
|
||||
module_state->pwm_voltage_lo = module_state->pwm_voltage_hi;
|
||||
}
|
||||
|
||||
if (module_state->pwm_error_f) {
|
||||
module_state->pwm_voltage_hi = -12.0;
|
||||
module_state->pwm_voltage_lo = -12.0;
|
||||
}
|
||||
if (module_state->simulation_data.error_e) {
|
||||
module_state->pwm_voltage_hi = 0.0;
|
||||
module_state->pwm_voltage_lo = 0.0;
|
||||
}
|
||||
if (module_state->simulation_data.diode_fail) {
|
||||
module_state->pwm_voltage_lo = -module_state->pwm_voltage_hi;
|
||||
}
|
||||
|
||||
const auto cpLo = module_state->pwm_voltage_lo;
|
||||
const auto cpHi = module_state->pwm_voltage_hi;
|
||||
|
||||
// sth is wrong with negative signal
|
||||
if (module_state->pwm_running and not is_voltage_in_range(cpLo, -12.0)) {
|
||||
// CP-PE short or signal somehow gone
|
||||
if (is_voltage_in_range(cpLo, 0.0) and is_voltage_in_range(cpHi, 0.0)) {
|
||||
module_state->current_state = state::State::STATE_E;
|
||||
drawPower(0, 0, 0, 0);
|
||||
} else if (is_voltage_in_range(cpHi + cpLo, 0.0)) { // Diode fault
|
||||
const auto error = p_board_support->error_factory->create_error(diode_fault.type, diode_fault.sub_type,
|
||||
diode_fault.message, diode_fault.severity);
|
||||
forward_error(p_board_support, error, true);
|
||||
|
||||
drawPower(0, 0, 0, 0);
|
||||
}
|
||||
} else if (is_voltage_in_range(cpHi, 12.0)) {
|
||||
// +12V State A IDLE (open circuit)
|
||||
// clear all errors that clear on disconnection
|
||||
if (p_board_support->error_state_monitor->is_error_active(diode_fault.type, diode_fault.sub_type)) {
|
||||
p_board_support->clear_error(diode_fault.type);
|
||||
}
|
||||
|
||||
module_state->current_state = state::State::STATE_A;
|
||||
drawPower(0, 0, 0, 0);
|
||||
} else if (is_voltage_in_range(cpHi, 9.0)) {
|
||||
module_state->current_state = state::State::STATE_B;
|
||||
drawPower(0, 0, 0, 0);
|
||||
} else if (is_voltage_in_range(cpHi, 6.0)) {
|
||||
module_state->current_state = state::State::STATE_C;
|
||||
drawPower(amps1, amps2, amps3, 0.2);
|
||||
} else if (is_voltage_in_range(cpHi, 3.0)) {
|
||||
module_state->current_state = state::State::STATE_D;
|
||||
drawPower(amps1, amps2, amps3, 0.2);
|
||||
} else if (is_voltage_in_range(cpHi, -12.0)) {
|
||||
module_state->current_state = state::State::STATE_F;
|
||||
drawPower(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void YetiSimulator::simulation_statemachine() {
|
||||
if (module_state->republish_state or module_state->last_state not_eq module_state->current_state) {
|
||||
publish_event(module_state->current_state);
|
||||
module_state->republish_state = false;
|
||||
}
|
||||
|
||||
switch (module_state->current_state) {
|
||||
case state::State::STATE_DISABLED:
|
||||
powerOff();
|
||||
module_state->power_on_allowed = false;
|
||||
break;
|
||||
|
||||
case state::State::STATE_A: {
|
||||
module_state->use_three_phases_confirmed = module_state->use_three_phases;
|
||||
cp_state_x1();
|
||||
module_state->simplified_mode = false;
|
||||
|
||||
if (module_state->last_state not_eq state::State::STATE_A and
|
||||
module_state->last_state not_eq state::State::STATE_DISABLED and
|
||||
module_state->last_state not_eq state::State::STATE_F) {
|
||||
powerOff();
|
||||
|
||||
// If car was unplugged, reset RCD flag.
|
||||
module_state->simdata_setting.rcd_current = 0.1;
|
||||
module_state->rcd_error = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case state::State::STATE_B:
|
||||
// Table A.6: Sequence 7 EV stops charging
|
||||
// Table A.6: Sequence 8.2 EV supply equipment
|
||||
// responds to EV opens S2 (w/o PWM)
|
||||
|
||||
if (module_state->last_state not_eq state::State::STATE_A and
|
||||
module_state->last_state not_eq state::State::STATE_B) {
|
||||
// Need to switch off according to Table A.6 Sequence 8.1 within
|
||||
powerOff();
|
||||
}
|
||||
|
||||
// Table A.6: Sequence 1.1 Plug-in
|
||||
if (module_state->last_state == state::State::STATE_A) {
|
||||
module_state->simplified_mode = false;
|
||||
// Fix a race-condition between resetting powermeter parameters and reporting powermeter to the EvseManager
|
||||
// back.
|
||||
// The EvseManager reports in the transaction_finished event the total charged kWh.
|
||||
// With resetting the powermeter too quickly, sometimes the EvseManager reports 0.00 kWh back.
|
||||
reset_powermeter();
|
||||
}
|
||||
|
||||
break;
|
||||
case state::State::STATE_C:
|
||||
// Table A.6: Sequence 1.2 Plug-in
|
||||
if (module_state->last_state == state::State::STATE_A) {
|
||||
module_state->simplified_mode = true;
|
||||
}
|
||||
|
||||
if (not module_state->pwm_running) { // C1
|
||||
// Table A.6 Sequence 10.2: EV does not stop drawing power even
|
||||
// if PWM stops. Stop within 6 seconds (E.g. Kona1!)
|
||||
// This is implemented in EvseManager
|
||||
if (not module_state->power_on_allowed)
|
||||
powerOff();
|
||||
} else if (module_state->power_on_allowed) { // C2
|
||||
// Table A.6: Sequence 4 EV ready to charge.
|
||||
// Must enable power within 3 seconds.
|
||||
powerOn();
|
||||
}
|
||||
break;
|
||||
case state::State::STATE_D:
|
||||
// Table A.6: Sequence 1.2 Plug-in (w/ventilation)
|
||||
if (module_state->last_state == state::State::STATE_A) {
|
||||
module_state->simplified_mode = true;
|
||||
}
|
||||
|
||||
if (not module_state->pwm_running) {
|
||||
// Table A.6 Sequence 10.2: EV does not stop drawing power
|
||||
// even if PWM stops. Stop within 6 seconds (E.g. Kona1!)
|
||||
/* if (mod.last_pwm_running) // FIMXE implement 6 second timer
|
||||
startTimer(6000);
|
||||
if (timerElapsed()) { */
|
||||
// force power off under load
|
||||
powerOff();
|
||||
// }
|
||||
} else if (module_state->power_on_allowed and not module_state->relais_on and module_state->has_ventilation) {
|
||||
// Table A.6: Sequence 4 EV ready to charge.
|
||||
// Must enable power within 3 seconds.
|
||||
powerOn();
|
||||
}
|
||||
break;
|
||||
case state::State::STATE_E: {
|
||||
powerOff();
|
||||
cp_state_x1();
|
||||
break;
|
||||
}
|
||||
case state::State::STATE_F:
|
||||
powerOff();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
module_state->last_state = module_state->current_state;
|
||||
module_state->last_pwm_running = module_state->pwm_running;
|
||||
}
|
||||
|
||||
void YetiSimulator::add_noise() {
|
||||
const auto random_number_between_0_and_1 = [] {
|
||||
return static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
|
||||
};
|
||||
const auto noise = 1 + (random_number_between_0_and_1() - 0.5) * 0.02;
|
||||
const auto lonoise = 1 + (random_number_between_0_and_1() - 0.5) * 0.005;
|
||||
const auto impedance = module_state->simdata_setting.impedance / 1000.0;
|
||||
|
||||
module_state->simulation_data.currents.L1 = module_state->simdata_setting.currents.L1 * noise;
|
||||
module_state->simulation_data.currents.L2 = module_state->simdata_setting.currents.L2 * noise;
|
||||
module_state->simulation_data.currents.L3 = module_state->simdata_setting.currents.L3 * noise;
|
||||
module_state->simulation_data.currents.N = module_state->simdata_setting.currents.N * noise;
|
||||
|
||||
module_state->simulation_data.voltages.L1 =
|
||||
module_state->simdata_setting.voltages.L1 * noise - impedance * module_state->simulation_data.currents.L1;
|
||||
module_state->simulation_data.voltages.L2 =
|
||||
module_state->simdata_setting.voltages.L2 * noise - impedance * module_state->simulation_data.currents.L2;
|
||||
module_state->simulation_data.voltages.L3 =
|
||||
module_state->simdata_setting.voltages.L3 * noise - impedance * module_state->simulation_data.currents.L3;
|
||||
|
||||
module_state->simulation_data.frequencies.L1 = module_state->simdata_setting.frequencies.L1 * lonoise;
|
||||
module_state->simulation_data.frequencies.L2 = module_state->simdata_setting.frequencies.L2 * lonoise;
|
||||
module_state->simulation_data.frequencies.L3 = module_state->simdata_setting.frequencies.L3 * lonoise;
|
||||
|
||||
module_state->simulation_data.cp_voltage = module_state->simdata_setting.cp_voltage * noise;
|
||||
module_state->simulation_data.rcd_current = module_state->simdata_setting.rcd_current * noise;
|
||||
module_state->simulation_data.pp_resistor = module_state->simdata_setting.pp_resistor * noise;
|
||||
|
||||
module_state->simulation_data.diode_fail = module_state->simdata_setting.diode_fail;
|
||||
module_state->simulation_data.error_e = module_state->simdata_setting.error_e;
|
||||
}
|
||||
|
||||
void YetiSimulator::simulate_powermeter() {
|
||||
using namespace std::chrono;
|
||||
|
||||
const auto time_stamp = time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count();
|
||||
if (module_state->powermeter_sim_last_time_stamp == 0)
|
||||
module_state->powermeter_sim_last_time_stamp = time_stamp;
|
||||
const auto deltat = time_stamp - module_state->powermeter_sim_last_time_stamp;
|
||||
module_state->powermeter_sim_last_time_stamp = time_stamp;
|
||||
|
||||
const auto wattL1 = module_state->simulation_data.voltages.L1 * module_state->simulation_data.currents.L1 *
|
||||
(module_state->relais_on ? 1 : 0);
|
||||
const auto wattL2 = module_state->simulation_data.voltages.L2 * module_state->simulation_data.currents.L2 *
|
||||
(module_state->relais_on and module_state->use_three_phases_confirmed ? 1 : 0);
|
||||
const auto wattL3 = module_state->simulation_data.voltages.L3 * module_state->simulation_data.currents.L3 *
|
||||
(module_state->relais_on and module_state->use_three_phases_confirmed ? 1 : 0);
|
||||
|
||||
if (module_state->simulation_data.currents.L1 >= 0) {
|
||||
module_state->import_watt_hr.L1 += wattL1 * deltat / 1000.0 / 3600.0;
|
||||
module_state->import_watt_hr.L2 += wattL2 * deltat / 1000.0 / 3600.0;
|
||||
module_state->import_watt_hr.L3 += wattL3 * deltat / 1000.0 / 3600.0;
|
||||
} else {
|
||||
module_state->export_watt_hr.L1 += wattL1 * deltat / 1000.0 / 3600.0;
|
||||
module_state->export_watt_hr.L2 += wattL2 * deltat / 1000.0 / 3600.0;
|
||||
module_state->export_watt_hr.L3 += wattL3 * deltat / 1000.0 / 3600.0;
|
||||
}
|
||||
|
||||
module_state->powermeter_data.time_stamp = round(time_stamp / 1000);
|
||||
module_state->powermeter_data.export_totalWattHr =
|
||||
round(module_state->export_watt_hr.L1 + module_state->export_watt_hr.L2 + module_state->export_watt_hr.L3);
|
||||
module_state->powermeter_data.import_totalWattHr =
|
||||
round(module_state->import_watt_hr.L1 + module_state->import_watt_hr.L2 + module_state->import_watt_hr.L3);
|
||||
|
||||
module_state->powermeter_data.wattL1 = round(wattL1);
|
||||
module_state->powermeter_data.vrmsL1 = module_state->simulation_data.voltages.L1;
|
||||
module_state->powermeter_data.irmsL1 = module_state->simulation_data.currents.L1;
|
||||
module_state->powermeter_data.import_wattHrL1 = round(module_state->import_watt_hr.L1);
|
||||
module_state->powermeter_data.export_wattHrL1 = round(module_state->export_watt_hr.L1);
|
||||
module_state->powermeter_data.tempL1 = 25.0 + fabs(wattL1 + wattL2 + wattL3) * 0.003;
|
||||
module_state->powermeter_data.freqL1 = module_state->simulation_data.frequencies.L1;
|
||||
|
||||
module_state->powermeter_data.wattL2 = round(wattL2);
|
||||
module_state->powermeter_data.vrmsL2 = module_state->simulation_data.voltages.L2;
|
||||
module_state->powermeter_data.irmsL2 = module_state->simulation_data.currents.L2;
|
||||
module_state->powermeter_data.import_wattHrL2 = round(module_state->import_watt_hr.L2);
|
||||
module_state->powermeter_data.export_wattHrL2 = round(module_state->export_watt_hr.L2);
|
||||
module_state->powermeter_data.tempL2 = 25.0 + fabs(wattL1 + wattL2 + wattL3) * 0.003;
|
||||
module_state->powermeter_data.freqL2 = module_state->simulation_data.frequencies.L2;
|
||||
|
||||
module_state->powermeter_data.wattL3 = round(wattL3);
|
||||
module_state->powermeter_data.vrmsL3 = module_state->simulation_data.voltages.L3;
|
||||
module_state->powermeter_data.irmsL3 = module_state->simulation_data.currents.L3;
|
||||
module_state->powermeter_data.import_wattHrL3 = round(module_state->import_watt_hr.L3);
|
||||
module_state->powermeter_data.export_wattHrL3 = round(module_state->export_watt_hr.L3);
|
||||
module_state->powermeter_data.tempL3 = 25.0 + fabs(wattL1 + wattL2 + wattL3) * 0.003;
|
||||
module_state->powermeter_data.freqL3 = module_state->simulation_data.frequencies.L3;
|
||||
|
||||
module_state->powermeter_data.irmsN = module_state->simulation_data.currents.N;
|
||||
}
|
||||
|
||||
void YetiSimulator::publish_ev_board_support() const {
|
||||
const auto pp = read_pp_ampacity();
|
||||
|
||||
p_ev_board_support->publish_bsp_measurement(
|
||||
{pp, static_cast<float>(module_state->pwm_duty_cycle * 100), module_state->simulation_data.rcd_current});
|
||||
}
|
||||
|
||||
void YetiSimulator::publish_powermeter() {
|
||||
p_powermeter->publish_powermeter(power_meter_external(module_state->powermeter_data));
|
||||
|
||||
// Deprecated external stuff
|
||||
const auto totalKWattHr =
|
||||
module_state->powermeter_data.irmsL1 >= 0
|
||||
? (module_state->powermeter_data.import_wattHrL1 + module_state->powermeter_data.import_wattHrL2 +
|
||||
module_state->powermeter_data.import_wattHrL3) /
|
||||
1000.0
|
||||
: (module_state->powermeter_data.export_wattHrL1 + module_state->powermeter_data.export_wattHrL2 +
|
||||
module_state->powermeter_data.export_wattHrL3) /
|
||||
1000.0;
|
||||
mqtt.publish("/external/powermeter/vrmsL1", module_state->powermeter_data.vrmsL1);
|
||||
mqtt.publish("/external/powermeter/phaseSeqError", false);
|
||||
mqtt.publish("/external/powermeter/time_stamp", std::to_string(module_state->powermeter_data.time_stamp));
|
||||
mqtt.publish("/external/powermeter/tempL1", module_state->powermeter_data.tempL1);
|
||||
mqtt.publish("/external/powermeter/totalKw",
|
||||
(module_state->powermeter_data.wattL1 + module_state->powermeter_data.wattL2 +
|
||||
module_state->powermeter_data.wattL3) /
|
||||
1000.0);
|
||||
mqtt.publish("/external/powermeter/totalKWattHr", totalKWattHr);
|
||||
mqtt.publish("/external/powermeter_json", json{module_state->powermeter_data}.dump());
|
||||
|
||||
mqtt.publish("/external/" + info.id + "/powermeter/tempL1", module_state->powermeter_data.tempL1);
|
||||
mqtt.publish("/external/" + info.id + "/powermeter/totalKw",
|
||||
(module_state->powermeter_data.wattL1 + module_state->powermeter_data.wattL2 +
|
||||
module_state->powermeter_data.wattL3) /
|
||||
1000.0);
|
||||
mqtt.publish("/external/" + info.id + "/powermeter/totalKWattHr", totalKWattHr);
|
||||
}
|
||||
|
||||
void YetiSimulator::publish_telemetry() {
|
||||
p_board_support->publish_telemetry({static_cast<float>(module_state->powermeter_data.tempL1), // evse_temperature_C
|
||||
1500., // fan_rpm
|
||||
12.01, // supply_voltage_12V
|
||||
-11.8, // supply_voltage_minus_12V
|
||||
module_state->relais_on}); // relais_on
|
||||
}
|
||||
|
||||
void YetiSimulator::publish_keepalive() {
|
||||
using namespace std::chrono;
|
||||
|
||||
mqtt.publish(
|
||||
"/external/keepalive_json",
|
||||
json{
|
||||
{"hw_revision", 0},
|
||||
{"hw_type", 0},
|
||||
{"protocol_version_major", 0},
|
||||
{"protocol_version_minor", 1},
|
||||
{"sw_version_string", "simulation"},
|
||||
{"time_stamp", {time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count() / 1000}},
|
||||
}
|
||||
.dump());
|
||||
}
|
||||
|
||||
void YetiSimulator::drawPower(const double l1, const double l2, const double l3, const double n) const {
|
||||
module_state->simdata_setting.currents.L1 = l1;
|
||||
module_state->simdata_setting.currents.L2 = l2;
|
||||
module_state->simdata_setting.currents.L3 = l3;
|
||||
module_state->simdata_setting.currents.N = n;
|
||||
}
|
||||
|
||||
void YetiSimulator::powerOn() {
|
||||
if (not module_state->relais_on) {
|
||||
publish_event(state::State::Event_PowerOn);
|
||||
module_state->relais_on = true;
|
||||
module_state->telemetry_data.power_switch.switching_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void YetiSimulator::powerOff() {
|
||||
if (module_state->relais_on) {
|
||||
publish_event(state::State::Event_PowerOff);
|
||||
module_state->telemetry_data.power_switch.switching_count++;
|
||||
module_state->relais_on = false;
|
||||
}
|
||||
}
|
||||
|
||||
void YetiSimulator::publish_event(state::State event) {
|
||||
p_board_support->publish_event(event_to_enum(event));
|
||||
}
|
||||
|
||||
void YetiSimulator::pwm_on(const double dutycycle) {
|
||||
if (dutycycle > 0.0) {
|
||||
module_state->pwm_duty_cycle = dutycycle;
|
||||
module_state->pwm_running = true;
|
||||
module_state->pwm_error_f = false;
|
||||
} else {
|
||||
cp_state_x1();
|
||||
}
|
||||
}
|
||||
void YetiSimulator::cp_state_x1() {
|
||||
module_state->pwm_duty_cycle = 1.0;
|
||||
module_state->pwm_running = false;
|
||||
module_state->pwm_error_f = false;
|
||||
}
|
||||
void YetiSimulator::cp_state_f() {
|
||||
module_state->pwm_duty_cycle = 1.0;
|
||||
module_state->pwm_running = false;
|
||||
module_state->pwm_error_f = true;
|
||||
}
|
||||
|
||||
void YetiSimulator::reset_powermeter() const {
|
||||
if (config.reset_powermeter_on_session_start) {
|
||||
module_state->import_watt_hr.L1 = 0;
|
||||
module_state->import_watt_hr.L2 = 0;
|
||||
module_state->import_watt_hr.L3 = 0;
|
||||
module_state->export_watt_hr.L1 = 0;
|
||||
module_state->export_watt_hr.L2 = 0;
|
||||
module_state->export_watt_hr.L3 = 0;
|
||||
}
|
||||
module_state->powermeter_sim_last_time_stamp = 0;
|
||||
}
|
||||
|
||||
types::board_support_common::ProximityPilot YetiSimulator::read_pp_ampacity() const {
|
||||
const auto pp_resistor = module_state->simdata_setting.pp_resistor;
|
||||
|
||||
if (pp_resistor < 80.0 or pp_resistor > 2460) {
|
||||
EVLOG_error << "PP resistor value " << pp_resistor << " Ohm seems to be outside the allowed range.";
|
||||
return {types::board_support_common::Ampacity::None};
|
||||
}
|
||||
|
||||
// PP resistor value in spec, use a conservative interpretation of the resistance ranges
|
||||
if (pp_resistor > 936.0 and pp_resistor <= 2460.0) {
|
||||
return {types::board_support_common::Ampacity::A_13};
|
||||
}
|
||||
if (pp_resistor > 308.0 && pp_resistor <= 936.0) {
|
||||
return {types::board_support_common::Ampacity::A_20};
|
||||
}
|
||||
if (pp_resistor > 140.0 && pp_resistor <= 308.0) {
|
||||
return {types::board_support_common::Ampacity::A_32};
|
||||
}
|
||||
if (pp_resistor > 80.0 && pp_resistor <= 140.0) {
|
||||
return {types::board_support_common::Ampacity::A_63_3ph_70_1ph};
|
||||
}
|
||||
return {types::board_support_common::Ampacity::None};
|
||||
}
|
||||
|
||||
} // namespace module
|
||||
@@ -0,0 +1,111 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef YETI_SIMULATOR_HPP
|
||||
#define YETI_SIMULATOR_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 2
|
||||
//
|
||||
|
||||
#include "ld-ev.hpp"
|
||||
|
||||
// headers for provided interface implementations
|
||||
#include <generated/interfaces/ac_rcd/Implementation.hpp>
|
||||
#include <generated/interfaces/connector_lock/Implementation.hpp>
|
||||
#include <generated/interfaces/ev_board_support/Implementation.hpp>
|
||||
#include <generated/interfaces/evse_board_support/Implementation.hpp>
|
||||
#include <generated/interfaces/powermeter/Implementation.hpp>
|
||||
|
||||
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
|
||||
#include "util/errors.hpp"
|
||||
#include "util/state.hpp"
|
||||
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
|
||||
|
||||
namespace module {
|
||||
|
||||
struct Conf {
|
||||
int connector_id;
|
||||
bool reset_powermeter_on_session_start;
|
||||
};
|
||||
|
||||
class YetiSimulator : public Everest::ModuleBase {
|
||||
public:
|
||||
YetiSimulator() = delete;
|
||||
YetiSimulator(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, Everest::TelemetryProvider& telemetry,
|
||||
std::unique_ptr<powermeterImplBase> p_powermeter,
|
||||
std::unique_ptr<evse_board_supportImplBase> p_board_support,
|
||||
std::unique_ptr<ev_board_supportImplBase> p_ev_board_support, std::unique_ptr<ac_rcdImplBase> p_rcd,
|
||||
std::unique_ptr<connector_lockImplBase> p_connector_lock, Conf& config) :
|
||||
ModuleBase(info),
|
||||
mqtt(mqtt_provider),
|
||||
telemetry(telemetry),
|
||||
p_powermeter(std::move(p_powermeter)),
|
||||
p_board_support(std::move(p_board_support)),
|
||||
p_ev_board_support(std::move(p_ev_board_support)),
|
||||
p_rcd(std::move(p_rcd)),
|
||||
p_connector_lock(std::move(p_connector_lock)),
|
||||
config(config){};
|
||||
|
||||
Everest::MqttProvider& mqtt;
|
||||
Everest::TelemetryProvider& telemetry;
|
||||
const std::unique_ptr<powermeterImplBase> p_powermeter;
|
||||
const std::unique_ptr<evse_board_supportImplBase> p_board_support;
|
||||
const std::unique_ptr<ev_board_supportImplBase> p_ev_board_support;
|
||||
const std::unique_ptr<ac_rcdImplBase> p_rcd;
|
||||
const std::unique_ptr<connector_lockImplBase> p_connector_lock;
|
||||
const Conf& config;
|
||||
|
||||
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
|
||||
std::unique_ptr<state::ModuleState> module_state;
|
||||
|
||||
void reset_module_state() {
|
||||
module_state = std::make_unique<state::ModuleState>();
|
||||
}
|
||||
|
||||
void pwm_on(const double dutycycle);
|
||||
void cp_state_x1();
|
||||
void cp_state_f();
|
||||
// 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
|
||||
void run_telemetry_slow() const;
|
||||
void run_telemetry_fast() const;
|
||||
[[noreturn]] void run_simulation(int sleep_time_ms);
|
||||
void simulation_step();
|
||||
void check_error_rcd();
|
||||
void read_from_car();
|
||||
void simulation_statemachine();
|
||||
void add_noise();
|
||||
void simulate_powermeter();
|
||||
void publish_ev_board_support() const;
|
||||
void publish_powermeter();
|
||||
void publish_telemetry();
|
||||
void publish_keepalive();
|
||||
void drawPower(const double l1, const double l2, const double l3, const double n) const;
|
||||
void powerOn();
|
||||
void powerOff();
|
||||
void reset_powermeter() const;
|
||||
[[nodiscard]] types::board_support_common::ProximityPilot read_pp_ampacity() const;
|
||||
|
||||
void publish_event(state::State event);
|
||||
// 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 // YETI_SIMULATOR_HPP
|
||||
@@ -0,0 +1,76 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "evse_board_supportImpl.hpp"
|
||||
#include "util/state.hpp"
|
||||
|
||||
namespace module::board_support {
|
||||
|
||||
namespace {
|
||||
types::evse_board_support::HardwareCapabilities set_default_capabilities() {
|
||||
return {32.0, // max_current_A_import
|
||||
6.0, // min_current_A_import
|
||||
3, // max_phase_count_import
|
||||
1, // min_phase_count_import
|
||||
16.0, // max_current_A_export
|
||||
0.0, // min_current_A_export
|
||||
3, // max_phase_count_export
|
||||
1, // min_phase_count_export
|
||||
true, // supports_changing_phases_during_charging
|
||||
false, // supports_cp_state_E
|
||||
types::evse_board_support::Connector_type::IEC62196Type2Cable, // connector_type
|
||||
std::nullopt}; // max_plug_temperature_C
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void evse_board_supportImpl::init() {
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::ready() {
|
||||
const auto default_capabilities = set_default_capabilities();
|
||||
publish_capabilities(default_capabilities);
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_enable(bool& value) {
|
||||
auto& current_state = mod->module_state->current_state;
|
||||
if (value) {
|
||||
if (current_state == state::State::STATE_DISABLED) {
|
||||
current_state = state::State::STATE_A;
|
||||
} else {
|
||||
mod->module_state->republish_state = true;
|
||||
}
|
||||
} else {
|
||||
current_state = state::State::STATE_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_pwm_on(double& value) {
|
||||
const auto dutycycle = value / 100.0;
|
||||
mod->pwm_on(dutycycle);
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_cp_state_X1() {
|
||||
mod->cp_state_x1();
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_cp_state_F() {
|
||||
mod->cp_state_f();
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_cp_state_E() {
|
||||
EVLOG_warning << "Command cp_state_E is not supported. Ignoring command.";
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_allow_power_on(types::evse_board_support::PowerOnOff& value) {
|
||||
mod->module_state->power_on_allowed = value.allow_power_on;
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_ac_switch_three_phases_while_charging(bool& value) {
|
||||
mod->module_state->use_three_phases = value;
|
||||
mod->module_state->use_three_phases_confirmed = value;
|
||||
}
|
||||
|
||||
void evse_board_supportImpl::handle_ac_set_overcurrent_limit_A(double& value) {
|
||||
}
|
||||
|
||||
} // namespace module::board_support
|
||||
@@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef BOARD_SUPPORT_EVSE_BOARD_SUPPORT_IMPL_HPP
|
||||
#define BOARD_SUPPORT_EVSE_BOARD_SUPPORT_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/evse_board_support/Implementation.hpp>
|
||||
|
||||
#include "../YetiSimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace board_support {
|
||||
|
||||
struct Conf {};
|
||||
|
||||
class evse_board_supportImpl : public evse_board_supportImplBase {
|
||||
public:
|
||||
evse_board_supportImpl() = delete;
|
||||
evse_board_supportImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<YetiSimulator>& mod, Conf& config) :
|
||||
evse_board_supportImplBase(ev, "board_support"), mod(mod), config(config){};
|
||||
|
||||
// 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_enable(bool& value) override;
|
||||
virtual void handle_pwm_on(double& value) override;
|
||||
virtual void handle_cp_state_X1() override;
|
||||
virtual void handle_cp_state_F() override;
|
||||
virtual void handle_cp_state_E() override;
|
||||
virtual void handle_allow_power_on(types::evse_board_support::PowerOnOff& value) override;
|
||||
virtual void handle_ac_switch_three_phases_while_charging(bool& value) override;
|
||||
virtual void handle_ac_set_overcurrent_limit_A(double& value) override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<YetiSimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
// 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 board_support
|
||||
} // namespace module
|
||||
|
||||
#endif // BOARD_SUPPORT_EVSE_BOARD_SUPPORT_IMPL_HPP
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "connector_lockImpl.hpp"
|
||||
#include <everest/logging.hpp>
|
||||
|
||||
namespace module::connector_lock {
|
||||
|
||||
void connector_lockImpl::init() {
|
||||
}
|
||||
|
||||
void connector_lockImpl::ready() {
|
||||
}
|
||||
|
||||
void connector_lockImpl::handle_lock() {
|
||||
EVLOG_info << "Lock connector";
|
||||
}
|
||||
|
||||
void connector_lockImpl::handle_unlock() {
|
||||
EVLOG_info << "Unlock connector";
|
||||
}
|
||||
|
||||
} // namespace module::connector_lock
|
||||
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef CONNECTOR_LOCK_CONNECTOR_LOCK_IMPL_HPP
|
||||
#define CONNECTOR_LOCK_CONNECTOR_LOCK_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/connector_lock/Implementation.hpp>
|
||||
|
||||
#include "../YetiSimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace connector_lock {
|
||||
|
||||
struct Conf {};
|
||||
|
||||
class connector_lockImpl : public connector_lockImplBase {
|
||||
public:
|
||||
connector_lockImpl() = delete;
|
||||
connector_lockImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<YetiSimulator>& mod, Conf& config) :
|
||||
connector_lockImplBase(ev, "connector_lock"), mod(mod), config(config){};
|
||||
|
||||
// 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_lock() override;
|
||||
virtual void handle_unlock() override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<YetiSimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
// 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 connector_lock
|
||||
} // namespace module
|
||||
|
||||
#endif // CONNECTOR_LOCK_CONNECTOR_LOCK_IMPL_HPP
|
||||
@@ -0,0 +1,89 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "ev_board_supportImpl.hpp"
|
||||
#include <everest/logging.hpp>
|
||||
|
||||
namespace module::ev_board_support {
|
||||
|
||||
namespace {
|
||||
constexpr auto CP_VOLTAGE_A = 12.0;
|
||||
constexpr auto CP_VOLTAGE_B = 9.0;
|
||||
constexpr auto CP_VOLTAGE_C = 6.0;
|
||||
constexpr auto CP_VOLTAGE_D = 3.0;
|
||||
} // namespace
|
||||
|
||||
void ev_board_supportImpl::init() {
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::ready() {
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::handle_enable(bool& value) {
|
||||
if (mod->module_state->simulation_enabled and not value) {
|
||||
publish_bsp_event({types::board_support_common::Event::A});
|
||||
mod->reset_module_state();
|
||||
}
|
||||
mod->module_state->simulation_enabled = value;
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::handle_set_cp_state(types::ev_board_support::EvCpState& cp_state) {
|
||||
using types::ev_board_support::EvCpState;
|
||||
auto& simdata_setting = mod->module_state->simdata_setting;
|
||||
|
||||
if (mod->module_state->pwm_error_f) {
|
||||
EVLOG_warning << "Cannot change CP state, because PWM F is active";
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cp_state) {
|
||||
case EvCpState::A:
|
||||
simdata_setting.cp_voltage = CP_VOLTAGE_A;
|
||||
publish_bsp_event({types::board_support_common::Event::A});
|
||||
break;
|
||||
case EvCpState::B:
|
||||
simdata_setting.cp_voltage = CP_VOLTAGE_B;
|
||||
publish_bsp_event({types::board_support_common::Event::B});
|
||||
break;
|
||||
case EvCpState::C:
|
||||
simdata_setting.cp_voltage = CP_VOLTAGE_C;
|
||||
publish_bsp_event({types::board_support_common::Event::C});
|
||||
break;
|
||||
case EvCpState::D:
|
||||
simdata_setting.cp_voltage = CP_VOLTAGE_D;
|
||||
publish_bsp_event({types::board_support_common::Event::D});
|
||||
break;
|
||||
case EvCpState::E:
|
||||
simdata_setting.error_e = true;
|
||||
publish_bsp_event({types::board_support_common::Event::E});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::handle_allow_power_on(bool& value) {
|
||||
EVLOG_debug << "EV Power On: " << value;
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::handle_diode_fail(bool& value) {
|
||||
mod->module_state->simdata_setting.diode_fail = value;
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::handle_set_ac_max_current(double& current) {
|
||||
mod->module_state->ev_max_current = current;
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::handle_set_three_phases(bool& three_phases) {
|
||||
if (three_phases) {
|
||||
mod->module_state->ev_phases = 3;
|
||||
} else {
|
||||
mod->module_state->ev_phases = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ev_board_supportImpl::handle_set_rcd_error(double& rcd_current_mA) {
|
||||
mod->module_state->simdata_setting.rcd_current = rcd_current_mA;
|
||||
}
|
||||
|
||||
} // namespace module::ev_board_support
|
||||
@@ -0,0 +1,67 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef EV_BOARD_SUPPORT_EV_BOARD_SUPPORT_IMPL_HPP
|
||||
#define EV_BOARD_SUPPORT_EV_BOARD_SUPPORT_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/ev_board_support/Implementation.hpp>
|
||||
|
||||
#include "../YetiSimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace ev_board_support {
|
||||
|
||||
struct Conf {};
|
||||
|
||||
class ev_board_supportImpl : public ev_board_supportImplBase {
|
||||
public:
|
||||
ev_board_supportImpl() = delete;
|
||||
ev_board_supportImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<YetiSimulator>& mod, Conf& config) :
|
||||
ev_board_supportImplBase(ev, "ev_board_support"), mod(mod), config(config){};
|
||||
|
||||
// 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_enable(bool& value) override;
|
||||
virtual void handle_set_cp_state(types::ev_board_support::EvCpState& cp_state) override;
|
||||
virtual void handle_allow_power_on(bool& value) override;
|
||||
virtual void handle_diode_fail(bool& value) override;
|
||||
virtual void handle_set_ac_max_current(double& current) override;
|
||||
virtual void handle_set_three_phases(bool& three_phases) override;
|
||||
virtual void handle_set_rcd_error(double& rcd_current_mA) override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<YetiSimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
// 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_board_support
|
||||
} // namespace module
|
||||
|
||||
#endif // EV_BOARD_SUPPORT_EV_BOARD_SUPPORT_IMPL_HPP
|
||||
@@ -0,0 +1,32 @@
|
||||
description: SIL simulator for YETI hardware v1.0
|
||||
config:
|
||||
connector_id:
|
||||
description: Connector id of the evse manager to which this simulator is connected to
|
||||
type: integer
|
||||
reset_powermeter_on_session_start:
|
||||
description: Reset absolute powermeter readings to zero when CP changes from state A to B
|
||||
type: boolean
|
||||
default: true
|
||||
provides:
|
||||
powermeter:
|
||||
interface: powermeter
|
||||
description: provides the Yeti Internal Power Meter
|
||||
board_support:
|
||||
interface: evse_board_support
|
||||
description: provides the EVSE board support Interface to low level control pilot, relais, rcd, motor lock
|
||||
ev_board_support:
|
||||
interface: ev_board_support
|
||||
description: provides the EV board support Interface to low level control pilot, relais, rcd
|
||||
rcd:
|
||||
interface: ac_rcd
|
||||
description: Interface for the simulated AC RCD
|
||||
connector_lock:
|
||||
interface: connector_lock
|
||||
description: Interface for the simulated Connector lock
|
||||
enable_external_mqtt: true
|
||||
enable_telemetry: true
|
||||
metadata:
|
||||
license: https://opensource.org/licenses/Apache-2.0
|
||||
authors:
|
||||
- Cornelius Claussen
|
||||
- Tobias Marzell (Pionix GmbH)
|
||||
@@ -0,0 +1,26 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "powermeterImpl.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace module::powermeter {
|
||||
|
||||
void powermeterImpl::init() {
|
||||
}
|
||||
|
||||
void powermeterImpl::ready() {
|
||||
this->publish_public_key_ocmf("TESTPUBLICKEY" + std::to_string(this->mod->config.connector_id));
|
||||
}
|
||||
|
||||
types::powermeter::TransactionStartResponse
|
||||
powermeterImpl::handle_start_transaction(types::powermeter::TransactionReq& _) {
|
||||
return {types::powermeter::TransactionRequestStatus::OK};
|
||||
}
|
||||
|
||||
types::powermeter::TransactionStopResponse powermeterImpl::handle_stop_transaction(std::string& transaction_id) {
|
||||
return {types::powermeter::TransactionRequestStatus::NOT_SUPPORTED, std::nullopt, std::nullopt,
|
||||
"YetiDriver does not support stop transaction request."};
|
||||
}
|
||||
|
||||
} // namespace module::powermeter
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef POWERMETER_POWERMETER_IMPL_HPP
|
||||
#define POWERMETER_POWERMETER_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/powermeter/Implementation.hpp>
|
||||
|
||||
#include "../YetiSimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace powermeter {
|
||||
|
||||
struct Conf {};
|
||||
|
||||
class powermeterImpl : public powermeterImplBase {
|
||||
public:
|
||||
powermeterImpl() = delete;
|
||||
powermeterImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<YetiSimulator>& mod, Conf& config) :
|
||||
powermeterImplBase(ev, "powermeter"), mod(mod), config(config){};
|
||||
|
||||
// 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 types::powermeter::TransactionStartResponse
|
||||
handle_start_transaction(types::powermeter::TransactionReq& value) override;
|
||||
virtual types::powermeter::TransactionStopResponse handle_stop_transaction(std::string& transaction_id) override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<YetiSimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
// 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 powermeter
|
||||
} // namespace module
|
||||
|
||||
#endif // POWERMETER_POWERMETER_IMPL_HPP
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "ac_rcdImpl.hpp"
|
||||
|
||||
namespace module::rcd {
|
||||
|
||||
void ac_rcdImpl::init() {
|
||||
}
|
||||
|
||||
void ac_rcdImpl::ready() {
|
||||
}
|
||||
|
||||
void ac_rcdImpl::handle_self_test() {
|
||||
// your code for cmd self_test goes here
|
||||
}
|
||||
|
||||
bool ac_rcdImpl::handle_reset() {
|
||||
// your code for cmd reset goes here
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace module::rcd
|
||||
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#ifndef RCD_AC_RCD_IMPL_HPP
|
||||
#define RCD_AC_RCD_IMPL_HPP
|
||||
|
||||
//
|
||||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
|
||||
// template version 3
|
||||
//
|
||||
|
||||
#include <generated/interfaces/ac_rcd/Implementation.hpp>
|
||||
|
||||
#include "../YetiSimulator.hpp"
|
||||
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
// insert your custom include headers here
|
||||
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
|
||||
|
||||
namespace module {
|
||||
namespace rcd {
|
||||
|
||||
struct Conf {};
|
||||
|
||||
class ac_rcdImpl : public ac_rcdImplBase {
|
||||
public:
|
||||
ac_rcdImpl() = delete;
|
||||
ac_rcdImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<YetiSimulator>& mod, Conf& config) :
|
||||
ac_rcdImplBase(ev, "rcd"), mod(mod), config(config){};
|
||||
|
||||
// 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_self_test() override;
|
||||
virtual bool handle_reset() override;
|
||||
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
// insert your protected definitions here
|
||||
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
|
||||
|
||||
private:
|
||||
const Everest::PtrContainer<YetiSimulator>& mod;
|
||||
const Conf& config;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void ready() override;
|
||||
|
||||
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
|
||||
// insert your private definitions here
|
||||
// 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 rcd
|
||||
} // namespace module
|
||||
|
||||
#endif // RCD_AC_RCD_IMPL_HPP
|
||||
@@ -0,0 +1,134 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "errors.hpp"
|
||||
|
||||
#include "everest/logging.hpp"
|
||||
|
||||
std::tuple<bool, std::optional<ErrorDefinition>> parse_error_type(const std::string& payload) {
|
||||
|
||||
// parsing, getting raise
|
||||
const auto e = json::parse(payload);
|
||||
|
||||
const auto raise = (e.value("raise", "false") == "true") ? true : false;
|
||||
|
||||
const auto error_type = static_cast<std::string>(e.at("error_type"));
|
||||
|
||||
if (error_type == "powermeter/CommunicationFault") {
|
||||
return {raise, error_definitions::powermeter_CommunicationFault};
|
||||
}
|
||||
if (error_type == "DiodeFault") {
|
||||
return {raise, error_definitions::evse_board_support_DiodeFault};
|
||||
}
|
||||
if (error_type == "BrownOut") {
|
||||
return {raise, error_definitions::evse_board_support_BrownOut};
|
||||
}
|
||||
if (error_type == "EnergyManagement") {
|
||||
return {raise, error_definitions::evse_board_support_EnergyManagement};
|
||||
}
|
||||
if (error_type == "PermanentFault") {
|
||||
return {raise, error_definitions::evse_board_support_PermanentFault};
|
||||
}
|
||||
if (error_type == "MREC2GroundFailure") {
|
||||
return {raise, error_definitions::evse_board_support_MREC2GroundFailure};
|
||||
}
|
||||
if (error_type == "MREC3HighTemperature") {
|
||||
return {raise, error_definitions::evse_board_support_MREC3HighTemperature};
|
||||
}
|
||||
if (error_type == "MREC4OverCurrentFailure") {
|
||||
return {raise, error_definitions::evse_board_support_MREC4OverCurrentFailure};
|
||||
}
|
||||
if (error_type == "MREC5OverVoltage") {
|
||||
return {raise, error_definitions::evse_board_support_MREC5OverVoltage};
|
||||
}
|
||||
if (error_type == "MREC6UnderVoltage") {
|
||||
return {raise, error_definitions::evse_board_support_MREC6UnderVoltage};
|
||||
}
|
||||
if (error_type == "MREC8EmergencyStop") {
|
||||
return {raise, error_definitions::evse_board_support_MREC8EmergencyStop};
|
||||
}
|
||||
if (error_type == "MREC10InvalidVehicleMode") {
|
||||
return {raise, error_definitions::evse_board_support_MREC10InvalidVehicleMode};
|
||||
}
|
||||
if (error_type == "MREC14PilotFault") {
|
||||
return {raise, error_definitions::evse_board_support_MREC14PilotFault};
|
||||
}
|
||||
if (error_type == "MREC15PowerLoss") {
|
||||
return {raise, error_definitions::evse_board_support_MREC15PowerLoss};
|
||||
}
|
||||
if (error_type == "MREC17EVSEContactorFault") {
|
||||
return {raise, error_definitions::evse_board_support_MREC17EVSEContactorFault};
|
||||
}
|
||||
if (error_type == "MREC18CableOverTempDerate") {
|
||||
return {raise, error_definitions::evse_board_support_MREC18CableOverTempDerate};
|
||||
}
|
||||
if (error_type == "MREC19CableOverTempStop") {
|
||||
return {raise, error_definitions::evse_board_support_MREC19CableOverTempStop};
|
||||
}
|
||||
if (error_type == "MREC20PartialInsertion") {
|
||||
return {raise, error_definitions::evse_board_support_MREC20PartialInsertion};
|
||||
}
|
||||
if (error_type == "MREC23ProximityFault") {
|
||||
return {raise, error_definitions::evse_board_support_MREC23ProximityFault};
|
||||
}
|
||||
if (error_type == "MREC24ConnectorVoltageHigh") {
|
||||
return {raise, error_definitions::evse_board_support_MREC24ConnectorVoltageHigh};
|
||||
}
|
||||
if (error_type == "MREC25BrokenLatch") {
|
||||
return {raise, error_definitions::evse_board_support_MREC25BrokenLatch};
|
||||
}
|
||||
if (error_type == "MREC26CutCable") {
|
||||
return {raise, error_definitions::evse_board_support_MREC26CutCable};
|
||||
}
|
||||
if (error_type == "TiltDetected") {
|
||||
return {raise, error_definitions::evse_board_support_TiltDetected};
|
||||
}
|
||||
if (error_type == "WaterIngressDetected") {
|
||||
return {raise, error_definitions::evse_board_support_WaterIngressDetected};
|
||||
}
|
||||
if (error_type == "EnclosureOpen") {
|
||||
return {raise, error_definitions::evse_board_support_EnclosureOpen};
|
||||
}
|
||||
if (error_type == "ac_rcd_MREC2GroundFailure") {
|
||||
return {raise, error_definitions::ac_rcd_MREC2GroundFailure};
|
||||
}
|
||||
if (error_type == "ac_rcd_VendorError") {
|
||||
return {raise, error_definitions::ac_rcd_VendorError};
|
||||
}
|
||||
if (error_type == "ac_rcd_Selftest") {
|
||||
return {raise, error_definitions::ac_rcd_Selftest};
|
||||
}
|
||||
if (error_type == "ac_rcd_AC") {
|
||||
return {raise, error_definitions::ac_rcd_AC};
|
||||
}
|
||||
if (error_type == "ac_rcd_DC") {
|
||||
return {raise, error_definitions::ac_rcd_DC};
|
||||
}
|
||||
if (error_type == "lock_ConnectorLockCapNotCharged") {
|
||||
return {raise, error_definitions::connector_lock_ConnectorLockCapNotCharged};
|
||||
}
|
||||
if (error_type == "lock_ConnectorLockUnexpectedOpen") {
|
||||
return {raise, error_definitions::connector_lock_ConnectorLockUnexpectedOpen};
|
||||
}
|
||||
if (error_type == "lock_ConnectorLockUnexpectedClose") {
|
||||
return {raise, error_definitions::connector_lock_ConnectorLockUnexpectedClose};
|
||||
}
|
||||
if (error_type == "lock_ConnectorLockFailedLock") {
|
||||
return {raise, error_definitions::connector_lock_ConnectorLockFailedLock};
|
||||
}
|
||||
if (error_type == "lock_ConnectorLockFailedUnlock") {
|
||||
return {raise, error_definitions::connector_lock_ConnectorLockFailedUnlock};
|
||||
}
|
||||
if (error_type == "lock_MREC1ConnectorLockFailure") {
|
||||
return {raise, error_definitions::connector_lock_MREC1ConnectorLockFailure};
|
||||
}
|
||||
if (error_type == "lock_VendorError") {
|
||||
return {raise, error_definitions::connector_lock_VendorError};
|
||||
}
|
||||
EVLOG_error << "Unknown error raised via MQTT";
|
||||
return {raise, std::nullopt};
|
||||
}
|
||||
|
||||
Everest::error::Error create_error(const Everest::error::ErrorFactory& error_factory, const ErrorDefinition& def) {
|
||||
return error_factory.create_error(def.type, def.sub_type, def.message, def.severity);
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
|
||||
#include <utils/error.hpp>
|
||||
#include <utils/error/error_factory.hpp>
|
||||
|
||||
enum class ErrorTarget {
|
||||
BoardSupport,
|
||||
ConnectorLock,
|
||||
Rcd,
|
||||
Powermeter
|
||||
};
|
||||
|
||||
struct ErrorDefinition {
|
||||
const char* type;
|
||||
const char* sub_type{""};
|
||||
const char* message{""};
|
||||
Everest::error::Severity severity{Everest::error::Severity::High};
|
||||
ErrorTarget error_target;
|
||||
};
|
||||
|
||||
Everest::error::Error create_error(const Everest::error::ErrorFactory& error_factory, const ErrorDefinition& def);
|
||||
|
||||
std::tuple<bool, std::optional<ErrorDefinition>> parse_error_type(const std::string& payload);
|
||||
|
||||
template <typename T> void forward_error(T& target, const Everest::error::Error& error, bool raise) {
|
||||
if (raise) {
|
||||
target->raise_error(error);
|
||||
} else {
|
||||
target->clear_error(error.type);
|
||||
}
|
||||
}
|
||||
|
||||
namespace error_definitions {
|
||||
inline const auto connector_lock_ConnectorLockUnexpectedClose =
|
||||
ErrorDefinition{"connector_lock/ConnectorLockUnexpectedClose"};
|
||||
|
||||
inline const auto evse_board_support_DiodeFault =
|
||||
ErrorDefinition{"evse_board_support/DiodeFault", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_BrownOut =
|
||||
ErrorDefinition{"evse_board_support/BrownOut", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_EnergyManagement =
|
||||
ErrorDefinition{"evse_board_support/EnergyManagement", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_PermanentFault =
|
||||
ErrorDefinition{"evse_board_support/PermanentFault", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC2GroundFailure =
|
||||
ErrorDefinition{"evse_board_support/MREC2GroundFailure", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC3HighTemperature =
|
||||
ErrorDefinition{"evse_board_support/MREC3HighTemperature", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC4OverCurrentFailure =
|
||||
ErrorDefinition{"evse_board_support/MREC4OverCurrentFailure", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC5OverVoltage =
|
||||
ErrorDefinition{"evse_board_support/MREC5OverVoltage", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC6UnderVoltage =
|
||||
ErrorDefinition{"evse_board_support/MREC6UnderVoltage", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC8EmergencyStop =
|
||||
ErrorDefinition{"evse_board_support/MREC8EmergencyStop", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC10InvalidVehicleMode =
|
||||
ErrorDefinition{"evse_board_support/MREC10InvalidVehicleMode", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC14PilotFault =
|
||||
ErrorDefinition{"evse_board_support/MREC14PilotFault", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC15PowerLoss =
|
||||
ErrorDefinition{"evse_board_support/MREC15PowerLoss", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC17EVSEContactorFault =
|
||||
ErrorDefinition{"evse_board_support/MREC17EVSEContactorFault", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC18CableOverTempDerate =
|
||||
ErrorDefinition{"evse_board_support/MREC18CableOverTempDerate", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC19CableOverTempStop =
|
||||
ErrorDefinition{"evse_board_support/MREC19CableOverTempStop", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC20PartialInsertion =
|
||||
ErrorDefinition{"evse_board_support/MREC20PartialInsertion", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC23ProximityFault =
|
||||
ErrorDefinition{"evse_board_support/MREC23ProximityFault", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC24ConnectorVoltageHigh =
|
||||
ErrorDefinition{"evse_board_support/MREC24ConnectorVoltageHigh", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC25BrokenLatch =
|
||||
ErrorDefinition{"evse_board_support/MREC25BrokenLatch", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_MREC26CutCable =
|
||||
ErrorDefinition{"evse_board_support/MREC26CutCable", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_TiltDetected =
|
||||
ErrorDefinition{"evse_board_support/TiltDetected", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_WaterIngressDetected =
|
||||
ErrorDefinition{"evse_board_support/WaterIngressDetected", "", "Simulated fault event"};
|
||||
|
||||
inline const auto evse_board_support_EnclosureOpen =
|
||||
ErrorDefinition{"evse_board_support/EnclosureOpen", "", "Simulated fault event"};
|
||||
|
||||
inline const auto ac_rcd_VendorError = ErrorDefinition{"ac_rcd/VendorError", "", "Simulated fault event"};
|
||||
|
||||
inline const auto ac_rcd_Selftest = ErrorDefinition{"ac_rcd/Selftest", "", "Simulated fault event"};
|
||||
|
||||
inline const auto ac_rcd_AC = ErrorDefinition{"ac_rcd/AC", "", "Simulated fault event"};
|
||||
|
||||
inline const auto ac_rcd_DC = ErrorDefinition{"ac_rcd/DC", "", "Simulated fault event"};
|
||||
|
||||
inline const auto ac_rcd_MREC2GroundFailure = ErrorDefinition{"ac_rcd/MREC2GroundFailure", "", "Simulated fault event"};
|
||||
|
||||
inline const auto connector_lock_ConnectorLockCapNotCharged =
|
||||
ErrorDefinition{"connector_lock/ConnectorLockCapNotCharged", "", "Simulated fault event"};
|
||||
|
||||
inline const auto connector_lock_ConnectorLockUnexpectedOpen =
|
||||
ErrorDefinition{"connector_lock/ConnectorLockUnexpectedOpen", "", "Simulated fault event"};
|
||||
|
||||
inline const auto connector_lock_ConnectorLockFailedLock =
|
||||
ErrorDefinition{"connector_lock/ConnectorLockFailedLock", "", "Simulated fault event"};
|
||||
|
||||
inline const auto connector_lock_ConnectorLockFailedUnlock =
|
||||
ErrorDefinition{"connector_lock/ConnectorLockFailedUnlock", "", "Simulated fault event"};
|
||||
|
||||
inline const auto connector_lock_MREC1ConnectorLockFailure =
|
||||
ErrorDefinition{"connector_lock/MREC1ConnectorLockFailure", "", "Simulated fault event"};
|
||||
|
||||
inline const auto connector_lock_VendorError =
|
||||
ErrorDefinition{"connector_lock/VendorError", "", "Simulated fault event"};
|
||||
|
||||
inline const auto powermeter_CommunicationFault =
|
||||
ErrorDefinition{"powermeter/CommunicationFault", "", "Simulated fault event", Everest::error::Severity::High,
|
||||
ErrorTarget::Powermeter};
|
||||
|
||||
} // namespace error_definitions
|
||||
@@ -0,0 +1,84 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "state.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace module::state {
|
||||
using std::chrono::milliseconds;
|
||||
using std::chrono::system_clock;
|
||||
using std::chrono::time_point_cast;
|
||||
|
||||
TimeStamp::TimeStamp() :
|
||||
time_stamp{time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count() / milliseconds_in_second} {
|
||||
}
|
||||
|
||||
TimeStamp& TimeStamp::operator=(const double value) {
|
||||
time_stamp = static_cast<int64_t>(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TimeStamp::operator int64_t() const {
|
||||
return time_stamp;
|
||||
}
|
||||
|
||||
std::string state_to_string(const ModuleState& module_state) {
|
||||
using state::State;
|
||||
|
||||
const auto pwm = module_state.pwm_running ? '2' : '1';
|
||||
|
||||
switch (module_state.current_state) {
|
||||
case State::STATE_DISABLED:
|
||||
return "Disabled";
|
||||
case State::STATE_A:
|
||||
return "A" + std::to_string(pwm);
|
||||
case State::STATE_B:
|
||||
return "B" + std::to_string(pwm);
|
||||
case State::STATE_C:
|
||||
return "C" + std::to_string(pwm);
|
||||
case State::STATE_D:
|
||||
return "D" + std::to_string(pwm);
|
||||
case State::STATE_E:
|
||||
return "E" + std::to_string(pwm);
|
||||
case State::STATE_F:
|
||||
return "F" + std::to_string(pwm);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& json, const PowermeterData& powermeter_data) {
|
||||
json = nlohmann::json{{"time_stamp", static_cast<uint64_t>(powermeter_data.time_stamp)},
|
||||
{"total_importWattHr", powermeter_data.import_totalWattHr},
|
||||
{"total_exportWattHr", powermeter_data.export_totalWattHr},
|
||||
{"wattL1", powermeter_data.wattL1},
|
||||
{"vrmsL1", powermeter_data.vrmsL1},
|
||||
{"irmsL1", powermeter_data.irmsL1},
|
||||
{"import_wattHrL1", powermeter_data.import_wattHrL1},
|
||||
{"export_wattHrL1", powermeter_data.export_wattHrL1},
|
||||
{"tempL1", powermeter_data.tempL1},
|
||||
{"freqL1", powermeter_data.freqL1},
|
||||
|
||||
{"wattL2", powermeter_data.wattL2},
|
||||
{"vrmsL2", powermeter_data.vrmsL2},
|
||||
{"irmsL2", powermeter_data.irmsL2},
|
||||
{"import_wattHrL2", powermeter_data.import_wattHrL2},
|
||||
{"export_wattHrL2", powermeter_data.export_wattHrL2},
|
||||
{"tempL2", powermeter_data.tempL2},
|
||||
{"freqL2", powermeter_data.freqL2},
|
||||
|
||||
{"wattL3", powermeter_data.wattL3},
|
||||
{"vrmsL3", powermeter_data.vrmsL3},
|
||||
{"irmsL3", powermeter_data.irmsL3},
|
||||
{"import_wattHrL3", powermeter_data.import_wattHrL3},
|
||||
{"export_wattHrL3", powermeter_data.export_wattHrL3},
|
||||
{"tempL3", powermeter_data.tempL3},
|
||||
{"freqL3", powermeter_data.freqL3},
|
||||
|
||||
{"irmsN", powermeter_data.irmsN}};
|
||||
}
|
||||
|
||||
} // namespace module::state
|
||||
@@ -0,0 +1,250 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
// NOLINTBEGIN: ignore things like public access or magic values
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace module::state {
|
||||
|
||||
struct TimeStamp {
|
||||
TimeStamp();
|
||||
TimeStamp& operator=(const double value);
|
||||
|
||||
operator int64_t() const;
|
||||
|
||||
int64_t time_stamp;
|
||||
};
|
||||
struct PowermeterData {
|
||||
TimeStamp time_stamp;
|
||||
double import_totalWattHr = 0.0;
|
||||
double export_totalWattHr = 0.0;
|
||||
|
||||
double wattL1 = 0.0;
|
||||
double vrmsL1 = 230.0;
|
||||
double irmsL1 = 0.0;
|
||||
double import_wattHrL1 = 0.0;
|
||||
double export_wattHrL1 = 0.0;
|
||||
double tempL1 = 25.0;
|
||||
double freqL1 = 50.0;
|
||||
|
||||
double wattL2 = 0.0;
|
||||
double vrmsL2 = 230.0;
|
||||
double irmsL2 = 0.0;
|
||||
double import_wattHrL2 = 0.0;
|
||||
double export_wattHrL2 = 0.0;
|
||||
double tempL2 = 25.0;
|
||||
double freqL2 = 50.0;
|
||||
|
||||
double wattL3 = 0.0;
|
||||
double vrmsL3 = 230.0;
|
||||
double irmsL3 = 0.0;
|
||||
double import_wattHrL3 = 0.0;
|
||||
double export_wattHrL3 = 0.0;
|
||||
double tempL3 = 25.0;
|
||||
double freqL3 = 50.0;
|
||||
|
||||
double irmsN = 0.0;
|
||||
};
|
||||
|
||||
struct SimulationData {
|
||||
double cp_voltage = 12.0;
|
||||
bool diode_fail = false;
|
||||
bool error_e = false;
|
||||
double pp_resistor = 220.1;
|
||||
double rcd_current = 0.1;
|
||||
|
||||
struct Currents {
|
||||
double L1 = 0.0;
|
||||
double L2 = 0.0;
|
||||
double L3 = 0.0;
|
||||
double N = 0.0;
|
||||
};
|
||||
|
||||
Currents currents;
|
||||
|
||||
struct Voltages {
|
||||
double L1 = 230.0;
|
||||
double L2 = 230.0;
|
||||
double L3 = 230.0;
|
||||
};
|
||||
|
||||
Voltages voltages;
|
||||
|
||||
struct Frequencies {
|
||||
double L1 = 50.0;
|
||||
double L2 = 50.0;
|
||||
double L3 = 50.0;
|
||||
};
|
||||
|
||||
Frequencies frequencies;
|
||||
};
|
||||
|
||||
struct SimdataSetting {
|
||||
double cp_voltage = 12.0;
|
||||
double pp_resistor = 220.1;
|
||||
double impedance = 500.0;
|
||||
double rcd_current = 0.1;
|
||||
bool diode_fail = false;
|
||||
bool error_e = false;
|
||||
|
||||
struct Voltages {
|
||||
double L1 = 230.0;
|
||||
double L2 = 230.0;
|
||||
double L3 = 230.0;
|
||||
};
|
||||
|
||||
Voltages voltages;
|
||||
|
||||
struct Currents {
|
||||
double L1 = 0.0;
|
||||
double L2 = 0.0;
|
||||
double L3 = 0.0;
|
||||
double N = 0.0;
|
||||
};
|
||||
|
||||
Currents currents;
|
||||
|
||||
struct Frequencies {
|
||||
double L1 = 50.0;
|
||||
double L2 = 50.0;
|
||||
double L3 = 50.0;
|
||||
};
|
||||
|
||||
Frequencies frequencies;
|
||||
};
|
||||
|
||||
struct WattHr {
|
||||
double L1 = 0.0;
|
||||
double L2 = 0.0;
|
||||
double L3 = 0.0;
|
||||
};
|
||||
|
||||
struct TelemetryData {
|
||||
|
||||
struct PowerPathControllerVersion {
|
||||
std::string timestamp;
|
||||
std::string type = "power_path_controller_version";
|
||||
int hardware_version = 3;
|
||||
std::string software_version = "1.01";
|
||||
std::string date_manufactured = "20220304";
|
||||
int64_t operating_time_h = 2330;
|
||||
int64_t operating_time_h_warning = 5000;
|
||||
int64_t operating_time_h_error = 6000;
|
||||
bool error = false;
|
||||
};
|
||||
|
||||
PowerPathControllerVersion power_path_controller_version;
|
||||
|
||||
struct PowerPathController {
|
||||
std::string timestamp;
|
||||
std::string type = "power_path_controller";
|
||||
double cp_voltage_high = 0.0;
|
||||
double cp_voltage_low = 0.0;
|
||||
double cp_pwm_duty_cycle = 0.0;
|
||||
std::string cp_state = "A1";
|
||||
double pp_ohm = 220.1;
|
||||
double supply_voltage_12V = 12.1;
|
||||
double supply_voltage_minus_12V = -11.9;
|
||||
double temperature_controller = 33;
|
||||
double temperature_car_connector = 65;
|
||||
int64_t watchdog_reset_count = 1;
|
||||
bool error = false;
|
||||
};
|
||||
|
||||
PowerPathController power_path_controller;
|
||||
|
||||
struct PowerSwitch {
|
||||
std::string timestamp;
|
||||
std::string type = "power_switch";
|
||||
int64_t switching_count = 0;
|
||||
int64_t switching_count_warning = 30000;
|
||||
int64_t switching_count_error = 50000;
|
||||
bool is_on = false;
|
||||
int64_t time_to_switch_on_ms = 110;
|
||||
int64_t time_to_switch_off_ms = 100;
|
||||
double temperature_C = 20;
|
||||
bool error = false;
|
||||
bool error_over_current = false;
|
||||
};
|
||||
|
||||
PowerSwitch power_switch;
|
||||
|
||||
struct Rcd {
|
||||
std::string timestamp;
|
||||
std::string type = "rcd";
|
||||
bool enabled = true;
|
||||
double current_mA = 2.5;
|
||||
bool triggered = false;
|
||||
bool error = false;
|
||||
};
|
||||
|
||||
Rcd rcd;
|
||||
};
|
||||
|
||||
enum class State {
|
||||
STATE_DISABLED = 0,
|
||||
STATE_A = 1,
|
||||
STATE_B = 2,
|
||||
STATE_C = 3,
|
||||
STATE_D = 4,
|
||||
STATE_E = 5,
|
||||
STATE_F = 6,
|
||||
Event_PowerOn = 8,
|
||||
Event_PowerOff = 9,
|
||||
};
|
||||
|
||||
struct ModuleState {
|
||||
PowermeterData powermeter_data;
|
||||
SimulationData simulation_data;
|
||||
SimdataSetting simdata_setting;
|
||||
TelemetryData telemetry_data;
|
||||
|
||||
int64_t pubCnt = 0;
|
||||
|
||||
bool power_on_allowed = false;
|
||||
|
||||
bool relais_on = false;
|
||||
State current_state = State::STATE_DISABLED;
|
||||
State last_state = State::STATE_DISABLED;
|
||||
TimeStamp time_stamp;
|
||||
bool use_three_phases = true;
|
||||
bool simplified_mode = false;
|
||||
|
||||
bool has_ventilation = false;
|
||||
|
||||
bool rcd_error = false;
|
||||
|
||||
bool simulation_enabled = false;
|
||||
double pwm_duty_cycle = 0;
|
||||
bool pwm_running = false;
|
||||
bool pwm_error_f = false;
|
||||
bool last_pwm_running = false;
|
||||
bool use_three_phases_confirmed = true;
|
||||
double pwm_voltage_hi = 12.1;
|
||||
double pwm_voltage_lo = 12.1;
|
||||
|
||||
std::string country_code = "DE";
|
||||
int64_t last_pwm_update = 0;
|
||||
|
||||
WattHr export_watt_hr;
|
||||
WattHr import_watt_hr;
|
||||
|
||||
int64_t powermeter_sim_last_time_stamp = 0L;
|
||||
|
||||
double ev_max_current = 0.0;
|
||||
int ev_phases = 3;
|
||||
|
||||
bool republish_state = false;
|
||||
};
|
||||
|
||||
std::string state_to_string(const state::ModuleState& module_state);
|
||||
|
||||
void to_json(nlohmann::json& json, const PowermeterData& powermeter_data);
|
||||
|
||||
constexpr inline auto milliseconds_in_second = 1000;
|
||||
|
||||
} // namespace module::state
|
||||
|
||||
// NOLINTEND
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "util.hpp"
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace module::util {
|
||||
std::string get_current_iso_time_string() {
|
||||
using std::chrono::system_clock;
|
||||
const auto date = system_clock::to_time_t(system_clock::now());
|
||||
|
||||
auto string_stream = std::stringstream{};
|
||||
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
||||
string_stream << std::put_time(gmtime(&date), "%FT%TZ");
|
||||
const auto iso_time_string = string_stream.str();
|
||||
return iso_time_string;
|
||||
}
|
||||
|
||||
} // namespace module::util
|
||||
@@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
namespace module::util {
|
||||
|
||||
std::string get_current_iso_time_string();
|
||||
|
||||
} // namespace module::util
|
||||
Reference in New Issue
Block a user