Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/watchdog framework #514

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions modules/API/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,19 @@ struct Conf {
class API : public Everest::ModuleBase {
public:
API() = delete;
API(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, std::unique_ptr<emptyImplBase> p_main,
std::vector<std::unique_ptr<evse_managerIntf>> r_evse_manager, std::vector<std::unique_ptr<ocppIntf>> r_ocpp,
Conf& config) :
API(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<emptyImplBase> p_main, std::vector<std::unique_ptr<evse_managerIntf>> r_evse_manager,
std::vector<std::unique_ptr<ocppIntf>> r_ocpp, Conf& config) :
ModuleBase(info),
mqtt(mqtt_provider),
watchdog_supervisor(watchdog_supervisor),
p_main(std::move(p_main)),
r_evse_manager(std::move(r_evse_manager)),
r_ocpp(std::move(r_ocpp)),
config(config){};

Everest::MqttProvider& mqtt;
Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<emptyImplBase> p_main;
const std::vector<std::unique_ptr<evse_managerIntf>> r_evse_manager;
const std::vector<std::unique_ptr<ocppIntf>> r_ocpp;
Expand Down
4 changes: 3 additions & 1 deletion modules/Auth/Auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ struct Conf {
class Auth : public Everest::ModuleBase {
public:
Auth() = delete;
Auth(const ModuleInfo& info, std::unique_ptr<authImplBase> p_main,
Auth(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor, std::unique_ptr<authImplBase> p_main,
std::unique_ptr<reservationImplBase> p_reservation,
std::vector<std::unique_ptr<auth_token_providerIntf>> r_token_provider,
std::vector<std::unique_ptr<auth_token_validatorIntf>> r_token_validator,
std::vector<std::unique_ptr<evse_managerIntf>> r_evse_manager, Conf& config) :
ModuleBase(info),
watchdog_supervisor(watchdog_supervisor),
p_main(std::move(p_main)),
p_reservation(std::move(p_reservation)),
r_token_provider(std::move(r_token_provider)),
r_token_validator(std::move(r_token_validator)),
r_evse_manager(std::move(r_evse_manager)),
config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<authImplBase> p_main;
const std::unique_ptr<reservationImplBase> p_reservation;
const std::vector<std::unique_ptr<auth_token_providerIntf>> r_token_provider;
Expand Down
1 change: 0 additions & 1 deletion modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ev_add_module(DummyTokenValidator)
ev_add_module(DummyTokenProvider)
ev_add_module(DummyTokenProviderManual)

add_subdirectory(deprecated)
add_subdirectory(examples)
add_subdirectory(simulation)

Expand Down
6 changes: 4 additions & 2 deletions modules/DPM1000/DPM1000.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ struct Conf {
class DPM1000 : public Everest::ModuleBase {
public:
DPM1000() = delete;
DPM1000(const ModuleInfo& info, std::unique_ptr<power_supply_DCImplBase> p_main, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), config(config){};
DPM1000(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<power_supply_DCImplBase> p_main, Conf& config) :
ModuleBase(info), watchdog_supervisor(watchdog_supervisor), p_main(std::move(p_main)), config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<power_supply_DCImplBase> p_main;
const Conf& config;

Expand Down
14 changes: 10 additions & 4 deletions modules/DummyTokenProvider/DummyTokenProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ struct Conf {};
class DummyTokenProvider : public Everest::ModuleBase {
public:
DummyTokenProvider() = delete;
DummyTokenProvider(const ModuleInfo& info, std::unique_ptr<auth_token_providerImplBase> p_main,
std::unique_ptr<evse_managerIntf> r_evse, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), r_evse(std::move(r_evse)), config(config){};

DummyTokenProvider(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<auth_token_providerImplBase> p_main, std::unique_ptr<evse_managerIntf> r_evse,
Conf& config) :
ModuleBase(info),
watchdog_supervisor(watchdog_supervisor),
p_main(std::move(p_main)),
r_evse(std::move(r_evse)),
config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<auth_token_providerImplBase> p_main;
const std::unique_ptr<evse_managerIntf> r_evse;
const Conf& config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ class DummyTokenProviderManual : public Everest::ModuleBase {
public:
DummyTokenProviderManual() = delete;
DummyTokenProviderManual(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider,
Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<auth_token_providerImplBase> p_main, Conf& config) :
ModuleBase(info), mqtt(mqtt_provider), p_main(std::move(p_main)), config(config){};
ModuleBase(info),
mqtt(mqtt_provider),
watchdog_supervisor(watchdog_supervisor),
p_main(std::move(p_main)),
config(config){};

Everest::MqttProvider& mqtt;
Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<auth_token_providerImplBase> p_main;
const Conf& config;

Expand Down
6 changes: 4 additions & 2 deletions modules/DummyTokenValidator/DummyTokenValidator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ struct Conf {};
class DummyTokenValidator : public Everest::ModuleBase {
public:
DummyTokenValidator() = delete;
DummyTokenValidator(const ModuleInfo& info, std::unique_ptr<auth_token_validatorImplBase> p_main, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), config(config){};
DummyTokenValidator(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<auth_token_validatorImplBase> p_main, Conf& config) :
ModuleBase(info), watchdog_supervisor(watchdog_supervisor), p_main(std::move(p_main)), config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<auth_token_validatorImplBase> p_main;
const Conf& config;

Expand Down
6 changes: 4 additions & 2 deletions modules/DummyV2G/DummyV2G.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ struct Conf {};
class DummyV2G : public Everest::ModuleBase {
public:
DummyV2G() = delete;
DummyV2G(const ModuleInfo& info, std::unique_ptr<ISO15118_chargerImplBase> p_main, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), config(config){};
DummyV2G(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<ISO15118_chargerImplBase> p_main, Conf& config) :
ModuleBase(info), watchdog_supervisor(watchdog_supervisor), p_main(std::move(p_main)), config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<ISO15118_chargerImplBase> p_main;
const Conf& config;

Expand Down
3 changes: 3 additions & 0 deletions modules/EnergyManager/EnergyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ void EnergyManager::ready() {

// start thread to update energy optimization
std::thread([this] {
auto watchdog = watchdog_supervisor.register_watchdog("Energy optimization thread",
std::chrono::seconds(config.update_interval * 10));
while (true) {
globals.init(date::utc_clock::now(), config.schedule_interval_duration, config.schedule_total_duration,
config.slice_ampere, config.slice_watt, config.debug, energy_flow_request);
auto optimized_values = run_optimizer(energy_flow_request);
enforce_limits(optimized_values);
sleep(config.update_interval);
watchdog();
}
}).detach();
}
Expand Down
14 changes: 10 additions & 4 deletions modules/EnergyManager/EnergyManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ struct Conf {
class EnergyManager : public Everest::ModuleBase {
public:
EnergyManager() = delete;
EnergyManager(const ModuleInfo& info, std::unique_ptr<energy_managerImplBase> p_main,
std::unique_ptr<energyIntf> r_energy_trunk, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), r_energy_trunk(std::move(r_energy_trunk)), config(config){};

EnergyManager(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<energy_managerImplBase> p_main, std::unique_ptr<energyIntf> r_energy_trunk,
Conf& config) :
ModuleBase(info),
watchdog_supervisor(watchdog_supervisor),
p_main(std::move(p_main)),
r_energy_trunk(std::move(r_energy_trunk)),
config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<energy_managerImplBase> p_main;
const std::unique_ptr<energyIntf> r_energy_trunk;
const Conf& config;
Expand Down
5 changes: 4 additions & 1 deletion modules/EnergyNode/EnergyNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ struct Conf {
class EnergyNode : public Everest::ModuleBase {
public:
EnergyNode() = delete;
EnergyNode(const ModuleInfo& info, std::unique_ptr<energyImplBase> p_energy_grid,
EnergyNode(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<energyImplBase> p_energy_grid,
std::unique_ptr<external_energy_limitsImplBase> p_external_limits,
std::vector<std::unique_ptr<energyIntf>> r_energy_consumer,
std::vector<std::unique_ptr<powermeterIntf>> r_powermeter,
std::vector<std::unique_ptr<energy_price_informationIntf>> r_price_information, Conf& config) :
ModuleBase(info),
watchdog_supervisor(watchdog_supervisor),
p_energy_grid(std::move(p_energy_grid)),
p_external_limits(std::move(p_external_limits)),
r_energy_consumer(std::move(r_energy_consumer)),
r_powermeter(std::move(r_powermeter)),
r_price_information(std::move(r_price_information)),
config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<energyImplBase> p_energy_grid;
const std::unique_ptr<external_energy_limitsImplBase> p_external_limits;
const std::vector<std::unique_ptr<energyIntf>> r_energy_consumer;
Expand Down
1 change: 0 additions & 1 deletion modules/EvSlac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ target_link_libraries(${MODULE_NAME}
slac::io
slac::fsm::ev
)

# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

target_sources(${MODULE_NAME}
Expand Down
6 changes: 4 additions & 2 deletions modules/EvSlac/EvSlac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ struct Conf {};
class EvSlac : public Everest::ModuleBase {
public:
EvSlac() = delete;
EvSlac(const ModuleInfo& info, std::unique_ptr<ev_slacImplBase> p_main, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), config(config){};
EvSlac(const ModuleInfo& info, Everest::WatchdogSupervisor& watchdog_supervisor,
std::unique_ptr<ev_slacImplBase> p_main, Conf& config) :
ModuleBase(info), watchdog_supervisor(watchdog_supervisor), p_main(std::move(p_main)), config(config){};

Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<ev_slacImplBase> p_main;
const Conf& config;

Expand Down
26 changes: 16 additions & 10 deletions modules/EvseManager/Charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
namespace module {

Charger::Charger(const std::unique_ptr<IECStateMachine>& bsp, const std::unique_ptr<ErrorHandling>& error_handling,
const types::evse_board_support::Connector_type& connector_type) :
bsp(bsp), error_handling(error_handling), connector_type(connector_type) {

#ifdef EVEREST_USE_BACKTRACES
Everest::install_backtrace_handler();
#endif

shared_context.connector_enabled = true;
shared_context.max_current = 6.0;
const types::evse_board_support::Connector_type& connector_type,
Everest::WatchdogSupervisor& _watchdog_supervisor) :
bsp(bsp),
error_handling(error_handling),
connector_type(connector_type),
watchdog_supervisor(_watchdog_supervisor) {

connectorEnabled = true;
maxCurrent = 6.0;
if (connector_type == types::evse_board_support::Connector_type::IEC62196Type2Socket) {
shared_context.max_current_cable = bsp->read_pp_ampacity();
}
Expand Down Expand Up @@ -82,7 +82,11 @@ Charger::~Charger() {
pwm_F();
}

void Charger::main_thread() {
void Charger::mainThread() {

// Register our watchdog for the main loop thread
auto watchdog = watchdog_supervisor.register_watchdog("Charger main loop", std::chrono::seconds(5));

// Enable CP output
bsp->enable(true);

Expand All @@ -105,6 +109,8 @@ void Charger::main_thread() {
// to be done on regular intervals independent from events)
run_state_machine();
}

watchdog();
}
}

Expand Down
6 changes: 5 additions & 1 deletion modules/EvseManager/Charger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <queue>
#include <sigslot/signal.hpp>

#include <utils/watchdog.hpp>

#include "ErrorHandling.hpp"
#include "IECStateMachine.hpp"
#include "scoped_lock_timeout.hpp"
Expand All @@ -48,7 +50,8 @@ const std::string IEC62196Type2Socket = "IEC62196Type2Socket";
class Charger {
public:
Charger(const std::unique_ptr<IECStateMachine>& bsp, const std::unique_ptr<ErrorHandling>& error_handling,
const types::evse_board_support::Connector_type& connector_type);
const types::evse_board_support::Connector_type& connector_type,
Everest::WatchdogSupervisor& watchdog_supervisor);
~Charger();

enum class ChargeMode {
Expand Down Expand Up @@ -299,6 +302,7 @@ class Charger {
const std::unique_ptr<IECStateMachine>& bsp;
const std::unique_ptr<ErrorHandling>& error_handling;
const types::evse_board_support::Connector_type& connector_type;
Everest::WatchdogSupervisor& watchdog_supervisor;

// constants
static constexpr float CHARGER_ABSOLUTE_MAX_CURRENT{80.};
Expand Down
9 changes: 7 additions & 2 deletions modules/EvseManager/EvseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ void EvseManager::ready() {

hw_capabilities = r_bsp->call_get_hw_capabilities();

charger = std::unique_ptr<Charger>(new Charger(bsp, error_handling, hw_capabilities.connector_type));
charger =
std::unique_ptr<Charger>(new Charger(bsp, error_handling, hw_capabilities.connector_type, watchdog_supervisor));

if (r_connector_lock.size() > 0) {
bsp->signal_lock.connect([this]() { r_connector_lock[0]->call_lock(); });
Expand Down Expand Up @@ -743,8 +744,12 @@ void EvseManager::ready() {
}

telemetryThreadHandle = std::thread([this]() {
while (not telemetryThreadHandle.shouldExit()) {
auto watchdog = watchdog_supervisor.register_watchdog("Telemetry thread", std::chrono::seconds(20));

while (!telemetryThreadHandle.shouldExit()) {
sleep(10);
watchdog();

auto p = get_latest_powermeter_data_billing();
Everest::TelemetryMap telemetry_data{{"timestamp", p.timestamp},
{"type", "power_meter"},
Expand Down
6 changes: 4 additions & 2 deletions modules/EvseManager/EvseManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class EvseManager : public Everest::ModuleBase {
public:
EvseManager() = delete;
EvseManager(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, Everest::TelemetryProvider& telemetry,
std::unique_ptr<evse_managerImplBase> p_evse, std::unique_ptr<energyImplBase> p_energy_grid,
Everest::WatchdogSupervisor& watchdog_supervisor, std::unique_ptr<evse_managerImplBase> p_evse,
std::unique_ptr<energyImplBase> p_energy_grid,
std::unique_ptr<auth_token_providerImplBase> p_token_provider,
std::unique_ptr<evse_board_supportIntf> r_bsp, std::vector<std::unique_ptr<ac_rcdIntf>> r_ac_rcd,
std::vector<std::unique_ptr<connector_lockIntf>> r_connector_lock,
Expand All @@ -105,6 +106,7 @@ class EvseManager : public Everest::ModuleBase {
ModuleBase(info),
mqtt(mqtt_provider),
telemetry(telemetry),
watchdog_supervisor(watchdog_supervisor),
p_evse(std::move(p_evse)),
p_energy_grid(std::move(p_energy_grid)),
p_token_provider(std::move(p_token_provider)),
Expand All @@ -121,6 +123,7 @@ class EvseManager : public Everest::ModuleBase {

Everest::MqttProvider& mqtt;
Everest::TelemetryProvider& telemetry;
Everest::WatchdogSupervisor& watchdog_supervisor;
const std::unique_ptr<evse_managerImplBase> p_evse;
const std::unique_ptr<energyImplBase> p_energy_grid;
const std::unique_ptr<auth_token_providerImplBase> p_token_provider;
Expand Down Expand Up @@ -259,7 +262,6 @@ class EvseManager : public Everest::ModuleBase {
static constexpr auto CABLECHECK_CONTACTORS_CLOSE_TIMEOUT{std::chrono::seconds(5)};

std::atomic_bool current_demand_active{false};

// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};

Expand Down
1 change: 0 additions & 1 deletion modules/EvseManager/IECStateMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <sigslot/signal.hpp>

#include "Timeout.hpp"
#include "utils/thread.hpp"

#include "scoped_lock_timeout.hpp"

Expand Down
3 changes: 3 additions & 0 deletions modules/EvseManager/energy_grid/energyImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ void energyImpl::ready() {

// request energy every second
std::thread([this] {
auto watchdog = mod->watchdog_supervisor.register_watchdog("Energy request thread", std::chrono::seconds(10));

while (true) {
request_energy_from_energy_manager();
std::this_thread::sleep_for(std::chrono::seconds(1));
watchdog();
}
}).detach();

Expand Down
6 changes: 5 additions & 1 deletion modules/EvseSecurity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ target_link_libraries(${MODULE_NAME}
PRIVATE
everest::evse_security
)

target_sources(${MODULE_NAME}
PRIVATE
"conversions.cpp"
)
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

target_sources(${MODULE_NAME}
PRIVATE
"main/evse_securityImpl.cpp"
"conversions.cpp"
)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
Expand Down
Loading
Loading