Browse Source

2022-06-29 / Simon Xue

Simon Xue 2 years ago
parent
commit
7fd32b8b14
64 changed files with 675 additions and 738 deletions
  1. 1 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. 134 159
      EVSE/Projects/DD360/Apps/CSU/main.c
  6. 2 2
      EVSE/Projects/DD360/Apps/CSU/main.h
  7. 1 0
      EVSE/Projects/DD360/Apps/Config.h
  8. 1 1
      EVSE/Projects/DD360/Apps/Define/define.h
  9. 25 20
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  10. 1 1
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  11. 5 2
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCCS.c
  12. 1 1
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCHA.c
  13. 1 1
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalGBT.c
  14. 36 29
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  15. 5 8
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  16. 0 9
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  17. 1 0
      EVSE/Projects/DD360/Apps/ModulePsuComm/Module_PsuComm.c
  18. BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  19. BIN
      EVSE/Projects/DD360/output/FactoryConfig
  20. BIN
      EVSE/Projects/DD360/output/Module_ChkSysTask
  21. BIN
      EVSE/Projects/DD360/output/Module_DoComm
  22. BIN
      EVSE/Projects/DD360/output/Module_EvComm
  23. BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  24. BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  25. BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  26. BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  27. BIN
      EVSE/Projects/DD360/output/Module_UpdateFW
  28. BIN
      EVSE/Projects/DD360/output/ReadCmdline
  29. BIN
      EVSE/Projects/DD360/output/main
  30. 1 1
      EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c
  31. 3 3
      EVSE/Projects/DD360Audi/Apps/CSU/OCPP.c
  32. 6 7
      EVSE/Projects/DD360Audi/Apps/CSU/Primary.c
  33. 2 2
      EVSE/Projects/DD360Audi/Apps/CSU/RFID.c
  34. 134 159
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  35. 2 2
      EVSE/Projects/DD360Audi/Apps/CSU/main.h
  36. 1 0
      EVSE/Projects/DD360Audi/Apps/Config.h
  37. 1 1
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  38. 25 20
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  39. 1 1
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  40. 5 2
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCCS.c
  41. 1 1
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCHA.c
  42. 1 1
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalGBT.c
  43. 36 29
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  44. 5 8
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  45. 0 9
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  46. 1 0
      EVSE/Projects/DD360Audi/Apps/ModulePsuComm/Module_PsuComm.c
  47. 1 1
      EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c
  48. 3 3
      EVSE/Projects/DD360ComBox/Apps/CSU/OCPP.c
  49. 6 7
      EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c
  50. 2 2
      EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c
  51. 134 159
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  52. 2 2
      EVSE/Projects/DD360ComBox/Apps/CSU/main.h
  53. 1 0
      EVSE/Projects/DD360ComBox/Apps/Config.h
  54. 1 1
      EVSE/Projects/DD360ComBox/Apps/Define/define.h
  55. 25 20
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c
  56. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h
  57. 5 2
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCCS.c
  58. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCHA.c
  59. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalGBT.c
  60. 36 29
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c
  61. 5 8
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c
  62. 0 9
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c
  63. 1 0
      EVSE/Projects/DD360ComBox/Apps/ModulePsuComm/Module_PsuComm.c
  64. BIN
      EVSE/rootfs/root/Module_Payment_Bazel8

+ 1 - 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);

+ 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;
     }

+ 134 - 159
EVSE/Projects/DD360/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/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);

+ 1 - 0
EVSE/Projects/DD360/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/DD360/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/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);
     }

+ 36 - 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);
 
@@ -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/DD360/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/DD360/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/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;

BIN
EVSE/Projects/DD360/Images/ramdisk.gz


BIN
EVSE/Projects/DD360/output/FactoryConfig


BIN
EVSE/Projects/DD360/output/Module_ChkSysTask


BIN
EVSE/Projects/DD360/output/Module_DoComm


BIN
EVSE/Projects/DD360/output/Module_EvComm


BIN
EVSE/Projects/DD360/output/Module_EventLogging


BIN
EVSE/Projects/DD360/output/Module_InternalComm


BIN
EVSE/Projects/DD360/output/Module_LcmControl


BIN
EVSE/Projects/DD360/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360/output/Module_UpdateFW


BIN
EVSE/Projects/DD360/output/ReadCmdline


BIN
EVSE/Projects/DD360/output/main


+ 1 - 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);

+ 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;
     }

+ 134 - 159
EVSE/Projects/DD360Audi/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/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);

+ 1 - 0
EVSE/Projects/DD360Audi/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/DD360Audi/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/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);
     }

+ 36 - 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);
 
@@ -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/DD360Audi/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/DD360Audi/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/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;

+ 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;

BIN
EVSE/rootfs/root/Module_Payment_Bazel8