Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Convert sendBootNotification to OCPP message sending handler
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Mar 7, 2022
1 parent 94a464f commit 6a8b180
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 67 deletions.
30 changes: 19 additions & 11 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,12 +937,16 @@ export default class ChargingStation {
// Send BootNotification
let registrationRetryCount = 0;
do {
this.bootNotificationResponse = await this.ocppRequestService.sendBootNotification(
this.bootNotificationRequest.chargePointModel,
this.bootNotificationRequest.chargePointVendor,
this.bootNotificationRequest.chargeBoxSerialNumber,
this.bootNotificationRequest.firmwareVersion
);
this.bootNotificationResponse = (await this.ocppRequestService.sendMessageHandler(
RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel: this.bootNotificationRequest.chargePointModel,
chargePointVendor: this.bootNotificationRequest.chargePointVendor,
chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
firmwareVersion: this.bootNotificationRequest.firmwareVersion,
},
{ skipBufferingOnError: true }
)) as BootNotificationResponse;
if (!this.isInAcceptedState()) {
this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
await Utils.sleep(
Expand Down Expand Up @@ -1237,11 +1241,15 @@ export default class ChargingStation {

private async startMessageSequence(): Promise<void> {
if (this.stationInfo.autoRegister) {
await this.ocppRequestService.sendBootNotification(
this.bootNotificationRequest.chargePointModel,
this.bootNotificationRequest.chargePointVendor,
this.bootNotificationRequest.chargeBoxSerialNumber,
this.bootNotificationRequest.firmwareVersion
await this.ocppRequestService.sendMessageHandler(
RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel: this.bootNotificationRequest.chargePointModel,
chargePointVendor: this.bootNotificationRequest.chargePointVendor,
chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
firmwareVersion: this.bootNotificationRequest.firmwareVersion,
},
{ skipBufferingOnError: true }
);
}
// Start WebSocket ping
Expand Down
31 changes: 20 additions & 11 deletions src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,17 +811,26 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
case MessageTrigger.BootNotification:
setTimeout(() => {
this.chargingStation.ocppRequestService
.sendBootNotification(
this.chargingStation.getBootNotificationRequest().chargePointModel,
this.chargingStation.getBootNotificationRequest().chargePointVendor,
this.chargingStation.getBootNotificationRequest().chargeBoxSerialNumber,
this.chargingStation.getBootNotificationRequest().firmwareVersion,
this.chargingStation.getBootNotificationRequest().chargePointSerialNumber,
this.chargingStation.getBootNotificationRequest().iccid,
this.chargingStation.getBootNotificationRequest().imsi,
this.chargingStation.getBootNotificationRequest().meterSerialNumber,
this.chargingStation.getBootNotificationRequest().meterType,
{ triggerMessage: true }
.sendMessageHandler(
OCPP16RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel:
this.chargingStation.getBootNotificationRequest().chargePointModel,
chargePointVendor:
this.chargingStation.getBootNotificationRequest().chargePointVendor,
chargeBoxSerialNumber:
this.chargingStation.getBootNotificationRequest().chargeBoxSerialNumber,
firmwareVersion:
this.chargingStation.getBootNotificationRequest().firmwareVersion,
chargePointSerialNumber:
this.chargingStation.getBootNotificationRequest().chargePointSerialNumber,
iccid: this.chargingStation.getBootNotificationRequest().iccid,
imsi: this.chargingStation.getBootNotificationRequest().imsi,
meterSerialNumber:
this.chargingStation.getBootNotificationRequest().meterSerialNumber,
meterType: this.chargingStation.getBootNotificationRequest().meterType,
},
{ skipBufferingOnError: true, triggerMessage: true }
)
.catch(() => {
/* This is intentional */
Expand Down
32 changes: 0 additions & 32 deletions src/charging-station/ocpp/1.6/OCPP16RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { JsonType } from '../../../types/JsonType';
import { OCPP16BootNotificationResponse } from '../../../types/ocpp/1.6/Responses';
import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
Expand Down Expand Up @@ -64,37 +63,6 @@ export default class OCPP16RequestService extends OCPPRequestService {
);
}

public async sendBootNotification(
chargePointModel: string,
chargePointVendor: string,
chargeBoxSerialNumber?: string,
firmwareVersion?: string,
chargePointSerialNumber?: string,
iccid?: string,
imsi?: string,
meterSerialNumber?: string,
meterType?: string,
params?: SendParams
): Promise<OCPP16BootNotificationResponse> {
const payload: OCPP16BootNotificationRequest = {
chargePointModel,
chargePointVendor,
...(!Utils.isUndefined(chargeBoxSerialNumber) && { chargeBoxSerialNumber }),
...(!Utils.isUndefined(chargePointSerialNumber) && { chargePointSerialNumber }),
...(!Utils.isUndefined(firmwareVersion) && { firmwareVersion }),
...(!Utils.isUndefined(iccid) && { iccid }),
...(!Utils.isUndefined(imsi) && { imsi }),
...(!Utils.isUndefined(meterSerialNumber) && { meterSerialNumber }),
...(!Utils.isUndefined(meterType) && { meterType }),
};
return (await this.sendMessage(
Utils.generateUUID(),
payload,
OCPP16RequestCommand.BOOT_NOTIFICATION,
{ ...params, skipBufferingOnError: true }
)) as OCPP16BootNotificationResponse;
}

public async sendStatusNotification(
connectorId: number,
status: OCPP16ChargePointStatus,
Expand Down
13 changes: 0 additions & 13 deletions src/charging-station/ocpp/OCPPRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,6 @@ export default abstract class OCPPRequestService {
params?: SendParams
): Promise<ResponseType>;

public abstract sendBootNotification(
chargePointModel: string,
chargePointVendor: string,
chargeBoxSerialNumber?: string,
firmwareVersion?: string,
chargePointSerialNumber?: string,
iccid?: string,
imsi?: string,
meterSerialNumber?: string,
meterType?: string,
params?: SendParams
): Promise<BootNotificationResponse>;

public abstract sendStatusNotification(
connectorId: number,
status: ChargePointStatus,
Expand Down

0 comments on commit 6a8b180

Please sign in to comment.