X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16IncomingRequestService.ts;h=937edd41cc22000530c000dbba844a2282d4fe8a;hb=6f35d2daed5ff5d26de15c1547ffa3dbd013c5b3;hp=ef1c7db2e8d96b8c8dfb57edad7976e82a455a21;hpb=e7aeea18e189dd087c8f951cf77a253e2818ae90;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index ef1c7db2..937edd41 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -4,12 +4,16 @@ import { ChangeAvailabilityRequest, ChangeConfigurationRequest, ClearChargingProfileRequest, + DiagnosticsStatusNotificationRequest, GetConfigurationRequest, GetDiagnosticsRequest, MessageTrigger, OCPP16AvailabilityType, + OCPP16BootNotificationRequest, + OCPP16HeartbeatRequest, OCPP16IncomingRequestCommand, OCPP16RequestCommand, + OCPP16StatusNotificationRequest, OCPP16TriggerMessageRequest, RemoteStartTransactionRequest, RemoteStopTransactionRequest, @@ -21,8 +25,12 @@ import { ChangeAvailabilityResponse, ChangeConfigurationResponse, ClearChargingProfileResponse, + DiagnosticsStatusNotificationResponse, GetConfigurationResponse, GetDiagnosticsResponse, + OCPP16BootNotificationResponse, + OCPP16HeartbeatResponse, + OCPP16StatusNotificationResponse, OCPP16TriggerMessageResponse, SetChargingProfileResponse, UnlockConnectorResponse, @@ -34,8 +42,22 @@ import { import { Client, FTPResponse } from 'basic-ftp'; import { OCPP16AuthorizationStatus, + OCPP16AuthorizeRequest, + OCPP16AuthorizeResponse, + OCPP16StartTransactionRequest, + OCPP16StartTransactionResponse, OCPP16StopTransactionReason, + OCPP16StopTransactionRequest, + OCPP16StopTransactionResponse, } from '../../../types/ocpp/1.6/Transaction'; +import { + OCPP16MeterValuesRequest, + OCPP16MeterValuesResponse, +} from '../../../types/ocpp/1.6/MeterValues'; +import { + OCPP16StandardParametersKey, + OCPP16SupportedFeatureProfiles, +} from '../../../types/ocpp/1.6/Configuration'; import type ChargingStation from '../../ChargingStation'; import Constants from '../../../utils/Constants'; @@ -43,9 +65,10 @@ import { DefaultResponse } from '../../../types/ocpp/Responses'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { IncomingRequestHandler } from '../../../types/ocpp/Requests'; import { JsonType } from '../../../types/JsonType'; +import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus'; -import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration'; +import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration'; import OCPPError from '../../../exception/OCPPError'; import OCPPIncomingRequestService from '../OCPPIncomingRequestService'; @@ -201,21 +224,48 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) { const transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId; - const stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction( + if ( + this.chargingStation.getBeginEndMeterValues() && + this.chargingStation.getOcppStrictCompliance() && + !this.chargingStation.getOutOfOrderEndMeterValues() + ) { + // FIXME: Implement OCPP version agnostic helpers + const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue( + this.chargingStation, + connectorId, + this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId) + ); + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16MeterValuesRequest, + OCPP16MeterValuesResponse + >(OCPP16RequestCommand.METER_VALUES, { + connectorId, + transactionId, + meterValue: transactionEndMeterValue, + }); + } + const stopResponse = await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StopTransactionRequest, + OCPP16StopTransactionResponse + >(OCPP16RequestCommand.STOP_TRANSACTION, { transactionId, - this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), - this.chargingStation.getTransactionIdTag(transactionId), - OCPP16StopTransactionReason.UNLOCK_COMMAND - ); + meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), + idTag: this.chargingStation.getTransactionIdTag(transactionId), + reason: OCPP16StopTransactionReason.UNLOCK_COMMAND, + }); if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { return Constants.OCPP_RESPONSE_UNLOCKED; } return Constants.OCPP_RESPONSE_UNLOCK_FAILED; } - await this.chargingStation.ocppRequestService.sendStatusNotification( + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StatusNotificationRequest, + OCPP16StatusNotificationResponse + >(OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - OCPP16ChargePointStatus.AVAILABLE - ); + status: OCPP16ChargePointStatus.AVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; return Constants.OCPP_RESPONSE_UNLOCKED; } @@ -226,7 +276,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer const configurationKey: OCPPConfigurationKey[] = []; const unknownKey: string[] = []; if (Utils.isEmptyArray(commandPayload.key)) { - for (const configuration of this.chargingStation.configuration.configurationKey) { + for (const configuration of this.chargingStation.ocppConfiguration.configurationKey) { if (Utils.isUndefined(configuration.visible)) { configuration.visible = true; } @@ -272,7 +322,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer if (!Utils.isString(commandPayload.key)) { logger.error( `${this.chargingStation.logPrefix()} ${ - OCPP16RequestCommand.CHANGE_CONFIGURATION + OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION } request key field is not a string:`, commandPayload ); @@ -280,7 +330,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer if (!Utils.isString(commandPayload.value)) { logger.error( `${this.chargingStation.logPrefix()} ${ - OCPP16RequestCommand.CHANGE_CONFIGURATION + OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION } request value field is not a string:`, commandPayload ); @@ -291,12 +341,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } else if (keyToChange && keyToChange.readonly) { return Constants.OCPP_CONFIGURATION_RESPONSE_REJECTED; } else if (keyToChange && !keyToChange.readonly) { - const keyIndex = this.chargingStation.configuration.configurationKey.indexOf(keyToChange); let valueChanged = false; - if ( - this.chargingStation.configuration.configurationKey[keyIndex].value !== commandPayload.value - ) { - this.chargingStation.configuration.configurationKey[keyIndex].value = commandPayload.value; + if (keyToChange.value !== commandPayload.value) { + this.chargingStation.setConfigurationKeyValue( + commandPayload.key, + commandPayload.value, + true + ); valueChanged = true; } let triggerHeartbeatRestart = false; @@ -330,6 +381,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer private handleRequestSetChargingProfile( commandPayload: SetChargingProfileRequest ): SetChargingProfileResponse { + if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.SmartCharging)) { + logger.error( + `${this.chargingStation.logPrefix()} Trying to set charging profile(s) without '${ + OCPP16SupportedFeatureProfiles.SmartCharging + }' feature enabled in ${ + OCPP16StandardParametersKey.SupportedFeatureProfiles + } in configuration` + ); + return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED; + } if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) { logger.error( `${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${ @@ -358,7 +419,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer commandPayload.csChargingProfiles ); logger.debug( - `${this.chargingStation.logPrefix()} Charging profile(s) set, dump their stack: %j`, + `${this.chargingStation.logPrefix()} Charging profile(s) set on connector id ${ + commandPayload.connectorId + }, dump their stack: %j`, this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles ); return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED; @@ -367,7 +430,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer private handleRequestClearChargingProfile( commandPayload: ClearChargingProfileRequest ): ClearChargingProfileResponse { - if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) { + if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.SmartCharging)) { + logger.error( + `${this.chargingStation.logPrefix()} Trying to clear charging profile(s) without '${ + OCPP16SupportedFeatureProfiles.SmartCharging + }' feature enabled in ${ + OCPP16StandardParametersKey.SupportedFeatureProfiles + } in configuration` + ); + return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN; + } + const connectorStatus = this.chargingStation.getConnectorStatus(commandPayload.connectorId); + if (!connectorStatus) { logger.error( `${this.chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${ commandPayload.connectorId @@ -375,16 +449,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ); return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN; } - if ( - commandPayload.connectorId && - !Utils.isEmptyArray( - this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles - ) - ) { - this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles = []; + if (commandPayload.connectorId && !Utils.isEmptyArray(connectorStatus.chargingProfiles)) { + connectorStatus.chargingProfiles = []; logger.debug( - `${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, - this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles + `${this.chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${ + commandPayload.connectorId + }, dump their stack: %j`, + connectorStatus.chargingProfiles ); return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED; } @@ -420,13 +491,12 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer clearCurrentCP = true; } if (clearCurrentCP) { - this.chargingStation.getConnectorStatus( - commandPayload.connectorId - ).chargingProfiles[index] = {} as OCPP16ChargingProfile; + connectorStatus.chargingProfiles[index] = {} as OCPP16ChargingProfile; logger.debug( - `${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, - this.chargingStation.getConnectorStatus(commandPayload.connectorId) - .chargingProfiles + `${this.chargingStation.logPrefix()} Matching charging profile(s) cleared on connector id ${ + commandPayload.connectorId + }, dump their stack: %j`, + connectorStatus.chargingProfiles ); clearedCP = true; } @@ -462,10 +532,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } this.chargingStation.getConnectorStatus(id).availability = commandPayload.type; if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - id, - chargePointStatus - ); + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StatusNotificationRequest, + OCPP16StatusNotificationResponse + >(OCPP16RequestCommand.STATUS_NOTIFICATION, { + connectorId: id, + status: chargePointStatus, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); this.chargingStation.getConnectorStatus(id).status = chargePointStatus; } } @@ -483,10 +557,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED; } this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type; - await this.chargingStation.ocppRequestService.sendStatusNotification( + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StatusNotificationRequest, + OCPP16StatusNotificationResponse + >(OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - chargePointStatus - ); + status: chargePointStatus, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); this.chargingStation.getConnectorStatus(connectorId).status = chargePointStatus; return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED; } @@ -496,18 +574,19 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer private async handleRequestRemoteStartTransaction( commandPayload: RemoteStartTransactionRequest ): Promise { - const transactionConnectorId: number = commandPayload.connectorId; + const transactionConnectorId = commandPayload.connectorId; + const connectorStatus = this.chargingStation.getConnectorStatus(transactionConnectorId); if (transactionConnectorId) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - transactionConnectorId, - OCPP16ChargePointStatus.PREPARING - ); - this.chargingStation.getConnectorStatus(transactionConnectorId).status = - OCPP16ChargePointStatus.PREPARING; - if ( - this.chargingStation.isChargingStationAvailable() && - this.chargingStation.isConnectorAvailable(transactionConnectorId) - ) { + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StatusNotificationRequest, + OCPP16StatusNotificationResponse + >(OCPP16RequestCommand.STATUS_NOTIFICATION, { + connectorId: transactionConnectorId, + status: OCPP16ChargePointStatus.PREPARING, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); + connectorStatus.status = OCPP16ChargePointStatus.PREPARING; + if (this.chargingStation.isChargingStationAvailable() && connectorStatus) { // Check if authorized if (this.chargingStation.getAuthorizeRemoteTxRequests()) { let authorized = false; @@ -516,16 +595,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer this.chargingStation.hasAuthorizedTags() && this.chargingStation.authorizedTags.find((value) => value === commandPayload.idTag) ) { - this.chargingStation.getConnectorStatus(transactionConnectorId).localAuthorizeIdTag = - commandPayload.idTag; - this.chargingStation.getConnectorStatus(transactionConnectorId).idTagLocalAuthorized = - true; + connectorStatus.localAuthorizeIdTag = commandPayload.idTag; + connectorStatus.idTagLocalAuthorized = true; authorized = true; } else if (this.chargingStation.getMayAuthorizeAtRemoteStart()) { - const authorizeResponse = await this.chargingStation.ocppRequestService.sendAuthorize( - transactionConnectorId, - commandPayload.idTag - ); + connectorStatus.authorizeIdTag = commandPayload.idTag; + const authorizeResponse: OCPP16AuthorizeResponse = + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16AuthorizeRequest, + OCPP16AuthorizeResponse + >(OCPP16RequestCommand.AUTHORIZE, { + idTag: commandPayload.idTag, + }); if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { authorized = true; } @@ -542,15 +623,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer commandPayload.chargingProfile ) ) { - this.chargingStation.getConnectorStatus( - transactionConnectorId - ).transactionRemoteStarted = true; + connectorStatus.transactionRemoteStarted = true; if ( ( - await this.chargingStation.ocppRequestService.sendStartTransaction( - transactionConnectorId, - commandPayload.idTag - ) + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StartTransactionRequest, + OCPP16StartTransactionResponse + >(OCPP16RequestCommand.START_TRANSACTION, { + connectorId: transactionConnectorId, + idTag: commandPayload.idTag, + }) ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED ) { logger.debug( @@ -586,14 +668,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer commandPayload.chargingProfile ) ) { - this.chargingStation.getConnectorStatus(transactionConnectorId).transactionRemoteStarted = - true; + connectorStatus.transactionRemoteStarted = true; if ( ( - await this.chargingStation.ocppRequestService.sendStartTransaction( - transactionConnectorId, - commandPayload.idTag - ) + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StartTransactionRequest, + OCPP16StartTransactionResponse + >(OCPP16RequestCommand.START_TRANSACTION, { + connectorId: transactionConnectorId, + idTag: commandPayload.idTag, + }) ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED ) { logger.debug( @@ -633,10 +717,14 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer this.chargingStation.getConnectorStatus(connectorId).status !== OCPP16ChargePointStatus.AVAILABLE ) { - await this.chargingStation.ocppRequestService.sendStatusNotification( + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StatusNotificationRequest, + OCPP16StatusNotificationResponse + >(OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - OCPP16ChargePointStatus.AVAILABLE - ); + status: OCPP16ChargePointStatus.AVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; } @@ -661,7 +749,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) { this.chargingStation.setChargingProfile(connectorId, cp); logger.debug( - `${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction, dump their stack: %j`, + `${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}, dump their stack: %j`, this.chargingStation.getConnectorStatus(connectorId).chargingProfiles ); return true; @@ -686,17 +774,45 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer connectorId > 0 && this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId ) { - await this.chargingStation.ocppRequestService.sendStatusNotification( + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StatusNotificationRequest, + OCPP16StatusNotificationResponse + >(OCPP16RequestCommand.STATUS_NOTIFICATION, { connectorId, - OCPP16ChargePointStatus.FINISHING - ); + status: OCPP16ChargePointStatus.FINISHING, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + }); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.FINISHING; - await this.chargingStation.ocppRequestService.sendStopTransaction( + if ( + this.chargingStation.getBeginEndMeterValues() && + this.chargingStation.getOcppStrictCompliance() && + !this.chargingStation.getOutOfOrderEndMeterValues() + ) { + // FIXME: Implement OCPP version agnostic helpers + const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue( + this.chargingStation, + connectorId, + this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId) + ); + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16MeterValuesRequest, + OCPP16MeterValuesResponse + >(OCPP16RequestCommand.METER_VALUES, { + connectorId, + transactionId, + meterValue: transactionEndMeterValue, + }); + } + await this.chargingStation.ocppRequestService.sendMessageHandler< + OCPP16StopTransactionRequest, + OCPP16StopTransactionResponse + >(OCPP16RequestCommand.STOP_TRANSACTION, { transactionId, - this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), - this.chargingStation.getTransactionIdTag(transactionId) - ); + meterStop: + this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), + idTag: this.chargingStation.getTransactionIdTag(transactionId), + }); return Constants.OCPP_RESPONSE_ACCEPTED; } } @@ -711,6 +827,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer private async handleRequestGetDiagnostics( commandPayload: GetDiagnosticsRequest ): Promise { + if ( + !this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.FirmwareManagement) + ) { + logger.error( + `${this.chargingStation.logPrefix()} Trying to get diagnostics without '${ + OCPP16SupportedFeatureProfiles.FirmwareManagement + }' feature enabled in ${ + OCPP16StandardParametersKey.SupportedFeatureProfiles + } in configuration` + ); + return Constants.OCPP_RESPONSE_EMPTY; + } logger.debug( this.chargingStation.logPrefix() + ' ' + @@ -732,9 +860,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ftpClient = new Client(); const accessResponse = await ftpClient.access({ host: uri.host, - ...(uri.port !== '' && { port: Utils.convertToInt(uri.port) }), - ...(uri.username !== '' && { user: uri.username }), - ...(uri.password !== '' && { password: uri.password }), + ...(!Utils.isEmptyString(uri.port) && { port: Utils.convertToInt(uri.port) }), + ...(!Utils.isEmptyString(uri.username) && { user: uri.username }), + ...(!Utils.isEmptyString(uri.password) && { password: uri.password }), }); let uploadResponse: FTPResponse; if (accessResponse.code === 220) { @@ -745,18 +873,24 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer info.bytes / 1024 } bytes transferred from diagnostics archive ${info.name}` ); - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.Uploading - ); + await this.chargingStation.ocppRequestService.sendMessageHandler< + DiagnosticsStatusNotificationRequest, + DiagnosticsStatusNotificationResponse + >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, { + status: OCPP16DiagnosticsStatus.Uploading, + }); }); uploadResponse = await ftpClient.uploadFrom( path.join(path.resolve(__dirname, '../../../../'), diagnosticsArchive), uri.pathname + diagnosticsArchive ); if (uploadResponse.code === 226) { - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.Uploaded - ); + await this.chargingStation.ocppRequestService.sendMessageHandler< + DiagnosticsStatusNotificationRequest, + DiagnosticsStatusNotificationResponse + >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, { + status: OCPP16DiagnosticsStatus.Uploaded, + }); if (ftpClient) { ftpClient.close(); } @@ -778,9 +912,12 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer OCPP16IncomingRequestCommand.GET_DIAGNOSTICS ); } catch (error) { - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.UploadFailed - ); + await this.chargingStation.ocppRequestService.sendMessageHandler< + DiagnosticsStatusNotificationRequest, + DiagnosticsStatusNotificationResponse + >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, { + status: OCPP16DiagnosticsStatus.UploadFailed, + }); if (ftpClient) { ftpClient.close(); } @@ -796,9 +933,12 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer uri.protocol } to transfer the diagnostic logs archive` ); - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.UploadFailed - ); + await this.chargingStation.ocppRequestService.sendMessageHandler< + DiagnosticsStatusNotificationRequest, + DiagnosticsStatusNotificationResponse + >(OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, { + status: OCPP16DiagnosticsStatus.UploadFailed, + }); return Constants.OCPP_RESPONSE_EMPTY; } } @@ -806,23 +946,45 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer private handleRequestTriggerMessage( commandPayload: OCPP16TriggerMessageRequest ): OCPP16TriggerMessageResponse { + if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.RemoteTrigger)) { + logger.error( + `${this.chargingStation.logPrefix()} Trying to remote trigger message without '${ + OCPP16SupportedFeatureProfiles.RemoteTrigger + }' feature enabled in ${ + OCPP16StandardParametersKey.SupportedFeatureProfiles + } in configuration` + ); + return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED; + } try { switch (commandPayload.requestedMessage) { case MessageTrigger.BootNotification: setTimeout(() => { this.chargingStation.ocppRequestService - .sendBootNotification( - this.chargingStation.getBootNotificationRequest().chargePointModel, - this.chargingStation.getBootNotificationRequest().chargePointVendor, - this.chargingStation.getBootNotificationRequest().chargeBoxSerialNumber, - this.chargingStation.getBootNotificationRequest().firmwareVersion, - this.chargingStation.getBootNotificationRequest().chargePointSerialNumber, - this.chargingStation.getBootNotificationRequest().iccid, - this.chargingStation.getBootNotificationRequest().imsi, - this.chargingStation.getBootNotificationRequest().meterSerialNumber, - this.chargingStation.getBootNotificationRequest().meterType, - { triggerMessage: true } + .sendMessageHandler( + OCPP16RequestCommand.BOOT_NOTIFICATION, + { + chargePointModel: + this.chargingStation.getBootNotificationRequest().chargePointModel, + chargePointVendor: + this.chargingStation.getBootNotificationRequest().chargePointVendor, + chargeBoxSerialNumber: + this.chargingStation.getBootNotificationRequest().chargeBoxSerialNumber, + firmwareVersion: + this.chargingStation.getBootNotificationRequest().firmwareVersion, + chargePointSerialNumber: + this.chargingStation.getBootNotificationRequest().chargePointSerialNumber, + iccid: this.chargingStation.getBootNotificationRequest().iccid, + imsi: this.chargingStation.getBootNotificationRequest().imsi, + meterSerialNumber: + this.chargingStation.getBootNotificationRequest().meterSerialNumber, + meterType: this.chargingStation.getBootNotificationRequest().meterType, + }, + { skipBufferingOnError: true, triggerMessage: true } ) + .then((value) => { + this.chargingStation.bootNotificationResponse = value; + }) .catch(() => { /* This is intentional */ }); @@ -831,7 +993,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer case MessageTrigger.Heartbeat: setTimeout(() => { this.chargingStation.ocppRequestService - .sendHeartbeat({ triggerMessage: true }) + .sendMessageHandler( + OCPP16RequestCommand.HEARTBEAT, + null, + { + triggerMessage: true, + } + ) .catch(() => { /* This is intentional */ });