import {
ErrorType,
type IncomingRequestHandler,
- type JsonObject,
type JsonType,
type OCPP20ClearCacheRequest,
OCPP20IncomingRequestCommand,
const moduleName = 'OCPP20IncomingRequestService';
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
- protected jsonSchemas: Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonObject>>;
+ protected jsonSchemas: Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonType>>;
private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
public constructor() {
this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
[OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
]);
- this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonType>>([
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
) => boolean;
}
- public async incomingRequestHandler(
+ public async incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
messageId: string,
commandName: OCPP20IncomingRequestCommand,
- commandPayload: JsonType,
+ commandPayload: ReqType,
): Promise<void> {
- let response: JsonType;
+ let response: ResType;
if (
- chargingStation.getOcppStrictCompliance() === true &&
+ chargingStation.stationInfo?.ocppStrictCompliance === true &&
chargingStation.inPendingState() === true &&
(commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION ||
commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION)
ErrorType.SECURITY_ERROR,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
- null,
+ undefined,
2,
)} while the charging station is in pending state on the central server`,
commandName,
}
if (
chargingStation.isRegistered() === true ||
- (chargingStation.getOcppStrictCompliance() === false &&
+ (chargingStation.stationInfo?.ocppStrictCompliance === false &&
chargingStation.inUnknownState() === true)
) {
if (
try {
this.validatePayload(chargingStation, commandName, commandPayload);
// Call the method to build the response
- response = await this.incomingRequestHandlers.get(commandName)(
+ response = (await this.incomingRequestHandlers.get(commandName)!(
chargingStation,
commandPayload,
- );
+ )) as ResType;
} catch (error) {
// Log
logger.error(
ErrorType.NOT_IMPLEMENTED,
`${commandName} is not implemented to handle request PDU ${JSON.stringify(
commandPayload,
- null,
+ undefined,
2,
)}`,
commandName,
ErrorType.SECURITY_ERROR,
`${commandName} cannot be issued to handle request PDU ${JSON.stringify(
commandPayload,
- null,
+ undefined,
2,
)} while the charging station is not registered on the central server.`,
commandName,
return this.validateIncomingRequestPayload(
chargingStation,
commandName,
- this.jsonSchemas.get(commandName),
+ this.jsonSchemas.get(commandName)!,
commandPayload,
);
}