X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ResponseService.ts;h=05e2ed9a4f7e0c4043a2d31d6caf616f7d73953f;hb=d18886407cdb8b8148c87492f2c953075e708401;hp=3e63c84ac90e6c128f614a20225adaaf148b30d0;hpb=a4bc29426a2f56c987ec161d86baf9a83c0398ca;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 3e63c84a..05e2ed9a 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -7,10 +7,11 @@ import { MeterValuesRequest, MeterValuesResponse } from '../../../types/ocpp/1.6 import ChargingStation from '../../ChargingStation'; import { ErrorType } from '../../../types/ocpp/ErrorType'; +import { JsonType } from '../../../types/JsonType'; import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration'; -import OCPPError from '../OCPPError'; +import OCPPError from '../../../exception/OCPPError'; import OCPPResponseService from '../OCPPResponseService'; import { ResponseHandler } from '../../../types/ocpp/Responses'; import Utils from '../../../utils/Utils'; @@ -32,24 +33,28 @@ export default class OCPP16ResponseService extends OCPPResponseService { ]); } - public async handleResponse(commandName: OCPP16RequestCommand, payload: Record | string, requestPayload: Record): Promise { - if (this.responseHandlers.has(commandName)) { - try { - await this.responseHandlers.get(commandName)(payload, requestPayload); - } catch (error) { - logger.error(this.chargingStation.logPrefix() + ' Handle request response error: %j', error); - throw error; + public async handleResponse(commandName: OCPP16RequestCommand, payload: JsonType | string, requestPayload: JsonType): Promise { + if (this.chargingStation.isRegistered() || commandName === OCPP16RequestCommand.BOOT_NOTIFICATION) { + if (this.responseHandlers.has(commandName)) { + try { + await this.responseHandlers.get(commandName)(payload, requestPayload); + } catch (error) { + logger.error(this.chargingStation.logPrefix() + ' Handle request response error: %j', error); + throw error; + } + } else { + // Throw exception + throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request response payload ${JSON.stringify(payload, null, 2)}`, commandName); } } else { - // Throw exception - throw new OCPPError(ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle request response payload ${JSON.stringify(payload, null, 2)}`, commandName); + throw new OCPPError(ErrorType.SECURITY_ERROR, `The charging station is not registered on the central server. ${commandName} cannot be not issued to handle request response payload ${JSON.stringify(payload, null, 2)}`, commandName); } } private handleResponseBootNotification(payload: OCPP16BootNotificationResponse): void { if (payload.status === OCPP16RegistrationStatus.ACCEPTED) { this.chargingStation.addConfigurationKey(OCPP16StandardParametersKey.HeartBeatInterval, payload.interval.toString()); - this.chargingStation.addConfigurationKey(OCPP16StandardParametersKey.HeartbeatInterval, payload.interval.toString(), false, false); + this.chargingStation.addConfigurationKey(OCPP16StandardParametersKey.HeartbeatInterval, payload.interval.toString(), { visible: false }); this.chargingStation.heartbeatSetInterval ? this.chargingStation.restartHeartbeat() : this.chargingStation.startHeartbeat(); } else if (payload.status === OCPP16RegistrationStatus.PENDING) { logger.info(this.chargingStation.logPrefix() + ' Charging station in pending state on the central server');