+ public static buildStatusNotificationRequest(
+ chargingStation: ChargingStation,
+ connectorId: number,
+ status: ConnectorStatusEnum
+ ): StatusNotificationRequest {
+ switch (chargingStation.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16) {
+ case OCPPVersion.VERSION_16:
+ return {
+ connectorId,
+ status,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ } as OCPP16StatusNotificationRequest;
+ case OCPPVersion.VERSION_20:
+ case OCPPVersion.VERSION_201:
+ return {
+ timestamp: new Date(),
+ connectorStatus: status,
+ connectorId,
+ evseId: connectorId,
+ } as OCPP20StatusNotificationRequest;
+ default:
+ throw new BaseError('Cannot build status notification payload: OCPP version not supported');
+ }
+ }
+
+ protected static parseJsonSchemaFile<T extends JsonType>(
+ filePath: string,
+ ocppVersion: OCPPVersion,
+ moduleName?: string,
+ methodName?: string
+ ): JSONSchemaType<T> {
+ try {
+ return JSON.parse(fs.readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
+ } catch (error) {
+ FileUtils.handleFileException(
+ filePath,
+ FileType.JsonSchema,
+ error as NodeJS.ErrnoException,
+ OCPPServiceUtils.logPrefix(ocppVersion, moduleName, methodName),
+ { throwError: false }
+ );
+ }
+ }
+