X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16IncomingRequestService.ts;h=2301a0fec0d54a744db8f8a8adfc7a993ded3c7d;hb=85d206672d2dc688827177e4de87a069c4b2cdc1;hp=541a27fb631584efdc6a78aa7142b408e70ec672;hpb=802cfa135dad14f8b15401685c3429395cb3e6e1;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 541a27fb..2301a0fe 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1,7 +1,5 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. -import * as url from 'url'; - 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'; @@ -19,6 +17,7 @@ import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configurati import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration'; import OCPPError from '../OCPPError'; import OCPPIncomingRequestService from '../OCPPIncomingRequestService'; +import { URL } from 'url'; import Utils from '../../../utils/Utils'; import fs from 'fs'; import logger from '../../../utils/Logger'; @@ -59,7 +58,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer await Utils.sleep(this.chargingStation.stationInfo.resetTime); this.chargingStation.start(); }); - logger.info(`${this.chargingStation.logPrefix()} ${commandPayload.type} reset command received, simulating it. The station will be back online in ${Utils.milliSecondsToHHMMSS(this.chargingStation.stationInfo.resetTime)}`); + logger.info(`${this.chargingStation.logPrefix()} ${commandPayload.type} reset command received, simulating it. The station will be back online in ${Utils.formatDurationMilliSeconds(this.chargingStation.stationInfo.resetTime)}`); return Constants.OCPP_RESPONSE_ACCEPTED; } @@ -243,7 +242,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer if (connectorId === 0) { let response: ChangeAvailabilityResponse = Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED; for (const connector in this.chargingStation.connectors) { - if (this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionStarted) { + if (this.chargingStation.getConnector(Utils.convertToInt(connector))?.transactionStarted) { response = Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED; } this.chargingStation.getConnector(Utils.convertToInt(connector)).availability = commandPayload.type; @@ -354,7 +353,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer private async handleRequestGetDiagnostics(commandPayload: GetDiagnosticsRequest): Promise { logger.debug(this.chargingStation.logPrefix() + ' ' + IncomingRequestCommand.GET_DIAGNOSTICS + ' request received: %j', commandPayload); - const uri = new url.URL(commandPayload.location); + const uri = new URL(commandPayload.location); if (uri.protocol.startsWith('ftp:')) { let ftpClient: Client; try { @@ -407,19 +406,19 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer setTimeout(() => { this.chargingStation.ocppRequestService.sendBootNotification(this.chargingStation.getBootNotificationRequest().chargePointModel, this.chargingStation.getBootNotificationRequest().chargePointVendor, this.chargingStation.getBootNotificationRequest().chargeBoxSerialNumber, - this.chargingStation.getBootNotificationRequest().firmwareVersion).catch(() => {}); + this.chargingStation.getBootNotificationRequest().firmwareVersion).catch(() => { /* This is intentional */ }); }, Constants.OCPP_TRIGGER_MESSAGE_DELAY); return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED; case MessageTrigger.Heartbeat: setTimeout(() => { - this.chargingStation.ocppRequestService.sendHeartbeat().catch(() => {}); + this.chargingStation.ocppRequestService.sendHeartbeat().catch(() => { /* This is intentional */ }); }, 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) as OCPP16TriggerMessageResponse; + return this.handleIncomingRequestError(IncomingRequestCommand.TRIGGER_MESSAGE, error, Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED); } } }