-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import fs from 'fs';
import path from 'path';
OCPP16MeterValuesResponse,
} from '../../../types/ocpp/1.6/MeterValues';
import {
- OCPP16BootNotificationRequest,
+ type OCPP16BootNotificationRequest,
OCPP16RequestCommand,
- OCPP16StatusNotificationRequest,
+ type OCPP16StatusNotificationRequest,
} from '../../../types/ocpp/1.6/Requests';
-import {
+import type {
DiagnosticsStatusNotificationResponse,
OCPP16BootNotificationResponse,
+ OCPP16DataTransferResponse,
OCPP16HeartbeatResponse,
- OCPP16RegistrationStatus,
OCPP16StatusNotificationResponse,
} from '../../../types/ocpp/1.6/Responses';
import {
OCPP16AuthorizationStatus,
- OCPP16AuthorizeRequest,
- OCPP16AuthorizeResponse,
- OCPP16StartTransactionRequest,
- OCPP16StartTransactionResponse,
- OCPP16StopTransactionRequest,
- OCPP16StopTransactionResponse,
+ type OCPP16AuthorizeRequest,
+ type OCPP16AuthorizeResponse,
+ type OCPP16StartTransactionRequest,
+ type OCPP16StartTransactionResponse,
+ type OCPP16StopTransactionRequest,
+ type OCPP16StopTransactionResponse,
} from '../../../types/ocpp/1.6/Transaction';
import { ErrorType } from '../../../types/ocpp/ErrorType';
-import type { ResponseHandler } from '../../../types/ocpp/Responses';
+import { OCPPVersion } from '../../../types/ocpp/OCPPVersion';
+import { RegistrationStatusEnumType, type ResponseHandler } from '../../../types/ocpp/Responses';
import Constants from '../../../utils/Constants';
import logger from '../../../utils/Logger';
import Utils from '../../../utils/Utils';
if (new.target?.name === moduleName) {
throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
}
- super();
+ super(OCPPVersion.VERSION_16);
this.responseHandlers = new Map<OCPP16RequestCommand, ResponseHandler>([
[OCPP16RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
[OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
[OCPP16RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
[OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler.bind(this)],
[OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+ [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler.bind(this)],
]);
this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
[
)
) as JSONSchemaType<DiagnosticsStatusNotificationResponse>,
],
+ [
+ OCPP16RequestCommand.DATA_TRANSFER,
+ JSON.parse(
+ fs.readFileSync(
+ path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
+ ),
+ 'utf8'
+ )
+ ) as JSONSchemaType<OCPP16DataTransferResponse>,
+ ],
]);
this.validatePayload.bind(this);
}
payload,
null,
2
- )} while the charging station is not registered on the central server. `,
+ )} while the charging station is not registered on the central server.`,
commandName,
payload
);
chargingStation: ChargingStation,
payload: OCPP16BootNotificationResponse
): void {
- if (payload.status === OCPP16RegistrationStatus.ACCEPTED) {
+ if (payload.status === RegistrationStatusEnumType.ACCEPTED) {
ChargingStationConfigurationUtils.addConfigurationKey(
chargingStation,
OCPP16StandardParametersKey.HeartbeatInterval,
? chargingStation.restartHeartbeat()
: chargingStation.startHeartbeat();
}
- if (Object.values(OCPP16RegistrationStatus).includes(payload.status)) {
+ if (Object.values(RegistrationStatusEnumType).includes(payload.status)) {
const logMsg = `${chargingStation.logPrefix()} Charging station in '${
payload.status
}' state on the central server`;
- payload.status === OCPP16RegistrationStatus.REJECTED
+ payload.status === RegistrationStatusEnumType.REJECTED
? logger.warn(logMsg)
: logger.info(logMsg);
} else {