}
}
+ public getNumberOfRunningTransactions(): number {
+ let trxCount = 0;
+ if (this.hasEvses) {
+ for (const evseStatus of this.evses.values()) {
+ for (const connectorStatus of evseStatus.connectors.values()) {
+ if (connectorStatus.transactionStarted === true) {
+ ++trxCount;
+ }
+ }
+ }
+ } else {
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) {
+ ++trxCount;
+ }
+ }
+ }
+ return trxCount;
+ }
+
public getOutOfOrderEndMeterValues(): boolean {
return this.stationInfo?.outOfOrderEndMeterValues ?? false;
}
}
private handleUnsupportedVersion(version: OCPPVersion) {
- const errMsg = `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
- logger.error(`${this.logPrefix()} ${errMsg}`);
- throw new BaseError(errMsg);
+ const errorMsg = `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
+ logger.error(`${this.logPrefix()} ${errorMsg}`);
+ throw new BaseError(errorMsg);
}
private initialize(): void {
private initializeConnectors(stationInfo: ChargingStationInfo): void {
if (!stationInfo?.Connectors && this.connectors.size === 0) {
- const logMsg = `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`;
- logger.error(`${this.logPrefix()} ${logMsg}`);
- throw new BaseError(logMsg);
+ const errorMsg = `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`;
+ logger.error(`${this.logPrefix()} ${errorMsg}`);
+ throw new BaseError(errorMsg);
}
if (!stationInfo?.Connectors[0]) {
logger.warn(
private initializeEvses(stationInfo: ChargingStationInfo): void {
if (!stationInfo?.Evses && this.evses.size === 0) {
- const logMsg = `No already defined evses and charging station information from template ${this.templateFile} with no evses configuration defined`;
- logger.error(`${this.logPrefix()} ${logMsg}`);
- throw new BaseError(logMsg);
+ const errorMsg = `No already defined evses and charging station information from template ${this.templateFile} with no evses configuration defined`;
+ logger.error(`${this.logPrefix()} ${errorMsg}`);
+ throw new BaseError(errorMsg);
}
if (!stationInfo?.Evses[0]) {
logger.warn(
private async onMessage(data: RawData): Promise<void> {
let request: IncomingRequest | Response | ErrorResponse;
let messageType: number;
- let errMsg: string;
+ let errorMsg: string;
try {
request = JSON.parse(data.toString()) as IncomingRequest | Response | ErrorResponse;
if (Array.isArray(request) === true) {
// Unknown Message
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- errMsg = `Wrong message type ${messageType}`;
- logger.error(`${this.logPrefix()} ${errMsg}`);
- throw new OCPPError(ErrorType.PROTOCOL_ERROR, errMsg);
+ errorMsg = `Wrong message type ${messageType}`;
+ logger.error(`${this.logPrefix()} ${errorMsg}`);
+ throw new OCPPError(ErrorType.PROTOCOL_ERROR, errorMsg);
}
parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
} else {
return localStationInfo?.useConnectorId0 ?? true;
}
- private getNumberOfRunningTransactions(): number {
- let trxCount = 0;
- if (this.hasEvses) {
- for (const evseStatus of this.evses.values()) {
- for (const connectorStatus of evseStatus.connectors.values()) {
- if (connectorStatus.transactionStarted === true) {
- trxCount++;
- }
- }
- }
- } else {
- for (const connectorId of this.connectors.keys()) {
- if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) {
- trxCount++;
- }
- }
- }
- return trxCount;
- }
-
private async stopRunningTransactions(reason = StopTransactionReason.NONE): Promise<void> {
if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
if (connectorId === 0) {
let response: ChangeAvailabilityResponse =
OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
- for (const id of chargingStation.connectors.keys()) {
- if (chargingStation.getConnectorStatus(id)?.transactionStarted === true) {
+ const changeAvailability = async (id: number, connectorStatus: ConnectorStatus) => {
+ if (connectorStatus?.transactionStarted === true) {
response = OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
- chargingStation.getConnectorStatus(id).availability = commandPayload.type;
+ connectorStatus.availability = commandPayload.type;
if (response === OCPP16Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
await OCPP16ServiceUtils.sendAndSetConnectorStatus(
chargingStation,
chargePointStatus
);
}
+ };
+ if (chargingStation.hasEvses) {
+ for (const evseStatus of chargingStation.evses.values()) {
+ for (const [id, connectorStatus] of evseStatus.connectors) {
+ await changeAvailability(id, connectorStatus);
+ }
+ }
+ } else {
+ for (const id of chargingStation.connectors.keys()) {
+ await changeAvailability(id, chargingStation.getConnectorStatus(id));
+ }
}
return response;
} else if (
commandPayload: RemoteStopTransactionRequest
): Promise<GenericResponse> {
const transactionId = commandPayload.transactionId;
- for (const connectorId of chargingStation.connectors.keys()) {
- if (
- connectorId > 0 &&
- chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId
- ) {
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Finishing
- );
- const stopResponse = await chargingStation.stopTransactionOnConnector(
- connectorId,
- OCPP16StopTransactionReason.REMOTE
- );
- if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
- return OCPP16Constants.OCPP_RESPONSE_ACCEPTED;
+ const remoteStopTransaction = async (connectorId: number): Promise<GenericResponse> => {
+ await OCPP16ServiceUtils.sendAndSetConnectorStatus(
+ chargingStation,
+ connectorId,
+ OCPP16ChargePointStatus.Finishing
+ );
+ const stopResponse = await chargingStation.stopTransactionOnConnector(
+ connectorId,
+ OCPP16StopTransactionReason.REMOTE
+ );
+ if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
+ return OCPP16Constants.OCPP_RESPONSE_ACCEPTED;
+ }
+ return OCPP16Constants.OCPP_RESPONSE_REJECTED;
+ };
+ if (chargingStation.hasEvses) {
+ for (const [evseId, evseStatus] of chargingStation.evses) {
+ if (evseId > 0) {
+ for (const [connectorId, connectorStatus] of evseStatus.connectors) {
+ if (connectorStatus.transactionId === transactionId) {
+ return remoteStopTransaction(connectorId);
+ }
+ }
+ }
+ }
+ } else {
+ for (const connectorId of chargingStation.connectors.keys()) {
+ if (
+ connectorId > 0 &&
+ chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId
+ ) {
+ return remoteStopTransaction(connectorId);
}
- return OCPP16Constants.OCPP_RESPONSE_REJECTED;
}
}
logger.warn(
) {
return;
}
- for (const connectorId of chargingStation.connectors.keys()) {
- if (
- connectorId > 0 &&
- chargingStation.getConnectorStatus(connectorId)?.transactionStarted === false
- ) {
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Unavailable
- );
+ if (chargingStation.hasEvses) {
+ for (const [evseId, evseStatus] of chargingStation.evses) {
+ if (evseId > 0) {
+ for (const [connectorId, connectorStatus] of evseStatus.connectors) {
+ if (connectorStatus?.transactionStarted === false) {
+ await OCPP16ServiceUtils.sendAndSetConnectorStatus(
+ chargingStation,
+ connectorId,
+ OCPP16ChargePointStatus.Unavailable
+ );
+ }
+ }
+ }
+ }
+ } else {
+ for (const connectorId of chargingStation.connectors.keys()) {
+ if (
+ connectorId > 0 &&
+ chargingStation.getConnectorStatus(connectorId)?.transactionStarted === false
+ ) {
+ await OCPP16ServiceUtils.sendAndSetConnectorStatus(
+ chargingStation,
+ connectorId,
+ OCPP16ChargePointStatus.Unavailable
+ );
+ }
}
}
await chargingStation.ocppRequestService.requestHandler<
let wasTransactionsStarted = false;
let transactionsStarted: boolean;
do {
- let trxCount = 0;
- for (const connectorId of chargingStation.connectors.keys()) {
- if (
- connectorId > 0 &&
- chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true
- ) {
- trxCount++;
- }
- }
- if (trxCount > 0) {
+ const runningTransactions = chargingStation.getNumberOfRunningTransactions();
+ if (runningTransactions > 0) {
const waitTime = 15 * 1000;
logger.debug(
- `${chargingStation.logPrefix()} ${moduleName}.updateFirmwareSimulation: ${trxCount} transaction(s) in progress, waiting ${
+ `${chargingStation.logPrefix()} ${moduleName}.updateFirmwareSimulation: ${runningTransactions} transaction(s) in progress, waiting ${
waitTime / 1000
} seconds before continuing firmware update simulation`
);
transactionsStarted = true;
wasTransactionsStarted = true;
} else {
- for (const connectorId of chargingStation.connectors.keys()) {
- if (
- connectorId > 0 &&
- chargingStation.getConnectorStatus(connectorId)?.status !==
- OCPP16ChargePointStatus.Unavailable
- ) {
- await OCPP16ServiceUtils.sendAndSetConnectorStatus(
- chargingStation,
- connectorId,
- OCPP16ChargePointStatus.Unavailable
- );
+ if (chargingStation.hasEvses) {
+ for (const [evseId, evseStatus] of chargingStation.evses) {
+ if (evseId > 0) {
+ for (const [connectorId, connectorStatus] of evseStatus.connectors) {
+ if (connectorStatus?.status !== OCPP16ChargePointStatus.Unavailable) {
+ await OCPP16ServiceUtils.sendAndSetConnectorStatus(
+ chargingStation,
+ connectorId,
+ OCPP16ChargePointStatus.Unavailable
+ );
+ }
+ }
+ }
+ }
+ } else {
+ for (const connectorId of chargingStation.connectors.keys()) {
+ if (
+ connectorId > 0 &&
+ chargingStation.getConnectorStatus(connectorId)?.status !==
+ OCPP16ChargePointStatus.Unavailable
+ ) {
+ await OCPP16ServiceUtils.sendAndSetConnectorStatus(
+ chargingStation,
+ connectorId,
+ OCPP16ChargePointStatus.Unavailable
+ );
+ }
}
}
transactionsStarted = false;
)
.catch(Constants.EMPTY_FUNCTION);
} else {
- for (const connectorId of chargingStation.connectors.keys()) {
- chargingStation.ocppRequestService
- .requestHandler<
- OCPP16StatusNotificationRequest,
- OCPP16StatusNotificationResponse
- >(
- chargingStation,
- OCPP16RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
- status: chargingStation.getConnectorStatus(connectorId)?.status,
- },
- {
- triggerMessage: true,
- }
- )
- .catch(Constants.EMPTY_FUNCTION);
+ // eslint-disable-next-line no-lonely-if
+ if (chargingStation.hasEvses) {
+ for (const evseStatus of chargingStation.evses.values()) {
+ for (const [connectorId, connectorStatus] of evseStatus.connectors) {
+ chargingStation.ocppRequestService
+ .requestHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: connectorStatus.status,
+ },
+ {
+ triggerMessage: true,
+ }
+ )
+ .catch(Constants.EMPTY_FUNCTION);
+ }
+ }
+ } else {
+ for (const connectorId of chargingStation.connectors.keys()) {
+ chargingStation.ocppRequestService
+ .requestHandler<
+ OCPP16StatusNotificationRequest,
+ OCPP16StatusNotificationResponse
+ >(
+ chargingStation,
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ status: chargingStation.getConnectorStatus(connectorId)?.status,
+ },
+ {
+ triggerMessage: true,
+ }
+ )
+ .catch(Constants.EMPTY_FUNCTION);
+ }
}
}
}, OCPP16Constants.OCPP_TRIGGER_MESSAGE_DELAY);