Skip to content

Commit

Permalink
* Calling on_enabled and on_unavailable as part of connector_effectiv…
Browse files Browse the repository at this point in the history
…e_operative_status_changed_callback to synchronously update the state machine in libocpp. Async updates using Enabled and Disabled events lead to a race condition on boot and could result in StatusNotification.req that are not up to date

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Jan 17, 2024
1 parent 6f0d23d commit ba4d075
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions modules/OCPP201/OCPP201.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,23 +645,17 @@ void OCPP201::ready() {
}
};

// callbacks.change_cs_effective_availability_callback is left empty

callbacks.evse_effective_operative_status_changed_callback =
[this](const int32_t evse_id, const ocpp::v201::OperationalStatusEnum new_status) {
if (new_status == ocpp::v201::OperationalStatusEnum::Operative) {
this->r_evse_manager.at(evse_id - 1)->call_enable(0);
} else {
this->r_evse_manager.at(evse_id - 1)->call_disable(0);
}
};

callbacks.connector_effective_operative_status_changed_callback =
[this](const int32_t evse_id, const int32_t connector_id, const ocpp::v201::OperationalStatusEnum new_status) {
if (new_status == ocpp::v201::OperationalStatusEnum::Operative) {
this->r_evse_manager.at(evse_id - 1)->call_enable(connector_id);
if (this->r_evse_manager.at(evse_id - 1)->call_enable(connector_id)) {
this->charge_point->on_enabled(evse_id, connector_id);
}
} else {
this->r_evse_manager.at(evse_id - 1)->call_disable(connector_id);
if (this->r_evse_manager.at(evse_id - 1)->call_disable(connector_id)) {
this->charge_point->on_unavailable(evse_id, connector_id);
}
}
};

Expand Down Expand Up @@ -869,27 +863,12 @@ void OCPP201::ready() {
break;
}
case types::evse_manager::SessionEventEnum::Disabled: {
if (session_event.connector_id.has_value()) {
// A single connector was disabled
this->charge_point->set_connector_operative_status(
evse_id, connector_id, ocpp::v201::OperationalStatusEnum::Inoperative, false);
} else {
// A whole EVSE was disabled
this->charge_point->set_evse_operative_status(
evse_id, ocpp::v201::OperationalStatusEnum::Inoperative, false);
}
this->charge_point->on_unavailable(evse_id, connector_id);
break;
}
case types::evse_manager::SessionEventEnum::Enabled: {
if (session_event.connector_id.has_value()) {
// A single connector was enabled
this->charge_point->set_connector_operative_status(
evse_id, connector_id, ocpp::v201::OperationalStatusEnum::Operative, false);
} else {
// A whole EVSE was enabled
this->charge_point->set_evse_operative_status(evse_id, ocpp::v201::OperationalStatusEnum::Operative,
false);
}
// A single connector was enabled
this->charge_point->on_enabled(evse_id, connector_id);
break;
}
}
Expand Down

0 comments on commit ba4d075

Please sign in to comment.