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';
11 import { OCPP16ServiceUtils
} from
'./OCPP16ServiceUtils';
12 import OCPPError from
'../../../exception/OCPPError';
13 import type { JsonObject
, JsonType
} from
'../../../types/JsonType';
14 import { OCPP16ChargePointErrorCode
} from
'../../../types/ocpp/1.6/ChargePointErrorCode';
15 import { OCPP16ChargePointStatus
} from
'../../../types/ocpp/1.6/ChargePointStatus';
17 ChargingProfilePurposeType
,
18 type OCPP16ChargingProfile
,
19 } from
'../../../types/ocpp/1.6/ChargingProfile';
21 OCPP16StandardParametersKey
,
22 OCPP16SupportedFeatureProfiles
,
23 } from
'../../../types/ocpp/1.6/Configuration';
24 import { OCPP16DiagnosticsStatus
} from
'../../../types/ocpp/1.6/DiagnosticsStatus';
26 type ChangeAvailabilityRequest
,
27 type ChangeConfigurationRequest
,
28 type ClearChargingProfileRequest
,
29 type GetConfigurationRequest
,
30 type GetDiagnosticsRequest
,
31 OCPP16AvailabilityType
,
32 type OCPP16BootNotificationRequest
,
33 type OCPP16ClearCacheRequest
,
34 type OCPP16DataTransferRequest
,
35 OCPP16DataTransferVendorId
,
36 type OCPP16DiagnosticsStatusNotificationRequest
,
38 type OCPP16FirmwareStatusNotificationRequest
,
39 type OCPP16HeartbeatRequest
,
40 OCPP16IncomingRequestCommand
,
43 type OCPP16StatusNotificationRequest
,
44 type OCPP16TriggerMessageRequest
,
45 type OCPP16UpdateFirmwareRequest
,
46 type RemoteStartTransactionRequest
,
47 type RemoteStopTransactionRequest
,
49 type SetChargingProfileRequest
,
50 type UnlockConnectorRequest
,
51 } from
'../../../types/ocpp/1.6/Requests';
53 type ChangeAvailabilityResponse
,
54 type ChangeConfigurationResponse
,
55 type ClearChargingProfileResponse
,
56 type GetConfigurationResponse
,
57 type GetDiagnosticsResponse
,
58 type OCPP16BootNotificationResponse
,
59 type OCPP16DataTransferResponse
,
60 OCPP16DataTransferStatus
,
61 type OCPP16DiagnosticsStatusNotificationResponse
,
62 type OCPP16FirmwareStatusNotificationResponse
,
63 type OCPP16HeartbeatResponse
,
64 type OCPP16StatusNotificationResponse
,
65 type OCPP16TriggerMessageResponse
,
66 type OCPP16UpdateFirmwareResponse
,
67 type SetChargingProfileResponse
,
68 type UnlockConnectorResponse
,
69 } from
'../../../types/ocpp/1.6/Responses';
71 OCPP16AuthorizationStatus
,
72 type OCPP16AuthorizeRequest
,
73 type OCPP16AuthorizeResponse
,
74 type OCPP16StartTransactionRequest
,
75 type OCPP16StartTransactionResponse
,
76 OCPP16StopTransactionReason
,
77 } from
'../../../types/ocpp/1.6/Transaction';
78 import type { OCPPConfigurationKey
} from
'../../../types/ocpp/Configuration';
79 import { ErrorType
} from
'../../../types/ocpp/ErrorType';
80 import { OCPPVersion
} from
'../../../types/ocpp/OCPPVersion';
81 import type { IncomingRequestHandler
} from
'../../../types/ocpp/Requests';
82 import type { GenericResponse
} from
'../../../types/ocpp/Responses';
83 import Constants from
'../../../utils/Constants';
84 import logger from
'../../../utils/Logger';
85 import Utils from
'../../../utils/Utils';
86 import type ChargingStation from
'../../ChargingStation';
87 import { ChargingStationConfigurationUtils
} from
'../../ChargingStationConfigurationUtils';
88 import { ChargingStationUtils
} from
'../../ChargingStationUtils';
89 import OCPPConstants from
'../OCPPConstants';
90 import OCPPIncomingRequestService from
'../OCPPIncomingRequestService';
92 const moduleName
= 'OCPP16IncomingRequestService';
94 export default class OCPP16IncomingRequestService
extends OCPPIncomingRequestService
{
95 protected jsonSchemas
: Map
<OCPP16IncomingRequestCommand
, JSONSchemaType
<JsonObject
>>;
96 private incomingRequestHandlers
: Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>;
98 public constructor() {
99 if (new.target
?.name
=== moduleName
) {
100 throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
102 super(OCPPVersion
.VERSION_16
);
103 this.incomingRequestHandlers
= new Map
<OCPP16IncomingRequestCommand
, IncomingRequestHandler
>([
104 [OCPP16IncomingRequestCommand
.RESET
, this.handleRequestReset
.bind(this)],
105 [OCPP16IncomingRequestCommand
.CLEAR_CACHE
, this.handleRequestClearCache
.bind(this)],
106 [OCPP16IncomingRequestCommand
.UNLOCK_CONNECTOR
, this.handleRequestUnlockConnector
.bind(this)],
108 OCPP16IncomingRequestCommand
.GET_CONFIGURATION
,
109 this.handleRequestGetConfiguration
.bind(this),
112 OCPP16IncomingRequestCommand
.CHANGE_CONFIGURATION
,
113 this.handleRequestChangeConfiguration
.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
.SET_CHARGING_PROFILE
,
191 OCPP16ServiceUtils
.parseJsonSchemaFile
<SetChargingProfileRequest
>(
192 '../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json',
198 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
,
199 OCPP16ServiceUtils
.parseJsonSchemaFile
<ClearChargingProfileRequest
>(
200 '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json',
206 OCPP16IncomingRequestCommand
.CHANGE_AVAILABILITY
,
207 OCPP16ServiceUtils
.parseJsonSchemaFile
<ChangeAvailabilityRequest
>(
208 '../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json',
214 OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
,
215 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStartTransactionRequest
>(
216 '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json',
222 OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
,
223 OCPP16ServiceUtils
.parseJsonSchemaFile
<RemoteStopTransactionRequest
>(
224 '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json',
230 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
231 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16TriggerMessageRequest
>(
232 '../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json',
238 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
239 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16DataTransferRequest
>(
240 '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json',
246 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
,
247 OCPP16ServiceUtils
.parseJsonSchemaFile
<OCPP16UpdateFirmwareRequest
>(
248 '../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json',
254 this.validatePayload
.bind(this);
257 public async incomingRequestHandler(
258 chargingStation
: ChargingStation
,
260 commandName
: OCPP16IncomingRequestCommand
,
261 commandPayload
: JsonType
263 let response
: JsonType
;
265 chargingStation
.getOcppStrictCompliance() === true &&
266 chargingStation
.isInPendingState() === true &&
267 (commandName
=== OCPP16IncomingRequestCommand
.REMOTE_START_TRANSACTION
||
268 commandName
=== OCPP16IncomingRequestCommand
.REMOTE_STOP_TRANSACTION
)
271 ErrorType
.SECURITY_ERROR
,
272 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
276 )} while the charging station is in pending state on the central server`,
282 chargingStation
.isRegistered() === true ||
283 (chargingStation
.getOcppStrictCompliance() === false &&
284 chargingStation
.isInUnknownState() === true)
287 this.incomingRequestHandlers
.has(commandName
) === true &&
288 OCPP16ServiceUtils
.isIncomingRequestCommandSupported(chargingStation
, commandName
) === true
291 this.validatePayload(chargingStation
, commandName
, commandPayload
);
292 // Call the method to build the response
293 response
= await this.incomingRequestHandlers
.get(commandName
)(
300 `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: Handle incoming request error:`,
308 ErrorType
.NOT_IMPLEMENTED
,
309 `${commandName} is not implemented to handle request PDU ${JSON.stringify(
320 ErrorType
.SECURITY_ERROR
,
321 `${commandName} cannot be issued to handle request PDU ${JSON.stringify(
325 )} while the charging station is not registered on the central server.`,
330 // Send the built response
331 await chargingStation
.ocppRequestService
.sendResponse(
339 private validatePayload(
340 chargingStation
: ChargingStation
,
341 commandName
: OCPP16IncomingRequestCommand
,
342 commandPayload
: JsonType
344 if (this.jsonSchemas
.has(commandName
) === true) {
345 return this.validateIncomingRequestPayload(
348 this.jsonSchemas
.get(commandName
),
353 `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command '${commandName}' PDU validation`
358 // Simulate charging station restart
359 private handleRequestReset(
360 chargingStation
: ChargingStation
,
361 commandPayload
: ResetRequest
365 chargingStation
.reset
.bind(chargingStation
) as (
366 this: ChargingStation
,
370 `${commandPayload.type}Reset` as OCPP16StopTransactionReason
373 /* This is intentional */
376 `${chargingStation.logPrefix()} ${
378 } reset command received, simulating it. The station will be back online in ${Utils.formatDurationMilliSeconds(
379 chargingStation.stationInfo.resetTime
382 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
385 private async handleRequestUnlockConnector(
386 chargingStation
: ChargingStation
,
387 commandPayload
: UnlockConnectorRequest
388 ): Promise
<UnlockConnectorResponse
> {
389 const connectorId
= commandPayload
.connectorId
;
390 if (chargingStation
.connectors
.has(connectorId
) === false) {
392 `${chargingStation.logPrefix()} Trying to unlock a non existing connector Id ${connectorId.toString()}`
394 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
396 if (connectorId
=== 0) {
398 `${chargingStation.logPrefix()} Trying to unlock connector Id ${connectorId.toString()}`
400 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED
;
402 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
403 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
405 OCPP16StopTransactionReason
.UNLOCK_COMMAND
407 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
408 return OCPPConstants
.OCPP_RESPONSE_UNLOCKED
;
410 return OCPPConstants
.OCPP_RESPONSE_UNLOCK_FAILED
;
412 await chargingStation
.ocppRequestService
.requestHandler
<
413 OCPP16StatusNotificationRequest
,
414 OCPP16StatusNotificationResponse
415 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
417 status: OCPP16ChargePointStatus
.AVAILABLE
,
418 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
420 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.AVAILABLE
;
421 return OCPPConstants
.OCPP_RESPONSE_UNLOCKED
;
424 private handleRequestGetConfiguration(
425 chargingStation
: ChargingStation
,
426 commandPayload
: GetConfigurationRequest
427 ): GetConfigurationResponse
{
428 const configurationKey
: OCPPConfigurationKey
[] = [];
429 const unknownKey
: string[] = [];
430 if (Utils
.isEmptyArray(commandPayload
.key
) === true) {
431 for (const configuration
of chargingStation
.ocppConfiguration
.configurationKey
) {
432 if (Utils
.isUndefined(configuration
.visible
) === true) {
433 configuration
.visible
= true;
435 if (configuration
.visible
=== false) {
438 configurationKey
.push({
439 key
: configuration
.key
,
440 readonly: configuration
.readonly,
441 value
: configuration
.value
,
445 for (const key
of commandPayload
.key
) {
446 const keyFound
= ChargingStationConfigurationUtils
.getConfigurationKey(
451 if (Utils
.isUndefined(keyFound
.visible
) === true) {
452 keyFound
.visible
= true;
454 if (keyFound
.visible
=== false) {
457 configurationKey
.push({
459 readonly: keyFound
.readonly,
460 value
: keyFound
.value
,
463 unknownKey
.push(key
);
473 private handleRequestChangeConfiguration(
474 chargingStation
: ChargingStation
,
475 commandPayload
: ChangeConfigurationRequest
476 ): ChangeConfigurationResponse
{
477 const keyToChange
= ChargingStationConfigurationUtils
.getConfigurationKey(
483 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_NOT_SUPPORTED
;
484 } else if (keyToChange
&& keyToChange
.readonly) {
485 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_REJECTED
;
486 } else if (keyToChange
&& !keyToChange
.readonly) {
487 let valueChanged
= false;
488 if (keyToChange
.value
!== commandPayload
.value
) {
489 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
492 commandPayload
.value
,
497 let triggerHeartbeatRestart
= false;
498 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartBeatInterval
&& valueChanged
) {
499 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
501 OCPP16StandardParametersKey
.HeartbeatInterval
,
504 triggerHeartbeatRestart
= true;
506 if (keyToChange
.key
=== OCPP16StandardParametersKey
.HeartbeatInterval
&& valueChanged
) {
507 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
509 OCPP16StandardParametersKey
.HeartBeatInterval
,
512 triggerHeartbeatRestart
= true;
514 if (triggerHeartbeatRestart
) {
515 chargingStation
.restartHeartbeat();
517 if (keyToChange
.key
=== OCPP16StandardParametersKey
.WebSocketPingInterval
&& valueChanged
) {
518 chargingStation
.restartWebSocketPing();
520 if (keyToChange
.reboot
) {
521 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_REBOOT_REQUIRED
;
523 return OCPPConstants
.OCPP_CONFIGURATION_RESPONSE_ACCEPTED
;
527 private handleRequestSetChargingProfile(
528 chargingStation
: ChargingStation
,
529 commandPayload
: SetChargingProfileRequest
530 ): SetChargingProfileResponse
{
532 OCPP16ServiceUtils
.checkFeatureProfile(
534 OCPP16SupportedFeatureProfiles
.SmartCharging
,
535 OCPP16IncomingRequestCommand
.SET_CHARGING_PROFILE
538 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED
;
540 if (chargingStation
.connectors
.has(commandPayload
.connectorId
) === false) {
542 `${chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${
543 commandPayload.connectorId
546 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
549 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
550 ChargingProfilePurposeType
.CHARGE_POINT_MAX_PROFILE
&&
551 commandPayload
.connectorId
!== 0
553 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
556 commandPayload
.csChargingProfiles
.chargingProfilePurpose
===
557 ChargingProfilePurposeType
.TX_PROFILE
&&
558 (commandPayload
.connectorId
=== 0 ||
559 chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.transactionStarted
===
563 `${chargingStation.logPrefix()} Trying to set transaction charging profile(s) on connector ${
564 commandPayload.connectorId
565 } without a started transaction`
567 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED
;
569 OCPP16ServiceUtils
.setChargingProfile(
571 commandPayload
.connectorId
,
572 commandPayload
.csChargingProfiles
575 `${chargingStation.logPrefix()} Charging profile(s) set on connector id ${
576 commandPayload.connectorId
578 commandPayload
.csChargingProfiles
580 return OCPPConstants
.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
583 private handleRequestClearChargingProfile(
584 chargingStation
: ChargingStation
,
585 commandPayload
: ClearChargingProfileRequest
586 ): ClearChargingProfileResponse
{
588 OCPP16ServiceUtils
.checkFeatureProfile(
590 OCPP16SupportedFeatureProfiles
.SmartCharging
,
591 OCPP16IncomingRequestCommand
.CLEAR_CHARGING_PROFILE
594 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
596 if (chargingStation
.connectors
.has(commandPayload
.connectorId
) === false) {
598 `${chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${
599 commandPayload.connectorId
602 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
604 const connectorStatus
= chargingStation
.getConnectorStatus(commandPayload
.connectorId
);
606 !Utils
.isNullOrUndefined(commandPayload
.connectorId
) &&
607 !Utils
.isEmptyArray(connectorStatus
?.chargingProfiles
)
609 connectorStatus
.chargingProfiles
= [];
611 `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${
612 commandPayload.connectorId
615 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
617 if (Utils
.isNullOrUndefined(commandPayload
.connectorId
)) {
618 let clearedCP
= false;
619 for (const connectorId
of chargingStation
.connectors
.keys()) {
621 !Utils
.isEmptyArray(chargingStation
.getConnectorStatus(connectorId
)?.chargingProfiles
)
624 .getConnectorStatus(connectorId
)
625 ?.chargingProfiles
?.forEach((chargingProfile
: OCPP16ChargingProfile
, index
: number) => {
626 let clearCurrentCP
= false;
627 if (chargingProfile
.chargingProfileId
=== commandPayload
.id
) {
628 clearCurrentCP
= true;
631 !commandPayload
.chargingProfilePurpose
&&
632 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
634 clearCurrentCP
= true;
637 !chargingProfile
.stackLevel
&&
638 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
640 clearCurrentCP
= true;
643 chargingProfile
.stackLevel
=== commandPayload
.stackLevel
&&
644 chargingProfile
.chargingProfilePurpose
=== commandPayload
.chargingProfilePurpose
646 clearCurrentCP
= true;
648 if (clearCurrentCP
) {
649 connectorStatus
?.chargingProfiles
?.splice(index
, 1);
651 `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`,
660 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED
;
663 return OCPPConstants
.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN
;
666 private async handleRequestChangeAvailability(
667 chargingStation
: ChargingStation
,
668 commandPayload
: ChangeAvailabilityRequest
669 ): Promise
<ChangeAvailabilityResponse
> {
670 const connectorId
: number = commandPayload
.connectorId
;
671 if (chargingStation
.connectors
.has(connectorId
) === false) {
673 `${chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`
675 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
677 const chargePointStatus
: OCPP16ChargePointStatus
=
678 commandPayload
.type === OCPP16AvailabilityType
.OPERATIVE
679 ? OCPP16ChargePointStatus
.AVAILABLE
680 : OCPP16ChargePointStatus
.UNAVAILABLE
;
681 if (connectorId
=== 0) {
682 let response
: ChangeAvailabilityResponse
= OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
683 for (const id
of chargingStation
.connectors
.keys()) {
684 if (chargingStation
.getConnectorStatus(id
)?.transactionStarted
=== true) {
685 response
= OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
687 chargingStation
.getConnectorStatus(id
).availability
= commandPayload
.type;
688 if (response
=== OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
) {
689 await chargingStation
.ocppRequestService
.requestHandler
<
690 OCPP16StatusNotificationRequest
,
691 OCPP16StatusNotificationResponse
692 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
694 status: chargePointStatus
,
695 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
697 chargingStation
.getConnectorStatus(id
).status = chargePointStatus
;
703 (chargingStation
.isChargingStationAvailable() === true ||
704 (chargingStation
.isChargingStationAvailable() === false &&
705 commandPayload
.type === OCPP16AvailabilityType
.INOPERATIVE
))
707 if (chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
708 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
709 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_SCHEDULED
;
711 chargingStation
.getConnectorStatus(connectorId
).availability
= commandPayload
.type;
712 await chargingStation
.ocppRequestService
.requestHandler
<
713 OCPP16StatusNotificationRequest
,
714 OCPP16StatusNotificationResponse
715 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
717 status: chargePointStatus
,
718 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
720 chargingStation
.getConnectorStatus(connectorId
).status = chargePointStatus
;
721 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_ACCEPTED
;
723 return OCPPConstants
.OCPP_AVAILABILITY_RESPONSE_REJECTED
;
726 private async handleRequestRemoteStartTransaction(
727 chargingStation
: ChargingStation
,
728 commandPayload
: RemoteStartTransactionRequest
729 ): Promise
<GenericResponse
> {
730 const transactionConnectorId
= commandPayload
.connectorId
;
731 if (chargingStation
.connectors
.has(transactionConnectorId
) === true) {
732 const remoteStartTransactionLogMsg
= `${chargingStation.logPrefix()} Transaction remotely STARTED on ${
733 chargingStation.stationInfo.chargingStationId
734 }#${transactionConnectorId.toString()} for idTag '${commandPayload.idTag}'`;
735 await chargingStation
.ocppRequestService
.requestHandler
<
736 OCPP16StatusNotificationRequest
,
737 OCPP16StatusNotificationResponse
738 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
739 connectorId
: transactionConnectorId
,
740 status: OCPP16ChargePointStatus
.PREPARING
,
741 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
743 const connectorStatus
= chargingStation
.getConnectorStatus(transactionConnectorId
);
744 connectorStatus
.status = OCPP16ChargePointStatus
.PREPARING
;
745 if (chargingStation
.isChargingStationAvailable() === true) {
746 // Check if authorized
747 if (chargingStation
.getAuthorizeRemoteTxRequests() === true) {
748 let authorized
= false;
750 chargingStation
.getLocalAuthListEnabled() === true &&
751 chargingStation
.hasAuthorizedTags() === true &&
752 Utils
.isNotEmptyString(
753 chargingStation
.authorizedTagsCache
755 ChargingStationUtils
.getAuthorizationFile(chargingStation
.stationInfo
)
757 ?.find((idTag
) => idTag
=== commandPayload
.idTag
)
760 connectorStatus
.localAuthorizeIdTag
= commandPayload
.idTag
;
761 connectorStatus
.idTagLocalAuthorized
= true;
763 } else if (chargingStation
.getMustAuthorizeAtRemoteStart() === true) {
764 connectorStatus
.authorizeIdTag
= commandPayload
.idTag
;
765 const authorizeResponse
: OCPP16AuthorizeResponse
=
766 await chargingStation
.ocppRequestService
.requestHandler
<
767 OCPP16AuthorizeRequest
,
768 OCPP16AuthorizeResponse
769 >(chargingStation
, OCPP16RequestCommand
.AUTHORIZE
, {
770 idTag
: commandPayload
.idTag
,
772 if (authorizeResponse
?.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
777 `${chargingStation.logPrefix()} The charging station configuration expects authorize at remote start transaction but local authorization or authorize isn't enabled`
780 if (authorized
=== true) {
781 // Authorization successful, start transaction
783 this.setRemoteStartTransactionChargingProfile(
785 transactionConnectorId
,
786 commandPayload
.chargingProfile
789 connectorStatus
.transactionRemoteStarted
= true;
792 await chargingStation
.ocppRequestService
.requestHandler
<
793 OCPP16StartTransactionRequest
,
794 OCPP16StartTransactionResponse
795 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
796 connectorId
: transactionConnectorId
,
797 idTag
: commandPayload
.idTag
,
799 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
801 logger
.debug(remoteStartTransactionLogMsg
);
802 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
804 return this.notifyRemoteStartTransactionRejected(
806 transactionConnectorId
,
810 return this.notifyRemoteStartTransactionRejected(
812 transactionConnectorId
,
816 return this.notifyRemoteStartTransactionRejected(
818 transactionConnectorId
,
822 // No authorization check required, start transaction
824 this.setRemoteStartTransactionChargingProfile(
826 transactionConnectorId
,
827 commandPayload
.chargingProfile
830 connectorStatus
.transactionRemoteStarted
= true;
833 await chargingStation
.ocppRequestService
.requestHandler
<
834 OCPP16StartTransactionRequest
,
835 OCPP16StartTransactionResponse
836 >(chargingStation
, OCPP16RequestCommand
.START_TRANSACTION
, {
837 connectorId
: transactionConnectorId
,
838 idTag
: commandPayload
.idTag
,
840 ).idTagInfo
.status === OCPP16AuthorizationStatus
.ACCEPTED
842 logger
.debug(remoteStartTransactionLogMsg
);
843 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
845 return this.notifyRemoteStartTransactionRejected(
847 transactionConnectorId
,
851 return this.notifyRemoteStartTransactionRejected(
853 transactionConnectorId
,
857 return this.notifyRemoteStartTransactionRejected(
859 transactionConnectorId
,
863 return this.notifyRemoteStartTransactionRejected(
865 transactionConnectorId
,
870 private async notifyRemoteStartTransactionRejected(
871 chargingStation
: ChargingStation
,
874 ): Promise
<GenericResponse
> {
876 chargingStation
.getConnectorStatus(connectorId
)?.status !== OCPP16ChargePointStatus
.AVAILABLE
878 await chargingStation
.ocppRequestService
.requestHandler
<
879 OCPP16StatusNotificationRequest
,
880 OCPP16StatusNotificationResponse
881 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
883 status: OCPP16ChargePointStatus
.AVAILABLE
,
884 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
886 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.AVAILABLE
;
889 `${chargingStation.logPrefix()} Remote starting transaction REJECTED on connector Id ${connectorId.toString()}, idTag '${idTag}', availability '${
890 chargingStation.getConnectorStatus(connectorId)?.availability
891 }', status '${chargingStation.getConnectorStatus(connectorId)?.status}'`
893 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
896 private setRemoteStartTransactionChargingProfile(
897 chargingStation
: ChargingStation
,
899 cp
: OCPP16ChargingProfile
901 if (cp
&& cp
.chargingProfilePurpose
=== ChargingProfilePurposeType
.TX_PROFILE
) {
902 OCPP16ServiceUtils
.setChargingProfile(chargingStation
, connectorId
, cp
);
904 `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`,
908 } else if (cp
&& cp
.chargingProfilePurpose
!== ChargingProfilePurposeType
.TX_PROFILE
) {
910 `${chargingStation.logPrefix()} Not allowed to set ${
911 cp.chargingProfilePurpose
912 } charging profile(s) at remote start transaction`
920 private async handleRequestRemoteStopTransaction(
921 chargingStation
: ChargingStation
,
922 commandPayload
: RemoteStopTransactionRequest
923 ): Promise
<GenericResponse
> {
924 const transactionId
= commandPayload
.transactionId
;
925 for (const connectorId
of chargingStation
.connectors
.keys()) {
928 chargingStation
.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
930 await chargingStation
.ocppRequestService
.requestHandler
<
931 OCPP16StatusNotificationRequest
,
932 OCPP16StatusNotificationResponse
933 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
935 status: OCPP16ChargePointStatus
.FINISHING
,
936 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
938 chargingStation
.getConnectorStatus(connectorId
).status = OCPP16ChargePointStatus
.FINISHING
;
939 const stopResponse
= await chargingStation
.stopTransactionOnConnector(
941 OCPP16StopTransactionReason
.REMOTE
943 if (stopResponse
.idTagInfo
?.status === OCPP16AuthorizationStatus
.ACCEPTED
) {
944 return OCPPConstants
.OCPP_RESPONSE_ACCEPTED
;
946 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
950 `${chargingStation.logPrefix()} Trying to remote stop a non existing transaction ${transactionId.toString()}`
952 return OCPPConstants
.OCPP_RESPONSE_REJECTED
;
955 private handleRequestUpdateFirmware(
956 chargingStation
: ChargingStation
,
957 commandPayload
: OCPP16UpdateFirmwareRequest
958 ): OCPP16UpdateFirmwareResponse
{
960 OCPP16ServiceUtils
.checkFeatureProfile(
962 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
963 OCPP16IncomingRequestCommand
.UPDATE_FIRMWARE
967 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: feature profile not supported`
969 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
972 !Utils
.isNullOrUndefined(chargingStation
.stationInfo
.firmwareStatus
) &&
973 chargingStation
.stationInfo
.firmwareStatus
!== OCPP16FirmwareStatus
.Installed
976 `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress`
978 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
980 const retrieveDate
= Utils
.convertToDate(commandPayload
.retrieveDate
);
981 const now
= Date.now();
982 if (retrieveDate
?.getTime() <= now
) {
985 this.updateFirmware
.bind(this) as (
986 this: OCPP16IncomingRequestService
,
993 /* This is intentional */
997 this.updateFirmware(chargingStation
).catch(() => {
1000 }, retrieveDate
?.getTime() - now
);
1002 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1005 private async updateFirmware(
1006 chargingStation
: ChargingStation
,
1010 chargingStation
.stopAutomaticTransactionGenerator();
1011 for (const connectorId
of chargingStation
.connectors
.keys()) {
1014 chargingStation
.getConnectorStatus(connectorId
)?.transactionStarted
=== false
1016 await chargingStation
.ocppRequestService
.requestHandler
<
1017 OCPP16StatusNotificationRequest
,
1018 OCPP16StatusNotificationResponse
1019 >(chargingStation
, OCPP16RequestCommand
.STATUS_NOTIFICATION
, {
1021 status: OCPP16ChargePointStatus
.UNAVAILABLE
,
1022 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1024 chargingStation
.getConnectorStatus(connectorId
).status =
1025 OCPP16ChargePointStatus
.UNAVAILABLE
;
1029 chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
&&
1030 Utils
.isNotEmptyString(chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
)
1032 await chargingStation
.ocppRequestService
.requestHandler
<
1033 OCPP16FirmwareStatusNotificationRequest
,
1034 OCPP16FirmwareStatusNotificationResponse
1035 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1036 status: chargingStation
.stationInfo
?.firmwareUpgrade
?.failureStatus
,
1040 await chargingStation
.ocppRequestService
.requestHandler
<
1041 OCPP16FirmwareStatusNotificationRequest
,
1042 OCPP16FirmwareStatusNotificationResponse
1043 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1044 status: OCPP16FirmwareStatus
.Downloading
,
1046 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloading
;
1047 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1048 await chargingStation
.ocppRequestService
.requestHandler
<
1049 OCPP16FirmwareStatusNotificationRequest
,
1050 OCPP16FirmwareStatusNotificationResponse
1051 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1052 status: OCPP16FirmwareStatus
.Downloaded
,
1054 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Downloaded
;
1055 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1056 await chargingStation
.ocppRequestService
.requestHandler
<
1057 OCPP16FirmwareStatusNotificationRequest
,
1058 OCPP16FirmwareStatusNotificationResponse
1059 >(chargingStation
, OCPP16RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1060 status: OCPP16FirmwareStatus
.Installing
,
1062 chargingStation
.stationInfo
.firmwareStatus
= OCPP16FirmwareStatus
.Installing
;
1063 if (chargingStation
.stationInfo
?.firmwareUpgrade
?.reset
=== true) {
1064 await Utils
.sleep(Utils
.getRandomInteger(maxDelay
, minDelay
) * 1000);
1065 await chargingStation
.reset(OCPP16StopTransactionReason
.REBOOT
);
1069 private async handleRequestGetDiagnostics(
1070 chargingStation
: ChargingStation
,
1071 commandPayload
: GetDiagnosticsRequest
1072 ): Promise
<GetDiagnosticsResponse
> {
1074 OCPP16ServiceUtils
.checkFeatureProfile(
1076 OCPP16SupportedFeatureProfiles
.FirmwareManagement
,
1077 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1081 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Cannot get diagnostics: feature profile not supported`
1083 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1085 const uri
= new URL(commandPayload
.location
);
1086 if (uri
.protocol
.startsWith('ftp:')) {
1087 let ftpClient
: Client
;
1090 .readdirSync(path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'))
1091 .filter((file
) => file
.endsWith('.log'))
1092 .map((file
) => path
.join('./', file
));
1093 const diagnosticsArchive
= `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`;
1094 tar
.create({ gzip
: true }, logFiles
).pipe(fs
.createWriteStream(diagnosticsArchive
));
1095 ftpClient
= new Client();
1096 const accessResponse
= await ftpClient
.access({
1098 ...(Utils
.isNotEmptyString(uri
.port
) && { port
: Utils
.convertToInt(uri
.port
) }),
1099 ...(Utils
.isNotEmptyString(uri
.username
) && { user
: uri
.username
}),
1100 ...(Utils
.isNotEmptyString(uri
.password
) && { password
: uri
.password
}),
1102 let uploadResponse
: FTPResponse
;
1103 if (accessResponse
.code
=== 220) {
1104 ftpClient
.trackProgress((info
) => {
1106 `${chargingStation.logPrefix()} ${
1108 } bytes transferred from diagnostics archive ${info.name}`
1110 chargingStation
.ocppRequestService
1112 OCPP16DiagnosticsStatusNotificationRequest
,
1113 OCPP16DiagnosticsStatusNotificationResponse
1114 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1115 status: OCPP16DiagnosticsStatus
.Uploading
,
1119 `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
1120 OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
1126 uploadResponse
= await ftpClient
.uploadFrom(
1128 path
.resolve(path
.dirname(fileURLToPath(import.meta
.url
)), '../../../../'),
1131 `${uri.pathname}${diagnosticsArchive}`
1133 if (uploadResponse
.code
=== 226) {
1134 await chargingStation
.ocppRequestService
.requestHandler
<
1135 OCPP16DiagnosticsStatusNotificationRequest
,
1136 OCPP16DiagnosticsStatusNotificationResponse
1137 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1138 status: OCPP16DiagnosticsStatus
.Uploaded
,
1143 return { fileName
: diagnosticsArchive
};
1145 throw new OCPPError(
1146 ErrorType
.GENERIC_ERROR
,
1147 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1148 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1150 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1153 throw new OCPPError(
1154 ErrorType
.GENERIC_ERROR
,
1155 `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${
1156 uploadResponse?.code && `|${uploadResponse?.code.toString()}
`
1158 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
1161 await chargingStation
.ocppRequestService
.requestHandler
<
1162 OCPP16DiagnosticsStatusNotificationRequest
,
1163 OCPP16DiagnosticsStatusNotificationResponse
1164 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1165 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1170 return this.handleIncomingRequestError(
1172 OCPP16IncomingRequestCommand
.GET_DIAGNOSTICS
,
1174 { errorResponse
: OCPPConstants
.OCPP_RESPONSE_EMPTY
}
1179 `${chargingStation.logPrefix()} Unsupported protocol ${
1181 } to transfer the diagnostic logs archive`
1183 await chargingStation
.ocppRequestService
.requestHandler
<
1184 OCPP16DiagnosticsStatusNotificationRequest
,
1185 OCPP16DiagnosticsStatusNotificationResponse
1186 >(chargingStation
, OCPP16RequestCommand
.DIAGNOSTICS_STATUS_NOTIFICATION
, {
1187 status: OCPP16DiagnosticsStatus
.UploadFailed
,
1189 return OCPPConstants
.OCPP_RESPONSE_EMPTY
;
1193 private handleRequestTriggerMessage(
1194 chargingStation
: ChargingStation
,
1195 commandPayload
: OCPP16TriggerMessageRequest
1196 ): OCPP16TriggerMessageResponse
{
1198 !OCPP16ServiceUtils
.checkFeatureProfile(
1200 OCPP16SupportedFeatureProfiles
.RemoteTrigger
,
1201 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
1203 !OCPP16ServiceUtils
.isMessageTriggerSupported(
1205 commandPayload
.requestedMessage
1208 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1211 !OCPP16ServiceUtils
.isConnectorIdValid(
1213 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1214 commandPayload
.connectorId
1217 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
;
1220 switch (commandPayload
.requestedMessage
) {
1221 case OCPP16MessageTrigger
.BootNotification
:
1223 chargingStation
.ocppRequestService
1224 .requestHandler
<OCPP16BootNotificationRequest
, OCPP16BootNotificationResponse
>(
1226 OCPP16RequestCommand
.BOOT_NOTIFICATION
,
1227 chargingStation
.bootNotificationRequest
,
1228 { skipBufferingOnError
: true, triggerMessage
: true }
1230 .then((response
) => {
1231 chargingStation
.bootNotificationResponse
= response
;
1234 /* This is intentional */
1236 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1237 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1238 case OCPP16MessageTrigger
.Heartbeat
:
1240 chargingStation
.ocppRequestService
1241 .requestHandler
<OCPP16HeartbeatRequest
, OCPP16HeartbeatResponse
>(
1243 OCPP16RequestCommand
.HEARTBEAT
,
1246 triggerMessage
: true,
1250 /* This is intentional */
1252 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1253 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1254 case OCPP16MessageTrigger
.StatusNotification
:
1256 if (!Utils
.isNullOrUndefined(commandPayload
?.connectorId
)) {
1257 chargingStation
.ocppRequestService
1258 .requestHandler
<OCPP16StatusNotificationRequest
, OCPP16StatusNotificationResponse
>(
1260 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1262 connectorId
: commandPayload
.connectorId
,
1263 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1264 status: chargingStation
.getConnectorStatus(commandPayload
.connectorId
)?.status,
1267 triggerMessage
: true,
1271 /* This is intentional */
1274 for (const connectorId
of chargingStation
.connectors
.keys()) {
1275 chargingStation
.ocppRequestService
1277 OCPP16StatusNotificationRequest
,
1278 OCPP16StatusNotificationResponse
1281 OCPP16RequestCommand
.STATUS_NOTIFICATION
,
1284 errorCode
: OCPP16ChargePointErrorCode
.NO_ERROR
,
1285 status: chargingStation
.getConnectorStatus(connectorId
)?.status,
1288 triggerMessage
: true,
1292 /* This is intentional */
1296 }, Constants
.OCPP_TRIGGER_MESSAGE_DELAY
);
1297 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED
;
1299 return OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED
;
1302 return this.handleIncomingRequestError(
1304 OCPP16IncomingRequestCommand
.TRIGGER_MESSAGE
,
1306 { errorResponse
: OCPPConstants
.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED
}
1311 private handleRequestDataTransfer(
1312 chargingStation
: ChargingStation
,
1313 commandPayload
: OCPP16DataTransferRequest
1314 ): OCPP16DataTransferResponse
{
1316 if (Object.values(OCPP16DataTransferVendorId
).includes(commandPayload
.vendorId
)) {
1318 status: OCPP16DataTransferStatus
.ACCEPTED
,
1322 status: OCPP16DataTransferStatus
.UNKNOWN_VENDOR_ID
,
1325 return this.handleIncomingRequestError(
1327 OCPP16IncomingRequestCommand
.DATA_TRANSFER
,
1329 { errorResponse
: OCPPConstants
.OCPP_DATA_TRANSFER_RESPONSE_REJECTED
}