Skip to content

Commit

Permalink
- moved execution of run function of state machine to charge_point st…
Browse files Browse the repository at this point in the history
…art()

- catching exception if state machine event could not be submitted successfully

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Mar 2, 2023
1 parent 54e2e97 commit 18918e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/ocpp/v16/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ocpp::MessageLogging>(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<ocpp::MessageLogging>(
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<Everest::SteadyTimer>(&this->io_service, [this]() { this->boot_notification(); });
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -897,11 +902,6 @@ void ChargePoint::handleBootNotificationResponse(ocpp::CallResult<BootNotificati
// activate clock aligned sampling of meter values
this->update_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:
Expand Down
7 changes: 6 additions & 1 deletion lib/ocpp/v16/charge_point_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stddef.h>
#include <stdexcept>
#include <utility>
#include <everest/logging.hpp>

#include <fsm/async.hpp>

Expand Down Expand Up @@ -275,7 +276,11 @@ void ChargePointStates::run(std::map<int32_t, v16::AvailabilityType> connector_a
void ChargePointStates::submit_event(int32_t connector, const EventBaseType& event) {

if (connector > 0 && connector < static_cast<int32_t>(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;
}
}
}

Expand Down

0 comments on commit 18918e0

Please sign in to comment.