import path from 'path';
import { URL, fileURLToPath } from 'url';
-import { JSONSchemaType } from 'ajv';
+import type { JSONSchemaType } from 'ajv';
import { Client, FTPResponse } from 'basic-ftp';
import tar from 'tar';
import OCPPError from '../../../exception/OCPPError';
-import { JsonObject, JsonType } from '../../../types/JsonType';
+import type { JsonObject, JsonType } from '../../../types/JsonType';
import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import {
OCPP16SupportedFeatureProfiles,
} from '../../../types/ocpp/1.6/Configuration';
import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
-import {
+import type {
OCPP16MeterValuesRequest,
OCPP16MeterValuesResponse,
} from '../../../types/ocpp/1.6/MeterValues';
SetChargingProfileRequest,
UnlockConnectorRequest,
} from '../../../types/ocpp/1.6/Requests';
-import {
+import type {
ChangeAvailabilityResponse,
ChangeConfigurationResponse,
ClearChargingProfileResponse,
OCPP16StopTransactionRequest,
OCPP16StopTransactionResponse,
} from '../../../types/ocpp/1.6/Transaction';
-import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
+import type { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
import { ErrorType } from '../../../types/ocpp/ErrorType';
-import { IncomingRequestHandler } from '../../../types/ocpp/Requests';
-import { DefaultResponse } from '../../../types/ocpp/Responses';
+import type { IncomingRequestHandler } from '../../../types/ocpp/Requests';
+import type { DefaultResponse } from '../../../types/ocpp/Responses';
import Constants from '../../../utils/Constants';
import logger from '../../../utils/Logger';
import Utils from '../../../utils/Utils';
) as JSONSchemaType<OCPP16TriggerMessageRequest>,
],
]);
+ this.validatePayload.bind(this);
}
public async incomingRequestHandler(
ChargingStationUtils.isIncomingRequestCommandSupported(commandName, chargingStation)
) {
try {
- if (this.jsonSchemas.has(commandName)) {
- this.validateIncomingRequestPayload(
- chargingStation,
- commandName,
- this.jsonSchemas.get(commandName),
- commandPayload
- );
- } else {
- logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: No JSON schema found for command ${commandName} PDU validation`
- );
- }
+ this.validatePayload(chargingStation, commandName, commandPayload);
// Call the method to build the response
response = await this.incomingRequestHandlers.get(commandName)(
chargingStation,
);
} catch (error) {
// Log
- logger.error(chargingStation.logPrefix() + ' Handle request error: %j', error);
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: Handle incoming request error:`,
+ error
+ );
throw error;
}
} else {
);
}
+ private validatePayload(
+ chargingStation: ChargingStation,
+ commandName: OCPP16IncomingRequestCommand,
+ commandPayload: JsonType
+ ): boolean {
+ if (this.jsonSchemas.has(commandName)) {
+ return this.validateIncomingRequestPayload(
+ chargingStation,
+ commandName,
+ this.jsonSchemas.get(commandName),
+ commandPayload
+ );
+ }
+ logger.warn(
+ `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command ${commandName} PDU validation`
+ );
+ return false;
+ }
+
// Simulate charging station restart
private handleRequestReset(
chargingStation: ChargingStation,