this.starting = false;
}
- public async stop(): Promise<void> {
+ public stop(): void {
if (this.started === false) {
logger.warn(`${this.logPrefix()} is already stopped`);
return;
return;
}
this.stopping = true;
- await this.stopConnectors();
+ this.stopConnectors();
this.started = false;
this.stopping = false;
}
}
}
- public async stopConnector(connectorId: number): Promise<void> {
+ public stopConnector(connectorId: number): void {
if (this.connectorsStatus.has(connectorId) === false) {
logger.error(`${this.logPrefix(connectorId)} stopping on non existing connector`);
throw new BaseError(`Connector ${connectorId} does not exist`);
}
if (this.connectorsStatus.get(connectorId)?.start === true) {
this.connectorsStatus.get(connectorId)!.start = false;
- await this.stopTransaction(connectorId);
} else if (this.connectorsStatus.get(connectorId)?.start === false) {
logger.warn(`${this.logPrefix(connectorId)} is already stopped on connector`);
}
}
}
- private async stopConnectors(): Promise<void> {
+ private stopConnectors(): void {
if (this.chargingStation.hasEvses) {
for (const [evseId, evseStatus] of this.chargingStation.evses) {
if (evseId > 0) {
for (const connectorId of evseStatus.connectors.keys()) {
- await this.stopConnector(connectorId);
+ this.stopConnector(connectorId);
}
}
}
} else {
for (const connectorId of this.chargingStation.connectors.keys()) {
if (connectorId > 0) {
- await this.stopConnector(connectorId);
+ this.stopConnector(connectorId);
}
}
}
);
while (this.connectorsStatus.get(connectorId)?.start === true) {
if (!this.canStartConnector(connectorId)) {
- await this.stopConnector(connectorId);
+ this.stopConnector(connectorId);
break;
}
if (!this.chargingStation?.ocppRequestService) {
private async stopTransaction(
connectorId: number,
- reason: StopTransactionReason = StopTransactionReason.LOCAL,
+ reason = StopTransactionReason.LOCAL,
): Promise<StopTransactionResponse | undefined> {
const measureId = 'StopTransaction with ATG';
const beginId = PerformanceStatistics.beginMeasure(measureId);
}
}
- public async stop(reason?: StopTransactionReason): Promise<void> {
+ public async stop(reason?: StopTransactionReason, stopTransactions?: boolean): Promise<void> {
if (this.started === true) {
if (this.stopping === false) {
this.stopping = true;
- await this.stopMessageSequence(reason);
+ await this.stopMessageSequence(reason, stopTransactions);
this.closeWSConnection();
if (this.getEnableStatistics() === true) {
this.performanceStatistics?.stop();
parentPort?.postMessage(buildUpdatedMessage(this));
}
- public async stopAutomaticTransactionGenerator(connectorIds?: number[]): Promise<void> {
+ public stopAutomaticTransactionGenerator(connectorIds?: number[]): void {
if (isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds!) {
- await this.automaticTransactionGenerator?.stopConnector(connectorId);
+ this.automaticTransactionGenerator?.stopConnector(connectorId);
}
} else {
- await this.automaticTransactionGenerator?.stop();
+ this.automaticTransactionGenerator?.stop();
}
this.saveAutomaticTransactionGeneratorConfiguration();
parentPort?.postMessage(buildUpdatedMessage(this));
public async stopTransactionOnConnector(
connectorId: number,
- reason = StopTransactionReason.NONE,
+ reason?: StopTransactionReason,
): Promise<StopTransactionResponse> {
const transactionId = this.getConnectorStatus(connectorId)?.transactionId;
if (
{
transactionId,
meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId!, true),
- reason,
+ ...(isNullOrUndefined(reason) && { reason }),
},
);
}
return stationTemplate?.useConnectorId0 ?? true;
}
- private async stopRunningTransactions(reason = StopTransactionReason.NONE): Promise<void> {
+ private async stopRunningTransactions(reason?: StopTransactionReason): Promise<void> {
if (this.hasEvses) {
for (const [evseId, evseStatus] of this.evses) {
if (evseId === 0) {
}
private async stopMessageSequence(
- reason: StopTransactionReason = StopTransactionReason.NONE,
+ reason?: StopTransactionReason,
+ stopTransactions = true,
): Promise<void> {
// Stop WebSocket ping
this.stopWebSocketPing();
// Stop heartbeat
this.stopHeartbeat();
// Stop ongoing transactions
+ stopTransactions && (await this.stopRunningTransactions(reason));
+ // Stop the ATG
if (this.automaticTransactionGenerator?.started === true) {
- await this.stopAutomaticTransactionGenerator();
- } else {
- await this.stopRunningTransactions(reason);
+ this.stopAutomaticTransactionGenerator();
}
if (this.hasEvses) {
for (const [evseId, evseStatus] of this.evses) {
this.stopHeartbeat();
// Stop the ATG if needed
if (this.getAutomaticTransactionGeneratorConfiguration().stopOnConnectionFailure === true) {
- await this.stopAutomaticTransactionGenerator();
+ this.stopAutomaticTransactionGenerator();
}
if (
this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries()! ||
],
[
BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
- async (requestPayload?: BroadcastChannelRequestPayload) =>
- await this.chargingStation.stopAutomaticTransactionGenerator(
- requestPayload?.connectorIds,
- ),
+ (requestPayload?: BroadcastChannelRequestPayload) =>
+ this.chargingStation.stopAutomaticTransactionGenerator(requestPayload?.connectorIds),
],
[
BroadcastChannelProcedureName.SET_SUPERVISION_URL,
}
if (connectorStatus?.transactionStarted === true) {
logger.error(
- `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId} by idTag ${connectorStatus?.transactionIdTag}}`,
+ `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId} by idTag ${connectorStatus?.transactionIdTag}`,
);
return;
}
for (const [id, status] of evseStatus.connectors) {
if (id !== connectorId && status?.transactionStarted === true) {
logger.error(
- `${chargingStation.logPrefix()} Trying to start a transaction on an already used evse id ${evseId} by connector id ${id} with idTag ${status?.transactionIdTag}}`,
+ `${chargingStation.logPrefix()} Trying to start a transaction on an already used evse id ${evseId} by connector id ${id} with idTag ${status?.transactionIdTag}`,
);
await this.resetConnectorOnStartTransactionError(chargingStation, connectorId);
return;
OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
}: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${socMinimumValue}/${
meterValue.sampledValue[sampledValuesIndex].value
- }/${socMaximumValue}}`,
+ }/${socMaximumValue}`,
);
}
}
validate.errors,
);
throw new OCPPError(
- OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
'Incoming request PDU is invalid',
commandName,
JSON.stringify(validate.errors, undefined, 2),
);
// OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
throw new OCPPError(
- OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
'Request PDU is invalid',
commandName,
JSON.stringify(validate.errors, undefined, 2),
);
// OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
throw new OCPPError(
- OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
'Response PDU is invalid',
commandName,
JSON.stringify(validate.errors, undefined, 2),
validate.errors,
);
throw new OCPPError(
- OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
'Response PDU is invalid',
commandName,
JSON.stringify(validate.errors, undefined, 2),
// This is intentional
}
- public static ajvErrorsToErrorType(errors: ErrorObject[]): ErrorType {
- for (const error of errors as DefinedError[]) {
- switch (error.keyword) {
- case 'type':
- return ErrorType.TYPE_CONSTRAINT_VIOLATION;
- case 'dependencies':
- case 'required':
- return ErrorType.OCCURRENCE_CONSTRAINT_VIOLATION;
- case 'pattern':
- case 'format':
- return ErrorType.PROPERTY_CONSTRAINT_VIOLATION;
+ public static ajvErrorsToErrorType(errors: ErrorObject[] | null | undefined): ErrorType {
+ if (isNotEmptyArray(errors) === true) {
+ for (const error of errors as DefinedError[]) {
+ switch (error.keyword) {
+ case 'type':
+ return ErrorType.TYPE_CONSTRAINT_VIOLATION;
+ case 'dependencies':
+ case 'required':
+ return ErrorType.OCCURRENCE_CONSTRAINT_VIOLATION;
+ case 'pattern':
+ case 'format':
+ return ErrorType.PROPERTY_CONSTRAINT_VIOLATION;
+ }
}
}
return ErrorType.FORMAT_VIOLATION;
import type { JsonObject } from '../../JsonType';
export enum OCPP16StopTransactionReason {
- NONE = '',
EMERGENCY_STOP = 'EmergencyStop',
EV_DISCONNECTED = 'EVDisconnected',
HARD_RESET = 'HardReset',