Repository navigation
fix(ocpp): drive FirmwareStatusNotification trigger from last-sent notification (L01.FR.26) #1981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,6 +262,11 @@ const FIRMWARE_STAGE_FAILURE_STATUS = { | |
| install: OCPP20FirmwareStatusEnumType.InstallationFailed, | ||
| } as const satisfies Record<Exclude<FirmwareStage, 'installed'>, OCPP20FirmwareStatusEnumType> | ||
|
|
||
| interface LastFirmwareStatusNotification { | ||
| requestId: number | ||
| status: OCPP20FirmwareStatusEnumType | ||
| } | ||
|
|
||
| interface OCPP20StationState { | ||
| activeFirmwareUpdateAbortController?: AbortController | ||
| activeFirmwareUpdateRequestId?: number | ||
|
|
@@ -270,6 +275,7 @@ interface OCPP20StationState { | |
| activeLogUploadStatus?: UploadLogStatusEnumType | ||
| certSigningRetryManager?: OCPP20CertSigningRetryManager | ||
| isDrainingSecurityEvents: boolean | ||
| lastFirmwareStatusNotification?: LastFirmwareStatusNotification | ||
| preInoperativeConnectorStatuses: Map<number, OCPP20ConnectorStatusEnumType> | ||
| reportDataCache: Map<number, ReportDataType[]> | ||
| securityEventQueue: QueuedSecurityEvent[] | ||
|
|
@@ -574,22 +580,24 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { | |
| .catch(errorHandler) | ||
| break | ||
| case MessageTriggerEnumType.FirmwareStatusNotification: { | ||
| const stationState = this.stationsState.get(chargingStation) | ||
| const requestId = stationState?.activeFirmwareUpdateRequestId | ||
| const firmwareStatus = | ||
| requestId != null && this.hasFirmwareUpdateInProgress(chargingStation) | ||
| ? (chargingStation.stationInfo?.firmwareStatus as OCPP20FirmwareStatusEnumType) | ||
| : OCPP20FirmwareStatusEnumType.Idle | ||
| // L01.FR.25 & L02.FR.16 — last-sent = Installed → { status: Idle }. | ||
| // L01.FR.26 & L02.FR.17 — last-sent ≠ Installed → { requestId, status: <last-sent> }. | ||
| // L01.FR.20 & L02.FR.14 — requestId mandatory unless status = Idle. | ||
| // Fresh station (no notification ever sent): Idle (spec-silent precondition, | ||
| // consistent with FirmwareStatusEnumType.Idle §3.33 "trigger-only" restriction). | ||
| const lastSent = this.stationsState.get(chargingStation)?.lastFirmwareStatusNotification | ||
| const payload: OCPP20FirmwareStatusNotificationRequest = | ||
| lastSent == null || lastSent.status === OCPP20FirmwareStatusEnumType.Installed | ||
| ? { status: OCPP20FirmwareStatusEnumType.Idle } | ||
| : { requestId: lastSent.requestId, status: lastSent.status } | ||
| chargingStation.ocppRequestService | ||
| .requestHandler< | ||
| OCPP20FirmwareStatusNotificationRequest, | ||
| OCPP20FirmwareStatusNotificationResponse | ||
| >( | ||
| chargingStation, | ||
| OCPP20RequestCommand.FIRMWARE_STATUS_NOTIFICATION, | ||
| { requestId, status: firmwareStatus }, | ||
| { skipBufferingOnError: true, triggerMessage: true } | ||
| ) | ||
| >(chargingStation, OCPP20RequestCommand.FIRMWARE_STATUS_NOTIFICATION, payload, { | ||
| skipBufferingOnError: true, | ||
| triggerMessage: true, | ||
| }) | ||
| .catch(errorHandler) | ||
| break | ||
| } | ||
|
|
@@ -3537,6 +3545,12 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { | |
| if (chargingStation.stationInfo != null) { | ||
| chargingStation.stationInfo.firmwareStatus = status | ||
| } | ||
| // L01.FR.26 & L02.FR.17 last-sent projection: persistent source of truth for the | ||
| // trigger case, distinct from `stationInfo.firmwareStatus` (state-machine field reset by #1976). | ||
| this.getOrCreateStationState(chargingStation).lastFirmwareStatusNotification = { | ||
| requestId, | ||
| status, | ||
| } | ||
|
Comment on lines
+3550
to
+3553
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Informational — pre-existing, out of scope] Oracle H1: this persistence happens BEFORE the Pre-existing symmetry with the Follow-up candidate: move both assignments inside |
||
| return chargingStation.ocppRequestService.requestHandler< | ||
| OCPP20FirmwareStatusNotificationRequest, | ||
| OCPP20FirmwareStatusNotificationResponse | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic Error:
sendFirmwareStatusNotificationalways includesrequestIdin the outgoing OCPP message at line 3562, even whenstatusisOCPP20FirmwareStatusEnumType.Idle. Per L01.FR.20 (quoted in the PR description): "The field requestId in FirmwareStatusNotificationRequest is mandatory, unless status = Idle." No current internal caller passesIdle, but the lack of a guard means any future call withIdlewould silently send a spec-violating payload that also contradicts the trigger path which deliberately omitsrequestIdforIdle. Consider adding a payload guard analogous to the trigger-case logic so the method is always spec-compliant regardless of caller:Please provide feedback on the review comment by checking the appropriate box: