X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=bd25116b990170ab1a4c776a693306a359d23021;hb=f3a6f63b4e690cecc8fdf84847a994970e12b94a;hp=71de426c4af701b5572320882b93015fc2a2e423;hpb=a7fc8211ff35f821074120edea9ddb6ce024d58d;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 71de426c..bd25116b 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -19,7 +19,7 @@ import { MessageType } from '../types/ocpp/MessageType'; import OCPP16IncomingRequestService from './ocpp/1.6/OCCP16IncomingRequestService'; import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService'; import OCPP16ResponseService from './ocpp/1.6/OCPP16ResponseService'; -import OCPPError from './OcppError'; +import OCPPError from './OCPPError'; import OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService'; import OCPPRequestService from './ocpp/OCPPRequestService'; import { OCPPVersion } from '../types/ocpp/OCPPVersion'; @@ -140,7 +140,7 @@ export default class ChargingStation { break; default: logger.error(errMsg); - throw Error(errMsg); + throw new Error(errMsg); } return !Utils.isUndefined(this.stationInfo.voltageOut) ? this.stationInfo.voltageOut : defaultVoltageOut; } @@ -228,7 +228,10 @@ export default class ChargingStation { } const sampledValueTemplates: SampledValueTemplate[] = this.getConnector(connectorId).MeterValues; for (let index = 0; !Utils.isEmptyArray(sampledValueTemplates) && index < sampledValueTemplates.length; index++) { - if (phase && sampledValueTemplates[index]?.phase === phase && sampledValueTemplates[index]?.measurand === measurand + if (!Constants.SUPPORTED_MEASURANDS.includes(sampledValueTemplates[index]?.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER)) { + logger.warn(`${this.logPrefix()} Unsupported MeterValues measurand ${measurand} ${phase ? `on phase ${phase} ` : ''}in template on connectorId ${connectorId}`); + continue; + } else if (phase && sampledValueTemplates[index]?.phase === phase && sampledValueTemplates[index]?.measurand === measurand && this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(measurand)) { return sampledValueTemplates[index]; } else if (!phase && !sampledValueTemplates[index].phase && sampledValueTemplates[index]?.measurand === measurand @@ -547,6 +550,13 @@ export default class ChargingStation { } // OCPP parameters this.initOCPPParameters(); + if (this.stationInfo.autoRegister) { + this.bootNotificationResponse = { + currentTime: new Date().toISOString(), + interval: this.getHeartbeatInterval() / 1000, + status: RegistrationStatus.ACCEPTED + }; + } this.stationInfo.powerDivider = this.getPowerDivider(); if (this.getEnableStatistics()) { this.performanceStatistics = new PerformanceStatistics(this.stationInfo.chargingStationId); @@ -643,8 +653,13 @@ export default class ChargingStation { let requestPayload: Record; let errMsg: string; try { - // Parse the message - [messageType, messageId, commandName, commandPayload, errorDetails] = JSON.parse(messageEvent.toString()) as IncomingRequest; + const request = JSON.parse(messageEvent.toString()) as IncomingRequest; + if (Utils.isIterable(request)) { + // Parse the message + [messageType, messageId, commandName, commandPayload, errorDetails] = request; + } else { + throw new Error('Incoming request is not iterable'); + } // Check the Type of message switch (messageType) { // Incoming Message @@ -692,7 +707,7 @@ export default class ChargingStation { } } catch (error) { // Log - logger.error('%s Incoming message %j processing error %j on request content type %j', this.logPrefix(), messageEvent, error, this.requests[messageId]); + logger.error('%s Incoming request message %j processing error %j on content type %j', this.logPrefix(), messageEvent, error, this.requests[messageId]); // Send error messageType !== MessageType.CALL_ERROR_MESSAGE && await this.ocppRequestService.sendError(messageId, error, commandName); } @@ -926,6 +941,8 @@ export default class ChargingStation { if (HeartBeatInterval) { return Utils.convertToInt(HeartBeatInterval.value) * 1000; } + !this.stationInfo.autoRegister && logger.warn(`${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${Constants.DEFAULT_HEARTBEAT_INTERVAL}`); + return Constants.DEFAULT_HEARTBEAT_INTERVAL; } private stopHeartbeat(): void {