Skip to content

Commit

Permalink
-S
Browse files Browse the repository at this point in the history
use watchdogs in modules

Signed-off-by: Cornelius Claussen <[email protected]>
  • Loading branch information
corneliusclaussen committed Jan 26, 2024
1 parent b4bea2e commit 41410a4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
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
15 changes: 13 additions & 2 deletions modules/EvseManager/Charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
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) {
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) {
Expand Down Expand Up @@ -67,6 +72,10 @@ Charger::~Charger() {
}

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 @@ -89,6 +98,8 @@ void Charger::mainThread() {
// to be done on regular intervals independent from events)
runStateMachine();
}

watchdog();
}
}

Expand Down
7 changes: 6 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"

Expand All @@ -47,7 +49,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();

// Public interface to configure Charger
Expand Down Expand Up @@ -332,6 +335,8 @@ class Charger {
constexpr static int legacy_wakeup_timeout{30000};

void clear_errors_on_unplug();

Everest::WatchdogSupervisor& watchdog_supervisor;
};

#define CHARGER_ABSOLUTE_MAX_CURRENT double(80.0F)
Expand Down
7 changes: 6 additions & 1 deletion modules/EvseManager/EvseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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 @@ -729,8 +730,12 @@ void EvseManager::ready() {
}

telemetryThreadHandle = std::thread([this]() {
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
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"

namespace module {

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

0 comments on commit 41410a4

Please sign in to comment.