// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+import OCPPError from '../../../exception/OCPPError';
+import { JsonType } from '../../../types/JsonType';
+import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
+import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
+import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
import {
- OCPP16AuthorizationStatus,
- OCPP16AuthorizeRequest,
- OCPP16AuthorizeResponse,
- OCPP16StartTransactionRequest,
- OCPP16StartTransactionResponse,
- OCPP16StopTransactionRequest,
- OCPP16StopTransactionResponse,
-} from '../../../types/ocpp/1.6/Transaction';
+ OCPP16MeterValuesRequest,
+ OCPP16MeterValuesResponse,
+} from '../../../types/ocpp/1.6/MeterValues';
import {
OCPP16BootNotificationRequest,
OCPP16RequestCommand,
OCPP16StatusNotificationResponse,
} from '../../../types/ocpp/1.6/Responses';
import {
- OCPP16MeterValuesRequest,
- OCPP16MeterValuesResponse,
-} from '../../../types/ocpp/1.6/MeterValues';
-
-import type ChargingStation from '../../ChargingStation';
-import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils';
+ OCPP16AuthorizationStatus,
+ OCPP16AuthorizeRequest,
+ OCPP16AuthorizeResponse,
+ OCPP16StartTransactionRequest,
+ OCPP16StartTransactionResponse,
+ OCPP16StopTransactionRequest,
+ OCPP16StopTransactionResponse,
+} from '../../../types/ocpp/1.6/Transaction';
import { ErrorType } from '../../../types/ocpp/ErrorType';
-import { JsonType } from '../../../types/JsonType';
-import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
-import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
-import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
-import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
-import OCPPError from '../../../exception/OCPPError';
-import OCPPResponseService from '../OCPPResponseService';
import { ResponseHandler } from '../../../types/ocpp/Responses';
-import Utils from '../../../utils/Utils';
import logger from '../../../utils/Logger';
+import Utils from '../../../utils/Utils';
+import type ChargingStation from '../../ChargingStation';
+import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils';
+import { ChargingStationUtils } from '../../ChargingStationUtils';
+import OCPPResponseService from '../OCPPResponseService';
+import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
const moduleName = 'OCPP16ResponseService';
requestPayload: JsonType
): Promise<void> {
if (chargingStation.isRegistered() || commandName === OCPP16RequestCommand.BOOT_NOTIFICATION) {
- if (this.responseHandlers.has(commandName)) {
+ if (
+ this.responseHandlers.has(commandName) &&
+ ChargingStationUtils.isRequestCommandSupported(commandName, chargingStation)
+ ) {
try {
await this.responseHandlers.get(commandName)(chargingStation, payload, requestPayload);
} catch (error) {
// Throw exception
throw new OCPPError(
ErrorType.NOT_IMPLEMENTED,
- `${commandName} is not implemented to handle request response payload ${JSON.stringify(
+ `${commandName} is not implemented to handle request response PDU ${JSON.stringify(
payload,
null,
2
)}`,
- commandName
+ commandName,
+ payload
);
}
} else {
throw new OCPPError(
ErrorType.SECURITY_ERROR,
- `${commandName} cannot be issued to handle request response payload ${JSON.stringify(
+ `${commandName} cannot be issued to handle request response PDU ${JSON.stringify(
payload,
null,
2
)} while the charging station is not registered on the central server. `,
- commandName
+ commandName,
+ payload
);
}
}
>(chargingStation, OCPP16RequestCommand.METER_VALUES, {
connectorId,
transactionId: payload.transactionId,
- meterValue: chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
+ meterValue: [chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue],
}));
await chargingStation.ocppRequestService.requestHandler<
OCPP16StatusNotificationRequest,
requestPayload.idTag
);
if (chargingStation.stationInfo.powerSharedByConnectors) {
- chargingStation.stationInfo.powerDivider++;
+ chargingStation.powerDivider++;
}
const configuredMeterValueSampleInterval =
ChargingStationConfigurationUtils.getConfigurationKey(
>(chargingStation, OCPP16RequestCommand.METER_VALUES, {
connectorId: transactionConnectorId,
transactionId: requestPayload.transactionId,
- meterValue: OCPP16ServiceUtils.buildTransactionEndMeterValue(
- chargingStation,
- transactionConnectorId,
- requestPayload.meterStop
- ),
+ meterValue: [
+ OCPP16ServiceUtils.buildTransactionEndMeterValue(
+ chargingStation,
+ transactionConnectorId,
+ requestPayload.meterStop
+ ),
+ ],
}));
if (
!chargingStation.isChargingStationAvailable() ||
OCPP16ChargePointStatus.AVAILABLE;
}
if (chargingStation.stationInfo.powerSharedByConnectors) {
- chargingStation.stationInfo.powerDivider--;
+ chargingStation.powerDivider--;
}
logger.info(
chargingStation.logPrefix() +