FolusWen 3 лет назад
Родитель
Сommit
78a485ba88
100 измененных файлов с 4770 добавлено и 2676 удалено
  1. 10 3
      EVSE/Modularization/Module_RatedCurrent.c
  2. 35 13
      EVSE/Projects/DD360/Apps/CSU/Ethernet.c
  3. 175 32
      EVSE/Projects/DD360/Apps/CSU/Primary.c
  4. 273 235
      EVSE/Projects/DD360/Apps/CSU/RFID.c
  5. 144 136
      EVSE/Projects/DD360/Apps/CSU/SelfTest.c
  6. 7 10
      EVSE/Projects/DD360/Apps/CSU/UpgradeFW.c
  7. 421 171
      EVSE/Projects/DD360/Apps/CSU/main.c
  8. 32 31
      EVSE/Projects/DD360/Apps/CSU/main.h
  9. 40 3
      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. 5 5
      EVSE/Projects/DD360/Apps/Define/define.c
  14. 206 165
      EVSE/Projects/DD360/Apps/Define/define.h
  15. 81 18
      EVSE/Projects/DD360/Apps/FactoryConfig.c
  16. 28 19
      EVSE/Projects/DD360/Apps/Makefile
  17. 96 84
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  18. 3 1
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  19. 6 3
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalState.c
  20. 9 9
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.c
  21. 9 9
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.h
  22. 0 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvCommOrg.c
  23. 73 67
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  24. 67 55
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  25. 9 4
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  26. 25 25
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c
  27. 235 133
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  28. 10 0
      EVSE/Projects/DD360/Apps/Script/SearchIP.sh
  29. 2 0
      EVSE/Projects/DD360/Apps/Script/init.sh
  30. 12 4
      EVSE/Projects/DD360/Apps/Script/replaceOtherDD360Project.sh
  31. 1 1
      EVSE/Projects/DD360/Apps/SelectGun/SelectGun.c
  32. 2 1
      EVSE/Projects/DD360/Apps/SelectGun/SelectGun.h
  33. 14 0
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c
  34. 119 52
      EVSE/Projects/DD360/Apps/mainOrg.c
  35. 18 15
      EVSE/Projects/DD360/Apps/timeout.h
  36. BIN
      EVSE/Projects/DD360/Images/FactoryDefaultConfig.bin
  37. BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  38. 3 0
      EVSE/Projects/DD360/ModelNameList.txt
  39. BIN
      EVSE/Projects/DD360/output/FactoryConfig
  40. BIN
      EVSE/Projects/DD360/output/Module_DoComm
  41. BIN
      EVSE/Projects/DD360/output/Module_EvComm
  42. BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  43. BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  44. BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  45. BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  46. BIN
      EVSE/Projects/DD360/output/ReadCmdline
  47. 10 0
      EVSE/Projects/DD360/output/SearchIP.sh
  48. 2 0
      EVSE/Projects/DD360/output/init.sh
  49. BIN
      EVSE/Projects/DD360/output/main
  50. 35 13
      EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c
  51. 175 32
      EVSE/Projects/DD360Audi/Apps/CSU/Primary.c
  52. 273 235
      EVSE/Projects/DD360Audi/Apps/CSU/RFID.c
  53. 144 136
      EVSE/Projects/DD360Audi/Apps/CSU/SelfTest.c
  54. 7 10
      EVSE/Projects/DD360Audi/Apps/CSU/UpgradeFW.c
  55. 421 171
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  56. 32 31
      EVSE/Projects/DD360Audi/Apps/CSU/main.h
  57. 40 3
      EVSE/Projects/DD360Audi/Apps/Config.h
  58. 84 13
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c
  59. 9 0
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.h
  60. 10 0
      EVSE/Projects/DD360Audi/Apps/DebugLog.md
  61. 5 5
      EVSE/Projects/DD360Audi/Apps/Define/define.c
  62. 206 165
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  63. 81 18
      EVSE/Projects/DD360Audi/Apps/FactoryConfig.c
  64. 28 19
      EVSE/Projects/DD360Audi/Apps/Makefile
  65. 96 84
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  66. 3 1
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  67. 6 3
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalState.c
  68. 9 9
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.c
  69. 9 9
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.h
  70. 0 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvCommOrg.c
  71. 73 67
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  72. 67 55
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  73. 9 4
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  74. 25 25
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c
  75. 235 133
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  76. 10 0
      EVSE/Projects/DD360Audi/Apps/Script/SearchIP.sh
  77. 2 0
      EVSE/Projects/DD360Audi/Apps/Script/init.sh
  78. 12 4
      EVSE/Projects/DD360Audi/Apps/Script/replaceOtherDD360Project.sh
  79. 1 1
      EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.c
  80. 2 1
      EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.h
  81. 14 0
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c
  82. 119 52
      EVSE/Projects/DD360Audi/Apps/mainOrg.c
  83. 18 15
      EVSE/Projects/DD360Audi/Apps/timeout.h
  84. BIN
      EVSE/Projects/DD360Audi/Images/FactoryDefaultConfig.bin
  85. BIN
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  86. 3 0
      EVSE/Projects/DD360Audi/ModelNameList.txt
  87. BIN
      EVSE/Projects/DD360Audi/output/FactoryConfig
  88. BIN
      EVSE/Projects/DD360Audi/output/Module_DoComm
  89. BIN
      EVSE/Projects/DD360Audi/output/Module_EvComm
  90. BIN
      EVSE/Projects/DD360Audi/output/Module_EventLogging
  91. BIN
      EVSE/Projects/DD360Audi/output/Module_FactoryConfig
  92. BIN
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  93. BIN
      EVSE/Projects/DD360Audi/output/Module_LcmControl
  94. BIN
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  95. BIN
      EVSE/Projects/DD360Audi/output/ReadCmdline
  96. 10 0
      EVSE/Projects/DD360Audi/output/SearchIP.sh
  97. 2 0
      EVSE/Projects/DD360Audi/output/init.sh
  98. BIN
      EVSE/Projects/DD360Audi/output/main
  99. 35 13
      EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c
  100. 175 32
      EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c

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

+ 35 - 13
EVSE/Projects/DD360/Apps/CSU/Ethernet.c

@@ -11,6 +11,18 @@
 #include "../common.h"
 
 //------------------------------------------------------------------------------
+static void InitialDHCP(void)
+{
+    char tmpbuf[256] = {0};
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+    sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+            pSysConfig->SystemId);
+
+    system(tmpbuf);
+}
+
 void GetMacAddress(void)
 {
     uint8_t index = 0;
@@ -70,10 +82,12 @@ static int isRouteFail(void)
 static int isReachableInternet(void)
 {
     int result = FAIL;
+    int idx = 0;
     FILE *fp;
-    char cmd[256];
-    char buf[512];
-    char tmp[512];
+    char cmd[256] = {0};
+    char buf[512] = {0};
+    char tmp[512] = {0};
+    char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
 
@@ -92,6 +106,7 @@ static int isReachableInternet(void)
             }
         }
     }
+
     pclose(fp);
 
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
@@ -100,9 +115,13 @@ static int isReachableInternet(void)
     } else {
         result = PASS;
     }
-#else
+
+    return result;
+#endif //defined DD360 || defined DD360Audi
+
     memset(buf, 0x00, sizeof(buf));
-    for (int idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
+
+    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");
         if (fp != NULL) {
@@ -122,20 +141,18 @@ static int isReachableInternet(void)
         pclose(fp);
     }
 
-#endif //defined DD360 || defined DD360Audi
-
     return result;
 }
 
 void InitEthernet(void)
 {
     char tmpbuf[256];
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
     bool ethResult = false;
     uint8_t cnt_pingDNS_Fail = 0;
-#endif //!defined DD360 && !defined DD360Audi
 
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
 
     system("ifconfig eth0 down");// eth0 down
     system("ifconfig eth1 down");// eth1 down
@@ -144,6 +161,7 @@ void InitEthernet(void)
     // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
     system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
     sleep(2);
+
     //Init Eth0 for internet
     memset(tmpbuf, 0, 256);
     sprintf(tmpbuf, "/sbin/ifconfig eth0 %s netmask %s up",
@@ -159,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",
@@ -186,8 +205,14 @@ 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
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            isReachableInternet();
+            sleep(5);
+            continue;
+#endif //!defined DD360 && !defined DD360
+
             if (isRouteFail()) {
                 //log_info("eth0 not in route, restart eht0. \n");
                 system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
@@ -266,9 +291,6 @@ void InitEthernet(void)
             }
 
             pSysInfo->InternetConn = ethResult;
-#else
-            isReachableInternet();
-#endif //!defined DD360 && !defined DD360
 
             sleep(5);
         }

+ 175 - 32
EVSE/Projects/DD360/Apps/CSU/Primary.c

@@ -9,7 +9,7 @@
 #include "../ShareMemory/shmMem.h"
 
 #include "../SelectGun/SelectGun.h"
-#include "../main.h"
+#include "main.h"
 
 //------------------------------------------------------------------------------
 
@@ -22,10 +22,16 @@ static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
 
     if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
         ret = YES;
-        if (pLedConfig->RedLED == YES) {
+        if (pLedConfig->RedLED == YES ||
+                pLedConfig->YellowLED == YES ||
+                pLedConfig->GreenLED == YES) {
             pLedConfig->RedLED = NO;
+            pLedConfig->YellowLED = NO;
+            pLedConfig->GreenLED = NO;
         } else {
             pLedConfig->RedLED = YES;
+            pLedConfig->YellowLED = YES;
+            pLedConfig->GreenLED = YES;
         }
     }
 
@@ -55,6 +61,19 @@ void PrimaryLedIndicatorCtrlFork(void)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
+                if (pSysWarning->Level == WARN_LV_ER) {
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        usleep(500000);
+                        continue;
+                    }
+
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    pLedConfig->RedLED = YES;
+                    usleep(500000);
+                    continue;
+                }
+
                 //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
                 //printf("level = %d\r\n", pSysWarning->Level);
                 switch (pDcChargingInfo->SystemStatus) {
@@ -127,32 +146,31 @@ void PrimaryLedIndicatorCtrlFork(void)
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    if (pSysWarning->Level == 2) {
-                        pLedConfig->YellowLED = NO;
-                        pLedConfig->GreenLED = NO;
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    } else {
-                        pLedConfig->RedLED = NO;
-                        pLedConfig->YellowLED = YES;
-                        pLedConfig->GreenLED = NO;
-                    }
+                    //if (pSysWarning->Level == WARN_LV_ER) {
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
+                    pLedConfig->RedLED = NO;
+                    pLedConfig->YellowLED = YES;
+                    pLedConfig->GreenLED = NO;
+                    //}
                     break;
 
                 case S_MAINTAIN:
                 case S_FAULT:
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
-                    if (pSysWarning->Level == 2) {
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    }
+                    pLedConfig->RedLED = YES;
+                    //if (pSysWarning->Level == WARN_LV_ER) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->RedLED = YES;
+                    //}
                     break;
 
                 case S_BOOKING:
@@ -160,65 +178,187 @@ void PrimaryLedIndicatorCtrlFork(void)
                 case S_UPDATE:
                 case S_NONE:
                     break;
-                }
-
-                usleep(500000);
-            }//switch
-        }//for
-    }//while
+                }//switch
+            }//for
+            usleep(500000);
+        }//while
+    }//fork
 }
 
 //------------------------------------------------------------------------------
+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;
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042252", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = YES;
                 EmcOccureByString("042252");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042200", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = YES;
                 EmcOccureByString("042200");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042201", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = YES;
                 EmcOccureByString("042201");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042202", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = YES;
                 EmcOccureByString("042202");
                 Rtn = 1;
+            } else if (memcmp(&pSysWarning->WarningCode[i][0], "042267", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = YES;
+                EmcOccureByString("042267");
+                Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
                 EmcOccureByString("012304");
                 Rtn = 1;
             }
         }
+
         if (Rtn == 0) {
+            ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
             ReleaseEmsOccureByString(0, "042251");
             ReleaseEmsOccureByString(0, "042252");
             ReleaseEmsOccureByString(0, "042200");
             ReleaseEmsOccureByString(0, "042201");
             ReleaseEmsOccureByString(0, "042202");
+            ReleaseEmsOccureByString(0, "042267");
             ReleaseEmsOccureByString(0, "012304");
         }
     } else {
+        ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
         ReleaseEmsOccureByString(0, "042251");
         ReleaseEmsOccureByString(0, "042252");
         ReleaseEmsOccureByString(0, "042200");
         ReleaseEmsOccureByString(0, "042201");
         ReleaseEmsOccureByString(0, "042202");
+        ReleaseEmsOccureByString(0, "042267");
         ReleaseEmsOccureByString(0, "012304");
     }
 
@@ -272,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);
 
@@ -305,7 +448,6 @@ void ChkPrimaryStatus(void)
                     break;
                 }
             }
-
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
                 if (isDetectPlugin()) {
@@ -356,6 +498,7 @@ void ChkPrimaryStatus(void)
                 //pDcChargingInfo->SystemStatus = S_IDLE;
                 break;
             }
+#endif //0
         }
     } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
         if (leftBtnPush) {

+ 273 - 235
EVSE/Projects/DD360/Apps/CSU/RFID.c

@@ -9,7 +9,7 @@
 #include "../ShareMemory/shmMem.h"
 #include "../SelectGun/SelectGun.h"
 
-#include "../main.h"
+#include "main.h"
 #include "../timeout.h"
 
 //------------------------------------------------------------------------------
@@ -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);
         }
     }
 }

+ 144 - 136
EVSE/Projects/DD360/Apps/CSU/SelfTest.c

@@ -8,7 +8,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 
-#include "../main.h"
+#include "main.h"
 #include "../timeout.h"
 
 //------------------------------------------------------------------------------
@@ -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;
         }
 

+ 7 - 10
EVSE/Projects/DD360/Apps/CSU/UpgradeFW.c

@@ -11,7 +11,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 
-#include "../main.h"
+#include "main.h"
 
 //------------------------------------------------------------------------------
 static char *_priPortName = "/dev/ttyS1";
@@ -25,16 +25,19 @@ 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);
     }
 
     if (fd <= 0) {
-#ifdef SystemLogMessage
         log_error("open 407 Communication port NG \n");
-#endif
         return -1;
     }
+
     ioctl (fd, TCGETS, &tios);
     tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
     tios.c_lflag = 0;
@@ -66,21 +69,15 @@ static int InitCanBus(void)
     tv.tv_sec = 0;
     tv.tv_usec = 10000;
     if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct  timeval)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVTIMEO NG");
-#endif
     }
     nbytes = 40960;
     if (setsockopt(fd, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVBUF NG");
-#endif
     }
     nbytes = 40960;
     if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_SNDBUF NG");
-#endif
     }
 
     strcpy(ifr0.ifr_name, "can0");

Разница между файлами не показана из-за своего большого размера
+ 421 - 171
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)

+ 40 - 3
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 {
@@ -310,6 +316,34 @@ typedef union {
     } GunBits;
 } EvBoardErrMsg;
 
+typedef union {
+    uint8_t AlarmState;
+    struct {
+        uint8_t EmergencyStop: 1;    //Power cabinet emergency stop
+        uint8_t DoorOpen: 1;         //Power cabinet emergency door open
+        uint8_t SystemL1InputOVP: 1; //Power cabinet system L1 input OVP
+        uint8_t SystemL2InputOVP: 1; //Power cabinet System L2 input OVP
+        uint8_t SystemL3InputOVP: 1; //Power cabinet System L3 input OVP
+        uint8_t PsuFailure: 1;       //Power cabinet PSU Failure Alarm
+        uint8_t Reserved: 2;
+    } StatusBit;
+} PowerAlarmState;
+
+typedef union {
+    uint8_t ChillerState;
+    struct {
+        uint8_t ChillerOTP: 1;            //chiller Temperature OVP
+        uint8_t ChillerTempSensorFail: 1; //Chiller temperature sensor failure
+        uint8_t Reserved: 6;
+    } 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;
@@ -318,6 +352,9 @@ typedef struct StDcCommonInfo {
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
     uint8_t SystemModeChange;
+    PowerAlarmState PowerAlarmState;
+    ChillerTempState ChillerTempState[2];
+    ChillerValve ChillerValve;
     uint8_t Reserved[3];
 } DcCommonInfo;
 

+ 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後再通知小板進入充電狀態。

+ 5 - 5
EVSE/Projects/DD360/Apps/Define/define.c

@@ -102,7 +102,7 @@ char FaultStatusCode[40][6]=
 "011035", //Ble module broken
 "011036", //Rotary switch fault
 "011037", //CCS liquid chiller water level fault
-"011038", //Reserved
+"011038", //Chiller temperature sensor broken
 "011039", //Reserved
 "011040" //Reserved
 };
@@ -229,10 +229,10 @@ char AlarmStatusCode[128][6]=
 "012317", // Psu Dcdc Eeprom Fault
 "012318", // Psu Pfc Eeprom Fault
 "012319", // Psu Dcdc Over Voltage
-"012320", // reserved
-"012321", // reserved
-"012322", // reserved
-"012323", // reserved
+"012320", // System CHAdeMO output UCP
+"012321", // System CCS output UCP
+"012322", // System GBT output UCP
+"012323", // System Chiller output OTP
 "012324", // reserved
 "012325", // reserved
 "012326", // reserved

+ 206 - 165
EVSE/Projects/DD360/Apps/Define/define.h

@@ -169,6 +169,10 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #define ShmOcpp20ModuleKey		1012
 #define ShmRelay2BdKey			1013
 
+#define FaultCodeLength         5
+#define AlarmCodeLength         16
+#define InfoCodeLength          41
+
 /**************************************************************************************/
 /****************** Share memory configuration value constant define ******************/
 /**************************************************************************************/
@@ -289,7 +293,7 @@ enum CoreProfile {
      DefaultPrice,
      CustomDisplayCostAndPrice,
      CustomIdleFeeAfterStop,
-	 ConfigurationVersion,
+     ConfigurationVersion,
 	 _CoreProfile_CNT
 };
 
@@ -401,10 +405,19 @@ typedef union
         unsigned int NormalStop:1;                  // 0: no effect,    1: normal stop
         unsigned int AlarmStop:1;                   // 0: no effect,    1: alarm stop
         unsigned int BackendStop:1;                 // 0: no effect,    1: backend stop
-        unsigned int res:29;
+        unsigned int ManualStop:1;                  // 0: no effect,    1: manual stop
+        unsigned int res:28;
     }bits;
 }ChargingStop;
 
+typedef struct
+{
+    unsigned char DispenserSequence;                    // dispenser sequence
+    unsigned char MaxConnectorQuantity;                 // max connector quantity
+    unsigned char WiringSetting[8];                     // record connector quantity of dispenser
+    unsigned char PowerCabinetReserved[32];
+}WiringInfoData;
+
 struct SysConfigData
 {
 	/**************System***************/
@@ -465,7 +478,10 @@ struct SysConfigData
 	unsigned char			ShowInformation;
 	unsigned char           isReqFirstUpgrade;          //EVSE is request first upgrade from PH server
 	unsigned char           isEnableLocalPowerSharging; //0: Disable power sharing  1: Enable power sharing
-	unsigned char			StopChargingByButton;		//0: Disable  1: Enable
+	unsigned char           StopChargingByButton;       //0: Disable  1: Enable
+
+    /************PowerCabinet************/
+    WiringInfoData          WiringInfo;
 };
 
 struct ChargingInfoData
@@ -510,6 +526,8 @@ struct ChargingInfoData
 	float					ChargingFee;
 	// Connector Temp
 	unsigned char 		ConnectorTemp;			//0x00: -60¢XC  ~  0xFE: 194
+	//Chiller Temp
+    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;
@@ -552,6 +570,10 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
+	char 				ReservedStartFlag;
+	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
+	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
+	unsigned char 		ModelType;
 };
 
 typedef union
@@ -580,7 +602,9 @@ typedef union
         unsigned int EthernetStatusRequest:1;           // 0: no request,   1: ethernet connection status has changed           ( cabinet -> dispenser)
         unsigned int WiFiStatusRequest:1;               // 0: no request,   1: wifi connection status has changed               ( cabinet -> dispenser)
         unsigned int TelcomModemStatusRequest:1;        // 0: no request,   1: 4g connection status has changed                 ( cabinet -> dispenser)
-        unsigned int res:11;
+        unsigned int BillingStatusRequest:1;            // 0: no request,   1: billing status has changed                       ( cabinet -> dispenser)
+        unsigned int StopButtonStatusRequest:1;         // 0: no request,   1: stop charging button status has changed          ( cabinet -> dispenser)
+        unsigned int res:9;
     }bits;
 }DispenserSettingFlag;
 
@@ -636,10 +660,13 @@ struct ConnectionInfoData
 
 struct DispenserInfoData
 {
-    unsigned char               DispenserQuantity;
-    unsigned char               TotalConnectorQuantity;
+    unsigned char               DispenserQuantity;                  // record max dispenser quantity
+    unsigned char               TotalConnectorQuantity;             // record max connector quantity
     struct DispenserModule      Dispenser[GENERAL_GUN_QUANTITY];
 
+    unsigned char               PresentDispenserQuantity;
+    unsigned char               PresentConnectorQuantity;
+
     union
     {
         unsigned char Status;
@@ -747,7 +774,10 @@ typedef union
         unsigned int AuthorizingCompleted:1;    // 0: not yet, 1: authorizing completed
         unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
         unsigned int BackendAuthorized:1;       // 0: local authorized, 1: backend authorized
-        unsigned int res:28;
+        unsigned int WiringInfoChanged:1;       // 0: no effect, 1: wiring info has changed
+        unsigned int EnableWriteWiringInfo:1;   // 0: no effect, 1: enable write wiring info after timeout
+        unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
+        unsigned int res:25;
     }bits;
 }CabinetSettingFlag;
 
@@ -760,6 +790,8 @@ typedef struct
     unsigned int EthernetStatus;                // 0: disable, 1: connected, 2: disconnected
     unsigned int WiFiStatus;                    // 0: disable, 1: connected, 2: disconnected
     unsigned int TelcomModemStatus;             // 0: disable, 1: connected, 2: disconnected
+    unsigned int BillingStatus;                 // 0: disable, 1: enable
+    unsigned int StopChargingButton;            // 0: disable, 1: enable
     unsigned int HardwareReboot;                // 1: HardwareReboot, Other value: no effect
     unsigned int SoftwareRestart;               // 1: SoftwareRestart, Other value: no effect
 }CabinetMiscCommand;
@@ -978,7 +1010,7 @@ char FaultStatusCode[40][6]=
 	"011035",	//Ble module broken
 	"011036",	//Rotary switch fault
 	"011037",	//CCS liquid chiller water level fault
-	"011038",	//Reserved
+	"011038",	//Chiller temperature sensor broken
 	"011039",	//Reserved
 	"011040"	//Reserved
 };
@@ -986,10 +1018,10 @@ char FaultStatusCode[40][6]=
 
 struct FaultCodeData
 {
-	unsigned char PreviousFaultVal[5];
+	unsigned char PreviousFaultVal[FaultCodeLength];
 	union
 	{
-		unsigned char FaultVal[5];
+		unsigned char FaultVal[FaultCodeLength];
 		struct
 		{
 			//FaultVal[0]
@@ -1034,7 +1066,8 @@ struct FaultCodeData
 			unsigned char BleModuleBroken:1;					//bit 2
 			unsigned char RotarySwitchFault:1;					//bit 3 
 			unsigned char CcsLiquidChillerWaterLevelFault:1;    //bit 4
-			unsigned char :3;									//bit 5 ~ 7	reserved
+			unsigned char ChillerTempSensorBroken:1;            //bit 5
+			unsigned char :2;									//bit 6 ~ 7	reserved
 		}bits;
 	}FaultEvents;
 };
@@ -1162,10 +1195,10 @@ char AlarmStatusCode[128][6]=
     "012317",   // Psu Dcdc Eeprom Fault
     "012318",   // Psu Pfc Eeprom Fault
     "012319",   // Psu Dcdc Over Voltage
-    "012320",   // reserved
-    "012321",   // reserved
-    "012322",   // reserved
-    "012323",   // reserved
+    "012320",   // System CHAdeMO output UCP
+    "012321",   // System CCS output UCP
+    "012322",   // System GBT output UCP
+    "012323",   // System Chiller output OTP
     "012324",   // reserved
     "012325",   // reserved
     "012326",   // reserved
@@ -1174,10 +1207,10 @@ char AlarmStatusCode[128][6]=
 */
 struct AlarmCodeData
 {
-	unsigned char PreviousAlarmVal[16];
+	unsigned char PreviousAlarmVal[AlarmCodeLength];
 	union
 	{
-		unsigned char AlarmVal[16];
+		unsigned char AlarmVal[AlarmCodeLength];
 		struct
 		{
 			//AlarmVal[0]
@@ -1316,7 +1349,11 @@ struct AlarmCodeData
             unsigned char PsuPfcEepromFault:1;                      //bit 6
             unsigned char PsuDcdcOverVoltage:1;                     //bit 7
             //AlarmVal[15]
-            unsigned char Reserved:8;                               //bit 0~7
+            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;
 	}AlarmEvents;
 };
@@ -1658,10 +1695,10 @@ char InfoStatusCode[384][6]=
 */
 struct InfoCodeData
 {
-	unsigned char PreviousInfoVal[41];
+	unsigned char PreviousInfoVal[InfoCodeLength];
 	union
 	{
-		unsigned char InfoVal[41];
+		unsigned char InfoVal[InfoCodeLength];
 		struct
 		{
 			//InfoVal[0]
@@ -2083,6 +2120,10 @@ struct PsuGroupData
 	unsigned int            GroupPresentOutputPower;        //Watt
 	struct PsuModuleData 	PsuModule[MAX_PSU_QUANTITY];
 	PsuGroupError           GroupErrorFlag;
+    unsigned short          TotalIAvailableCurrent;         // unit: 0.1A
+    unsigned short          TempIAvailableCurrent;          // unit: 0.1A
+    unsigned short          StableIAvailableCurrent;        // unit: 0.1A
+    unsigned short          StableCurrentCounter;           // stable current counter
 };
 
 /*Following is the information for system all PSU*/
@@ -4230,104 +4271,104 @@ struct StructCost
 
 struct CertificateHashDataType
 {
-	unsigned char hashAlgorithm[8];								// Required. Used algorithms for the hashes provided.
-	unsigned char issuerNameHash[129];							// Required. hashed value of the IssuerName.
-	unsigned char issuerKeyHash[129];							// Required. Hashed value of the issuers public key
-	unsigned char serialNumber[41];								// Required. The serial number of the certificate.
+    unsigned char hashAlgorithm[8];                             // Required. Used algorithms for the hashes provided.
+    unsigned char issuerNameHash[129];                          // Required. hashed value of the IssuerName.
+    unsigned char issuerKeyHash[129];                           // Required. Hashed value of the issuers public key
+    unsigned char serialNumber[41];                             // Required. The serial number of the certificate.
 };
 
 struct LogParametersType
 {
-	unsigned char remoteLocation[513];								// Required. The URL of the location at the remote system where the log should be stored.
-	unsigned char oldestTimestamp[36];								// Optional. This contains the date and time of the oldest logging information to include in the diagnostics.
-	unsigned char latestTimestamp[36];								// Optional. This contains the date and time of the latest logging information to include in the diagnostics.
+    unsigned char remoteLocation[513];                              // Required. The URL of the location at the remote system where the log should be stored.
+    unsigned char oldestTimestamp[36];                              // Optional. This contains the date and time of the oldest logging information to include in the diagnostics.
+    unsigned char latestTimestamp[36];                              // Optional. This contains the date and time of the latest logging information to include in the diagnostics.
 };
 
 struct FirmwareType
 {
-	unsigned char location[513];									// Required. URI defining the origin of the firmware.
-	unsigned char retrieveDateTime[36];								// Required. Date and time at which the firmware shall be retrieved.
-	unsigned char installDateTime[36];								// Optional. Date and time at which the firmware shall be installed.
-	unsigned char signingCertificate[5501];							// Optional. Certificate with which the firmware was signed. X.509 certificate, first DER encoded into binary, and then Base64 encoded.
-	unsigned char signature[801];									// Optional. Base64 encoded firmware signature.
+    unsigned char location[513];                                    // Required. URI defining the origin of the firmware.
+    unsigned char retrieveDateTime[36];                             // Required. Date and time at which the firmware shall be retrieved.
+    unsigned char installDateTime[36];                              // Optional. Date and time at which the firmware shall be installed.
+    unsigned char signingCertificate[5501];                         // Optional. Certificate with which the firmware was signed. X.509 certificate, first DER encoded into binary, and then Base64 encoded.
+    unsigned char signature[801];                                   // Optional. Base64 encoded firmware signature.
 };
 
 struct StructCertificateSigned
 {
-	unsigned char certificateChain[10001];
-	unsigned char Response_status[16];
+    unsigned char certificateChain[10001];
+    unsigned char Response_status[16];
 };
 
 struct StructDeleteCertificate
 {
-	struct CertificateHashDataType certificateHashData;
-	unsigned char Response_status[16];
+    struct CertificateHashDataType certificateHashData;
+    unsigned char Response_status[16];
 };
 
 struct StructExtendedTrigger
 {
-	unsigned char requestedMessage[32];
-	int connectorId;
-	unsigned char Response_status[16];
+    unsigned char requestedMessage[32];
+    int connectorId;
+    unsigned char Response_status[16];
 };
 
 struct StructGetInstalledCertificateIds
 {
-	unsigned char certificateType[32];
-	unsigned char Response_status[16];
-	struct CertificateHashDataType Response_certificateHashData[3];
+    unsigned char certificateType[32];
+    unsigned char Response_status[16];
+    struct CertificateHashDataType Response_certificateHashData[3];
 };
 
 struct StructGetLog
 {
-	unsigned char logType[16];
-	int requestId;
-	int retries;
-	int retryInterval;
-	struct LogParametersType log;
-	unsigned char Response_status[16];
-	unsigned char Response_filename[256];
+    unsigned char logType[16];
+    int requestId;
+    int retries;
+    int retryInterval;
+    struct LogParametersType log;
+    unsigned char Response_status[16];
+    unsigned char Response_filename[256];
 };
 
 struct StructInstallCertificate
 {
-	unsigned char certificateType[32];
-	unsigned char certificate[5501];
-	unsigned char Response_status[16];
+    unsigned char certificateType[32];
+    unsigned char certificate[5501];
+    unsigned char Response_status[16];
 };
 
 struct StructSignedUpdateFirmware
 {
-	int retries;
-	int retryInterval;
-	int requestId;
-	struct FirmwareType firmware;
-	unsigned char Response_status[16];
+    int retries;
+    int retryInterval;
+    int requestId;
+    struct FirmwareType firmware;
+    unsigned char Response_status[16];
 };
 
 struct StructLogStatusNotification
 {
-	unsigned char status[32];
-	int requestId;
+    unsigned char status[32];
+    int requestId;
 };
 
 struct StructSecurityEventNotification
 {
-	unsigned char type[51];
-	unsigned char timestamp[28];
-	unsigned char techInfo[256];
+    unsigned char type[51];
+    unsigned char timestamp[28];
+    unsigned char techInfo[256];
 };
 
 struct StructSignCertificate
 {
-	unsigned char csr[5501];
-	unsigned char Response_status[16];
+    unsigned char csr[5501];
+    unsigned char Response_status[16];
 };
 
 struct StructSignedFirmwareStatusNotification
 {
-	unsigned char status[32];
-	int requestId;
+    unsigned char status[32];
+    int requestId;
 };
 
 struct OCPP16Data
@@ -4362,23 +4403,23 @@ struct OCPP16Data
         struct
         {
             //SpMsgValue[0]
-            unsigned char BootNotificationReq :1;               	//bit 0,
-            unsigned char BootNotificationConf :1;              	//bit 1,
-            unsigned char AuthorizeReq :1;                      	//bit 2,
-            unsigned char AuthorizeConf :1;                     	//bit 3,
-            unsigned char DiagnosticsStatusNotificationReq :1;  	//bit 4,
-            unsigned char DiagnosticsStatusNotificationConf :1; 	//bit 5,
-            unsigned char FirmwareStatusNotificationReq :1;     	//bit 6,
-            unsigned char FirmwareStatusNotificationConf :1;   	 	//bit 7,
+            unsigned char BootNotificationReq :1;                   //bit 0,
+            unsigned char BootNotificationConf :1;                  //bit 1,
+            unsigned char AuthorizeReq :1;                          //bit 2,
+            unsigned char AuthorizeConf :1;                         //bit 3,
+            unsigned char DiagnosticsStatusNotificationReq :1;      //bit 4,
+            unsigned char DiagnosticsStatusNotificationConf :1;     //bit 5,
+            unsigned char FirmwareStatusNotificationReq :1;         //bit 6,
+            unsigned char FirmwareStatusNotificationConf :1;        //bit 7,
             //SpMsgValue[1]
             unsigned char LogStatusNotificationReq :1;              //bit 0,
-			unsigned char LogStatusNotificationConf :1;             //bit 1,
-			unsigned char SecurityEventNotificationReq :1;          //bit 2,
-			unsigned char SecurityEventNotificationConf :1;         //bit 3,
-			unsigned char SignCertificateReq :1;  					//bit 4,
-			unsigned char SignCertificateConf :1; 					//bit 5,
-			unsigned char SignedFirmwareStatusNotificationReq :1;   //bit 6,
-			unsigned char SignedFirmwareStatusNotificationConf :1;	//bit 7,
+            unsigned char LogStatusNotificationConf :1;             //bit 1,
+            unsigned char SecurityEventNotificationReq :1;          //bit 2,
+            unsigned char SecurityEventNotificationConf :1;         //bit 3,
+            unsigned char SignCertificateReq :1;                    //bit 4,
+            unsigned char SignCertificateConf :1;                   //bit 5,
+            unsigned char SignedFirmwareStatusNotificationReq :1;   //bit 6,
+            unsigned char SignedFirmwareStatusNotificationConf :1;  //bit 7,
         } bits;
     } SpMsg;
 
@@ -4424,40 +4465,40 @@ struct OCPP16Data
         struct
         {
             //CsMsgValue[0]
-            unsigned char ChangeConfigurationReq :1;    			//bit 0,
-            unsigned char ChangeConfigurationConf :1;   			//bit 1,
-            unsigned char ClearCacheReq :1;             			//bit 2,
-            unsigned char ClearCacheConf :1;            			//bit 3,
-            unsigned char GetConfigurationReq :1;       			//bit 4,
-            unsigned char GetConfigurationConf :1;      			//bit 5,
-            unsigned char UpdateFirmwareReq :1;         			//bit 6,
-            unsigned char UpdateFirmwareConf :1;        			//bit 7,
+            unsigned char ChangeConfigurationReq :1;                //bit 0,
+            unsigned char ChangeConfigurationConf :1;               //bit 1,
+            unsigned char ClearCacheReq :1;                         //bit 2,
+            unsigned char ClearCacheConf :1;                        //bit 3,
+            unsigned char GetConfigurationReq :1;                   //bit 4,
+            unsigned char GetConfigurationConf :1;                  //bit 5,
+            unsigned char UpdateFirmwareReq :1;                     //bit 6,
+            unsigned char UpdateFirmwareConf :1;                    //bit 7,
             //CsMsgValue[1]
-            unsigned char GetDiagnosticsReq :1;         			//bit 0,
-            unsigned char GetDiagnosticsConf :1;        			//bit 1,
-            unsigned char GetLocalListVersionReq :1;   				//bit 2,
-            unsigned char GetLocalListVersionConf :1;   			//bit 3,
-            unsigned char ResetReq :1;                  			//bit 4,
-            unsigned char ResetConf :1;                 			//bit 5,
-            unsigned char SendLocalListReq :1;         				//bit 6,
-            unsigned char SendLocalListConf :1;         			//bit 7,
+            unsigned char GetDiagnosticsReq :1;                     //bit 0,
+            unsigned char GetDiagnosticsConf :1;                    //bit 1,
+            unsigned char GetLocalListVersionReq :1;                //bit 2,
+            unsigned char GetLocalListVersionConf :1;               //bit 3,
+            unsigned char ResetReq :1;                              //bit 4,
+            unsigned char ResetConf :1;                             //bit 5,
+            unsigned char SendLocalListReq :1;                      //bit 6,
+            unsigned char SendLocalListConf :1;                     //bit 7,
             //CsMsgValue[2]
-            unsigned char CertificateSignedReq :1;					//bit 0
-            unsigned char CertificateSignedConf :1;					//bit 1
-            unsigned char DeleteCertificateReq :1;					//bit 2
-            unsigned char DeleteCertificateConf :1;					//bit 3
-            unsigned char ExtendedTriggerMessageReq :1;				//bit 4
-            unsigned char ExtendedTriggerMessageConf :1;			//bit 5
-            unsigned char GetInstalledCertificateIdsReq :1;			//bit 6
-            unsigned char GetInstalledCertificateIdsConf :1;		//bit 7
+            unsigned char CertificateSignedReq :1;                  //bit 0
+            unsigned char CertificateSignedConf :1;                 //bit 1
+            unsigned char DeleteCertificateReq :1;                  //bit 2
+            unsigned char DeleteCertificateConf :1;                 //bit 3
+            unsigned char ExtendedTriggerMessageReq :1;             //bit 4
+            unsigned char ExtendedTriggerMessageConf :1;            //bit 5
+            unsigned char GetInstalledCertificateIdsReq :1;         //bit 6
+            unsigned char GetInstalledCertificateIdsConf :1;        //bit 7
             //CsMsgValue[3]
-            unsigned char GetLogReq :1;								//bit 0
-            unsigned char GetLogConf :1;							//bit 1
-            unsigned char InstallCertificateReq :1;					//bit 2
-            unsigned char InstallCertificateConf :1;				//bit 3
-            unsigned char SignedUpdateFirmwareReq :1;				//bit 4
-            unsigned char SignedUpdateFirmwareConf :1;				//bit 5
-            unsigned char :2;										//bit 6 & 7
+            unsigned char GetLogReq :1;                             //bit 0
+            unsigned char GetLogConf :1;                            //bit 1
+            unsigned char InstallCertificateReq :1;                 //bit 2
+            unsigned char InstallCertificateConf :1;                //bit 3
+            unsigned char SignedUpdateFirmwareReq :1;               //bit 4
+            unsigned char SignedUpdateFirmwareConf :1;              //bit 5
+            unsigned char :2;                                       //bit 6 & 7
         } bits;
     } MsMsg;
 
@@ -4474,48 +4515,48 @@ struct OCPP16Data
         } bits[CONNECTOR_QUANTITY];
     }CSUMsg;
 
-    struct StructBootNotification               	BootNotification;
-    struct StructHeartbeat                     	 	Heartbeat;
-    struct StructAuthorize                      	Authorize;
-    struct StructStartTransaction               	StartTransaction[CONNECTOR_QUANTITY];
-    struct StructStopTransaction                	StopTransaction[CONNECTOR_QUANTITY];
-    struct StructStatusNotification             	StatusNotification[CONNECTOR_QUANTITY];
-    struct StructCancelReservation              	CancelReservation[CONNECTOR_QUANTITY];
-    struct StructChangeAvailability             	ChangeAvailability[CONNECTOR_QUANTITY];
-    struct StructChangeConfiguration            	ChangeConfiguration;
-    struct StructClearCache                     	ClearCache;
-    struct StructClearChargingProfile           	ClearChargingProfile[CONNECTOR_QUANTITY];
-    struct StructDataTransfer                   	DataTransfer[CONNECTOR_QUANTITY];
-    struct StructDiagnosticsStatusNotification  	DiagnosticsStatusNotification;
-    struct StructFirmwareStatusNotification     	FirmwareStatusNotification;
-    struct StructGetCompositeSchedule           	GetCompositeSchedule[CONNECTOR_QUANTITY];
-    struct StructGetConfiguration               	GetConfiguration;
-    struct StructGetDiagnostics                 	GetDiagnostics;
-    struct StructGetLocalListVersion            	GetLocalListVersion;
-    struct StructMeterValues                    	MeterValues[CONNECTOR_QUANTITY];
-    struct StructRemoteStartTransaction         	RemoteStartTransaction[CONNECTOR_QUANTITY];
-    struct StructRemoteStopTransaction          	RemoteStopTransaction[CONNECTOR_QUANTITY];
-    struct StructReserveNow                     	ReserveNow[CONNECTOR_QUANTITY];
-    struct StructReset                          	Reset;
-    struct StructSendLocalList                  	SendLocalList;
-    struct StructSetChargingProfile            		SetChargingProfile[CONNECTOR_QUANTITY];
-    struct StructTriggerMessage                 	TriggerMessage[CONNECTOR_QUANTITY];
-    struct StructUnlockConnector                	UnlockConnector[CONNECTOR_QUANTITY];
-    struct StructUpdateFirmware                 	UpdateFirmware;
-    struct OCPP16ConfigurationTable             	ConfigurationTable;
-    struct StructChargingProfile                	SmartChargingProfile[CONNECTOR_QUANTITY];
-    struct StructCost                           	Cost;
-    struct StructCertificateSigned					CertificateSigned;
-    struct StructDeleteCertificate					DeleteCertificate;
-    struct StructExtendedTrigger					ExtendedTriggerMessage;
-    struct StructGetInstalledCertificateIds			GetInstalledCertificateIds;
-    struct StructGetLog								GetLog;
-    struct StructInstallCertificate					InstallCertificate;
-    struct StructSignedUpdateFirmware				SignedUpdateFirmware;
-    struct StructLogStatusNotification				LogStatusNotification;
-    struct StructSecurityEventNotification			SecurityEventNotification;
-    struct StructSignCertificate					SignCertificate;
-    struct StructSignedFirmwareStatusNotification 	SignedFirmwareStatusNotification;
+    struct StructBootNotification                   BootNotification;
+    struct StructHeartbeat                          Heartbeat;
+    struct StructAuthorize                          Authorize;
+    struct StructStartTransaction                   StartTransaction[CONNECTOR_QUANTITY];
+    struct StructStopTransaction                    StopTransaction[CONNECTOR_QUANTITY];
+    struct StructStatusNotification                 StatusNotification[CONNECTOR_QUANTITY];
+    struct StructCancelReservation                  CancelReservation[CONNECTOR_QUANTITY];
+    struct StructChangeAvailability                 ChangeAvailability[CONNECTOR_QUANTITY];
+    struct StructChangeConfiguration                ChangeConfiguration;
+    struct StructClearCache                         ClearCache;
+    struct StructClearChargingProfile               ClearChargingProfile[CONNECTOR_QUANTITY];
+    struct StructDataTransfer                       DataTransfer[CONNECTOR_QUANTITY];
+    struct StructDiagnosticsStatusNotification      DiagnosticsStatusNotification;
+    struct StructFirmwareStatusNotification         FirmwareStatusNotification;
+    struct StructGetCompositeSchedule               GetCompositeSchedule[CONNECTOR_QUANTITY];
+    struct StructGetConfiguration                   GetConfiguration;
+    struct StructGetDiagnostics                     GetDiagnostics;
+    struct StructGetLocalListVersion                GetLocalListVersion;
+    struct StructMeterValues                        MeterValues[CONNECTOR_QUANTITY];
+    struct StructRemoteStartTransaction             RemoteStartTransaction[CONNECTOR_QUANTITY];
+    struct StructRemoteStopTransaction              RemoteStopTransaction[CONNECTOR_QUANTITY];
+    struct StructReserveNow                         ReserveNow[CONNECTOR_QUANTITY];
+    struct StructReset                              Reset;
+    struct StructSendLocalList                      SendLocalList;
+    struct StructSetChargingProfile                 SetChargingProfile[CONNECTOR_QUANTITY];
+    struct StructTriggerMessage                     TriggerMessage[CONNECTOR_QUANTITY];
+    struct StructUnlockConnector                    UnlockConnector[CONNECTOR_QUANTITY];
+    struct StructUpdateFirmware                     UpdateFirmware;
+    struct OCPP16ConfigurationTable                 ConfigurationTable;
+    struct StructChargingProfile                    SmartChargingProfile[CONNECTOR_QUANTITY];
+    struct StructCost                               Cost;
+    struct StructCertificateSigned                  CertificateSigned;
+    struct StructDeleteCertificate                  DeleteCertificate;
+    struct StructExtendedTrigger                    ExtendedTriggerMessage;
+    struct StructGetInstalledCertificateIds         GetInstalledCertificateIds;
+    struct StructGetLog                             GetLog;
+    struct StructInstallCertificate                 InstallCertificate;
+    struct StructSignedUpdateFirmware               SignedUpdateFirmware;
+    struct StructLogStatusNotification              LogStatusNotification;
+    struct StructSecurityEventNotification          SecurityEventNotification;
+    struct StructSignCertificate                    SignCertificate;
+    struct StructSignedFirmwareStatusNotification   SignedFirmwareStatusNotification;
 };
 
 
@@ -5082,8 +5123,8 @@ struct TransactionType
 
 struct StatusInfoType
 {
-	unsigned char reasonCode[21];									// Required. A predefined code for the reason why thestatus is returned in this response. The string is case-insensitive.
-	unsigned char additionalInfo[513];								// Optional. Additional text to provide detailed information.
+    unsigned char reasonCode[21];                                   // Required. A predefined code for the reason why thestatus is returned in this response. The string is case-insensitive.
+    unsigned char additionalInfo[513];                              // Optional. Additional text to provide detailed information.
 };
 /*
  * =============== Message ===============
@@ -5114,11 +5155,11 @@ struct CancelReservation_20
 
 struct CertificateSigned_20
 {
-	unsigned char certificateChain[10001];							// Required. Required. The signed PEM encoded X.509 certificate.This can also contain the necessary sub CA certificates.In that case, the order of the bundle should follow thecertificate chain, starting from the leaf certificate.The Configuration Variable MaxCertificateChainSize canbe used to limit the maximum size of this field.
-	unsigned char certificateType[32];								// Optional. Indicates the type of the signed certificate that is returned.
-	unsigned char Response_status[16];								// Required. Returns whether certificate signing has been accepted, otherwise rejected.
-	struct StatusInfoType Response_statusInfo;						// Optional. Detailed status information.
-	unsigned char guid[37];											// Save guid from server request
+    unsigned char certificateChain[10001];                          // Required. Required. The signed PEM encoded X.509 certificate.This can also contain the necessary sub CA certificates.In that case, the order of the bundle should follow thecertificate chain, starting from the leaf certificate.The Configuration Variable MaxCertificateChainSize canbe used to limit the maximum size of this field.
+    unsigned char certificateType[32];                              // Optional. Indicates the type of the signed certificate that is returned.
+    unsigned char Response_status[16];                              // Required. Returns whether certificate signing has been accepted, otherwise rejected.
+    struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
+    unsigned char guid[37];                                         // Save guid from server request
 };
 
 struct ChangeAvailability_20
@@ -5548,10 +5589,10 @@ struct SetVariables_20
 
 struct SignCertificate_20
 {
-	unsigned char csr[5501];										// Required. The Charging Station SHALL send the public key in form of a Certificate Signing Request (CSR) as described in RFC 2986 [22] using the SignCertificateRequest message.
-	unsigned char certificateType[32];								// Optional. Indicates the type of certificate that is to be signed. When omitted the certificate is to be used for both the 15118 connection (if implemented) and the Charging Station to CSMS connection.
-	unsigned char Response_status[16];								// Required. Specifies whether the CSMS can process the request.
-	struct StatusInfoType Response_statusInfo;						// Optional. Detailed status information.
+    unsigned char csr[5501];                                        // Required. The Charging Station SHALL send the public key in form of a Certificate Signing Request (CSR) as described in RFC 2986 [22] using the SignCertificateRequest message.
+    unsigned char certificateType[32];                              // Optional. Indicates the type of certificate that is to be signed. When omitted the certificate is to be used for both the 15118 connection (if implemented) and the Charging Station to CSMS connection.
+    unsigned char Response_status[16];                              // Required. Specifies whether the CSMS can process the request.
+    struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
 };
 
 struct StatusNotification_20

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

+ 28 - 19
EVSE/Projects/DD360/Apps/Makefile

@@ -76,9 +76,10 @@ MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 	$(CC) $(CFLAGS) -c $<
 
 #internal comm lib
-INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o $(InternalCommLib)/Module_InternalComm.o \
-							$(InternalCommLib)/FanBoard.o $(InternalCommLib)/LEDlight.o $(InternalCommLib)/RelayBoard.o \
-								$(InternalCommLib)/AcPlug.o
+INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o \
+							$(InternalCommLib)/Module_InternalComm.o $(InternalCommLib)/FanBoard.o \
+								$(InternalCommLib)/LEDlight.o $(InternalCommLib)/RelayBoard.o \
+									$(InternalCommLib)/AcPlug.o
 INTERNALCOMM_SRC_FILES = $(patsubst %.o, %.c, $(INTERNALCOMM_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
@@ -91,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
 
@@ -100,12 +107,12 @@ apps: MainTask DoCommTask EvCommTask \
 				FactoryConfigApp OtherTools CleanExec
 
 MainTask:
-	#$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
-	#	$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) -o main
-	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
-	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c
-	$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
+	$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
+		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) -o main
+	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
+	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c
+	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
 
 DoCommTask:
 	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
@@ -113,12 +120,13 @@ DoCommTask:
 	$(CC) -o Module_DoComm DoComm.o define.o
 
 EvCommTask:
-	#$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
-	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
+	$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
+	#$(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
@@ -153,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
 
@@ -182,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)

+ 96 - 84
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");
     }
 }
@@ -439,7 +440,7 @@ static void clearMiscCommand(void)
 
 static int qrCodeUrlInfoHandle(uint8_t *data)
 {
-    int len = 0;
+    //int len = 0;
     //char cmdBuf[128] = {0};
     char localTime[128] = {0};
     uint16_t timeLen = 0;
@@ -466,7 +467,8 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
         memset(ShmSysConfigAndInfo->SysConfig.SystemId, '\0', sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
         //printf("data =  %s\r\n", data);
-        len = string2ByteArray((char *)data, (uint8_t *)ShmSysConfigAndInfo->SysConfig.SystemId);
+        //len =
+        string2ByteArray((char *)data, (uint8_t *)ShmSysConfigAndInfo->SysConfig.SystemId);
         //printf("SystemId =  %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
     }
 
@@ -565,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;
 
@@ -628,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:
@@ -699,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
@@ -711,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
@@ -732,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;
 
@@ -829,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;
@@ -914,7 +916,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
     uint8_t EventCodeTmp[7] = {0};
     uint8_t StatusArray[MAX_REGISTER_NUM][WARNING_CODE_SIZE] = {0};
     uint8_t remaindLen = 0;
-    uint8_t statusCodeError = 0;
+    //uint8_t statusCodeError = 0;
 
     if (dataLen > 0) {
         Hexdump((uint8_t *)data, dataLen);
@@ -1110,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;
@@ -1123,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;
 
@@ -1370,15 +1374,21 @@ 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
-        strcpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, "");
-        strcpy(&vendorErrorCodeTmp[plugNum][0], "");
+        strncpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
+                "",
+                sizeof(ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode));
+
+        strncpy(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE);
     } else if ((ChargingData[plugNum]->SystemStatus <= S_PREPARING_FOR_EVSE) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST0) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST1)) {
@@ -1390,9 +1400,11 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     } else if ((ChargingData[plugNum]->SystemStatus == S_ALARM) ||
                (ChargingData[plugNum]->SystemStatus == S_FAULT)) {
         pConnState->State = CONN_ST_ALARM;
-        strncpy((char *)pConnState->WarningCode, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+        strncpy((char *)pConnState->WarningCode,
+                (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
+                WARNING_CODE_SIZE);
 
-        if (strcmp(&vendorErrorCodeTmp[plugNum][0], "") == 0) {
+        if (strncmp(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE) == 0) {
             strncpy(&vendorErrorCodeTmp[plugNum][0],
                     (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
                     WARNING_CODE_SIZE);
@@ -1687,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;
     }
@@ -1746,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) ||
@@ -1766,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]);
@@ -1983,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;
 
@@ -2219,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];
@@ -2243,7 +2254,8 @@ int main(int argc, char *argv[])
 
 
             if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
-                sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+                sprintf(tmpbuf,
+                        "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
                         ShmSysConfigAndInfo->SysConfig.SystemId);
                 system(tmpbuf);
             }

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

+ 0 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.c → EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvCommOrg.c


+ 73 - 67
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -25,13 +25,14 @@ 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;
 
 //------------------------------------------------------------------------------
 extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
 
 //------------------------------------------------------------------------------
-static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
+/*static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
         uint8_t chillerTemp1, uint8_t chillerTemp2)
 {
     uint8_t i = 0;
@@ -64,6 +65,7 @@ static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
 
     return maxTemp;
 }
+*/
 
 static uint8_t getMaxConnectTemp(uint8_t headTemp1, uint8_t headTemp2)
 {
@@ -98,7 +100,6 @@ static float ReadAdcVolt(uint8_t AdcChannel)
     int fd = -1;
     uint8_t str[64] = {0};
     uint8_t AdcValue[8] = {'\0'};
-    //uint32_t AdcValue = 0;
 
     if (AdcChannel > 7) {
         return -1;
@@ -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,6 +191,11 @@ void CANReceiver(int fd)
 
     canRecPid = fork();
 
+    if (canRecPid < 0) {
+        log_error("Create CAN Bus receive task failed\r\n");
+        return;
+    }
+
     if (canRecPid == 0) {
         int isContinue = 1;
         int nbytes;
@@ -211,6 +219,9 @@ void CANReceiver(int fd)
         ShmGBTData = (struct GBTData *)GetShmGBTData();
         ShmCcsData = (struct CcsData *)GetShmCcsData();
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+        ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
+
+        log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
 
         while (isContinue) {
             memset(&frame, 0, sizeof(struct can_frame));
@@ -249,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;
@@ -268,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]) {
@@ -328,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;
@@ -346,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];
                     }
@@ -448,70 +462,62 @@ void CANReceiver(int fd)
                     //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureN = frame.data[2];
                 }
                 }*/
-#if 1
-                //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->ConnectorTemp = getMaxConnectTempAndChiller(
-                                                         frame.data[1],
-                                                         frame.data[2],
-                                                         chiilerTemp.Temp[0],
-                                                         chiilerTemp.Temp[1]);
-
-                    //log_info("%d chiller Temp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
-                    //         targetGun,
-                    //         chiilerTemp.Temp[0],
-                    //         chiilerTemp.Temp[1],
-                    //         frame.data[1],
-                    //         frame.data[2]);
-                } else if (targetGun == 1 &&
-                           ((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->ConnectorTemp = getMaxConnectTempAndChiller(
-                                                         frame.data[1],
-                                                         frame.data[2],
-                                                         chiilerTemp.Temp[0],
-                                                         chiilerTemp.Temp[1]);
-
-                    //log_info("%d chillerTemp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
-                    //         targetGun,
-                    //         chiilerTemp.Temp[0],
-                    //         chiilerTemp.Temp[1],
-                    //         frame.data[1],
-                    //         frame.data[2]);
-                } else {
-                    pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
-                    //log_info("connector temperature = %d\r\n",
-                    //         pDcChargingInfo->ConnectorTemp);
+                    pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                 }
-#endif //0
-                if (ShmDcCommonData->SystemModeChange == YES) {
+
+                pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
+
+                //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
+                if ((ShmDcCommonData->SystemModeChange == YES) ||
+                        (((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
+                          (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
+                         ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
+                          (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
+                   ) {
                     ShmDcCommonData->SystemModeChange = NO;
-                    //log_info("EvboardStatus = %x \n",
-                    //         ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
-                    //log_info("ConnectorPlug locked = %x \n",
-                    //         frame.data[0]);
-
-                    //if (frame.data[1] >= GUN_OTP_VALUE ||
-                    //        frame.data[2] >= GUN_OTP_VALUE ||
-                    //        chiilerTemp.Temp[0] >= GUN_OTP_VALUE ||
-                    //        chiilerTemp.Temp[1] >= GUN_OTP_VALUE) {
                     log_info("Conn %d Temp 0= %d, Temp 1 = %d, chillerTemp1 = %d, chillerTemp2 = %d\r\n",
                              targetGun,
                              frame.data[1],
                              frame.data[2],
                              chiilerTemp.Temp[0],
                              chiilerTemp.Temp[1]);
-                    //}
-                    //log_info("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
                 }
+
+                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",
+                //         frame.data[0]);
+                //log_info("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
                 break;
 
             case ACK_EVSE_ISOLATION_STATUS:

+ 67 - 55
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
@@ -88,23 +90,17 @@ int InitCanBus(void)
     tv.tv_usec = 10000;
 
     if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct  timeval)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVTIMEO NG");
-#endif
     }
 
     nbytes = 40960;
     if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVBUF NG");
-#endif
     }
 
     nbytes = 40960;
     if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_SNDBUF NG");
-#endif
     }
 
     rxfilter[0].can_id = 0x01;
@@ -115,10 +111,10 @@ int InitCanBus(void)
     rxfilter[2].can_mask = 0x00000FFF;
     if (setsockopt(s0, SOL_CAN_RAW, CAN_RAW_FILTER,
                    &rxfilter, sizeof(struct can_filter) * 3) < 0) {
-        log_error("RX setsockopt CAN_RAW_FILTER failed");
+        log_error("RX setsockopt CAN_RAW_FILTER failed\r\n");
     }
 
-    strcpy(ifr0.ifr_name, "can0" );
+    strcpy(ifr0.ifr_name, "can0");
     ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
     addr0.can_family = AF_CAN;
     addr0.can_ifindex = ifr0.ifr_ifindex;
@@ -482,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) {
@@ -507,6 +503,10 @@ static void checkConnectorOVPState(uint8_t gunIndex)
         break;
     }
 
+    if (ShmDcCommonData->ChillerTempState[gunIndex].StatusBit.ChillerOTP == YES) {
+        isOTP = true;
+    }
+
     if (isOTP) {
         if (gunTempAllowCount[gunIndex] >= 2) {
             pDcChargingInfo->StopChargeFlag = YES;
@@ -574,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};
@@ -597,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();
 
@@ -629,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,
@@ -671,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);
 
@@ -687,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;
@@ -742,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;
@@ -765,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;
 
@@ -829,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) {
@@ -856,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);
                     }
                 }
@@ -909,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) {
@@ -920,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;
@@ -935,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);
@@ -954,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,
@@ -976,8 +990,6 @@ int main(int argc, char *argv[])
                 SetPresentChargingOutputPower();
 
                 if (priorityLow == 1) {
-                    float maxVol, maxCur;
-
                     // 樁端輸出能力
                     maxVol = pDcChargingInfo->MaximumChargingVoltage;
                     maxCur = pDcChargingInfo->AvailableChargingCurrent;

+ 9 - 4
EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c

@@ -112,7 +112,7 @@ static uint8_t getCommTargetID(uint8_t index)
     return targetID;
 }
 
-static void MatchRelayStatus(void)
+/*static void MatchRelayStatus(void)
 {
     // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
     //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
@@ -127,6 +127,7 @@ static void MatchRelayStatus(void)
     regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
     regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
 }
+*/
 
 static bool IsNoneMatchRelayStatus(void)
 {
@@ -368,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;
@@ -498,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) {

+ 235 - 133
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;
+            _chargingData[curGun]->Type = 9;
+            break;
 
-        }
-        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];
@@ -940,26 +957,74 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             }
         }
 
-        if (strcmp(newString[0], "chg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+        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
+               ) {
+                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
                 continue;
             }
-            if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+
+            if (atoi(newString[1]) == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            _Voltage = atof((char *)newString[2]);
+            _Current = atof((char *)newString[3]);
+
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
                 continue;
             }
 
-            float _vol = atof(newString[1]);
-            float _cur = atof(newString[2]);
+            printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+                    ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+                    _Voltage,
+                    _Current);
+
+            if (_Voltage > 1000 || _Voltage < 50) {
+                _Voltage = 200;
+                printf ("Input Voltage over range\n");
+                continue;
+            }
+
+            ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+        } else if (strcmp(newString[0], "chg") == 0) {
+            if (strcmp(newString[1], "-1") == 0) {
+                continue;
+            }
+
+            if (strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0) {
+                continue;
+            }
+
+            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;
         }
@@ -1138,6 +1203,43 @@ int main(void)
                 _chargingData[1]->ConnectorTemp = atoi(newString[2]);
                 printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
             }
+        } else if (strcmp(newString[0], "tempC") == 0) {
+            if (strcmp(newString[1], "0") == 0) {
+                uint8_t _GunIndex = 0;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
+                _chargingData[0]->ChillerTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
+            } else if (strcmp(newString[1], "1") == 0) {
+                uint8_t _GunIndex = 1;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
+                _chargingData[1]->ChillerTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            }
+        } else if (strcmp(newString[0], "TempCR") == 0) {
+            if (strcmp(newString[1], "0") == 0) {
+                uint8_t _GunIndex = 0;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
+            } else if (strcmp(newString[1], "1") == 0) {
+                uint8_t _GunIndex = 1;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
+                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            }
         } else {
             printf ("%s\n", msg);
         }

+ 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

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

@@ -1,15 +1,23 @@
 #/bin/bash
 
+# Absolute path to this script, e.g. /home/user/bin/foo.sh
+SCRIPT=$(readlink -f "$0")
+
+# Absolute path this script is in, thus /home/user/bin
+SCRIPTPATH=$(dirname "$SCRIPT")
+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;
 git add $ProjectPath/DD360ComBox;
+git status;

+ 1 - 1
EVSE/Projects/DD360/Apps/SelectGun/SelectGun.c

@@ -9,7 +9,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../timeout.h"
-#include "../main.h"
+#include "../CSU/main.h"
 
 #include "SelectGun.h"
 

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

+ 119 - 52
EVSE/Projects/DD360/Apps/main.c → EVSE/Projects/DD360/Apps/mainOrg.c

@@ -266,7 +266,7 @@ static void destroySelGun(uint8_t curGun)
 static int waitRightGunPlugIt(uint8_t curGun)
 {
 #if !defined DD360Audi
-    return;
+    return PASS;
 #endif //!defined DD360Audi
 
     if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
@@ -279,7 +279,7 @@ static int waitRightGunPlugIt(uint8_t curGun)
 static int waitLeftGunPlugIt(uint8_t curGun)
 {
 #if !defined DD360Audi
-    return;
+    return PASS;
 #endif //!defined DD360Audi
 
     if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
@@ -309,7 +309,7 @@ static void setSelGunWaitToAuthor(uint8_t curSel)
 static int getConfirmSelectedGun(uint8_t curSel)
 {
 #if !defined DD360Audi
-    return;
+    return PASS;
 #endif //!defined DD360Audi
 
     if (((curSel == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
@@ -343,6 +343,30 @@ static void confirmSelGun(uint8_t selGun)
 
 static void checkGunOTPState(uint8_t _index)
 {
+
+    if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
+            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "V", 1) == 0) ||
+            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "F", 1) == 0) ||
+            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "F", 1) == 0)
+       ) {
+        if (chargingInfo[_index]->ChillerTemp != UNDEFINED_TEMP) {
+            ResetChargerAlarmCode(_index, "011038"); //清除溫度檢測異常status code
+
+            if (chargingInfo[_index]->ChillerTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012323");
+            } else if (chargingInfo[_index]->ChillerTemp != 0 &&
+                       chargingInfo[_index]->ChillerTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012323");
+            }
+
+            //ResetChargerAlarmCode(_index, "011019");
+        } else {
+            // 沒接上 Sensor or 異常
+            RecordAlarmCode(_index, "011038");
+            ResetChargerAlarmCode(_index, "012323");
+        }
+    }
+
     switch (chargingInfo[_index]->Type) {
     case _Type_Chademo:
         if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
@@ -597,22 +621,28 @@ static void checkEvBoardAlarmState(uint8_t gunType)
 
 static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
 {
-    uint8_t ret = NO;
     LedConfig *pLedConfig = (LedConfig *)ledConfig;
 
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
-        ret = YES;
-        if (pLedConfig->RedLED == YES) {
-            pLedConfig->RedLED = NO;
-        } else {
-            pLedConfig->RedLED = YES;
-        }
+    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == NO) {
+        return NO;
+    }
+
+    if (pLedConfig->RedLED == YES ||
+            pLedConfig->YellowLED == YES ||
+            pLedConfig->GreenLED == YES) {
+        pLedConfig->YellowLED = NO;
+        pLedConfig->GreenLED = NO;
+        pLedConfig->RedLED = NO;
+    } else {
+        pLedConfig->YellowLED = YES;
+        pLedConfig->GreenLED = YES;
+        pLedConfig->RedLED = YES;
     }
 
-    return ret;
+    return YES;
 }
 
-static void startPrimaryLedIndicatorCtrlFork(void)
+static void PrimaryLedIndicatorCtrlFork(void)
 {
 #if !defined DD360ComBox
     return;
@@ -625,10 +655,22 @@ static void startPrimaryLedIndicatorCtrlFork(void)
         int isContinue = 1;
         LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
 
+
         while (isContinue) {
             for (gunIndex = 0; gunIndex < totalGun; gunIndex++) {
+                if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 &&
+                        chargingInfo[gunIndex]->SystemStatus != S_BOOTING) {
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        continue;
+                    }
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    pLedConfig->RedLED = YES;
+                    continue;
+                }
+
                 //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
-                //printf("level = %d\r\n", ShmSysConfigAndInfo->SysWarningInfo.Level);
+                //printf("level = %d\r\n", pSysWarning->Level);
                 switch (chargingInfo[gunIndex]->SystemStatus) {
                 case S_BOOTING:
                     if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
@@ -653,10 +695,19 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                     break;
 
                 case S_IDLE:
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
                     //Module_DoComm connected and system idle
                     pLedConfig->RedLED = NO;
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = YES;
+                    //}
                     break;
 
                 case S_RESERVATION:
@@ -668,12 +719,21 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                 case S_PREPARING_FOR_EVSE:
                 case S_CCS_PRECHARGE_ST0:
                 case S_CCS_PRECHARGE_ST1:
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
                     //precharging status
                     if (pLedConfig->GreenLED == YES) {
                         pLedConfig->GreenLED = NO;
                     } else {
                         pLedConfig->GreenLED = YES;
                     }
+                    //}
                     break;
 
                 case S_CHARGING:
@@ -687,44 +747,43 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                     break;
 
                 case S_ALARM:
+                    //if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //    break;
+                    //}
+
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
-
-                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                        break;
-                    }
-
                     pLedConfig->RedLED = YES;
                     break;
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        pLedConfig->YellowLED = NO;
-                        pLedConfig->GreenLED = NO;
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    } else {
-                        pLedConfig->RedLED = NO;
-                        pLedConfig->YellowLED = YES;
-                        pLedConfig->GreenLED = NO;
-                    }
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
+                    pLedConfig->RedLED = NO;
+                    pLedConfig->YellowLED = YES;
+                    pLedConfig->GreenLED = NO;
+                    //}
                     break;
 
                 case S_MAINTAIN:
                 case S_FAULT:
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    //pLedConfig->RedLED = YES;
+                    //}
+
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
-                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    }
+                    pLedConfig->RedLED = YES;
                     break;
 
                 case S_BOOKING:
@@ -732,12 +791,11 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                 case S_UPDATE:
                 case S_NONE:
                     break;
-                }
-
-                usleep(500000);
-            }//switch
-        }//for
-    }//while
+                }//switch
+            }//for
+            usleep(500000);
+        }//while
+    }//fork
 }
 
 //================================================
@@ -2644,6 +2702,8 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
     else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO; }
     else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO; }
     else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO; }
+    else if (strcmp(code, "012323") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChillerOTP = NO; }
+    else if (strcmp(code, "011038") == EQUAL) {  ShmStatusCodeData->FaultCode.FaultEvents.bits.ChillerTempSensorBroken = NO; }
 
     if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
         if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012229", 6) == EQUAL ||
@@ -2657,7 +2717,10 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
                 strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011016", 6) == EQUAL ||
                 strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011018", 6) == EQUAL ||
                 strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011019", 6) == EQUAL ||
-                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL) {
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012323", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011038", 6) == EQUAL
+           ) {
             strncpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
         }
     }
@@ -2698,6 +2761,8 @@ void RecordAlarmCode(uint8_t gunIndex, char *code)
     else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
     else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
     else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
+    else if (strcmp(code, "012323") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChillerOTP = YES; }
+    else if (strcmp(code, "012323") == EQUAL) { ShmStatusCodeData->FaultCode.FaultEvents.bits.ChillerTempSensorBroken = YES; }
 }
 
 void RecordWarningCode(uint8_t gunIndex, char *code)
@@ -3151,7 +3216,9 @@ void ChkPrimaryStatus()
                 if (isDetectPlugin()) {
                     _DetectPlugInTimeout();
                     StopSystemTimeoutDet();
+#if defined DD360Audi
                     destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+#endif //defined DD360Audi
                 }
 #if defined DD360Audi
                 else {
@@ -5895,11 +5962,11 @@ static void ReviewCriticalAlarm(void)
             ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
             ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
             ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES ||
+            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == YES ||
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo
        ) {
         ShmSysConfigAndInfo->SysWarningInfo.Level = 2;
@@ -6029,7 +6096,7 @@ int main(void)
     }
     CreateTimeoutFork();
     log_info("Start self test... \n");
-    startPrimaryLedIndicatorCtrlFork();
+    PrimaryLedIndicatorCtrlFork();
     SelfTestRun();
     StopSystemTimeoutDet();
     log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",

+ 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


+ 35 - 13
EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c

@@ -11,6 +11,18 @@
 #include "../common.h"
 
 //------------------------------------------------------------------------------
+static void InitialDHCP(void)
+{
+    char tmpbuf[256] = {0};
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+    sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+            pSysConfig->SystemId);
+
+    system(tmpbuf);
+}
+
 void GetMacAddress(void)
 {
     uint8_t index = 0;
@@ -70,10 +82,12 @@ static int isRouteFail(void)
 static int isReachableInternet(void)
 {
     int result = FAIL;
+    int idx = 0;
     FILE *fp;
-    char cmd[256];
-    char buf[512];
-    char tmp[512];
+    char cmd[256] = {0};
+    char buf[512] = {0};
+    char tmp[512] = {0};
+    char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
 
@@ -92,6 +106,7 @@ static int isReachableInternet(void)
             }
         }
     }
+
     pclose(fp);
 
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
@@ -100,9 +115,13 @@ static int isReachableInternet(void)
     } else {
         result = PASS;
     }
-#else
+
+    return result;
+#endif //defined DD360 || defined DD360Audi
+
     memset(buf, 0x00, sizeof(buf));
-    for (int idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
+
+    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");
         if (fp != NULL) {
@@ -122,20 +141,18 @@ static int isReachableInternet(void)
         pclose(fp);
     }
 
-#endif //defined DD360 || defined DD360Audi
-
     return result;
 }
 
 void InitEthernet(void)
 {
     char tmpbuf[256];
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
     bool ethResult = false;
     uint8_t cnt_pingDNS_Fail = 0;
-#endif //!defined DD360 && !defined DD360Audi
 
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
 
     system("ifconfig eth0 down");// eth0 down
     system("ifconfig eth1 down");// eth1 down
@@ -144,6 +161,7 @@ void InitEthernet(void)
     // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
     system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
     sleep(2);
+
     //Init Eth0 for internet
     memset(tmpbuf, 0, 256);
     sprintf(tmpbuf, "/sbin/ifconfig eth0 %s netmask %s up",
@@ -159,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",
@@ -186,8 +205,14 @@ 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
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            isReachableInternet();
+            sleep(5);
+            continue;
+#endif //!defined DD360 && !defined DD360
+
             if (isRouteFail()) {
                 //log_info("eth0 not in route, restart eht0. \n");
                 system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
@@ -266,9 +291,6 @@ void InitEthernet(void)
             }
 
             pSysInfo->InternetConn = ethResult;
-#else
-            isReachableInternet();
-#endif //!defined DD360 && !defined DD360
 
             sleep(5);
         }

+ 175 - 32
EVSE/Projects/DD360Audi/Apps/CSU/Primary.c

@@ -9,7 +9,7 @@
 #include "../ShareMemory/shmMem.h"
 
 #include "../SelectGun/SelectGun.h"
-#include "../main.h"
+#include "main.h"
 
 //------------------------------------------------------------------------------
 
@@ -22,10 +22,16 @@ static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
 
     if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
         ret = YES;
-        if (pLedConfig->RedLED == YES) {
+        if (pLedConfig->RedLED == YES ||
+                pLedConfig->YellowLED == YES ||
+                pLedConfig->GreenLED == YES) {
             pLedConfig->RedLED = NO;
+            pLedConfig->YellowLED = NO;
+            pLedConfig->GreenLED = NO;
         } else {
             pLedConfig->RedLED = YES;
+            pLedConfig->YellowLED = YES;
+            pLedConfig->GreenLED = YES;
         }
     }
 
@@ -55,6 +61,19 @@ void PrimaryLedIndicatorCtrlFork(void)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
+                if (pSysWarning->Level == WARN_LV_ER) {
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        usleep(500000);
+                        continue;
+                    }
+
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    pLedConfig->RedLED = YES;
+                    usleep(500000);
+                    continue;
+                }
+
                 //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
                 //printf("level = %d\r\n", pSysWarning->Level);
                 switch (pDcChargingInfo->SystemStatus) {
@@ -127,32 +146,31 @@ void PrimaryLedIndicatorCtrlFork(void)
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    if (pSysWarning->Level == 2) {
-                        pLedConfig->YellowLED = NO;
-                        pLedConfig->GreenLED = NO;
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    } else {
-                        pLedConfig->RedLED = NO;
-                        pLedConfig->YellowLED = YES;
-                        pLedConfig->GreenLED = NO;
-                    }
+                    //if (pSysWarning->Level == WARN_LV_ER) {
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
+                    pLedConfig->RedLED = NO;
+                    pLedConfig->YellowLED = YES;
+                    pLedConfig->GreenLED = NO;
+                    //}
                     break;
 
                 case S_MAINTAIN:
                 case S_FAULT:
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
-                    if (pSysWarning->Level == 2) {
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    }
+                    pLedConfig->RedLED = YES;
+                    //if (pSysWarning->Level == WARN_LV_ER) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->RedLED = YES;
+                    //}
                     break;
 
                 case S_BOOKING:
@@ -160,65 +178,187 @@ void PrimaryLedIndicatorCtrlFork(void)
                 case S_UPDATE:
                 case S_NONE:
                     break;
-                }
-
-                usleep(500000);
-            }//switch
-        }//for
-    }//while
+                }//switch
+            }//for
+            usleep(500000);
+        }//while
+    }//fork
 }
 
 //------------------------------------------------------------------------------
+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;
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042252", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = YES;
                 EmcOccureByString("042252");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042200", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = YES;
                 EmcOccureByString("042200");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042201", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = YES;
                 EmcOccureByString("042201");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042202", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = YES;
                 EmcOccureByString("042202");
                 Rtn = 1;
+            } else if (memcmp(&pSysWarning->WarningCode[i][0], "042267", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = YES;
+                EmcOccureByString("042267");
+                Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
                 EmcOccureByString("012304");
                 Rtn = 1;
             }
         }
+
         if (Rtn == 0) {
+            ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
             ReleaseEmsOccureByString(0, "042251");
             ReleaseEmsOccureByString(0, "042252");
             ReleaseEmsOccureByString(0, "042200");
             ReleaseEmsOccureByString(0, "042201");
             ReleaseEmsOccureByString(0, "042202");
+            ReleaseEmsOccureByString(0, "042267");
             ReleaseEmsOccureByString(0, "012304");
         }
     } else {
+        ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
         ReleaseEmsOccureByString(0, "042251");
         ReleaseEmsOccureByString(0, "042252");
         ReleaseEmsOccureByString(0, "042200");
         ReleaseEmsOccureByString(0, "042201");
         ReleaseEmsOccureByString(0, "042202");
+        ReleaseEmsOccureByString(0, "042267");
         ReleaseEmsOccureByString(0, "012304");
     }
 
@@ -272,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);
 
@@ -305,7 +448,6 @@ void ChkPrimaryStatus(void)
                     break;
                 }
             }
-
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
                 if (isDetectPlugin()) {
@@ -356,6 +498,7 @@ void ChkPrimaryStatus(void)
                 //pDcChargingInfo->SystemStatus = S_IDLE;
                 break;
             }
+#endif //0
         }
     } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
         if (leftBtnPush) {

+ 273 - 235
EVSE/Projects/DD360Audi/Apps/CSU/RFID.c

@@ -9,7 +9,7 @@
 #include "../ShareMemory/shmMem.h"
 #include "../SelectGun/SelectGun.h"
 
-#include "../main.h"
+#include "main.h"
 #include "../timeout.h"
 
 //------------------------------------------------------------------------------
@@ -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);
         }
     }
 }

+ 144 - 136
EVSE/Projects/DD360Audi/Apps/CSU/SelfTest.c

@@ -8,7 +8,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 
-#include "../main.h"
+#include "main.h"
 #include "../timeout.h"
 
 //------------------------------------------------------------------------------
@@ -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;
         }
 

+ 7 - 10
EVSE/Projects/DD360Audi/Apps/CSU/UpgradeFW.c

@@ -11,7 +11,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 
-#include "../main.h"
+#include "main.h"
 
 //------------------------------------------------------------------------------
 static char *_priPortName = "/dev/ttyS1";
@@ -25,16 +25,19 @@ 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);
     }
 
     if (fd <= 0) {
-#ifdef SystemLogMessage
         log_error("open 407 Communication port NG \n");
-#endif
         return -1;
     }
+
     ioctl (fd, TCGETS, &tios);
     tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
     tios.c_lflag = 0;
@@ -66,21 +69,15 @@ static int InitCanBus(void)
     tv.tv_sec = 0;
     tv.tv_usec = 10000;
     if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct  timeval)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVTIMEO NG");
-#endif
     }
     nbytes = 40960;
     if (setsockopt(fd, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVBUF NG");
-#endif
     }
     nbytes = 40960;
     if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_SNDBUF NG");
-#endif
     }
 
     strcpy(ifr0.ifr_name, "can0");

Разница между файлами не показана из-за своего большого размера
+ 421 - 171
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)

+ 40 - 3
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 {
@@ -310,6 +316,34 @@ typedef union {
     } GunBits;
 } EvBoardErrMsg;
 
+typedef union {
+    uint8_t AlarmState;
+    struct {
+        uint8_t EmergencyStop: 1;    //Power cabinet emergency stop
+        uint8_t DoorOpen: 1;         //Power cabinet emergency door open
+        uint8_t SystemL1InputOVP: 1; //Power cabinet system L1 input OVP
+        uint8_t SystemL2InputOVP: 1; //Power cabinet System L2 input OVP
+        uint8_t SystemL3InputOVP: 1; //Power cabinet System L3 input OVP
+        uint8_t PsuFailure: 1;       //Power cabinet PSU Failure Alarm
+        uint8_t Reserved: 2;
+    } StatusBit;
+} PowerAlarmState;
+
+typedef union {
+    uint8_t ChillerState;
+    struct {
+        uint8_t ChillerOTP: 1;            //chiller Temperature OVP
+        uint8_t ChillerTempSensorFail: 1; //Chiller temperature sensor failure
+        uint8_t Reserved: 6;
+    } 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;
@@ -318,6 +352,9 @@ typedef struct StDcCommonInfo {
     uint8_t GunRelayWeldingOccur[2];
     uint8_t GunRelayDrivingOccur[2];
     uint8_t SystemModeChange;
+    PowerAlarmState PowerAlarmState;
+    ChillerTempState ChillerTempState[2];
+    ChillerValve ChillerValve;
     uint8_t Reserved[3];
 } DcCommonInfo;
 

+ 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後再通知小板進入充電狀態。

+ 5 - 5
EVSE/Projects/DD360Audi/Apps/Define/define.c

@@ -102,7 +102,7 @@ char FaultStatusCode[40][6]=
 "011035", //Ble module broken
 "011036", //Rotary switch fault
 "011037", //CCS liquid chiller water level fault
-"011038", //Reserved
+"011038", //Chiller temperature sensor broken
 "011039", //Reserved
 "011040" //Reserved
 };
@@ -229,10 +229,10 @@ char AlarmStatusCode[128][6]=
 "012317", // Psu Dcdc Eeprom Fault
 "012318", // Psu Pfc Eeprom Fault
 "012319", // Psu Dcdc Over Voltage
-"012320", // reserved
-"012321", // reserved
-"012322", // reserved
-"012323", // reserved
+"012320", // System CHAdeMO output UCP
+"012321", // System CCS output UCP
+"012322", // System GBT output UCP
+"012323", // System Chiller output OTP
 "012324", // reserved
 "012325", // reserved
 "012326", // reserved

+ 206 - 165
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -169,6 +169,10 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #define ShmOcpp20ModuleKey		1012
 #define ShmRelay2BdKey			1013
 
+#define FaultCodeLength         5
+#define AlarmCodeLength         16
+#define InfoCodeLength          41
+
 /**************************************************************************************/
 /****************** Share memory configuration value constant define ******************/
 /**************************************************************************************/
@@ -289,7 +293,7 @@ enum CoreProfile {
      DefaultPrice,
      CustomDisplayCostAndPrice,
      CustomIdleFeeAfterStop,
-	 ConfigurationVersion,
+     ConfigurationVersion,
 	 _CoreProfile_CNT
 };
 
@@ -401,10 +405,19 @@ typedef union
         unsigned int NormalStop:1;                  // 0: no effect,    1: normal stop
         unsigned int AlarmStop:1;                   // 0: no effect,    1: alarm stop
         unsigned int BackendStop:1;                 // 0: no effect,    1: backend stop
-        unsigned int res:29;
+        unsigned int ManualStop:1;                  // 0: no effect,    1: manual stop
+        unsigned int res:28;
     }bits;
 }ChargingStop;
 
+typedef struct
+{
+    unsigned char DispenserSequence;                    // dispenser sequence
+    unsigned char MaxConnectorQuantity;                 // max connector quantity
+    unsigned char WiringSetting[8];                     // record connector quantity of dispenser
+    unsigned char PowerCabinetReserved[32];
+}WiringInfoData;
+
 struct SysConfigData
 {
 	/**************System***************/
@@ -465,7 +478,10 @@ struct SysConfigData
 	unsigned char			ShowInformation;
 	unsigned char           isReqFirstUpgrade;          //EVSE is request first upgrade from PH server
 	unsigned char           isEnableLocalPowerSharging; //0: Disable power sharing  1: Enable power sharing
-	unsigned char			StopChargingByButton;		//0: Disable  1: Enable
+	unsigned char           StopChargingByButton;       //0: Disable  1: Enable
+
+    /************PowerCabinet************/
+    WiringInfoData          WiringInfo;
 };
 
 struct ChargingInfoData
@@ -510,6 +526,8 @@ struct ChargingInfoData
 	float					ChargingFee;
 	// Connector Temp
 	unsigned char 		ConnectorTemp;			//0x00: -60¢XC  ~  0xFE: 194
+	//Chiller Temp
+    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;
@@ -552,6 +570,10 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
+	char 				ReservedStartFlag;
+	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
+	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
+	unsigned char 		ModelType;
 };
 
 typedef union
@@ -580,7 +602,9 @@ typedef union
         unsigned int EthernetStatusRequest:1;           // 0: no request,   1: ethernet connection status has changed           ( cabinet -> dispenser)
         unsigned int WiFiStatusRequest:1;               // 0: no request,   1: wifi connection status has changed               ( cabinet -> dispenser)
         unsigned int TelcomModemStatusRequest:1;        // 0: no request,   1: 4g connection status has changed                 ( cabinet -> dispenser)
-        unsigned int res:11;
+        unsigned int BillingStatusRequest:1;            // 0: no request,   1: billing status has changed                       ( cabinet -> dispenser)
+        unsigned int StopButtonStatusRequest:1;         // 0: no request,   1: stop charging button status has changed          ( cabinet -> dispenser)
+        unsigned int res:9;
     }bits;
 }DispenserSettingFlag;
 
@@ -636,10 +660,13 @@ struct ConnectionInfoData
 
 struct DispenserInfoData
 {
-    unsigned char               DispenserQuantity;
-    unsigned char               TotalConnectorQuantity;
+    unsigned char               DispenserQuantity;                  // record max dispenser quantity
+    unsigned char               TotalConnectorQuantity;             // record max connector quantity
     struct DispenserModule      Dispenser[GENERAL_GUN_QUANTITY];
 
+    unsigned char               PresentDispenserQuantity;
+    unsigned char               PresentConnectorQuantity;
+
     union
     {
         unsigned char Status;
@@ -747,7 +774,10 @@ typedef union
         unsigned int AuthorizingCompleted:1;    // 0: not yet, 1: authorizing completed
         unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
         unsigned int BackendAuthorized:1;       // 0: local authorized, 1: backend authorized
-        unsigned int res:28;
+        unsigned int WiringInfoChanged:1;       // 0: no effect, 1: wiring info has changed
+        unsigned int EnableWriteWiringInfo:1;   // 0: no effect, 1: enable write wiring info after timeout
+        unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
+        unsigned int res:25;
     }bits;
 }CabinetSettingFlag;
 
@@ -760,6 +790,8 @@ typedef struct
     unsigned int EthernetStatus;                // 0: disable, 1: connected, 2: disconnected
     unsigned int WiFiStatus;                    // 0: disable, 1: connected, 2: disconnected
     unsigned int TelcomModemStatus;             // 0: disable, 1: connected, 2: disconnected
+    unsigned int BillingStatus;                 // 0: disable, 1: enable
+    unsigned int StopChargingButton;            // 0: disable, 1: enable
     unsigned int HardwareReboot;                // 1: HardwareReboot, Other value: no effect
     unsigned int SoftwareRestart;               // 1: SoftwareRestart, Other value: no effect
 }CabinetMiscCommand;
@@ -978,7 +1010,7 @@ char FaultStatusCode[40][6]=
 	"011035",	//Ble module broken
 	"011036",	//Rotary switch fault
 	"011037",	//CCS liquid chiller water level fault
-	"011038",	//Reserved
+	"011038",	//Chiller temperature sensor broken
 	"011039",	//Reserved
 	"011040"	//Reserved
 };
@@ -986,10 +1018,10 @@ char FaultStatusCode[40][6]=
 
 struct FaultCodeData
 {
-	unsigned char PreviousFaultVal[5];
+	unsigned char PreviousFaultVal[FaultCodeLength];
 	union
 	{
-		unsigned char FaultVal[5];
+		unsigned char FaultVal[FaultCodeLength];
 		struct
 		{
 			//FaultVal[0]
@@ -1034,7 +1066,8 @@ struct FaultCodeData
 			unsigned char BleModuleBroken:1;					//bit 2
 			unsigned char RotarySwitchFault:1;					//bit 3 
 			unsigned char CcsLiquidChillerWaterLevelFault:1;    //bit 4
-			unsigned char :3;									//bit 5 ~ 7	reserved
+			unsigned char ChillerTempSensorBroken:1;            //bit 5
+			unsigned char :2;									//bit 6 ~ 7	reserved
 		}bits;
 	}FaultEvents;
 };
@@ -1162,10 +1195,10 @@ char AlarmStatusCode[128][6]=
     "012317",   // Psu Dcdc Eeprom Fault
     "012318",   // Psu Pfc Eeprom Fault
     "012319",   // Psu Dcdc Over Voltage
-    "012320",   // reserved
-    "012321",   // reserved
-    "012322",   // reserved
-    "012323",   // reserved
+    "012320",   // System CHAdeMO output UCP
+    "012321",   // System CCS output UCP
+    "012322",   // System GBT output UCP
+    "012323",   // System Chiller output OTP
     "012324",   // reserved
     "012325",   // reserved
     "012326",   // reserved
@@ -1174,10 +1207,10 @@ char AlarmStatusCode[128][6]=
 */
 struct AlarmCodeData
 {
-	unsigned char PreviousAlarmVal[16];
+	unsigned char PreviousAlarmVal[AlarmCodeLength];
 	union
 	{
-		unsigned char AlarmVal[16];
+		unsigned char AlarmVal[AlarmCodeLength];
 		struct
 		{
 			//AlarmVal[0]
@@ -1316,7 +1349,11 @@ struct AlarmCodeData
             unsigned char PsuPfcEepromFault:1;                      //bit 6
             unsigned char PsuDcdcOverVoltage:1;                     //bit 7
             //AlarmVal[15]
-            unsigned char Reserved:8;                               //bit 0~7
+            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;
 	}AlarmEvents;
 };
@@ -1658,10 +1695,10 @@ char InfoStatusCode[384][6]=
 */
 struct InfoCodeData
 {
-	unsigned char PreviousInfoVal[41];
+	unsigned char PreviousInfoVal[InfoCodeLength];
 	union
 	{
-		unsigned char InfoVal[41];
+		unsigned char InfoVal[InfoCodeLength];
 		struct
 		{
 			//InfoVal[0]
@@ -2083,6 +2120,10 @@ struct PsuGroupData
 	unsigned int            GroupPresentOutputPower;        //Watt
 	struct PsuModuleData 	PsuModule[MAX_PSU_QUANTITY];
 	PsuGroupError           GroupErrorFlag;
+    unsigned short          TotalIAvailableCurrent;         // unit: 0.1A
+    unsigned short          TempIAvailableCurrent;          // unit: 0.1A
+    unsigned short          StableIAvailableCurrent;        // unit: 0.1A
+    unsigned short          StableCurrentCounter;           // stable current counter
 };
 
 /*Following is the information for system all PSU*/
@@ -4230,104 +4271,104 @@ struct StructCost
 
 struct CertificateHashDataType
 {
-	unsigned char hashAlgorithm[8];								// Required. Used algorithms for the hashes provided.
-	unsigned char issuerNameHash[129];							// Required. hashed value of the IssuerName.
-	unsigned char issuerKeyHash[129];							// Required. Hashed value of the issuers public key
-	unsigned char serialNumber[41];								// Required. The serial number of the certificate.
+    unsigned char hashAlgorithm[8];                             // Required. Used algorithms for the hashes provided.
+    unsigned char issuerNameHash[129];                          // Required. hashed value of the IssuerName.
+    unsigned char issuerKeyHash[129];                           // Required. Hashed value of the issuers public key
+    unsigned char serialNumber[41];                             // Required. The serial number of the certificate.
 };
 
 struct LogParametersType
 {
-	unsigned char remoteLocation[513];								// Required. The URL of the location at the remote system where the log should be stored.
-	unsigned char oldestTimestamp[36];								// Optional. This contains the date and time of the oldest logging information to include in the diagnostics.
-	unsigned char latestTimestamp[36];								// Optional. This contains the date and time of the latest logging information to include in the diagnostics.
+    unsigned char remoteLocation[513];                              // Required. The URL of the location at the remote system where the log should be stored.
+    unsigned char oldestTimestamp[36];                              // Optional. This contains the date and time of the oldest logging information to include in the diagnostics.
+    unsigned char latestTimestamp[36];                              // Optional. This contains the date and time of the latest logging information to include in the diagnostics.
 };
 
 struct FirmwareType
 {
-	unsigned char location[513];									// Required. URI defining the origin of the firmware.
-	unsigned char retrieveDateTime[36];								// Required. Date and time at which the firmware shall be retrieved.
-	unsigned char installDateTime[36];								// Optional. Date and time at which the firmware shall be installed.
-	unsigned char signingCertificate[5501];							// Optional. Certificate with which the firmware was signed. X.509 certificate, first DER encoded into binary, and then Base64 encoded.
-	unsigned char signature[801];									// Optional. Base64 encoded firmware signature.
+    unsigned char location[513];                                    // Required. URI defining the origin of the firmware.
+    unsigned char retrieveDateTime[36];                             // Required. Date and time at which the firmware shall be retrieved.
+    unsigned char installDateTime[36];                              // Optional. Date and time at which the firmware shall be installed.
+    unsigned char signingCertificate[5501];                         // Optional. Certificate with which the firmware was signed. X.509 certificate, first DER encoded into binary, and then Base64 encoded.
+    unsigned char signature[801];                                   // Optional. Base64 encoded firmware signature.
 };
 
 struct StructCertificateSigned
 {
-	unsigned char certificateChain[10001];
-	unsigned char Response_status[16];
+    unsigned char certificateChain[10001];
+    unsigned char Response_status[16];
 };
 
 struct StructDeleteCertificate
 {
-	struct CertificateHashDataType certificateHashData;
-	unsigned char Response_status[16];
+    struct CertificateHashDataType certificateHashData;
+    unsigned char Response_status[16];
 };
 
 struct StructExtendedTrigger
 {
-	unsigned char requestedMessage[32];
-	int connectorId;
-	unsigned char Response_status[16];
+    unsigned char requestedMessage[32];
+    int connectorId;
+    unsigned char Response_status[16];
 };
 
 struct StructGetInstalledCertificateIds
 {
-	unsigned char certificateType[32];
-	unsigned char Response_status[16];
-	struct CertificateHashDataType Response_certificateHashData[3];
+    unsigned char certificateType[32];
+    unsigned char Response_status[16];
+    struct CertificateHashDataType Response_certificateHashData[3];
 };
 
 struct StructGetLog
 {
-	unsigned char logType[16];
-	int requestId;
-	int retries;
-	int retryInterval;
-	struct LogParametersType log;
-	unsigned char Response_status[16];
-	unsigned char Response_filename[256];
+    unsigned char logType[16];
+    int requestId;
+    int retries;
+    int retryInterval;
+    struct LogParametersType log;
+    unsigned char Response_status[16];
+    unsigned char Response_filename[256];
 };
 
 struct StructInstallCertificate
 {
-	unsigned char certificateType[32];
-	unsigned char certificate[5501];
-	unsigned char Response_status[16];
+    unsigned char certificateType[32];
+    unsigned char certificate[5501];
+    unsigned char Response_status[16];
 };
 
 struct StructSignedUpdateFirmware
 {
-	int retries;
-	int retryInterval;
-	int requestId;
-	struct FirmwareType firmware;
-	unsigned char Response_status[16];
+    int retries;
+    int retryInterval;
+    int requestId;
+    struct FirmwareType firmware;
+    unsigned char Response_status[16];
 };
 
 struct StructLogStatusNotification
 {
-	unsigned char status[32];
-	int requestId;
+    unsigned char status[32];
+    int requestId;
 };
 
 struct StructSecurityEventNotification
 {
-	unsigned char type[51];
-	unsigned char timestamp[28];
-	unsigned char techInfo[256];
+    unsigned char type[51];
+    unsigned char timestamp[28];
+    unsigned char techInfo[256];
 };
 
 struct StructSignCertificate
 {
-	unsigned char csr[5501];
-	unsigned char Response_status[16];
+    unsigned char csr[5501];
+    unsigned char Response_status[16];
 };
 
 struct StructSignedFirmwareStatusNotification
 {
-	unsigned char status[32];
-	int requestId;
+    unsigned char status[32];
+    int requestId;
 };
 
 struct OCPP16Data
@@ -4362,23 +4403,23 @@ struct OCPP16Data
         struct
         {
             //SpMsgValue[0]
-            unsigned char BootNotificationReq :1;               	//bit 0,
-            unsigned char BootNotificationConf :1;              	//bit 1,
-            unsigned char AuthorizeReq :1;                      	//bit 2,
-            unsigned char AuthorizeConf :1;                     	//bit 3,
-            unsigned char DiagnosticsStatusNotificationReq :1;  	//bit 4,
-            unsigned char DiagnosticsStatusNotificationConf :1; 	//bit 5,
-            unsigned char FirmwareStatusNotificationReq :1;     	//bit 6,
-            unsigned char FirmwareStatusNotificationConf :1;   	 	//bit 7,
+            unsigned char BootNotificationReq :1;                   //bit 0,
+            unsigned char BootNotificationConf :1;                  //bit 1,
+            unsigned char AuthorizeReq :1;                          //bit 2,
+            unsigned char AuthorizeConf :1;                         //bit 3,
+            unsigned char DiagnosticsStatusNotificationReq :1;      //bit 4,
+            unsigned char DiagnosticsStatusNotificationConf :1;     //bit 5,
+            unsigned char FirmwareStatusNotificationReq :1;         //bit 6,
+            unsigned char FirmwareStatusNotificationConf :1;        //bit 7,
             //SpMsgValue[1]
             unsigned char LogStatusNotificationReq :1;              //bit 0,
-			unsigned char LogStatusNotificationConf :1;             //bit 1,
-			unsigned char SecurityEventNotificationReq :1;          //bit 2,
-			unsigned char SecurityEventNotificationConf :1;         //bit 3,
-			unsigned char SignCertificateReq :1;  					//bit 4,
-			unsigned char SignCertificateConf :1; 					//bit 5,
-			unsigned char SignedFirmwareStatusNotificationReq :1;   //bit 6,
-			unsigned char SignedFirmwareStatusNotificationConf :1;	//bit 7,
+            unsigned char LogStatusNotificationConf :1;             //bit 1,
+            unsigned char SecurityEventNotificationReq :1;          //bit 2,
+            unsigned char SecurityEventNotificationConf :1;         //bit 3,
+            unsigned char SignCertificateReq :1;                    //bit 4,
+            unsigned char SignCertificateConf :1;                   //bit 5,
+            unsigned char SignedFirmwareStatusNotificationReq :1;   //bit 6,
+            unsigned char SignedFirmwareStatusNotificationConf :1;  //bit 7,
         } bits;
     } SpMsg;
 
@@ -4424,40 +4465,40 @@ struct OCPP16Data
         struct
         {
             //CsMsgValue[0]
-            unsigned char ChangeConfigurationReq :1;    			//bit 0,
-            unsigned char ChangeConfigurationConf :1;   			//bit 1,
-            unsigned char ClearCacheReq :1;             			//bit 2,
-            unsigned char ClearCacheConf :1;            			//bit 3,
-            unsigned char GetConfigurationReq :1;       			//bit 4,
-            unsigned char GetConfigurationConf :1;      			//bit 5,
-            unsigned char UpdateFirmwareReq :1;         			//bit 6,
-            unsigned char UpdateFirmwareConf :1;        			//bit 7,
+            unsigned char ChangeConfigurationReq :1;                //bit 0,
+            unsigned char ChangeConfigurationConf :1;               //bit 1,
+            unsigned char ClearCacheReq :1;                         //bit 2,
+            unsigned char ClearCacheConf :1;                        //bit 3,
+            unsigned char GetConfigurationReq :1;                   //bit 4,
+            unsigned char GetConfigurationConf :1;                  //bit 5,
+            unsigned char UpdateFirmwareReq :1;                     //bit 6,
+            unsigned char UpdateFirmwareConf :1;                    //bit 7,
             //CsMsgValue[1]
-            unsigned char GetDiagnosticsReq :1;         			//bit 0,
-            unsigned char GetDiagnosticsConf :1;        			//bit 1,
-            unsigned char GetLocalListVersionReq :1;   				//bit 2,
-            unsigned char GetLocalListVersionConf :1;   			//bit 3,
-            unsigned char ResetReq :1;                  			//bit 4,
-            unsigned char ResetConf :1;                 			//bit 5,
-            unsigned char SendLocalListReq :1;         				//bit 6,
-            unsigned char SendLocalListConf :1;         			//bit 7,
+            unsigned char GetDiagnosticsReq :1;                     //bit 0,
+            unsigned char GetDiagnosticsConf :1;                    //bit 1,
+            unsigned char GetLocalListVersionReq :1;                //bit 2,
+            unsigned char GetLocalListVersionConf :1;               //bit 3,
+            unsigned char ResetReq :1;                              //bit 4,
+            unsigned char ResetConf :1;                             //bit 5,
+            unsigned char SendLocalListReq :1;                      //bit 6,
+            unsigned char SendLocalListConf :1;                     //bit 7,
             //CsMsgValue[2]
-            unsigned char CertificateSignedReq :1;					//bit 0
-            unsigned char CertificateSignedConf :1;					//bit 1
-            unsigned char DeleteCertificateReq :1;					//bit 2
-            unsigned char DeleteCertificateConf :1;					//bit 3
-            unsigned char ExtendedTriggerMessageReq :1;				//bit 4
-            unsigned char ExtendedTriggerMessageConf :1;			//bit 5
-            unsigned char GetInstalledCertificateIdsReq :1;			//bit 6
-            unsigned char GetInstalledCertificateIdsConf :1;		//bit 7
+            unsigned char CertificateSignedReq :1;                  //bit 0
+            unsigned char CertificateSignedConf :1;                 //bit 1
+            unsigned char DeleteCertificateReq :1;                  //bit 2
+            unsigned char DeleteCertificateConf :1;                 //bit 3
+            unsigned char ExtendedTriggerMessageReq :1;             //bit 4
+            unsigned char ExtendedTriggerMessageConf :1;            //bit 5
+            unsigned char GetInstalledCertificateIdsReq :1;         //bit 6
+            unsigned char GetInstalledCertificateIdsConf :1;        //bit 7
             //CsMsgValue[3]
-            unsigned char GetLogReq :1;								//bit 0
-            unsigned char GetLogConf :1;							//bit 1
-            unsigned char InstallCertificateReq :1;					//bit 2
-            unsigned char InstallCertificateConf :1;				//bit 3
-            unsigned char SignedUpdateFirmwareReq :1;				//bit 4
-            unsigned char SignedUpdateFirmwareConf :1;				//bit 5
-            unsigned char :2;										//bit 6 & 7
+            unsigned char GetLogReq :1;                             //bit 0
+            unsigned char GetLogConf :1;                            //bit 1
+            unsigned char InstallCertificateReq :1;                 //bit 2
+            unsigned char InstallCertificateConf :1;                //bit 3
+            unsigned char SignedUpdateFirmwareReq :1;               //bit 4
+            unsigned char SignedUpdateFirmwareConf :1;              //bit 5
+            unsigned char :2;                                       //bit 6 & 7
         } bits;
     } MsMsg;
 
@@ -4474,48 +4515,48 @@ struct OCPP16Data
         } bits[CONNECTOR_QUANTITY];
     }CSUMsg;
 
-    struct StructBootNotification               	BootNotification;
-    struct StructHeartbeat                     	 	Heartbeat;
-    struct StructAuthorize                      	Authorize;
-    struct StructStartTransaction               	StartTransaction[CONNECTOR_QUANTITY];
-    struct StructStopTransaction                	StopTransaction[CONNECTOR_QUANTITY];
-    struct StructStatusNotification             	StatusNotification[CONNECTOR_QUANTITY];
-    struct StructCancelReservation              	CancelReservation[CONNECTOR_QUANTITY];
-    struct StructChangeAvailability             	ChangeAvailability[CONNECTOR_QUANTITY];
-    struct StructChangeConfiguration            	ChangeConfiguration;
-    struct StructClearCache                     	ClearCache;
-    struct StructClearChargingProfile           	ClearChargingProfile[CONNECTOR_QUANTITY];
-    struct StructDataTransfer                   	DataTransfer[CONNECTOR_QUANTITY];
-    struct StructDiagnosticsStatusNotification  	DiagnosticsStatusNotification;
-    struct StructFirmwareStatusNotification     	FirmwareStatusNotification;
-    struct StructGetCompositeSchedule           	GetCompositeSchedule[CONNECTOR_QUANTITY];
-    struct StructGetConfiguration               	GetConfiguration;
-    struct StructGetDiagnostics                 	GetDiagnostics;
-    struct StructGetLocalListVersion            	GetLocalListVersion;
-    struct StructMeterValues                    	MeterValues[CONNECTOR_QUANTITY];
-    struct StructRemoteStartTransaction         	RemoteStartTransaction[CONNECTOR_QUANTITY];
-    struct StructRemoteStopTransaction          	RemoteStopTransaction[CONNECTOR_QUANTITY];
-    struct StructReserveNow                     	ReserveNow[CONNECTOR_QUANTITY];
-    struct StructReset                          	Reset;
-    struct StructSendLocalList                  	SendLocalList;
-    struct StructSetChargingProfile            		SetChargingProfile[CONNECTOR_QUANTITY];
-    struct StructTriggerMessage                 	TriggerMessage[CONNECTOR_QUANTITY];
-    struct StructUnlockConnector                	UnlockConnector[CONNECTOR_QUANTITY];
-    struct StructUpdateFirmware                 	UpdateFirmware;
-    struct OCPP16ConfigurationTable             	ConfigurationTable;
-    struct StructChargingProfile                	SmartChargingProfile[CONNECTOR_QUANTITY];
-    struct StructCost                           	Cost;
-    struct StructCertificateSigned					CertificateSigned;
-    struct StructDeleteCertificate					DeleteCertificate;
-    struct StructExtendedTrigger					ExtendedTriggerMessage;
-    struct StructGetInstalledCertificateIds			GetInstalledCertificateIds;
-    struct StructGetLog								GetLog;
-    struct StructInstallCertificate					InstallCertificate;
-    struct StructSignedUpdateFirmware				SignedUpdateFirmware;
-    struct StructLogStatusNotification				LogStatusNotification;
-    struct StructSecurityEventNotification			SecurityEventNotification;
-    struct StructSignCertificate					SignCertificate;
-    struct StructSignedFirmwareStatusNotification 	SignedFirmwareStatusNotification;
+    struct StructBootNotification                   BootNotification;
+    struct StructHeartbeat                          Heartbeat;
+    struct StructAuthorize                          Authorize;
+    struct StructStartTransaction                   StartTransaction[CONNECTOR_QUANTITY];
+    struct StructStopTransaction                    StopTransaction[CONNECTOR_QUANTITY];
+    struct StructStatusNotification                 StatusNotification[CONNECTOR_QUANTITY];
+    struct StructCancelReservation                  CancelReservation[CONNECTOR_QUANTITY];
+    struct StructChangeAvailability                 ChangeAvailability[CONNECTOR_QUANTITY];
+    struct StructChangeConfiguration                ChangeConfiguration;
+    struct StructClearCache                         ClearCache;
+    struct StructClearChargingProfile               ClearChargingProfile[CONNECTOR_QUANTITY];
+    struct StructDataTransfer                       DataTransfer[CONNECTOR_QUANTITY];
+    struct StructDiagnosticsStatusNotification      DiagnosticsStatusNotification;
+    struct StructFirmwareStatusNotification         FirmwareStatusNotification;
+    struct StructGetCompositeSchedule               GetCompositeSchedule[CONNECTOR_QUANTITY];
+    struct StructGetConfiguration                   GetConfiguration;
+    struct StructGetDiagnostics                     GetDiagnostics;
+    struct StructGetLocalListVersion                GetLocalListVersion;
+    struct StructMeterValues                        MeterValues[CONNECTOR_QUANTITY];
+    struct StructRemoteStartTransaction             RemoteStartTransaction[CONNECTOR_QUANTITY];
+    struct StructRemoteStopTransaction              RemoteStopTransaction[CONNECTOR_QUANTITY];
+    struct StructReserveNow                         ReserveNow[CONNECTOR_QUANTITY];
+    struct StructReset                              Reset;
+    struct StructSendLocalList                      SendLocalList;
+    struct StructSetChargingProfile                 SetChargingProfile[CONNECTOR_QUANTITY];
+    struct StructTriggerMessage                     TriggerMessage[CONNECTOR_QUANTITY];
+    struct StructUnlockConnector                    UnlockConnector[CONNECTOR_QUANTITY];
+    struct StructUpdateFirmware                     UpdateFirmware;
+    struct OCPP16ConfigurationTable                 ConfigurationTable;
+    struct StructChargingProfile                    SmartChargingProfile[CONNECTOR_QUANTITY];
+    struct StructCost                               Cost;
+    struct StructCertificateSigned                  CertificateSigned;
+    struct StructDeleteCertificate                  DeleteCertificate;
+    struct StructExtendedTrigger                    ExtendedTriggerMessage;
+    struct StructGetInstalledCertificateIds         GetInstalledCertificateIds;
+    struct StructGetLog                             GetLog;
+    struct StructInstallCertificate                 InstallCertificate;
+    struct StructSignedUpdateFirmware               SignedUpdateFirmware;
+    struct StructLogStatusNotification              LogStatusNotification;
+    struct StructSecurityEventNotification          SecurityEventNotification;
+    struct StructSignCertificate                    SignCertificate;
+    struct StructSignedFirmwareStatusNotification   SignedFirmwareStatusNotification;
 };
 
 
@@ -5082,8 +5123,8 @@ struct TransactionType
 
 struct StatusInfoType
 {
-	unsigned char reasonCode[21];									// Required. A predefined code for the reason why thestatus is returned in this response. The string is case-insensitive.
-	unsigned char additionalInfo[513];								// Optional. Additional text to provide detailed information.
+    unsigned char reasonCode[21];                                   // Required. A predefined code for the reason why thestatus is returned in this response. The string is case-insensitive.
+    unsigned char additionalInfo[513];                              // Optional. Additional text to provide detailed information.
 };
 /*
  * =============== Message ===============
@@ -5114,11 +5155,11 @@ struct CancelReservation_20
 
 struct CertificateSigned_20
 {
-	unsigned char certificateChain[10001];							// Required. Required. The signed PEM encoded X.509 certificate.This can also contain the necessary sub CA certificates.In that case, the order of the bundle should follow thecertificate chain, starting from the leaf certificate.The Configuration Variable MaxCertificateChainSize canbe used to limit the maximum size of this field.
-	unsigned char certificateType[32];								// Optional. Indicates the type of the signed certificate that is returned.
-	unsigned char Response_status[16];								// Required. Returns whether certificate signing has been accepted, otherwise rejected.
-	struct StatusInfoType Response_statusInfo;						// Optional. Detailed status information.
-	unsigned char guid[37];											// Save guid from server request
+    unsigned char certificateChain[10001];                          // Required. Required. The signed PEM encoded X.509 certificate.This can also contain the necessary sub CA certificates.In that case, the order of the bundle should follow thecertificate chain, starting from the leaf certificate.The Configuration Variable MaxCertificateChainSize canbe used to limit the maximum size of this field.
+    unsigned char certificateType[32];                              // Optional. Indicates the type of the signed certificate that is returned.
+    unsigned char Response_status[16];                              // Required. Returns whether certificate signing has been accepted, otherwise rejected.
+    struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
+    unsigned char guid[37];                                         // Save guid from server request
 };
 
 struct ChangeAvailability_20
@@ -5548,10 +5589,10 @@ struct SetVariables_20
 
 struct SignCertificate_20
 {
-	unsigned char csr[5501];										// Required. The Charging Station SHALL send the public key in form of a Certificate Signing Request (CSR) as described in RFC 2986 [22] using the SignCertificateRequest message.
-	unsigned char certificateType[32];								// Optional. Indicates the type of certificate that is to be signed. When omitted the certificate is to be used for both the 15118 connection (if implemented) and the Charging Station to CSMS connection.
-	unsigned char Response_status[16];								// Required. Specifies whether the CSMS can process the request.
-	struct StatusInfoType Response_statusInfo;						// Optional. Detailed status information.
+    unsigned char csr[5501];                                        // Required. The Charging Station SHALL send the public key in form of a Certificate Signing Request (CSR) as described in RFC 2986 [22] using the SignCertificateRequest message.
+    unsigned char certificateType[32];                              // Optional. Indicates the type of certificate that is to be signed. When omitted the certificate is to be used for both the 15118 connection (if implemented) and the Charging Station to CSMS connection.
+    unsigned char Response_status[16];                              // Required. Specifies whether the CSMS can process the request.
+    struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
 };
 
 struct StatusNotification_20

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

+ 28 - 19
EVSE/Projects/DD360Audi/Apps/Makefile

@@ -76,9 +76,10 @@ MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 	$(CC) $(CFLAGS) -c $<
 
 #internal comm lib
-INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o $(InternalCommLib)/Module_InternalComm.o \
-							$(InternalCommLib)/FanBoard.o $(InternalCommLib)/LEDlight.o $(InternalCommLib)/RelayBoard.o \
-								$(InternalCommLib)/AcPlug.o
+INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o \
+							$(InternalCommLib)/Module_InternalComm.o $(InternalCommLib)/FanBoard.o \
+								$(InternalCommLib)/LEDlight.o $(InternalCommLib)/RelayBoard.o \
+									$(InternalCommLib)/AcPlug.o
 INTERNALCOMM_SRC_FILES = $(patsubst %.o, %.c, $(INTERNALCOMM_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
@@ -91,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
 
@@ -100,12 +107,12 @@ apps: MainTask DoCommTask EvCommTask \
 				FactoryConfigApp OtherTools CleanExec
 
 MainTask:
-	#$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
-	#	$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) -o main
-	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
-	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c
-	$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
+	$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
+		$(RFID_H) $(Lib_Module_RFID) $(Lib_Module_Upgrade) $(Lib_SQLite3) $(Lib_Module_RateCurrent) -o main
+	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
+	#$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c
+	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
 
 DoCommTask:
 	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
@@ -113,12 +120,13 @@ DoCommTask:
 	$(CC) -o Module_DoComm DoComm.o define.o
 
 EvCommTask:
-	#$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
-	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
+	$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
+	#$(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
@@ -153,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
 
@@ -182,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)

+ 96 - 84
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");
     }
 }
@@ -439,7 +440,7 @@ static void clearMiscCommand(void)
 
 static int qrCodeUrlInfoHandle(uint8_t *data)
 {
-    int len = 0;
+    //int len = 0;
     //char cmdBuf[128] = {0};
     char localTime[128] = {0};
     uint16_t timeLen = 0;
@@ -466,7 +467,8 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
         memset(ShmSysConfigAndInfo->SysConfig.SystemId, '\0', sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
         //printf("data =  %s\r\n", data);
-        len = string2ByteArray((char *)data, (uint8_t *)ShmSysConfigAndInfo->SysConfig.SystemId);
+        //len =
+        string2ByteArray((char *)data, (uint8_t *)ShmSysConfigAndInfo->SysConfig.SystemId);
         //printf("SystemId =  %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
     }
 
@@ -565,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;
 
@@ -628,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:
@@ -699,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
@@ -711,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
@@ -732,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;
 
@@ -829,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;
@@ -914,7 +916,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
     uint8_t EventCodeTmp[7] = {0};
     uint8_t StatusArray[MAX_REGISTER_NUM][WARNING_CODE_SIZE] = {0};
     uint8_t remaindLen = 0;
-    uint8_t statusCodeError = 0;
+    //uint8_t statusCodeError = 0;
 
     if (dataLen > 0) {
         Hexdump((uint8_t *)data, dataLen);
@@ -1110,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;
@@ -1123,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;
 
@@ -1370,15 +1374,21 @@ 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
-        strcpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, "");
-        strcpy(&vendorErrorCodeTmp[plugNum][0], "");
+        strncpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
+                "",
+                sizeof(ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode));
+
+        strncpy(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE);
     } else if ((ChargingData[plugNum]->SystemStatus <= S_PREPARING_FOR_EVSE) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST0) ||
                (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST1)) {
@@ -1390,9 +1400,11 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     } else if ((ChargingData[plugNum]->SystemStatus == S_ALARM) ||
                (ChargingData[plugNum]->SystemStatus == S_FAULT)) {
         pConnState->State = CONN_ST_ALARM;
-        strncpy((char *)pConnState->WarningCode, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
+        strncpy((char *)pConnState->WarningCode,
+                (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
+                WARNING_CODE_SIZE);
 
-        if (strcmp(&vendorErrorCodeTmp[plugNum][0], "") == 0) {
+        if (strncmp(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE) == 0) {
             strncpy(&vendorErrorCodeTmp[plugNum][0],
                     (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
                     WARNING_CODE_SIZE);
@@ -1687,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;
     }
@@ -1746,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) ||
@@ -1766,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]);
@@ -1983,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;
 
@@ -2219,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];
@@ -2243,7 +2254,8 @@ int main(int argc, char *argv[])
 
 
             if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
-                sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+                sprintf(tmpbuf,
+                        "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
                         ShmSysConfigAndInfo->SysConfig.SystemId);
                 system(tmpbuf);
             }

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

+ 0 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.c → EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvCommOrg.c


+ 73 - 67
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -25,13 +25,14 @@ 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;
 
 //------------------------------------------------------------------------------
 extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
 
 //------------------------------------------------------------------------------
-static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
+/*static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
         uint8_t chillerTemp1, uint8_t chillerTemp2)
 {
     uint8_t i = 0;
@@ -64,6 +65,7 @@ static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
 
     return maxTemp;
 }
+*/
 
 static uint8_t getMaxConnectTemp(uint8_t headTemp1, uint8_t headTemp2)
 {
@@ -98,7 +100,6 @@ static float ReadAdcVolt(uint8_t AdcChannel)
     int fd = -1;
     uint8_t str[64] = {0};
     uint8_t AdcValue[8] = {'\0'};
-    //uint32_t AdcValue = 0;
 
     if (AdcChannel > 7) {
         return -1;
@@ -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,6 +191,11 @@ void CANReceiver(int fd)
 
     canRecPid = fork();
 
+    if (canRecPid < 0) {
+        log_error("Create CAN Bus receive task failed\r\n");
+        return;
+    }
+
     if (canRecPid == 0) {
         int isContinue = 1;
         int nbytes;
@@ -211,6 +219,9 @@ void CANReceiver(int fd)
         ShmGBTData = (struct GBTData *)GetShmGBTData();
         ShmCcsData = (struct CcsData *)GetShmCcsData();
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+        ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
+
+        log_info("Module_EvRXComm Child's PID is %d\r\n", getpid());
 
         while (isContinue) {
             memset(&frame, 0, sizeof(struct can_frame));
@@ -249,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;
@@ -268,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]) {
@@ -328,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;
@@ -346,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];
                     }
@@ -448,70 +462,62 @@ void CANReceiver(int fd)
                     //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureN = frame.data[2];
                 }
                 }*/
-#if 1
-                //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->ConnectorTemp = getMaxConnectTempAndChiller(
-                                                         frame.data[1],
-                                                         frame.data[2],
-                                                         chiilerTemp.Temp[0],
-                                                         chiilerTemp.Temp[1]);
-
-                    //log_info("%d chiller Temp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
-                    //         targetGun,
-                    //         chiilerTemp.Temp[0],
-                    //         chiilerTemp.Temp[1],
-                    //         frame.data[1],
-                    //         frame.data[2]);
-                } else if (targetGun == 1 &&
-                           ((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->ConnectorTemp = getMaxConnectTempAndChiller(
-                                                         frame.data[1],
-                                                         frame.data[2],
-                                                         chiilerTemp.Temp[0],
-                                                         chiilerTemp.Temp[1]);
-
-                    //log_info("%d chillerTemp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
-                    //         targetGun,
-                    //         chiilerTemp.Temp[0],
-                    //         chiilerTemp.Temp[1],
-                    //         frame.data[1],
-                    //         frame.data[2]);
-                } else {
-                    pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
-                    //log_info("connector temperature = %d\r\n",
-                    //         pDcChargingInfo->ConnectorTemp);
+                    pDcChargingInfo->ChillerTemp = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                 }
-#endif //0
-                if (ShmDcCommonData->SystemModeChange == YES) {
+
+                pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
+
+                //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
+                if ((ShmDcCommonData->SystemModeChange == YES) ||
+                        (((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
+                          (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
+                         ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
+                          (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
+                   ) {
                     ShmDcCommonData->SystemModeChange = NO;
-                    //log_info("EvboardStatus = %x \n",
-                    //         ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
-                    //log_info("ConnectorPlug locked = %x \n",
-                    //         frame.data[0]);
-
-                    //if (frame.data[1] >= GUN_OTP_VALUE ||
-                    //        frame.data[2] >= GUN_OTP_VALUE ||
-                    //        chiilerTemp.Temp[0] >= GUN_OTP_VALUE ||
-                    //        chiilerTemp.Temp[1] >= GUN_OTP_VALUE) {
                     log_info("Conn %d Temp 0= %d, Temp 1 = %d, chillerTemp1 = %d, chillerTemp2 = %d\r\n",
                              targetGun,
                              frame.data[1],
                              frame.data[2],
                              chiilerTemp.Temp[0],
                              chiilerTemp.Temp[1]);
-                    //}
-                    //log_info("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
                 }
+
+                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",
+                //         frame.data[0]);
+                //log_info("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
                 break;
 
             case ACK_EVSE_ISOLATION_STATUS:

+ 67 - 55
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
@@ -88,23 +90,17 @@ int InitCanBus(void)
     tv.tv_usec = 10000;
 
     if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct  timeval)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVTIMEO NG");
-#endif
     }
 
     nbytes = 40960;
     if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_RCVBUF NG");
-#endif
     }
 
     nbytes = 40960;
     if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
         log_error("Set SO_SNDBUF NG");
-#endif
     }
 
     rxfilter[0].can_id = 0x01;
@@ -115,10 +111,10 @@ int InitCanBus(void)
     rxfilter[2].can_mask = 0x00000FFF;
     if (setsockopt(s0, SOL_CAN_RAW, CAN_RAW_FILTER,
                    &rxfilter, sizeof(struct can_filter) * 3) < 0) {
-        log_error("RX setsockopt CAN_RAW_FILTER failed");
+        log_error("RX setsockopt CAN_RAW_FILTER failed\r\n");
     }
 
-    strcpy(ifr0.ifr_name, "can0" );
+    strcpy(ifr0.ifr_name, "can0");
     ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
     addr0.can_family = AF_CAN;
     addr0.can_ifindex = ifr0.ifr_ifindex;
@@ -482,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) {
@@ -507,6 +503,10 @@ static void checkConnectorOVPState(uint8_t gunIndex)
         break;
     }
 
+    if (ShmDcCommonData->ChillerTempState[gunIndex].StatusBit.ChillerOTP == YES) {
+        isOTP = true;
+    }
+
     if (isOTP) {
         if (gunTempAllowCount[gunIndex] >= 2) {
             pDcChargingInfo->StopChargeFlag = YES;
@@ -574,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};
@@ -597,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();
 
@@ -629,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,
@@ -671,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);
 
@@ -687,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;
@@ -742,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;
@@ -765,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;
 
@@ -829,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) {
@@ -856,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);
                     }
                 }
@@ -909,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) {
@@ -920,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;
@@ -935,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);
@@ -954,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,
@@ -976,8 +990,6 @@ int main(int argc, char *argv[])
                 SetPresentChargingOutputPower();
 
                 if (priorityLow == 1) {
-                    float maxVol, maxCur;
-
                     // 樁端輸出能力
                     maxVol = pDcChargingInfo->MaximumChargingVoltage;
                     maxCur = pDcChargingInfo->AvailableChargingCurrent;

+ 9 - 4
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c

@@ -112,7 +112,7 @@ static uint8_t getCommTargetID(uint8_t index)
     return targetID;
 }
 
-static void MatchRelayStatus(void)
+/*static void MatchRelayStatus(void)
 {
     // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
     //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
@@ -127,6 +127,7 @@ static void MatchRelayStatus(void)
     regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
     regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
 }
+*/
 
 static bool IsNoneMatchRelayStatus(void)
 {
@@ -368,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;
@@ -498,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) {

+ 235 - 133
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;
+            _chargingData[curGun]->Type = 9;
+            break;
 
-        }
-        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];
@@ -940,26 +957,74 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             }
         }
 
-        if (strcmp(newString[0], "chg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+        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
+               ) {
+                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
                 continue;
             }
-            if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+
+            if (atoi(newString[1]) == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            _Voltage = atof((char *)newString[2]);
+            _Current = atof((char *)newString[3]);
+
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
                 continue;
             }
 
-            float _vol = atof(newString[1]);
-            float _cur = atof(newString[2]);
+            printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+                    ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+                    _Voltage,
+                    _Current);
+
+            if (_Voltage > 1000 || _Voltage < 50) {
+                _Voltage = 200;
+                printf ("Input Voltage over range\n");
+                continue;
+            }
+
+            ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+        } else if (strcmp(newString[0], "chg") == 0) {
+            if (strcmp(newString[1], "-1") == 0) {
+                continue;
+            }
+
+            if (strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0) {
+                continue;
+            }
+
+            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;
         }
@@ -1138,6 +1203,43 @@ int main(void)
                 _chargingData[1]->ConnectorTemp = atoi(newString[2]);
                 printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
             }
+        } else if (strcmp(newString[0], "tempC") == 0) {
+            if (strcmp(newString[1], "0") == 0) {
+                uint8_t _GunIndex = 0;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
+                _chargingData[0]->ChillerTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
+            } else if (strcmp(newString[1], "1") == 0) {
+                uint8_t _GunIndex = 1;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
+                _chargingData[1]->ChillerTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            }
+        } else if (strcmp(newString[0], "TempCR") == 0) {
+            if (strcmp(newString[1], "0") == 0) {
+                uint8_t _GunIndex = 0;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
+            } else if (strcmp(newString[1], "1") == 0) {
+                uint8_t _GunIndex = 1;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
+                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            }
         } else {
             printf ("%s\n", msg);
         }

+ 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

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

@@ -1,15 +1,23 @@
 #/bin/bash
 
+# Absolute path to this script, e.g. /home/user/bin/foo.sh
+SCRIPT=$(readlink -f "$0")
+
+# Absolute path this script is in, thus /home/user/bin
+SCRIPTPATH=$(dirname "$SCRIPT")
+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;
 git add $ProjectPath/DD360ComBox;
+git status;

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.c

@@ -9,7 +9,7 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../timeout.h"
-#include "../main.h"
+#include "../CSU/main.h"
 
 #include "SelectGun.h"
 

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

+ 119 - 52
EVSE/Projects/DD360Audi/Apps/main.c → EVSE/Projects/DD360Audi/Apps/mainOrg.c

@@ -266,7 +266,7 @@ static void destroySelGun(uint8_t curGun)
 static int waitRightGunPlugIt(uint8_t curGun)
 {
 #if !defined DD360Audi
-    return;
+    return PASS;
 #endif //!defined DD360Audi
 
     if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
@@ -279,7 +279,7 @@ static int waitRightGunPlugIt(uint8_t curGun)
 static int waitLeftGunPlugIt(uint8_t curGun)
 {
 #if !defined DD360Audi
-    return;
+    return PASS;
 #endif //!defined DD360Audi
 
     if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
@@ -309,7 +309,7 @@ static void setSelGunWaitToAuthor(uint8_t curSel)
 static int getConfirmSelectedGun(uint8_t curSel)
 {
 #if !defined DD360Audi
-    return;
+    return PASS;
 #endif //!defined DD360Audi
 
     if (((curSel == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
@@ -343,6 +343,30 @@ static void confirmSelGun(uint8_t selGun)
 
 static void checkGunOTPState(uint8_t _index)
 {
+
+    if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
+            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "V", 1) == 0) ||
+            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "F", 1) == 0) ||
+            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "F", 1) == 0)
+       ) {
+        if (chargingInfo[_index]->ChillerTemp != UNDEFINED_TEMP) {
+            ResetChargerAlarmCode(_index, "011038"); //清除溫度檢測異常status code
+
+            if (chargingInfo[_index]->ChillerTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012323");
+            } else if (chargingInfo[_index]->ChillerTemp != 0 &&
+                       chargingInfo[_index]->ChillerTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012323");
+            }
+
+            //ResetChargerAlarmCode(_index, "011019");
+        } else {
+            // 沒接上 Sensor or 異常
+            RecordAlarmCode(_index, "011038");
+            ResetChargerAlarmCode(_index, "012323");
+        }
+    }
+
     switch (chargingInfo[_index]->Type) {
     case _Type_Chademo:
         if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
@@ -597,22 +621,28 @@ static void checkEvBoardAlarmState(uint8_t gunType)
 
 static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
 {
-    uint8_t ret = NO;
     LedConfig *pLedConfig = (LedConfig *)ledConfig;
 
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
-        ret = YES;
-        if (pLedConfig->RedLED == YES) {
-            pLedConfig->RedLED = NO;
-        } else {
-            pLedConfig->RedLED = YES;
-        }
+    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == NO) {
+        return NO;
+    }
+
+    if (pLedConfig->RedLED == YES ||
+            pLedConfig->YellowLED == YES ||
+            pLedConfig->GreenLED == YES) {
+        pLedConfig->YellowLED = NO;
+        pLedConfig->GreenLED = NO;
+        pLedConfig->RedLED = NO;
+    } else {
+        pLedConfig->YellowLED = YES;
+        pLedConfig->GreenLED = YES;
+        pLedConfig->RedLED = YES;
     }
 
-    return ret;
+    return YES;
 }
 
-static void startPrimaryLedIndicatorCtrlFork(void)
+static void PrimaryLedIndicatorCtrlFork(void)
 {
 #if !defined DD360ComBox
     return;
@@ -625,10 +655,22 @@ static void startPrimaryLedIndicatorCtrlFork(void)
         int isContinue = 1;
         LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
 
+
         while (isContinue) {
             for (gunIndex = 0; gunIndex < totalGun; gunIndex++) {
+                if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 &&
+                        chargingInfo[gunIndex]->SystemStatus != S_BOOTING) {
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        continue;
+                    }
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    pLedConfig->RedLED = YES;
+                    continue;
+                }
+
                 //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
-                //printf("level = %d\r\n", ShmSysConfigAndInfo->SysWarningInfo.Level);
+                //printf("level = %d\r\n", pSysWarning->Level);
                 switch (chargingInfo[gunIndex]->SystemStatus) {
                 case S_BOOTING:
                     if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
@@ -653,10 +695,19 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                     break;
 
                 case S_IDLE:
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
                     //Module_DoComm connected and system idle
                     pLedConfig->RedLED = NO;
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = YES;
+                    //}
                     break;
 
                 case S_RESERVATION:
@@ -668,12 +719,21 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                 case S_PREPARING_FOR_EVSE:
                 case S_CCS_PRECHARGE_ST0:
                 case S_CCS_PRECHARGE_ST1:
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
                     //precharging status
                     if (pLedConfig->GreenLED == YES) {
                         pLedConfig->GreenLED = NO;
                     } else {
                         pLedConfig->GreenLED = YES;
                     }
+                    //}
                     break;
 
                 case S_CHARGING:
@@ -687,44 +747,43 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                     break;
 
                 case S_ALARM:
+                    //if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //    break;
+                    //}
+
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
-
-                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                        break;
-                    }
-
                     pLedConfig->RedLED = YES;
                     break;
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        pLedConfig->YellowLED = NO;
-                        pLedConfig->GreenLED = NO;
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    } else {
-                        pLedConfig->RedLED = NO;
-                        pLedConfig->YellowLED = YES;
-                        pLedConfig->GreenLED = NO;
-                    }
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
+                    pLedConfig->RedLED = NO;
+                    pLedConfig->YellowLED = YES;
+                    pLedConfig->GreenLED = NO;
+                    //}
                     break;
 
                 case S_MAINTAIN:
                 case S_FAULT:
+                    //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    //pLedConfig->RedLED = YES;
+                    //}
+
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
-                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    }
+                    pLedConfig->RedLED = YES;
                     break;
 
                 case S_BOOKING:
@@ -732,12 +791,11 @@ static void startPrimaryLedIndicatorCtrlFork(void)
                 case S_UPDATE:
                 case S_NONE:
                     break;
-                }
-
-                usleep(500000);
-            }//switch
-        }//for
-    }//while
+                }//switch
+            }//for
+            usleep(500000);
+        }//while
+    }//fork
 }
 
 //================================================
@@ -2644,6 +2702,8 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
     else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO; }
     else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO; }
     else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO; }
+    else if (strcmp(code, "012323") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChillerOTP = NO; }
+    else if (strcmp(code, "011038") == EQUAL) {  ShmStatusCodeData->FaultCode.FaultEvents.bits.ChillerTempSensorBroken = NO; }
 
     if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
         if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012229", 6) == EQUAL ||
@@ -2657,7 +2717,10 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
                 strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011016", 6) == EQUAL ||
                 strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011018", 6) == EQUAL ||
                 strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011019", 6) == EQUAL ||
-                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL) {
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012323", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011038", 6) == EQUAL
+           ) {
             strncpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
         }
     }
@@ -2698,6 +2761,8 @@ void RecordAlarmCode(uint8_t gunIndex, char *code)
     else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
     else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
     else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
+    else if (strcmp(code, "012323") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChillerOTP = YES; }
+    else if (strcmp(code, "012323") == EQUAL) { ShmStatusCodeData->FaultCode.FaultEvents.bits.ChillerTempSensorBroken = YES; }
 }
 
 void RecordWarningCode(uint8_t gunIndex, char *code)
@@ -3151,7 +3216,9 @@ void ChkPrimaryStatus()
                 if (isDetectPlugin()) {
                     _DetectPlugInTimeout();
                     StopSystemTimeoutDet();
+#if defined DD360Audi
                     destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+#endif //defined DD360Audi
                 }
 #if defined DD360Audi
                 else {
@@ -5895,11 +5962,11 @@ static void ReviewCriticalAlarm(void)
             ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
             ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
             ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES ||
+            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == YES ||
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo
        ) {
         ShmSysConfigAndInfo->SysWarningInfo.Level = 2;
@@ -6029,7 +6096,7 @@ int main(void)
     }
     CreateTimeoutFork();
     log_info("Start self test... \n");
-    startPrimaryLedIndicatorCtrlFork();
+    PrimaryLedIndicatorCtrlFork();
     SelfTestRun();
     StopSystemTimeoutDet();
     log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",

+ 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


+ 35 - 13
EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c

@@ -11,6 +11,18 @@
 #include "../common.h"
 
 //------------------------------------------------------------------------------
+static void InitialDHCP(void)
+{
+    char tmpbuf[256] = {0};
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+    sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
+            pSysConfig->SystemId);
+
+    system(tmpbuf);
+}
+
 void GetMacAddress(void)
 {
     uint8_t index = 0;
@@ -70,10 +82,12 @@ static int isRouteFail(void)
 static int isReachableInternet(void)
 {
     int result = FAIL;
+    int idx = 0;
     FILE *fp;
-    char cmd[256];
-    char buf[512];
-    char tmp[512];
+    char cmd[256] = {0};
+    char buf[512] = {0};
+    char tmp[512] = {0};
+    char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
 
@@ -92,6 +106,7 @@ static int isReachableInternet(void)
             }
         }
     }
+
     pclose(fp);
 
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
@@ -100,9 +115,13 @@ static int isReachableInternet(void)
     } else {
         result = PASS;
     }
-#else
+
+    return result;
+#endif //defined DD360 || defined DD360Audi
+
     memset(buf, 0x00, sizeof(buf));
-    for (int idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
+
+    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");
         if (fp != NULL) {
@@ -122,20 +141,18 @@ static int isReachableInternet(void)
         pclose(fp);
     }
 
-#endif //defined DD360 || defined DD360Audi
-
     return result;
 }
 
 void InitEthernet(void)
 {
     char tmpbuf[256];
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
     bool ethResult = false;
     uint8_t cnt_pingDNS_Fail = 0;
-#endif //!defined DD360 && !defined DD360Audi
 
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
 
     system("ifconfig eth0 down");// eth0 down
     system("ifconfig eth1 down");// eth1 down
@@ -144,6 +161,7 @@ void InitEthernet(void)
     // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
     system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
     sleep(2);
+
     //Init Eth0 for internet
     memset(tmpbuf, 0, 256);
     sprintf(tmpbuf, "/sbin/ifconfig eth0 %s netmask %s up",
@@ -159,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",
@@ -186,8 +205,14 @@ 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
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            isReachableInternet();
+            sleep(5);
+            continue;
+#endif //!defined DD360 && !defined DD360
+
             if (isRouteFail()) {
                 //log_info("eth0 not in route, restart eht0. \n");
                 system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
@@ -266,9 +291,6 @@ void InitEthernet(void)
             }
 
             pSysInfo->InternetConn = ethResult;
-#else
-            isReachableInternet();
-#endif //!defined DD360 && !defined DD360
 
             sleep(5);
         }

+ 175 - 32
EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c

@@ -9,7 +9,7 @@
 #include "../ShareMemory/shmMem.h"
 
 #include "../SelectGun/SelectGun.h"
-#include "../main.h"
+#include "main.h"
 
 //------------------------------------------------------------------------------
 
@@ -22,10 +22,16 @@ static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
 
     if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
         ret = YES;
-        if (pLedConfig->RedLED == YES) {
+        if (pLedConfig->RedLED == YES ||
+                pLedConfig->YellowLED == YES ||
+                pLedConfig->GreenLED == YES) {
             pLedConfig->RedLED = NO;
+            pLedConfig->YellowLED = NO;
+            pLedConfig->GreenLED = NO;
         } else {
             pLedConfig->RedLED = YES;
+            pLedConfig->YellowLED = YES;
+            pLedConfig->GreenLED = YES;
         }
     }
 
@@ -55,6 +61,19 @@ void PrimaryLedIndicatorCtrlFork(void)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
+                if (pSysWarning->Level == WARN_LV_ER) {
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        usleep(500000);
+                        continue;
+                    }
+
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    pLedConfig->RedLED = YES;
+                    usleep(500000);
+                    continue;
+                }
+
                 //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
                 //printf("level = %d\r\n", pSysWarning->Level);
                 switch (pDcChargingInfo->SystemStatus) {
@@ -127,32 +146,31 @@ void PrimaryLedIndicatorCtrlFork(void)
 
                 case S_TERMINATING:
                 case S_COMPLETE:
-                    if (pSysWarning->Level == 2) {
-                        pLedConfig->YellowLED = NO;
-                        pLedConfig->GreenLED = NO;
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    } else {
-                        pLedConfig->RedLED = NO;
-                        pLedConfig->YellowLED = YES;
-                        pLedConfig->GreenLED = NO;
-                    }
+                    //if (pSysWarning->Level == WARN_LV_ER) {
+                    //    pLedConfig->YellowLED = NO;
+                    //    pLedConfig->GreenLED = NO;
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->RedLED = YES;
+                    //} else {
+                    pLedConfig->RedLED = NO;
+                    pLedConfig->YellowLED = YES;
+                    pLedConfig->GreenLED = NO;
+                    //}
                     break;
 
                 case S_MAINTAIN:
                 case S_FAULT:
                     pLedConfig->YellowLED = NO;
                     pLedConfig->GreenLED = NO;
-                    if (pSysWarning->Level == 2) {
-                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                            break;
-                        }
-
-                        pLedConfig->RedLED = YES;
-                    }
+                    pLedConfig->RedLED = YES;
+                    //if (pSysWarning->Level == WARN_LV_ER) {
+                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                    //        break;
+                    //    }
+                    //    pLedConfig->RedLED = YES;
+                    //}
                     break;
 
                 case S_BOOKING:
@@ -160,65 +178,187 @@ void PrimaryLedIndicatorCtrlFork(void)
                 case S_UPDATE:
                 case S_NONE:
                     break;
-                }
-
-                usleep(500000);
-            }//switch
-        }//for
-    }//while
+                }//switch
+            }//for
+            usleep(500000);
+        }//while
+    }//fork
 }
 
 //------------------------------------------------------------------------------
+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;
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042252", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = YES;
                 EmcOccureByString("042252");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042200", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = YES;
                 EmcOccureByString("042200");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042201", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = YES;
                 EmcOccureByString("042201");
                 Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "042202", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = YES;
                 EmcOccureByString("042202");
                 Rtn = 1;
+            } else if (memcmp(&pSysWarning->WarningCode[i][0], "042267", 6) == 0) {
+                ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = YES;
+                EmcOccureByString("042267");
+                Rtn = 1;
             } else if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
                 EmcOccureByString("012304");
                 Rtn = 1;
             }
         }
+
         if (Rtn == 0) {
+            ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
+            ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
             ReleaseEmsOccureByString(0, "042251");
             ReleaseEmsOccureByString(0, "042252");
             ReleaseEmsOccureByString(0, "042200");
             ReleaseEmsOccureByString(0, "042201");
             ReleaseEmsOccureByString(0, "042202");
+            ReleaseEmsOccureByString(0, "042267");
             ReleaseEmsOccureByString(0, "012304");
         }
     } else {
+        ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP = NO;
+        ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure = NO;
         ReleaseEmsOccureByString(0, "042251");
         ReleaseEmsOccureByString(0, "042252");
         ReleaseEmsOccureByString(0, "042200");
         ReleaseEmsOccureByString(0, "042201");
         ReleaseEmsOccureByString(0, "042202");
+        ReleaseEmsOccureByString(0, "042267");
         ReleaseEmsOccureByString(0, "012304");
     }
 
@@ -272,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);
 
@@ -305,7 +448,6 @@ void ChkPrimaryStatus(void)
                     break;
                 }
             }
-
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
                 if (isDetectPlugin()) {
@@ -356,6 +498,7 @@ void ChkPrimaryStatus(void)
                 //pDcChargingInfo->SystemStatus = S_IDLE;
                 break;
             }
+#endif //0
         }
     } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
         if (leftBtnPush) {

Некоторые файлы не были показаны из-за большого количества измененных файлов