return AutomaticTransactionGenerator.instances.get(chargingStation.stationInfo!.hashId)
}
- public start (): void {
+ public start (stopAbsoluteDuration?: boolean): void {
if (!checkChargingStation(this.chargingStation, this.logPrefix())) {
return
}
return
}
this.starting = true
- this.startConnectors()
+ this.startConnectors(stopAbsoluteDuration)
this.started = true
this.starting = false
}
this.stopping = false
}
- public startConnector (connectorId: number): void {
+ public startConnector (connectorId: number, stopAbsoluteDuration?: boolean): void {
if (!checkChargingStation(this.chargingStation, this.logPrefix(connectorId))) {
return
}
throw new BaseError(`Connector ${connectorId} does not exist`)
}
if (this.connectorsStatus.get(connectorId)?.start === false) {
- this.internalStartConnector(connectorId).catch(Constants.EMPTY_FUNCTION)
+ this.internalStartConnector(connectorId, stopAbsoluteDuration).catch(Constants.EMPTY_FUNCTION)
} else if (this.connectorsStatus.get(connectorId)?.start === true) {
logger.warn(`${this.logPrefix(connectorId)} is already started on connector`)
}
}
}
- private startConnectors (): void {
+ private startConnectors (stopAbsoluteDuration?: boolean): void {
if (
this.connectorsStatus.size > 0 &&
this.connectorsStatus.size !== this.chargingStation.getNumberOfConnectors()
for (const [evseId, evseStatus] of this.chargingStation.evses) {
if (evseId > 0) {
for (const connectorId of evseStatus.connectors.keys()) {
- this.startConnector(connectorId)
+ this.startConnector(connectorId, stopAbsoluteDuration)
}
}
}
} else {
for (const connectorId of this.chargingStation.connectors.keys()) {
if (connectorId > 0) {
- this.startConnector(connectorId)
+ this.startConnector(connectorId, stopAbsoluteDuration)
}
}
}
}
}
- private async internalStartConnector (connectorId: number): Promise<void> {
- this.setStartConnectorStatus(connectorId)
+ private async internalStartConnector (
+ connectorId: number,
+ stopAbsoluteDuration?: boolean
+ ): Promise<void> {
+ this.setStartConnectorStatus(connectorId, stopAbsoluteDuration)
logger.info(
`${this.logPrefix(
connectorId
)
}
- private setStartConnectorStatus (connectorId: number): void {
+ private setStartConnectorStatus (
+ connectorId: number,
+ stopAbsoluteDuration = this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
+ ?.stopAbsoluteDuration
+ ): void {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.connectorsStatus.get(connectorId)!.startDate = new Date()
if (
- this.chargingStation.getAutomaticTransactionGeneratorConfiguration()?.stopAbsoluteDuration ===
- false ||
+ stopAbsoluteDuration === false ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
!isValidDate(this.connectorsStatus.get(connectorId)!.stopDate)
) {
type OCPPIncomingRequestService,
type OCPPRequestService,
buildMeterValue,
- buildStatusNotificationRequest,
buildTransactionEndMeterValue,
getMessageTypeString,
sendAndSetConnectorStatus
type Response,
StandardParametersKey,
type Status,
- type StatusNotificationRequest,
- type StatusNotificationResponse,
type StopTransactionReason,
type StopTransactionRequest,
type StopTransactionResponse,
parentPort?.postMessage(buildUpdatedMessage(this))
})
this.on(ChargingStationEvents.accepted, () => {
- this.startMessageSequence().catch(error => {
+ this.startMessageSequence(
+ this.autoReconnectRetryCount > 0
+ ? true
+ : this.getAutomaticTransactionGeneratorConfiguration()?.stopAbsoluteDuration
+ ).catch(error => {
logger.error(`${this.logPrefix()} Error while starting the message sequence:`, error)
})
})
+ this.on(ChargingStationEvents.disconnected, () => {
+ try {
+ this.internalStopMessageSequence()
+ } catch (error) {
+ logger.error(
+ `${this.logPrefix()} Error while stopping the internal message sequence:`,
+ error
+ )
+ }
+ })
this.initialize()
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo!)!)
// Restart the ATG
- this.stopAutomaticTransactionGenerator()
+ const ATGStarted = this.automaticTransactionGenerator?.started
+ if (ATGStarted === true) {
+ this.stopAutomaticTransactionGenerator()
+ }
delete this.automaticTransactionGeneratorConfiguration
- if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) {
- this.startAutomaticTransactionGenerator()
+ if (
+ this.getAutomaticTransactionGeneratorConfiguration()?.enable === true &&
+ ATGStarted === true
+ ) {
+ this.startAutomaticTransactionGenerator(undefined, true)
}
if (this.stationInfo?.enableStatistics === true) {
this.performanceStatistics?.restart()
return this.getConfigurationFromFile()?.automaticTransactionGeneratorStatuses
}
- public startAutomaticTransactionGenerator (connectorIds?: number[]): void {
+ public startAutomaticTransactionGenerator (
+ connectorIds?: number[],
+ stopAbsoluteDuration?: boolean
+ ): void {
this.automaticTransactionGenerator = AutomaticTransactionGenerator.getInstance(this)
if (isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
- this.automaticTransactionGenerator?.startConnector(connectorId)
+ this.automaticTransactionGenerator?.startConnector(connectorId, stopAbsoluteDuration)
}
} else {
- this.automaticTransactionGenerator?.start()
+ this.automaticTransactionGenerator?.start(stopAbsoluteDuration)
}
this.saveAutomaticTransactionGeneratorConfiguration()
this.emit(ChargingStationEvents.updated)
this.emit(ChargingStationEvents.accepted)
}
} else {
+ if (this.inRejectedState()) {
+ this.emit(ChargingStationEvents.rejected)
+ }
logger.error(
`${this.logPrefix()} Registration failure: maximum retries reached (${registrationRetryCount}) or retry disabled (${
this.stationInfo?.registrationMaxRetries
}
private onClose (code: WebSocketCloseEventStatusCode, reason: Buffer): void {
+ this.emit(ChargingStationEvents.disconnected)
switch (code) {
// Normal close
case WebSocketCloseEventStatusCode.CLOSE_NORMAL:
}
}
- private async startMessageSequence (): Promise<void> {
+ private async startMessageSequence (ATGStopAbsoluteDuration?: boolean): Promise<void> {
if (this.stationInfo?.autoRegister === true) {
await this.ocppRequestService.requestHandler<
BootNotificationRequest,
// Start the ATG
if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) {
- this.startAutomaticTransactionGenerator()
+ this.startAutomaticTransactionGenerator(undefined, ATGStopAbsoluteDuration)
}
this.flushMessageBuffer()
}
- private async stopMessageSequence (
- reason?: StopTransactionReason,
- stopTransactions = this.stationInfo?.stopTransactionsOnStopped
- ): Promise<void> {
+ private internalStopMessageSequence (): void {
// Stop WebSocket ping
this.stopWebSocketPing()
// Stop heartbeat
if (this.automaticTransactionGenerator?.started === true) {
this.stopAutomaticTransactionGenerator()
}
+ }
+
+ private async stopMessageSequence (
+ reason?: StopTransactionReason,
+ stopTransactions = this.stationInfo?.stopTransactionsOnStopped
+ ): Promise<void> {
+ this.internalStopMessageSequence()
// Stop ongoing transactions
stopTransactions === true && (await this.stopRunningTransactions(reason))
if (this.hasEvses) {
for (const [evseId, evseStatus] of this.evses) {
if (evseId > 0) {
for (const [connectorId, connectorStatus] of evseStatus.connectors) {
- await this.ocppRequestService.requestHandler<
- StatusNotificationRequest,
- StatusNotificationResponse
- >(
+ await sendAndSetConnectorStatus(
this,
- RequestCommand.STATUS_NOTIFICATION,
- buildStatusNotificationRequest(
- this,
- connectorId,
- ConnectorStatusEnum.Unavailable,
- evseId
- )
+ connectorId,
+ ConnectorStatusEnum.Unavailable,
+ evseId
)
delete connectorStatus.status
}
} else {
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
- await this.ocppRequestService.requestHandler<
- StatusNotificationRequest,
- StatusNotificationResponse
- >(
- this,
- RequestCommand.STATUS_NOTIFICATION,
- buildStatusNotificationRequest(this, connectorId, ConnectorStatusEnum.Unavailable)
- )
+ await sendAndSetConnectorStatus(this, connectorId, ConnectorStatusEnum.Unavailable)
delete this.getConnectorStatus(connectorId)?.status
}
}
}
private async reconnect (): Promise<void> {
- // Stop WebSocket ping
- this.stopWebSocketPing()
- // Stop heartbeat
- this.stopHeartbeat()
- // Stop the ATG if needed
- if (this.getAutomaticTransactionGeneratorConfiguration()?.stopOnConnectionFailure === true) {
- this.stopAutomaticTransactionGenerator()
- }
if (
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.autoReconnectRetryCount < this.stationInfo!.autoReconnectMaxRetries! ||