Skip to content

Commit

Permalink
OCPP2.0.1: Ensure individual firmware status notifications are sent o…
Browse files Browse the repository at this point in the history
…nce (#277)

Make firmware_status_id an optional and check its value in on_firmware_status_notification
Send InstallScheduled if firmware is to be installed during active transactions
Don't send same firmware update status notification with request_id = -1 multiple times as well

Signed-off-by: Kai-Uwe Hermann <[email protected]>
Co-authored-by: valentin-dimov <[email protected]>
  • Loading branch information
hikinggrass and valentin-dimov authored Dec 7, 2023
1 parent bb11e09 commit 775f02b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ class ChargePoint : ocpp::ChargingStationBase {
RegistrationStatusEnum registration_status;
OperationalStatusEnum operational_state;
FirmwareStatusEnum firmware_status;
int32_t firmware_status_id;
// The request ID in the last firmware update status received
std::optional<int32_t> firmware_status_id;
// The last firmware status which will be posted before the firmware is installed.
FirmwareStatusEnum firmware_status_before_installing = FirmwareStatusEnum::SignatureVerified;
UploadLogStatusEnum upload_log_status;
int32_t upload_log_status_id;
Expand Down
18 changes: 18 additions & 0 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ void ChargePoint::disconnect_websocket(websocketpp::close::status::value code) {

void ChargePoint::on_firmware_update_status_notification(int32_t request_id,
const FirmwareStatusEnum& firmware_update_status) {
if (this->firmware_status == firmware_update_status) {
if (request_id == -1 or
this->firmware_status_id.has_value() and this->firmware_status_id.value() == request_id) {
// already sent, do not send again
return;
}
}
FirmwareStatusNotificationRequest req;
req.status = firmware_update_status;
// Firmware status and id are stored for future trigger message request.
Expand Down Expand Up @@ -228,6 +235,17 @@ void ChargePoint::on_firmware_update_status_notification(int32_t request_id,
}

if (this->firmware_status_before_installing == req.status) {
// FIXME(Kai): This is a temporary workaround, because the EVerest System module does not keep track of
// transactions and can't inquire about their status from the OCPP modules. If the firmware status is expected
// to become "Installing", but we still have a transaction running, the update will wait for the transaction to
// finish, and so we send an "InstallScheduled" status. This is necessary for OCTT TC_L_15_CS to pass.
const auto transaction_active = this->any_transaction_active(std::nullopt);
if (transaction_active) {
this->firmware_status = FirmwareStatusEnum::InstallScheduled;
req.status = firmware_status;
ocpp::Call<FirmwareStatusNotificationRequest> call(req, this->message_queue->createMessageId());
this->send_async<FirmwareStatusNotificationRequest>(call);
}
this->change_all_connectors_to_unavailable_for_firmware_update();
}
}
Expand Down

0 comments on commit 775f02b

Please sign in to comment.