Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: MarzellT <[email protected]>
  • Loading branch information
MarzellT committed Sep 12, 2024
1 parent 56b2697 commit 7ac3d30
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 62 deletions.
2 changes: 2 additions & 0 deletions modules/YetiSimulator/YetiSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ void YetiSimulator::init() {
invoke_init(*p_ev_board_support);
invoke_init(*p_rcd);
invoke_init(*p_connector_lock);

clear_data();

mqtt_handler = std::make_unique<MqttHandler>(p_board_support.get(), p_rcd.get(), p_connector_lock.get());
mqtt.subscribe("everest_external/nodered/" + std::to_string(config.connector_id) + "/carsim/error",
[this](const std::string& payload) { mqtt_handler->handle_mqtt_payload(payload); });
Expand Down
1 change: 0 additions & 1 deletion modules/YetiSimulator/util/mqtt_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "mqtt_handler.hpp"
#include "everest/logging.hpp"
#include "nlohmann/json.hpp"
#include <utils/error.hpp>

namespace module {

Expand Down
11 changes: 7 additions & 4 deletions modules/YetiSimulator/util/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template <typename YetiSimulatorT, typename BoardSupportT> class Simulator {
std::thread(&Simulator::run_simulation, this, sleep_time_ms, yeti_simulator).detach();
}

void run_simulation(int sleep_time_ms, YetiSimulatorT* yeti_simulator) {
[[noreturn]] void run_simulation(int sleep_time_ms, YetiSimulatorT* yeti_simulator) {
auto& module_state = yeti_simulator->get_module_state();
while (true) {
if (module_state.simulation_enabled) {
Expand Down Expand Up @@ -83,9 +83,9 @@ template <typename YetiSimulatorT, typename BoardSupportT> class Simulator {

auto& module_state = yeti_simulator->get_module_state();

auto amps1 = 0.0;
auto amps2 = 0.0;
auto amps3 = 0.0;
auto amps1 = double{};
auto amps2 = double{};
auto amps3 = double{};

auto hlc_active = false;
if (module_state.pwm_duty_cycle >= 0.03 && module_state.pwm_duty_cycle <= 0.07)
Expand Down Expand Up @@ -515,10 +515,12 @@ template <typename YetiSimulatorT, typename BoardSupportT> class Simulator {
}
}

// NOLINTNEXTLINE
void publish_event(evse_board_supportImplBase& board_support, state::State event) {
board_support.publish_event(event_to_enum(event));
}

// NOLINTNEXTLINE
static types::board_support_common::BspEvent event_to_enum(state::State event) {
using state::State;
using types::board_support_common::Event;
Expand Down Expand Up @@ -548,6 +550,7 @@ template <typename YetiSimulatorT, typename BoardSupportT> class Simulator {
}
}

// NOLINTNEXTLINE
static std::string event_to_string(state::State state) {
using state::State;

Expand Down
50 changes: 27 additions & 23 deletions modules/YetiSimulator/util/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

#include "state.hpp"
#include <chrono>
#include <nlohmann/json_fwd.hpp>
#include <string>

namespace module::state {
using namespace std::chrono;
using std::chrono::milliseconds;
using std::chrono::system_clock;
using std::chrono::time_point_cast;

PowermeterData::PowermeterData() :
time_stamp{time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count() / 1000} {
Expand Down Expand Up @@ -39,31 +42,32 @@ std::string state_to_string(state::ModuleState& module_state) {
return "";
}
}
void to_json(nlohmann::json& j, const PowermeterData& powermeter_data) {
j = nlohmann::json{{"time_stamp", powermeter_data.time_stamp},
{"totalWattHr", powermeter_data.totalWattHr},
{"wattL1", powermeter_data.wattL1},
{"vrmsL1", powermeter_data.vrmsL1},
{"irmsL1", powermeter_data.irmsL1},
{"wattHrL1", powermeter_data.wattHrL1},
{"tempL1", powermeter_data.tempL1},
{"freqL1", powermeter_data.freqL1},

{"wattL2", powermeter_data.wattL2},
{"vrmsL2", powermeter_data.vrmsL2},
{"irmsL2", powermeter_data.irmsL2},
{"wattHrL2", powermeter_data.wattHrL2},
{"tempL2", powermeter_data.tempL2},
{"freqL2", powermeter_data.freqL2},
void to_json(nlohmann::json& json, const PowermeterData& powermeter_data) {
json = nlohmann::json{{"time_stamp", powermeter_data.time_stamp},
{"totalWattHr", powermeter_data.totalWattHr},
{"wattL1", powermeter_data.wattL1},
{"vrmsL1", powermeter_data.vrmsL1},
{"irmsL1", powermeter_data.irmsL1},
{"wattHrL1", powermeter_data.wattHrL1},
{"tempL1", powermeter_data.tempL1},
{"freqL1", powermeter_data.freqL1},

{"wattL3", powermeter_data.wattL3},
{"vrmsL3", powermeter_data.vrmsL3},
{"irmsL3", powermeter_data.irmsL3},
{"wattHrL3", powermeter_data.wattHrL3},
{"tempL3", powermeter_data.tempL3},
{"freqL3", powermeter_data.freqL3},
{"wattL2", powermeter_data.wattL2},
{"vrmsL2", powermeter_data.vrmsL2},
{"irmsL2", powermeter_data.irmsL2},
{"wattHrL2", powermeter_data.wattHrL2},
{"tempL2", powermeter_data.tempL2},
{"freqL2", powermeter_data.freqL2},

{"irmsN", powermeter_data.irmsN}};
{"wattL3", powermeter_data.wattL3},
{"vrmsL3", powermeter_data.vrmsL3},
{"irmsL3", powermeter_data.irmsL3},
{"wattHrL3", powermeter_data.wattHrL3},
{"tempL3", powermeter_data.tempL3},
{"freqL3", powermeter_data.freqL3},

{"irmsN", powermeter_data.irmsN}};
}

} // namespace module::state
52 changes: 28 additions & 24 deletions modules/YetiSimulator/util/state.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#pragma once
#ifndef EVEREST_CORE_MODULES_YETISIMULATOR_UTIL_STATE_HPP
#define EVEREST_CORE_MODULES_YETISIMULATOR_UTIL_STATE_HPP

// NOLINTBEGIN: ignore things like public access or magic values
#include "nlohmann/json.hpp"
#include <string>
namespace module {
namespace state {

namespace module::state {

struct PowermeterData {
PowermeterData();
long time_stamp;
int64_t time_stamp;

Check notice on line 15 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L15

struct member 'PowermeterData::time_stamp' is never used.

double totalWattHr = 0.0;

Expand Down Expand Up @@ -114,21 +116,21 @@ struct WattHr {
struct TelemetryData {

struct PowerPathControllerVersion {
std::string timestamp = "";
std::string timestamp;

Check notice on line 119 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L119

struct member 'PowerPathControllerVersion::timestamp' is never used.
std::string type = "power_path_controller_version";
int hardware_version = 3;
std::string software_version = "1.01";
std::string date_manufactured = "20220304";
long operating_time_h = 2330;
long operating_time_h_warning = 5000;
long operating_time_h_error = 6000;
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;

Check notice on line 130 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L130

struct member 'TelemetryData::power_path_controller_version' is never used.

struct PowerPathController {
std::string timestamp = "";
std::string timestamp;
std::string type = "power_path_controller";
double cp_voltage_high = 0.0;
double cp_voltage_low = 0.0;
Expand All @@ -139,21 +141,21 @@ struct TelemetryData {
double supply_voltage_minus_12V = -11.9;
double temperature_controller = 33;
double temperature_car_connector = 65;
long watchdog_reset_count = 1;
int64_t watchdog_reset_count = 1;
bool error = false;
};

PowerPathController power_path_controller;

Check notice on line 148 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L148

struct member 'TelemetryData::power_path_controller' is never used.

struct PowerSwitch {
std::string timestamp = "";
std::string timestamp;
std::string type = "power_switch";
long switching_count = 0;
long switching_count_warning = 30000;
long switching_count_error = 50000;
int64_t switching_count = 0;
int64_t switching_count_warning = 30000;
int64_t switching_count_error = 50000;
bool is_on = false;
long time_to_switch_on_ms = 110;
long time_to_switch_off_ms = 100;
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;
Expand All @@ -162,7 +164,7 @@ struct TelemetryData {
PowerSwitch power_switch;

Check notice on line 164 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L164

struct member 'TelemetryData::power_switch' is never used.

struct Rcd {
std::string timestamp = "";
std::string timestamp;
std::string type = "rcd";
bool enabled = true;
double current_mA = 2.5;
Expand Down Expand Up @@ -193,14 +195,14 @@ struct ModuleState {
SimdataSetting simdata_setting;

Check notice on line 195 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L195

struct member 'ModuleState::simdata_setting' is never used.
TelemetryData telemetry_data;

Check notice on line 196 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L196

struct member 'ModuleState::telemetry_data' is never used.

long pubCnt = 0;
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;
long time_stamp;
int64_t time_stamp;
bool use_three_phases = true;
bool simplified_mode = false;

Expand All @@ -219,19 +221,21 @@ struct ModuleState {
double pwm_voltage_lo = 12.1;

std::string country_code = "DE";
long last_pwm_update = 0;
int64_t last_pwm_update = 0;

WattHr watt_hr;

Check notice on line 226 in modules/YetiSimulator/util/state.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/YetiSimulator/util/state.hpp#L226

struct member 'ModuleState::watt_hr' is never used.

long powermeter_sim_last_time_stamp = 0L;
int64_t powermeter_sim_last_time_stamp = 0L;

double ev_max_current = 0.0;
int ev_three_phases = 3;
};

std::string state_to_string(state::ModuleState& module_state);

void to_json(nlohmann::json& j, const PowermeterData& powermeter_data);
void to_json(nlohmann::json& json, const PowermeterData& powermeter_data);

} // namespace module::state

} // namespace state
} // namespace module
#endif
// NOLINTEND
11 changes: 6 additions & 5 deletions modules/YetiSimulator/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

#include "util.hpp"
#include <chrono>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <string>

namespace module {
namespace util {
namespace module::util {
std::string get_current_iso_time_string() {
using namespace std::chrono;
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), "%F:%T%Z");
const auto iso_time_string = string_stream.str();
return iso_time_string;
}

} // namespace util
} // namespace module
} // namespace module::util
11 changes: 6 additions & 5 deletions modules/YetiSimulator/util/util.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#pragma once
#ifndef EVEREST_CORE_MODULES_YETISIMULATOR_UTIL_UTIL_HPP
#define EVEREST_CORE_MODULES_YETISIMULATOR_UTIL_UTIL_HPP

#include <string>
namespace module {
namespace util {
namespace module::util {

std::string get_current_iso_time_string();

} // namespace util
} // namespace module
} // namespace module::util

#endif

0 comments on commit 7ac3d30

Please sign in to comment.