Преглед на файлове

2021.06.25 / Jerry Wang

Actions:
1. ReadCmdLine.c add support two gun test charging function.
2. Add dispenser wait for power cabinet permission to enter charging.
3. Debug Module_RateCurrent.c lost gun type issue.
4. DoComm writeConnectorState() add ConnectorTemp and ChillerTemp field.
5. FactoryConfig issue fiexed.
6. Debug DD360 two gun test charging issue.
7. Release to V1.09. DD360 V1.09 with DO360 V1.00.

Files:
1. As follow as commit history.
Jerry_Wang преди 3 години
родител
ревизия
ec5a860b7d
променени са 100 файла, в които са добавени 4580 реда и са изтрити 2741 реда
  1. 10 3
      EVSE/Modularization/Module_RatedCurrent.c
  2. 4 0
      EVSE/Projects/DD360/Apps/CSU/Ethernet.c
  3. 108 8
      EVSE/Projects/DD360/Apps/CSU/Primary.c
  4. 272 234
      EVSE/Projects/DD360/Apps/CSU/RFID.c
  5. 143 135
      EVSE/Projects/DD360/Apps/CSU/SelfTest.c
  6. 5 1
      EVSE/Projects/DD360/Apps/CSU/UpgradeFW.c
  7. 454 222
      EVSE/Projects/DD360/Apps/CSU/main.c
  8. 32 31
      EVSE/Projects/DD360/Apps/CSU/main.h
  9. 17 4
      EVSE/Projects/DD360/Apps/Config.h
  10. 84 13
      EVSE/Projects/DD360/Apps/DataBase/DataBase.c
  11. 9 0
      EVSE/Projects/DD360/Apps/DataBase/DataBase.h
  12. 10 0
      EVSE/Projects/DD360/Apps/DebugLog.md
  13. 4 4
      EVSE/Projects/DD360/Apps/Define/define.h
  14. 81 18
      EVSE/Projects/DD360/Apps/FactoryConfig.c
  15. 14 6
      EVSE/Projects/DD360/Apps/Makefile
  16. 81 76
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  17. 3 1
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  18. 6 3
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalState.c
  19. 9 9
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.c
  20. 9 9
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.h
  21. 50 40
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  22. 61 47
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  23. 7 3
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  24. 25 25
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c
  25. 168 136
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  26. 10 0
      EVSE/Projects/DD360/Apps/Script/SearchIP.sh
  27. 2 0
      EVSE/Projects/DD360/Apps/Script/init.sh
  28. 4 4
      EVSE/Projects/DD360/Apps/Script/replaceOtherDD360Project.sh
  29. 2 1
      EVSE/Projects/DD360/Apps/SelectGun/SelectGun.h
  30. 14 0
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c
  31. 18 15
      EVSE/Projects/DD360/Apps/timeout.h
  32. BIN
      EVSE/Projects/DD360/Images/FactoryDefaultConfig.bin
  33. BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  34. 3 0
      EVSE/Projects/DD360/ModelNameList.txt
  35. BIN
      EVSE/Projects/DD360/output/FactoryConfig
  36. BIN
      EVSE/Projects/DD360/output/Module_DoComm
  37. BIN
      EVSE/Projects/DD360/output/Module_EvComm
  38. BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  39. BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  40. BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  41. BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  42. BIN
      EVSE/Projects/DD360/output/ReadCmdline
  43. 10 0
      EVSE/Projects/DD360/output/SearchIP.sh
  44. 2 0
      EVSE/Projects/DD360/output/init.sh
  45. BIN
      EVSE/Projects/DD360/output/main
  46. 4 0
      EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c
  47. 108 8
      EVSE/Projects/DD360Audi/Apps/CSU/Primary.c
  48. 272 234
      EVSE/Projects/DD360Audi/Apps/CSU/RFID.c
  49. 143 135
      EVSE/Projects/DD360Audi/Apps/CSU/SelfTest.c
  50. 5 1
      EVSE/Projects/DD360Audi/Apps/CSU/UpgradeFW.c
  51. 454 222
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  52. 32 31
      EVSE/Projects/DD360Audi/Apps/CSU/main.h
  53. 17 4
      EVSE/Projects/DD360Audi/Apps/Config.h
  54. 84 13
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c
  55. 9 0
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.h
  56. 10 0
      EVSE/Projects/DD360Audi/Apps/DebugLog.md
  57. 4 4
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  58. 81 18
      EVSE/Projects/DD360Audi/Apps/FactoryConfig.c
  59. 14 6
      EVSE/Projects/DD360Audi/Apps/Makefile
  60. 81 76
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  61. 3 1
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  62. 6 3
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalState.c
  63. 9 9
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.c
  64. 9 9
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.h
  65. 50 40
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  66. 61 47
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  67. 7 3
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  68. 25 25
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c
  69. 168 136
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  70. 10 0
      EVSE/Projects/DD360Audi/Apps/Script/SearchIP.sh
  71. 2 0
      EVSE/Projects/DD360Audi/Apps/Script/init.sh
  72. 4 4
      EVSE/Projects/DD360Audi/Apps/Script/replaceOtherDD360Project.sh
  73. 2 1
      EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.h
  74. 14 0
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c
  75. 18 15
      EVSE/Projects/DD360Audi/Apps/timeout.h
  76. BIN
      EVSE/Projects/DD360Audi/Images/FactoryDefaultConfig.bin
  77. BIN
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  78. 3 0
      EVSE/Projects/DD360Audi/ModelNameList.txt
  79. BIN
      EVSE/Projects/DD360Audi/output/FactoryConfig
  80. BIN
      EVSE/Projects/DD360Audi/output/Module_DoComm
  81. BIN
      EVSE/Projects/DD360Audi/output/Module_EvComm
  82. BIN
      EVSE/Projects/DD360Audi/output/Module_EventLogging
  83. BIN
      EVSE/Projects/DD360Audi/output/Module_FactoryConfig
  84. BIN
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  85. BIN
      EVSE/Projects/DD360Audi/output/Module_LcmControl
  86. BIN
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  87. BIN
      EVSE/Projects/DD360Audi/output/ReadCmdline
  88. 10 0
      EVSE/Projects/DD360Audi/output/SearchIP.sh
  89. 2 0
      EVSE/Projects/DD360Audi/output/init.sh
  90. BIN
      EVSE/Projects/DD360Audi/output/main
  91. 4 0
      EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c
  92. 108 8
      EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c
  93. 272 234
      EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c
  94. 143 135
      EVSE/Projects/DD360ComBox/Apps/CSU/SelfTest.c
  95. 5 1
      EVSE/Projects/DD360ComBox/Apps/CSU/UpgradeFW.c
  96. 454 222
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  97. 32 31
      EVSE/Projects/DD360ComBox/Apps/CSU/main.h
  98. 17 4
      EVSE/Projects/DD360ComBox/Apps/Config.h
  99. 84 13
      EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.c
  100. 9 0
      EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.h

+ 10 - 3
EVSE/Modularization/Module_RatedCurrent.c

@@ -16,9 +16,9 @@
 #define PASS                                    (1)
 #define FAIL                                    (-1)
 
-#define log_info(format, args...)               StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...)               StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...)              StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 static SymStruct modelTable[] = {
@@ -80,6 +80,13 @@ static SymStruct gunTypeTable[] = {
     {"E", GUN_TYPE_E},
     {"F", GUN_TYPE_F},
     {"G", GUN_TYPE_G},
+    {"T", GUN_TYPE_T},
+    {"D", GUN_TYPE_D},
+    {"K", GUN_TYPE_K},
+    {"M", GUN_TYPE_M},
+    {"N", GUN_TYPE_N},
+    {"P", GUN_TYPE_P},
+    {"R", GUN_TYPE_R},
 };
 
 //------------------------------------------------------------------------------

+ 4 - 0
EVSE/Projects/DD360/Apps/CSU/Ethernet.c

@@ -106,6 +106,7 @@ static int isReachableInternet(void)
             }
         }
     }
+
     pclose(fp);
 
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
@@ -119,6 +120,7 @@ static int isReachableInternet(void)
 #endif //defined DD360 || defined DD360Audi
 
     memset(buf, 0x00, sizeof(buf));
+
     for (idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
         sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
         fp = popen(cmd, "r");
@@ -175,6 +177,7 @@ void InitEthernet(void)
     system(tmpbuf);
     //system("ifconfig lo up");
     //  /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
+
     //Init Eth1 for administrator tool
     memset(tmpbuf, 0, 256);
     sprintf(tmpbuf, "/sbin/ifconfig eth1 %s netmask %s up",
@@ -202,6 +205,7 @@ void InitEthernet(void)
     pid_t pid = fork();
     if (pid == 0) {
         log_info("InitEthernet = %d\r\n", pid);
+
         for (;;) {
 #if defined DD360 || defined DD360Audi || defined DD360ComBox
             isReachableInternet();

+ 108 - 8
EVSE/Projects/DD360/Apps/CSU/Primary.c

@@ -54,7 +54,6 @@ void PrimaryLedIndicatorCtrlFork(void)
         struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
         struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
         struct ChargingInfoData *pDcChargingInfo = NULL;
-        DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
         LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
 
@@ -62,7 +61,7 @@ void PrimaryLedIndicatorCtrlFork(void)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-                if (pSysWarning->Level == 2) {
+                if (pSysWarning->Level == WARN_LV_ER) {
                     if (checkCabinetEthConnectState(pLedConfig) == YES) {
                         usleep(500000);
                         continue;
@@ -147,7 +146,7 @@ void PrimaryLedIndicatorCtrlFork(void)
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    //if (pSysWarning->Level == 2) {
+                    //if (pSysWarning->Level == WARN_LV_ER) {
                     //    pLedConfig->YellowLED = NO;
                     //    pLedConfig->GreenLED = NO;
                     //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
@@ -166,7 +165,7 @@ void PrimaryLedIndicatorCtrlFork(void)
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
                     pLedConfig->RedLED = YES;
-                    //if (pSysWarning->Level == 2) {
+                    //if (pSysWarning->Level == WARN_LV_ER) {
                     //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
                     //        break;
                     //    }
@@ -187,23 +186,121 @@ void PrimaryLedIndicatorCtrlFork(void)
 }
 
 //------------------------------------------------------------------------------
+static void checkChargingInfoByDC(uint8_t systemStatus)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    switch (systemStatus) {
+    case S_IDLE:
+        if (isDetectPlugin()) {
+            _DetectPlugInTimeout();
+            StopSystemTimeoutDet();
+            destroySelGun(pSysInfo->CurGunSelected);
+        } else {
+#if !defined DD360Audi
+            break;
+#endif //!defined DD360Audi
+
+            if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
+                //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
+                destroySelGun(pSysInfo->CurGunSelected);
+            } else {
+                confirmSelGun(pSysInfo->CurGunSelected);
+                log_info("confirm select gun ............................... %d \n",
+                         pSysInfo->CurGunSelected);
+            }
+        }
+        break;
+
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+    case S_PREPARING_FOR_EVSE:
+    case S_CCS_PRECHARGE_ST0:
+    case S_CCS_PRECHARGE_ST1:
+        // 取消充電
+        if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+            AcChargingTerminalProcess();
+        } else {
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+        }
+        break;
+
+    case S_CHARGING:
+        if (pSysConfig->StopChargingByButton == YES ||
+                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+            // 停止充電
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+        }
+        break;
+
+    case S_COMPLETE:
+        break;
+    }
+}
+
+static void checkChargingInfoByAC(void)
+{
+    struct ChargingInfoData *pAcChargingInfo = NULL;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    if (pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
+        return;
+    }
+
+    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    switch (pAcChargingInfo->SystemStatus) {
+    case S_IDLE:
+        if (isDetectPlugin()) {
+            _DetectPlugInTimeout();
+            StopSystemTimeoutDet();
+        }
+        break;
+
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+    case S_PREPARING_FOR_EVSE:
+    case S_CCS_PRECHARGE_ST0:
+    case S_CCS_PRECHARGE_ST1:
+        // 取消充電
+        AcChargingTerminalProcess();
+        break;
+
+    case S_CHARGING:
+        if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+            // 停止充電
+            AcChargingTerminalProcess();
+        }
+        break;
+
+    case S_COMPLETE:
+        break;
+    }
+}
+
 void ChkPrimaryStatus(void)
 {
     static bool leftBtnPush = false;
     static bool rightBtnPush = false;
-    uint8_t Rtn;
+    uint8_t i = 0;
+    uint8_t Rtn = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
     struct ChargingInfoData *pDcChargingInfo = NULL;
-    struct ChargingInfoData *pAcChargingInfo = NULL;
     DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
     if (pSysWarning->WarningCount > 0) {
         Rtn = 0;
-        for (uint8_t i = 0; i < pSysWarning->WarningCount; i++) {
+        for (i = 0; i < pSysWarning->WarningCount; i++) {
             if (memcmp(&pSysWarning->WarningCode[i][0], "042251", 6) == 0) {
                 EmcOccureByString("042251");
                 ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = YES;
@@ -315,6 +412,9 @@ void ChkPrimaryStatus(void)
             leftBtnPush = true;
             log_info("left btn down...............................%x\n",
                      pDcChargingInfo->SystemStatus);
+            checkChargingInfoByAC();
+            checkChargingInfoByDC(pDcChargingInfo->SystemStatus);
+#if 0
             if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
                 pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
@@ -348,7 +448,6 @@ void ChkPrimaryStatus(void)
                     break;
                 }
             }
-
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
                 if (isDetectPlugin()) {
@@ -399,6 +498,7 @@ void ChkPrimaryStatus(void)
                 //pDcChargingInfo->SystemStatus = S_IDLE;
                 break;
             }
+#endif //0
         }
     } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
         if (leftBtnPush) {

+ 272 - 234
EVSE/Projects/DD360/Apps/CSU/RFID.c

@@ -32,17 +32,75 @@ static bool canStartCharging(void)
     // 因為無法得知實際的長度,所以只能用搜尋的方式
     if (strcmp(buf2, "Accepted") == EQUAL) {
         return true;
-    } else {
-
     }
 
     return false;
 }
 
+static void isAutorCompleteHandle(uint8_t *authorizeIndex)
+{
+    uint8_t i = 0;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+
+    // 透過後臺停止充電的判斷
+    if (isAuthorizedComplete()
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            || (pSysInfo->OcppConnStatus == NO &&
+                pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+#endif //!defined DD360 && !defined DD360Audi
+       ) {
+
+        // 判斷後台回覆狀態
+        if (canStartCharging() == false) {
+            strcpy((char *)pSysConfig->UserId, "");
+            ClearAuthorizedFlag();
+
+            return;
+        }
+
+        if (*(authorizeIndex) != NO_DEFINE) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(*(authorizeIndex));
+
+            if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
+                    strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
+                // 先找 AC
+                if (*(authorizeIndex) == DEFAULT_AC_INDEX) {
+                    AcChargingTerminalProcess();
+                } else {
+                    ChargingTerminalProcess(*(authorizeIndex));
+                }
+            }
+
+            strcpy((char *)pSysConfig->UserId, "");
+            *(authorizeIndex) = NO_DEFINE;
+        }
+
+        ClearAuthorizedFlag();
+    } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
+        // 白名單驗證
+        for (i = 0; i < 10; i++) {
+            if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
+                continue;
+            }
+
+            if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
+                ChargingTerminalProcess(*(authorizeIndex));
+                strcpy((char *)pSysConfig->UserId, "");
+                ClearAuthorizedFlag();
+
+                break;
+            }
+        }
+    }
+}
+
 static void UserScanFunction(void)
 {
     bool idleReq = false;
+    uint8_t i = 0;
     uint8_t stopReq = NO_DEFINE;
+    char value[32] = {0};
     static uint8_t _authorizeIndex = NO_DEFINE;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -51,164 +109,138 @@ static void UserScanFunction(void)
     GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
     // 當前非驗證的狀態
-    if (!IsAuthorizingMode()) {
-#if defined DD360Audi
-        //當前沒有選槍
-        if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) { //Jerry add
-            strcpy((char *)pSysConfig->UserId, "");
-            return;
+    if (IsAuthorizingMode()) {
+        isAutorCompleteHandle(&_authorizeIndex);
+    }
+
+    //當前沒有選槍
+    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) {
+        strcpy((char *)pSysConfig->UserId, "");
+        return;
+    }
+
+    // 先判斷現在是否可以提供刷卡
+    // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
+    // 2. 停止充電
+    if (pSysInfo->PageIndex == _LCM_FIX) {
+        strcpy((char *)pSysConfig->UserId, "");
+        return;
+    }
+
+    for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+        if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+            stopReq = i;
         }
-#endif //defined DD360Audi
 
-        // 先判斷現在是否可以提供刷卡
-        // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
-        // 2. 停止充電
-        if (pSysInfo->PageIndex == _LCM_FIX) {
-            strcpy((char *)pSysConfig->UserId, "");
-            return;
+        if ((pDcChargingInfo->SystemStatus == S_IDLE &&
+                pDcChargingInfo->IsAvailable == YES) ||
+                (pGunIndexInfo->AcGunIndex > 0 &&
+                 pAcChargingInfo->SystemStatus == S_IDLE &&
+                 pAcChargingInfo->IsAvailable)
+           ) {
+            idleReq = true;
         }
+    }
 
-        for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+    if (pGunIndexInfo->AcGunIndex > 0 &&
+            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
+            pAcChargingInfo->SystemStatus == S_CHARGING) {
+        stopReq = DEFAULT_AC_INDEX;
+    }
 
-            if (pDcChargingInfo->SystemStatus == S_CHARGING) {
-                stopReq = i;
-            }
-            if ((pDcChargingInfo->SystemStatus == S_IDLE &&
-                    pDcChargingInfo->IsAvailable) == YES ||
-                    (pGunIndexInfo->AcGunIndex > 0 && pAcChargingInfo->SystemStatus ==
-                     S_IDLE && pAcChargingInfo->IsAvailable)
-               ) {
-                idleReq = true;
-            }
+    if (strlen((char *)pSysConfig->UserId) <= 0) {
+        return;
+    }
+
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+
+    if (pGunIndexInfo->AcGunIndex > 0 &&
+            stopReq == DEFAULT_AC_INDEX &&
+            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
+        log_info("ac stop charging \n");
+        log_info("index = %d, card number = %s, UserId = %s \n",
+                 pSysInfo->CurGunSelectedByAc,
+                 pAcChargingInfo->StartUserId,
+                 pSysConfig->UserId);
+
+        memset(value, 0, sizeof(value));
+        memcpy(value,
+               (uint8_t *)pAcChargingInfo->StartUserId,
+               ARRAY_SIZE(pAcChargingInfo->StartUserId));
+        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
+            AcChargingTerminalProcess();
         }
+        strcpy((char *)pSysConfig->UserId, "");
+    } else if (stopReq < pSysConfig->TotalConnectorCount &&
+               pDcChargingInfo->SystemStatus == S_CHARGING &&
+               (pGunIndexInfo->AcGunIndex <= 0 ||
+                (pGunIndexInfo->AcGunIndex > 0 &&
+                 pSysInfo->CurGunSelectedByAc == NO_DEFINE))
+              ) {
+        log_info("stop charging \n");
+        log_info("index = %d, card number = %s, UserId = %s \n",
+                 pSysInfo->CurGunSelected,
+                 pDcChargingInfo->StartUserId,
+                 pSysConfig->UserId);
+
+        memset(value, 0, sizeof(value));
+        memcpy(value,
+               (uint8_t *)pDcChargingInfo->StartUserId,
+               ARRAY_SIZE(pDcChargingInfo->StartUserId));
+
+        // 同一張卡直接停掉
+        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+            strcpy((char *)pSysConfig->UserId, "");
 
-        if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-                pAcChargingInfo->SystemStatus == S_CHARGING) {
-            stopReq = DEFAULT_AC_INDEX;
+            return;
         }
 
-        if (strlen((char *)pSysConfig->UserId) > 0) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+        // 進驗證
+        if (pGunIndexInfo->AcGunIndex > 0 &&
+                pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
+            _authorizeIndex = pSysInfo->CurGunSelectedByAc;
+        } else {
+            _authorizeIndex = pSysInfo->CurGunSelected;
+        }
 
-            if (pGunIndexInfo->AcGunIndex > 0 && stopReq == DEFAULT_AC_INDEX &&
-                    pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                char value[32];
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+        strcpy((char *)pSysConfig->UserId, "");
 
-                log_info("ac stop charging \n");
-                log_info("index = %d, card number = %s, UserId = %s \n", pSysInfo->CurGunSelectedByAc,
-                         pAcChargingInfo->StartUserId, pSysConfig->UserId);
-                memcpy(value, (uint8_t *)pAcChargingInfo->StartUserId,
-                       ARRAY_SIZE(pAcChargingInfo->StartUserId));
-                if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-                    AcChargingTerminalProcess();
-                }
-                strcpy((char *)pSysConfig->UserId, "");
-            } else if (stopReq < pSysConfig->TotalConnectorCount &&
-                       pDcChargingInfo->SystemStatus == S_CHARGING &&
-                       (pGunIndexInfo->AcGunIndex <= 0 || (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == NO_DEFINE))) {
-                char value[32];
-
-                log_info("stop charging \n");
-                log_info("index = %d, card number = %s, UserId = %s \n",
-                         pSysInfo->CurGunSelected,
-                         pDcChargingInfo->StartUserId,
-                         pSysConfig->UserId);
-                memcpy(value, (uint8_t *)pDcChargingInfo->StartUserId,
-                       ARRAY_SIZE(pDcChargingInfo->StartUserId));
-
-                // 同一張卡直接停掉
-                if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-                    ChargingTerminalProcess(pSysInfo->CurGunSelected);
-                    strcpy((char *)pSysConfig->UserId, "");
-                } else {
-                    // 進驗證
-                    if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                        _authorizeIndex = pSysInfo->CurGunSelectedByAc;
-                    } else {
-                        _authorizeIndex = pSysInfo->CurGunSelected;
-                    }
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    StartSystemTimeoutDet(Timeout_AuthorizingForStop);
-                    AuthorizingStart();
-#else
-                    strcpy((char *)pSysConfig->UserId, "");
-#endif //!defined DD360 && !defined DD360Audi
-                }
-            } else if (idleReq) {
-                if (pSysConfig->TotalConnectorCount > 1 &&
-                        stopReq != 255 &&
-                        pSysInfo->IsAlternatvieConf == YES) {
-                    idleReq = false;
-                    strcpy((char *)pSysConfig->UserId, "");
-                } else if ((pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-                           pDcChargingInfo->SystemStatus == S_IDLE) {
-                    log_info("// LCM => Authorizing \n");
-#if defined DD360Audi
-                    setSelGunWaitToAuthor(pSysInfo->CurGunSelected); //Jerry add
-#endif //defined DD360Audi
-                    // LCM => Authorizing
-                    pSysInfo->SystemPage = _LCM_AUTHORIZING;
-                    // 進入確認卡號狀態
-                    AuthorizingStart();
-                } else {
-                    strcpy((char *)pSysConfig->UserId, "");
-                }
-            } else {
-                strcpy((char *)pSysConfig->UserId, "");
-            }
+        return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+        StartSystemTimeoutDet(Timeout_AuthorizingForStop);
+
+        AuthorizingStart();
+    } else if (idleReq) {
+        if (pSysConfig->TotalConnectorCount > 1 &&
+                stopReq != 255 &&
+                pSysInfo->IsAlternatvieConf == YES) {
+            idleReq = false;
+            strcpy((char *)pSysConfig->UserId, "");
+        } else if ((pGunIndexInfo->AcGunIndex > 0 &&
+                    pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
+                   pDcChargingInfo->SystemStatus == S_IDLE) {
+            log_info("// LCM => Authorizing\r\n");
+
+            setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
+
+            // LCM => Authorizing
+            pSysInfo->SystemPage = _LCM_AUTHORIZING;
+
+            // 進入確認卡號狀態
+            AuthorizingStart();
+        } else {
+            strcpy((char *)pSysConfig->UserId, "");
         }
     } else {
-        // 透過後臺停止充電的判斷
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || (pSysInfo->OcppConnStatus == NO &&
-                    pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-           ) {
-            // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || (pSysInfo->OcppConnStatus == NO &&
-                        pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
-                if (_authorizeIndex != NO_DEFINE) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_authorizeIndex);
-
-                    // 先找 AC
-                    if (_authorizeIndex == DEFAULT_AC_INDEX) {
-                        if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
-                            AcChargingTerminalProcess();
-                        }
-                    } else {
-                        if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
-                            ChargingTerminalProcess(_authorizeIndex);
-                        }
-                    }
-                    strcpy((char *)pSysConfig->UserId, "");
-                    _authorizeIndex = NO_DEFINE;
-                }
-            } else {
-                strcpy((char *)pSysConfig->UserId, "");
-            }
-            ClearAuthorizedFlag();
-        } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                        ChargingTerminalProcess(_authorizeIndex);
-                        strcpy((char *)pSysConfig->UserId, "");
-                        ClearAuthorizedFlag();
-                        break;
-                    }
-                }
-            }
-        }
+        strcpy((char *)pSysConfig->UserId, "");
     }
+
+    return;
 }
 
 bool GetIsCardScan(void)
@@ -223,12 +255,15 @@ void SetIsCardScan(bool value)
 
 void ScannerCardProcess(void)
 {
+    int i = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
 
-    if (!isDetectPlugin() && !isCardScan && pSysWarning->Level != 2 &&
+    if (!isDetectPlugin() &&
+            !isCardScan &&
+            pSysWarning->Level != WARN_LV_ER &&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
         isCardScan = true;
         // 處理刷卡及驗證卡號的動作
@@ -238,21 +273,18 @@ void ScannerCardProcess(void)
     if (pSysInfo->PageIndex == _LCM_AUTHORIZING) {
         StartSystemTimeoutDet(Timeout_Authorizing);
 
+        //printf("isAuthorizedComplete = %d, %f\r\n", isAuthorizedComplete(), ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
         // 確認驗證卡號完成沒
         if (isAuthorizedComplete()
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#else
+#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 && ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance != FAIL_BALANCE_PRICES
-#endif //!defined DD360 && !defined DD360Audi
            ) {
             StopSystemTimeoutDet();
+
             // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
+            if (canStartCharging()) {
                 // LCM => Authorize complete
                 pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
             } else {
@@ -260,16 +292,19 @@ void ScannerCardProcess(void)
                 pSysInfo->SystemPage = _LCM_AUTHORIZ_FAIL;
                 strcpy((char *)pSysConfig->UserId, "");
             }
+
             ClearAuthorizedFlag();
         } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
             // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                        pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
-                        ClearAuthorizedFlag();
-                        break;
-                    }
+            for (i = 0; i < 10; i++) {
+                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
+                    continue;
+                }
+
+                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
+                    pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
+                    ClearAuthorizedFlag();
+                    break;
                 }
             }
         }
@@ -317,98 +352,101 @@ void CreateRfidFork(void)
     pid_t rfidRecPid;
 
     rfidRecPid = fork();
-    log_info("CreateRfidFork = %d\r\n", rfidRecPid);
     if (rfidRecPid == 0) {
         int fd = -1;
+        int isContinue = 1;
         RFID rfid = {0};
         fd = InitialRfidPort();
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
 
-        while (true) {
+        log_info("RFID fork Child's PID is %d\r\n", getpid());
+
+        while (isContinue) {
+            usleep(500000);
+
             // 刷卡判斷
             if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
                     !pSysConfig->isRFID) {
-                usleep(500000);
                 continue;
             }
 
             if (getRequestCardSN(fd, 0, &rfid) == false) {
-                usleep(500000);
                 continue;
             }
 
             //log_info("Get Card..-%s- \n", pSysConfig->UserId);
-            if (strlen((char *)pSysConfig->UserId) == 0) {
-                if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
-                    switch (rfid.snType) {
-                    case RFID_SN_TYPE_6BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5]);
-                        break;
-                    case RFID_SN_TYPE_7BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5],
-                                rfid.currentCard[6]);
-                        break;
-                    case RFID_SN_TYPE_10BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5],
-                                rfid.currentCard[6], rfid.currentCard[7],
-                                rfid.currentCard[8], rfid.currentCard[9]);
-                        break;
-                    case RFID_SN_TYPE_4BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3]);
-                        break;
-                    }
-                } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
-                    switch (rfid.snType) {
-                    case RFID_SN_TYPE_6BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[5], rfid.currentCard[4],
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_7BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[6], rfid.currentCard[5],
-                                rfid.currentCard[4], rfid.currentCard[3],
-                                rfid.currentCard[2], rfid.currentCard[1],
-                                rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_10BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[9], rfid.currentCard[8],
-                                rfid.currentCard[7], rfid.currentCard[6],
-                                rfid.currentCard[5], rfid.currentCard[4],
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_4BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X",
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    }
+            if (strlen((char *)pSysConfig->UserId) != 0) {
+                continue;
+            }
+
+            if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
+                switch (rfid.snType) {
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5],
+                            rfid.currentCard[6]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5],
+                            rfid.currentCard[6], rfid.currentCard[7],
+                            rfid.currentCard[8], rfid.currentCard[9]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3]);
+                    break;
+                }
+            } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
+                switch (rfid.snType) {
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[5], rfid.currentCard[4],
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[6], rfid.currentCard[5],
+                            rfid.currentCard[4], rfid.currentCard[3],
+                            rfid.currentCard[2], rfid.currentCard[1],
+                            rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[9], rfid.currentCard[8],
+                            rfid.currentCard[7], rfid.currentCard[6],
+                            rfid.currentCard[5], rfid.currentCard[4],
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X",
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
                 }
-                log_info("card number = %s\n", pSysConfig->UserId);
             }
-            usleep(500000);
+            log_info("card number = %s\n", pSysConfig->UserId);
         }
     }
 }

+ 143 - 135
EVSE/Projects/DD360/Apps/CSU/SelfTest.c

@@ -18,6 +18,7 @@ extern void ChkPrimaryStatus(void);
 void SelfTestRun(void)
 {
     bool evInitFlag = false;
+    uint8_t index = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
@@ -36,177 +37,184 @@ void SelfTestRun(void)
     StartSystemTimeoutDet(Timeout_SelftestChk);
     pSysInfo->SelfTestSeq = _STEST_VERSION;
 
-    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE //||
-            //GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL <= 20 //DS60-120 add
-          ) {
-        if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
+        if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) { //自檢完成
             return;
         }
 
-        ChkPrimaryStatus();
-        if (pSysWarning->Level == 2 //||
-                //pAlarmCode->AlarmEvents.bits.PsuDipSwitchStestFail == YES //DS60-120 add
-           ) {
+        ChkPrimaryStatus(); //確認硬體有無錯誤,如急停按鈕或門有打開
+
+        if (pSysWarning->Level == WARN_LV_ER) {
             pSysInfo->SelfTestSeq = _STEST_FAIL;
             return;
         }
 
-        if (pSysConfig->TotalConnectorCount > 0) {
-            if (ShmPsuData->Work_Step == _NO_WORKING ||
-                    pSysInfo->SelfTestSeq == _STEST_FAIL) {
-                pSysInfo->SelfTestSeq = _STEST_FAIL;
-                return;
+        if (pSysConfig->TotalConnectorCount <= 0) {
+            pSysInfo->SelfTestSeq = _STEST_FAIL;
+            return;
+        }
+
+        if (ShmPsuData->Work_Step == _NO_WORKING ||
+                pSysInfo->SelfTestSeq == _STEST_FAIL) {
+            pSysInfo->SelfTestSeq = _STEST_FAIL;
+            return;
+        }
+
+        switch (pSysInfo->SelfTestSeq) {
+        case _STEST_VERSION:
+            if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
+                    pSysInfo->RelayModuleFwRev[0] != '\0') &&
+                    (ShmRelayModuleData->SelfTest_Comp != YES)
+               ) {
+                log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
+                ShmRelayModuleData->SelfTest_Comp = YES;
             }
 
-            switch (pSysInfo->SelfTestSeq) {
-            case _STEST_VERSION: {
-                if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
-                        pSysInfo->RelayModuleFwRev[0] != '\0')
-                        && (ShmRelayModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
-                    ShmRelayModuleData->SelfTest_Comp = YES;
-                }
 #if !defined NO_FAN_BOARD && !defined DD360ComBox
-                if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
-                        pSysInfo->FanModuleFwRev[0] != '\0')
-                        && (ShmFanModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
-                    ShmFanModuleData->SelfTest_Comp = YES;
-                }
-#else
+            if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
+                    pSysInfo->FanModuleFwRev[0] != '\0') &&
+                    (ShmFanModuleData->SelfTest_Comp != YES)
+               ) {
+                log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
                 ShmFanModuleData->SelfTest_Comp = YES;
+            }
+#else
+            ShmFanModuleData->SelfTest_Comp = YES;
 #endif //NO_FAN_BOARD
 
-                if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
-                        ShmPrimaryMcuData->version[0] != '\0')
-                        && (ShmPrimaryMcuData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
-                    ShmPrimaryMcuData->SelfTest_Comp = YES;
-                }
+            if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
+                    ShmPrimaryMcuData->version[0] != '\0') &&
+                    (ShmPrimaryMcuData->SelfTest_Comp != YES)
+               ) {
+                log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
+                ShmPrimaryMcuData->SelfTest_Comp = YES;
+            }
 
-                // EV 小板
-                if (!evInitFlag) {
-                    evInitFlag = YES;
-                    for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
-
-                        //log_info("index = %d, charging index = %d, type = %d\r\n",
-                        //         index,
-                        //         chargingInfo[index]->type_index,
-                        //         chargingInfo[index]->Type);
-                        if (pDcChargingInfo->Type == _Type_Chademo) {
-                            if ((strlen((char *)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version) != 0 ||
-                                    ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
-                                    //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
-                               ) {
-                                log_info("CHAdeMO[%d] FW Rev = %s", pDcChargingInfo->type_index, ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
-                                ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
-                            } else {
-                                //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
-                                evInitFlag = NO;
-                            }
-                        } else if (pDcChargingInfo->Type == _Type_GB) {
-                            if ((strlen((char *)ShmGBTData->evse[pDcChargingInfo->type_index].version) != 0 ||
-                                    ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
-                                    //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+            // EV 小板
+            if (!evInitFlag) {
+                evInitFlag = YES;
+                for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+                    //log_info("index = %d, charging index = %d, type = %d\r\n",
+                    //         index,
+                    //         chargingInfo[index]->type_index,
+                    //         chargingInfo[index]->Type);
+                    if (pDcChargingInfo->Type == _Type_Chademo) {
+                        if ((strlen((char *)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version) != 0 ||
+                                ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
+                                //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+                           ) {
+                            log_info("CHAdeMO[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                        } else {
+                            //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            evInitFlag = NO;
+                        }
+                    } else if (pDcChargingInfo->Type == _Type_GB) {
+                        if ((strlen((char *)ShmGBTData->evse[pDcChargingInfo->type_index].version) != 0 ||
+                                ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
+                                //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+                           ) {
+                            log_info("GBT[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmGBTData->evse[pDcChargingInfo->type_index].version);
+                            ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                        } else {
+                            //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            evInitFlag = NO;
+                        }
+                    } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                            if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version) != 0 ||
+                                    ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
+                                    /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
                                ) {
-                                log_info("GBT[%d] FW Rev = %s", pDcChargingInfo->type_index, ShmGBTData->evse[pDcChargingInfo->type_index].version);
-                                ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                                log_info("CCS[%d] FW Rev = %s",
+                                         pDcChargingInfo->type_index,
+                                         ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
+                                ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
                             } else {
-                                //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                                //log_info("CCS[%d] ccs fw lose...... %s \n",
+                                //         chargingInfo[index]->type_index,
+                                //         ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
                                 evInitFlag = NO;
                             }
-                        } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                            if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                                if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version) != 0 ||
-                                        ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
-                                        /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
-                                   ) {
-                                    log_info("CCS[%d] FW Rev = %s",
-                                             pDcChargingInfo->type_index,
-                                             ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
-                                    ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
-                                } else {
-                                    //log_info("CCS[%d] ccs fw lose...... %s \n",
-                                    //         chargingInfo[index]->type_index,
-                                    //         ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
-                                    evInitFlag = NO;
-                                }
-                            }
                         }
                     }
+                }
 
-                    for (uint8_t index = 0; index < pSysConfig->AcConnectorCount; index++) {
-                        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
-
-                        if (pAcChargingInfo->Type == _Type_AC) {
-                            if ((strlen((char *)pAcChargingInfo->version) != 0 || pAcChargingInfo->version[0] != '\0')
-                                    && (pAcChargingInfo->SelfTest_Comp != YES)
-                               ) {
-                                log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
-                                pAcChargingInfo->SelfTest_Comp = YES;
-                            } else {
-                                evInitFlag = NO;
-                            }
+                for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
+                    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
+
+                    if (pAcChargingInfo->Type == _Type_AC) {
+                        if ((strlen((char *)pAcChargingInfo->version) != 0 ||
+                                pAcChargingInfo->version[0] != '\0')
+                                && (pAcChargingInfo->SelfTest_Comp != YES)
+                           ) {
+                            log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
+                            pAcChargingInfo->SelfTest_Comp = YES;
+                        } else {
+                            evInitFlag = NO;
                         }
                     }
                 }
+            }
 
-                if ( ShmFanModuleData->SelfTest_Comp &&
-                        ShmRelayModuleData->SelfTest_Comp &&
-                        ShmPrimaryMcuData->SelfTest_Comp &&
-                        evInitFlag
-                   ) {
-                    pSysInfo->SelfTestSeq = _STEST_AC_CONTACTOR;
-                }
+            if (ShmFanModuleData->SelfTest_Comp &&
+                    ShmRelayModuleData->SelfTest_Comp &&
+                    ShmPrimaryMcuData->SelfTest_Comp &&
+                    evInitFlag
+               ) {
+                pSysInfo->SelfTestSeq = _STEST_AC_CONTACTOR;
             }
             break;
-            case _STEST_AC_CONTACTOR: {
-                //ShmPsuData->Work_Step = _TEST_COMPLETE;
-                // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (pSysInfo->AcContactorStatus == YES) {
-                    pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
-                    log_info("AC contactor self test OK");
-                }
-#else
+
+        case _STEST_AC_CONTACTOR:
+            //ShmPsuData->Work_Step = _TEST_COMPLETE;
+            // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
+            log_info("Waiting for DO communication");
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (pSysInfo->AcContactorStatus == YES) {
                 pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
-                log_info("Waiting for DO communication");
-#endif //!defined DD360 && !defined DD360Audi
+                log_info("AC contactor self test OK");
             }
             break;
-            case _STEST_PSU_DETECT: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
-                    pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
-                }
-#else
+
+        case _STEST_PSU_DETECT:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
                 pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
-#endif //defined DD360 && !defined DD360Audi
             }
             break;
-            case _STEST_PSU_CAP: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                // 此測試是要確認當前總輸出能力
-                // 如果沒有 PSU 模組請 bypass
-                if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
-                    sleep(1);
-                    pSysInfo->SelfTestSeq = _STEST_COMPLETE;
-                    pSysInfo->BootingStatus = BOOT_COMPLETE;
-                }
-#else
-                //check the power limit from DO
+
+        case _STEST_PSU_CAP:
+            // 此測試是要確認當前總輸出能力
+            // 如果沒有 PSU 模組請 bypass
+
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            //check the power limit from DO
+            pSysInfo->SelfTestSeq = _STEST_COMPLETE;
+            pSysInfo->BootingStatus = BOOT_COMPLETE;
+            log_info("Successful Self Test");
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
+                sleep(1);
                 pSysInfo->SelfTestSeq = _STEST_COMPLETE;
                 pSysInfo->BootingStatus = BOOT_COMPLETE;
-                log_info("Successful Self Test");
-#endif //defined DD360 && !defined DD360Audi
-            }
-            break;
             }
-        } else {
             break;
         }
 

+ 5 - 1
EVSE/Projects/DD360/Apps/CSU/UpgradeFW.c

@@ -25,7 +25,11 @@ static int InitComPort(uint8_t target)
 
     if (target == UPGRADE_PRI) {
         fd = open(_priPortName, O_RDWR);
-    } else if (target == UPGRADE_FAN ||  target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED) {
+    } else if (target == UPGRADE_FAN ||
+               target == UPGRADE_RB ||
+               target == UPGRADE_AC ||
+               target == UPGRADE_LED
+              ) {
         fd = open(_485PortName, O_RDWR);
     }
 

Файловите разлики са ограничени, защото са твърде много
+ 454 - 222
EVSE/Projects/DD360/Apps/CSU/main.c


+ 32 - 31
EVSE/Projects/DD360/Apps/CSU/main.h

@@ -5,43 +5,44 @@
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
-#define MODELNAME_FAIL                          0
-#define BUFFER_SIZE                             128
-#define BTN_RELEASE                             0
-#define BTN_PRESS                               1
-#define MAX_BUF                                 64
-#define MtdBlockSize                            0x600000
+#define MODELNAME_FAIL                          (0)
+#define BUFFER_SIZE                             (128)
+#define BTN_RELEASE                             (0)
+#define BTN_PRESS                               (1)
+#define MAX_BUF                                 (64)
 #define SYSFS_GPIO_DIR                          "/sys/class/gpio"
-#define UPGRADE_FAN                             0x02
+#define UPGRADE_FAN                             (0x02)
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
-#define UPGRADE_RB                              0x09 //0x09 for DD360 dispenser
+#define UPGRADE_RB                              (0x09) //0x09 for DD360 dispenser
 #else
-#define UPGRADE_RB                              0x03 //other module use
-#endif //defined DD360 || defined DD360Audi
-#define UPGRADE_PRI                             0x04
-#define UPGRADE_AC                              0x05
-#define UPGRADE_LED                             0x06
-#define SYSTEM_MIN_VOL                          80 //150
-#define MIN_OUTPUT_CUR                          0
-#define AC_OUTPUT_VOL                           220
-
-#define DEFAULT_AC_INDEX                        2
-#define PSU_MIN_CUR                             100
+#define UPGRADE_RB                              (0x03) //other module use
+#endif //defined DD360 ||defined DD360Audi || defined DD360ComBox
+#define UPGRADE_PRI                             (0x04)
+#define UPGRADE_AC                              (0x05)
+#define UPGRADE_LED                             (0x06)
+#define SYSTEM_MIN_VOL                          (80) //150
+#define MIN_OUTPUT_CUR                          (0)
+#define AC_OUTPUT_VOL                           (220)
+
+#define DEFAULT_AC_INDEX                        (2)
+#define PSU_MIN_CUR                             (100)
 
 //#define DB_FILE                                 "/Storage/ChargeLog/localCgargingRecord.db"
 
-#define uSEC_VAL                                1000000
-#define SELFTEST_TIMEOUT                        60//45
-#define AUTHORIZE_TIMEOUT                       15//30
-#define AUTHORIZE_COMP_TIMEOUT                  3
-#define AUTHORIZE_FAIL_TIMEOUT                  3
-#define AUTHORIZE_STOP_TIMEOUT                  30
-#define RETURN_TO_CHARGING_PAGE                 30
-#define GUN_PREPARE_TIMEOUT                     30
-#define GUN_EV_WAIT_TIMEOUT                     120
-#define GUN_EVSE_WAIT_TIMEOUT                   60
-#define GUN_COMP_WAIT_TIMEOUT                   10
-#define GUN_PRECHARGING_TIMEOUT                 60
+#define uSEC_VAL                                (1000000)
+#define SELFTEST_TIMEOUT                        (60)//45
+#define AUTHORIZE_TIMEOUT                       (15)//30
+#define AUTHORIZE_COMP_TIMEOUT                  (3)
+#define AUTHORIZE_FAIL_TIMEOUT                  (3)
+#define AUTHORIZE_STOP_TIMEOUT                  (30)
+#define RETURN_TO_CHARGING_PAGE                 (30)
+#define GUN_PREPARE_TIMEOUT                     (30)
+#define GUN_EV_WAIT_TIMEOUT                     (120)
+#define GUN_EVSE_WAIT_TIMEOUT                   (60)
+#define GUN_COMP_WAIT_TIMEOUT                   (10)
+#define GUN_PRECHARGING_TIMEOUT                 (60)
+
+#define WHILE_LOOP_TIME                         (10000)
 
 //#define log_info(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)

+ 17 - 4
EVSE/Projects/DD360/Apps/Config.h

@@ -77,12 +77,18 @@
 
 #define NO_DEFINE                               (255)
 
+#define MtdBlockSize                            (0x300000) //(0x600000)
+
 //------------------------------------------------------------------------------
 //gun temperatures
 //------------------------------------------------------------------------------
-#define GUN_OTP_VALUE                           150
-#define GUN_OTP_RECOVERY                        140
-#define UNDEFINED_TEMP                          255
+#define GUN_OTP_VALUE                           (150)
+#define GUN_OTP_RECOVERY                        (140)
+#define UNDEFINED_TEMP                          (255)
+
+#define WARN_LV_NL                              (0) //normal state
+#define WARN_LV_WARN                            (1)
+#define WARN_LV_ER                              (2) //emergency state
 
 //------------------------------------------------------------------------------
 enum _SYSTEM_STATUS {
@@ -332,6 +338,12 @@ typedef union {
     } StatusBit;
 } ChillerTempState;
 
+typedef struct StChillerValve {
+    uint8_t MultiChillerGun; //0x80, 0: 沒有水冷槍, 1: 有水冷槍, 0x7F: 紀錄水冷槍數
+    uint8_t LeftTemp;  //左槍最高溫度
+    uint8_t RightTemp; //右槍最高溫度
+} ChillerValve;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -340,9 +352,10 @@ typedef struct StDcCommonInfo {
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
     uint8_t SystemModeChange;
-    uint8_t Reserved[3];
     PowerAlarmState PowerAlarmState;
     ChillerTempState ChillerTempState[2];
+    ChillerValve ChillerValve;
+    uint8_t Reserved[3];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 84 - 13
EVSE/Projects/DD360/Apps/DataBase/DataBase.c

@@ -101,18 +101,18 @@ int DB_Open(void)
     return result;
 }
 
-int DB_Insert_Record(int gun_index)
+int DB_Insert_Record(int gunIndex)
 {
     int result = PASS;
     char *errMsg = NULL;
     char insertSql[1024];
-    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
     struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
 
     sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
             "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
             pDcChargingInfo->ReservationId, //DS60-120 add
-            ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+            ShmOCPP16Data->StartTransaction[gunIndex].ResponseTransactionId,
             pDcChargingInfo->StartMethod,
             pDcChargingInfo->StartUserId,
             pDcChargingInfo->StartDateTime,
@@ -120,7 +120,7 @@ int DB_Insert_Record(int gun_index)
             pDcChargingInfo->EvBatteryStartSoc,
             pDcChargingInfo->EvBatterySoc,
             pDcChargingInfo->PresentChargedEnergy,
-            ShmOCPP16Data->StopTransaction[gun_index].StopReason);
+            ShmOCPP16Data->StopTransaction[gunIndex].StopReason);
 
     //if (sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db)) {
     if (sqlite3_open(DB_FILE, &localDb)) { //DS60-120 add
@@ -151,7 +151,7 @@ int DB_Insert_Record(int gun_index)
     return result;
 }
 
-int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
+int DB_Update_Operactive(uint8_t gunIndex, uint8_t IsAvailable)
 {
     uint8_t result = false;
     char *errMsg = NULL;
@@ -165,14 +165,17 @@ int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
     } else {
         log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
 
-        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
-        sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
+        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gunIndex, IsAvailable);
+        sprintf(sqlStr,
+                "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);",
+                gunIndex,
+                IsAvailable); //DS60-120 add
         log_info("sqlStr= %s\r\n", sqlStr);
         if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
             log_info( "update config error message: %s\n", errMsg);
         } else {
-            log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+            log_info("update connector-%d config item isOperactive to %d\r\n", gunIndex, IsAvailable);
         }
 
         sqlite3_close(localDb);
@@ -181,7 +184,7 @@ int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
     return result;
 }
 
-int DB_Get_Operactive(uint8_t gun_index)
+int DB_Get_Operactive(uint8_t gunIndex)
 {
     uint8_t result = true;
     char *errMsg = NULL;
@@ -189,8 +192,8 @@ int DB_Get_Operactive(uint8_t gun_index)
     char **rs;
     int  rows, cols;
 
-    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
-    sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gun_index); //DS60-120 add
+    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gunIndex);
+    sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gunIndex); //DS60-120 add
     //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
 
     if (sqlite3_open(DB_FILE, &localDb)) {
@@ -205,10 +208,10 @@ int DB_Get_Operactive(uint8_t gun_index)
                 if (strcmp(rs[(idxRow * cols) + 3], "0") == 0) {
                     result = false;
                 }
-                log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
+                log_info("Query connector-%d isOperactive: %s\r\n", gunIndex, rs[(idxRow * cols) + 3]);
             }
         } else {
-            log_info("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
+            log_info("Query connector-%d fail, set default value to operactive.\r\n", gunIndex);
         }
 
         sqlite3_free_table(rs);
@@ -252,3 +255,71 @@ int DB_Reboot_Record(void)
 
     return result;
 }
+
+//------------------------------------------------------------------------------
+//for Module_EventLog
+//------------------------------------------------------------------------------
+int CreateEventRecord(void)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char *createRecordSql = "CREATE TABLE IF NOT EXISTS event_record("
+                            "idx integer primary key AUTOINCREMENT, "
+                            "occurDatetime text NOT NULL, "
+                            "statusCode text NOT NULL"
+                            ");";
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_error( "Can't open database: %s\n", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info( "Local event record database open successfully.\n");
+
+        if (sqlite3_exec(localDb, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_error( "Create local event record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local event record table successfully\n");
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int InsertEventRecord(uint8_t *statusCode)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char sqlStr[1024] = {0};
+
+    sprintf(sqlStr, "insert into event_record(occurDatetime, statusCode) values(CURRENT_TIMESTAMP, '%s');", statusCode);
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info( "Local event record database open successfully.\n");
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert local event record error message: %s\n", errMsg);
+        } else {
+            log_info( "Insert local event record successfully\n");
+        }
+
+        sprintf(sqlStr, "delete from event_record where idx < (select idx from event_record order by idx desc limit 1)-2000;");
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "delete local event_record error message: %s\n", errMsg);
+        } else {
+            log_info( "delete local event record successfully\n");
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}

+ 9 - 0
EVSE/Projects/DD360/Apps/DataBase/DataBase.h

@@ -1,5 +1,14 @@
 #ifndef _DATA_BASE_H_
 #define _DATA_BASE_H_
 
+int DB_Open(void);
+int DB_Insert_Record(int gunIndex);
+int DB_Update_Operactive(uint8_t gunIndex, uint8_t IsAvailable);
+int DB_Get_Operactive(uint8_t gunIndex);
+int DB_Reboot_Record(void);
+
+//for Module_EventLog
+int CreateEventRecord(void);
+int InsertEventRecord(uint8_t *statusCode);
 
 #endif /* _DATA_BASE_H_ */

+ 10 - 0
EVSE/Projects/DD360/Apps/DebugLog.md

@@ -5,3 +5,13 @@
 4. Fix ccs OVP status code not release issue.
 5. Add to complete the registration but did not get the balance to restart DoComm.
 6. Add button stop charging function.
+
+2021/06/10
+1. Add Chiller temperature OTP and chiller sensor broken status code 012323 and 011038.
+
+2021/06/18
+1. ReadCmdLine.c add support double test charging function.
+
+2021/06/23
+1. Debug Module_RateCurrent.c lost gun type issue.
+2. 在充電第二把槍時,槍櫃等待主後送permission後再通知小板進入充電狀態。

+ 4 - 4
EVSE/Projects/DD360/Apps/Define/define.h

@@ -527,7 +527,7 @@ struct ChargingInfoData
 	// Connector Temp
 	unsigned char 		ConnectorTemp;			//0x00: -60¢XC  ~  0xFE: 194
 	//Chiller Temp
-	unsigned char 		ChillerTemp;			//0x00: -60¢XC  ~  0xFE: 194
+    unsigned char       ChillerTemp;            //0x00: -60¢XC  ~  0xFE: 194
 	// Charging Status
 	unsigned char 		GroundFaultStatus;		// for GFD result => 0x00 : None, 0x01 : Can Start Charging, 0x02 : Stop Charging
 	unsigned short		RealRatingPower;
@@ -1345,9 +1345,9 @@ struct AlarmCodeData
             unsigned char PsuPfcEepromFault:1;                      //bit 6
             unsigned char PsuDcdcOverVoltage:1;                     //bit 7
             //AlarmVal[15]
-            unsigned char SystemChademoOutputUCP:1;				    //bit 0
-            unsigned char SystemCCSOutputUCP:1;				        //bit 1
-            unsigned char SystemGBTOutputUCP:1;				        //bit 2
+            unsigned char SystemChademoOutputUCP:1;                 //bit 0
+            unsigned char SystemCCSOutputUCP:1;                     //bit 1
+            unsigned char SystemGBTOutputUCP:1;                     //bit 2
             unsigned char SystemChillerOTP:1;                       //bit 3
             unsigned char Reserved:4;                               //bit 4~7
 		}bits;

+ 81 - 18
EVSE/Projects/DD360/Apps/FactoryConfig.c

@@ -63,6 +63,25 @@ int StoreLogMsg(const char *fmt, ...)
     return rc;
 }
 
+int runShellCmd(const char *cmd)
+{
+    int result = FAIL;
+    char buf[256];
+    FILE *fp;
+
+    fp = popen(cmd, "r");
+    if (fp != NULL) {
+        while (fgets(buf, sizeof(buf), fp) != NULL) {
+            StoreLogMsg("%s\n", buf);
+        }
+
+        result = PASS;
+    }
+    pclose(fp);
+
+    return result;
+}
+
 void helpOutput(void)
 {
     printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
@@ -80,7 +99,7 @@ void helpOutput(void)
 int main(int argc, char *argv[])
 {
     uint8_t outType = 0;
-    unsigned int i, Chk, MtdBlockSize = 0x600000;
+    unsigned int i, Chk;
     uint8_t *ptr;
     int fd, wrd;
 
@@ -188,10 +207,15 @@ int main(int argc, char *argv[])
 
     //calculate CRC
     Chk = 0;
-    for (i = 0; i < (MtdBlockSize - 4); i++) {
+    for (i = ARRAY_SIZE(SysConfig.CsuBootLoadFwRev); i < (MtdBlockSize - 4); i++) {
         Chk += *(ptr + i);
     }
-    memcpy( ptr + MtdBlockSize - 4, &Chk, 4);
+    memcpy(ptr + MtdBlockSize - 4, &Chk, 4);
+    //Chk = 0;
+    //for (i = 0; i < (MtdBlockSize - 4); i++) {
+    //    Chk += *(ptr + i);
+    //}
+    //memcpy( ptr + MtdBlockSize - 4, &Chk, 4);
 
     /*
     * Parameter process
@@ -235,27 +259,65 @@ int main(int argc, char *argv[])
     /*
      * Configuration bin file generate
     */
-    if ((outType & OUTPUT_FILE) > 0) {
-        fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
-        if (fd < 0) {
-            StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
-            free(ptr);
-            return 0;
-        }
-        wrd = write(fd, ptr, MtdBlockSize);
-        close(fd);
-        if (wrd < MtdBlockSize) {
-            StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
-            free(ptr);
-            return 0;
-        }
-        StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
+    fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT | O_TRUNC);
+    if (fd < 0) {
+
+        StoreLogMsg("open /mnt/FactoryDefaultConfig.bin NG\n");
+
+        free(ptr);
+        return 0;
     }
+    wrd = write(fd, ptr, MtdBlockSize);
+    close(fd);
+    if (wrd < MtdBlockSize) {
+        StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\n");
+
+        free(ptr);
+        return 0;
+    }
+
+    StoreLogMsg("FactoryConfig write to file in /mnt OK.\n");
+
+    //if ((outType & OUTPUT_FILE) > 0) {
+    //    fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
+    //    if (fd < 0) {
+    //        StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
+    //        free(ptr);
+    //        return 0;
+    //    }
+    //    wrd = write(fd, ptr, MtdBlockSize);
+    //    close(fd);
+    //    if (wrd < MtdBlockSize) {
+    //        StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+    //        free(ptr);
+    //        return 0;
+    //    }
+    //    StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
+    //}
 
     /*
     * Flash memory write
     */
     if ((outType & OUTPUT_FLASH) > 0) {
+        StoreLogMsg("Erase /dev/mtd10.\n");
+        runShellCmd("flash_erase /dev/mtd10 0 0");
+        StoreLogMsg("Write /dev/mtd10.\n");
+        runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
+
+        StoreLogMsg("Erase /dev/mtd11.\n");
+        runShellCmd("flash_erase /dev/mtd11 0 0");
+        StoreLogMsg("Write /dev/mtd11.\n");
+        runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
+
+        StoreLogMsg("Erase /dev/mtd12.\n");
+        runShellCmd("flash_erase /dev/mtd12 0 0");
+        StoreLogMsg("Write /dev/mtd12.\n");
+        runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
+
+        system("rm -f /mnt/FactoryDefaultConfig.bin");
+
+        StoreLogMsg("FactoryConfig write to flash OK\n");
+#if 0
         // Save factory default setting value to flash factory default setting block
         fd = open("/dev/mtdblock12", O_RDWR);
         if (fd < 0) {
@@ -301,6 +363,7 @@ int main(int argc, char *argv[])
             return 0;
         }
         StoreLogMsg("FactoryConfig write to flash OK\r\n");
+#endif //0
     }
 
     free(ptr);

+ 14 - 6
EVSE/Projects/DD360/Apps/Makefile

@@ -92,6 +92,12 @@ EVCOMM_SRC_FILES = $(patsubst %.o, %.c, $(EVCOMM_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#Event Log
+EVENTLOG_OBJ_FILES = $(COMMON_OBJ_FILES) $(DataBaseLib)/DataBase.o \
+						$(EventLogLib)/Module_EventLogging.o
+EVENTLOG_SRC_FILES = $(patsubst %.o, %.c, $(EVENTLOG_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
 
 all: CopyFile apps
 
@@ -120,6 +126,7 @@ EvCommTask:
 	#$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
 
 EventLoggingTask:
+	#$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
 	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
 	$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
 	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
@@ -154,12 +161,12 @@ UnsafetyOutputTool:
 
 FactoryConfigApp:
 	@echo "===== Module_FactoryConfig_Task =================================="
-	rm -f FactoryConfig
-#	gcc -D $(DEFINE) "-I../../" -o FactoryConfig "./FactoryConfig.c"
-#	mkdir -p /Storage/SystemLog
-#	./FactoryConfig -f;true
-#	cp /mnt/FactoryDefaultConfig.bin ../Images
-#	rm -f FactoryConfig;
+	rm -f Module_FactoryConfig
+	gcc $(DEFINE) -o FactoryConfig FactoryConfig.c
+	mkdir -p /Storage/SystemLog
+	./FactoryConfig -f;true
+	cp /mnt/FactoryDefaultConfig.bin ../Images
+	rm -f FactoryConfig;
 	$(CC) $(DEFINE) $(CFLAGS) -c -o FactoryConfig.o FactoryConfig.c
 	$(CC) -o FactoryConfig FactoryConfig.o
 
@@ -183,6 +190,7 @@ OtherTools:
 	cp -f $(ScriptLib)/init.sh $(OutputPath)
 	cp -f $(ScriptLib)/kill.sh $(OutputPath)
 	cp -f $(ScriptLib)/web.sh $(OutputPath)
+	cp -f $(ScriptLib)/SearchIP.sh $(OutputPath)
 	cp -f main $(OutputPath)
 	cp -f Module_DoComm $(OutputPath)
 	cp -f Module_EvComm $(OutputPath)

+ 81 - 76
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -37,15 +37,16 @@
 //static uint8_t PacketSe;
 static DoCommGblData gDoCommGblData = {0};
 
-static struct SysConfigAndInfo  *ShmSysConfigAndInfo;
-static struct StatusCodeData    *ShmStatusCodeData;
-static struct PsuData           *ShmPsuData;
-static struct OCPP16Data        *ShmOCPP16Data;
-static struct PrimaryMcuData    *ShmPrimaryMcuData;
+static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
+static struct StatusCodeData *ShmStatusCodeData     = NULL;
+static struct PsuData *ShmPsuData                   = NULL;
+static struct OCPP16Data *ShmOCPP16Data             = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData     = NULL;
+static SelectGunInfo *ShmSelectGunInfo              = NULL;
+
 static struct ChargingInfoData  *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 static struct timeb             gRegTimeUp[2][MAX_REGISTER_NUM] = {0};
 static struct WARNING_CODE_INFO gPreSysWarningInfo = {0};
-static SelectGunInfo             *gAudiCustInfo = NULL;
 
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
@@ -300,8 +301,8 @@ static int doCommConnToServer(void)
 //------------------------------------------------------------------------------
 static void clearPricesInfo(uint8_t id)
 {
-    memset(&gAudiCustInfo->PricesInfo[id], 0, sizeof(PricesInfo));
-    gAudiCustInfo->PricesInfo[id].Balance = FAIL_BALANCE_PRICES;
+    memset(&ShmSelectGunInfo->PricesInfo[id], 0, sizeof(PricesInfo));
+    ShmSelectGunInfo->PricesInfo[id].Balance = FAIL_BALANCE_PRICES;
 }
 
 static void ClearAuthorizedFlag(void)
@@ -330,8 +331,8 @@ static void destroySelectGun(uint8_t curGun)
     uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
 
     if (curGun == DESTROY_ALL_SEL) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
 
         for (i = 0; i < totalGun; i++) {
             ChargingData[i]->TimeoutFlag = Timeout_None;
@@ -342,15 +343,15 @@ static void destroySelectGun(uint8_t curGun)
     }
 
     //for charging timeout or complete
-    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+    if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
         if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
             ClearAuthorizedFlag();
         }
         clearPricesInfo(curGun);
     }
 
-    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
+    if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
         if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
             ClearAuthorizedFlag();
         }
@@ -361,8 +362,8 @@ static void destroySelectGun(uint8_t curGun)
 
 static int getConfirmSelectedGun(uint8_t curSel)
 {
-    if (((curSel == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
-            ((curSel == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
+    if (((curSel == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
+            ((curSel == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
         return PASS;
     }
 
@@ -371,11 +372,11 @@ static int getConfirmSelectedGun(uint8_t curSel)
 
 static int getSelGunWaitToAuthor(uint8_t curGun)
 {
-    if (curGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
+    if (curGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
         return FAIL;
     }
 
-    if (curGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
+    if (curGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
         return FAIL;
     }
 
@@ -384,11 +385,11 @@ static int getSelGunWaitToAuthor(uint8_t curGun)
 
 static void setConfirmSelGun(uint8_t selGun)
 {
-    if (selGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun right\r\n");
     }
 }
@@ -566,8 +567,8 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
         switch (cmd) {
         //--- Execute parameter ---
         case MISC_CMD_CONNECOTOR_TIMEOUT:
-            gAudiCustInfo->RemoteSetup.ConnectionTimeout = value;
-            log_info("connection timeout = %d\r\n", gAudiCustInfo->RemoteSetup.ConnectionTimeout);
+            ShmSelectGunInfo->RemoteSetup.ConnectionTimeout = value;
+            log_info("connection timeout = %d\r\n", ShmSelectGunInfo->RemoteSetup.ConnectionTimeout);
             clearMiscCommand();
             break;
 
@@ -629,25 +630,25 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 #endif //DD360Audi
 
-            gAudiCustInfo->PricesInfo[plugNum].Balance = transPricesUnit((int)value);
-            log_info("%d misc balance = %.2f\r\n", plugNum, gAudiCustInfo->PricesInfo[plugNum].Balance);
+            ShmSelectGunInfo->PricesInfo[plugNum].Balance = transPricesUnit((int)value);
+            log_info("%d misc balance = %.2f\r\n", plugNum, ShmSelectGunInfo->PricesInfo[plugNum].Balance);
             clearMiscCommand();
             break;
 
         case MISC_CMD_BACKEND_STATUS :
-            gAudiCustInfo->EthDevStatus.Backend = value;
+            ShmSelectGunInfo->EthDevStatus.Backend = value;
             break;
 
         case MISC_CMD_ETHERNET_STATUS :
-            gAudiCustInfo->EthDevStatus.Ethernet = value;
+            ShmSelectGunInfo->EthDevStatus.Ethernet = value;
             break;
 
         case MISC_CMD_WIFI_STATUS :
-            gAudiCustInfo->EthDevStatus.Wifi = value;
+            ShmSelectGunInfo->EthDevStatus.Wifi = value;
             break;
 
         case MISC_CMD_4G_STATUS :
-            gAudiCustInfo->EthDevStatus.FourG = value;
+            ShmSelectGunInfo->EthDevStatus.FourG = value;
             break;
 
         case MISC_CMD_BILLING_INFO:
@@ -700,9 +701,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
                 if (plugNum == LEFT_GUN_NUM &&
-                        (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
-                         gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-                    gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+                        (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
+                         ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+                    ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
                     strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
                     ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
                     sleep(1); //Jerry add
@@ -712,9 +713,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 }
 
                 if (plugNum == RIGHT_GUN_NUM &&
-                        (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
-                         gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-                    gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
+                        (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
+                         ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+                    ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
                     strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
                     ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
                     sleep(1); //Jerry add
@@ -733,7 +734,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
 
             ShmOCPP16Data->CsMsg.bits[plugNum].RemoteStartTransactionReq = YES;
-            gAudiCustInfo->PricesInfo[plugNum].Balance = 0.00;
+            ShmSelectGunInfo->PricesInfo[plugNum].Balance = 0.00;
             clearMiscCommand();
             break;
 
@@ -830,22 +831,22 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     pAccountInfo = (AccountInfo *)&data[addr];
 
     ShmSysConfigAndInfo->SysConfig.BillingData.Currency = pAccountInfo->Currency;
-    gAudiCustInfo->PricesInfo[plugNum].UserPrices         = transPricesUnit(ntohl(pAccountInfo->UserPrices));
-    ChargingData[plugNum]->ChargingFee                    = transPricesUnit(ntohl(pAccountInfo->TotalCost));
-    gAudiCustInfo->PricesInfo[plugNum].Balance            = transPricesUnit(ntohl(pAccountInfo->Balance));
+    ShmSelectGunInfo->PricesInfo[plugNum].UserPrices    = transPricesUnit(ntohl(pAccountInfo->UserPrices));
+    ChargingData[plugNum]->ChargingFee                  = transPricesUnit(ntohl(pAccountInfo->TotalCost));
+    ShmSelectGunInfo->PricesInfo[plugNum].Balance       = transPricesUnit(ntohl(pAccountInfo->Balance));
 
-    if ((pricesInfo[plugNum].UserPrices != gAudiCustInfo->PricesInfo[plugNum].UserPrices) ||
-            (pricesInfo[plugNum].Balance != gAudiCustInfo->PricesInfo[plugNum].Balance)) {
-        pricesInfo[plugNum].UserPrices = gAudiCustInfo->PricesInfo[plugNum].UserPrices;
-        pricesInfo[plugNum].Balance = gAudiCustInfo->PricesInfo[plugNum].Balance;
+    if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
+            (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance)) {
+        pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
+        pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
 
         log_info("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
                  plugNum,
-                 gAudiCustInfo->PricesInfo[plugNum].UserPrices,
+                 ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
                  ChargingData[plugNum]->ChargingFee,
-                 gAudiCustInfo->PricesInfo[plugNum].Balance,
-                 (uint8_t *)GetCurrency(ShmSysConfigAndInfo->SysConfig.BillingData.Currency));
-        //(uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+                 ShmSelectGunInfo->PricesInfo[plugNum].Balance,
+                 (uint8_t *)GetCurrency(ShmSysConfigAndInfo->SysConfig.BillingData.Currency)
+                );
     }
 
     return PASS;
@@ -1111,7 +1112,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             return COMMAND_RESULT_NG;
         }
 
-        gAudiCustInfo->AuthorStateFromCabinet[plugNum] = pCsuResult->Data.Data[0];
+        ShmSelectGunInfo->AuthorStateFromCabinet[plugNum] = pCsuResult->Data.Data[0];
 
         return pCsuResult->Data.Data[0];
         break;
@@ -1124,6 +1125,8 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
             return COMMAND_RESULT_NG;
         }
+
+        ShmSelectGunInfo->WaitDoCommPermission[plugNum] = pCsuResult->Data.Data[0];
         return pCsuResult->Data.Data[0];
         break;
 
@@ -1371,11 +1374,14 @@ 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[8] = {'\0'};
+    uint8_t dataBuf[10] = {'\0'};
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
 
+    pConnState->ConnectorTemp = ChargingData[plugNum]->ConnectorTemp;
+    pConnState->ChillerTemp = ChargingData[plugNum]->ChillerTemp;
+
     if (ChargingData[plugNum]->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
         strncpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
@@ -1693,7 +1699,7 @@ static int InitShareMemory(void)
     if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
         log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
@@ -1752,6 +1758,8 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
     //gunID = gDoCommGblData.ConnectorID[plugNum];
 #else
     gunID = ID_REGISTER;
+
+    ShmSelectGunInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0;
 #endif // DD360Audi
 
     if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == YES) ||
@@ -1772,22 +1780,17 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
                     strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
                 }
 
-                //printf("gAudiCustInfo->PricesInfo[plugNum].Balance = %.2f, %.2f\r\n",
-                //       gAudiCustInfo->PricesInfo[plugNum].Balance,
+                //printf("%d Balance = %.2f, %.2f\r\n",
+                //       plugNum,
+                //       ShmSelectGunInfo->PricesInfo[plugNum].Balance,
                 //       FAIL_BALANCE_PRICES);
-#if defined DD360Audi
-                if (gAudiCustInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES)
-#else
-                if (gAudiCustInfo->PricesInfo[plugNum].Balance == FAIL_BALANCE_PRICES) {
-                    gAudiCustInfo->PricesInfo[plugNum].Balance = 0;
-                }
-#endif //
-                {
+
+                if (ShmSelectGunInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES) {
                     ShmOCPP16Data->SpMsg.bits.AuthorizeConf    = YES; //isAuthorizedComplete
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq     = 0;
-                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
-                    ShmPsuData->SystemAvailablePower           = 0;
-                    ShmPsuData->SystemPresentPsuQuantity       = 0;
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq     = NO;
+                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+                    ShmPsuData->SystemAvailablePower           = NO;
+                    ShmPsuData->SystemPresentPsuQuantity       = NO;
                 }
             }
             ftime(&gRegTimeUp[plugNum][REG_USER_ID]);
@@ -1989,18 +1992,20 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         checkAuthorProcess(fd, plugNum);
 
         //authorization complete, write wait plug it state
-        if (gAudiCustInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES) {
-            ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
-                writeWaitPlugItState(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
-            }
+        if (ShmSelectGunInfo->PricesInfo[plugNum].Balance == FAIL_BALANCE_PRICES) {
+            break;
+        }
 
-            ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
-                readChargingCapability(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
-            }
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
+            writeWaitPlugItState(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
+        }
+
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+            readChargingCapability(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
 
@@ -2225,7 +2230,7 @@ int main(int argc, char *argv[])
             plugNum = 0;
             gunID = 0;
             for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
-                checkAuthorProcess(fd, plugNum);
+                //checkAuthorProcess(fd, plugNum);
                 //plugNum = setup chargingData value for bottom layer
                 //gunID = (plugNum  + 1); //connector Id, 1 = left gun, 2 = right gun
                 gunID = gDoCommGblData.ConnectorID[plugNum];

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

@@ -125,7 +125,9 @@
 typedef struct StConnectorState {
     uint8_t State;
     uint8_t WarningCode[6];
-    uint8_t Reserved;
+    uint8_t ConnectorTemp;
+    uint8_t ChillerTemp;
+    uint8_t Reserved[3];
 } ConnectorState;
 
 typedef struct StConnectorIDTable {

+ 6 - 3
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalState.c

@@ -27,7 +27,8 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     //iflog_info("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
 
     if (strncmp(string, "000000", 6) == EQUAL ||
-            strncmp(string, "023979", 6) == EQUAL) {
+            strncmp(string, "023979", 6) == EQUAL
+       ) {
         return false;
     }
 
@@ -37,11 +38,15 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
 
     memcpy(pDcChargingInfo->EvConnAlarmCode, string, 6);
     log_info("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s\n", pDcChargingInfo->EvConnAlarmCode);
+
     //OVP error
     if (strcmp(string, "012217") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES; }
     if (strcmp(string, "012219") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES; }
     if (strcmp(string, "012221") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES; }
 
+    //UVP error
+    if (strcmp(string, "012288") == EQUAL) { pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES; }
+
     if (strcmp(string, "023700") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvCommFail = YES; }
     if (strcmp(string, "023704") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryMalfun = YES; }
     if (strcmp(string, "023705") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoNoPermission = YES; }
@@ -77,8 +82,6 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     if (strcmp(string, "023735") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = YES; }
     if (strcmp(string, "023736") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown = YES; }
 
-    if (strcmp(string, "012288") == EQUAL) { pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES; }
-
     if (strcmp(string, "023701") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = YES; }
     if (strcmp(string, "023737") == EQUAL) { pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit = YES; }
     if (strcmp(string, "023738") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVShiftPosition = YES; }

+ 9 - 9
EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.c

@@ -50,7 +50,7 @@ void SetTargetAddr(uint8_t *target_number, uint8_t index)
     SendCmdToEvboard(id, data, 5);
 }
 
-void GetFirmwareVersion(uint8_t gun_index, uint8_t toId)
+void GetFirmwareVersion(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_FW_VER + toId);
     uint8_t data[8];
@@ -58,7 +58,7 @@ void GetFirmwareVersion(uint8_t gun_index, uint8_t toId)
     SendCmdToEvboard(id, data, 0);
 }
 
-void GetHardwareVersion(uint8_t gun_index, uint8_t toId)
+void GetHardwareVersion(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_HW_VER + toId);
     uint8_t data[8];
@@ -66,7 +66,7 @@ void GetHardwareVersion(uint8_t gun_index, uint8_t toId)
     SendCmdToEvboard(id, data, 0);
 }
 
-void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch)
+void SyncRtcInfo(uint8_t gunIndex, uint8_t toId, int epoch)
 {
     int id = PackageIdCmd(CMD_SYNC_RTC + toId);
     uint8_t data[8];
@@ -79,7 +79,7 @@ void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch)
     SendCmdToEvboard(id, data, 4);
 }
 
-void SetChargingPermission(uint8_t gun_index, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputCur, uint16_t aOutputVol, uint8_t toId)
+void SetChargingPermission(uint8_t gunIndex, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputCur, uint16_t aOutputVol, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_CHARGING_PERMISSION + toId);
     uint8_t data[8];
@@ -130,7 +130,7 @@ void SetPresentOutputCapacity(uint16_t aOutputPw_b1, uint16_t aOutputCur_b1, uin
     SendCmdToEvboard(id, data, 8);
 }
 
-void GetOutputReq(uint8_t gun_index, uint8_t toId)
+void GetOutputReq(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_OUTPUT_REQ + toId);
     uint8_t data[8];
@@ -138,7 +138,7 @@ void GetOutputReq(uint8_t gun_index, uint8_t toId)
     SendCmdToEvboard(id, data, 0);
 }
 
-void GetEvBatteryInfo(uint8_t gun_index, uint8_t toId)
+void GetEvBatteryInfo(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_BATTERY_INFO + toId);
     uint8_t data[8];
@@ -162,7 +162,7 @@ void EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId
     SendCmdToEvboard(id, data, 7);
 }
 
-void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, float voltage, uint8_t toId)
+void GetMiscellaneousInfo(uint8_t gunIndex, uint8_t relayStatus, float power, float voltage, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_MISC_INFO + toId);
     uint8_t data[8];
@@ -178,7 +178,7 @@ void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, f
     SendCmdToEvboard(id, data, 5);
 }
 
-void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId)
+void SetIsolationStatus(uint8_t gunIndex, uint8_t result, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_ISOLATION_STATUS + toId);
     uint8_t data[8];
@@ -187,7 +187,7 @@ void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId)
     SendCmdToEvboard(id, data, 1);
 }
 
-void SetEvsePrechargeInfo(uint8_t gun_index, uint8_t result, uint8_t toId)
+void SetEvsePrechargeInfo(uint8_t gunIndex, uint8_t result, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_EVSE_PRECHARGE + toId);
     uint8_t data[8];

+ 9 - 9
EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.h

@@ -46,17 +46,17 @@
 // Send msg to can-bus
 void SetTargetAddr(uint8_t *target_number, uint8_t index);
 
-void GetFirmwareVersion(uint8_t gun_index, uint8_t toId);
-void GetHardwareVersion(uint8_t gun_index, uint8_t toId);
-void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch);
-void SetChargingPermission(uint8_t gun_index, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputVol, uint16_t aOutputCur, uint8_t toId);
+void GetFirmwareVersion(uint8_t gunIndex, uint8_t toId);
+void GetHardwareVersion(uint8_t gunIndex, uint8_t toId);
+void SyncRtcInfo(uint8_t gunIndex, uint8_t toId, int epoch);
+void SetChargingPermission(uint8_t gunIndex, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputVol, uint16_t aOutputCur, uint8_t toId);
 void SetPresentOutputPower(uint16_t outputVol_b1, uint16_t outputCur_b1, uint16_t outputVol_b2, uint16_t outputCur_b2);
 void SetPresentOutputCapacity(uint16_t aOutputPw_b1, uint16_t aOutputCur_b1, uint16_t aOutputPw_b2, uint16_t aOutputCur_b2);
-void GetOutputReq(uint8_t gun_index, uint8_t toId);
-void GetEvBatteryInfo(uint8_t gun_index, uint8_t toId);
-void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, float voltage, uint8_t toId);
-void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId);
-void SetEvsePrechargeInfo(uint8_t gun_index, uint8_t result, uint8_t toId);
+void GetOutputReq(uint8_t gunIndex, uint8_t toId);
+void GetEvBatteryInfo(uint8_t gunIndex, uint8_t toId);
+void GetMiscellaneousInfo(uint8_t gunIndex, uint8_t relayStatus, float power, float voltage, uint8_t toId);
+void SetIsolationStatus(uint8_t gunIndex, uint8_t result, uint8_t toId);
+void SetEvsePrechargeInfo(uint8_t gunIndex, uint8_t result, uint8_t toId);
 // 發送電樁主動停止充電結果及原因
 void EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId);
 

+ 50 - 40
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -25,6 +25,7 @@ static struct AlarmCodeData *pAlarmCode = NULL;
 static struct CHAdeMOData *ShmCHAdeMOData = NULL;
 static struct GBTData *ShmGBTData = NULL;
 static struct CcsData *ShmCcsData = NULL;
+static struct FanModuleData *ShmFanModuleData = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
 
 //------------------------------------------------------------------------------
@@ -133,15 +134,16 @@ static void getChillerTemperature(ChillerTemp *chillerTemp)
             pChillerTemp->Temp[i] = 195;
         }
 
-        //CcsConnectorTemp1 = ReadAdcVolt(i);
-        //if ((CcsConnectorTemp1 <= 0.9) && (CcsConnectorTemp1 >= 0.8)) { //0 ~ -40
-        //    CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 500;
-        //} else if ((CcsConnectorTemp1 <= 1.07) && (CcsConnectorTemp1 > 0.9)) {
-        //    CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 705.88;
-        //} else {
-        //    CcsConnectorTemp1 = 195;    //not available
-        //}
-        //CcsConnectorTemp |= ((unsigned int)(CcsConnectorTemp1 + 60) & 0xFF) << (i * 8); //0x00(-60)~0xFE(194)
+        /*CcsConnectorTemp1 = ReadAdcVolt(i);
+        if ((CcsConnectorTemp1 <= 0.9) && (CcsConnectorTemp1 >= 0.8)) { //0 ~ -40
+            CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 500;
+        } else if ((CcsConnectorTemp1 <= 1.07) && (CcsConnectorTemp1 > 0.9)) {
+            CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 705.88;
+        } else {
+            CcsConnectorTemp1 = 195;    //not available
+        }
+        CcsConnectorTemp |= ((unsigned int)(CcsConnectorTemp1 + 60) & 0xFF) << (i * 8); //0x00(-60)~0xFE(194)
+        */
     }
 }
 
@@ -178,6 +180,7 @@ static void AddrAssignment(uint8_t *data)
     //log_info("target_number[4] = %x \n", target_number[4]);
 
     log_info("SetTargetAddr = %d, type = %d \n", index, pDcChargingInfo->Type);
+
     SetTargetAddr(target_number, index);
     //}
 }
@@ -188,7 +191,6 @@ void CANReceiver(int fd)
 
     canRecPid = fork();
 
-
     if (canRecPid < 0) {
         log_error("Create CAN Bus receive task failed\r\n");
         return;
@@ -217,8 +219,9 @@ void CANReceiver(int fd)
         ShmGBTData = (struct GBTData *)GetShmGBTData();
         ShmCcsData = (struct CcsData *)GetShmCcsData();
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+        ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
 
-        log_info("Child's PID is %d\r\n", getpid());
+        log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
 
         while (isContinue) {
             memset(&frame, 0, sizeof(struct can_frame));
@@ -257,7 +260,7 @@ void CANReceiver(int fd)
                 }
             }
 
-            if (targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) {
+            if ((targetGun < 0) || (targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)) {
                 log_info("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
                 usleep(10000);
                 continue;
@@ -276,7 +279,7 @@ void CANReceiver(int fd)
 
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
             gunTypeIndex = pDcChargingInfo->type_index;
-            //log_info("intCmd = %x\r\n", intCmd);
+
             switch (intCmd) {
             case NOTIFICATION_EV_STATUS:
                 if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
@@ -336,11 +339,13 @@ void CANReceiver(int fd)
                     memset(pSysInfo->Connector1FwRev,
                            0,
                            sizeof(pSysInfo->Connector1FwRev));
+
                     memcpy(pSysInfo->Connector1FwRev, ver, ARRAY_SIZE(ver));
                 } else if (targetGun == 1) {
                     memset(pSysInfo->Connector2FwRev,
                            0,
                            sizeof(pSysInfo->Connector2FwRev));
+
                     memcpy(pSysInfo->Connector2FwRev, ver, ARRAY_SIZE(ver));
                 }
                 break;
@@ -354,7 +359,8 @@ void CANReceiver(int fd)
                 if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
                         pDcChargingInfo->SystemStatus <= S_CHARGING) ||
                         (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
+                   ) {
                     if (pDcChargingInfo->EvBatteryStartSoc <= 0) {
                         pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
                     }
@@ -457,37 +463,14 @@ void CANReceiver(int fd)
                 }
                 }*/
 
-                //memset((uint8_t)&chiilerTemp, 0, sizeof(ChillerTemp));
-                //if (targetGun == 0 &&
-                //        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                //         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
-                //   ) {
-                //    getChillerTemperature(&chiilerTemp);
-                //    pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
-                //    //pDcChargingInfo->ConnectorTemp = getMaxConnectTempAndChiller(
-                //    //                                     frame.data[1],
-                //    //                                     frame.data[2],
-                //    //                                     chiilerTemp.Temp[0],
-                //    //                                     chiilerTemp.Temp[1]);
-                //} else if (targetGun == 1 &&
-                //           ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                //            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
-                //          ) {
-                //    getChillerTemperature(&chiilerTemp);
-                //    pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
-                //}
-#if 1
-                if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                        (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
-                        (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                        (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
-                   ) {
+                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) == YES) {
                     getChillerTemperature(&chiilerTemp);
                     pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                 }
 
                 pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
 
+                //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
                 if ((ShmDcCommonData->SystemModeChange == YES) ||
                         (((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
                           (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
@@ -502,7 +485,34 @@ void CANReceiver(int fd)
                              chiilerTemp.Temp[0],
                              chiilerTemp.Temp[1]);
                 }
-#endif //0
+
+                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) == NO) {
+                    //沒有水冷槍
+                    break;
+                }
+
+                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
+                    //單一水冷槍,不需要切換水冷機油閥
+                    //ShmFanModuleData-> ? = YES; //尚未定義
+                    break;
+                }
+
+                //紀錄槍頭溫度
+                if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
+                    if (targetGun == 0) {
+                        ShmDcCommonData->ChillerValve.LeftTemp = pDcChargingInfo->ConnectorTemp;
+                    } else if (targetGun == 1) {
+                        ShmDcCommonData->ChillerValve.RightTemp = pDcChargingInfo->ConnectorTemp;
+                    }
+                }
+
+                //有兩把水冷槍,判斷兩把槍頭溫度,將水冷機節流閥導向溫度高的那一把槍
+                if (ShmDcCommonData->ChillerValve.LeftTemp > ShmDcCommonData->ChillerValve.RightTemp) {
+                    //ShmFanModuleData->? = YES; //尚未定義
+                } else {
+                    //ShmFanModuleData->? = NO; //尚未定義
+                }
+
                 //log_info("EvboardStatus = %x \n",
                 //         ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
                 //log_info("ConnectorPlug locked = %x \n",

+ 61 - 47
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -20,6 +20,7 @@
 #include "../Log/log.h"
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
+#include "../SelectGun/SelectGun.h"
 #include "Ev_Comm.h"
 #include "Module_EvComm.h"
 
@@ -33,6 +34,7 @@ static struct CHAdeMOData *ShmCHAdeMOData = NULL;
 static struct GBTData *ShmGBTData = NULL;
 static struct CcsData *ShmCcsData = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
 
 // 限制最大充電電壓,因應不同 type 槍線來限制
 // Chademo : 500V, 125A,
@@ -42,9 +44,9 @@ static DcCommonInfo *ShmDcCommonData = NULL;
 //static double chademoVol = 5000;
 //static double ccsVol = 9500;
 //static double gbVol = 7500;
-static float maxChargingVol[2] = { 0, 0 };       // 限制最大充電電壓,如依照模塊則填上 0
+static float maxChargingVol[2] = {0, 0};       // 限制最大充電電壓,如依照模塊則填上 0
 // 限制最大充電電流與能量透過 Web
-static float maxChargingCur[2] = { 0, 0 };         // 限制最大充電電流,如依照模塊則填上 0
+static float maxChargingCur[2] = {0, 0};         // 限制最大充電電流,如依照模塊則填上 0
 static float maxChargingPow = 0;                   // 限制最大充電能量,如依照模塊則填上 0
 
 static float LogInfo[2][10]; //DS60-120 add
@@ -476,9 +478,9 @@ static void SetPresentChargingOutputPower(void)
 static void checkConnectorOVPState(uint8_t gunIndex)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-
     // 避免槍溫偵測誤判
     static uint8_t gunTempAllowCount[2] = {0};
+
     bool isOTP = false;
 
     switch (pDcChargingInfo->Type) {
@@ -572,9 +574,11 @@ int main(int argc, char *argv[])
     uint8_t gunIndex = 0;
     uint8_t typeIndex = 0;
     uint8_t priorityLow = 1;
-    uint8_t SendErrorCount[2] = { 0, 0};
+    uint8_t SendErrorCount[2] = {0, 0};
+    uint8_t gfgResult = 0;
     uint32_t _timeBuf = 0;
     uint32_t chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {0};
+    float maxVol, maxCur;
     struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     time_t rtc = {0};
@@ -595,6 +599,7 @@ int main(int argc, char *argv[])
     ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
     ShmGBTData = (struct GBTData *)GetShmGBTData();
     ShmCcsData = (struct CcsData *)GetShmCcsData();
+    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
 
     CanFd = InitCanBus();
 
@@ -627,8 +632,10 @@ int main(int argc, char *argv[])
                     }
                 }
 
-                // 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
-                //log_info("GetMiscellaneousInfo. index = %d, Eid = %d \n", gunIndex, pDcChargingInfo->Evboard_id);
+                //固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
+                //log_info("GetMiscellaneousInfo. index = %d, Eid = %d \n",
+                //         gunIndex,
+                //         pDcChargingInfo->Evboard_id);
                 GetMiscellaneousInfo(gunIndex,
                                      pDcChargingInfo->RelayK1K2Status,
                                      pDcChargingInfo->PresentChargedEnergy,
@@ -669,7 +676,6 @@ int main(int argc, char *argv[])
                     if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP == NO) {
                         pDcChargingInfo->StopChargeFlag = NO;
                     }
-
                 } else if (pDcChargingInfo->Type == _Type_GB) {
                     ClearAbnormalStatus_GB(gunIndex);
 
@@ -685,21 +691,20 @@ int main(int argc, char *argv[])
                 }
 
                 if (priorityLow == 1) {
-                    pDcChargingInfo->PresentChargedEnergy = 0;
-                    pDcChargingInfo->PresentChargingPower = 0;
-                    pDcChargingInfo->GroundFaultStatus = GFD_WAIT;
-                    pDcChargingInfo->RealRatingPower = 0;
-                    pDcChargingInfo->StopChargeFlag = NO;
-                    pDcChargingInfo->NormalStopChargeFlag = NO;//DS60-120 add
-                    pDcChargingInfo->ChargingFee = 0.0;
-                    pDcChargingInfo->EvBatterySoc = 0;
-                    pDcChargingInfo->EvBatteryStartSoc = 0; //DS60-120 add
-                    pDcChargingInfo->EvBatteryMaxVoltage = 0; //DS60-120 add
-                    pDcChargingInfo->ChargingProfilePower = -1; //DS60-120 add
+                    pDcChargingInfo->PresentChargedEnergy   = 0;
+                    pDcChargingInfo->PresentChargingPower   = 0;
+                    pDcChargingInfo->GroundFaultStatus      = GFD_WAIT;
+                    pDcChargingInfo->RealRatingPower        = 0;
+                    pDcChargingInfo->StopChargeFlag         = NO;
+                    pDcChargingInfo->NormalStopChargeFlag   = NO;//DS60-120 add
+                    pDcChargingInfo->ChargingFee            = 0.0;
+                    pDcChargingInfo->EvBatterySoc           = 0;
+                    pDcChargingInfo->EvBatteryStartSoc      = 0; //DS60-120 add
+                    pDcChargingInfo->EvBatteryMaxVoltage    = 0; //DS60-120 add
+                    pDcChargingInfo->ChargingProfilePower   = -1; //DS60-120 add
                     pDcChargingInfo->ChargingProfileCurrent = -1; //DS60-120 add
 
                     if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) { //DS60-120 add
-
                         pDcChargingInfo->PresentChargingVoltage = 0;
                         pDcChargingInfo->PresentChargingCurrent = 0;
                         pDcChargingInfo->EvBatteryMaxVoltage = 0;
@@ -740,17 +745,18 @@ int main(int argc, char *argv[])
                 // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
 
-//                  log_info("PresentChargingVoltage = %f \n", pDcChargingInfo->PresentChargingVoltage);
-//                  log_info("PresentChargingCurrent = %f \n", pDcChargingInfo->PresentChargingCurrent);
-//                  log_info("AvailableChargingPower = %f \n", pDcChargingInfo->AvailableChargingPower);
-//                  log_info("AvailableChargingCurrent = %f \n", pDcChargingInfo->AvailableChargingCurrent);
-//                  log_info("MaximumChargingVoltage = %f \n", pDcChargingInfo->MaximumChargingVoltage);
+                //log_info("PresentChargingVoltage = %f \n", pDcChargingInfo->PresentChargingVoltage);
+                //log_info("PresentChargingCurrent = %f \n", pDcChargingInfo->PresentChargingCurrent);
+                //log_info("AvailableChargingPower = %f \n", pDcChargingInfo->AvailableChargingPower);
+                //log_info("AvailableChargingCurrent = %f \n", pDcChargingInfo->AvailableChargingCurrent);
+                //log_info("MaximumChargingVoltage = %f \n", pDcChargingInfo->MaximumChargingVoltage);
 
                 // 設定當前輸出
                 SetPresentChargingOutputPower();
 
-                if (priorityLow == 1) {
-                    float maxVol, maxCur;
+                if (ShmSelectGunInfo->WaitDoCommPermission[gunIndex] == YES) {
+                    ShmSelectGunInfo->WaitDoCommPermission[gunIndex] = NO;
+                    //if (priorityLow == 1) {
                     // 樁端輸出能力
                     maxVol = pDcChargingInfo->MaximumChargingVoltage;
                     maxCur = pDcChargingInfo->AvailableChargingCurrent;
@@ -763,11 +769,12 @@ int main(int argc, char *argv[])
                         LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = maxVol;
                         LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = maxCur;
 
-                        log_info("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f \n",
-                                 gunIndex, maxVol / 10, maxCur / 10, pDcChargingInfo->AvailableChargingPower / 10);
+                        log_info("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f\n",
+                                 gunIndex,
+                                 maxVol / 10,
+                                 maxCur / 10,
+                                 pDcChargingInfo->AvailableChargingPower / 10);
                     }
-                    //log_info("To EV_%d Max_Vol = %f, Cap_Cur = %f, Cap_Pow = %f \n",
-                    //            gunIndex, maxVol, maxCur, pDcChargingInfo->AvailableChargingPower);
 
                     pDcChargingInfo->RealMaxVoltage = maxVol;
 
@@ -827,23 +834,23 @@ int main(int argc, char *argv[])
                     //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
                     {
                         //if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
-                        uint8_t _result = pDcChargingInfo->GroundFaultStatus;
+                        gfgResult = pDcChargingInfo->GroundFaultStatus;
 
                         // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
                         if (pDcChargingInfo->Type == _Type_Chademo ||
                                 pDcChargingInfo->Type == _Type_GB) {
-                            if (_result == GFD_WARNING) {
-                                _result = GFD_PASS;
+                            if (gfgResult == GFD_WARNING) {
+                                gfgResult = GFD_PASS;
                             }
                         }
 
-                        if (_result == GFD_WARNING || _result == GFD_PASS) {
+                        if (gfgResult == GFD_WARNING || gfgResult == GFD_PASS) {
                             if (((GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 12000 &&
                                     pDcChargingInfo->RealRatingPower > 0) ||
                                     (GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 14000) {
                                 //log_info("**********EvComm : gunIndex= %d, RealRatingPower = %d \n",
                                 //            gunIndex,pDcChargingInfo->RealRatingPower);
-                                //_result = GFD_PASS;
+                                //gfgResult = GFD_PASS;
 
                                 //DS60-120 add
                                 if (LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] != pDcChargingInfo->RealRatingPower) {
@@ -854,15 +861,16 @@ int main(int argc, char *argv[])
 
                                 }
                             } else {
-                                _result = GFD_WAIT;
+                                gfgResult = GFD_WAIT;
                             }
                         }
 
-                        SetIsolationStatus(gunIndex, _result, pDcChargingInfo->Evboard_id);
+                        SetIsolationStatus(gunIndex, gfgResult, pDcChargingInfo->Evboard_id);
                     }
 
                     if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 &&
-                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
+                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY
+                       ) {
                         SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
                     }
                 }
@@ -907,7 +915,9 @@ int main(int argc, char *argv[])
 
                 if ((pDcChargingInfo->GroundFaultStatus == GFD_FAIL) ||
                         (pDcChargingInfo->Type == _Type_CCS_2)) {
-                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                    SetIsolationStatus(gunIndex,
+                                       pDcChargingInfo->GroundFaultStatus,
+                                       pDcChargingInfo->Evboard_id);
                 }
                 /*
                 else if (pDcChargingInfo->Type == _Type_CCS_2) {
@@ -918,7 +928,9 @@ int main(int argc, char *argv[])
                 if (priorityLow == 1) {
                     if (pDcChargingInfo->Type == _Type_CCS_2 &&
                             pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
-                        SetEvsePrechargeInfo(gunIndex, PRECHARGE_CHARELAY_PASS, pDcChargingInfo->Evboard_id);
+                        SetEvsePrechargeInfo(gunIndex,
+                                             PRECHARGE_CHARELAY_PASS,
+                                             pDcChargingInfo->Evboard_id);
                     }
                 }
                 break;
@@ -933,18 +945,23 @@ int main(int argc, char *argv[])
                 if (pDcChargingInfo->GunLocked == START ||
                         pDcChargingInfo->Type == _Type_CCS_2) {
                     uint8_t normalStop = 0x01;
-                    uint8_t stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+                    uint8_t stopReason[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
 
                     if (GetStopChargingReasonByEvse(gunIndex, stopReason)) {
                         normalStop = 0x02;
                     }
 
-                    EvseStopChargingEvent(normalStop, stopReason, pDcChargingInfo->Evboard_id);
+                    EvseStopChargingEvent(normalStop,
+                                          stopReason,
+                                          pDcChargingInfo->Evboard_id);
+
                     SendErrorCount[gunIndex] += 1; //DS60-120 add
                 }
 
                 if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                    SetIsolationStatus(gunIndex,
+                                       pDcChargingInfo->GroundFaultStatus,
+                                       pDcChargingInfo->Evboard_id);
                 }
 
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
@@ -952,13 +969,12 @@ int main(int argc, char *argv[])
                 //DS60-120 add
                 if (pDcChargingInfo->SystemStatus == S_ALARM) {
                     if (priorityLow == 1) {
-                        float maxVol, maxCur;
-
                         // 樁端輸出能力
                         maxVol = pDcChargingInfo->MaximumChargingVoltage;
                         maxCur = pDcChargingInfo->AvailableChargingCurrent;
 
                         GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+
                         SetChargingPermission(gunIndex,
                                               STOP,
                                               pDcChargingInfo->AvailableChargingPower,
@@ -974,8 +990,6 @@ int main(int argc, char *argv[])
                 SetPresentChargingOutputPower();
 
                 if (priorityLow == 1) {
-                    float maxVol, maxCur;
-
                     // 樁端輸出能力
                     maxVol = pDcChargingInfo->MaximumChargingVoltage;
                     maxCur = pDcChargingInfo->AvailableChargingCurrent;

+ 7 - 3
EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c

@@ -369,9 +369,12 @@ void CheckOutputPowerOverCarReq(uint8_t index)
                 }
             } else {
                 log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                         pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
+                         pDcChargingInfo->FireChargingVoltage,
+                         (pDcChargingInfo->EvBatterytargetVoltage * 10));
+
                 log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                          pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
+                          pDcChargingInfo->FireChargingVoltage,
+                          (pDcChargingInfo->EvBatterytargetVoltage * 10));
                 if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
                     if (pDcChargingInfo->Type == _Type_Chademo) {
                         pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
@@ -499,7 +502,8 @@ void SetK1K2RelayStatus(uint8_t index)
     GunPNState *pOutputGunPNState = NULL;
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
-    if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
+    if (ShmPsuData->Work_Step >= _TEST_MODE &&
+            ShmPsuData->Work_Step <= _TEST_MODE) {
         if (regRelay.relay_event.bits.Gun1_N == NO) {
             outputRelay.relay_event.bits.Gun1_N = YES;
         } else if (regRelay.relay_event.bits.Gun1_P == NO) {

+ 25 - 25
EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -4,7 +4,7 @@
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
 
-static SelectGunInfo *gAudiCustInfo = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
 bool needReloadQr = true;
 
 bool _isShow = false; //DS60-120 add
@@ -102,7 +102,7 @@ int InitShareMemory()
     if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
         log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
@@ -647,7 +647,7 @@ static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
     uint8_t cmd[10] = {0};
     uint8_t value[10] = {0};
     uint8_t len = 0;
-    float balance = gAudiCustInfo->PricesInfo[index].Balance;
+    float balance = ShmSelectGunInfo->PricesInfo[index].Balance;
 
     if ((balance) == (FAIL_BALANCE_PRICES)) {
         balance = 0.00;
@@ -921,62 +921,62 @@ void RefreshConnStatus()
     for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
             ehtStatus = 1;
-            //if (gAudiCustInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
-            //    gAudiCustInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
+            //if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+            //    ShmSelectGunInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
             //}
             break;
         }
     }
 
-    if (gAudiCustInfo->EthDevStatus.Backend == DEV_ST_DISABLE) {
+    if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_DISABLE) {
         ChangeDisplay2Value(__conn_status, _disappear);
-    } else if (gAudiCustInfo->EthDevStatus.Backend == DEV_ST_ENABLE_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_USE) {
         ChangeDisplay2Value(__conn_status, _connect);
-    } else if (gAudiCustInfo->EthDevStatus.Backend == DEV_ST_ENABLE_NO_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_NO_USE) {
         ChangeDisplay2Value(__conn_status, _disconnect);
     }
 
     if (ehtStatus == 1) {
-        if (gAudiCustInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
         }
     } else {
-        if (gAudiCustInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             ChangeDisplay2Value(__ethernet_status, _eth_connect);
         }
-        //if (gAudiCustInfo->EthDevStatus.Ethernet == DEV_ST_DISABLE) {
-        //} else if (gAudiCustInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_USE) {
+        //if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_DISABLE) {
+        //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_USE) {
         //    ChangeDisplay2Value(__ethernet_status, _eth_connect);
-        //} else if (gAudiCustInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_NO_USE) {
+        //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_NO_USE) {
         //    ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
         //}
     }
 
-    if (gAudiCustInfo->EthDevStatus.Wifi == DEV_ST_DISABLE) {
+    if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_DISABLE) {
         ChangeDisplay2Value(__wifi_status, _disappear);
 
         ChangeDisplay2Value(__3G4G_status, _disappear);
-        if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
             ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
             ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
             ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
         }
-    } else if (gAudiCustInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_USE) {
         ChangeDisplay2Value(__3G4G_move_status, _disappear);
         ChangeDisplay2Value(__wifi_status, _wifi_connect);
-    } else if (gAudiCustInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_NO_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_NO_USE) {
         ChangeDisplay2Value(__3G4G_move_status, _disappear);
         ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
     }
 
-    if (gAudiCustInfo->EthDevStatus.Wifi != DEV_ST_DISABLE) {
-        if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
+    if (ShmSelectGunInfo->EthDevStatus.Wifi != DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
             ChangeDisplay2Value(__3G4G_status, _disappear);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
             ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
             ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
         }
     }
@@ -1872,8 +1872,8 @@ void ChangeDisplayMoneyInfo()
 
         ChangeDisplay2Value(__money_rate_map, _charging_money);
 #if defined DD360Audi
-        if (gAudiCustInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
-            DisplayMoneyRate(gAudiCustInfo->PricesInfo[curGun].UserPrices);
+        if (ShmSelectGunInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
+            DisplayMoneyRate(ShmSelectGunInfo->PricesInfo[curGun].UserPrices);
         } else {
 #endif //defined DD360Audi
             if (tmCSU->tm_hour <= 23) {

+ 168 - 136
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -58,21 +58,21 @@ uint8_t _curAutoRunCount = 0;
 uint8_t _usingAutoRun = 0;
 struct timeval _autoTime;
 
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-struct CHAdeMOData              *ShmCHAdeMOData;
-struct CcsData                  *ShmCcsData;
-struct GBTData                  *ShmGBTData;
-struct FanModuleData            *ShmFanModuleData;
-struct RelayModuleData          *ShmRelayModuleData;
-struct LedModuleData            *ShmLedModuleData;
-struct PsuData                  *ShmPsuData;
-struct OCPP16Data               *ShmOCPP16Data;
-static SelectGunInfo             *gAudiCustInfo = NULL; //Jerry add
-
-struct ChargingInfoData         *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData         *ac_chargingInfo[AC_QUANTITY];
+struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
+struct StatusCodeData *ShmStatusCodeData = NULL;
+struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+struct CHAdeMOData *ShmCHAdeMOData = NULL;
+struct CcsData *ShmCcsData = NULL;
+struct GBTData *ShmGBTData = NULL;
+struct FanModuleData *ShmFanModuleData = NULL;
+struct RelayModuleData *ShmRelayModuleData = NULL;
+struct LedModuleData *ShmLedModuleData = NULL;
+struct PsuData *ShmPsuData = NULL;
+struct OCPP16Data *ShmOCPP16Data = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
+
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
 
 char *msg = "state : get gun state (index) \n"
             "card : scanning card (x) : \n"
@@ -128,16 +128,14 @@ int InitShareMemory()
         result = FAIL;
     } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         result = FAIL;
-    } else
-    {}
+    }
 
     //initial ShmStatusCodeData
     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
         result = FAIL;
     } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         result = FAIL;
-    } else
-    {}
+    }
 
     if (CHAdeMO_QUANTITY > 0) {
         if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
@@ -146,7 +144,6 @@ int InitShareMemory()
         } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
                    == (void *) - 1) {
             result = FAIL;
-        } else {
         }
     }
 
@@ -156,7 +153,6 @@ int InitShareMemory()
             result = FAIL;
         } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
             result = FAIL;
-        } else {
         }
     }
 
@@ -209,7 +205,7 @@ int InitShareMemory()
 
     if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
         return FAIL;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         return FAIL;
     }
 
@@ -653,11 +649,11 @@ static void get_char(char *word)
 
 static void setConfirmSelGun(uint8_t selGun)
 {
-    if (selGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun right\r\n");
     }
 }
@@ -665,8 +661,12 @@ static void setConfirmSelGun(uint8_t selGun)
 void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 {
     int _GunIndex;
+    uint8_t gunIndex = 0;
+    uint8_t stopChg = 0;
+    uint8_t curGun = 0;
     float _Voltage;
     float _Current;
+    uint8_t PreviousSystemStatus[2] = {0xff};
 
     if (strcmp(v1, "auto") == EQUAL) {
         _usingAutoRun = 0x01;
@@ -680,14 +680,15 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         _Current = atof(v3);
     }
 
-    uint8_t PreviousSystemStatus = 0xff;
     if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
         printf ("FindChargingInfoData error\n");
         return;
     }
 
-    printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-            ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
+    printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+           ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+           _Voltage,
+           _Current);
 
     if (_Voltage > 1000 || _Voltage < 50) {
         printf ("Input Voltage over range\n");
@@ -711,32 +712,35 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     //system(STTY_US TTY_PATH);
 
+    ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+
     while (true) {
+        curGun = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
+
         //fix gun 1
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+        switch (_chargingData[curGun]->SystemStatus) {
+        case S_IDLE:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 #if defined DD360Audi
-        setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                setConfirmSelGun(curGun);
 #endif //defined DD360Audi
-        switch (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-        case S_IDLE: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
                 strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->ConnectorPlugIn = 1;
+                _chargingData[curGun]->ConnectorPlugIn = 1;
                 printf ("[UnconditionalCharge - S_IDLE]\n");
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+                _chargingData[curGun]->Type = 9;
 
             }
             if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
                 ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
+                _chargingData[curGun]->SystemStatus = S_PREPARNING;
             }
-        }
-        break;
+            break;
 
-        case S_PREPARNING: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_PREPARNING:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARNIN]\n");
 
@@ -755,47 +759,45 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             //sleep(10);
 
             //清除 main timeout 機制
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+            _chargingData[curGun]->TimeoutFlag = 0;
             //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
-
-        }
-        break;
+            _chargingData[curGun]->Type = 9;
+            break;
 
-        case S_PREPARING_FOR_EV: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_PREPARING_FOR_EV:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
                 printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
 
             }
             //清除 main timeout 機制
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+            _chargingData[curGun]->TimeoutFlag = 0;
             //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+            _chargingData[curGun]->Type = 9;
 
             //充電電壓電流
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+            _chargingData[curGun]->EvBatterySoc             = 50;
+            _chargingData[curGun]->EvBatterytargetVoltage   = 500;
+            _chargingData[curGun]->EvBatterytargetCurrent   = 2;
+            _chargingData[curGun]->AvailableChargingCurrent = 1000;
 
             //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
             //確定模組己升壓完成
-            //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <=  (3000+500) &&
-            //  _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >=  (3000-500) )
+            //if(_chargingData[curGun]->PresentChargingVoltage <=  (3000+500) &&
+            //  _chargingData[curGun]->PresentChargingVoltage >=  (3000-500) )
             {
-                printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+                printf ("Precharge Done = %f \n",
+                        _chargingData[curGun]->PresentChargingVoltage);
                 //EV done
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
+                _chargingData[curGun]->SystemStatus = S_PREPARING_FOR_EVSE;
             }
-        }
-        break;
+            break;
 
-        case S_PREPARING_FOR_EVSE: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_PREPARING_FOR_EVSE:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
 
@@ -804,115 +806,130 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             //printf ("tar cur = %d \n", _Current);
 
             //清除 main timeout 機制
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+            _chargingData[curGun]->TimeoutFlag = 0;
             //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+            _chargingData[curGun]->Type = 9;
 
             //充電電壓電流
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+            _chargingData[curGun]->EvBatterySoc = 50;
+            _chargingData[curGun]->EvBatterytargetVoltage = 500;
+            _chargingData[curGun]->EvBatterytargetCurrent = 2;
+            _chargingData[curGun]->AvailableChargingCurrent = 1000;
 
-            //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
-            // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
+            //printf ("tar vol_ = %d \n", _chargingData[curGun]->EvBatterytargetVoltage);
+            // printf ("tar cur_ = %d \n", _chargingData[curGun]->EvBatterytargetCurrent);
 
             //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
             //確定模組己升壓完成
-            if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03) {
-                printf ("First Ground Fault State (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-                printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+            if (_chargingData[curGun]->GroundFaultStatus == 0x01 ||
+                    _chargingData[curGun]->GroundFaultStatus == 0x03) {
+                printf ("First Ground Fault State (%d)\n",
+                        _chargingData[curGun]->GroundFaultStatus);
+                printf ("Wait K1K2 = %f \n", _chargingData[curGun]->PresentChargingVoltage);
                 sleep(5);
                 //EV done
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
-            } else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02) {
-                printf ("First Ground Fault check Fail (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                _chargingData[curGun]->SystemStatus = S_CHARGING;
+            } else if (_chargingData[curGun]->GroundFaultStatus > 0x02) {
+                printf ("First Ground Fault check Fail (%d)\n",
+                        _chargingData[curGun]->GroundFaultStatus);
+                _chargingData[curGun]->SystemStatus = S_TERMINATING;
             }
+            break;
 
-        }
-        break;
-
-        case S_CHARGING: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_CHARGING:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 if (_usingAutoRun == 0x00) {
                     //充電電壓電流
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+                    _chargingData[curGun]->EvBatterytargetVoltage = _Voltage;
+                    _chargingData[curGun]->EvBatterytargetCurrent = _Current;
                 } else {
                     _curAutoRunCount = 0;
                     gettimeofday(&_autoTime, NULL);
                 }
 
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+                _chargingData[curGun]->EvBatterySoc = 50;
+                _chargingData[curGun]->AvailableChargingCurrent = 1000;
 
                 printf ("[UnconditionalCharge - S_CHARGING]\n");
             }
 
             if (_usingAutoRun == 0x01) {
-                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
-                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)) {
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
+                        (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
+                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
+                         (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
+                   ) {
+                    _chargingData[curGun]->EvBatterytargetVoltage = _Voltage;
+                    _chargingData[curGun]->EvBatterytargetCurrent = _Current;
                 } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
                     _curAutoRunCount++;
                     if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
-                        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                        _chargingData[curGun]->SystemStatus = S_TERMINATING;
                     } else {
                         gettimeofday(&_autoTime, NULL);
                     }
                 } else {
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
+                    _chargingData[curGun]->EvBatterytargetVoltage = 0;
+                    _chargingData[curGun]->EvBatterytargetCurrent = 0;
                 }
             }
 
 //              printf("out : vol = %f, cur = %f \n",
-//                      _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
-//                      _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
+//                      _chargingData[curGun]->EvBatterytargetVoltage,
+//                      _chargingData[curGun]->EvBatterytargetCurrent);
             //ev task do this
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
-                ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
-
-            if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02) {
-                printf ("Charging Ground Fault check Fail (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+            _chargingData[curGun]->PresentChargingPower =
+                ((float)((_chargingData[curGun]->PresentChargingVoltage) *
+                         (_chargingData[curGun]->PresentChargingCurrent)) / 1000);
+
+            if (_chargingData[curGun]->GroundFaultStatus == 0x02) {
+                printf ("Charging Ground Fault check Fail (%d)\n",
+                        _chargingData[curGun]->GroundFaultStatus);
+                _chargingData[curGun]->SystemStatus = S_TERMINATING;
             }
-        }
-        break;
+            break;
 
-        case S_TERMINATING: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-                system("/root/Module_EvComm &");
+        case S_TERMINATING:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_TERMINATING]\n");
                 //無阻塞偵測 keybaord 結束
                 system(STTY_DEF TTY_PATH);
             }
 
-            sleep(3);
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
-            return;
-        }
-        break;
+            _chargingData[curGun]->SystemStatus = S_COMPLETE;
+            break;
 
-        case S_COMPLETE: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_COMPLETE:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_COMPLETE]\n");
             }
 
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
-            sleep(3);
-            return;
-        }
-        break;
+            PreviousSystemStatus[curGun] = 0xFF;
+            stopChg = 0;
+            for (gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++) {
+                if (PreviousSystemStatus[gunIndex] == 0xFF) {
+                    _chargingData[curGun]->SystemStatus = S_IDLE;
+                }
+
+                if (_chargingData[gunIndex]->SystemStatus == S_IDLE) {
+                    stopChg++;
+                }
+            }
+
+            _chargingData[curGun]->PresentChargingPower = 0;
+
+            if (stopChg == ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                system("/root/Module_EvComm &");
+                sleep(3);
+                return;
+            }
+            break;
         }
 
         char word[128];
@@ -941,8 +958,11 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         }
 
         if (strcmp(newString[0], "strchg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
-                    strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0 ||
+                    strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0
+               ) {
                 printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
                 continue;
             }
@@ -955,14 +975,15 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             _Voltage = atof((char *)newString[2]);
             _Current = atof((char *)newString[3]);
 
-            uint8_t PreviousSystemStatus = 0xff;
             if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
                 printf ("FindChargingInfoData error\n");
                 continue;
             }
 
             printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-                    ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
+                    ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+                    _Voltage,
+                    _Current);
 
             if (_Voltage > 1000 || _Voltage < 50) {
                 _Voltage = 200;
@@ -970,29 +991,40 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 continue;
             }
 
+            ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
         } else if (strcmp(newString[0], "chg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+            if (strcmp(newString[1], "-1") == 0) {
                 continue;
             }
-            if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+
+            if (strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0) {
                 continue;
             }
 
-            float _vol = atof(newString[1]);
-            float _cur = atof(newString[2]);
+            if (strcmp(newString[3], "-1") == 0 ||
+                    strcmp(newString[3], "") == 0) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            float _vol = atof(newString[2]);
+            float _cur = atof(newString[3]);
 
             if (_cur <= 0 || _cur <= 0) {
                 continue;
             }
 
             printf("vol = %f, cur = %f \n", _vol, _cur);
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
+            _chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
+            _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
         } else if (strcmp(newString[0], "c") == 0) {
             if (atoi((char *)newString[1]) != -1) {
                 ShmSysConfigAndInfo->SysInfo.CurGunSelected = atoi((char *)newString[1]);
             }
             printf("stop \n\r");
+
             ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
             _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
         }

+ 10 - 0
EVSE/Projects/DD360/Apps/Script/SearchIP.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+# 用 arping 來 ping 區域網路中所有的 IP 位址
+echo $0;
+
+for ip in "$1".{1..254}; do
+  arping -I "$0" -w 3 -f $ip | grep reply &;
+done
+
+# 等待所有背景的 arping 結束
+wait;

+ 2 - 0
EVSE/Projects/DD360/Apps/Script/init.sh

@@ -9,3 +9,5 @@ chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
 chmod 777 Module_DoComm
+chmod 777 SearchIP.sh
+chmod 777 Module_FactoryConfig

+ 4 - 4
EVSE/Projects/DD360/Apps/Script/replaceOtherDD360Project.sh

@@ -10,12 +10,12 @@ echo $SCRIPTPATH
 ProjectPath="/opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects"
 
 rm -rf $ProjectPath/DD360/Apps/;
-cp -r  $ProjectPath/DD360Audi/Apps/  $ProjectPath/DD360/Apps;
-cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360/ModelNameList.txt;
+cp -r $ProjectPath/DD360Audi/Apps/ $ProjectPath/DD360/Apps;
+cp -r $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360/ModelNameList.txt;
 
 rm -rf $ProjectPath/DD360ComBox/Apps/;
-cp -r  $ProjectPath/DD360Audi/Apps/  $ProjectPath/DD360ComBox/Apps;
-cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360ComBox/ModelNameList.txt;
+cp -r $ProjectPath/DD360Audi/Apps/ $ProjectPath/DD360ComBox/Apps;
+cp -r $ProjectPath/DD360Audi/ModelNameList.txt $ProjectPath/DD360ComBox/ModelNameList.txt;
 
 git add $ProjectPath/DD360;
 git add $ProjectPath/DD360Audi;

+ 2 - 1
EVSE/Projects/DD360/Apps/SelectGun/SelectGun.h

@@ -93,7 +93,8 @@ typedef struct StAudiCustInfo {
     RemoteSetup RemoteSetup;
     EthDevStatus EthDevStatus;
     uint8_t AuthorStateFromCabinet[2];
-    uint8_t Reserved[2];
+    uint8_t WaitDoCommPermission[2]; //等待主櫃回覆再進入充電檢測
+    //uint8_t Reserved; //保留
 } SelectGunInfo;
 
 //------------------------------------------------------------------------------

+ 14 - 0
EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c

@@ -737,6 +737,8 @@ int InitSysConfigAndInfoShmMem(void)
 
 void ClearAllShmMemParameter(void)
 {
+    uint8_t i = 0;
+
     memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
     memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
     memset(ShmPsuData, 0, sizeof(struct PsuData));
@@ -764,6 +766,10 @@ void ClearAllShmMemParameter(void)
 
 #if defined DD360 || defined DD360Audi || defined DD360ComBox
     memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
+
+    for (i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
+        ShmSelectGunInfo->PricesInfo[i].Balance = FAIL_BALANCE_PRICES;
+    }
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 }
 
@@ -978,6 +984,14 @@ bool MappingGunChargingInfo(char *whichTask)
             log_error("%s add gun info failed\r\n", whichTask);
             return false;
         }
+
+        //確認有幾把水冷槍
+        if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 ||
+                strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0
+           ) {
+            ShmDcCommonData->ChillerValve.MultiChillerGun++;
+            ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80;
+        }
         slots++;
     }
 

+ 18 - 15
EVSE/Projects/DD360/Apps/timeout.h

@@ -32,26 +32,29 @@
 #include    <ctype.h>
 #include    <ifaddrs.h>
 
-#define CONN_PLUG_TIME_OUT          40
+//------------------------------------------------------------------------------
+#define CONN_PLUG_TIME_OUT                      (40)
 
+//------------------------------------------------------------------------------
 enum Timeout_flag {
-    Timeout_None =                      0,
-    Timeout_SelftestChk =               1,
-    Timeout_Authorizing =               2,
-    Timeout_VerifyFail =                3,
-    Timeout_VerifyComp =                4,
-    Timeout_WaitPlug =                  5,
+    Timeout_None                   = 0,
+    Timeout_SelftestChk            = 1,
+    Timeout_Authorizing            = 2,
+    Timeout_VerifyFail             = 3,
+    Timeout_VerifyComp             = 4,
+    Timeout_WaitPlug               = 5,
 
-    Timeout_Preparing =                 6,
-    Timeout_EvChargingDet =             7,
-    Timeout_EvseChargingDet =           8,
-    Timeout_EvseCompleteDet =           9,
-    Timeout_ForCcsPrechargeDet =        10,
-    Timeout_ReturnToChargingGunDet =    11,
-    Timeout_AuthorizingForStop =        12,
-    Timeout_SelectGun =                 13,
+    Timeout_Preparing              = 6,
+    Timeout_EvChargingDet          = 7,
+    Timeout_EvseChargingDet        = 8,
+    Timeout_EvseCompleteDet        = 9,
+    Timeout_ForCcsPrechargeDet     = 10,
+    Timeout_ReturnToChargingGunDet = 11,
+    Timeout_AuthorizingForStop     = 12,
+    Timeout_SelectGun              = 13,
 };
 
+//------------------------------------------------------------------------------
 // for timeout fork
 struct timeval _cmdSubPriority_time;
 unsigned short _connectionTimeout;

BIN
EVSE/Projects/DD360/Images/FactoryDefaultConfig.bin


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


+ 3 - 0
EVSE/Projects/DD360/ModelNameList.txt

@@ -13,3 +13,6 @@ Model Name: DDYE362F0KE2XP
 // *********** BYD *********** //
 Model Name: DOYE242000D2BD
 Model Name: DDYE242V0UE2BD
+
+
+DDWU362K0TE2PH

BIN
EVSE/Projects/DD360/output/FactoryConfig


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/ReadCmdline


+ 10 - 0
EVSE/Projects/DD360/output/SearchIP.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+# 用 arping 來 ping 區域網路中所有的 IP 位址
+echo $0;
+
+for ip in "$1".{1..254}; do
+  arping -I "$0" -w 3 -f $ip | grep reply &;
+done
+
+# 等待所有背景的 arping 結束
+wait;

+ 2 - 0
EVSE/Projects/DD360/output/init.sh

@@ -9,3 +9,5 @@ chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
 chmod 777 Module_DoComm
+chmod 777 SearchIP.sh
+chmod 777 Module_FactoryConfig

BIN
EVSE/Projects/DD360/output/main


+ 4 - 0
EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c

@@ -106,6 +106,7 @@ static int isReachableInternet(void)
             }
         }
     }
+
     pclose(fp);
 
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
@@ -119,6 +120,7 @@ static int isReachableInternet(void)
 #endif //defined DD360 || defined DD360Audi
 
     memset(buf, 0x00, sizeof(buf));
+
     for (idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
         sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
         fp = popen(cmd, "r");
@@ -175,6 +177,7 @@ void InitEthernet(void)
     system(tmpbuf);
     //system("ifconfig lo up");
     //  /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
+
     //Init Eth1 for administrator tool
     memset(tmpbuf, 0, 256);
     sprintf(tmpbuf, "/sbin/ifconfig eth1 %s netmask %s up",
@@ -202,6 +205,7 @@ void InitEthernet(void)
     pid_t pid = fork();
     if (pid == 0) {
         log_info("InitEthernet = %d\r\n", pid);
+
         for (;;) {
 #if defined DD360 || defined DD360Audi || defined DD360ComBox
             isReachableInternet();

+ 108 - 8
EVSE/Projects/DD360Audi/Apps/CSU/Primary.c

@@ -54,7 +54,6 @@ void PrimaryLedIndicatorCtrlFork(void)
         struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
         struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
         struct ChargingInfoData *pDcChargingInfo = NULL;
-        DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
         LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
 
@@ -62,7 +61,7 @@ void PrimaryLedIndicatorCtrlFork(void)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-                if (pSysWarning->Level == 2) {
+                if (pSysWarning->Level == WARN_LV_ER) {
                     if (checkCabinetEthConnectState(pLedConfig) == YES) {
                         usleep(500000);
                         continue;
@@ -147,7 +146,7 @@ void PrimaryLedIndicatorCtrlFork(void)
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    //if (pSysWarning->Level == 2) {
+                    //if (pSysWarning->Level == WARN_LV_ER) {
                     //    pLedConfig->YellowLED = NO;
                     //    pLedConfig->GreenLED = NO;
                     //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
@@ -166,7 +165,7 @@ void PrimaryLedIndicatorCtrlFork(void)
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
                     pLedConfig->RedLED = YES;
-                    //if (pSysWarning->Level == 2) {
+                    //if (pSysWarning->Level == WARN_LV_ER) {
                     //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
                     //        break;
                     //    }
@@ -187,23 +186,121 @@ void PrimaryLedIndicatorCtrlFork(void)
 }
 
 //------------------------------------------------------------------------------
+static void checkChargingInfoByDC(uint8_t systemStatus)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    switch (systemStatus) {
+    case S_IDLE:
+        if (isDetectPlugin()) {
+            _DetectPlugInTimeout();
+            StopSystemTimeoutDet();
+            destroySelGun(pSysInfo->CurGunSelected);
+        } else {
+#if !defined DD360Audi
+            break;
+#endif //!defined DD360Audi
+
+            if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
+                //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
+                destroySelGun(pSysInfo->CurGunSelected);
+            } else {
+                confirmSelGun(pSysInfo->CurGunSelected);
+                log_info("confirm select gun ............................... %d \n",
+                         pSysInfo->CurGunSelected);
+            }
+        }
+        break;
+
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+    case S_PREPARING_FOR_EVSE:
+    case S_CCS_PRECHARGE_ST0:
+    case S_CCS_PRECHARGE_ST1:
+        // 取消充電
+        if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+            AcChargingTerminalProcess();
+        } else {
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+        }
+        break;
+
+    case S_CHARGING:
+        if (pSysConfig->StopChargingByButton == YES ||
+                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+            // 停止充電
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+        }
+        break;
+
+    case S_COMPLETE:
+        break;
+    }
+}
+
+static void checkChargingInfoByAC(void)
+{
+    struct ChargingInfoData *pAcChargingInfo = NULL;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    if (pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
+        return;
+    }
+
+    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    switch (pAcChargingInfo->SystemStatus) {
+    case S_IDLE:
+        if (isDetectPlugin()) {
+            _DetectPlugInTimeout();
+            StopSystemTimeoutDet();
+        }
+        break;
+
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+    case S_PREPARING_FOR_EVSE:
+    case S_CCS_PRECHARGE_ST0:
+    case S_CCS_PRECHARGE_ST1:
+        // 取消充電
+        AcChargingTerminalProcess();
+        break;
+
+    case S_CHARGING:
+        if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+            // 停止充電
+            AcChargingTerminalProcess();
+        }
+        break;
+
+    case S_COMPLETE:
+        break;
+    }
+}
+
 void ChkPrimaryStatus(void)
 {
     static bool leftBtnPush = false;
     static bool rightBtnPush = false;
-    uint8_t Rtn;
+    uint8_t i = 0;
+    uint8_t Rtn = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
     struct ChargingInfoData *pDcChargingInfo = NULL;
-    struct ChargingInfoData *pAcChargingInfo = NULL;
     DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
     if (pSysWarning->WarningCount > 0) {
         Rtn = 0;
-        for (uint8_t i = 0; i < pSysWarning->WarningCount; i++) {
+        for (i = 0; i < pSysWarning->WarningCount; i++) {
             if (memcmp(&pSysWarning->WarningCode[i][0], "042251", 6) == 0) {
                 EmcOccureByString("042251");
                 ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = YES;
@@ -315,6 +412,9 @@ void ChkPrimaryStatus(void)
             leftBtnPush = true;
             log_info("left btn down...............................%x\n",
                      pDcChargingInfo->SystemStatus);
+            checkChargingInfoByAC();
+            checkChargingInfoByDC(pDcChargingInfo->SystemStatus);
+#if 0
             if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
                 pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
@@ -348,7 +448,6 @@ void ChkPrimaryStatus(void)
                     break;
                 }
             }
-
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
                 if (isDetectPlugin()) {
@@ -399,6 +498,7 @@ void ChkPrimaryStatus(void)
                 //pDcChargingInfo->SystemStatus = S_IDLE;
                 break;
             }
+#endif //0
         }
     } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
         if (leftBtnPush) {

+ 272 - 234
EVSE/Projects/DD360Audi/Apps/CSU/RFID.c

@@ -32,17 +32,75 @@ static bool canStartCharging(void)
     // 因為無法得知實際的長度,所以只能用搜尋的方式
     if (strcmp(buf2, "Accepted") == EQUAL) {
         return true;
-    } else {
-
     }
 
     return false;
 }
 
+static void isAutorCompleteHandle(uint8_t *authorizeIndex)
+{
+    uint8_t i = 0;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+
+    // 透過後臺停止充電的判斷
+    if (isAuthorizedComplete()
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            || (pSysInfo->OcppConnStatus == NO &&
+                pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+#endif //!defined DD360 && !defined DD360Audi
+       ) {
+
+        // 判斷後台回覆狀態
+        if (canStartCharging() == false) {
+            strcpy((char *)pSysConfig->UserId, "");
+            ClearAuthorizedFlag();
+
+            return;
+        }
+
+        if (*(authorizeIndex) != NO_DEFINE) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(*(authorizeIndex));
+
+            if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
+                    strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
+                // 先找 AC
+                if (*(authorizeIndex) == DEFAULT_AC_INDEX) {
+                    AcChargingTerminalProcess();
+                } else {
+                    ChargingTerminalProcess(*(authorizeIndex));
+                }
+            }
+
+            strcpy((char *)pSysConfig->UserId, "");
+            *(authorizeIndex) = NO_DEFINE;
+        }
+
+        ClearAuthorizedFlag();
+    } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
+        // 白名單驗證
+        for (i = 0; i < 10; i++) {
+            if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
+                continue;
+            }
+
+            if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
+                ChargingTerminalProcess(*(authorizeIndex));
+                strcpy((char *)pSysConfig->UserId, "");
+                ClearAuthorizedFlag();
+
+                break;
+            }
+        }
+    }
+}
+
 static void UserScanFunction(void)
 {
     bool idleReq = false;
+    uint8_t i = 0;
     uint8_t stopReq = NO_DEFINE;
+    char value[32] = {0};
     static uint8_t _authorizeIndex = NO_DEFINE;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -51,164 +109,138 @@ static void UserScanFunction(void)
     GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
     // 當前非驗證的狀態
-    if (!IsAuthorizingMode()) {
-#if defined DD360Audi
-        //當前沒有選槍
-        if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) { //Jerry add
-            strcpy((char *)pSysConfig->UserId, "");
-            return;
+    if (IsAuthorizingMode()) {
+        isAutorCompleteHandle(&_authorizeIndex);
+    }
+
+    //當前沒有選槍
+    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) {
+        strcpy((char *)pSysConfig->UserId, "");
+        return;
+    }
+
+    // 先判斷現在是否可以提供刷卡
+    // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
+    // 2. 停止充電
+    if (pSysInfo->PageIndex == _LCM_FIX) {
+        strcpy((char *)pSysConfig->UserId, "");
+        return;
+    }
+
+    for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+        if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+            stopReq = i;
         }
-#endif //defined DD360Audi
 
-        // 先判斷現在是否可以提供刷卡
-        // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
-        // 2. 停止充電
-        if (pSysInfo->PageIndex == _LCM_FIX) {
-            strcpy((char *)pSysConfig->UserId, "");
-            return;
+        if ((pDcChargingInfo->SystemStatus == S_IDLE &&
+                pDcChargingInfo->IsAvailable == YES) ||
+                (pGunIndexInfo->AcGunIndex > 0 &&
+                 pAcChargingInfo->SystemStatus == S_IDLE &&
+                 pAcChargingInfo->IsAvailable)
+           ) {
+            idleReq = true;
         }
+    }
 
-        for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+    if (pGunIndexInfo->AcGunIndex > 0 &&
+            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
+            pAcChargingInfo->SystemStatus == S_CHARGING) {
+        stopReq = DEFAULT_AC_INDEX;
+    }
 
-            if (pDcChargingInfo->SystemStatus == S_CHARGING) {
-                stopReq = i;
-            }
-            if ((pDcChargingInfo->SystemStatus == S_IDLE &&
-                    pDcChargingInfo->IsAvailable) == YES ||
-                    (pGunIndexInfo->AcGunIndex > 0 && pAcChargingInfo->SystemStatus ==
-                     S_IDLE && pAcChargingInfo->IsAvailable)
-               ) {
-                idleReq = true;
-            }
+    if (strlen((char *)pSysConfig->UserId) <= 0) {
+        return;
+    }
+
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+
+    if (pGunIndexInfo->AcGunIndex > 0 &&
+            stopReq == DEFAULT_AC_INDEX &&
+            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
+        log_info("ac stop charging \n");
+        log_info("index = %d, card number = %s, UserId = %s \n",
+                 pSysInfo->CurGunSelectedByAc,
+                 pAcChargingInfo->StartUserId,
+                 pSysConfig->UserId);
+
+        memset(value, 0, sizeof(value));
+        memcpy(value,
+               (uint8_t *)pAcChargingInfo->StartUserId,
+               ARRAY_SIZE(pAcChargingInfo->StartUserId));
+        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
+            AcChargingTerminalProcess();
         }
+        strcpy((char *)pSysConfig->UserId, "");
+    } else if (stopReq < pSysConfig->TotalConnectorCount &&
+               pDcChargingInfo->SystemStatus == S_CHARGING &&
+               (pGunIndexInfo->AcGunIndex <= 0 ||
+                (pGunIndexInfo->AcGunIndex > 0 &&
+                 pSysInfo->CurGunSelectedByAc == NO_DEFINE))
+              ) {
+        log_info("stop charging \n");
+        log_info("index = %d, card number = %s, UserId = %s \n",
+                 pSysInfo->CurGunSelected,
+                 pDcChargingInfo->StartUserId,
+                 pSysConfig->UserId);
+
+        memset(value, 0, sizeof(value));
+        memcpy(value,
+               (uint8_t *)pDcChargingInfo->StartUserId,
+               ARRAY_SIZE(pDcChargingInfo->StartUserId));
+
+        // 同一張卡直接停掉
+        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+            strcpy((char *)pSysConfig->UserId, "");
 
-        if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-                pAcChargingInfo->SystemStatus == S_CHARGING) {
-            stopReq = DEFAULT_AC_INDEX;
+            return;
         }
 
-        if (strlen((char *)pSysConfig->UserId) > 0) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+        // 進驗證
+        if (pGunIndexInfo->AcGunIndex > 0 &&
+                pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
+            _authorizeIndex = pSysInfo->CurGunSelectedByAc;
+        } else {
+            _authorizeIndex = pSysInfo->CurGunSelected;
+        }
 
-            if (pGunIndexInfo->AcGunIndex > 0 && stopReq == DEFAULT_AC_INDEX &&
-                    pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                char value[32];
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+        strcpy((char *)pSysConfig->UserId, "");
 
-                log_info("ac stop charging \n");
-                log_info("index = %d, card number = %s, UserId = %s \n", pSysInfo->CurGunSelectedByAc,
-                         pAcChargingInfo->StartUserId, pSysConfig->UserId);
-                memcpy(value, (uint8_t *)pAcChargingInfo->StartUserId,
-                       ARRAY_SIZE(pAcChargingInfo->StartUserId));
-                if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-                    AcChargingTerminalProcess();
-                }
-                strcpy((char *)pSysConfig->UserId, "");
-            } else if (stopReq < pSysConfig->TotalConnectorCount &&
-                       pDcChargingInfo->SystemStatus == S_CHARGING &&
-                       (pGunIndexInfo->AcGunIndex <= 0 || (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == NO_DEFINE))) {
-                char value[32];
-
-                log_info("stop charging \n");
-                log_info("index = %d, card number = %s, UserId = %s \n",
-                         pSysInfo->CurGunSelected,
-                         pDcChargingInfo->StartUserId,
-                         pSysConfig->UserId);
-                memcpy(value, (uint8_t *)pDcChargingInfo->StartUserId,
-                       ARRAY_SIZE(pDcChargingInfo->StartUserId));
-
-                // 同一張卡直接停掉
-                if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-                    ChargingTerminalProcess(pSysInfo->CurGunSelected);
-                    strcpy((char *)pSysConfig->UserId, "");
-                } else {
-                    // 進驗證
-                    if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                        _authorizeIndex = pSysInfo->CurGunSelectedByAc;
-                    } else {
-                        _authorizeIndex = pSysInfo->CurGunSelected;
-                    }
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    StartSystemTimeoutDet(Timeout_AuthorizingForStop);
-                    AuthorizingStart();
-#else
-                    strcpy((char *)pSysConfig->UserId, "");
-#endif //!defined DD360 && !defined DD360Audi
-                }
-            } else if (idleReq) {
-                if (pSysConfig->TotalConnectorCount > 1 &&
-                        stopReq != 255 &&
-                        pSysInfo->IsAlternatvieConf == YES) {
-                    idleReq = false;
-                    strcpy((char *)pSysConfig->UserId, "");
-                } else if ((pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-                           pDcChargingInfo->SystemStatus == S_IDLE) {
-                    log_info("// LCM => Authorizing \n");
-#if defined DD360Audi
-                    setSelGunWaitToAuthor(pSysInfo->CurGunSelected); //Jerry add
-#endif //defined DD360Audi
-                    // LCM => Authorizing
-                    pSysInfo->SystemPage = _LCM_AUTHORIZING;
-                    // 進入確認卡號狀態
-                    AuthorizingStart();
-                } else {
-                    strcpy((char *)pSysConfig->UserId, "");
-                }
-            } else {
-                strcpy((char *)pSysConfig->UserId, "");
-            }
+        return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+        StartSystemTimeoutDet(Timeout_AuthorizingForStop);
+
+        AuthorizingStart();
+    } else if (idleReq) {
+        if (pSysConfig->TotalConnectorCount > 1 &&
+                stopReq != 255 &&
+                pSysInfo->IsAlternatvieConf == YES) {
+            idleReq = false;
+            strcpy((char *)pSysConfig->UserId, "");
+        } else if ((pGunIndexInfo->AcGunIndex > 0 &&
+                    pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
+                   pDcChargingInfo->SystemStatus == S_IDLE) {
+            log_info("// LCM => Authorizing\r\n");
+
+            setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
+
+            // LCM => Authorizing
+            pSysInfo->SystemPage = _LCM_AUTHORIZING;
+
+            // 進入確認卡號狀態
+            AuthorizingStart();
+        } else {
+            strcpy((char *)pSysConfig->UserId, "");
         }
     } else {
-        // 透過後臺停止充電的判斷
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || (pSysInfo->OcppConnStatus == NO &&
-                    pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-           ) {
-            // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || (pSysInfo->OcppConnStatus == NO &&
-                        pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
-                if (_authorizeIndex != NO_DEFINE) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_authorizeIndex);
-
-                    // 先找 AC
-                    if (_authorizeIndex == DEFAULT_AC_INDEX) {
-                        if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
-                            AcChargingTerminalProcess();
-                        }
-                    } else {
-                        if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
-                            ChargingTerminalProcess(_authorizeIndex);
-                        }
-                    }
-                    strcpy((char *)pSysConfig->UserId, "");
-                    _authorizeIndex = NO_DEFINE;
-                }
-            } else {
-                strcpy((char *)pSysConfig->UserId, "");
-            }
-            ClearAuthorizedFlag();
-        } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                        ChargingTerminalProcess(_authorizeIndex);
-                        strcpy((char *)pSysConfig->UserId, "");
-                        ClearAuthorizedFlag();
-                        break;
-                    }
-                }
-            }
-        }
+        strcpy((char *)pSysConfig->UserId, "");
     }
+
+    return;
 }
 
 bool GetIsCardScan(void)
@@ -223,12 +255,15 @@ void SetIsCardScan(bool value)
 
 void ScannerCardProcess(void)
 {
+    int i = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
 
-    if (!isDetectPlugin() && !isCardScan && pSysWarning->Level != 2 &&
+    if (!isDetectPlugin() &&
+            !isCardScan &&
+            pSysWarning->Level != WARN_LV_ER &&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
         isCardScan = true;
         // 處理刷卡及驗證卡號的動作
@@ -238,21 +273,18 @@ void ScannerCardProcess(void)
     if (pSysInfo->PageIndex == _LCM_AUTHORIZING) {
         StartSystemTimeoutDet(Timeout_Authorizing);
 
+        //printf("isAuthorizedComplete = %d, %f\r\n", isAuthorizedComplete(), ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
         // 確認驗證卡號完成沒
         if (isAuthorizedComplete()
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#else
+#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 && ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance != FAIL_BALANCE_PRICES
-#endif //!defined DD360 && !defined DD360Audi
            ) {
             StopSystemTimeoutDet();
+
             // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
+            if (canStartCharging()) {
                 // LCM => Authorize complete
                 pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
             } else {
@@ -260,16 +292,19 @@ void ScannerCardProcess(void)
                 pSysInfo->SystemPage = _LCM_AUTHORIZ_FAIL;
                 strcpy((char *)pSysConfig->UserId, "");
             }
+
             ClearAuthorizedFlag();
         } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
             // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                        pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
-                        ClearAuthorizedFlag();
-                        break;
-                    }
+            for (i = 0; i < 10; i++) {
+                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
+                    continue;
+                }
+
+                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
+                    pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
+                    ClearAuthorizedFlag();
+                    break;
                 }
             }
         }
@@ -317,98 +352,101 @@ void CreateRfidFork(void)
     pid_t rfidRecPid;
 
     rfidRecPid = fork();
-    log_info("CreateRfidFork = %d\r\n", rfidRecPid);
     if (rfidRecPid == 0) {
         int fd = -1;
+        int isContinue = 1;
         RFID rfid = {0};
         fd = InitialRfidPort();
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
 
-        while (true) {
+        log_info("RFID fork Child's PID is %d\r\n", getpid());
+
+        while (isContinue) {
+            usleep(500000);
+
             // 刷卡判斷
             if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
                     !pSysConfig->isRFID) {
-                usleep(500000);
                 continue;
             }
 
             if (getRequestCardSN(fd, 0, &rfid) == false) {
-                usleep(500000);
                 continue;
             }
 
             //log_info("Get Card..-%s- \n", pSysConfig->UserId);
-            if (strlen((char *)pSysConfig->UserId) == 0) {
-                if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
-                    switch (rfid.snType) {
-                    case RFID_SN_TYPE_6BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5]);
-                        break;
-                    case RFID_SN_TYPE_7BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5],
-                                rfid.currentCard[6]);
-                        break;
-                    case RFID_SN_TYPE_10BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5],
-                                rfid.currentCard[6], rfid.currentCard[7],
-                                rfid.currentCard[8], rfid.currentCard[9]);
-                        break;
-                    case RFID_SN_TYPE_4BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3]);
-                        break;
-                    }
-                } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
-                    switch (rfid.snType) {
-                    case RFID_SN_TYPE_6BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[5], rfid.currentCard[4],
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_7BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[6], rfid.currentCard[5],
-                                rfid.currentCard[4], rfid.currentCard[3],
-                                rfid.currentCard[2], rfid.currentCard[1],
-                                rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_10BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[9], rfid.currentCard[8],
-                                rfid.currentCard[7], rfid.currentCard[6],
-                                rfid.currentCard[5], rfid.currentCard[4],
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_4BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X",
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    }
+            if (strlen((char *)pSysConfig->UserId) != 0) {
+                continue;
+            }
+
+            if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
+                switch (rfid.snType) {
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5],
+                            rfid.currentCard[6]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5],
+                            rfid.currentCard[6], rfid.currentCard[7],
+                            rfid.currentCard[8], rfid.currentCard[9]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3]);
+                    break;
+                }
+            } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
+                switch (rfid.snType) {
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[5], rfid.currentCard[4],
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[6], rfid.currentCard[5],
+                            rfid.currentCard[4], rfid.currentCard[3],
+                            rfid.currentCard[2], rfid.currentCard[1],
+                            rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[9], rfid.currentCard[8],
+                            rfid.currentCard[7], rfid.currentCard[6],
+                            rfid.currentCard[5], rfid.currentCard[4],
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X",
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
                 }
-                log_info("card number = %s\n", pSysConfig->UserId);
             }
-            usleep(500000);
+            log_info("card number = %s\n", pSysConfig->UserId);
         }
     }
 }

+ 143 - 135
EVSE/Projects/DD360Audi/Apps/CSU/SelfTest.c

@@ -18,6 +18,7 @@ extern void ChkPrimaryStatus(void);
 void SelfTestRun(void)
 {
     bool evInitFlag = false;
+    uint8_t index = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
@@ -36,177 +37,184 @@ void SelfTestRun(void)
     StartSystemTimeoutDet(Timeout_SelftestChk);
     pSysInfo->SelfTestSeq = _STEST_VERSION;
 
-    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE //||
-            //GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL <= 20 //DS60-120 add
-          ) {
-        if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
+        if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) { //自檢完成
             return;
         }
 
-        ChkPrimaryStatus();
-        if (pSysWarning->Level == 2 //||
-                //pAlarmCode->AlarmEvents.bits.PsuDipSwitchStestFail == YES //DS60-120 add
-           ) {
+        ChkPrimaryStatus(); //確認硬體有無錯誤,如急停按鈕或門有打開
+
+        if (pSysWarning->Level == WARN_LV_ER) {
             pSysInfo->SelfTestSeq = _STEST_FAIL;
             return;
         }
 
-        if (pSysConfig->TotalConnectorCount > 0) {
-            if (ShmPsuData->Work_Step == _NO_WORKING ||
-                    pSysInfo->SelfTestSeq == _STEST_FAIL) {
-                pSysInfo->SelfTestSeq = _STEST_FAIL;
-                return;
+        if (pSysConfig->TotalConnectorCount <= 0) {
+            pSysInfo->SelfTestSeq = _STEST_FAIL;
+            return;
+        }
+
+        if (ShmPsuData->Work_Step == _NO_WORKING ||
+                pSysInfo->SelfTestSeq == _STEST_FAIL) {
+            pSysInfo->SelfTestSeq = _STEST_FAIL;
+            return;
+        }
+
+        switch (pSysInfo->SelfTestSeq) {
+        case _STEST_VERSION:
+            if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
+                    pSysInfo->RelayModuleFwRev[0] != '\0') &&
+                    (ShmRelayModuleData->SelfTest_Comp != YES)
+               ) {
+                log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
+                ShmRelayModuleData->SelfTest_Comp = YES;
             }
 
-            switch (pSysInfo->SelfTestSeq) {
-            case _STEST_VERSION: {
-                if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
-                        pSysInfo->RelayModuleFwRev[0] != '\0')
-                        && (ShmRelayModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
-                    ShmRelayModuleData->SelfTest_Comp = YES;
-                }
 #if !defined NO_FAN_BOARD && !defined DD360ComBox
-                if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
-                        pSysInfo->FanModuleFwRev[0] != '\0')
-                        && (ShmFanModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
-                    ShmFanModuleData->SelfTest_Comp = YES;
-                }
-#else
+            if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
+                    pSysInfo->FanModuleFwRev[0] != '\0') &&
+                    (ShmFanModuleData->SelfTest_Comp != YES)
+               ) {
+                log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
                 ShmFanModuleData->SelfTest_Comp = YES;
+            }
+#else
+            ShmFanModuleData->SelfTest_Comp = YES;
 #endif //NO_FAN_BOARD
 
-                if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
-                        ShmPrimaryMcuData->version[0] != '\0')
-                        && (ShmPrimaryMcuData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
-                    ShmPrimaryMcuData->SelfTest_Comp = YES;
-                }
+            if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
+                    ShmPrimaryMcuData->version[0] != '\0') &&
+                    (ShmPrimaryMcuData->SelfTest_Comp != YES)
+               ) {
+                log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
+                ShmPrimaryMcuData->SelfTest_Comp = YES;
+            }
 
-                // EV 小板
-                if (!evInitFlag) {
-                    evInitFlag = YES;
-                    for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
-
-                        //log_info("index = %d, charging index = %d, type = %d\r\n",
-                        //         index,
-                        //         chargingInfo[index]->type_index,
-                        //         chargingInfo[index]->Type);
-                        if (pDcChargingInfo->Type == _Type_Chademo) {
-                            if ((strlen((char *)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version) != 0 ||
-                                    ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
-                                    //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
-                               ) {
-                                log_info("CHAdeMO[%d] FW Rev = %s", pDcChargingInfo->type_index, ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
-                                ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
-                            } else {
-                                //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
-                                evInitFlag = NO;
-                            }
-                        } else if (pDcChargingInfo->Type == _Type_GB) {
-                            if ((strlen((char *)ShmGBTData->evse[pDcChargingInfo->type_index].version) != 0 ||
-                                    ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
-                                    //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+            // EV 小板
+            if (!evInitFlag) {
+                evInitFlag = YES;
+                for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+                    //log_info("index = %d, charging index = %d, type = %d\r\n",
+                    //         index,
+                    //         chargingInfo[index]->type_index,
+                    //         chargingInfo[index]->Type);
+                    if (pDcChargingInfo->Type == _Type_Chademo) {
+                        if ((strlen((char *)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version) != 0 ||
+                                ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
+                                //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+                           ) {
+                            log_info("CHAdeMO[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                        } else {
+                            //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            evInitFlag = NO;
+                        }
+                    } else if (pDcChargingInfo->Type == _Type_GB) {
+                        if ((strlen((char *)ShmGBTData->evse[pDcChargingInfo->type_index].version) != 0 ||
+                                ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
+                                //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+                           ) {
+                            log_info("GBT[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmGBTData->evse[pDcChargingInfo->type_index].version);
+                            ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                        } else {
+                            //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            evInitFlag = NO;
+                        }
+                    } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                            if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version) != 0 ||
+                                    ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
+                                    /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
                                ) {
-                                log_info("GBT[%d] FW Rev = %s", pDcChargingInfo->type_index, ShmGBTData->evse[pDcChargingInfo->type_index].version);
-                                ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                                log_info("CCS[%d] FW Rev = %s",
+                                         pDcChargingInfo->type_index,
+                                         ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
+                                ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
                             } else {
-                                //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                                //log_info("CCS[%d] ccs fw lose...... %s \n",
+                                //         chargingInfo[index]->type_index,
+                                //         ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
                                 evInitFlag = NO;
                             }
-                        } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                            if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                                if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version) != 0 ||
-                                        ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
-                                        /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
-                                   ) {
-                                    log_info("CCS[%d] FW Rev = %s",
-                                             pDcChargingInfo->type_index,
-                                             ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
-                                    ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
-                                } else {
-                                    //log_info("CCS[%d] ccs fw lose...... %s \n",
-                                    //         chargingInfo[index]->type_index,
-                                    //         ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
-                                    evInitFlag = NO;
-                                }
-                            }
                         }
                     }
+                }
 
-                    for (uint8_t index = 0; index < pSysConfig->AcConnectorCount; index++) {
-                        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
-
-                        if (pAcChargingInfo->Type == _Type_AC) {
-                            if ((strlen((char *)pAcChargingInfo->version) != 0 || pAcChargingInfo->version[0] != '\0')
-                                    && (pAcChargingInfo->SelfTest_Comp != YES)
-                               ) {
-                                log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
-                                pAcChargingInfo->SelfTest_Comp = YES;
-                            } else {
-                                evInitFlag = NO;
-                            }
+                for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
+                    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
+
+                    if (pAcChargingInfo->Type == _Type_AC) {
+                        if ((strlen((char *)pAcChargingInfo->version) != 0 ||
+                                pAcChargingInfo->version[0] != '\0')
+                                && (pAcChargingInfo->SelfTest_Comp != YES)
+                           ) {
+                            log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
+                            pAcChargingInfo->SelfTest_Comp = YES;
+                        } else {
+                            evInitFlag = NO;
                         }
                     }
                 }
+            }
 
-                if ( ShmFanModuleData->SelfTest_Comp &&
-                        ShmRelayModuleData->SelfTest_Comp &&
-                        ShmPrimaryMcuData->SelfTest_Comp &&
-                        evInitFlag
-                   ) {
-                    pSysInfo->SelfTestSeq = _STEST_AC_CONTACTOR;
-                }
+            if (ShmFanModuleData->SelfTest_Comp &&
+                    ShmRelayModuleData->SelfTest_Comp &&
+                    ShmPrimaryMcuData->SelfTest_Comp &&
+                    evInitFlag
+               ) {
+                pSysInfo->SelfTestSeq = _STEST_AC_CONTACTOR;
             }
             break;
-            case _STEST_AC_CONTACTOR: {
-                //ShmPsuData->Work_Step = _TEST_COMPLETE;
-                // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (pSysInfo->AcContactorStatus == YES) {
-                    pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
-                    log_info("AC contactor self test OK");
-                }
-#else
+
+        case _STEST_AC_CONTACTOR:
+            //ShmPsuData->Work_Step = _TEST_COMPLETE;
+            // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
+            log_info("Waiting for DO communication");
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (pSysInfo->AcContactorStatus == YES) {
                 pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
-                log_info("Waiting for DO communication");
-#endif //!defined DD360 && !defined DD360Audi
+                log_info("AC contactor self test OK");
             }
             break;
-            case _STEST_PSU_DETECT: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
-                    pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
-                }
-#else
+
+        case _STEST_PSU_DETECT:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
                 pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
-#endif //defined DD360 && !defined DD360Audi
             }
             break;
-            case _STEST_PSU_CAP: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                // 此測試是要確認當前總輸出能力
-                // 如果沒有 PSU 模組請 bypass
-                if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
-                    sleep(1);
-                    pSysInfo->SelfTestSeq = _STEST_COMPLETE;
-                    pSysInfo->BootingStatus = BOOT_COMPLETE;
-                }
-#else
-                //check the power limit from DO
+
+        case _STEST_PSU_CAP:
+            // 此測試是要確認當前總輸出能力
+            // 如果沒有 PSU 模組請 bypass
+
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            //check the power limit from DO
+            pSysInfo->SelfTestSeq = _STEST_COMPLETE;
+            pSysInfo->BootingStatus = BOOT_COMPLETE;
+            log_info("Successful Self Test");
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
+                sleep(1);
                 pSysInfo->SelfTestSeq = _STEST_COMPLETE;
                 pSysInfo->BootingStatus = BOOT_COMPLETE;
-                log_info("Successful Self Test");
-#endif //defined DD360 && !defined DD360Audi
-            }
-            break;
             }
-        } else {
             break;
         }
 

+ 5 - 1
EVSE/Projects/DD360Audi/Apps/CSU/UpgradeFW.c

@@ -25,7 +25,11 @@ static int InitComPort(uint8_t target)
 
     if (target == UPGRADE_PRI) {
         fd = open(_priPortName, O_RDWR);
-    } else if (target == UPGRADE_FAN ||  target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED) {
+    } else if (target == UPGRADE_FAN ||
+               target == UPGRADE_RB ||
+               target == UPGRADE_AC ||
+               target == UPGRADE_LED
+              ) {
         fd = open(_485PortName, O_RDWR);
     }
 

Файловите разлики са ограничени, защото са твърде много
+ 454 - 222
EVSE/Projects/DD360Audi/Apps/CSU/main.c


+ 32 - 31
EVSE/Projects/DD360Audi/Apps/CSU/main.h

@@ -5,43 +5,44 @@
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
-#define MODELNAME_FAIL                          0
-#define BUFFER_SIZE                             128
-#define BTN_RELEASE                             0
-#define BTN_PRESS                               1
-#define MAX_BUF                                 64
-#define MtdBlockSize                            0x600000
+#define MODELNAME_FAIL                          (0)
+#define BUFFER_SIZE                             (128)
+#define BTN_RELEASE                             (0)
+#define BTN_PRESS                               (1)
+#define MAX_BUF                                 (64)
 #define SYSFS_GPIO_DIR                          "/sys/class/gpio"
-#define UPGRADE_FAN                             0x02
+#define UPGRADE_FAN                             (0x02)
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
-#define UPGRADE_RB                              0x09 //0x09 for DD360 dispenser
+#define UPGRADE_RB                              (0x09) //0x09 for DD360 dispenser
 #else
-#define UPGRADE_RB                              0x03 //other module use
-#endif //defined DD360 || defined DD360Audi
-#define UPGRADE_PRI                             0x04
-#define UPGRADE_AC                              0x05
-#define UPGRADE_LED                             0x06
-#define SYSTEM_MIN_VOL                          80 //150
-#define MIN_OUTPUT_CUR                          0
-#define AC_OUTPUT_VOL                           220
-
-#define DEFAULT_AC_INDEX                        2
-#define PSU_MIN_CUR                             100
+#define UPGRADE_RB                              (0x03) //other module use
+#endif //defined DD360 ||defined DD360Audi || defined DD360ComBox
+#define UPGRADE_PRI                             (0x04)
+#define UPGRADE_AC                              (0x05)
+#define UPGRADE_LED                             (0x06)
+#define SYSTEM_MIN_VOL                          (80) //150
+#define MIN_OUTPUT_CUR                          (0)
+#define AC_OUTPUT_VOL                           (220)
+
+#define DEFAULT_AC_INDEX                        (2)
+#define PSU_MIN_CUR                             (100)
 
 //#define DB_FILE                                 "/Storage/ChargeLog/localCgargingRecord.db"
 
-#define uSEC_VAL                                1000000
-#define SELFTEST_TIMEOUT                        60//45
-#define AUTHORIZE_TIMEOUT                       15//30
-#define AUTHORIZE_COMP_TIMEOUT                  3
-#define AUTHORIZE_FAIL_TIMEOUT                  3
-#define AUTHORIZE_STOP_TIMEOUT                  30
-#define RETURN_TO_CHARGING_PAGE                 30
-#define GUN_PREPARE_TIMEOUT                     30
-#define GUN_EV_WAIT_TIMEOUT                     120
-#define GUN_EVSE_WAIT_TIMEOUT                   60
-#define GUN_COMP_WAIT_TIMEOUT                   10
-#define GUN_PRECHARGING_TIMEOUT                 60
+#define uSEC_VAL                                (1000000)
+#define SELFTEST_TIMEOUT                        (60)//45
+#define AUTHORIZE_TIMEOUT                       (15)//30
+#define AUTHORIZE_COMP_TIMEOUT                  (3)
+#define AUTHORIZE_FAIL_TIMEOUT                  (3)
+#define AUTHORIZE_STOP_TIMEOUT                  (30)
+#define RETURN_TO_CHARGING_PAGE                 (30)
+#define GUN_PREPARE_TIMEOUT                     (30)
+#define GUN_EV_WAIT_TIMEOUT                     (120)
+#define GUN_EVSE_WAIT_TIMEOUT                   (60)
+#define GUN_COMP_WAIT_TIMEOUT                   (10)
+#define GUN_PRECHARGING_TIMEOUT                 (60)
+
+#define WHILE_LOOP_TIME                         (10000)
 
 //#define log_info(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)

+ 17 - 4
EVSE/Projects/DD360Audi/Apps/Config.h

@@ -77,12 +77,18 @@
 
 #define NO_DEFINE                               (255)
 
+#define MtdBlockSize                            (0x300000) //(0x600000)
+
 //------------------------------------------------------------------------------
 //gun temperatures
 //------------------------------------------------------------------------------
-#define GUN_OTP_VALUE                           150
-#define GUN_OTP_RECOVERY                        140
-#define UNDEFINED_TEMP                          255
+#define GUN_OTP_VALUE                           (150)
+#define GUN_OTP_RECOVERY                        (140)
+#define UNDEFINED_TEMP                          (255)
+
+#define WARN_LV_NL                              (0) //normal state
+#define WARN_LV_WARN                            (1)
+#define WARN_LV_ER                              (2) //emergency state
 
 //------------------------------------------------------------------------------
 enum _SYSTEM_STATUS {
@@ -332,6 +338,12 @@ typedef union {
     } StatusBit;
 } ChillerTempState;
 
+typedef struct StChillerValve {
+    uint8_t MultiChillerGun; //0x80, 0: 沒有水冷槍, 1: 有水冷槍, 0x7F: 紀錄水冷槍數
+    uint8_t LeftTemp;  //左槍最高溫度
+    uint8_t RightTemp; //右槍最高溫度
+} ChillerValve;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -340,9 +352,10 @@ typedef struct StDcCommonInfo {
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
     uint8_t SystemModeChange;
-    uint8_t Reserved[3];
     PowerAlarmState PowerAlarmState;
     ChillerTempState ChillerTempState[2];
+    ChillerValve ChillerValve;
+    uint8_t Reserved[3];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 84 - 13
EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c

@@ -101,18 +101,18 @@ int DB_Open(void)
     return result;
 }
 
-int DB_Insert_Record(int gun_index)
+int DB_Insert_Record(int gunIndex)
 {
     int result = PASS;
     char *errMsg = NULL;
     char insertSql[1024];
-    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
     struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
 
     sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
             "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
             pDcChargingInfo->ReservationId, //DS60-120 add
-            ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+            ShmOCPP16Data->StartTransaction[gunIndex].ResponseTransactionId,
             pDcChargingInfo->StartMethod,
             pDcChargingInfo->StartUserId,
             pDcChargingInfo->StartDateTime,
@@ -120,7 +120,7 @@ int DB_Insert_Record(int gun_index)
             pDcChargingInfo->EvBatteryStartSoc,
             pDcChargingInfo->EvBatterySoc,
             pDcChargingInfo->PresentChargedEnergy,
-            ShmOCPP16Data->StopTransaction[gun_index].StopReason);
+            ShmOCPP16Data->StopTransaction[gunIndex].StopReason);
 
     //if (sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db)) {
     if (sqlite3_open(DB_FILE, &localDb)) { //DS60-120 add
@@ -151,7 +151,7 @@ int DB_Insert_Record(int gun_index)
     return result;
 }
 
-int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
+int DB_Update_Operactive(uint8_t gunIndex, uint8_t IsAvailable)
 {
     uint8_t result = false;
     char *errMsg = NULL;
@@ -165,14 +165,17 @@ int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
     } else {
         log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
 
-        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
-        sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
+        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gunIndex, IsAvailable);
+        sprintf(sqlStr,
+                "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);",
+                gunIndex,
+                IsAvailable); //DS60-120 add
         log_info("sqlStr= %s\r\n", sqlStr);
         if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
             log_info( "update config error message: %s\n", errMsg);
         } else {
-            log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+            log_info("update connector-%d config item isOperactive to %d\r\n", gunIndex, IsAvailable);
         }
 
         sqlite3_close(localDb);
@@ -181,7 +184,7 @@ int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
     return result;
 }
 
-int DB_Get_Operactive(uint8_t gun_index)
+int DB_Get_Operactive(uint8_t gunIndex)
 {
     uint8_t result = true;
     char *errMsg = NULL;
@@ -189,8 +192,8 @@ int DB_Get_Operactive(uint8_t gun_index)
     char **rs;
     int  rows, cols;
 
-    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
-    sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gun_index); //DS60-120 add
+    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gunIndex);
+    sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gunIndex); //DS60-120 add
     //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
 
     if (sqlite3_open(DB_FILE, &localDb)) {
@@ -205,10 +208,10 @@ int DB_Get_Operactive(uint8_t gun_index)
                 if (strcmp(rs[(idxRow * cols) + 3], "0") == 0) {
                     result = false;
                 }
-                log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
+                log_info("Query connector-%d isOperactive: %s\r\n", gunIndex, rs[(idxRow * cols) + 3]);
             }
         } else {
-            log_info("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
+            log_info("Query connector-%d fail, set default value to operactive.\r\n", gunIndex);
         }
 
         sqlite3_free_table(rs);
@@ -252,3 +255,71 @@ int DB_Reboot_Record(void)
 
     return result;
 }
+
+//------------------------------------------------------------------------------
+//for Module_EventLog
+//------------------------------------------------------------------------------
+int CreateEventRecord(void)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char *createRecordSql = "CREATE TABLE IF NOT EXISTS event_record("
+                            "idx integer primary key AUTOINCREMENT, "
+                            "occurDatetime text NOT NULL, "
+                            "statusCode text NOT NULL"
+                            ");";
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_error( "Can't open database: %s\n", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info( "Local event record database open successfully.\n");
+
+        if (sqlite3_exec(localDb, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_error( "Create local event record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local event record table successfully\n");
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int InsertEventRecord(uint8_t *statusCode)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char sqlStr[1024] = {0};
+
+    sprintf(sqlStr, "insert into event_record(occurDatetime, statusCode) values(CURRENT_TIMESTAMP, '%s');", statusCode);
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info( "Local event record database open successfully.\n");
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert local event record error message: %s\n", errMsg);
+        } else {
+            log_info( "Insert local event record successfully\n");
+        }
+
+        sprintf(sqlStr, "delete from event_record where idx < (select idx from event_record order by idx desc limit 1)-2000;");
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "delete local event_record error message: %s\n", errMsg);
+        } else {
+            log_info( "delete local event record successfully\n");
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}

+ 9 - 0
EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.h

@@ -1,5 +1,14 @@
 #ifndef _DATA_BASE_H_
 #define _DATA_BASE_H_
 
+int DB_Open(void);
+int DB_Insert_Record(int gunIndex);
+int DB_Update_Operactive(uint8_t gunIndex, uint8_t IsAvailable);
+int DB_Get_Operactive(uint8_t gunIndex);
+int DB_Reboot_Record(void);
+
+//for Module_EventLog
+int CreateEventRecord(void);
+int InsertEventRecord(uint8_t *statusCode);
 
 #endif /* _DATA_BASE_H_ */

+ 10 - 0
EVSE/Projects/DD360Audi/Apps/DebugLog.md

@@ -5,3 +5,13 @@
 4. Fix ccs OVP status code not release issue.
 5. Add to complete the registration but did not get the balance to restart DoComm.
 6. Add button stop charging function.
+
+2021/06/10
+1. Add Chiller temperature OTP and chiller sensor broken status code 012323 and 011038.
+
+2021/06/18
+1. ReadCmdLine.c add support double test charging function.
+
+2021/06/23
+1. Debug Module_RateCurrent.c lost gun type issue.
+2. 在充電第二把槍時,槍櫃等待主後送permission後再通知小板進入充電狀態。

+ 4 - 4
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -527,7 +527,7 @@ struct ChargingInfoData
 	// Connector Temp
 	unsigned char 		ConnectorTemp;			//0x00: -60¢XC  ~  0xFE: 194
 	//Chiller Temp
-	unsigned char 		ChillerTemp;			//0x00: -60¢XC  ~  0xFE: 194
+    unsigned char       ChillerTemp;            //0x00: -60¢XC  ~  0xFE: 194
 	// Charging Status
 	unsigned char 		GroundFaultStatus;		// for GFD result => 0x00 : None, 0x01 : Can Start Charging, 0x02 : Stop Charging
 	unsigned short		RealRatingPower;
@@ -1345,9 +1345,9 @@ struct AlarmCodeData
             unsigned char PsuPfcEepromFault:1;                      //bit 6
             unsigned char PsuDcdcOverVoltage:1;                     //bit 7
             //AlarmVal[15]
-            unsigned char SystemChademoOutputUCP:1;				    //bit 0
-            unsigned char SystemCCSOutputUCP:1;				        //bit 1
-            unsigned char SystemGBTOutputUCP:1;				        //bit 2
+            unsigned char SystemChademoOutputUCP:1;                 //bit 0
+            unsigned char SystemCCSOutputUCP:1;                     //bit 1
+            unsigned char SystemGBTOutputUCP:1;                     //bit 2
             unsigned char SystemChillerOTP:1;                       //bit 3
             unsigned char Reserved:4;                               //bit 4~7
 		}bits;

+ 81 - 18
EVSE/Projects/DD360Audi/Apps/FactoryConfig.c

@@ -63,6 +63,25 @@ int StoreLogMsg(const char *fmt, ...)
     return rc;
 }
 
+int runShellCmd(const char *cmd)
+{
+    int result = FAIL;
+    char buf[256];
+    FILE *fp;
+
+    fp = popen(cmd, "r");
+    if (fp != NULL) {
+        while (fgets(buf, sizeof(buf), fp) != NULL) {
+            StoreLogMsg("%s\n", buf);
+        }
+
+        result = PASS;
+    }
+    pclose(fp);
+
+    return result;
+}
+
 void helpOutput(void)
 {
     printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
@@ -80,7 +99,7 @@ void helpOutput(void)
 int main(int argc, char *argv[])
 {
     uint8_t outType = 0;
-    unsigned int i, Chk, MtdBlockSize = 0x600000;
+    unsigned int i, Chk;
     uint8_t *ptr;
     int fd, wrd;
 
@@ -188,10 +207,15 @@ int main(int argc, char *argv[])
 
     //calculate CRC
     Chk = 0;
-    for (i = 0; i < (MtdBlockSize - 4); i++) {
+    for (i = ARRAY_SIZE(SysConfig.CsuBootLoadFwRev); i < (MtdBlockSize - 4); i++) {
         Chk += *(ptr + i);
     }
-    memcpy( ptr + MtdBlockSize - 4, &Chk, 4);
+    memcpy(ptr + MtdBlockSize - 4, &Chk, 4);
+    //Chk = 0;
+    //for (i = 0; i < (MtdBlockSize - 4); i++) {
+    //    Chk += *(ptr + i);
+    //}
+    //memcpy( ptr + MtdBlockSize - 4, &Chk, 4);
 
     /*
     * Parameter process
@@ -235,27 +259,65 @@ int main(int argc, char *argv[])
     /*
      * Configuration bin file generate
     */
-    if ((outType & OUTPUT_FILE) > 0) {
-        fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
-        if (fd < 0) {
-            StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
-            free(ptr);
-            return 0;
-        }
-        wrd = write(fd, ptr, MtdBlockSize);
-        close(fd);
-        if (wrd < MtdBlockSize) {
-            StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
-            free(ptr);
-            return 0;
-        }
-        StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
+    fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT | O_TRUNC);
+    if (fd < 0) {
+
+        StoreLogMsg("open /mnt/FactoryDefaultConfig.bin NG\n");
+
+        free(ptr);
+        return 0;
     }
+    wrd = write(fd, ptr, MtdBlockSize);
+    close(fd);
+    if (wrd < MtdBlockSize) {
+        StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\n");
+
+        free(ptr);
+        return 0;
+    }
+
+    StoreLogMsg("FactoryConfig write to file in /mnt OK.\n");
+
+    //if ((outType & OUTPUT_FILE) > 0) {
+    //    fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
+    //    if (fd < 0) {
+    //        StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
+    //        free(ptr);
+    //        return 0;
+    //    }
+    //    wrd = write(fd, ptr, MtdBlockSize);
+    //    close(fd);
+    //    if (wrd < MtdBlockSize) {
+    //        StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+    //        free(ptr);
+    //        return 0;
+    //    }
+    //    StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
+    //}
 
     /*
     * Flash memory write
     */
     if ((outType & OUTPUT_FLASH) > 0) {
+        StoreLogMsg("Erase /dev/mtd10.\n");
+        runShellCmd("flash_erase /dev/mtd10 0 0");
+        StoreLogMsg("Write /dev/mtd10.\n");
+        runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
+
+        StoreLogMsg("Erase /dev/mtd11.\n");
+        runShellCmd("flash_erase /dev/mtd11 0 0");
+        StoreLogMsg("Write /dev/mtd11.\n");
+        runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
+
+        StoreLogMsg("Erase /dev/mtd12.\n");
+        runShellCmd("flash_erase /dev/mtd12 0 0");
+        StoreLogMsg("Write /dev/mtd12.\n");
+        runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
+
+        system("rm -f /mnt/FactoryDefaultConfig.bin");
+
+        StoreLogMsg("FactoryConfig write to flash OK\n");
+#if 0
         // Save factory default setting value to flash factory default setting block
         fd = open("/dev/mtdblock12", O_RDWR);
         if (fd < 0) {
@@ -301,6 +363,7 @@ int main(int argc, char *argv[])
             return 0;
         }
         StoreLogMsg("FactoryConfig write to flash OK\r\n");
+#endif //0
     }
 
     free(ptr);

+ 14 - 6
EVSE/Projects/DD360Audi/Apps/Makefile

@@ -92,6 +92,12 @@ EVCOMM_SRC_FILES = $(patsubst %.o, %.c, $(EVCOMM_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#Event Log
+EVENTLOG_OBJ_FILES = $(COMMON_OBJ_FILES) $(DataBaseLib)/DataBase.o \
+						$(EventLogLib)/Module_EventLogging.o
+EVENTLOG_SRC_FILES = $(patsubst %.o, %.c, $(EVENTLOG_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
 
 all: CopyFile apps
 
@@ -120,6 +126,7 @@ EvCommTask:
 	#$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
 
 EventLoggingTask:
+	#$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
 	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
 	$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
 	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
@@ -154,12 +161,12 @@ UnsafetyOutputTool:
 
 FactoryConfigApp:
 	@echo "===== Module_FactoryConfig_Task =================================="
-	rm -f FactoryConfig
-#	gcc -D $(DEFINE) "-I../../" -o FactoryConfig "./FactoryConfig.c"
-#	mkdir -p /Storage/SystemLog
-#	./FactoryConfig -f;true
-#	cp /mnt/FactoryDefaultConfig.bin ../Images
-#	rm -f FactoryConfig;
+	rm -f Module_FactoryConfig
+	gcc $(DEFINE) -o FactoryConfig FactoryConfig.c
+	mkdir -p /Storage/SystemLog
+	./FactoryConfig -f;true
+	cp /mnt/FactoryDefaultConfig.bin ../Images
+	rm -f FactoryConfig;
 	$(CC) $(DEFINE) $(CFLAGS) -c -o FactoryConfig.o FactoryConfig.c
 	$(CC) -o FactoryConfig FactoryConfig.o
 
@@ -183,6 +190,7 @@ OtherTools:
 	cp -f $(ScriptLib)/init.sh $(OutputPath)
 	cp -f $(ScriptLib)/kill.sh $(OutputPath)
 	cp -f $(ScriptLib)/web.sh $(OutputPath)
+	cp -f $(ScriptLib)/SearchIP.sh $(OutputPath)
 	cp -f main $(OutputPath)
 	cp -f Module_DoComm $(OutputPath)
 	cp -f Module_EvComm $(OutputPath)

+ 81 - 76
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -37,15 +37,16 @@
 //static uint8_t PacketSe;
 static DoCommGblData gDoCommGblData = {0};
 
-static struct SysConfigAndInfo  *ShmSysConfigAndInfo;
-static struct StatusCodeData    *ShmStatusCodeData;
-static struct PsuData           *ShmPsuData;
-static struct OCPP16Data        *ShmOCPP16Data;
-static struct PrimaryMcuData    *ShmPrimaryMcuData;
+static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
+static struct StatusCodeData *ShmStatusCodeData     = NULL;
+static struct PsuData *ShmPsuData                   = NULL;
+static struct OCPP16Data *ShmOCPP16Data             = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData     = NULL;
+static SelectGunInfo *ShmSelectGunInfo              = NULL;
+
 static struct ChargingInfoData  *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 static struct timeb             gRegTimeUp[2][MAX_REGISTER_NUM] = {0};
 static struct WARNING_CODE_INFO gPreSysWarningInfo = {0};
-static SelectGunInfo             *gAudiCustInfo = NULL;
 
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
@@ -300,8 +301,8 @@ static int doCommConnToServer(void)
 //------------------------------------------------------------------------------
 static void clearPricesInfo(uint8_t id)
 {
-    memset(&gAudiCustInfo->PricesInfo[id], 0, sizeof(PricesInfo));
-    gAudiCustInfo->PricesInfo[id].Balance = FAIL_BALANCE_PRICES;
+    memset(&ShmSelectGunInfo->PricesInfo[id], 0, sizeof(PricesInfo));
+    ShmSelectGunInfo->PricesInfo[id].Balance = FAIL_BALANCE_PRICES;
 }
 
 static void ClearAuthorizedFlag(void)
@@ -330,8 +331,8 @@ static void destroySelectGun(uint8_t curGun)
     uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
 
     if (curGun == DESTROY_ALL_SEL) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
 
         for (i = 0; i < totalGun; i++) {
             ChargingData[i]->TimeoutFlag = Timeout_None;
@@ -342,15 +343,15 @@ static void destroySelectGun(uint8_t curGun)
     }
 
     //for charging timeout or complete
-    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+    if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
         if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
             ClearAuthorizedFlag();
         }
         clearPricesInfo(curGun);
     }
 
-    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
+    if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
         if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
             ClearAuthorizedFlag();
         }
@@ -361,8 +362,8 @@ static void destroySelectGun(uint8_t curGun)
 
 static int getConfirmSelectedGun(uint8_t curSel)
 {
-    if (((curSel == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
-            ((curSel == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
+    if (((curSel == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
+            ((curSel == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
         return PASS;
     }
 
@@ -371,11 +372,11 @@ static int getConfirmSelectedGun(uint8_t curSel)
 
 static int getSelGunWaitToAuthor(uint8_t curGun)
 {
-    if (curGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
+    if (curGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
         return FAIL;
     }
 
-    if (curGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
+    if (curGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
         return FAIL;
     }
 
@@ -384,11 +385,11 @@ static int getSelGunWaitToAuthor(uint8_t curGun)
 
 static void setConfirmSelGun(uint8_t selGun)
 {
-    if (selGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun right\r\n");
     }
 }
@@ -566,8 +567,8 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
         switch (cmd) {
         //--- Execute parameter ---
         case MISC_CMD_CONNECOTOR_TIMEOUT:
-            gAudiCustInfo->RemoteSetup.ConnectionTimeout = value;
-            log_info("connection timeout = %d\r\n", gAudiCustInfo->RemoteSetup.ConnectionTimeout);
+            ShmSelectGunInfo->RemoteSetup.ConnectionTimeout = value;
+            log_info("connection timeout = %d\r\n", ShmSelectGunInfo->RemoteSetup.ConnectionTimeout);
             clearMiscCommand();
             break;
 
@@ -629,25 +630,25 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 #endif //DD360Audi
 
-            gAudiCustInfo->PricesInfo[plugNum].Balance = transPricesUnit((int)value);
-            log_info("%d misc balance = %.2f\r\n", plugNum, gAudiCustInfo->PricesInfo[plugNum].Balance);
+            ShmSelectGunInfo->PricesInfo[plugNum].Balance = transPricesUnit((int)value);
+            log_info("%d misc balance = %.2f\r\n", plugNum, ShmSelectGunInfo->PricesInfo[plugNum].Balance);
             clearMiscCommand();
             break;
 
         case MISC_CMD_BACKEND_STATUS :
-            gAudiCustInfo->EthDevStatus.Backend = value;
+            ShmSelectGunInfo->EthDevStatus.Backend = value;
             break;
 
         case MISC_CMD_ETHERNET_STATUS :
-            gAudiCustInfo->EthDevStatus.Ethernet = value;
+            ShmSelectGunInfo->EthDevStatus.Ethernet = value;
             break;
 
         case MISC_CMD_WIFI_STATUS :
-            gAudiCustInfo->EthDevStatus.Wifi = value;
+            ShmSelectGunInfo->EthDevStatus.Wifi = value;
             break;
 
         case MISC_CMD_4G_STATUS :
-            gAudiCustInfo->EthDevStatus.FourG = value;
+            ShmSelectGunInfo->EthDevStatus.FourG = value;
             break;
 
         case MISC_CMD_BILLING_INFO:
@@ -700,9 +701,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
                 if (plugNum == LEFT_GUN_NUM &&
-                        (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
-                         gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-                    gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+                        (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
+                         ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+                    ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
                     strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
                     ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
                     sleep(1); //Jerry add
@@ -712,9 +713,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 }
 
                 if (plugNum == RIGHT_GUN_NUM &&
-                        (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
-                         gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-                    gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
+                        (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
+                         ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+                    ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
                     strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
                     ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
                     sleep(1); //Jerry add
@@ -733,7 +734,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
 
             ShmOCPP16Data->CsMsg.bits[plugNum].RemoteStartTransactionReq = YES;
-            gAudiCustInfo->PricesInfo[plugNum].Balance = 0.00;
+            ShmSelectGunInfo->PricesInfo[plugNum].Balance = 0.00;
             clearMiscCommand();
             break;
 
@@ -830,22 +831,22 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     pAccountInfo = (AccountInfo *)&data[addr];
 
     ShmSysConfigAndInfo->SysConfig.BillingData.Currency = pAccountInfo->Currency;
-    gAudiCustInfo->PricesInfo[plugNum].UserPrices         = transPricesUnit(ntohl(pAccountInfo->UserPrices));
-    ChargingData[plugNum]->ChargingFee                    = transPricesUnit(ntohl(pAccountInfo->TotalCost));
-    gAudiCustInfo->PricesInfo[plugNum].Balance            = transPricesUnit(ntohl(pAccountInfo->Balance));
+    ShmSelectGunInfo->PricesInfo[plugNum].UserPrices    = transPricesUnit(ntohl(pAccountInfo->UserPrices));
+    ChargingData[plugNum]->ChargingFee                  = transPricesUnit(ntohl(pAccountInfo->TotalCost));
+    ShmSelectGunInfo->PricesInfo[plugNum].Balance       = transPricesUnit(ntohl(pAccountInfo->Balance));
 
-    if ((pricesInfo[plugNum].UserPrices != gAudiCustInfo->PricesInfo[plugNum].UserPrices) ||
-            (pricesInfo[plugNum].Balance != gAudiCustInfo->PricesInfo[plugNum].Balance)) {
-        pricesInfo[plugNum].UserPrices = gAudiCustInfo->PricesInfo[plugNum].UserPrices;
-        pricesInfo[plugNum].Balance = gAudiCustInfo->PricesInfo[plugNum].Balance;
+    if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
+            (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance)) {
+        pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
+        pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
 
         log_info("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
                  plugNum,
-                 gAudiCustInfo->PricesInfo[plugNum].UserPrices,
+                 ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
                  ChargingData[plugNum]->ChargingFee,
-                 gAudiCustInfo->PricesInfo[plugNum].Balance,
-                 (uint8_t *)GetCurrency(ShmSysConfigAndInfo->SysConfig.BillingData.Currency));
-        //(uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+                 ShmSelectGunInfo->PricesInfo[plugNum].Balance,
+                 (uint8_t *)GetCurrency(ShmSysConfigAndInfo->SysConfig.BillingData.Currency)
+                );
     }
 
     return PASS;
@@ -1111,7 +1112,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             return COMMAND_RESULT_NG;
         }
 
-        gAudiCustInfo->AuthorStateFromCabinet[plugNum] = pCsuResult->Data.Data[0];
+        ShmSelectGunInfo->AuthorStateFromCabinet[plugNum] = pCsuResult->Data.Data[0];
 
         return pCsuResult->Data.Data[0];
         break;
@@ -1124,6 +1125,8 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
             return COMMAND_RESULT_NG;
         }
+
+        ShmSelectGunInfo->WaitDoCommPermission[plugNum] = pCsuResult->Data.Data[0];
         return pCsuResult->Data.Data[0];
         break;
 
@@ -1371,11 +1374,14 @@ 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[8] = {'\0'};
+    uint8_t dataBuf[10] = {'\0'};
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
 
+    pConnState->ConnectorTemp = ChargingData[plugNum]->ConnectorTemp;
+    pConnState->ChillerTemp = ChargingData[plugNum]->ChillerTemp;
+
     if (ChargingData[plugNum]->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
         strncpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
@@ -1693,7 +1699,7 @@ static int InitShareMemory(void)
     if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
         log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
@@ -1752,6 +1758,8 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
     //gunID = gDoCommGblData.ConnectorID[plugNum];
 #else
     gunID = ID_REGISTER;
+
+    ShmSelectGunInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0;
 #endif // DD360Audi
 
     if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == YES) ||
@@ -1772,22 +1780,17 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
                     strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
                 }
 
-                //printf("gAudiCustInfo->PricesInfo[plugNum].Balance = %.2f, %.2f\r\n",
-                //       gAudiCustInfo->PricesInfo[plugNum].Balance,
+                //printf("%d Balance = %.2f, %.2f\r\n",
+                //       plugNum,
+                //       ShmSelectGunInfo->PricesInfo[plugNum].Balance,
                 //       FAIL_BALANCE_PRICES);
-#if defined DD360Audi
-                if (gAudiCustInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES)
-#else
-                if (gAudiCustInfo->PricesInfo[plugNum].Balance == FAIL_BALANCE_PRICES) {
-                    gAudiCustInfo->PricesInfo[plugNum].Balance = 0;
-                }
-#endif //
-                {
+
+                if (ShmSelectGunInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES) {
                     ShmOCPP16Data->SpMsg.bits.AuthorizeConf    = YES; //isAuthorizedComplete
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq     = 0;
-                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
-                    ShmPsuData->SystemAvailablePower           = 0;
-                    ShmPsuData->SystemPresentPsuQuantity       = 0;
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq     = NO;
+                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+                    ShmPsuData->SystemAvailablePower           = NO;
+                    ShmPsuData->SystemPresentPsuQuantity       = NO;
                 }
             }
             ftime(&gRegTimeUp[plugNum][REG_USER_ID]);
@@ -1989,18 +1992,20 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         checkAuthorProcess(fd, plugNum);
 
         //authorization complete, write wait plug it state
-        if (gAudiCustInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES) {
-            ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
-                writeWaitPlugItState(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
-            }
+        if (ShmSelectGunInfo->PricesInfo[plugNum].Balance == FAIL_BALANCE_PRICES) {
+            break;
+        }
 
-            ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
-                readChargingCapability(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
-            }
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
+            writeWaitPlugItState(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
+        }
+
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME) {
+            readChargingCapability(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
 
@@ -2225,7 +2230,7 @@ int main(int argc, char *argv[])
             plugNum = 0;
             gunID = 0;
             for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
-                checkAuthorProcess(fd, plugNum);
+                //checkAuthorProcess(fd, plugNum);
                 //plugNum = setup chargingData value for bottom layer
                 //gunID = (plugNum  + 1); //connector Id, 1 = left gun, 2 = right gun
                 gunID = gDoCommGblData.ConnectorID[plugNum];

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

@@ -125,7 +125,9 @@
 typedef struct StConnectorState {
     uint8_t State;
     uint8_t WarningCode[6];
-    uint8_t Reserved;
+    uint8_t ConnectorTemp;
+    uint8_t ChillerTemp;
+    uint8_t Reserved[3];
 } ConnectorState;
 
 typedef struct StConnectorIDTable {

+ 6 - 3
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalState.c

@@ -27,7 +27,8 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     //iflog_info("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
 
     if (strncmp(string, "000000", 6) == EQUAL ||
-            strncmp(string, "023979", 6) == EQUAL) {
+            strncmp(string, "023979", 6) == EQUAL
+       ) {
         return false;
     }
 
@@ -37,11 +38,15 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
 
     memcpy(pDcChargingInfo->EvConnAlarmCode, string, 6);
     log_info("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s\n", pDcChargingInfo->EvConnAlarmCode);
+
     //OVP error
     if (strcmp(string, "012217") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES; }
     if (strcmp(string, "012219") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES; }
     if (strcmp(string, "012221") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES; }
 
+    //UVP error
+    if (strcmp(string, "012288") == EQUAL) { pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES; }
+
     if (strcmp(string, "023700") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvCommFail = YES; }
     if (strcmp(string, "023704") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryMalfun = YES; }
     if (strcmp(string, "023705") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoNoPermission = YES; }
@@ -77,8 +82,6 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     if (strcmp(string, "023735") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = YES; }
     if (strcmp(string, "023736") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown = YES; }
 
-    if (strcmp(string, "012288") == EQUAL) { pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES; }
-
     if (strcmp(string, "023701") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = YES; }
     if (strcmp(string, "023737") == EQUAL) { pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit = YES; }
     if (strcmp(string, "023738") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVShiftPosition = YES; }

+ 9 - 9
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.c

@@ -50,7 +50,7 @@ void SetTargetAddr(uint8_t *target_number, uint8_t index)
     SendCmdToEvboard(id, data, 5);
 }
 
-void GetFirmwareVersion(uint8_t gun_index, uint8_t toId)
+void GetFirmwareVersion(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_FW_VER + toId);
     uint8_t data[8];
@@ -58,7 +58,7 @@ void GetFirmwareVersion(uint8_t gun_index, uint8_t toId)
     SendCmdToEvboard(id, data, 0);
 }
 
-void GetHardwareVersion(uint8_t gun_index, uint8_t toId)
+void GetHardwareVersion(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_HW_VER + toId);
     uint8_t data[8];
@@ -66,7 +66,7 @@ void GetHardwareVersion(uint8_t gun_index, uint8_t toId)
     SendCmdToEvboard(id, data, 0);
 }
 
-void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch)
+void SyncRtcInfo(uint8_t gunIndex, uint8_t toId, int epoch)
 {
     int id = PackageIdCmd(CMD_SYNC_RTC + toId);
     uint8_t data[8];
@@ -79,7 +79,7 @@ void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch)
     SendCmdToEvboard(id, data, 4);
 }
 
-void SetChargingPermission(uint8_t gun_index, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputCur, uint16_t aOutputVol, uint8_t toId)
+void SetChargingPermission(uint8_t gunIndex, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputCur, uint16_t aOutputVol, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_CHARGING_PERMISSION + toId);
     uint8_t data[8];
@@ -130,7 +130,7 @@ void SetPresentOutputCapacity(uint16_t aOutputPw_b1, uint16_t aOutputCur_b1, uin
     SendCmdToEvboard(id, data, 8);
 }
 
-void GetOutputReq(uint8_t gun_index, uint8_t toId)
+void GetOutputReq(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_OUTPUT_REQ + toId);
     uint8_t data[8];
@@ -138,7 +138,7 @@ void GetOutputReq(uint8_t gun_index, uint8_t toId)
     SendCmdToEvboard(id, data, 0);
 }
 
-void GetEvBatteryInfo(uint8_t gun_index, uint8_t toId)
+void GetEvBatteryInfo(uint8_t gunIndex, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_BATTERY_INFO + toId);
     uint8_t data[8];
@@ -162,7 +162,7 @@ void EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId
     SendCmdToEvboard(id, data, 7);
 }
 
-void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, float voltage, uint8_t toId)
+void GetMiscellaneousInfo(uint8_t gunIndex, uint8_t relayStatus, float power, float voltage, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_GET_MISC_INFO + toId);
     uint8_t data[8];
@@ -178,7 +178,7 @@ void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, f
     SendCmdToEvboard(id, data, 5);
 }
 
-void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId)
+void SetIsolationStatus(uint8_t gunIndex, uint8_t result, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_ISOLATION_STATUS + toId);
     uint8_t data[8];
@@ -187,7 +187,7 @@ void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId)
     SendCmdToEvboard(id, data, 1);
 }
 
-void SetEvsePrechargeInfo(uint8_t gun_index, uint8_t result, uint8_t toId)
+void SetEvsePrechargeInfo(uint8_t gunIndex, uint8_t result, uint8_t toId)
 {
     int id = PackageIdCmd(CMD_EVSE_PRECHARGE + toId);
     uint8_t data[8];

+ 9 - 9
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.h

@@ -46,17 +46,17 @@
 // Send msg to can-bus
 void SetTargetAddr(uint8_t *target_number, uint8_t index);
 
-void GetFirmwareVersion(uint8_t gun_index, uint8_t toId);
-void GetHardwareVersion(uint8_t gun_index, uint8_t toId);
-void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch);
-void SetChargingPermission(uint8_t gun_index, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputVol, uint16_t aOutputCur, uint8_t toId);
+void GetFirmwareVersion(uint8_t gunIndex, uint8_t toId);
+void GetHardwareVersion(uint8_t gunIndex, uint8_t toId);
+void SyncRtcInfo(uint8_t gunIndex, uint8_t toId, int epoch);
+void SetChargingPermission(uint8_t gunIndex, uint8_t permissionStatus, uint16_t aOutputPw, uint16_t aOutputVol, uint16_t aOutputCur, uint8_t toId);
 void SetPresentOutputPower(uint16_t outputVol_b1, uint16_t outputCur_b1, uint16_t outputVol_b2, uint16_t outputCur_b2);
 void SetPresentOutputCapacity(uint16_t aOutputPw_b1, uint16_t aOutputCur_b1, uint16_t aOutputPw_b2, uint16_t aOutputCur_b2);
-void GetOutputReq(uint8_t gun_index, uint8_t toId);
-void GetEvBatteryInfo(uint8_t gun_index, uint8_t toId);
-void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, float voltage, uint8_t toId);
-void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId);
-void SetEvsePrechargeInfo(uint8_t gun_index, uint8_t result, uint8_t toId);
+void GetOutputReq(uint8_t gunIndex, uint8_t toId);
+void GetEvBatteryInfo(uint8_t gunIndex, uint8_t toId);
+void GetMiscellaneousInfo(uint8_t gunIndex, uint8_t relayStatus, float power, float voltage, uint8_t toId);
+void SetIsolationStatus(uint8_t gunIndex, uint8_t result, uint8_t toId);
+void SetEvsePrechargeInfo(uint8_t gunIndex, uint8_t result, uint8_t toId);
 // 發送電樁主動停止充電結果及原因
 void EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId);
 

+ 50 - 40
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -25,6 +25,7 @@ static struct AlarmCodeData *pAlarmCode = NULL;
 static struct CHAdeMOData *ShmCHAdeMOData = NULL;
 static struct GBTData *ShmGBTData = NULL;
 static struct CcsData *ShmCcsData = NULL;
+static struct FanModuleData *ShmFanModuleData = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
 
 //------------------------------------------------------------------------------
@@ -133,15 +134,16 @@ static void getChillerTemperature(ChillerTemp *chillerTemp)
             pChillerTemp->Temp[i] = 195;
         }
 
-        //CcsConnectorTemp1 = ReadAdcVolt(i);
-        //if ((CcsConnectorTemp1 <= 0.9) && (CcsConnectorTemp1 >= 0.8)) { //0 ~ -40
-        //    CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 500;
-        //} else if ((CcsConnectorTemp1 <= 1.07) && (CcsConnectorTemp1 > 0.9)) {
-        //    CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 705.88;
-        //} else {
-        //    CcsConnectorTemp1 = 195;    //not available
-        //}
-        //CcsConnectorTemp |= ((unsigned int)(CcsConnectorTemp1 + 60) & 0xFF) << (i * 8); //0x00(-60)~0xFE(194)
+        /*CcsConnectorTemp1 = ReadAdcVolt(i);
+        if ((CcsConnectorTemp1 <= 0.9) && (CcsConnectorTemp1 >= 0.8)) { //0 ~ -40
+            CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 500;
+        } else if ((CcsConnectorTemp1 <= 1.07) && (CcsConnectorTemp1 > 0.9)) {
+            CcsConnectorTemp1 = (CcsConnectorTemp1 - 0.9) * 705.88;
+        } else {
+            CcsConnectorTemp1 = 195;    //not available
+        }
+        CcsConnectorTemp |= ((unsigned int)(CcsConnectorTemp1 + 60) & 0xFF) << (i * 8); //0x00(-60)~0xFE(194)
+        */
     }
 }
 
@@ -178,6 +180,7 @@ static void AddrAssignment(uint8_t *data)
     //log_info("target_number[4] = %x \n", target_number[4]);
 
     log_info("SetTargetAddr = %d, type = %d \n", index, pDcChargingInfo->Type);
+
     SetTargetAddr(target_number, index);
     //}
 }
@@ -188,7 +191,6 @@ void CANReceiver(int fd)
 
     canRecPid = fork();
 
-
     if (canRecPid < 0) {
         log_error("Create CAN Bus receive task failed\r\n");
         return;
@@ -217,8 +219,9 @@ void CANReceiver(int fd)
         ShmGBTData = (struct GBTData *)GetShmGBTData();
         ShmCcsData = (struct CcsData *)GetShmCcsData();
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+        ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
 
-        log_info("Child's PID is %d\r\n", getpid());
+        log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
 
         while (isContinue) {
             memset(&frame, 0, sizeof(struct can_frame));
@@ -257,7 +260,7 @@ void CANReceiver(int fd)
                 }
             }
 
-            if (targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) {
+            if ((targetGun < 0) || (targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)) {
                 log_info("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
                 usleep(10000);
                 continue;
@@ -276,7 +279,7 @@ void CANReceiver(int fd)
 
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
             gunTypeIndex = pDcChargingInfo->type_index;
-            //log_info("intCmd = %x\r\n", intCmd);
+
             switch (intCmd) {
             case NOTIFICATION_EV_STATUS:
                 if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
@@ -336,11 +339,13 @@ void CANReceiver(int fd)
                     memset(pSysInfo->Connector1FwRev,
                            0,
                            sizeof(pSysInfo->Connector1FwRev));
+
                     memcpy(pSysInfo->Connector1FwRev, ver, ARRAY_SIZE(ver));
                 } else if (targetGun == 1) {
                     memset(pSysInfo->Connector2FwRev,
                            0,
                            sizeof(pSysInfo->Connector2FwRev));
+
                     memcpy(pSysInfo->Connector2FwRev, ver, ARRAY_SIZE(ver));
                 }
                 break;
@@ -354,7 +359,8 @@ void CANReceiver(int fd)
                 if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
                         pDcChargingInfo->SystemStatus <= S_CHARGING) ||
                         (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
+                   ) {
                     if (pDcChargingInfo->EvBatteryStartSoc <= 0) {
                         pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
                     }
@@ -457,37 +463,14 @@ void CANReceiver(int fd)
                 }
                 }*/
 
-                //memset((uint8_t)&chiilerTemp, 0, sizeof(ChillerTemp));
-                //if (targetGun == 0 &&
-                //        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                //         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
-                //   ) {
-                //    getChillerTemperature(&chiilerTemp);
-                //    pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
-                //    //pDcChargingInfo->ConnectorTemp = getMaxConnectTempAndChiller(
-                //    //                                     frame.data[1],
-                //    //                                     frame.data[2],
-                //    //                                     chiilerTemp.Temp[0],
-                //    //                                     chiilerTemp.Temp[1]);
-                //} else if (targetGun == 1 &&
-                //           ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                //            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
-                //          ) {
-                //    getChillerTemperature(&chiilerTemp);
-                //    pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
-                //}
-#if 1
-                if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                        (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
-                        (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                        (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
-                   ) {
+                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) == YES) {
                     getChillerTemperature(&chiilerTemp);
                     pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                 }
 
                 pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
 
+                //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
                 if ((ShmDcCommonData->SystemModeChange == YES) ||
                         (((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
                           (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
@@ -502,7 +485,34 @@ void CANReceiver(int fd)
                              chiilerTemp.Temp[0],
                              chiilerTemp.Temp[1]);
                 }
-#endif //0
+
+                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) == NO) {
+                    //沒有水冷槍
+                    break;
+                }
+
+                if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
+                    //單一水冷槍,不需要切換水冷機油閥
+                    //ShmFanModuleData-> ? = YES; //尚未定義
+                    break;
+                }
+
+                //紀錄槍頭溫度
+                if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
+                    if (targetGun == 0) {
+                        ShmDcCommonData->ChillerValve.LeftTemp = pDcChargingInfo->ConnectorTemp;
+                    } else if (targetGun == 1) {
+                        ShmDcCommonData->ChillerValve.RightTemp = pDcChargingInfo->ConnectorTemp;
+                    }
+                }
+
+                //有兩把水冷槍,判斷兩把槍頭溫度,將水冷機節流閥導向溫度高的那一把槍
+                if (ShmDcCommonData->ChillerValve.LeftTemp > ShmDcCommonData->ChillerValve.RightTemp) {
+                    //ShmFanModuleData->? = YES; //尚未定義
+                } else {
+                    //ShmFanModuleData->? = NO; //尚未定義
+                }
+
                 //log_info("EvboardStatus = %x \n",
                 //         ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
                 //log_info("ConnectorPlug locked = %x \n",

+ 61 - 47
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -20,6 +20,7 @@
 #include "../Log/log.h"
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
+#include "../SelectGun/SelectGun.h"
 #include "Ev_Comm.h"
 #include "Module_EvComm.h"
 
@@ -33,6 +34,7 @@ static struct CHAdeMOData *ShmCHAdeMOData = NULL;
 static struct GBTData *ShmGBTData = NULL;
 static struct CcsData *ShmCcsData = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
 
 // 限制最大充電電壓,因應不同 type 槍線來限制
 // Chademo : 500V, 125A,
@@ -42,9 +44,9 @@ static DcCommonInfo *ShmDcCommonData = NULL;
 //static double chademoVol = 5000;
 //static double ccsVol = 9500;
 //static double gbVol = 7500;
-static float maxChargingVol[2] = { 0, 0 };       // 限制最大充電電壓,如依照模塊則填上 0
+static float maxChargingVol[2] = {0, 0};       // 限制最大充電電壓,如依照模塊則填上 0
 // 限制最大充電電流與能量透過 Web
-static float maxChargingCur[2] = { 0, 0 };         // 限制最大充電電流,如依照模塊則填上 0
+static float maxChargingCur[2] = {0, 0};         // 限制最大充電電流,如依照模塊則填上 0
 static float maxChargingPow = 0;                   // 限制最大充電能量,如依照模塊則填上 0
 
 static float LogInfo[2][10]; //DS60-120 add
@@ -476,9 +478,9 @@ static void SetPresentChargingOutputPower(void)
 static void checkConnectorOVPState(uint8_t gunIndex)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-
     // 避免槍溫偵測誤判
     static uint8_t gunTempAllowCount[2] = {0};
+
     bool isOTP = false;
 
     switch (pDcChargingInfo->Type) {
@@ -572,9 +574,11 @@ int main(int argc, char *argv[])
     uint8_t gunIndex = 0;
     uint8_t typeIndex = 0;
     uint8_t priorityLow = 1;
-    uint8_t SendErrorCount[2] = { 0, 0};
+    uint8_t SendErrorCount[2] = {0, 0};
+    uint8_t gfgResult = 0;
     uint32_t _timeBuf = 0;
     uint32_t chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {0};
+    float maxVol, maxCur;
     struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     time_t rtc = {0};
@@ -595,6 +599,7 @@ int main(int argc, char *argv[])
     ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
     ShmGBTData = (struct GBTData *)GetShmGBTData();
     ShmCcsData = (struct CcsData *)GetShmCcsData();
+    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
 
     CanFd = InitCanBus();
 
@@ -627,8 +632,10 @@ int main(int argc, char *argv[])
                     }
                 }
 
-                // 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
-                //log_info("GetMiscellaneousInfo. index = %d, Eid = %d \n", gunIndex, pDcChargingInfo->Evboard_id);
+                //固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
+                //log_info("GetMiscellaneousInfo. index = %d, Eid = %d \n",
+                //         gunIndex,
+                //         pDcChargingInfo->Evboard_id);
                 GetMiscellaneousInfo(gunIndex,
                                      pDcChargingInfo->RelayK1K2Status,
                                      pDcChargingInfo->PresentChargedEnergy,
@@ -669,7 +676,6 @@ int main(int argc, char *argv[])
                     if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP == NO) {
                         pDcChargingInfo->StopChargeFlag = NO;
                     }
-
                 } else if (pDcChargingInfo->Type == _Type_GB) {
                     ClearAbnormalStatus_GB(gunIndex);
 
@@ -685,21 +691,20 @@ int main(int argc, char *argv[])
                 }
 
                 if (priorityLow == 1) {
-                    pDcChargingInfo->PresentChargedEnergy = 0;
-                    pDcChargingInfo->PresentChargingPower = 0;
-                    pDcChargingInfo->GroundFaultStatus = GFD_WAIT;
-                    pDcChargingInfo->RealRatingPower = 0;
-                    pDcChargingInfo->StopChargeFlag = NO;
-                    pDcChargingInfo->NormalStopChargeFlag = NO;//DS60-120 add
-                    pDcChargingInfo->ChargingFee = 0.0;
-                    pDcChargingInfo->EvBatterySoc = 0;
-                    pDcChargingInfo->EvBatteryStartSoc = 0; //DS60-120 add
-                    pDcChargingInfo->EvBatteryMaxVoltage = 0; //DS60-120 add
-                    pDcChargingInfo->ChargingProfilePower = -1; //DS60-120 add
+                    pDcChargingInfo->PresentChargedEnergy   = 0;
+                    pDcChargingInfo->PresentChargingPower   = 0;
+                    pDcChargingInfo->GroundFaultStatus      = GFD_WAIT;
+                    pDcChargingInfo->RealRatingPower        = 0;
+                    pDcChargingInfo->StopChargeFlag         = NO;
+                    pDcChargingInfo->NormalStopChargeFlag   = NO;//DS60-120 add
+                    pDcChargingInfo->ChargingFee            = 0.0;
+                    pDcChargingInfo->EvBatterySoc           = 0;
+                    pDcChargingInfo->EvBatteryStartSoc      = 0; //DS60-120 add
+                    pDcChargingInfo->EvBatteryMaxVoltage    = 0; //DS60-120 add
+                    pDcChargingInfo->ChargingProfilePower   = -1; //DS60-120 add
                     pDcChargingInfo->ChargingProfileCurrent = -1; //DS60-120 add
 
                     if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) { //DS60-120 add
-
                         pDcChargingInfo->PresentChargingVoltage = 0;
                         pDcChargingInfo->PresentChargingCurrent = 0;
                         pDcChargingInfo->EvBatteryMaxVoltage = 0;
@@ -740,17 +745,18 @@ int main(int argc, char *argv[])
                 // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
 
-//                  log_info("PresentChargingVoltage = %f \n", pDcChargingInfo->PresentChargingVoltage);
-//                  log_info("PresentChargingCurrent = %f \n", pDcChargingInfo->PresentChargingCurrent);
-//                  log_info("AvailableChargingPower = %f \n", pDcChargingInfo->AvailableChargingPower);
-//                  log_info("AvailableChargingCurrent = %f \n", pDcChargingInfo->AvailableChargingCurrent);
-//                  log_info("MaximumChargingVoltage = %f \n", pDcChargingInfo->MaximumChargingVoltage);
+                //log_info("PresentChargingVoltage = %f \n", pDcChargingInfo->PresentChargingVoltage);
+                //log_info("PresentChargingCurrent = %f \n", pDcChargingInfo->PresentChargingCurrent);
+                //log_info("AvailableChargingPower = %f \n", pDcChargingInfo->AvailableChargingPower);
+                //log_info("AvailableChargingCurrent = %f \n", pDcChargingInfo->AvailableChargingCurrent);
+                //log_info("MaximumChargingVoltage = %f \n", pDcChargingInfo->MaximumChargingVoltage);
 
                 // 設定當前輸出
                 SetPresentChargingOutputPower();
 
-                if (priorityLow == 1) {
-                    float maxVol, maxCur;
+                if (ShmSelectGunInfo->WaitDoCommPermission[gunIndex] == YES) {
+                    ShmSelectGunInfo->WaitDoCommPermission[gunIndex] = NO;
+                    //if (priorityLow == 1) {
                     // 樁端輸出能力
                     maxVol = pDcChargingInfo->MaximumChargingVoltage;
                     maxCur = pDcChargingInfo->AvailableChargingCurrent;
@@ -763,11 +769,12 @@ int main(int argc, char *argv[])
                         LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = maxVol;
                         LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = maxCur;
 
-                        log_info("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f \n",
-                                 gunIndex, maxVol / 10, maxCur / 10, pDcChargingInfo->AvailableChargingPower / 10);
+                        log_info("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f\n",
+                                 gunIndex,
+                                 maxVol / 10,
+                                 maxCur / 10,
+                                 pDcChargingInfo->AvailableChargingPower / 10);
                     }
-                    //log_info("To EV_%d Max_Vol = %f, Cap_Cur = %f, Cap_Pow = %f \n",
-                    //            gunIndex, maxVol, maxCur, pDcChargingInfo->AvailableChargingPower);
 
                     pDcChargingInfo->RealMaxVoltage = maxVol;
 
@@ -827,23 +834,23 @@ int main(int argc, char *argv[])
                     //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
                     {
                         //if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
-                        uint8_t _result = pDcChargingInfo->GroundFaultStatus;
+                        gfgResult = pDcChargingInfo->GroundFaultStatus;
 
                         // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
                         if (pDcChargingInfo->Type == _Type_Chademo ||
                                 pDcChargingInfo->Type == _Type_GB) {
-                            if (_result == GFD_WARNING) {
-                                _result = GFD_PASS;
+                            if (gfgResult == GFD_WARNING) {
+                                gfgResult = GFD_PASS;
                             }
                         }
 
-                        if (_result == GFD_WARNING || _result == GFD_PASS) {
+                        if (gfgResult == GFD_WARNING || gfgResult == GFD_PASS) {
                             if (((GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 12000 &&
                                     pDcChargingInfo->RealRatingPower > 0) ||
                                     (GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 14000) {
                                 //log_info("**********EvComm : gunIndex= %d, RealRatingPower = %d \n",
                                 //            gunIndex,pDcChargingInfo->RealRatingPower);
-                                //_result = GFD_PASS;
+                                //gfgResult = GFD_PASS;
 
                                 //DS60-120 add
                                 if (LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] != pDcChargingInfo->RealRatingPower) {
@@ -854,15 +861,16 @@ int main(int argc, char *argv[])
 
                                 }
                             } else {
-                                _result = GFD_WAIT;
+                                gfgResult = GFD_WAIT;
                             }
                         }
 
-                        SetIsolationStatus(gunIndex, _result, pDcChargingInfo->Evboard_id);
+                        SetIsolationStatus(gunIndex, gfgResult, pDcChargingInfo->Evboard_id);
                     }
 
                     if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 &&
-                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
+                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY
+                       ) {
                         SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
                     }
                 }
@@ -907,7 +915,9 @@ int main(int argc, char *argv[])
 
                 if ((pDcChargingInfo->GroundFaultStatus == GFD_FAIL) ||
                         (pDcChargingInfo->Type == _Type_CCS_2)) {
-                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                    SetIsolationStatus(gunIndex,
+                                       pDcChargingInfo->GroundFaultStatus,
+                                       pDcChargingInfo->Evboard_id);
                 }
                 /*
                 else if (pDcChargingInfo->Type == _Type_CCS_2) {
@@ -918,7 +928,9 @@ int main(int argc, char *argv[])
                 if (priorityLow == 1) {
                     if (pDcChargingInfo->Type == _Type_CCS_2 &&
                             pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
-                        SetEvsePrechargeInfo(gunIndex, PRECHARGE_CHARELAY_PASS, pDcChargingInfo->Evboard_id);
+                        SetEvsePrechargeInfo(gunIndex,
+                                             PRECHARGE_CHARELAY_PASS,
+                                             pDcChargingInfo->Evboard_id);
                     }
                 }
                 break;
@@ -933,18 +945,23 @@ int main(int argc, char *argv[])
                 if (pDcChargingInfo->GunLocked == START ||
                         pDcChargingInfo->Type == _Type_CCS_2) {
                     uint8_t normalStop = 0x01;
-                    uint8_t stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+                    uint8_t stopReason[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
 
                     if (GetStopChargingReasonByEvse(gunIndex, stopReason)) {
                         normalStop = 0x02;
                     }
 
-                    EvseStopChargingEvent(normalStop, stopReason, pDcChargingInfo->Evboard_id);
+                    EvseStopChargingEvent(normalStop,
+                                          stopReason,
+                                          pDcChargingInfo->Evboard_id);
+
                     SendErrorCount[gunIndex] += 1; //DS60-120 add
                 }
 
                 if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                    SetIsolationStatus(gunIndex,
+                                       pDcChargingInfo->GroundFaultStatus,
+                                       pDcChargingInfo->Evboard_id);
                 }
 
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
@@ -952,13 +969,12 @@ int main(int argc, char *argv[])
                 //DS60-120 add
                 if (pDcChargingInfo->SystemStatus == S_ALARM) {
                     if (priorityLow == 1) {
-                        float maxVol, maxCur;
-
                         // 樁端輸出能力
                         maxVol = pDcChargingInfo->MaximumChargingVoltage;
                         maxCur = pDcChargingInfo->AvailableChargingCurrent;
 
                         GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+
                         SetChargingPermission(gunIndex,
                                               STOP,
                                               pDcChargingInfo->AvailableChargingPower,
@@ -974,8 +990,6 @@ int main(int argc, char *argv[])
                 SetPresentChargingOutputPower();
 
                 if (priorityLow == 1) {
-                    float maxVol, maxCur;
-
                     // 樁端輸出能力
                     maxVol = pDcChargingInfo->MaximumChargingVoltage;
                     maxCur = pDcChargingInfo->AvailableChargingCurrent;

+ 7 - 3
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c

@@ -369,9 +369,12 @@ void CheckOutputPowerOverCarReq(uint8_t index)
                 }
             } else {
                 log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                         pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
+                         pDcChargingInfo->FireChargingVoltage,
+                         (pDcChargingInfo->EvBatterytargetVoltage * 10));
+
                 log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                          pDcChargingInfo->FireChargingVoltage, (pDcChargingInfo->EvBatterytargetVoltage * 10));
+                          pDcChargingInfo->FireChargingVoltage,
+                          (pDcChargingInfo->EvBatterytargetVoltage * 10));
                 if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
                     if (pDcChargingInfo->Type == _Type_Chademo) {
                         pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
@@ -499,7 +502,8 @@ void SetK1K2RelayStatus(uint8_t index)
     GunPNState *pOutputGunPNState = NULL;
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
-    if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
+    if (ShmPsuData->Work_Step >= _TEST_MODE &&
+            ShmPsuData->Work_Step <= _TEST_MODE) {
         if (regRelay.relay_event.bits.Gun1_N == NO) {
             outputRelay.relay_event.bits.Gun1_N = YES;
         } else if (regRelay.relay_event.bits.Gun1_P == NO) {

+ 25 - 25
EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -4,7 +4,7 @@
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
 
-static SelectGunInfo *gAudiCustInfo = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
 bool needReloadQr = true;
 
 bool _isShow = false; //DS60-120 add
@@ -102,7 +102,7 @@ int InitShareMemory()
     if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
         log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
@@ -647,7 +647,7 @@ static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
     uint8_t cmd[10] = {0};
     uint8_t value[10] = {0};
     uint8_t len = 0;
-    float balance = gAudiCustInfo->PricesInfo[index].Balance;
+    float balance = ShmSelectGunInfo->PricesInfo[index].Balance;
 
     if ((balance) == (FAIL_BALANCE_PRICES)) {
         balance = 0.00;
@@ -921,62 +921,62 @@ void RefreshConnStatus()
     for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
             ehtStatus = 1;
-            //if (gAudiCustInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
-            //    gAudiCustInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
+            //if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+            //    ShmSelectGunInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
             //}
             break;
         }
     }
 
-    if (gAudiCustInfo->EthDevStatus.Backend == DEV_ST_DISABLE) {
+    if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_DISABLE) {
         ChangeDisplay2Value(__conn_status, _disappear);
-    } else if (gAudiCustInfo->EthDevStatus.Backend == DEV_ST_ENABLE_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_USE) {
         ChangeDisplay2Value(__conn_status, _connect);
-    } else if (gAudiCustInfo->EthDevStatus.Backend == DEV_ST_ENABLE_NO_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Backend == DEV_ST_ENABLE_NO_USE) {
         ChangeDisplay2Value(__conn_status, _disconnect);
     }
 
     if (ehtStatus == 1) {
-        if (gAudiCustInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
         }
     } else {
-        if (gAudiCustInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             ChangeDisplay2Value(__ethernet_status, _eth_connect);
         }
-        //if (gAudiCustInfo->EthDevStatus.Ethernet == DEV_ST_DISABLE) {
-        //} else if (gAudiCustInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_USE) {
+        //if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_DISABLE) {
+        //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_USE) {
         //    ChangeDisplay2Value(__ethernet_status, _eth_connect);
-        //} else if (gAudiCustInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_NO_USE) {
+        //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_NO_USE) {
         //    ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
         //}
     }
 
-    if (gAudiCustInfo->EthDevStatus.Wifi == DEV_ST_DISABLE) {
+    if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_DISABLE) {
         ChangeDisplay2Value(__wifi_status, _disappear);
 
         ChangeDisplay2Value(__3G4G_status, _disappear);
-        if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
             ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
             ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
             ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
         }
-    } else if (gAudiCustInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_USE) {
         ChangeDisplay2Value(__3G4G_move_status, _disappear);
         ChangeDisplay2Value(__wifi_status, _wifi_connect);
-    } else if (gAudiCustInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_NO_USE) {
+    } else if (ShmSelectGunInfo->EthDevStatus.Wifi == DEV_ST_ENABLE_NO_USE) {
         ChangeDisplay2Value(__3G4G_move_status, _disappear);
         ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
     }
 
-    if (gAudiCustInfo->EthDevStatus.Wifi != DEV_ST_DISABLE) {
-        if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
+    if (ShmSelectGunInfo->EthDevStatus.Wifi != DEV_ST_DISABLE) {
+        if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_DISABLE) {
             ChangeDisplay2Value(__3G4G_status, _disappear);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_USE) {
             ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
-        } else if (gAudiCustInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
+        } else if (ShmSelectGunInfo->EthDevStatus.FourG == DEV_ST_ENABLE_NO_USE) {
             ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
         }
     }
@@ -1872,8 +1872,8 @@ void ChangeDisplayMoneyInfo()
 
         ChangeDisplay2Value(__money_rate_map, _charging_money);
 #if defined DD360Audi
-        if (gAudiCustInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
-            DisplayMoneyRate(gAudiCustInfo->PricesInfo[curGun].UserPrices);
+        if (ShmSelectGunInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
+            DisplayMoneyRate(ShmSelectGunInfo->PricesInfo[curGun].UserPrices);
         } else {
 #endif //defined DD360Audi
             if (tmCSU->tm_hour <= 23) {

+ 168 - 136
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -58,21 +58,21 @@ uint8_t _curAutoRunCount = 0;
 uint8_t _usingAutoRun = 0;
 struct timeval _autoTime;
 
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-struct CHAdeMOData              *ShmCHAdeMOData;
-struct CcsData                  *ShmCcsData;
-struct GBTData                  *ShmGBTData;
-struct FanModuleData            *ShmFanModuleData;
-struct RelayModuleData          *ShmRelayModuleData;
-struct LedModuleData            *ShmLedModuleData;
-struct PsuData                  *ShmPsuData;
-struct OCPP16Data               *ShmOCPP16Data;
-static SelectGunInfo             *gAudiCustInfo = NULL; //Jerry add
-
-struct ChargingInfoData         *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData         *ac_chargingInfo[AC_QUANTITY];
+struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
+struct StatusCodeData *ShmStatusCodeData = NULL;
+struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+struct CHAdeMOData *ShmCHAdeMOData = NULL;
+struct CcsData *ShmCcsData = NULL;
+struct GBTData *ShmGBTData = NULL;
+struct FanModuleData *ShmFanModuleData = NULL;
+struct RelayModuleData *ShmRelayModuleData = NULL;
+struct LedModuleData *ShmLedModuleData = NULL;
+struct PsuData *ShmPsuData = NULL;
+struct OCPP16Data *ShmOCPP16Data = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
+
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
 
 char *msg = "state : get gun state (index) \n"
             "card : scanning card (x) : \n"
@@ -128,16 +128,14 @@ int InitShareMemory()
         result = FAIL;
     } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         result = FAIL;
-    } else
-    {}
+    }
 
     //initial ShmStatusCodeData
     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
         result = FAIL;
     } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         result = FAIL;
-    } else
-    {}
+    }
 
     if (CHAdeMO_QUANTITY > 0) {
         if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
@@ -146,7 +144,6 @@ int InitShareMemory()
         } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
                    == (void *) - 1) {
             result = FAIL;
-        } else {
         }
     }
 
@@ -156,7 +153,6 @@ int InitShareMemory()
             result = FAIL;
         } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
             result = FAIL;
-        } else {
         }
     }
 
@@ -209,7 +205,7 @@ int InitShareMemory()
 
     if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
         return FAIL;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+    } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
         return FAIL;
     }
 
@@ -653,11 +649,11 @@ static void get_char(char *word)
 
 static void setConfirmSelGun(uint8_t selGun)
 {
-    if (selGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
         //printf("confirmSelGun right\r\n");
     }
 }
@@ -665,8 +661,12 @@ static void setConfirmSelGun(uint8_t selGun)
 void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 {
     int _GunIndex;
+    uint8_t gunIndex = 0;
+    uint8_t stopChg = 0;
+    uint8_t curGun = 0;
     float _Voltage;
     float _Current;
+    uint8_t PreviousSystemStatus[2] = {0xff};
 
     if (strcmp(v1, "auto") == EQUAL) {
         _usingAutoRun = 0x01;
@@ -680,14 +680,15 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         _Current = atof(v3);
     }
 
-    uint8_t PreviousSystemStatus = 0xff;
     if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
         printf ("FindChargingInfoData error\n");
         return;
     }
 
-    printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-            ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
+    printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+           ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+           _Voltage,
+           _Current);
 
     if (_Voltage > 1000 || _Voltage < 50) {
         printf ("Input Voltage over range\n");
@@ -711,32 +712,35 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     //system(STTY_US TTY_PATH);
 
+    ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+
     while (true) {
+        curGun = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
+
         //fix gun 1
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+        switch (_chargingData[curGun]->SystemStatus) {
+        case S_IDLE:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 #if defined DD360Audi
-        setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                setConfirmSelGun(curGun);
 #endif //defined DD360Audi
-        switch (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-        case S_IDLE: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
                 strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->ConnectorPlugIn = 1;
+                _chargingData[curGun]->ConnectorPlugIn = 1;
                 printf ("[UnconditionalCharge - S_IDLE]\n");
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+                _chargingData[curGun]->Type = 9;
 
             }
             if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
                 ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
+                _chargingData[curGun]->SystemStatus = S_PREPARNING;
             }
-        }
-        break;
+            break;
 
-        case S_PREPARNING: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_PREPARNING:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARNIN]\n");
 
@@ -755,47 +759,45 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             //sleep(10);
 
             //清除 main timeout 機制
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+            _chargingData[curGun]->TimeoutFlag = 0;
             //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
-
-        }
-        break;
+            _chargingData[curGun]->Type = 9;
+            break;
 
-        case S_PREPARING_FOR_EV: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_PREPARING_FOR_EV:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
                 printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
 
             }
             //清除 main timeout 機制
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+            _chargingData[curGun]->TimeoutFlag = 0;
             //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+            _chargingData[curGun]->Type = 9;
 
             //充電電壓電流
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+            _chargingData[curGun]->EvBatterySoc             = 50;
+            _chargingData[curGun]->EvBatterytargetVoltage   = 500;
+            _chargingData[curGun]->EvBatterytargetCurrent   = 2;
+            _chargingData[curGun]->AvailableChargingCurrent = 1000;
 
             //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
             //確定模組己升壓完成
-            //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <=  (3000+500) &&
-            //  _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >=  (3000-500) )
+            //if(_chargingData[curGun]->PresentChargingVoltage <=  (3000+500) &&
+            //  _chargingData[curGun]->PresentChargingVoltage >=  (3000-500) )
             {
-                printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+                printf ("Precharge Done = %f \n",
+                        _chargingData[curGun]->PresentChargingVoltage);
                 //EV done
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
+                _chargingData[curGun]->SystemStatus = S_PREPARING_FOR_EVSE;
             }
-        }
-        break;
+            break;
 
-        case S_PREPARING_FOR_EVSE: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_PREPARING_FOR_EVSE:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
 
@@ -804,115 +806,130 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             //printf ("tar cur = %d \n", _Current);
 
             //清除 main timeout 機制
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+            _chargingData[curGun]->TimeoutFlag = 0;
             //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+            _chargingData[curGun]->Type = 9;
 
             //充電電壓電流
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+            _chargingData[curGun]->EvBatterySoc = 50;
+            _chargingData[curGun]->EvBatterytargetVoltage = 500;
+            _chargingData[curGun]->EvBatterytargetCurrent = 2;
+            _chargingData[curGun]->AvailableChargingCurrent = 1000;
 
-            //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
-            // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
+            //printf ("tar vol_ = %d \n", _chargingData[curGun]->EvBatterytargetVoltage);
+            // printf ("tar cur_ = %d \n", _chargingData[curGun]->EvBatterytargetCurrent);
 
             //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
             //確定模組己升壓完成
-            if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03) {
-                printf ("First Ground Fault State (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-                printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+            if (_chargingData[curGun]->GroundFaultStatus == 0x01 ||
+                    _chargingData[curGun]->GroundFaultStatus == 0x03) {
+                printf ("First Ground Fault State (%d)\n",
+                        _chargingData[curGun]->GroundFaultStatus);
+                printf ("Wait K1K2 = %f \n", _chargingData[curGun]->PresentChargingVoltage);
                 sleep(5);
                 //EV done
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
-            } else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02) {
-                printf ("First Ground Fault check Fail (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                _chargingData[curGun]->SystemStatus = S_CHARGING;
+            } else if (_chargingData[curGun]->GroundFaultStatus > 0x02) {
+                printf ("First Ground Fault check Fail (%d)\n",
+                        _chargingData[curGun]->GroundFaultStatus);
+                _chargingData[curGun]->SystemStatus = S_TERMINATING;
             }
+            break;
 
-        }
-        break;
-
-        case S_CHARGING: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_CHARGING:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 if (_usingAutoRun == 0x00) {
                     //充電電壓電流
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+                    _chargingData[curGun]->EvBatterytargetVoltage = _Voltage;
+                    _chargingData[curGun]->EvBatterytargetCurrent = _Current;
                 } else {
                     _curAutoRunCount = 0;
                     gettimeofday(&_autoTime, NULL);
                 }
 
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+                _chargingData[curGun]->EvBatterySoc = 50;
+                _chargingData[curGun]->AvailableChargingCurrent = 1000;
 
                 printf ("[UnconditionalCharge - S_CHARGING]\n");
             }
 
             if (_usingAutoRun == 0x01) {
-                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
-                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)) {
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
+                        (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
+                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
+                         (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
+                   ) {
+                    _chargingData[curGun]->EvBatterytargetVoltage = _Voltage;
+                    _chargingData[curGun]->EvBatterytargetCurrent = _Current;
                 } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
                     _curAutoRunCount++;
                     if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
-                        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                        _chargingData[curGun]->SystemStatus = S_TERMINATING;
                     } else {
                         gettimeofday(&_autoTime, NULL);
                     }
                 } else {
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
+                    _chargingData[curGun]->EvBatterytargetVoltage = 0;
+                    _chargingData[curGun]->EvBatterytargetCurrent = 0;
                 }
             }
 
 //              printf("out : vol = %f, cur = %f \n",
-//                      _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
-//                      _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
+//                      _chargingData[curGun]->EvBatterytargetVoltage,
+//                      _chargingData[curGun]->EvBatterytargetCurrent);
             //ev task do this
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
-                ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
-
-            if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02) {
-                printf ("Charging Ground Fault check Fail (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+            _chargingData[curGun]->PresentChargingPower =
+                ((float)((_chargingData[curGun]->PresentChargingVoltage) *
+                         (_chargingData[curGun]->PresentChargingCurrent)) / 1000);
+
+            if (_chargingData[curGun]->GroundFaultStatus == 0x02) {
+                printf ("Charging Ground Fault check Fail (%d)\n",
+                        _chargingData[curGun]->GroundFaultStatus);
+                _chargingData[curGun]->SystemStatus = S_TERMINATING;
             }
-        }
-        break;
+            break;
 
-        case S_TERMINATING: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-                system("/root/Module_EvComm &");
+        case S_TERMINATING:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_TERMINATING]\n");
                 //無阻塞偵測 keybaord 結束
                 system(STTY_DEF TTY_PATH);
             }
 
-            sleep(3);
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
-            return;
-        }
-        break;
+            _chargingData[curGun]->SystemStatus = S_COMPLETE;
+            break;
 
-        case S_COMPLETE: {
-            if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-                PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        case S_COMPLETE:
+            if (PreviousSystemStatus[curGun] != _chargingData[curGun]->SystemStatus) {
+                PreviousSystemStatus[curGun] = _chargingData[curGun]->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_COMPLETE]\n");
             }
 
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
-            sleep(3);
-            return;
-        }
-        break;
+            PreviousSystemStatus[curGun] = 0xFF;
+            stopChg = 0;
+            for (gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++) {
+                if (PreviousSystemStatus[gunIndex] == 0xFF) {
+                    _chargingData[curGun]->SystemStatus = S_IDLE;
+                }
+
+                if (_chargingData[gunIndex]->SystemStatus == S_IDLE) {
+                    stopChg++;
+                }
+            }
+
+            _chargingData[curGun]->PresentChargingPower = 0;
+
+            if (stopChg == ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                system("/root/Module_EvComm &");
+                sleep(3);
+                return;
+            }
+            break;
         }
 
         char word[128];
@@ -941,8 +958,11 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         }
 
         if (strcmp(newString[0], "strchg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
-                    strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0 ||
+                    strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0
+               ) {
                 printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
                 continue;
             }
@@ -955,14 +975,15 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             _Voltage = atof((char *)newString[2]);
             _Current = atof((char *)newString[3]);
 
-            uint8_t PreviousSystemStatus = 0xff;
             if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
                 printf ("FindChargingInfoData error\n");
                 continue;
             }
 
             printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-                    ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
+                    ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+                    _Voltage,
+                    _Current);
 
             if (_Voltage > 1000 || _Voltage < 50) {
                 _Voltage = 200;
@@ -970,29 +991,40 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 continue;
             }
 
+            ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
         } else if (strcmp(newString[0], "chg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+            if (strcmp(newString[1], "-1") == 0) {
                 continue;
             }
-            if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+
+            if (strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0) {
                 continue;
             }
 
-            float _vol = atof(newString[1]);
-            float _cur = atof(newString[2]);
+            if (strcmp(newString[3], "-1") == 0 ||
+                    strcmp(newString[3], "") == 0) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            float _vol = atof(newString[2]);
+            float _cur = atof(newString[3]);
 
             if (_cur <= 0 || _cur <= 0) {
                 continue;
             }
 
             printf("vol = %f, cur = %f \n", _vol, _cur);
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
-            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
+            _chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
+            _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
         } else if (strcmp(newString[0], "c") == 0) {
             if (atoi((char *)newString[1]) != -1) {
                 ShmSysConfigAndInfo->SysInfo.CurGunSelected = atoi((char *)newString[1]);
             }
             printf("stop \n\r");
+
             ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
             _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
         }

+ 10 - 0
EVSE/Projects/DD360Audi/Apps/Script/SearchIP.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+# 用 arping 來 ping 區域網路中所有的 IP 位址
+echo $0;
+
+for ip in "$1".{1..254}; do
+  arping -I "$0" -w 3 -f $ip | grep reply &;
+done
+
+# 等待所有背景的 arping 結束
+wait;

+ 2 - 0
EVSE/Projects/DD360Audi/Apps/Script/init.sh

@@ -9,3 +9,5 @@ chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
 chmod 777 Module_DoComm
+chmod 777 SearchIP.sh
+chmod 777 Module_FactoryConfig

+ 4 - 4
EVSE/Projects/DD360Audi/Apps/Script/replaceOtherDD360Project.sh

@@ -10,12 +10,12 @@ echo $SCRIPTPATH
 ProjectPath="/opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects"
 
 rm -rf $ProjectPath/DD360/Apps/;
-cp -r  $ProjectPath/DD360Audi/Apps/  $ProjectPath/DD360/Apps;
-cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360/ModelNameList.txt;
+cp -r $ProjectPath/DD360Audi/Apps/ $ProjectPath/DD360/Apps;
+cp -r $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360/ModelNameList.txt;
 
 rm -rf $ProjectPath/DD360ComBox/Apps/;
-cp -r  $ProjectPath/DD360Audi/Apps/  $ProjectPath/DD360ComBox/Apps;
-cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360ComBox/ModelNameList.txt;
+cp -r $ProjectPath/DD360Audi/Apps/ $ProjectPath/DD360ComBox/Apps;
+cp -r $ProjectPath/DD360Audi/ModelNameList.txt $ProjectPath/DD360ComBox/ModelNameList.txt;
 
 git add $ProjectPath/DD360;
 git add $ProjectPath/DD360Audi;

+ 2 - 1
EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.h

@@ -93,7 +93,8 @@ typedef struct StAudiCustInfo {
     RemoteSetup RemoteSetup;
     EthDevStatus EthDevStatus;
     uint8_t AuthorStateFromCabinet[2];
-    uint8_t Reserved[2];
+    uint8_t WaitDoCommPermission[2]; //等待主櫃回覆再進入充電檢測
+    //uint8_t Reserved; //保留
 } SelectGunInfo;
 
 //------------------------------------------------------------------------------

+ 14 - 0
EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c

@@ -737,6 +737,8 @@ int InitSysConfigAndInfoShmMem(void)
 
 void ClearAllShmMemParameter(void)
 {
+    uint8_t i = 0;
+
     memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
     memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
     memset(ShmPsuData, 0, sizeof(struct PsuData));
@@ -764,6 +766,10 @@ void ClearAllShmMemParameter(void)
 
 #if defined DD360 || defined DD360Audi || defined DD360ComBox
     memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
+
+    for (i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
+        ShmSelectGunInfo->PricesInfo[i].Balance = FAIL_BALANCE_PRICES;
+    }
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 }
 
@@ -978,6 +984,14 @@ bool MappingGunChargingInfo(char *whichTask)
             log_error("%s add gun info failed\r\n", whichTask);
             return false;
         }
+
+        //確認有幾把水冷槍
+        if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 ||
+                strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0
+           ) {
+            ShmDcCommonData->ChillerValve.MultiChillerGun++;
+            ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80;
+        }
         slots++;
     }
 

+ 18 - 15
EVSE/Projects/DD360Audi/Apps/timeout.h

@@ -32,26 +32,29 @@
 #include    <ctype.h>
 #include    <ifaddrs.h>
 
-#define CONN_PLUG_TIME_OUT          40
+//------------------------------------------------------------------------------
+#define CONN_PLUG_TIME_OUT                      (40)
 
+//------------------------------------------------------------------------------
 enum Timeout_flag {
-    Timeout_None =                      0,
-    Timeout_SelftestChk =               1,
-    Timeout_Authorizing =               2,
-    Timeout_VerifyFail =                3,
-    Timeout_VerifyComp =                4,
-    Timeout_WaitPlug =                  5,
+    Timeout_None                   = 0,
+    Timeout_SelftestChk            = 1,
+    Timeout_Authorizing            = 2,
+    Timeout_VerifyFail             = 3,
+    Timeout_VerifyComp             = 4,
+    Timeout_WaitPlug               = 5,
 
-    Timeout_Preparing =                 6,
-    Timeout_EvChargingDet =             7,
-    Timeout_EvseChargingDet =           8,
-    Timeout_EvseCompleteDet =           9,
-    Timeout_ForCcsPrechargeDet =        10,
-    Timeout_ReturnToChargingGunDet =    11,
-    Timeout_AuthorizingForStop =        12,
-    Timeout_SelectGun =                 13,
+    Timeout_Preparing              = 6,
+    Timeout_EvChargingDet          = 7,
+    Timeout_EvseChargingDet        = 8,
+    Timeout_EvseCompleteDet        = 9,
+    Timeout_ForCcsPrechargeDet     = 10,
+    Timeout_ReturnToChargingGunDet = 11,
+    Timeout_AuthorizingForStop     = 12,
+    Timeout_SelectGun              = 13,
 };
 
+//------------------------------------------------------------------------------
 // for timeout fork
 struct timeval _cmdSubPriority_time;
 unsigned short _connectionTimeout;

BIN
EVSE/Projects/DD360Audi/Images/FactoryDefaultConfig.bin


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


+ 3 - 0
EVSE/Projects/DD360Audi/ModelNameList.txt

@@ -13,3 +13,6 @@ Model Name: DDYE362F0KE2XP
 // *********** BYD *********** //
 Model Name: DOYE242000D2BD
 Model Name: DDYE242V0UE2BD
+
+
+DDWU362K0TE2PH

BIN
EVSE/Projects/DD360Audi/output/FactoryConfig


BIN
EVSE/Projects/DD360Audi/output/Module_DoComm


BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN
EVSE/Projects/DD360Audi/output/Module_EventLogging


BIN
EVSE/Projects/DD360Audi/output/Module_FactoryConfig


BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN
EVSE/Projects/DD360Audi/output/Module_LcmControl


BIN
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Audi/output/ReadCmdline


+ 10 - 0
EVSE/Projects/DD360Audi/output/SearchIP.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+# 用 arping 來 ping 區域網路中所有的 IP 位址
+echo $0;
+
+for ip in "$1".{1..254}; do
+  arping -I "$0" -w 3 -f $ip | grep reply &;
+done
+
+# 等待所有背景的 arping 結束
+wait;

+ 2 - 0
EVSE/Projects/DD360Audi/output/init.sh

@@ -9,3 +9,5 @@ chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
 chmod 777 Module_DoComm
+chmod 777 SearchIP.sh
+chmod 777 Module_FactoryConfig

BIN
EVSE/Projects/DD360Audi/output/main


+ 4 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c

@@ -106,6 +106,7 @@ static int isReachableInternet(void)
             }
         }
     }
+
     pclose(fp);
 
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
@@ -119,6 +120,7 @@ static int isReachableInternet(void)
 #endif //defined DD360 || defined DD360Audi
 
     memset(buf, 0x00, sizeof(buf));
+
     for (idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
         sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
         fp = popen(cmd, "r");
@@ -175,6 +177,7 @@ void InitEthernet(void)
     system(tmpbuf);
     //system("ifconfig lo up");
     //  /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
+
     //Init Eth1 for administrator tool
     memset(tmpbuf, 0, 256);
     sprintf(tmpbuf, "/sbin/ifconfig eth1 %s netmask %s up",
@@ -202,6 +205,7 @@ void InitEthernet(void)
     pid_t pid = fork();
     if (pid == 0) {
         log_info("InitEthernet = %d\r\n", pid);
+
         for (;;) {
 #if defined DD360 || defined DD360Audi || defined DD360ComBox
             isReachableInternet();

+ 108 - 8
EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c

@@ -54,7 +54,6 @@ void PrimaryLedIndicatorCtrlFork(void)
         struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
         struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
         struct ChargingInfoData *pDcChargingInfo = NULL;
-        DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
         LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
 
@@ -62,7 +61,7 @@ void PrimaryLedIndicatorCtrlFork(void)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-                if (pSysWarning->Level == 2) {
+                if (pSysWarning->Level == WARN_LV_ER) {
                     if (checkCabinetEthConnectState(pLedConfig) == YES) {
                         usleep(500000);
                         continue;
@@ -147,7 +146,7 @@ void PrimaryLedIndicatorCtrlFork(void)
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    //if (pSysWarning->Level == 2) {
+                    //if (pSysWarning->Level == WARN_LV_ER) {
                     //    pLedConfig->YellowLED = NO;
                     //    pLedConfig->GreenLED = NO;
                     //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
@@ -166,7 +165,7 @@ void PrimaryLedIndicatorCtrlFork(void)
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
                     pLedConfig->RedLED = YES;
-                    //if (pSysWarning->Level == 2) {
+                    //if (pSysWarning->Level == WARN_LV_ER) {
                     //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
                     //        break;
                     //    }
@@ -187,23 +186,121 @@ void PrimaryLedIndicatorCtrlFork(void)
 }
 
 //------------------------------------------------------------------------------
+static void checkChargingInfoByDC(uint8_t systemStatus)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    switch (systemStatus) {
+    case S_IDLE:
+        if (isDetectPlugin()) {
+            _DetectPlugInTimeout();
+            StopSystemTimeoutDet();
+            destroySelGun(pSysInfo->CurGunSelected);
+        } else {
+#if !defined DD360Audi
+            break;
+#endif //!defined DD360Audi
+
+            if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
+                //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
+                destroySelGun(pSysInfo->CurGunSelected);
+            } else {
+                confirmSelGun(pSysInfo->CurGunSelected);
+                log_info("confirm select gun ............................... %d \n",
+                         pSysInfo->CurGunSelected);
+            }
+        }
+        break;
+
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+    case S_PREPARING_FOR_EVSE:
+    case S_CCS_PRECHARGE_ST0:
+    case S_CCS_PRECHARGE_ST1:
+        // 取消充電
+        if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+            AcChargingTerminalProcess();
+        } else {
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+        }
+        break;
+
+    case S_CHARGING:
+        if (pSysConfig->StopChargingByButton == YES ||
+                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+            // 停止充電
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+        }
+        break;
+
+    case S_COMPLETE:
+        break;
+    }
+}
+
+static void checkChargingInfoByAC(void)
+{
+    struct ChargingInfoData *pAcChargingInfo = NULL;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    if (pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
+        return;
+    }
+
+    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    switch (pAcChargingInfo->SystemStatus) {
+    case S_IDLE:
+        if (isDetectPlugin()) {
+            _DetectPlugInTimeout();
+            StopSystemTimeoutDet();
+        }
+        break;
+
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+    case S_PREPARING_FOR_EVSE:
+    case S_CCS_PRECHARGE_ST0:
+    case S_CCS_PRECHARGE_ST1:
+        // 取消充電
+        AcChargingTerminalProcess();
+        break;
+
+    case S_CHARGING:
+        if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+            // 停止充電
+            AcChargingTerminalProcess();
+        }
+        break;
+
+    case S_COMPLETE:
+        break;
+    }
+}
+
 void ChkPrimaryStatus(void)
 {
     static bool leftBtnPush = false;
     static bool rightBtnPush = false;
-    uint8_t Rtn;
+    uint8_t i = 0;
+    uint8_t Rtn = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
     struct ChargingInfoData *pDcChargingInfo = NULL;
-    struct ChargingInfoData *pAcChargingInfo = NULL;
     DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
     if (pSysWarning->WarningCount > 0) {
         Rtn = 0;
-        for (uint8_t i = 0; i < pSysWarning->WarningCount; i++) {
+        for (i = 0; i < pSysWarning->WarningCount; i++) {
             if (memcmp(&pSysWarning->WarningCode[i][0], "042251", 6) == 0) {
                 EmcOccureByString("042251");
                 ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = YES;
@@ -315,6 +412,9 @@ void ChkPrimaryStatus(void)
             leftBtnPush = true;
             log_info("left btn down...............................%x\n",
                      pDcChargingInfo->SystemStatus);
+            checkChargingInfoByAC();
+            checkChargingInfoByDC(pDcChargingInfo->SystemStatus);
+#if 0
             if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
                 pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
@@ -348,7 +448,6 @@ void ChkPrimaryStatus(void)
                     break;
                 }
             }
-
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
                 if (isDetectPlugin()) {
@@ -399,6 +498,7 @@ void ChkPrimaryStatus(void)
                 //pDcChargingInfo->SystemStatus = S_IDLE;
                 break;
             }
+#endif //0
         }
     } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
         if (leftBtnPush) {

+ 272 - 234
EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c

@@ -32,17 +32,75 @@ static bool canStartCharging(void)
     // 因為無法得知實際的長度,所以只能用搜尋的方式
     if (strcmp(buf2, "Accepted") == EQUAL) {
         return true;
-    } else {
-
     }
 
     return false;
 }
 
+static void isAutorCompleteHandle(uint8_t *authorizeIndex)
+{
+    uint8_t i = 0;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+
+    // 透過後臺停止充電的判斷
+    if (isAuthorizedComplete()
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            || (pSysInfo->OcppConnStatus == NO &&
+                pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+#endif //!defined DD360 && !defined DD360Audi
+       ) {
+
+        // 判斷後台回覆狀態
+        if (canStartCharging() == false) {
+            strcpy((char *)pSysConfig->UserId, "");
+            ClearAuthorizedFlag();
+
+            return;
+        }
+
+        if (*(authorizeIndex) != NO_DEFINE) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(*(authorizeIndex));
+
+            if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
+                    strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
+                // 先找 AC
+                if (*(authorizeIndex) == DEFAULT_AC_INDEX) {
+                    AcChargingTerminalProcess();
+                } else {
+                    ChargingTerminalProcess(*(authorizeIndex));
+                }
+            }
+
+            strcpy((char *)pSysConfig->UserId, "");
+            *(authorizeIndex) = NO_DEFINE;
+        }
+
+        ClearAuthorizedFlag();
+    } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
+        // 白名單驗證
+        for (i = 0; i < 10; i++) {
+            if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
+                continue;
+            }
+
+            if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
+                ChargingTerminalProcess(*(authorizeIndex));
+                strcpy((char *)pSysConfig->UserId, "");
+                ClearAuthorizedFlag();
+
+                break;
+            }
+        }
+    }
+}
+
 static void UserScanFunction(void)
 {
     bool idleReq = false;
+    uint8_t i = 0;
     uint8_t stopReq = NO_DEFINE;
+    char value[32] = {0};
     static uint8_t _authorizeIndex = NO_DEFINE;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -51,164 +109,138 @@ static void UserScanFunction(void)
     GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
     // 當前非驗證的狀態
-    if (!IsAuthorizingMode()) {
-#if defined DD360Audi
-        //當前沒有選槍
-        if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) { //Jerry add
-            strcpy((char *)pSysConfig->UserId, "");
-            return;
+    if (IsAuthorizingMode()) {
+        isAutorCompleteHandle(&_authorizeIndex);
+    }
+
+    //當前沒有選槍
+    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) {
+        strcpy((char *)pSysConfig->UserId, "");
+        return;
+    }
+
+    // 先判斷現在是否可以提供刷卡
+    // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
+    // 2. 停止充電
+    if (pSysInfo->PageIndex == _LCM_FIX) {
+        strcpy((char *)pSysConfig->UserId, "");
+        return;
+    }
+
+    for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+        if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+            stopReq = i;
         }
-#endif //defined DD360Audi
 
-        // 先判斷現在是否可以提供刷卡
-        // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
-        // 2. 停止充電
-        if (pSysInfo->PageIndex == _LCM_FIX) {
-            strcpy((char *)pSysConfig->UserId, "");
-            return;
+        if ((pDcChargingInfo->SystemStatus == S_IDLE &&
+                pDcChargingInfo->IsAvailable == YES) ||
+                (pGunIndexInfo->AcGunIndex > 0 &&
+                 pAcChargingInfo->SystemStatus == S_IDLE &&
+                 pAcChargingInfo->IsAvailable)
+           ) {
+            idleReq = true;
         }
+    }
 
-        for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+    if (pGunIndexInfo->AcGunIndex > 0 &&
+            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
+            pAcChargingInfo->SystemStatus == S_CHARGING) {
+        stopReq = DEFAULT_AC_INDEX;
+    }
 
-            if (pDcChargingInfo->SystemStatus == S_CHARGING) {
-                stopReq = i;
-            }
-            if ((pDcChargingInfo->SystemStatus == S_IDLE &&
-                    pDcChargingInfo->IsAvailable) == YES ||
-                    (pGunIndexInfo->AcGunIndex > 0 && pAcChargingInfo->SystemStatus ==
-                     S_IDLE && pAcChargingInfo->IsAvailable)
-               ) {
-                idleReq = true;
-            }
+    if (strlen((char *)pSysConfig->UserId) <= 0) {
+        return;
+    }
+
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+
+    if (pGunIndexInfo->AcGunIndex > 0 &&
+            stopReq == DEFAULT_AC_INDEX &&
+            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
+        log_info("ac stop charging \n");
+        log_info("index = %d, card number = %s, UserId = %s \n",
+                 pSysInfo->CurGunSelectedByAc,
+                 pAcChargingInfo->StartUserId,
+                 pSysConfig->UserId);
+
+        memset(value, 0, sizeof(value));
+        memcpy(value,
+               (uint8_t *)pAcChargingInfo->StartUserId,
+               ARRAY_SIZE(pAcChargingInfo->StartUserId));
+        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
+            AcChargingTerminalProcess();
         }
+        strcpy((char *)pSysConfig->UserId, "");
+    } else if (stopReq < pSysConfig->TotalConnectorCount &&
+               pDcChargingInfo->SystemStatus == S_CHARGING &&
+               (pGunIndexInfo->AcGunIndex <= 0 ||
+                (pGunIndexInfo->AcGunIndex > 0 &&
+                 pSysInfo->CurGunSelectedByAc == NO_DEFINE))
+              ) {
+        log_info("stop charging \n");
+        log_info("index = %d, card number = %s, UserId = %s \n",
+                 pSysInfo->CurGunSelected,
+                 pDcChargingInfo->StartUserId,
+                 pSysConfig->UserId);
+
+        memset(value, 0, sizeof(value));
+        memcpy(value,
+               (uint8_t *)pDcChargingInfo->StartUserId,
+               ARRAY_SIZE(pDcChargingInfo->StartUserId));
+
+        // 同一張卡直接停掉
+        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+            strcpy((char *)pSysConfig->UserId, "");
 
-        if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-                pAcChargingInfo->SystemStatus == S_CHARGING) {
-            stopReq = DEFAULT_AC_INDEX;
+            return;
         }
 
-        if (strlen((char *)pSysConfig->UserId) > 0) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+        // 進驗證
+        if (pGunIndexInfo->AcGunIndex > 0 &&
+                pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
+            _authorizeIndex = pSysInfo->CurGunSelectedByAc;
+        } else {
+            _authorizeIndex = pSysInfo->CurGunSelected;
+        }
 
-            if (pGunIndexInfo->AcGunIndex > 0 && stopReq == DEFAULT_AC_INDEX &&
-                    pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                char value[32];
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+        strcpy((char *)pSysConfig->UserId, "");
 
-                log_info("ac stop charging \n");
-                log_info("index = %d, card number = %s, UserId = %s \n", pSysInfo->CurGunSelectedByAc,
-                         pAcChargingInfo->StartUserId, pSysConfig->UserId);
-                memcpy(value, (uint8_t *)pAcChargingInfo->StartUserId,
-                       ARRAY_SIZE(pAcChargingInfo->StartUserId));
-                if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-                    AcChargingTerminalProcess();
-                }
-                strcpy((char *)pSysConfig->UserId, "");
-            } else if (stopReq < pSysConfig->TotalConnectorCount &&
-                       pDcChargingInfo->SystemStatus == S_CHARGING &&
-                       (pGunIndexInfo->AcGunIndex <= 0 || (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == NO_DEFINE))) {
-                char value[32];
-
-                log_info("stop charging \n");
-                log_info("index = %d, card number = %s, UserId = %s \n",
-                         pSysInfo->CurGunSelected,
-                         pDcChargingInfo->StartUserId,
-                         pSysConfig->UserId);
-                memcpy(value, (uint8_t *)pDcChargingInfo->StartUserId,
-                       ARRAY_SIZE(pDcChargingInfo->StartUserId));
-
-                // 同一張卡直接停掉
-                if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-                    ChargingTerminalProcess(pSysInfo->CurGunSelected);
-                    strcpy((char *)pSysConfig->UserId, "");
-                } else {
-                    // 進驗證
-                    if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                        _authorizeIndex = pSysInfo->CurGunSelectedByAc;
-                    } else {
-                        _authorizeIndex = pSysInfo->CurGunSelected;
-                    }
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    StartSystemTimeoutDet(Timeout_AuthorizingForStop);
-                    AuthorizingStart();
-#else
-                    strcpy((char *)pSysConfig->UserId, "");
-#endif //!defined DD360 && !defined DD360Audi
-                }
-            } else if (idleReq) {
-                if (pSysConfig->TotalConnectorCount > 1 &&
-                        stopReq != 255 &&
-                        pSysInfo->IsAlternatvieConf == YES) {
-                    idleReq = false;
-                    strcpy((char *)pSysConfig->UserId, "");
-                } else if ((pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-                           pDcChargingInfo->SystemStatus == S_IDLE) {
-                    log_info("// LCM => Authorizing \n");
-#if defined DD360Audi
-                    setSelGunWaitToAuthor(pSysInfo->CurGunSelected); //Jerry add
-#endif //defined DD360Audi
-                    // LCM => Authorizing
-                    pSysInfo->SystemPage = _LCM_AUTHORIZING;
-                    // 進入確認卡號狀態
-                    AuthorizingStart();
-                } else {
-                    strcpy((char *)pSysConfig->UserId, "");
-                }
-            } else {
-                strcpy((char *)pSysConfig->UserId, "");
-            }
+        return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+        StartSystemTimeoutDet(Timeout_AuthorizingForStop);
+
+        AuthorizingStart();
+    } else if (idleReq) {
+        if (pSysConfig->TotalConnectorCount > 1 &&
+                stopReq != 255 &&
+                pSysInfo->IsAlternatvieConf == YES) {
+            idleReq = false;
+            strcpy((char *)pSysConfig->UserId, "");
+        } else if ((pGunIndexInfo->AcGunIndex > 0 &&
+                    pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
+                   pDcChargingInfo->SystemStatus == S_IDLE) {
+            log_info("// LCM => Authorizing\r\n");
+
+            setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
+
+            // LCM => Authorizing
+            pSysInfo->SystemPage = _LCM_AUTHORIZING;
+
+            // 進入確認卡號狀態
+            AuthorizingStart();
+        } else {
+            strcpy((char *)pSysConfig->UserId, "");
         }
     } else {
-        // 透過後臺停止充電的判斷
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || (pSysInfo->OcppConnStatus == NO &&
-                    pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-           ) {
-            // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || (pSysInfo->OcppConnStatus == NO &&
-                        pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
-                if (_authorizeIndex != NO_DEFINE) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_authorizeIndex);
-
-                    // 先找 AC
-                    if (_authorizeIndex == DEFAULT_AC_INDEX) {
-                        if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
-                            AcChargingTerminalProcess();
-                        }
-                    } else {
-                        if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) {
-                            ChargingTerminalProcess(_authorizeIndex);
-                        }
-                    }
-                    strcpy((char *)pSysConfig->UserId, "");
-                    _authorizeIndex = NO_DEFINE;
-                }
-            } else {
-                strcpy((char *)pSysConfig->UserId, "");
-            }
-            ClearAuthorizedFlag();
-        } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                        ChargingTerminalProcess(_authorizeIndex);
-                        strcpy((char *)pSysConfig->UserId, "");
-                        ClearAuthorizedFlag();
-                        break;
-                    }
-                }
-            }
-        }
+        strcpy((char *)pSysConfig->UserId, "");
     }
+
+    return;
 }
 
 bool GetIsCardScan(void)
@@ -223,12 +255,15 @@ void SetIsCardScan(bool value)
 
 void ScannerCardProcess(void)
 {
+    int i = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
 
-    if (!isDetectPlugin() && !isCardScan && pSysWarning->Level != 2 &&
+    if (!isDetectPlugin() &&
+            !isCardScan &&
+            pSysWarning->Level != WARN_LV_ER &&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
         isCardScan = true;
         // 處理刷卡及驗證卡號的動作
@@ -238,21 +273,18 @@ void ScannerCardProcess(void)
     if (pSysInfo->PageIndex == _LCM_AUTHORIZING) {
         StartSystemTimeoutDet(Timeout_Authorizing);
 
+        //printf("isAuthorizedComplete = %d, %f\r\n", isAuthorizedComplete(), ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
         // 確認驗證卡號完成沒
         if (isAuthorizedComplete()
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#else
+#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 && ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance != FAIL_BALANCE_PRICES
-#endif //!defined DD360 && !defined DD360Audi
            ) {
             StopSystemTimeoutDet();
+
             // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
+            if (canStartCharging()) {
                 // LCM => Authorize complete
                 pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
             } else {
@@ -260,16 +292,19 @@ void ScannerCardProcess(void)
                 pSysInfo->SystemPage = _LCM_AUTHORIZ_FAIL;
                 strcpy((char *)pSysConfig->UserId, "");
             }
+
             ClearAuthorizedFlag();
         } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
             // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                        pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
-                        ClearAuthorizedFlag();
-                        break;
-                    }
+            for (i = 0; i < 10; i++) {
+                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
+                    continue;
+                }
+
+                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
+                    pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
+                    ClearAuthorizedFlag();
+                    break;
                 }
             }
         }
@@ -317,98 +352,101 @@ void CreateRfidFork(void)
     pid_t rfidRecPid;
 
     rfidRecPid = fork();
-    log_info("CreateRfidFork = %d\r\n", rfidRecPid);
     if (rfidRecPid == 0) {
         int fd = -1;
+        int isContinue = 1;
         RFID rfid = {0};
         fd = InitialRfidPort();
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
 
-        while (true) {
+        log_info("RFID fork Child's PID is %d\r\n", getpid());
+
+        while (isContinue) {
+            usleep(500000);
+
             // 刷卡判斷
             if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
                     !pSysConfig->isRFID) {
-                usleep(500000);
                 continue;
             }
 
             if (getRequestCardSN(fd, 0, &rfid) == false) {
-                usleep(500000);
                 continue;
             }
 
             //log_info("Get Card..-%s- \n", pSysConfig->UserId);
-            if (strlen((char *)pSysConfig->UserId) == 0) {
-                if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
-                    switch (rfid.snType) {
-                    case RFID_SN_TYPE_6BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5]);
-                        break;
-                    case RFID_SN_TYPE_7BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5],
-                                rfid.currentCard[6]);
-                        break;
-                    case RFID_SN_TYPE_10BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3],
-                                rfid.currentCard[4], rfid.currentCard[5],
-                                rfid.currentCard[6], rfid.currentCard[7],
-                                rfid.currentCard[8], rfid.currentCard[9]);
-                        break;
-                    case RFID_SN_TYPE_4BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X",
-                                rfid.currentCard[0], rfid.currentCard[1],
-                                rfid.currentCard[2], rfid.currentCard[3]);
-                        break;
-                    }
-                } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
-                    switch (rfid.snType) {
-                    case RFID_SN_TYPE_6BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[5], rfid.currentCard[4],
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_7BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[6], rfid.currentCard[5],
-                                rfid.currentCard[4], rfid.currentCard[3],
-                                rfid.currentCard[2], rfid.currentCard[1],
-                                rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_10BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                                rfid.currentCard[9], rfid.currentCard[8],
-                                rfid.currentCard[7], rfid.currentCard[6],
-                                rfid.currentCard[5], rfid.currentCard[4],
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    case RFID_SN_TYPE_4BYTE:
-                        sprintf((char *) pSysConfig->UserId,
-                                "%02X%02X%02X%02X",
-                                rfid.currentCard[3], rfid.currentCard[2],
-                                rfid.currentCard[1], rfid.currentCard[0]);
-                        break;
-                    }
+            if (strlen((char *)pSysConfig->UserId) != 0) {
+                continue;
+            }
+
+            if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
+                switch (rfid.snType) {
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5],
+                            rfid.currentCard[6]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3],
+                            rfid.currentCard[4], rfid.currentCard[5],
+                            rfid.currentCard[6], rfid.currentCard[7],
+                            rfid.currentCard[8], rfid.currentCard[9]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X",
+                            rfid.currentCard[0], rfid.currentCard[1],
+                            rfid.currentCard[2], rfid.currentCard[3]);
+                    break;
+                }
+            } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
+                switch (rfid.snType) {
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[5], rfid.currentCard[4],
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[6], rfid.currentCard[5],
+                            rfid.currentCard[4], rfid.currentCard[3],
+                            rfid.currentCard[2], rfid.currentCard[1],
+                            rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                            rfid.currentCard[9], rfid.currentCard[8],
+                            rfid.currentCard[7], rfid.currentCard[6],
+                            rfid.currentCard[5], rfid.currentCard[4],
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char *) pSysConfig->UserId,
+                            "%02X%02X%02X%02X",
+                            rfid.currentCard[3], rfid.currentCard[2],
+                            rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
                 }
-                log_info("card number = %s\n", pSysConfig->UserId);
             }
-            usleep(500000);
+            log_info("card number = %s\n", pSysConfig->UserId);
         }
     }
 }

+ 143 - 135
EVSE/Projects/DD360ComBox/Apps/CSU/SelfTest.c

@@ -18,6 +18,7 @@ extern void ChkPrimaryStatus(void);
 void SelfTestRun(void)
 {
     bool evInitFlag = false;
+    uint8_t index = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
@@ -36,177 +37,184 @@ void SelfTestRun(void)
     StartSystemTimeoutDet(Timeout_SelftestChk);
     pSysInfo->SelfTestSeq = _STEST_VERSION;
 
-    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE //||
-            //GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL <= 20 //DS60-120 add
-          ) {
-        if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
+        if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) { //自檢完成
             return;
         }
 
-        ChkPrimaryStatus();
-        if (pSysWarning->Level == 2 //||
-                //pAlarmCode->AlarmEvents.bits.PsuDipSwitchStestFail == YES //DS60-120 add
-           ) {
+        ChkPrimaryStatus(); //確認硬體有無錯誤,如急停按鈕或門有打開
+
+        if (pSysWarning->Level == WARN_LV_ER) {
             pSysInfo->SelfTestSeq = _STEST_FAIL;
             return;
         }
 
-        if (pSysConfig->TotalConnectorCount > 0) {
-            if (ShmPsuData->Work_Step == _NO_WORKING ||
-                    pSysInfo->SelfTestSeq == _STEST_FAIL) {
-                pSysInfo->SelfTestSeq = _STEST_FAIL;
-                return;
+        if (pSysConfig->TotalConnectorCount <= 0) {
+            pSysInfo->SelfTestSeq = _STEST_FAIL;
+            return;
+        }
+
+        if (ShmPsuData->Work_Step == _NO_WORKING ||
+                pSysInfo->SelfTestSeq == _STEST_FAIL) {
+            pSysInfo->SelfTestSeq = _STEST_FAIL;
+            return;
+        }
+
+        switch (pSysInfo->SelfTestSeq) {
+        case _STEST_VERSION:
+            if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
+                    pSysInfo->RelayModuleFwRev[0] != '\0') &&
+                    (ShmRelayModuleData->SelfTest_Comp != YES)
+               ) {
+                log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
+                ShmRelayModuleData->SelfTest_Comp = YES;
             }
 
-            switch (pSysInfo->SelfTestSeq) {
-            case _STEST_VERSION: {
-                if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
-                        pSysInfo->RelayModuleFwRev[0] != '\0')
-                        && (ShmRelayModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
-                    ShmRelayModuleData->SelfTest_Comp = YES;
-                }
 #if !defined NO_FAN_BOARD && !defined DD360ComBox
-                if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
-                        pSysInfo->FanModuleFwRev[0] != '\0')
-                        && (ShmFanModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
-                    ShmFanModuleData->SelfTest_Comp = YES;
-                }
-#else
+            if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
+                    pSysInfo->FanModuleFwRev[0] != '\0') &&
+                    (ShmFanModuleData->SelfTest_Comp != YES)
+               ) {
+                log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
                 ShmFanModuleData->SelfTest_Comp = YES;
+            }
+#else
+            ShmFanModuleData->SelfTest_Comp = YES;
 #endif //NO_FAN_BOARD
 
-                if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
-                        ShmPrimaryMcuData->version[0] != '\0')
-                        && (ShmPrimaryMcuData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
-                    ShmPrimaryMcuData->SelfTest_Comp = YES;
-                }
+            if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
+                    ShmPrimaryMcuData->version[0] != '\0') &&
+                    (ShmPrimaryMcuData->SelfTest_Comp != YES)
+               ) {
+                log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
+                ShmPrimaryMcuData->SelfTest_Comp = YES;
+            }
 
-                // EV 小板
-                if (!evInitFlag) {
-                    evInitFlag = YES;
-                    for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
-
-                        //log_info("index = %d, charging index = %d, type = %d\r\n",
-                        //         index,
-                        //         chargingInfo[index]->type_index,
-                        //         chargingInfo[index]->Type);
-                        if (pDcChargingInfo->Type == _Type_Chademo) {
-                            if ((strlen((char *)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version) != 0 ||
-                                    ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
-                                    //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
-                               ) {
-                                log_info("CHAdeMO[%d] FW Rev = %s", pDcChargingInfo->type_index, ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
-                                ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
-                            } else {
-                                //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
-                                evInitFlag = NO;
-                            }
-                        } else if (pDcChargingInfo->Type == _Type_GB) {
-                            if ((strlen((char *)ShmGBTData->evse[pDcChargingInfo->type_index].version) != 0 ||
-                                    ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
-                                    //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+            // EV 小板
+            if (!evInitFlag) {
+                evInitFlag = YES;
+                for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+                    //log_info("index = %d, charging index = %d, type = %d\r\n",
+                    //         index,
+                    //         chargingInfo[index]->type_index,
+                    //         chargingInfo[index]->Type);
+                    if (pDcChargingInfo->Type == _Type_Chademo) {
+                        if ((strlen((char *)ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version) != 0 ||
+                                ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
+                                //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+                           ) {
+                            log_info("CHAdeMO[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                        } else {
+                            //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            evInitFlag = NO;
+                        }
+                    } else if (pDcChargingInfo->Type == _Type_GB) {
+                        if ((strlen((char *)ShmGBTData->evse[pDcChargingInfo->type_index].version) != 0 ||
+                                ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
+                                //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
+                           ) {
+                            log_info("GBT[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmGBTData->evse[pDcChargingInfo->type_index].version);
+                            ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                        } else {
+                            //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            evInitFlag = NO;
+                        }
+                    } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                            if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version) != 0 ||
+                                    ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
+                                    /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
                                ) {
-                                log_info("GBT[%d] FW Rev = %s", pDcChargingInfo->type_index, ShmGBTData->evse[pDcChargingInfo->type_index].version);
-                                ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
+                                log_info("CCS[%d] FW Rev = %s",
+                                         pDcChargingInfo->type_index,
+                                         ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
+                                ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
                             } else {
-                                //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                                //log_info("CCS[%d] ccs fw lose...... %s \n",
+                                //         chargingInfo[index]->type_index,
+                                //         ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
                                 evInitFlag = NO;
                             }
-                        } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                            if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                                if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version) != 0 ||
-                                        ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
-                                        /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
-                                   ) {
-                                    log_info("CCS[%d] FW Rev = %s",
-                                             pDcChargingInfo->type_index,
-                                             ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
-                                    ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
-                                } else {
-                                    //log_info("CCS[%d] ccs fw lose...... %s \n",
-                                    //         chargingInfo[index]->type_index,
-                                    //         ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
-                                    evInitFlag = NO;
-                                }
-                            }
                         }
                     }
+                }
 
-                    for (uint8_t index = 0; index < pSysConfig->AcConnectorCount; index++) {
-                        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
-
-                        if (pAcChargingInfo->Type == _Type_AC) {
-                            if ((strlen((char *)pAcChargingInfo->version) != 0 || pAcChargingInfo->version[0] != '\0')
-                                    && (pAcChargingInfo->SelfTest_Comp != YES)
-                               ) {
-                                log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
-                                pAcChargingInfo->SelfTest_Comp = YES;
-                            } else {
-                                evInitFlag = NO;
-                            }
+                for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
+                    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
+
+                    if (pAcChargingInfo->Type == _Type_AC) {
+                        if ((strlen((char *)pAcChargingInfo->version) != 0 ||
+                                pAcChargingInfo->version[0] != '\0')
+                                && (pAcChargingInfo->SelfTest_Comp != YES)
+                           ) {
+                            log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
+                            pAcChargingInfo->SelfTest_Comp = YES;
+                        } else {
+                            evInitFlag = NO;
                         }
                     }
                 }
+            }
 
-                if ( ShmFanModuleData->SelfTest_Comp &&
-                        ShmRelayModuleData->SelfTest_Comp &&
-                        ShmPrimaryMcuData->SelfTest_Comp &&
-                        evInitFlag
-                   ) {
-                    pSysInfo->SelfTestSeq = _STEST_AC_CONTACTOR;
-                }
+            if (ShmFanModuleData->SelfTest_Comp &&
+                    ShmRelayModuleData->SelfTest_Comp &&
+                    ShmPrimaryMcuData->SelfTest_Comp &&
+                    evInitFlag
+               ) {
+                pSysInfo->SelfTestSeq = _STEST_AC_CONTACTOR;
             }
             break;
-            case _STEST_AC_CONTACTOR: {
-                //ShmPsuData->Work_Step = _TEST_COMPLETE;
-                // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (pSysInfo->AcContactorStatus == YES) {
-                    pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
-                    log_info("AC contactor self test OK");
-                }
-#else
+
+        case _STEST_AC_CONTACTOR:
+            //ShmPsuData->Work_Step = _TEST_COMPLETE;
+            // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
+            log_info("Waiting for DO communication");
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (pSysInfo->AcContactorStatus == YES) {
                 pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
-                log_info("Waiting for DO communication");
-#endif //!defined DD360 && !defined DD360Audi
+                log_info("AC contactor self test OK");
             }
             break;
-            case _STEST_PSU_DETECT: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
-                    pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
-                }
-#else
+
+        case _STEST_PSU_DETECT:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
                 pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
-#endif //defined DD360 && !defined DD360Audi
             }
             break;
-            case _STEST_PSU_CAP: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                // 此測試是要確認當前總輸出能力
-                // 如果沒有 PSU 模組請 bypass
-                if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
-                    sleep(1);
-                    pSysInfo->SelfTestSeq = _STEST_COMPLETE;
-                    pSysInfo->BootingStatus = BOOT_COMPLETE;
-                }
-#else
-                //check the power limit from DO
+
+        case _STEST_PSU_CAP:
+            // 此測試是要確認當前總輸出能力
+            // 如果沒有 PSU 模組請 bypass
+
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            //check the power limit from DO
+            pSysInfo->SelfTestSeq = _STEST_COMPLETE;
+            pSysInfo->BootingStatus = BOOT_COMPLETE;
+            log_info("Successful Self Test");
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
+                sleep(1);
                 pSysInfo->SelfTestSeq = _STEST_COMPLETE;
                 pSysInfo->BootingStatus = BOOT_COMPLETE;
-                log_info("Successful Self Test");
-#endif //defined DD360 && !defined DD360Audi
-            }
-            break;
             }
-        } else {
             break;
         }
 

+ 5 - 1
EVSE/Projects/DD360ComBox/Apps/CSU/UpgradeFW.c

@@ -25,7 +25,11 @@ static int InitComPort(uint8_t target)
 
     if (target == UPGRADE_PRI) {
         fd = open(_priPortName, O_RDWR);
-    } else if (target == UPGRADE_FAN ||  target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED) {
+    } else if (target == UPGRADE_FAN ||
+               target == UPGRADE_RB ||
+               target == UPGRADE_AC ||
+               target == UPGRADE_LED
+              ) {
         fd = open(_485PortName, O_RDWR);
     }
 

Файловите разлики са ограничени, защото са твърде много
+ 454 - 222
EVSE/Projects/DD360ComBox/Apps/CSU/main.c


+ 32 - 31
EVSE/Projects/DD360ComBox/Apps/CSU/main.h

@@ -5,43 +5,44 @@
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
-#define MODELNAME_FAIL                          0
-#define BUFFER_SIZE                             128
-#define BTN_RELEASE                             0
-#define BTN_PRESS                               1
-#define MAX_BUF                                 64
-#define MtdBlockSize                            0x600000
+#define MODELNAME_FAIL                          (0)
+#define BUFFER_SIZE                             (128)
+#define BTN_RELEASE                             (0)
+#define BTN_PRESS                               (1)
+#define MAX_BUF                                 (64)
 #define SYSFS_GPIO_DIR                          "/sys/class/gpio"
-#define UPGRADE_FAN                             0x02
+#define UPGRADE_FAN                             (0x02)
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
-#define UPGRADE_RB                              0x09 //0x09 for DD360 dispenser
+#define UPGRADE_RB                              (0x09) //0x09 for DD360 dispenser
 #else
-#define UPGRADE_RB                              0x03 //other module use
-#endif //defined DD360 || defined DD360Audi
-#define UPGRADE_PRI                             0x04
-#define UPGRADE_AC                              0x05
-#define UPGRADE_LED                             0x06
-#define SYSTEM_MIN_VOL                          80 //150
-#define MIN_OUTPUT_CUR                          0
-#define AC_OUTPUT_VOL                           220
-
-#define DEFAULT_AC_INDEX                        2
-#define PSU_MIN_CUR                             100
+#define UPGRADE_RB                              (0x03) //other module use
+#endif //defined DD360 ||defined DD360Audi || defined DD360ComBox
+#define UPGRADE_PRI                             (0x04)
+#define UPGRADE_AC                              (0x05)
+#define UPGRADE_LED                             (0x06)
+#define SYSTEM_MIN_VOL                          (80) //150
+#define MIN_OUTPUT_CUR                          (0)
+#define AC_OUTPUT_VOL                           (220)
+
+#define DEFAULT_AC_INDEX                        (2)
+#define PSU_MIN_CUR                             (100)
 
 //#define DB_FILE                                 "/Storage/ChargeLog/localCgargingRecord.db"
 
-#define uSEC_VAL                                1000000
-#define SELFTEST_TIMEOUT                        60//45
-#define AUTHORIZE_TIMEOUT                       15//30
-#define AUTHORIZE_COMP_TIMEOUT                  3
-#define AUTHORIZE_FAIL_TIMEOUT                  3
-#define AUTHORIZE_STOP_TIMEOUT                  30
-#define RETURN_TO_CHARGING_PAGE                 30
-#define GUN_PREPARE_TIMEOUT                     30
-#define GUN_EV_WAIT_TIMEOUT                     120
-#define GUN_EVSE_WAIT_TIMEOUT                   60
-#define GUN_COMP_WAIT_TIMEOUT                   10
-#define GUN_PRECHARGING_TIMEOUT                 60
+#define uSEC_VAL                                (1000000)
+#define SELFTEST_TIMEOUT                        (60)//45
+#define AUTHORIZE_TIMEOUT                       (15)//30
+#define AUTHORIZE_COMP_TIMEOUT                  (3)
+#define AUTHORIZE_FAIL_TIMEOUT                  (3)
+#define AUTHORIZE_STOP_TIMEOUT                  (30)
+#define RETURN_TO_CHARGING_PAGE                 (30)
+#define GUN_PREPARE_TIMEOUT                     (30)
+#define GUN_EV_WAIT_TIMEOUT                     (120)
+#define GUN_EVSE_WAIT_TIMEOUT                   (60)
+#define GUN_COMP_WAIT_TIMEOUT                   (10)
+#define GUN_PRECHARGING_TIMEOUT                 (60)
+
+#define WHILE_LOOP_TIME                         (10000)
 
 //#define log_info(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)

+ 17 - 4
EVSE/Projects/DD360ComBox/Apps/Config.h

@@ -77,12 +77,18 @@
 
 #define NO_DEFINE                               (255)
 
+#define MtdBlockSize                            (0x300000) //(0x600000)
+
 //------------------------------------------------------------------------------
 //gun temperatures
 //------------------------------------------------------------------------------
-#define GUN_OTP_VALUE                           150
-#define GUN_OTP_RECOVERY                        140
-#define UNDEFINED_TEMP                          255
+#define GUN_OTP_VALUE                           (150)
+#define GUN_OTP_RECOVERY                        (140)
+#define UNDEFINED_TEMP                          (255)
+
+#define WARN_LV_NL                              (0) //normal state
+#define WARN_LV_WARN                            (1)
+#define WARN_LV_ER                              (2) //emergency state
 
 //------------------------------------------------------------------------------
 enum _SYSTEM_STATUS {
@@ -332,6 +338,12 @@ typedef union {
     } StatusBit;
 } ChillerTempState;
 
+typedef struct StChillerValve {
+    uint8_t MultiChillerGun; //0x80, 0: 沒有水冷槍, 1: 有水冷槍, 0x7F: 紀錄水冷槍數
+    uint8_t LeftTemp;  //左槍最高溫度
+    uint8_t RightTemp; //右槍最高溫度
+} ChillerValve;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -340,9 +352,10 @@ typedef struct StDcCommonInfo {
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
     uint8_t SystemModeChange;
-    uint8_t Reserved[3];
     PowerAlarmState PowerAlarmState;
     ChillerTempState ChillerTempState[2];
+    ChillerValve ChillerValve;
+    uint8_t Reserved[3];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 84 - 13
EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.c

@@ -101,18 +101,18 @@ int DB_Open(void)
     return result;
 }
 
-int DB_Insert_Record(int gun_index)
+int DB_Insert_Record(int gunIndex)
 {
     int result = PASS;
     char *errMsg = NULL;
     char insertSql[1024];
-    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
     struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
 
     sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
             "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
             pDcChargingInfo->ReservationId, //DS60-120 add
-            ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+            ShmOCPP16Data->StartTransaction[gunIndex].ResponseTransactionId,
             pDcChargingInfo->StartMethod,
             pDcChargingInfo->StartUserId,
             pDcChargingInfo->StartDateTime,
@@ -120,7 +120,7 @@ int DB_Insert_Record(int gun_index)
             pDcChargingInfo->EvBatteryStartSoc,
             pDcChargingInfo->EvBatterySoc,
             pDcChargingInfo->PresentChargedEnergy,
-            ShmOCPP16Data->StopTransaction[gun_index].StopReason);
+            ShmOCPP16Data->StopTransaction[gunIndex].StopReason);
 
     //if (sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db)) {
     if (sqlite3_open(DB_FILE, &localDb)) { //DS60-120 add
@@ -151,7 +151,7 @@ int DB_Insert_Record(int gun_index)
     return result;
 }
 
-int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
+int DB_Update_Operactive(uint8_t gunIndex, uint8_t IsAvailable)
 {
     uint8_t result = false;
     char *errMsg = NULL;
@@ -165,14 +165,17 @@ int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
     } else {
         log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
 
-        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
-        sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
+        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gunIndex, IsAvailable);
+        sprintf(sqlStr,
+                "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);",
+                gunIndex,
+                IsAvailable); //DS60-120 add
         log_info("sqlStr= %s\r\n", sqlStr);
         if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
             log_info( "update config error message: %s\n", errMsg);
         } else {
-            log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+            log_info("update connector-%d config item isOperactive to %d\r\n", gunIndex, IsAvailable);
         }
 
         sqlite3_close(localDb);
@@ -181,7 +184,7 @@ int DB_Update_Operactive(uint8_t gun_index, uint8_t IsAvailable)
     return result;
 }
 
-int DB_Get_Operactive(uint8_t gun_index)
+int DB_Get_Operactive(uint8_t gunIndex)
 {
     uint8_t result = true;
     char *errMsg = NULL;
@@ -189,8 +192,8 @@ int DB_Get_Operactive(uint8_t gun_index)
     char **rs;
     int  rows, cols;
 
-    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
-    sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gun_index); //DS60-120 add
+    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gunIndex);
+    sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gunIndex); //DS60-120 add
     //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
 
     if (sqlite3_open(DB_FILE, &localDb)) {
@@ -205,10 +208,10 @@ int DB_Get_Operactive(uint8_t gun_index)
                 if (strcmp(rs[(idxRow * cols) + 3], "0") == 0) {
                     result = false;
                 }
-                log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
+                log_info("Query connector-%d isOperactive: %s\r\n", gunIndex, rs[(idxRow * cols) + 3]);
             }
         } else {
-            log_info("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
+            log_info("Query connector-%d fail, set default value to operactive.\r\n", gunIndex);
         }
 
         sqlite3_free_table(rs);
@@ -252,3 +255,71 @@ int DB_Reboot_Record(void)
 
     return result;
 }
+
+//------------------------------------------------------------------------------
+//for Module_EventLog
+//------------------------------------------------------------------------------
+int CreateEventRecord(void)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char *createRecordSql = "CREATE TABLE IF NOT EXISTS event_record("
+                            "idx integer primary key AUTOINCREMENT, "
+                            "occurDatetime text NOT NULL, "
+                            "statusCode text NOT NULL"
+                            ");";
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_error( "Can't open database: %s\n", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info( "Local event record database open successfully.\n");
+
+        if (sqlite3_exec(localDb, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_error( "Create local event record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local event record table successfully\n");
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int InsertEventRecord(uint8_t *statusCode)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char sqlStr[1024] = {0};
+
+    sprintf(sqlStr, "insert into event_record(occurDatetime, statusCode) values(CURRENT_TIMESTAMP, '%s');", statusCode);
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info( "Local event record database open successfully.\n");
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert local event record error message: %s\n", errMsg);
+        } else {
+            log_info( "Insert local event record successfully\n");
+        }
+
+        sprintf(sqlStr, "delete from event_record where idx < (select idx from event_record order by idx desc limit 1)-2000;");
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "delete local event_record error message: %s\n", errMsg);
+        } else {
+            log_info( "delete local event record successfully\n");
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}

+ 9 - 0
EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.h

@@ -1,5 +1,14 @@
 #ifndef _DATA_BASE_H_
 #define _DATA_BASE_H_
 
+int DB_Open(void);
+int DB_Insert_Record(int gunIndex);
+int DB_Update_Operactive(uint8_t gunIndex, uint8_t IsAvailable);
+int DB_Get_Operactive(uint8_t gunIndex);
+int DB_Reboot_Record(void);
+
+//for Module_EventLog
+int CreateEventRecord(void);
+int InsertEventRecord(uint8_t *statusCode);
 
 #endif /* _DATA_BASE_H_ */

Някои файлове не бяха показани, защото твърде много файлове са промени