From: Jérôme Benoit Date: Fri, 10 Feb 2023 21:10:40 +0000 (+0100) Subject: fix(simulator): fix brown paper bag bugs after helpers semantic fix X-Git-Tag: v1.1.94~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9a15316cb7ede50d57ab25f758f0ccf1aa1bd903;p=e-mobility-charging-stations-simulator.git fix(simulator): fix brown paper bag bugs after helpers semantic fix Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 54e4df72..9d23f1b4 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -268,15 +268,19 @@ export class ChargingStationUtils { upperCase: params.randomSerialNumberUpperCase, }) : ''; - stationInfo.chargePointSerialNumber = - Utils.isNotEmptyString(stationTemplate?.chargePointSerialNumberPrefix) && - `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`; - stationInfo.chargeBoxSerialNumber = - Utils.isNotEmptyString(stationTemplate?.chargeBoxSerialNumberPrefix) && - `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`; - stationInfo.meterSerialNumber = - Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) && - `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`; + stationInfo.chargePointSerialNumber = Utils.isNotEmptyString( + stationTemplate?.chargePointSerialNumberPrefix + ) + ? `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}` + : undefined; + stationInfo.chargeBoxSerialNumber = Utils.isNotEmptyString( + stationTemplate?.chargeBoxSerialNumberPrefix + ) + ? `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}` + : undefined; + stationInfo.meterSerialNumber = Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) + ? `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}` + : undefined; } public static propagateSerialNumber( diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 7fcb12fb..3d5517dd 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -425,7 +425,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ): GetConfigurationResponse { const configurationKey: OCPPConfigurationKey[] = []; const unknownKey: string[] = []; - if (Utils.isEmptyArray(commandPayload.key) === true) { + if (Utils.isUndefined(commandPayload.key) === true) { for (const configuration of chargingStation.ocppConfiguration.configurationKey) { if (Utils.isUndefined(configuration.visible) === true) { configuration.visible = true; @@ -439,7 +439,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer value: configuration.value, }); } - } else { + } else if (Utils.isNotEmptyArray(commandPayload.key) === true) { for (const key of commandPayload.key) { const keyFound = ChargingStationConfigurationUtils.getConfigurationKey( chargingStation, diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 1d3bb76c..aa0cc723 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -8,8 +8,9 @@ import { MessageChannelUtils } from '../charging-station/MessageChannelUtils'; import { MessageType } from '../types/ocpp/MessageType'; import type { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; import type { Statistics, TimeSeries } from '../types/Statistics'; -import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray'; +import { CircularArray } from '../utils/CircularArray'; import Configuration from '../utils/Configuration'; +import Constants from '../utils/Constants'; import logger from '../utils/Logger'; import Utils from '../utils/Utils'; @@ -253,12 +254,12 @@ export default class PerformanceStatistics { this.statistics.statisticsData.get(entryName).avgTimeMeasurement = this.statistics.statisticsData.get(entryName).totalTimeMeasurement / this.statistics.statisticsData.get(entryName).countTimeMeasurement; - Array.isArray(this.statistics.statisticsData.get(entryName)?.timeMeasurementSeries) === true + this.statistics.statisticsData.get(entryName)?.timeMeasurementSeries instanceof CircularArray ? this.statistics.statisticsData .get(entryName) ?.timeMeasurementSeries?.push({ timestamp: entry.startTime, value: entry.duration }) : (this.statistics.statisticsData.get(entryName).timeMeasurementSeries = - new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, { + new CircularArray(Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY, { timestamp: entry.startTime, value: entry.duration, })); diff --git a/src/types/ocpp/1.6/Requests.ts b/src/types/ocpp/1.6/Requests.ts index f8a19570..89316dc6 100644 --- a/src/types/ocpp/1.6/Requests.ts +++ b/src/types/ocpp/1.6/Requests.ts @@ -82,7 +82,7 @@ export interface UnlockConnectorRequest extends JsonObject { } export interface GetConfigurationRequest extends JsonObject { - key?: string | OCPP16StandardParametersKey[]; + key?: (string | OCPP16StandardParametersKey)[]; } export enum ResetType { diff --git a/src/utils/CircularArray.ts b/src/utils/CircularArray.ts index 5fdeeaad..ad25bf85 100644 --- a/src/utils/CircularArray.ts +++ b/src/utils/CircularArray.ts @@ -1,6 +1,6 @@ // Copyright Jerome Benoit. 2021-2023. All Rights Reserved. -export const DEFAULT_CIRCULAR_ARRAY_SIZE = Number.MAX_SAFE_INTEGER; +const DEFAULT_CIRCULAR_ARRAY_SIZE = 1024; /** * Array with a maximum length shifting items when full. diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 241018fc..c6c691b0 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -13,7 +13,7 @@ export default class Constants { static readonly SEMVER_PATTERN = '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$'; - static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = Number.MAX_SAFE_INTEGER; + static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 1024; static readonly DEFAULT_HASH_ALGORITHM = 'sha384'; diff --git a/test/utils/CircularArrayTest.ts b/test/utils/CircularArrayTest.ts index c8b38a9a..10174520 100644 --- a/test/utils/CircularArrayTest.ts +++ b/test/utils/CircularArrayTest.ts @@ -10,7 +10,7 @@ describe('Circular array test suite', () => { it('Verify circular array default size at instance creation', () => { const circularArray = new CircularArray(); - expect(circularArray.size).toBe(Number.MAX_SAFE_INTEGER); + expect(circularArray.size).toBe(1024); }); it('Verify that circular array size can be set at instance creation', () => {