hasFeatureProfile,
hasReservationExpired,
initializeConnectorsMapStatus,
+ prepareConnectorStatus,
propagateSerialNumber,
setChargingStationOptions,
stationTemplateToStationInfo,
private ocppIncomingRequestService!: OCPPIncomingRequestService
private readonly messageBuffer: Set<string>
private configuredSupervisionUrl!: URL
- private wsConnectionRetried: boolean
private wsConnectionRetryCount: number
private templateFileWatcher?: FSWatcher
private templateFileHash!: string
this.starting = false
this.stopping = false
this.wsConnection = null
- this.wsConnectionRetried = false
this.wsConnectionRetryCount = 0
this.index = index
this.templateFile = templateFile
})
this.on(ChargingStationEvents.accepted, () => {
this.startMessageSequence(
- this.wsConnectionRetried
+ this.wsConnectionRetryCount > 0
? true
: this.getAutomaticTransactionGeneratorConfiguration()?.stopAbsoluteDuration
).catch((error: unknown) => {
logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error)
})
- this.wsConnectionRetried = false
+ this.wsConnectionRetryCount = 0
})
this.on(ChargingStationEvents.rejected, () => {
- this.wsConnectionRetried = false
+ this.wsConnectionRetryCount = 0
})
this.on(ChargingStationEvents.connected, () => {
if (this.wsPingSetInterval == null) {
}
}
+ public restartMeterValues (connectorId: number, interval: number): void {
+ this.stopMeterValues(connectorId)
+ this.startMeterValues(connectorId, interval)
+ }
+
private add (): void {
this.emit(ChargingStationEvents.added)
}
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()) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
evseStatusConfiguration.connectorsStatus!.map((connectorStatus, connectorId) => [
connectorId,
- connectorStatus
+ prepareConnectorStatus(connectorStatus)
])
)
})
if (!this.isRegistered()) {
// Send BootNotification
do {
- // FIXME: duplicated assignment with the boot notification response handler
- this.bootNotificationResponse = await this.ocppRequestService.requestHandler<
+ await this.ocppRequestService.requestHandler<
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(
})`
)
}
- this.wsConnectionRetryCount = 0
this.emit(ChargingStationEvents.updated)
} else {
logger.warn(
}
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,
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)
}
// Error
throw new OCPPError(
ErrorType.INTERNAL_ERROR,
- `Response for unknown message id ${messageId}`,
+ `Response for unknown message id '${messageId}'`,
undefined,
commandPayload
)
// 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 }
)
}
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
- }' message '${data.toString()}' handling is not an OCPPError:`,
+ } message '${data.toString()}' handling is not an OCPPError:`,
error
)
}
this.wsConnectionRetryCount < this.stationInfo!.autoReconnectMaxRetries! ||
this.stationInfo?.autoReconnectMaxRetries === -1
) {
- this.wsConnectionRetried = true
++this.wsConnectionRetryCount
const reconnectDelay =
this.stationInfo?.reconnectExponentialDelay === true
)
} else if (this.stationInfo?.autoReconnectMaxRetries !== -1) {
logger.error(
- `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${this.wsConnectionRetryCount.toString()}) 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()})`
)
}
}