From 18918e08b4d472998bb55fe032dacab9a0c7ed77 Mon Sep 17 00:00:00 2001 From: pietfried Date: Thu, 2 Mar 2023 11:40:52 +0100 Subject: [PATCH] - moved execution of run function of state machine to charge_point start() - catching exception if state machine event could not be submitted successfully Signed-off-by: pietfried --- lib/ocpp/v16/charge_point.cpp | 18 +++++++++--------- lib/ocpp/v16/charge_point_state_machine.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/ocpp/v16/charge_point.cpp b/lib/ocpp/v16/charge_point.cpp index d3b6f9f65..59fcc84f1 100644 --- a/lib/ocpp/v16/charge_point.cpp +++ b/lib/ocpp/v16/charge_point.cpp @@ -47,10 +47,9 @@ ChargePoint::ChargePoint(const json& config, const std::string& share_path, cons bool log_to_html = std::find(log_formats.begin(), log_formats.end(), "html") != log_formats.end(); bool session_logging = std::find(log_formats.begin(), log_formats.end(), "session_logging") != log_formats.end(); - this->logging = std::make_shared(this->configuration->getLogMessages(), message_log_path, - DateTime().to_rfc3339(), log_to_console, - detailed_log_to_console, log_to_file, log_to_html, - session_logging); + this->logging = std::make_shared( + this->configuration->getLogMessages(), message_log_path, DateTime().to_rfc3339(), log_to_console, + detailed_log_to_console, log_to_file, log_to_html, session_logging); this->boot_notification_timer = std::make_unique(&this->io_service, [this]() { this->boot_notification(); }); @@ -593,6 +592,12 @@ void ChargePoint::send_meter_value(int32_t connector, MeterValue meter_value) { } bool ChargePoint::start() { + auto connector_availability = this->database_handler->get_connector_availability(); + connector_availability[0] = AvailabilityType::Operative; // FIXME(kai): fix internal representation in charge + // point states, we need a different kind of state + // machine for connector 0 anyway (with reduced states) + this->status->run(connector_availability); + this->init_websocket(this->configuration->getSecurityProfile()); this->websocket->connect(this->configuration->getSecurityProfile()); this->boot_notification(); @@ -897,11 +902,6 @@ void ChargePoint::handleBootNotificationResponse(ocpp::CallResultupdate_clock_aligned_meter_values_interval(); - auto connector_availability = this->database_handler->get_connector_availability(); - connector_availability[0] = AvailabilityType::Operative; // FIXME(kai): fix internal representation in charge - // point states, we need a different kind of state - // machine for connector 0 anyway (with reduced states) - this->status->run(connector_availability); break; } case RegistrationStatus::Pending: diff --git a/lib/ocpp/v16/charge_point_state_machine.cpp b/lib/ocpp/v16/charge_point_state_machine.cpp index 68603025b..95148275b 100644 --- a/lib/ocpp/v16/charge_point_state_machine.cpp +++ b/lib/ocpp/v16/charge_point_state_machine.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -275,7 +276,11 @@ void ChargePointStates::run(std::map connector_a void ChargePointStates::submit_event(int32_t connector, const EventBaseType& event) { if (connector > 0 && connector < static_cast(this->state_machines.size())) { - this->state_machines.at(connector)->controller->submit_event(event); + try { + this->state_machines.at(connector)->controller->submit_event(event); + } catch (const std::exception &e) { + EVLOG_warning << "Could not submit event to state machine at connector# " << connector; + } } }