import { PerformanceStatistics } from '../performance';
import {
AuthorizationStatus,
- ConnectorStatusEnum,
RequestCommand,
type StartTransactionRequest,
type StartTransactionResponse,
)}`,
);
while (this.connectorsStatus.get(connectorId)?.start === true) {
+ await this.waitChargingStationServiceInitialization(connectorId);
+ await this.waitChargingStationAvailable(connectorId);
+ await this.waitConnectorAvailable(connectorId);
if (!this.canStartConnector(connectorId)) {
this.stopConnector(connectorId);
break;
}
- if (!this.chargingStation?.ocppRequestService) {
- logger.info(
- `${this.logPrefix(
- connectorId,
- )} transaction loop waiting for charging station service to be initialized`,
- );
- do {
- await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
- } while (!this.chargingStation?.ocppRequestService);
- }
const wait = secondsToMilliseconds(
getRandomInteger(
this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
);
return false;
}
- if (
- this.chargingStation.getConnectorStatus(connectorId)?.status ===
- ConnectorStatusEnum.Unavailable
- ) {
- logger.info(
- `${this.logPrefix(
- connectorId,
- )} entered in transaction loop while the connector ${connectorId} status is unavailable`,
- );
- return false;
- }
return true;
}
+ private async waitChargingStationServiceInitialization(connectorId: number): Promise<void> {
+ let logged = false;
+ while (!this.chargingStation?.ocppRequestService) {
+ if (!logged) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} transaction loop waiting for charging station service to be initialized`,
+ );
+ logged = true;
+ }
+ await sleep(Constants.CHARGING_STATION_ATG_INITIALIZATION_TIME);
+ }
+ }
+
+ private async waitChargingStationAvailable(connectorId: number): Promise<void> {
+ let logged = false;
+ while (!this.chargingStation.isChargingStationAvailable()) {
+ if (!logged) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} transaction loop waiting for charging station to be available`,
+ );
+ logged = true;
+ }
+ await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
+ }
+ }
+
+ private async waitConnectorAvailable(connectorId: number): Promise<void> {
+ let logged = false;
+ while (!this.chargingStation.isConnectorAvailable(connectorId)) {
+ if (!logged) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} transaction loop waiting for connector ${connectorId} to be available`,
+ );
+ logged = true;
+ }
+ await sleep(Constants.CHARGING_STATION_ATG_AVAILABILITY_TIME);
+ }
+ }
+
private initializeConnectorsStatus(): void {
if (this.chargingStation.hasEvses) {
for (const [evseId, evseStatus] of this.chargingStation.evses) {
this.chargingStation.getAutomaticTransactionGeneratorStatuses()![connectorId],
)
: undefined;
- delete connectorStatus?.startDate;
- delete connectorStatus?.lastRunDate;
- delete connectorStatus?.stopDate;
- delete connectorStatus?.stoppedDate;
- if (!this.started && connectorStatus?.start === true) {
- connectorStatus.start = false;
- }
+ this.resetConnectorStatus(connectorStatus);
return (
connectorStatus ?? {
start: false,
);
}
+ private resetConnectorStatus(connectorStatus: Status | undefined): void {
+ delete connectorStatus?.startDate;
+ delete connectorStatus?.lastRunDate;
+ delete connectorStatus?.stopDate;
+ delete connectorStatus?.stoppedDate;
+ if (
+ !this.started &&
+ (connectorStatus?.start === true ||
+ this.chargingStation.getAutomaticTransactionGeneratorConfiguration().enable === false)
+ ) {
+ connectorStatus!.start = false;
+ }
+ }
+
private async startTransaction(
connectorId: number,
): Promise<StartTransactionResponse | undefined> {