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
,
26 type GetConfigurationRequest
,
27 type GetConfigurationResponse
,
28 type GetDiagnosticsRequest
,
29 type GetDiagnosticsResponse
,
30 type IncomingRequestHandler
,
33 OCPP16AuthorizationStatus
,
34 type OCPP16AuthorizeRequest
,
35 type OCPP16AuthorizeResponse
,
36 OCPP16AvailabilityType
,
37 type OCPP16BootNotificationRequest
,
38 type OCPP16BootNotificationResponse
,
39 OCPP16ChargePointErrorCode
,
40 OCPP16ChargePointStatus
,
41 type OCPP16ChargingProfile
,
42 OCPP16ChargingProfilePurposeType
,
43 type OCPP16ClearCacheRequest
,
44 type OCPP16DataTransferRequest
,
45 type OCPP16DataTransferResponse
,
46 OCPP16DataTransferStatus
,
47 OCPP16DataTransferVendorId
,
48 OCPP16DiagnosticsStatus
,
49 type OCPP16DiagnosticsStatusNotificationRequest
,
50 type OCPP16DiagnosticsStatusNotificationResponse
,
52 type OCPP16FirmwareStatusNotificationRequest
,
53 type OCPP16FirmwareStatusNotificationResponse
,
54 type OCPP16HeartbeatRequest
,
55 type OCPP16HeartbeatResponse
,
56 OCPP16IncomingRequestCommand
,
59 OCPP16StandardParametersKey
,
60 type OCPP16StartTransactionRequest
,
61 type OCPP16StartTransactionResponse
,
62 type OCPP16StatusNotificationRequest
,
63 type OCPP16StatusNotificationResponse
,
64 OCPP16StopTransactionReason
,
65 OCPP16SupportedFeatureProfiles
,
66 type OCPP16TriggerMessageRequest
,
67 type OCPP16TriggerMessageResponse
,
68 type OCPP16UpdateFirmwareRequest
,
69 type OCPP16UpdateFirmwareResponse
,
70 type OCPPConfigurationKey
,
72 type RemoteStartTransactionRequest
,
73 type RemoteStopTransactionRequest
,
75 type SetChargingProfileRequest
,
76 type SetChargingProfileResponse
,
77 type UnlockConnectorRequest
,
78 type UnlockConnectorResponse
,
79 } from
'../../../types';
80 import { Constants
, Utils
, logger
} from
'../../../utils';
81 import { OCPP16ServiceUtils
, OCPPConstants
, OCPPIncomingRequestService
} from
'../internal';
83 const moduleName
= 'OCPP16IncomingRequestService';
85 export class OCPP16IncomingRequestService
extends OCPPIncomingRequestService
{
86 protected jsonSchemas
: Map
<OCPP16IncomingRequestCommand
, JSONSchemaType
<JsonObject
>>;
87 private incomingRequestHandlers
: Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>;
89 public constructor() {
90 // if (new.target?.name === moduleName) {
91 // throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
93 super(OCPPVersion
.VERSION_16
);
94 this.incomingRequestHandlers
= new Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>([
95 [OCPP16IncomingRequestCommand
.RESET
, this.handleRequestReset
.bind(this)],
96 [OCPP16IncomingRequestCommand
.CLEAR_CACHE
, this.handleRequestClearCache
.bind(this)],
97 [OCPP16IncomingRequestCommand
.UNLOCK_CONNECTOR
, this.handleRequestUnlockConnector
.bind(this)],
99 OCPP16IncomingRequestCommand
.GET_CONFIGURATION
,
100 this.handleRequestGetConfiguration
.bind(this),
103 OCPP16IncomingRequestCommand
.CHANGE_CONFIGURATION
,
104 this.handleRequestChangeConfiguration
.bind(this),
107 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
,
108 this.handleRequestSetChargingProfile
.bind(this),
111 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
,
112 this.handleRequestClearChargingProfile
.bind(this),
115 OCPP16IncomingRequestCommand
.CHANGE_AVAILABILITY
,
116 this.handleRequestChangeAvailability
.bind(this),
119 OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
,
120 this.handleRequestRemoteStartTransaction
.bind(this),
123 OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
,
124 this.handleRequestRemoteStopTransaction
.bind(this),
126 [OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
, this.handleRequestGetDiagnostics
.bind(this)],
127 [OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
, this.handleRequestTriggerMessage
.bind(this)],
128 [OCPP16IncomingRequestCommand
.DATA_TRANSFER
, this.handleRequestDataTransfer
.bind(this)],
129 [OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
, this.handleRequestUpdateFirmware
.bind(this)],
131 this.jsonSchemas
= new Map
<OCPP16IncomingRequestCommand
, JSONSchemaType
<JsonObject
>>([
133 OCPP16IncomingRequestCommand
.RESET
,
134 OCPP16ServiceUtils
.parseJsonSchemaFile
<ResetRequest
>(
135 '../../../assets/json-schemas/ocpp/1.6/Reset.json',
141 OCPP16IncomingRequestCommand
.CLEAR_CACHE
,
142 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16ClearCacheRequest
>(
143 '../../../assets/json-schemas/ocpp/1.6/ClearCache.json',
149 OCPP16IncomingRequestCommand
.UNLOCK_CONNECTOR
,
150 OCPP16ServiceUtils
.parseJsonSchemaFile
<UnlockConnectorRequest
>(
151 '../../../assets/json-schemas/ocpp/1.6/UnlockConnector.json',
157 OCPP16IncomingRequestCommand
.GET_CONFIGURATION
,
158 OCPP16ServiceUtils
.parseJsonSchemaFile
<GetConfigurationRequest
>(
159 '../../../assets/json-schemas/ocpp/1.6/GetConfiguration.json',
165 OCPP16IncomingRequestCommand
.CHANGE_CONFIGURATION
,
166 OCPP16ServiceUtils
.parseJsonSchemaFile
<ChangeConfigurationRequest
>(
167 '../../../assets/json-schemas/ocpp/1.6/ChangeConfiguration.json',
173 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
,
174 OCPP16ServiceUtils
.parseJsonSchemaFile
<GetDiagnosticsRequest
>(
175 '../../../assets/json-schemas/ocpp/1.6/GetDiagnostics.json',
181 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
,
182 OCPP16ServiceUtils
.parseJsonSchemaFile
<SetChargingProfileRequest
>(
183 '../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json',
189 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
,
190 OCPP16ServiceUtils
.parseJsonSchemaFile
<ClearChargingProfileRequest
>(
191 '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json',
197 OCPP16IncomingRequestCommand
.CHANGE_AVAILABILITY
,
198 OCPP16ServiceUtils
.parseJsonSchemaFile
<ChangeAvailabilityRequest
>(
199 '../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json',
205 OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
,
206 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStartTransactionRequest
>(
207 '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json',
213 OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
,
214 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStopTransactionRequest
>(
215 '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json',
221 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
222 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16TriggerMessageRequest
>(
223 '../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json',
229 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
230 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16DataTransferRequest
>(
231 '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json',
237 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
,
238 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16UpdateFirmwareRequest
>(
239 '../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json',
245 this.validatePayload
.bind(this);
248 public async incomingRequestHandler(
249 chargingStation
: ChargingStation
,
251 commandName
: OCPP16IncomingRequestCommand
,
252 commandPayload
: JsonType
254 let response
: JsonType
;
256 chargingStation
.getOcppStrictCompliance() === true &&
257 chargingStation
.isInPendingState() === true &&
258 (commandName
=== OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
||
259 commandName
=== OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
)
262 ErrorType
.SECURITY_ERROR
,
263 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
267 )} while the charging station is in pending state on the central server`,
273 chargingStation
.isRegistered() === true ||
274 (chargingStation
.getOcppStrictCompliance() === false &&
275 chargingStation
.isInUnknownState() === true)
278 this.incomingRequestHandlers
.has(commandName
) === true &&
279 OCPP16ServiceUtils
.isIncomingRequestCommandSupported(chargingStation
, commandName
) === true
282 this.validatePayload(chargingStation
, commandName
, commandPayload
);
283 // Call the method to build the response
284 response
= await this.incomingRequestHandlers
.get(commandName
)(
291 `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: Handle incoming request error:`,
299 ErrorType
.NOT_IMPLEMENTED
,
300 `${commandName} is not implemented to handle request PDU ${JSON.stringify(
311 ErrorType
.SECURITY_ERROR
,
312 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
316 )} while the charging station is not registered on the central server.`,
321 // Send the built response
322 await chargingStation
.ocppRequestService
.sendResponse(
330 private validatePayload(
331 chargingStation
: ChargingStation
,
332 commandName
: OCPP16IncomingRequestCommand
,
333 commandPayload
: JsonType
335 if (this.jsonSchemas
.has(commandName
) === true) {
336 return this.validateIncomingRequestPayload(
339 this.jsonSchemas
.get(commandName
),
344 `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command '${commandName}' PDU validation`
349 // Simulate charging station restart
350 private handleRequestReset(
351 chargingStation
: ChargingStation
,
352 commandPayload
: ResetRequest
354 this.runInAsyncScope(
355 chargingStation
.reset
.bind(chargingStation
) as (
356 this: ChargingStation
,
360 `${commandPayload.type}Reset` as OCPP16StopTransactionReason
361 ).catch(Constants
.EMPTY_FUNCTION
);
363 `${chargingStation.logPrefix()} ${
365 } reset command received, simulating it. The station will be back online in ${Utils.formatDurationMilliSeconds(
366 chargingStation.stationInfo.resetTime
369 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
372 private async handleRequestUnlockConnector(
373 chargingStation
: ChargingStation
,
374 commandPayload
: UnlockConnectorRequest
375 ): Promise
<UnlockConnectorResponse
> {
376 const connectorId
= commandPayload
.connectorId
;
377 if (chargingStation
.connectors
.has(connectorId
) === false) {
379 `${chargingStation.logPrefix()} Trying to unlock a non existing connector Id ${connectorId.toString()}`
381 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
383 if (connectorId
=== 0) {
385 `${chargingStation.logPrefix()} Trying to unlock connector Id ${connectorId.toString()}`
387 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
389 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
390 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
392 OCPP16StopTransactionReason
.UNLOCK_COMMAND
394 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
395 return OCPPConstants
.OCPP_RESPONSE_UNLOCKED
;
397 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_FAILED
;
399 await chargingStation
.ocppRequestService
.requestHandler
<
400 OCPP16StatusNotificationRequest
,
401 OCPP16StatusNotificationResponse
402 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
404 status: OCPP16ChargePointStatus
.Available
,
405 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
407 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.Available
;
408 return OCPPConstants
.OCPP_RESPONSE_UNLOCKED
;
411 private handleRequestGetConfiguration(
412 chargingStation
: ChargingStation
,
413 commandPayload
: GetConfigurationRequest
414 ): GetConfigurationResponse
{
415 const configurationKey
: OCPPConfigurationKey
[] = [];
416 const unknownKey
: string[] = [];
417 if (Utils
.isUndefined(commandPayload
.key
) === true) {
418 for (const configuration
of chargingStation
.ocppConfiguration
.configurationKey
) {
419 if (Utils
.isUndefined(configuration
.visible
) === true) {
420 configuration
.visible
= true;
422 if (configuration
.visible
=== false) {
425 configurationKey
.push({
426 key
: configuration
.key
,
427 readonly: configuration
.readonly,
428 value
: configuration
.value
,
431 } else if (Utils
.isNotEmptyArray(commandPayload
.key
) === true) {
432 for (const key
of commandPayload
.key
) {
433 const keyFound
= ChargingStationConfigurationUtils
.getConfigurationKey(
439 if (Utils
.isUndefined(keyFound
.visible
) === true) {
440 keyFound
.visible
= true;
442 if (keyFound
.visible
=== false) {
445 configurationKey
.push({
447 readonly: keyFound
.readonly,
448 value
: keyFound
.value
,
451 unknownKey
.push(key
);
461 private handleRequestChangeConfiguration(
462 chargingStation
: ChargingStation
,
463 commandPayload
: ChangeConfigurationRequest
464 ): ChangeConfigurationResponse
{
465 const keyToChange
= ChargingStationConfigurationUtils
.getConfigurationKey(
471 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED
;
472 } else if (keyToChange
&& keyToChange
.readonly) {
473 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_REJECTED
;
474 } else if (keyToChange
&& !keyToChange
.readonly) {
475 let valueChanged
= false;
476 if (keyToChange
.value
!== commandPayload
.value
) {
477 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
480 commandPayload
.value
,
485 let triggerHeartbeatRestart
= false;
486 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartBeatInterval
&& valueChanged
) {
487 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
489 OCPP16StandardParametersKey
.HeartbeatInterval
,
492 triggerHeartbeatRestart
= true;
494 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartbeatInterval
&& valueChanged
) {
495 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
497 OCPP16StandardParametersKey
.HeartBeatInterval
,
500 triggerHeartbeatRestart
= true;
502 if (triggerHeartbeatRestart
) {
503 chargingStation
.restartHeartbeat();
505 if (keyToChange
.key
=== OCPP16StandardParametersKey
.WebSocketPingInterval
&& valueChanged
) {
506 chargingStation
.restartWebSocketPing();
508 if (keyToChange
.reboot
) {
509 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED
;
511 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_ACCEPTED
;
515 private handleRequestSetChargingProfile(
516 chargingStation
: ChargingStation
,
517 commandPayload
: SetChargingProfileRequest
518 ): SetChargingProfileResponse
{
520 OCPP16ServiceUtils
.checkFeatureProfile(
522 OCPP16SupportedFeatureProfiles
.SmartCharging
,
523 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
526 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED
;
528 if (chargingStation
.connectors
.has(commandPayload
.connectorId
) === false) {
530 `${chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${
531 commandPayload.connectorId
534 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
537 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
538 OCPP16ChargingProfilePurposeType
.CHARGE_POINT_MAX_PROFILE
&&
539 commandPayload
.connectorId
!== 0
541 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
544 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
545 OCPP16ChargingProfilePurposeType
.TX_PROFILE
&&
546 (commandPayload
.connectorId
=== 0 ||
547 chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.transactionStarted
===
551 `${chargingStation.logPrefix()} Trying to set transaction charging profile(s) on connector ${
552 commandPayload.connectorId
553 } without a started transaction`
555 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
557 OCPP16ServiceUtils
.setChargingProfile(
559 commandPayload
.connectorId
,
560 commandPayload
.csChargingProfiles
563 `${chargingStation.logPrefix()} Charging profile(s) set on connector id ${
564 commandPayload.connectorId
566 commandPayload
.csChargingProfiles
568 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
571 private handleRequestClearChargingProfile(
572 chargingStation
: ChargingStation
,
573 commandPayload
: ClearChargingProfileRequest
574 ): ClearChargingProfileResponse
{
576 OCPP16ServiceUtils
.checkFeatureProfile(
578 OCPP16SupportedFeatureProfiles
.SmartCharging
,
579 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
582 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
584 if (chargingStation
.connectors
.has(commandPayload
.connectorId
) === false) {
586 `${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${
587 commandPayload.connectorId
590 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
592 const connectorStatus
= chargingStation
.getConnectorStatus(commandPayload
.connectorId
);
594 !Utils
.isNullOrUndefined(commandPayload
.connectorId
) &&
595 Utils
.isNotEmptyArray(connectorStatus
?.chargingProfiles
)
597 connectorStatus
.chargingProfiles
= [];
599 `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${
600 commandPayload.connectorId
603 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
605 if (Utils
.isNullOrUndefined(commandPayload
.connectorId
)) {
606 let clearedCP
= false;
607 for (const connectorId
of chargingStation
.connectors
.keys()) {
609 Utils
.isNotEmptyArray(chargingStation
.getConnectorStatus(connectorId
)?.chargingProfiles
)
612 .getConnectorStatus(connectorId
)
613 ?.chargingProfiles
?.forEach((chargingProfile
: OCPP16ChargingProfile
, index
: number) => {
614 let clearCurrentCP
= false;
615 if (chargingProfile
.chargingProfileId
=== commandPayload
.id
) {
616 clearCurrentCP
= true;
619 !commandPayload
.chargingProfilePurpose
&&
620 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
622 clearCurrentCP
= true;
625 !chargingProfile
.stackLevel
&&
626 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
628 clearCurrentCP
= true;
631 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
&&
632 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
634 clearCurrentCP
= true;
636 if (clearCurrentCP
) {
637 connectorStatus
?.chargingProfiles
?.splice(index
, 1);
639 `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`,
648 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
651 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
654 private async handleRequestChangeAvailability(
655 chargingStation
: ChargingStation
,
656 commandPayload
: ChangeAvailabilityRequest
657 ): Promise
<ChangeAvailabilityResponse
> {
658 const connectorId
: number = commandPayload
.connectorId
;
659 if (chargingStation
.connectors
.has(connectorId
) === false) {
661 `${chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`
663 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
665 const chargePointStatus
: OCPP16ChargePointStatus
=
666 commandPayload
.type === OCPP16AvailabilityType
.OPERATIVE
667 ? OCPP16ChargePointStatus
.Available
668 : OCPP16ChargePointStatus
.Unavailable
;
669 if (connectorId
=== 0) {
670 let response
: ChangeAvailabilityResponse
= OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
671 for (const id
of chargingStation
.connectors
.keys()) {
672 if (chargingStation
.getConnectorStatus(id
)?.transactionStarted
=== true) {
673 response
= OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
675 chargingStation
.getConnectorStatus(id
).availability
= commandPayload
.type;
676 if (response
=== OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
) {
677 await chargingStation
.ocppRequestService
.requestHandler
<
678 OCPP16StatusNotificationRequest
,
679 OCPP16StatusNotificationResponse
680 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
682 status: chargePointStatus
,
683 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
685 chargingStation
.getConnectorStatus(id
).status = chargePointStatus
;
691 (chargingStation
.isChargingStationAvailable() === true ||
692 (chargingStation
.isChargingStationAvailable() === false &&
693 commandPayload
.type === OCPP16AvailabilityType
.INOPERATIVE
))
695 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
696 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
697 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
699 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
700 await chargingStation
.ocppRequestService
.requestHandler
<
701 OCPP16StatusNotificationRequest
,
702 OCPP16StatusNotificationResponse
703 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
705 status: chargePointStatus
,
706 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
708 chargingStation
.getConnectorStatus(connectorId
).status = chargePointStatus
;
709 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
711 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
714 private async handleRequestRemoteStartTransaction(
715 chargingStation
: ChargingStation
,
716 commandPayload
: RemoteStartTransactionRequest
717 ): Promise
<GenericResponse
> {
718 const transactionConnectorId
= commandPayload
.connectorId
;
719 if (chargingStation
.connectors
.has(transactionConnectorId
) === true) {
720 const remoteStartTransactionLogMsg
= `${chargingStation.logPrefix()} Transaction remotely STARTED on ${
721 chargingStation.stationInfo.chargingStationId
722 }#${transactionConnectorId.toString()} for idTag '${commandPayload.idTag}'`;
723 await chargingStation
.ocppRequestService
.requestHandler
<
724 OCPP16StatusNotificationRequest
,
725 OCPP16StatusNotificationResponse
726 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
727 connectorId
: transactionConnectorId
,
728 status: OCPP16ChargePointStatus
.Preparing
,
729 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
731 const connectorStatus
= chargingStation
.getConnectorStatus(transactionConnectorId
);
732 connectorStatus
.status = OCPP16ChargePointStatus
.Preparing
;
734 chargingStation
.isChargingStationAvailable() === true &&
735 chargingStation
.isConnectorAvailable(transactionConnectorId
) === true
737 // Check if authorized
738 if (chargingStation
.getAuthorizeRemoteTxRequests() === true) {
739 let authorized
= false;
741 chargingStation
.getLocalAuthListEnabled() === true &&
742 chargingStation
.hasIdTags() === true &&
743 Utils
.isNotEmptyString(
744 chargingStation
.idTagsCache
745 .getIdTags(ChargingStationUtils
.getAuthorizationFile(chargingStation
.stationInfo
))
746 ?.find((idTag
) => idTag
=== commandPayload
.idTag
)
749 connectorStatus
.localAuthorizeIdTag
= commandPayload
.idTag
;
750 connectorStatus
.idTagLocalAuthorized
= true;
752 } else if (chargingStation
.getMustAuthorizeAtRemoteStart() === true) {
753 connectorStatus
.authorizeIdTag
= commandPayload
.idTag
;
754 const authorizeResponse
: OCPP16AuthorizeResponse
=
755 await chargingStation
.ocppRequestService
.requestHandler
<
756 OCPP16AuthorizeRequest
,
757 OCPP16AuthorizeResponse
758 >(chargingStation
, OCPP16RequestCommand
.AUTHORIZE
, {
759 idTag
: commandPayload
.idTag
,
761 if (authorizeResponse
?.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
766 `${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled`
769 if (authorized
=== true) {
770 // Authorization successful, start transaction
772 this.setRemoteStartTransactionChargingProfile(
774 transactionConnectorId
,
775 commandPayload
.chargingProfile
778 connectorStatus
.transactionRemoteStarted
= true;
781 await chargingStation
.ocppRequestService
.requestHandler
<
782 OCPP16StartTransactionRequest
,
783 OCPP16StartTransactionResponse
784 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
785 connectorId
: transactionConnectorId
,
786 idTag
: commandPayload
.idTag
,
788 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
790 logger
.debug(remoteStartTransactionLogMsg
);
791 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
793 return this.notifyRemoteStartTransactionRejected(
795 transactionConnectorId
,
799 return this.notifyRemoteStartTransactionRejected(
801 transactionConnectorId
,
805 return this.notifyRemoteStartTransactionRejected(
807 transactionConnectorId
,
811 // No authorization check required, start transaction
813 this.setRemoteStartTransactionChargingProfile(
815 transactionConnectorId
,
816 commandPayload
.chargingProfile
819 connectorStatus
.transactionRemoteStarted
= true;
822 await chargingStation
.ocppRequestService
.requestHandler
<
823 OCPP16StartTransactionRequest
,
824 OCPP16StartTransactionResponse
825 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
826 connectorId
: transactionConnectorId
,
827 idTag
: commandPayload
.idTag
,
829 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
831 logger
.debug(remoteStartTransactionLogMsg
);
832 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
834 return this.notifyRemoteStartTransactionRejected(
836 transactionConnectorId
,
840 return this.notifyRemoteStartTransactionRejected(
842 transactionConnectorId
,
846 return this.notifyRemoteStartTransactionRejected(
848 transactionConnectorId
,
852 return this.notifyRemoteStartTransactionRejected(
854 transactionConnectorId
,
859 private async notifyRemoteStartTransactionRejected(
860 chargingStation
: ChargingStation
,
863 ): Promise
<GenericResponse
> {
865 chargingStation
.getConnectorStatus(connectorId
)?.status !== OCPP16ChargePointStatus
.Available
867 await chargingStation
.ocppRequestService
.requestHandler
<
868 OCPP16StatusNotificationRequest
,
869 OCPP16StatusNotificationResponse
870 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
872 status: OCPP16ChargePointStatus
.Available
,
873 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
875 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.Available
;
878 `${chargingStation.logPrefix()} Remote starting transaction REJECTED on connector Id ${connectorId.toString()}, idTag '${idTag}', availability '${
879 chargingStation.getConnectorStatus(connectorId)?.availability
880 }', status '${chargingStation.getConnectorStatus(connectorId)?.status}'`
882 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
885 private setRemoteStartTransactionChargingProfile(
886 chargingStation
: ChargingStation
,
888 cp
: OCPP16ChargingProfile
890 if (cp
&& cp
.chargingProfilePurpose
=== OCPP16ChargingProfilePurposeType
.TX_PROFILE
) {
891 OCPP16ServiceUtils
.setChargingProfile(chargingStation
, connectorId
, cp
);
893 `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`,
897 } else if (cp
&& cp
.chargingProfilePurpose
!== OCPP16ChargingProfilePurposeType
.TX_PROFILE
) {
899 `${chargingStation.logPrefix()} Not allowed to set ${
900 cp.chargingProfilePurpose
901 } charging profile(s) at remote start transaction`
909 private async handleRequestRemoteStopTransaction(
910 chargingStation
: ChargingStation
,
911 commandPayload
: RemoteStopTransactionRequest
912 ): Promise
<GenericResponse
> {
913 const transactionId
= commandPayload
.transactionId
;
914 for (const connectorId
of chargingStation
.connectors
.keys()) {
917 chargingStation
.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
919 await chargingStation
.ocppRequestService
.requestHandler
<
920 OCPP16StatusNotificationRequest
,
921 OCPP16StatusNotificationResponse
922 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
924 status: OCPP16ChargePointStatus
.Finishing
,
925 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
927 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.Finishing
;
928 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
930 OCPP16StopTransactionReason
.REMOTE
932 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
933 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
935 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
939 `${chargingStation.logPrefix()} Trying to remote stop a non existing transaction ${transactionId.toString()}`
941 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
944 private handleRequestUpdateFirmware(
945 chargingStation
: ChargingStation
,
946 commandPayload
: OCPP16UpdateFirmwareRequest
947 ): OCPP16UpdateFirmwareResponse
{
949 OCPP16ServiceUtils
.checkFeatureProfile(
951 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
952 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
956 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: feature profile not supported`
958 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
961 !Utils
.isNullOrUndefined(chargingStation
.stationInfo
.firmwareStatus
) &&
962 chargingStation
.stationInfo
.firmwareStatus
!== OCPP16FirmwareStatus
.Installed
965 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`
967 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
969 const retrieveDate
= Utils
.convertToDate(commandPayload
.retrieveDate
);
970 const now
= Date.now();
971 if (retrieveDate
?.getTime() <= now
) {
972 this.runInAsyncScope(
973 this.updateFirmwareSimulation
.bind(this) as (
974 this: OCPP16IncomingRequestService
,
979 ).catch(Constants
.EMPTY_FUNCTION
);
982 this.updateFirmwareSimulation(chargingStation
).catch(Constants
.EMPTY_FUNCTION
);
983 }, retrieveDate
?.getTime() - now
);
985 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
988 private async updateFirmwareSimulation(
989 chargingStation
: ChargingStation
,
994 ChargingStationUtils
.checkChargingStation(chargingStation
, chargingStation
.logPrefix()) ===
999 for (const connectorId
of chargingStation
.connectors
.keys()) {
1002 chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== false
1004 await chargingStation
.ocppRequestService
.requestHandler
<
1005 OCPP16StatusNotificationRequest
,
1006 OCPP16StatusNotificationResponse
1007 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
1009 status: OCPP16ChargePointStatus
.Unavailable
,
1010 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1012 chargingStation
.getConnectorStatus(connectorId
).status =
1013 OCPP16ChargePointStatus
.Unavailable
;
1016 await chargingStation
.ocppRequestService
.requestHandler
<
1017 OCPP16FirmwareStatusNotificationRequest
,
1018 OCPP16FirmwareStatusNotificationResponse
1019 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1020 status: OCPP16FirmwareStatus
.Downloading
,
1022 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloading
;
1024 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
===
1025 OCPP16FirmwareStatus
.DownloadFailed
1027 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1028 await chargingStation
.ocppRequestService
.requestHandler
<
1029 OCPP16FirmwareStatusNotificationRequest
,
1030 OCPP16FirmwareStatusNotificationResponse
1031 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1032 status: chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
,
1034 chargingStation
.stationInfo
.firmwareStatus
=
1035 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
;
1038 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1039 await chargingStation
.ocppRequestService
.requestHandler
<
1040 OCPP16FirmwareStatusNotificationRequest
,
1041 OCPP16FirmwareStatusNotificationResponse
1042 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1043 status: OCPP16FirmwareStatus
.Downloaded
,
1045 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloaded
;
1046 let wasTransactionsStarted
= false;
1047 let transactionsStarted
: boolean;
1050 for (const connectorId
of chargingStation
.connectors
.keys()) {
1053 chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true
1059 const waitTime
= 15 * 1000;
1061 `${chargingStation.logPrefix()} ${moduleName}.updateFirmwareSimulation: ${trxCount} transaction(s) in progress, waiting ${
1063 } seconds before continuing firmware update simulation`
1065 await Utils
.sleep(waitTime
);
1066 transactionsStarted
= true;
1067 wasTransactionsStarted
= true;
1069 for (const connectorId
of chargingStation
.connectors
.keys()) {
1072 chargingStation
.getConnectorStatus(connectorId
)?.status !==
1073 OCPP16ChargePointStatus
.Unavailable
1075 await chargingStation
.ocppRequestService
.requestHandler
<
1076 OCPP16StatusNotificationRequest
,
1077 OCPP16StatusNotificationResponse
1078 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
1080 status: OCPP16ChargePointStatus
.Unavailable
,
1081 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1083 chargingStation
.getConnectorStatus(connectorId
).status =
1084 OCPP16ChargePointStatus
.Unavailable
;
1087 transactionsStarted
= false;
1089 } while (transactionsStarted
);
1090 !wasTransactionsStarted
&&
1091 (await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000));
1093 ChargingStationUtils
.checkChargingStation(chargingStation
, chargingStation
.logPrefix()) ===
1098 await chargingStation
.ocppRequestService
.requestHandler
<
1099 OCPP16FirmwareStatusNotificationRequest
,
1100 OCPP16FirmwareStatusNotificationResponse
1101 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1102 status: OCPP16FirmwareStatus
.Installing
,
1104 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Installing
;
1106 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
===
1107 OCPP16FirmwareStatus
.InstallationFailed
1109 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1110 await chargingStation
.ocppRequestService
.requestHandler
<
1111 OCPP16FirmwareStatusNotificationRequest
,
1112 OCPP16FirmwareStatusNotificationResponse
1113 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1114 status: chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
,
1116 chargingStation
.stationInfo
.firmwareStatus
=
1117 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
;
1120 if (chargingStation
.stationInfo
?.firmwareUpgrade
?.reset
=== true) {
1121 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1122 await chargingStation
.reset(OCPP16StopTransactionReason
.REBOOT
);
1126 private async handleRequestGetDiagnostics(
1127 chargingStation
: ChargingStation
,
1128 commandPayload
: GetDiagnosticsRequest
1129 ): Promise
<GetDiagnosticsResponse
> {
1131 OCPP16ServiceUtils
.checkFeatureProfile(
1133 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
1134 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1138 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Cannot get diagnostics: feature profile not supported`
1140 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1142 const uri
= new URL(commandPayload
.location
);
1143 if (uri
.protocol
.startsWith('ftp:')) {
1144 let ftpClient
: Client
;
1147 .readdirSync(path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'))
1148 .filter((file
) => file
.endsWith('.log'))
1149 .map((file
) => path
.join('./', file
));
1150 const diagnosticsArchive
= `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`;
1151 tar
.create({ gzip
: true }, logFiles
).pipe(fs
.createWriteStream(diagnosticsArchive
));
1152 ftpClient
= new Client();
1153 const accessResponse
= await ftpClient
.access({
1155 ...(Utils
.isNotEmptyString(uri
.port
) && { port
: Utils
.convertToInt(uri
.port
) }),
1156 ...(Utils
.isNotEmptyString(uri
.username
) && { user
: uri
.username
}),
1157 ...(Utils
.isNotEmptyString(uri
.password
) && { password
: uri
.password
}),
1159 let uploadResponse
: FTPResponse
;
1160 if (accessResponse
.code
=== 220) {
1161 ftpClient
.trackProgress((info
) => {
1163 `${chargingStation.logPrefix()} ${
1165 } bytes transferred from diagnostics archive ${info.name}`
1167 chargingStation
.ocppRequestService
1169 OCPP16DiagnosticsStatusNotificationRequest
,
1170 OCPP16DiagnosticsStatusNotificationResponse
1171 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1172 status: OCPP16DiagnosticsStatus
.Uploading
,
1176 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
1177 OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
1183 uploadResponse
= await ftpClient
.uploadFrom(
1185 path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'),
1188 `${uri.pathname}${diagnosticsArchive}`
1190 if (uploadResponse
.code
=== 226) {
1191 await chargingStation
.ocppRequestService
.requestHandler
<
1192 OCPP16DiagnosticsStatusNotificationRequest
,
1193 OCPP16DiagnosticsStatusNotificationResponse
1194 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1195 status: OCPP16DiagnosticsStatus
.Uploaded
,
1200 return { fileName
: diagnosticsArchive
};
1202 throw new OCPPError(
1203 ErrorType
.GENERIC_ERROR
,
1204 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1205 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1207 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1210 throw new OCPPError(
1211 ErrorType
.GENERIC_ERROR
,
1212 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1213 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1215 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1218 await chargingStation
.ocppRequestService
.requestHandler
<
1219 OCPP16DiagnosticsStatusNotificationRequest
,
1220 OCPP16DiagnosticsStatusNotificationResponse
1221 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1222 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1227 return this.handleIncomingRequestError(
1229 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
,
1231 { errorResponse
: OCPPConstants
.OCPP_RESPONSE_EMPTY
}
1236 `${chargingStation.logPrefix()} Unsupported protocol ${
1238 } to transfer the diagnostic logs archive`
1240 await chargingStation
.ocppRequestService
.requestHandler
<
1241 OCPP16DiagnosticsStatusNotificationRequest
,
1242 OCPP16DiagnosticsStatusNotificationResponse
1243 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1244 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1246 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1250 private handleRequestTriggerMessage(
1251 chargingStation
: ChargingStation
,
1252 commandPayload
: OCPP16TriggerMessageRequest
1253 ): OCPP16TriggerMessageResponse
{
1255 !OCPP16ServiceUtils
.checkFeatureProfile(
1257 OCPP16SupportedFeatureProfiles
.RemoteTrigger
,
1258 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
1260 !OCPP16ServiceUtils
.isMessageTriggerSupported(
1262 commandPayload
.requestedMessage
1265 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1268 !OCPP16ServiceUtils
.isConnectorIdValid(
1270 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1271 commandPayload
.connectorId
1274 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
;
1277 switch (commandPayload
.requestedMessage
) {
1278 case OCPP16MessageTrigger
.BootNotification
:
1280 chargingStation
.ocppRequestService
1281 .requestHandler
<OCPP16BootNotificationRequest
, OCPP16BootNotificationResponse
>(
1283 OCPP16RequestCommand
.BOOT_NOTIFICATION
,
1284 chargingStation
.bootNotificationRequest
,
1285 { skipBufferingOnError
: true, triggerMessage
: true }
1287 .then((response
) => {
1288 chargingStation
.bootNotificationResponse
= response
;
1290 .catch(Constants
.EMPTY_FUNCTION
);
1291 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1292 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1293 case OCPP16MessageTrigger
.Heartbeat
:
1295 chargingStation
.ocppRequestService
1296 .requestHandler
<OCPP16HeartbeatRequest
, OCPP16HeartbeatResponse
>(
1298 OCPP16RequestCommand
.HEARTBEAT
,
1301 triggerMessage
: true,
1304 .catch(Constants
.EMPTY_FUNCTION
);
1305 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1306 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1307 case OCPP16MessageTrigger
.StatusNotification
:
1309 if (!Utils
.isNullOrUndefined(commandPayload
?.connectorId
)) {
1310 chargingStation
.ocppRequestService
1311 .requestHandler
<OCPP16StatusNotificationRequest
, OCPP16StatusNotificationResponse
>(
1313 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1315 connectorId
: commandPayload
.connectorId
,
1316 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1317 status: chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.status,
1320 triggerMessage
: true,
1323 .catch(Constants
.EMPTY_FUNCTION
);
1325 for (const connectorId
of chargingStation
.connectors
.keys()) {
1326 chargingStation
.ocppRequestService
1328 OCPP16StatusNotificationRequest
,
1329 OCPP16StatusNotificationResponse
1332 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1335 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1336 status: chargingStation
.getConnectorStatus(connectorId
)?.status,
1339 triggerMessage
: true,
1342 .catch(Constants
.EMPTY_FUNCTION
);
1345 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1346 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1348 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1351 return this.handleIncomingRequestError(
1353 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1355 { errorResponse
: OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
}
1360 private handleRequestDataTransfer(
1361 chargingStation
: ChargingStation
,
1362 commandPayload
: OCPP16DataTransferRequest
1363 ): OCPP16DataTransferResponse
{
1365 if (Object.values(OCPP16DataTransferVendorId
).includes(commandPayload
.vendorId
)) {
1367 status: OCPP16DataTransferStatus
.ACCEPTED
,
1371 status: OCPP16DataTransferStatus
.UNKNOWN_VENDOR_ID
,
1374 return this.handleIncomingRequestError(
1376 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
1378 { errorResponse
: OCPPConstants
.OCPP_DATA_TRANSFER_RESPONSE_REJECTED
}