Skip to content

Commit

Permalink
Merge pull request #11 from juherr/bugfix/bootnotification-format
Browse files Browse the repository at this point in the history
fix: BootNotification must respect the OCPP specification
  • Loading branch information
shiv3 authored Oct 9, 2024
2 parents cc33093 + 304e327 commit 00e62ac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/cp/ChargePoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ export class ChargePoint {
this._messageHandler.sendHeartbeat();
}

public sendReset(): void {
this._messageHandler.sendReset();
}

public startHeartbeat(period: number): void {
this._logger.info("Setting heartbeat period to " + period + "s");
if (this._heartbeat) {
Expand Down
37 changes: 18 additions & 19 deletions src/cp/OCPPMessageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {OCPPWebSocket} from "./OCPPWebSocket";
import {OcppMessageRequestPayload, OcppMessageResponsePayload, OCPPWebSocket} from "./OCPPWebSocket";
import {ChargePoint} from "./ChargePoint";
import {Transaction} from "./Transaction";
import {Logger} from "./Logger";
import {OCPPMessageType, OCPPAction, OCPPStatus, BootNotification} from "./OcppTypes";
import {OCPPMessageType, OCPPAction, OCPPStatus, BootNotification, OCPPErrorCode} from "./OcppTypes";

import * as request from "@voltbras/ts-ocpp/dist/messages/json/request";
import * as response from "@voltbras/ts-ocpp/dist/messages/json/response";
Expand Down Expand Up @@ -126,11 +126,22 @@ export class OCPPMessageHandler {

public sendBootNotification(bootPayload: BootNotification): void {
const messageId = this.generateMessageId();
const payload: request.BootNotificationRequest = {
chargePointVendor: bootPayload.ChargePointVendor,
chargePointModel: bootPayload.ChargePointModel,
chargePointSerialNumber: bootPayload.ChargePointSerialNumber,
chargeBoxSerialNumber: bootPayload.ChargeBoxSerialNumber,
firmwareVersion: bootPayload.FirmwareVersion,
iccid: bootPayload.Iccid,
imsi: bootPayload.Imsi,
meterType: bootPayload.MeterType,
meterSerialNumber: bootPayload.MeterSerialNumber,
};
this.sendRequest(
OCPPMessageType.CALL,
OCPPAction.BootNotification,
messageId,
bootPayload
payload,
);
}

Expand All @@ -145,17 +156,6 @@ export class OCPPMessageHandler {
);
}

public sendReset(): void {
const messageId = this.generateMessageId();
const payload: request.ResetRequest = {type: "Hard"};
this.sendRequest(
OCPPMessageType.CALL,
OCPPAction.Reset,
messageId,
payload
);
}

public sendMeterValue(transactionId:number|undefined,connectorId: number, meterValue: number): void {
const messageId = this.generateMessageId();
const payload: request.MeterValuesRequest = {
Expand Down Expand Up @@ -195,7 +195,7 @@ export class OCPPMessageHandler {
type: OCPPMessageType,
action: OCPPAction,
id: string,
payload: OcppMessagePayload,
payload: OcppMessageRequestPayload,
connectorId?: number
): void {
this._requests.add({type, action, id, payload, connectorId});
Expand Down Expand Up @@ -231,7 +231,7 @@ export class OCPPMessageHandler {
action: OCPPAction,
payload: OcppMessagePayloadCall
): void {
let response;
let response: OcppMessageResponsePayload;
switch (action) {
case OCPPAction.RemoteStartTransaction:
response = this.handleRemoteStartTransaction(
Expand Down Expand Up @@ -361,7 +361,6 @@ export class OCPPMessageHandler {

private handleReset(payload: request.ResetRequest): response.ResetResponse {
this._logger.log(`Reset request received: ${payload.type}`);
this._chargePoint.sendReset();
return {status: "Accepted"};
}

Expand Down Expand Up @@ -454,7 +453,7 @@ export class OCPPMessageHandler {
this._logger.log(`Status notification sent successfully: ${JSON.stringify(payload)}`);
}

private sendCallResult(messageId: string, payload: OcppMessagePayload): void {
private sendCallResult(messageId: string, payload: OcppMessageResponsePayload): void {
this._webSocket.send(
OCPPMessageType.CALL_RESULT,
messageId,
Expand All @@ -465,7 +464,7 @@ export class OCPPMessageHandler {

private sendCallError(
messageId: string,
errorCode: string,
errorCode: OCPPErrorCode,
errorDescription: string
): void {
const errorDetails = {
Expand Down
30 changes: 21 additions & 9 deletions src/cp/OCPPWebSocket.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import {Logger} from "./Logger";
import {OCPPAction, OCPPMessageType} from "./OcppTypes";
import {OCPPAction, OCPPErrorCode, OCPPMessageType} from "./OcppTypes";
import * as request from "@voltbras/ts-ocpp/dist/messages/json/request";
import * as response from "@voltbras/ts-ocpp/dist/messages/json/response";

export type OcppMessagePayload =
| request.StartTransactionRequest
| request.StopTransactionRequest
export type OcppMessagePayload = OcppMessageRequestPayload | OcppMessageResponsePayload | OcppMessageErrorPayload;

export type OcppMessageRequestPayload =
| request.AuthorizeRequest
| request.BootNotificationRequest
| request.HeartbeatRequest
| request.MeterValuesRequest
| request.StartTransactionRequest
| request.StatusNotificationRequest
| request.GetDiagnosticsRequest
| request.TriggerMessageRequest
| request.ResetRequest
| request.RemoteStartTransactionRequest
| request.RemoteStopTransactionRequest
| request.StopTransactionRequest;

export type OcppMessageResponsePayload =
| response.GetDiagnosticsResponse
| response.RemoteStartTransactionResponse
| response.RemoteStopTransactionResponse
| response.ResetResponse
| response.TriggerMessageResponse;

export type OcppMessageErrorPayload = {
readonly errorCode: OCPPErrorCode;
readonly errorDescription: string;
readonly errorDetails?: object;
};

type MessageHandler = (
messageType: OCPPMessageType,
Expand Down
4 changes: 4 additions & 0 deletions src/cp/OcppTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {ErrorCode} from "@voltbras/ts-ocpp/dist/ws";

export enum OCPPStatus {
Available = "Available",
Preparing = "Preparing",
Expand Down Expand Up @@ -39,6 +41,8 @@ export enum OCPPAction {
Reset = "Reset",
}

export type OCPPErrorCode = ErrorCode;

export interface BootNotification {
ChargeBoxSerialNumber: string;
ChargePointModel: string;
Expand Down

0 comments on commit 00e62ac

Please sign in to comment.