repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: use native node random integer generator
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
OCPPServiceUtils.ts
diff --git
a/src/charging-station/ocpp/OCPPServiceUtils.ts
b/src/charging-station/ocpp/OCPPServiceUtils.ts
index 0a3935c4130e408631e5b800b9432bc2229e42cd..8a42bf67a7b05f361374a1d04bf996ab5d6b304f 100644
(file)
--- 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'
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 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,
import {
type ChargingStation,
getConfigurationKey,
@@
-51,23
+49,25
@@
import {
import {
ACElectricUtils,
Constants,
import {
ACElectricUtils,
Constants,
- DCElectricUtils,
convertToFloat,
convertToInt,
convertToFloat,
convertToInt,
+ DCElectricUtils,
getRandomFloatFluctuatedRounded,
getRandomFloatRounded,
getRandomFloatFluctuatedRounded,
getRandomFloatRounded,
- getRandomInteger,
handleFileException,
isNotEmptyArray,
isNotEmptyString,
handleFileException,
isNotEmptyArray,
isNotEmptyString,
- logPrefix,
logger,
logger,
+ logPrefix,
max,
min,
roundTo
} from '../../utils/index.js'
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'
switch (messageType) {
case MessageType.CALL_MESSAGE:
return 'request'
@@
-284,7
+284,7
@@
export const buildMeterValue = (
parseInt(socSampledValueTemplate.value),
socSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT
)
parseInt(socSampledValueTemplate.value),
socSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT
)
- :
getRandomInteger(socMaximumValue, socMin
imumValue)
+ :
randomInt(socMinimumValue, socMax
imumValue)
meterValue.sampledValue.push(
buildSampledValue(socSampledValueTemplate, socSampledValueTemplateValue)
)
meterValue.sampledValue.push(
buildSampledValue(socSampledValueTemplate, socSampledValueTemplateValue)
)