X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPServiceUtils.ts;h=8a42bf67a7b05f361374a1d04bf996ab5d6b304f;hb=fcda9151b9eb6d13f06f7a5db45c89a77bda9eb8;hp=0a3935c4130e408631e5b800b9432bc2229e42cd;hpb=1d6f2eb4f4c766283604e417bd34e16f18c8e997;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 0a3935c4..8a42bf67 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -1,3 +1,4 @@ +import { randomInt } from 'node:crypto' import { readFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' @@ -5,9 +6,6 @@ import { fileURLToPath } from 'node:url' import type { DefinedError, ErrorObject, JSONSchemaType } from 'ajv' import { isDate } from 'date-fns' -import { OCPP16Constants } from './1.6/OCPP16Constants.js' -import { OCPP20Constants } from './2.0/OCPP20Constants.js' -import { OCPPConstants } from './OCPPConstants.js' import { type ChargingStation, getConfigurationKey, @@ -51,23 +49,25 @@ import { import { ACElectricUtils, Constants, - DCElectricUtils, convertToFloat, convertToInt, + DCElectricUtils, getRandomFloatFluctuatedRounded, getRandomFloatRounded, - getRandomInteger, handleFileException, isNotEmptyArray, isNotEmptyString, - logPrefix, logger, + logPrefix, max, min, roundTo } from '../../utils/index.js' +import { OCPP16Constants } from './1.6/OCPP16Constants.js' +import { OCPP20Constants } from './2.0/OCPP20Constants.js' +import { OCPPConstants } from './OCPPConstants.js' -export const getMessageTypeString = (messageType: MessageType): string => { +export const getMessageTypeString = (messageType: MessageType | undefined): string => { switch (messageType) { case MessageType.CALL_MESSAGE: return 'request' @@ -284,7 +284,7 @@ export const buildMeterValue = ( parseInt(socSampledValueTemplate.value), socSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT ) - : getRandomInteger(socMaximumValue, socMinimumValue) + : randomInt(socMinimumValue, socMaximumValue) meterValue.sampledValue.push( buildSampledValue(socSampledValueTemplate, socSampledValueTemplateValue) )