Initial implementation to get the charging profiles limit
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 23 Mar 2022 09:56:44 +0000 (10:56 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 23 Mar 2022 09:56:44 +0000 (10:56 +0100)
Not used yet

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
README.md
src/charging-station/ChargingStation.ts
src/types/ocpp/1.6/ChargingProfile.ts
src/types/ocpp/ChargingProfile.ts

index 978a2bb1b851b9e79edbc23f50ed5f50ce335c28..aa55b80426b8f6683d63af5582fc66226c0a651b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -225,7 +225,7 @@ But the modifications to test have to be done to the files in the build result d
 
 **src/assets/configurations/\<hashId\>.json**:
 
-The charging station configuration file is automatically generated at startup from the charging station configuration template file.
+The charging station configuration file is automatically generated at startup from the charging station configuration template file and are persistent.
 
 The charging station configuration file content can be regenerated partially on matching charging station configuration template file changes. The charging station serial number is kept unchanged.
 
index 507246b538fc7a0bfd54493dfea958e1d6207e73..06276174e9c851f86c9c5107573ac7f2e2f81e04 100644 (file)
@@ -16,6 +16,11 @@ import {
   RegistrationStatus,
   StatusNotificationResponse,
 } from '../types/ocpp/Responses';
+import {
+  ChargingProfile,
+  ChargingRateUnitType,
+  ChargingSchedulePeriod,
+} from '../types/ocpp/ChargingProfile';
 import ChargingStationConfiguration, { Section } from '../types/ChargingStationConfiguration';
 import ChargingStationOcppConfiguration, {
   ConfigurationKey,
@@ -41,7 +46,6 @@ import WebSocket, { Data, OPEN, RawData } from 'ws';
 import AutomaticTransactionGenerator from './AutomaticTransactionGenerator';
 import { ChargePointErrorCode } from '../types/ocpp/ChargePointErrorCode';
 import { ChargePointStatus } from '../types/ocpp/ChargePointStatus';
-import { ChargingProfile } from '../types/ocpp/ChargingProfile';
 import ChargingStationInfo from '../types/ChargingStationInfo';
 import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
 import Configuration from '../utils/Configuration';
@@ -704,6 +708,56 @@ export default class ChargingStation {
     }
   }
 
+  public getChargingProfileLimit(
+    connectorId: number
+  ): { limit: number; unit: ChargingRateUnitType } | undefined {
+    const timestamp = new Date().getTime();
+    let matchingChargingProfile: ChargingProfile;
+    let chargingSchedulePeriods: ChargingSchedulePeriod[] = [];
+    if (!Utils.isEmptyArray(this.getConnectorStatus(connectorId).chargingProfiles)) {
+      const chargingProfiles: ChargingProfile[] = this.getConnectorStatus(
+        connectorId
+      ).chargingProfiles.filter(
+        (chargingProfile) =>
+          timestamp >= chargingProfile.chargingSchedule?.startSchedule.getTime() &&
+          timestamp <
+            chargingProfile.chargingSchedule?.startSchedule.getTime() +
+              chargingProfile.chargingSchedule.duration &&
+          chargingProfile?.stackLevel === Math.max(...chargingProfiles.map((cp) => cp?.stackLevel))
+      );
+      if (!Utils.isEmptyArray(chargingProfiles)) {
+        for (const chargingProfile of chargingProfiles) {
+          if (!Utils.isEmptyArray(chargingProfile.chargingSchedule.chargingSchedulePeriod)) {
+            chargingSchedulePeriods =
+              chargingProfile.chargingSchedule.chargingSchedulePeriod.filter(
+                (chargingSchedulePeriod, index) => {
+                  timestamp >=
+                    chargingProfile.chargingSchedule.startSchedule.getTime() +
+                      chargingSchedulePeriod.startPeriod &&
+                    chargingProfile.chargingSchedule.chargingSchedulePeriod[index + 1] &&
+                    timestamp <
+                      chargingProfile.chargingSchedule.startSchedule.getTime() +
+                        chargingProfile.chargingSchedule.chargingSchedulePeriod[index + 1]
+                          ?.startPeriod;
+                }
+              );
+            if (!Utils.isEmptyArray(chargingSchedulePeriods)) {
+              matchingChargingProfile = chargingProfile;
+              break;
+            }
+          }
+        }
+      }
+    }
+
+    return (
+      !Utils.isEmptyArray(chargingSchedulePeriods) && {
+        limit: chargingSchedulePeriods[0].limit,
+        unit: matchingChargingProfile.chargingSchedule.chargingRateUnit,
+      }
+    );
+  }
+
   public setChargingProfile(connectorId: number, cp: ChargingProfile): void {
     let cpReplaced = false;
     if (!Utils.isEmptyArray(this.getConnectorStatus(connectorId).chargingProfiles)) {
index 6416bf5d1bd2f0e25a10c58e79641cb4e891c874..e39c213793f77f8acc6da0d7cb9e490b923aee66 100644 (file)
@@ -15,18 +15,18 @@ export interface OCPP16ChargingProfile extends JsonType {
 export interface ChargingSchedule extends JsonType {
   duration?: number;
   startSchedule?: Date;
-  chargingRateUnit: ChargingRateUnitType;
-  chargingSchedulePeriod: ChargingSchedulePeriod[];
+  chargingRateUnit: OCPP16ChargingRateUnitType;
+  chargingSchedulePeriod: OCPP16ChargingSchedulePeriod[];
   minChargeRate?: number;
 }
 
-export interface ChargingSchedulePeriod extends JsonType {
+export interface OCPP16ChargingSchedulePeriod extends JsonType {
   startPeriod: number;
   limit: number;
   numberPhases?: number;
 }
 
-export enum ChargingRateUnitType {
+export enum OCPP16ChargingRateUnitType {
   WATT = 'W',
   AMPERE = 'A',
 }
@@ -46,4 +46,5 @@ export enum ChargingProfilePurposeType {
 export enum RecurrencyKindType {
   DAILY = 'Daily',
   WEEKLY = 'Weekly',
+  MONTHLY = 'Monthly',
 }
index 6dab7cff1284465a8fc07bc1fac9472015cb31ce..d2c36d7d8903e7c9634bb2ecb03e1c536fdab7c6 100644 (file)
@@ -1,3 +1,15 @@
-import { OCPP16ChargingProfile } from './1.6/ChargingProfile';
+import {
+  OCPP16ChargingProfile,
+  OCPP16ChargingRateUnitType,
+  OCPP16ChargingSchedulePeriod,
+} from './1.6/ChargingProfile';
 
 export type ChargingProfile = OCPP16ChargingProfile;
+
+export type ChargingSchedulePeriod = OCPP16ChargingSchedulePeriod;
+
+export type ChargingRateUnitType = OCPP16ChargingRateUnitType;
+
+export const ChargingRateUnitType = {
+  ...OCPP16ChargingRateUnitType,
+};