refactor: move template firmware defaults to constants
[e-mobility-charging-stations-simulator.git] / src / utils / Constants.ts
1 import {
2 type AutomaticTransactionGeneratorConfiguration,
3 type ChargingStationInfo,
4 CurrentType,
5 type IncomingRequestCommand,
6 OCPPVersion,
7 type RequestCommand,
8 VendorParametersKey
9 } from '../types/index.js'
10
11 // eslint-disable-next-line @typescript-eslint/no-extraneous-class
12 export class Constants {
13 // See https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
14 private static readonly SEMVER_PATTERN =
15 '^(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-]+)*))?$'
16
17 private static readonly DEFAULT_CHARGING_STATION_RESET_TIME = 30000 // Ms
18
19 static readonly DEFAULT_STATION_INFO: Partial<ChargingStationInfo> = Object.freeze({
20 enableStatistics: false,
21 autoStart: true,
22 remoteAuthorization: true,
23 currentOutType: CurrentType.AC,
24 mainVoltageMeterValues: true,
25 phaseLineToLineVoltageMeterValues: false,
26 customValueLimitationMeterValues: true,
27 ocppStrictCompliance: true,
28 outOfOrderEndMeterValues: false,
29 beginEndMeterValues: false,
30 meteringPerTransaction: true,
31 transactionDataMeterValues: false,
32 supervisionUrlOcppConfiguration: false,
33 supervisionUrlOcppKey: VendorParametersKey.ConnectionUrl,
34 useConnectorId0: true,
35 ocppVersion: OCPPVersion.VERSION_16,
36 firmwareVersionPattern: Constants.SEMVER_PATTERN,
37 firmwareUpgrade: {
38 versionUpgrade: {
39 step: 1
40 },
41 reset: true
42 },
43 ocppPersistentConfiguration: true,
44 stationInfoPersistentConfiguration: true,
45 automaticTransactionGeneratorPersistentConfiguration: true,
46 resetTime: Constants.DEFAULT_CHARGING_STATION_RESET_TIME,
47 autoReconnectMaxRetries: -1,
48 registrationMaxRetries: -1,
49 reconnectExponentialDelay: false,
50 stopTransactionsOnStopped: true
51 })
52
53 static readonly DEFAULT_BOOT_NOTIFICATION_INTERVAL = 60000 // Ms
54 static readonly DEFAULT_HEARTBEAT_INTERVAL = 60000 // Ms
55 static readonly DEFAULT_METER_VALUES_INTERVAL = 60000 // Ms
56
57 static readonly DEFAULT_ATG_WAIT_TIME = 1000 // Ms
58 static readonly DEFAULT_ATG_CONFIGURATION: AutomaticTransactionGeneratorConfiguration =
59 Object.freeze({
60 enable: false,
61 minDuration: 60,
62 maxDuration: 120,
63 minDelayBetweenTwoTransactions: 15,
64 maxDelayBetweenTwoTransactions: 30,
65 probabilityOfStart: 1,
66 stopAfterHours: 0.25,
67 stopAbsoluteDuration: false
68 })
69
70 static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 4096
71
72 static readonly DEFAULT_HASH_ALGORITHM = 'sha384'
73
74 static readonly DEFAULT_IDTAG = '00000000'
75
76 static readonly DEFAULT_CONNECTION_TIMEOUT = 30
77
78 static readonly DEFAULT_LOG_STATISTICS_INTERVAL = 60 // Seconds
79
80 static readonly DEFAULT_FLUCTUATION_PERCENT = 5
81
82 static readonly DEFAULT_PERFORMANCE_DIRECTORY = 'performance'
83 static readonly DEFAULT_PERFORMANCE_RECORDS_FILENAME = 'performanceRecords.json'
84 static readonly DEFAULT_PERFORMANCE_RECORDS_DB_NAME = 'e-mobility-charging-stations-simulator'
85 static readonly PERFORMANCE_RECORDS_TABLE = 'performance_records'
86
87 static readonly DEFAULT_UI_SERVER_HOST = 'localhost'
88 static readonly DEFAULT_UI_SERVER_PORT = 8080
89
90 static readonly UNKNOWN_OCPP_COMMAND = 'unknown OCPP command' as
91 | RequestCommand
92 | IncomingRequestCommand
93
94 static readonly MAX_RANDOM_INTEGER = 281474976710655
95
96 static readonly STOP_CHARGING_STATIONS_TIMEOUT = 60000 // Ms
97
98 static readonly EMPTY_FROZEN_OBJECT = Object.freeze({})
99 static readonly EMPTY_FUNCTION = Object.freeze(() => {
100 /* This is intentional */
101 })
102
103 static readonly DEFAULT_MESSAGE_BUFFER_FLUSH_INTERVAL = 60000 // Ms
104
105 private constructor () {
106 // This is intentional
107 }
108 }