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
,
27 type GetConfigurationRequest
,
28 type GetConfigurationResponse
,
29 type GetDiagnosticsRequest
,
30 type GetDiagnosticsResponse
,
31 type IncomingRequestHandler
,
34 OCPP16AuthorizationStatus
,
35 type OCPP16AuthorizeRequest
,
36 type OCPP16AuthorizeResponse
,
37 OCPP16AvailabilityType
,
38 type OCPP16BootNotificationRequest
,
39 type OCPP16BootNotificationResponse
,
40 OCPP16ChargePointErrorCode
,
41 OCPP16ChargePointStatus
,
42 type OCPP16ChargingProfile
,
43 OCPP16ChargingProfilePurposeType
,
44 type OCPP16ChargingSchedule
,
45 type OCPP16ClearCacheRequest
,
46 type OCPP16DataTransferRequest
,
47 type OCPP16DataTransferResponse
,
48 OCPP16DataTransferStatus
,
49 OCPP16DataTransferVendorId
,
50 OCPP16DiagnosticsStatus
,
51 type OCPP16DiagnosticsStatusNotificationRequest
,
52 type OCPP16DiagnosticsStatusNotificationResponse
,
54 type OCPP16FirmwareStatusNotificationRequest
,
55 type OCPP16FirmwareStatusNotificationResponse
,
56 type OCPP16GetCompositeScheduleRequest
,
57 type OCPP16GetCompositeScheduleResponse
,
58 type OCPP16HeartbeatRequest
,
59 type OCPP16HeartbeatResponse
,
60 OCPP16IncomingRequestCommand
,
63 OCPP16StandardParametersKey
,
64 type OCPP16StartTransactionRequest
,
65 type OCPP16StartTransactionResponse
,
66 type OCPP16StatusNotificationRequest
,
67 type OCPP16StatusNotificationResponse
,
68 OCPP16StopTransactionReason
,
69 OCPP16SupportedFeatureProfiles
,
70 type OCPP16TriggerMessageRequest
,
71 type OCPP16TriggerMessageResponse
,
72 type OCPP16UpdateFirmwareRequest
,
73 type OCPP16UpdateFirmwareResponse
,
74 type OCPPConfigurationKey
,
76 type RemoteStartTransactionRequest
,
77 type RemoteStopTransactionRequest
,
79 type SetChargingProfileRequest
,
80 type SetChargingProfileResponse
,
81 type UnlockConnectorRequest
,
82 type UnlockConnectorResponse
,
83 } from
'../../../types';
84 import { Constants
, Utils
, logger
} from
'../../../utils';
85 import { OCPP16ServiceUtils
, OCPPConstants
, OCPPIncomingRequestService
} from
'../internal';
87 const moduleName
= 'OCPP16IncomingRequestService';
89 export class OCPP16IncomingRequestService
extends OCPPIncomingRequestService
{
90 protected jsonSchemas
: Map
<OCPP16IncomingRequestCommand
, JSONSchemaType
<JsonObject
>>;
91 private incomingRequestHandlers
: Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>;
93 public constructor() {
94 // if (new.target?.name === moduleName) {
95 // throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
97 super(OCPPVersion
.VERSION_16
);
98 this.incomingRequestHandlers
= new Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>([
99 [OCPP16IncomingRequestCommand
.RESET
, this.handleRequestReset
.bind(this)],
100 [OCPP16IncomingRequestCommand
.CLEAR_CACHE
, this.handleRequestClearCache
.bind(this)],
101 [OCPP16IncomingRequestCommand
.UNLOCK_CONNECTOR
, this.handleRequestUnlockConnector
.bind(this)],
103 OCPP16IncomingRequestCommand
.GET_CONFIGURATION
,
104 this.handleRequestGetConfiguration
.bind(this),
107 OCPP16IncomingRequestCommand
.CHANGE_CONFIGURATION
,
108 this.handleRequestChangeConfiguration
.bind(this),
111 OCPP16IncomingRequestCommand
.GET_COMPOSITE_SCHEDULE
,
112 this.handleRequestGetCompositeSchedule
.bind(this),
115 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
,
116 this.handleRequestSetChargingProfile
.bind(this),
119 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
,
120 this.handleRequestClearChargingProfile
.bind(this),
123 OCPP16IncomingRequestCommand
.CHANGE_AVAILABILITY
,
124 this.handleRequestChangeAvailability
.bind(this),
127 OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
,
128 this.handleRequestRemoteStartTransaction
.bind(this),
131 OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
,
132 this.handleRequestRemoteStopTransaction
.bind(this),
134 [OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
, this.handleRequestGetDiagnostics
.bind(this)],
135 [OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
, this.handleRequestTriggerMessage
.bind(this)],
136 [OCPP16IncomingRequestCommand
.DATA_TRANSFER
, this.handleRequestDataTransfer
.bind(this)],
137 [OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
, this.handleRequestUpdateFirmware
.bind(this)],
139 this.jsonSchemas
= new Map
<OCPP16IncomingRequestCommand
, JSONSchemaType
<JsonObject
>>([
141 OCPP16IncomingRequestCommand
.RESET
,
142 OCPP16ServiceUtils
.parseJsonSchemaFile
<ResetRequest
>(
143 '../../../assets/json-schemas/ocpp/1.6/Reset.json',
149 OCPP16IncomingRequestCommand
.CLEAR_CACHE
,
150 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16ClearCacheRequest
>(
151 '../../../assets/json-schemas/ocpp/1.6/ClearCache.json',
157 OCPP16IncomingRequestCommand
.UNLOCK_CONNECTOR
,
158 OCPP16ServiceUtils
.parseJsonSchemaFile
<UnlockConnectorRequest
>(
159 '../../../assets/json-schemas/ocpp/1.6/UnlockConnector.json',
165 OCPP16IncomingRequestCommand
.GET_CONFIGURATION
,
166 OCPP16ServiceUtils
.parseJsonSchemaFile
<GetConfigurationRequest
>(
167 '../../../assets/json-schemas/ocpp/1.6/GetConfiguration.json',
173 OCPP16IncomingRequestCommand
.CHANGE_CONFIGURATION
,
174 OCPP16ServiceUtils
.parseJsonSchemaFile
<ChangeConfigurationRequest
>(
175 '../../../assets/json-schemas/ocpp/1.6/ChangeConfiguration.json',
181 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
,
182 OCPP16ServiceUtils
.parseJsonSchemaFile
<GetDiagnosticsRequest
>(
183 '../../../assets/json-schemas/ocpp/1.6/GetDiagnostics.json',
189 OCPP16IncomingRequestCommand
.GET_COMPOSITE_SCHEDULE
,
190 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16GetCompositeScheduleRequest
>(
191 '../../../assets/json-schemas/ocpp/1.6/GetCompositeSchedule.json',
197 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
,
198 OCPP16ServiceUtils
.parseJsonSchemaFile
<SetChargingProfileRequest
>(
199 '../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json',
205 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
,
206 OCPP16ServiceUtils
.parseJsonSchemaFile
<ClearChargingProfileRequest
>(
207 '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json',
213 OCPP16IncomingRequestCommand
.CHANGE_AVAILABILITY
,
214 OCPP16ServiceUtils
.parseJsonSchemaFile
<ChangeAvailabilityRequest
>(
215 '../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json',
221 OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
,
222 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStartTransactionRequest
>(
223 '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json',
229 OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
,
230 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStopTransactionRequest
>(
231 '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json',
237 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
238 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16TriggerMessageRequest
>(
239 '../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json',
245 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
246 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16DataTransferRequest
>(
247 '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json',
253 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
,
254 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16UpdateFirmwareRequest
>(
255 '../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json',
261 this.validatePayload
.bind(this);
264 public async incomingRequestHandler(
265 chargingStation
: ChargingStation
,
267 commandName
: OCPP16IncomingRequestCommand
,
268 commandPayload
: JsonType
270 let response
: JsonType
;
272 chargingStation
.getOcppStrictCompliance() === true &&
273 chargingStation
.isInPendingState() === true &&
274 (commandName
=== OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
||
275 commandName
=== OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
)
278 ErrorType
.SECURITY_ERROR
,
279 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
283 )} while the charging station is in pending state on the central server`,
289 chargingStation
.isRegistered() === true ||
290 (chargingStation
.getOcppStrictCompliance() === false &&
291 chargingStation
.isInUnknownState() === true)
294 this.incomingRequestHandlers
.has(commandName
) === true &&
295 OCPP16ServiceUtils
.isIncomingRequestCommandSupported(chargingStation
, commandName
) === true
298 this.validatePayload(chargingStation
, commandName
, commandPayload
);
299 // Call the method to build the response
300 response
= await this.incomingRequestHandlers
.get(commandName
)(
307 `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: Handle incoming request error:`,
315 ErrorType
.NOT_IMPLEMENTED
,
316 `${commandName} is not implemented to handle request PDU ${JSON.stringify(
327 ErrorType
.SECURITY_ERROR
,
328 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
332 )} while the charging station is not registered on the central server.`,
337 // Send the built response
338 await chargingStation
.ocppRequestService
.sendResponse(
346 private validatePayload(
347 chargingStation
: ChargingStation
,
348 commandName
: OCPP16IncomingRequestCommand
,
349 commandPayload
: JsonType
351 if (this.jsonSchemas
.has(commandName
) === true) {
352 return this.validateIncomingRequestPayload(
355 this.jsonSchemas
.get(commandName
),
360 `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command '${commandName}' PDU validation`
365 // Simulate charging station restart
366 private handleRequestReset(
367 chargingStation
: ChargingStation
,
368 commandPayload
: ResetRequest
370 this.runInAsyncScope(
371 chargingStation
.reset
.bind(chargingStation
) as (
372 this: ChargingStation
,
376 `${commandPayload.type}Reset` as OCPP16StopTransactionReason
377 ).catch(Constants
.EMPTY_FUNCTION
);
379 `${chargingStation.logPrefix()} ${
381 } reset command received, simulating it. The station will be back online in ${Utils.formatDurationMilliSeconds(
382 chargingStation.stationInfo.resetTime
385 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
388 private async handleRequestUnlockConnector(
389 chargingStation
: ChargingStation
,
390 commandPayload
: UnlockConnectorRequest
391 ): Promise
<UnlockConnectorResponse
> {
392 const connectorId
= commandPayload
.connectorId
;
393 if (chargingStation
.connectors
.has(connectorId
) === false) {
395 `${chargingStation.logPrefix()} Trying to unlock a non existing connector Id ${connectorId.toString()}`
397 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
399 if (connectorId
=== 0) {
401 `${chargingStation.logPrefix()} Trying to unlock connector Id ${connectorId.toString()}`
403 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
405 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
406 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
408 OCPP16StopTransactionReason
.UNLOCK_COMMAND
410 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
411 return OCPPConstants
.OCPP_RESPONSE_UNLOCKED
;
413 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_FAILED
;
415 await chargingStation
.ocppRequestService
.requestHandler
<
416 OCPP16StatusNotificationRequest
,
417 OCPP16StatusNotificationResponse
418 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
420 status: OCPP16ChargePointStatus
.Available
,
421 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
423 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.Available
;
424 return OCPPConstants
.OCPP_RESPONSE_UNLOCKED
;
427 private handleRequestGetConfiguration(
428 chargingStation
: ChargingStation
,
429 commandPayload
: GetConfigurationRequest
430 ): GetConfigurationResponse
{
431 const configurationKey
: OCPPConfigurationKey
[] = [];
432 const unknownKey
: string[] = [];
433 if (Utils
.isUndefined(commandPayload
.key
) === true) {
434 for (const configuration
of chargingStation
.ocppConfiguration
.configurationKey
) {
435 if (Utils
.isUndefined(configuration
.visible
) === true) {
436 configuration
.visible
= true;
438 if (configuration
.visible
=== false) {
441 configurationKey
.push({
442 key
: configuration
.key
,
443 readonly: configuration
.readonly,
444 value
: configuration
.value
,
447 } else if (Utils
.isNotEmptyArray(commandPayload
.key
) === true) {
448 for (const key
of commandPayload
.key
) {
449 const keyFound
= ChargingStationConfigurationUtils
.getConfigurationKey(
455 if (Utils
.isUndefined(keyFound
.visible
) === true) {
456 keyFound
.visible
= true;
458 if (keyFound
.visible
=== false) {
461 configurationKey
.push({
463 readonly: keyFound
.readonly,
464 value
: keyFound
.value
,
467 unknownKey
.push(key
);
477 private handleRequestChangeConfiguration(
478 chargingStation
: ChargingStation
,
479 commandPayload
: ChangeConfigurationRequest
480 ): ChangeConfigurationResponse
{
481 const keyToChange
= ChargingStationConfigurationUtils
.getConfigurationKey(
487 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED
;
488 } else if (keyToChange
&& keyToChange
.readonly) {
489 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_REJECTED
;
490 } else if (keyToChange
&& !keyToChange
.readonly) {
491 let valueChanged
= false;
492 if (keyToChange
.value
!== commandPayload
.value
) {
493 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
496 commandPayload
.value
,
501 let triggerHeartbeatRestart
= false;
502 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartBeatInterval
&& valueChanged
) {
503 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
505 OCPP16StandardParametersKey
.HeartbeatInterval
,
508 triggerHeartbeatRestart
= true;
510 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartbeatInterval
&& valueChanged
) {
511 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
513 OCPP16StandardParametersKey
.HeartBeatInterval
,
516 triggerHeartbeatRestart
= true;
518 if (triggerHeartbeatRestart
) {
519 chargingStation
.restartHeartbeat();
521 if (keyToChange
.key
=== OCPP16StandardParametersKey
.WebSocketPingInterval
&& valueChanged
) {
522 chargingStation
.restartWebSocketPing();
524 if (keyToChange
.reboot
) {
525 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED
;
527 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_ACCEPTED
;
531 private handleRequestSetChargingProfile(
532 chargingStation
: ChargingStation
,
533 commandPayload
: SetChargingProfileRequest
534 ): SetChargingProfileResponse
{
536 OCPP16ServiceUtils
.checkFeatureProfile(
538 OCPP16SupportedFeatureProfiles
.SmartCharging
,
539 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
542 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED
;
544 if (chargingStation
.connectors
.has(commandPayload
.connectorId
) === false) {
546 `${chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${
547 commandPayload.connectorId
550 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
553 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
554 OCPP16ChargingProfilePurposeType
.CHARGE_POINT_MAX_PROFILE
&&
555 commandPayload
.connectorId
!== 0
557 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
560 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
561 OCPP16ChargingProfilePurposeType
.TX_PROFILE
&&
562 (commandPayload
.connectorId
=== 0 ||
563 chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.transactionStarted
===
567 `${chargingStation.logPrefix()} Trying to set transaction charging profile(s) on connector ${
568 commandPayload.connectorId
569 } without a started transaction`
571 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
573 OCPP16ServiceUtils
.setChargingProfile(
575 commandPayload
.connectorId
,
576 commandPayload
.csChargingProfiles
579 `${chargingStation.logPrefix()} Charging profile(s) set on connector id ${
580 commandPayload.connectorId
582 commandPayload
.csChargingProfiles
584 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
587 private handleRequestGetCompositeSchedule(
588 chargingStation
: ChargingStation
,
589 commandPayload
: OCPP16GetCompositeScheduleRequest
590 ): OCPP16GetCompositeScheduleResponse
{
592 OCPP16ServiceUtils
.checkFeatureProfile(
594 OCPP16SupportedFeatureProfiles
.SmartCharging
,
595 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
598 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
600 if (chargingStation
.connectors
.has(commandPayload
.connectorId
) === false) {
602 `${chargingStation.logPrefix()} Trying to get composite schedule to a non existing connector Id ${
603 commandPayload.connectorId
606 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
610 chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.chargingProfiles
613 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
615 const startDate
= new Date();
616 const endDate
= new Date(startDate
.getTime() + commandPayload
.duration
* 1000);
617 let compositeSchedule
: OCPP16ChargingSchedule
;
618 for (const chargingProfile
of chargingStation
.getConnectorStatus(commandPayload
.connectorId
)
620 // FIXME: build the composite schedule including the local power limit, the stack level, the charging rate unit, etc.
622 chargingProfile
.chargingSchedule
?.startSchedule
>= startDate
&&
623 chargingProfile
.chargingSchedule
?.startSchedule
<= endDate
625 compositeSchedule
= chargingProfile
.chargingSchedule
;
630 status: GenericStatus
.Accepted
,
631 scheduleStart
: compositeSchedule
?.startSchedule
,
632 connectorId
: commandPayload
.connectorId
,
633 chargingSchedule
: compositeSchedule
,
637 private handleRequestClearChargingProfile(
638 chargingStation
: ChargingStation
,
639 commandPayload
: ClearChargingProfileRequest
640 ): ClearChargingProfileResponse
{
642 OCPP16ServiceUtils
.checkFeatureProfile(
644 OCPP16SupportedFeatureProfiles
.SmartCharging
,
645 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
648 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
650 if (chargingStation
.connectors
.has(commandPayload
.connectorId
) === false) {
652 `${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${
653 commandPayload.connectorId
656 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
658 const connectorStatus
= chargingStation
.getConnectorStatus(commandPayload
.connectorId
);
660 !Utils
.isNullOrUndefined(commandPayload
.connectorId
) &&
661 Utils
.isNotEmptyArray(connectorStatus
?.chargingProfiles
)
663 connectorStatus
.chargingProfiles
= [];
665 `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${
666 commandPayload.connectorId
669 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
671 if (Utils
.isNullOrUndefined(commandPayload
.connectorId
)) {
672 let clearedCP
= false;
673 for (const connectorId
of chargingStation
.connectors
.keys()) {
675 Utils
.isNotEmptyArray(chargingStation
.getConnectorStatus(connectorId
)?.chargingProfiles
)
678 .getConnectorStatus(connectorId
)
679 ?.chargingProfiles
?.forEach((chargingProfile
: OCPP16ChargingProfile
, index
: number) => {
680 let clearCurrentCP
= false;
681 if (chargingProfile
.chargingProfileId
=== commandPayload
.id
) {
682 clearCurrentCP
= true;
685 !commandPayload
.chargingProfilePurpose
&&
686 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
688 clearCurrentCP
= true;
691 !chargingProfile
.stackLevel
&&
692 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
694 clearCurrentCP
= true;
697 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
&&
698 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
700 clearCurrentCP
= true;
702 if (clearCurrentCP
) {
703 connectorStatus
?.chargingProfiles
?.splice(index
, 1);
705 `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`,
714 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
717 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
720 private async handleRequestChangeAvailability(
721 chargingStation
: ChargingStation
,
722 commandPayload
: ChangeAvailabilityRequest
723 ): Promise
<ChangeAvailabilityResponse
> {
724 const connectorId
: number = commandPayload
.connectorId
;
725 if (chargingStation
.connectors
.has(connectorId
) === false) {
727 `${chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`
729 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
731 const chargePointStatus
: OCPP16ChargePointStatus
=
732 commandPayload
.type === OCPP16AvailabilityType
.OPERATIVE
733 ? OCPP16ChargePointStatus
.Available
734 : OCPP16ChargePointStatus
.Unavailable
;
735 if (connectorId
=== 0) {
736 let response
: ChangeAvailabilityResponse
= OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
737 for (const id
of chargingStation
.connectors
.keys()) {
738 if (chargingStation
.getConnectorStatus(id
)?.transactionStarted
=== true) {
739 response
= OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
741 chargingStation
.getConnectorStatus(id
).availability
= commandPayload
.type;
742 if (response
=== OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
) {
743 await chargingStation
.ocppRequestService
.requestHandler
<
744 OCPP16StatusNotificationRequest
,
745 OCPP16StatusNotificationResponse
746 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
748 status: chargePointStatus
,
749 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
751 chargingStation
.getConnectorStatus(id
).status = chargePointStatus
;
757 (chargingStation
.isChargingStationAvailable() === true ||
758 (chargingStation
.isChargingStationAvailable() === false &&
759 commandPayload
.type === OCPP16AvailabilityType
.INOPERATIVE
))
761 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
762 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
763 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
765 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
766 await chargingStation
.ocppRequestService
.requestHandler
<
767 OCPP16StatusNotificationRequest
,
768 OCPP16StatusNotificationResponse
769 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
771 status: chargePointStatus
,
772 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
774 chargingStation
.getConnectorStatus(connectorId
).status = chargePointStatus
;
775 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
777 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
780 private async handleRequestRemoteStartTransaction(
781 chargingStation
: ChargingStation
,
782 commandPayload
: RemoteStartTransactionRequest
783 ): Promise
<GenericResponse
> {
784 const transactionConnectorId
= commandPayload
.connectorId
;
785 if (chargingStation
.connectors
.has(transactionConnectorId
) === true) {
786 const remoteStartTransactionLogMsg
= `${chargingStation.logPrefix()} Transaction remotely STARTED on ${
787 chargingStation.stationInfo.chargingStationId
788 }#${transactionConnectorId.toString()} for idTag '${commandPayload.idTag}'`;
789 await chargingStation
.ocppRequestService
.requestHandler
<
790 OCPP16StatusNotificationRequest
,
791 OCPP16StatusNotificationResponse
792 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
793 connectorId
: transactionConnectorId
,
794 status: OCPP16ChargePointStatus
.Preparing
,
795 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
797 const connectorStatus
= chargingStation
.getConnectorStatus(transactionConnectorId
);
798 connectorStatus
.status = OCPP16ChargePointStatus
.Preparing
;
800 chargingStation
.isChargingStationAvailable() === true &&
801 chargingStation
.isConnectorAvailable(transactionConnectorId
) === true
803 // Check if authorized
804 if (chargingStation
.getAuthorizeRemoteTxRequests() === true) {
805 let authorized
= false;
807 chargingStation
.getLocalAuthListEnabled() === true &&
808 chargingStation
.hasIdTags() === true &&
809 Utils
.isNotEmptyString(
810 chargingStation
.idTagsCache
811 .getIdTags(ChargingStationUtils
.getIdTagsFile(chargingStation
.stationInfo
))
812 ?.find((idTag
) => idTag
=== commandPayload
.idTag
)
815 connectorStatus
.localAuthorizeIdTag
= commandPayload
.idTag
;
816 connectorStatus
.idTagLocalAuthorized
= true;
818 } else if (chargingStation
.getMustAuthorizeAtRemoteStart() === true) {
819 connectorStatus
.authorizeIdTag
= commandPayload
.idTag
;
820 const authorizeResponse
: OCPP16AuthorizeResponse
=
821 await chargingStation
.ocppRequestService
.requestHandler
<
822 OCPP16AuthorizeRequest
,
823 OCPP16AuthorizeResponse
824 >(chargingStation
, OCPP16RequestCommand
.AUTHORIZE
, {
825 idTag
: commandPayload
.idTag
,
827 if (authorizeResponse
?.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
832 `${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled`
835 if (authorized
=== true) {
836 // Authorization successful, start transaction
838 this.setRemoteStartTransactionChargingProfile(
840 transactionConnectorId
,
841 commandPayload
.chargingProfile
844 connectorStatus
.transactionRemoteStarted
= true;
847 await chargingStation
.ocppRequestService
.requestHandler
<
848 OCPP16StartTransactionRequest
,
849 OCPP16StartTransactionResponse
850 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
851 connectorId
: transactionConnectorId
,
852 idTag
: commandPayload
.idTag
,
854 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
856 logger
.debug(remoteStartTransactionLogMsg
);
857 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
859 return this.notifyRemoteStartTransactionRejected(
861 transactionConnectorId
,
865 return this.notifyRemoteStartTransactionRejected(
867 transactionConnectorId
,
871 return this.notifyRemoteStartTransactionRejected(
873 transactionConnectorId
,
877 // No authorization check required, start transaction
879 this.setRemoteStartTransactionChargingProfile(
881 transactionConnectorId
,
882 commandPayload
.chargingProfile
885 connectorStatus
.transactionRemoteStarted
= true;
888 await chargingStation
.ocppRequestService
.requestHandler
<
889 OCPP16StartTransactionRequest
,
890 OCPP16StartTransactionResponse
891 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
892 connectorId
: transactionConnectorId
,
893 idTag
: commandPayload
.idTag
,
895 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
897 logger
.debug(remoteStartTransactionLogMsg
);
898 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
900 return this.notifyRemoteStartTransactionRejected(
902 transactionConnectorId
,
906 return this.notifyRemoteStartTransactionRejected(
908 transactionConnectorId
,
912 return this.notifyRemoteStartTransactionRejected(
914 transactionConnectorId
,
918 return this.notifyRemoteStartTransactionRejected(
920 transactionConnectorId
,
925 private async notifyRemoteStartTransactionRejected(
926 chargingStation
: ChargingStation
,
929 ): Promise
<GenericResponse
> {
931 chargingStation
.getConnectorStatus(connectorId
)?.status !== OCPP16ChargePointStatus
.Available
933 await chargingStation
.ocppRequestService
.requestHandler
<
934 OCPP16StatusNotificationRequest
,
935 OCPP16StatusNotificationResponse
936 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
938 status: OCPP16ChargePointStatus
.Available
,
939 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
941 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.Available
;
944 `${chargingStation.logPrefix()} Remote starting transaction REJECTED on connector Id ${connectorId.toString()}, idTag '${idTag}', availability '${
945 chargingStation.getConnectorStatus(connectorId)?.availability
946 }', status '${chargingStation.getConnectorStatus(connectorId)?.status}'`
948 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
951 private setRemoteStartTransactionChargingProfile(
952 chargingStation
: ChargingStation
,
954 cp
: OCPP16ChargingProfile
956 if (cp
&& cp
.chargingProfilePurpose
=== OCPP16ChargingProfilePurposeType
.TX_PROFILE
) {
957 OCPP16ServiceUtils
.setChargingProfile(chargingStation
, connectorId
, cp
);
959 `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`,
963 } else if (cp
&& cp
.chargingProfilePurpose
!== OCPP16ChargingProfilePurposeType
.TX_PROFILE
) {
965 `${chargingStation.logPrefix()} Not allowed to set ${
966 cp.chargingProfilePurpose
967 } charging profile(s) at remote start transaction`
975 private async handleRequestRemoteStopTransaction(
976 chargingStation
: ChargingStation
,
977 commandPayload
: RemoteStopTransactionRequest
978 ): Promise
<GenericResponse
> {
979 const transactionId
= commandPayload
.transactionId
;
980 for (const connectorId
of chargingStation
.connectors
.keys()) {
983 chargingStation
.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
985 await chargingStation
.ocppRequestService
.requestHandler
<
986 OCPP16StatusNotificationRequest
,
987 OCPP16StatusNotificationResponse
988 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
990 status: OCPP16ChargePointStatus
.Finishing
,
991 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
993 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.Finishing
;
994 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
996 OCPP16StopTransactionReason
.REMOTE
998 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
999 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
1001 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
1005 `${chargingStation.logPrefix()} Trying to remote stop a non existing transaction ${transactionId.toString()}`
1007 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
1010 private handleRequestUpdateFirmware(
1011 chargingStation
: ChargingStation
,
1012 commandPayload
: OCPP16UpdateFirmwareRequest
1013 ): OCPP16UpdateFirmwareResponse
{
1015 OCPP16ServiceUtils
.checkFeatureProfile(
1017 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
1018 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
1022 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: feature profile not supported`
1024 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1027 !Utils
.isNullOrUndefined(chargingStation
.stationInfo
.firmwareStatus
) &&
1028 chargingStation
.stationInfo
.firmwareStatus
!== OCPP16FirmwareStatus
.Installed
1031 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`
1033 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1035 const retrieveDate
= Utils
.convertToDate(commandPayload
.retrieveDate
);
1036 const now
= Date.now();
1037 if (retrieveDate
?.getTime() <= now
) {
1038 this.runInAsyncScope(
1039 this.updateFirmwareSimulation
.bind(this) as (
1040 this: OCPP16IncomingRequestService
,
1045 ).catch(Constants
.EMPTY_FUNCTION
);
1048 this.updateFirmwareSimulation(chargingStation
).catch(Constants
.EMPTY_FUNCTION
);
1049 }, retrieveDate
?.getTime() - now
);
1051 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1054 private async updateFirmwareSimulation(
1055 chargingStation
: ChargingStation
,
1060 ChargingStationUtils
.checkChargingStation(chargingStation
, chargingStation
.logPrefix()) ===
1065 for (const connectorId
of chargingStation
.connectors
.keys()) {
1068 chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== false
1070 await chargingStation
.ocppRequestService
.requestHandler
<
1071 OCPP16StatusNotificationRequest
,
1072 OCPP16StatusNotificationResponse
1073 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
1075 status: OCPP16ChargePointStatus
.Unavailable
,
1076 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1078 chargingStation
.getConnectorStatus(connectorId
).status =
1079 OCPP16ChargePointStatus
.Unavailable
;
1082 await chargingStation
.ocppRequestService
.requestHandler
<
1083 OCPP16FirmwareStatusNotificationRequest
,
1084 OCPP16FirmwareStatusNotificationResponse
1085 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1086 status: OCPP16FirmwareStatus
.Downloading
,
1088 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloading
;
1090 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
===
1091 OCPP16FirmwareStatus
.DownloadFailed
1093 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1094 await chargingStation
.ocppRequestService
.requestHandler
<
1095 OCPP16FirmwareStatusNotificationRequest
,
1096 OCPP16FirmwareStatusNotificationResponse
1097 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1098 status: chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
,
1100 chargingStation
.stationInfo
.firmwareStatus
=
1101 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
;
1104 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1105 await chargingStation
.ocppRequestService
.requestHandler
<
1106 OCPP16FirmwareStatusNotificationRequest
,
1107 OCPP16FirmwareStatusNotificationResponse
1108 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1109 status: OCPP16FirmwareStatus
.Downloaded
,
1111 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloaded
;
1112 let wasTransactionsStarted
= false;
1113 let transactionsStarted
: boolean;
1116 for (const connectorId
of chargingStation
.connectors
.keys()) {
1119 chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true
1125 const waitTime
= 15 * 1000;
1127 `${chargingStation.logPrefix()} ${moduleName}.updateFirmwareSimulation: ${trxCount} transaction(s) in progress, waiting ${
1129 } seconds before continuing firmware update simulation`
1131 await Utils
.sleep(waitTime
);
1132 transactionsStarted
= true;
1133 wasTransactionsStarted
= true;
1135 for (const connectorId
of chargingStation
.connectors
.keys()) {
1138 chargingStation
.getConnectorStatus(connectorId
)?.status !==
1139 OCPP16ChargePointStatus
.Unavailable
1141 await chargingStation
.ocppRequestService
.requestHandler
<
1142 OCPP16StatusNotificationRequest
,
1143 OCPP16StatusNotificationResponse
1144 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
1146 status: OCPP16ChargePointStatus
.Unavailable
,
1147 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1149 chargingStation
.getConnectorStatus(connectorId
).status =
1150 OCPP16ChargePointStatus
.Unavailable
;
1153 transactionsStarted
= false;
1155 } while (transactionsStarted
);
1156 !wasTransactionsStarted
&&
1157 (await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000));
1159 ChargingStationUtils
.checkChargingStation(chargingStation
, chargingStation
.logPrefix()) ===
1164 await chargingStation
.ocppRequestService
.requestHandler
<
1165 OCPP16FirmwareStatusNotificationRequest
,
1166 OCPP16FirmwareStatusNotificationResponse
1167 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1168 status: OCPP16FirmwareStatus
.Installing
,
1170 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Installing
;
1172 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
===
1173 OCPP16FirmwareStatus
.InstallationFailed
1175 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1176 await chargingStation
.ocppRequestService
.requestHandler
<
1177 OCPP16FirmwareStatusNotificationRequest
,
1178 OCPP16FirmwareStatusNotificationResponse
1179 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1180 status: chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
,
1182 chargingStation
.stationInfo
.firmwareStatus
=
1183 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
;
1186 if (chargingStation
.stationInfo
?.firmwareUpgrade
?.reset
=== true) {
1187 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1188 await chargingStation
.reset(OCPP16StopTransactionReason
.REBOOT
);
1192 private async handleRequestGetDiagnostics(
1193 chargingStation
: ChargingStation
,
1194 commandPayload
: GetDiagnosticsRequest
1195 ): Promise
<GetDiagnosticsResponse
> {
1197 OCPP16ServiceUtils
.checkFeatureProfile(
1199 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
1200 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1204 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Cannot get diagnostics: feature profile not supported`
1206 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1208 const uri
= new URL(commandPayload
.location
);
1209 if (uri
.protocol
.startsWith('ftp:')) {
1210 let ftpClient
: Client
;
1213 .readdirSync(path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'))
1214 .filter((file
) => file
.endsWith('.log'))
1215 .map((file
) => path
.join('./', file
));
1216 const diagnosticsArchive
= `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`;
1217 tar
.create({ gzip
: true }, logFiles
).pipe(fs
.createWriteStream(diagnosticsArchive
));
1218 ftpClient
= new Client();
1219 const accessResponse
= await ftpClient
.access({
1221 ...(Utils
.isNotEmptyString(uri
.port
) && { port
: Utils
.convertToInt(uri
.port
) }),
1222 ...(Utils
.isNotEmptyString(uri
.username
) && { user
: uri
.username
}),
1223 ...(Utils
.isNotEmptyString(uri
.password
) && { password
: uri
.password
}),
1225 let uploadResponse
: FTPResponse
;
1226 if (accessResponse
.code
=== 220) {
1227 ftpClient
.trackProgress((info
) => {
1229 `${chargingStation.logPrefix()} ${
1231 } bytes transferred from diagnostics archive ${info.name}`
1233 chargingStation
.ocppRequestService
1235 OCPP16DiagnosticsStatusNotificationRequest
,
1236 OCPP16DiagnosticsStatusNotificationResponse
1237 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1238 status: OCPP16DiagnosticsStatus
.Uploading
,
1242 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
1243 OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
1249 uploadResponse
= await ftpClient
.uploadFrom(
1251 path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'),
1254 `${uri.pathname}${diagnosticsArchive}`
1256 if (uploadResponse
.code
=== 226) {
1257 await chargingStation
.ocppRequestService
.requestHandler
<
1258 OCPP16DiagnosticsStatusNotificationRequest
,
1259 OCPP16DiagnosticsStatusNotificationResponse
1260 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1261 status: OCPP16DiagnosticsStatus
.Uploaded
,
1266 return { fileName
: diagnosticsArchive
};
1268 throw new OCPPError(
1269 ErrorType
.GENERIC_ERROR
,
1270 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1271 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1273 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1276 throw new OCPPError(
1277 ErrorType
.GENERIC_ERROR
,
1278 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1279 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1281 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1284 await chargingStation
.ocppRequestService
.requestHandler
<
1285 OCPP16DiagnosticsStatusNotificationRequest
,
1286 OCPP16DiagnosticsStatusNotificationResponse
1287 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1288 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1293 return this.handleIncomingRequestError(
1295 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
,
1297 { errorResponse
: OCPPConstants
.OCPP_RESPONSE_EMPTY
}
1302 `${chargingStation.logPrefix()} Unsupported protocol ${
1304 } to transfer the diagnostic logs archive`
1306 await chargingStation
.ocppRequestService
.requestHandler
<
1307 OCPP16DiagnosticsStatusNotificationRequest
,
1308 OCPP16DiagnosticsStatusNotificationResponse
1309 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1310 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1312 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1316 private handleRequestTriggerMessage(
1317 chargingStation
: ChargingStation
,
1318 commandPayload
: OCPP16TriggerMessageRequest
1319 ): OCPP16TriggerMessageResponse
{
1321 !OCPP16ServiceUtils
.checkFeatureProfile(
1323 OCPP16SupportedFeatureProfiles
.RemoteTrigger
,
1324 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
1326 !OCPP16ServiceUtils
.isMessageTriggerSupported(
1328 commandPayload
.requestedMessage
1331 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1334 !OCPP16ServiceUtils
.isConnectorIdValid(
1336 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1337 commandPayload
.connectorId
1340 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
;
1343 switch (commandPayload
.requestedMessage
) {
1344 case OCPP16MessageTrigger
.BootNotification
:
1346 chargingStation
.ocppRequestService
1347 .requestHandler
<OCPP16BootNotificationRequest
, OCPP16BootNotificationResponse
>(
1349 OCPP16RequestCommand
.BOOT_NOTIFICATION
,
1350 chargingStation
.bootNotificationRequest
,
1351 { skipBufferingOnError
: true, triggerMessage
: true }
1353 .then((response
) => {
1354 chargingStation
.bootNotificationResponse
= response
;
1356 .catch(Constants
.EMPTY_FUNCTION
);
1357 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1358 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1359 case OCPP16MessageTrigger
.Heartbeat
:
1361 chargingStation
.ocppRequestService
1362 .requestHandler
<OCPP16HeartbeatRequest
, OCPP16HeartbeatResponse
>(
1364 OCPP16RequestCommand
.HEARTBEAT
,
1367 triggerMessage
: true,
1370 .catch(Constants
.EMPTY_FUNCTION
);
1371 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1372 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1373 case OCPP16MessageTrigger
.StatusNotification
:
1375 if (!Utils
.isNullOrUndefined(commandPayload
?.connectorId
)) {
1376 chargingStation
.ocppRequestService
1377 .requestHandler
<OCPP16StatusNotificationRequest
, OCPP16StatusNotificationResponse
>(
1379 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1381 connectorId
: commandPayload
.connectorId
,
1382 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1383 status: chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.status,
1386 triggerMessage
: true,
1389 .catch(Constants
.EMPTY_FUNCTION
);
1391 for (const connectorId
of chargingStation
.connectors
.keys()) {
1392 chargingStation
.ocppRequestService
1394 OCPP16StatusNotificationRequest
,
1395 OCPP16StatusNotificationResponse
1398 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1401 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1402 status: chargingStation
.getConnectorStatus(connectorId
)?.status,
1405 triggerMessage
: true,
1408 .catch(Constants
.EMPTY_FUNCTION
);
1411 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1412 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1414 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1417 return this.handleIncomingRequestError(
1419 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1421 { errorResponse
: OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
}
1426 private handleRequestDataTransfer(
1427 chargingStation
: ChargingStation
,
1428 commandPayload
: OCPP16DataTransferRequest
1429 ): OCPP16DataTransferResponse
{
1431 if (Object.values(OCPP16DataTransferVendorId
).includes(commandPayload
.vendorId
)) {
1433 status: OCPP16DataTransferStatus
.ACCEPTED
,
1437 status: OCPP16DataTransferStatus
.UNKNOWN_VENDOR_ID
,
1440 return this.handleIncomingRequestError(
1442 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
1444 { errorResponse
: OCPPConstants
.OCPP_DATA_TRANSFER_RESPONSE_REJECTED
}