+ this.connectorsStatus.get(connectorId)!.lastRunDate = new Date();
+ }
+ this.connectorsStatus.get(connectorId)!.stoppedDate = new Date();
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} stopped on connector and lasted for ${formatDurationMilliSeconds(
+ this.connectorsStatus.get(connectorId)!.stoppedDate!.getTime() -
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime(),
+ )}`,
+ );
+ logger.debug(
+ `${this.logPrefix(connectorId)} connector status: %j`,
+ this.connectorsStatus.get(connectorId),
+ );
+ }
+
+ private setStartConnectorStatus(connectorId: number): void {
+ this.connectorsStatus.get(connectorId)!.skippedConsecutiveTransactions = 0;
+ const previousRunDuration =
+ this.connectorsStatus.get(connectorId)?.startDate &&
+ this.connectorsStatus.get(connectorId)?.lastRunDate
+ ? this.connectorsStatus.get(connectorId)!.lastRunDate!.getTime() -
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime()
+ : 0;
+ this.connectorsStatus.get(connectorId)!.startDate = new Date();
+ this.connectorsStatus.get(connectorId)!.stopDate = new Date(
+ this.connectorsStatus.get(connectorId)!.startDate!.getTime() +
+ hoursToMilliseconds(
+ this.chargingStation.getAutomaticTransactionGeneratorConfiguration().stopAfterHours,
+ ) -
+ previousRunDuration,
+ );
+ this.connectorsStatus.get(connectorId)!.start = true;
+ }
+
+ private canStartConnector(connectorId: number): boolean {
+ if (new Date() > this.connectorsStatus.get(connectorId)!.stopDate!) {
+ return false;
+ }
+ if (this.chargingStation.inAcceptedState() === false) {
+ logger.error(
+ `${this.logPrefix(
+ connectorId,
+ )} entered in transaction loop while the charging station is not in accepted state`,
+ );
+ return false;
+ }
+ if (this.chargingStation.isChargingStationAvailable() === false) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} entered in transaction loop while the charging station is unavailable`,
+ );
+ return false;
+ }
+ if (this.chargingStation.isConnectorAvailable(connectorId) === false) {
+ logger.info(
+ `${this.logPrefix(
+ connectorId,
+ )} entered in transaction loop while the connector ${connectorId} is unavailable`,
+ );
+ 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 initializeConnectorsStatus(): void {
+ if (this.chargingStation.hasEvses) {
+ for (const [evseId, evseStatus] of this.chargingStation.evses) {
+ if (evseId > 0) {
+ for (const connectorId of evseStatus.connectors.keys()) {
+ this.connectorsStatus.set(connectorId, this.getConnectorStatus(connectorId));
+ }
+ }
+ }
+ } else {
+ for (const connectorId of this.chargingStation.connectors.keys()) {
+ if (connectorId > 0) {
+ this.connectorsStatus.set(connectorId, this.getConnectorStatus(connectorId));
+ }
+ }
+ }
+ }
+
+ private getConnectorStatus(connectorId: number): Status {
+ const connectorStatus = this.chargingStation.getAutomaticTransactionGeneratorStatuses()?.[
+ connectorId
+ ]
+ ? cloneObject<Status>(
+ this.chargingStation.getAutomaticTransactionGeneratorStatuses()![connectorId],
+ )
+ : undefined;
+ delete connectorStatus?.startDate;
+ delete connectorStatus?.lastRunDate;
+ delete connectorStatus?.stopDate;
+ delete connectorStatus?.stoppedDate;
+ return (
+ connectorStatus ?? {
+ start: false,
+ authorizeRequests: 0,
+ acceptedAuthorizeRequests: 0,
+ rejectedAuthorizeRequests: 0,
+ startTransactionRequests: 0,
+ acceptedStartTransactionRequests: 0,
+ rejectedStartTransactionRequests: 0,
+ stopTransactionRequests: 0,
+ acceptedStopTransactionRequests: 0,
+ rejectedStopTransactionRequests: 0,
+ skippedConsecutiveTransactions: 0,
+ skippedTransactions: 0,
+ }
+ );
+ }
+
+ private async startTransaction(
+ connectorId: number,
+ ): Promise<StartTransactionResponse | undefined> {
+ const measureId = 'StartTransaction with ATG';
+ const beginId = PerformanceStatistics.beginMeasure(measureId);
+ let startResponse: StartTransactionResponse | undefined;
+ if (this.chargingStation.hasIdTags()) {
+ const idTag = IdTagsCache.getInstance().getIdTag(
+ this.chargingStation.getAutomaticTransactionGeneratorConfiguration().idTagDistribution!,
+ this.chargingStation,
+ connectorId,
+ );
+ const startTransactionLogMsg = `${this.logPrefix(
+ connectorId,
+ )} start transaction with an idTag '${idTag}'`;
+ if (this.getRequireAuthorize()) {
+ ++this.connectorsStatus.get(connectorId)!.authorizeRequests!;
+ if (await OCPPServiceUtils.isIdTagAuthorized(this.chargingStation, connectorId, idTag)) {
+ ++this.connectorsStatus.get(connectorId)!.acceptedAuthorizeRequests!;
+ logger.info(startTransactionLogMsg);