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
build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ChargingStation.ts
diff --git
a/src/charging-station/ChargingStation.ts
b/src/charging-station/ChargingStation.ts
index 080349eae731cbe27e9ba6b00354da0d40a66f7e..e217991ac8aad3c7c4256010687929df0f0162a3 100644
(file)
--- a/
src/charging-station/ChargingStation.ts
+++ b/
src/charging-station/ChargingStation.ts
@@
-120,8
+120,9
@@
import {
createSerialNumber,
getAmperageLimitationUnitDivider,
getBootConnectorStatus,
createSerialNumber,
getAmperageLimitationUnitDivider,
getBootConnectorStatus,
- getChargingStationC
onnectorChargingProfilesPower
Limit,
+ getChargingStationC
hargingProfiles
Limit,
getChargingStationId,
getChargingStationId,
+ getConnectorChargingProfilesLimit,
getDefaultVoltageOut,
getHashId,
getIdTagsFile,
getDefaultVoltageOut,
getHashId,
getIdTagsFile,
@@
-131,6
+132,7
@@
import {
hasFeatureProfile,
hasReservationExpired,
initializeConnectorsMapStatus,
hasFeatureProfile,
hasReservationExpired,
initializeConnectorsMapStatus,
+ prepareConnectorStatus,
propagateSerialNumber,
setChargingStationOptions,
stationTemplateToStationInfo,
propagateSerialNumber,
setChargingStationOptions,
stationTemplateToStationInfo,
@@
-181,7
+183,6
@@
export class ChargingStation extends EventEmitter {
private ocppIncomingRequestService!: OCPPIncomingRequestService
private readonly messageBuffer: Set<string>
private configuredSupervisionUrl!: URL
private ocppIncomingRequestService!: OCPPIncomingRequestService
private readonly messageBuffer: Set<string>
private configuredSupervisionUrl!: URL
- private wsConnectionRetried: boolean
private wsConnectionRetryCount: number
private templateFileWatcher?: FSWatcher
private templateFileHash!: string
private wsConnectionRetryCount: number
private templateFileWatcher?: FSWatcher
private templateFileHash!: string
@@
-196,7
+197,6
@@
export class ChargingStation extends EventEmitter {
this.starting = false
this.stopping = false
this.wsConnection = null
this.starting = false
this.stopping = false
this.wsConnection = null
- this.wsConnectionRetried = false
this.wsConnectionRetryCount = 0
this.index = index
this.templateFile = templateFile
this.wsConnectionRetryCount = 0
this.index = index
this.templateFile = templateFile
@@
-225,16
+225,21
@@
export class ChargingStation extends EventEmitter {
})
this.on(ChargingStationEvents.accepted, () => {
this.startMessageSequence(
})
this.on(ChargingStationEvents.accepted, () => {
this.startMessageSequence(
- this.wsConnectionRetr
ied
+ this.wsConnectionRetr
yCount > 0
? true
: this.getAutomaticTransactionGeneratorConfiguration()?.stopAbsoluteDuration
).catch((error: unknown) => {
logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error)
})
? true
: this.getAutomaticTransactionGeneratorConfiguration()?.stopAbsoluteDuration
).catch((error: unknown) => {
logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error)
})
- this.wsConnectionRetr
ied = false
+ this.wsConnectionRetr
yCount = 0
})
this.on(ChargingStationEvents.rejected, () => {
})
this.on(ChargingStationEvents.rejected, () => {
- this.wsConnectionRetried = false
+ this.wsConnectionRetryCount = 0
+ })
+ this.on(ChargingStationEvents.connected, () => {
+ if (this.wsPingSetInterval == null) {
+ this.startWebSocketPing()
+ }
})
this.on(ChargingStationEvents.disconnected, () => {
try {
})
this.on(ChargingStationEvents.disconnected, () => {
try {
@@
-269,7
+274,9
@@
export class ChargingStation extends EventEmitter {
: this.configuredSupervisionUrl.href
}`
return new URL(
: this.configuredSupervisionUrl.href
}`
return new URL(
- `${wsConnectionBaseUrlStr}${!wsConnectionBaseUrlStr.endsWith('/') ? '/' : ''}${this.stationInfo?.chargingStationId}`
+ `${wsConnectionBaseUrlStr}${
+ !wsConnectionBaseUrlStr.endsWith('/') ? '/' : ''
+ }${this.stationInfo?.chargingStationId}`
)
}
)
}
@@
-385,14
+392,14
@@
export class ChargingStation extends EventEmitter {
}
public getConnectorMaximumAvailablePower (connectorId: number): number {
}
public getConnectorMaximumAvailablePower (connectorId: number): number {
- let connectorAmperageLimitation
Power
Limit: number | undefined
+ let connectorAmperageLimitationLimit: number | undefined
const amperageLimitation = this.getAmperageLimitation()
if (
amperageLimitation != null &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
amperageLimitation < this.stationInfo!.maximumAmperage!
) {
const amperageLimitation = this.getAmperageLimitation()
if (
amperageLimitation != null &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
amperageLimitation < this.stationInfo!.maximumAmperage!
) {
- connectorAmperageLimitation
Power
Limit =
+ connectorAmperageLimitationLimit =
(this.stationInfo?.currentOutType === CurrentType.AC
? ACElectricUtils.powerTotal(
this.getNumberOfPhases(),
(this.stationInfo?.currentOutType === CurrentType.AC
? ACElectricUtils.powerTotal(
this.getNumberOfPhases(),
@@
-408,17
+415,25
@@
export class ChargingStation extends EventEmitter {
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const connectorMaximumPower = this.stationInfo!.maximumPower! / this.powerDivider!
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const connectorMaximumPower = this.stationInfo!.maximumPower! / this.powerDivider!
- const connectorChargingProfilesPowerLimit =
- getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId)
+ const chargingStationChargingProfilesLimit =
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ getChargingStationChargingProfilesLimit(this)! / this.powerDivider!
+ const connectorChargingProfilesLimit = getConnectorChargingProfilesLimit(this, connectorId)
return min(
return min(
- isNaN(connectorMaximumPower) ?
Infinity
: connectorMaximumPower,
+ isNaN(connectorMaximumPower) ?
Number.POSITIVE_INFINITY
: connectorMaximumPower,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- isNaN(connectorAmperageLimitation
Power
Limit!)
- ?
Infinity
+ isNaN(connectorAmperageLimitationLimit!)
+ ?
Number.POSITIVE_INFINITY
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- connectorAmperageLimitationPowerLimit!,
+ connectorAmperageLimitationLimit!,
+ isNaN(chargingStationChargingProfilesLimit)
+ ? Number.POSITIVE_INFINITY
+ : chargingStationChargingProfilesLimit,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- isNaN(connectorChargingProfilesPowerLimit!) ? Infinity : connectorChargingProfilesPowerLimit!
+ isNaN(connectorChargingProfilesLimit!)
+ ? Number.POSITIVE_INFINITY
+ : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ connectorChargingProfilesLimit!
)
}
)
}
@@
-549,7
+564,8
@@
export class ChargingStation extends EventEmitter {
}
public startHeartbeat (): void {
}
public startHeartbeat (): void {
- if (this.getHeartbeatInterval() > 0 && this.heartbeatSetInterval == null) {
+ const heartbeatInterval = this.getHeartbeatInterval()
+ if (heartbeatInterval > 0 && this.heartbeatSetInterval == null) {
this.heartbeatSetInterval = setInterval(() => {
this.ocppRequestService
.requestHandler<HeartbeatRequest, HeartbeatResponse>(this, RequestCommand.HEARTBEAT)
this.heartbeatSetInterval = setInterval(() => {
this.ocppRequestService
.requestHandler<HeartbeatRequest, HeartbeatResponse>(this, RequestCommand.HEARTBEAT)
@@
-559,21
+575,21
@@
export class ChargingStation extends EventEmitter {
error
)
})
error
)
})
- },
this.getHeartbeatInterval()
)
+ },
heartbeatInterval
)
logger.info(
`${this.logPrefix()} Heartbeat started every ${formatDurationMilliSeconds(
logger.info(
`${this.logPrefix()} Heartbeat started every ${formatDurationMilliSeconds(
- this.getHeartbeatInterval()
+ heartbeatInterval
)}`
)
} else if (this.heartbeatSetInterval != null) {
logger.info(
`${this.logPrefix()} Heartbeat already started every ${formatDurationMilliSeconds(
)}`
)
} else if (this.heartbeatSetInterval != null) {
logger.info(
`${this.logPrefix()} Heartbeat already started every ${formatDurationMilliSeconds(
- this.getHeartbeatInterval()
+ heartbeatInterval
)}`
)
} else {
logger.error(
)}`
)
} else {
logger.error(
- `${this.logPrefix()} Heartbeat interval set to ${
this.getHeartbeatInterval()
}, not starting the heartbeat`
+ `${this.logPrefix()} Heartbeat interval set to ${
heartbeatInterval
}, not starting the heartbeat`
)
}
}
)
}
}
@@
-661,6
+677,11
@@
export class ChargingStation extends EventEmitter {
}
}
}
}
+ public restartMeterValues (connectorId: number, interval: number): void {
+ this.stopMeterValues(connectorId)
+ this.startMeterValues(connectorId, interval)
+ }
+
private add (): void {
this.emit(ChargingStationEvents.added)
}
private add (): void {
this.emit(ChargingStationEvents.added)
}
@@
-1359,7
+1380,9
@@
export class ChargingStation extends EventEmitter {
addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0')
}
if (getConfigurationKey(this, StandardParametersKey.HeartBeatInterval) == null) {
addConfigurationKey(this, StandardParametersKey.HeartbeatInterval, '0')
}
if (getConfigurationKey(this, StandardParametersKey.HeartBeatInterval) == null) {
- addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', { visible: false })
+ addConfigurationKey(this, StandardParametersKey.HeartBeatInterval, '0', {
+ visible: false
+ })
}
if (
this.stationInfo?.supervisionUrlOcppConfiguration === true &&
}
if (
this.stationInfo?.supervisionUrlOcppConfiguration === true &&
@@
-1377,7
+1400,9
@@
export class ChargingStation extends EventEmitter {
isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) &&
getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey) != null
) {
isNotEmptyString(this.stationInfo.supervisionUrlOcppKey) &&
getConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey) != null
) {
- deleteConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey, { save: false })
+ deleteConfigurationKey(this, this.stationInfo.supervisionUrlOcppKey, {
+ save: false
+ })
}
if (
isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
}
if (
isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
@@
-1459,7
+1484,10
@@
export class ChargingStation extends EventEmitter {
private initializeConnectorsOrEvsesFromFile (configuration: ChargingStationConfiguration): void {
if (configuration.connectorsStatus != null && configuration.evsesStatus == null) {
for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) {
private initializeConnectorsOrEvsesFromFile (configuration: ChargingStationConfiguration): void {
if (configuration.connectorsStatus != null && configuration.evsesStatus == null) {
for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) {
- this.connectors.set(connectorId, clone<ConnectorStatus>(connectorStatus))
+ this.connectors.set(
+ connectorId,
+ prepareConnectorStatus(clone<ConnectorStatus>(connectorStatus))
+ )
}
} else if (configuration.evsesStatus != null && configuration.connectorsStatus == null) {
for (const [evseId, evseStatusConfiguration] of configuration.evsesStatus.entries()) {
}
} else if (configuration.evsesStatus != null && configuration.connectorsStatus == null) {
for (const [evseId, evseStatusConfiguration] of configuration.evsesStatus.entries()) {
@@
-1471,7
+1499,7
@@
export class ChargingStation extends EventEmitter {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
evseStatusConfiguration.connectorsStatus!.map((connectorStatus, connectorId) => [
connectorId,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
evseStatusConfiguration.connectorsStatus!.map((connectorStatus, connectorId) => [
connectorId,
- connectorStatus
+ prepareConnectorStatus(connectorStatus)
])
)
})
])
)
})
@@
-1736,7
+1764,9
@@
export class ChargingStation extends EventEmitter {
...(this.connectors.size > 0 && {
connectorsStatus: configurationData.connectorsStatus
}),
...(this.connectors.size > 0 && {
connectorsStatus: configurationData.connectorsStatus
}),
- ...(this.evses.size > 0 && { evsesStatus: configurationData.evsesStatus })
+ ...(this.evses.size > 0 && {
+ evsesStatus: configurationData.evsesStatus
+ })
} satisfies ChargingStationConfiguration)
)
.digest('hex')
} satisfies ChargingStationConfiguration)
)
.digest('hex')
@@
-1811,27
+1841,27
@@
export class ChargingStation extends EventEmitter {
private async onOpen (): Promise<void> {
if (this.isWebSocketConnectionOpened()) {
private async onOpen (): Promise<void> {
if (this.isWebSocketConnectionOpened()) {
+ this.emit(ChargingStationEvents.connected)
this.emit(ChargingStationEvents.updated)
logger.info(
this.emit(ChargingStationEvents.updated)
logger.info(
- `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.href} succeeded`
+ `${this.logPrefix()} Connection to OCPP server through ${
+ this.wsConnectionUrl.href
+ } succeeded`
)
let registrationRetryCount = 0
if (!this.isRegistered()) {
// Send BootNotification
do {
)
let registrationRetryCount = 0
if (!this.isRegistered()) {
// Send BootNotification
do {
-
this.bootNotificationResponse =
await this.ocppRequestService.requestHandler<
+ await this.ocppRequestService.requestHandler<
BootNotificationRequest,
BootNotificationResponse
>(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, {
skipBufferingOnError: true
})
BootNotificationRequest,
BootNotificationResponse
>(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, {
skipBufferingOnError: true
})
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
- if (this.bootNotificationResponse?.currentTime != null) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- this.bootNotificationResponse.currentTime = convertToDate(
- this.bootNotificationResponse.currentTime
- )!
- }
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.bootNotificationResponse!.currentTime = convertToDate(
+ this.bootNotificationResponse?.currentTime
+ )!
if (!this.isRegistered()) {
this.stationInfo?.registrationMaxRetries !== -1 && ++registrationRetryCount
await sleep(
if (!this.isRegistered()) {
this.stationInfo?.registrationMaxRetries !== -1 && ++registrationRetryCount
await sleep(
@@
-1848,22
+1878,13
@@
export class ChargingStation extends EventEmitter {
this.stationInfo?.registrationMaxRetries === -1)
)
}
this.stationInfo?.registrationMaxRetries === -1)
)
}
- if (this.isRegistered()) {
- this.emit(ChargingStationEvents.registered)
- if (this.inAcceptedState()) {
- this.emit(ChargingStationEvents.accepted)
- }
- } else {
- if (this.inRejectedState()) {
- this.emit(ChargingStationEvents.rejected)
- }
+ if (!this.isRegistered()) {
logger.error(
`${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${
this.stationInfo?.registrationMaxRetries
})`
)
}
logger.error(
`${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${
this.stationInfo?.registrationMaxRetries
})`
)
}
- this.wsConnectionRetryCount = 0
this.emit(ChargingStationEvents.updated)
} else {
logger.warn(
this.emit(ChargingStationEvents.updated)
} else {
logger.warn(
@@
-1915,7
+1936,7
@@
export class ChargingStation extends EventEmitter {
}
throw new OCPPError(
ErrorType.PROTOCOL_ERROR,
}
throw new OCPPError(
ErrorType.PROTOCOL_ERROR,
- `Cached request for message id
${messageId}
${getMessageTypeString(
+ `Cached request for message id
'${messageId}'
${getMessageTypeString(
messageType
)} is not an array`,
undefined,
messageType
)} is not an array`,
undefined,
@@
-1925,6
+1946,14
@@
export class ChargingStation extends EventEmitter {
private async handleIncomingMessage (request: IncomingRequest): Promise<void> {
const [messageType, messageId, commandName, commandPayload] = request
private async handleIncomingMessage (request: IncomingRequest): Promise<void> {
const [messageType, messageId, commandName, commandPayload] = request
+ if (this.requests.has(messageId)) {
+ throw new OCPPError(
+ ErrorType.SECURITY_ERROR,
+ `Received message with duplicate message id '${messageId}'`,
+ commandName,
+ commandPayload
+ )
+ }
if (this.stationInfo?.enableStatistics === true) {
this.performanceStatistics?.addRequestStatistic(commandName, messageType)
}
if (this.stationInfo?.enableStatistics === true) {
this.performanceStatistics?.addRequestStatistic(commandName, messageType)
}
@@
-1949,7
+1978,7
@@
export class ChargingStation extends EventEmitter {
// Error
throw new OCPPError(
ErrorType.INTERNAL_ERROR,
// Error
throw new OCPPError(
ErrorType.INTERNAL_ERROR,
- `Response for unknown message id
${messageId}
`,
+ `Response for unknown message id
'${messageId}'
`,
undefined,
commandPayload
)
undefined,
commandPayload
)
@@
-1974,7
+2003,7
@@
export class ChargingStation extends EventEmitter {
// Error
throw new OCPPError(
ErrorType.INTERNAL_ERROR,
// Error
throw new OCPPError(
ErrorType.INTERNAL_ERROR,
- `Error response for unknown message id
${messageId}
`,
+ `Error response for unknown message id
'${messageId}'
`,
undefined,
{ errorType, errorMessage, errorDetails }
)
undefined,
{ errorType, errorMessage, errorDetails }
)
@@
-2059,10
+2088,10
@@
export class ChargingStation extends EventEmitter {
}
if (!(error instanceof OCPPError)) {
logger.warn(
}
if (!(error instanceof OCPPError)) {
logger.warn(
- `${this.logPrefix()} Error thrown at incoming OCPP command
'
${
+ `${this.logPrefix()} Error thrown at incoming OCPP command ${
commandName ?? requestCommandName ?? Constants.UNKNOWN_OCPP_COMMAND
// eslint-disable-next-line @typescript-eslint/no-base-to-string
commandName ?? requestCommandName ?? Constants.UNKNOWN_OCPP_COMMAND
// eslint-disable-next-line @typescript-eslint/no-base-to-string
- }
'
message '${data.toString()}' handling is not an OCPPError:`,
+ } message '${data.toString()}' handling is not an OCPPError:`,
error
)
}
error
)
}
@@
-2072,7
+2101,9
@@
export class ChargingStation extends EventEmitter {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
}' message '${data.toString()}'${
this.requests.has(messageId)
// eslint-disable-next-line @typescript-eslint/no-base-to-string
}' message '${data.toString()}'${
this.requests.has(messageId)
- ? ` matching cached request '${JSON.stringify(this.getCachedRequest(messageType, messageId))}'`
+ ? ` matching cached request '${JSON.stringify(
+ this.getCachedRequest(messageType, messageId)
+ )}'`
: ''
} processing error:`,
error
: ''
} processing error:`,
error
@@
-2214,9
+2245,13
@@
export class ChargingStation extends EventEmitter {
})
}
// Start WebSocket ping
})
}
// Start WebSocket ping
- this.startWebSocketPing()
+ if (this.wsPingSetInterval == null) {
+ this.startWebSocketPing()
+ }
// Start heartbeat
// Start heartbeat
- this.startHeartbeat()
+ if (this.heartbeatSetInterval == null) {
+ this.startHeartbeat()
+ }
// Initialize connectors status
if (this.hasEvses) {
for (const [evseId, evseStatus] of this.evses) {
// Initialize connectors status
if (this.hasEvses) {
for (const [evseId, evseStatus] of this.evses) {
@@
-2306,13
+2341,14
@@
export class ChargingStation extends EventEmitter {
}
}
}
}
+ private getWebSocketPingInterval (): number {
+ return getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval) != null
+ ? convertToInt(getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value)
+ : 0
+ }
+
private startWebSocketPing (): void {
private startWebSocketPing (): void {
- const webSocketPingInterval =
- getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval) != null
- ? convertToInt(
- getConfigurationKey(this, StandardParametersKey.WebSocketPingInterval)?.value
- )
- : 0
+ const webSocketPingInterval = this.getWebSocketPingInterval()
if (webSocketPingInterval > 0 && this.wsPingSetInterval == null) {
this.wsPingSetInterval = setInterval(() => {
if (this.isWebSocketConnectionOpened()) {
if (webSocketPingInterval > 0 && this.wsPingSetInterval == null) {
this.wsPingSetInterval = setInterval(() => {
if (this.isWebSocketConnectionOpened()) {
@@
-2402,7
+2438,6
@@
export class ChargingStation extends EventEmitter {
this.wsConnectionRetryCount < this.stationInfo!.autoReconnectMaxRetries! ||
this.stationInfo?.autoReconnectMaxRetries === -1
) {
this.wsConnectionRetryCount < this.stationInfo!.autoReconnectMaxRetries! ||
this.stationInfo?.autoReconnectMaxRetries === -1
) {
- this.wsConnectionRetried = true
++this.wsConnectionRetryCount
const reconnectDelay =
this.stationInfo?.reconnectExponentialDelay === true
++this.wsConnectionRetryCount
const reconnectDelay =
this.stationInfo?.reconnectExponentialDelay === true
@@
-2429,9
+2464,7
@@
export class ChargingStation extends EventEmitter {
)
} else if (this.stationInfo?.autoReconnectMaxRetries !== -1) {
logger.error(
)
} else if (this.stationInfo?.autoReconnectMaxRetries !== -1) {
logger.error(
- `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${
- this.wsConnectionRetryCount
- }) or retries disabled (${this.stationInfo?.autoReconnectMaxRetries})`
+ `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${this.wsConnectionRetryCount.toString()}) or retries disabled (${this.stationInfo?.autoReconnectMaxRetries?.toString()})`
)
}
}
)
}
}