Skip to content

Commit

Permalink
Add DataTransfer support for incoming request
Browse files Browse the repository at this point in the history
Ref #36

Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
Jérôme Benoit committed Nov 16, 2022
1 parent 82cbef8 commit 77b95a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
OCPP16AvailabilityType,
OCPP16BootNotificationRequest,
OCPP16ClearCacheRequest,
OCPP16DataTransferRequest,
OCPP16DataTransferVendorId,
OCPP16HeartbeatRequest,
OCPP16IncomingRequestCommand,
OCPP16MessageTrigger,
Expand All @@ -43,14 +45,16 @@ import {
SetChargingProfileRequest,
UnlockConnectorRequest,
} from '../../../types/ocpp/1.6/Requests';
import type {
import {
ChangeAvailabilityResponse,
ChangeConfigurationResponse,
ClearChargingProfileResponse,
DiagnosticsStatusNotificationResponse,
GetConfigurationResponse,
GetDiagnosticsResponse,
OCPP16BootNotificationResponse,
OCPP16DataTransferResponse,
OCPP16DataTransferStatus,
OCPP16HeartbeatResponse,
OCPP16StatusNotificationResponse,
OCPP16TriggerMessageResponse,
Expand Down Expand Up @@ -123,6 +127,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
],
[OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, this.handleRequestGetDiagnostics.bind(this)],
[OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, this.handleRequestTriggerMessage.bind(this)],
[OCPP16IncomingRequestCommand.DATA_TRANSFER, this.handleRequestDataTransfer.bind(this)],
]);
this.jsonSchemas = new Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonObject>>([
[
Expand Down Expand Up @@ -269,6 +274,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
)
) as JSONSchemaType<OCPP16TriggerMessageRequest>,
],
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
JSON.parse(
fs.readFileSync(
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../../../assets/json-schemas/ocpp/1.6/DataTransfer.json'
),
'utf8'
)
) as JSONSchemaType<OCPP16DataTransferRequest>,
],
]);
this.validatePayload.bind(this);
}
Expand Down Expand Up @@ -1226,4 +1243,27 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
);
}
}

private handleRequestDataTransfer(
chargingStation: ChargingStation,
commandPayload: OCPP16DataTransferRequest
): OCPP16DataTransferResponse {
try {
if (Object.values(OCPP16DataTransferVendorId).includes(commandPayload.vendorId)) {
return {
status: OCPP16DataTransferStatus.ACCEPTED,
};
}
return {
status: OCPP16DataTransferStatus.UNKNOWN_VENDOR_ID,
};
} catch (error) {
return this.handleIncomingRequestError(
chargingStation,
OCPP16IncomingRequestCommand.DATA_TRANSFER,
error as Error,
{ errorResponse: Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED }
);
}
}
}
3 changes: 3 additions & 0 deletions src/types/ocpp/1.6/Requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export enum OCPP16IncomingRequestCommand {
REMOTE_STOP_TRANSACTION = 'RemoteStopTransaction',
GET_DIAGNOSTICS = 'GetDiagnostics',
TRIGGER_MESSAGE = 'TriggerMessage',
DATA_TRANSFER = 'DataTransfer',
}

export type OCPP16ClearCacheRequest = EmptyObject;
Expand Down Expand Up @@ -139,6 +140,8 @@ export interface OCPP16TriggerMessageRequest extends JsonObject {
connectorId?: number;
}

export enum OCPP16DataTransferVendorId {}

export interface OCPP16DataTransferRequest extends JsonObject {
vendorId: string;
messageId?: string;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChargingProfileStatus,
ClearChargingProfileStatus,
ConfigurationStatus,
DataTransferStatus,
DefaultStatus,
TriggerMessageStatus,
UnlockStatus,
Expand Down Expand Up @@ -82,6 +83,10 @@ export default class Constants {
status: TriggerMessageStatus.NOT_IMPLEMENTED,
});

static readonly OCPP_DATA_TRANSFER_RESPONSE_REJECTED = Object.freeze({
status: DataTransferStatus.REJECTED,
});

static readonly OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL = 60000; // Ms
static readonly OCPP_WEBSOCKET_TIMEOUT = 60000; // Ms
static readonly OCPP_TRIGGER_MESSAGE_DELAY = 500; // Ms
Expand Down

0 comments on commit 77b95a8

Please sign in to comment.