Fixed signed data handling after refactoring
MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
-import { ChargePointErrorCode, ChargePointStatus, OCPPAttribute, OCPPAuthorizationStatus, OCPPAuthorizeRequestExtended, OCPPAuthorizeResponse, OCPPBootNotificationRequestExtended, OCPPBootNotificationResponse, OCPPDataTransferRequestExtended, OCPPDataTransferResponse, OCPPDataTransferStatus, OCPPDiagnosticsStatusNotificationRequestExtended, OCPPDiagnosticsStatusNotificationResponse, OCPPFirmwareStatusNotificationRequestExtended, OCPPFirmwareStatusNotificationResponse, OCPPHeartbeatRequestExtended, OCPPHeartbeatResponse, OCPPLocation, OCPPMeasurand, OCPPMeterValuesRequest, OCPPMeterValuesRequestExtended, OCPPMeterValuesResponse, OCPPNormalizedMeterValue, OCPPNormalizedMeterValues, OCPPPhase, OCPPProtocol, OCPPReadingContext, OCPPSampledValue, OCPPStartTransactionRequestExtended, OCPPStartTransactionResponse, OCPPStatusNotificationRequestExtended, OCPPStatusNotificationResponse, OCPPStopTransactionRequestExtended, OCPPStopTransactionResponse, OCPPUnitOfMeasure, OCPPValueFormat, OCPPVersion, RegistrationStatus } from '../../../types/ocpp/OCPPServer';
+/* eslint-disable quotes */
+import { ChargePointErrorCode, ChargePointStatus, OCPPAttribute, OCPPAuthorizationStatus, OCPPAuthorizeRequestExtended, OCPPAuthorizeResponse, OCPPBootNotificationRequestExtended, OCPPBootNotificationResponse, OCPPDataTransferRequestExtended, OCPPDataTransferResponse, OCPPDataTransferStatus, OCPPDiagnosticsStatusNotificationRequestExtended, OCPPDiagnosticsStatusNotificationResponse, OCPPFirmwareStatusNotificationRequestExtended, OCPPFirmwareStatusNotificationResponse, OCPPHeartbeatRequestExtended, OCPPHeartbeatResponse, OCPPLocation, OCPPMeasurand, OCPPMeterValue, OCPPMeterValuesRequest, OCPPMeterValuesRequestExtended, OCPPMeterValuesResponse, OCPPNormalizedMeterValue, OCPPNormalizedMeterValues, OCPPPhase, OCPPProtocol, OCPPReadingContext, OCPPSampledValue, OCPPStartTransactionRequestExtended, OCPPStartTransactionResponse, OCPPStatusNotificationRequestExtended, OCPPStatusNotificationResponse, OCPPStopTransactionRequestExtended, OCPPStopTransactionResponse, OCPPUnitOfMeasure, OCPPValueFormat, OCPPVersion, RegistrationStatus } from '../../../types/ocpp/OCPPServer';
import { ChargingProfilePurposeType, ChargingRateUnitType } from '../../../types/ChargingProfile';
import ChargingStation, { ChargerVendor, Connector, ConnectorCurrentLimitSource, ConnectorType, CurrentType, StaticLimitAmps, TemplateUpdateResult } from '../../../types/ChargingStation';
import { OCPPChangeConfigurationCommandResult, OCPPConfigurationStatus } from '../../../types/ocpp/OCPPClient';
@@ -504,6 +505,8 @@ export default class OCPPService {
this.checkSoftStopTransaction(transaction, stopTransaction, isSoftStop);
// Transaction End has already been received?
await this.checkAndApplyLastConsumptionInStopTransaction(tenant, chargingStation, transaction, stopTransaction);
+ // Signed Data
+ this.checkAndUpdateTransactionWithSignedDataInStopTransaction(transaction, stopTransaction);
// Update Transaction with Stop Transaction and Stop MeterValues
OCPPUtils.updateTransactionWithStopTransaction(transaction, stopTransaction, user, alternateUser, tagID);
// Bill
@@ -545,6 +548,25 @@ export default class OCPPService {
}
}
+ private checkAndUpdateTransactionWithSignedDataInStopTransaction(transaction: Transaction, stopTransaction: OCPPStopTransactionRequestExtended) {
+ // Handle Signed Data in Stop Transaction
+ if (!Utils.isEmptyArray(stopTransaction.transactionData)) {
+ for (const meterValue of stopTransaction.transactionData as OCPPMeterValue[]) {
+ for (const sampledValue of meterValue.sampledValue) {
+ if (sampledValue.format === OCPPValueFormat.SIGNED_DATA) {
+ // Set Signed data in Start of Transaction
+ if (sampledValue.context === OCPPReadingContext.TRANSACTION_BEGIN) {
+ transaction.signedData = sampledValue.value;
+ }
+ if (sampledValue.context === OCPPReadingContext.TRANSACTION_END) {
+ transaction.currentSignedData = sampledValue.value;
+ }
+ }
+ }
+ }
+ }
+ }
+
private async checkAuthorizeStopTransactionAndGetUsers(tenant: Tenant, chargingStation: ChargingStation, transaction: Transaction,
tagId: string, isStoppedByCentralSystem: boolean): Promise<{ user: User; alternateUser: User; }> {
let user: User;

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
import { BillingDataTransactionStart, BillingDataTransactionStop } from '../../../types/Billing';
import { ChargingProfile, ChargingProfilePurposeType } from '../../../types/ChargingProfile';
import ChargingStation, { ChargingStationCapabilities, ChargingStationOcppParameters, ChargingStationTemplate, Connector, ConnectorCurrentLimitSource, CurrentType, OcppParameter, SiteAreaLimitSource, StaticLimitAmps, TemplateUpdate, TemplateUpdateResult } from '../../../types/ChargingStation';
-import { OCPPAttribute, OCPPAuthorizeRequestExtended, OCPPMeasurand, OCPPMeterValue, OCPPNormalizedMeterValue, OCPPPhase, OCPPReadingContext, OCPPStopTransactionRequestExtended, OCPPUnitOfMeasure, OCPPValueFormat } from '../../../types/ocpp/OCPPServer';
+import { OCPPAuthorizeRequestExtended, OCPPMeasurand, OCPPNormalizedMeterValue, OCPPPhase, OCPPReadingContext, OCPPStopTransactionRequestExtended, OCPPUnitOfMeasure, OCPPValueFormat } from '../../../types/ocpp/OCPPServer';
import { OCPPChangeConfigurationCommandParam, OCPPChangeConfigurationCommandResult, OCPPChargingProfileStatus, OCPPConfigurationStatus, OCPPGetConfigurationCommandParam, OCPPGetConfigurationCommandResult, OCPPResetCommandResult, OCPPResetStatus, OCPPResetType } from '../../../types/ocpp/OCPPClient';
import { OICPIdentification, OICPSessionID } from '../../../types/oicp/OICPIdentification';
-import Transaction, { InactivityStatus, TransactionAction, TransactionStop } from '../../../types/Transaction';
+import Transaction, { InactivityStatus, TransactionAction } from '../../../types/Transaction';
import { ActionsResponse } from '../../../types/GlobalType';
import BackendError from '../../../exception/BackendError';
@@ -39,7 +39,6 @@ import TenantComponents from '../../../types/TenantComponents';
import TenantStorage from '../../../storage/mongodb/TenantStorage';
import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
import User from '../../../types/User';
-import UserToken from '../../../types/UserToken';
import Utils from '../../../utils/Utils';
import _ from 'lodash';
import moment from 'moment';
@@ -667,44 +666,6 @@ export default class OCPPUtils {
value: stopTransaction.meterStop,
attribute: Constants.OCPP_ENERGY_ACTIVE_IMPORT_REGISTER_ATTRIBUTE
});
- // Add SignedData
- if (!Utils.isEmptyArray(stopTransaction.transactionData)) {
- for (const meterValue of stopTransaction.transactionData as OCPPMeterValue[]) {
- for (const sampledValue of meterValue.sampledValue) {
- if (sampledValue.format === OCPPValueFormat.SIGNED_DATA) {
- let attribute: OCPPAttribute;
- if (sampledValue.context === OCPPReadingContext.TRANSACTION_BEGIN) {
- attribute = Constants.OCPP_START_SIGNED_DATA_ATTRIBUTE;
- } else if (sampledValue.context === OCPPReadingContext.TRANSACTION_END) {
- attribute = Constants.OCPP_STOP_SIGNED_DATA_ATTRIBUTE;
- }
- stopMeterValues.push({
- id: (id++).toString(),
- ...meterValueBasedProps,
- value: sampledValue.value,
- attribute: attribute
- });
- }
- }
- }
- } else {
- if (transaction.signedData) {
- stopMeterValues.push({
- id:(id++).toString(),
- ...meterValueBasedProps,
- value: transaction.signedData,
- attribute: Constants.OCPP_START_SIGNED_DATA_ATTRIBUTE
- });
- }
- if (transaction.currentSignedData) {
- stopMeterValues.push({
- id:(id++).toString(),
- ...meterValueBasedProps,
- value: transaction.currentSignedData,
- attribute: Constants.OCPP_STOP_SIGNED_DATA_ATTRIBUTE
- });
- }
- }
// Add SoC
if (transaction.currentStateOfCharge > 0) {
stopMeterValues.push({

Fixed signed data handling after refactoring