Use crypto unbiased random integer generator
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16IncomingRequestService.ts
index 68d9da4daf3c2b3bb98a7effef67fb638b2d775b..f62e0ef0b6daf460c7277c9d4c0e58b495436bde 100644 (file)
@@ -544,8 +544,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     logger.debug(
       `${chargingStation.logPrefix()} Charging profile(s) set on connector id ${
         commandPayload.connectorId
-      }, dump their stack: %j`,
-      chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles
+      }: %j`,
+      commandPayload.csChargingProfiles
     );
     return OCPPConstants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED;
   }
@@ -577,8 +577,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       logger.debug(
         `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${
           commandPayload.connectorId
-        }, dump their stack: %j`,
-        connectorStatus.chargingProfiles
+        }`
       );
       return OCPPConstants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
     }
@@ -614,10 +613,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               if (clearCurrentCP) {
                 connectorStatus.chargingProfiles.splice(index, 1);
                 logger.debug(
-                  `${chargingStation.logPrefix()} Matching charging profile(s) cleared on connector id ${
-                    commandPayload.connectorId
-                  }, dump their stack: %j`,
-                  connectorStatus.chargingProfiles
+                  `${chargingStation.logPrefix()} Matching charging profile(s) cleared: %j`,
+                  chargingProfile
                 );
                 clearedCP = true;
               }
@@ -880,8 +877,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
       OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, cp);
       logger.debug(
-        `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}, dump their stack: %j`,
-        chargingStation.getConnectorStatus(connectorId).chargingProfiles
+        `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`,
+        cp
       );
       return true;
     } else if (cp && cp.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE) {
@@ -959,7 +956,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       return OCPPConstants.OCPP_RESPONSE_EMPTY;
     }
     const retrieveDate = Utils.convertToDate(commandPayload.retrieveDate);
-    if (retrieveDate.getTime() <= Date.now()) {
+    const now = Date.now();
+    if (retrieveDate.getTime() <= now) {
       this.asyncResource
         .runInAsyncScope(
           this.updateFirmware.bind(this) as (
@@ -977,7 +975,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         this.updateFirmware(chargingStation).catch(() => {
           /* Intentional */
         });
-      }, retrieveDate.getTime() - Date.now());
+      }, retrieveDate.getTime() - now);
     }
     return OCPPConstants.OCPP_RESPONSE_EMPTY;
   }
@@ -1081,19 +1079,27 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         });
         let uploadResponse: FTPResponse;
         if (accessResponse.code === 220) {
-          // eslint-disable-next-line @typescript-eslint/no-misused-promises
-          ftpClient.trackProgress(async (info) => {
+          ftpClient.trackProgress((info) => {
             logger.info(
               `${chargingStation.logPrefix()} ${
                 info.bytes / 1024
               } bytes transferred from diagnostics archive ${info.name}`
             );
-            await chargingStation.ocppRequestService.requestHandler<
-              OCPP16DiagnosticsStatusNotificationRequest,
-              OCPP16DiagnosticsStatusNotificationResponse
-            >(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
-              status: OCPP16DiagnosticsStatus.Uploading,
-            });
+            chargingStation.ocppRequestService
+              .requestHandler<
+                OCPP16DiagnosticsStatusNotificationRequest,
+                OCPP16DiagnosticsStatusNotificationResponse
+              >(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
+                status: OCPP16DiagnosticsStatus.Uploading,
+              })
+              .catch((error) => {
+                logger.error(
+                  `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
+                    OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
+                  }'`,
+                  error
+                );
+              });
           });
           uploadResponse = await ftpClient.uploadFrom(
             path.join(