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:
@@ -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