X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16IncomingRequestService.ts;h=7fde148b4834af16a4428345cc745661536eefb8;hb=d4bc21e04c653b325c1b7d8cb28fe928915a3c28;hp=8f86f478c7aba1c4507b02edd6ab0ac5838edfe8;hpb=14763b466177d8e74d2e1925647e04e2d62ac72a;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 8f86f478..7fde148b 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -2,8 +2,8 @@ import * as url from 'url'; -import { ChangeAvailabilityRequest, ChangeConfigurationRequest, ClearChargingProfileRequest, GetConfigurationRequest, GetDiagnosticsRequest, OCPP16AvailabilityType, OCPP16IncomingRequestCommand, RemoteStartTransactionRequest, RemoteStopTransactionRequest, ResetRequest, SetChargingProfileRequest, UnlockConnectorRequest } from '../../../types/ocpp/1.6/Requests'; -import { ChangeAvailabilityResponse, ChangeConfigurationResponse, ClearChargingProfileResponse, GetConfigurationResponse, GetDiagnosticsResponse, SetChargingProfileResponse, UnlockConnectorResponse } from '../../../types/ocpp/1.6/Responses'; +import { ChangeAvailabilityRequest, ChangeConfigurationRequest, ClearChargingProfileRequest, GetConfigurationRequest, GetDiagnosticsRequest, MessageTrigger, OCPP16AvailabilityType, OCPP16IncomingRequestCommand, OCPP16TriggerMessageRequest, RemoteStartTransactionRequest, RemoteStopTransactionRequest, ResetRequest, SetChargingProfileRequest, UnlockConnectorRequest } from '../../../types/ocpp/1.6/Requests'; +import { ChangeAvailabilityResponse, ChangeConfigurationResponse, ClearChargingProfileResponse, GetConfigurationResponse, GetDiagnosticsResponse, OCPP16TriggerMessageResponse, SetChargingProfileResponse, UnlockConnectorResponse } from '../../../types/ocpp/1.6/Responses'; import { ChargingProfilePurposeType, OCPP16ChargingProfile } from '../../../types/ocpp/1.6/ChargingProfile'; import { Client, FTPResponse } from 'basic-ftp'; import { IncomingRequestCommand, RequestCommand } from '../../../types/ocpp/Requests'; @@ -43,9 +43,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } } else { // Throw exception - const errMsg = `${commandName} is not implemented to handle payload ${JSON.stringify(commandPayload, null, 2)}`; - await this.chargingStation.ocppRequestService.sendError(messageId, new OCPPError(ErrorType.NOT_IMPLEMENTED, errMsg), commandName); - throw new OCPPError(ErrorType.NOT_IMPLEMENTED, errMsg); + const error = new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle payload ${JSON.stringify(commandPayload, null, 2)}`, commandName); + await this.chargingStation.ocppRequestService.sendError(messageId, error, commandName); + throw error; } // Send the built response await this.chargingStation.ocppRequestService.sendMessage(messageId, response, MessageType.CALL_RESULT_MESSAGE, commandName); @@ -383,9 +383,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } return { fileName: diagnosticsArchive }; } - throw new OCPPError(ErrorType.GENERIC_ERROR, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`); + throw new OCPPError(ErrorType.GENERIC_ERROR, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`, IncomingRequestCommand.GET_DIAGNOSTICS); } - throw new OCPPError(ErrorType.GENERIC_ERROR, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`); + throw new OCPPError(ErrorType.GENERIC_ERROR, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`, IncomingRequestCommand.GET_DIAGNOSTICS); } catch (error) { await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus.UploadFailed); if (ftpClient) { @@ -399,4 +399,27 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer return Constants.OCPP_RESPONSE_EMPTY; } } + + private handleRequestTriggerMessage(commandPayload: OCPP16TriggerMessageRequest): OCPP16TriggerMessageResponse { + 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).catch(() => {}); + }, Constants.OCPP_TRIGGER_MESSAGE_DELAY); + return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED; + case MessageTrigger.Heartbeat: + setTimeout(() => { + this.chargingStation.ocppRequestService.sendHeartbeat().catch(() => {}); + }, Constants.OCPP_TRIGGER_MESSAGE_DELAY); + return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED; + default: + return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED; + } + } catch (error) { + return this.handleIncomingRequestError(IncomingRequestCommand.TRIGGER_MESSAGE, error, Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED); + } + } }