瀏覽代碼

Merge remote-tracking branch 'origin/DD360Audi'

FolusWen 2 年之前
父節點
當前提交
89a5b41ac2
共有 85 個文件被更改,包括 1601 次插入936 次删除
  1. 3 1
      EVSE/Projects/DD360/Apps/CSU/Ethernet.c
  2. 3 3
      EVSE/Projects/DD360/Apps/CSU/OCPP.c
  3. 6 7
      EVSE/Projects/DD360/Apps/CSU/Primary.c
  4. 2 2
      EVSE/Projects/DD360/Apps/CSU/RFID.c
  5. 279 160
      EVSE/Projects/DD360/Apps/CSU/main.c
  6. 2 2
      EVSE/Projects/DD360/Apps/CSU/main.h
  7. 8 0
      EVSE/Projects/DD360/Apps/Config.h
  8. 193 44
      EVSE/Projects/DD360/Apps/Define/define.h
  9. 4 4
      EVSE/Projects/DD360/Apps/Log/log.h
  10. 25 20
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  11. 1 1
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  12. 5 2
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCCS.c
  13. 1 1
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCHA.c
  14. 1 1
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalGBT.c
  15. 47 29
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  16. 43 9
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  17. 1 1
      EVSE/Projects/DD360/Apps/ModuleEventLog/Module_EventLogging.c
  18. 3 3
      EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.h
  19. 24 10
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  20. 8 40
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c
  21. 1 0
      EVSE/Projects/DD360/Apps/ModulePsuComm/Module_PsuComm.c
  22. 18 1
      EVSE/Projects/DD360/Apps/ModuleUpdateFW/Module_UpdateFW.c
  23. 二進制
      EVSE/Projects/DD360/Apps/Module_ChkSysTask
  24. 二進制
      EVSE/Projects/DD360/Apps/Module_DoComm
  25. 二進制
      EVSE/Projects/DD360/Apps/Module_EvComm
  26. 二進制
      EVSE/Projects/DD360/Apps/Module_EventLogging
  27. 二進制
      EVSE/Projects/DD360/Apps/Module_InternalComm
  28. 二進制
      EVSE/Projects/DD360/Apps/Module_UpdateFW
  29. 10 4
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  30. 二進制
      EVSE/Projects/DD360/Apps/UnsafetyOutputTask
  31. 二進制
      EVSE/Projects/DD360/Apps/main
  32. 二進制
      EVSE/Projects/DD360/Images/ramdisk.gz
  33. 二進制
      EVSE/Projects/DD360/output/FactoryConfig
  34. 二進制
      EVSE/Projects/DD360/output/Module_ChkSysTask
  35. 二進制
      EVSE/Projects/DD360/output/Module_DoComm
  36. 二進制
      EVSE/Projects/DD360/output/Module_EvComm
  37. 二進制
      EVSE/Projects/DD360/output/Module_EventLogging
  38. 二進制
      EVSE/Projects/DD360/output/Module_InternalComm
  39. 二進制
      EVSE/Projects/DD360/output/Module_LcmControl
  40. 二進制
      EVSE/Projects/DD360/output/Module_PrimaryComm
  41. 二進制
      EVSE/Projects/DD360/output/Module_UpdateFW
  42. 二進制
      EVSE/Projects/DD360/output/ReadCmdline
  43. 二進制
      EVSE/Projects/DD360/output/UnsafetyOutputTask
  44. 二進制
      EVSE/Projects/DD360/output/main
  45. 3 1
      EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c
  46. 3 3
      EVSE/Projects/DD360Audi/Apps/CSU/OCPP.c
  47. 6 7
      EVSE/Projects/DD360Audi/Apps/CSU/Primary.c
  48. 2 2
      EVSE/Projects/DD360Audi/Apps/CSU/RFID.c
  49. 279 160
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  50. 2 2
      EVSE/Projects/DD360Audi/Apps/CSU/main.h
  51. 8 0
      EVSE/Projects/DD360Audi/Apps/Config.h
  52. 193 44
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  53. 4 4
      EVSE/Projects/DD360Audi/Apps/Log/log.h
  54. 25 20
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  55. 1 1
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  56. 5 2
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCCS.c
  57. 1 1
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCHA.c
  58. 1 1
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalGBT.c
  59. 47 29
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  60. 43 9
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  61. 1 1
      EVSE/Projects/DD360Audi/Apps/ModuleEventLog/Module_EventLogging.c
  62. 3 3
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.h
  63. 24 10
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  64. 8 40
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c
  65. 1 0
      EVSE/Projects/DD360Audi/Apps/ModulePsuComm/Module_PsuComm.c
  66. 18 1
      EVSE/Projects/DD360Audi/Apps/ModuleUpdateFW/Module_UpdateFW.c
  67. 10 4
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  68. 1 1
      EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c
  69. 3 3
      EVSE/Projects/DD360ComBox/Apps/CSU/OCPP.c
  70. 6 7
      EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c
  71. 2 2
      EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c
  72. 134 159
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  73. 2 2
      EVSE/Projects/DD360ComBox/Apps/CSU/main.h
  74. 1 0
      EVSE/Projects/DD360ComBox/Apps/Config.h
  75. 1 1
      EVSE/Projects/DD360ComBox/Apps/Define/define.h
  76. 25 20
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c
  77. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h
  78. 5 2
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCCS.c
  79. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCHA.c
  80. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalGBT.c
  81. 36 29
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c
  82. 5 8
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c
  83. 0 9
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c
  84. 1 0
      EVSE/Projects/DD360ComBox/Apps/ModulePsuComm/Module_PsuComm.c
  85. 二進制
      EVSE/rootfs/root/Module_Payment_Bazel8

+ 3 - 1
EVSE/Projects/DD360/Apps/CSU/Ethernet.c

@@ -98,7 +98,7 @@ static int isReachableInternet(void)
         while (fgets(buf, sizeof(buf), fp) != NULL) {
             if (strstr(buf, "inet addr:") > 0) {
                 sscanf(buf, "%*s%s", tmp);
-                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
+                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(tmp) - strspn(tmp, "addr:"));
 
                 if (strcmp(tmp, (char *)pSysConfig->Eth0Interface.EthIpAddress) != EQUAL) {
                     strcpy((char *) pSysConfig->Eth0Interface.EthIpAddress, tmp);
@@ -186,6 +186,8 @@ void InitEthernet(void)
     log_info("%s",tmpbuf);
     system(tmpbuf);
 
+    system("/sbin/ifconfig lo up");
+
     //Run DHCP client if enabled
     system("killall udhcpc");
     system("rm -rf /etc/resolv.conf");

+ 3 - 3
EVSE/Projects/DD360/Apps/CSU/OCPP.c

@@ -422,7 +422,7 @@ void ocpp_chk_remoteStart_cmd()
                     ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                     //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
                     //ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
+                    DetectPluginStart(ac_index);
                     return;
                 }
                 ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
@@ -473,7 +473,7 @@ void ocpp_chk_remoteStart_cmd()
                 chargingInfo[dcIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                 //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
-                DetectPluginStart();
+                DetectPluginStart(dcIndex);
             }
             ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
         } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
@@ -481,7 +481,7 @@ void ocpp_chk_remoteStart_cmd()
                     chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
                 chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                DetectPluginStart();
+                DetectPluginStart(scheduleIndex);
             }
             chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
         }

+ 6 - 7
EVSE/Projects/DD360/Apps/CSU/Primary.c

@@ -218,9 +218,8 @@ static void checkChargingInfoByDC(uint8_t systemStatus)
     switch (systemStatus) {
     case S_IDLE:
     case S_RESERVATION:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
+        if (isDetectPlugin(pSysInfo->CurGunSelected)) {
+            _DetectPlugInTimeout(pSysInfo->CurGunSelected);
             destroySelGun(pSysInfo->CurGunSelected);
             
         } else {
@@ -261,7 +260,8 @@ static void checkChargingInfoByDC(uint8_t systemStatus)
 
     case S_CHARGING:
         if (pSysConfig->StopChargingByButton == YES ||
-                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE ||
+                pSysConfig->isAuthrizeByEVCCID) {
             // 停止充電
             ChargingTerminalProcess(pSysInfo->CurGunSelected);
         }
@@ -286,9 +286,8 @@ static void checkChargingInfoByAC(void)
 
     switch (pAcChargingInfo->SystemStatus) {
     case S_IDLE:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
+        if (isDetectPlugin(pSysInfo->CurGunSelected)) {
+            _DetectPlugInTimeout(pSysInfo->CurGunSelected);
         }
         break;
 

+ 2 - 2
EVSE/Projects/DD360/Apps/CSU/RFID.c

@@ -269,7 +269,7 @@ void ScannerCardProcess(void)
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
     ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
 
-    if (!isDetectPlugin() &&
+    if (!isDetectPlugin(pSysInfo->CurGunSelected) &&
             !isCardScan &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
@@ -325,7 +325,7 @@ void ScannerCardProcess(void)
     } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
         StartSystemTimeoutDet(Timeout_VerifyComp);
     } else if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
-        StartSystemTimeoutDet(Timeout_WaitPlug);
+        //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected, Timeout_WaitPlug);
     } else {
         isCardScan = false;
     }

+ 279 - 160
EVSE/Projects/DD360/Apps/CSU/main.c

@@ -77,6 +77,8 @@ static ChillerTempErr gChillerTempErr = {0};
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 
+#define DERATING_TARGET_LEVEL 5
+
 // for initial index to check EV board type is correct
 uint8_t bd0_1_status = 0;
 uint8_t bd0_2_status = 0;
@@ -84,12 +86,12 @@ uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
 char *fwVersion = "V1.21.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "v1.21.5";
+char* DebugVersion = "V1.21.9";
 //sqlite3 *localDb;
 bool isDb_ready;
 
 //------------------------------------------------------------------------------
-void ClearDetectPluginFlag();
+void ClearDetectPluginFlag(int gunIndex);
 
 long long DiffTimebWithNow(struct timeb ST);
 uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
@@ -323,7 +325,7 @@ static void GetFirmwareVersion(void)
 {
     // Get CSU root file system version
     sprintf((char *)pSysInfo->CsuRootFsFwRev, fwVersion);
-
+    sprintf((char *)ShmDcCommonData->DebugVersion, DebugVersion);
     uint8_t count = 0, chademo = 0, ccs = 0, gb = 0;
     for (uint8_t idx = 0; idx < 3; idx++) {
         if (pSysConfig->ModelName[7 + idx] == 'J') {
@@ -1273,11 +1275,12 @@ int Initialization(void)
     // 初始化卡號驗證的 Flag
     ClearAuthorizedFlag();
 
-    // 初始化插槍驗證的 Flag
-    ClearDetectPluginFlag();
+
 
     for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
+        // 初始化插槍驗證的 Flag
+        ClearDetectPluginFlag(count);
 
         pDcChargingInfo->RemoteStartFlag = NO;
 
@@ -1483,36 +1486,41 @@ bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
 //===============================================
 // 掃描插槍狀況
 //===============================================
-void ClearDetectPluginFlag(void)
+void ClearDetectPluginFlag(int gunIndex)
 {
-    uint8_t gunIndex = 0;
-    pSysInfo->WaitForPlugit = NO;
 
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
     //DS60-120 add
-    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-        if (pDcChargingInfo->RemoteStartFlag == YES) {
-            pDcChargingInfo->RemoteStartFlag = NO;
-        }
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+    if (pDcChargingInfo->RemoteStartFlag == YES) {
+        pDcChargingInfo->RemoteStartFlag = NO;
     }
 
+
     if (pSysInfo->OrderCharging != NO_DEFINE) {
         pSysInfo->OrderCharging = NO_DEFINE;
     }
 }
 
-void DetectPluginStart()
+void DetectPluginStart(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = YES;
+    //pSysInfo->WaitForPlugit = YES;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
+    log_info("Gun%d start detect plug in",gunIndex);
 }
 
-bool isDetectPlugin()
+bool isDetectPlugin(int gunIndex)
 {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
+        return true;
+    }
+    /*
     if (pSysInfo->WaitForPlugit == YES) {
         return true;
     }
-
+    */
     return false;
 }
 
@@ -1544,7 +1552,7 @@ bool isEvStopCharging_chademo(uint8_t gunIndex)
 {
     if (isEvGunLocked_chademo(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none (%d) ", gunIndex);
+        //log_info("gun locked none (%d) ", gunIndex);
         return YES;
     }
 
@@ -1575,7 +1583,7 @@ bool isEvStopCharging_gb(uint8_t gunIndex)
 {
     if (isEvGunLocked_gb(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none. ");
+        //log_info("gun locked none. ");
         return YES;
     }
 
@@ -1614,7 +1622,7 @@ bool isEvStopCharging_ccs(uint8_t gunIndex)
 {
     if (isEvGunLocked_ccs(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none. ");
+        //log_info("gun locked none. ");
         return YES;
     }
 
@@ -1656,13 +1664,29 @@ void DisplayChargingInfo()
     systemPageRestoreInit();
 }
 
-void _AutoReturnTimeout(void)
+void _AutoReturnTimeout(int gunIndex)
 {
     log_info("*********** _AutoReturnTimeout(%d) *********** ", pSysInfo->PageIndex);
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
-        ClearDetectPluginFlag();
+        
+        if (pDcChargingInfo->RemoteStartFlag) {
+            ClearDetectPluginFlag(gunIndex);
+        } else {
+            ClearDetectPluginFlag(0);
+            ClearDetectPluginFlag(1);
+        }
     } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
-        DetectPluginStart();
+        if (pDcChargingInfo->RemoteStartFlag) {
+            DetectPluginStart(gunIndex);
+        } else {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                DetectPluginStart(LEFT_GUN_NUM);
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                DetectPluginStart(RIGHT_GUN_NUM);
+        }
     }
 
     usleep(50000);
@@ -1696,18 +1720,39 @@ void _AuthorizedTimeout(void)
     }
 }
 
-void _DetectPlugInTimeout(void)
+void _DetectPlugInTimeout(int gunIndex)
 {
-    log_info("*********** _DetectPlugInTimeout *********** ");
     strcpy((char *)pSysConfig->UserId, "");
-    ClearDetectPluginFlag();
-
+    
+
+    uint8_t is_remote = NO;
+    for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+        if (pDcChargingInfo->RemoteStartFlag) {
+            //此停止為remote start停止
+            is_remote = YES;
+            break;
+        }
+    }
+    if (is_remote) {
+        // Remote start進入充電
+        log_info("Clear Gun%d Remote start detect plugin flag",gunIndex);
+        StopGunInfoTimeoutDet(gunIndex);
+        ClearDetectPluginFlag(gunIndex);
+    } else {
+        log_info("Clear Gun%d RFID detect plugin flag", gunIndex);
+        // 刷卡進入充電
+        ClearDetectPluginFlag(LEFT_GUN_NUM);
+        ClearDetectPluginFlag(RIGHT_GUN_NUM);
+        StopGunInfoTimeoutDet(LEFT_GUN_NUM);
+        StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
+    }
     sleep(1); //等待DoComm回報插槍訊號給主櫃
 #if defined DD360Audi
 	//pSysInfo->SystemPage = _LCM_COMPLETE;
-	setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
+	setChargerMode(gunIndex, S_TERMINATING);
 #elif DD360 || DD360Combox
- 	setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
+ 	setChargerMode(gunIndex, S_IDLE);
 #endif
     systemPageRestoreInit();
 }
@@ -1730,7 +1775,7 @@ void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
         }
     }
     ChargingTerminalProcess(gunIndex);
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
 }
 
 void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
@@ -1744,7 +1789,7 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
 #elif DD360 || DD360Combox
 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
 #endif
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
     }
 }
 
@@ -1758,7 +1803,7 @@ void _PrepareTimeout(uint8_t gunIndex)
 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
 #endif
     pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
 }
 
 void _CcsPrechargeTimeout(uint8_t gunIndex)
@@ -2769,6 +2814,7 @@ void StartSystemTimeoutDet(uint8_t flag)
 {
     if (pSysInfo->SystemTimeoutFlag != flag) {
         GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
+       //log_info("Start System Timeout: %d",flag);
     }
     pSysInfo->SystemTimeoutFlag = flag;
 }
@@ -2786,6 +2832,7 @@ void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
     if (gunIndex < pSysConfig->TotalConnectorCount) {
         if (pDcChargingInfo->TimeoutFlag != flag) {
             gettimeofday(&pDcChargingInfo->TimeoutTimer, NULL);
+            //log_info("Start Gun%d Info timeout: %d",gunIndex,flag);
         }
         pDcChargingInfo->TimeoutFlag = flag;
     }
@@ -2894,7 +2941,7 @@ void CreateTimeoutFork(void)
                 break;
             case Timeout_VerifyFail:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
-                    _AutoReturnTimeout();
+                    _AutoReturnTimeout(pSysInfo->CurGunSelected);
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
                     if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
@@ -2910,16 +2957,8 @@ void CreateTimeoutFork(void)
 
             case Timeout_VerifyComp:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
-                    _AutoReturnTimeout();
-                    StopSystemTimeoutDet();
-                }
-                break;
-
-            case Timeout_WaitPlug:
-                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
-                    _DetectPlugInTimeout();
+                    _AutoReturnTimeout(pSysInfo->CurGunSelected);
                     StopSystemTimeoutDet();
-                    destroySelGun(pSysInfo->CurGunSelected);
                 }
                 break;
 
@@ -2962,6 +3001,14 @@ void CreateTimeoutFork(void)
                 }
                 break;
 
+                case Timeout_WaitPlug:
+                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
+                        log_info("*********** Gun%d _DetectPlugInTimeout *********** ", gunIndex);
+                        _DetectPlugInTimeout(gunIndex);
+                        StopGunInfoTimeoutDet(gunIndex);
+                        destroySelGun(gunIndex);
+                    }
+                    break;
                 case Timeout_Preparing:
                     if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
                         _PrepareTimeout(gunIndex);
@@ -3192,35 +3239,36 @@ void OcppRemoteStartChk()
 {
     if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
 
-    } else if (!isDetectPlugin()) {
+    } else{
         // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
         uint8_t acDirIndex = pSysConfig->AcConnectorCount;
 
         for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
             pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(ac_index);
-
-            if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
-                if (pAcChargingInfo->SystemStatus == S_IDLE ||
+            if (!isDetectPlugin(acDirIndex)) {
+                if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
+                    if (pAcChargingInfo->SystemStatus == S_IDLE ||
                         pAcChargingInfo->SystemStatus == S_RESERVATION) {
+                        ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
+                        pAcChargingInfo->RemoteStartFlag = YES;
+                        pSysInfo->OrderCharging = YES;
+                        //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
+                        ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
+                        DetectPluginStart(acDirIndex);
+                        return;
+                    }
                     ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-                    pAcChargingInfo->RemoteStartFlag = YES;
-                    pSysInfo->OrderCharging = YES;
-                    //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
-                    ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
-                    return;
                 }
-                ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
             }
         }
-
+        
         uint8_t threeGunIndex = 0;
         uint8_t dcIndex = 0;
         bool isGunUsingStatus = false;
 
         for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
+            /*
             // 如果有 AC 槍,且 DC 槍也有兩把
             if (acDirIndex == 1 && _index == 1) {
                 threeGunIndex = 1;
@@ -3248,22 +3296,23 @@ void OcppRemoteStartChk()
         if (dcIndex == 0) {
             threeGunIndex = 0;
         }
+        */
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
 
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(dcIndex);
-
-        if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES) {
-            if (pDcChargingInfo->SystemStatus == S_IDLE ||
+            if (ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq == YES) {
+                if (pDcChargingInfo->SystemStatus == S_IDLE ||
                     pDcChargingInfo->SystemStatus == S_RESERVATION) {
-                pDcChargingInfo->RemoteStartFlag = YES;
-                pSysInfo->OrderCharging = YES;
-                //pSysInfo->OrderCharging = gunIndex;
-                ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-                DetectPluginStart();
+                    pDcChargingInfo->RemoteStartFlag = YES;
+                    pSysInfo->OrderCharging = YES;
+                    //pSysInfo->OrderCharging = gunIndex;
+                    ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
+                    DetectPluginStart(_index);
 #if defined DD360Audi
-                setSelGunWaitToAuthor(dcIndex); //Jerry add
+                    setSelGunWaitToAuthor(_index); //Jerry add
 #endif //defined DD360Audi
+                }
+                ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
             }
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
         }
     }
 }
@@ -4383,6 +4432,144 @@ void showversion()
     }
     log_info("\t================================ ");
 }
+
+
+void SetNatural300AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetCurrent[0] = 5000;
+    deratingByConnOtp->deratingTargetCurrent[1] = 3000;
+    deratingByConnOtp->deratingTargetCurrent[2] = 1000;
+    deratingByConnOtp->deratingTargetCurrent[3] = 0;
+    deratingByConnOtp->deratingTargetCurrent[4] = 0;
+}
+void SetLiquidCoolGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetCurrent[0] = 5000;
+    deratingByConnOtp->deratingTargetCurrent[1] = 4000;
+    deratingByConnOtp->deratingTargetCurrent[2] = 3000;
+    deratingByConnOtp->deratingTargetCurrent[3] = 0;
+    deratingByConnOtp->deratingTargetCurrent[4] = 0;
+}
+
+void SetCHAdeMoTypeKOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetRate[0] = 1;
+    deratingByConnOtp->deratingTargetRate[1] = 0.8;
+    deratingByConnOtp->deratingTargetRate[2] = 0.8;
+    deratingByConnOtp->deratingTargetRate[3] = 0;
+    deratingByConnOtp->deratingTargetRate[4] = 0;
+
+    memset(&deratingByConnOtp->deratingTargetCurrent[0], 0, sizeof(deratingByConnOtp->deratingTargetCurrent));
+}
+
+void SetCHAdeMoTypeSJOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetCurrent[0] = 2000;
+    deratingByConnOtp->deratingTargetCurrent[1] = 1250;
+    deratingByConnOtp->deratingTargetCurrent[2] = 1250;
+    deratingByConnOtp->deratingTargetCurrent[3] = 0;
+    deratingByConnOtp->deratingTargetCurrent[4] = 0;
+}
+
+static void SetGunTypeOTPValue(void)
+{
+    //struct ChargingInfoData* chargingData_2 = NULL;
+    uint8_t Gun1Type = 0;
+    uint8_t Gun2Type = 0;
+    uint8_t Type;
+    int i,cnt;
+    if (pSysConfig->TotalConnectorCount == 1) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(0);
+        Gun1Type = pSysConfig->ModelName[7];
+        Gun2Type = pSysConfig->ModelName[7];
+
+        switch (Gun1Type) {
+
+        case 'K':
+            SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        case 'S':
+            SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        case 'T':
+        case 'D':
+            SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+            // 水冷
+        case 'V':
+        case 'F':
+            SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        default:
+            pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
+        }
+        if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
+            log_info("------------ Gun0 - Type:%c Derating info (OTP)-----------", Gun1Type);
+            if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
+                for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                    if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
+                        log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
+                    }
+                }
+            } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
+                for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                    if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
+                        log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
+                    }
+                }
+            }
+        }
+
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        Gun1Type = pSysConfig->ModelName[7];
+        Gun2Type = pSysConfig->ModelName[9];
+        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+
+            switch (i == 0 ? Gun1Type : Gun2Type) {
+            case 'K':
+                SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+            case 'S':
+                SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+                // 風冷300A
+            case 'T':
+            case 'D':
+                SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+                // 水冷
+            case 'V':
+            case 'F':
+                SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+            default:
+                pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
+            }
+            if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
+                log_info("------------ Gun%d - Type:%c Derating info (OTP)-----------",i, i == 0 ? Gun1Type : Gun2Type);
+                if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
+                    for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                        if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
+                            log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
+                        }
+                    }
+                } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
+                    for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                        if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
+                            log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
 int main(void)
 {
     bool isModelNameMatch = true;
@@ -4554,6 +4741,8 @@ int main(void)
 
     time_t ShowEVStatusTimer[2] = { 0 };
 
+    SetGunTypeOTPValue();
+
     for (;;) {
 
         CheckOcppStatus();
@@ -4584,11 +4773,6 @@ int main(void)
         //確認Power cabinet PSU Status
         //powerCabinetPsuAlarmStatus();
 
-        if (pGunIndexInfo->AcGunIndex > 0 && isDetectPlugin() && !GetIsCardScan()) {
-            // AUDI_LCM_CHANGE
-            pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
-        }
-
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
             //CheckTask();
 
@@ -4645,6 +4829,14 @@ int main(void)
 
             ChkOcppStatus(gunIndex);
 
+            if (pGunIndexInfo->AcGunIndex > 0 &&
+                isDetectPlugin(gunIndex) &&
+                !GetIsCardScan() &&
+                gunIndex == pSysInfo->CurGunSelected) {
+                // AUDI_LCM_CHANGE
+                pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
+            }
+
             if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
                     pDcChargingInfo->SystemStatus <= S_CHARGING) ||
                     (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
@@ -4670,7 +4862,9 @@ int main(void)
                     strcpy((char *)pDcChargingInfo->StopDateTime, "");
                     strcpy((char *)pDcChargingInfo->StartUserId, "");
                     strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "");
-                    
+                    if (pDcChargingInfo->deratingByConnOtp.deratingIndex != 0) {
+                        pDcChargingInfo->deratingByConnOtp.deratingIndex = 0;
+                    }
                     //Jerry add
                     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
                     memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
@@ -4736,7 +4930,7 @@ int main(void)
                             systemPageRestoreInit();
                         }
                     }
-                    ClearDetectPluginFlag();
+                    ClearDetectPluginFlag(gunIndex);
 
                     if (pDcChargingInfo->SystemStatus != S_FAULT)
                     {
@@ -4776,13 +4970,8 @@ int main(void)
 
                 // Idle 正常程序起點
                 // 判斷是否有啟用檢查插槍
-                if (isDetectPlugin()) {
-                    /*
-                    if(pDcChargingInfo->Type == _Type_CCS_2 &&
-                            pSysConfig->isAuthrizeByEVCCID &&
-                            strcmp((char *)pDcChargingInfo->EVCCID,(char *)pSysConfig->UserId) != EQUAL )
-                        continue;
-                        */
+                if (isDetectPlugin(gunIndex)) {
+                    StartGunInfoTimeoutDet(gunIndex, Timeout_WaitPlug);
                     // 卡號驗證成功後,等待充電槍插入充電車
                     if (pDcChargingInfo->RemoteStartFlag == YES) {
                         if (pDcChargingInfo->ConnectorPlugIn == YES &&
@@ -4794,7 +4983,8 @@ int main(void)
                             AddPlugInTimes(gunIndex);
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             strcpy((char *)pDcChargingInfo->StartUserId, "");
-                            ClearDetectPluginFlag();
+                            ClearDetectPluginFlag(gunIndex);
+                            StopGunInfoTimeoutDet(gunIndex);
                             continue;
                         }
                     } else if (pSysInfo->OrderCharging == NO_DEFINE) {
@@ -4819,11 +5009,13 @@ int main(void)
                                      gunIndex,
                                      pDcChargingInfo->StartUserId);
                             strcpy((char *)pSysConfig->UserId, "");
-                            ShmDcCommonData->AuthroizeType = IdTokenType_ISO14443;
+                            ShmDcCommonData->AuthroizeType = IdTokenType_Central;
                             // 當前操作的槍號,進入 Preparing
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
-                            ClearDetectPluginFlag();
-
+                            ClearDetectPluginFlag(LEFT_GUN_NUM);
+                            ClearDetectPluginFlag(RIGHT_GUN_NUM);
+                            StopGunInfoTimeoutDet(LEFT_GUN_NUM);
+                            StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
                             continue;
                         }
                     }
@@ -4833,21 +5025,7 @@ int main(void)
                         // AUDI_LCM_CHANGE
                         pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
                     }
-                } /*else if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE &&
-                           (pDcChargingInfo->ConnectorPlugIn == YES &&
-                            pDcChargingInfo->IsAvailable)
-                          ) {
-                    log_info("-----------------3-----------------");
-
-                    if (GetStartChargingByAlterMode(gunIndex) == true) {
-                        ChangeGunSelectByIndex(gunIndex);
-                        AddPlugInTimes(gunIndex);
-                        setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
-                        ClearDetectPluginFlag();
-                        continue;
-                    }
-                } */
-                else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn && 
+                } else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn && 
                         pSysInfo->CurGunSelected == gunIndex && !pDcChargingInfo->isEVCCIDVerify) {
                     systemPageRestoreInit();
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -4872,17 +5050,7 @@ int main(void)
                     gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
                 }
 
-                isRessign = NO;
-
-                if (distributionPsuModule(&isRessign, gunIndex) == YES) {
-                    continue;
-                }
-
-                if (isRessign == YES) {
-                    setChargerMode(gunIndex, MODE_REASSIGN);
-                } else {
-                    setChargerMode(gunIndex, MODE_PRECHARGE);
-                }
+                setChargerMode(gunIndex, S_PREPARNING);
 
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -4893,36 +5061,6 @@ int main(void)
             }
             break;
 
-            case S_REASSIGN:
-                if (isModeChange(gunIndex)) {
-                    log_info("============================= S_REASSIGN(%x) ============================= ", gunIndex);
-                    gettimeofday(&_toAverage_time, NULL);
-                }
-
-                // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
-                // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
-                if (pSysInfo->ReAssignedFlag == _REASSIGNED_NONE ||
-                        pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-                    if (pSysInfo->CanAverageCharging) {
-                        pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;//DS60-120 add
-                        setChargerMode(gunIndex, MODE_PRECHARGE);
-                    } else {
-                        setChargerMode(gunIndex, MODE_IDLE);
-                    }
-                    pSysInfo->ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 add
-                } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
-                           pSysInfo->BridgeRelayStatus == NO) {
-                    log_info("=============Smart Charging : _REASSIGNED_COMP============= Step 6 ");
-                    pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                    //pSysInfo->ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 remove
-                    pSysInfo->CanAverageCharging = true; //DS60-120 add
-                }
-
-                if (pSysInfo->CurGunSelected == gunIndex) {
-                    pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
-                }
-                break;
-
             case S_PREPARNING:
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_PREPARNING(%x) ============================= ", gunIndex);
@@ -4936,25 +5074,6 @@ int main(void)
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 
-                //DS60-120 add
-                if (pSysConfig->TotalConnectorCount >= 2) {
-                    bool oughtAver = true;
-                    for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                        pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(index);
-                        // 共同進入充電邏輯
-                        if (pDcChargingInfo->SystemStatus != S_PREPARNING) {
-                            oughtAver = false;
-                            break;
-                        }
-                    }
-
-                    if (oughtAver) {
-                        log_info("********* Automatically change to aver mode ********** ");
-                        pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                        pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
-                    }
-                }
-
                 checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
 
                 if (pSysInfo->CurGunSelected == gunIndex) {

+ 2 - 2
EVSE/Projects/DD360/Apps/CSU/main.h

@@ -65,8 +65,8 @@
 //} LedConfig;
 
 //------------------------------------------------------------------------------
-bool isDetectPlugin(void);
-void _DetectPlugInTimeout(void);
+bool isDetectPlugin(int gunIndex);
+void _DetectPlugInTimeout(int gunIndex);
 void _evccidlinktimeout(uint8_t gunIndex);
 void StartSystemTimeoutDet(uint8_t flag);
 void StopSystemTimeoutDet(void);

+ 8 - 0
EVSE/Projects/DD360/Apps/Config.h

@@ -293,6 +293,10 @@ enum _CREDITCARD_STATUS {
 	_CREDITCARD_SETTLEMENT,
 	_CREDITCARD_START,
 };
+enum _DERATING_TEMP {
+    STAGE1_GUN_DERATING_TEMP = 140,
+    STAGE2_GUN_DERATING_TEMP = 145,
+};
 //------------------------------------------------------------------------------
 //struct StructMeter {
 //    float curMeterValue;
@@ -418,6 +422,7 @@ typedef struct StGunInfo {
     char ChargeStopTime[32];
     char ChargeDuration[32];
     uint8_t withChiller;      //是否有水冷機
+    uint8_t WaitForPlugit;    // 等待插槍FLAG
 } GunInfo;
 
 typedef struct Psu_VersionInfo{
@@ -488,6 +493,9 @@ typedef struct StDcCommonInfo {
     GunInfo pGunInfo[2];
     uint8_t showNetPackage;
     uint8_t showCanPackage;
+    time_t FanOnTime;
+    float TempVolt[4];
+    char DebugVersion[32];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 193 - 44
EVSE/Projects/DD360/Apps/Define/define.h

@@ -153,6 +153,15 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
     #define GENERAL_GUN_QUANTITY	0
     #define PSU_QUANTITY            2
     #define ONE_CONNECTOR_USE       0
+#elif defined Emulator
+    #define MAX_PSU_QUANTITY        62
+    #define CHAdeMO_QUANTITY        3
+    #define CCS_QUANTITY            3
+    #define GB_QUANTITY             3
+    #define AC_QUANTITY             3
+    #define GENERAL_GUN_QUANTITY    0
+    #define PSU_QUANTITY            2
+    #define ONE_CONNECTOR_USE       0
 #else
     #define MAX_PSU_QUANTITY        62
     #define CHAdeMO_QUANTITY        2
@@ -188,6 +197,7 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #define ShmRelay2BdKey			1013
 #define ShmYesCustomKey         1014
 #define ShmOcppPHModuleKey      1015
+#define ShmSmartBoxKey          1016
 
 #define FaultCodeLength         5
 #define AlarmCodeLength         20
@@ -332,6 +342,7 @@ enum CoreProfile {
      isEnableLocalPowerSharing,
      PowerSharingServerIP,
      EVCCID_PREFIX,
+     OffLineMaxChargingPower,
      ConfigurationVersion,
 	 _CoreProfile_CNT
 };
@@ -370,7 +381,9 @@ struct WifiConfigData
 {
 	unsigned char		WifiMode;					//0: disable, 1: Infrastructure client, 2: Infrastructure server, 3: Ad-Hoc
 	unsigned char		WifiSsid[256];				//default: Null
-	unsigned char		WifiPassword[256];			//default: Null
+    unsigned char       WifiPassword[224];          //default: Null
+    unsigned char       WifiBroadcastSsid;          //the SSID broadcast configuration, 0: hidden   1: broadcast
+    unsigned char       WifiTargetBssidMac[31];     //Target connect SSID MAC address, default: Null
 	int					WifiRssi;					//dbm
 	unsigned char		WifiDhcpServer;				//0: enable, 1: disable
 	unsigned char		WifiDhcpClient;				//0: enable, 1: disable
@@ -385,7 +398,8 @@ struct TeleConfigData
 {
 	unsigned char		TelcomModelName[64];		//default: Null
 	unsigned char		TelcomSoftwareVer[64];		//default: Null
-	unsigned char		TelcomApn[256];				//default: Null
+    unsigned char       TelcomApn[255];             //default: Null
+    unsigned char       TelcomNetworkType;          //0: Auto   1: CDMA  2: WCDMA  3: LTE  4: TD-SCDMA  5: UMTS  6: CDMA  7: HDR  8: CDMA/HDR
 	int					TelcomRssi;					//dbm
 	unsigned char		TelcomChapPapId[256];		//default: Null
 	unsigned char		TelcomChapPapPwd[256];		//default: Null
@@ -484,7 +498,8 @@ typedef union
         unsigned int InvalidIdStop:1;               // 0: no effect,    1: invalid stop when StopTransactionOnInvalidId is true
         unsigned int RemoteStop:1;                  // 0: no effect,    1: remote stop
         unsigned int UnlockStop:1;                  // 0: no effect,    1: unlock stop
-        unsigned int res:23;
+        unsigned int SessionTargetStop:1;           // 0: no effect,    1: session target stop
+        unsigned int res:22;
     }bits;
 }ChargingStop;
 
@@ -591,6 +606,16 @@ struct SysConfigData
     unsigned char           MaintainServerSecurityProfile;      // Maintain server security profile 0~3
     unsigned char           MaintainServerSecurityPassword[41]; // Maintain server AuthorizationKey for security profile
     unsigned char           PowerSharingServerIP[512];          // Local power sharing server ip address
+    unsigned int            PowerSharingCapacityPower;          // Local power sharing capacity power
+    unsigned char           MaxChargingSoc;                     //0: unlimit, 1 ~ 100 percent
+};
+
+struct DERATING_BY_OTP
+{
+    unsigned char isNeedDerating;
+    unsigned char deratingIndex;        // Current used power or current
+    double deratingTargetRate[5];       // Reduce the output energy rate
+    double deratingTargetCurrent[5];    // derating target current
 };
 
 struct ChargingInfoData
@@ -626,6 +651,7 @@ struct ChargingInfoData
 	int EvBatterySoc;				// 0~100%
 	unsigned char ConnectorPlugIn;			//0: unplug, 1: Plug-in
 	unsigned char GunLocked;				//0: unlocked 1: locked
+	unsigned char InProgress;               //0: real idle, 1: session(transaction) in progress
 	float PilotVoltage;
 	unsigned char PilotState;//1:state A, 2:State B1, 3:State B2, 4:State C, 5:State D, 6:State E, 7:State F, 8: Pilot error
 	unsigned char PilotDuty;					// 0~100%
@@ -695,6 +721,9 @@ struct ChargingInfoData
     unsigned char       CCSGunType;
     struct timeval      PreChargeTimer;
     unsigned char       _SaftyDetect;
+    unsigned char       _TotalPsuCount;                 // Psu count for connector
+    unsigned char       _TakePsuGpCount;                // Get the used psu group count
+    struct DERATING_BY_OTP deratingByConnOtp;
 };
 
 typedef struct
@@ -878,6 +907,7 @@ struct ConnectorInfoData
     float                   CostDiscount;                   // connector user's Discount or couponPoint, unit: 1 point
     float                   EnergyCost;                     // connector user's energy cost, unit: 1 dollar
     float                   ParkingFee;                     // connector user's parking fee, unit: 1 dollar
+    float                   RemainAmount;                   // connector user's remain amount, unit: 1 dollar
 };
 
 typedef union
@@ -885,15 +915,11 @@ typedef union
     unsigned int SettingValue;
     struct
     {
-        unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
-        unsigned int FlashConfigChanged:1;      // 0: no effect, 1: flash config has changed
-        unsigned int EnableWriteFlash:1;        // 0: no effect, 1: enable to write flash after timeout
-        unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
-        unsigned int res:28;
+        unsigned int res:32;
     }bits;
 }CabinetSettingFlag;
 
-typedef struct DC_METER_INFO
+struct DC_METER_INFO
 {
     double presetVoltage;                       // resolution: 1.000v
     double presentCurrent;                      // resolution: 1.000a
@@ -901,7 +927,61 @@ typedef struct DC_METER_INFO
     double totlizeImportEnergy;                 // resolution: 1.000kwh
     double totlizeExportEnergy;                 // resolution: 1.000kwh
     unsigned char LinkStatus;                   // 0 = unknow ,1 = link , 2 miss link
-}DC_Meter_Info;
+};
+
+typedef struct Bazel8Command
+{
+    unsigned char isReq:1;
+    unsigned char isRes:1;
+    unsigned char isWaitRes:1;
+    unsigned char isResultPass:1;
+} bazel8Command;
+
+typedef struct EventInfo
+{
+    int messageId;
+    char messageString[64];
+    unsigned char isGetOn:1;
+}eventInfo;
+
+typedef struct StartTxResp
+{
+    char statusCode[8];
+    char statusText[128];
+    char txnId[32];
+    unsigned char isGetOn:1;
+}startTxResp;
+
+struct BAZEL8
+{
+    eventInfo       event;
+    startTxResp     txResp;
+
+    bazel8Command   cmdPreAuth;
+};
+
+struct Enegate
+{
+    union
+    {
+        unsigned char OperationValue[CONNECTOR_QUANTITY];
+        struct
+        {
+            unsigned char isAuthorizing:1;
+            unsigned char isAuthorized:1;
+            unsigned char isAuthorizedPass:1;
+            unsigned char isSessionStopReq:1;
+            unsigned char isStopService:1;
+            unsigned char isAutoStartEnable:1;
+            unsigned char isConnectTimeout:1;
+            unsigned char :1;
+        } bits[CONNECTOR_QUANTITY];
+    }Operation;
+
+    unsigned char   serviceStartTimestamp[36];
+    unsigned char   serviceStopTimestamp[36];
+    unsigned char   isEnable:1;
+};
 
 struct SysInfoData
 {
@@ -996,10 +1076,12 @@ struct SysInfoData
     unsigned char           AuthorizedStatus;           // cabinet authorized status
     CabinetSettingFlag      CabinetSetting;
     struct LocalSharingInfo localSharingInfo;           // Local power sharing info structure
-    DC_Meter_Info DcMeterInfo[4];
+    struct DC_METER_INFO    DcMeterInfo[4];
     unsigned char           OTPTemp;                    // OTP Temperature
     unsigned char           OTPTempR;                   // OTP Recovery Temperature
     struct LCD_OVERRIDE     LcdOveride;                 // LCD override info (no use anymore)
+    struct BAZEL8           bazel8;                     // Bazel8 payment used
+    struct Enegate          enegate;                    // Enegate payment used
 };
 
 struct SysConfigAndInfo
@@ -1253,18 +1335,18 @@ char AlarmStatusCode[160][6]=
 	"012261",	//GB groundfault detection timeout (GFD)
 	"012262",	//Circuit Short L1
 	"012263",	// PSU Duplicate ID
-	"012264", 	// PSU Output Short Circuit
+	"012264", 	// Psu Fault : Infy => Output Short Circuit,UU => Abnormal discharge circuit
 	"012265", 	// PSU Discharge Abnormal
 	"012266", 	// PSU Dc Side ShutDown
 	"012267", 	// PSU Failure Alarm
 	"012268", 	// PSU Protection Alarm
-	"012269", 	// PSU FanFailure Alarm
+	"012269", 	// Psu Fault : Infy => Fan Fault,UU => Fan Fault
 	"012270", 	// PSU Input UVP
 	"012271",	// PSU Input OVP
 	"012272", 	// PSU WalkIn State
-	"012273", 	// PSU Power Limited State
-	"012274", 	// PSU Id Repeat
-	"012275", 	// PSU Severe Uneven Current
+	"012273", 	// Psu Fault : Infy => Power Limited State,UU => Dc OVP and shutdown
+	"012274", 	// Psu Fault : Infy => Id Repeat,UU => Id Repeat
+	"012275", 	// Psu Fault : Infy => Severe Uneven Current,UU => Pfc internal unbalance
 	"012276", 	// PSU Three Phase Input Inadequate
 	"012277", 	// PSU Three Phase Onput Imbalance
 	"012278", 	// PSU Ffc Side ShutDown
@@ -1296,18 +1378,18 @@ char AlarmStatusCode[160][6]=
 	"012304",   // connection disconnected from power cabinet
 	"012305",   // Meter communication timeout
 	"012306",   // The dip switch of the PSU may be incorrect
-    "012307",   // Psu Fuse Burn-Out
-    "012308",   // Psu Pfc And Dcdc Communication Fault
-    "012309",   // Psu Bus Voltage Unbalance
-    "012310",   // Psu Bus Over Voltage
-    "012311",   // Psu Bus Voltage Abnormal
-    "012312",   // Psu Bus Under Voltage
-    "012313",   // Psu Input Phase Loss
-    "012314",   // Psu Fan Full Speed
-    "012315",   // Psu Temperature Power Limit
-    "012316",   // Psu Ac Power Limit
-    "012317",   // Psu Dcdc Eeprom Fault
-    "012318",   // Psu Pfc Eeprom Fault
+    "012307",   // Psu Fault : Infy => Fuse Burn-Out,UU => Pfc internal OVP
+    "012308",   // Psu Fault : Infy => Pfc And Dcdc Communication Fault,UU => Pfc And Dcdc Communication Fault
+    "012309",   // Psu Fault : Infy => Bus Voltage Unbalance,UU => Dc output voltage unbalance
+    "012310",   // Psu Fault : Infy => Bus Over Voltage,UU => Ac site OVP
+    "012311",   // Psu Fault : Infy => Bus Voltage Abnormal,UU => Ac site UVP
+    "012312",   // Psu Fault : Infy => Bus Under Voltage,UU => Pfc internal UVP
+    "012313",   // Psu Fault : Infy => Input Phase Loss,UU => Dc to Dc don’t work
+    "012314",   // Psu Fault : Infy => Fan Full Speed,UU => Fan don’t work
+    "012315",   // Psu Fault : Infy => Temperature Power Limit,UU => env OTP、Pfc OTP、output relay broken、Dc OTP
+    "012316",   // Psu Fault : Infy => Ac Power Limit,UU => Ac OVP and shutdown
+    "012317",   // Psu Fault : Infy => Dcdc Eeprom Fault,UU => Dc to Dc broken
+    "012318",   // Psu Fault : Infy => Pfc Eeprom Fault,UU => Pfc broken
     "012319",   // Psu Dcdc Over Voltage
     "012320",   // System CHAdeMO output UCP
     "012321",   // System CCS output UCP
@@ -1316,13 +1398,13 @@ char AlarmStatusCode[160][6]=
     "012324",   // Connector 1 detects abnormal voltage on the output line
     "012325",   // Connector 2 detects abnormal voltage on the output line
     "012326",   // System task is lost
-    "012327",   // DC input ovp
-    "012328",   // DC input uvp
-    "012329",   // Psu Can Communication Fault
-    "012330",   // Psu Dc to Dc OTP
-    "012331",   // Psu Dc to Dc OVP
-    "012332",   // reserved
-    "012333",   // reserved
+    "012327",   // System DC input ovp
+    "012328",   // System DC input uvp
+    "012329",   // Psu Fault : Infy => Psu Can Communication Fault,UU =>
+    "012330",   // Psu Fault : Infy => Psu Dc to Dc OTP,UU => env UTP
+    "012331",   // Psu Fault : Infy => Psu Dc to Dc OVP,UU => Dc output OVP
+    "012332",   // Chiller Tube OTP
+    "012333",   // Psu Fault : Infy => DC input ovp (Phase OVP),UU => Dc output UVP
     "012334",   // reserved
     "012335",   // reserved
     "012336",   // reserved
@@ -1336,12 +1418,12 @@ char AlarmStatusCode[160][6]=
     "012344",   // AC: Meter IC communication timeout
     "012345",   // AC: Pilot negative error
     "012346",   // Psu Communication error with CSU
-    "012347",   // reserved
+    "012347",   // AC: Local power sharing communication error (Slave disconnect from Master)
     "012348",   // reserved
     "012349",   // reserved
     "012350",   // reserved
     "012351",   // reserved
-    "012352",   // reserved
+    "012352",   // Payment system communication timeout
     "012353",   // reserved
     "012354",   // reserved
     "012355",   // reserved
@@ -1508,16 +1590,20 @@ struct AlarmCodeData
             unsigned char PsuCanCommFault:1;                        //bit 1
             unsigned char PsuDcDcOtp:1;                             //bit 2
             unsigned char PsuDcDcOvp:1;                             //bit 3
-            unsigned char :4;                                       //reserved bit 4 ~ bit 7
+            unsigned char ChillerTubeOTP : 1;                       //bit 4
+            unsigned char PsuPhaseOvp:1;                            //bit 5
+            unsigned char :2;                                       //reserved bit 6 ~ bit 7
             //AlarmVal[17]
             unsigned char :8;                                       //reserved bit 0 ~ bit 7
             //AlarmVal[18]
             unsigned char MeterIcCommTimeout:1;                     //bit 0
             unsigned char PilotNegativeError:1;                     //bit 1
             unsigned char PsuComminicationErrWithCSU:1;             //bit 2
-            unsigned char :5;                                       //reserved bit 3 ~ bit 7
+            unsigned char LocalPowerSharingCommunicationError:1;    //bit 3
+            unsigned char :4;                                       //reserved bit 4 ~ bit 7
             //AlarmVal[19]
-            unsigned char :8;                                       //reserved bit 0 ~ bit 7
+            unsigned char PaymentCommTimeout:1;                     //Payment system communication timeout
+            unsigned char :7;                                       //reserved bit 1 ~ bit 7
 		}bits;
 	}AlarmEvents;
 };
@@ -1843,7 +1929,7 @@ char InfoStatusCode[384][6]=
     "023981",   // ERROR_CODE_CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT
     "023982",   // ERROR_CODE_CHADEMO_ADC_LESS_THAN_10V
     "023983",   // STOP by EV with unknow reason
-    "023984",   // Reserved
+    "023984",   // STOP by EVSE condition (Config or OCPP)
     "023985",   // Reserved
     "023986",   // Reserved
     "023987",   // Reserved
@@ -2190,7 +2276,8 @@ struct InfoCodeData
             unsigned char CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT:1; //bit 1
             unsigned char CHADEMO_ADC_LESS_THAN_10V:1;              //bit 2
             unsigned char Stop_by_EV_with_unknow_reason:1;          //bit 3
-            unsigned char :4;                                       //bit 4 ~ 7 reserved
+            unsigned char Stop_by_EVSE_condition:1;                 //bit 4
+            unsigned char :3;                                       //bit 5 ~ 7 reserved
 			//InfoVal[40]
 			unsigned char BackendDisconnectedViaEthernet:1;			//bit 0
 			unsigned char BackendDisconnectViaWiFi:1;				//bit 1
@@ -2267,6 +2354,8 @@ struct PsuModuleData
 	unsigned int 		AlarmCode;
 	unsigned int 		FaultCode;			//
 	unsigned int 		IAvailableCurrent;		            // unit: 0.1A
+    unsigned short  PresentMaxOutputVoltage;//abcd=abc.d volt
+    unsigned short  KwAvailablePower;       // unit: 0.1 kw
 };
 
 /*Following are the information for each PSU Group*/
@@ -2288,6 +2377,11 @@ struct PsuGroupData
     unsigned short          TempIAvailableCurrent;          // unit: 0.1A
     unsigned short          StableIAvailableCurrent;        // unit: 0.1A
     unsigned short          StableCurrentCounter;           // stable current counter
+    unsigned short          GroupMaxVoltage;                // unit: 0.1V
+    unsigned char           IsUsing;                        // 0 : none use
+    unsigned char           UsingTarget;                    // 0xFF : Check
+    unsigned char           PwSwitchStatus;
+    unsigned short          TotalRatingPower;               // unit: 1kW
 };
 
 /*Following is the information for system all PSU*/
@@ -2303,6 +2397,54 @@ struct PsuData
 	unsigned char           PsuStopChargeFlag;
 };
 
+struct SmartTimeChk
+{
+    struct timespec     FetchLoopTime;
+    unsigned char       IsFetchStart;
+
+    struct timespec     ReleaseLoopTime;
+    unsigned char       IsReleaseStart;
+};
+
+struct DynamicFetchCtrl
+{
+    unsigned char       ShareGroup;         // 255 : None
+    unsigned char       FetchLoopStep;      // 0 : None, 1 : Output Vol, 2 : RCB ON, 3 : Current sharing, 4 : Finish
+    unsigned short      ShareTargetCurrent; // 0.1A
+    unsigned char       TargetRelay;        // 255 : None
+};
+
+struct DynamicReleaseCtrl
+{
+    unsigned char       ReleaseGroup;       // 255 : None
+    unsigned char       ReleaseLoopStep;    // 0 : None, 1 : Limit Pwr, 2 : Pwr OFF, 3. RCB OFF, 4. Finish
+    float               CheckOutPwrIsStable;// 0.1kw
+    unsigned char       TargetRelay;        // 255 : None
+
+    float               LimitCurCap;        // Inform 0.1A
+    float               LimitPwrCap;        // Inform 0.1kw
+    float               LimitCur;           // Target 0.1A
+    float               LimitPwr;           // Target 0.1kw
+};
+
+struct ConnInfo
+{
+    unsigned char ConnectorStaus;
+    unsigned char NeedToFetch;
+};
+
+struct SmartBoxData
+{
+    struct ConnInfo     ConnectorStatus[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];     // Connector 1 / 2 Status : None, Wait, Using
+    struct ConnInfo     AnotherConnectorStatus[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    unsigned char       ConnectorUsingGroupCount[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; // Psu group for connector
+    struct SmartTimeChk SmartChk[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct DynamicFetchCtrl Dynamic4Fetch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct DynamicReleaseCtrl Dynamic4Release[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    unsigned char       ParallelRelayStatus[3];
+    unsigned char       RcbParallelStatus[3];
+};
+
 /************************************************************************************/
 /**************************CHAdeMO protocol Share memory*********************/
 /**************************************************************************************/
@@ -4449,6 +4591,7 @@ struct Triggers
                                                     // be used to trigger a meter value when vehicle stops charging or when vehicle charges at a high power that requires a
                                                     // different tariff.
                                                     // It is recommended to implement a hysteresis around this value to avoid repetitive triggers when the power fluctuates around this level.
+    unsigned char atCPStatus[100];
 };
 
 struct StrcutRunningCost
@@ -4469,6 +4612,10 @@ struct StrcutFinalCost
 {
     int             txId;
     unsigned char   description[1024];
+
+    float           cost;
+    unsigned char   priceText[1024];
+    unsigned char   qrCodeText[1024];
 };
 
 struct StructCost
@@ -4874,6 +5021,7 @@ enum OCPP20CtrlrVariable
 	ChargingStation_SystemUptimeSec,
 	ChargingStation_FreeVend,
 	ChargingStation_FreeVendIdtag,
+	ChargingStation_OffLineMaxChargingPower,
 	Connector_Available,
 	Connector_ConnectorType,
 	Connector_SupplyPhases,
@@ -6008,7 +6156,8 @@ struct OCPP20Data
 			unsigned char SecurityEventNotificationConf :1;
 			unsigned char SignCertificateReq :1;
 			unsigned char SignCertificateConf :1;
-			unsigned char :2;
+            unsigned char NotifyCustomerInformationReq :1;  //bit 6
+            unsigned char NotifyCustomerInformationConf :1; //bit 7
 
 		} bits;
 	} SpMsg;
@@ -6210,7 +6359,7 @@ struct OCPP20Data
 	struct UpdateFirmware_20					UpdateFirmware;
 	struct ChargingProfileType                  SmartChargingProfile[CONNECTOR_QUANTITY];
 	struct ChargingProfileType                  MaxChargingProfile;
-	struct StructSessionTarget	                SessionTarget[CONNECTOR_QUANTITY];
+	struct StructSessionTarget                  SessionTarget[CONNECTOR_QUANTITY];
 };
 
 

+ 4 - 4
EVSE/Projects/DD360/Apps/Log/log.h

@@ -2,11 +2,11 @@
 #define _LOG_H_
 
 //------------------------------------------------------------------------------
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
 
-#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args) //DS60-120 add
 //------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...);
 int StoreEventLogMsg(const char *fmt, ...);

+ 25 - 20
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -354,18 +354,22 @@ static void ClearAuthorizedFlag(void)
     pSysInfo->AuthorizeFlag = NO;
 }
 
-static void ClearDetectPluginFlag(void)
+static void ClearDetectPluginFlag(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = NO;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
 }
 
-static bool isDetectPlugin(void)
+static bool isDetectPlugin(int gunIndex)
 {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
+        return true;
+    }
+    /*
     if (pSysInfo->WaitForPlugit == YES) {
-        return YES;
+        return true;
     }
-
-    return NO;
+    */
+    return false;
 }
 
 static void destroySelectGun(uint8_t curGun)
@@ -526,7 +530,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     string2Date((char*)data, (uint8_t*)_setTime);
     //printf("SystemId =  %s", pSysConfig->SystemId);
     if (!timecmp(localTime, _setTime)) {
-        log_info("Set Timer:%s", _setTime);
+        //log_info("Set Timer:%s", _setTime);
         sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
         system((char*)cmdBuf);
         system("hwclock -w -u");
@@ -810,7 +814,8 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             strcpy((char *)pSysConfig->UserId, "");
-            pSysInfo->WaitForPlugit = NO;
+            //pSysInfo->WaitForPlugit = NO;
+            ClearDetectPluginFlag(plugNum);
 #ifdef DD360Audi
             pSysInfo->SystemPage = _LCM_SELECT_GUN;
 #endif
@@ -829,10 +834,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            if (isDetectPlugin() == YES) {
-                ClearDetectPluginFlag();
+            if (isDetectPlugin(plugNum) == YES) {
+                ClearDetectPluginFlag(plugNum);
                 strcpy((char *)pSysConfig->UserId, "");
-                pSysInfo->WaitForPlugit = NO;
 #ifdef DD360Audi
                 pSysInfo->SystemPage = _LCM_SELECT_GUN;
 #endif
@@ -1534,12 +1538,12 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun2_Consumption, (char*)&pValue->Gun2_Consumption, sizeof(uint32_t));
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun3_Consumption, (char*)&pValue->Gun3_Consumption, sizeof(uint32_t));
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun4_Consumption, (char*)&pValue->Gun4_Consumption, sizeof(uint32_t));
-
+        /*
         log_info("Gun1_Consumption:%f", ShmDcCommonData->pConsumption.Gun1_Consumption);
         log_info("Gun2_Consumption:%f", ShmDcCommonData->pConsumption.Gun2_Consumption);
         log_info("Gun3_Consumption:%f", ShmDcCommonData->pConsumption.Gun3_Consumption);
         log_info("Gun4_Consumption:%f", ShmDcCommonData->pConsumption.Gun4_Consumption);
-        
+        */
         
         break;
         
@@ -1751,13 +1755,13 @@ static int readChargingTimeStamp(int fd, uint8_t id)
 
     return ret;
 }
-static int writeWaitPlugItState(int fd, uint8_t id)
+static int writeWaitPlugItState(int fd, uint8_t id, uint8_t gunIndex)
 {
     int ret = PASS;
-    uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-    if (_isplugin != pSysInfo->WaitForPlugit) {
-        log_info("Wait for plug:%s", pSysInfo->WaitForPlugit == 0 ? "disable" : "enable");
-        _isplugin = pSysInfo->WaitForPlugit;
+    uint8_t data[2] = { ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit, 0 };
+    if (_isplugin != ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit) {
+        //log_info("Wait Gun%d for plug:%s", gunIndex, ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin = ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit;
     }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
@@ -1927,7 +1931,7 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[15] = {'\0'};
+    uint8_t dataBuf[16] = {'\0'};
     uint32_t _consumption;
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
@@ -1937,6 +1941,7 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     pConnState->ConnectorTemp = pDcChargingInfo->ConnectorTemp;
     pConnState->ChillerTemp = pDcChargingInfo->ChillerTemp;
     pConnState->PlugIn = pDcChargingInfo->ConnectorPlugIn;
+    pConnState->ConnectMode = pDcChargingInfo->SystemStatus;
 
     if (pDcChargingInfo->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
@@ -2725,7 +2730,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
            ) {
-            writeWaitPlugItState(fd, gunID);
+            writeWaitPlugItState(fd, gunID, plugNum);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
         /*

+ 1 - 1
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h

@@ -222,7 +222,7 @@ typedef struct StConnectorState {
     uint8_t ChillerTemp;
     uint8_t PlugIn;
     uint32_t consumption;
-    uint8_t Reserved[1];
+    uint8_t ConnectMode;
 } ConnectorState;
 
 typedef struct StConnectorIDTable {

+ 5 - 2
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCCS.c

@@ -17,6 +17,8 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
     struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    memset(code, '\n', sizeof(code));
+
 
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
         return;
@@ -751,8 +753,8 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
 
     if (isCleanCheck) {
         for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
             if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
                 log_info("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
                          index,
@@ -760,6 +762,7 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
                          code);
 
                 if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+
                     if (strncmp(code, "012219", 6) == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO; }
 
                     if (strncmp(code, "023701", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = NO; }
@@ -910,7 +913,7 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 1 - 1
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCHA.c

@@ -244,7 +244,7 @@ void ClearAbnormalStatus_Chademo(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 1 - 1
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalGBT.c

@@ -412,7 +412,7 @@ void ClearAbnormalStatus_GB(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 47 - 29
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -34,7 +34,8 @@ uint8_t TempArray_2[TempArraySize]={0};
 uint8_t ptemp_1 = 0;
 uint8_t ptemp_2 = 0;
 bool firstcircule = true;
-
+float EvTargetVolt[2] = { 0 };
+float EvTargetCur[2] = { 0 };
 //------------------------------------------------------------------------------
 extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
 
@@ -165,6 +166,7 @@ static void getChillerTemperature(ChillerTemp *chillerTemp)
     for (i = 0; i < 4; i++) {
         adcVoltage = 0.0;
         adcVoltage =  ReadAdcVolt(i);
+        ShmDcCommonData->TempVolt[i] = adcVoltage;
         if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
             pChillerTemp->Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
             //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
@@ -308,6 +310,7 @@ void CANReceiver(int fd)
         int len = 0;
         char _info[1024];
         int i;
+        unsigned char GunStatus[2];
 
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -333,19 +336,24 @@ void CANReceiver(int fd)
             for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
                 pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
                 // 檢查是否有收到EV小板訊號
-                if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 3) &&
-                    !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
-                    pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
-
-                    ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
-                    ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
-
-                    system("/sbin/ip link set can0 down");
-                    sleep(1);
-                    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-                    system("/sbin/ip link set can0 up");
+                if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+                    if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 5) &&
+                        !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
+                        pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
+
+                        ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
+                        ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
+
+                        system("/sbin/ip link set can0 down");
+                        sleep(1);
+                        system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+                        system("/sbin/ip link set can0 up");
+                    }
+                    CheckEvConnect(_index);
+                } else {
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
                 }
-                CheckEvConnect(_index);
             }
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -438,22 +446,15 @@ void CANReceiver(int fd)
                         pSysInfo->CurGunSelected = targetGun;
                     }
                 }
-                // CCS 小板確認拔除三秒
-                if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (frame.data[0] == UNPLUG) {
-                        if ((time((time_t*)NULL) - CCS_PlugoutTimer[targetGun]) > 3) {
-                            if (pDcChargingInfo->ConnectorPlugIn != frame.data[0])
-                                log_info("CCS Conn %d, Unplug. ", targetGun);
-                        } else {
-                            frame.data[0] = PLUG;
-                        }
-                    } else {
-                        CCS_PlugoutTimer[targetGun] = time((time_t*)NULL);
-                        frame.data[0] = PLUG;
-                    }
-                }
-                pDcChargingInfo->ConnectorPlugIn = frame.data[0];
                 pDcChargingInfo->PilotVoltage = frame.data[1];
+                // CCS 小板確認Pilot Voltage != 0
+                if (pDcChargingInfo->Type == _Type_CCS_2 && pDcChargingInfo->PilotVoltage != 0) {
+                    if (frame.data[0] == UNPLUG && pDcChargingInfo->ConnectorPlugIn != frame.data[0])
+                        log_info("Conn %d, Unplug. ", targetGun);
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                } else {
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                }
 
                 //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x ",
                 //         targetGun,
@@ -516,6 +517,7 @@ void CANReceiver(int fd)
 
             case ACK_GET_OUTPUT_REQ:
                 //DS60-120 add
+
                 if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
                         pDcChargingInfo->SystemStatus <= S_CHARGING) ||
                         (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
@@ -526,6 +528,14 @@ void CANReceiver(int fd)
                         pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
                     }
 
+                    // 進入充電時重新更新電池電量
+                    if (GunStatus[targetGun] != pDcChargingInfo->SystemStatus && pDcChargingInfo->SystemStatus == S_CHARGING) {
+
+                        log_info("Reset Gun%d SoC:%d", targetGun, frame.data[1]);
+                        pDcChargingInfo->EvBatterySoc = frame.data[1];
+                        GunStatus[targetGun] = pDcChargingInfo->SystemStatus;
+                    }
+
                     if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
                         pDcChargingInfo->EvBatterySoc = frame.data[1];
                         log_info("Gun%d SOC:%d", targetGun,pDcChargingInfo->EvBatterySoc);
@@ -576,7 +586,15 @@ void CANReceiver(int fd)
                         ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
                 }
-
+                if (pDcChargingInfo->EvBatterytargetVoltage > (EvTargetVolt[targetGun] + 5) ||
+                    pDcChargingInfo->EvBatterytargetVoltage < (EvTargetVolt[targetGun] - 5) ||
+                    pDcChargingInfo->EvBatterytargetCurrent >(EvTargetCur[targetGun] + 2) ||
+                    pDcChargingInfo->EvBatterytargetCurrent < (EvTargetCur[targetGun] - 2)) {
+                    log_info("Gun%d TargetVoltage = %f , TargetCurrent = %f",
+                        targetGun, pDcChargingInfo->EvBatterytargetVoltage, pDcChargingInfo->EvBatterytargetCurrent);
+                    EvTargetVolt[targetGun] = pDcChargingInfo->EvBatterytargetVoltage;
+                    EvTargetCur[targetGun] = pDcChargingInfo->EvBatterytargetCurrent;
+                }
                 //log_info("EvBatterytargetVoltage = %f ", pDcChargingInfo->EvBatterytargetVoltage);
                 //log_info("EvBatterytargetCurrent = %f ", pDcChargingInfo->EvBatterytargetCurrent);
                 //log_info("BatteryVoltage = %d ",

+ 43 - 9
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -55,7 +55,7 @@ static float LogInfo[2][10]; //DS60-120 add
 static int CanFd = -1;
 
 bool psuOutputReady[2] = {0, 0};
-
+uint8_t deratingIndex[2];
 //------------------------------------------------------------------------------
 extern void CANReceiver(int fd);
 extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
@@ -301,7 +301,29 @@ static void setCurrentOutput(void)
         }
     }
 }
+void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
+{
+    if (chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
+        chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP &&
+        chargingData->deratingByConnOtp.deratingIndex < 1)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 1;
+    } else if (chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP &&
+        chargingData->ConnectorTemp != UNDEFINED_TEMP &&
+        chargingData->deratingByConnOtp.deratingIndex < 2)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 2;
+    }
 
+    if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
+    } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        if (*cur > chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex])
+            *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex];
+    }
+}
 static void SetPresentChargingOutputCap(void)
 {
     float pow1 = 0, cur1 = 0;
@@ -346,6 +368,13 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_1->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_1, &pow1, &cur1);
+        if (deratingIndex[0] != chargingData_1->deratingByConnOtp.deratingIndex) {
+            log_info("Gun0 Derating Index Set %d", chargingData_1->deratingByConnOtp.deratingIndex);
+            deratingIndex[0] = chargingData_1->deratingByConnOtp.deratingIndex;
+        }
+    }
     pow2 = chargingData_2->AvailableChargingPower;
     cur2 = chargingData_2->AvailableChargingCurrent;
 
@@ -371,6 +400,14 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_2->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_2, &pow2, &cur2);
+        if (deratingIndex[1] != chargingData_2->deratingByConnOtp.deratingIndex) {
+            log_info("Gun1 Derating Index Set %d", chargingData_2->deratingByConnOtp.deratingIndex);
+            deratingIndex[1] = chargingData_2->deratingByConnOtp.deratingIndex;
+        }
+    }
+
     //DS60-120 add
     if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 ||
             LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
@@ -546,13 +583,11 @@ static void SetPresentChargingOutputPower(void)
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) ||
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
        ) {
-        log_info("G1->Out Vol(%s)=%.1f,Out Cur=%.1f - G2->Out Vol(%s) = %.1f, Out Cur = %.1f",
-                 isPsuVol1 == true ? "P" : "R",
-                 vol1 / 10,
-                 cur1 / 10,
-                 isPsuVol2 == true ? "P" : "R",
-                 vol2 / 10,
-                 cur2 / 10);
+        log_info("G1-> Vol=%.1f, Cur=%.1f - G2-> Vol = %.1f, Cur = %.1f",
+            vol1 / 10,
+            cur1 / 10,
+            vol2 / 10,
+            cur2 / 10);
 
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
         LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
@@ -815,7 +850,6 @@ int main(int argc, char *argv[])
                     }
                 } else if (pDcChargingInfo->Type == _Type_CCS_2) {
                     ClearAbnormalStatus_CCS(gunIndex);
-
                     if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO) {
                         pDcChargingInfo->StopChargeFlag = NO;
                     }

+ 1 - 1
EVSE/Projects/DD360/Apps/ModuleEventLog/Module_EventLogging.c

@@ -52,7 +52,7 @@ static struct FaultCodeData *pFaultCode      = NULL;
 //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args) //DS60-120 add
 
 /*
 int StoreLogMsg(const char *fmt, ...)

+ 3 - 3
EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.h

@@ -85,9 +85,9 @@
 #define AC_ROTARY_SWITCH_FAULT                  (131072)
 #define AC_RELAY_DRIVE_FAULT                    (262144)
 
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 

+ 24 - 10
EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c

@@ -1245,9 +1245,31 @@ static void GetFanSpeed(void)
 static void GetFanSpeedByFunction(void)
 {
     if (ShmDcCommonData->debugflag== YES) {
+        ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
         return;
     }
 
+    int gunIndex;
+    struct ChargingInfoData* pDcChargingInfo = NULL;
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
+        if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+            ShmDcCommonData->FanOnTime = time((time_t*)NULL);
+            if (ShmFanModuleData->SetFan1Speed == 0) {
+                ShmFanModuleData->SetFan1Speed = 7000;
+                log_info("Set Fan speed 7000");
+            }
+        }
+    }
+
+    if ((time((time_t*)NULL) - ShmDcCommonData->FanOnTime) >= 600 &&
+        ShmFanModuleData->SetFan1Speed == 7000) {
+        ShmFanModuleData->SetFan1Speed = 0;
+        log_info("Close fan");
+    }
+
+    /*
     // 風控修改 :
     // ******************************************************* //
     //
@@ -1305,6 +1327,7 @@ static void GetFanSpeedByFunction(void)
     if (ShmFanModuleData->TestFanSpeed < 0) {
         ShmFanModuleData->TestFanSpeed = 0;
     }
+    */
 //
 //  printf("power = %f \n", power);
 //  printf("_maxPower = %d \n", _maxPower);
@@ -1406,7 +1429,7 @@ static void fanBoardPorcess(void)
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
             //GetPsuTempForFanSpeed();
-            //GetFanSpeedByFunction();
+            GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
@@ -1688,15 +1711,6 @@ static void LEDBoardProcess(void)
     }
 
     if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-
-        //if (pSysConfig->TotalConnectorCount == 1) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
-        //} else if (pSysConfig->TotalConnectorCount == 2) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
-        //}
         if (time((time_t*)NULL) - ReservationFlashTimer >= 3) {
             ReservationFlashTimer = time((time_t*)NULL);
             if (ReservationLed)

+ 8 - 40
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -372,68 +372,36 @@ static void checkChillerStatus(Gpio_out *gpio)
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
         if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
-            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
-        {
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
             pChillerInfo->ChillerSwitch = YES;
             pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        }
-        else
-        {
-            if(pChillerInfo->ChillerSwitch == YES)
-            {
+        } else {
+            if(pChillerInfo->ChillerSwitch == YES) {
                 //10分鐘後停止
-                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600)
-                {
+                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
                     pChillerInfo->ChillerSwitch = NO;
-                    ShmFanModuleData->SetFan1Speed = 0;
-                }
-            }
-            else
-            {
-                pChillerInfo->ChillerSwitch = NO;
-            }
-        }
-#if 0
-        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
-            pChillerInfo->ChillerSwitch = YES;
-            pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        } else {
-            if (pChillerInfo->ChillerSwitch == YES) {
-                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) { //判斷如果還是大於100A不變動
-                    pChillerInfo->ChillerSwitch = YES;
-                    pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-                } else {
-                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) { //5分鐘後停止
-                        pChillerInfo->ChillerSwitch = NO;
-                    } else {
-                        pChillerInfo->ChillerSwitch = YES;
-                    }
                 }
             } else {
                 pChillerInfo->ChillerSwitch = NO;
             }
         }
-#endif
     }
 
     uint8_t _chillerNeedOn = NO;
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
-        if(pChillerInfo->ChillerSwitch == YES)
-        {
+        if(pChillerInfo->ChillerSwitch == YES) {
             _chillerNeedOn = YES;
-            if (chillerCount >= 2) {
-                ShmFanModuleData->SetFan1Speed = 7000;
-            }
         }
     }
 
+    /*
     if (ShmDcCommonData->debugflag == YES)
         _chillerNeedOn = ShmDcCommonData->chillerCtrl;
+    */
 
-    if(_chiller.ChillerSwitch != _chillerNeedOn)
-    {
+    if(_chiller.ChillerSwitch != _chillerNeedOn) {
         log_info("Chiller Need Turn %s", _chillerNeedOn == YES ? "ON" : "OFF");
     }
     _chiller.ChillerSwitch = _chillerNeedOn;

+ 1 - 0
EVSE/Projects/DD360/Apps/ModulePsuComm/Module_PsuComm.c

@@ -180,6 +180,7 @@ unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
 
 void AbnormalStopAnalysis(byte gun_index, int errCode)
 {
+	DEBUG_INFO("Gun%d Erro Code:%s", gun_index, errCode);
 	for (char i = 0; i < 3; i++)
 	{
 		unsigned char byteIndex = (errCode >> (8 * i)) & 0xff;

+ 18 - 1
EVSE/Projects/DD360/Apps/ModuleUpdateFW/Module_UpdateFW.c

@@ -185,6 +185,13 @@ static int InitCanBus(void)
     return fd;
 }
 
+unsigned long long getAvailableMemory()
+{
+    long pages = sysconf(_SC_AVPHYS_PAGES);
+    long page_size = sysconf(_SC_PAGE_SIZE);
+    return pages * page_size;
+}
+
 static int CheckUpdateProcess(void)
 {
     //bool isPass = true;
@@ -205,6 +212,13 @@ static int CheckUpdateProcess(void)
     DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     struct ChargingInfoData *pDcChargingInfo = NULL;
 
+
+    if (getAvailableMemory() < (200 * 1024 * 1024))
+    {
+        log_info("Available memory (%.2f Bytes) less than 200 MBytes, free cache first.\n", getAvailableMemory() / (1024 * 1024.0));
+        system("echo 3 > /proc/sys/vm/drop_caches");
+    }
+
     pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     d = opendir("/mnt/");
     if (d) {
@@ -243,6 +257,8 @@ static int CheckUpdateProcess(void)
                         ((unsigned int)ptr[19]));
                 log_info("Typed...%x ", Type);
 
+                free(ptr);
+
                 switch (Type) {
                 case 0x10000001:
                 case 0x10000002:
@@ -396,9 +412,10 @@ static int CheckUpdateProcess(void)
                     //return isPass;
                     break;
                 }
+            } else {
+                free(ptr);
             }
             free(new_str);
-            free(ptr);
         }
     }
     free(dir);

二進制
EVSE/Projects/DD360/Apps/Module_ChkSysTask


二進制
EVSE/Projects/DD360/Apps/Module_DoComm


二進制
EVSE/Projects/DD360/Apps/Module_EvComm


二進制
EVSE/Projects/DD360/Apps/Module_EventLogging


二進制
EVSE/Projects/DD360/Apps/Module_InternalComm


二進制
EVSE/Projects/DD360/Apps/Module_UpdateFW


+ 10 - 4
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -342,6 +342,7 @@ void GetFwVerProc(void)
 
     printf("ModelName = %s\r\n", pSysConfig->ModelName);
     printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
+    printf("DC Main Debug Version = %s \n", ShmDcCommonData->DebugVersion);
     printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
     printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
     printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
@@ -781,7 +782,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARNIN]\n");
-
+                ShmFanModuleData->TestFanSpeed = 7000;
                 //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
                 printf ("wait find module\n");
 
@@ -939,7 +940,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 //無阻塞偵測 keybaord 結束
                 system(STTY_DEF TTY_PATH);
             }
-
+            pDcChargingInfo->ConnectorPlugIn = 0;
             pDcChargingInfo->SystemStatus = S_COMPLETE;
             break;
 
@@ -971,6 +972,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
             if (stopChg == pSysConfig->TotalConnectorCount) {
                 ShmDcCommonData->debugflag = NO;
+                ShmFanModuleData->TestFanSpeed = 0;
                 system("/root/Module_EvComm &");
                 sleep(3);
 
@@ -1127,16 +1129,20 @@ static void resdGunAndChillerTemp(void)
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
-                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
+                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d(%.3f), %3d(%.3f), %3d(%.3f), %3d(%.3f)\r\n",
                              i,
                              pDcChargingInfo->ConnectorTemp,
                              pDcChargingInfo->ChillerTemp,
                              ShmDcCommonData->ConnectorTemp[i][0],
                              ShmDcCommonData->ConnectorTemp[i][1],
                              ShmDcCommonData->SystemTemp[0],
+                             ShmDcCommonData->TempVolt[0],
                              ShmDcCommonData->SystemTemp[1],
+                             ShmDcCommonData->TempVolt[1],
                              ShmDcCommonData->SystemTemp[2],
-                             ShmDcCommonData->SystemTemp[3]);
+                             ShmDcCommonData->TempVolt[2],
+                             ShmDcCommonData->SystemTemp[3],
+                             ShmDcCommonData->TempVolt[3]);
             }//for
             ftime(&showTime);
         }

二進制
EVSE/Projects/DD360/Apps/UnsafetyOutputTask


二進制
EVSE/Projects/DD360/Apps/main


二進制
EVSE/Projects/DD360/Images/ramdisk.gz


二進制
EVSE/Projects/DD360/output/FactoryConfig


二進制
EVSE/Projects/DD360/output/Module_ChkSysTask


二進制
EVSE/Projects/DD360/output/Module_DoComm


二進制
EVSE/Projects/DD360/output/Module_EvComm


二進制
EVSE/Projects/DD360/output/Module_EventLogging


二進制
EVSE/Projects/DD360/output/Module_InternalComm


二進制
EVSE/Projects/DD360/output/Module_LcmControl


二進制
EVSE/Projects/DD360/output/Module_PrimaryComm


二進制
EVSE/Projects/DD360/output/Module_UpdateFW


二進制
EVSE/Projects/DD360/output/ReadCmdline


二進制
EVSE/Projects/DD360/output/UnsafetyOutputTask


二進制
EVSE/Projects/DD360/output/main


+ 3 - 1
EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c

@@ -98,7 +98,7 @@ static int isReachableInternet(void)
         while (fgets(buf, sizeof(buf), fp) != NULL) {
             if (strstr(buf, "inet addr:") > 0) {
                 sscanf(buf, "%*s%s", tmp);
-                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
+                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(tmp) - strspn(tmp, "addr:"));
 
                 if (strcmp(tmp, (char *)pSysConfig->Eth0Interface.EthIpAddress) != EQUAL) {
                     strcpy((char *) pSysConfig->Eth0Interface.EthIpAddress, tmp);
@@ -186,6 +186,8 @@ void InitEthernet(void)
     log_info("%s",tmpbuf);
     system(tmpbuf);
 
+    system("/sbin/ifconfig lo up");
+
     //Run DHCP client if enabled
     system("killall udhcpc");
     system("rm -rf /etc/resolv.conf");

+ 3 - 3
EVSE/Projects/DD360Audi/Apps/CSU/OCPP.c

@@ -422,7 +422,7 @@ void ocpp_chk_remoteStart_cmd()
                     ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                     //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
                     //ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
+                    DetectPluginStart(ac_index);
                     return;
                 }
                 ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
@@ -473,7 +473,7 @@ void ocpp_chk_remoteStart_cmd()
                 chargingInfo[dcIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                 //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
-                DetectPluginStart();
+                DetectPluginStart(dcIndex);
             }
             ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
         } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
@@ -481,7 +481,7 @@ void ocpp_chk_remoteStart_cmd()
                     chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
                 chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                DetectPluginStart();
+                DetectPluginStart(scheduleIndex);
             }
             chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
         }

+ 6 - 7
EVSE/Projects/DD360Audi/Apps/CSU/Primary.c

@@ -218,9 +218,8 @@ static void checkChargingInfoByDC(uint8_t systemStatus)
     switch (systemStatus) {
     case S_IDLE:
     case S_RESERVATION:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
+        if (isDetectPlugin(pSysInfo->CurGunSelected)) {
+            _DetectPlugInTimeout(pSysInfo->CurGunSelected);
             destroySelGun(pSysInfo->CurGunSelected);
             
         } else {
@@ -261,7 +260,8 @@ static void checkChargingInfoByDC(uint8_t systemStatus)
 
     case S_CHARGING:
         if (pSysConfig->StopChargingByButton == YES ||
-                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE ||
+                pSysConfig->isAuthrizeByEVCCID) {
             // 停止充電
             ChargingTerminalProcess(pSysInfo->CurGunSelected);
         }
@@ -286,9 +286,8 @@ static void checkChargingInfoByAC(void)
 
     switch (pAcChargingInfo->SystemStatus) {
     case S_IDLE:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
+        if (isDetectPlugin(pSysInfo->CurGunSelected)) {
+            _DetectPlugInTimeout(pSysInfo->CurGunSelected);
         }
         break;
 

+ 2 - 2
EVSE/Projects/DD360Audi/Apps/CSU/RFID.c

@@ -269,7 +269,7 @@ void ScannerCardProcess(void)
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
     ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
 
-    if (!isDetectPlugin() &&
+    if (!isDetectPlugin(pSysInfo->CurGunSelected) &&
             !isCardScan &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
@@ -325,7 +325,7 @@ void ScannerCardProcess(void)
     } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
         StartSystemTimeoutDet(Timeout_VerifyComp);
     } else if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
-        StartSystemTimeoutDet(Timeout_WaitPlug);
+        //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected, Timeout_WaitPlug);
     } else {
         isCardScan = false;
     }

+ 279 - 160
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -77,6 +77,8 @@ static ChillerTempErr gChillerTempErr = {0};
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 
+#define DERATING_TARGET_LEVEL 5
+
 // for initial index to check EV board type is correct
 uint8_t bd0_1_status = 0;
 uint8_t bd0_2_status = 0;
@@ -84,12 +86,12 @@ uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
 char *fwVersion = "V1.21.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "v1.21.5";
+char* DebugVersion = "V1.21.9";
 //sqlite3 *localDb;
 bool isDb_ready;
 
 //------------------------------------------------------------------------------
-void ClearDetectPluginFlag();
+void ClearDetectPluginFlag(int gunIndex);
 
 long long DiffTimebWithNow(struct timeb ST);
 uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
@@ -323,7 +325,7 @@ static void GetFirmwareVersion(void)
 {
     // Get CSU root file system version
     sprintf((char *)pSysInfo->CsuRootFsFwRev, fwVersion);
-
+    sprintf((char *)ShmDcCommonData->DebugVersion, DebugVersion);
     uint8_t count = 0, chademo = 0, ccs = 0, gb = 0;
     for (uint8_t idx = 0; idx < 3; idx++) {
         if (pSysConfig->ModelName[7 + idx] == 'J') {
@@ -1273,11 +1275,12 @@ int Initialization(void)
     // 初始化卡號驗證的 Flag
     ClearAuthorizedFlag();
 
-    // 初始化插槍驗證的 Flag
-    ClearDetectPluginFlag();
+
 
     for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
+        // 初始化插槍驗證的 Flag
+        ClearDetectPluginFlag(count);
 
         pDcChargingInfo->RemoteStartFlag = NO;
 
@@ -1483,36 +1486,41 @@ bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
 //===============================================
 // 掃描插槍狀況
 //===============================================
-void ClearDetectPluginFlag(void)
+void ClearDetectPluginFlag(int gunIndex)
 {
-    uint8_t gunIndex = 0;
-    pSysInfo->WaitForPlugit = NO;
 
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
     //DS60-120 add
-    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-        if (pDcChargingInfo->RemoteStartFlag == YES) {
-            pDcChargingInfo->RemoteStartFlag = NO;
-        }
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+    if (pDcChargingInfo->RemoteStartFlag == YES) {
+        pDcChargingInfo->RemoteStartFlag = NO;
     }
 
+
     if (pSysInfo->OrderCharging != NO_DEFINE) {
         pSysInfo->OrderCharging = NO_DEFINE;
     }
 }
 
-void DetectPluginStart()
+void DetectPluginStart(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = YES;
+    //pSysInfo->WaitForPlugit = YES;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
+    log_info("Gun%d start detect plug in",gunIndex);
 }
 
-bool isDetectPlugin()
+bool isDetectPlugin(int gunIndex)
 {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
+        return true;
+    }
+    /*
     if (pSysInfo->WaitForPlugit == YES) {
         return true;
     }
-
+    */
     return false;
 }
 
@@ -1544,7 +1552,7 @@ bool isEvStopCharging_chademo(uint8_t gunIndex)
 {
     if (isEvGunLocked_chademo(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none (%d) ", gunIndex);
+        //log_info("gun locked none (%d) ", gunIndex);
         return YES;
     }
 
@@ -1575,7 +1583,7 @@ bool isEvStopCharging_gb(uint8_t gunIndex)
 {
     if (isEvGunLocked_gb(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none. ");
+        //log_info("gun locked none. ");
         return YES;
     }
 
@@ -1614,7 +1622,7 @@ bool isEvStopCharging_ccs(uint8_t gunIndex)
 {
     if (isEvGunLocked_ccs(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none. ");
+        //log_info("gun locked none. ");
         return YES;
     }
 
@@ -1656,13 +1664,29 @@ void DisplayChargingInfo()
     systemPageRestoreInit();
 }
 
-void _AutoReturnTimeout(void)
+void _AutoReturnTimeout(int gunIndex)
 {
     log_info("*********** _AutoReturnTimeout(%d) *********** ", pSysInfo->PageIndex);
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
-        ClearDetectPluginFlag();
+        
+        if (pDcChargingInfo->RemoteStartFlag) {
+            ClearDetectPluginFlag(gunIndex);
+        } else {
+            ClearDetectPluginFlag(0);
+            ClearDetectPluginFlag(1);
+        }
     } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
-        DetectPluginStart();
+        if (pDcChargingInfo->RemoteStartFlag) {
+            DetectPluginStart(gunIndex);
+        } else {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                DetectPluginStart(LEFT_GUN_NUM);
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                DetectPluginStart(RIGHT_GUN_NUM);
+        }
     }
 
     usleep(50000);
@@ -1696,18 +1720,39 @@ void _AuthorizedTimeout(void)
     }
 }
 
-void _DetectPlugInTimeout(void)
+void _DetectPlugInTimeout(int gunIndex)
 {
-    log_info("*********** _DetectPlugInTimeout *********** ");
     strcpy((char *)pSysConfig->UserId, "");
-    ClearDetectPluginFlag();
-
+    
+
+    uint8_t is_remote = NO;
+    for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+        if (pDcChargingInfo->RemoteStartFlag) {
+            //此停止為remote start停止
+            is_remote = YES;
+            break;
+        }
+    }
+    if (is_remote) {
+        // Remote start進入充電
+        log_info("Clear Gun%d Remote start detect plugin flag",gunIndex);
+        StopGunInfoTimeoutDet(gunIndex);
+        ClearDetectPluginFlag(gunIndex);
+    } else {
+        log_info("Clear Gun%d RFID detect plugin flag", gunIndex);
+        // 刷卡進入充電
+        ClearDetectPluginFlag(LEFT_GUN_NUM);
+        ClearDetectPluginFlag(RIGHT_GUN_NUM);
+        StopGunInfoTimeoutDet(LEFT_GUN_NUM);
+        StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
+    }
     sleep(1); //等待DoComm回報插槍訊號給主櫃
 #if defined DD360Audi
 	//pSysInfo->SystemPage = _LCM_COMPLETE;
-	setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
+	setChargerMode(gunIndex, S_TERMINATING);
 #elif DD360 || DD360Combox
- 	setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
+ 	setChargerMode(gunIndex, S_IDLE);
 #endif
     systemPageRestoreInit();
 }
@@ -1730,7 +1775,7 @@ void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
         }
     }
     ChargingTerminalProcess(gunIndex);
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
 }
 
 void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
@@ -1744,7 +1789,7 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
 #elif DD360 || DD360Combox
 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
 #endif
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
     }
 }
 
@@ -1758,7 +1803,7 @@ void _PrepareTimeout(uint8_t gunIndex)
 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
 #endif
     pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
 }
 
 void _CcsPrechargeTimeout(uint8_t gunIndex)
@@ -2769,6 +2814,7 @@ void StartSystemTimeoutDet(uint8_t flag)
 {
     if (pSysInfo->SystemTimeoutFlag != flag) {
         GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
+       //log_info("Start System Timeout: %d",flag);
     }
     pSysInfo->SystemTimeoutFlag = flag;
 }
@@ -2786,6 +2832,7 @@ void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
     if (gunIndex < pSysConfig->TotalConnectorCount) {
         if (pDcChargingInfo->TimeoutFlag != flag) {
             gettimeofday(&pDcChargingInfo->TimeoutTimer, NULL);
+            //log_info("Start Gun%d Info timeout: %d",gunIndex,flag);
         }
         pDcChargingInfo->TimeoutFlag = flag;
     }
@@ -2894,7 +2941,7 @@ void CreateTimeoutFork(void)
                 break;
             case Timeout_VerifyFail:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
-                    _AutoReturnTimeout();
+                    _AutoReturnTimeout(pSysInfo->CurGunSelected);
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
                     if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
@@ -2910,16 +2957,8 @@ void CreateTimeoutFork(void)
 
             case Timeout_VerifyComp:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
-                    _AutoReturnTimeout();
-                    StopSystemTimeoutDet();
-                }
-                break;
-
-            case Timeout_WaitPlug:
-                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
-                    _DetectPlugInTimeout();
+                    _AutoReturnTimeout(pSysInfo->CurGunSelected);
                     StopSystemTimeoutDet();
-                    destroySelGun(pSysInfo->CurGunSelected);
                 }
                 break;
 
@@ -2962,6 +3001,14 @@ void CreateTimeoutFork(void)
                 }
                 break;
 
+                case Timeout_WaitPlug:
+                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
+                        log_info("*********** Gun%d _DetectPlugInTimeout *********** ", gunIndex);
+                        _DetectPlugInTimeout(gunIndex);
+                        StopGunInfoTimeoutDet(gunIndex);
+                        destroySelGun(gunIndex);
+                    }
+                    break;
                 case Timeout_Preparing:
                     if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
                         _PrepareTimeout(gunIndex);
@@ -3192,35 +3239,36 @@ void OcppRemoteStartChk()
 {
     if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
 
-    } else if (!isDetectPlugin()) {
+    } else{
         // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
         uint8_t acDirIndex = pSysConfig->AcConnectorCount;
 
         for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
             pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(ac_index);
-
-            if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
-                if (pAcChargingInfo->SystemStatus == S_IDLE ||
+            if (!isDetectPlugin(acDirIndex)) {
+                if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
+                    if (pAcChargingInfo->SystemStatus == S_IDLE ||
                         pAcChargingInfo->SystemStatus == S_RESERVATION) {
+                        ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
+                        pAcChargingInfo->RemoteStartFlag = YES;
+                        pSysInfo->OrderCharging = YES;
+                        //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
+                        ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
+                        DetectPluginStart(acDirIndex);
+                        return;
+                    }
                     ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-                    pAcChargingInfo->RemoteStartFlag = YES;
-                    pSysInfo->OrderCharging = YES;
-                    //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
-                    ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
-                    return;
                 }
-                ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
             }
         }
-
+        
         uint8_t threeGunIndex = 0;
         uint8_t dcIndex = 0;
         bool isGunUsingStatus = false;
 
         for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
+            /*
             // 如果有 AC 槍,且 DC 槍也有兩把
             if (acDirIndex == 1 && _index == 1) {
                 threeGunIndex = 1;
@@ -3248,22 +3296,23 @@ void OcppRemoteStartChk()
         if (dcIndex == 0) {
             threeGunIndex = 0;
         }
+        */
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
 
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(dcIndex);
-
-        if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES) {
-            if (pDcChargingInfo->SystemStatus == S_IDLE ||
+            if (ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq == YES) {
+                if (pDcChargingInfo->SystemStatus == S_IDLE ||
                     pDcChargingInfo->SystemStatus == S_RESERVATION) {
-                pDcChargingInfo->RemoteStartFlag = YES;
-                pSysInfo->OrderCharging = YES;
-                //pSysInfo->OrderCharging = gunIndex;
-                ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-                DetectPluginStart();
+                    pDcChargingInfo->RemoteStartFlag = YES;
+                    pSysInfo->OrderCharging = YES;
+                    //pSysInfo->OrderCharging = gunIndex;
+                    ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
+                    DetectPluginStart(_index);
 #if defined DD360Audi
-                setSelGunWaitToAuthor(dcIndex); //Jerry add
+                    setSelGunWaitToAuthor(_index); //Jerry add
 #endif //defined DD360Audi
+                }
+                ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
             }
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
         }
     }
 }
@@ -4383,6 +4432,144 @@ void showversion()
     }
     log_info("\t================================ ");
 }
+
+
+void SetNatural300AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetCurrent[0] = 5000;
+    deratingByConnOtp->deratingTargetCurrent[1] = 3000;
+    deratingByConnOtp->deratingTargetCurrent[2] = 1000;
+    deratingByConnOtp->deratingTargetCurrent[3] = 0;
+    deratingByConnOtp->deratingTargetCurrent[4] = 0;
+}
+void SetLiquidCoolGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetCurrent[0] = 5000;
+    deratingByConnOtp->deratingTargetCurrent[1] = 4000;
+    deratingByConnOtp->deratingTargetCurrent[2] = 3000;
+    deratingByConnOtp->deratingTargetCurrent[3] = 0;
+    deratingByConnOtp->deratingTargetCurrent[4] = 0;
+}
+
+void SetCHAdeMoTypeKOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetRate[0] = 1;
+    deratingByConnOtp->deratingTargetRate[1] = 0.8;
+    deratingByConnOtp->deratingTargetRate[2] = 0.8;
+    deratingByConnOtp->deratingTargetRate[3] = 0;
+    deratingByConnOtp->deratingTargetRate[4] = 0;
+
+    memset(&deratingByConnOtp->deratingTargetCurrent[0], 0, sizeof(deratingByConnOtp->deratingTargetCurrent));
+}
+
+void SetCHAdeMoTypeSJOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->isNeedDerating = YES;
+    deratingByConnOtp->deratingTargetCurrent[0] = 2000;
+    deratingByConnOtp->deratingTargetCurrent[1] = 1250;
+    deratingByConnOtp->deratingTargetCurrent[2] = 1250;
+    deratingByConnOtp->deratingTargetCurrent[3] = 0;
+    deratingByConnOtp->deratingTargetCurrent[4] = 0;
+}
+
+static void SetGunTypeOTPValue(void)
+{
+    //struct ChargingInfoData* chargingData_2 = NULL;
+    uint8_t Gun1Type = 0;
+    uint8_t Gun2Type = 0;
+    uint8_t Type;
+    int i,cnt;
+    if (pSysConfig->TotalConnectorCount == 1) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(0);
+        Gun1Type = pSysConfig->ModelName[7];
+        Gun2Type = pSysConfig->ModelName[7];
+
+        switch (Gun1Type) {
+
+        case 'K':
+            SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        case 'S':
+            SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        case 'T':
+        case 'D':
+            SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+            // 水冷
+        case 'V':
+        case 'F':
+            SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        default:
+            pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
+        }
+        if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
+            log_info("------------ Gun0 - Type:%c Derating info (OTP)-----------", Gun1Type);
+            if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
+                for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                    if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
+                        log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
+                    }
+                }
+            } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
+                for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                    if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
+                        log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
+                    }
+                }
+            }
+        }
+
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        Gun1Type = pSysConfig->ModelName[7];
+        Gun2Type = pSysConfig->ModelName[9];
+        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+
+            switch (i == 0 ? Gun1Type : Gun2Type) {
+            case 'K':
+                SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+            case 'S':
+                SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+                // 風冷300A
+            case 'T':
+            case 'D':
+                SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+                // 水冷
+            case 'V':
+            case 'F':
+                SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+            default:
+                pDcChargingInfo->deratingByConnOtp.isNeedDerating = NO;
+            }
+            if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
+                log_info("------------ Gun%d - Type:%c Derating info (OTP)-----------",i, i == 0 ? Gun1Type : Gun2Type);
+                if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[0] != 0) {
+                    for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                        if (pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt] != 0) {
+                            log_info(" (Pwr) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetRate[cnt]);
+                        }
+                    }
+                } else if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[0] != 0) {
+                    for (cnt = 0; cnt < DERATING_TARGET_LEVEL; cnt++) {
+                        if (pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt] != 0) {
+                            log_info(" (Cur) count = %d, valut = %.1f ", cnt, pDcChargingInfo->deratingByConnOtp.deratingTargetCurrent[cnt]);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
 int main(void)
 {
     bool isModelNameMatch = true;
@@ -4554,6 +4741,8 @@ int main(void)
 
     time_t ShowEVStatusTimer[2] = { 0 };
 
+    SetGunTypeOTPValue();
+
     for (;;) {
 
         CheckOcppStatus();
@@ -4584,11 +4773,6 @@ int main(void)
         //確認Power cabinet PSU Status
         //powerCabinetPsuAlarmStatus();
 
-        if (pGunIndexInfo->AcGunIndex > 0 && isDetectPlugin() && !GetIsCardScan()) {
-            // AUDI_LCM_CHANGE
-            pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
-        }
-
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
             //CheckTask();
 
@@ -4645,6 +4829,14 @@ int main(void)
 
             ChkOcppStatus(gunIndex);
 
+            if (pGunIndexInfo->AcGunIndex > 0 &&
+                isDetectPlugin(gunIndex) &&
+                !GetIsCardScan() &&
+                gunIndex == pSysInfo->CurGunSelected) {
+                // AUDI_LCM_CHANGE
+                pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
+            }
+
             if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
                     pDcChargingInfo->SystemStatus <= S_CHARGING) ||
                     (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
@@ -4670,7 +4862,9 @@ int main(void)
                     strcpy((char *)pDcChargingInfo->StopDateTime, "");
                     strcpy((char *)pDcChargingInfo->StartUserId, "");
                     strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "");
-                    
+                    if (pDcChargingInfo->deratingByConnOtp.deratingIndex != 0) {
+                        pDcChargingInfo->deratingByConnOtp.deratingIndex = 0;
+                    }
                     //Jerry add
                     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
                     memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
@@ -4736,7 +4930,7 @@ int main(void)
                             systemPageRestoreInit();
                         }
                     }
-                    ClearDetectPluginFlag();
+                    ClearDetectPluginFlag(gunIndex);
 
                     if (pDcChargingInfo->SystemStatus != S_FAULT)
                     {
@@ -4776,13 +4970,8 @@ int main(void)
 
                 // Idle 正常程序起點
                 // 判斷是否有啟用檢查插槍
-                if (isDetectPlugin()) {
-                    /*
-                    if(pDcChargingInfo->Type == _Type_CCS_2 &&
-                            pSysConfig->isAuthrizeByEVCCID &&
-                            strcmp((char *)pDcChargingInfo->EVCCID,(char *)pSysConfig->UserId) != EQUAL )
-                        continue;
-                        */
+                if (isDetectPlugin(gunIndex)) {
+                    StartGunInfoTimeoutDet(gunIndex, Timeout_WaitPlug);
                     // 卡號驗證成功後,等待充電槍插入充電車
                     if (pDcChargingInfo->RemoteStartFlag == YES) {
                         if (pDcChargingInfo->ConnectorPlugIn == YES &&
@@ -4794,7 +4983,8 @@ int main(void)
                             AddPlugInTimes(gunIndex);
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             strcpy((char *)pDcChargingInfo->StartUserId, "");
-                            ClearDetectPluginFlag();
+                            ClearDetectPluginFlag(gunIndex);
+                            StopGunInfoTimeoutDet(gunIndex);
                             continue;
                         }
                     } else if (pSysInfo->OrderCharging == NO_DEFINE) {
@@ -4819,11 +5009,13 @@ int main(void)
                                      gunIndex,
                                      pDcChargingInfo->StartUserId);
                             strcpy((char *)pSysConfig->UserId, "");
-                            ShmDcCommonData->AuthroizeType = IdTokenType_ISO14443;
+                            ShmDcCommonData->AuthroizeType = IdTokenType_Central;
                             // 當前操作的槍號,進入 Preparing
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
-                            ClearDetectPluginFlag();
-
+                            ClearDetectPluginFlag(LEFT_GUN_NUM);
+                            ClearDetectPluginFlag(RIGHT_GUN_NUM);
+                            StopGunInfoTimeoutDet(LEFT_GUN_NUM);
+                            StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
                             continue;
                         }
                     }
@@ -4833,21 +5025,7 @@ int main(void)
                         // AUDI_LCM_CHANGE
                         pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
                     }
-                } /*else if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE &&
-                           (pDcChargingInfo->ConnectorPlugIn == YES &&
-                            pDcChargingInfo->IsAvailable)
-                          ) {
-                    log_info("-----------------3-----------------");
-
-                    if (GetStartChargingByAlterMode(gunIndex) == true) {
-                        ChangeGunSelectByIndex(gunIndex);
-                        AddPlugInTimes(gunIndex);
-                        setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
-                        ClearDetectPluginFlag();
-                        continue;
-                    }
-                } */
-                else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn && 
+                } else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn && 
                         pSysInfo->CurGunSelected == gunIndex && !pDcChargingInfo->isEVCCIDVerify) {
                     systemPageRestoreInit();
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -4872,17 +5050,7 @@ int main(void)
                     gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
                 }
 
-                isRessign = NO;
-
-                if (distributionPsuModule(&isRessign, gunIndex) == YES) {
-                    continue;
-                }
-
-                if (isRessign == YES) {
-                    setChargerMode(gunIndex, MODE_REASSIGN);
-                } else {
-                    setChargerMode(gunIndex, MODE_PRECHARGE);
-                }
+                setChargerMode(gunIndex, S_PREPARNING);
 
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -4893,36 +5061,6 @@ int main(void)
             }
             break;
 
-            case S_REASSIGN:
-                if (isModeChange(gunIndex)) {
-                    log_info("============================= S_REASSIGN(%x) ============================= ", gunIndex);
-                    gettimeofday(&_toAverage_time, NULL);
-                }
-
-                // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
-                // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
-                if (pSysInfo->ReAssignedFlag == _REASSIGNED_NONE ||
-                        pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-                    if (pSysInfo->CanAverageCharging) {
-                        pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;//DS60-120 add
-                        setChargerMode(gunIndex, MODE_PRECHARGE);
-                    } else {
-                        setChargerMode(gunIndex, MODE_IDLE);
-                    }
-                    pSysInfo->ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 add
-                } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
-                           pSysInfo->BridgeRelayStatus == NO) {
-                    log_info("=============Smart Charging : _REASSIGNED_COMP============= Step 6 ");
-                    pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                    //pSysInfo->ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 remove
-                    pSysInfo->CanAverageCharging = true; //DS60-120 add
-                }
-
-                if (pSysInfo->CurGunSelected == gunIndex) {
-                    pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
-                }
-                break;
-
             case S_PREPARNING:
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_PREPARNING(%x) ============================= ", gunIndex);
@@ -4936,25 +5074,6 @@ int main(void)
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 
-                //DS60-120 add
-                if (pSysConfig->TotalConnectorCount >= 2) {
-                    bool oughtAver = true;
-                    for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                        pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(index);
-                        // 共同進入充電邏輯
-                        if (pDcChargingInfo->SystemStatus != S_PREPARNING) {
-                            oughtAver = false;
-                            break;
-                        }
-                    }
-
-                    if (oughtAver) {
-                        log_info("********* Automatically change to aver mode ********** ");
-                        pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                        pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
-                    }
-                }
-
                 checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
 
                 if (pSysInfo->CurGunSelected == gunIndex) {

+ 2 - 2
EVSE/Projects/DD360Audi/Apps/CSU/main.h

@@ -65,8 +65,8 @@
 //} LedConfig;
 
 //------------------------------------------------------------------------------
-bool isDetectPlugin(void);
-void _DetectPlugInTimeout(void);
+bool isDetectPlugin(int gunIndex);
+void _DetectPlugInTimeout(int gunIndex);
 void _evccidlinktimeout(uint8_t gunIndex);
 void StartSystemTimeoutDet(uint8_t flag);
 void StopSystemTimeoutDet(void);

+ 8 - 0
EVSE/Projects/DD360Audi/Apps/Config.h

@@ -293,6 +293,10 @@ enum _CREDITCARD_STATUS {
 	_CREDITCARD_SETTLEMENT,
 	_CREDITCARD_START,
 };
+enum _DERATING_TEMP {
+    STAGE1_GUN_DERATING_TEMP = 140,
+    STAGE2_GUN_DERATING_TEMP = 145,
+};
 //------------------------------------------------------------------------------
 //struct StructMeter {
 //    float curMeterValue;
@@ -418,6 +422,7 @@ typedef struct StGunInfo {
     char ChargeStopTime[32];
     char ChargeDuration[32];
     uint8_t withChiller;      //是否有水冷機
+    uint8_t WaitForPlugit;    // 等待插槍FLAG
 } GunInfo;
 
 typedef struct Psu_VersionInfo{
@@ -488,6 +493,9 @@ typedef struct StDcCommonInfo {
     GunInfo pGunInfo[2];
     uint8_t showNetPackage;
     uint8_t showCanPackage;
+    time_t FanOnTime;
+    float TempVolt[4];
+    char DebugVersion[32];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 193 - 44
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -153,6 +153,15 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
     #define GENERAL_GUN_QUANTITY	0
     #define PSU_QUANTITY            2
     #define ONE_CONNECTOR_USE       0
+#elif defined Emulator
+    #define MAX_PSU_QUANTITY        62
+    #define CHAdeMO_QUANTITY        3
+    #define CCS_QUANTITY            3
+    #define GB_QUANTITY             3
+    #define AC_QUANTITY             3
+    #define GENERAL_GUN_QUANTITY    0
+    #define PSU_QUANTITY            2
+    #define ONE_CONNECTOR_USE       0
 #else
     #define MAX_PSU_QUANTITY        62
     #define CHAdeMO_QUANTITY        2
@@ -188,6 +197,7 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #define ShmRelay2BdKey			1013
 #define ShmYesCustomKey         1014
 #define ShmOcppPHModuleKey      1015
+#define ShmSmartBoxKey          1016
 
 #define FaultCodeLength         5
 #define AlarmCodeLength         20
@@ -332,6 +342,7 @@ enum CoreProfile {
      isEnableLocalPowerSharing,
      PowerSharingServerIP,
      EVCCID_PREFIX,
+     OffLineMaxChargingPower,
      ConfigurationVersion,
 	 _CoreProfile_CNT
 };
@@ -370,7 +381,9 @@ struct WifiConfigData
 {
 	unsigned char		WifiMode;					//0: disable, 1: Infrastructure client, 2: Infrastructure server, 3: Ad-Hoc
 	unsigned char		WifiSsid[256];				//default: Null
-	unsigned char		WifiPassword[256];			//default: Null
+    unsigned char       WifiPassword[224];          //default: Null
+    unsigned char       WifiBroadcastSsid;          //the SSID broadcast configuration, 0: hidden   1: broadcast
+    unsigned char       WifiTargetBssidMac[31];     //Target connect SSID MAC address, default: Null
 	int					WifiRssi;					//dbm
 	unsigned char		WifiDhcpServer;				//0: enable, 1: disable
 	unsigned char		WifiDhcpClient;				//0: enable, 1: disable
@@ -385,7 +398,8 @@ struct TeleConfigData
 {
 	unsigned char		TelcomModelName[64];		//default: Null
 	unsigned char		TelcomSoftwareVer[64];		//default: Null
-	unsigned char		TelcomApn[256];				//default: Null
+    unsigned char       TelcomApn[255];             //default: Null
+    unsigned char       TelcomNetworkType;          //0: Auto   1: CDMA  2: WCDMA  3: LTE  4: TD-SCDMA  5: UMTS  6: CDMA  7: HDR  8: CDMA/HDR
 	int					TelcomRssi;					//dbm
 	unsigned char		TelcomChapPapId[256];		//default: Null
 	unsigned char		TelcomChapPapPwd[256];		//default: Null
@@ -484,7 +498,8 @@ typedef union
         unsigned int InvalidIdStop:1;               // 0: no effect,    1: invalid stop when StopTransactionOnInvalidId is true
         unsigned int RemoteStop:1;                  // 0: no effect,    1: remote stop
         unsigned int UnlockStop:1;                  // 0: no effect,    1: unlock stop
-        unsigned int res:23;
+        unsigned int SessionTargetStop:1;           // 0: no effect,    1: session target stop
+        unsigned int res:22;
     }bits;
 }ChargingStop;
 
@@ -591,6 +606,16 @@ struct SysConfigData
     unsigned char           MaintainServerSecurityProfile;      // Maintain server security profile 0~3
     unsigned char           MaintainServerSecurityPassword[41]; // Maintain server AuthorizationKey for security profile
     unsigned char           PowerSharingServerIP[512];          // Local power sharing server ip address
+    unsigned int            PowerSharingCapacityPower;          // Local power sharing capacity power
+    unsigned char           MaxChargingSoc;                     //0: unlimit, 1 ~ 100 percent
+};
+
+struct DERATING_BY_OTP
+{
+    unsigned char isNeedDerating;
+    unsigned char deratingIndex;        // Current used power or current
+    double deratingTargetRate[5];       // Reduce the output energy rate
+    double deratingTargetCurrent[5];    // derating target current
 };
 
 struct ChargingInfoData
@@ -626,6 +651,7 @@ struct ChargingInfoData
 	int EvBatterySoc;				// 0~100%
 	unsigned char ConnectorPlugIn;			//0: unplug, 1: Plug-in
 	unsigned char GunLocked;				//0: unlocked 1: locked
+	unsigned char InProgress;               //0: real idle, 1: session(transaction) in progress
 	float PilotVoltage;
 	unsigned char PilotState;//1:state A, 2:State B1, 3:State B2, 4:State C, 5:State D, 6:State E, 7:State F, 8: Pilot error
 	unsigned char PilotDuty;					// 0~100%
@@ -695,6 +721,9 @@ struct ChargingInfoData
     unsigned char       CCSGunType;
     struct timeval      PreChargeTimer;
     unsigned char       _SaftyDetect;
+    unsigned char       _TotalPsuCount;                 // Psu count for connector
+    unsigned char       _TakePsuGpCount;                // Get the used psu group count
+    struct DERATING_BY_OTP deratingByConnOtp;
 };
 
 typedef struct
@@ -878,6 +907,7 @@ struct ConnectorInfoData
     float                   CostDiscount;                   // connector user's Discount or couponPoint, unit: 1 point
     float                   EnergyCost;                     // connector user's energy cost, unit: 1 dollar
     float                   ParkingFee;                     // connector user's parking fee, unit: 1 dollar
+    float                   RemainAmount;                   // connector user's remain amount, unit: 1 dollar
 };
 
 typedef union
@@ -885,15 +915,11 @@ typedef union
     unsigned int SettingValue;
     struct
     {
-        unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
-        unsigned int FlashConfigChanged:1;      // 0: no effect, 1: flash config has changed
-        unsigned int EnableWriteFlash:1;        // 0: no effect, 1: enable to write flash after timeout
-        unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
-        unsigned int res:28;
+        unsigned int res:32;
     }bits;
 }CabinetSettingFlag;
 
-typedef struct DC_METER_INFO
+struct DC_METER_INFO
 {
     double presetVoltage;                       // resolution: 1.000v
     double presentCurrent;                      // resolution: 1.000a
@@ -901,7 +927,61 @@ typedef struct DC_METER_INFO
     double totlizeImportEnergy;                 // resolution: 1.000kwh
     double totlizeExportEnergy;                 // resolution: 1.000kwh
     unsigned char LinkStatus;                   // 0 = unknow ,1 = link , 2 miss link
-}DC_Meter_Info;
+};
+
+typedef struct Bazel8Command
+{
+    unsigned char isReq:1;
+    unsigned char isRes:1;
+    unsigned char isWaitRes:1;
+    unsigned char isResultPass:1;
+} bazel8Command;
+
+typedef struct EventInfo
+{
+    int messageId;
+    char messageString[64];
+    unsigned char isGetOn:1;
+}eventInfo;
+
+typedef struct StartTxResp
+{
+    char statusCode[8];
+    char statusText[128];
+    char txnId[32];
+    unsigned char isGetOn:1;
+}startTxResp;
+
+struct BAZEL8
+{
+    eventInfo       event;
+    startTxResp     txResp;
+
+    bazel8Command   cmdPreAuth;
+};
+
+struct Enegate
+{
+    union
+    {
+        unsigned char OperationValue[CONNECTOR_QUANTITY];
+        struct
+        {
+            unsigned char isAuthorizing:1;
+            unsigned char isAuthorized:1;
+            unsigned char isAuthorizedPass:1;
+            unsigned char isSessionStopReq:1;
+            unsigned char isStopService:1;
+            unsigned char isAutoStartEnable:1;
+            unsigned char isConnectTimeout:1;
+            unsigned char :1;
+        } bits[CONNECTOR_QUANTITY];
+    }Operation;
+
+    unsigned char   serviceStartTimestamp[36];
+    unsigned char   serviceStopTimestamp[36];
+    unsigned char   isEnable:1;
+};
 
 struct SysInfoData
 {
@@ -996,10 +1076,12 @@ struct SysInfoData
     unsigned char           AuthorizedStatus;           // cabinet authorized status
     CabinetSettingFlag      CabinetSetting;
     struct LocalSharingInfo localSharingInfo;           // Local power sharing info structure
-    DC_Meter_Info DcMeterInfo[4];
+    struct DC_METER_INFO    DcMeterInfo[4];
     unsigned char           OTPTemp;                    // OTP Temperature
     unsigned char           OTPTempR;                   // OTP Recovery Temperature
     struct LCD_OVERRIDE     LcdOveride;                 // LCD override info (no use anymore)
+    struct BAZEL8           bazel8;                     // Bazel8 payment used
+    struct Enegate          enegate;                    // Enegate payment used
 };
 
 struct SysConfigAndInfo
@@ -1253,18 +1335,18 @@ char AlarmStatusCode[160][6]=
 	"012261",	//GB groundfault detection timeout (GFD)
 	"012262",	//Circuit Short L1
 	"012263",	// PSU Duplicate ID
-	"012264", 	// PSU Output Short Circuit
+	"012264", 	// Psu Fault : Infy => Output Short Circuit,UU => Abnormal discharge circuit
 	"012265", 	// PSU Discharge Abnormal
 	"012266", 	// PSU Dc Side ShutDown
 	"012267", 	// PSU Failure Alarm
 	"012268", 	// PSU Protection Alarm
-	"012269", 	// PSU FanFailure Alarm
+	"012269", 	// Psu Fault : Infy => Fan Fault,UU => Fan Fault
 	"012270", 	// PSU Input UVP
 	"012271",	// PSU Input OVP
 	"012272", 	// PSU WalkIn State
-	"012273", 	// PSU Power Limited State
-	"012274", 	// PSU Id Repeat
-	"012275", 	// PSU Severe Uneven Current
+	"012273", 	// Psu Fault : Infy => Power Limited State,UU => Dc OVP and shutdown
+	"012274", 	// Psu Fault : Infy => Id Repeat,UU => Id Repeat
+	"012275", 	// Psu Fault : Infy => Severe Uneven Current,UU => Pfc internal unbalance
 	"012276", 	// PSU Three Phase Input Inadequate
 	"012277", 	// PSU Three Phase Onput Imbalance
 	"012278", 	// PSU Ffc Side ShutDown
@@ -1296,18 +1378,18 @@ char AlarmStatusCode[160][6]=
 	"012304",   // connection disconnected from power cabinet
 	"012305",   // Meter communication timeout
 	"012306",   // The dip switch of the PSU may be incorrect
-    "012307",   // Psu Fuse Burn-Out
-    "012308",   // Psu Pfc And Dcdc Communication Fault
-    "012309",   // Psu Bus Voltage Unbalance
-    "012310",   // Psu Bus Over Voltage
-    "012311",   // Psu Bus Voltage Abnormal
-    "012312",   // Psu Bus Under Voltage
-    "012313",   // Psu Input Phase Loss
-    "012314",   // Psu Fan Full Speed
-    "012315",   // Psu Temperature Power Limit
-    "012316",   // Psu Ac Power Limit
-    "012317",   // Psu Dcdc Eeprom Fault
-    "012318",   // Psu Pfc Eeprom Fault
+    "012307",   // Psu Fault : Infy => Fuse Burn-Out,UU => Pfc internal OVP
+    "012308",   // Psu Fault : Infy => Pfc And Dcdc Communication Fault,UU => Pfc And Dcdc Communication Fault
+    "012309",   // Psu Fault : Infy => Bus Voltage Unbalance,UU => Dc output voltage unbalance
+    "012310",   // Psu Fault : Infy => Bus Over Voltage,UU => Ac site OVP
+    "012311",   // Psu Fault : Infy => Bus Voltage Abnormal,UU => Ac site UVP
+    "012312",   // Psu Fault : Infy => Bus Under Voltage,UU => Pfc internal UVP
+    "012313",   // Psu Fault : Infy => Input Phase Loss,UU => Dc to Dc don’t work
+    "012314",   // Psu Fault : Infy => Fan Full Speed,UU => Fan don’t work
+    "012315",   // Psu Fault : Infy => Temperature Power Limit,UU => env OTP、Pfc OTP、output relay broken、Dc OTP
+    "012316",   // Psu Fault : Infy => Ac Power Limit,UU => Ac OVP and shutdown
+    "012317",   // Psu Fault : Infy => Dcdc Eeprom Fault,UU => Dc to Dc broken
+    "012318",   // Psu Fault : Infy => Pfc Eeprom Fault,UU => Pfc broken
     "012319",   // Psu Dcdc Over Voltage
     "012320",   // System CHAdeMO output UCP
     "012321",   // System CCS output UCP
@@ -1316,13 +1398,13 @@ char AlarmStatusCode[160][6]=
     "012324",   // Connector 1 detects abnormal voltage on the output line
     "012325",   // Connector 2 detects abnormal voltage on the output line
     "012326",   // System task is lost
-    "012327",   // DC input ovp
-    "012328",   // DC input uvp
-    "012329",   // Psu Can Communication Fault
-    "012330",   // Psu Dc to Dc OTP
-    "012331",   // Psu Dc to Dc OVP
-    "012332",   // reserved
-    "012333",   // reserved
+    "012327",   // System DC input ovp
+    "012328",   // System DC input uvp
+    "012329",   // Psu Fault : Infy => Psu Can Communication Fault,UU =>
+    "012330",   // Psu Fault : Infy => Psu Dc to Dc OTP,UU => env UTP
+    "012331",   // Psu Fault : Infy => Psu Dc to Dc OVP,UU => Dc output OVP
+    "012332",   // Chiller Tube OTP
+    "012333",   // Psu Fault : Infy => DC input ovp (Phase OVP),UU => Dc output UVP
     "012334",   // reserved
     "012335",   // reserved
     "012336",   // reserved
@@ -1336,12 +1418,12 @@ char AlarmStatusCode[160][6]=
     "012344",   // AC: Meter IC communication timeout
     "012345",   // AC: Pilot negative error
     "012346",   // Psu Communication error with CSU
-    "012347",   // reserved
+    "012347",   // AC: Local power sharing communication error (Slave disconnect from Master)
     "012348",   // reserved
     "012349",   // reserved
     "012350",   // reserved
     "012351",   // reserved
-    "012352",   // reserved
+    "012352",   // Payment system communication timeout
     "012353",   // reserved
     "012354",   // reserved
     "012355",   // reserved
@@ -1508,16 +1590,20 @@ struct AlarmCodeData
             unsigned char PsuCanCommFault:1;                        //bit 1
             unsigned char PsuDcDcOtp:1;                             //bit 2
             unsigned char PsuDcDcOvp:1;                             //bit 3
-            unsigned char :4;                                       //reserved bit 4 ~ bit 7
+            unsigned char ChillerTubeOTP : 1;                       //bit 4
+            unsigned char PsuPhaseOvp:1;                            //bit 5
+            unsigned char :2;                                       //reserved bit 6 ~ bit 7
             //AlarmVal[17]
             unsigned char :8;                                       //reserved bit 0 ~ bit 7
             //AlarmVal[18]
             unsigned char MeterIcCommTimeout:1;                     //bit 0
             unsigned char PilotNegativeError:1;                     //bit 1
             unsigned char PsuComminicationErrWithCSU:1;             //bit 2
-            unsigned char :5;                                       //reserved bit 3 ~ bit 7
+            unsigned char LocalPowerSharingCommunicationError:1;    //bit 3
+            unsigned char :4;                                       //reserved bit 4 ~ bit 7
             //AlarmVal[19]
-            unsigned char :8;                                       //reserved bit 0 ~ bit 7
+            unsigned char PaymentCommTimeout:1;                     //Payment system communication timeout
+            unsigned char :7;                                       //reserved bit 1 ~ bit 7
 		}bits;
 	}AlarmEvents;
 };
@@ -1843,7 +1929,7 @@ char InfoStatusCode[384][6]=
     "023981",   // ERROR_CODE_CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT
     "023982",   // ERROR_CODE_CHADEMO_ADC_LESS_THAN_10V
     "023983",   // STOP by EV with unknow reason
-    "023984",   // Reserved
+    "023984",   // STOP by EVSE condition (Config or OCPP)
     "023985",   // Reserved
     "023986",   // Reserved
     "023987",   // Reserved
@@ -2190,7 +2276,8 @@ struct InfoCodeData
             unsigned char CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT:1; //bit 1
             unsigned char CHADEMO_ADC_LESS_THAN_10V:1;              //bit 2
             unsigned char Stop_by_EV_with_unknow_reason:1;          //bit 3
-            unsigned char :4;                                       //bit 4 ~ 7 reserved
+            unsigned char Stop_by_EVSE_condition:1;                 //bit 4
+            unsigned char :3;                                       //bit 5 ~ 7 reserved
 			//InfoVal[40]
 			unsigned char BackendDisconnectedViaEthernet:1;			//bit 0
 			unsigned char BackendDisconnectViaWiFi:1;				//bit 1
@@ -2267,6 +2354,8 @@ struct PsuModuleData
 	unsigned int 		AlarmCode;
 	unsigned int 		FaultCode;			//
 	unsigned int 		IAvailableCurrent;		            // unit: 0.1A
+    unsigned short  PresentMaxOutputVoltage;//abcd=abc.d volt
+    unsigned short  KwAvailablePower;       // unit: 0.1 kw
 };
 
 /*Following are the information for each PSU Group*/
@@ -2288,6 +2377,11 @@ struct PsuGroupData
     unsigned short          TempIAvailableCurrent;          // unit: 0.1A
     unsigned short          StableIAvailableCurrent;        // unit: 0.1A
     unsigned short          StableCurrentCounter;           // stable current counter
+    unsigned short          GroupMaxVoltage;                // unit: 0.1V
+    unsigned char           IsUsing;                        // 0 : none use
+    unsigned char           UsingTarget;                    // 0xFF : Check
+    unsigned char           PwSwitchStatus;
+    unsigned short          TotalRatingPower;               // unit: 1kW
 };
 
 /*Following is the information for system all PSU*/
@@ -2303,6 +2397,54 @@ struct PsuData
 	unsigned char           PsuStopChargeFlag;
 };
 
+struct SmartTimeChk
+{
+    struct timespec     FetchLoopTime;
+    unsigned char       IsFetchStart;
+
+    struct timespec     ReleaseLoopTime;
+    unsigned char       IsReleaseStart;
+};
+
+struct DynamicFetchCtrl
+{
+    unsigned char       ShareGroup;         // 255 : None
+    unsigned char       FetchLoopStep;      // 0 : None, 1 : Output Vol, 2 : RCB ON, 3 : Current sharing, 4 : Finish
+    unsigned short      ShareTargetCurrent; // 0.1A
+    unsigned char       TargetRelay;        // 255 : None
+};
+
+struct DynamicReleaseCtrl
+{
+    unsigned char       ReleaseGroup;       // 255 : None
+    unsigned char       ReleaseLoopStep;    // 0 : None, 1 : Limit Pwr, 2 : Pwr OFF, 3. RCB OFF, 4. Finish
+    float               CheckOutPwrIsStable;// 0.1kw
+    unsigned char       TargetRelay;        // 255 : None
+
+    float               LimitCurCap;        // Inform 0.1A
+    float               LimitPwrCap;        // Inform 0.1kw
+    float               LimitCur;           // Target 0.1A
+    float               LimitPwr;           // Target 0.1kw
+};
+
+struct ConnInfo
+{
+    unsigned char ConnectorStaus;
+    unsigned char NeedToFetch;
+};
+
+struct SmartBoxData
+{
+    struct ConnInfo     ConnectorStatus[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];     // Connector 1 / 2 Status : None, Wait, Using
+    struct ConnInfo     AnotherConnectorStatus[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    unsigned char       ConnectorUsingGroupCount[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; // Psu group for connector
+    struct SmartTimeChk SmartChk[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct DynamicFetchCtrl Dynamic4Fetch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct DynamicReleaseCtrl Dynamic4Release[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    unsigned char       ParallelRelayStatus[3];
+    unsigned char       RcbParallelStatus[3];
+};
+
 /************************************************************************************/
 /**************************CHAdeMO protocol Share memory*********************/
 /**************************************************************************************/
@@ -4449,6 +4591,7 @@ struct Triggers
                                                     // be used to trigger a meter value when vehicle stops charging or when vehicle charges at a high power that requires a
                                                     // different tariff.
                                                     // It is recommended to implement a hysteresis around this value to avoid repetitive triggers when the power fluctuates around this level.
+    unsigned char atCPStatus[100];
 };
 
 struct StrcutRunningCost
@@ -4469,6 +4612,10 @@ struct StrcutFinalCost
 {
     int             txId;
     unsigned char   description[1024];
+
+    float           cost;
+    unsigned char   priceText[1024];
+    unsigned char   qrCodeText[1024];
 };
 
 struct StructCost
@@ -4874,6 +5021,7 @@ enum OCPP20CtrlrVariable
 	ChargingStation_SystemUptimeSec,
 	ChargingStation_FreeVend,
 	ChargingStation_FreeVendIdtag,
+	ChargingStation_OffLineMaxChargingPower,
 	Connector_Available,
 	Connector_ConnectorType,
 	Connector_SupplyPhases,
@@ -6008,7 +6156,8 @@ struct OCPP20Data
 			unsigned char SecurityEventNotificationConf :1;
 			unsigned char SignCertificateReq :1;
 			unsigned char SignCertificateConf :1;
-			unsigned char :2;
+            unsigned char NotifyCustomerInformationReq :1;  //bit 6
+            unsigned char NotifyCustomerInformationConf :1; //bit 7
 
 		} bits;
 	} SpMsg;
@@ -6210,7 +6359,7 @@ struct OCPP20Data
 	struct UpdateFirmware_20					UpdateFirmware;
 	struct ChargingProfileType                  SmartChargingProfile[CONNECTOR_QUANTITY];
 	struct ChargingProfileType                  MaxChargingProfile;
-	struct StructSessionTarget	                SessionTarget[CONNECTOR_QUANTITY];
+	struct StructSessionTarget                  SessionTarget[CONNECTOR_QUANTITY];
 };
 
 

+ 4 - 4
EVSE/Projects/DD360Audi/Apps/Log/log.h

@@ -2,11 +2,11 @@
 #define _LOG_H_
 
 //------------------------------------------------------------------------------
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
 
-#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args) //DS60-120 add
 //------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...);
 int StoreEventLogMsg(const char *fmt, ...);

+ 25 - 20
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -354,18 +354,22 @@ static void ClearAuthorizedFlag(void)
     pSysInfo->AuthorizeFlag = NO;
 }
 
-static void ClearDetectPluginFlag(void)
+static void ClearDetectPluginFlag(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = NO;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
 }
 
-static bool isDetectPlugin(void)
+static bool isDetectPlugin(int gunIndex)
 {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
+        return true;
+    }
+    /*
     if (pSysInfo->WaitForPlugit == YES) {
-        return YES;
+        return true;
     }
-
-    return NO;
+    */
+    return false;
 }
 
 static void destroySelectGun(uint8_t curGun)
@@ -526,7 +530,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     string2Date((char*)data, (uint8_t*)_setTime);
     //printf("SystemId =  %s", pSysConfig->SystemId);
     if (!timecmp(localTime, _setTime)) {
-        log_info("Set Timer:%s", _setTime);
+        //log_info("Set Timer:%s", _setTime);
         sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
         system((char*)cmdBuf);
         system("hwclock -w -u");
@@ -810,7 +814,8 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             strcpy((char *)pSysConfig->UserId, "");
-            pSysInfo->WaitForPlugit = NO;
+            //pSysInfo->WaitForPlugit = NO;
+            ClearDetectPluginFlag(plugNum);
 #ifdef DD360Audi
             pSysInfo->SystemPage = _LCM_SELECT_GUN;
 #endif
@@ -829,10 +834,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            if (isDetectPlugin() == YES) {
-                ClearDetectPluginFlag();
+            if (isDetectPlugin(plugNum) == YES) {
+                ClearDetectPluginFlag(plugNum);
                 strcpy((char *)pSysConfig->UserId, "");
-                pSysInfo->WaitForPlugit = NO;
 #ifdef DD360Audi
                 pSysInfo->SystemPage = _LCM_SELECT_GUN;
 #endif
@@ -1534,12 +1538,12 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun2_Consumption, (char*)&pValue->Gun2_Consumption, sizeof(uint32_t));
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun3_Consumption, (char*)&pValue->Gun3_Consumption, sizeof(uint32_t));
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun4_Consumption, (char*)&pValue->Gun4_Consumption, sizeof(uint32_t));
-
+        /*
         log_info("Gun1_Consumption:%f", ShmDcCommonData->pConsumption.Gun1_Consumption);
         log_info("Gun2_Consumption:%f", ShmDcCommonData->pConsumption.Gun2_Consumption);
         log_info("Gun3_Consumption:%f", ShmDcCommonData->pConsumption.Gun3_Consumption);
         log_info("Gun4_Consumption:%f", ShmDcCommonData->pConsumption.Gun4_Consumption);
-        
+        */
         
         break;
         
@@ -1751,13 +1755,13 @@ static int readChargingTimeStamp(int fd, uint8_t id)
 
     return ret;
 }
-static int writeWaitPlugItState(int fd, uint8_t id)
+static int writeWaitPlugItState(int fd, uint8_t id, uint8_t gunIndex)
 {
     int ret = PASS;
-    uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-    if (_isplugin != pSysInfo->WaitForPlugit) {
-        log_info("Wait for plug:%s", pSysInfo->WaitForPlugit == 0 ? "disable" : "enable");
-        _isplugin = pSysInfo->WaitForPlugit;
+    uint8_t data[2] = { ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit, 0 };
+    if (_isplugin != ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit) {
+        //log_info("Wait Gun%d for plug:%s", gunIndex, ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin = ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit;
     }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
@@ -1927,7 +1931,7 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[15] = {'\0'};
+    uint8_t dataBuf[16] = {'\0'};
     uint32_t _consumption;
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
@@ -1937,6 +1941,7 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     pConnState->ConnectorTemp = pDcChargingInfo->ConnectorTemp;
     pConnState->ChillerTemp = pDcChargingInfo->ChillerTemp;
     pConnState->PlugIn = pDcChargingInfo->ConnectorPlugIn;
+    pConnState->ConnectMode = pDcChargingInfo->SystemStatus;
 
     if (pDcChargingInfo->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
@@ -2725,7 +2730,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
            ) {
-            writeWaitPlugItState(fd, gunID);
+            writeWaitPlugItState(fd, gunID, plugNum);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
         /*

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h

@@ -222,7 +222,7 @@ typedef struct StConnectorState {
     uint8_t ChillerTemp;
     uint8_t PlugIn;
     uint32_t consumption;
-    uint8_t Reserved[1];
+    uint8_t ConnectMode;
 } ConnectorState;
 
 typedef struct StConnectorIDTable {

+ 5 - 2
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCCS.c

@@ -17,6 +17,8 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
     struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    memset(code, '\n', sizeof(code));
+
 
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
         return;
@@ -751,8 +753,8 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
 
     if (isCleanCheck) {
         for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
             if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
                 log_info("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
                          index,
@@ -760,6 +762,7 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
                          code);
 
                 if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+
                     if (strncmp(code, "012219", 6) == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO; }
 
                     if (strncmp(code, "023701", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = NO; }
@@ -910,7 +913,7 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCHA.c

@@ -244,7 +244,7 @@ void ClearAbnormalStatus_Chademo(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalGBT.c

@@ -412,7 +412,7 @@ void ClearAbnormalStatus_GB(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 47 - 29
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -34,7 +34,8 @@ uint8_t TempArray_2[TempArraySize]={0};
 uint8_t ptemp_1 = 0;
 uint8_t ptemp_2 = 0;
 bool firstcircule = true;
-
+float EvTargetVolt[2] = { 0 };
+float EvTargetCur[2] = { 0 };
 //------------------------------------------------------------------------------
 extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
 
@@ -165,6 +166,7 @@ static void getChillerTemperature(ChillerTemp *chillerTemp)
     for (i = 0; i < 4; i++) {
         adcVoltage = 0.0;
         adcVoltage =  ReadAdcVolt(i);
+        ShmDcCommonData->TempVolt[i] = adcVoltage;
         if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
             pChillerTemp->Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
             //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
@@ -308,6 +310,7 @@ void CANReceiver(int fd)
         int len = 0;
         char _info[1024];
         int i;
+        unsigned char GunStatus[2];
 
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -333,19 +336,24 @@ void CANReceiver(int fd)
             for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
                 pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
                 // 檢查是否有收到EV小板訊號
-                if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 3) &&
-                    !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
-                    pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
-
-                    ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
-                    ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
-
-                    system("/sbin/ip link set can0 down");
-                    sleep(1);
-                    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-                    system("/sbin/ip link set can0 up");
+                if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+                    if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 5) &&
+                        !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
+                        pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
+
+                        ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
+                        ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
+
+                        system("/sbin/ip link set can0 down");
+                        sleep(1);
+                        system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+                        system("/sbin/ip link set can0 up");
+                    }
+                    CheckEvConnect(_index);
+                } else {
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
                 }
-                CheckEvConnect(_index);
             }
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -438,22 +446,15 @@ void CANReceiver(int fd)
                         pSysInfo->CurGunSelected = targetGun;
                     }
                 }
-                // CCS 小板確認拔除三秒
-                if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (frame.data[0] == UNPLUG) {
-                        if ((time((time_t*)NULL) - CCS_PlugoutTimer[targetGun]) > 3) {
-                            if (pDcChargingInfo->ConnectorPlugIn != frame.data[0])
-                                log_info("CCS Conn %d, Unplug. ", targetGun);
-                        } else {
-                            frame.data[0] = PLUG;
-                        }
-                    } else {
-                        CCS_PlugoutTimer[targetGun] = time((time_t*)NULL);
-                        frame.data[0] = PLUG;
-                    }
-                }
-                pDcChargingInfo->ConnectorPlugIn = frame.data[0];
                 pDcChargingInfo->PilotVoltage = frame.data[1];
+                // CCS 小板確認Pilot Voltage != 0
+                if (pDcChargingInfo->Type == _Type_CCS_2 && pDcChargingInfo->PilotVoltage != 0) {
+                    if (frame.data[0] == UNPLUG && pDcChargingInfo->ConnectorPlugIn != frame.data[0])
+                        log_info("Conn %d, Unplug. ", targetGun);
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                } else {
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                }
 
                 //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x ",
                 //         targetGun,
@@ -516,6 +517,7 @@ void CANReceiver(int fd)
 
             case ACK_GET_OUTPUT_REQ:
                 //DS60-120 add
+
                 if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
                         pDcChargingInfo->SystemStatus <= S_CHARGING) ||
                         (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
@@ -526,6 +528,14 @@ void CANReceiver(int fd)
                         pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
                     }
 
+                    // 進入充電時重新更新電池電量
+                    if (GunStatus[targetGun] != pDcChargingInfo->SystemStatus && pDcChargingInfo->SystemStatus == S_CHARGING) {
+
+                        log_info("Reset Gun%d SoC:%d", targetGun, frame.data[1]);
+                        pDcChargingInfo->EvBatterySoc = frame.data[1];
+                        GunStatus[targetGun] = pDcChargingInfo->SystemStatus;
+                    }
+
                     if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
                         pDcChargingInfo->EvBatterySoc = frame.data[1];
                         log_info("Gun%d SOC:%d", targetGun,pDcChargingInfo->EvBatterySoc);
@@ -576,7 +586,15 @@ void CANReceiver(int fd)
                         ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
                 }
-
+                if (pDcChargingInfo->EvBatterytargetVoltage > (EvTargetVolt[targetGun] + 5) ||
+                    pDcChargingInfo->EvBatterytargetVoltage < (EvTargetVolt[targetGun] - 5) ||
+                    pDcChargingInfo->EvBatterytargetCurrent >(EvTargetCur[targetGun] + 2) ||
+                    pDcChargingInfo->EvBatterytargetCurrent < (EvTargetCur[targetGun] - 2)) {
+                    log_info("Gun%d TargetVoltage = %f , TargetCurrent = %f",
+                        targetGun, pDcChargingInfo->EvBatterytargetVoltage, pDcChargingInfo->EvBatterytargetCurrent);
+                    EvTargetVolt[targetGun] = pDcChargingInfo->EvBatterytargetVoltage;
+                    EvTargetCur[targetGun] = pDcChargingInfo->EvBatterytargetCurrent;
+                }
                 //log_info("EvBatterytargetVoltage = %f ", pDcChargingInfo->EvBatterytargetVoltage);
                 //log_info("EvBatterytargetCurrent = %f ", pDcChargingInfo->EvBatterytargetCurrent);
                 //log_info("BatteryVoltage = %d ",

+ 43 - 9
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -55,7 +55,7 @@ static float LogInfo[2][10]; //DS60-120 add
 static int CanFd = -1;
 
 bool psuOutputReady[2] = {0, 0};
-
+uint8_t deratingIndex[2];
 //------------------------------------------------------------------------------
 extern void CANReceiver(int fd);
 extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
@@ -301,7 +301,29 @@ static void setCurrentOutput(void)
         }
     }
 }
+void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
+{
+    if (chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
+        chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP &&
+        chargingData->deratingByConnOtp.deratingIndex < 1)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 1;
+    } else if (chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP &&
+        chargingData->ConnectorTemp != UNDEFINED_TEMP &&
+        chargingData->deratingByConnOtp.deratingIndex < 2)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 2;
+    }
 
+    if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
+    } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        if (*cur > chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex])
+            *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex];
+    }
+}
 static void SetPresentChargingOutputCap(void)
 {
     float pow1 = 0, cur1 = 0;
@@ -346,6 +368,13 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_1->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_1, &pow1, &cur1);
+        if (deratingIndex[0] != chargingData_1->deratingByConnOtp.deratingIndex) {
+            log_info("Gun0 Derating Index Set %d", chargingData_1->deratingByConnOtp.deratingIndex);
+            deratingIndex[0] = chargingData_1->deratingByConnOtp.deratingIndex;
+        }
+    }
     pow2 = chargingData_2->AvailableChargingPower;
     cur2 = chargingData_2->AvailableChargingCurrent;
 
@@ -371,6 +400,14 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_2->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_2, &pow2, &cur2);
+        if (deratingIndex[1] != chargingData_2->deratingByConnOtp.deratingIndex) {
+            log_info("Gun1 Derating Index Set %d", chargingData_2->deratingByConnOtp.deratingIndex);
+            deratingIndex[1] = chargingData_2->deratingByConnOtp.deratingIndex;
+        }
+    }
+
     //DS60-120 add
     if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 ||
             LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
@@ -546,13 +583,11 @@ static void SetPresentChargingOutputPower(void)
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) ||
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
        ) {
-        log_info("G1->Out Vol(%s)=%.1f,Out Cur=%.1f - G2->Out Vol(%s) = %.1f, Out Cur = %.1f",
-                 isPsuVol1 == true ? "P" : "R",
-                 vol1 / 10,
-                 cur1 / 10,
-                 isPsuVol2 == true ? "P" : "R",
-                 vol2 / 10,
-                 cur2 / 10);
+        log_info("G1-> Vol=%.1f, Cur=%.1f - G2-> Vol = %.1f, Cur = %.1f",
+            vol1 / 10,
+            cur1 / 10,
+            vol2 / 10,
+            cur2 / 10);
 
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
         LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
@@ -815,7 +850,6 @@ int main(int argc, char *argv[])
                     }
                 } else if (pDcChargingInfo->Type == _Type_CCS_2) {
                     ClearAbnormalStatus_CCS(gunIndex);
-
                     if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO) {
                         pDcChargingInfo->StopChargeFlag = NO;
                     }

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/ModuleEventLog/Module_EventLogging.c

@@ -52,7 +52,7 @@ static struct FaultCodeData *pFaultCode      = NULL;
 //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args) //DS60-120 add
 
 /*
 int StoreLogMsg(const char *fmt, ...)

+ 3 - 3
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.h

@@ -85,9 +85,9 @@
 #define AC_ROTARY_SWITCH_FAULT                  (131072)
 #define AC_RELAY_DRIVE_FAULT                    (262144)
 
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 

+ 24 - 10
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c

@@ -1245,9 +1245,31 @@ static void GetFanSpeed(void)
 static void GetFanSpeedByFunction(void)
 {
     if (ShmDcCommonData->debugflag== YES) {
+        ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
         return;
     }
 
+    int gunIndex;
+    struct ChargingInfoData* pDcChargingInfo = NULL;
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
+        if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+            ShmDcCommonData->FanOnTime = time((time_t*)NULL);
+            if (ShmFanModuleData->SetFan1Speed == 0) {
+                ShmFanModuleData->SetFan1Speed = 7000;
+                log_info("Set Fan speed 7000");
+            }
+        }
+    }
+
+    if ((time((time_t*)NULL) - ShmDcCommonData->FanOnTime) >= 600 &&
+        ShmFanModuleData->SetFan1Speed == 7000) {
+        ShmFanModuleData->SetFan1Speed = 0;
+        log_info("Close fan");
+    }
+
+    /*
     // 風控修改 :
     // ******************************************************* //
     //
@@ -1305,6 +1327,7 @@ static void GetFanSpeedByFunction(void)
     if (ShmFanModuleData->TestFanSpeed < 0) {
         ShmFanModuleData->TestFanSpeed = 0;
     }
+    */
 //
 //  printf("power = %f \n", power);
 //  printf("_maxPower = %d \n", _maxPower);
@@ -1406,7 +1429,7 @@ static void fanBoardPorcess(void)
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
             //GetPsuTempForFanSpeed();
-            //GetFanSpeedByFunction();
+            GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
@@ -1688,15 +1711,6 @@ static void LEDBoardProcess(void)
     }
 
     if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-
-        //if (pSysConfig->TotalConnectorCount == 1) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
-        //} else if (pSysConfig->TotalConnectorCount == 2) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
-        //}
         if (time((time_t*)NULL) - ReservationFlashTimer >= 3) {
             ReservationFlashTimer = time((time_t*)NULL);
             if (ReservationLed)

+ 8 - 40
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -372,68 +372,36 @@ static void checkChillerStatus(Gpio_out *gpio)
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
         if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
-            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
-        {
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
             pChillerInfo->ChillerSwitch = YES;
             pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        }
-        else
-        {
-            if(pChillerInfo->ChillerSwitch == YES)
-            {
+        } else {
+            if(pChillerInfo->ChillerSwitch == YES) {
                 //10分鐘後停止
-                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600)
-                {
+                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
                     pChillerInfo->ChillerSwitch = NO;
-                    ShmFanModuleData->SetFan1Speed = 0;
-                }
-            }
-            else
-            {
-                pChillerInfo->ChillerSwitch = NO;
-            }
-        }
-#if 0
-        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
-            pChillerInfo->ChillerSwitch = YES;
-            pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        } else {
-            if (pChillerInfo->ChillerSwitch == YES) {
-                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) { //判斷如果還是大於100A不變動
-                    pChillerInfo->ChillerSwitch = YES;
-                    pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-                } else {
-                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) { //5分鐘後停止
-                        pChillerInfo->ChillerSwitch = NO;
-                    } else {
-                        pChillerInfo->ChillerSwitch = YES;
-                    }
                 }
             } else {
                 pChillerInfo->ChillerSwitch = NO;
             }
         }
-#endif
     }
 
     uint8_t _chillerNeedOn = NO;
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
-        if(pChillerInfo->ChillerSwitch == YES)
-        {
+        if(pChillerInfo->ChillerSwitch == YES) {
             _chillerNeedOn = YES;
-            if (chillerCount >= 2) {
-                ShmFanModuleData->SetFan1Speed = 7000;
-            }
         }
     }
 
+    /*
     if (ShmDcCommonData->debugflag == YES)
         _chillerNeedOn = ShmDcCommonData->chillerCtrl;
+    */
 
-    if(_chiller.ChillerSwitch != _chillerNeedOn)
-    {
+    if(_chiller.ChillerSwitch != _chillerNeedOn) {
         log_info("Chiller Need Turn %s", _chillerNeedOn == YES ? "ON" : "OFF");
     }
     _chiller.ChillerSwitch = _chillerNeedOn;

+ 1 - 0
EVSE/Projects/DD360Audi/Apps/ModulePsuComm/Module_PsuComm.c

@@ -180,6 +180,7 @@ unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
 
 void AbnormalStopAnalysis(byte gun_index, int errCode)
 {
+	DEBUG_INFO("Gun%d Erro Code:%s", gun_index, errCode);
 	for (char i = 0; i < 3; i++)
 	{
 		unsigned char byteIndex = (errCode >> (8 * i)) & 0xff;

+ 18 - 1
EVSE/Projects/DD360Audi/Apps/ModuleUpdateFW/Module_UpdateFW.c

@@ -185,6 +185,13 @@ static int InitCanBus(void)
     return fd;
 }
 
+unsigned long long getAvailableMemory()
+{
+    long pages = sysconf(_SC_AVPHYS_PAGES);
+    long page_size = sysconf(_SC_PAGE_SIZE);
+    return pages * page_size;
+}
+
 static int CheckUpdateProcess(void)
 {
     //bool isPass = true;
@@ -205,6 +212,13 @@ static int CheckUpdateProcess(void)
     DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     struct ChargingInfoData *pDcChargingInfo = NULL;
 
+
+    if (getAvailableMemory() < (200 * 1024 * 1024))
+    {
+        log_info("Available memory (%.2f Bytes) less than 200 MBytes, free cache first.\n", getAvailableMemory() / (1024 * 1024.0));
+        system("echo 3 > /proc/sys/vm/drop_caches");
+    }
+
     pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     d = opendir("/mnt/");
     if (d) {
@@ -243,6 +257,8 @@ static int CheckUpdateProcess(void)
                         ((unsigned int)ptr[19]));
                 log_info("Typed...%x ", Type);
 
+                free(ptr);
+
                 switch (Type) {
                 case 0x10000001:
                 case 0x10000002:
@@ -396,9 +412,10 @@ static int CheckUpdateProcess(void)
                     //return isPass;
                     break;
                 }
+            } else {
+                free(ptr);
             }
             free(new_str);
-            free(ptr);
         }
     }
     free(dir);

+ 10 - 4
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -342,6 +342,7 @@ void GetFwVerProc(void)
 
     printf("ModelName = %s\r\n", pSysConfig->ModelName);
     printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
+    printf("DC Main Debug Version = %s \n", ShmDcCommonData->DebugVersion);
     printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
     printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
     printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
@@ -781,7 +782,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARNIN]\n");
-
+                ShmFanModuleData->TestFanSpeed = 7000;
                 //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
                 printf ("wait find module\n");
 
@@ -939,7 +940,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 //無阻塞偵測 keybaord 結束
                 system(STTY_DEF TTY_PATH);
             }
-
+            pDcChargingInfo->ConnectorPlugIn = 0;
             pDcChargingInfo->SystemStatus = S_COMPLETE;
             break;
 
@@ -971,6 +972,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
             if (stopChg == pSysConfig->TotalConnectorCount) {
                 ShmDcCommonData->debugflag = NO;
+                ShmFanModuleData->TestFanSpeed = 0;
                 system("/root/Module_EvComm &");
                 sleep(3);
 
@@ -1127,16 +1129,20 @@ static void resdGunAndChillerTemp(void)
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
-                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
+                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d(%.3f), %3d(%.3f), %3d(%.3f), %3d(%.3f)\r\n",
                              i,
                              pDcChargingInfo->ConnectorTemp,
                              pDcChargingInfo->ChillerTemp,
                              ShmDcCommonData->ConnectorTemp[i][0],
                              ShmDcCommonData->ConnectorTemp[i][1],
                              ShmDcCommonData->SystemTemp[0],
+                             ShmDcCommonData->TempVolt[0],
                              ShmDcCommonData->SystemTemp[1],
+                             ShmDcCommonData->TempVolt[1],
                              ShmDcCommonData->SystemTemp[2],
-                             ShmDcCommonData->SystemTemp[3]);
+                             ShmDcCommonData->TempVolt[2],
+                             ShmDcCommonData->SystemTemp[3],
+                             ShmDcCommonData->TempVolt[3]);
             }//for
             ftime(&showTime);
         }

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c

@@ -98,7 +98,7 @@ static int isReachableInternet(void)
         while (fgets(buf, sizeof(buf), fp) != NULL) {
             if (strstr(buf, "inet addr:") > 0) {
                 sscanf(buf, "%*s%s", tmp);
-                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
+                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(tmp) - strspn(tmp, "addr:"));
 
                 if (strcmp(tmp, (char *)pSysConfig->Eth0Interface.EthIpAddress) != EQUAL) {
                     strcpy((char *) pSysConfig->Eth0Interface.EthIpAddress, tmp);

+ 3 - 3
EVSE/Projects/DD360ComBox/Apps/CSU/OCPP.c

@@ -422,7 +422,7 @@ void ocpp_chk_remoteStart_cmd()
                     ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                     //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
                     //ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
+                    DetectPluginStart(ac_index);
                     return;
                 }
                 ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
@@ -473,7 +473,7 @@ void ocpp_chk_remoteStart_cmd()
                 chargingInfo[dcIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                 //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
-                DetectPluginStart();
+                DetectPluginStart(dcIndex);
             }
             ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
         } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
@@ -481,7 +481,7 @@ void ocpp_chk_remoteStart_cmd()
                     chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
                 chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                DetectPluginStart();
+                DetectPluginStart(scheduleIndex);
             }
             chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
         }

+ 6 - 7
EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c

@@ -218,9 +218,8 @@ static void checkChargingInfoByDC(uint8_t systemStatus)
     switch (systemStatus) {
     case S_IDLE:
     case S_RESERVATION:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
+        if (isDetectPlugin(pSysInfo->CurGunSelected)) {
+            _DetectPlugInTimeout(pSysInfo->CurGunSelected);
             destroySelGun(pSysInfo->CurGunSelected);
             
         } else {
@@ -261,7 +260,8 @@ static void checkChargingInfoByDC(uint8_t systemStatus)
 
     case S_CHARGING:
         if (pSysConfig->StopChargingByButton == YES ||
-                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE ||
+                pSysConfig->isAuthrizeByEVCCID) {
             // 停止充電
             ChargingTerminalProcess(pSysInfo->CurGunSelected);
         }
@@ -286,9 +286,8 @@ static void checkChargingInfoByAC(void)
 
     switch (pAcChargingInfo->SystemStatus) {
     case S_IDLE:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
+        if (isDetectPlugin(pSysInfo->CurGunSelected)) {
+            _DetectPlugInTimeout(pSysInfo->CurGunSelected);
         }
         break;
 

+ 2 - 2
EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c

@@ -269,7 +269,7 @@ void ScannerCardProcess(void)
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
     ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
 
-    if (!isDetectPlugin() &&
+    if (!isDetectPlugin(pSysInfo->CurGunSelected) &&
             !isCardScan &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
@@ -325,7 +325,7 @@ void ScannerCardProcess(void)
     } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
         StartSystemTimeoutDet(Timeout_VerifyComp);
     } else if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
-        StartSystemTimeoutDet(Timeout_WaitPlug);
+        //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected, Timeout_WaitPlug);
     } else {
         isCardScan = false;
     }

+ 134 - 159
EVSE/Projects/DD360ComBox/Apps/CSU/main.c

@@ -83,13 +83,13 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.21.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "v1.21.5";
+char *fwVersion = "T1.21.00.0000.00"; // "V0.16.00.0000.00";
+char* DebugVersion = "T1.21.7";
 //sqlite3 *localDb;
 bool isDb_ready;
 
 //------------------------------------------------------------------------------
-void ClearDetectPluginFlag();
+void ClearDetectPluginFlag(int gunIndex);
 
 long long DiffTimebWithNow(struct timeb ST);
 uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
@@ -1273,11 +1273,12 @@ int Initialization(void)
     // 初始化卡號驗證的 Flag
     ClearAuthorizedFlag();
 
-    // 初始化插槍驗證的 Flag
-    ClearDetectPluginFlag();
+
 
     for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
+        // 初始化插槍驗證的 Flag
+        ClearDetectPluginFlag(count);
 
         pDcChargingInfo->RemoteStartFlag = NO;
 
@@ -1483,36 +1484,41 @@ bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
 //===============================================
 // 掃描插槍狀況
 //===============================================
-void ClearDetectPluginFlag(void)
+void ClearDetectPluginFlag(int gunIndex)
 {
-    uint8_t gunIndex = 0;
-    pSysInfo->WaitForPlugit = NO;
 
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
     //DS60-120 add
-    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-        if (pDcChargingInfo->RemoteStartFlag == YES) {
-            pDcChargingInfo->RemoteStartFlag = NO;
-        }
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+    if (pDcChargingInfo->RemoteStartFlag == YES) {
+        pDcChargingInfo->RemoteStartFlag = NO;
     }
 
+
     if (pSysInfo->OrderCharging != NO_DEFINE) {
         pSysInfo->OrderCharging = NO_DEFINE;
     }
 }
 
-void DetectPluginStart()
+void DetectPluginStart(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = YES;
+    //pSysInfo->WaitForPlugit = YES;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
+    log_info("Gun%d start detect plug in",gunIndex);
 }
 
-bool isDetectPlugin()
+bool isDetectPlugin(int gunIndex)
 {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
+        return true;
+    }
+    /*
     if (pSysInfo->WaitForPlugit == YES) {
         return true;
     }
-
+    */
     return false;
 }
 
@@ -1544,7 +1550,7 @@ bool isEvStopCharging_chademo(uint8_t gunIndex)
 {
     if (isEvGunLocked_chademo(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none (%d) ", gunIndex);
+        //log_info("gun locked none (%d) ", gunIndex);
         return YES;
     }
 
@@ -1575,7 +1581,7 @@ bool isEvStopCharging_gb(uint8_t gunIndex)
 {
     if (isEvGunLocked_gb(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none. ");
+        //log_info("gun locked none. ");
         return YES;
     }
 
@@ -1614,7 +1620,7 @@ bool isEvStopCharging_ccs(uint8_t gunIndex)
 {
     if (isEvGunLocked_ccs(gunIndex) == NO) {
         // 無鎖槍 = 停止
-        log_info("gun locked none. ");
+        //log_info("gun locked none. ");
         return YES;
     }
 
@@ -1656,13 +1662,29 @@ void DisplayChargingInfo()
     systemPageRestoreInit();
 }
 
-void _AutoReturnTimeout(void)
+void _AutoReturnTimeout(int gunIndex)
 {
     log_info("*********** _AutoReturnTimeout(%d) *********** ", pSysInfo->PageIndex);
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
-        ClearDetectPluginFlag();
+        
+        if (pDcChargingInfo->RemoteStartFlag) {
+            ClearDetectPluginFlag(gunIndex);
+        } else {
+            ClearDetectPluginFlag(0);
+            ClearDetectPluginFlag(1);
+        }
     } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
-        DetectPluginStart();
+        if (pDcChargingInfo->RemoteStartFlag) {
+            DetectPluginStart(gunIndex);
+        } else {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                DetectPluginStart(LEFT_GUN_NUM);
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                DetectPluginStart(RIGHT_GUN_NUM);
+        }
     }
 
     usleep(50000);
@@ -1696,18 +1718,39 @@ void _AuthorizedTimeout(void)
     }
 }
 
-void _DetectPlugInTimeout(void)
+void _DetectPlugInTimeout(int gunIndex)
 {
-    log_info("*********** _DetectPlugInTimeout *********** ");
     strcpy((char *)pSysConfig->UserId, "");
-    ClearDetectPluginFlag();
-
+    
+
+    uint8_t is_remote = NO;
+    for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+        if (pDcChargingInfo->RemoteStartFlag) {
+            //此停止為remote start停止
+            is_remote = YES;
+            break;
+        }
+    }
+    if (is_remote) {
+        // Remote start進入充電
+        log_info("Clear Gun%d Remote start detect plugin flag",gunIndex);
+        StopGunInfoTimeoutDet(gunIndex);
+        ClearDetectPluginFlag(gunIndex);
+    } else {
+        log_info("Clear Gun%d RFID detect plugin flag", gunIndex);
+        // 刷卡進入充電
+        ClearDetectPluginFlag(LEFT_GUN_NUM);
+        ClearDetectPluginFlag(RIGHT_GUN_NUM);
+        StopGunInfoTimeoutDet(LEFT_GUN_NUM);
+        StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
+    }
     sleep(1); //等待DoComm回報插槍訊號給主櫃
 #if defined DD360Audi
 	//pSysInfo->SystemPage = _LCM_COMPLETE;
-	setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
+	setChargerMode(gunIndex, S_TERMINATING);
 #elif DD360 || DD360Combox
- 	setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
+ 	setChargerMode(gunIndex, S_IDLE);
 #endif
     systemPageRestoreInit();
 }
@@ -1730,7 +1773,7 @@ void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
         }
     }
     ChargingTerminalProcess(gunIndex);
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
 }
 
 void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
@@ -1744,7 +1787,7 @@ void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
 #elif DD360 || DD360Combox
 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
 #endif
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
     }
 }
 
@@ -1758,7 +1801,7 @@ void _PrepareTimeout(uint8_t gunIndex)
 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
 #endif
     pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
-    _AutoReturnTimeout();
+    _AutoReturnTimeout(gunIndex);
 }
 
 void _CcsPrechargeTimeout(uint8_t gunIndex)
@@ -2769,6 +2812,7 @@ void StartSystemTimeoutDet(uint8_t flag)
 {
     if (pSysInfo->SystemTimeoutFlag != flag) {
         GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
+       //log_info("Start System Timeout: %d",flag);
     }
     pSysInfo->SystemTimeoutFlag = flag;
 }
@@ -2786,6 +2830,7 @@ void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
     if (gunIndex < pSysConfig->TotalConnectorCount) {
         if (pDcChargingInfo->TimeoutFlag != flag) {
             gettimeofday(&pDcChargingInfo->TimeoutTimer, NULL);
+            //log_info("Start Gun%d Info timeout: %d",gunIndex,flag);
         }
         pDcChargingInfo->TimeoutFlag = flag;
     }
@@ -2894,7 +2939,7 @@ void CreateTimeoutFork(void)
                 break;
             case Timeout_VerifyFail:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
-                    _AutoReturnTimeout();
+                    _AutoReturnTimeout(pSysInfo->CurGunSelected);
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
                     if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
@@ -2910,19 +2955,11 @@ void CreateTimeoutFork(void)
 
             case Timeout_VerifyComp:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
-                    _AutoReturnTimeout();
+                    _AutoReturnTimeout(pSysInfo->CurGunSelected);
                     StopSystemTimeoutDet();
                 }
                 break;
 
-            case Timeout_WaitPlug:
-                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
-                    _DetectPlugInTimeout();
-                    StopSystemTimeoutDet();
-                    destroySelGun(pSysInfo->CurGunSelected);
-                }
-                break;
-
             case Timeout_ReturnToChargingGunDet:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
 #if defined DD360Audi
@@ -2962,6 +2999,14 @@ void CreateTimeoutFork(void)
                 }
                 break;
 
+                case Timeout_WaitPlug:
+                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
+                        log_info("*********** Gun%d _DetectPlugInTimeout *********** ", gunIndex);
+                        _DetectPlugInTimeout(gunIndex);
+                        StopGunInfoTimeoutDet(gunIndex);
+                        destroySelGun(gunIndex);
+                    }
+                    break;
                 case Timeout_Preparing:
                     if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
                         _PrepareTimeout(gunIndex);
@@ -3192,35 +3237,36 @@ void OcppRemoteStartChk()
 {
     if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
 
-    } else if (!isDetectPlugin()) {
+    } else{
         // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
         uint8_t acDirIndex = pSysConfig->AcConnectorCount;
 
         for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
             pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(ac_index);
-
-            if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
-                if (pAcChargingInfo->SystemStatus == S_IDLE ||
+            if (!isDetectPlugin(acDirIndex)) {
+                if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
+                    if (pAcChargingInfo->SystemStatus == S_IDLE ||
                         pAcChargingInfo->SystemStatus == S_RESERVATION) {
+                        ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
+                        pAcChargingInfo->RemoteStartFlag = YES;
+                        pSysInfo->OrderCharging = YES;
+                        //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
+                        ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
+                        DetectPluginStart(acDirIndex);
+                        return;
+                    }
                     ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-                    pAcChargingInfo->RemoteStartFlag = YES;
-                    pSysInfo->OrderCharging = YES;
-                    //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
-                    ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
-                    return;
                 }
-                ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
             }
         }
-
+        
         uint8_t threeGunIndex = 0;
         uint8_t dcIndex = 0;
         bool isGunUsingStatus = false;
 
         for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
+            /*
             // 如果有 AC 槍,且 DC 槍也有兩把
             if (acDirIndex == 1 && _index == 1) {
                 threeGunIndex = 1;
@@ -3248,22 +3294,23 @@ void OcppRemoteStartChk()
         if (dcIndex == 0) {
             threeGunIndex = 0;
         }
+        */
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
 
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(dcIndex);
-
-        if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES) {
-            if (pDcChargingInfo->SystemStatus == S_IDLE ||
+            if (ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq == YES) {
+                if (pDcChargingInfo->SystemStatus == S_IDLE ||
                     pDcChargingInfo->SystemStatus == S_RESERVATION) {
-                pDcChargingInfo->RemoteStartFlag = YES;
-                pSysInfo->OrderCharging = YES;
-                //pSysInfo->OrderCharging = gunIndex;
-                ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-                DetectPluginStart();
+                    pDcChargingInfo->RemoteStartFlag = YES;
+                    pSysInfo->OrderCharging = YES;
+                    //pSysInfo->OrderCharging = gunIndex;
+                    ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
+                    DetectPluginStart(_index);
 #if defined DD360Audi
-                setSelGunWaitToAuthor(dcIndex); //Jerry add
+                    setSelGunWaitToAuthor(_index); //Jerry add
 #endif //defined DD360Audi
+                }
+                ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
             }
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
         }
     }
 }
@@ -4584,11 +4631,6 @@ int main(void)
         //確認Power cabinet PSU Status
         //powerCabinetPsuAlarmStatus();
 
-        if (pGunIndexInfo->AcGunIndex > 0 && isDetectPlugin() && !GetIsCardScan()) {
-            // AUDI_LCM_CHANGE
-            pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
-        }
-
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
             //CheckTask();
 
@@ -4645,6 +4687,14 @@ int main(void)
 
             ChkOcppStatus(gunIndex);
 
+            if (pGunIndexInfo->AcGunIndex > 0 &&
+                isDetectPlugin(gunIndex) &&
+                !GetIsCardScan() &&
+                gunIndex == pSysInfo->CurGunSelected) {
+                // AUDI_LCM_CHANGE
+                pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
+            }
+
             if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
                     pDcChargingInfo->SystemStatus <= S_CHARGING) ||
                     (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
@@ -4736,7 +4786,7 @@ int main(void)
                             systemPageRestoreInit();
                         }
                     }
-                    ClearDetectPluginFlag();
+                    ClearDetectPluginFlag(gunIndex);
 
                     if (pDcChargingInfo->SystemStatus != S_FAULT)
                     {
@@ -4776,13 +4826,8 @@ int main(void)
 
                 // Idle 正常程序起點
                 // 判斷是否有啟用檢查插槍
-                if (isDetectPlugin()) {
-                    /*
-                    if(pDcChargingInfo->Type == _Type_CCS_2 &&
-                            pSysConfig->isAuthrizeByEVCCID &&
-                            strcmp((char *)pDcChargingInfo->EVCCID,(char *)pSysConfig->UserId) != EQUAL )
-                        continue;
-                        */
+                if (isDetectPlugin(gunIndex)) {
+                    StartGunInfoTimeoutDet(gunIndex, Timeout_WaitPlug);
                     // 卡號驗證成功後,等待充電槍插入充電車
                     if (pDcChargingInfo->RemoteStartFlag == YES) {
                         if (pDcChargingInfo->ConnectorPlugIn == YES &&
@@ -4794,7 +4839,8 @@ int main(void)
                             AddPlugInTimes(gunIndex);
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             strcpy((char *)pDcChargingInfo->StartUserId, "");
-                            ClearDetectPluginFlag();
+                            ClearDetectPluginFlag(gunIndex);
+                            StopGunInfoTimeoutDet(gunIndex);
                             continue;
                         }
                     } else if (pSysInfo->OrderCharging == NO_DEFINE) {
@@ -4819,11 +4865,13 @@ int main(void)
                                      gunIndex,
                                      pDcChargingInfo->StartUserId);
                             strcpy((char *)pSysConfig->UserId, "");
-                            ShmDcCommonData->AuthroizeType = IdTokenType_ISO14443;
+                            ShmDcCommonData->AuthroizeType = IdTokenType_Central;
                             // 當前操作的槍號,進入 Preparing
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
-                            ClearDetectPluginFlag();
-
+                            ClearDetectPluginFlag(LEFT_GUN_NUM);
+                            ClearDetectPluginFlag(RIGHT_GUN_NUM);
+                            StopGunInfoTimeoutDet(LEFT_GUN_NUM);
+                            StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
                             continue;
                         }
                     }
@@ -4833,21 +4881,7 @@ int main(void)
                         // AUDI_LCM_CHANGE
                         pSysInfo->SystemPage = _LCM_WAIT_FOR_PLUG;
                     }
-                } /*else if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE &&
-                           (pDcChargingInfo->ConnectorPlugIn == YES &&
-                            pDcChargingInfo->IsAvailable)
-                          ) {
-                    log_info("-----------------3-----------------");
-
-                    if (GetStartChargingByAlterMode(gunIndex) == true) {
-                        ChangeGunSelectByIndex(gunIndex);
-                        AddPlugInTimes(gunIndex);
-                        setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
-                        ClearDetectPluginFlag();
-                        continue;
-                    }
-                } */
-                else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn && 
+                } else if (pSysConfig->isAuthrizeByEVCCID && pDcChargingInfo->ConnectorPlugIn && 
                         pSysInfo->CurGunSelected == gunIndex && !pDcChargingInfo->isEVCCIDVerify) {
                     systemPageRestoreInit();
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -4872,17 +4906,7 @@ int main(void)
                     gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
                 }
 
-                isRessign = NO;
-
-                if (distributionPsuModule(&isRessign, gunIndex) == YES) {
-                    continue;
-                }
-
-                if (isRessign == YES) {
-                    setChargerMode(gunIndex, MODE_REASSIGN);
-                } else {
-                    setChargerMode(gunIndex, MODE_PRECHARGE);
-                }
+                setChargerMode(gunIndex, S_PREPARNING);
 
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -4893,36 +4917,6 @@ int main(void)
             }
             break;
 
-            case S_REASSIGN:
-                if (isModeChange(gunIndex)) {
-                    log_info("============================= S_REASSIGN(%x) ============================= ", gunIndex);
-                    gettimeofday(&_toAverage_time, NULL);
-                }
-
-                // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
-                // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
-                if (pSysInfo->ReAssignedFlag == _REASSIGNED_NONE ||
-                        pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-                    if (pSysInfo->CanAverageCharging) {
-                        pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;//DS60-120 add
-                        setChargerMode(gunIndex, MODE_PRECHARGE);
-                    } else {
-                        setChargerMode(gunIndex, MODE_IDLE);
-                    }
-                    pSysInfo->ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 add
-                } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
-                           pSysInfo->BridgeRelayStatus == NO) {
-                    log_info("=============Smart Charging : _REASSIGNED_COMP============= Step 6 ");
-                    pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                    //pSysInfo->ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 remove
-                    pSysInfo->CanAverageCharging = true; //DS60-120 add
-                }
-
-                if (pSysInfo->CurGunSelected == gunIndex) {
-                    pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
-                }
-                break;
-
             case S_PREPARNING:
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_PREPARNING(%x) ============================= ", gunIndex);
@@ -4936,25 +4930,6 @@ int main(void)
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 
-                //DS60-120 add
-                if (pSysConfig->TotalConnectorCount >= 2) {
-                    bool oughtAver = true;
-                    for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                        pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(index);
-                        // 共同進入充電邏輯
-                        if (pDcChargingInfo->SystemStatus != S_PREPARNING) {
-                            oughtAver = false;
-                            break;
-                        }
-                    }
-
-                    if (oughtAver) {
-                        log_info("********* Automatically change to aver mode ********** ");
-                        pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                        pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
-                    }
-                }
-
                 checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
 
                 if (pSysInfo->CurGunSelected == gunIndex) {

+ 2 - 2
EVSE/Projects/DD360ComBox/Apps/CSU/main.h

@@ -65,8 +65,8 @@
 //} LedConfig;
 
 //------------------------------------------------------------------------------
-bool isDetectPlugin(void);
-void _DetectPlugInTimeout(void);
+bool isDetectPlugin(int gunIndex);
+void _DetectPlugInTimeout(int gunIndex);
 void _evccidlinktimeout(uint8_t gunIndex);
 void StartSystemTimeoutDet(uint8_t flag);
 void StopSystemTimeoutDet(void);

+ 1 - 0
EVSE/Projects/DD360ComBox/Apps/Config.h

@@ -418,6 +418,7 @@ typedef struct StGunInfo {
     char ChargeStopTime[32];
     char ChargeDuration[32];
     uint8_t withChiller;      //是否有水冷機
+    uint8_t WaitForPlugit;    // 等待插槍FLAG
 } GunInfo;
 
 typedef struct Psu_VersionInfo{

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/Define/define.h

@@ -6210,7 +6210,7 @@ struct OCPP20Data
 	struct UpdateFirmware_20					UpdateFirmware;
 	struct ChargingProfileType                  SmartChargingProfile[CONNECTOR_QUANTITY];
 	struct ChargingProfileType                  MaxChargingProfile;
-	struct StructSessionTarget	                SessionTarget[CONNECTOR_QUANTITY];
+	struct StructSessionTarget                  SessionTarget[CONNECTOR_QUANTITY];
 };
 
 

+ 25 - 20
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c

@@ -354,18 +354,22 @@ static void ClearAuthorizedFlag(void)
     pSysInfo->AuthorizeFlag = NO;
 }
 
-static void ClearDetectPluginFlag(void)
+static void ClearDetectPluginFlag(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = NO;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
 }
 
-static bool isDetectPlugin(void)
+static bool isDetectPlugin(int gunIndex)
 {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
+        return true;
+    }
+    /*
     if (pSysInfo->WaitForPlugit == YES) {
-        return YES;
+        return true;
     }
-
-    return NO;
+    */
+    return false;
 }
 
 static void destroySelectGun(uint8_t curGun)
@@ -526,7 +530,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     string2Date((char*)data, (uint8_t*)_setTime);
     //printf("SystemId =  %s", pSysConfig->SystemId);
     if (!timecmp(localTime, _setTime)) {
-        log_info("Set Timer:%s", _setTime);
+        //log_info("Set Timer:%s", _setTime);
         sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
         system((char*)cmdBuf);
         system("hwclock -w -u");
@@ -810,7 +814,8 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             strcpy((char *)pSysConfig->UserId, "");
-            pSysInfo->WaitForPlugit = NO;
+            //pSysInfo->WaitForPlugit = NO;
+            ClearDetectPluginFlag(plugNum);
 #ifdef DD360Audi
             pSysInfo->SystemPage = _LCM_SELECT_GUN;
 #endif
@@ -829,10 +834,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            if (isDetectPlugin() == YES) {
-                ClearDetectPluginFlag();
+            if (isDetectPlugin(plugNum) == YES) {
+                ClearDetectPluginFlag(plugNum);
                 strcpy((char *)pSysConfig->UserId, "");
-                pSysInfo->WaitForPlugit = NO;
 #ifdef DD360Audi
                 pSysInfo->SystemPage = _LCM_SELECT_GUN;
 #endif
@@ -1534,12 +1538,12 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun2_Consumption, (char*)&pValue->Gun2_Consumption, sizeof(uint32_t));
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun3_Consumption, (char*)&pValue->Gun3_Consumption, sizeof(uint32_t));
         memcpy((char*)&ShmDcCommonData->pConsumption.Gun4_Consumption, (char*)&pValue->Gun4_Consumption, sizeof(uint32_t));
-
+        /*
         log_info("Gun1_Consumption:%f", ShmDcCommonData->pConsumption.Gun1_Consumption);
         log_info("Gun2_Consumption:%f", ShmDcCommonData->pConsumption.Gun2_Consumption);
         log_info("Gun3_Consumption:%f", ShmDcCommonData->pConsumption.Gun3_Consumption);
         log_info("Gun4_Consumption:%f", ShmDcCommonData->pConsumption.Gun4_Consumption);
-        
+        */
         
         break;
         
@@ -1751,13 +1755,13 @@ static int readChargingTimeStamp(int fd, uint8_t id)
 
     return ret;
 }
-static int writeWaitPlugItState(int fd, uint8_t id)
+static int writeWaitPlugItState(int fd, uint8_t id, uint8_t gunIndex)
 {
     int ret = PASS;
-    uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-    if (_isplugin != pSysInfo->WaitForPlugit) {
-        log_info("Wait for plug:%s", pSysInfo->WaitForPlugit == 0 ? "disable" : "enable");
-        _isplugin = pSysInfo->WaitForPlugit;
+    uint8_t data[2] = { ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit, 0 };
+    if (_isplugin != ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit) {
+        //log_info("Wait Gun%d for plug:%s", gunIndex, ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin = ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit;
     }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
@@ -1927,7 +1931,7 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[15] = {'\0'};
+    uint8_t dataBuf[16] = {'\0'};
     uint32_t _consumption;
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
@@ -1937,6 +1941,7 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     pConnState->ConnectorTemp = pDcChargingInfo->ConnectorTemp;
     pConnState->ChillerTemp = pDcChargingInfo->ChillerTemp;
     pConnState->PlugIn = pDcChargingInfo->ConnectorPlugIn;
+    pConnState->ConnectMode = pDcChargingInfo->SystemStatus;
 
     if (pDcChargingInfo->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
@@ -2725,7 +2730,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
            ) {
-            writeWaitPlugItState(fd, gunID);
+            writeWaitPlugItState(fd, gunID, plugNum);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
         /*

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h

@@ -222,7 +222,7 @@ typedef struct StConnectorState {
     uint8_t ChillerTemp;
     uint8_t PlugIn;
     uint32_t consumption;
-    uint8_t Reserved[1];
+    uint8_t ConnectMode;
 } ConnectorState;
 
 typedef struct StConnectorIDTable {

+ 5 - 2
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCCS.c

@@ -17,6 +17,8 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
     struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    memset(code, '\n', sizeof(code));
+
 
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
         return;
@@ -751,8 +753,8 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
 
     if (isCleanCheck) {
         for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
             if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
                 log_info("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
                          index,
@@ -760,6 +762,7 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
                          code);
 
                 if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+
                     if (strncmp(code, "012219", 6) == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO; }
 
                     if (strncmp(code, "023701", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = NO; }
@@ -910,7 +913,7 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCHA.c

@@ -244,7 +244,7 @@ void ClearAbnormalStatus_Chademo(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalGBT.c

@@ -412,7 +412,7 @@ void ClearAbnormalStatus_GB(uint8_t gun_index)
             }
         }
     }
-
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gun_index);
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
     }

+ 36 - 29
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -34,7 +34,8 @@ uint8_t TempArray_2[TempArraySize]={0};
 uint8_t ptemp_1 = 0;
 uint8_t ptemp_2 = 0;
 bool firstcircule = true;
-
+float EvTargetVolt[2] = { 0 };
+float EvTargetCur[2] = { 0 };
 //------------------------------------------------------------------------------
 extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
 
@@ -333,19 +334,24 @@ void CANReceiver(int fd)
             for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
                 pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
                 // 檢查是否有收到EV小板訊號
-                if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 3) &&
-                    !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
-                    pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
-
-                    ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
-                    ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
-
-                    system("/sbin/ip link set can0 down");
-                    sleep(1);
-                    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-                    system("/sbin/ip link set can0 up");
+                if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+                    if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 5) &&
+                        !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
+                        pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
+
+                        ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
+                        ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
+
+                        system("/sbin/ip link set can0 down");
+                        sleep(1);
+                        system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+                        system("/sbin/ip link set can0 up");
+                    }
+                    CheckEvConnect(_index);
+                } else {
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
                 }
-                CheckEvConnect(_index);
             }
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -438,22 +444,15 @@ void CANReceiver(int fd)
                         pSysInfo->CurGunSelected = targetGun;
                     }
                 }
-                // CCS 小板確認拔除三秒
-                if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (frame.data[0] == UNPLUG) {
-                        if ((time((time_t*)NULL) - CCS_PlugoutTimer[targetGun]) > 3) {
-                            if (pDcChargingInfo->ConnectorPlugIn != frame.data[0])
-                                log_info("CCS Conn %d, Unplug. ", targetGun);
-                        } else {
-                            frame.data[0] = PLUG;
-                        }
-                    } else {
-                        CCS_PlugoutTimer[targetGun] = time((time_t*)NULL);
-                        frame.data[0] = PLUG;
-                    }
-                }
-                pDcChargingInfo->ConnectorPlugIn = frame.data[0];
                 pDcChargingInfo->PilotVoltage = frame.data[1];
+                // CCS 小板確認Pilot Voltage != 0
+                if (pDcChargingInfo->Type == _Type_CCS_2 && pDcChargingInfo->PilotVoltage != 0) {
+                    if (frame.data[0] == UNPLUG && pDcChargingInfo->ConnectorPlugIn != frame.data[0])
+                        log_info("Conn %d, Unplug. ", targetGun);
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                } else {
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                }
 
                 //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x ",
                 //         targetGun,
@@ -576,7 +575,15 @@ void CANReceiver(int fd)
                         ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
                 }
-
+                if (pDcChargingInfo->EvBatterytargetVoltage > (EvTargetVolt[targetGun] + 5) ||
+                    pDcChargingInfo->EvBatterytargetVoltage < (EvTargetVolt[targetGun] - 5) ||
+                    pDcChargingInfo->EvBatterytargetCurrent >(EvTargetCur[targetGun] + 2) ||
+                    pDcChargingInfo->EvBatterytargetCurrent < (EvTargetCur[targetGun] - 2)) {
+                    log_info("Gun%d TargetVoltage = %f , TargetCurrent = %f",
+                        targetGun, pDcChargingInfo->EvBatterytargetVoltage, pDcChargingInfo->EvBatterytargetCurrent);
+                    EvTargetVolt[targetGun] = pDcChargingInfo->EvBatterytargetVoltage;
+                    EvTargetCur[targetGun] = pDcChargingInfo->EvBatterytargetCurrent;
+                }
                 //log_info("EvBatterytargetVoltage = %f ", pDcChargingInfo->EvBatterytargetVoltage);
                 //log_info("EvBatterytargetCurrent = %f ", pDcChargingInfo->EvBatterytargetCurrent);
                 //log_info("BatteryVoltage = %d ",

+ 5 - 8
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -546,13 +546,11 @@ static void SetPresentChargingOutputPower(void)
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) ||
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
        ) {
-        log_info("G1->Out Vol(%s)=%.1f,Out Cur=%.1f - G2->Out Vol(%s) = %.1f, Out Cur = %.1f",
-                 isPsuVol1 == true ? "P" : "R",
-                 vol1 / 10,
-                 cur1 / 10,
-                 isPsuVol2 == true ? "P" : "R",
-                 vol2 / 10,
-                 cur2 / 10);
+        log_info("G1-> Vol=%.1f, Cur=%.1f - G2-> Vol = %.1f, Cur = %.1f",
+            vol1 / 10,
+            cur1 / 10,
+            vol2 / 10,
+            cur2 / 10);
 
         LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
         LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
@@ -815,7 +813,6 @@ int main(int argc, char *argv[])
                     }
                 } else if (pDcChargingInfo->Type == _Type_CCS_2) {
                     ClearAbnormalStatus_CCS(gunIndex);
-
                     if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO) {
                         pDcChargingInfo->StopChargeFlag = NO;
                     }

+ 0 - 9
EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c

@@ -1688,15 +1688,6 @@ static void LEDBoardProcess(void)
     }
 
     if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-
-        //if (pSysConfig->TotalConnectorCount == 1) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
-        //} else if (pSysConfig->TotalConnectorCount == 2) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
-        //}
         if (time((time_t*)NULL) - ReservationFlashTimer >= 3) {
             ReservationFlashTimer = time((time_t*)NULL);
             if (ReservationLed)

+ 1 - 0
EVSE/Projects/DD360ComBox/Apps/ModulePsuComm/Module_PsuComm.c

@@ -180,6 +180,7 @@ unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
 
 void AbnormalStopAnalysis(byte gun_index, int errCode)
 {
+	DEBUG_INFO("Gun%d Erro Code:%s", gun_index, errCode);
 	for (char i = 0; i < 3; i++)
 	{
 		unsigned char byteIndex = (errCode >> (8 * i)) & 0xff;

二進制
EVSE/rootfs/root/Module_Payment_Bazel8