import WebSocket, { ClientOptions, Data, OPEN, RawData } from 'ws';
import AutomaticTransactionGenerator from './AutomaticTransactionGenerator';
+import { ChargePointErrorCode } from '../types/ocpp/ChargePointErrorCode';
import { ChargePointStatus } from '../types/ocpp/ChargePointStatus';
import { ChargingProfile } from '../types/ocpp/ChargingProfile';
import ChargingStationInfo from '../types/ChargingStationInfo';
await this.stopMessageSequence(reason);
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
- await this.ocppRequestService.sendStatusNotification(
+ await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
connectorId,
- ChargePointStatus.UNAVAILABLE
- );
+ status: ChargePointStatus.UNAVAILABLE,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE;
}
}
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template at startup
- await this.ocppRequestService.sendStatusNotification(
+ await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
connectorId,
- this.getConnectorStatus(connectorId).bootStatus
- );
+ status: this.getConnectorStatus(connectorId).bootStatus,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
this.getConnectorStatus(connectorId).status =
this.getConnectorStatus(connectorId).bootStatus;
} else if (
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template after reset
- await this.ocppRequestService.sendStatusNotification(
+ await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
connectorId,
- this.getConnectorStatus(connectorId).bootStatus
- );
+ status: this.getConnectorStatus(connectorId).bootStatus,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
this.getConnectorStatus(connectorId).status =
this.getConnectorStatus(connectorId).bootStatus;
} else if (!this.stopped && this.getConnectorStatus(connectorId)?.status) {
// Send previous status at template reload
- await this.ocppRequestService.sendStatusNotification(
+ await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
connectorId,
- this.getConnectorStatus(connectorId).status
- );
+ status: this.getConnectorStatus(connectorId).status,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
} else {
// Send default status
- await this.ocppRequestService.sendStatusNotification(
+ await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, {
connectorId,
- ChargePointStatus.AVAILABLE
- );
+ status: ChargePointStatus.AVAILABLE,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
this.getConnectorStatus(connectorId).status = ChargePointStatus.AVAILABLE;
}
}
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { IncomingRequestHandler } from '../../../types/ocpp/Requests';
import { JsonType } from '../../../types/JsonType';
+import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
}
return Constants.OCPP_RESPONSE_UNLOCK_FAILED;
}
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- connectorId,
- OCPP16ChargePointStatus.AVAILABLE
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
return Constants.OCPP_RESPONSE_UNLOCKED;
}
this.chargingStation.getConnectorStatus(id).availability = commandPayload.type;
if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- id,
- chargePointStatus
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: id,
+ status: chargePointStatus,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(id).status = chargePointStatus;
}
return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- connectorId,
- chargePointStatus
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ { connectorId, status: chargePointStatus, errorCode: OCPP16ChargePointErrorCode.NO_ERROR }
);
this.chargingStation.getConnectorStatus(connectorId).status = chargePointStatus;
return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
): Promise<DefaultResponse> {
const transactionConnectorId: number = commandPayload.connectorId;
if (transactionConnectorId) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- transactionConnectorId,
- OCPP16ChargePointStatus.PREPARING
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: transactionConnectorId,
+ status: OCPP16ChargePointStatus.PREPARING,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(transactionConnectorId).status =
OCPP16ChargePointStatus.PREPARING;
this.chargingStation.getConnectorStatus(connectorId).status !==
OCPP16ChargePointStatus.AVAILABLE
) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- connectorId,
- OCPP16ChargePointStatus.AVAILABLE
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.AVAILABLE;
connectorId > 0 &&
this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId
) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- connectorId,
- OCPP16ChargePointStatus.FINISHING
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: OCPP16ChargePointStatus.FINISHING,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.FINISHING;
);
}
- public async sendStatusNotification(
- connectorId: number,
- status: OCPP16ChargePointStatus,
- errorCode: OCPP16ChargePointErrorCode = OCPP16ChargePointErrorCode.NO_ERROR
- ): Promise<void> {
- const payload: StatusNotificationRequest = {
- connectorId,
- errorCode,
- status,
- };
- await this.sendMessage(Utils.generateUUID(), payload, OCPP16RequestCommand.STATUS_NOTIFICATION);
- }
-
public async sendAuthorize(
connectorId: number,
idTag?: string
case OCPP16RequestCommand.STATUS_NOTIFICATION:
return {
connectorId: commandParams?.connectorId,
- errorCode: commandParams?.errorCode,
status: commandParams?.status,
+ errorCode: commandParams?.errorCode,
} as StatusNotificationRequest;
case OCPP16RequestCommand.START_TRANSACTION:
return {
import type ChargingStation from '../../ChargingStation';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { JsonType } from '../../../types/JsonType';
+import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
payload.transactionId,
this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue
));
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- connectorId,
- OCPP16ChargePointStatus.CHARGING
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: OCPP16ChargePointStatus.CHARGING,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.CHARGING;
this.chargingStation.getConnectorStatus(connectorId).status !==
OCPP16ChargePointStatus.AVAILABLE
) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- connectorId,
- OCPP16ChargePointStatus.AVAILABLE
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.AVAILABLE;
!this.chargingStation.isChargingStationAvailable() ||
!this.chargingStation.isConnectorAvailable(transactionConnectorId)
) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- transactionConnectorId,
- OCPP16ChargePointStatus.UNAVAILABLE
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: transactionConnectorId,
+ status: OCPP16ChargePointStatus.UNAVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(transactionConnectorId).status =
OCPP16ChargePointStatus.UNAVAILABLE;
} else {
- await this.chargingStation.ocppRequestService.sendStatusNotification(
- transactionConnectorId,
- OCPP16ChargePointStatus.AVAILABLE
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ {
+ connectorId: transactionConnectorId,
+ status: OCPP16ChargePointStatus.AVAILABLE,
+ errorCode: OCPP16ChargePointErrorCode.NO_ERROR,
+ }
);
this.chargingStation.getConnectorStatus(transactionConnectorId).status =
OCPP16ChargePointStatus.AVAILABLE;
params?: SendParams
): Promise<ResponseType>;
- public abstract sendStatusNotification(
- connectorId: number,
- status: ChargePointStatus,
- errorCode?: ChargePointErrorCode
- ): Promise<void>;
-
public abstract sendAuthorize(connectorId: number, idTag?: string): Promise<AuthorizeResponse>;
public abstract sendStartTransaction(
connectorId: number,