1 // Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
3 import fs from
'node:fs';
4 import path from
'node:path';
5 import { URL
, fileURLToPath
} from
'node:url';
7 import type { JSONSchemaType
} from
'ajv';
8 import { Client
, type FTPResponse
} from
'basic-ftp';
13 ChargingStationConfigurationUtils
,
15 } from
'../../../charging-station';
16 import { OCPPError
} from
'../../../exception';
18 type ChangeAvailabilityRequest
,
19 type ChangeAvailabilityResponse
,
20 type ChangeConfigurationRequest
,
21 type ChangeConfigurationResponse
,
22 type ClearChargingProfileRequest
,
23 type ClearChargingProfileResponse
,
28 type GetConfigurationRequest
,
29 type GetConfigurationResponse
,
30 type GetDiagnosticsRequest
,
31 type GetDiagnosticsResponse
,
32 type IncomingRequestHandler
,
35 OCPP16AuthorizationStatus
,
36 type OCPP16AuthorizeRequest
,
37 type OCPP16AuthorizeResponse
,
38 OCPP16AvailabilityType
,
39 type OCPP16BootNotificationRequest
,
40 type OCPP16BootNotificationResponse
,
41 OCPP16ChargePointErrorCode
,
42 OCPP16ChargePointStatus
,
43 type OCPP16ChargingProfile
,
44 OCPP16ChargingProfilePurposeType
,
45 type OCPP16ChargingSchedule
,
46 type OCPP16ClearCacheRequest
,
47 type OCPP16DataTransferRequest
,
48 type OCPP16DataTransferResponse
,
49 OCPP16DataTransferStatus
,
50 OCPP16DataTransferVendorId
,
51 OCPP16DiagnosticsStatus
,
52 type OCPP16DiagnosticsStatusNotificationRequest
,
53 type OCPP16DiagnosticsStatusNotificationResponse
,
55 type OCPP16FirmwareStatusNotificationRequest
,
56 type OCPP16FirmwareStatusNotificationResponse
,
57 type OCPP16GetCompositeScheduleRequest
,
58 type OCPP16GetCompositeScheduleResponse
,
59 type OCPP16HeartbeatRequest
,
60 type OCPP16HeartbeatResponse
,
61 OCPP16IncomingRequestCommand
,
64 OCPP16StandardParametersKey
,
65 type OCPP16StartTransactionRequest
,
66 type OCPP16StartTransactionResponse
,
67 type OCPP16StatusNotificationRequest
,
68 type OCPP16StatusNotificationResponse
,
69 OCPP16StopTransactionReason
,
70 OCPP16SupportedFeatureProfiles
,
71 type OCPP16TriggerMessageRequest
,
72 type OCPP16TriggerMessageResponse
,
73 type OCPP16UpdateFirmwareRequest
,
74 type OCPP16UpdateFirmwareResponse
,
75 type OCPPConfigurationKey
,
77 type RemoteStartTransactionRequest
,
78 type RemoteStopTransactionRequest
,
80 type SetChargingProfileRequest
,
81 type SetChargingProfileResponse
,
82 type UnlockConnectorRequest
,
83 type UnlockConnectorResponse
,
84 } from
'../../../types';
85 import { Constants
, Utils
, logger
} from
'../../../utils';
86 import { OCPP16Constants
, OCPP16ServiceUtils
, OCPPIncomingRequestService
} from
'../internal';
88 const moduleName
= 'OCPP16IncomingRequestService';
90 export class OCPP16IncomingRequestService
extends OCPPIncomingRequestService
{
91 protected jsonSchemas
: Map
<OCPP16IncomingRequestCommand
, JSONSchemaType
<JsonObject
>>;
92 private incomingRequestHandlers
: Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>;
94 public constructor() {
95 // if (new.target?.name === moduleName) {
96 // throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
98 super(OCPPVersion
.VERSION_16
);
99 this.incomingRequestHandlers
= new Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>([
100 [OCPP16IncomingRequestCommand
.RESET
, this.handleRequestReset
.bind(this)],
101 [OCPP16IncomingRequestCommand
.CLEAR_CACHE
, this.handleRequestClearCache
.bind(this)],
102 [OCPP16IncomingRequestCommand
.UNLOCK_CONNECTOR
, this.handleRequestUnlockConnector
.bind(this)],
104 OCPP16IncomingRequestCommand
.GET_CONFIGURATION
,
105 this.handleRequestGetConfiguration
.bind(this),
108 OCPP16IncomingRequestCommand
.CHANGE_CONFIGURATION
,
109 this.handleRequestChangeConfiguration
.bind(this),
112 OCPP16IncomingRequestCommand
.GET_COMPOSITE_SCHEDULE
,
113 this.handleRequestGetCompositeSchedule
.bind(this),
116 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
,
117 this.handleRequestSetChargingProfile
.bind(this),
120 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
,
121 this.handleRequestClearChargingProfile
.bind(this),
124 OCPP16IncomingRequestCommand
.CHANGE_AVAILABILITY
,
125 this.handleRequestChangeAvailability
.bind(this),
128 OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
,
129 this.handleRequestRemoteStartTransaction
.bind(this),
132 OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
,
133 this.handleRequestRemoteStopTransaction
.bind(this),
135 [OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
, this.handleRequestGetDiagnostics
.bind(this)],
136 [OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
, this.handleRequestTriggerMessage
.bind(this)],
137 [OCPP16IncomingRequestCommand
.DATA_TRANSFER
, this.handleRequestDataTransfer
.bind(this)],
138 [OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
, this.handleRequestUpdateFirmware
.bind(this)],
140 this.jsonSchemas
= new Map
<OCPP16IncomingRequestCommand
, JSONSchemaType
<JsonObject
>>([
142 OCPP16IncomingRequestCommand
.RESET
,
143 OCPP16ServiceUtils
.parseJsonSchemaFile
<ResetRequest
>(
144 '../../../assets/json-schemas/ocpp/1.6/Reset.json',
150 OCPP16IncomingRequestCommand
.CLEAR_CACHE
,
151 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16ClearCacheRequest
>(
152 '../../../assets/json-schemas/ocpp/1.6/ClearCache.json',
158 OCPP16IncomingRequestCommand
.UNLOCK_CONNECTOR
,
159 OCPP16ServiceUtils
.parseJsonSchemaFile
<UnlockConnectorRequest
>(
160 '../../../assets/json-schemas/ocpp/1.6/UnlockConnector.json',
166 OCPP16IncomingRequestCommand
.GET_CONFIGURATION
,
167 OCPP16ServiceUtils
.parseJsonSchemaFile
<GetConfigurationRequest
>(
168 '../../../assets/json-schemas/ocpp/1.6/GetConfiguration.json',
174 OCPP16IncomingRequestCommand
.CHANGE_CONFIGURATION
,
175 OCPP16ServiceUtils
.parseJsonSchemaFile
<ChangeConfigurationRequest
>(
176 '../../../assets/json-schemas/ocpp/1.6/ChangeConfiguration.json',
182 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
,
183 OCPP16ServiceUtils
.parseJsonSchemaFile
<GetDiagnosticsRequest
>(
184 '../../../assets/json-schemas/ocpp/1.6/GetDiagnostics.json',
190 OCPP16IncomingRequestCommand
.GET_COMPOSITE_SCHEDULE
,
191 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16GetCompositeScheduleRequest
>(
192 '../../../assets/json-schemas/ocpp/1.6/GetCompositeSchedule.json',
198 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
,
199 OCPP16ServiceUtils
.parseJsonSchemaFile
<SetChargingProfileRequest
>(
200 '../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json',
206 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
,
207 OCPP16ServiceUtils
.parseJsonSchemaFile
<ClearChargingProfileRequest
>(
208 '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json',
214 OCPP16IncomingRequestCommand
.CHANGE_AVAILABILITY
,
215 OCPP16ServiceUtils
.parseJsonSchemaFile
<ChangeAvailabilityRequest
>(
216 '../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json',
222 OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
,
223 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStartTransactionRequest
>(
224 '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json',
230 OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
,
231 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStopTransactionRequest
>(
232 '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json',
238 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
239 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16TriggerMessageRequest
>(
240 '../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json',
246 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
247 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16DataTransferRequest
>(
248 '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json',
254 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
,
255 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16UpdateFirmwareRequest
>(
256 '../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json',
262 this.validatePayload
= this.validatePayload
.bind(this) as (
263 chargingStation
: ChargingStation
,
264 commandName
: OCPP16IncomingRequestCommand
,
265 commandPayload
: JsonType
269 public async incomingRequestHandler(
270 chargingStation
: ChargingStation
,
272 commandName
: OCPP16IncomingRequestCommand
,
273 commandPayload
: JsonType
275 let response
: JsonType
;
277 chargingStation
.getOcppStrictCompliance() === true &&
278 chargingStation
.isInPendingState() === true &&
279 (commandName
=== OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
||
280 commandName
=== OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
)
283 ErrorType
.SECURITY_ERROR
,
284 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
288 )} while the charging station is in pending state on the central server`,
294 chargingStation
.isRegistered() === true ||
295 (chargingStation
.getOcppStrictCompliance() === false &&
296 chargingStation
.isInUnknownState() === true)
299 this.incomingRequestHandlers
.has(commandName
) === true &&
300 OCPP16ServiceUtils
.isIncomingRequestCommandSupported(chargingStation
, commandName
) === true
303 this.validatePayload(chargingStation
, commandName
, commandPayload
);
304 // Call the method to build the response
305 response
= await this.incomingRequestHandlers
.get(commandName
)(
312 `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: Handle incoming request error:`,
320 ErrorType
.NOT_IMPLEMENTED
,
321 `${commandName} is not implemented to handle request PDU ${JSON.stringify(
332 ErrorType
.SECURITY_ERROR
,
333 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
337 )} while the charging station is not registered on the central server.`,
342 // Send the built response
343 await chargingStation
.ocppRequestService
.sendResponse(
351 private validatePayload(
352 chargingStation
: ChargingStation
,
353 commandName
: OCPP16IncomingRequestCommand
,
354 commandPayload
: JsonType
356 if (this.jsonSchemas
.has(commandName
) === true) {
357 return this.validateIncomingRequestPayload(
360 this.jsonSchemas
.get(commandName
),
365 `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command '${commandName}' PDU validation`
370 // Simulate charging station restart
371 private handleRequestReset(
372 chargingStation
: ChargingStation
,
373 commandPayload
: ResetRequest
375 this.runInAsyncScope(
376 chargingStation
.reset
.bind(chargingStation
) as (
377 this: ChargingStation
,
381 `${commandPayload.type}Reset` as OCPP16StopTransactionReason
382 ).catch(Constants
.EMPTY_FUNCTION
);
384 `${chargingStation.logPrefix()} ${
386 } reset command received, simulating it. The station will be back online in ${Utils.formatDurationMilliSeconds(
387 chargingStation.stationInfo.resetTime
390 return OCPP16Constants
.OCPP_RESPONSE_ACCEPTED
;
393 private async handleRequestUnlockConnector(
394 chargingStation
: ChargingStation
,
395 commandPayload
: UnlockConnectorRequest
396 ): Promise
<UnlockConnectorResponse
> {
397 const connectorId
= commandPayload
.connectorId
;
398 if (chargingStation
.hasConnector(connectorId
) === false) {
400 `${chargingStation.logPrefix()} Trying to unlock a non existing connector id ${connectorId.toString()}`
402 return OCPP16Constants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
404 if (connectorId
=== 0) {
406 `${chargingStation.logPrefix()} Trying to unlock connector id ${connectorId.toString()}`
408 return OCPP16Constants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
410 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
411 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
413 OCPP16StopTransactionReason
.UNLOCK_COMMAND
415 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
416 return OCPP16Constants
.OCPP_RESPONSE_UNLOCKED
;
418 return OCPP16Constants
.OCPP_RESPONSE_UNLOCK_FAILED
;
420 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
423 OCPP16ChargePointStatus
.Available
425 return OCPP16Constants
.OCPP_RESPONSE_UNLOCKED
;
428 private handleRequestGetConfiguration(
429 chargingStation
: ChargingStation
,
430 commandPayload
: GetConfigurationRequest
431 ): GetConfigurationResponse
{
432 const configurationKey
: OCPPConfigurationKey
[] = [];
433 const unknownKey
: string[] = [];
434 if (Utils
.isUndefined(commandPayload
.key
) === true) {
435 for (const configuration
of chargingStation
.ocppConfiguration
.configurationKey
) {
436 if (Utils
.isUndefined(configuration
.visible
) === true) {
437 configuration
.visible
= true;
439 if (configuration
.visible
=== false) {
442 configurationKey
.push({
443 key
: configuration
.key
,
444 readonly: configuration
.readonly,
445 value
: configuration
.value
,
448 } else if (Utils
.isNotEmptyArray(commandPayload
.key
) === true) {
449 for (const key
of commandPayload
.key
) {
450 const keyFound
= ChargingStationConfigurationUtils
.getConfigurationKey(
456 if (Utils
.isUndefined(keyFound
.visible
) === true) {
457 keyFound
.visible
= true;
459 if (keyFound
.visible
=== false) {
462 configurationKey
.push({
464 readonly: keyFound
.readonly,
465 value
: keyFound
.value
,
468 unknownKey
.push(key
);
478 private handleRequestChangeConfiguration(
479 chargingStation
: ChargingStation
,
480 commandPayload
: ChangeConfigurationRequest
481 ): ChangeConfigurationResponse
{
482 const keyToChange
= ChargingStationConfigurationUtils
.getConfigurationKey(
488 return OCPP16Constants
.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED
;
489 } else if (keyToChange
?.readonly === true) {
490 return OCPP16Constants
.OCPP_CONFIGURATION_RESPONSE_REJECTED
;
491 } else if (keyToChange
?.readonly === false) {
492 let valueChanged
= false;
493 if (keyToChange
.value
!== commandPayload
.value
) {
494 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
497 commandPayload
.value
,
502 let triggerHeartbeatRestart
= false;
503 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartBeatInterval
&& valueChanged
) {
504 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
506 OCPP16StandardParametersKey
.HeartbeatInterval
,
509 triggerHeartbeatRestart
= true;
511 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartbeatInterval
&& valueChanged
) {
512 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
514 OCPP16StandardParametersKey
.HeartBeatInterval
,
517 triggerHeartbeatRestart
= true;
519 if (triggerHeartbeatRestart
) {
520 chargingStation
.restartHeartbeat();
522 if (keyToChange
.key
=== OCPP16StandardParametersKey
.WebSocketPingInterval
&& valueChanged
) {
523 chargingStation
.restartWebSocketPing();
525 if (keyToChange
.reboot
) {
526 return OCPP16Constants
.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED
;
528 return OCPP16Constants
.OCPP_CONFIGURATION_RESPONSE_ACCEPTED
;
532 private handleRequestSetChargingProfile(
533 chargingStation
: ChargingStation
,
534 commandPayload
: SetChargingProfileRequest
535 ): SetChargingProfileResponse
{
537 OCPP16ServiceUtils
.checkFeatureProfile(
539 OCPP16SupportedFeatureProfiles
.SmartCharging
,
540 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
543 return OCPP16Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED
;
545 if (chargingStation
.hasConnector(commandPayload
.connectorId
) === false) {
547 `${chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector id ${
548 commandPayload.connectorId
551 return OCPP16Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
554 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
555 OCPP16ChargingProfilePurposeType
.CHARGE_POINT_MAX_PROFILE
&&
556 commandPayload
.connectorId
!== 0
558 return OCPP16Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
561 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
562 OCPP16ChargingProfilePurposeType
.TX_PROFILE
&&
563 (commandPayload
.connectorId
=== 0 ||
564 chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.transactionStarted
===
568 `${chargingStation.logPrefix()} Trying to set transaction charging profile(s) on connector ${
569 commandPayload.connectorId
570 } without a started transaction`
572 return OCPP16Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
574 OCPP16ServiceUtils
.setChargingProfile(
576 commandPayload
.connectorId
,
577 commandPayload
.csChargingProfiles
580 `${chargingStation.logPrefix()} Charging profile(s) set on connector id ${
581 commandPayload.connectorId
583 commandPayload
.csChargingProfiles
585 return OCPP16Constants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
588 private handleRequestGetCompositeSchedule(
589 chargingStation
: ChargingStation
,
590 commandPayload
: OCPP16GetCompositeScheduleRequest
591 ): OCPP16GetCompositeScheduleResponse
{
593 OCPP16ServiceUtils
.checkFeatureProfile(
595 OCPP16SupportedFeatureProfiles
.SmartCharging
,
596 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
599 return OCPP16Constants
.OCPP_RESPONSE_REJECTED
;
601 if (chargingStation
.hasConnector(commandPayload
.connectorId
) === false) {
603 `${chargingStation.logPrefix()} Trying to get composite schedule to a non existing connector id ${
604 commandPayload.connectorId
607 return OCPP16Constants
.OCPP_RESPONSE_REJECTED
;
611 chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.chargingProfiles
614 return OCPP16Constants
.OCPP_RESPONSE_REJECTED
;
616 const startDate
= new Date();
617 const endDate
= new Date(startDate
.getTime() + commandPayload
.duration
* 1000);
618 let compositeSchedule
: OCPP16ChargingSchedule
;
619 for (const chargingProfile
of chargingStation
.getConnectorStatus(commandPayload
.connectorId
)
621 // FIXME: build the composite schedule including the local power limit, the stack level, the charging rate unit, etc.
623 chargingProfile
.chargingSchedule
?.startSchedule
>= startDate
&&
624 chargingProfile
.chargingSchedule
?.startSchedule
<= endDate
626 compositeSchedule
= chargingProfile
.chargingSchedule
;
631 status: GenericStatus
.Accepted
,
632 scheduleStart
: compositeSchedule
?.startSchedule
,
633 connectorId
: commandPayload
.connectorId
,
634 chargingSchedule
: compositeSchedule
,
638 private handleRequestClearChargingProfile(
639 chargingStation
: ChargingStation
,
640 commandPayload
: ClearChargingProfileRequest
641 ): ClearChargingProfileResponse
{
643 OCPP16ServiceUtils
.checkFeatureProfile(
645 OCPP16SupportedFeatureProfiles
.SmartCharging
,
646 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
649 return OCPP16Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
651 if (chargingStation
.hasConnector(commandPayload
.connectorId
) === false) {
653 `${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector id ${
654 commandPayload.connectorId
657 return OCPP16Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
660 !Utils
.isNullOrUndefined(commandPayload
.connectorId
) &&
661 Utils
.isNotEmptyArray(
662 chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.chargingProfiles
665 chargingStation
.getConnectorStatus(commandPayload
.connectorId
).chargingProfiles
= [];
667 `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${
668 commandPayload.connectorId
671 return OCPP16Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
673 if (Utils
.isNullOrUndefined(commandPayload
.connectorId
)) {
674 let clearedCP
= false;
675 const clearChargingProfiles
= (connectorStatus
: ConnectorStatus
) => {
676 if (Utils
.isNotEmptyArray(connectorStatus
?.chargingProfiles
)) {
677 connectorStatus
?.chargingProfiles
?.forEach(
678 (chargingProfile
: OCPP16ChargingProfile
, index
: number) => {
679 let clearCurrentCP
= false;
680 if (chargingProfile
.chargingProfileId
=== commandPayload
.id
) {
681 clearCurrentCP
= true;
684 !commandPayload
.chargingProfilePurpose
&&
685 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
687 clearCurrentCP
= true;
690 !chargingProfile
.stackLevel
&&
691 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
693 clearCurrentCP
= true;
696 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
&&
697 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
699 clearCurrentCP
= true;
701 if (clearCurrentCP
) {
702 connectorStatus
?.chargingProfiles
?.splice(index
, 1);
704 `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`,
713 if (chargingStation
.hasEvses
) {
714 for (const evseStatus
of chargingStation
.evses
.values()) {
715 for (const connectorStatus
of evseStatus
.connectors
.values()) {
716 clearChargingProfiles(connectorStatus
);
720 for (const connectorId
of chargingStation
.connectors
.keys()) {
721 clearChargingProfiles(chargingStation
.getConnectorStatus(connectorId
));
725 return OCPP16Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
728 return OCPP16Constants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
731 private async handleRequestChangeAvailability(
732 chargingStation
: ChargingStation
,
733 commandPayload
: ChangeAvailabilityRequest
734 ): Promise
<ChangeAvailabilityResponse
> {
735 const connectorId
: number = commandPayload
.connectorId
;
736 if (chargingStation
.hasConnector(connectorId
) === false) {
738 `${chargingStation.logPrefix()} Trying to change the availability of a non existing connector id ${connectorId.toString()}`
740 return OCPP16Constants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
742 const chargePointStatus
: OCPP16ChargePointStatus
=
743 commandPayload
.type === OCPP16AvailabilityType
.Operative
744 ? OCPP16ChargePointStatus
.Available
745 : OCPP16ChargePointStatus
.Unavailable
;
746 if (connectorId
=== 0) {
747 let response
: ChangeAvailabilityResponse
=
748 OCPP16Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
749 const changeAvailability
= async (id
: number, connectorStatus
: ConnectorStatus
) => {
750 if (connectorStatus
?.transactionStarted
=== true) {
751 response
= OCPP16Constants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
753 connectorStatus
.availability
= commandPayload
.type;
754 if (response
=== OCPP16Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
) {
755 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
762 if (chargingStation
.hasEvses
) {
763 for (const evseStatus
of chargingStation
.evses
.values()) {
764 for (const [id
, connectorStatus
] of evseStatus
.connectors
) {
765 await changeAvailability(id
, connectorStatus
);
769 for (const id
of chargingStation
.connectors
.keys()) {
770 await changeAvailability(id
, chargingStation
.getConnectorStatus(id
));
776 (chargingStation
.isChargingStationAvailable() === true ||
777 (chargingStation
.isChargingStationAvailable() === false &&
778 commandPayload
.type === OCPP16AvailabilityType
.Inoperative
))
780 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
781 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
782 return OCPP16Constants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
784 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
785 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
790 return OCPP16Constants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
792 return OCPP16Constants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
795 private async handleRequestRemoteStartTransaction(
796 chargingStation
: ChargingStation
,
797 commandPayload
: RemoteStartTransactionRequest
798 ): Promise
<GenericResponse
> {
799 const transactionConnectorId
= commandPayload
.connectorId
;
800 if (chargingStation
.hasConnector(transactionConnectorId
) === false) {
801 return this.notifyRemoteStartTransactionRejected(
803 transactionConnectorId
,
808 chargingStation
.isChargingStationAvailable() === false ||
809 chargingStation
.isConnectorAvailable(transactionConnectorId
) === false
811 return this.notifyRemoteStartTransactionRejected(
813 transactionConnectorId
,
817 const remoteStartTransactionLogMsg
= `${chargingStation.logPrefix()} Transaction remotely STARTED on ${
818 chargingStation.stationInfo.chargingStationId
819 }#${transactionConnectorId.toString()} for idTag '${commandPayload.idTag}'`;
820 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
822 transactionConnectorId
,
823 OCPP16ChargePointStatus
.Preparing
825 const connectorStatus
= chargingStation
.getConnectorStatus(transactionConnectorId
);
826 // Check if authorized
827 if (chargingStation
.getAuthorizeRemoteTxRequests() === true) {
828 let authorized
= false;
830 chargingStation
.getLocalAuthListEnabled() === true &&
831 chargingStation
.hasIdTags() === true &&
832 Utils
.isNotEmptyString(
833 chargingStation
.idTagsCache
834 .getIdTags(ChargingStationUtils
.getIdTagsFile(chargingStation
.stationInfo
))
835 ?.find((idTag
) => idTag
=== commandPayload
.idTag
)
838 connectorStatus
.localAuthorizeIdTag
= commandPayload
.idTag
;
839 connectorStatus
.idTagLocalAuthorized
= true;
841 } else if (chargingStation
.getMustAuthorizeAtRemoteStart() === true) {
842 connectorStatus
.authorizeIdTag
= commandPayload
.idTag
;
843 const authorizeResponse
: OCPP16AuthorizeResponse
=
844 await chargingStation
.ocppRequestService
.requestHandler
<
845 OCPP16AuthorizeRequest
,
846 OCPP16AuthorizeResponse
847 >(chargingStation
, OCPP16RequestCommand
.AUTHORIZE
, {
848 idTag
: commandPayload
.idTag
,
850 if (authorizeResponse
?.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
855 `${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled`
858 if (authorized
=== true) {
859 // Authorization successful, start transaction
861 this.setRemoteStartTransactionChargingProfile(
863 transactionConnectorId
,
864 commandPayload
.chargingProfile
867 connectorStatus
.transactionRemoteStarted
= true;
870 await chargingStation
.ocppRequestService
.requestHandler
<
871 OCPP16StartTransactionRequest
,
872 OCPP16StartTransactionResponse
873 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
874 connectorId
: transactionConnectorId
,
875 idTag
: commandPayload
.idTag
,
877 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
879 logger
.debug(remoteStartTransactionLogMsg
);
880 return OCPP16Constants
.OCPP_RESPONSE_ACCEPTED
;
882 return this.notifyRemoteStartTransactionRejected(
884 transactionConnectorId
,
888 return this.notifyRemoteStartTransactionRejected(
890 transactionConnectorId
,
894 return this.notifyRemoteStartTransactionRejected(
896 transactionConnectorId
,
900 // No authorization check required, start transaction
902 this.setRemoteStartTransactionChargingProfile(
904 transactionConnectorId
,
905 commandPayload
.chargingProfile
908 connectorStatus
.transactionRemoteStarted
= true;
911 await chargingStation
.ocppRequestService
.requestHandler
<
912 OCPP16StartTransactionRequest
,
913 OCPP16StartTransactionResponse
914 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
915 connectorId
: transactionConnectorId
,
916 idTag
: commandPayload
.idTag
,
918 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
920 logger
.debug(remoteStartTransactionLogMsg
);
921 return OCPP16Constants
.OCPP_RESPONSE_ACCEPTED
;
923 return this.notifyRemoteStartTransactionRejected(
925 transactionConnectorId
,
929 return this.notifyRemoteStartTransactionRejected(
931 transactionConnectorId
,
936 private async notifyRemoteStartTransactionRejected(
937 chargingStation
: ChargingStation
,
940 ): Promise
<GenericResponse
> {
942 chargingStation
.getConnectorStatus(connectorId
)?.status !== OCPP16ChargePointStatus
.Available
944 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
947 OCPP16ChargePointStatus
.Available
951 `${chargingStation.logPrefix()} Remote starting transaction REJECTED on connector id ${connectorId.toString()}, idTag '${idTag}', availability '${
952 chargingStation.getConnectorStatus(connectorId)?.availability
953 }', status '${chargingStation.getConnectorStatus(connectorId)?.status}'`
955 return OCPP16Constants
.OCPP_RESPONSE_REJECTED
;
958 private setRemoteStartTransactionChargingProfile(
959 chargingStation
: ChargingStation
,
961 cp
: OCPP16ChargingProfile
963 if (cp
&& cp
.chargingProfilePurpose
=== OCPP16ChargingProfilePurposeType
.TX_PROFILE
) {
964 OCPP16ServiceUtils
.setChargingProfile(chargingStation
, connectorId
, cp
);
966 `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`,
970 } else if (cp
&& cp
.chargingProfilePurpose
!== OCPP16ChargingProfilePurposeType
.TX_PROFILE
) {
972 `${chargingStation.logPrefix()} Not allowed to set ${
973 cp.chargingProfilePurpose
974 } charging profile(s) at remote start transaction`
982 private async handleRequestRemoteStopTransaction(
983 chargingStation
: ChargingStation
,
984 commandPayload
: RemoteStopTransactionRequest
985 ): Promise
<GenericResponse
> {
986 const transactionId
= commandPayload
.transactionId
;
987 const remoteStopTransaction
= async (connectorId
: number): Promise
<GenericResponse
> => {
988 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
991 OCPP16ChargePointStatus
.Finishing
993 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
995 OCPP16StopTransactionReason
.REMOTE
997 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
998 return OCPP16Constants
.OCPP_RESPONSE_ACCEPTED
;
1000 return OCPP16Constants
.OCPP_RESPONSE_REJECTED
;
1002 if (chargingStation
.hasEvses
) {
1003 for (const [evseId
, evseStatus
] of chargingStation
.evses
) {
1005 for (const [connectorId
, connectorStatus
] of evseStatus
.connectors
) {
1006 if (connectorStatus
.transactionId
=== transactionId
) {
1007 return remoteStopTransaction(connectorId
);
1013 for (const connectorId
of chargingStation
.connectors
.keys()) {
1016 chargingStation
.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
1018 return remoteStopTransaction(connectorId
);
1023 `${chargingStation.logPrefix()} Trying to remote stop a non existing transaction with id: ${transactionId.toString()}`
1025 return OCPP16Constants
.OCPP_RESPONSE_REJECTED
;
1028 private handleRequestUpdateFirmware(
1029 chargingStation
: ChargingStation
,
1030 commandPayload
: OCPP16UpdateFirmwareRequest
1031 ): OCPP16UpdateFirmwareResponse
{
1033 OCPP16ServiceUtils
.checkFeatureProfile(
1035 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
1036 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
1040 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: feature profile not supported`
1042 return OCPP16Constants
.OCPP_RESPONSE_EMPTY
;
1045 !Utils
.isNullOrUndefined(chargingStation
.stationInfo
.firmwareStatus
) &&
1046 chargingStation
.stationInfo
.firmwareStatus
!== OCPP16FirmwareStatus
.Installed
1049 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`
1051 return OCPP16Constants
.OCPP_RESPONSE_EMPTY
;
1053 const retrieveDate
= Utils
.convertToDate(commandPayload
.retrieveDate
);
1054 const now
= Date.now();
1055 if (retrieveDate
?.getTime() <= now
) {
1056 this.runInAsyncScope(
1057 this.updateFirmwareSimulation
.bind(this) as (
1058 this: OCPP16IncomingRequestService
,
1063 ).catch(Constants
.EMPTY_FUNCTION
);
1066 this.updateFirmwareSimulation(chargingStation
).catch(Constants
.EMPTY_FUNCTION
);
1067 }, retrieveDate
?.getTime() - now
);
1069 return OCPP16Constants
.OCPP_RESPONSE_EMPTY
;
1072 private async updateFirmwareSimulation(
1073 chargingStation
: ChargingStation
,
1078 ChargingStationUtils
.checkChargingStation(chargingStation
, chargingStation
.logPrefix()) ===
1083 if (chargingStation
.hasEvses
) {
1084 for (const [evseId
, evseStatus
] of chargingStation
.evses
) {
1086 for (const [connectorId
, connectorStatus
] of evseStatus
.connectors
) {
1087 if (connectorStatus
?.transactionStarted
=== false) {
1088 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
1091 OCPP16ChargePointStatus
.Unavailable
1098 for (const connectorId
of chargingStation
.connectors
.keys()) {
1101 chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== false
1103 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
1106 OCPP16ChargePointStatus
.Unavailable
1111 await chargingStation
.ocppRequestService
.requestHandler
<
1112 OCPP16FirmwareStatusNotificationRequest
,
1113 OCPP16FirmwareStatusNotificationResponse
1114 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1115 status: OCPP16FirmwareStatus
.Downloading
,
1117 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloading
;
1119 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
===
1120 OCPP16FirmwareStatus
.DownloadFailed
1122 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1123 await chargingStation
.ocppRequestService
.requestHandler
<
1124 OCPP16FirmwareStatusNotificationRequest
,
1125 OCPP16FirmwareStatusNotificationResponse
1126 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1127 status: chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
,
1129 chargingStation
.stationInfo
.firmwareStatus
=
1130 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
;
1133 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1134 await chargingStation
.ocppRequestService
.requestHandler
<
1135 OCPP16FirmwareStatusNotificationRequest
,
1136 OCPP16FirmwareStatusNotificationResponse
1137 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1138 status: OCPP16FirmwareStatus
.Downloaded
,
1140 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloaded
;
1141 let wasTransactionsStarted
= false;
1142 let transactionsStarted
: boolean;
1144 const runningTransactions
= chargingStation
.getNumberOfRunningTransactions();
1145 if (runningTransactions
> 0) {
1146 const waitTime
= 15 * 1000;
1148 `${chargingStation.logPrefix()} ${moduleName}.updateFirmwareSimulation: ${runningTransactions} transaction(s) in progress, waiting ${
1150 } seconds before continuing firmware update simulation`
1152 await Utils
.sleep(waitTime
);
1153 transactionsStarted
= true;
1154 wasTransactionsStarted
= true;
1156 if (chargingStation
.hasEvses
) {
1157 for (const [evseId
, evseStatus
] of chargingStation
.evses
) {
1159 for (const [connectorId
, connectorStatus
] of evseStatus
.connectors
) {
1160 if (connectorStatus
?.status !== OCPP16ChargePointStatus
.Unavailable
) {
1161 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
1164 OCPP16ChargePointStatus
.Unavailable
1171 for (const connectorId
of chargingStation
.connectors
.keys()) {
1174 chargingStation
.getConnectorStatus(connectorId
)?.status !==
1175 OCPP16ChargePointStatus
.Unavailable
1177 await OCPP16ServiceUtils
.sendAndSetConnectorStatus(
1180 OCPP16ChargePointStatus
.Unavailable
1185 transactionsStarted
= false;
1187 } while (transactionsStarted
);
1188 !wasTransactionsStarted
&&
1189 (await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000));
1191 ChargingStationUtils
.checkChargingStation(chargingStation
, chargingStation
.logPrefix()) ===
1196 await chargingStation
.ocppRequestService
.requestHandler
<
1197 OCPP16FirmwareStatusNotificationRequest
,
1198 OCPP16FirmwareStatusNotificationResponse
1199 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1200 status: OCPP16FirmwareStatus
.Installing
,
1202 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Installing
;
1204 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
===
1205 OCPP16FirmwareStatus
.InstallationFailed
1207 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1208 await chargingStation
.ocppRequestService
.requestHandler
<
1209 OCPP16FirmwareStatusNotificationRequest
,
1210 OCPP16FirmwareStatusNotificationResponse
1211 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1212 status: chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
,
1214 chargingStation
.stationInfo
.firmwareStatus
=
1215 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
;
1218 if (chargingStation
.stationInfo
?.firmwareUpgrade
?.reset
=== true) {
1219 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1220 await chargingStation
.reset(OCPP16StopTransactionReason
.REBOOT
);
1224 private async handleRequestGetDiagnostics(
1225 chargingStation
: ChargingStation
,
1226 commandPayload
: GetDiagnosticsRequest
1227 ): Promise
<GetDiagnosticsResponse
> {
1229 OCPP16ServiceUtils
.checkFeatureProfile(
1231 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
1232 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1236 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Cannot get diagnostics: feature profile not supported`
1238 return OCPP16Constants
.OCPP_RESPONSE_EMPTY
;
1240 const uri
= new URL(commandPayload
.location
);
1241 if (uri
.protocol
.startsWith('ftp:')) {
1242 let ftpClient
: Client
;
1245 .readdirSync(path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'))
1246 .filter((file
) => file
.endsWith('.log'))
1247 .map((file
) => path
.join('./', file
));
1248 const diagnosticsArchive
= `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`;
1249 tar
.create({ gzip
: true }, logFiles
).pipe(fs
.createWriteStream(diagnosticsArchive
));
1250 ftpClient
= new Client();
1251 const accessResponse
= await ftpClient
.access({
1253 ...(Utils
.isNotEmptyString(uri
.port
) && { port
: Utils
.convertToInt(uri
.port
) }),
1254 ...(Utils
.isNotEmptyString(uri
.username
) && { user
: uri
.username
}),
1255 ...(Utils
.isNotEmptyString(uri
.password
) && { password
: uri
.password
}),
1257 let uploadResponse
: FTPResponse
;
1258 if (accessResponse
.code
=== 220) {
1259 ftpClient
.trackProgress((info
) => {
1261 `${chargingStation.logPrefix()} ${
1263 } bytes transferred from diagnostics archive ${info.name}`
1265 chargingStation
.ocppRequestService
1267 OCPP16DiagnosticsStatusNotificationRequest
,
1268 OCPP16DiagnosticsStatusNotificationResponse
1269 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1270 status: OCPP16DiagnosticsStatus
.Uploading
,
1274 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
1275 OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
1281 uploadResponse
= await ftpClient
.uploadFrom(
1283 path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'),
1286 `${uri.pathname}${diagnosticsArchive}`
1288 if (uploadResponse
.code
=== 226) {
1289 await chargingStation
.ocppRequestService
.requestHandler
<
1290 OCPP16DiagnosticsStatusNotificationRequest
,
1291 OCPP16DiagnosticsStatusNotificationResponse
1292 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1293 status: OCPP16DiagnosticsStatus
.Uploaded
,
1298 return { fileName
: diagnosticsArchive
};
1300 throw new OCPPError(
1301 ErrorType
.GENERIC_ERROR
,
1302 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1303 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1305 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1308 throw new OCPPError(
1309 ErrorType
.GENERIC_ERROR
,
1310 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1311 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1313 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1316 await chargingStation
.ocppRequestService
.requestHandler
<
1317 OCPP16DiagnosticsStatusNotificationRequest
,
1318 OCPP16DiagnosticsStatusNotificationResponse
1319 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1320 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1325 return this.handleIncomingRequestError(
1327 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
,
1329 { errorResponse
: OCPP16Constants
.OCPP_RESPONSE_EMPTY
}
1334 `${chargingStation.logPrefix()} Unsupported protocol ${
1336 } to transfer the diagnostic logs archive`
1338 await chargingStation
.ocppRequestService
.requestHandler
<
1339 OCPP16DiagnosticsStatusNotificationRequest
,
1340 OCPP16DiagnosticsStatusNotificationResponse
1341 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1342 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1344 return OCPP16Constants
.OCPP_RESPONSE_EMPTY
;
1348 private handleRequestTriggerMessage(
1349 chargingStation
: ChargingStation
,
1350 commandPayload
: OCPP16TriggerMessageRequest
1351 ): OCPP16TriggerMessageResponse
{
1353 !OCPP16ServiceUtils
.checkFeatureProfile(
1355 OCPP16SupportedFeatureProfiles
.RemoteTrigger
,
1356 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
1358 !OCPP16ServiceUtils
.isMessageTriggerSupported(
1360 commandPayload
.requestedMessage
1363 return OCPP16Constants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1366 !OCPP16ServiceUtils
.isConnectorIdValid(
1368 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1369 commandPayload
.connectorId
1372 return OCPP16Constants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
;
1375 switch (commandPayload
.requestedMessage
) {
1376 case OCPP16MessageTrigger
.BootNotification
:
1378 chargingStation
.ocppRequestService
1379 .requestHandler
<OCPP16BootNotificationRequest
, OCPP16BootNotificationResponse
>(
1381 OCPP16RequestCommand
.BOOT_NOTIFICATION
,
1382 chargingStation
.bootNotificationRequest
,
1383 { skipBufferingOnError
: true, triggerMessage
: true }
1385 .then((response
) => {
1386 chargingStation
.bootNotificationResponse
= response
;
1388 .catch(Constants
.EMPTY_FUNCTION
);
1389 }, OCPP16Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1390 return OCPP16Constants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1391 case OCPP16MessageTrigger
.Heartbeat
:
1393 chargingStation
.ocppRequestService
1394 .requestHandler
<OCPP16HeartbeatRequest
, OCPP16HeartbeatResponse
>(
1396 OCPP16RequestCommand
.HEARTBEAT
,
1399 triggerMessage
: true,
1402 .catch(Constants
.EMPTY_FUNCTION
);
1403 }, OCPP16Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1404 return OCPP16Constants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1405 case OCPP16MessageTrigger
.StatusNotification
:
1407 if (!Utils
.isNullOrUndefined(commandPayload
?.connectorId
)) {
1408 chargingStation
.ocppRequestService
1409 .requestHandler
<OCPP16StatusNotificationRequest
, OCPP16StatusNotificationResponse
>(
1411 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1413 connectorId
: commandPayload
.connectorId
,
1414 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1415 status: chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.status,
1418 triggerMessage
: true,
1421 .catch(Constants
.EMPTY_FUNCTION
);
1423 // eslint-disable-next-line no-lonely-if
1424 if (chargingStation
.hasEvses
) {
1425 for (const evseStatus
of chargingStation
.evses
.values()) {
1426 for (const [connectorId
, connectorStatus
] of evseStatus
.connectors
) {
1427 chargingStation
.ocppRequestService
1429 OCPP16StatusNotificationRequest
,
1430 OCPP16StatusNotificationResponse
1433 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1436 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1437 status: connectorStatus
.status,
1440 triggerMessage
: true,
1443 .catch(Constants
.EMPTY_FUNCTION
);
1447 for (const connectorId
of chargingStation
.connectors
.keys()) {
1448 chargingStation
.ocppRequestService
1450 OCPP16StatusNotificationRequest
,
1451 OCPP16StatusNotificationResponse
1454 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1457 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1458 status: chargingStation
.getConnectorStatus(connectorId
)?.status,
1461 triggerMessage
: true,
1464 .catch(Constants
.EMPTY_FUNCTION
);
1468 }, OCPP16Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1469 return OCPP16Constants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1471 return OCPP16Constants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1474 return this.handleIncomingRequestError(
1476 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1478 { errorResponse
: OCPP16Constants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
}
1483 private handleRequestDataTransfer(
1484 chargingStation
: ChargingStation
,
1485 commandPayload
: OCPP16DataTransferRequest
1486 ): OCPP16DataTransferResponse
{
1488 if (Object.values(OCPP16DataTransferVendorId
).includes(commandPayload
.vendorId
)) {
1490 status: OCPP16DataTransferStatus
.ACCEPTED
,
1494 status: OCPP16DataTransferStatus
.UNKNOWN_VENDOR_ID
,
1497 return this.handleIncomingRequestError(
1499 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
1501 { errorResponse
: OCPP16Constants
.OCPP_DATA_TRANSFER_RESPONSE_REJECTED
}