Переглянути джерело

2021.05.11 / Jerry Wang

Actions:
1. Add check gun temperature.
2. Fixed Rated Current API.

Files:
1. As follow as commit history.
Jerry_Wang 4 роки тому
батько
коміт
5deaf4ac26
100 змінених файлів з 6215 додано та 36405 видалено
  1. 65 11
      EVSE/Modularization/Module_RatedCurrent.c
  2. 3 3
      EVSE/Modularization/Module_RatedCurrent.h
  3. 199 120
      EVSE/Projects/DD360/Apps/Config.h
  4. 0 1252
      EVSE/Projects/DD360/Apps/DoComm.c
  5. 0 196
      EVSE/Projects/DD360/Apps/Ev_Comm.c
  6. 3 8
      EVSE/Projects/DD360/Apps/FactoryConfig.c
  7. 49 32
      EVSE/Projects/DD360/Apps/Makefile
  8. 143 119
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  9. 22 27
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  10. 198 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.c
  11. 62 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.h
  12. 295 108
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.c
  13. 38 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.h
  14. 63 79
      EVSE/Projects/DD360/Apps/ModuleEventLog/Module_EventLogging.c
  15. 171 248
      EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.c
  16. 92 0
      EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.h
  17. 299 345
      EVSE/Projects/DD360/Apps/ModuleInternalComm/internalComm.c
  18. 251 0
      EVSE/Projects/DD360/Apps/ModuleInternalComm/internalComm.h
  19. 114 127
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c
  20. 90 99
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.h
  21. 105 186
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c
  22. 34 0
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.h
  23. 96 100
      EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.c
  24. 79 0
      EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.h
  25. 0 0
      EVSE/Projects/DD360/Apps/ModulePsuComm/Module_PsuComm.c
  26. 0 0
      EVSE/Projects/DD360/Apps/ModulePsuComm/Module_PsuComm.h
  27. 0 2934
      EVSE/Projects/DD360/Apps/Module_EvComm.c
  28. 0 88
      EVSE/Projects/DD360/Apps/Module_EvComm.h
  29. 0 324
      EVSE/Projects/DD360/Apps/Module_EventLogging.c
  30. 0 2409
      EVSE/Projects/DD360/Apps/Module_InternalComm.c
  31. 0 196
      EVSE/Projects/DD360/Apps/Module_LcmContro.h
  32. 0 1526
      EVSE/Projects/DD360/Apps/Module_LcmControl.c
  33. 0 517
      EVSE/Projects/DD360/Apps/Module_PrimaryComm.c
  34. 102 113
      EVSE/Projects/DD360/Apps/OutputTask.h
  35. 0 76
      EVSE/Projects/DD360/Apps/PrimaryComm.h
  36. 0 6608
      EVSE/Projects/DD360/Apps/ReMain.c
  37. 60 49
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  38. 1 1
      EVSE/Projects/DD360/Apps/Script/init.sh
  39. 40 0
      EVSE/Projects/DD360/Apps/Script/kill.sh
  40. 0 0
      EVSE/Projects/DD360/Apps/Script/replaceOtherProject.sh
  41. 0 0
      EVSE/Projects/DD360/Apps/Script/web.sh
  42. 19 16
      EVSE/Projects/DD360/Apps/SelectGun/SelectGun.h
  43. BIN
      EVSE/Projects/DD360/Apps/UnsafetyOutputTask
  44. 60 0
      EVSE/Projects/DD360/Apps/common.c
  45. 13 0
      EVSE/Projects/DD360/Apps/common.h
  46. 0 276
      EVSE/Projects/DD360/Apps/internalComm.h
  47. 0 39
      EVSE/Projects/DD360/Apps/kill.sh
  48. 710 210
      EVSE/Projects/DD360/Apps/main.c
  49. 63 0
      EVSE/Projects/DD360/Apps/main.h
  50. 2 1
      EVSE/Projects/DD360/Apps/timeout.h
  51. BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  52. BIN
      EVSE/Projects/DD360/output/FactoryConfig
  53. BIN
      EVSE/Projects/DD360/output/Module_DoComm
  54. BIN
      EVSE/Projects/DD360/output/Module_EvComm
  55. BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  56. BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  57. BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  58. BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  59. BIN
      EVSE/Projects/DD360/output/ReadCmdline
  60. 1 1
      EVSE/Projects/DD360/output/init.sh
  61. 1 1
      EVSE/Projects/DD360/output/kill.sh
  62. BIN
      EVSE/Projects/DD360/output/main
  63. 199 120
      EVSE/Projects/DD360Audi/Apps/Config.h
  64. 0 1252
      EVSE/Projects/DD360Audi/Apps/DoComm.c
  65. 0 196
      EVSE/Projects/DD360Audi/Apps/Ev_Comm.c
  66. 3 8
      EVSE/Projects/DD360Audi/Apps/FactoryConfig.c
  67. 49 32
      EVSE/Projects/DD360Audi/Apps/Makefile
  68. 143 119
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  69. 22 27
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  70. 198 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.c
  71. 62 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.h
  72. 361 181
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.c
  73. 38 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.h
  74. 63 79
      EVSE/Projects/DD360Audi/Apps/ModuleEventLog/Module_EventLogging.c
  75. 171 248
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.c
  76. 92 0
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.h
  77. 299 345
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/internalComm.c
  78. 251 0
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/internalComm.h
  79. 114 127
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c
  80. 90 99
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.h
  81. 105 186
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c
  82. 34 0
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.h
  83. 96 100
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.c
  84. 79 0
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.h
  85. 0 0
      EVSE/Projects/DD360Audi/Apps/ModulePsuComm/Module_PsuComm.c
  86. 0 0
      EVSE/Projects/DD360Audi/Apps/ModulePsuComm/Module_PsuComm.h
  87. 0 2934
      EVSE/Projects/DD360Audi/Apps/Module_EvComm.c
  88. 0 88
      EVSE/Projects/DD360Audi/Apps/Module_EvComm.h
  89. 0 324
      EVSE/Projects/DD360Audi/Apps/Module_EventLogging.c
  90. 0 2409
      EVSE/Projects/DD360Audi/Apps/Module_InternalComm.c
  91. 0 196
      EVSE/Projects/DD360Audi/Apps/Module_LcmContro.h
  92. 0 1526
      EVSE/Projects/DD360Audi/Apps/Module_LcmControl.c
  93. 0 517
      EVSE/Projects/DD360Audi/Apps/Module_PrimaryComm.c
  94. 102 113
      EVSE/Projects/DD360Audi/Apps/OutputTask.h
  95. 0 76
      EVSE/Projects/DD360Audi/Apps/PrimaryComm.h
  96. 0 6608
      EVSE/Projects/DD360Audi/Apps/ReMain.c
  97. 60 49
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  98. 1 1
      EVSE/Projects/DD360Audi/Apps/Script/init.sh
  99. 40 0
      EVSE/Projects/DD360Audi/Apps/Script/kill.sh
  100. 0 0
      EVSE/Projects/DD360Audi/Apps/Script/replaceOtherProject.sh

+ 65 - 11
EVSE/Modularization/Module_RatedCurrent.c

@@ -140,6 +140,56 @@ static int keyfromstring(char *key, SymStruct *table, int tableCount)
 }
 
 //------------------------------------------------------------------------------
+static uint16_t defaultRatedCurrent(uint32_t gunType)
+{
+    switch (gunType) {
+    case GUN_TYPE_J:
+        return RC_125A;
+        break;
+
+    case GUN_TYPE_U:
+    case GUN_TYPE_E:
+    case GUN_TYPE_K:
+        return RC_200A;
+        break;
+
+    case GUN_TYPE_V:
+    case GUN_TYPE_F:
+    case GUN_TYPE_P:
+    case GUN_TYPE_R:
+        return RC_500A;
+        break;
+
+    case GUN_TYPE_G:
+        return RC_250A;
+        break;
+
+    case GUN_TYPE_T:
+    case GUN_TYPE_D:
+        return RC_300A;
+        break;
+
+    case GUN_TYPE_M:
+    case GUN_TYPE_N:
+        return RC_80A;
+        break;
+
+    case GUN_TYPE_0:
+    case GUN_TYPE_1:
+    case GUN_TYPE_2:
+    case GUN_TYPE_3:
+    case GUN_TYPE_4:
+    case GUN_TYPE_5:
+    case GUN_TYPE_6:
+    case GUN_TYPE_7:
+    case GUN_TYPE_8:
+    default:
+        log_error("The gun type is not on the default current table\r\n");
+        return RC_0A;
+        break;
+    }
+}
+
 static uint16_t exchangeRatingCur(uint32_t key)
 {
     switch (key) {
@@ -351,22 +401,27 @@ static void exchangeGunTypeAndVolValue(uint8_t key, GunTypeAndVolInfo *gunAndVol
     case GUN_TYPE_5:// : GB/T AC Plug
     case GUN_TYPE_6:// : GB/T AC Socket
     case GUN_TYPE_7:// :CCS2 AC Plug
+    case GUN_TYPE_8:// :Type E socket
         pGunAndVol->GunType = Gun_Type_AC;
         pGunAndVol->GunVoltage = VOL_CHADEMO;
         break;
 
-    case GUN_TYPE_8:// :Type E socket
-        break;
-
     case GUN_TYPE_J:// : CHAdeMO
+    case GUN_TYPE_K:
         pGunAndVol->GunType = Gun_Type_Chademo;
         pGunAndVol->GunVoltage = VOL_CHADEMO;
         break;
 
     case GUN_TYPE_U:// : Natural cooling CCS1 combo
-    case GUN_TYPE_V:// : Liquid cooling CCS1 combo
     case GUN_TYPE_E:// : Natural cooling CCS2 combo
+    case GUN_TYPE_V:// : Liquid cooling CCS1 combo
     case GUN_TYPE_F:// : Liquid cooling CCS2 combo
+    case GUN_TYPE_T:// : Rema CCS1 300A
+    case GUN_TYPE_D:// : Rema CCS2 300A
+    case GUN_TYPE_M:// : CCS2 80A
+    case GUN_TYPE_N:// : CCS1 80A
+    case GUN_TYPE_P:// : Phoenix CCS2 500A 水冷
+    case GUN_TYPE_R:// : Phoenix CCS1 500A 水冷
         pGunAndVol->GunType = Gun_Type_CCS_2;
         pGunAndVol->GunVoltage = VOL_CCS;
         break;
@@ -440,11 +495,11 @@ int RatedCurrentParsing(char *pModuleName, void *pDestStruct)
     char power[2] = {'\0'};
     char gunType[1] = {'\0'};
     ParsingRatedCur *pParsingInfo = NULL;
-    GunRateCurInfo *pGunRateCurInfo = NULL;
+    RateCurInfo *pGunRateCurInfo = NULL;
     GunTypeAndVolInfo fGunAndVol = {0};
 
-    if (pModuleName == NULL || pDestStruct == NULL) {
-        log_error("Failed to parse source data\r\n");
+    if (pModuleName == NULL || (strlen(pModuleName) <= 0) || pDestStruct == NULL) {
+        log_error("Failed to parse source\r\n");
         return FAIL;
     }
 
@@ -462,8 +517,8 @@ int RatedCurrentParsing(char *pModuleName, void *pDestStruct)
     pParsingInfo->Power = exchangePowerValue(powerKey);
 
     pParsingInfo->GetGunCount = 0;
-    for (i = 0; i < sizeof(pParsingInfo->ParsingInfo) / sizeof(GunRateCurInfo); i++) {
-        pGunRateCurInfo = (GunRateCurInfo *)&pParsingInfo->ParsingInfo[pParsingInfo->GetGunCount];
+    for (i = 0; i < sizeof(pParsingInfo->ParsingInfo) / sizeof(RateCurInfo); i++) {
+        pGunRateCurInfo = (RateCurInfo *)&pParsingInfo->ParsingInfo[pParsingInfo->GetGunCount];
 
         if (i == 0) {
             gunTypeIndex = DC_ONE;
@@ -488,8 +543,7 @@ int RatedCurrentParsing(char *pModuleName, void *pDestStruct)
         ret = ((modelKey << 24) | (reguKey << 16) | (powerKey << 8) | gunTypeKey);
         ratingCurVal = exchangeRatingCur(ret);
         if (ratingCurVal == RC_0A) {
-            log_error("Rated Current Parsing model name format none match\r\n");
-            return FAIL;
+            ratingCurVal = defaultRatedCurrent(gunTypeKey);
         }
 
         memset((uint8_t *)&fGunAndVol, 0, sizeof(GunTypeAndVolInfo));

+ 3 - 3
EVSE/Modularization/Module_RatedCurrent.h

@@ -308,17 +308,17 @@ typedef struct StGunTypeAndVolInfo {
     uint16_t GunVoltage;
 } GunTypeAndVolInfo;
 
-typedef struct StGunRateCurInfo {
+typedef struct StRateCurInfo {
     uint8_t GunType;
     uint16_t Current;       //* 0.1A
     uint16_t Voltage;       //* 0.1V
     uint8_t Reserved[3];
-} GunRateCurInfo;
+} RateCurInfo;
 
 typedef struct StParsingRatingCur {
     uint8_t GetGunCount;
     uint16_t Power;
-    GunRateCurInfo ParsingInfo[3];
+    RateCurInfo ParsingInfo[3];
     uint8_t Reserved;
 } ParsingRatedCur;
 

+ 199 - 120
EVSE/Projects/DD360/Apps/Config.h

@@ -7,49 +7,86 @@
 #ifndef CONFIG_H_
 #define CONFIG_H_
 
-#define ShmCsuMeterKey          2001
-#define ShmCommonKey            2002
-
-typedef unsigned char           byte;
-
-#define TOTAL_QUANTITY_GUN          4               //Max Count
-
-#define MODE_BOOT                   0
-#define MODE_IDLE                   1
-#define MODE_AUTHORIZING            2
-#define MODE_REASSIGN_CHECK         3
-#define MODE_REASSIGN               4
-#define MODE_PRECHARGE              5
-#define MODE_PREPARE_FOR_EV         6
-#define MODE_PREPARE_FOR_EVSE       7
-#define MODE_CHARGING               8
-#define MODE_TERMINATING            9
-#define MODE_COMPLETE               10
-#define MODE_ALARM                  11
-#define MODE_FAULT                  12
-#define MODE_RESERVATION            13
-#define MODE_BOOKING                14
-#define MODE_MAINTAIN               15
-#define MODE_DEBUG                  16
-#define MODE_CCS_PRECHARGE_STEP0    17  // ready for ccs precharge processing, For D+ relay to precharge relay
-#define MODE_CCS_PRECHARGE_STEP1    18  // waitting for ev board inform to enter to charging, For precharge relay to D+ relay
-#define MODE_UPDATE                 19
-
-#define GFD_WAIT            0
-#define GFD_PASS            1
-#define GFD_FAIL            2
-#define GFD_WARNING         3
-
-#define PRECHARGE_WAIT              0
-#define PRECHARGE_READY             1
-#define PRECHARGE_PRERELAY_PASS     2
-#define PRECHARGE_CHARELAY_PASS     3
-
-#define BOOTTING            0
-#define BOOT_COMPLETE       1
-
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//independent common share memory key
+//------------------------------------------------------------------------------
+#define ShmCsuMeterKey                          2001
+#define ShmCommonKey                            2002
+
+//------------------------------------------------------------------------------
+#define TOTAL_QUANTITY_GUN                      4               //Max Count
+
+//------------------------------------------------------------------------------
+//system  runtime state
+//------------------------------------------------------------------------------
+#define MODE_BOOT                               (0)
+#define MODE_IDLE                               (1)
+#define MODE_AUTHORIZING                        (2)
+#define MODE_REASSIGN_CHECK                     (3)
+#define MODE_REASSIGN                           (4)
+#define MODE_PRECHARGE                          (5)
+#define MODE_PREPARE_FOR_EV                     (6)
+#define MODE_PREPARE_FOR_EVSE                   (7)
+#define MODE_CHARGING                           (8)
+#define MODE_TERMINATING                        (9)
+#define MODE_COMPLETE                           (10)
+#define MODE_ALARM                              (11)
+#define MODE_FAULT                              (12)
+#define MODE_RESERVATION                        (13)
+#define MODE_BOOKING                            (14)
+#define MODE_MAINTAIN                           (15)
+#define MODE_DEBUG                              (16)
+#define MODE_CCS_PRECHARGE_STEP0                (17)  // ready for ccs precharge processing, For D+ relay to precharge relay
+#define MODE_CCS_PRECHARGE_STEP1                (18)  // waitting for ev board inform to enter to charging, For precharge relay to D+ relay
+#define MODE_UPDATE                             (19)
+
+#define GFD_WAIT                                (0)
+#define GFD_PASS                                (1)
+#define GFD_FAIL                                (2)
+#define GFD_WARNING                             (3)
+
+#define PRECHARGE_WAIT                          (0)
+#define PRECHARGE_READY                         (1)
+#define PRECHARGE_PRERELAY_PASS                 (2)
+#define PRECHARGE_CHARELAY_PASS                 (3)
+
+#define BOOTTING                                (0)
+#define BOOT_COMPLETE                           (1)
+
+//------------------------------------------------------------------------------
+//common define
+//------------------------------------------------------------------------------
+#define ARRAY_SIZE(A)                           (sizeof(A) / sizeof(A[0]))
+
+#define PASS                                    (1)
+#define FAIL                                    (-1)
+
+#define START                                   (1)
+#define STOP                                    (0)
+
+#define YES                                     (1)
+#define NO                                      (0)
+
+#define NORMAL                                  (0)
+#define ABNORMAL                                (1)
+
+#define EQUAL                                   (0)
+
+#define NO_DEFINE                               (255)
+
+//------------------------------------------------------------------------------
+//gun temperatures
+//------------------------------------------------------------------------------
+#define GUN_OTP_VALUE                           150
+#define GUN_OTP_RECOVERY                        140
+#define UNDEFINED_TEMP                          255
+
+//------------------------------------------------------------------------------
 enum _SYSTEM_STATUS {
-    S_BOOTING =                         0,
+    S_BOOTING = 0,
     S_IDLE,
     S_AUTHORIZING,
     S_REASSIGN_CHECK,
@@ -73,7 +110,7 @@ enum _SYSTEM_STATUS {
 };
 
 enum _AC_SYSTEM_STATUS {
-    AC_SYS_NONE =   0,
+    AC_SYS_NONE = 0,
     AC_SYS_A,
     AC_SYS_B,
     AC_SYS_C,
@@ -82,159 +119,201 @@ enum _AC_SYSTEM_STATUS {
 };
 
 enum _GUN_TYPE {
-    _Type_Chademo =         0,
+    _Type_Chademo = 0,
     _Type_CCS_2,
     _Type_GB,
     _Type_AC,
 };
 
 enum _LCM_INDEX {
-    _LCM_INIT =             0x00,
-    _LCM_IDLE =             0x01,
-    _LCM_AUTHORIZING =      0x02,
-    _LCM_AUTHORIZ_COMP =    0x03,
-    _LCM_AUTHORIZ_FAIL =    0x04,
-    _LCM_WAIT_FOR_PLUG =    0x05,
-    _LCM_PRE_CHARGE =       0x06,
-    _LCM_CHARGING =         0x07,
-    _LCM_COMPLETE =         0x08,
-    _LCM_FIX =              0x09,
-    _LCM_SELECT_GUN =       0x0A,
-    _LCM_NONE =             0xFF,
+    _LCM_INIT          = 0x00,
+    _LCM_IDLE          = 0x01,
+    _LCM_AUTHORIZING   = 0x02,
+    _LCM_AUTHORIZ_COMP = 0x03,
+    _LCM_AUTHORIZ_FAIL = 0x04,
+    _LCM_WAIT_FOR_PLUG = 0x05,
+    _LCM_PRE_CHARGE    = 0x06,
+    _LCM_CHARGING      = 0x07,
+    _LCM_COMPLETE      = 0x08,
+    _LCM_FIX           = 0x09,
+    _LCM_SELECT_GUN    = 0x0A,
+    _LCM_NONE          = 0xFF,
 };
 
 enum _SELF_TEST_SEQ {
-    _STEST_VERSION = 0x00,
+    _STEST_VERSION      = 0x00,
     _STEST_AC_CONTACTOR = 0x01,
-    _STEST_PSU_DETECT = 0x02,
-    _STEST_PSU_CAP = 0x03,
-    _STEST_FAIL = 0x04,
-    _STEST_COMPLETE = 0xEE,
+    _STEST_PSU_DETECT   = 0x02,
+    _STEST_PSU_CAP      = 0x03,
+    _STEST_FAIL         = 0x04,
+    _STEST_COMPLETE     = 0xEE,
 };
 
 enum _MODULE_PSU_WORK_STEP {
-    INITIAL_START       =       0,
-    GET_PSU_COUNT       =       1,
-    GET_SYS_CAP         =       2,
-    BOOTING_COMPLETE    =       3,
+    INITIAL_START    = 0,
+    GET_PSU_COUNT    = 1,
+    GET_SYS_CAP      = 2,
+    BOOTING_COMPLETE = 3,
 
-    _WORK_CHARGING      =       10,
+    _WORK_CHARGING   = 10,
 
-    _TEST_MODE          =       20,
+    _TEST_MODE       = 20,
 
-    _NO_WORKING         =       254,
-    _INIT_PSU_STATUS    =       255
+    _NO_WORKING      = 254,
+    _INIT_PSU_STATUS = 255,
 };
 
 enum _OFFLINE_POLICY {
-    _OFFLINE_POLICY_LOCAL_LIST = 0x00,
+    _OFFLINE_POLICY_LOCAL_LIST       = 0x00,
     _OFFLINE_POLICY_PHIHONG_RFID_TAG = 0x01,
-    _OFFLINE_POLICY_FREE_CHARGING = 0x02,
-    _OFFLINE_POLICY_NO_CHARGING = 0x03,
+    _OFFLINE_POLICY_FREE_CHARGING    = 0x02,
+    _OFFLINE_POLICY_NO_CHARGING      = 0x03,
 };
 
 enum _REASSIGNED_RESOURCE_STEP {
-    _REASSIGNED_NONE =              0,  //
-    _REASSIGNED_PREPARE_M_TO_A =    1,  // 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
-    _REASSIGNED_GET_NEW_CAP =       2,  // 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
-    _REASSIGNED_ADJUST_M_TO_A =     3,  // 模塊重新分配完成
-    _REASSIGNED_RELAY_M_TO_A =      4,  // 切斷橋接的 Relay
-
-    _REASSIGNED_PREPARE_A_TO_M =    11,
-    _REASSIGNED_ADJUST_A_TO_M =     12, // 模塊升壓
-    _REASSIGNED_RELAY_A_TO_M =      13, // 搭接橋接的 Relay
-    _REASSIGNED_WAITING =           14,
-    _REASSIGNED_COMP =              15
+    _REASSIGNED_NONE           = 0,  //
+    _REASSIGNED_PREPARE_M_TO_A = 1,  // 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
+    _REASSIGNED_GET_NEW_CAP    = 2,  // 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
+    _REASSIGNED_ADJUST_M_TO_A  = 3,  // 模塊重新分配完成
+    _REASSIGNED_RELAY_M_TO_A   = 4,  // 切斷橋接的 Relay
+
+    _REASSIGNED_PREPARE_A_TO_M = 11,
+    _REASSIGNED_ADJUST_A_TO_M  = 12, // 模塊升壓
+    _REASSIGNED_RELAY_A_TO_M   = 13, // 搭接橋接的 Relay
+    _REASSIGNED_WAITING        = 14,
+    _REASSIGNED_COMP           = 15,
 };
 
 enum _MAIN_CHARGING_MODE {
-    _MAIN_CHARGING_MODE_MAX = 0,
+    _MAIN_CHARGING_MODE_MAX  = 0,
     _MAIN_CHARGING_MODE_AVER = 1,
 };
 
 enum _EXTRA_ERR_PROCESS {
-    _EXTRA_ERR_PROCESS_NONE = 0,
+    _EXTRA_ERR_PROCESS_NONE  = 0,
     _EXTRA_ERR_PROCESS_INUVP = 1,
-    _EXTRA_ERR_PROCESS_INOVP = 2
+    _EXTRA_ERR_PROCESS_INOVP = 2,
 };
 
 enum _CHARGER_TYPE {
     _CHARGER_TYPE_IEC = 0,
-    _CHARGER_TYPE_UL = 1,
+    _CHARGER_TYPE_UL  = 1,
 };
 
 enum _SYS_WIFI_MODE {
     _SYS_WIFI_MODE_DISABLE = 0,
     _SYS_WIFI_MODE_STATION = 1,
-    _SYS_WIFI_MODE_AP = 2
+    _SYS_WIFI_MODE_AP      = 2,
 };
 
 enum _LED_INTENSITY_LV {
     _LED_INTENSITY_DARKEST   = 0,
     _LED_INTENSITY_MEDIUM    = 1,
-    _LED_INTENSITY_BRIGHTEST = 2
+    _LED_INTENSITY_BRIGHTEST = 2,
 };
 
 enum _CCS_COMM_PROTOCOL {
-    _CCS_COMM_V2GMessage_DIN70121       = 0x01,
-    _CCS_COMM_V2GMessage_ISO15118_2014  = 0x02,
-    _CCS_COMM_V2GMessage_ISO15118_2018  = 0x03
+    _CCS_COMM_V2GMessage_DIN70121      = 0x01,
+    _CCS_COMM_V2GMessage_ISO15118_2014 = 0x02,
+    _CCS_COMM_V2GMessage_ISO15118_2018 = 0x03
 };
 
 enum _ETHERNET_USAGE {
-    _ETHERNET_USAGE_NONE    = 0,
+    _ETHERNET_USAGE_NONE = 0,
     _ETHERNET_USAGE_LAN,
     _ETHERNET_USAGE_WIFI,
-    _ETHERNET_USAGE_3G_4g
+    _ETHERNET_USAGE_3G_4g,
 };
 
 enum _PRIMARY_CHECK_TAG {
-    _PRIMARY_CHECK_TAG_AC_CONTACT       = 0,
-    _PRIMARY_CHECK_TAG_MAIN_BREAKER     = 1,
+    _PRIMARY_CHECK_TAG_AC_CONTACT   = 0,
+    _PRIMARY_CHECK_TAG_MAIN_BREAKER = 1,
+};
+
+enum _CCS_VERSION_CHECK_TAG {
+    _CCS_VERSION_CHECK_TAG_V015S0 = 0,
+    _CCS_VERSION_CHECK_TAG_V013S0 = 1,
+};
+
+enum RELAY_STATUS_ERROR_INDEX {
+    RELAY_SMR1_P_STATUS = 0,
+    RELAY_SMR1_N_STATUS = 1,
+    RELAY_SMR2_P_STATUS = 2,
+    RELAY_SMR2_N_STATUS = 3,
+    RELAY_PARA_P_STATUS = 4,
+    RELAY_PARA_N_STATUS = 5,
+};
+
+enum RELAY_STATUS_ERROR_TYPE {
+    RELAY_STATUS_ERROR_NONE    = 0,
+    RELAY_STATUS_ERROR_WELDING = 10,
+    RELAY_STATUS_ERROR_DRIVING = 11,
 };
 
+//------------------------------------------------------------------------------
 struct StructMeter {
     float curMeterValue;
     float newMeterValue;
-    byte isCalculation;
+    uint8_t isCalculation;
     float _chargingValue;
     float _curTotalCharging;
 };
 
 struct MeterInformation {
     struct StructMeter _meter[2];
-    byte isWorking;
-};
-
-enum _CCS_VERSION_CHECK_TAG {
-    _CCS_VERSION_CHECK_TAG_V015S0       = 0,
-    _CCS_VERSION_CHECK_TAG_V013S0       = 1,
-};
-
-enum RELAY_STATUS_ERROR_INDEX {
-    RELAY_SMR1_P_STATUS =   0,
-    RELAY_SMR1_N_STATUS =   1,
-    RELAY_SMR2_P_STATUS =   2,
-    RELAY_SMR2_N_STATUS =   3,
-    RELAY_PARA_P_STATUS =   4,
-    RELAY_PARA_N_STATUS =   5,
-};
-
-enum RELAY_STATUS_ERROR_TYPE {
-    RELAY_STATUS_ERROR_NONE = 0,
-    RELAY_STATUS_ERROR_WELDING = 10,
-    RELAY_STATUS_ERROR_DRIVING = 11
+    uint8_t isWorking;
 };
 
 struct DcCommonInformation {
     // check if the guns are of the same type
-    byte SysGunAreSameType;
+    uint8_t SysGunAreSameType;
     // to check the ccs version
-    byte CcsVersion;
+    uint8_t CcsVersion;
     // for relay welding/driving check
     char RelayCheckStatus[6];
     char GunRelayWeldingOccur[2];
     char GunRelayDrivingOccur[2];
 };
 
+typedef union {
+    uint32_t GunErrMessage;
+    struct {
+        // Chademo
+        uint8_t ChaGfdTrip: 1;
+        uint8_t ChaUvpFail: 1;
+        uint8_t ChaConnectOTP: 1;
+        uint8_t ChaConnectOVP: 1;
+        uint8_t ChaGfdWarning: 1;
+        uint8_t ChaRelayWeldingFault: 1;
+        uint8_t ChaRelayDrivingFault: 1;
+        uint8_t ChaConnectTempSensorFail: 1;
+
+        // CCS
+        uint8_t CCSGfdTrip : 1;
+        uint8_t CCSUvpFail : 1;
+        uint8_t CCSConnectOTP : 1;
+        uint8_t CCSConnectOVP : 1;
+        uint8_t CCSGfdWarning : 1;
+        uint8_t CCSRelayWeldingFault : 1;
+        uint8_t CCSRelayDrivingFault : 1;
+        uint8_t CCSConnectTempSensorFail : 1;
+
+        // GBT
+        uint8_t GBTGfdTrip : 1;
+        uint8_t GBTUvpFail : 1;
+        uint8_t GBTConnectOTP : 1;
+        uint8_t GBTConnectOVP : 1;
+        uint8_t GBTGfdWarning : 1;
+        uint8_t GBTRelayWeldingFault : 1;
+        uint8_t GBTRelayDrivingFault : 1;
+        uint8_t GBTConnectTempSensorFail : 1;
+    } GunBits;
+} EvBoardErrMsg;
+
+typedef struct StDcCommonInfo {
+    uint8_t RebootCount;
+    EvBoardErrMsg ConnectErrList[2]; //connector error list, 0: left gun, 1: right gun
+    uint8_t Reserved[3];
+} DcCommonInfo;
+
 #endif /* CONFIG_H_ */

+ 0 - 1252
EVSE/Projects/DD360/Apps/DoComm.c

@@ -1,1252 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/can.h>
-#include    <linux/can/raw.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-#include <signal.h>
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    "../../define.h"
-#include    "Config.h"
-
-//#define Debug
-
-#define DoIPAddress "192.168.100.1"
-#define DoTcpPort       36000
-#define TriggerMsgeNum      20
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-struct ApplicationPacket {
-    unsigned char Se;
-    unsigned char Id;
-    unsigned char Op;
-    unsigned char Len;
-    unsigned char RegisterNum;
-    unsigned char Data[250];
-};
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PsuData              *ShmPsuData;
-struct OCPP16Data               *ShmOCPP16Data;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-int                             TcpSock = 0;
-unsigned char                   PacketSe;
-struct ChargingInfoData         *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeb                    TriggerTimeUp[2][TriggerMsgeNum];
-struct WARNING_CODE_INFO        PreSysWarningInfo;
-int DisconnectFlag;
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-int InitShareMemory()
-{
-    int result = 1;
-    int MeterSMId;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-        result = 0;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-        result = 0;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-        result = 0;
-    }
-    //creat ShmPsuData
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPsuData NG \n");
-        result = 0;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPsuData NG \n");
-        result = 0;
-    }
-    //creat ShmOCPP16Data
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
-        result = 0;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-        result = 0;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-        result = 0;
-    }
-    return result;
-}
-
-int CheckNetworkStatus()
-{
-    //printf("ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress=%s\n",ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
-    if (strstr(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, "192.168.100") != NULL) {
-        return 1;
-    } else {
-        return 0;
-    }
-}
-
-int TcpConnected()
-{
-    struct sockaddr_in dest;
-    struct timeval tv;
-    int flag;
-
-    if (TcpSock > 0) {
-        close(TcpSock);
-    }
-
-    if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-        DEBUG_ERROR("Open TCP socket NG");
-        return -1;
-    }
-    /*   flag=fcntl (TcpSock, F_GETFL, 0);
-       if(flag>=0)
-       {
-           flag |= O_NONBLOCK;
-           fcntl(TcpSock,F_SETFL, flag );
-       }*/
-    tv.tv_sec = 0;
-    tv.tv_usec = 100000;
-    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
-    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
-    flag = 1;
-    setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
-
-    memset(&dest, 0, sizeof(dest));
-    dest.sin_family = AF_INET;
-    dest.sin_port = htons(DoTcpPort);
-    inet_aton(DoIPAddress, (struct in_addr *) &dest.sin_addr.s_addr);
-
-    if (connect(TcpSock, (struct sockaddr *) &dest, sizeof(dest)) != 0) {
-        close(TcpSock);
-        return -1;
-    }
-    return TcpSock;
-}
-void AddFaultCodeToBuf(unsigned char *Code)
-{
-    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, strlen(Code));
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
-    }
-}
-
-void RemoveFaultCodeToBuf(unsigned char *Code)
-{
-    unsigned char find = 0x01;
-    char _code[7];
-    sprintf(_code, "%s", Code);
-
-    // 把相關的錯誤碼一次移除,避免重複顯示
-    while (find) {
-        find = 0x00;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-            if (find == 0x00) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
-                    find = 0x01;
-                }
-            } else {
-                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
-            }
-        }
-
-        if (find) {
-            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
-        }
-    }
-}
-
-int StatusCodeProcessing(unsigned char *StatusCode)
-{
-    unsigned char Rtn = 0;
-    int ByteCount, BitCount;
-    unsigned char tmp, EventCodeTmp[7];
-
-    if (strlen(StatusCode) != 6) {
-        return 0;
-    }
-    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-    memcpy(EventCodeTmp, StatusCode, strlen(StatusCode));
-
-    if (*(StatusCode + 1) == 0x34) { //alarm from power cabinet itself
-        if (StatusCode[0] == 0x30) { //trigger
-            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], EventCodeTmp, 7) == 0) {
-                    Rtn = 1;
-                    break;
-                }
-            }
-            if (Rtn == 0) {
-                AddFaultCodeToBuf(EventCodeTmp);
-            }
-            Rtn = 1;
-        } else if (StatusCode[0] == 0x31) { //recovery
-            RemoveFaultCodeToBuf(EventCodeTmp);
-            Rtn = 1;
-        }
-    } else {
-        switch (*(StatusCode + 2)) {
-        case 0x31://Fault
-            for (ByteCount = 0; ByteCount < (sizeof(FaultStatusCode) / 6); ByteCount++) {
-                if (memcmp(FaultStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
-                    if (StatusCode[0] == 0x30) { //trigger
-                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] |= 1 << (ByteCount % 8);
-                    } else if (StatusCode[0] == 0x31) { //recovery
-                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] &= 0 << (ByteCount % 8);
-                    }
-                    Rtn = 1;
-                    break;
-                }
-            }
-            break;
-        case 0x32://Alarm
-            for (ByteCount = 0; ByteCount < (sizeof(AlarmStatusCode) / 6); ByteCount++) {
-                if (memcmp(AlarmStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
-
-                    if (StatusCode[0] == 0x30) { //trigger
-                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] |= 1 << (ByteCount % 8);
-                    } else if (StatusCode[0] == 0x31) { //recovery
-                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] &= 0 << (ByteCount % 8);
-                    }
-                    Rtn = 1;
-                    break;
-                }
-            }
-            break;
-        case 0x33://Information
-            for (ByteCount = 0; ByteCount < (sizeof(InfoStatusCode) / 6); ByteCount++) {
-                if (memcmp(InfoStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
-                    if (StatusCode[0] == 0x30) { //trigger
-                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] |= 1 << (ByteCount % 8);
-                    } else if (StatusCode[0] == 0x31) { //recovery
-                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] &= 0 << (ByteCount % 8);
-                    }
-                    Rtn = 1;
-                    break;
-                }
-            }
-            break;
-        default:
-            break;
-        }
-    }
-
-    return Rtn;
-}
-
-int SendPacket(unsigned char Id, unsigned char Op, unsigned char RegNum, unsigned char DataLen, unsigned char *Data)
-{
-    int Rtn = 0, PacketLen, Tmp;
-    struct ApplicationPacket SendBuffer;
-    struct timeb ST, ET;
-
-    memset(&SendBuffer, 0, sizeof(struct ApplicationPacket));
-    SendBuffer.Se = (PacketSe++);
-    SendBuffer.Id = Id;
-    SendBuffer.Op = Op;
-    SendBuffer.Len = DataLen + 1;
-    SendBuffer.RegisterNum = RegNum;
-    if (DataLen > 0) {
-        memcpy(SendBuffer.Data, Data, DataLen);
-    }
-    PacketLen = SendBuffer.Len + 4;
-    ftime(&ST);
-    while (Rtn < PacketLen) {
-        Tmp = send(TcpSock, &SendBuffer + Rtn, PacketLen - Rtn, MSG_NOSIGNAL);
-        if (Tmp > 0) {
-            Rtn += Tmp;
-        }
-        ftime(&ET);
-        if (DiffTimeb(ST, ET) > 500) {
-            DisconnectFlag++;
-            if (DisconnectFlag >= 10) {
-                DisconnectFlag = 10;
-            }
-#ifdef Debug
-            printf("Send Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-                   Rtn, PacketLen, PacketSe, Id, Op, RegNum);
-#endif
-            return 0;
-        }
-    }
-    return Rtn;
-}
-
-int RecvPacket(unsigned char *DataLen, struct ApplicationPacket *Packet)
-{
-    int Rtn = 0, Tmp;
-    unsigned char TmpBuf[250];
-    struct timeb ST, ET;
-
-    memset(Packet, 0, sizeof(struct ApplicationPacket));
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    ftime(&ST);
-    while (Rtn < 5) {
-        Tmp = recv(TcpSock, TmpBuf + Rtn, 5 - Rtn, 0);
-        if (Tmp > 0) {
-            Rtn += Tmp;
-        }
-        ftime(&ET);
-        if (DiffTimeb(ST, ET) > 500) {
-            DisconnectFlag++;
-            if (DisconnectFlag >= 10) {
-                DisconnectFlag = 10;
-            }
-#ifdef Debug
-            printf("Recv Packet header Timeout(%d/5)(disconnect count=%d): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-                   Rtn, DisconnectFlag, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
-#endif
-            return 0;
-        }
-    }
-    if ((TmpBuf[0] > 255)/*||(TmpBuf[1]>2)*/ || (TmpBuf[2] > 3) || (TmpBuf[3] > 250)) {
-        DEBUG_INFO("Recv Wrong Packet header (%d/5): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-                   Rtn, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
-        return 0;
-    }
-    memcpy(Packet, TmpBuf, 5);
-    *DataLen = Packet->Len - 1;
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    Rtn = 0;
-    ftime(&ST);
-    while (Rtn < *DataLen) {
-        Tmp = recv(TcpSock, TmpBuf + Rtn, *DataLen - Rtn, 0);
-        if (Tmp > 0) {
-            Rtn += Tmp;
-        }
-        ftime(&ET);
-        if (DiffTimeb(ST, ET) > 500) {
-            DEBUG_INFO("Recv Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-                       Rtn, *DataLen, Packet->Se, Packet->Id, Packet->Op, Packet->RegisterNum);
-            return 0;
-        }
-    }
-    memcpy(Packet->Data, TmpBuf, *DataLen);
-    DisconnectFlag = 0;
-    return Rtn;
-}
-
-int WriteModelName()
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    memcpy(TmpBuf, ShmSysConfigAndInfo->SysConfig.ModelName, strlen(ShmSysConfigAndInfo->SysConfig.ModelName));
-    Tmp = (unsigned char)(ShmPrimaryMcuData->InputDet.bits.Key2 << 2 | ShmPrimaryMcuData->InputDet.bits.Key1 << 1 | ShmPrimaryMcuData->InputDet.bits.Key0);
-    TmpBuf[strlen(ShmSysConfigAndInfo->SysConfig.ModelName)] = Tmp; //Dispenser switch value
-#ifdef Debug
-    printf("WriteModelName(%s)(%d) => ", ShmSysConfigAndInfo->SysConfig.ModelName, Tmp);
-#endif
-    if (SendPacket(0xFF, 0x02, 0x01, strlen(ShmSysConfigAndInfo->SysConfig.ModelName) + 1, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("OK\n");
-#endif
-    return 1;
-}
-
-int ReadConnectorID()
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-#ifdef Debug
-    printf("ReadConnectorID => ");
-#endif
-    if (SendPacket(0xFF, 0x01, 0x02, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("OK (Left connector ID = %d, Right connector ID = %d)\n", PacketData.Data[1], PacketData.Data[2]);
-#endif
-    return 1;
-}
-
-int ReadDoStatus()
-{
-    unsigned char Tmp = 0, count, Rtn;
-    struct ApplicationPacket PacketData;
-    unsigned char StatusArray[20][6];
-    unsigned char EventCodeTmp[7];
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    memset(StatusArray, 0, sizeof(StatusArray));
-#ifdef Debug
-    printf("ReadDoStatus => ");
-#endif
-    if (SendPacket(0x01, 0x01, 0x03, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-    Tmp--;//decrase OK/NG byte
-    if (Tmp < 6) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
-            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-                if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
-                    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                    memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
-                    RemoveFaultCodeToBuf(EventCodeTmp);
-                }
-            }
-        }
-#ifdef Debug
-        printf("no alarm (%d)\n", Tmp);
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("OK, (%d) ", Tmp);
-    //printf("PacketData.Se=%d\n",PacketData.Se);
-    //printf("PacketData.Id=%d\n",PacketData.Id);
-    //printf("PacketData.Op=%d\n",PacketData.Op);
-    //printf("PacketData.Len=%d\n",PacketData.Len);
-    //printf("PacketData.RegisterNum=%d\n",PacketData.RegisterNum);
-    //for(Rtn=0;Rtn<=PacketData.Len-1;Rtn++)
-    //printf("PacketData.Data[%d]=0x%x\n",Rtn,PacketData.Data[Rtn]);
-#endif
-    for (count = 0; count < Tmp; count += 6) {
-        //if((Tmp-count)<6)
-        strncpy(StatusArray[count / 6], (PacketData.Data + 1) + count, 6);
-        Rtn = 0;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-            if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count / 6], 6) == 0) {
-                Rtn = 1;
-                break;
-            }
-        }
-        if (Rtn == 0) {
-            AddFaultCodeToBuf(StatusArray[count / 6]);
-        }
-        //Rtn=StatusCodeProcessing(StatusArray[count/6]);
-#ifdef Debug
-        printf("(%d)(%s) = %s,  ", count / 6, Rtn == 1 ? "Process OK" : "Process NG", StatusArray[count / 6]);
-#endif
-    }
-    for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
-            Rtn = 0;
-            for (count = 0; count < (Tmp / 6); count++) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count], 6) == 0) {
-                    Rtn = 1;
-                    break;
-                }
-            }
-            if (Rtn == 0) {
-                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
-                RemoveFaultCodeToBuf(EventCodeTmp);
-            }
-        }
-    }
-#ifdef Debug
-    printf("\n");
-#endif
-    return 1;
-}
-
-int WriteDdStatus()
-{
-    unsigned char Tmp = 0, count;
-    unsigned char TmpBuf[255], CurWarnCodeTmp[10][6], PreWarnCodeTmp[10][6];
-    struct ApplicationPacket PacketData;
-
-    if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) && (PreSysWarningInfo.WarningCount <= 0)) {
-        return -1;
-    }
-    memset(CurWarnCodeTmp, 0, sizeof(CurWarnCodeTmp));
-    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-    for (count = 0; count < Tmp; count++) {
-        memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], 6);
-    }
-    memset(PreWarnCodeTmp, 0, sizeof(PreWarnCodeTmp));
-    Tmp = PreSysWarningInfo.WarningCount;
-    for (count = 0; count < Tmp; count++) {
-        memcpy(PreWarnCodeTmp[count], PreSysWarningInfo.WarningCode[count], 6);
-    }
-    if (strcmp(CurWarnCodeTmp, PreWarnCodeTmp) == 0) {
-        return -1;
-    }
-
-
-    /*memset(TmpBuf,0,sizeof(TmpBuf));
-    Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-    for(count=0;count<Tmp;count++)
-    {
-        memcpy(TmpBuf+(count*6),ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
-        #ifdef Debug
-        printf("WriteDdStatus(%d) = %s", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
-        #endif
-    }
-    if(SendPacket(0x01, 0x02, 0x04,strlen(TmpBuf), TmpBuf)<=0)
-        return -1;
-    */
-#ifdef Debug
-    printf("WriteDdStatus => ");
-#endif
-    if (SendPacket(0x01, 0x02, 0x04, strlen(CurWarnCodeTmp), CurWarnCodeTmp) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
-    memcpy(&PreSysWarningInfo, &(ShmSysConfigAndInfo->SysWarningInfo), sizeof(struct WARNING_CODE_INFO));
-#ifdef Debug
-    printf("OK,  ");
-    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-    for (count = 0; count < Tmp; count++) {
-        printf("(%d)%s,  ", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
-    }
-    printf("\n");
-#endif
-    return 1;
-}
-
-int ReadChargingCapability(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-    float MaxVolt, MaxCurrent, MaxPower;
-
-#ifdef Debug
-    printf("Read Charging Capability => ");
-#endif
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    if (SendPacket(PlugNum, 0x01, 0x05, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-    MaxVolt = (float)(PacketData.Data[1] << 8 | PacketData.Data[2]);
-    MaxCurrent = (float)(PacketData.Data[3] << 8 | PacketData.Data[4]);
-    MaxPower = (float)(PacketData.Data[5] << 8 | PacketData.Data[6]);
-    if ((MaxVolt >= 0) && (MaxVolt <= 10000)) {
-        ChargingData[PlugNum - 1]->MaximumChargingVoltage = MaxVolt;
-    }
-    if ((MaxCurrent >= 0) && (MaxCurrent <= 5000)) {
-        ChargingData[PlugNum - 1]->AvailableChargingCurrent = MaxCurrent;
-    }
-    if ((MaxPower >= 0) && (MaxPower <= 3600)) {
-        ChargingData[PlugNum - 1]->AvailableChargingPower = MaxPower;
-    }
-#ifdef Debug
-    printf(" MaxVolt=%f, MaxCurrent=%f, MaxPower=%f,\n", MaxVolt, MaxCurrent, MaxPower);
-#endif
-    return 1;
-}
-
-int WriteChargingTarget(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-    float ChargingVolt, ChargingAmp;
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    ChargingVolt = ChargingData[PlugNum - 1]->EvBatterytargetVoltage;
-    ChargingAmp = ChargingData[PlugNum - 1]->EvBatterytargetCurrent;
-    ChargingVolt *= 10;
-    ChargingAmp *= 10;
-    TmpBuf[0] = ((unsigned short)ChargingVolt >> 8) & 0xFF;
-    TmpBuf[1] = ((unsigned short)ChargingVolt) & 0xFF;
-    TmpBuf[2] = ((unsigned short)ChargingAmp >> 8) & 0xFF;
-    TmpBuf[3] = ((unsigned short)ChargingAmp) & 0xFF;
-#ifdef Debug
-    printf("WriteChargingTarget(%d), EvBatterytargetVoltage=%f,EvBatteryMaxVoltage=%f => ",
-           PlugNum, ChargingData[PlugNum - 1]->EvBatterytargetVoltage, ChargingData[PlugNum - 1]->EvBatteryMaxVoltage);
-#endif
-    if (SendPacket(PlugNum, 0x02, 0x06, 4, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("ChargingVolt=%f, ChargingAmp=%f\n", ChargingVolt / 10, ChargingAmp / 10);
-#endif
-
-    return 1;
-}
-int ReadSoftwareUpdate()
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    if (SendPacket(0x01, 0x01, 0x07, 0, PacketData.Data) <= 0) {
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-        return -1;
-    }
-    if (PacketData.Data[1] != 0x01) { //not update
-        return -1;
-    }
-    return PacketData.Data[1];
-}
-int WritePlugInStatus(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    TmpBuf[0] = ChargingData[PlugNum - 1]->ConnectorPlugIn;
-#ifdef Debug
-    printf("WritePlugInStatus(%d) =>", PlugNum);
-#endif
-    if (SendPacket(PlugNum, 0x02, 0x08, 1, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" %s\n", TmpBuf[0] == 1 ? "Plug-in" : "Un-plug");
-#endif
-
-    return 1;
-}
-
-int WriteConnectorState(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    if (ChargingData[PlugNum - 1]->SystemStatus <= 2) {
-        TmpBuf[0] = 0;    //idle
-    } else if ((ChargingData[PlugNum - 1]->SystemStatus <= 7) || (ChargingData[PlugNum - 1]->SystemStatus == 17) || (ChargingData[PlugNum - 1]->SystemStatus == 18)) {
-        TmpBuf[0] = 1;    //preparing
-    } else if (ChargingData[PlugNum - 1]->SystemStatus == 8) {
-        TmpBuf[0] = 2;    //charging
-    } else if (ChargingData[PlugNum - 1]->SystemStatus == 9) {
-        TmpBuf[0] = 3;    //terminating
-    }
-
-#ifdef Debug
-    printf("WriteConnectorState(%d) SystemStatus=%d,TmpBuf[0]=%d => ", PlugNum, ChargingData[PlugNum - 1]->SystemStatus, TmpBuf[0]);
-#endif
-    if (SendPacket(PlugNum, 0x02, 0x09, 1, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" %d\n", TmpBuf[0]);
-#endif
-
-    return 1;
-}
-
-int WriteUserID(unsigned char ConnectorID, unsigned char *UserID)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-    if (strlen(UserID) <= 0) {
-        return -1;
-    }
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    strcpy(TmpBuf, UserID);
-#ifdef Debug
-    printf("WriteUserID(%d) => ", ConnectorID);
-#endif
-    if (SendPacket(ConnectorID, 0x02, 0x0A, strlen(TmpBuf), TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" StartUserId=%s, PacketData.Data[1]=%d\n", TmpBuf, PacketData.Data[1]);
-#endif
-    return PacketData.Data[1];
-}
-
-int ReadChargePermission(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-#ifdef Debug
-    printf("ReadChargePermission[%d] => ", PlugNum);
-#endif
-    if (SendPacket(PlugNum, 0x01, 0x0B, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" %s\n", PacketData.Data[1] == 1 ? "Permitted" : "NOT permitted" );
-#endif
-
-    return PacketData.Data[1];
-}
-
-int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-int MessageTrigger(unsigned char connectorID)
-{
-    struct timeb  NowTime;
-    unsigned char Reg;
-    for (Reg = 0; Reg < TriggerMsgeNum; Reg++) {
-        ftime(&NowTime);
-        switch (Reg) {
-        case 3://ReadDoStatus
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (ReadDoStatus()) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        case 4://WriteDdStatus
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (WriteDdStatus()) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        /*case 5://ReadChargingCapability
-            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>200)
-            {
-                if(ReadChargingCapability(connectorID))
-                {
-                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
-                }
-            }
-            break;
-        case 6://WriteChargingTarget
-            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>100)
-            {
-                if(WriteChargingTarget(connectorID))
-                {
-                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
-                }
-            }
-            break;*/
-        case 8://WritePlugInStatus
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (WritePlugInStatus(connectorID)) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        case 9://WriteConnectorState
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (WriteConnectorState(connectorID)) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        /*case 0x0B://ReadChargePermission
-            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-            {
-                if(ReadChargePermission(connectorID))
-                {
-                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
-                }
-            }
-            break;*/
-        default:
-            break;
-        }
-    }
-}
-
-int main(int argc, char *argv[])
-{
-    unsigned char Tmp, PlugNum;
-    int Rtn;
-    struct timeb  AuthNowTime;
-
-    /**************** Initialization **********/
-    if (InitShareMemory() == 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-ReConnect:
-    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
-    PacketSe = 0;
-    DisconnectFlag = 0;
-    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-        if (!FindChargingInfoData(_index, &ChargingData[0])) {
-            DEBUG_ERROR("FindChargingInfoData false \n");
-            break;
-        }
-    }
-
-    /**************** Check Network **********/
-    DEBUG_INFO("Check Dispenser Network Information");
-    while (!CheckNetworkStatus()) {
-        sleep(1);
-        if (DisconnectFlag >= 10) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Dispenser Network Information checked: IP=%s Netmask=%s, Gateway=%s",
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-
-    /**************** Power cabinet connection **********/
-    DEBUG_INFO("Connect to Power Cabinet");
-    while (TcpConnected() < 0) {
-        sleep(1);
-        if (DisconnectFlag >= 5) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Power cabinet connected(TcpSock=%d): IP=%s Netmask=%s, Gateway=%s",
-               TcpSock,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-
-    /**************** Write Model Name**********/
-    DEBUG_INFO("Write Model Name");
-    while (WriteModelName() < 0) {
-        sleep(1);
-        if (DisconnectFlag >= 5) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Write Model Name OK: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
-
-    /**************** Get Connector ID**********/
-    DEBUG_INFO("Get Connector ID");
-    while (ReadConnectorID() < 0) {
-        sleep(1);
-        if (DisconnectFlag >= 5) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Get Connector ID OK");
-    /*while(1)
-    {
-        //for self testin main.c
-        if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq >= _STEST_PSU_DETECT)
-        {
-            ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
-            break;
-        }
-    }*/
-    for (Tmp = 0; Tmp < TriggerMsgeNum; Tmp++) {
-        ftime(&TriggerTimeUp[0][Tmp]);
-        ftime(&TriggerTimeUp[1][Tmp]);
-        usleep(50000);
-    }
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 0;
-    DEBUG_INFO("Start Communication");
-    /**************** Data transmission**********/
-    while (1) {
-        if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
-            ftime(&AuthNowTime);
-            if (DiffTimeb(TriggerTimeUp[0][10], AuthNowTime) > 1000) {
-                Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
-                if (Rtn >= 0) {
-                    memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-                    if (Rtn == 0) {
-                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
-                    } else {
-                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
-                    }
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
-                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
-                    ShmPsuData->SystemAvailablePower = 0;
-                    ShmPsuData->SystemPresentPsuQuantity = 0;
-                }
-                ftime(&TriggerTimeUp[0][10]);
-            }
-        }
-
-        for (PlugNum = 1; PlugNum <= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; PlugNum++) {
-            //printf("ChargingData[PlugNum-1]->SystemStatus=%d\n",ChargingData[PlugNum-1]->SystemStatus);
-            //printf("ShmOCPP16Data->SpMsg.bits.AuthorizeReq=%d\n",ShmOCPP16Data->SpMsg.bits.AuthorizeReq);
-            //printf("ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=%d\n",ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
-            //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-            //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-            switch (ChargingData[PlugNum - 1]->SystemStatus) {
-            case S_IDLE:
-            case S_RESERVATION:
-            case S_MAINTAIN:
-            case S_ALARM:
-            case S_AUTHORIZING:
-                if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
-                    ftime(&AuthNowTime);
-                    if (DiffTimeb(TriggerTimeUp[PlugNum - 1][10], AuthNowTime) > 1000) {
-                        Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
-                        if (Rtn >= 0) {
-                            memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-                            if (Rtn == 0) {
-                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
-                            } else {
-                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
-                            }
-                            ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
-                            ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
-                            ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
-                            ShmPsuData->SystemAvailablePower = 0;
-                            ShmPsuData->SystemPresentPsuQuantity = 0;
-                            ftime(&TriggerTimeUp[PlugNum - 1][10]);
-
-                        }
-                        ftime(&TriggerTimeUp[PlugNum - 1][10]);
-                    }
-                }
-                /*if(ReadSoftwareUpdate())//0x07
-                {
-                    //firmware update
-                }*/
-                break;
-            case S_PREPARNING: //get permission
-                //printf("S_PREPARNING\n");
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if ((ReadChargePermission(PlugNum)) && (ReadChargingCapability(PlugNum))) {
-                        ShmPsuData->SystemAvailablePower = ChargingData[0]->AvailableChargingPower + ChargingData[1]->AvailableChargingPower;
-                        ShmPsuData->SystemPresentPsuQuantity = ShmPsuData->SystemAvailablePower / 30;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                break;
-            case S_PREPARING_FOR_EV://wait connector lock
-                //printf("S_PREPARING_FOR_EV\n");
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
-                    ReadChargingCapability(PlugNum);
-                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
-                }
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if (ReadChargePermission(PlugNum) == 0) {
-                        DEBUG_INFO("Stop charging by power cabinet's permission");
-                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                break;
-            case S_PREPARING_FOR_EVSE: //insaulation test
-            case S_CCS_PRECHARGE_ST0:
-            case S_CCS_PRECHARGE_ST1:
-                //printf("S_PREPARING_FOR_EVSE\n");
-                WriteChargingTarget(PlugNum);
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
-                    ReadChargingCapability(PlugNum);
-                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
-                }
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if (ReadChargePermission(PlugNum) == 0) {
-                        DEBUG_INFO("Stop charging by power cabinet's permission");
-                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                break;
-            case S_CHARGING: //charging
-            case S_TERMINATING:
-                //printf("S_CHARGING,S_TERMINATING\n");
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
-                    ReadChargingCapability(PlugNum);
-                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
-                }
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if (ReadChargePermission(PlugNum) == 0) {
-                        DEBUG_INFO("Stop charging by power cabinet's permission");
-                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                WriteChargingTarget(PlugNum);
-                //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-                //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-                break;
-            default:
-                break;
-            }//switch   case
-            MessageTrigger(PlugNum);
-        }//for connector #
-        if (DisconnectFlag >= 10) {
-            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == 0) {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-                DEBUG_INFO("Disconnected from power cabinet...re-connecting");
-            }
-            goto ReConnect;
-        }
-    }//while(1)
-}

+ 0 - 196
EVSE/Projects/DD360/Apps/Ev_Comm.c

@@ -1,196 +0,0 @@
-#include "Module_EvComm.h"
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<string.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-
-//================================================
-//================================================
-// CANBUS send cmd
-//================================================
-//================================================
-
-int PackageIdCmd(int cmd)
-{
-	return cmd | 0x80000000;
-}
-
-void SendCmdToEvboard(int cmd, byte *data, byte dataLen)
-{
-    struct can_frame frame;
-
-    frame.can_id = cmd;
-    frame.can_dlc = dataLen;
-    memcpy(frame.data, data, sizeof(frame.data));
-
-    write(CanFd, &frame, sizeof(struct can_frame));
-}
-
-void SetTargetAddr(byte *target_number, byte index)
-{
-	int id = PackageIdCmd(Ev_Cmd.address_assignment + index);
-	//printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
-	//cmd = cmd & CAN_EFF_MASK;
-
-	byte data[8];
-
-	data[0] = *target_number;
-	data[1] = *(target_number + 1);
-	data[2] = *(target_number + 2);
-	data[3] = *(target_number + 3);
-	data[4] = index;
-
-	SendCmdToEvboard(id, data, 5);
-}
-
-void GetFirmwareVersion(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void SyncRtcInfo(byte gun_index, byte toId, int epoch)
-{
-	int id = PackageIdCmd(Ev_Cmd.sync_rtc_info + toId);
-	byte data[8];
-
-	data[0] = epoch & 0xff;
-	data[1] = (epoch >> 8) & 0xff;
-	data[2] = (epoch >> 16) & 0xff;
-	data[3] = (epoch >> 24) & 0xff;
-
-	SendCmdToEvboard(id, data, 4);
-}
-
-void GetHardwareVersion(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.charging_permission + toId);
-	byte data[8];
-
-	data[0] = permissionStatus;
-	data[1] = aOutputPw & 0xff;
-	data[2] = (aOutputPw >> 8) & 0xff;
-	data[3] = aOutputCur & 0xff;
-	data[4] = (aOutputCur >> 8) & 0xff;
-	data[5] = aOutputVol & 0xff;
-	data[6] = (aOutputVol >> 8) & 0xff;
-	data[7] = 0xf0;
-
-	SendCmdToEvboard(id, data, sizeof(data));
-}
-
-void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2)
-{
-	int id = PackageIdCmd(Ev_Cmd.present_output_power);
-	byte data[8];
-
-	data[0] = outputVol_b1 & 0xff;
-	data[1] = (outputVol_b1 >> 8) & 0xff;
-	data[2] = outputCur_b1 & 0xff;
-	data[3] = (outputCur_b1 >> 8) & 0xff;
-	data[4] = outputVol_b2 & 0xff;
-	data[5] = (outputVol_b2 >> 8) & 0xff;
-	data[6] = outputCur_b2 & 0xff;
-	data[7] = (outputCur_b2 >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 8);
-}
-
-void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2)
-{
-	int id = PackageIdCmd(Ev_Cmd.present_output_cap);
-	byte data[8];
-
-	data[0] = aOutputPw_b1 & 0xff;
-	data[1] = (aOutputPw_b1 >> 8) & 0xff;
-	data[2] = aOutputCur_b1 & 0xff;
-	data[3] = (aOutputCur_b1 >> 8) & 0xff;
-	data[4] = aOutputPw_b2 & 0xff;
-	data[5] = (aOutputPw_b2 >> 8) & 0xff;
-	data[6] = aOutputCur_b2 & 0xff;
-	data[7] = (aOutputCur_b2 >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 8);
-}
-
-void GetOutputReq(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_output_req + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void GetEvBatteryInfo(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_battery_info + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId);
-	byte data[8];
-
-	data[0] = stopResult;
-	data[1] = *stopReason;
-	data[2] = *(stopReason + 1);
-	data[3] = *(stopReason + 2);
-	data[4] = *(stopReason + 3);
-	data[5] = *(stopReason + 4);
-	data[6] = *(stopReason + 5);
-
-	SendCmdToEvboard(id, data, 7);
-}
-
-void GetMiscellaneousInfo(byte gun_index, byte relayStatus, float power, float voltage, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId);
-	byte data[8];
-
-	int _power = power * 10;
-
-	data[0] = relayStatus;
-	data[1] = (int)_power & 0xff;
-	data[2] = ((int)_power >> 8) & 0xff;
-	data[3] = (int)voltage & 0xff;
-	data[4] = ((int)voltage >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 5);
-}
-
-void SetIsolationStatus(byte gun_index, byte result, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.isolation_status + toId);
-	byte data[8];
-
-	data[0] = result;
-	SendCmdToEvboard(id, data, 1);
-}
-
-void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId);
-	byte data[8];
-
-	data[0] = result;
-	SendCmdToEvboard(id, data, 1);
-}
-

+ 3 - 8
EVSE/Projects/DD360/Apps/FactoryConfig.c

@@ -32,16 +32,11 @@
 #include    "Config.h"
 
 #define Debug
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
 #define OUTPUT_FLASH        0x01
 #define OUTPUT_FILE         0x02
 
 struct SysConfigData            SysConfig;
 
-int StoreLogMsg(const char *fmt, ...);
-
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -84,9 +79,9 @@ void helpOutput(void)
 /**************************************************************************************/
 int main(int argc, char *argv[])
 {
-    unsigned char outType = 0;
+    uint8_t outType = 0;
     unsigned int i, Chk, MtdBlockSize = 0x600000;
-    unsigned char *ptr;
+    uint8_t *ptr;
     int fd, wrd;
 
     ptr = malloc(MtdBlockSize);
@@ -134,7 +129,7 @@ int main(int argc, char *argv[])
     SysConfig.AcMaxChargingCurrent = 0;
     SysConfig.PhaseLossPolicy = 0;
     /*+++ 20200908, vern, modify it +++*/
-    /*for(unsigned char i = 0; i < 10; i++)
+    /*for(uint8_t i = 0; i < 10; i++)
         strcpy((char *)SysConfig.LocalWhiteCard, "");*/
     memset(SysConfig.LocalWhiteCard, 0, sizeof(SysConfig.LocalWhiteCard));
     /*--- 20200908, vern, modify it ---*/

+ 49 - 32
EVSE/Projects/DD360/Apps/Makefile

@@ -7,9 +7,27 @@ OutputPath = ../output
 
 DEFINE = -D $(Project)
 
-CFLAGS = -O0 -g3 -Wall -c -fmessage-length=0
+CFLAGS = -O0 -g3 -Wall -fmessage-length=0
 TFLAGS = -lrt -lm -lpthread
 
+TOP = .
+
+INC_FLAGS += -I $(TOP)/ModuleInternalComm
+INC_FLAGS += -I $(TOP)/ModuleEvComm
+INC_FLAGS += -I $(TOP)/ModulePrimary
+INC_FLAGS += -I $(TOP)/ModuleLcmCtrl
+INC_FLAGS += -I $(TOP)/ModuleDoComm
+INC_FLAGS += -I $(TOP)/ModuleEventLog
+
+InternalCommLib = $(TOP)/ModuleInternalComm
+EvCommLib = $(TOP)/ModuleEvComm
+PrimaryLib = $(TOP)/ModulePrimary
+LcmLib = $(TOP)/ModuleLcmCtrl
+DoCommLib = $(TOP)/ModuleDoComm
+EventLogLib = $(TOP)/ModuleEventLog
+ScriptLib = $(TOP)/Script
+
+
 #define library variable
 Internal485ProtocolLib = -L $(ModularizationPath)/Internal485Protocol -lInternal485Protocol
 #PsuCommProtocolLib = -L $(ModularizationPath)/PsuCommProtocol -lPsuCommProtocol
@@ -38,69 +56,68 @@ apps: MainTask DoCommTask EvCommTask \
 			PrimaryCommTask ReadCmdlineTask UnsafetyOutputTool \
 				FactoryConfigApp OtherTools CleanExec
 
-LOG_INC = Log
-
 MainTask:
-	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -o main.o ReMain.c
-	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -o timeout.o timeout.c
-	$(CC) $(TFLAGS) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
+	$(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) -D $(Project) -includeConfig.h $(CFLAGS) -o DoComm.o ReDoComm.c
-	$(CC) -o DoComm DoComm.o
+	$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
+	$(CC) -o Module_DoComm DoComm.o
 
 EvCommTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Ev_Comm.o Ev_Comm.c
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_EvComm.o ReModule_EvComm.c
-	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o
+	$(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) -D $(Project) -includeConfig.h $(SQLite3_H) $(CFLAGS) -o Module_EventLogging.o ReModule_EventLogging.c
+	$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
 	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3}
 
 InternalCommTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o internalComm.o internalComm.c
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_InternalComm.o ReModule_InternalComm.c
-	$(CC) -o Module_InternalComm Module_InternalComm.o internalComm.o
+	$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o internalComm.o $(InternalCommLib)/internalComm.c
+	$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o Module_InternalComm.o $(InternalCommLib)/Module_InternalComm.c
+	$(CC) $(TFLAGS) -o Module_InternalComm Module_InternalComm.o internalComm.o $(Lib_ModuleRelay)
 
 LcmControlTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_LcmControl.o ReModule_LcmControl.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
 	$(CC) -o Module_LcmControl Module_LcmControl.o
 
 PrimaryCommTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_PrimaryComm.o ReModule_PrimaryComm.c
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o PrimaryComm.o PrimaryComm.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
 	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
 
 PsuCommTask:
-	$(CC) -D $(Project) $(InfypwrPsuComm_H) -includeConfig.h $(CFLAGS) -o Module_PsuComm.o Module_PsuComm.c
+	$(CC) $(DEFINE) $(InfypwrPsuComm_H) $(CFLAGS) -c -o Module_PsuComm.o Module_PsuComm.c
 	$(CC) -o Module_PsuComm Module_PsuComm.o $(InfypwrPsuComm_A)
 
 ReadCmdlineTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o ReadCmdline.o ReadCmdline.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o ReadCmdline.o ReadCmdline.c
 	$(CC) -o ReadCmdline ReadCmdline.o
 
 UnsafetyOutputTool:
-	$(CC) -D $(Project) $(InfypwrPsuComm_H) $(CFLAGS) -o OutputTask.o OutputTask.c
+	$(CC) $(DEFINE) $(InfypwrPsuComm_H) $(CFLAGS) -c -o OutputTask.o OutputTask.c
 	$(CC) -o UnsafetyOutputTask OutputTask.o $(InfypwrPsuComm_A)
 
 FactoryConfigApp:
 	@echo "===== Module_FactoryConfig_Task =================================="
 	rm -f FactoryConfig
-#	gcc -D $(Project) "-I../../" -o FactoryConfig "./FactoryConfig.c"
+#	gcc -D $(DEFINE) "-I../../" -o FactoryConfig "./FactoryConfig.c"
 #	mkdir -p /Storage/SystemLog
 #	./FactoryConfig -f;true
 #	cp /mnt/FactoryDefaultConfig.bin ../Images
 #	rm -f FactoryConfig;
-	$(CC) -D $(Project) $(CFLAGS) -o FactoryConfig.o FactoryConfig.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o FactoryConfig.o FactoryConfig.c
 	$(CC) -o FactoryConfig FactoryConfig.o
 
 OtherTools:
-	cp -f init.sh $(RootPath)
-	cp -f kill.sh $(RootPath)
-	cp -f web.sh $(RootPath)
+	cp -f $(ScriptLib)/init.sh $(RootPath)
+	cp -f $(ScriptLib)/kill.sh $(RootPath)
+	cp -f $(ScriptLib)/web.sh $(RootPath)
 	cp -f main $(RootPath)
-	cp -f DoComm $(RootPath)
+	cp -f Module_DoComm $(RootPath)
 	cp -f Module_EvComm $(RootPath)
 	cp -f Module_EventLogging $(RootPath)
 	cp -f Module_InternalComm $(RootPath)
@@ -112,11 +129,11 @@ OtherTools:
 	cp -f FactoryConfig $(RootPath)
 
 	if [ ! -d $(OutputPath) ]; then mkdir -p $(OutputPath); fi
-	cp -f init.sh $(OutputPath)
-	cp -f kill.sh $(OutputPath)
-	cp -f web.sh $(OutputPath)
+	cp -f $(ScriptLib)/init.sh $(OutputPath)
+	cp -f $(ScriptLib)/kill.sh $(OutputPath)
+	cp -f $(ScriptLib)/web.sh $(OutputPath)
 	cp -f main $(OutputPath)
-	cp -f DoComm $(OutputPath)
+	cp -f Module_DoComm $(OutputPath)
 	cp -f Module_EvComm $(OutputPath)
 	cp -f Module_EventLogging $(OutputPath)
 	cp -f Module_InternalComm $(OutputPath)
@@ -142,4 +159,4 @@ CleanExec:
 	#rm Module_PsuComm
 	rm ReadCmdline
 	rm FactoryConfig
-	rm DoComm
+	rm Module_DoComm

+ 143 - 119
EVSE/Projects/DD360Audi/Apps/ReDoComm.c → EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -21,16 +21,16 @@
 #include <unistd.h>
 #include <signal.h>
 
-#include "../../define.h"
-#include "Config.h"
-#include "ReDoComm.h"
-#include "AudiCust.h"
-#include "timeout.h"
+#include "../../../define.h"
+#include "../Config.h"
+#include "../SelectGun/SelectGun.h"
+#include "../timeout.h"
+#include "DoComm.h"
 
 //------------------------------------------------------------------------------
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_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 int TcpSock = 0;
@@ -152,10 +152,10 @@ static void Hexdump(const void *p, size_t size)
 
     message_len += sprintf(&message[message_len], "\r\n");
 
-    DEBUG_INFO("%s", message);
+    log_info("%s", message);
 }
 
-static int string2ByteArray(char *input, byte *output)
+static int string2ByteArray(char *input, uint8_t *output)
 {
     int loop = 0;
     int i = 0;
@@ -170,7 +170,7 @@ static int string2ByteArray(char *input, byte *output)
 
 static void unixSocketSigPipeHandle(int sig)
 {
-    DEBUG_ERROR("socket packet error %x\r\n", sig);
+    log_error("socket packet error %x\r\n", sig);
 }
 
 static void InitSocketSigPipe(void)
@@ -199,7 +199,7 @@ static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
     size = send(fd, data, dataLen , 0);
     if ((size < 0) || (errno == EAGAIN)) {
         if (size < 0) {
-            DEBUG_ERROR("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
+            log_error("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
         }
     }
 
@@ -213,7 +213,7 @@ static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
 
     size = recv(fd, pdata, dataLen, MSG_WAITALL);
     if ((errno == EAGAIN) || (size < 0)) {
-        DEBUG_ERROR("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
+        log_error("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
     }
 
     return size;
@@ -225,7 +225,7 @@ static int getSO_ERROR(int fd)
     socklen_t len = sizeof err;
 
     if (-1 == getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &len)) {
-        DEBUG_ERROR("getSO_ERROR\r\n");
+        log_error("getSO_ERROR\r\n");
     }
 
     if (err) {
@@ -244,12 +244,12 @@ static void closeSocket(int fd)        // *not* the Windows closesocket()
     getSO_ERROR(fd); // first clear any errors, which can cause close to fail
     if (shutdown(fd, SHUT_RDWR) < 0) { // secondly, terminate the 'reliable' delivery
         if (errno != ENOTCONN && errno != EINVAL) { // SGI causes EINVAL
-            DEBUG_INFO("shutdown\r\n");
+            log_info("shutdown\r\n");
         }
     }
 
     if (close(fd) < 0) { // finally call close()
-        DEBUG_INFO("client socket close\r\n");
+        log_info("client socket close\r\n");
     }
 }
 
@@ -265,7 +265,7 @@ static int doCommConnToServer(void)
     //}
 
     if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-        DEBUG_ERROR("Open TCP socket NG");
+        log_error("Open TCP socket NG");
         return -1;
     }
 
@@ -399,7 +399,7 @@ static void setConfirmSelGun(uint8_t selGun)
 static int compareOpcode(uint8_t opCode)
 {
     if (opCode != OP_WAIT_RESPONSE) {
-        //DEBUG_ERROR("response operative code fail\r\n");
+        //log_error("response operative code fail\r\n");
         return FAIL;
     }
 
@@ -409,7 +409,7 @@ static int compareOpcode(uint8_t opCode)
 static int compareResult(uint8_t result)
 {
     if (result != COMMAND_RESULT_OK) {
-        //DEBUG_ERROR("response result fail\r\n");
+        //log_error("response result fail\r\n");
         return FAIL;
     }
 
@@ -419,7 +419,7 @@ static int compareResult(uint8_t result)
 static int compareRegister(uint8_t srcReg, uint8_t destReg)
 {
     if (srcReg != destReg) {
-        //DEBUG_ERROR("response register fail\r\n");
+        //log_error("response register fail\r\n");
         return FAIL;
     }
 
@@ -447,7 +447,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     struct tm *tm;
 
     if ((char *)&data[0] == '\0') {
-        DEBUG_ERROR("QR code date error\r\n");
+        log_error("QR code date error\r\n");
         return FAIL;
     }
 
@@ -471,7 +471,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     }
 
     //if ((char *)&data[len] == '\0') {
-    //    DEBUG_ERROR("power cabinet system date error\r\n");
+    //    log_error("power cabinet system date error\r\n");
     //    return FAIL;
     //}
 
@@ -479,7 +479,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     //if (strncmp((char *)localTime, (char *)&data[len], timeLen) != 0) {
     //    sprintf(cmdBuf, "date -s \"%s\" >> /dev/null", (char *)&data[len]);
     //    system(cmdBuf);
-    //    DEBUG_INFO("local time = %s, data time = %s\r\n", localTime, (char *)&data[len]);
+    //    log_info("local time = %s, data time = %s\r\n", localTime, (char *)&data[len]);
     //    ShmOCPP16Data->MsMsg.bits.ResetReq = YES;
     //    strcpy((char *)ShmOCPP16Data->Reset.Type, "Soft");
     //    sleep(3);
@@ -495,12 +495,12 @@ static int updateFirmwareHandle(uint8_t *imgName)
     char cmdBuf[1024] = {0};
 
     sprintf(cmdBuf, "/mnt/%s", imgName);
-    DEBUG_INFO("Program ready to check file %s\n", cmdBuf);
+    log_info("Program ready to check file %s\n", cmdBuf);
     if ( access(cmdBuf, F_OK) != -1) {
-        DEBUG_INFO("File '%s' exist.\n", cmdBuf);
+        log_info("File '%s' exist.\n", cmdBuf);
         ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = YES;
     } else {
-        DEBUG_INFO("File '%s' doesn't exist.\n", cmdBuf);
+        log_info("File '%s' doesn't exist.\n", cmdBuf);
         ret = FAIL;
     }
 
@@ -560,13 +560,13 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
         pMiscCmd = (MiscCommand *)data + i;
         cmd = ntohs(pMiscCmd->CMD);
         value = ntohl(*((uint32_t *)&pMiscCmd->Value[0]));
-        //DEBUG_INFO("misc command = %x, value = %d\r\n", cmd, value);
+        //log_info("misc command = %x, value = %d\r\n", cmd, value);
 
         switch (cmd) {
         //--- Execute parameter ---
         case MISC_CMD_CONNECOTOR_TIMEOUT:
             gAudiCustInfo->RemoteSetup.ConnectionTimeout = value;
-            DEBUG_INFO("connection timeout = %d\r\n", gAudiCustInfo->RemoteSetup.ConnectionTimeout);
+            log_info("connection timeout = %d\r\n", gAudiCustInfo->RemoteSetup.ConnectionTimeout);
             clearMiscCommand();
             break;
 
@@ -578,7 +578,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            DEBUG_INFO("change availability plugNum = %d, value = %d\r\n", plugNum, value);
+            log_info("change availability plugNum = %d, value = %d\r\n", plugNum, value);
             ShmOCPP16Data->CsMsg.bits[plugNum].ChangeAvailabilityReq = YES;
             if (value == YES) {
                 strcpy((char *)ShmOCPP16Data->ChangeAvailability[plugNum].Type, "Operative");
@@ -593,9 +593,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
         case MISC_CMD_DEFAULT_PRICES:
             prices = transPricesUnit((int)value);
-            DEBUG_INFO("default prices = %.2f\r\n", prices);
+            log_info("default prices = %.2f\r\n", prices);
 
-            ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = YES;
+            //ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = YES;
             for (j = 0; j < 24; j++) {
                 ShmSysConfigAndInfo->SysConfig.BillingData.Fee[j] = prices;
             }
@@ -609,7 +609,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 return FAIL;
             }
 
-            DEBUG_INFO("default currency = %s%c\r\n", (uint8_t *)Currency[value]);
+            log_info("default currency = %s%c\r\n", (uint8_t *)Currency[value]);
             ShmSysConfigAndInfo->SysConfig.BillingData.Currency = value;
             clearMiscCommand();
             break;
@@ -622,13 +622,13 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
 #if defined DD360Audi
             if (getConfirmSelectedGun(plugNum) == FAIL) {
-                DEBUG_INFO("Remote start not select gun\r\n");
+                log_info("Remote start not select gun\r\n");
                 break;
             }
 #endif //DD360Audi
 
             gAudiCustInfo->PricesInfo[plugNum].Balance = transPricesUnit((int)value);
-            DEBUG_INFO("%d misc balance = %.2f\r\n", plugNum, gAudiCustInfo->PricesInfo[plugNum].Balance);
+            log_info("%d misc balance = %.2f\r\n", plugNum, gAudiCustInfo->PricesInfo[plugNum].Balance);
             clearMiscCommand();
             break;
 
@@ -648,6 +648,14 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             gAudiCustInfo->EthDevStatus.FourG = value;
             break;
 
+        case MISC_CMD_BILLING_INFO:
+            ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
+            break;
+
+        case MISC_CMD_WEB_STOP_CHARGING:
+            gAudiCustInfo->RemoteSetup.BtnStopCharging = value;
+            break;
+
         //--- Control Dispenser ---
         case MISC_CMD_HARDWARE_REBOOT:
             if (value != YES) {
@@ -655,7 +663,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            DEBUG_INFO("Hardware reboot\r\n");
+            log_info("Hardware reboot\r\n");
             ShmOCPP16Data->MsMsg.bits.ResetReq = YES;
             strcpy((char *)ShmOCPP16Data->Reset.Type, "Hard");
             clearMiscCommand();
@@ -668,7 +676,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             clearMiscCommand();
-            DEBUG_INFO("Software reboot\r\n");
+            log_info("Software reboot\r\n");
             ShmOCPP16Data->MsMsg.bits.ResetReq = YES;
             strcpy((char *)ShmOCPP16Data->Reset.Type, "Soft");
             break;
@@ -680,11 +688,11 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 }
                 break;
             }
-            DEBUG_INFO("Remote start charging plugNum = %d\r\n", plugNum);
+            log_info("Remote start charging plugNum = %d\r\n", plugNum);
 
 #if defined DD360Audi
             if (getSelGunWaitToAuthor(plugNum) == FAIL) {
-                DEBUG_ERROR("Remote start gun already charging\r\n");
+                log_error("Remote start gun already charging\r\n");
                 break;
             }
 
@@ -829,12 +837,12 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         pricesInfo[plugNum].UserPrices = gAudiCustInfo->PricesInfo[plugNum].UserPrices;
         pricesInfo[plugNum].Balance = gAudiCustInfo->PricesInfo[plugNum].Balance;
 
-        DEBUG_INFO("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
-                   plugNum,
-                   gAudiCustInfo->PricesInfo[plugNum].UserPrices,
-                   ChargingData[plugNum]->ChargingFee,
-                   gAudiCustInfo->PricesInfo[plugNum].Balance,
-                   (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+        log_info("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
+                 plugNum,
+                 gAudiCustInfo->PricesInfo[plugNum].UserPrices,
+                 ChargingData[plugNum]->ChargingFee,
+                 gAudiCustInfo->PricesInfo[plugNum].Balance,
+                 (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
     }
 
     return PASS;
@@ -906,19 +914,18 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
     uint8_t remaindLen = 0;
     uint8_t statusCodeError = 0;
 
-    //if (dataLen <= 0) {
-    //    return FAIL;
-    //}
-
     if (dataLen > 0) {
+        Hexdump((uint8_t *)data, dataLen);
+
         remaindLen = dataLen % WARNING_CODE_SIZE;
 
         if (remaindLen != 0) {
+            log_info("fail status code length =  %d\r\n", dataLen);
             dataLen -= remaindLen;
         }
 
         if (dataLen < WARNING_CODE_SIZE) {
-            DEBUG_ERROR("fail status code length = %d\r\n", dataLen);
+            log_error("fail status code length = %d\r\n", dataLen);
             Hexdump(data, dataLen);
             if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
                 for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
@@ -939,17 +946,24 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
 
         for (count = 0; count < dataLen; count += WARNING_CODE_SIZE) {
             usleep(128);
+
+            if (strncmp((char *)&data[count + 1], "1", 1) != 0 &&
+                    strncmp((char *)&data[count + 1], "2", 1) != 0 &&
+                    strncmp((char *)&data[count + 1], "3", 1) != 0 &&
+                    (strncmp((char *)&data[count], "B", 1) != 0 &&
+                     strncmp((char *)&data[count + 1], "4", 1) != 0)
+               ) {
+                log_error("error status code = %s", (char *)&data[count]);
+                continue;
+            }
+
             // misc command status code handle
             if (strncmp((char *)&data[count], MISC_ST_MISC_CMD, WARNING_CODE_SIZE) == 0) {
-                //if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
                 gDoCommGblData.MiscCmd = REG_MISC_CONTROL;
-                //}
                 memset((char *)&data[count], 0, WARNING_CODE_SIZE);
                 continue;
             } else if (strncmp((char *)&data[count], MISC_ST_VERSION, WARNING_CODE_SIZE) == 0) {
-                //if (gDoCommGblData.MiscCmd != REG_REPORT_CSU_VERSION) {
                 gDoCommGblData.MiscCmd = REG_REPORT_CSU_VERSION;
-                //}
                 memset((char *)&data[count], 0, WARNING_CODE_SIZE);
                 continue;
             }
@@ -957,7 +971,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             if (CompareArrayIsZero((uint8_t *)&data[count], WARNING_CODE_SIZE) == true) {
                 memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
                 memcpy(EventCodeTmp, (char *)&data[count], sizeof(EventCodeTmp));
-                DEBUG_ERROR("error status = %s\r\n", EventCodeTmp);
+                log_error("error status = %s\r\n", EventCodeTmp);
                 continue;
             }
 
@@ -979,18 +993,15 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             }
             //Rtn=StatusCodeProcessing(StatusArray[count/6]);
         }
+    } else {
+        if (CompareArrayIsZero(data, WARNING_CODE_SIZE) == false) {
+            log_error("power cabinet status code data length is zero, but have data\r\n");
+            Hexdump((uint8_t *)data, WARNING_CODE_SIZE);
+        }
     }
 
     for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         usleep(128);
-        //if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
-        //        ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4') {
-        //    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-        //    memcpy(EventCodeTmp,
-        //           ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
-        //           sizeof(EventCodeTmp));
-        //    removeFaultCodeToBuf(EventCodeTmp);
-        //}
 
         if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' || //from backend or power cabinet 0x33
                 (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
@@ -1045,9 +1056,9 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
     case REG_CONNECTOR_ID:
         gDoCommGblData.ConnectorID[0] = pCsuResult->Data.Data[0];
         gDoCommGblData.ConnectorID[1] = pCsuResult->Data.Data[1];
-        DEBUG_INFO("OK (Left connector ID = %d, Right connector ID = %d)\n",
-                   pCsuResult->Data.Data[0],
-                   pCsuResult->Data.Data[1]);
+        log_info("OK (Left connector ID = %d, Right connector ID = %d)\n",
+                 pCsuResult->Data.Data[0],
+                 pCsuResult->Data.Data[1]);
         break;
 
     case REG_POWER_CABINET_STATUS:
@@ -1089,18 +1100,21 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         break;
 
     case REG_USER_ID:
-        //DEBUG_INFO("%s\n", pCsuResult->Data.Data[0] == 1 ? "Accept" : "Reject" );
+        //log_info("%s\n", pCsuResult->Data.Data[0] == 1 ? "Accept" : "Reject" );
         //if (pCsuResult->Data.Data[0] <= 0) {
         //    return FAIL;
         //}
         if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
             return COMMAND_RESULT_NG;
         }
+
+        gAudiCustInfo->AuthorStateFromCabinet = pCsuResult->Data.Data[0];
+
         return pCsuResult->Data.Data[0];
         break;
 
     case REG_CHARGING_PERMISSION:
-        //DEBUG_INFO("id = %d, result = %s, action = %s\r\n",
+        //log_info("id = %d, result = %s, action = %s\r\n",
         //           pCsuResult->Head.ID,
         //           pCsuResult->Data.Result == 1 ? "OK" : "NG",
         //           pCsuResult->Data.Data[0] == 1 ? "Permitted" : "NOT permitted");
@@ -1166,21 +1180,21 @@ static int composeSocketData(int fd,
 
     //send command packet
     if ((size = sendTcpSocket(fd, (uint8_t *)&csuCmdPkt, sendPktLen)) < 0) {
-        DEBUG_ERROR("TCP socket send packet fail = %d\r\n", size);
+        log_error("TCP socket send packet fail = %d\r\n", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result head
     if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
-        DEBUG_ERROR("TCP socket RX head fail = %d\r\n", size);
+        log_error("TCP socket RX head fail = %d\r\n", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result raw data
     if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
-        DEBUG_ERROR("TCP socket RX data fail = %d\r\n", size);
+        log_error("TCP socket RX data fail = %d\r\n", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
@@ -1379,12 +1393,12 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
         if (strcmp(&vendorErrorCodeTmp[plugNum][0], "") == 0) {
             strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
             vendorErrorCodeTmp[plugNum][6] = '\0';
-            DEBUG_INFO("1 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+            log_info("1 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
         } else {
             if (strncmp(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE) != 0) {
                 strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
                 vendorErrorCodeTmp[plugNum][6] = '\0';
-                DEBUG_INFO("2 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+                log_info("2 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
             }
         }
     }
@@ -1581,7 +1595,7 @@ static int CheckNetworkStatus(void)
     return 0;
 }
 
-static int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+static int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
     uint8_t index = 0;
 
@@ -1615,53 +1629,53 @@ static int InitShareMemory(void)
     int MeterSMId = 0;
 
     if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+        log_error("shmget ShmSysConfigAndInfo NG\n");
         result = 0;
     } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+        log_error("[shmat ShmSysConfigAndInfo NG\n");
         result = 0;
     }
 
     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+        log_error("shmget ShmStatusCodeData NG\n");
         result = 0;
     } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        log_error("shmat ShmStatusCodeData NG\n");
         result = 0;
     }
 
     //creat ShmPsuData
     if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPsuData NG \n");
+        log_error("shmget ShmPsuData NG \n");
         result = 0;
     } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPsuData NG \n");
+        log_error("shmat ShmPsuData NG \n");
         result = 0;
     }
 
     //creat ShmOCPP16Data
     if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
+        log_error("shmget ShmOCPP16Data NG \n");
         result = 0;
     } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
+        log_error("shmat ShmOCPP16Data NG \n");
         result = 0;
     }
 
     if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+        log_error("shmget ShmPrimaryMcuData NG\n");
         result = 0;
     } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+        log_error("shmat ShmPrimaryMcuData NG\n");
         result = 0;
     }
 
     //creat Audi customization info
     if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmget select gun info NG \n");
+        log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
     } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmat shmget select gun info \n");
+        log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
 
@@ -1791,7 +1805,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             break;
 
         case REG_POWER_CABINET_STATUS:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 readPowerCabinetStatus(fd, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
@@ -1799,7 +1814,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             break;
 
         case REG_DISPENSER_STATUS:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 writeDispenserStatus(fd, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
@@ -1816,13 +1832,15 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
         //case REG_SOFTWARE_UPDATE:
         //    if (ChargingData[plugNum]->SystemStatus == S_IDLE) {
-        //        if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME * 10) {
+        //        if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > L OOP_RETRY_TIME||
+        //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0  * 1) {
         //            readSoftwareUpdate(fd);
         //            ftime(&gRegTimeUp[plugNum][curReg]);
         //        }
         //        while (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
         //            ftime(&NowTime);
-        //            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+        //            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowT ime) > LOOP_RETRY_TIME||
+        //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
         //                readSoftwareUpdate(fd);
         //            }
         //            usleep(128);
@@ -1832,7 +1850,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //    break;
 
         case REG_PLUG_IN_STATE:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 writePlugInStatus(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
@@ -1840,13 +1859,17 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             break;
 
         case REG_CONNECTOR_STATE:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 writeConnectorState(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
 
             //check misc command from power cabinet
             if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x\r\n", gDoCommGblData.MiscCmd);
+                }
                 curReg = gDoCommGblData.MiscCmd;
             } else {
                 curReg = REG_QRCODE_URL_INFO;
@@ -1877,7 +1900,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 //power up write dispenser version and get power cabinet system ID
                 if ((writeCsuModuleVersion(fd) == PASS) &&
                         (writeOtherModuleVersion(fd) == PASS) &&
-                        (readQRcodeURLAndSystemDate(fd) == PASS)) {
+                        (readQRcodeURLAndSystemDate(fd) == PASS)
+                   ) {
                     //gDoCommGblData.DisConnCount = 0;
                     isContinue = 0;
                 }
@@ -1907,7 +1931,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //    break;
 
         default:
-            DEBUG_ERROR("error curReg = %x\r\n", curReg);
+            log_error("error curReg = %x\r\n", curReg);
             gDoCommGblData.MiscCmd = 0;
             gDoCommGblData.DisConnCount = CHECK_NETWORK_FAIL_COUNT;
             isContinue = 0;
@@ -1995,9 +2019,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) == 0) {
-                DEBUG_INFO("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
-                           plugNum,
-                           REG_CHARGING_PERMISSION);
+                log_info("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
+                         plugNum,
+                         REG_CHARGING_PERMISSION);
                 ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
@@ -2024,9 +2048,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) == 0) {
-                DEBUG_INFO("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
-                           plugNum,
-                           REG_CHARGING_PERMISSION);
+                log_info("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
+                         plugNum,
+                         REG_CHARGING_PERMISSION);
                 ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
@@ -2050,9 +2074,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) == 0) {
-                DEBUG_INFO("Stop charging by power cabinet's permission = %d, %d\r\n",
-                           plugNum,
-                           REG_CHARGING_PERMISSION);
+                log_info("Stop charging by power cabinet's permission = %d, %d\r\n",
+                         plugNum,
+                         REG_CHARGING_PERMISSION);
                 ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
                 //printf("%d StopChargeFlag = %d\r\n", plugNum, ChargingData[plugNum]->StopChargeFlag);
             }
@@ -2090,33 +2114,33 @@ static int networkCreatePorcess(void)
     setTcpStatus(ABNORMAL);
 
     /**************** Check Network **********/
-    DEBUG_INFO("Check Dispenser Network Information");
+    log_info("Check Dispenser Network Information");
     while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE) {
         usleep(125);
     }
 
     while (!CheckNetworkStatus()) {
         calDisconnectCount(&gDoCommGblData.DisConnCount, CHECK_NETWORK_FAIL_COUNT);
-        DEBUG_ERROR("disconnect count = % d\r\n", gDoCommGblData.DisConnCount);
+        log_error("disconnect count = % d\r\n", gDoCommGblData.DisConnCount);
     }
-    DEBUG_INFO("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s",
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+    log_info("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s",
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
 
     /**************** Power cabinet connection **********/
-    DEBUG_INFO("Connect to Power Cabinet");
+    log_info("Connect to Power Cabinet");
     while ((fd = doCommConnToServer()) <= 0) {
         calDisconnectCount(&gDoCommGblData.DisConnCount, CONNECT_SERVER_FAIL_COUNT);
-        DEBUG_ERROR("disconnect count = %d, fd = %d\r\n", gDoCommGblData.DisConnCount, fd);
+        log_error("disconnect count = %d, fd = %d\r\n", gDoCommGblData.DisConnCount, fd);
     }
-    DEBUG_INFO("Power cabinet connected(fd = % d): IP = % s Netmask = % s, Gateway = % s",
-               fd,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+    log_info("Power cabinet connected(fd = % d): IP = % s Netmask = % s, Gateway = % s",
+             fd,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
     destroySelectGun(DESTROY_ALL_SEL);
@@ -2145,7 +2169,7 @@ int main(int argc, char *argv[])
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = YES;
         }
 
-        DEBUG_ERROR("DoComm Initial share memory fail\r\n");
+        log_error("DoComm Initial share memory fail\r\n");
         sleep(5);
 
         return 0;
@@ -2155,7 +2179,7 @@ int main(int argc, char *argv[])
 
     for (index = 0; index < totalConnCount; index++) {
         if (!FindChargingInfoData(index, &ChargingData[0])) {
-            DEBUG_ERROR("FindChargingInfoData false \n");
+            log_error("FindChargingInfoData false \n");
             break;
         }
         clearPricesInfo(index);
@@ -2197,7 +2221,7 @@ int main(int argc, char *argv[])
         }
 
         if (initDone == DISPENSER_SOCKET_RECONN) {
-            DEBUG_INFO("Disconnected from power cabinet...re-connecting");
+            log_info("Disconnected from power cabinet...re-connecting");
             setTcpStatus(ABNORMAL);
 
             gDoCommGblData.DisConnCount = 0;
@@ -2214,6 +2238,6 @@ int main(int argc, char *argv[])
             updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
         }
 
-        usleep(1000);
+        usleep(10000);
     }
 }

+ 22 - 27
EVSE/Projects/DD360/Apps/ReDoComm.h → EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h

@@ -1,6 +1,9 @@
 #ifndef _DO_COMM_H_
 #define _DO_COMM_H_
 
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
 //------------------------------------------------------------------------------
 //--- common define ---
 //------------------------------------------------------------------------------
@@ -31,19 +34,8 @@
 
 #define PRICES_UNIT                             0.01
 
-#define PASS                                    (1)
-#define FAIL                                    (-1)
-
-#define YES                                     (1)
-#define NO                                      (0)
-
-#define NO_DEFINE                               255
-
 #define LOOP_RETRY_TIME                         1000 //1 second
 
-#define NORMAL                                  0
-#define ABNORMAL                                1
-
 //------------------------------------------------------------------------------
 //--- dispenser ID ---
 //------------------------------------------------------------------------------
@@ -104,25 +96,27 @@
 //------------------------------------------------------------------------------
 //--- power cabinet misc command ---
 //------------------------------------------------------------------------------
-#define MISC_CMD_CONNECOTOR_TIMEOUT             0X0001
-#define MISC_CMD_OPERATIVE_STATE                0X0002
-#define MISC_CMD_DEFAULT_PRICES                 0x0003
-#define MISC_CMD_DEFAULT_CURRENCY               0x0004
-#define MISC_CMD_ACCOUNT_BALANCE                0x0005
+#define MISC_CMD_CONNECOTOR_TIMEOUT             (0X0001)
+#define MISC_CMD_OPERATIVE_STATE                (0X0002)
+#define MISC_CMD_DEFAULT_PRICES                 (0x0003)
+#define MISC_CMD_DEFAULT_CURRENCY               (0x0004)
+#define MISC_CMD_ACCOUNT_BALANCE                (0x0005)
 
-#define MISC_CMD_BACKEND_STATUS                 0x0006
-#define MISC_CMD_ETHERNET_STATUS                0x0007
-#define MISC_CMD_WIFI_STATUS                    0x0008
-#define MISC_CMD_4G_STATUS                      0x0009
+#define MISC_CMD_BACKEND_STATUS                 (0x0006)
+#define MISC_CMD_ETHERNET_STATUS                (0x0007)
+#define MISC_CMD_WIFI_STATUS                    (0x0008)
+#define MISC_CMD_4G_STATUS                      (0x0009)
+#define MISC_CMD_BILLING_INFO                   (0x000A)
+#define MISC_CMD_WEB_STOP_CHARGING              (0x000B)
 
-#define MISC_CMD_HARDWARE_REBOOT                0x0101
-#define MISC_CMD_SOFTWARE_RESTART               0x0102
-#define MISC_CMD_REMOTE_START_CHARGING          0x0103
-#define MISC_CMD_REMOTE_STOP_CHARGING           0x0104
-#define MISC_CMD_REMOTE_UNLOCK                  0x0105
+#define MISC_CMD_HARDWARE_REBOOT                (0x0101)
+#define MISC_CMD_SOFTWARE_RESTART               (0x0102)
+#define MISC_CMD_REMOTE_START_CHARGING          (0x0103)
+#define MISC_CMD_REMOTE_STOP_CHARGING           (0x0104)
+#define MISC_CMD_REMOTE_UNLOCK                  (0x0105)
 
-#define ST_UPDATE_FIRMWARE                      0x01
-#define ST_NO_UPDATE_FIRMWARE                   0x02
+#define ST_UPDATE_FIRMWARE                      (0x01)
+#define ST_NO_UPDATE_FIRMWARE                   (0x02)
 
 //------------------------------------------------------------------------------
 #pragma pack(push)
@@ -138,6 +132,7 @@ typedef struct StConnectorIDTable {
     uint8_t DcConnID1;
     uint8_t DcConnID2;
     uint8_t AcConnID;
+    uint8_t Reserved;
 } ConnectorIDTable;
 
 typedef struct StDoCommGlobalVar {

+ 198 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.c

@@ -0,0 +1,198 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <stdint.h>
+#include <string.h>
+
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+
+#include "Ev_Comm.h"
+#include "Module_EvComm.h"
+
+//------------------------------------------------------------------------------
+int PackageIdCmd(int cmd)
+{
+    return cmd | 0x80000000;
+}
+
+void SendCmdToEvboard(int cmd, uint8_t *data, uint8_t dataLen)
+{
+    int fd = GetCanFd();
+    struct can_frame frame;
+
+    frame.can_id = cmd;
+    frame.can_dlc = dataLen;
+    memcpy(frame.data, data, sizeof(frame.data));
+
+    write(fd, &frame, sizeof(struct can_frame));
+}
+
+//------------------------------------------------------------------------------
+void SetTargetAddr(uint8_t *target_number, uint8_t index)
+{
+    int id = PackageIdCmd(CMD_ADDR_ASSIGNMENT + index);
+    //printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
+    //cmd = cmd & CAN_EFF_MASK;
+
+    uint8_t data[8];
+
+    data[0] = *target_number;
+    data[1] = *(target_number + 1);
+    data[2] = *(target_number + 2);
+    data[3] = *(target_number + 3);
+    data[4] = index;
+
+    SendCmdToEvboard(id, data, 5);
+}
+
+void GetFirmwareVersion(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_FW_VER + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void GetHardwareVersion(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_HW_VER + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch)
+{
+    int id = PackageIdCmd(CMD_SYNC_RTC + toId);
+    uint8_t data[8];
+
+    data[0] = epoch & 0xff;
+    data[1] = (epoch >> 8) & 0xff;
+    data[2] = (epoch >> 16) & 0xff;
+    data[3] = (epoch >> 24) & 0xff;
+
+    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)
+{
+    int id = PackageIdCmd(CMD_CHARGING_PERMISSION + toId);
+    uint8_t data[8];
+
+    data[0] = permissionStatus;
+    data[1] = aOutputPw & 0xff;
+    data[2] = (aOutputPw >> 8) & 0xff;
+    data[3] = aOutputCur & 0xff;
+    data[4] = (aOutputCur >> 8) & 0xff;
+    data[5] = aOutputVol & 0xff;
+    data[6] = (aOutputVol >> 8) & 0xff;
+    data[7] = 0xf0;
+
+    SendCmdToEvboard(id, data, sizeof(data));
+}
+
+void SetPresentOutputPower(uint16_t outputVol_b1, uint16_t outputCur_b1, uint16_t outputVol_b2, uint16_t outputCur_b2)
+{
+    int id = PackageIdCmd(CMD_PRESENT_OUTPUT_POWER);
+    uint8_t data[8];
+
+    data[0] = outputVol_b1 & 0xff;
+    data[1] = (outputVol_b1 >> 8) & 0xff;
+    data[2] = outputCur_b1 & 0xff;
+    data[3] = (outputCur_b1 >> 8) & 0xff;
+    data[4] = outputVol_b2 & 0xff;
+    data[5] = (outputVol_b2 >> 8) & 0xff;
+    data[6] = outputCur_b2 & 0xff;
+    data[7] = (outputCur_b2 >> 8) & 0xff;
+
+    SendCmdToEvboard(id, data, 8);
+}
+
+void SetPresentOutputCapacity(uint16_t aOutputPw_b1, uint16_t aOutputCur_b1, uint16_t aOutputPw_b2, uint16_t aOutputCur_b2)
+{
+    int id = PackageIdCmd(CMD_PRESENT_OUTPUT_CAPABILITIES);
+    uint8_t data[8];
+
+    data[0] = aOutputPw_b1 & 0xff;
+    data[1] = (aOutputPw_b1 >> 8) & 0xff;
+    data[2] = aOutputCur_b1 & 0xff;
+    data[3] = (aOutputCur_b1 >> 8) & 0xff;
+    data[4] = aOutputPw_b2 & 0xff;
+    data[5] = (aOutputPw_b2 >> 8) & 0xff;
+    data[6] = aOutputCur_b2 & 0xff;
+    data[7] = (aOutputCur_b2 >> 8) & 0xff;
+
+    SendCmdToEvboard(id, data, 8);
+}
+
+void GetOutputReq(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_OUTPUT_REQ + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void GetEvBatteryInfo(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_BATTERY_INFO + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_EVSE_STOP_CHARGING + toId);
+    uint8_t data[8];
+
+    data[0] = stopResult;
+    data[1] = *stopReason;
+    data[2] = *(stopReason + 1);
+    data[3] = *(stopReason + 2);
+    data[4] = *(stopReason + 3);
+    data[5] = *(stopReason + 4);
+    data[6] = *(stopReason + 5);
+
+    SendCmdToEvboard(id, data, 7);
+}
+
+void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, float voltage, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_MISC_INFO + toId);
+    uint8_t data[8];
+
+    int _power = power * 10;
+
+    data[0] = relayStatus;
+    data[1] = (int)_power & 0xff;
+    data[2] = ((int)_power >> 8) & 0xff;
+    data[3] = (int)voltage & 0xff;
+    data[4] = ((int)voltage >> 8) & 0xff;
+
+    SendCmdToEvboard(id, data, 5);
+}
+
+void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_ISOLATION_STATUS + toId);
+    uint8_t data[8];
+
+    data[0] = result;
+    SendCmdToEvboard(id, data, 1);
+}
+
+void SetEvsePrechargeInfo(uint8_t gun_index, uint8_t result, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_EVSE_PRECHARGE + toId);
+    uint8_t data[8];
+
+    data[0] = result;
+    SendCmdToEvboard(id, data, 1);
+}
+

+ 62 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.h

@@ -0,0 +1,62 @@
+#ifndef _EV_COMM_H_
+#define _EV_COMM_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//EV command address
+//------------------------------------------------------------------------------
+#define CMD_NONE                                (0)
+#define CMD_ADDR_ASSIGNMENT                     (0x00000200)
+#define CMD_GET_FW_VER                          (0x00000400)
+#define CMD_GET_HW_VER                          (0x00000500)
+#define CMD_CHARGING_PERMISSION                 (0x00000600)
+#define CMD_PRESENT_OUTPUT_POWER                (0x00000700)
+#define CMD_PRESENT_OUTPUT_CAPABILITIES         (0x00000800)
+#define CMD_GET_OUTPUT_REQ                      (0x00000900)
+#define CMD_GET_BATTERY_INFO                    (0x00000A00)
+#define CMD_EVSE_STOP_CHARGING                  (0x00000C00)
+#define CMD_GET_MISC_INFO                       (0x00000D00)
+
+#define CMD_DOWNLOAD_REQ                        (0x00000E00)
+#define CMD_START_BLOCK_TRANS                   (0x00000F00)
+#define CMD_DATA_TRANS                          (0x00001000)
+#define CMD_DOWNLOAD_FINISH                     (0x00001100)
+
+#define CMD_ISOLATION_STATUS                    (0x00001200)
+#define CMD_SYNC_RTC                            (0x00001400)
+#define CMD_EVSE_PRECHARGE                      (0x00001500)
+
+// 車端主動
+#define ADDRESS_REQ                             (0x080001FF)
+#define NOTIFICATION_EV_STATUS                  (0x08000300)
+#define NOTIFICATION_EV_STOP                    (0x08000B00)
+// 車端回應
+#define ACK_EV_FW_VERSION                       (0x08000400)
+#define ACK_EV_HW_VERSION                       (0x08000500)
+#define ACK_GET_OUTPUT_REQ                      (0x08000900)
+#define ACK_GET_EV_BATTERY_INFO                 (0x08000A00)
+#define ACK_GET_MISCELLANEOUS_INFO              (0x08000D00)
+#define ACK_EVSE_ISOLATION_STATUS               (0x08001200)
+#define ACK_EVSE_PRECHAGE_INFO                  (0x08001500)
+
+//------------------------------------------------------------------------------
+// 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 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 EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId);
+
+#endif /* _EV_COMM_H_ */

+ 295 - 108
EVSE/Projects/DD360Audi/Apps/ReModule_EvComm.c → EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.c

@@ -29,24 +29,12 @@
 #include <ctype.h>
 #include <ifaddrs.h>
 
-#include "../../define.h"
+#include "../../../define.h"
+#include "../Config.h"
 #include "Module_EvComm.h"
-#include "Config.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define START               1
-#define STOP                0
-#define COMMUNICATION       2
-#define YES                 1
-#define NO                  0
-#define EQUAL               0
-#define CHK_VOL_RANGE       50
-#define CHK_CUR_RANGE       20
-#define PLUG                1
-#define UNPLUG              0
+#include "Ev_Comm.h"
 
+//------------------------------------------------------------------------------
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 struct FanModuleData            *ShmFanModuleData;
@@ -54,8 +42,10 @@ struct CHAdeMOData              *ShmCHAdeMOData;
 struct GBTData                  *ShmGBTData;
 struct CcsData                  *ShmCcsData;
 struct PsuData                  *ShmPsuData;
+DcCommonInfo                    *ShmDcCommonData;
 
-byte gun_count;
+uint8_t gun_count;
+int CanFd = -1;
 int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 //struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 remove
 
@@ -95,42 +85,24 @@ struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUAN
 struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 bool chkChademoPermission[2] = { false, false };
-byte SendErrorCount[2] = { 0, 0};
-
-struct Ev_Board_Cmd Ev_Cmd = {
-    0,
-    0x00000200,
-    0x00000400,
-    0x00000500,
-    0x00000600,
-    0x00000700,
-    0x00000800,
-    0x00000900,
-    0x00000A00,
-    0x00000C00,
-    0x00000D00,
-
-    0x00000E00,
-    0x00000F00,
-    0x00001000,
-    0x00001100,
-
-    0x00001200,
-    0x00001400,
-    0x00001500,
-};
-
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur);
-void GetMaxPowerMethod(byte index, float *pow);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
+uint8_t SendErrorCount[2] = { 0, 0};
+
+uint8_t mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+
+void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur);
+void GetMaxPowerMethod(uint8_t index, float *pow);
+uint32_t GetTimeoutValue(struct timeval _sour_time);
 
 #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)
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+int GetCanFd(void)
+{
+    return CanFd;
+}
+
+uint32_t GetTimeoutValue(struct timeval _sour_time)
 {
     struct timeval _end_time;
     gettimeofday(&_end_time, NULL);
@@ -173,10 +145,10 @@ int StoreLogMsg(const char *fmt, ...)
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
     //return milli-second
-    unsigned int StartTime, StopTime;
+    uint32_t StartTime, StopTime;
 
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
+    StartTime = (uint32_t)ST.time;
+    StopTime = (uint32_t)ET.time;
     return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
 }
 
@@ -193,13 +165,15 @@ void getTimeString(char *buff)
     sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
 }
 
-bool CheckUniqNumber(byte value)
+bool CheckUniqNumber(uint8_t value)
 {
-    for (byte index = 0; index < gun_count; index++) {
+    static struct timeval _id_assign_time;
+
+    for (uint8_t index = 0; index < gun_count; index++) {
         if (_chargingData[index]->Evboard_id == value) {
             struct timeval _end_time;
             gettimeofday(&_end_time, NULL);
-            unsigned long diff = 1000000 *  (_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
+            uint32_t diff = 1000000 *  (_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
             if (diff >= 3000000) {
                 gettimeofday(&_id_assign_time, NULL);
                 return true;
@@ -210,6 +184,7 @@ bool CheckUniqNumber(byte value)
     }
 
     gettimeofday(&_id_assign_time, NULL);
+
     return true;
 }
 
@@ -266,6 +241,12 @@ int InitShareMemory()
         }
     }
 
+    if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
+        return FAIL;
+    } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        return FAIL;
+    }
+
     return result;
 }
 
@@ -318,23 +299,23 @@ int InitCanBus()
 // CANBUS receive task
 //================================================
 //================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
             return true;
@@ -344,10 +325,10 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
     return false;
 }
 
-void AddrAssignment(byte *data)
+void AddrAssignment(uint8_t *data)
 {
-    byte target_number[8];
-    byte index = 0x00;
+    uint8_t target_number[8];
+    uint8_t index = 0x00;
 
     memcpy(target_number, data, sizeof(target_number));
     index = *(data + 4);
@@ -378,7 +359,7 @@ void AddrAssignment(byte *data)
     }
 }
 
-void ClearAbnormalStatus_Chademo(byte gun_index)
+void ClearAbnormalStatus_Chademo(uint8_t gun_index)
 {
     bool isCleanCheck = false;
     char code[7];
@@ -562,7 +543,7 @@ void ClearAbnormalStatus_Chademo(byte gun_index)
     }
 
     if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
+        for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
             if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
                 log_info("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
                 if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
@@ -606,7 +587,7 @@ void ClearAbnormalStatus_Chademo(byte gun_index)
     }
 }
 
-void ClearAbnormalStatus_GB(byte gun_index)
+void ClearAbnormalStatus_GB(uint8_t gun_index)
 {
     bool isCleanCheck = false;
     char code[7];
@@ -930,7 +911,7 @@ void ClearAbnormalStatus_GB(byte gun_index)
     }
 
     if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
+        for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
             if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
                 log_info("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
                 if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
@@ -1002,7 +983,7 @@ void ClearAbnormalStatus_GB(byte gun_index)
     }
 }
 
-void ClearAbnormalStatus_CCS(byte gun_index)
+void ClearAbnormalStatus_CCS(uint8_t gun_index)
 {
     bool isCleanCheck = false;
     char code[7];
@@ -1739,7 +1720,7 @@ void ClearAbnormalStatus_CCS(byte gun_index)
     }
 
     if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
+        for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
             if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
                 log_info("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
                 if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
@@ -1894,7 +1875,7 @@ void ClearAbnormalStatus_CCS(byte gun_index)
     }
 }
 
-bool AbnormalStopAnalysis(byte gun_index, byte *errCode)
+bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
 {
     char string[7];
     sprintf(string, "%d%d%d%d%d%d", *(errCode + 0), *(errCode + 1), *(errCode + 2), *(errCode + 3), *(errCode + 4), *(errCode + 5));
@@ -2167,6 +2148,118 @@ bool AbnormalStopAnalysis(byte gun_index, byte *errCode)
     return true;
 }
 
+static uint8_t returnConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
+        uint8_t chillerTemp1, uint8_t chillerTemp2)
+{
+    uint8_t i = 0;
+    uint8_t tempSource[4] = {headTemp1, headTemp2, chillerTemp1, chillerTemp2};
+    uint8_t maxTemp = 0;
+
+    if (headTemp1 == UNDEFINED_TEMP &&
+            headTemp2 == UNDEFINED_TEMP &&
+            chillerTemp1 == UNDEFINED_TEMP &&
+            chillerTemp2 == UNDEFINED_TEMP) {
+        return UNDEFINED_TEMP;
+    }
+
+    for (i = 0; i < (sizeof(tempSource) / sizeof(uint8_t)); i++) {
+        if (tempSource[i] != UNDEFINED_TEMP) {
+            maxTemp = tempSource[i];
+            break;
+        }
+    }
+
+    for (i = 0; i < (sizeof(tempSource) / sizeof(uint8_t)); i++) {
+        if (tempSource[i] != UNDEFINED_TEMP) {
+            if (maxTemp < tempSource[i]) {
+                maxTemp = tempSource[i];
+            }
+        }
+    }
+
+    return maxTemp;
+}
+
+static uint8_t returnConnectTemp(uint8_t headTemp1, uint8_t headTemp2)
+{
+    uint8_t maxTemp = 0;
+
+    if (headTemp1 == UNDEFINED_TEMP &&
+            headTemp2 == UNDEFINED_TEMP) {
+        return UNDEFINED_TEMP;
+    }
+
+    if (headTemp1 != UNDEFINED_TEMP) {
+        maxTemp = headTemp1;
+    } else {
+        headTemp1 = 0;
+    }
+
+    if (headTemp2 != UNDEFINED_TEMP) {
+        if (headTemp2 > headTemp1) {
+            maxTemp = headTemp2;
+        }
+    }
+
+    return maxTemp;
+}
+
+static float ReadAdcVolt(uint8_t AdcChannel)
+{
+    //AIN0=CCS GUN Temp 1
+    //AIN1=CCS GUN Temp 2
+    //AIN2=CCS_Proximity/2
+    //AIN3=pilot voltage
+    int fd = -1;
+    uint8_t str[64];
+    uint8_t AdcValue[4];
+
+    if (AdcChannel > 7) {
+        return -1;
+    }
+
+    memset(str, 0, sizeof(str));
+    memset(AdcValue, 0, sizeof(AdcValue));
+    sprintf((char *)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel);
+    fd = open((char *)str, O_RDONLY);
+    read(fd, AdcValue, 4);
+
+    close(fd);
+
+    return (1.8 * atoi(AdcValue)) / 4095;
+}
+
+static void getChillerTemperature(ChillerTemp *chillerTemp)
+{
+    uint8_t i = 0;
+    float adcVoltage = 0.0;
+    ChillerTemp *pChillerTemp = (ChillerTemp *)chillerTemp;
+
+    for (i = 0; i < 2; i++) {
+        adcVoltage = 0.0;
+        adcVoltage =  ReadAdcVolt(i);
+        if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
+            chillerTemp->Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
+            //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
+        } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) {
+            chillerTemp->Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60;
+            //log_info("2 adcVoltage = %f", (adcVoltage - 0.9) * 500);
+        } /*else {
+            chillerTemp->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)
+    }
+}
+
 void CANReceiver()
 {
     pid_t canRecPid;
@@ -2174,12 +2267,11 @@ void CANReceiver()
     canRecPid = fork();
 
     if (canRecPid > 0) {
-        uint8_t temperatureP[2] = {0};
-        uint8_t temperatureN[2] = {0};
         int nbytes;
         struct can_frame frame;
         int intCmd;
         bool isClearBuf = false; //DS60-120 add
+        ChillerTemp chiilerTemp = {0};
 
         // 槍資訊
         struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
@@ -2190,7 +2282,7 @@ void CANReceiver()
 
         while (!isPass) {
             isPass = true;
-            for (byte _index = 0; _index < gun_count; _index++) {
+            for (uint8_t _index = 0; _index < gun_count; _index++) {
                 if (!FindChargingInfoData(_index, &_chargingData[0])) {
                     log_error("EvComm (main) : FindChargingInfoData false \n");
                     isPass = false;
@@ -2201,7 +2293,7 @@ void CANReceiver()
             sleep(1);
         }
 
-        for (byte _index = 0; _index < gun_count; _index++) {
+        for (uint8_t _index = 0; _index < gun_count; _index++) {
             gettimeofday(&_cmd_ack_timeout[_index], NULL);
         }
 
@@ -2209,7 +2301,7 @@ void CANReceiver()
             memset(&frame, 0, sizeof(struct can_frame));
             nbytes = read(CanFd, &frame, sizeof(struct can_frame));
 
-            for (byte _index = 0; _index < gun_count; _index++) {
+            for (uint8_t _index = 0; _index < gun_count; _index++) {
                 if (GetTimeoutValue(_cmd_ack_timeout[_index]) >= 5000000) {
                     // ACK timeout
                     //log_info("gun = %x, ack timeout \n", _index);
@@ -2217,8 +2309,8 @@ void CANReceiver()
             }
 
             if (nbytes > 0) {
-                byte target;
-                byte targetGun = 0x00;
+                uint8_t target;
+                uint8_t targetGun = 0x00;
                 intCmd = (int) (frame.can_id & CAN_EFF_MASK);
 
                 if (!isClearBuf) { //DS60-120 add
@@ -2232,9 +2324,9 @@ void CANReceiver()
 
                 intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
 
-                target = ((byte) (frame.can_id & 0x000000FF));      // 0x01 or 0x02
+                target = ((uint8_t) (frame.can_id & 0x000000FF));      // 0x01 or 0x02
 
-                for (byte _index = 0; _index < gun_count; _index++) {                    // 假設有找到回應的 Index
+                for (uint8_t _index = 0; _index < gun_count; _index++) {                    // 假設有找到回應的 Index
                     if (_chargingData[_index]->Evboard_id == target) {
                         targetGun = _index;
                         break;
@@ -2274,7 +2366,7 @@ void CANReceiver()
                 }
                 break;
                 case ACK_EV_FW_VERSION: {
-                    byte ver[16];
+                    uint8_t ver[16];
 
                     memset(ver, 0, sizeof(ver));
                     if (_chargingData[targetGun]->Type == _Type_Chademo) {
@@ -2291,7 +2383,7 @@ void CANReceiver()
                         if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
                             memcpy(ver, frame.data, frame.can_dlc); //DS60-120 add
 
-                            //for (byte _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++) {//DS60-120 remove
+                            //for (uint8_t _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++) {//DS60-120 remove
                             /*if (_vCount % 2 == 0 && _vCount != 0)
                             {
                                 ver[_vCount + _vPoint] = 0x2E;
@@ -2417,23 +2509,58 @@ void CANReceiver()
                         ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
                         ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
                         ShmGBTData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                            //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
-                            //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
-                        }
+                    }
+                    /*else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
+                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                        //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
+                        //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
+                    }
+                    }*/
+
+                    //memset((uint8_t)&chiilerTemp, 0, sizeof(ChillerTemp));
+                    if (targetGun == 0 &&
+                            ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
+                             (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "F", 1) == 0))
+                       ) {
+                        getChillerTemperature(&chiilerTemp);
+                        //log_info("%d chillerTemp1 = %d, temp2 = %d\r\n", targetGun, chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
+                        _chargingData[targetGun]->ConnectorTemp = returnConnectTempAndChiller(
+                                    frame.data[1],
+                                    frame.data[2],
+                                    chiilerTemp.Temp[0],
+                                    chiilerTemp.Temp[1]);
+                    } else if (targetGun == 1 &&
+                               ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "V", 1) == 0) ||
+                                (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "F", 1) == 0))
+                              ) {
+                        getChillerTemperature(&chiilerTemp);
+                        //log_info("%d chillerTemp1 = %d, temp2 = %d\r\n", targetGun, chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
+                        _chargingData[targetGun]->ConnectorTemp = returnConnectTempAndChiller(
+                                    frame.data[1],
+                                    frame.data[2],
+                                    chiilerTemp.Temp[0],
+                                    chiilerTemp.Temp[1]);
+                    } else {
+                        _chargingData[targetGun]->ConnectorTemp = returnConnectTemp(frame.data[1], frame.data[2]);
+                        //log_info("connector temperature = %d\r\n", _chargingData[targetGun]->ConnectorTemp);
                     }
 
                     //log_info("EvboardStatus = %x \n",
                     //         ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus);
                     //log_info("ConnectorPlug locked = %x \n",
                     //         frame.data[0]);
-                    //if (targetGun == 1) {
-                    //    log_info("ConnectorTemp 0= %d\r\n",
-                    //             frame.data[1]);
-                    //    log_info("ConnectorTemp 1= %d\r\n",
-                    //             frame.data[2]);
-                    //}
+
+                    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);
                 }
                 break;
@@ -2481,10 +2608,10 @@ void CANReceiver()
 //================================================
 // Main process
 //================================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
+// 檢查 uint8_t 中某個 Bit 的值
+// _uint8_t : 欲改變的 byte
+// _bit : 該 uint8_t 的第幾個 bit
+uint8_t EvDetectionStatus(uint8_t _byte, uint8_t _bit)
 {
     return ( _byte & mask_table[_bit] ) != 0x00;
 }
@@ -2639,7 +2766,7 @@ void Initialization()
     bool isPass = false;
     while (!isPass) {
         isPass = true;
-        for (byte _index = 0; _index < gun_count; _index++) {
+        for (uint8_t _index = 0; _index < gun_count; _index++) {
             if (!FindChargingInfoData(_index, &_chargingData[0])) {
                 log_error("EvComm (main) : FindChargingInfoData false \n");
                 isPass = false;
@@ -2650,7 +2777,7 @@ void Initialization()
     }
 }
 
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
+void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
 {
     if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol) {
         *vol = maxChargingVol[index];
@@ -2670,7 +2797,7 @@ void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
     }
 }
 
-void GetMaxPowerMethod(byte index, float *pow)
+void GetMaxPowerMethod(uint8_t index, float *pow)
 {
     if (maxChargingPow != 0 && maxChargingPow <= *pow) {
         *pow = maxChargingPow;
@@ -2705,9 +2832,9 @@ time_t GetRtcInfoForEpoch()
     return result;
 }
 
-byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
+uint8_t GetStopChargingReasonByEvse(uint8_t gunIndex, uint8_t *reason)
 {
-    byte result = NO;
+    uint8_t result = NO;
 
     if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == 0x01) {
         // 012251
@@ -2805,6 +2932,24 @@ byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
 
 void FormatVoltageAndCurrent()
 {
+    uint8_t gunIndex = 0;
+    ParsingRatedCur parsingRatedCur = {0};
+    RateCurInfo *pRatedCurInfo = NULL;
+
+    if (RatedCurrentParsing((char *)ShmSysConfigAndInfo->SysConfig.ModelName, &parsingRatedCur) != PASS) {
+        log_error("Parsing rated current failed\r\n");
+        return;
+    }
+
+    maxChargingPow = parsingRatedCur.Power;
+
+    for (gunIndex = 0; gunIndex < gun_count; gunIndex++) {
+        pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[gunIndex];
+
+        maxChargingVol[gunIndex] = pRatedCurInfo->Voltage;
+        maxChargingCur[gunIndex] = pRatedCurInfo->Current;
+    }
+#if 0
     char isLowCur = 0x00;
     char EvsePower[2];
 
@@ -2821,7 +2966,7 @@ void FormatVoltageAndCurrent()
         }
     }
 
-    for (byte _index = 0; _index < gun_count; _index++) {
+    for (uint8_t _index = 0; _index < gun_count; _index++) {
         if (_chargingData[_index]->Type == _Type_Chademo) {
             maxChargingVol[_index] = chademoVol;
         } else if (_chargingData[_index]->Type == _Type_CCS_2) {
@@ -2900,6 +3045,44 @@ void FormatVoltageAndCurrent()
             }
         }
     }
+#endif //0
+}
+
+static void checkConnectorOVPState(uint8_t _index)
+{
+    // 避免槍溫偵測誤判
+    static uint8_t gunTempAllowCount[2] = {0, 0};
+    bool isOTP = false;
+
+    switch (_chargingData[_index]->Type) {
+    case _Type_Chademo:
+        if (ShmDcCommonData->ConnectErrList[_index].GunBits.ChaConnectOTP) {
+            isOTP = true;
+        }
+        break;
+
+    case _Type_CCS_2:
+        if (ShmDcCommonData->ConnectErrList[_index].GunBits.CCSConnectOTP) {
+            isOTP = true;
+        }
+        break;
+
+    case _Type_GB:
+        if (ShmDcCommonData->ConnectErrList[_index].GunBits.GBTConnectOTP) {
+            isOTP = true;
+        }
+        break;
+    }
+
+    if (isOTP) {
+        if (gunTempAllowCount[_index] >= 2) {
+            _chargingData[_index]->StopChargeFlag = YES;
+        } else {
+            gunTempAllowCount[_index] += 1;
+        }
+    } else {
+        gunTempAllowCount[_index] = 0;
+    }
 }
 
 int main(int argc, char *argv[])
@@ -2922,10 +3105,10 @@ int main(int argc, char *argv[])
     CanFd = InitCanBus();
     CANReceiver();
 
-    byte priorityLow = 1;
+    uint8_t priorityLow = 1;
     time_t rtc = GetRtcInfoForEpoch();
 
-    for (byte _index = 0; _index < gun_count; _index++) { //DS60-120 add
+    for (uint8_t _index = 0; _index < gun_count; _index++) { //DS60-120 add
         if (_chargingData[_index]->Type == _Type_Chademo) {
             log_info("Conn %d (Chademo), MaxVol = %f, MaxCur = %f \n",
                      _index, maxChargingVol[_index], maxChargingCur[_index]);
@@ -2939,7 +3122,7 @@ int main(int argc, char *argv[])
     }
 
     while (CanFd) {
-        for (byte _index = 0; _index < gun_count; _index++) {
+        for (uint8_t _index = 0; _index < gun_count; _index++) {
 
             if (priorityLow == 1) {
                 // 優先權較低 - 只要有回應即不會再詢問
@@ -2966,6 +3149,8 @@ int main(int argc, char *argv[])
                                      _chargingData[_index]->PresentChargedEnergy,
                                      (_chargingData[_index]->PresentChargingVoltage * 10),
                                      _chargingData[_index]->Evboard_id);
+
+                checkConnectorOVPState(_index);
             }
 
             switch (_chargingData[_index]->SystemStatus) {
@@ -3008,7 +3193,7 @@ int main(int argc, char *argv[])
 
                     //maxChargingPow = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
                     // ShmPsuData->SystemAvailablePower 已是 * 10
-                    maxChargingPow = ShmPsuData->SystemAvailablePower;
+                    //maxChargingPow = ShmPsuData->SystemAvailablePower;
                     if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 != 0 &&
                             ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 < maxChargingPow) {
                         maxChargingPow = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
@@ -3136,7 +3321,7 @@ int main(int argc, char *argv[])
                     //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
                     {
                         //if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
-                        unsigned char _result = _chargingData[_index]->GroundFaultStatus;
+                        uint8_t _result = _chargingData[_index]->GroundFaultStatus;
 
                         // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
                         if (_chargingData[_index]->Type == _Type_Chademo ||
@@ -3260,15 +3445,15 @@ int main(int argc, char *argv[])
                 // 槍鎖還在,則代表是樁端要求的停止
                 if (_chargingData[_index]->GunLocked == START ||
                         _chargingData[_index]->Type == _Type_CCS_2) {
-                    byte normalStop = 0x01;
-                    byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+                    uint8_t normalStop = 0x01;
+                    uint8_t stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
                     if (GetStopChargingReasonByEvse(_index, stopReason)) {
                         normalStop = 0x02;
                     }
 
                     EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);
-                    SendErrorCount[_index] += 1;//DS60-120 add
+                    SendErrorCount[_index] += 1; //DS60-120 add
                 }
 
                 if (_chargingData[_index]->Type == _Type_CCS_2) {
@@ -3338,6 +3523,8 @@ int main(int argc, char *argv[])
         priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
         usleep(45000); //EV 小板通訊 (50 ms)
     }
+
     log_info("Module_EvComm : Can-bus port = %d \n", CanFd);
+
     return FAIL;
 }

+ 38 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.h

@@ -0,0 +1,38 @@
+#ifndef MODULE_EVCOMM_H_
+#define MODULE_EVCOMM_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+#define COMMUNICATION       2
+#define CHK_VOL_RANGE       50
+#define CHK_CUR_RANGE       20
+#define PLUG                1
+#define UNPLUG              0
+
+//------------------------------------------------------------------------------
+//DS60-120 add
+enum EV_LOG_INDEX {
+    EV_LOG_OUTPUT_CAP_POW = 0,
+    EV_LOG_OUTPUT_CAP_CUR = 1,
+    EV_LOG_NOW_OUTPUT_VOL = 2,
+    EV_LOG_NOW_OUTPUT_CUR = 3,
+    EV_LOG_EVSE_MAX_VOL   = 4,
+    EV_LOG_EVSE_MAX_CUR   = 5,
+    EV_LOG_MAX_BATT_VOL   = 6,
+    EV_LOG_REAL_CAP_POW   = 7,
+    EV_LOG_SOC            = 8,
+};
+
+//------------------------------------------------------------------------------
+typedef struct StChiilerTemp {
+    uint8_t Temp[2];
+    uint8_t Reserved[2];
+} ChillerTemp;
+
+//------------------------------------------------------------------------------
+int GetCanFd(void);
+
+#endif /* MODULE_EVCOMM_H_ */
+

+ 63 - 79
EVSE/Projects/DD360Audi/Apps/ReModule_EventLogging.c → EVSE/Projects/DD360/Apps/ModuleEventLog/Module_EventLogging.c

@@ -1,52 +1,47 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    "../../define.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include "../../../define.h"
+#include "../Config.h"
+
+//------------------------------------------------------------------------------
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 
 sqlite3 *localDb; //DS60-120 add
-#define DB_FILE             "/Storage/ChargeLog/localCgargingRecord.db" //DS60-120 add
 
-void PRINTF_FUNC(char *string, ...);
+//------------------------------------------------------------------------------
+#define DB_FILE             "/Storage/ChargeLog/localCgargingRecord.db" //DS60-120 add
 
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define EVENT_INFO(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
 
 int StoreLogMsg(const char *fmt, ...)
 {
@@ -134,17 +129,6 @@ int DiffTimeb(struct timeb ST, struct timeb ET)
     return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
 }
 
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
 //=================================
 // Common routine
 //=================================
@@ -189,7 +173,7 @@ int InitShareMemory()
 //================================================
 // Main process
 //================================================
-void AddFaultCodeToBuf(unsigned char *Code)
+void AddFaultCodeToBuf(uint8_t *Code)
 {
     if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
         memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
@@ -197,16 +181,16 @@ void AddFaultCodeToBuf(unsigned char *Code)
     }
 }
 
-void RemoveFaultCodeToBuf(unsigned char *Code)
+void RemoveFaultCodeToBuf(uint8_t *Code)
 {
-    unsigned char find = 0x01;
+    uint8_t find = 0x01;
     char _code[7];
     sprintf(_code, "%s", Code);
 
     // 把相關的錯誤碼一次移除,避免重複顯示
     while (find) {
         find = 0x00;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
             if (find == 0x00) {
                 if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
                     find = 0x01;
@@ -238,16 +222,16 @@ int DB_Open(sqlite3 *db) //DS60-120 add
 
     if (sqlite3_open(DB_FILE, &db)) {
         result = FAIL;
-        DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
+        log_error( "Can't open database: %s\n", sqlite3_errmsg(db));
         sqlite3_close(db);
     } else {
-        DEBUG_INFO( "Local event record database open successfully.\n");
+        log_info( "Local event record database open successfully.\n");
 
         if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
-            DEBUG_ERROR( "Create local event record table error message: %s\n", errMsg);
+            log_error( "Create local event record table error message: %s\n", errMsg);
         } else {
-            DEBUG_INFO( "Opened local event record table successfully\n");
+            log_info( "Opened local event record table successfully\n");
         }
 
         sqlite3_close(db);
@@ -266,23 +250,23 @@ int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode) //DS60-120 add
 
     if (sqlite3_open(DB_FILE, &db)) {
         result = FAIL;
-        DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(db));
         sqlite3_close(db);
     } else {
-        DEBUG_INFO( "Local event record database open successfully.\n");
+        log_info( "Local event record database open successfully.\n");
         if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
-            DEBUG_INFO( "Insert local event record error message: %s\n", errMsg);
+            log_info( "Insert local event record error message: %s\n", errMsg);
         } else {
-            DEBUG_INFO( "Insert local event record successfully\n");
+            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(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
-            DEBUG_INFO( "delete local event_record error message: %s\n", errMsg);
+            log_info( "delete local event_record error message: %s\n", errMsg);
         } else {
-            DEBUG_INFO( "delete local event record successfully\n");
+            log_info( "delete local event record successfully\n");
         }
 
         sqlite3_close(db);
@@ -294,10 +278,10 @@ int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode) //DS60-120 add
 int main(void)
 {
     int ByteCount, BitCount;
-    unsigned char tmp, EventCodeTmp[7];
+    uint8_t tmp, EventCodeTmp[7];
 
     if (InitShareMemory() == FAIL) {
-        DEBUG_ERROR("InitShareMemory NG\n");
+        log_error("InitShareMemory NG\n");
         if (ShmStatusCodeData != NULL) {
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
         }
@@ -316,16 +300,16 @@ int main(void)
                         memcpy(EventCodeTmp, FaultStatusCode[ByteCount * 8 + BitCount], sizeof(EventCodeTmp) - 1);
                         if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
                             //EventCodeTmp[0]=1;
-                            DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
+                            log_info("Recovery Fault Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1 << BitCount);
                             RemoveFaultCodeToBuf(EventCodeTmp);
                             EventCodeTmp[0] = '1';//DS60-120 add
                         } else {
-                            DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
+                            log_info("Fault Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1 << BitCount);
                             AddFaultCodeToBuf(EventCodeTmp);
                         }
-                        EVENT_INFO("%s\n", EventCodeTmp); //DS60-120 add
+                        event_info("%s\n", EventCodeTmp); //DS60-120 add
                         DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
                     }
                 }
@@ -342,16 +326,16 @@ int main(void)
                         memcpy(EventCodeTmp, AlarmStatusCode[ByteCount * 8 + BitCount], sizeof(EventCodeTmp) - 1);
                         if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
                             //EventCodeTmp[0]=1;
-                            DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
+                            log_info("Recovery Alarm Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1 << BitCount);
                             RemoveFaultCodeToBuf(EventCodeTmp);
                             EventCodeTmp[0] = '1';//DS60-120 add
                         } else {
-                            DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
+                            log_info("Alarm Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1 << BitCount);
                             AddFaultCodeToBuf(EventCodeTmp);
                         }
-                        EVENT_INFO("%s\n", EventCodeTmp); //DS60-120 add
+                        event_info("%s\n", EventCodeTmp); //DS60-120 add
                         DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
                     }
                 }
@@ -368,16 +352,16 @@ int main(void)
                         memcpy(EventCodeTmp, InfoStatusCode[ByteCount * 8 + BitCount], sizeof(EventCodeTmp) - 1);
                         if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
                             //EventCodeTmp[0]=1;
-                            DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
+                            log_info("Recovery Info Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1 << BitCount);
                             RemoveFaultCodeToBuf(EventCodeTmp);
                             EventCodeTmp[0] = '1';//DS60-120 add
                         } else {
-                            DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
+                            log_info("Info Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1 << BitCount);
                             AddFaultCodeToBuf(EventCodeTmp);
                         }
-                        EVENT_INFO("%s\n", EventCodeTmp); //DS60-120 add
+                        event_info("%s\n", EventCodeTmp); //DS60-120 add
                         DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
                     }
                 }

+ 171 - 248
EVSE/Projects/DD360ComBox/Apps/ReModule_InternalComm.c → EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.c

@@ -7,7 +7,6 @@
 #include <sys/socket.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
-#include <sys/shm.h>
 #include <sys/mman.h>
 #include <linux/wireless.h>
 #include <arpa/inet.h>
@@ -29,35 +28,12 @@
 #include <math.h>
 #include <stdbool.h>
 
-#include "../../define.h"
+#include "../../../define.h"
+#include "Module_InternalComm.h"
 #include "internalComm.h"
-#include "Config.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-#define STOP                0
-#define START               1
-#define RELAY_CHECK_TIME    5       // s
-#define OUTPUT_VOL_CHK_TIME 200     // ms
-#define TEN_MINUTES         600     // s
-//#define TEN_MINUTES           5
-#define ENV_TEMP_MIN        45
-#define ENV_TEMP_MAX        50
-#define DEFAULT_AC_INDEX    2
-#define EQUAL               0
-#define COLOR_MAX_LV        100
-#define COLOR_MIN_LV        0
-
-#define AC_DEFAULT_VOL      220
-
-#define NO_DEFINE           255
-#define NDEFAULT_AC_INDEX   2
-
-#define OVP_UVP_CHK_COUNT   3
+#include "../Config.h"
 
+//------------------------------------------------------------------------------
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 struct FanModuleData            *ShmFanModuleData;
@@ -67,54 +43,8 @@ struct PsuData                  *ShmPsuData;
 struct OCPP16Data               *ShmOCPP16Data;
 struct DcCommonInformation      *ShmDcCommonData;
 
-#define VIN_MAX_VOLTAGE_IEC         285 // 大於該值 : OVP
-#define VIN_MAX_REV_VOLTAGE_IEC     275 // 小於賦歸 OVP
-#define VIN_MIN_VOLTAGE_IEC         160 // 小於該值 : UVP
-#define VIN_MIN_REV_VOLTAGE_IEC     170 // 大於賦歸 UVP
-
-#define VIN_MAX_VOLTAGE_UL          315 // 大於該值 : OVP // 美規 (W)
-#define VIN_MAX_REV_VOLTAGE_UL      305 // 小於賦歸 OVP
-#define VIN_MIN_VOLTAGE_UL          210 // 小於該值 : UVP
-#define VIN_MIN_REV_VOLTAGE_UL      220 // 大於賦歸 UVP
-
-#define VIN_DROP_VOLTAGE    150 // 小於該值 : ac drop
-
-#define VOUT_MAX_VOLTAGE    995
-#define VOUT_MIN_VOLTAGE    150
-#define IOUT_MAX_CURRENT    50
-
-#define MAX_FAN_SPEED       14000
-#define MIN_FAN_SPEED       3000
-#define NORMAL_FAN_SPEED    7000
-
-// GFD Status
-#define GFD_IDLE            0
-#define GFD_CABLECHK        1
-#define GFD_PRECHARGE       2
-#define GFD_CHARGING        3
-
-// LED Intensity (rate)
-#define LED_INTENSITY_DARKEST       0.2
-#define LED_INTENSITY_MEDIUM        0.6
-#define LED_INTENSITY_BRIGHTEST     1
-
-// EE Spec
-#define LED_BRIGHTNESS_LV_HIGH      1
-#define LED_BRIGHTNESS_LV_MID       0.5
-#define LED_BRIGHTNESS_LV_LOW       0.2
-
-// 最小切換 Relay 電壓
-#define SELF_TO_CHANGE_RELAY_STATUS         600
-// 透過電壓確認 Relay 是否搭上的依據電壓
-#define CHECK_RELAY_STATUS                  300
-#define CHECK_RELAY_STATUS_GAP              100
-// 安全在停止充電程序中斷開 Relay 的電流
-#define SEFETY_SWITCH_RELAY_CUR             50//20 DS60-120 modify
-// 確認 Relay Welding 電壓
-#define RELAY_WELDING_DET                   300
-
-byte gunCount;
-byte acgunCount;
+uint8_t gunCount;
+uint8_t acgunCount;
 // 槍資訊
 struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
@@ -131,10 +61,10 @@ struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_
 // SMR1 *2 + SMR2 * 2 + Parallel * 2
 struct timeval _relayStateChkTimer[6]; //DS60-120 add
 
-byte _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
-byte _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
+uint8_t _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
+uint8_t _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
 
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData);
 
 int Uart5Fd;
 char *relayRs485PortName = "/dev/ttyS5";
@@ -153,7 +83,7 @@ struct timeb    _ac_endChargingTime;
 
 unsigned short _setFanSpeed = 0;
 float _beforeChargingTotalEnergy = 0.0;
-byte _checkLedChanged = 3;
+uint8_t _checkLedChanged = 3;
 
 Ver ver;
 PresentInputVoltage inputVoltage;
@@ -177,38 +107,27 @@ Ac_Alarm_code acAlarmCode;
 Ac_Charging_energy acChargingEnergy;
 Ac_Charging_current acChargingCurrent;
 
-#define AC_OVP                      1
-#define AC_UVP                      2
-#define AC_OCP                      4
-#define AC_OTP                      8
-#define AC_GMI_FAULT                16
-#define AC_CP_ERROR                 32
-#define AC_AC_LEAKAGE               64
-#define AC_DC_LEAKAGE               128
-#define AC_SYSTEM_SELFTEST_FAULT    256
-#define AC_HANDSHAKE_TIMEOUT        512
-#define AC_EMC_STOP                 1024
-#define AC_RELAY_WELDING            2048
-#define AC_GF_MODULE_FAULT          4096
-#define AC_SHUTTER_FAULT            8192
-#define AC_LOCKER_FAULT             16384
-#define AC_POWER_DROP               32768
-#define AC_CIRCUIT_SHORT            65536
-#define AC_ROTARY_SWITCH_FAULT      131072
-#define AC_RELAY_DRIVE_FAULT        262144
-
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-int _alarm_code[] = {AC_OVP, AC_UVP, AC_OCP, AC_OTP, AC_GMI_FAULT, AC_CP_ERROR, AC_AC_LEAKAGE
-                     , AC_DC_LEAKAGE, AC_SYSTEM_SELFTEST_FAULT, AC_HANDSHAKE_TIMEOUT, AC_EMC_STOP, AC_RELAY_WELDING
-                     , AC_GF_MODULE_FAULT, AC_SHUTTER_FAULT, AC_LOCKER_FAULT, AC_POWER_DROP, AC_CIRCUIT_SHORT
-                     , AC_ROTARY_SWITCH_FAULT, AC_RELAY_DRIVE_FAULT
-                    };
-
-int StoreLogMsg(const char *fmt, ...);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
+int _alarm_code[] = {
+    AC_OVP,
+    AC_UVP,
+    AC_OCP,
+    AC_OTP,
+    AC_GMI_FAULT,
+    AC_CP_ERROR,
+    AC_AC_LEAKAGE,
+    AC_DC_LEAKAGE,
+    AC_SYSTEM_SELFTEST_FAULT,
+    AC_HANDSHAKE_TIMEOUT,
+    AC_EMC_STOP,
+    AC_RELAY_WELDING,
+    AC_GF_MODULE_FAULT,
+    AC_SHUTTER_FAULT,
+    AC_LOCKER_FAULT,
+    AC_POWER_DROP,
+    AC_CIRCUIT_SHORT,
+    AC_ROTARY_SWITCH_FAULT,
+    AC_RELAY_DRIVE_FAULT
+};
 
 unsigned long GetTimeoutValue(struct timeval _sour_time)
 {
@@ -271,7 +190,7 @@ unsigned short MaxValue(unsigned short value1, unsigned short value2)
 //==========================================
 void GetFwAndHwVersion_Fan()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // FanModuleData
         strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
         // SystemInfo
@@ -279,7 +198,7 @@ void GetFwAndHwVersion_Fan()
         //log_info("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
     }
 
-    if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
+    if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // SystemInfo
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
@@ -288,7 +207,7 @@ void GetFwAndHwVersion_Fan()
 
 void GetFwAndHwVersion_Relay()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
         // RelayModuleData
         strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
         // SystemInfo
@@ -296,7 +215,7 @@ void GetFwAndHwVersion_Relay()
         //log_info("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
     }
 
-    if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
+    if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
         // SystemInfo
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
@@ -305,7 +224,7 @@ void GetFwAndHwVersion_Relay()
 
 void GetFwAndHwVersion_Led()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS) {
         // LedModuleData
         strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
         // SystemInfo
@@ -316,7 +235,7 @@ void GetFwAndHwVersion_Led()
         //log_info("GetFwAndHwVersion_Led fail \n");
     }
 
-//  if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
+//  if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
 //  {
 //      // SystemInfo
 //      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
@@ -326,7 +245,7 @@ void GetFwAndHwVersion_Led()
 
 void GetFwVersion_AC()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_AC_PLUG, &ver) == PASS) {
         ac_chargingInfo[0]->SelfTest_Comp = YES;
         strcpy((char *) ac_chargingInfo[0]->version, ver.Version_FW);
     }
@@ -335,7 +254,7 @@ void GetFwVersion_AC()
 void GetAcModelName()
 {
     memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
-    if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
+    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
         log_info("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
     }
 }
@@ -371,14 +290,14 @@ void SetRtcData_Relay()
     rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
     rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
 
-    if (Config_Rtc_Data(Uart5Fd, Addr.Relay, &rtc) == PASS) {
+    if (Config_Rtc_Data(Uart5Fd, ADDR_RELAY, &rtc) == PASS) {
         //log_info("SetRtc (RB) sucessfully. \n");
     }
 }
 
 void SetModelName_Relay()
 {
-    if (Config_Model_Name(Uart5Fd, Addr.Relay, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(Uart5Fd, ADDR_RELAY, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
         //log_info("Set Model name (RB) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
     }
 }
@@ -414,22 +333,22 @@ void SetRtcData_Fan()
     rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
     rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
 
-    if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS) {
+    if (Config_Rtc_Data(Uart5Fd, ADDR_FAN, &rtc) == PASS) {
         //log_info("SetRtc (FB) sucessfully. \n");
     }
 }
 
 void SetModelName_Fan()
 {
-    if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(Uart5Fd, ADDR_FAN, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
         log_info("Set Model name PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
     }
 }
 
 // AC 三相輸入電壓
-void GetPresentInputVol()
+void GetPresentInputVol(void)
 {
-    if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS) {
+    if (Query_Present_InputVoltage(Uart5Fd, ADDR_RELAY, &inputVoltage) == PASS) {
         // resolution : 0.1
         ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
         ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
@@ -638,68 +557,65 @@ void GetPresentInputVol()
 }
 
 // 左右槍的 Relay 前後的輸出電壓
-void GetPersentOutputVol()
+void GetPersentOutputVol(void)
 {
-    if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS) {
-//      log_info("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-//      log_info("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
-//      log_info("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
-//      log_info("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
+    uint8_t index = 0;
 
-        //log_info("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-        //log_info("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+    if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
+        return;
+    }
 
-        ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
-        ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
-        ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
-        ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
+    //log_info("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+    //log_info("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
+    //log_info("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+    //log_info("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
 
-        for (int index = 0; index < gunCount; index++) {
-            if (index == 0) {
-                //if (_chargingData[index]->Evboard_id == 0x01) {
-                if (index == 0) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif //!defined DD360 && !defined DD360Audi
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+    //log_info("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+    //log_info("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
 
-                    //} else if (_chargingData[index]->Evboard_id == 0x02) {
-                } else if (index == 1) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif //!defined DD360 && !defined DD360Audi
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-                }
-            } else if (index == 1) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif //!defined DD360 && !defined DD360Audi
-                _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-            }
+    ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
+    ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
+    ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
+    ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
 
-            //unsigned short Ovp = 0;
-            //unsigned short Ocp = 0;
-            //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE]  // 最大輸出電壓與電池電壓最大值
-            //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]      // 最大輸出電流與需求電流最小值
-            if (_chargingData[index]->Type == _Type_Chademo) {
-                //Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
-                //Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
-            } else if (_chargingData[index]->Type == _Type_CCS_2) {
+    for (index = 0; index < gunCount; index++) {
+        switch (index) {
+        case 0:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+            _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
+            _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
+            _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-            }
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+            _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
+            break;
+
+        case 1:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+            _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
+            _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
+            _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+            _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
+            break;
         }
+
+        //unsigned short Ovp = 0;
+        //unsigned short Ocp = 0;
+        //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE]  // 最大輸出電壓與電池電壓最大值
+        //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]      // 最大輸出電流與需求電流最小值
+        //if (_chargingData[index]->Type == _Type_Chademo) {
+        //    //Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
+        //    //Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
+        //} else if (_chargingData[index]->Type == _Type_CCS_2) {
+        //}
     }
 }
 
@@ -707,7 +623,7 @@ void GetPersentOutputVol()
 void GetFanSpeed()
 {
     //log_info("Get fan board speed \n");
-    if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS) {
+    if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
         ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
         ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
         ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
@@ -716,15 +632,15 @@ void GetFanSpeed()
 //      log_info("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
 //      log_info("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
 //      log_info("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
-        // Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
+        // Config_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed[0]);
         //SysInfoData (SystemFanRotaSpeed)
     }
 }
 
 // 讀取 Relay 狀態
-void GetRelayOutputStatus()
+void GetRelayOutputStatus(void)
 {
-    if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS) {
+    if (Query_Relay_Output(Uart5Fd, ADDR_RELAY, &regRelay) == PASS) {
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
         regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
 #endif //!defined DD360 && !defined DD360Audi
@@ -732,7 +648,7 @@ void GetRelayOutputStatus()
 }
 
 // 確認 K1 K2 relay 的狀態
-void CheckK1K2RelayOutput(byte index)
+void CheckK1K2RelayOutput(uint8_t index)
 {
     if (index == 0) {
         //if (_chargingData[index]->Evboard_id == 0x01) {
@@ -842,7 +758,7 @@ void GetGfdAdc()
     // define : 每 0.2 ~ 1 秒一次
     // occur : <= 75k 歐姆 @ 150 - 750 Vdc
     // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
-    if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS) {
+    if (Query_Gfd_Adc(Uart5Fd, ADDR_RELAY, &gfd_adc) == PASS) {
         for (gunIndex = 0; gunIndex < gunCount; gunIndex++) {
             if (_chargingData[gunIndex]->Type == 0x09 &&
                     !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag
@@ -911,7 +827,7 @@ void GetGfdAdc()
 
 void GetGpioInput()
 {
-    if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS) {
+    if (Query_Gpio_Input(Uart5Fd, ADDR_AUX, &gpio_in) == PASS) {
         // AC Contactor Status
         if (gpio_in.AC_MainBreaker == 1) {
             // AC Main Breaker ON
@@ -979,7 +895,7 @@ void GetGpioInput()
 // 5V 12V 24V 48V
 void GetAuxPower()
 {
-    if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS) {
+    if (Query_Aux_PowerVoltage(Uart5Fd, ADDR_FAN, &auxPower) == PASS) {
         ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
         ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
         //ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
@@ -1010,7 +926,7 @@ void SetFanModuleSpeed()
 
         _fanSpeed.speed[3] = _setFanSpeed;
 
-        if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS) {
+        if (Config_Fan_Speed(Uart5Fd, ADDR_FAN, &_fanSpeed) == PASS) {
             //log_info("successfully Fan\n");
         }
     }
@@ -1031,7 +947,7 @@ typedef struct StPreCharginState {
 //==========================================
 // Common Function
 //==========================================
-void SetK1K2RelayStatus(byte index)
+void SetK1K2RelayStatus(uint8_t index)
 {
     PreChargingState *pRegPreChargingState = NULL;
     PreChargingState *pOutputPreChargingState = NULL;
@@ -1048,7 +964,7 @@ void SetK1K2RelayStatus(byte index)
         return;
     }
 
-#if 0
+#if 1
     pRegPreChargingState = (PreChargingState *)&regRelay.relay_event.relay_status[0];
     pOutputPreChargingState = (PreChargingState *)&outputRelay.relay_event.relay_status[0];
     if (index == 0) {
@@ -1135,7 +1051,7 @@ void SetK1K2RelayStatus(byte index)
     }
 #endif //0
 
-#if 1
+#if 0
     if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE) {
         //if (_chargingData[index]->Evboard_id == 0x01) {
         if (index == 0) {
@@ -1259,7 +1175,7 @@ void SetK1K2RelayStatus(byte index)
 #endif //0
 }
 
-void CheckAcInputOvpStatus(byte index)
+void CheckAcInputOvpStatus(uint8_t index)
 {
     if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
@@ -1297,7 +1213,7 @@ void CheckAcInputOvpStatus(byte index)
     }
 }
 
-void CheckPhaseLossStatus(byte index)
+void CheckPhaseLossStatus(uint8_t index)
 {
     if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
@@ -1368,7 +1284,7 @@ void SetParalleRelayStatus(void)
 void CheckAlarmOccur()
 {
     bool isErr = false;
-    for (byte count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
+    for (uint8_t count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
         if (acAlarmCode.AcAlarmCode & _alarm_code[count]) {
             isErr = true;
             switch (_alarm_code[count]) {
@@ -1438,7 +1354,7 @@ bool IsNoneMatchLedColor()
 
 void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
 {
-    byte _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
+    uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
 
     if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
         _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
@@ -1558,7 +1474,7 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
     }
 
     if (_checkLedChanged > 0) {
-        if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS) {
+        if (Config_Led_Color(Uart5Fd, ADDR_LED, &led_color) == PASS) {
             _checkLedChanged--;
 
             cur_led_color.Connect_1_Red     = led_color.Connect_1_Red;
@@ -1572,6 +1488,7 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
         _checkLedChanged = 3;
     }
 }
+
 //==========================================
 // Init all share memory
 //==========================================
@@ -1650,7 +1567,7 @@ int InitComPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (byte)0;     // timeout 0.5 second
+    tios.c_cc[VTIME] = (uint8_t)0;     // timeout 0.5 second
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl (fd, TCSETS, &tios);
@@ -1661,9 +1578,9 @@ int InitComPort()
 //================================================
 // Main process
 //================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
                 == target) {
             chargingData[target] =
@@ -1672,7 +1589,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
                 == target) {
             chargingData[target] =
@@ -1681,7 +1598,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
                 == target) {
             chargingData[target] =
@@ -1693,7 +1610,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
     return false;
 }
 
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
+bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
 {
     if (target < AC_QUANTITY) {
         acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
@@ -1707,13 +1624,13 @@ void Initialization()
 {
     bool isPass = false;
 
-    for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++) {
+    for (uint8_t index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++) {
         outputRelay.relay_event.relay_status[index] = 0x00;
     }
 
     while (!isPass) {
         isPass = true;
-        for (byte _index = 0; _index < gunCount; _index++) {
+        for (uint8_t _index = 0; _index < gunCount; _index++) {
             if (!FindChargingInfoData(_index, &_chargingData[0])) {
                 log_error("InternalComm : FindChargingInfoData false \n");
                 isPass = false;
@@ -1729,7 +1646,7 @@ void Initialization()
     if (acgunCount > 0) {
         while (!isPass) {
             isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
+            for (uint8_t _index = 0; _index < acgunCount; _index++) {
                 if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
                     log_error("EvComm : FindAcChargingInfoData false \n");
                     isPass = false;
@@ -1835,20 +1752,20 @@ void CheckRelayStatusByADC()
     }
 }
 
-void SetGfdConfig(byte index, byte resister)
+void SetGfdConfig(uint8_t index, uint8_t resister)
 {
     gfd_config.index = index;
     gfd_config.state = resister;
 
     //log_info("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
-    if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS) {
+    if (Config_Gfd_Value(Uart5Fd, ADDR_RELAY, &gfd_config) == PASS) {
 //      log_info("Set reqVol = %f, resister = %d \n",
 //              gfd_config.reqVol,
 //              gfd_config.resister);
     }
 }
 
-void CableCheckDetected(byte index)
+void CableCheckDetected(uint8_t index)
 {
     // Cable Check
     // 當火線上的電壓 = 車端要求的電壓電流
@@ -1857,10 +1774,14 @@ void CableCheckDetected(byte index)
     // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
     // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
     // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
-    if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
-            (_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)) {
-        if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_TERMINATING) ||
-                (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+    if ((_chargingData[index]->Type >= _Type_Chademo &&
+            _chargingData[index]->Type <= _Type_GB) ||
+            (_chargingData[index]->Type == 0x09 &&
+             ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)) {
+        if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
+                _chargingData[index]->SystemStatus <= S_TERMINATING) ||
+                (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                 _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
             if (_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE &&
                     _chargingData[index]->RelayWeldingCheck == YES) {
                 SetGfdConfig(index, GFD_CABLECHK);
@@ -1875,14 +1796,15 @@ void CableCheckDetected(byte index)
                     SetGfdConfig(index, GFD_CHARGING);
                 }
             }
-        } else if (_chargingData[index]->SystemStatus == S_COMPLETE || _chargingData[index]->SystemStatus == S_PREPARNING
+        } else if (_chargingData[index]->SystemStatus == S_COMPLETE ||
+                   _chargingData[index]->SystemStatus == S_PREPARNING
                    || _chargingData[index]->SystemStatus == S_IDLE) {
             SetGfdConfig(index, GFD_IDLE);
         }
     }
 }
 
-void CheckOutputPowerOverCarReq(byte index)
+void CheckOutputPowerOverCarReq(uint8_t index)
 {
     float fireV = _chargingData[index]->FireChargingVoltage;
     float carV = _chargingData[index]->EvBatteryMaxVoltage * 10;
@@ -1921,7 +1843,7 @@ void CheckOutputPowerOverCarReq(byte index)
     }
 }
 
-void CheckOutputVolNoneMatchFire(byte index)
+void CheckOutputVolNoneMatchFire(uint8_t index)
 {
     if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
             (_chargingData[index]->Type == _Type_Chademo ||
@@ -1947,7 +1869,7 @@ void CheckOutputVolNoneMatchFire(byte index)
     }
 }
 
-void CheckRelayWeldingStatus(byte index)
+void CheckRelayWeldingStatus(uint8_t index)
 {
     if (!_isRelayWelding[index]) {
         if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
@@ -1979,8 +1901,8 @@ void GetPsuTempForFanSpeed()
 {
     char temp = 0;
 
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
             if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
                 temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
             }
@@ -2022,18 +1944,18 @@ void GetFanSpeedByFunction()
     // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
     unsigned int _maxPower = ShmPsuData->SystemAvailablePower;
     // 當前PSU輸出總 KW & PSU Temp :
-    unsigned char temp = 0;
+    uint8_t temp = 0;
     float power = 0;
 
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
             if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
                 temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
             }
         }
     }
 
-    for (byte gunIndex = 0; gunIndex < gunCount; gunIndex++) {
+    for (uint8_t gunIndex = 0; gunIndex < gunCount; gunIndex++) {
         power += (_chargingData[gunIndex]->PresentChargingPower * 10);
     }
 
@@ -2045,7 +1967,7 @@ void GetFanSpeedByFunction()
     if (temp > 0) {
         _temp_rate = (double)temp / 50;
     }
-    unsigned char _temp_diff = 0;
+    uint8_t _temp_diff = 0;
     if (temp > 45) {
         _temp_diff = temp - 70;
     }
@@ -2073,7 +1995,7 @@ void GetFanSpeedByFunction()
 
 void GetAcStatus()
 {
-    if (Query_AC_Status(Uart5Fd, Addr.AcPlug, &acStatus) == PASS) {
+    if (Query_AC_Status(Uart5Fd, ADDR_AC_PLUG, &acStatus) == PASS) {
         ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = acStatus.MaxCurrent;
 
         if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0) {
@@ -2102,19 +2024,19 @@ void GetAcStatus()
 
 void GetAcAlarmCode()
 {
-    if (Query_AC_Alarm_Code(Uart5Fd, Addr.AcPlug, &acAlarmCode) == PASS) {
+    if (Query_AC_Alarm_Code(Uart5Fd, ADDR_AC_PLUG, &acAlarmCode) == PASS) {
         CheckAlarmOccur();
     }
 }
 
-unsigned char GetChargingEnergy()
+uint8_t GetChargingEnergy()
 {
-    return Query_Charging_Energy(Uart5Fd, Addr.AcPlug, &acChargingEnergy);
+    return Query_Charging_Energy(Uart5Fd, ADDR_AC_PLUG, &acChargingEnergy);
 }
 
-unsigned char GetChargingCurrent()
+uint8_t GetChargingCurrent()
 {
-    return Query_Charging_Current(Uart5Fd, Addr.AcPlug, &acChargingCurrent);
+    return Query_Charging_Current(Uart5Fd, ADDR_AC_PLUG, &acChargingCurrent);
 }
 
 void ChangeLedStatus()
@@ -2127,30 +2049,30 @@ void ChangeLedStatus()
         ledStatus.ActionMode = 4;
     }
 
-    Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
+    Config_LED_Status(Uart5Fd, ADDR_AC_PLUG, &ledStatus);
 }
 
-void SetLegacyReq(byte _switch)
+void SetLegacyReq(uint8_t _switch)
 {
-    Config_Legacy_Req(Uart5Fd, Addr.AcPlug, _switch);
+    Config_Legacy_Req(Uart5Fd, ADDR_AC_PLUG, _switch);
 }
 
-void SetCpDuty(byte _value)
+void SetCpDuty(uint8_t _value)
 {
-    Config_Ac_Duty(Uart5Fd, Addr.AcPlug, _value);
+    Config_Ac_Duty(Uart5Fd, ADDR_AC_PLUG, _value);
 }
 
 void ChangeToCsuMode()
 {
-    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, Addr.AcPlug);
+    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, ADDR_AC_PLUG);
 
 //  if (ac_chargingInfo[0]->IsModeChagned == PASS)
 //  {
-//      Config_Reset_MCU(Uart5Fd, Addr.AcPlug);
+//      Config_Reset_MCU(Uart5Fd, ADDR_AC_PLUG);
 //  }
 }
 
-void ChangeStartOrStopDateTime(byte isStart)
+void ChangeStartOrStopDateTime(uint8_t isStart)
 {
     char cmdBuf[32];
     struct timeb csuTime;
@@ -2169,7 +2091,7 @@ void ChangeStartOrStopDateTime(byte isStart)
     }
 }
 
-void OcppStartTransation(byte gunIndex)
+void OcppStartTransation(uint8_t gunIndex)
 {
     if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
         strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
@@ -2181,7 +2103,7 @@ void OcppStartTransation(byte gunIndex)
     ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
 }
 
-void OcppStopTransation(byte gunIndex)
+void OcppStopTransation(uint8_t gunIndex)
 {
     if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
@@ -2193,7 +2115,7 @@ void OcppStopTransation(byte gunIndex)
     ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
 }
 
-bool OcppRemoteStop(byte gunIndex)
+bool OcppRemoteStop(uint8_t gunIndex)
 {
     bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
 
@@ -2205,9 +2127,9 @@ bool OcppRemoteStop(byte gunIndex)
     return result;
 }
 
-unsigned char isModeChange()
+uint8_t isModeChange()
 {
-    unsigned char result = NO;
+    uint8_t result = NO;
 
     if (ac_chargingInfo[0]->SystemStatus != ac_chargingInfo[0]->PreviousSystemStatus) {
         result = YES;
@@ -2235,7 +2157,7 @@ void AcChargeTypeProcess()
             GetAcStatus();
             GetAcAlarmCode();
 
-            byte _status = S_NONE;
+            uint8_t _status = S_NONE;
 
             if (ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsErrorOccur) {
                 _status = S_ALARM;
@@ -2388,7 +2310,7 @@ void AcChargeTypeProcess()
     }
 }
 
-void ResetDetAlarmStatus(byte gun)
+void ResetDetAlarmStatus(uint8_t gun)
 {
     if (_chargingData[gun]->Type == _Type_Chademo) {
         if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
@@ -2407,6 +2329,7 @@ void ResetDetAlarmStatus(byte gun)
 
 int main(void)
 {
+    uint8_t i = 0;
     if (InitShareMemory() == FAIL) {
         log_error("InitShareMemory NG\n");
         if (ShmStatusCodeData != NULL) {
@@ -2436,7 +2359,7 @@ int main(void)
     outputRelay.relay_event.bits.Gun1_N = 0x00;
     outputRelay.relay_event.bits.Gun2_N = 0x00;
     outputRelay.relay_event.bits.Gun2_P = 0x00;
-    if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS) {
+    if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay) != PASS) {
         log_info("Config_Relay_Output fail \n");
 
     }
@@ -2509,7 +2432,7 @@ int main(void)
             GetRelayOutputStatus();
 #endif //!defined DD360 && !defined DD360Audi
 
-            for (int i = 0; i < gunCount; i++) {
+            for (i = 0; i < gunCount; i++) {
                 // Cable check (Set)
                 CableCheckDetected(i);
 
@@ -2599,7 +2522,7 @@ int main(void)
 
             // 搭上/鬆開 Relay
             if (IsNoneMatchRelayStatus()) {
-                if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay)) {
+                if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
                     //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
                     regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
                     regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;

+ 92 - 0
EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.h

@@ -0,0 +1,92 @@
+#ifndef _MODULE_INTERNAL_COMM_H_
+#define _MODULE_INTERNAL_COMM_H_
+
+//------------------------------------------------------------------------------
+#define RELAY_CHECK_TIME                        (5)       // s
+#define OUTPUT_VOL_CHK_TIME                     (200)     // ms
+#define TEN_MINUTES                             (600)     // s
+//#define TEN_MINUTES                             5
+#define ENV_TEMP_MIN                            (45)
+#define ENV_TEMP_MAX                            (50)
+#define DEFAULT_AC_INDEX                        (2)
+#define COLOR_MAX_LV                            (100)
+#define COLOR_MIN_LV                            (0)
+
+#define AC_DEFAULT_VOL                          (220)
+
+#define NDEFAULT_AC_INDEX                       (2)
+
+#define OVP_UVP_CHK_COUNT                       (3)
+
+#define VIN_MAX_VOLTAGE_IEC                     (285) // 大於該值 : OVP
+#define VIN_MAX_REV_VOLTAGE_IEC                 (275) // 小於賦歸 OVP
+#define VIN_MIN_VOLTAGE_IEC                     (160) // 小於該值 : UVP
+#define VIN_MIN_REV_VOLTAGE_IEC                 (170) // 大於賦歸 UVP
+
+#define VIN_MAX_VOLTAGE_UL                      (315) // 大於該值 : OVP // 美規 (W)
+#define VIN_MAX_REV_VOLTAGE_UL                  (305) // 小於賦歸 OVP
+#define VIN_MIN_VOLTAGE_UL                      (210) // 小於該值 : UVP
+#define VIN_MIN_REV_VOLTAGE_UL                  (220) // 大於賦歸 UVP
+
+#define VIN_DROP_VOLTAGE                        (150) // 小於該值 : ac drop
+
+#define VOUT_MAX_VOLTAGE                        (995)
+#define VOUT_MIN_VOLTAGE                        (150)
+#define IOUT_MAX_CURRENT                        (50)
+
+#define MAX_FAN_SPEED                           (14000)
+#define MIN_FAN_SPEED                           (3000)
+#define NORMAL_FAN_SPEED                        (7000)
+
+// GFD Status
+#define GFD_IDLE                                (0)
+#define GFD_CABLECHK                            (1)
+#define GFD_PRECHARGE                           (2)
+#define GFD_CHARGING                            (3)
+
+// LED Intensity (rate)
+#define LED_INTENSITY_DARKEST                   (0.2)
+#define LED_INTENSITY_MEDIUM                    (0.6)
+#define LED_INTENSITY_BRIGHTEST                 (1)
+
+// EE Spec
+#define LED_BRIGHTNESS_LV_HIGH                  (1)
+#define LED_BRIGHTNESS_LV_MID                   (0.5)
+#define LED_BRIGHTNESS_LV_LOW                   (0.2)
+
+// 最小切換 Relay 電壓
+#define SELF_TO_CHANGE_RELAY_STATUS             (600)
+// 透過電壓確認 Relay 是否搭上的依據電壓
+#define CHECK_RELAY_STATUS                      (300)
+#define CHECK_RELAY_STATUS_GAP                  (100)
+// 安全在停止充電程序中斷開 Relay 的電流
+#define SEFETY_SWITCH_RELAY_CUR                 (50)//20 DS60-120 modify
+// 確認 Relay Welding 電壓
+#define RELAY_WELDING_DET                       (300)
+
+#define AC_OVP                                  (1)
+#define AC_UVP                                  (2)
+#define AC_OCP                                  (4)
+#define AC_OTP                                  (8)
+#define AC_GMI_FAULT                            (16)
+#define AC_CP_ERROR                             (32)
+#define AC_AC_LEAKAGE                           (64)
+#define AC_DC_LEAKAGE                           (128)
+#define AC_SYSTEM_SELFTEST_FAULT                (256)
+#define AC_HANDSHAKE_TIMEOUT                    (512)
+#define AC_EMC_STOP                             (1024)
+#define AC_RELAY_WELDING                        (2048)
+#define AC_GF_MODULE_FAULT                      (4096)
+#define AC_SHUTTER_FAULT                        (8192)
+#define AC_LOCKER_FAULT                         (16384)
+#define AC_POWER_DROP                           (32768)
+#define AC_CIRCUIT_SHORT                        (65536)
+#define AC_ROTARY_SWITCH_FAULT                  (131072)
+#define AC_RELAY_DRIVE_FAULT                    (262144)
+
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
+#endif /* _MODULE_INTERNAL_COMM_H_ */

Різницю між файлами не показано, бо вона завелика
+ 299 - 345
EVSE/Projects/DD360/Apps/ModuleInternalComm/internalComm.c


+ 251 - 0
EVSE/Projects/DD360/Apps/ModuleInternalComm/internalComm.h

@@ -0,0 +1,251 @@
+/*
+ * internalComm.h
+ *
+ *  Created on: 2019年5月7日
+ *      Author: foluswen
+ */
+
+#ifndef _INTERNAL_COMM_H_
+#define _INTERNAL_COMM_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//address
+#define ADDR_AUX                                (0x01)
+#define ADDR_FAN                                (0x02)
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#define ADDR_RELAY                              (0x09)
+#else
+#define ADDR_RELAY                              (0x03)
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+#define ADDR_AC_PLUG                            (0x05)
+#define ADDR_LED                                (0x06)
+#define ADDR_BROADCAST                          (0xFF)
+
+//command
+#define CMD_QUERY_FW_VER                        (0x01)
+#define CMD_QUERY_HW_VER                        (0x02)
+#define CMD_QUERY_PRESENT_IN_VOL                (0x03)
+#define CMD_QUERY_PRESENT_OUT_VOL               (0x04)
+#define CMD_QUERY_FAN_SPEED                     (0x05)
+#define CMD_QUERY_TEMPERATURE                   (0x06)
+#define CMD_QUERY_AUX_POWER_VOL                 (0x07)
+#define CMD_QUERY_RELAY_OUTPUT                  (0x08)
+#define CMD_QUERY_GFD_ADC                       (0x09)
+#define CMD_QUERY_GPIO_IN                       (0x0a)
+#define CMD_QUERY_MODEL_NAME                    (0x24)
+#define CMD_QUERY_AC_OUTPUT_CURRENT             (0x27)
+#define CMD_QUERY_AC_STATUS                     (0x28)
+#define CMD_QUERY_AC_ALARM_CODE                 (0x29)
+#define CMD_QUERY_AC_OUTPUT_ENERGY              (0x2C)
+
+#define CMD_CONFIG_FAN_SPEED                    (0x81)
+#define CMD_CONFIG_MODEL_NAME                   (0x83)
+#define CMD_CONFIG_RELAY_OUTPUT                 (0x85)
+#define CMD_CONFIG_GPIO_OUTPUT                  (0x86)
+#define CMD_CONFIG_RTC_DATA                     (0x87)
+#define CMD_CONFIG_AC_LED_STATUS                (0x88)
+#define CMD_CONFIG_AC_DUTY                      (0x89)
+#define CMD_CONFIG_LEGACY_REQ                   (0x8A)
+#define CMD_CONFIG_GDF_VALUE                    (0x8B)
+#define CMD_CONFIG_RESET_MCU                    (0x8C)
+#define CMD_CONFIG_CSU_MODE                     (0x90)
+#define CMD_CONFIG_LEN_COLOR                    (0x93)
+
+#define CMD_UPDATE_START                        (0xe0)
+#define CMD_UPDATE_ABORT                        (0xe1)
+#define CMD_UPDATE_TRANSFER                     (0xe2)
+#define CMD_UPDATE_FINISH                       (0xe3)
+
+//------------------------------------------------------------------------------
+typedef struct Verion {
+    char Version_FW[9];
+    char Version_HW[9];
+} Ver;
+
+typedef struct PRESENTINPUTVOLTAGE {
+    uint8_t inputType;    // 0x00: Line to Line       0x01: Line to Neutral
+    double L1N_L12;
+    double L2N_L23;
+    double L3N_L31;
+} PresentInputVoltage;
+
+typedef struct PRESENTOUTPUTVOLTAGE {
+    double behindFuse_Voltage_C1;
+    double behindRelay_Voltage_C1;
+    double behindFuse_Voltage_C2;
+    double behindRelay_Voltage_C2;
+} PresentOutputVoltage;
+
+typedef struct FANSPEED {
+    uint16_t speed[8];
+} FanSpeed;
+
+typedef struct TEMPERATURE {
+    uint8_t temperature[8];
+} Temperature;
+
+typedef struct AUXPOWER {
+    uint8_t voltage[8];
+} AuxPower;
+
+typedef struct RELAY {
+    union {
+        uint8_t relay_status[8];
+        struct {
+            uint8_t AC_Contactor : 1;     //bit 0
+            uint8_t CCS_Precharge : 1; //bit 1
+            uint8_t : 1;              //bit 2 reserved
+            uint8_t : 1;                  //bit 3 reserved
+            uint8_t : 1;                  //bit 4 reserved
+            uint8_t : 1;                  //bit 5 reserved
+            uint8_t : 1;                  //bit 6 reserved
+            uint8_t : 1;                  //bit 7 reserved
+
+            uint8_t Gun1_N : 1;           //bit 0
+            uint8_t Gun1_P : 1;           //bit 1
+            uint8_t Gun1_Parallel_N : 1; //bit 2
+            uint8_t Gun1_Parallel_P : 1;  //bit 3
+            uint8_t : 1;                  //bit 4 reserved
+            uint8_t : 1;                  //bit 5 reserved
+            uint8_t : 1;                  //bit 6 reserved
+            uint8_t : 1;                  //bit 7 reserved
+
+            uint8_t Gun2_N : 1;           //bit 0
+            uint8_t Gun2_P : 1;           //bit 1
+            uint8_t : 1;                  //bit 2 reserved
+            uint8_t : 1;                  //bit 3 reserved
+            uint8_t : 1;                  //bit 4 reserved
+            uint8_t : 1;                  //bit 5 reserved
+            uint8_t : 1;                  //bit 6 reserved
+            uint8_t : 1;                  //bit 7 reserved
+        } bits;
+    } relay_event;
+} Relay;
+
+typedef struct GFD {
+    unsigned short Resister_conn1;
+    unsigned short voltage_conn1;
+    uint8_t result_conn1;
+    uint8_t rb_step_1;
+
+    unsigned short Resister_conn2;
+    unsigned short voltage_conn2;
+    uint8_t result_conn2;
+    uint8_t rb_step_2;
+} Gfd;
+
+typedef struct Gfd_CONFIG {
+    uint8_t index;
+    uint8_t state;
+} Gfd_config;
+
+typedef struct GPIO_IN {
+    uint8_t AC_Connector;         // bit 0
+    uint8_t AC_MainBreaker;           // bit 1
+    uint8_t SPD;                      // bit 2
+    uint8_t Door_Open;                // bit 3
+    uint8_t GFD[2];                   // bit 4,5
+    uint8_t AC_Drop;                  // bit 6
+
+    uint8_t Emergency_IO;         // bit 0
+
+    uint8_t Button_Emergency_Press;   // bit 0
+    uint8_t Button_On_Press;          // bit 1
+    uint8_t Button_Off_Press;     // bit 2
+    uint8_t Key_1_Press;              // bit 3
+    uint8_t Key_2_Press;              // bit 4
+    uint8_t Key_3_Press;              // bit 5
+    uint8_t Key_4_Press;              // bit 6
+} Gpio_in;
+
+typedef struct GPIO_OUT {
+    uint8_t AC_Connector;
+    uint8_t Button_LED[2];
+    uint8_t System_LED[4];
+} Gpio_out;
+
+typedef struct RTC {
+    uint8_t RtcData[14];
+} Rtc;
+
+typedef struct LED_Color {
+    uint8_t Connect_1_Red;
+    uint8_t Connect_1_Green;
+    uint8_t Connect_1_Blue;
+    uint8_t Connect_2_Red;
+    uint8_t Connect_2_Green;
+    uint8_t Connect_2_Blue;
+} Led_Color;
+
+typedef struct AC_Status {
+    uint8_t       CpStatus;
+    unsigned short      CurLimit;
+    short               PilotVol_P;
+    short               PilotVol_N;
+    uint8_t       LockStatus;
+    uint8_t       RelayStatus;
+    uint8_t       ShutterStatus;
+    uint8_t       MeterStatus;
+    uint8_t       PpStatus;
+    uint8_t       MaxCurrent;
+    uint8_t       RotateSwitchStatus;
+} Ac_Status;
+
+typedef struct AC_LED_Status {
+    uint8_t       ActionMode;
+    unsigned long       AcAlarmCode;
+} Ac_Led_Status;
+
+typedef struct AC_Alarm_Code {
+    uint32_t        AcAlarmCode;
+} Ac_Alarm_code;
+
+typedef struct AC_Charging_Energy {
+    uint32_t        Energy;
+} Ac_Charging_energy;
+
+typedef struct AC_Charging_Current {
+    unsigned short      OuputCurrentL1;
+    unsigned short      OuputCurrentL2;
+    unsigned short      OuputCurrentL3;
+} Ac_Charging_current;
+
+int Query_FW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_HW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_Present_InputVoltage(uint8_t fd, uint8_t targetAddr, PresentInputVoltage *Ret_Buf);
+int Query_Present_OutputVoltage(uint8_t fd, uint8_t targetAddr, PresentOutputVoltage *Ret_Buf);
+int Query_Fan_Speed(uint8_t fd, uint8_t targetAddr, FanSpeed *Ret_Buf);
+int Query_Temperature(uint8_t fd, uint8_t targetAddr, Temperature *Ret_Buf);
+int Query_Aux_PowerVoltage(uint8_t fd, uint8_t targetAddr, AuxPower *Ret_Buf);
+int Query_Relay_Output(uint8_t fd, uint8_t targetAddr, Relay *Ret_Buf);
+int Query_Gfd_Adc(uint8_t fd, uint8_t targetAddr, Gfd *Ret_Buf);
+int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf);
+int Query_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname);
+int Query_AC_Status(uint8_t fd, uint8_t targetAddr, Ac_Status *Ret_Buf);
+int Query_AC_Alarm_Code(uint8_t fd, uint8_t targetAddr, Ac_Alarm_code *Ret_Buf);
+int Query_Charging_Energy(uint8_t fd, uint8_t targetAddr, Ac_Charging_energy *Ret_Buf);
+int Query_Charging_Current(uint8_t fd, uint8_t targetAddr, Ac_Charging_current *Ret_Buf);
+
+int Config_Fan_Speed(uint8_t fd, uint8_t targetAddr, FanSpeed *Set_Buf);
+int Config_Relay_Output(uint8_t fd, uint8_t targetAddr, Relay *Set_Buf);
+int Config_Gpio_Output(uint8_t fd, uint8_t targetAddr, Gpio_out *Set_Buf);
+int Config_Gfd_Value(uint8_t fd, uint8_t targetAddr, Gfd_config *Set_Buf);
+int Config_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname);
+int Config_Rtc_Data(uint8_t fd, uint8_t targetAddr, Rtc *Set_Buf);
+
+int Config_LED_Status(uint8_t fd, uint8_t targetAddr, Ac_Led_Status *Ret_Buf);
+int Config_Legacy_Req(uint8_t fd, uint8_t targetAddr, uint8_t _switch);
+int Config_Ac_Duty(uint8_t fd, uint8_t targetAddr, uint8_t _value);
+int Config_CSU_Mode(uint8_t fd, uint8_t targetAddr);
+int Config_Reset_MCU(uint8_t fd, uint8_t targetAddr);
+int Config_Led_Color(uint8_t fd, uint8_t targetAddr, Led_Color *Ret_Buf);
+
+int Update_Start(uint8_t fd, uint8_t targetAddr, uint32_t crc32);
+int Update_Abord(uint8_t fd, uint8_t targetAddr);
+int Update_Transfer(uint8_t fd, uint8_t targetAddr, uint32_t startAddr, uint8_t *data, uint16_t length);
+int Update_Finish(uint8_t fd, uint8_t targetAddr);
+
+#endif /* _INTERNAL_COMM_H_ */

+ 114 - 127
EVSE/Projects/DD360ComBox/Apps/ReModule_LcmControl.c → EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -1,21 +1,18 @@
-#include "ReModule_LcmControl.h"
-#include "Config.h"
-#include "AudiCust.h"
+#include <stdint.h>
+
+#include "Module_LcmControl.h"
+#include "../Config.h"
+#include "../SelectGun/SelectGun.h"
 
 static AudiCustInfo *gAudiCustInfo = NULL;
 bool needReloadQr = true;
 
 bool _isShow = false; //DS60-120 add
-byte _showInformIndex = 0; //DS60-120 add
-
-void PRINTF_FUNC(char *string, ...);
+uint8_t _showInformIndex = 0; //DS60-120 add
 
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-char *getTimeString(void);
+#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)
 
 //=================================
 // Common routine
@@ -65,17 +62,6 @@ char *getTimeString(void)
     return result;
 }
 
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
 //==========================================
 // Init all share memory
 //==========================================
@@ -87,12 +73,12 @@ int InitShareMemory()
     //creat ShmSysConfigAndInfo
     if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+        log_error("shmget ShmSysConfigAndInfo NG\n");
 #endif
         result = FAIL;
     } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+        log_error("shmat ShmSysConfigAndInfo NG\n");
 #endif
         result = FAIL;
     } else
@@ -101,12 +87,12 @@ int InitShareMemory()
     //creat ShmStatusCodeData
     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+        log_error("shmget ShmStatusCodeData NG\n");
 #endif
         result = FAIL;
     } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        log_error("shmat ShmStatusCodeData NG\n");
 #endif
         result = FAIL;
     } else
@@ -114,22 +100,22 @@ int InitShareMemory()
 
     //creat Audi customization info
     if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmget select gun info NG \n");
+        log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
     } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmat shmget select gun info \n");
+        log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
 
     //creat ShmStatusCodeData
     if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+        log_error("shmget ShmPrimaryMcuData NG\n");
 #endif
         result = FAIL;
     } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
 #ifdef ShmPrimaryMcuData
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+        log_error("shmat ShmPrimaryMcuData NG\n");
 #endif
         result = FAIL;
     }
@@ -148,7 +134,7 @@ int CreateCommunicationLcmPort()
     fd = open(pPortName, O_RDWR);
     if (fd <= 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("open /dev/ttyS3 NG \n");
+        log_error("open /dev/ttyS3 NG \n");
 #endif
         return -1;
     }
@@ -158,7 +144,7 @@ int CreateCommunicationLcmPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char) 5;
+    tios.c_cc[VTIME] = (uint8_t) 5;
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl(fd, TCSETS, &tios);
@@ -171,15 +157,15 @@ void CloseCommunicationLcmPort()
     close(_port);
 }
 
-void WriteCmdToLcm(byte *cmd, byte cmdLen)
+void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
 {
     int len = write(_port, cmd, cmdLen);
     if (len >= sizeof(cmd)) {
-        //PRINTF_FUNC("Write cmd to LCM successfully. \n");
+        //log_info("Write cmd to LCM successfully. \n");
     }
 }
 
-void ReadMsgFromLcm(byte *msg, byte readLen)
+void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
 {
     read(_port, msg, readLen);
 
@@ -211,7 +197,7 @@ void ReadMsgFromLcm(byte *msg, byte readLen)
 //================================================
 void ChangeToOtherPage(short newPage)
 {
-    byte cmd[7];
+    uint8_t cmd[7];
     memset(cmd, 0x00, sizeof(cmd));
 
     cmd[0] = CMD_TITLE_1;
@@ -228,12 +214,12 @@ void ChangeToOtherPage(short newPage)
 
 void ChangeBackLight(bool islight)
 {
-    byte value = 0x01;
+    uint8_t value = 0x01;
 
     if (islight) {
         value = 0x20;
     }
-    byte cmd[7];
+    uint8_t cmd[7];
     memset(cmd, 0x00, sizeof(cmd));
 
     cmd[0] = CMD_TITLE_1;
@@ -249,9 +235,9 @@ void ChangeBackLight(bool islight)
 
 void GetCurrentPage()
 {
-    byte cmd[6];
+    uint8_t cmd[6];
     memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
+    uint8_t msg[8];
     memset(msg, 0x00, sizeof(msg));
 
     cmd[0] = CMD_TITLE_1;
@@ -266,9 +252,9 @@ void GetCurrentPage()
     ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
 }
 
-void DisplayValueToLcm(short address, byte *data, byte len)
+void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
 {
-    byte cmd[256];
+    uint8_t cmd[256];
     memset(cmd, 0x00, sizeof(cmd));
 
     cmd[0] = CMD_TITLE_1;
@@ -278,7 +264,7 @@ void DisplayValueToLcm(short address, byte *data, byte len)
     cmd[4] = address >> 8;
     cmd[5] = address & 0x00FF;
 
-    for (byte count = 0; count < len; count++) {
+    for (uint8_t count = 0; count < len; count++) {
         cmd[6 + count] = *(data + count);
     }
 
@@ -287,18 +273,18 @@ void DisplayValueToLcm(short address, byte *data, byte len)
 
 void ChangeDisplay2Value(short address, short value)
 {
-    byte data[2];
+    uint8_t data[2];
     data[0] = value >> 8;
     data[1] = value & 0x00FF;
 
     DisplayValueToLcm(address, data, sizeof(data));
 }
 
-void GetBtnStatus(short address, byte len)
+void GetBtnStatus(short address, uint8_t len)
 {
-    byte cmd[8];
+    uint8_t cmd[8];
     memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
+    uint8_t msg[8];
     memset(msg, 0x00, sizeof(msg));
 
     cmd[0] = CMD_TITLE_1;
@@ -317,7 +303,7 @@ void GetBtnStatus(short address, byte len)
 //================================================
 // Warning process
 //================================================
-void string2ByteArray(unsigned char *input, byte *output)
+void string2ByteArray(uint8_t *input, uint8_t *output)
 {
     int loop;
     int i;
@@ -333,12 +319,13 @@ void string2ByteArray(unsigned char *input, byte *output)
 
 void ChangeWarningFunc()
 {
-    byte cmd[7];
-    byte i = 0, j = 0;
-    //PRINTF_FUNC("ChangeWarningFunc \n");
+    uint8_t cmd[7] = {0};
+    uint8_t i = 0;
+    //uint8_t j = 0;
+    //log_info("ChangeWarningFunc \n");
     // 最多一次五筆
-    //PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
-    //PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
+    //log_info("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
+    //log_info("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
 //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
     for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         memset(cmd, 0x00, sizeof(cmd));
@@ -475,7 +462,7 @@ void ChangeQrCode_Idle(char *input)
 
 #else
     int len = strlen(input);
-    byte cmd[len];
+    uint8_t cmd[len];
 
     int loop = 0;
     int i = 0;
@@ -550,7 +537,7 @@ void ChangeQrCode_Charge(char *input)
 
 #else
     int len = strlen(input);
-    byte cmd[len];
+    uint8_t cmd[len];
 
     int loop = 0;
     int i = 0;
@@ -568,7 +555,7 @@ void ChangeQrCode_Charge(char *input)
 //================================================
 void ChangeCurPage()
 {
-    //PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
+    //log_info("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
     if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex) {
         _currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
         ChangeToOtherPage(_currentPage);
@@ -579,7 +566,7 @@ void ChangeCurPage()
 //================================================
 // Main process
 //================================================
-byte demoCount = 0;
+uint8_t demoCount = 0;
 void DemoFunction()
 {
     if (demoCount == 0) {
@@ -614,23 +601,23 @@ void DemoFunction()
 //================================================
 // Main process
 //================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **_chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
             _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
             _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
             _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
             return true;
@@ -640,7 +627,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
     return false;
 }
 
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
+bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
 {
     if (target < AC_QUANTITY) {
         acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
@@ -657,8 +644,8 @@ bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingDat
  */
 static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
 {
-    byte cmd[10] = {0};
-    byte value[10] = {0};
+    uint8_t cmd[10] = {0};
+    uint8_t value[10] = {0};
     uint8_t len = 0;
     float balance = gAudiCustInfo->PricesInfo[index].Balance;
 
@@ -669,7 +656,7 @@ static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
     len += sprintf((char *) value, "%.2f", balance);
     if (len < 6) {
         sprintf((char *)&value[len], "%s",
-                (byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+                (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
     }
 
     value[sizeof(value) - 1] = '\0';
@@ -782,8 +769,8 @@ void ChangeBattMapAndValue(short page, int soc)
         }
     }
 
-    byte cmd[5];
-    byte value[5];
+    uint8_t cmd[5];
+    uint8_t value[5];
 
     memset(cmd, 0x00, sizeof(cmd));
     memset(value, 0x00, sizeof(value));
@@ -795,8 +782,8 @@ void ChangeBattMapAndValue(short page, int soc)
 void ChangeRemainTime(int sec)
 {
     int h, m, s;
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -815,8 +802,8 @@ void ChangeRemainTime(int sec)
 
 void ChangeChargingEnergyValue(float energy)
 {
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
     if (energy >= 0.05) {
@@ -829,8 +816,8 @@ void ChangeChargingEnergyValue(float energy)
 
 void ChangeChargingPowerValue(float pow)
 {
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -844,8 +831,8 @@ void ChangeChargingPowerValue(float pow)
 
 void ChangeChargingFeeValue(float fee)
 {
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -856,8 +843,8 @@ void ChangeChargingFeeValue(float fee)
 
 void DisplayMoneyRate(float money)
 {
-    byte cmd[8];
-    byte value[8];
+    uint8_t cmd[8];
+    uint8_t value[8];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -866,10 +853,10 @@ void DisplayMoneyRate(float money)
     DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
 }
 
-void DisplayMoneyCur(byte *cur)
+void DisplayMoneyCur(uint8_t *cur)
 {
-    byte cmd[10] = {0};
-    byte buf[10] = {0};
+    uint8_t cmd[10] = {0};
+    uint8_t buf[10] = {0};
     uint8_t len = 0;
 
     *(cur + 3) = '\0';
@@ -880,7 +867,7 @@ void DisplayMoneyCur(byte *cur)
     DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
 }
 
-void RefreshPageAnimation(byte value)
+void RefreshPageAnimation(uint8_t value)
 {
     switch (_currentPage) {
     case _LCM_IDLE: {
@@ -994,7 +981,7 @@ void RefreshConnStatus()
         }
     }
 
-    //unsigned char flag[4] = {0};
+    //uint8_t flag[4] = {0};
 
     /*for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         //printf("status code = %s\r\n", &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
@@ -1162,9 +1149,9 @@ void RefreshConnStatus()
 #endif //defined DD360 || defined DD360Audi
 }
 
-byte FirstPageChanged()
+uint8_t FirstPageChanged()
 {
-    byte result = NO;
+    uint8_t result = NO;
 
     if (_currentPage != _oldPage) {
         result = YES;
@@ -1214,10 +1201,10 @@ void ClearDisplayInfo()
     ChangeDisplay2Value(__fan_speed_value, _disappear);
 }
 
-void DisplayInfoCsuVer(bool isShow, unsigned char *modelName)
+void DisplayInfoCsuVer(bool isShow, uint8_t *modelName)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *)value, "CSU Ver >");
@@ -1231,10 +1218,10 @@ void DisplayInfoCsuVer(bool isShow, unsigned char *modelName)
     }
 }
 
-void ShowWifiMode(bool isShow, unsigned char mode)
+void ShowWifiMode(bool isShow, uint8_t mode)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Wifi Mo. >");
@@ -1255,10 +1242,10 @@ void ShowWifiMode(bool isShow, unsigned char mode)
     }
 }
 
-void DisplayInfoEthIp(bool isShow, unsigned char *ip)
+void DisplayInfoEthIp(bool isShow, uint8_t *ip)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Eth IP >");
@@ -1275,7 +1262,7 @@ void DisplayInfoEthIp(bool isShow, unsigned char *ip)
 void Show4GRssi(bool isShow, int dbValue)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "RSSI >");
@@ -1289,10 +1276,10 @@ void Show4GRssi(bool isShow, int dbValue)
     }
 }
 
-void DisplayInfoSN(bool isShow, unsigned char *sn)
+void DisplayInfoSN(bool isShow, uint8_t *sn)
 {
     if (isShow) {
-        byte value[30];
+        uint8_t value[30];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "SN >");
@@ -1309,7 +1296,7 @@ void DisplayInfoSN(bool isShow, unsigned char *sn)
 void ShowWifiRssi(bool isShow, int dbValue)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "RSSI >");
@@ -1323,10 +1310,10 @@ void ShowWifiRssi(bool isShow, int dbValue)
     }
 }
 
-void DisplayInfoGun1Ver(bool isShow, unsigned char *version)
+void DisplayInfoGun1Ver(bool isShow, uint8_t *version)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Ct1 Ver >");
@@ -1340,10 +1327,10 @@ void DisplayInfoGun1Ver(bool isShow, unsigned char *version)
     }
 }
 
-void Show4GMode(bool isShow, unsigned char mode)
+void Show4GMode(bool isShow, uint8_t mode)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "3/4G Mo. >");
@@ -1362,10 +1349,10 @@ void Show4GMode(bool isShow, unsigned char mode)
     }
 }
 
-void DisplayInfoGun2Ver(bool isShow, unsigned char *version)
+void DisplayInfoGun2Ver(bool isShow, uint8_t *version)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Ct2 Ver >");
@@ -1379,10 +1366,10 @@ void DisplayInfoGun2Ver(bool isShow, unsigned char *version)
     }
 }
 
-void Show4GIP(bool isShow, unsigned char *ip)
+void Show4GIP(bool isShow, uint8_t *ip)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "3/4G IP >");
@@ -1399,7 +1386,7 @@ void Show4GIP(bool isShow, unsigned char *ip)
 void DisplayInfoSpeed(bool isShow, unsigned int fan)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Fan Spd >");
@@ -1413,10 +1400,10 @@ void DisplayInfoSpeed(bool isShow, unsigned int fan)
     }
 }
 
-void ShowWifiIP(bool isShow, unsigned char *ip)
+void ShowWifiIP(bool isShow, uint8_t *ip)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Wifi IP >");
@@ -1521,10 +1508,10 @@ void ProcessPageInfo()
         if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
             needReloadQr = false;
             if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO) {
-                //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+                //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
                 ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
             } else {
-                //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+                //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
                 ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
             }
             //ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
@@ -1533,7 +1520,7 @@ void ProcessPageInfo()
 
         //DS60-120 add
         bool isCharging = false;
-        for (byte i = 0; i < _totalCount; i++) {
+        for (uint8_t i = 0; i < _totalCount; i++) {
             if (_chargingInfoData[i]->SystemStatus == S_IDLE) {
                 continue;
             }
@@ -1566,7 +1553,7 @@ void ProcessPageInfo()
             // 新增隨插即充功能預設在等待插槍頁面在開啟
             ChangeDisplay2Value(__ret_home_btn, _disappear);
             bool isCharging = false;
-            for (byte i = 0; i < _totalCount; i++) {
+            for (uint8_t i = 0; i < _totalCount; i++) {
                 if (_chargingInfoData[i]->SystemStatus == S_IDLE) {
                     continue;
                 }
@@ -1589,7 +1576,7 @@ void ProcessPageInfo()
     case _LCM_CHARGING:
     case _LCM_COMPLETE: {
         bool isShowAc = false;
-        byte gunTargetIndex = 0;
+        uint8_t gunTargetIndex = 0;
 
         if (acgunCount > 0) {
             gunTargetIndex = 2;
@@ -1686,7 +1673,7 @@ void ProcessPageInfo()
         }
 
         gunTargetIndex = 0; //DS60-120 add
-        for (byte i = 0; i < _totalCount; i++) {
+        for (uint8_t i = 0; i < _totalCount; i++) {
             if (_totalCount == 1 && acgunCount <= 0) { //DS60-120 add
                 gunTargetIndex = 2;
             } else {
@@ -1832,7 +1819,7 @@ void ProcessPageInfo()
 
         // gun btn and QR code
         if (_totalCount + acgunCount >= 2 && _currentPage) {
-            byte index = 0;
+            uint8_t index = 0;
             for (index = 0; index < _totalCount; index++) {
                 if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index) {
                     break;
@@ -1847,10 +1834,10 @@ void ProcessPageInfo()
                         needReloadQr = false;
                         //ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId); //DS60-120 remove
                         if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO) {
-                            //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+                            //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
                             ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
                         } else {
-                            //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+                            //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
                             ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
                         }
                     }
@@ -1893,7 +1880,7 @@ void ChangeDisplayMoneyInfo()
             }
 
             if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53) {
-                DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+                DisplayMoneyCur((uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
             }
 #if defined DD360Audi
         }
@@ -1908,12 +1895,12 @@ void ChangeDisplayMoneyInfo()
 void Initialization()
 {
     bool isPass = false;
-    byte count = 5;
+    uint8_t count = 5;
     while (!isPass && count > 0) {
         isPass = true;
-        for (byte _index = 0; _index < _totalCount; _index++) {
+        for (uint8_t _index = 0; _index < _totalCount; _index++) {
             if (!FindChargingInfoData(_index, &_chargingInfoData[0])) {
-                DEBUG_ERROR("LcmComm (main) : FindChargingInfoData false \n");
+                log_error("LcmComm (main) : FindChargingInfoData false \n");
                 isPass = false;
                 count--;
                 break;
@@ -1928,9 +1915,9 @@ void Initialization()
     if (acgunCount > 0) {
         while (!isPass) {
             isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
+            for (uint8_t _index = 0; _index < acgunCount; _index++) {
                 if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
-                    DEBUG_ERROR("LcmComm : FindAcChargingInfoData false \n");
+                    log_error("LcmComm : FindAcChargingInfoData false \n");
                     isPass = false;
                     break;
                 }
@@ -1941,14 +1928,14 @@ void Initialization()
     }
 
     if (count == 0) {
-        PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
+        log_info("LCM Initialization Gun Fail.............\n");
     }
 }
 
 //DS60-120 add
 void DefaultIconStatus()
 {
-    for (byte i = 0; i < 3; i++) {
+    for (uint8_t i = 0; i < 3; i++) {
         ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
     }
 
@@ -1963,7 +1950,7 @@ int main(void)
 {
     if (InitShareMemory() == FAIL) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
+        log_error("InitShareMemory NG\n");
 #endif
         if (ShmStatusCodeData != NULL) {
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
@@ -1973,8 +1960,8 @@ int main(void)
     }
 
     _port = CreateCommunicationLcmPort();
-    byte changeWarningPriority = 0;
-    byte curWarningCount = 255;
+    uint8_t changeWarningPriority = 0;
+    uint8_t curWarningCount = 255;
     ChangeBackLight(true);
     _totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
     acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
@@ -1984,7 +1971,7 @@ int main(void)
     //ChangeToOtherPage(_LCM_COMPLETE);
     //return 0;
 
-    for (byte i = 0; i < 3; i++) {
+    for (uint8_t i = 0; i < 3; i++) {
         ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
     }
 

+ 90 - 99
EVSE/Projects/DD360ComBox/Apps/ReModule_LcmControl.h → EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -27,23 +27,14 @@
 #include <ctype.h>
 #include <ifaddrs.h>
 #include <stdbool.h>
-#include "../../define.h"
-#include "Config.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
-typedef unsigned char           byte;
+#include "../../../define.h"
+#include "../Config.h"
 
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 struct FanModuleData            *ShmFanModuleData;
 struct PrimaryMcuData           *ShmPrimaryMcuData;
 
-#define NO_DEFINE               255
 #define DEFAULT_AC_INDEX        2
 
 #define TIME_MAX_SEC            2592000 // 一個月,秒數
@@ -76,14 +67,14 @@ int _port;
 //char* pPortName         = "/dev/ttyO2";
 char *pPortName           = "/dev/ttyS3";
 char *moduleName          = "DMT80480T070_09WT";
-byte _totalCount;
-byte acgunCount;
+uint8_t _totalCount;
+uint8_t acgunCount;
 struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
 
-byte ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-byte isDiffStatus         = false;
-byte isChangeBattMap      = false;
+uint8_t ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
+uint8_t isDiffStatus         = false;
+uint8_t isChangeBattMap      = false;
 // 當前選擇的槍號
 #if defined DD360Audi
 short _currentPage        = _LCM_SELECT_GUN;
@@ -92,14 +83,14 @@ short _oldPage            = _LCM_SELECT_GUN;
 short _currentPage        = _LCM_NONE;
 short _oldPage            = _LCM_NONE;
 #endif //defined DD360Audi
-byte _gunIndex            = 0;
+uint8_t _gunIndex            = 0;
 bool _wifi_conn_status    = false;
 bool _battery_display_ani = false;
-byte _curPage_index       = 0;
+uint8_t _curPage_index       = 0;
 bool _page_reload         = false;
 
 // LCM - HW
-byte _everyPageRollChange    = 0;
+uint8_t _everyPageRollChange    = 0;
 short __conn_status          = 0x0030;
 short __ethernet_status      = 0x0032;
 short __3G4G_status          = 0x0036;
@@ -178,85 +169,85 @@ short __custStationIdL1      = 0x0450;
 short _emergency_map         = 0x011C;
 
 // ICON ID
-byte _disappear              = 0;
-byte _disconnect             = 1;
-byte _connect                = 2;
-byte _warning                = 3;
-byte _arrow_dark             = 4;
-byte _arrow_light            = 5;
-byte _3G4G_disconnect        = 6;
-byte __3G4G_connect          = 7;
-byte _wifi_disconnect        = 8;
-byte _wifi_connect           = 9;
-byte _logo                   = 10;
-byte _conn_map1              = 11;
-byte _conn_map2              = 12;
-byte _sel_gun_btn            = 13;
-byte _back_home_btn          = 14;
-byte _stop_charging_btn      = 15;
-byte _stop_charging_btn_scan = 16;
-byte _chademo_dark           = 17;
-byte _ccs_dark               = 18;
-byte _gbt_dark               = 19;
-byte _actype_dark            = 20;
-byte _chademo_light          = 21;
-byte _ccs_light              = 22;
-byte _gbt_light              = 23;
-byte _actype_light           = 24;
-byte _main_none_rfid         = 25;
-byte _main_rfid              = 26;
-byte _main_none_app          = 27;
-byte _main_app               = 28;
-byte _main_none_qr           = 29;
-byte _main_qr                = 30;
-byte _charging_map1          = 31;
-byte _charging_map2          = 32;
-byte _battery_empty          = 33;
-byte _battery_cap_20         = 34;
-byte _battery_cap_40         = 35;
-byte _battery_cap_60         = 36;
-byte _battery_cap_80         = 37;
-byte _battery_cap_100        = 38;
-byte _battery_map            = 39;
-byte _power_map              = 40;
-byte _time_map               = 41;
-byte _complete_map           = 42;
-byte _battery_soc_20         = 43;
-byte _battery_soc_40         = 44;
-byte _battery_soc_60         = 45;
-byte _battery_soc_80         = 46;
-byte _battery_soc_100        = 47;
-byte _battery_eng_map        = 48;
-byte _money_map              = 49;
-byte _elapse_time_map        = 50;
-byte _charging_money         = 51;
-//byte _side_none_rfid       = 52;
-//byte _side_rfid            = 53;
-//byte _side_none_app        = 54;
-//byte _side_app             = 55;
-//byte _side_none_qr         = 56;
-//byte _side_qr              = 57;
-byte _eth_disconnect         = 52; //58;
-byte _eth_connect            = 53; //59;
-
-byte _chademo_dark_cmp       = 54;
-byte _ccs_dark_cmp           = 55;
-byte _gbt_dark_cmp           = 56;
-byte _actype_dark_cmp        = 57;
-byte _chademo_light_cmp      = 58;
-byte _ccs_light_cmp          = 59;
-byte _gbt_light_cmp          = 60;
-byte _actype_light_cmp       = 61;
-
-byte _logo_cmp = 62;
-byte _battery_eng_trp_map = 63;
-byte _money_trp_map = 64;
-byte _elapse_time_trp_map = 65;
+uint8_t _disappear              = 0;
+uint8_t _disconnect             = 1;
+uint8_t _connect                = 2;
+uint8_t _warning                = 3;
+uint8_t _arrow_dark             = 4;
+uint8_t _arrow_light            = 5;
+uint8_t _3G4G_disconnect        = 6;
+uint8_t __3G4G_connect          = 7;
+uint8_t _wifi_disconnect        = 8;
+uint8_t _wifi_connect           = 9;
+uint8_t _logo                   = 10;
+uint8_t _conn_map1              = 11;
+uint8_t _conn_map2              = 12;
+uint8_t _sel_gun_btn            = 13;
+uint8_t _back_home_btn          = 14;
+uint8_t _stop_charging_btn      = 15;
+uint8_t _stop_charging_btn_scan = 16;
+uint8_t _chademo_dark           = 17;
+uint8_t _ccs_dark               = 18;
+uint8_t _gbt_dark               = 19;
+uint8_t _actype_dark            = 20;
+uint8_t _chademo_light          = 21;
+uint8_t _ccs_light              = 22;
+uint8_t _gbt_light              = 23;
+uint8_t _actype_light           = 24;
+uint8_t _main_none_rfid         = 25;
+uint8_t _main_rfid              = 26;
+uint8_t _main_none_app          = 27;
+uint8_t _main_app               = 28;
+uint8_t _main_none_qr           = 29;
+uint8_t _main_qr                = 30;
+uint8_t _charging_map1          = 31;
+uint8_t _charging_map2          = 32;
+uint8_t _battery_empty          = 33;
+uint8_t _battery_cap_20         = 34;
+uint8_t _battery_cap_40         = 35;
+uint8_t _battery_cap_60         = 36;
+uint8_t _battery_cap_80         = 37;
+uint8_t _battery_cap_100        = 38;
+uint8_t _battery_map            = 39;
+uint8_t _power_map              = 40;
+uint8_t _time_map               = 41;
+uint8_t _complete_map           = 42;
+uint8_t _battery_soc_20         = 43;
+uint8_t _battery_soc_40         = 44;
+uint8_t _battery_soc_60         = 45;
+uint8_t _battery_soc_80         = 46;
+uint8_t _battery_soc_100        = 47;
+uint8_t _battery_eng_map        = 48;
+uint8_t _money_map              = 49;
+uint8_t _elapse_time_map        = 50;
+uint8_t _charging_money         = 51;
+//uint8_t _side_none_rfid       = 52;
+//uint8_t _side_rfid            = 53;
+//uint8_t _side_none_app        = 54;
+//uint8_t _side_app             = 55;
+//uint8_t _side_none_qr         = 56;
+//uint8_t _side_qr              = 57;
+uint8_t _eth_disconnect         = 52; //58;
+uint8_t _eth_connect            = 53; //59;
+
+uint8_t _chademo_dark_cmp       = 54;
+uint8_t _ccs_dark_cmp           = 55;
+uint8_t _gbt_dark_cmp           = 56;
+uint8_t _actype_dark_cmp        = 57;
+uint8_t _chademo_light_cmp      = 58;
+uint8_t _ccs_light_cmp          = 59;
+uint8_t _gbt_light_cmp          = 60;
+uint8_t _actype_light_cmp       = 61;
+
+uint8_t _logo_cmp = 62;
+uint8_t _battery_eng_trp_map = 63;
+uint8_t _money_trp_map = 64;
+uint8_t _elapse_time_trp_map = 65;
 
 ////For Audi
-byte _left_gun_disable_map   = 66;
-byte _left_gun_enable_map    = 67;
-byte _right_gun_disable_map  = 68;
-byte _right_gun_enable_map   = 69;
-byte _select_gun_btn         = 70;
-byte _emergency_disable_map  = 72;
+uint8_t _left_gun_disable_map   = 66;
+uint8_t _left_gun_enable_map    = 67;
+uint8_t _right_gun_disable_map  = 68;
+uint8_t _right_gun_enable_map   = 69;
+uint8_t _select_gun_btn         = 70;
+uint8_t _emergency_disable_map  = 72;

+ 105 - 186
EVSE/Projects/DD360ComBox/Apps/ReModule_PrimaryComm.c → EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -1,95 +1,49 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "../../define.h"
-#include    "PrimaryComm.h"
-#include    <stdbool.h>
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
-typedef struct StChillerInfo {
-    uint8_t ChillerSwitch;
-    uint32_t ChillerOnTime;
-    uint8_t Reserved[3];
-} ChillerInfo;
-
-typedef struct StLedConfig {
-    //OutputDrvValue[0]
-    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
-    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
-    uint8_t GreenLED: 1;                          //bit 2,    H: ON,      L:OFF
-    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
-    uint8_t RedLED: 1;                        //bit 4,    H: ON,      L:OFF
-    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
-    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
-    uint8_t Reserved: 1;                        //bit 7 reserved
-} LedConfig;
-
-typedef unsigned char       byte;
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-
-void trim(char *s);
-int mystrcmp(char *p1, char *p2);
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt);
-void split(char **arr, char *str, const char *del);
-
-int Uart1Fd;
-char *priPortName = "/dev/ttyS1";
-Ver ver;
-Gpio_in gpio_in;
-Rtc rtc;
-
-struct timeval _flash_time;
-byte flash = NO;
-byte gun_count; //DS60-120 add
-
-byte _curDeviceStatus[3] = {0, 0, 0}; //DS60-120 add
-byte _reCheckCount[3] = {0, 0, 0}; //DS60-120 add
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-unsigned char ChillerSwitch; //DS60-120 remove
-unsigned int ChillerOnTime; //DS60-120 remove
-#endif //defined DD360 || defined DD360Audi
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdbool.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+
+#include "../../../define.h"
+#include "../Config.h"
+#include "PrimaryComm.h"
+#include "Module_PrimaryComm.h"
+
+struct SysConfigAndInfo *ShmSysConfigAndInfo;
+struct StatusCodeData *ShmStatusCodeData;
+struct PrimaryMcuData *ShmPrimaryMcuData;
+
+const char *priPortName = "/dev/ttyS1";
+uint8_t gun_count; //DS60-120 add
 
-int StoreLogMsg(const char *fmt, ...);
-#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)
+struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
+//------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -148,59 +102,6 @@ char *getTimeString(void)
     return result;
 }
 
-void trim(char *s)
-{
-    int i = 0, j, k, l = 0;
-
-    while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
-        i++;
-    }
-
-    j = strlen(s) - 1;
-    while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
-        j--;
-    }
-
-    if (i == 0 && j == strlen(s) - 1) { }
-    else if (i == 0) { s[j + 1] = '\0'; }
-    else {
-        for (k = i; k <= j; k++) { s[l++] = s[k]; }
-        s[l] = '\0';
-    }
-}
-
-int mystrcmp(char *p1, char *p2)
-{
-    while (*p1 == *p2) {
-        if (*p1 == '\0' || *p2 == '\0') {
-            break;
-        }
-        p1++;
-        p2++;
-    }
-    if (*p1 == '\0' && *p2 == '\0') {
-        return (PASS);
-    } else {
-        return (FAIL);
-    }
-}
-
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
-{
-    strncpy(dest, src + start, cnt);
-    dest[cnt] = 0;
-}
-
-void split(char **arr, char *str, const char *del)
-{
-    char *s = strtok(str, del);
-
-    while (s != NULL) {
-        *arr++ = s;
-        s = strtok(NULL, del);
-    }
-}
-
 //==========================================
 // Init all share memory
 //==========================================
@@ -236,26 +137,32 @@ int InitShareMemory()
 //================================================
 // Function
 //================================================
-void GetFwAndHwVersion()
+void GetFwAndHwVersion(int fd)
 {
-    if (Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) {
+    Ver ver = {0};
+
+    if (Query_FW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS) {
         //log_info("Primary FW Rev = %s \n", ver.Version_FW);
         strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
     }
 
-    //if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+    //if (Query_HW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS)
     //    ;//log_info("Primary HW Rev  = %s \n", ver.Version_HW);
 }
 
-void GetInputGpioStatus()
+void GetInputGpioStatus(int fd)
 {
     uint8_t dispenserSwTmp = 0;
+    Gpio_in gpio_in = {0};
     static uint8_t dispenserSw = 0;
 
     //log_info("GetInputGpioStatus \n");
-    if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS) {
+    if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) == PASS) {
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+        static uint8_t _curDeviceStatus[3] = {0};
+        static uint8_t _reCheckCount[3] = {0};
+
         //DS60-120 add
         if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
             if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
@@ -366,7 +273,8 @@ static void checkChillerStatus(Gpio_out *gpio)
 {
     uint8_t gunIndex = 0;
     uint8_t chillerCount = 0;
-    static ChillerInfo fChillerInfo[2] = {0};
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+    static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
     Gpio_out *pGpio = (Gpio_out *)gpio;
 
     if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
@@ -385,34 +293,38 @@ static void checkChillerStatus(Gpio_out *gpio)
     }
 
     for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
-        if ((ChargingData[gunIndex]->PresentChargingCurrent) >= 150) {
-            fChillerInfo[gunIndex].ChillerSwitch = YES;
-            fChillerInfo[gunIndex].ChillerOnTime = time((time_t *)NULL);
+        pDcChargingInfo = (struct ChargingInfoData *)ChargingData[gunIndex];
+        pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
+
+        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) {
+            pChillerInfo->ChillerSwitch = YES;
+            pChillerInfo->ChillerOnTime = time((time_t *)NULL);
         } else {
-            if (fChillerInfo[gunIndex].ChillerSwitch == YES) {
-                if ((ChargingData[gunIndex]->PresentChargingCurrent) >= 100) {
-                    fChillerInfo[gunIndex].ChillerSwitch = YES;
-                    fChillerInfo[gunIndex].ChillerOnTime = time((time_t *)NULL);
+            if (pChillerInfo->ChillerSwitch == YES) {
+                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) {
+                    pChillerInfo->ChillerSwitch = YES;
+                    pChillerInfo->ChillerOnTime = time((time_t *)NULL);
                 } else {
-                    if ((time((time_t *)NULL) - fChillerInfo[gunIndex].ChillerOnTime) >= 600) {
-                        fChillerInfo[gunIndex].ChillerSwitch = NO;
+                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
+                        pChillerInfo->ChillerSwitch = NO;
                     } else {
-                        fChillerInfo[gunIndex].ChillerSwitch = YES;
+                        pChillerInfo->ChillerSwitch = YES;
                     }
                 }
             } else {
-                fChillerInfo[gunIndex].ChillerSwitch = NO;
+                pChillerInfo->ChillerSwitch = NO;
             }
         }
     }
 
-    pGpio->AC_Connector = fChillerInfo[gunIndex].ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
+    pGpio->AC_Connector = pChillerInfo->ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
 }
 
-void SetOutputGpio(uint8_t outputValue)
+void SetOutputGpio(int fd, uint8_t outputValue)
 {
     Gpio_out gpio;
     LedConfig *pLedConfig = (LedConfig *)&outputValue;
+    static uint8_t flash = NO;
 
     if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
         if (flash == NO) {
@@ -441,19 +353,24 @@ void SetOutputGpio(uint8_t outputValue)
 
     gpio.AC_Breaker = 0x00;
 
-    Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio);
+    Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
 }
 
-void SetRtcData()
+void SetRtcData(int fd)
 {
+    Rtc rtc = {0};
     struct timeb csuTime;
     struct tm *tmCSU;
 
     ftime(&csuTime);
     tmCSU = localtime(&csuTime.time);
-//  log_info("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//          tmCSU->tm_sec);
+    //log_info("Time : %04d-%02d-%02d %02d:%02d:%02d \n",
+    //         tmCSU->tm_year + 1900,
+    //         tmCSU->tm_mon + 1,
+    //         tmCSU->tm_mday,
+    //         tmCSU->tm_hour,
+    //         tmCSU->tm_min,
+    //         tmCSU->tm_sec);
 
     rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
     rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
@@ -475,16 +392,16 @@ void SetRtcData()
     rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
     rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
 
-    if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS) {
+    if (Config_Rtc_Data(fd, OP_ADDR_IO_EXTEND, &rtc) == PASS) {
         //log_info("SetRtc sucessfully. \n");
     } else {
         //log_info("SetRtc fail. \n");
     }
 }
 
-void SetModelName()
+void SetModelName(int fd)
 {
-    if (Config_Model_Name(Uart1Fd, Addr.IoExtend, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
     }
 }
 
@@ -509,7 +426,7 @@ int InitComPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char)1;
+    tios.c_cc[VTIME] = (uint8_t)1;
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl (fd, TCSETS, &tios);
@@ -525,23 +442,23 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
-int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
             return 1;
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
             return 1;
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
             return 1;
@@ -556,7 +473,7 @@ void Initialization() //DS60-120 add
     bool isPass = false;
     while (!isPass) {
         isPass = true;
-        for (byte _index = 0; _index < gun_count; _index++) {
+        for (uint8_t _index = 0; _index < gun_count; _index++) {
             if (!FindChargingInfoData(_index, &ChargingData[0])) {
                 log_error("EvComm (main) : FindChargingInfoData false \n");
                 isPass = false;
@@ -569,6 +486,8 @@ void Initialization() //DS60-120 add
 
 int main(void)
 {
+    int Uart1Fd = -1;
+
     if (InitShareMemory() == FAIL) {
         log_error("InitShareMemory NG\r\n");
         if (ShmStatusCodeData != NULL) {
@@ -579,13 +498,13 @@ int main(void)
     }
 
     //DS60-120 remove
-    //for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+    //for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
     //    if (!FindChargingInfoData(_index, &ChargingData[0])) {
     //        log_error("FindChargingInfoData false \n");
     //        break;
     //    }
     //}
-    ChillerSwitch = 0;
+
     Uart1Fd = InitComPort();
     //log_info("407 Port id = %d \n", Uart1Fd);
 
@@ -597,29 +516,29 @@ int main(void)
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
         }
         sleep(5);
+
         return 0;
     }
 
-    SetRtcData();
-    SetModelName();//DS60-120 add
-    gettimeofday(&_flash_time, NULL);
-    //DS60-120 add
+    SetRtcData(Uart1Fd);
+    SetModelName(Uart1Fd);
+
     gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+
     Initialization();
-    byte _count = 0;
 
     for (;;) {
         // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
         // 模組更新 FW 後,需重新做
         if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
             //log_info("(407) Get Fw and Hw Ver. \n");
-            GetFwAndHwVersion();
+            GetFwAndHwVersion(Uart1Fd);
             sleep(1);
             ShmPrimaryMcuData->SelfTest_Comp = PASS;
         } else {
-            SetOutputGpio(ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
+            SetOutputGpio(Uart1Fd, ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
 
-            GetInputGpioStatus();
+            GetInputGpioStatus(Uart1Fd);
         }
 
         usleep(50000);

+ 34 - 0
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -0,0 +1,34 @@
+#ifndef _MODULE_PRIMARY_COMM_H_
+#define _MODULE_PRIMARY_COMM_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
+typedef struct StChillerInfo {
+    uint8_t ChillerSwitch;
+    uint32_t ChillerOnTime;
+    uint8_t Reserved[3];
+} ChillerInfo;
+
+typedef struct StLedConfig {
+    //OutputDrvValue[0]
+    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+    uint8_t GreenLED: 1;                          //bit 2,    H: ON,      L:OFF
+    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+    uint8_t RedLED: 1;                        //bit 4,    H: ON,      L:OFF
+    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+    uint8_t Reserved: 1;                        //bit 7 reserved
+} LedConfig;
+
+//------------------------------------------------------------------------------
+int StoreLogMsg(const char *fmt, ...);
+
+#endif /* _MODULE_PRIMARY_COMM_H_ */

+ 96 - 100
EVSE/Projects/DD360Audi/Apps/PrimaryComm.c → EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.c

@@ -1,41 +1,39 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "PrimaryComm.h"
-
-#define PASS                1
-#define FAIL                -1
-
-struct Address Addr = {0x01, 0x02, 0x03, 0x04, 0xFF};
-struct Command Cmd = {0x01, 0x02, 0x0a, 0x2C, 0x83, 0x86, 0x87, 0xe0, 0xe1, 0xe2, 0xe3};
-
-int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *rx)
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+#include "../Config.h"
+
+#include "Module_PrimaryComm.h"
+#include "PrimaryComm.h"
+
+//------------------------------------------------------------------------------
+int tranceive(int fd, uint8_t *cmd, uint8_t cmd_len, uint8_t *rx)
 {
     int len;
     //sleep(2); //required to make flush work, for some reason
@@ -44,21 +42,19 @@ int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *
         usleep(50000);
         len = read(fd, rx, 512);
     } else {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
-#endif
+        log_error("Serial command %s response fail.\n", cmd);
     }
 
     return len;
 }
 
-unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+int Query_FW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
-    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_FW_VER, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
+    uint8_t len = tranceive(fd, tx, sizeof(tx), rx);
 
     if (len > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -78,12 +74,12 @@ unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_
     return result;
 }
 
-unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+int Query_HW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_HW_VER, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     if (tranceive(fd, tx, sizeof(tx), rx) > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -103,13 +99,13 @@ unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_
     return result;
 }
 
-unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
+int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
-    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GPIO_IN, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
+    uint8_t len = tranceive(fd, tx, sizeof(tx), rx);
 
     if (len > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -143,12 +139,12 @@ unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_
     return result;
 }
 
-unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
+int Config_Gpio_Output(uint8_t fd, uint8_t targetAddr, Gpio_out *Set_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[9] = {0xaa, 0x00, targetAddr, CMD_CONFIG_GPIO_OUTPUT, 0x01, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     for (int idx = 0; idx < 2; idx++) {
         tx[6] |= (Set_Buf->Button_LED[idx] ? 0x01 : 0x00) << (0 + idx);
@@ -184,15 +180,15 @@ unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpi
     return result;
 }
 
-unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
+int Config_Rtc_Data(uint8_t fd, uint8_t targetAddr, Rtc *Set_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
-                             Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
-                             Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]
-                           };
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[21] = { 0xaa, 0x00, targetAddr, CMD_CONFIG_RTC, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
+                       Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
+                       Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]
+                     };
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++) {
         chksum ^= tx[6 + idx];
@@ -217,14 +213,14 @@ unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *S
     return result;
 }
 
-unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname)
+int Config_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[21] = {0xaa, 0x00, targetAddr, Cmd.config_Model_Name, 0x0E, 0x00,
-                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-                           };
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[21] = {0xaa, 0x00, targetAddr, CMD_CONFIG_MODEL_NAME, 0x0E, 0x00,
+                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+                     };
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     memcpy(tx + 6, modelname, 14);
 
@@ -235,7 +231,7 @@ unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsi
 
 //  for(int i = 0; i < 21; i++)
 //              printf ("tx = %x \n", tx[i]);
-    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+    uint8_t len = tranceive(fd, tx, sizeof(tx), rx);
 //  for(int i = 0; i < len; i++)
 //                  printf ("rx = %x \n", rx[i]);
     if (len > 6) {
@@ -259,12 +255,12 @@ unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsi
 
     return result;
 }
-unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
+int Update_Start(uint8_t fd, uint8_t targetAddr, uint32_t crc32)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32 >> 0) & 0xff, (crc32 >> 8) & 0xff, (crc32 >> 16) & 0xff, (crc32 >> 24) & 0xff, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[11] = {0xaa, 0x00, targetAddr, CMD_UPDATE_START, 0x04, 0x00, (crc32 >> 0) & 0xff, (crc32 >> 8) & 0xff, (crc32 >> 16) & 0xff, (crc32 >> 24) & 0xff, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++) {
         chksum ^= tx[6 + idx];
@@ -290,12 +286,12 @@ unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned
     return result;
 }
 
-unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
+int Update_Abord(uint8_t fd, uint8_t targetAddr)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_ABORT, 0x04, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     if (tranceive(fd, tx, sizeof(tx), rx) > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -314,17 +310,17 @@ unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
     return result;
 }
 
-unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+int Update_Transfer(uint8_t fd, uint8_t targetAddr, uint32_t startAddr, uint8_t *data, uint16_t length)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[11 + length];
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[11 + length];
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     tx[0] = 0xaa;
     tx[1] = 0x00;
     tx[2] = targetAddr;
-    tx[3] = Cmd.update_Transfer;
+    tx[3] = CMD_UPDATE_TRANSFER;
     tx[4] = (4 + length) & 0xff;
     tx[5] = ((4 + length) >> 8) & 0xff;
     tx[6] = (startAddr >> 0) & 0xff;
@@ -355,12 +351,12 @@ unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsign
     return result;
 }
 
-unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
+int Update_Finish(uint8_t fd, uint8_t targetAddr)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_FINISH, 0x04, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     if (tranceive(fd, tx, sizeof(tx), rx) > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {

+ 79 - 0
EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.h

@@ -0,0 +1,79 @@
+#ifndef PRIMARYCOMM_H_
+#define PRIMARYCOMM_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+// primary operative address
+//------------------------------------------------------------------------------
+#define OP_ADDR_AUX                             (0x01)
+#define OP_ADDR_FAN                             (0x02)
+#define OP_ADDR_RELAY                           (0x03)
+#define OP_ADDR_IO_EXTEND                       (0x04)
+#define OP_ADDR_BROADCAST                       (0xFF)
+
+//------------------------------------------------------------------------------
+// primary send packet command
+//------------------------------------------------------------------------------
+#define CMD_QUERY_FW_VER                        (0x01)
+#define CMD_QUERY_HW_VER                        (0x02)
+#define CMD_QUERY_GPIO_IN                       (0x0a)
+#define CMD_CONFIG_GPIO_OUTPUT                  (0x86)
+#define CMD_CONFIG_RTC                          (0x87)
+#define CMD_CONFIG_MODEL_NAME                   (0x83)
+#define CMD_UPDATE_START                        (0xe0)
+#define CMD_UPDATE_ABORT                        (0xe1)
+#define CMD_UPDATE_TRANSFER                     (0xe2)
+#define CMD_UPDATE_FINISH                       (0xe3)
+
+//------------------------------------------------------------------------------
+typedef struct Verion {
+    char Version_FW[16];
+    char Version_HW[16];
+} Ver;
+
+typedef struct GPIO_IN {
+    uint8_t AC_Connector;
+    uint8_t AC_MainBreaker;
+    uint8_t SPD;
+    uint8_t Door_Open;
+    uint8_t GFD[2];
+    uint8_t AC_Drop;
+    uint8_t Emergency_IO;
+
+    uint8_t Emergency_Btn;
+    uint8_t Button[2];
+    uint8_t Key[4];
+} Gpio_in;
+
+typedef struct GPIO_OUT {
+    uint8_t Button_LED[2];
+    uint8_t System_LED[4];
+    uint8_t AC_Connector;
+    uint8_t AC_Breaker;
+} Gpio_out;
+
+typedef struct RTC {
+    uint8_t RtcData[14];
+} Rtc;
+
+int Query_FW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_HW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf);
+
+int Config_Gpio_Output(uint8_t fd, uint8_t targetAddr, Gpio_out *Set_Buf);
+int Config_Rtc_Data(uint8_t fd, uint8_t targetAddr, Rtc *Set_Buf);
+int Config_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname);
+// 13 bytes
+// year : 4, month : 2, day : 2, hour : 2, min : 2, sec : 2
+//int Config_RTC();
+
+int Update_Start(uint8_t fd, uint8_t targetAddr, uint32_t crc32);
+int Update_Abord(uint8_t fd, uint8_t targetAddr);
+int Update_Transfer(uint8_t fd, uint8_t targetAddr, uint32_t startAddr, uint8_t *data, uint16_t length);
+int Update_Finish(uint8_t fd, uint8_t targetAddr);
+
+
+#endif /* PRIMARYCOMM_H_ */

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


+ 0 - 0
EVSE/Projects/DD360/Apps/Module_PsuComm.h → EVSE/Projects/DD360/Apps/ModulePsuComm/Module_PsuComm.h


+ 0 - 2934
EVSE/Projects/DD360/Apps/Module_EvComm.c

@@ -1,2934 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/can.h>
-#include    <linux/can/raw.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    "../../define.h"
-#include    "Module_EvComm.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define START               1
-#define STOP                0
-#define YES                 1
-#define NO                  0
-#define EQUAL               0
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct FanModuleData            *ShmFanModuleData;
-struct CHAdeMOData              *ShmCHAdeMOData;
-struct GBTData                  *ShmGBTData;
-struct CcsData                  *ShmCcsData;
-
-byte gun_count;
-int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-float _pow_1 = 0;
-float _cur_1 = 0;
-float _pow_2 = 0;
-float _cur_2 = 0;
-
-float _outVol_1 = 0;
-float _outCur_1 = 0;
-float _outVol_2 = 0;
-float _outCur_2 = 0;
-
-// 限制最大充電電壓,因應不同 type 槍線來限制
-// Chademo : 500V, 125A,
-// GB : 750, 120A
-// CCS : 950V, 120A
-float maxChargingVol[2] = { 5000, 9500 };           // 限制最大充電電壓,如依照模塊則填上 0
-// 限制最大充電電流與能量透過 Web
-float maxChargingCur[2] = { 5000, 1200 };           // 限制最大充電電流,如依照模塊則填上 0
-float maxChargingPow = 0;                           // 限制最大充電能量,如依照模塊則填上 0
-
-// 槍資訊
-struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-struct Ev_Board_Cmd Ev_Cmd = {
-    0,
-    0x00000200,
-    0x00000400,
-    0x00000500,
-    0x00000600,
-    0x00000700,
-    0x00000800,
-    0x00000900,
-    0x00000A00,
-    0x00000C00,
-    0x00000D00,
-
-    0x00000E00,
-    0x00000F00,
-    0x00001000,
-    0x00001100,
-
-    0x00001200,
-    0x00001400,
-    0x00001500,
-};
-
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-
-void PRINTF_FUNC(char *string, ...);
-
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur);
-void GetMaxPowerMethod(byte index, float *pow);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
-//=================================
-// Common routine
-//=================================
-void getTimeString(char *buff)
-{
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-}
-
-bool CheckUniqNumber(byte value)
-{
-    for (byte index = 0; index < gun_count; index++) {
-        if (_chargingData[index]->Evboard_id == value) {
-            struct timeval _end_time;
-            gettimeofday(&_end_time, NULL);
-            unsigned long diff = 1000000 *  (_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
-            if (diff >= 3000000) {
-                gettimeofday(&_id_assign_time, NULL);
-                return true;
-            } else {
-                return false;
-            }
-        }
-    }
-
-    gettimeofday(&_id_assign_time, NULL);
-    return true;
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //initial ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    //initial ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    if (CHAdeMO_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),  IPC_CREAT | 0777)) < 0) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
-#endif
-            return FAIL;
-        } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
-#endif
-            return FAIL;
-        } else
-        {}
-    }
-    if (GB_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),  IPC_CREAT | 0777)) < 0) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("[shmget ShmGBTData NG \n");
-#endif
-            return FAIL;
-        } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmat ShmGBTData NG \n");
-#endif
-            return FAIL;
-        } else
-        {}
-    }
-
-    if (CCS_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),  IPC_CREAT | 0777)) < 0) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmget ShmCcsData NG \n");
-#endif
-            return FAIL;
-        } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmat ShmCcsData NG \n");
-#endif
-            return FAIL;
-        } else
-        {}
-    }
-
-    return result;
-}
-
-//================================================
-// initial can-bus
-//================================================
-int InitCanBus()
-{
-    int                     s0, nbytes;
-    struct timeval          tv;
-    struct ifreq            ifr0;
-    struct sockaddr_can     addr0;
-
-    system("/sbin/ip link set can0 down");
-    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-    system("/sbin/ip link set can0 up");
-
-    s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
-
-    tv.tv_sec = 0;
-    tv.tv_usec = 10000;
-    if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct  timeval)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Set SO_RCVTIMEO NG");
-#endif
-    }
-    nbytes = 40960;
-    if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Set SO_RCVBUF NG");
-#endif
-    }
-    nbytes = 40960;
-    if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Set SO_SNDBUF NG");
-#endif
-    }
-
-    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;
-    bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
-    return s0;
-}
-
-//================================================
-//================================================
-// CANBUS receive task
-//================================================
-//================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return true;
-        }
-    }
-
-    return false;
-}
-
-void AddrAssignment(byte *data)
-{
-    byte target_number[8];
-    byte index = 0x00;
-
-    memcpy(target_number, data, sizeof(target_number));
-    index = *(data + 4);
-
-    if (gun_count == 1) {
-        index = 0x01;
-    }
-//  if (CheckUniqNumber(index))
-    {
-        PRINTF_FUNC("EV board id = %x \n", index);
-//      PRINTF_FUNC("target_number[0] = %x \n", target_number[0]);
-//      PRINTF_FUNC("target_number[1] = %x \n", target_number[1]);
-//      PRINTF_FUNC("target_number[2] = %x \n", target_number[2]);
-//      PRINTF_FUNC("target_number[3] = %x \n", target_number[3]);
-//      PRINTF_FUNC("target_number[4] = %x \n", target_number[4]);
-
-        PRINTF_FUNC("SetTargetAddr = %d, type = %d \n", index, _chargingData[index - 1]->Type);
-        SetTargetAddr(target_number, index);
-    }
-}
-
-void ClearAbnormalStatus_Chademo(byte gun_index)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL) {
-        return;
-    }
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023700", 6) == EQUAL &&
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail == YES) {
-        memcpy(code, "023700", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023704", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun == YES) {
-        memcpy(code, "023704", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023705", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission == YES) {
-        memcpy(code, "023705", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023706", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility == YES) {
-        memcpy(code, "023706", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023707", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP == YES) {
-        memcpy(code, "023707", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023708", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP == YES) {
-        memcpy(code, "023708", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023709", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP == YES) {
-        memcpy(code, "023709", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023710", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff == YES) {
-        memcpy(code, "023710", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023711", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff == YES) {
-        memcpy(code, "023711", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023712", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition == YES) {
-        memcpy(code, "023712", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023713", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault == YES) {
-        memcpy(code, "023713", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023714", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError == YES) {
-        memcpy(code, "023714", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023715", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop == YES) {
-        memcpy(code, "023715", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023716", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken == YES) {
-        memcpy(code, "023716", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023717", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail == YES) {
-        memcpy(code, "023717", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023718", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive == YES) {
-        memcpy(code, "023718", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023719", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout == YES) {
-        memcpy(code, "023719", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023720", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout == YES) {
-        memcpy(code, "023720", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023721", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout == YES) {
-        memcpy(code, "023721", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023722", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout == YES) {
-        memcpy(code, "023722", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023723", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout == YES) {
-        memcpy(code, "023723", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023724", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout == YES) {
-        memcpy(code, "023724", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023725", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout == YES) {
-        memcpy(code, "023725", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023726", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V == YES) {
-        memcpy(code, "023726", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023727", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V == YES) {
-        memcpy(code, "023727", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023728", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop == YES) {
-        memcpy(code, "023728", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023729", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop == YES) {
-        memcpy(code, "023729", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023730", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
-        memcpy(code, "023730", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023731", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail == YES) {
-        memcpy(code, "023731", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023732", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard == YES) {
-        memcpy(code, "023732", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023733", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit == YES) {
-        memcpy(code, "023733", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023734", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit == YES) {
-        memcpy(code, "023734", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023735", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed == YES) {
-        memcpy(code, "023735", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023736", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown == YES) {
-        memcpy(code, "023736", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                PRINTF_FUNC("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-                if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "023700", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = NO; }
-                    if (strncmp(code, "023704", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = NO; }
-                    if (strncmp(code, "023705", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = NO; }
-                    if (strncmp(code, "023706", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = NO; }
-                    if (strncmp(code, "023707", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = NO; }
-                    if (strncmp(code, "023708", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = NO; }
-                    if (strncmp(code, "023709", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = NO; }
-                    if (strncmp(code, "023710", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = NO; }
-                    if (strncmp(code, "023711", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = NO; }
-                    if (strncmp(code, "023712", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = NO; }
-                    if (strncmp(code, "023713", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = NO; }
-                    if (strncmp(code, "023714", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = NO; }
-                    if (strncmp(code, "023715", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = NO; }
-                    if (strncmp(code, "023716", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = NO; }
-                    if (strncmp(code, "023717", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = NO; }
-                    if (strncmp(code, "023718", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = NO; }
-                    if (strncmp(code, "023719", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = NO; }
-                    if (strncmp(code, "023720", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = NO; }
-                    if (strncmp(code, "023721", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = NO; }
-                    if (strncmp(code, "023722", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = NO; }
-                    if (strncmp(code, "023723", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = NO; }
-                    if (strncmp(code, "023724", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = NO; }
-                    if (strncmp(code, "023725", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = NO; }
-                    if (strncmp(code, "023726", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = NO; }
-                    if (strncmp(code, "023727", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = NO; }
-                    if (strncmp(code, "023728", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = NO; }
-                    if (strncmp(code, "023729", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = NO; }
-                    if (strncmp(code, "023730", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO; }
-                    if (strncmp(code, "023731", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = NO; }
-                    if (strncmp(code, "023732", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = NO; }
-                    if (strncmp(code, "023733", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = NO; }
-                    if (strncmp(code, "023734", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = NO; }
-                    if (strncmp(code, "023735", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = NO; }
-                    if (strncmp(code, "023736", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = NO; }
-                }
-            }
-        }
-    }
-}
-
-void ClearAbnormalStatus_GB(byte gun_index)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL) {
-        return;
-    }
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023702", 6) == EQUAL &&
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail == YES) {
-        memcpy(code, "023702", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023900", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 == YES) {
-        memcpy(code, "023900", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023901", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL == YES) {
-        memcpy(code, "023901", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023902", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE == YES) {
-        memcpy(code, "023902", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023903", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT == YES) {
-        memcpy(code, "023903", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023904", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT == YES) {
-        memcpy(code, "023904", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023905", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT == YES) {
-        memcpy(code, "023905", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023906", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE == YES) {
-        memcpy(code, "023906", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023907", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE == YES) {
-        memcpy(code, "023907", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023908", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT == YES) {
-        memcpy(code, "023908", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023909", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V == YES) {
-        memcpy(code, "023909", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023910", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V == YES) {
-        memcpy(code, "023910", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023911", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD == YES) {
-        memcpy(code, "023911", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023912", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD == YES) {
-        memcpy(code, "023912", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023913", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL == YES) {
-        memcpy(code, "023913", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023914", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK == YES) {
-        memcpy(code, "023914", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023915", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT == YES) {
-        memcpy(code, "023915", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023916", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT == YES) {
-        memcpy(code, "023916", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023917", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT == YES) {
-        memcpy(code, "023917", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023918", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT == YES) {
-        memcpy(code, "023918", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023919", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V == YES) {
-        memcpy(code, "023919", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023930", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT == YES) {
-        memcpy(code, "023930", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023931", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT == YES) {
-        memcpy(code, "023931", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023932", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT == YES) {
-        memcpy(code, "023932", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023933", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT == YES) {
-        memcpy(code, "023933", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023934", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT == YES) {
-        memcpy(code, "023934", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023935", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT == YES) {
-        memcpy(code, "023935", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023936", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT == YES) {
-        memcpy(code, "023936", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023937", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT == YES) {
-        memcpy(code, "023937", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023938", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT == YES) {
-        memcpy(code, "023938", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023939", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT == YES) {
-        memcpy(code, "023939", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023940", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT == YES) {
-        memcpy(code, "023940", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023941", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT == YES) {
-        memcpy(code, "023941", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023942", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT == YES) {
-        memcpy(code, "023942", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023943", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT == YES) {
-        memcpy(code, "023943", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023944", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT == YES) {
-        memcpy(code, "023944", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023945", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT == YES) {
-        memcpy(code, "023945", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023946", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT == YES) {
-        memcpy(code, "023946", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023947", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT == YES) {
-        memcpy(code, "023947", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023950", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL == YES) {
-        memcpy(code, "023950", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023951", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL == YES) {
-        memcpy(code, "023951", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023952", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL == YES) {
-        memcpy(code, "023952", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023953", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST == YES) {
-        memcpy(code, "023953", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023954", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION == YES) {
-        memcpy(code, "023954", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023955", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP == YES) {
-        memcpy(code, "023955", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023956", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT == YES) {
-        memcpy(code, "023956", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023957", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR == YES) {
-        memcpy(code, "023957", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023958", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP == YES) {
-        memcpy(code, "023958", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023959", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER == YES) {
-        memcpy(code, "023959", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023960", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V == YES) {
-        memcpy(code, "023960", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023961", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 == YES) {
-        memcpy(code, "023961", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023962", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT == YES) {
-        memcpy(code, "023962", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023963", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE == YES) {
-        memcpy(code, "023963", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023964", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON == YES) {
-        memcpy(code, "023964", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023970", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE == YES) {
-        memcpy(code, "023970", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023971", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE == YES) {
-        memcpy(code, "023971", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023972", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC == YES) {
-        memcpy(code, "023972", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023973", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC == YES) {
-        memcpy(code, "023973", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023974", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT == YES) {
-        memcpy(code, "023974", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023975", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE == YES) {
-        memcpy(code, "023975", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023976", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE == YES) {
-        memcpy(code, "023976", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023977", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR == YES) {
-        memcpy(code, "023977", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                PRINTF_FUNC("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-                if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "023702", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = NO; }
-                    if (strncmp(code, "023900", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = NO; }
-                    if (strncmp(code, "023901", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = NO; }
-                    if (strncmp(code, "023902", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = NO; }
-                    if (strncmp(code, "023903", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = NO; }
-                    if (strncmp(code, "023904", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = NO; }
-                    if (strncmp(code, "023905", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = NO; }
-                    if (strncmp(code, "023906", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = NO; }
-                    if (strncmp(code, "023907", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = NO; }
-                    if (strncmp(code, "023908", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = NO; }
-                    if (strncmp(code, "023909", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = NO; }
-                    if (strncmp(code, "023910", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = NO; }
-                    if (strncmp(code, "023911", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = NO; }
-                    if (strncmp(code, "023912", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = NO; }
-                    if (strncmp(code, "023913", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = NO; }
-                    if (strncmp(code, "023914", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = NO; }
-                    if (strncmp(code, "023915", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = NO; }
-                    if (strncmp(code, "023916", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = NO; }
-                    if (strncmp(code, "023917", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = NO; }
-                    if (strncmp(code, "023918", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = NO; }
-                    if (strncmp(code, "023919", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = NO; }
-                    if (strncmp(code, "023930", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = NO; }
-                    if (strncmp(code, "023931", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = NO; }
-                    if (strncmp(code, "023932", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = NO; }
-                    if (strncmp(code, "023933", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = NO; }
-                    if (strncmp(code, "023934", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = NO; }
-                    if (strncmp(code, "023935", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = NO; }
-                    if (strncmp(code, "023936", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = NO; }
-                    if (strncmp(code, "023937", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = NO; }
-                    if (strncmp(code, "023938", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = NO; }
-                    if (strncmp(code, "023939", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = NO; }
-                    if (strncmp(code, "023940", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = NO; }
-                    if (strncmp(code, "023941", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = NO; }
-                    if (strncmp(code, "023942", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = NO; }
-                    if (strncmp(code, "023943", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = NO; }
-                    if (strncmp(code, "023944", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = NO; }
-                    if (strncmp(code, "023945", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = NO; }
-                    if (strncmp(code, "023946", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = NO; }
-                    if (strncmp(code, "023947", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = NO; }
-                    if (strncmp(code, "023950", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = NO; }
-                    if (strncmp(code, "023951", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = NO; }
-                    if (strncmp(code, "023952", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = NO; }
-                    if (strncmp(code, "023953", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST = NO; }
-                    if (strncmp(code, "023954", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION = NO; }
-                    if (strncmp(code, "023955", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = NO; }
-                    if (strncmp(code, "023956", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT = NO; }
-                    if (strncmp(code, "023957", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = NO; }
-                    if (strncmp(code, "023958", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP = NO; }
-                    if (strncmp(code, "023959", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER = NO; }
-                    if (strncmp(code, "023960", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V = NO; }
-                    if (strncmp(code, "023961", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 = NO; }
-                    if (strncmp(code, "023962", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT = NO; }
-                    if (strncmp(code, "023963", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = NO; }
-                    if (strncmp(code, "023964", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = NO; }
-                    if (strncmp(code, "023970", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = NO; }
-                    if (strncmp(code, "023971", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = NO; }
-                    if (strncmp(code, "023972", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = NO; }
-                    if (strncmp(code, "023973", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = NO; }
-                    if (strncmp(code, "023974", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT = NO; }
-                    if (strncmp(code, "023975", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = NO; }
-                    if (strncmp(code, "023976", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = NO; }
-                    if (strncmp(code, "023977", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = NO; }
-                }
-            }
-        }
-    }
-}
-
-void ClearAbnormalStatus_CCS(byte gun_index)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL) {
-        return;
-    }
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023701", 6) == EQUAL &&
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail == YES) {
-        memcpy(code, "023701", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023737", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit == YES) {
-        memcpy(code, "023737", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023738", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition == YES) {
-        memcpy(code, "023738", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023739", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault == YES) {
-        memcpy(code, "023739", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023740", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction == YES) {
-        memcpy(code, "023740", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023741", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential == YES) {
-        memcpy(code, "023741", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023742", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange == YES) {
-        memcpy(code, "023742", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023743", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility == YES) {
-        memcpy(code, "023743", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023744", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent == YES) {
-        memcpy(code, "023744", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023745", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker == YES) {
-        memcpy(code, "023745", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023746", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData == YES) {
-        memcpy(code, "023746", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023747", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A == YES) {
-        memcpy(code, "023747", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023748", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B == YES) {
-        memcpy(code, "023748", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023749", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C == YES) {
-        memcpy(code, "023749", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023750", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 == YES) {
-        memcpy(code, "023750", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023751", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 == YES) {
-        memcpy(code, "023751", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023752", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 == YES) {
-        memcpy(code, "023752", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023753", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 == YES) {
-        memcpy(code, "023753", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023754", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 == YES) {
-        memcpy(code, "023754", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023755", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 == YES) {
-        memcpy(code, "023755", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023756", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 == YES) {
-        memcpy(code, "023756", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023757", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 == YES) {
-        memcpy(code, "023757", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023758", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError == YES) {
-        memcpy(code, "023758", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023759", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError == YES) {
-        memcpy(code, "023759", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023760", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession == YES) {
-        memcpy(code, "023760", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023761", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid == YES) {
-        memcpy(code, "023761", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023762", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid == YES) {
-        memcpy(code, "023762", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023763", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid == YES) {
-        memcpy(code, "023763", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023764", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid == YES) {
-        memcpy(code, "023764", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023765", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired == YES) {
-        memcpy(code, "023765", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023766", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid == YES) {
-        memcpy(code, "023766", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023767", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked == YES) {
-        memcpy(code, "023767", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023768", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable == YES) {
-        memcpy(code, "023768", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023769", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError == YES) {
-        memcpy(code, "023769", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023770", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError == YES) {
-        memcpy(code, "023770", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023771", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError == YES) {
-        memcpy(code, "023771", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023772", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled == YES) {
-        memcpy(code, "023772", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023773", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid == YES) {
-        memcpy(code, "023773", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023774", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode == YES) {
-        memcpy(code, "023774", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023775", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter == YES) {
-        memcpy(code, "023775", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023776", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid == YES) {
-        memcpy(code, "023776", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023777", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid == YES) {
-        memcpy(code, "023777", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023778", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow == YES) {
-        memcpy(code, "023778", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023779", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied == YES) {
-        memcpy(code, "023779", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023780", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid == YES) {
-        memcpy(code, "023780", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023781", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected == YES) {
-        memcpy(code, "023781", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023782", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError == YES) {
-        memcpy(code, "023782", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023783", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE == YES) {
-        memcpy(code, "023783", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023784", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop == YES) {
-        memcpy(code, "023784", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023785", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError == YES) {
-        memcpy(code, "023785", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023786", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError == YES) {
-        memcpy(code, "023786", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023787", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError == YES) {
-        memcpy(code, "023787", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023788", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort == YES) {
-        memcpy(code, "023788", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023789", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol == YES) {
-        memcpy(code, "023789", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023790", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted == YES) {
-        memcpy(code, "023790", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023791", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown == YES) {
-        memcpy(code, "023791", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023792", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke == YES) {
-        memcpy(code, "023792", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023793", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked == YES) {
-        memcpy(code, "023793", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023794", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked == YES) {
-        memcpy(code, "023794", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023795", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked == YES) {
-        memcpy(code, "023795", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023796", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked == YES) {
-        memcpy(code, "023796", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023797", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked == YES) {
-        memcpy(code, "023797", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023798", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked == YES) {
-        memcpy(code, "023798", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023799", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked == YES) {
-        memcpy(code, "023799", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023800", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked == YES) {
-        memcpy(code, "023800", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023801", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked == YES) {
-        memcpy(code, "023801", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023802", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked == YES) {
-        memcpy(code, "023802", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023803", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked == YES) {
-        memcpy(code, "023803", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023809", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init == YES) {
-        memcpy(code, "023809", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023810", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response == YES) {
-        memcpy(code, "023810", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023811", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence == YES) {
-        memcpy(code, "023811", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023812", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC == YES) {
-        memcpy(code, "023812", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023813", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc == YES) {
-        memcpy(code, "023813", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023814", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response == YES) {
-        memcpy(code, "023814", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023815", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session == YES) {
-        memcpy(code, "023815", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023816", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session == YES) {
-        memcpy(code, "023816", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023817", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle == YES) {
-        memcpy(code, "023817", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023818", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound == YES) {
-        memcpy(code, "023818", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023819", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq == YES) {
-        memcpy(code, "023819", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023823", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join == YES) {
-        memcpy(code, "023823", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023824", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join == YES) {
-        memcpy(code, "023824", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023825", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange == YES) {
-        memcpy(code, "023825", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023826", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification == YES) {
-        memcpy(code, "023826", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023832", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes == YES) {
-        memcpy(code, "023832", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023833", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes == YES) {
-        memcpy(code, "023833", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023834", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes == YES) {
-        memcpy(code, "023834", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023835", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes == YES) {
-        memcpy(code, "023835", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023836", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes == YES) {
-        memcpy(code, "023836", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023837", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes == YES) {
-        memcpy(code, "023837", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023838", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes == YES) {
-        memcpy(code, "023838", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023839", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes == YES) {
-        memcpy(code, "023839", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023840", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes == YES) {
-        memcpy(code, "023840", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023841", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes == YES) {
-        memcpy(code, "023841", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023842", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes == YES) {
-        memcpy(code, "023842", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023843", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes == YES) {
-        memcpy(code, "023843", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023844", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time == YES) {
-        memcpy(code, "023844", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023845", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time == YES) {
-        memcpy(code, "023845", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023846", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time == YES) {
-        memcpy(code, "023846", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023847", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time == YES) {
-        memcpy(code, "023847", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023848", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time == YES) {
-        memcpy(code, "023848", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023849", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time == YES) {
-        memcpy(code, "023849", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023850", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime == YES) {
-        memcpy(code, "023850", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023855", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO == YES) {
-        memcpy(code, "023855", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023856", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO == YES) {
-        memcpy(code, "023856", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023857", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO == YES) {
-        memcpy(code, "023857", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023858", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO == YES) {
-        memcpy(code, "023858", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023859", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT == YES) {
-        memcpy(code, "023859", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023860", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT == YES) {
-        memcpy(code, "023860", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023861", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT == YES) {
-        memcpy(code, "023861", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023862", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT == YES) {
-        memcpy(code, "023862", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023863", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO == YES) {
-        memcpy(code, "023863", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023864", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO == YES) {
-        memcpy(code, "023864", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023865", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST == YES) {
-        memcpy(code, "023865", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023866", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST == YES) {
-        memcpy(code, "023866", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023867", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER == YES) {
-        memcpy(code, "023867", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023868", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER == YES) {
-        memcpy(code, "023868", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023869", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER == YES) {
-        memcpy(code, "023869", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023870", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER == YES) {
-        memcpy(code, "023870", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023871", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH == YES) {
-        memcpy(code, "023871", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023872", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH == YES) {
-        memcpy(code, "023872", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023873", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS == YES) {
-        memcpy(code, "023873", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023874", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS == YES) {
-        memcpy(code, "023874", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023875", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO == YES) {
-        memcpy(code, "023875", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023876", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO == YES) {
-        memcpy(code, "023876", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023877", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO == YES) {
-        memcpy(code, "023877", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023878", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO == YES) {
-        memcpy(code, "023878", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023879", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO == YES) {
-        memcpy(code, "023879", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023880", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO == YES) {
-        memcpy(code, "023880", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023881", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence == YES) {
-        memcpy(code, "023881", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023882", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID == YES) {
-        memcpy(code, "023882", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023883", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error == YES) {
-        memcpy(code, "023883", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023884", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error == YES) {
-        memcpy(code, "023884", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023885", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error == YES) {
-        memcpy(code, "023885", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023886", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error == YES) {
-        memcpy(code, "023886", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023887", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error == YES) {
-        memcpy(code, "023887", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023888", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error == YES) {
-        memcpy(code, "023888", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023889", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error == YES) {
-        memcpy(code, "023889", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023890", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error == YES) {
-        memcpy(code, "023890", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023891", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging == YES) {
-        memcpy(code, "023891", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-//  else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023892", 6) == EQUAL &&
-//          ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
-//  {
-//      memcpy(code, "023892", 6);
-//      memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-//      isCleanCheck = true;
-//  }
-    else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023893", 6) == EQUAL &&
-             ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey == YES) {
-        memcpy(code, "023893", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                PRINTF_FUNC("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-                if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "023701", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = NO; }
-                    if (strncmp(code, "023737", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = NO; }
-                    if (strncmp(code, "023738", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = NO; }
-                    if (strncmp(code, "023739", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = NO; }
-                    if (strncmp(code, "023740", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = NO; }
-                    if (strncmp(code, "023741", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = NO; }
-                    if (strncmp(code, "023742", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = NO; }
-                    if (strncmp(code, "023743", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = NO; }
-                    if (strncmp(code, "023744", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = NO; }
-                    if (strncmp(code, "023745", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = NO; }
-                    if (strncmp(code, "023746", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = NO; }
-                    if (strncmp(code, "023747", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = NO; }
-                    if (strncmp(code, "023748", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = NO; }
-                    if (strncmp(code, "023749", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = NO; }
-                    if (strncmp(code, "023750", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = NO; }
-                    if (strncmp(code, "023751", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = NO; }
-                    if (strncmp(code, "023752", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = NO; }
-                    if (strncmp(code, "023753", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = NO; }
-                    if (strncmp(code, "023754", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = NO; }
-                    if (strncmp(code, "023755", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = NO; }
-                    if (strncmp(code, "023756", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = NO; }
-                    if (strncmp(code, "023757", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = NO; }
-                    if (strncmp(code, "023758", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = NO; }
-                    if (strncmp(code, "023759", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = NO; }
-                    if (strncmp(code, "023760", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = NO; }
-                    if (strncmp(code, "023761", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = NO; }
-                    if (strncmp(code, "023762", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = NO; }
-                    if (strncmp(code, "023763", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = NO; }
-                    if (strncmp(code, "023764", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = NO; }
-                    if (strncmp(code, "023765", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = NO; }
-                    if (strncmp(code, "023766", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = NO; }
-                    if (strncmp(code, "023767", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = NO; }
-                    if (strncmp(code, "023768", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = NO; }
-                    if (strncmp(code, "023769", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = NO; }
-                    if (strncmp(code, "023770", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = NO; }
-                    if (strncmp(code, "023771", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = NO; }
-                    if (strncmp(code, "023772", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = NO; }
-                    if (strncmp(code, "023773", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = NO; }
-                    if (strncmp(code, "023774", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = NO; }
-                    if (strncmp(code, "023775", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = NO; }
-                    if (strncmp(code, "023776", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = NO; }
-                    if (strncmp(code, "023777", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = NO; }
-                    if (strncmp(code, "023778", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = NO; }
-                    if (strncmp(code, "023779", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = NO; }
-                    if (strncmp(code, "023780", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = NO; }
-                    if (strncmp(code, "023781", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = NO; }
-                    if (strncmp(code, "023782", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = NO; }
-                    if (strncmp(code, "023783", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = NO; }
-                    if (strncmp(code, "023784", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = NO; }
-                    if (strncmp(code, "023785", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = NO; }
-                    if (strncmp(code, "023786", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = NO; }
-                    if (strncmp(code, "023787", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = NO; }
-                    if (strncmp(code, "023788", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = NO; }
-                    if (strncmp(code, "023789", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = NO; }
-                    if (strncmp(code, "023790", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = NO; }
-                    if (strncmp(code, "023791", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = NO; }
-                    if (strncmp(code, "023792", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = NO; }
-                    if (strncmp(code, "023793", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = NO; }
-                    if (strncmp(code, "023794", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = NO; }
-                    if (strncmp(code, "023795", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = NO; }
-                    if (strncmp(code, "023796", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = NO; }
-                    if (strncmp(code, "023797", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = NO; }
-                    if (strncmp(code, "023798", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = NO; }
-                    if (strncmp(code, "023799", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = NO; }
-                    if (strncmp(code, "023800", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = NO; }
-                    if (strncmp(code, "023801", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = NO; }
-                    if (strncmp(code, "023802", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = NO; }
-                    if (strncmp(code, "023803", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = NO; }
-                    if (strncmp(code, "023809", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = NO; }
-                    if (strncmp(code, "023810", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = NO; }
-                    if (strncmp(code, "023811", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = NO; }
-                    if (strncmp(code, "023812", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = NO; }
-                    if (strncmp(code, "023813", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = NO; }
-                    if (strncmp(code, "023814", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = NO; }
-                    if (strncmp(code, "023815", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = NO; }
-                    if (strncmp(code, "023816", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = NO; }
-                    if (strncmp(code, "023817", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = NO; }
-                    if (strncmp(code, "023818", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = NO; }
-                    if (strncmp(code, "023819", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = NO; }
-                    if (strncmp(code, "023823", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = NO; }
-                    if (strncmp(code, "023824", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = NO; }
-                    if (strncmp(code, "023825", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = NO; }
-                    if (strncmp(code, "023826", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = NO; }
-                    if (strncmp(code, "023832", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = NO; }
-                    if (strncmp(code, "023833", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = NO; }
-                    if (strncmp(code, "023834", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = NO; }
-                    if (strncmp(code, "023835", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = NO; }
-                    if (strncmp(code, "023836", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = NO; }
-                    if (strncmp(code, "023837", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = NO; }
-                    if (strncmp(code, "023838", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = NO; }
-                    if (strncmp(code, "023839", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = NO; }
-                    if (strncmp(code, "023840", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = NO; }
-                    if (strncmp(code, "023841", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = NO; }
-                    if (strncmp(code, "023842", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = NO; }
-                    if (strncmp(code, "023843", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = NO; }
-                    if (strncmp(code, "023844", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = NO; }
-                    if (strncmp(code, "023845", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = NO; }
-                    if (strncmp(code, "023846", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = NO; }
-                    if (strncmp(code, "023847", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = NO; }
-                    if (strncmp(code, "023848", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = NO; }
-                    if (strncmp(code, "023849", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = NO; }
-                    if (strncmp(code, "023850", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = NO; }
-                    if (strncmp(code, "023855", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = NO; }
-                    if (strncmp(code, "023856", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = NO; }
-                    if (strncmp(code, "023857", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = NO; }
-                    if (strncmp(code, "023858", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = NO; }
-                    if (strncmp(code, "023859", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = NO; }
-                    if (strncmp(code, "023860", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = NO; }
-                    if (strncmp(code, "023861", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = NO; }
-                    if (strncmp(code, "023862", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = NO; }
-                    if (strncmp(code, "023863", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = NO; }
-                    if (strncmp(code, "023864", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = NO; }
-                    if (strncmp(code, "023865", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = NO; }
-                    if (strncmp(code, "023866", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = NO; }
-                    if (strncmp(code, "023867", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = NO; }
-                    if (strncmp(code, "023868", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = NO; }
-                    if (strncmp(code, "023869", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = NO; }
-                    if (strncmp(code, "023870", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = NO; }
-                    if (strncmp(code, "023871", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = NO; }
-                    if (strncmp(code, "023872", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = NO; }
-                    if (strncmp(code, "023873", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = NO; }
-                    if (strncmp(code, "023874", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = NO; }
-                    if (strncmp(code, "023875", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = NO; }
-                    if (strncmp(code, "023876", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = NO; }
-                    if (strncmp(code, "023877", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = NO; }
-                    if (strncmp(code, "023878", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = NO; }
-                    if (strncmp(code, "023879", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = NO; }
-                    if (strncmp(code, "023880", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = NO; }
-                    if (strncmp(code, "023881", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = NO; }
-                    if (strncmp(code, "023882", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = NO; }
-                    if (strncmp(code, "023883", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = NO; }
-                    if (strncmp(code, "023884", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = NO; }
-                    if (strncmp(code, "023885", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = NO; }
-                    if (strncmp(code, "023886", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = NO; }
-                    if (strncmp(code, "023887", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = NO; }
-                    if (strncmp(code, "023888", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = NO; }
-                    if (strncmp(code, "023889", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = NO; }
-                    if (strncmp(code, "023890", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = NO; }
-                    if (strncmp(code, "023891", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = NO; }
-                    //if (strncmp(code, "023892", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = NO;
-                    if (strncmp(code, "023893", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey = NO; }
-                }
-            }
-        }
-    }
-}
-
-void AbnormalStopAnalysis(byte gun_index, byte *errCode)
-{
-    char string[7];
-    sprintf(string, "%d%d%d%d%d%d", *(errCode + 0), *(errCode + 1), *(errCode + 2), *(errCode + 3), *(errCode + 4), *(errCode + 5));
-
-    PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
-    if (strncmp(string, "000000", 6) == EQUAL ||
-            strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) != EQUAL) {
-        return;
-    }
-
-    memcpy(_chargingData[gun_index]->EvConnAlarmCode, string, 6);
-    PRINTF_FUNC("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s \n", _chargingData[gun_index]->EvConnAlarmCode);
-
-    if (strcmp(string, "023700") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = YES; }
-    if (strcmp(string, "023704") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = YES; }
-    if (strcmp(string, "023705") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = YES; }
-    if (strcmp(string, "023706") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = YES; }
-    if (strcmp(string, "023707") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = YES; }
-    if (strcmp(string, "023708") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = YES; }
-    if (strcmp(string, "023709") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = YES; }
-    if (strcmp(string, "023710") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = YES; }
-    if (strcmp(string, "023711") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = YES; }
-    if (strcmp(string, "023712") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = YES; }
-    if (strcmp(string, "023713") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = YES; }
-    if (strcmp(string, "023714") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = YES; }
-    if (strcmp(string, "023715") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = YES; }
-    if (strcmp(string, "023716") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = YES; }
-    if (strcmp(string, "023717") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = YES; }
-    if (strcmp(string, "023718") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = YES; }
-    if (strcmp(string, "023719") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = YES; }
-    if (strcmp(string, "023720") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = YES; }
-    if (strcmp(string, "023721") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = YES; }
-    if (strcmp(string, "023722") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = YES; }
-    if (strcmp(string, "023723") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = YES; }
-    if (strcmp(string, "023724") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = YES; }
-    if (strcmp(string, "023725") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = YES; }
-    if (strcmp(string, "023726") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = YES; }
-    if (strcmp(string, "023727") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = YES; }
-    if (strcmp(string, "023728") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = YES; }
-    if (strcmp(string, "023729") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = YES; }
-    if (strcmp(string, "023730") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES; }
-    if (strcmp(string, "023731") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = YES; }
-    if (strcmp(string, "023732") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = YES; }
-    if (strcmp(string, "023733") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = YES; }
-    if (strcmp(string, "023734") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = YES; }
-    if (strcmp(string, "023735") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = YES; }
-    if (strcmp(string, "023736") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = YES; }
-
-    if (strcmp(string, "023701") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = YES; }
-    if (strcmp(string, "023737") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = YES; }
-    if (strcmp(string, "023738") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = YES; }
-    if (strcmp(string, "023739") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = YES; }
-    if (strcmp(string, "023740") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = YES; }
-    if (strcmp(string, "023741") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = YES; }
-    if (strcmp(string, "023742") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = YES; }
-    if (strcmp(string, "023743") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = YES; }
-    if (strcmp(string, "023744") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = YES; }
-    if (strcmp(string, "023745") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = YES; }
-    if (strcmp(string, "023746") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = YES; }
-    if (strcmp(string, "023747") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = YES; }
-    if (strcmp(string, "023748") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = YES; }
-    if (strcmp(string, "023749") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = YES; }
-    if (strcmp(string, "023750") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = YES; }
-    if (strcmp(string, "023751") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = YES; }
-    if (strcmp(string, "023752") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = YES; }
-    if (strcmp(string, "023753") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = YES; }
-    if (strcmp(string, "023754") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = YES; }
-    if (strcmp(string, "023755") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = YES; }
-    if (strcmp(string, "023756") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = YES; }
-    if (strcmp(string, "023757") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = YES; }
-    if (strcmp(string, "023758") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = YES; }
-    if (strcmp(string, "023759") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = YES; }
-    if (strcmp(string, "023760") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = YES; }
-    if (strcmp(string, "023761") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = YES; }
-    if (strcmp(string, "023762") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = YES; }
-    if (strcmp(string, "023763") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = YES; }
-    if (strcmp(string, "023764") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = YES; }
-    if (strcmp(string, "023765") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = YES; }
-    if (strcmp(string, "023766") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = YES; }
-    if (strcmp(string, "023767") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = YES; }
-    if (strcmp(string, "023768") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = YES; }
-    if (strcmp(string, "023769") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = YES; }
-    if (strcmp(string, "023770") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = YES; }
-    if (strcmp(string, "023771") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = YES; }
-    if (strcmp(string, "023772") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = YES; }
-    if (strcmp(string, "023773") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = YES; }
-    if (strcmp(string, "023774") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = YES; }
-    if (strcmp(string, "023775") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = YES; }
-    if (strcmp(string, "023776") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = YES; }
-    if (strcmp(string, "023777") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = YES; }
-    if (strcmp(string, "023778") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = YES; }
-    if (strcmp(string, "023779") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = YES; }
-    if (strcmp(string, "023780") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = YES; }
-    if (strcmp(string, "023781") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = YES; }
-    if (strcmp(string, "023782") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = YES; }
-    if (strcmp(string, "023783") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = YES; }
-    if (strcmp(string, "023784") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = YES; }
-    if (strcmp(string, "023785") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = YES; }
-    if (strcmp(string, "023786") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = YES; }
-    if (strcmp(string, "023787") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = YES; }
-    if (strcmp(string, "023788") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = YES; }
-    if (strcmp(string, "023789") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = YES; }
-    if (strcmp(string, "023790") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = YES; }
-    if (strcmp(string, "023791") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = YES; }
-    if (strcmp(string, "023792") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = YES; }
-    if (strcmp(string, "023793") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = YES; }
-    if (strcmp(string, "023794") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = YES; }
-    if (strcmp(string, "023795") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = YES; }
-    if (strcmp(string, "023796") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = YES; }
-    if (strcmp(string, "023797") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = YES; }
-    if (strcmp(string, "023798") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = YES; }
-    if (strcmp(string, "023799") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = YES; }
-    if (strcmp(string, "023800") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = YES; }
-    if (strcmp(string, "023801") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = YES; }
-    if (strcmp(string, "023802") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = YES; }
-    if (strcmp(string, "023803") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = YES; }
-    if (strcmp(string, "023809") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = YES; }
-    if (strcmp(string, "023810") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = YES; }
-    if (strcmp(string, "023811") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = YES; }
-    if (strcmp(string, "023812") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = YES; }
-    if (strcmp(string, "023813") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = YES; }
-    if (strcmp(string, "023814") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = YES; }
-    if (strcmp(string, "023815") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = YES; }
-    if (strcmp(string, "023816") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = YES; }
-    if (strcmp(string, "023817") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = YES; }
-    if (strcmp(string, "023818") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = YES; }
-    if (strcmp(string, "023819") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = YES; }
-    if (strcmp(string, "023823") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = YES; }
-    if (strcmp(string, "023824") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = YES; }
-    if (strcmp(string, "023825") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = YES; }
-    if (strcmp(string, "023826") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = YES; }
-    if (strcmp(string, "023832") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = YES; }
-    if (strcmp(string, "023833") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = YES; }
-    if (strcmp(string, "023834") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = YES; }
-    if (strcmp(string, "023835") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = YES; }
-    if (strcmp(string, "023836") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = YES; }
-    if (strcmp(string, "023837") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = YES; }
-    if (strcmp(string, "023838") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = YES; }
-    if (strcmp(string, "023839") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = YES; }
-    if (strcmp(string, "023840") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = YES; }
-    if (strcmp(string, "023841") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = YES; }
-    if (strcmp(string, "023842") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = YES; }
-    if (strcmp(string, "023843") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = YES; }
-    if (strcmp(string, "023844") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = YES; }
-    if (strcmp(string, "023845") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = YES; }
-    if (strcmp(string, "023846") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = YES; }
-    if (strcmp(string, "023847") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = YES; }
-    if (strcmp(string, "023848") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = YES; }
-    if (strcmp(string, "023849") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = YES; }
-    if (strcmp(string, "023850") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = YES; }
-    if (strcmp(string, "023855") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = YES; }
-    if (strcmp(string, "023856") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = YES; }
-    if (strcmp(string, "023857") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = YES; }
-    if (strcmp(string, "023858") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = YES; }
-    if (strcmp(string, "023859") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = YES; }
-    if (strcmp(string, "023860") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = YES; }
-    if (strcmp(string, "023861") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = YES; }
-    if (strcmp(string, "023862") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = YES; }
-    if (strcmp(string, "023863") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = YES; }
-    if (strcmp(string, "023864") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = YES; }
-    if (strcmp(string, "023865") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = YES; }
-    if (strcmp(string, "023866") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = YES; }
-    if (strcmp(string, "023867") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = YES; }
-    if (strcmp(string, "023868") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = YES; }
-    if (strcmp(string, "023869") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = YES; }
-    if (strcmp(string, "023870") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = YES; }
-    if (strcmp(string, "023871") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = YES; }
-    if (strcmp(string, "023872") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = YES; }
-    if (strcmp(string, "023873") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = YES; }
-    if (strcmp(string, "023874") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = YES; }
-    if (strcmp(string, "023875") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = YES; }
-    if (strcmp(string, "023876") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = YES; }
-    if (strcmp(string, "023877") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = YES; }
-    if (strcmp(string, "023878") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = YES; }
-    if (strcmp(string, "023879") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = YES; }
-    if (strcmp(string, "023880") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = YES; }
-    if (strcmp(string, "023881") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = YES; }
-    if (strcmp(string, "023882") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = YES; }
-    if (strcmp(string, "023883") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = YES; }
-    if (strcmp(string, "023884") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = YES; }
-    if (strcmp(string, "023885") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = YES; }
-    if (strcmp(string, "023886") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = YES; }
-    if (strcmp(string, "023887") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = YES; }
-    if (strcmp(string, "023888") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = YES; }
-    if (strcmp(string, "023889") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = YES; }
-    if (strcmp(string, "023890") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = YES; }
-    if (strcmp(string, "023891") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = YES; }
-    if (strcmp(string, "023892") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = YES; }
-    if (strcmp(string, "023893") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey = YES; }
-
-    if (strcmp(string, "023702") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = YES; }
-    if (strcmp(string, "023900") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = YES; }
-    if (strcmp(string, "023901") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = YES; }
-    if (strcmp(string, "023902") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = YES; }
-    if (strcmp(string, "023903") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = YES; }
-    if (strcmp(string, "023904") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = YES; }
-    if (strcmp(string, "023905") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = YES; }
-    if (strcmp(string, "023906") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = YES; }
-    if (strcmp(string, "023907") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = YES; }
-    if (strcmp(string, "023908") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = YES; }
-    if (strcmp(string, "023909") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = YES; }
-    if (strcmp(string, "023910") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = YES; }
-    if (strcmp(string, "023911") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = YES; }
-    if (strcmp(string, "023912") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = YES; }
-    if (strcmp(string, "023913") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = YES; }
-    if (strcmp(string, "023914") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = YES; }
-    if (strcmp(string, "023915") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = YES; }
-    if (strcmp(string, "023916") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = YES; }
-    if (strcmp(string, "023917") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = YES; }
-    if (strcmp(string, "023918") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = YES; }
-    if (strcmp(string, "023919") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = YES; }
-    if (strcmp(string, "023930") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = YES; }
-    if (strcmp(string, "023931") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = YES; }
-    if (strcmp(string, "023932") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = YES; }
-    if (strcmp(string, "023933") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = YES; }
-    if (strcmp(string, "023934") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = YES; }
-    if (strcmp(string, "023935") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = YES; }
-    if (strcmp(string, "023936") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = YES; }
-    if (strcmp(string, "023937") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = YES; }
-    if (strcmp(string, "023938") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = YES; }
-    if (strcmp(string, "023939") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = YES; }
-    if (strcmp(string, "023940") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = YES; }
-    if (strcmp(string, "023941") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = YES; }
-    if (strcmp(string, "023942") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = YES; }
-    if (strcmp(string, "023943") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = YES; }
-    if (strcmp(string, "023944") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = YES; }
-    if (strcmp(string, "023945") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = YES; }
-    if (strcmp(string, "023946") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = YES; }
-    if (strcmp(string, "023947") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = YES; }
-    if (strcmp(string, "023950") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = YES; }
-    if (strcmp(string, "023951") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = YES; }
-    if (strcmp(string, "023952") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = YES; }
-    if (strcmp(string, "023953") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST = YES; }
-    if (strcmp(string, "023954") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION = YES; }
-    if (strcmp(string, "023955") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = YES; }
-    if (strcmp(string, "023956") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT = YES; }
-    if (strcmp(string, "023957") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = YES; }
-    if (strcmp(string, "023958") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP = YES; }
-    if (strcmp(string, "023959") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER = YES; }
-    if (strcmp(string, "023960") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V = YES; }
-    if (strcmp(string, "023961") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 = YES; }
-    if (strcmp(string, "023962") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT = YES; }
-    if (strcmp(string, "023963") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = YES; }
-    if (strcmp(string, "023964") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = YES; }
-    if (strcmp(string, "023970") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = YES; }
-    if (strcmp(string, "023971") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = YES; }
-    if (strcmp(string, "023972") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = YES; }
-    if (strcmp(string, "023973") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = YES; }
-    if (strcmp(string, "023974") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT = YES; }
-    if (strcmp(string, "023975") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = YES; }
-    if (strcmp(string, "023976") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = YES; }
-    if (strcmp(string, "023977") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = YES; }
-}
-
-void CANReceiver()
-{
-    pid_t canRecPid;
-
-    canRecPid = fork();
-
-    if (canRecPid > 0) {
-        int nbytes;
-        struct can_frame frame;
-        int intCmd;
-
-        // 槍資訊
-        struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-        struct timeval _cmd_ack_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-        bool isPass = false;
-        gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-
-        while (!isPass) {
-            isPass = true;
-            for (byte _index = 0; _index < gun_count; _index++) {
-                if (!FindChargingInfoData(_index, &_chargingData[0])) {
-                    DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-                    isPass = false;
-                    break;
-                }
-            }
-
-            sleep(1);
-        }
-
-        for (byte _index = 0; _index < gun_count; _index++) {
-            gettimeofday(&_cmd_ack_timeout[_index], NULL);
-        }
-
-        while (1) {
-            memset(&frame, 0, sizeof(struct can_frame));
-            nbytes = read(CanFd, &frame, sizeof(struct can_frame));
-
-            for (byte _index = 0; _index < gun_count; _index++) {
-                if (GetTimeoutValue(_cmd_ack_timeout[_index]) >= 5000000) {
-                    // ACK timeout
-                    //PRINTF_FUNC("gun = %x, ack timeout \n", _index);
-                }
-            }
-
-            if (nbytes > 0) {
-                byte target;
-                byte targetGun = 0x00;
-                intCmd = (int) (frame.can_id & CAN_EFF_MASK);
-
-                if (intCmd == ADDRESS_REQ) {
-                    AddrAssignment(frame.data);
-                    continue;
-                }
-                intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
-                target = ((byte) (frame.can_id & 0x000000FF));      // 0x01 or 0x02
-
-                for (byte _index = 0; _index < gun_count; _index++) {
-                    if (_chargingData[_index]->Evboard_id == target) {
-                        targetGun = _index;
-                        break;
-                    }
-                }
-
-                if (targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) {
-                    PRINTF_FUNC("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
-                    continue;
-                }
-                if (intCmd == 256) {
-                    continue;
-                }
-
-                gettimeofday(&_cmd_ack_timeout[targetGun], NULL);
-                switch (intCmd) {
-                case NOTIFICATION_EV_STATUS: {
-                    if (_chargingData[targetGun]->ConnectorPlugIn != frame.data[0]) {
-                        PRINTF_FUNC("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
-                    }
-
-                    _chargingData[targetGun]->ConnectorPlugIn = frame.data[0];
-                    _chargingData[targetGun]->PilotVoltage = frame.data[1];
-
-                    //PRINTF_FUNC("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
-                    //PRINTF_FUNC("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
-                }
-                break;
-                case ACK_EV_FW_VERSION: {
-                    byte ver[16];
-
-                    memset(ver, 0, sizeof(ver));
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        memcpy(ver, frame.data, frame.can_dlc);
-                        memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-                        //PRINTF_FUNC("chademo ver. : %s\n", ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version);
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        memcpy(ver, frame.data, frame.can_dlc);
-                        memcpy(ShmGBTData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-                        //PRINTF_FUNC("gbt ver. : %s\n", ShmGBTData->evse[_chargingData[targetGun]->type_index].version);
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                            for (byte _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++) {
-                                /*if (_vCount % 2 == 0 && _vCount != 0)
-                                {
-                                    ver[_vCount + _vPoint] = 0x2E;
-                                    _vPoint++;
-                                }*/
-
-                                ver[_vCount + _vPoint] = frame.data[_vCount];
-                            }
-
-                            memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-                            ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-                            //PRINTF_FUNC("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version);
-                        }
-                    }
-
-                    if (targetGun == 0) {
-                        memset(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
-                        memcpy(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, ver, ARRAY_SIZE(ver));
-                    } else {
-                        memset(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
-                        memcpy(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, ver, ARRAY_SIZE(ver));
-                    }
-                }
-                break;
-                case ACK_EV_HW_VERSION: {
-                    //PRINTF_FUNC("Get EV HW = %s \n", frame.data);
-                }
-                break;
-                case ACK_GET_OUTPUT_REQ: {
-                    _chargingData[targetGun]->EvBatterySoc = frame.data[1];
-                    _chargingData[targetGun]->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
-                    _chargingData[targetGun]->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
-                    _chargingData[targetGun]->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
-
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        //if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
-                        {
-                            ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-                        }
-
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        //if (ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
-                        {
-                            ShmGBTData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-                        }
-
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                            ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-                        }
-                    }
-
-                    //PRINTF_FUNC("EvBatterytargetVoltage = %f \n", _chargingData[targetGun]->EvBatterytargetVoltage);
-                    //PRINTF_FUNC("EvBatterytargetCurrent = %f \n", _chargingData[targetGun]->EvBatterytargetCurrent);
-                    //PRINTF_FUNC("BatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
-                    //PRINTF_FUNC("CurrentRequest = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
-                }
-                break;
-                case ACK_GET_EV_BATTERY_INFO: {
-                    //_chargingData[target].EvACorDCcharging = frame.data[0];
-                    //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
-                    _chargingData[targetGun]->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
-                    //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
-                    //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
-
-                        //PRINTF_FUNC("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
-                        //PRINTF_FUNC("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
-                        //PRINTF_FUNC("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-
-                    }
-                }
-                break;
-                case ACK_GET_MISCELLANEOUS_INFO: {
-                    _chargingData[targetGun]->GunLocked = frame.data[0];
-                    _chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
-
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                            //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
-                            //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
-                        }
-                    }
-
-                    //PRINTF_FUNC("EvboardStatus = %x \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].EvboardStatus);
-                    //PRINTF_FUNC("ConnectorPlug locked = %x \n", frame.data[0]);
-                    //PRINTF_FUNC("ConnectorTemp 0= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureP);
-                    //PRINTF_FUNC("ConnectorTemp 1= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureN);
-                    //PRINTF_FUNC("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
-                }
-                break;
-                case ACK_EVSE_ISOLATION_STATUS: {}
-                    break;
-                case ACK_EVSE_PRECHAGE_INFO: {
-                    _chargingData[targetGun]->PrechargeStatus = frame.data[0];
-                }
-                break;
-                case NOTIFICATION_EV_STOP: {
-                    // 車端要求停止
-                    // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
-                    PRINTF_FUNC("(%d) NOTIFICATION_EV_STOP err level = %d-----------------------------\n", targetGun, frame.data[0]);
-                    //if (frame.data[0] == 0x02)
-                    {
-                        AbnormalStopAnalysis(targetGun, frame.data + 1);
-                    }
-                    _chargingData[targetGun]->StopChargeFlag = YES;
-                }
-                break;
-                default:
-                    PRINTF_FUNC("EV board = %d, Ack none defined. intCmd = %d  \n", targetGun, intCmd);
-                    break;
-                }
-            }
-            usleep(10000);
-        }
-    }
-}
-
-//================================================
-// Main process
-//================================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
-{
-    return ( _byte & mask_table[_bit] ) != 0x00;
-}
-
-bool IsConnectorPlugIn(struct ChargingInfoData *chargingData)
-{
-    return (chargingData->ConnectorPlugIn == 0x01) ? true : false;
-}
-
-void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-    float vol1 = 0, cur1 = 0;
-    float vol2 = 0, cur2 = 0;
-
-    vol1 = chargingData_1->FireChargingVoltage;
-    cur1 = (chargingData_1->PresentChargingCurrent * 10);
-    vol2 = chargingData_2->FireChargingVoltage;
-    cur2 = (chargingData_2->PresentChargingCurrent * 10);
-
-    if (_outVol_1 != vol1 ||
-            _outCur_1 != cur1 ||
-            _outVol_2 != vol2 ||
-            _outCur_2 != cur2) {
-        /*PRINTF_FUNC("G1 -> Output Vol = %f, Output Cur = %f -- G2 -> Output Vol = %f, Output Cur = %f \n",
-            vol1, cur1, vol2, cur2);
-        */
-        _outVol_1 = vol1; _outCur_1 = cur1; _outVol_2 = vol2; _outCur_2 = cur2;
-    }
-
-    SetPresentOutputPower(vol1, cur1, vol2, cur2);
-}
-
-void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-    float pow1 = 0, cur1 = 0;
-    float pow2 = 0, cur2 = 0;
-    float vol = 0;
-
-    pow1 = chargingData_1->AvailableChargingPower;
-    cur1 = chargingData_1->AvailableChargingCurrent;
-
-    vol = chargingData_1->MaximumChargingVoltage;
-#ifndef DD360
-    GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
-    GetMaxPowerMethod(chargingData_1->Index, &pow1);
-#endif
-
-    pow2 = chargingData_2->AvailableChargingPower;
-    cur2 = chargingData_2->AvailableChargingCurrent;
-    vol = chargingData_2->MaximumChargingVoltage;
-#ifndef DD360
-    GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
-    GetMaxPowerMethod(chargingData_2->Index, &pow2);
-#endif
-
-    if (_pow_1 != pow1 ||
-            _cur_1 != cur1 ||
-            _pow_2 != pow2 ||
-            _cur_2 != cur2) {
-        PRINTF_FUNC("To EV (Real) Power_1 = %f, Cur_1 = %f, Power_2 = %f, Cur_2 = %f \n",
-                    pow1, cur1, pow2, cur2);
-        _pow_1 = pow1; _cur_1 = cur1; _pow_2 = pow2; _cur_2 = cur2;
-        chargingData_1->RealMaxCurrent = _cur_1;
-        chargingData_1->RealMaxPower = pow1;
-
-        if (gun_count == 2) {
-            chargingData_2->RealMaxCurrent = cur2;
-            chargingData_2->RealMaxPower = pow2;
-        }
-    }
-
-    SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
-}
-
-void Initialization()
-{
-    bool isPass = false;
-    while (!isPass) {
-        isPass = true;
-        for (byte _index = 0; _index < gun_count; _index++) {
-            if (!FindChargingInfoData(_index, &_chargingData[0])) {
-                DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-                isPass = false;
-                break;
-            }
-        }
-        sleep(1);
-    }
-}
-
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
-{
-    if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol) {
-        *vol = maxChargingVol[index];
-    }
-
-    if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur) {
-        *cur = maxChargingCur[index];
-    }
-
-    if (_chargingData[index]->SystemStatus == S_CHARGING &&
-            _chargingData[index]->ChargingProfileCurrent > 0 &&
-            _chargingData[index]->ChargingProfileCurrent <= *cur) {
-        *cur = _chargingData[index]->ChargingProfileCurrent;
-    }
-}
-
-void GetMaxPowerMethod(byte index, float *pow)
-{
-    if (maxChargingPow != 0 && maxChargingPow <= *pow) {
-        *pow = maxChargingPow;
-    }
-
-    if (_chargingData[index]->SystemStatus == S_CHARGING &&
-            _chargingData[index]->ChargingProfilePower > 0 &&
-            _chargingData[index]->ChargingProfilePower <= *pow) {
-        *pow = _chargingData[index]->ChargingProfilePower;
-    }
-}
-
-time_t GetRtcInfoForEpoch()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-    struct tm t;
-    time_t result;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-
-    t.tm_year = tmCSU->tm_year;
-    t.tm_mon = tmCSU->tm_mon;
-    t.tm_mday = tmCSU->tm_mday;
-    t.tm_hour = tmCSU->tm_hour;
-    t.tm_min = tmCSU->tm_min;
-    t.tm_sec = tmCSU->tm_sec;
-    t.tm_isdst = -1;
-    result = mktime(&t);
-
-    return result;
-}
-
-byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
-{
-    byte result = NO;
-
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == 0x01) {
-        // 012251
-        *(reason + 5)  = 0;
-        *(reason + 4)  = 1;
-        *(reason + 3)  = 2;
-        *(reason + 2)  = 2;
-        *(reason + 1)  = 5;
-        *(reason + 0)  = 1;
-        result = YES;
-    }
-
-    if (_chargingData[gunIndex]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            // 011012
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 1;
-            *(reason + 2) = 0;
-            *(reason + 1) = 1;
-            *(reason + 0) = 2;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES) {
-            // 012289
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 8;
-            *(reason + 0) = 9;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES) {
-            // 012234
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 3;
-            *(reason + 0) = 4;
-            result = YES;
-        }
-    } else if (_chargingData[gunIndex]->Type == _Type_GB) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            // 012290
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 9;
-            *(reason + 0) = 0;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES) {
-            // 012236
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 3;
-            *(reason + 0) = 6;
-            result = YES;
-        }
-    } else if (_chargingData[gunIndex]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-            // 011014
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 1;
-            *(reason + 2) = 0;
-            *(reason + 1) = 1;
-            *(reason + 0) = 4;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES) {
-            // 012288
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 8;
-            *(reason + 0) = 8;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES) {
-            // 012235
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 3;
-            *(reason + 0) = 5;
-            result = YES;
-        }
-    }
-
-    return result;
-}
-
-int main(int argc, char *argv[])
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-    Initialization();
-    CanFd = InitCanBus();
-    CANReceiver();
-
-    byte priorityLow = 1;
-    time_t rtc = GetRtcInfoForEpoch();
-    while (CanFd) {
-        for (byte _index = 0; _index < gun_count; _index++) {
-            if (priorityLow == 1) {
-                // 優先權較低 - 只要有回應即不會再詢問
-                if (_chargingData[_index]->Type == _Type_Chademo &&
-                        ShmCHAdeMOData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS) {
-                    SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-                    GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-                } else if (_chargingData[_index]->Type == _Type_GB &&
-                           ShmGBTData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS) {
-                    SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-                    GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-                } else if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 &&
-                            ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].SelfTest_Comp != PASS) {
-                        SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-                        GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-                    }
-                }
-
-                // 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
-                //PRINTF_FUNC("GetMiscellaneousInfo. index = %d, Eid = %d \n", _index, _chargingData[_index]->Evboard_id);
-                GetMiscellaneousInfo(_index,
-                                     _chargingData[_index]->RelayK1K2Status,
-                                     _chargingData[_index]->PresentChargedEnergy,
-                                     (_chargingData[_index]->PresentChargingVoltage * 10),
-                                     _chargingData[_index]->Evboard_id);
-            }
-
-            switch (_chargingData[_index]->SystemStatus) {
-            case S_IDLE:
-            case S_RESERVATION:
-                if (_chargingData[_index]->Type == _Type_Chademo) {
-                    ClearAbnormalStatus_Chademo(_index);
-                } else if (_chargingData[_index]->Type == _Type_GB) {
-                    ClearAbnormalStatus_GB(_index);
-                } else if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    ClearAbnormalStatus_CCS(_index);
-                }
-
-                if (priorityLow == 1) {
-                    _chargingData[_index]->PresentChargedEnergy = 0;
-                    _chargingData[_index]->PresentChargingPower = 0;
-                    _chargingData[_index]->GroundFaultStatus = GFD_WAIT;
-                    _chargingData[_index]->RealRatingPower = 0;
-                    _chargingData[_index]->StopChargeFlag = NO;
-                    _chargingData[_index]->ChargingFee = 0.0;
-                    _chargingData[_index]->EvBatterySoc = 0;
-                    _chargingData[_index]->PresentChargingVoltage = 0;
-                    _chargingData[_index]->PresentChargingCurrent = 0;
-                    _chargingData[_index]->EvBatteryMaxVoltage = 0;
-
-                    chargingTime[_index] = 0;
-
-                    //maxChargingCur[_index] = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
-                    maxChargingPow = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
-                }
-                break;
-            case S_PREPARNING: {
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                _chargingData[_index]->PowerConsumption = 0;
-            }
-            break;
-            case S_PREPARING_FOR_EV: {
-                // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-//                  PRINTF_FUNC("PresentChargingVoltage = %f \n", _chargingData[_index]->PresentChargingVoltage);
-//                  PRINTF_FUNC("PresentChargingCurrent = %f \n", _chargingData[_index]->PresentChargingCurrent);
-//                  PRINTF_FUNC("AvailableChargingPower = %f \n", _chargingData[_index]->AvailableChargingPower);
-//                  PRINTF_FUNC("AvailableChargingCurrent = %f \n", _chargingData[_index]->AvailableChargingCurrent);
-//                  PRINTF_FUNC("MaximumChargingVoltage = %f \n", _chargingData[_index]->MaximumChargingVoltage);
-
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                if (priorityLow == 1) {
-                    float maxVol, maxCur;
-                    // 樁端輸出能力
-                    maxVol = _chargingData[_index]->MaximumChargingVoltage;
-                    maxCur = _chargingData[_index]->AvailableChargingCurrent;
-
-                    GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
-
-                    PRINTF_FUNC("To EV_%d Max_Vol = %f, Cap_Cur = %f, Cap_Pow = %f \n",
-                                _index, maxVol, maxCur, _chargingData[_index]->AvailableChargingPower);
-                    _chargingData[_index]->RealMaxVoltage = maxVol;
-
-                    SetChargingPermission(_index, START,
-                                          _chargingData[_index]->AvailableChargingPower,
-                                          maxCur,
-                                          maxVol,
-                                          _chargingData[_index]->Evboard_id);
-
-                    // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
-                    GetEvBatteryInfo(_index, _chargingData[_index]->Evboard_id);
-                }
-                gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
-            }
-            break;
-            case S_PREPARING_FOR_EVSE:
-            case S_CCS_PRECHARGE_ST0:
-            case S_CCS_PRECHARGE_ST1: {
-                // 開始確認車端是否同意開始充電
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                if (priorityLow % 5 == 1) {
-                    // 樁端輸出能力改變
-                    if (gun_count == 1) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
-                    } else if (gun_count == 2) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
-                    }
-                }
-                // 持續通知 Isolation 測試狀態
-                if (priorityLow == 1) {
-                    // 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
-//                      if (_chargingData[_index]->FireChargingVoltage >= 3500)
-//                          _chargingData[_index]->GroundFaultStatus = GFD_PASS;
-
-                    //PRINTF_FUNC("To EV_%d GFD = %d \n",   _index, _chargingData[_index]->GroundFaultStatus);
-                    //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
-                    {
-                        //if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
-                        unsigned char _result = _chargingData[_index]->GroundFaultStatus;
-
-                        // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
-                        if (_chargingData[_index]->Type == _Type_Chademo ||
-                                _chargingData[_index]->Type == _Type_GB) {
-                            if (_result == GFD_WARNING) {
-                                _result = GFD_PASS;
-                            }
-                        }
-
-                        if (_result == GFD_WARNING || _result == GFD_PASS) {
-                            if (((GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 12000 &&
-                                    _chargingData[_index]->RealRatingPower > 0) ||
-                                    (GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 14000) {
-                                PRINTF_FUNC("**********EvComm : _index= %d, RealRatingPower = %d \n",
-                                            _index, _chargingData[_index]->RealRatingPower);
-                                //_result = GFD_PASS;
-                            } else {
-                                _result = GFD_WAIT;
-                            }
-                        }
-
-                        SetIsolationStatus(_index, _result, _chargingData[_index]->Evboard_id);
-                    }
-
-                    if (_chargingData[_index]->SystemStatus == S_CCS_PRECHARGE_ST0 &&
-                            _chargingData[_index]->PrechargeStatus == PRECHARGE_READY) {
-                        SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, _chargingData[_index]->Evboard_id);
-                    }
-                }
-            }
-            break;
-            case S_CHARGING: {
-                // 計算 Power
-                _chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
-
-                if (chargingTime[_index] == 0 ||
-                        chargingTime[_index] > _chargingData[_index]->PresentChargedDuration) {
-                    chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-                } else {
-                    int passTime = _chargingData[_index]->PresentChargedDuration - chargingTime[_index];
-
-                    if (passTime > 0) {
-                        float changingPow = (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            _chargingData[_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
-                        }
-
-                        _chargingData[_index]->PresentChargedEnergy += changingPow;
-                        _chargingData[_index]->PowerConsumption += changingPow;
-                        chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-                    }
-                }
-
-                // 開始確認車端是否同意開始充電
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                // for test end
-                if (priorityLow % 5 == 0) {
-                    // 樁端輸出能力改變
-                    if (gun_count == 1) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
-                    } else if (gun_count == 2) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
-                    }
-                }
-
-                if (_chargingData[_index]->GroundFaultStatus == GFD_FAIL) {
-                    SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
-                } else if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
-                }
-
-                // GFD 失敗再通知
-                if (priorityLow == 1) {
-                    if (_chargingData[_index]->Type == _Type_CCS_2 &&
-                            _chargingData[_index]->PrechargeStatus == PRECHARGE_READY) {
-                        SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, _chargingData[_index]->Evboard_id);
-                    }
-                }
-            }
-            break;
-            case S_TERMINATING: {
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                // 槍鎖還在,則代表是樁端要求的停止
-                if (_chargingData[_index]->GunLocked == START ||
-                        _chargingData[_index]->Type == _Type_CCS_2) {
-                    byte normalStop = 0x01;
-                    byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
-                    if (GetStopChargingReasonByEvse(_index, stopReason)) {
-                        normalStop = 0x02;
-                    }
-
-                    EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);
-                }
-
-                if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
-                }
-
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-            }
-            break;
-            case S_COMPLETE: {
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                if (priorityLow == 1) {
-                    float maxVol, maxCur;
-
-                    // 樁端輸出能力
-                    maxVol = _chargingData[_index]->MaximumChargingVoltage;
-                    maxCur = _chargingData[_index]->AvailableChargingCurrent;
-
-                    GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
-                    SetChargingPermission(_index, STOP,
-                                          _chargingData[_index]->AvailableChargingPower,
-                                          maxCur,
-                                          maxVol,
-                                          _chargingData[_index]->Evboard_id);
-                }
-            }
-            break;
-            }
-        }
-        priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
-        usleep(45000); //EV 小板通訊 (50 ms)
-    }
-    DEBUG_INFO("Module_EvComm : Can-bus port = %d \n", CanFd);
-    return FAIL;
-}

+ 0 - 88
EVSE/Projects/DD360/Apps/Module_EvComm.h

@@ -1,88 +0,0 @@
-#ifndef MODULE_EVCOMM_H_
-#define MODULE_EVCOMM_H_
-
-#include    <stdbool.h>
-
-int CanFd;
-
-typedef unsigned char       byte;
-
-extern struct Ev_Board_Cmd {
-    int none;                           // 0
-    int address_assignment;             // 0x00000200
-    int get_firmware_ver;               // 0x00000400
-    int get_hardware_ver;               // 0x00000500
-    int charging_permission;            // 0x00000600
-    int present_output_power;           // 0x00000700
-    int present_output_cap;             // 0x00000800
-    int get_output_req;                 // 0x00000900
-    int get_battery_info;               // 0x00000A00
-    int evse_stop_charging;             // 0x00000C00
-    int get_miscellaneous_info;         // 0x00000D00
-
-    int download_req;                   // 0x00000E00
-    int start_block_transfer;           // 0x00000F00
-    int data_transfer;                  // 0x00001000
-    int download_finish;                // 0x00001100
-
-    int isolation_status;               // 0x00001200
-    int sync_rtc_info;                  // 0x00001400
-    int evse_precharge_info;            // 0x00001500
-} Ev_Cmd;
-
-extern struct Ev_Cmd_Dir {
-    unsigned short master_to_slave;
-    unsigned short slave_to_master;
-} Ev_Dir;
-
-struct timeval _id_assign_time;
-
-// Send msg to can-bus
-void SetTargetAddr(byte *target_number, byte index);
-
-void GetFirmwareVersion(byte gun_index, byte toId);
-void SyncRtcInfo(byte gun_index, byte toId, int epoch);
-void GetHardwareVersion(byte gun_index, byte toId);
-void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputVol, short aOutputCur, byte toId);
-void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2);
-void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2);
-void GetOutputReq(byte gun_index, byte toId);
-void GetEvBatteryInfo(byte gun_index, byte toId);
-void GetMiscellaneousInfo(byte gun_index, byte relayStatus, float power, float voltage, byte toId);
-void SetIsolationStatus(byte gun_index, byte result, byte toId);
-void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId);
-// 發送電樁主動停止充電結果及原因
-void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId);
-
-// Receive msg From can-bus.
-
-enum Receieve_PSU_msgf {
-    // 車端主動
-    ADDRESS_REQ =                       0x080001FF,
-    NOTIFICATION_EV_STATUS =            0x08000300,
-    NOTIFICATION_EV_STOP =              0x08000B00,
-
-    // 車端回應
-    ACK_EV_FW_VERSION =                 0x08000400,
-    ACK_EV_HW_VERSION =                 0x08000500,
-    ACK_GET_OUTPUT_REQ =                0x08000900,
-    ACK_GET_EV_BATTERY_INFO =           0x08000A00,
-    ACK_GET_MISCELLANEOUS_INFO =        0x08000D00,
-    ACK_EVSE_ISOLATION_STATUS =         0x08001200,
-    ACK_EVSE_PRECHAGE_INFO =            0x08001500,
-};
-
-//DS60-120 add
-enum EV_LOG_INDEX {
-    EV_LOG_OUTPUT_CAP_POW = 0,
-    EV_LOG_OUTPUT_CAP_CUR = 1,
-    EV_LOG_NOW_OUTPUT_VOL = 2,
-    EV_LOG_NOW_OUTPUT_CUR = 3,
-    EV_LOG_EVSE_MAX_VOL =   4,
-    EV_LOG_EVSE_MAX_CUR =   5,
-    EV_LOG_MAX_BATT_VOL =   6,
-    EV_LOG_REAL_CAP_POW =   7,
-    EV_LOG_SOC =            8
-};
-#endif /* MODULE_EVCOMM_H_ */
-

+ 0 - 324
EVSE/Projects/DD360/Apps/Module_EventLogging.c

@@ -1,324 +0,0 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include	"../../define.h"
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-int StoreLogMsg(const char *fmt, ...)
-{
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-	//return milli-second
-	unsigned int StartTime,StopTime;
-
-	StartTime=(unsigned int)ST.time;
-	StopTime=(unsigned int)ET.time;
-	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-	va_list args;
-	char buffer[4096];
-	va_start(args, string);
-	vsnprintf(buffer, sizeof(buffer), string, args);
-	va_end(args);
-
-	DEBUG_INFO("%s \n", buffer);
-}
-
-//=================================
-// Common routine
-//=================================
-char* getTimeString(void)
-{
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
-
-	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-
-	return result;
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-	int result = PASS;
-	int MeterSMId;
-
-	//creat ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
-    {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
-		result = FAIL;
-	}
-    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	#ifdef SystemLogMessage
-    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-		#endif
-    	result = FAIL;
-   	 }
-    else
-    {}
-
-   	 //creat ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
-    {
-		#ifdef SystemLogMessage
-   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
-   		result = FAIL;
-	}
-    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	#ifdef SystemLogMessage
-    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-		#endif
-    	result = FAIL;
-   	}
-    else
-    {}
-
-    return result;
-}
-
-//================================================
-// Main process
-//================================================
-void AddFaultCodeToBuf(unsigned char *Code)
-{
-	if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10)
-	{
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
-		ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
-	}
-}
-
-void RemoveFaultCodeToBuf(unsigned char *Code)
-{
-	unsigned char find = 0x01;
-	char _code[7];
-	sprintf(_code,"%s", Code);
-
-	// 把相關的錯誤碼一次移除,避免重複顯示
-	while(find)
-	{
-		find = 0x00;
-		for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-		{
-			if (find == 0x00)
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0)
-				{
-					find = 0x01;
-				}
-			}
-			else
-			{
-				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-					&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
-			}
-		}
-
-		if (find)
-		{
-			ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
-		}
-	}
-}
-
-int main(void)
-{
-	int ByteCount,BitCount;
-	unsigned char tmp, EventCodeTmp[7];
-
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	for(;;)
-	{
-		//check Fault Status
-		for(ByteCount=0;ByteCount<sizeof(ShmStatusCodeData->FaultCode.PreviousFaultVal);ByteCount++)
-		{
-			if(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,FaultStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
-
-		//check Alarm Status
-		for(ByteCount=0;ByteCount<sizeof(ShmStatusCodeData->AlarmCode.PreviousAlarmVal);ByteCount++)
-		{
-			if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
-
-		//check Info Status
-		for(ByteCount=0;ByteCount<sizeof(ShmStatusCodeData->InfoCode.PreviousInfoVal);ByteCount++)
-		{
-			if(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,InfoStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
-		usleep(500000);
-	}
-
-	return FAIL;
-}

+ 0 - 2409
EVSE/Projects/DD360/Apps/Module_InternalComm.c

@@ -1,2409 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "../../define.h"
-#include    "internalComm.h"
-#include    <stdbool.h>
-
-#define AudiCustomized              1
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-#define TEN_MINUTES         600
-#define ENV_TEMP_MIN        45
-#define ENV_TEMP_MAX        50
-#define DEFAULT_AC_INDEX    2
-#define EQUAL               0
-#define COLOR_MAX_LV        100
-#define COLOR_MIN_LV        0
-
-#define AC_DEFAULT_VOL      220
-
-#define NO_DEFINE           255
-#define NDEFAULT_AC_INDEX   2
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct FanModuleData            *ShmFanModuleData;
-struct RelayModuleData          *ShmRelayModuleData;
-struct LedModuleData            *ShmLedModuleData;
-struct PsuData                  *ShmPsuData;
-struct OCPP16Data               *ShmOCPP16Data;
-
-#define VIN_MAX_VOLTAGE_IEC     285 // 大於該值 : OVP
-#define VIN_MIN_VOLTAGE_IEC     160 // 小於該值 : UVP
-#define VIN_MAX_VOLTAGE_UL      315 // 大於該值 : OVP // 美規 (W)
-#define VIN_MIN_VOLTAGE_UL      210 // 小於該值 : UVP
-
-#define VIN_DROP_VOLTAGE    150 // 小於該值 : ac drop
-
-#define VOUT_MAX_VOLTAGE    995
-#define VOUT_MIN_VOLTAGE    150
-#define IOUT_MAX_CURRENT    50
-
-#define MAX_FAN_SPEED       14000
-#define MIN_FAN_SPEED       3000
-#define NORMAL_FAN_SPEED    7000
-
-// GFD Status
-#define GFD_IDLE            0
-#define GFD_CABLECHK        1
-#define GFD_PRECHARGE       2
-#define GFD_CHARGING        3
-
-// LED Intensity (rate)
-#define LED_INTENSITY_DARKEST       0.2
-#define LED_INTENSITY_MEDIUM        0.6
-#define LED_INTENSITY_BRIGHTEST     1
-
-// EE Spec
-#define LED_BRIGHTNESS_LV_HIGH      1
-#define LED_BRIGHTNESS_LV_MID       0.5
-#define LED_BRIGHTNESS_LV_LOW       0.2
-
-// 最小切換 Relay 電壓
-#define SELF_TO_CHANGE_RELAY_STATUS         600
-// 透過電壓確認 Relay 是否搭上的依據電壓
-#define CHECK_RELAY_STATUS                  300
-#define CHECK_RELAY_STATUS_GAP              100
-// 安全在停止充電程序中斷開 Relay 的電流
-#define SEFETY_SWITCH_RELAY_CUR             20
-// 確認 Relay Welding 電壓
-#define RELAY_WELDING_DET                   300
-
-byte gunCount;
-byte acgunCount;
-// 槍資訊
-struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
-
-bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
-
-int Uart5Fd;
-char *relayRs485PortName = "/dev/ttyS5";
-unsigned short fanSpeedSmoothValue = 500;
-
-bool isStopChargingCount = false;
-struct timeval _close_ac_contactor;
-
-struct timeval _priority_time;
-struct timeval _led_priority_time;
-
-struct timeval  _ac_charging_comp;
-struct timeval  _ac_preparing;
-struct timeb    _ac_startChargingTime;
-struct timeb    _ac_endChargingTime;
-
-unsigned short _setFanSpeed = 0;
-float _beforeChargingTotalEnergy = 0.0;
-byte _checkLedChanged = 3;
-
-Ver ver;
-PresentInputVoltage inputVoltage;
-PresentOutputVoltage outputVoltage;
-FanSpeed fanSpeed;
-Temperature temperature;
-AuxPower auxPower;
-Gfd gfd_adc;
-Gfd_config gfd_config;
-Gpio_in gpio_in;
-Gpio_out gpio_out;
-Relay outputRelay;
-Relay regRelay;
-Rtc rtc;
-Led_Color cur_led_color;
-Led_Color led_color;
-
-Ac_Status acStatus;
-Ac_Led_Status ledStatus;
-Ac_Alarm_code acAlarmCode;
-Ac_Charging_energy acChargingEnergy;
-Ac_Charging_current acChargingCurrent;
-
-#define AC_OVP                      1
-#define AC_UVP                      2
-#define AC_OCP                      4
-#define AC_OTP                      8
-#define AC_GMI_FAULT                16
-#define AC_CP_ERROR                 32
-#define AC_AC_LEAKAGE               64
-#define AC_DC_LEAKAGE               128
-#define AC_SYSTEM_SELFTEST_FAULT    256
-#define AC_HANDSHAKE_TIMEOUT        512
-#define AC_EMC_STOP                 1024
-#define AC_RELAY_WELDING            2048
-#define AC_GF_MODULE_FAULT          4096
-#define AC_SHUTTER_FAULT            8192
-#define AC_LOCKER_FAULT             16384
-#define AC_POWER_DROP               32768
-#define AC_CIRCUIT_SHORT            65536
-#define AC_ROTARY_SWITCH_FAULT      131072
-#define AC_RELAY_DRIVE_FAULT        262144
-
-int _alarm_code[] = {AC_OVP, AC_UVP, AC_OCP, AC_OTP, AC_GMI_FAULT, AC_CP_ERROR, AC_AC_LEAKAGE
-                     , AC_DC_LEAKAGE, AC_SYSTEM_SELFTEST_FAULT, AC_HANDSHAKE_TIMEOUT, AC_EMC_STOP, AC_RELAY_WELDING
-                     , AC_GF_MODULE_FAULT, AC_SHUTTER_FAULT, AC_LOCKER_FAULT, AC_POWER_DROP, AC_CIRCUIT_SHORT
-                     , AC_ROTARY_SWITCH_FAULT, AC_RELAY_DRIVE_FAULT
-                    };
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int) ST.time;
-    StopTime = (unsigned int) ET.time;
-    //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-    return (StopTime - StartTime);
-}
-
-unsigned short MaxValue(unsigned short value1, unsigned short value2)
-{
-    return value1 >= value2 ? value1 : value2;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
-//==========================================
-// Communication Function
-//==========================================
-void GetFwAndHwVersion_Fan()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
-        // FanModuleData
-        strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
-    }
-
-    if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
-    }
-}
-
-void GetFwAndHwVersion_Relay()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
-        // RelayModuleData
-        strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
-    }
-
-    if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
-    }
-}
-
-void GetFwAndHwVersion_Led()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS) {
-        // LedModuleData
-        strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
-        //ShmLedModuleData->SelfTest_Comp = YES;
-    } else {
-        //PRINTF_FUNC("GetFwAndHwVersion_Led fail \n");
-    }
-
-//  if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
-//  {
-//      // SystemInfo
-//      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
-//      //PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
-//  }
-}
-
-void GetFwVersion_AC()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS) {
-        ac_chargingInfo[0]->SelfTest_Comp = YES;
-        strcpy((char *) ac_chargingInfo[0]->version, ver.Version_FW);
-    }
-}
-
-void GetAcModelName()
-{
-    memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
-    if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
-        PRINTF_FUNC("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
-    }
-}
-
-void SetRtcData_Relay()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-    //  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-    //          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-    //          tmCSU->tm_sec);
-
-    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-    if (Config_Rtc_Data(Uart5Fd, Addr.Relay, &rtc) == PASS) {
-        //PRINTF_FUNC("SetRtc (RB) sucessfully. \n");
-    }
-}
-
-void SetRtcData_Fan()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-    //  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-    //          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-    //          tmCSU->tm_sec);
-
-    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-    if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS) {
-        //PRINTF_FUNC("SetRtc (FB) sucessfully. \n");
-    }
-}
-
-void SetModelName_Fan()
-{
-    if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-        PRINTF_FUNC("Set Model name PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
-    }
-}
-
-// AC 三相輸入電壓
-void GetPresentInputVol()
-{
-    if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS) {
-        // resolution : 0.1
-        ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
-        ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
-        ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
-
-        //********************************************************************************************************//
-#ifndef DD360
-        // Vin (UVP)
-        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
-            if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
-            }
-        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
-            if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
-                PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
-                PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
-                PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
-            }
-        }
-        //********************************************************************************************************//
-        // Vin (OVP)
-        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
-            if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
-            }
-        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
-            if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
-                PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
-                PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
-                PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
-            }
-        }
-#endif
-    }
-}
-
-// 左右槍的 Relay 前後的輸出電壓
-void GetPersentOutputVol()
-{
-    if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS) {
-//      PRINTF_FUNC("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-//      PRINTF_FUNC("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
-//      PRINTF_FUNC("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
-//      PRINTF_FUNC("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
-
-        //PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-        //PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
-
-        ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
-        ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
-        ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
-        ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
-
-        for (int index = 0; index < gunCount; index++) {
-            if (index == 0) {
-                if (_chargingData[index]->Evboard_id == 0x01) {
-#ifndef DD360
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
-
-                } else if (_chargingData[index]->Evboard_id == 0x02) {
-#ifndef DD360
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-                }
-            } else if (index == 1) {
-#ifndef DD360
-                _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif
-                _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-            }
-
-            //unsigned short Ovp = 0;
-            //unsigned short Ocp = 0;
-            //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE]  // 最大輸出電壓與電池電壓最大值
-            //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]      // 最大輸出電流與需求電流最小值
-            if (_chargingData[index]->Type == _Type_Chademo) {
-                //Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
-                //Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
-            } else if (_chargingData[index]->Type == _Type_CCS_2) {
-
-            }
-        }
-    }
-}
-
-// 風扇速度
-void GetFanSpeed()
-{
-    //PRINTF_FUNC("Get fan board speed \n");
-    if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS) {
-        ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
-        ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
-        ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
-        ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
-//      PRINTF_FUNC("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
-//      PRINTF_FUNC("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
-//      PRINTF_FUNC("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
-//      PRINTF_FUNC("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
-        // Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
-        //SysInfoData (SystemFanRotaSpeed)
-    }
-}
-
-// 讀取 Relay 狀態
-void GetRelayOutputStatus()
-{
-    if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS) {
-#ifndef DD360
-        regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-#endif
-    }
-}
-
-// 確認 K1 K2 relay 的狀態
-void CheckK1K2RelayOutput(byte index)
-{
-    if (index == 0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-            if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES) {
-                _chargingData[index]->RelayK1K2Status = YES;
-            } else {
-                _chargingData[index]->RelayK1K2Status = NO;
-            }
-
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (gunCount == 1) {
-#ifndef DD360
-                    if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
-                        _chargingData[index]->RelayKPK2Status = YES;
-                    } else {
-                        _chargingData[index]->RelayKPK2Status = NO;
-                    }
-#else
-                    if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                        _chargingData[index]->RelayKPK2Status = YES;
-                    } else {
-                        _chargingData[index]->RelayKPK2Status = NO;
-                    }
-#endif
-                } else {
-                    if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                        _chargingData[index]->RelayKPK2Status = YES;
-                    } else {
-                        _chargingData[index]->RelayKPK2Status = NO;
-                    }
-                }
-            }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-            if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES) {
-                _chargingData[index]->RelayK1K2Status = YES;
-            } else {
-                _chargingData[index]->RelayK1K2Status = NO;
-            }
-
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-#ifndef DD360
-                if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    _chargingData[index]->RelayKPK2Status = YES;
-                } else {
-                    _chargingData[index]->RelayKPK2Status = NO;
-                }
-#else
-                if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                    _chargingData[index]->RelayKPK2Status = YES;
-                } else {
-                    _chargingData[index]->RelayKPK2Status = NO;
-                }
-#endif
-            }
-        }
-    } else if (index == 1) {
-        if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES) {
-            _chargingData[index]->RelayK1K2Status = YES;
-        } else {
-            _chargingData[index]->RelayK1K2Status = NO;
-        }
-
-        if (_chargingData[index]->Type == _Type_CCS_2) {
-#ifndef DD360
-            if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
-                _chargingData[index]->RelayKPK2Status = YES;
-            } else {
-                _chargingData[index]->RelayKPK2Status = NO;
-            }
-#else
-            if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                _chargingData[index]->RelayKPK2Status = YES;
-            } else {
-                _chargingData[index]->RelayKPK2Status = NO;
-            }
-#endif
-        }
-    }
-
-    /*if (regRelay.relay_event.bits.Gun1_Parallel_N == YES && regRelay.relay_event.bits.Gun1_Parallel_P == YES)
-        ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
-    else
-        ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;*/
-    ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
-
-//  PRINTF_FUNC("Check Relay Output. index = %d, RelayKPK2Status = %d, BridgeRelayStatus = %d \n",
-//          index, _chargingData[index]->RelayKPK2Status, ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus);
-}
-
-void GetGfdAdc()
-{
-    // define : 每 0.2 ~ 1 秒一次
-    // occur : <= 75k 歐姆 @ 150 - 750 Vdc
-    // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
-    if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS) {
-        for (int i = 0; i < gunCount; i++) {
-            if (_chargingData[i]->Type == 0x09 && !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag) {
-                if ((_chargingData[i]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE) {
-                    _chargingData[i]->GroundFaultStatus = GFD_PASS;
-                }
-                continue;
-            }
-
-            if (i == 0) {
-                if (gfd_adc.result_conn1 == GFD_WARNING) {
-                    gfd_adc.result_conn1 = GFD_PASS;
-                }
-                _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn1;
-//              PRINTF_FUNC("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
-//                      _chargingData[i]->GroundFaultStatus, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                if (_chargingData[i]->GroundFaultStatus == GFD_FAIL) {
-                    PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
-                                i, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                } else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
-                           _chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                    if (_chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                        PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
-                                    i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                    }
-                }
-            } else if (i == 1) {
-                if (gfd_adc.result_conn2 == GFD_WARNING) {
-                    gfd_adc.result_conn2 = GFD_PASS;
-                }
-                _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn2;
-                if (_chargingData[i]->GroundFaultStatus == GFD_FAIL) {
-                    PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
-                                i, gfd_adc.rb_step_2, gfd_adc.Resister_conn2, gfd_adc.voltage_conn2);
-                } else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
-                           _chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                    if (_chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                        PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
-                                    i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                    }
-                }
-            }
-        }
-    }
-}
-
-void GetGpioInput()
-{
-    if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS) {
-        // AC Contactor Status
-        if (gpio_in.AC_MainBreaker == 1) {
-            // AC Main Breaker ON
-            PRINTF_FUNC("RB AC Main Breaker. \n");
-        }
-
-        if (gpio_in.SPD == 1) {
-            // SPD (雷擊保護) ON
-            PRINTF_FUNC("RB SPD. \n");
-        }
-
-        if (gpio_in.Door_Open == 1) {
-            // Door Open
-            PRINTF_FUNC("RB Door Open. \n");
-        }
-
-        if (gpio_in.GFD[0] == 1) {
-            // GFD_1 Trigger
-        }
-
-        if (gpio_in.GFD[1] == 1) {
-            // GFD_2 Trigger
-        }
-
-        if (gpio_in.AC_Drop == 1) {
-            // AC Drop
-            PRINTF_FUNC("RB AC Drop. \n");
-        }
-
-        if (gpio_in.Emergency_IO == 1) {
-            // Emergency IO ON
-            PRINTF_FUNC("RB Emergency IO ON. \n");
-        }
-
-        if (gpio_in.Button_Emergency_Press == 1) {
-            // Emergency button Press
-        }
-
-        if (gpio_in.Button_On_Press == 1) {
-            // On button Press
-        }
-
-        if (gpio_in.Button_Off_Press == 1) {
-            // Off button Press
-        }
-
-        if (gpio_in.Key_1_Press == 1) {
-            // key 1 press
-        }
-
-        if (gpio_in.Key_2_Press == 1) {
-            // key 2 press
-        }
-
-        if (gpio_in.Key_3_Press == 1) {
-            // key 3 press
-        }
-
-        if (gpio_in.Key_4_Press == 1) {
-            // key 4 press
-        }
-    }
-}
-
-// 5V 12V 24V 48V
-void GetAuxPower()
-{
-    if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS) {
-        ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
-        ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
-        //ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
-        //ShmSysConfigAndInfo->SysInfo.AuxPower5V = auxPower.voltage[6];
-        // aux power voltage
-        //PRINTF_FUNC("aux1 = %x, \n", auxPower.voltage[0]);
-        //PRINTF_FUNC("aux2 = %x, \n", auxPower.voltage[1]);
-    }
-}
-
-void SetFanModuleSpeed()
-{
-    {
-        FanSpeed _fanSpeed;
-
-        _setFanSpeed += fanSpeedSmoothValue;
-
-        if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed) {
-            _setFanSpeed = ShmFanModuleData->SetFan1Speed;
-        }
-
-        //printf("_setFanSpeed = %d \n", _setFanSpeed);
-        _fanSpeed.speed[0] = _setFanSpeed;
-
-        _fanSpeed.speed[1] = _setFanSpeed;
-
-        _fanSpeed.speed[2] = _setFanSpeed;
-
-        _fanSpeed.speed[3] = _setFanSpeed;
-
-        if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS) {
-            //PRINTF_FUNC("successfully Fan\n");
-        }
-    }
-}
-
-//==========================================
-// Common Function
-//==========================================
-void SetK1K2RelayStatus(byte index)
-{
-    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) {
-            outputRelay.relay_event.bits.Gun1_P = YES;
-        }
-        return;
-    }
-
-    if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-            if (regRelay.relay_event.bits.Gun1_P == YES) {
-                outputRelay.relay_event.bits.Gun1_P = NO;
-            } else if (regRelay.relay_event.bits.Gun1_N == YES) {
-                outputRelay.relay_event.bits.Gun1_N = NO;
-            }
-
-            if (gunCount == 1 && _chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    outputRelay.relay_event.bits.CCS_Precharge = NO;
-                }
-            }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-            if (regRelay.relay_event.bits.Gun2_P == YES) {
-                outputRelay.relay_event.bits.Gun2_P = NO;
-            } else if (regRelay.relay_event.bits.Gun2_N == YES) {
-                outputRelay.relay_event.bits.Gun2_N = NO;
-            }
-
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    outputRelay.relay_event.bits.CCS_Precharge = NO;
-                }
-            }
-        }
-    } else if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                _chargingData[index]->SystemStatus <= S_CHARGING)) {
-        if (_chargingData[index]->RelayWeldingCheck == YES) {
-            if (_chargingData[index]->Evboard_id == 0x01) {
-                if (regRelay.relay_event.bits.Gun1_N == NO) {
-                    outputRelay.relay_event.bits.Gun1_N = YES;
-                } else if (regRelay.relay_event.bits.Gun1_P == NO) {
-                    outputRelay.relay_event.bits.Gun1_P = YES;
-                }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
-                if (regRelay.relay_event.bits.Gun2_N == NO) {
-                    outputRelay.relay_event.bits.Gun2_N = YES;
-                } else if (regRelay.relay_event.bits.Gun2_P == NO) {
-                    outputRelay.relay_event.bits.Gun2_P = YES;
-                }
-            }
-        }
-    } else if ((_chargingData[index]->SystemStatus >= S_TERMINATING &&
-                _chargingData[index]->SystemStatus <= S_COMPLETE)) {
-        if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
-            if (_chargingData[index]->Evboard_id == 0x01) {
-                if (regRelay.relay_event.bits.Gun1_P == YES) {
-                    outputRelay.relay_event.bits.Gun1_P = NO;
-                } else if (regRelay.relay_event.bits.Gun1_N == YES) {
-                    outputRelay.relay_event.bits.Gun1_N = NO;
-                }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
-                if (regRelay.relay_event.bits.Gun2_P == YES) {
-                    outputRelay.relay_event.bits.Gun2_P = NO;
-                } else if (regRelay.relay_event.bits.Gun2_N == YES) {
-                    outputRelay.relay_event.bits.Gun2_N = NO;
-                }
-            }
-        }
-    } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (gunCount == 1) {
-                    if (regRelay.relay_event.bits.CCS_Precharge == NO) {
-                        outputRelay.relay_event.bits.CCS_Precharge = YES;
-                    } else if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                        outputRelay.relay_event.bits.Gun1_P = NO;
-                    }
-                }
-            }
-#endif
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.CCS_Precharge == NO) {
-                    outputRelay.relay_event.bits.CCS_Precharge = YES;
-                } else if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    outputRelay.relay_event.bits.Gun2_P = NO;
-                }
-            }
-#endif
-        }
-    } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (gunCount == 1) {
-                    if (regRelay.relay_event.bits.Gun1_P == NO) {
-                        outputRelay.relay_event.bits.Gun1_P = YES;
-                    } else if (regRelay.relay_event.bits.Gun1_P == YES) {
-                        outputRelay.relay_event.bits.CCS_Precharge = NO;
-                    }
-                }
-            }
-#endif
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.Gun2_P == NO) {
-                    outputRelay.relay_event.bits.Gun2_P = YES;
-                } else if (regRelay.relay_event.bits.Gun2_P == YES) {
-                    outputRelay.relay_event.bits.CCS_Precharge = NO;
-                }
-            }
-#endif
-        }
-    }
-}
-
-void CheckAcInputOvpStatus(byte index)
-{
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
-//      if ((_chargingData[index]->SystemStatus >= S_PREPARNING && _chargingData[index]->SystemStatus <= S_CHARGING) ||
-//              (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-//      {
-//          if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
-//          {
-//              if (_psuInputVolR > VIN_MAX_VOLTAGE_IEC ||
-//                      _psuInputVolS > VIN_MAX_VOLTAGE_IEC ||
-//                      _psuInputVolT > VIN_MAX_VOLTAGE_IEC)
-//              {
-//                  PRINTF_FUNC("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
-//                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
-//              }
-//
-//          }
-//          else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
-//          {
-//              if (_psuInputVolR > VIN_MAX_VOLTAGE_UL ||
-//                      _psuInputVolS > VIN_MAX_VOLTAGE_UL ||
-//                      _psuInputVolT > VIN_MAX_VOLTAGE_UL)
-//              {
-//                  PRINTF_FUNC("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
-//                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
-//              }
-//          }
-//      }
-//      else
-        DEBUG_INFO("CheckAcInputOvpStatus\r\n");
-        _chargingData[index]->StopChargeFlag = YES;
-    }
-}
-
-void CheckPhaseLossStatus(byte index)
-{
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
-        DEBUG_INFO("CheckPhaseLossStatus\r\n");
-        _chargingData[index]->StopChargeFlag = YES;
-    }
-}
-
-void SetParalleRelayStatus()
-{
-    // 之後雙槍單模機種,橋接都會上
-    if (gunCount >= 2) {
-        if (_chargingData[0]->SystemStatus == S_BOOTING || _chargingData[1]->SystemStatus == S_BOOTING ||
-                (_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)) {
-            // 初始化~ 不搭橋接
-            if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
-                outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
-            } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
-                outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
-            }
-        } else {
-            if (_chargingData[0]->IsReadyToCharging == YES ||
-                    _chargingData[1]->IsReadyToCharging == YES) {
-                // ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
-                if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
-                    if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A) {
-                        // 最大充 - 搭上橋接
-                        if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
-                        }
-                    } else {
-                        // 平均充 - 不搭
-                        if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
-                        }
-                    }
-                } else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-                    if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M) {
-                        // 平均充 - 不搭
-                        if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
-                        }
-                    } else {
-                        // 最大充 - 搭上橋接
-                        if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
-                        }
-                    }
-                }
-            }
-        }
-    }
-}
-
-void CheckAlarmOccur()
-{
-    bool isErr = false;
-    for (byte count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
-        if (acAlarmCode.AcAlarmCode & _alarm_code[count]) {
-            isErr = true;
-            switch (_alarm_code[count]) {
-            case AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = YES; break;
-            case AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = YES; break;
-            case AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = YES; break;
-            case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = YES; break;
-            case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = YES; break;
-            case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = YES; break;
-            case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
-            case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
-            case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = YES; break;
-            case AC_HANDSHAKE_TIMEOUT: break;
-            //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES; break;
-            case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = YES; break;
-            case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = YES; break;
-            case AC_SHUTTER_FAULT: break;
-            case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = YES; break;
-            case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = YES; break;
-            case AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = YES; break;
-            case AC_ROTARY_SWITCH_FAULT: break;
-            case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = YES; break;
-            }
-        } else {
-            switch (_alarm_code[count]) {
-            case AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = NO; break;
-            case AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = NO; break;
-            case AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = NO; break;
-            case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = NO; break;
-            case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = NO; break;
-            case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = NO; break;
-            case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
-            case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
-            case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = NO; break;
-            case AC_HANDSHAKE_TIMEOUT: break;
-            //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO; break;
-            case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = NO; break;
-            case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = NO; break;
-            case AC_SHUTTER_FAULT: break;
-            case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = NO; break;
-            case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = NO; break;
-            case AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = NO; break;
-            case AC_ROTARY_SWITCH_FAULT:  break;
-            case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = NO; break;
-            }
-        }
-    }
-
-    ac_chargingInfo[0]->IsErrorOccur = isErr;
-}
-
-bool IsNoneMatchLedColor()
-{
-    bool result = false;
-
-    if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
-            cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
-            cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
-            cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
-            cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
-            cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue) {
-        result = true;
-    }
-
-    return result;
-}
-
-void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-    byte _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
-
-    if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
-        _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
-    } else if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
-        _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
-    }
-
-    //printf("chargingData_1->SystemStatus=%d\n",chargingData_1->SystemStatus);
-    //printf("chargingData_2->SystemStatus=%d\n",chargingData_2->SystemStatus);
-    //printf("ShmSysConfigAndInfo->SysWarningInfo.Level=%d\n",ShmSysConfigAndInfo->SysWarningInfo.Level);
-    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-        led_color.Connect_1_Green = COLOR_MIN_LV;
-        led_color.Connect_1_Blue = COLOR_MIN_LV;
-        led_color.Connect_1_Red = _colorBuf;
-        led_color.Connect_2_Green = COLOR_MIN_LV;
-        led_color.Connect_2_Blue = COLOR_MIN_LV;
-        led_color.Connect_2_Red = _colorBuf;
-    } else {
-        if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
-            if ((chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION) &&
-                    (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION)) {
-#ifdef AudiCustomized
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = _colorBuf;
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = _colorBuf;
-#else
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = COLOR_MIN_LV;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = COLOR_MIN_LV;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-#endif
-            } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                       (chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                led_color.Connect_1_Green = COLOR_MIN_LV;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-                led_color.Connect_2_Green = COLOR_MIN_LV;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-            }
-        } else {
-            if (chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION) {
-#ifdef AudiCustomized
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = _colorBuf;
-#else
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = COLOR_MIN_LV;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-#endif
-            } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                led_color.Connect_1_Green = COLOR_MIN_LV;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-            }
-
-            // --------------------------------------------------------------------------
-            if (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION) {
-#ifdef AudiCustomized
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = _colorBuf;
-#else
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = COLOR_MIN_LV;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-#endif
-            } else if ((chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                led_color.Connect_2_Green = COLOR_MIN_LV;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-            }
-        }
-    }
-    if (_checkLedChanged > 0) {
-        if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS) {
-            _checkLedChanged--;
-
-            cur_led_color.Connect_1_Red     = led_color.Connect_1_Red;
-            cur_led_color.Connect_1_Green   = led_color.Connect_1_Green;
-            cur_led_color.Connect_1_Blue    = led_color.Connect_1_Blue;
-            cur_led_color.Connect_2_Red     = led_color.Connect_2_Red;
-            cur_led_color.Connect_2_Green   = led_color.Connect_2_Green;
-            cur_led_color.Connect_2_Blue    = led_color.Connect_2_Blue;
-        }
-    } else if (IsNoneMatchLedColor()) {
-        _checkLedChanged = 3;
-    }
-}
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    }
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmFanModuleData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmFanModuleData NG\n");
-#endif
-        result = FAIL;
-    }
-    memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
-
-    if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmRelayModuleData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmRelayModuleData NG\n");
-#endif
-        result = FAIL;
-    }
-    memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
-
-    if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmLedModuleData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmLedModuleData NG\n");
-#endif
-        result = FAIL;
-    }
-    memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
-
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPsuData NG \n");
-#endif
-        result = FAIL;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmPsuData NG \n");
-#endif
-        result = FAIL;
-    }
-
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-#endif
-        result = FAIL;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-#endif
-        result = FAIL;
-    }
-
-    return result;
-}
-
-int InitComPort()
-{
-    int fd;
-    struct termios tios;
-
-    fd = open(relayRs485PortName, O_RDWR);
-    if (fd <= 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Module_InternalComm. InitComPort NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        return -1;
-    }
-    ioctl (fd, TCGETS, &tios);
-    tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
-    tios.c_lflag = 0;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (byte)0;     // timeout 0.5 second
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl (fd, TCSETS, &tios);
-
-    return fd;
-}
-
-//================================================
-// Main process
-//================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
-                == target) {
-            chargingData[target] =
-                &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
-                == target) {
-            chargingData[target] =
-                &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
-                == target) {
-            chargingData[target] =
-                &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return true;
-        }
-    }
-
-    return false;
-}
-
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
-{
-    if (target < AC_QUANTITY) {
-        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
-        return true;
-    }
-
-    return false;
-}
-
-void Initialization()
-{
-    bool isPass = false;
-
-    for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++) {
-        outputRelay.relay_event.relay_status[index] = 0x00;
-    }
-
-    while (!isPass) {
-        isPass = true;
-        for (byte _index = 0; _index < gunCount; _index++) {
-            if (!FindChargingInfoData(_index, &_chargingData[0])) {
-                DEBUG_ERROR("InternalComm : FindChargingInfoData false \n");
-                isPass = false;
-                break;
-            }
-        }
-
-        sleep(1);
-    }
-
-    isPass = false;
-
-    if (acgunCount > 0) {
-        while (!isPass) {
-            isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
-                if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
-                    DEBUG_ERROR("EvComm : FindAcChargingInfoData false \n");
-                    isPass = false;
-                    break;
-                }
-            }
-
-            sleep(1);
-        }
-    }
-}
-
-bool IsNoneMatchRelayStatus()
-{
-    bool result = false;
-
-    if (/*(regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
-        (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||*/
-        (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
-        (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
-        (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
-        (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N)/* ||
-        (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)*/) {
-        if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
-            PRINTF_FUNC("AC Contact Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
-            PRINTF_FUNC("CCS Precharge Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
-            PRINTF_FUNC("SMR1:D+ Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
-            PRINTF_FUNC("SMR1:D- Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
-            PRINTF_FUNC("SMR2:D+ Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
-            PRINTF_FUNC("SMR2:D- Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
-            PRINTF_FUNC("Parallel:D+ Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
-            PRINTF_FUNC("Parallel:D- Relay none match. \n");
-        }
-
-        result = true;
-    }
-
-    return result;
-}
-
-void MatchRelayStatus()
-{
-    // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
-    //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
-#ifndef DD360
-    ShmSysConfigAndInfo->SysInfo.AcContactorStatus  = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
-#endif
-    regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
-    regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
-    regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
-    regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
-    regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
-    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;
-}
-
-void CheckRelayStatusByADC()
-{
-    if (ShmRelayModuleData->Gun1FuseOutputVolt > 0 && ShmRelayModuleData->Gun1RelayOutputVolt > 0 &&
-            (ShmRelayModuleData->Gun1FuseOutputVolt == ShmRelayModuleData->Gun1RelayOutputVolt)) {
-        // Relay 前後電壓一致
-        _chargingData[0]->RelayK1K2Status = 0x01;
-    } else {
-        _chargingData[0]->RelayK1K2Status = 0x00;
-    }
-
-    if (ShmRelayModuleData->Gun2FuseOutputVolt > 0 && ShmRelayModuleData->Gun2RelayOutputVolt > 0 &&
-            (ShmRelayModuleData->Gun2FuseOutputVolt == ShmRelayModuleData->Gun2RelayOutputVolt)) {
-        // Relay 前後電壓一致
-        _chargingData[1]->RelayK1K2Status = 0x01;
-    } else {
-        _chargingData[1]->RelayK1K2Status = 0x00;
-    }
-}
-
-void SetGfdConfig(byte index, byte resister)
-{
-    gfd_config.index = index;
-    gfd_config.state = resister;
-
-    //PRINTF_FUNC("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
-    if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS) {
-//      PRINTF_FUNC("Set reqVol = %f, resister = %d \n",
-//              gfd_config.reqVol,
-//              gfd_config.resister);
-    }
-}
-
-void CableCheckDetected(byte index)
-{
-    // Cable Check
-    // 當火線上的電壓 = 車端要求的電壓電流
-    // _chargingData[targetGun]->EvBatterytargetVoltage
-    // 才可以開始偵測 1s
-    // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
-    // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
-    // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
-    if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
-            (_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)) {
-        if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_TERMINATING) ||
-                (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-            if (_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE &&
-                    _chargingData[index]->RelayWeldingCheck == YES) {
-                SetGfdConfig(index, GFD_CABLECHK);
-            } else if (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                       _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1) {
-                SetGfdConfig(index, GFD_PRECHARGE);
-            } else if (_chargingData[index]->SystemStatus >= S_CHARGING &&
-                       _chargingData[index]->SystemStatus <= S_TERMINATING) {
-                if (_chargingData[index]->Type == _Type_GB || _chargingData[index]->Type == _Type_Chademo) {
-                    SetGfdConfig(index, GFD_IDLE);
-                } else {
-                    SetGfdConfig(index, GFD_CHARGING);
-                }
-            }
-        } else if (_chargingData[index]->SystemStatus == S_COMPLETE || _chargingData[index]->SystemStatus == S_PREPARNING
-                   || _chargingData[index]->SystemStatus == S_IDLE) {
-            SetGfdConfig(index, GFD_IDLE);
-        }
-    }
-}
-
-void CheckOutputPowerOverCarReq(byte index)
-{
-    float fireV = _chargingData[index]->FireChargingVoltage;
-    float carV = _chargingData[index]->EvBatterytargetVoltage * 10;
-
-    if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
-            (_chargingData[index]->Type == _Type_Chademo ||
-             _chargingData[index]->Type == _Type_CCS_2 ||
-             _chargingData[index]->Type == _Type_GB)) {
-        if (fireV >= (carV + (carV * 0.1))) {
-            PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                        _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
-            DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                        _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
-            _chargingData[index]->StopChargeFlag = YES;
-        }
-    }
-}
-
-void CheckOutputVolNoneMatchFire(byte index)
-{
-    if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
-            (_chargingData[index]->Type == _Type_Chademo ||
-             _chargingData[index]->Type == _Type_CCS_2 ||
-             _chargingData[index]->Type == _Type_GB)) {
-        if (((_chargingData[index]->PresentChargingVoltage * 10) < _chargingData[index]->FireChargingVoltage - 300) ||
-                ((_chargingData[index]->PresentChargingVoltage * 10) > _chargingData[index]->FireChargingVoltage + 300)) {
-            if (!_isOutputNoneMatch[index]) {
-                _isOutputNoneMatch[index] = YES;
-                gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
-            } else {
-                if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
-                    /*PRINTF_FUNC("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
-                            index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
-                    DEBUG_ERROR("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f \n",
-                            index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
-                    _chargingData[index]->StopChargeFlag = YES;*/
-                }
-            }
-        } else {
-            _isOutputNoneMatch[index] = NO;
-        }
-    }
-}
-
-void CheckRelayWeldingStatus(byte index)
-{
-    if (!_isRelayWelding[index]) {
-        if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
-            gettimeofday(&_checkRelayWeldingTimer[index], NULL);
-            _isRelayWelding[index] = YES;
-        }
-    } else {
-        if ((GetTimeoutValue(_checkRelayWeldingTimer[index]) / 1000) >= 1000) {
-            _chargingData[index]->RelayWeldingCheck = YES;
-            return;
-        }
-
-        if (_chargingData[index]->FireChargingVoltage >= VOUT_MIN_VOLTAGE) {
-            if (_chargingData[index]->Type == _Type_Chademo) {
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
-            } else if (_chargingData[index]->Type == _Type_GB) {
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
-            } else if (_chargingData[index]->Type == _Type_CCS_2) {
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
-            }
-
-            PRINTF_FUNC("CheckRelayWeldingStatus : fail \n");
-            _chargingData[index]->StopChargeFlag = YES;
-        }
-    }
-}
-
-void GetPsuTempForFanSpeed()
-{
-    char temp = 0;
-
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
-            if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
-                temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
-            }
-        }
-    }
-
-    ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = temp;
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO) {
-        if (ShmFanModuleData->TestFanSpeed == NORMAL_FAN_SPEED) {
-            if (temp >= ENV_TEMP_MAX) {
-                ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
-            }
-        } else if (ShmFanModuleData->TestFanSpeed == MAX_FAN_SPEED) {
-            if (temp <= ENV_TEMP_MIN) {
-                ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
-            }
-        } else {
-            ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
-        }
-    }
-}
-
-void GetFanSpeedByFunction()
-{
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        return;
-    }
-
-    // 風控修改 :
-    // ******************************************************* //
-    //
-    //       當前PSU輸出總 KW       PSU Temp
-    // 30 x -------------------- x ---------- + 14 x (PSU Temp - 45)
-    //       當前樁最大功率 KW         45
-    //
-    // ******************************************************* //
-
-    // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
-    unsigned int _maxPower = ShmPsuData->SystemAvailablePower;
-    // 當前PSU輸出總 KW & PSU Temp :
-    unsigned char temp = 0;
-    float power = 0;
-
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
-            if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
-                temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
-            }
-        }
-        power += (_chargingData[index]->PresentChargingPower * 10);
-    }
-
-    double _pw_rate = 0;
-    if (_maxPower > 0) {
-        _pw_rate = power / (double)_maxPower;
-    }
-    double _temp_rate = 0;
-    if (temp > 0) {
-        _temp_rate = (double)temp / 45;
-    }
-    unsigned char _temp_diff = 0;
-    if (temp > 45) {
-        _temp_diff = temp - 45;
-    }
-
-    ShmFanModuleData->TestFanSpeed = ((30 * _pw_rate * _temp_rate + 14 * _temp_diff) / 100) * MAX_FAN_SPEED;
-
-    if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED) {
-        ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
-    }
-
-    if (ShmFanModuleData->TestFanSpeed < 0) {
-        ShmFanModuleData->TestFanSpeed = 0;
-    }
-//
-//  printf("power = %f \n", power);
-//  printf("_maxPower = %d \n", _maxPower);
-//  printf("temp = %d \n", temp);
-//
-//  printf("_pw_rate = %f \n", _pw_rate);
-//  printf("_temp_rate = %f \n", _temp_rate);
-//  printf("_temp_diff = %d \n", _temp_diff);
-//  printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
-//  printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
-}
-
-void GetAcStatus()
-{
-    if (Query_AC_Status(Uart5Fd, Addr.AcPlug, &acStatus) == PASS) {
-        ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = acStatus.MaxCurrent;
-
-        if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0) {
-            ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
-        }
-
-        ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
-        //  PRINTF_FUNC("CpStatus = %d \n", acStatus.CpStatus);
-        //              printf("CurLimit = %d \n", acStatus.CurLimit);
-        //              printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
-        //              printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
-        //              printf("LockStatus = %d \n", acStatus.LockStatus);
-        //              printf("RelayStatus = %d \n", acStatus.RelayStatus);
-        //              printf("ShutterStatus = %d \n", acStatus.ShutterStatus);
-        //              printf("MeterStatus = %d \n", acStatus.MeterStatus);
-        //              printf("PpStatus = %d \n", acStatus.PpStatus);
-        //              printf("MaxCurrent = %d \n", acStatus.MaxCurrent);
-        //              printf("RotateSwitchStatus = %d \n", acStatus.RelayStatus);
-        //              printf("============================== \n");
-        //
-        //              ac_chargingInfo[0]->SystemStatus = acStatus.CpStatus;
-    }
-//  else
-//      PRINTF_FUNC("GetAcStatus return fail. \n");
-}
-
-void GetAcAlarmCode()
-{
-    if (Query_AC_Alarm_Code(Uart5Fd, Addr.AcPlug, &acAlarmCode) == PASS) {
-        CheckAlarmOccur();
-    }
-}
-
-unsigned char GetChargingEnergy()
-{
-    return Query_Charging_Energy(Uart5Fd, Addr.AcPlug, &acChargingEnergy);
-}
-
-unsigned char GetChargingCurrent()
-{
-    return Query_Charging_Current(Uart5Fd, Addr.AcPlug, &acChargingCurrent);
-}
-
-void ChangeLedStatus()
-{
-    if (ac_chargingInfo[0]->SystemStatus == S_IDLE) {
-        ledStatus.ActionMode = 1;
-    } else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING) {
-        ledStatus.ActionMode = 3;
-    } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-        ledStatus.ActionMode = 4;
-    }
-
-    Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
-}
-
-void SetLegacyReq(byte _switch)
-{
-    Config_Legacy_Req(Uart5Fd, Addr.AcPlug, _switch);
-}
-
-void SetCpDuty(byte _value)
-{
-    Config_Ac_Duty(Uart5Fd, Addr.AcPlug, _value);
-}
-
-void ChangeToCsuMode()
-{
-    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, Addr.AcPlug);
-
-//  if (ac_chargingInfo[0]->IsModeChagned == PASS)
-//  {
-//      Config_Reset_MCU(Uart5Fd, Addr.AcPlug);
-//  }
-}
-
-void ChangeStartOrStopDateTime(byte isStart)
-{
-    char cmdBuf[32];
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-
-    sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
-            tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-            tmCSU->tm_sec);
-    if (isStart) {
-        strcpy((char *)ac_chargingInfo[0]->StartDateTime, cmdBuf);
-    } else {
-        strcpy((char *)ac_chargingInfo[0]->StopDateTime, cmdBuf);
-    }
-}
-
-void OcppStartTransation(byte gunIndex)
-{
-    if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
-    }
-
-    PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
-}
-
-void OcppStopTransation(byte gunIndex)
-{
-    if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
-    }
-
-    PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
-}
-
-bool OcppRemoteStop(byte gunIndex)
-{
-    bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
-    }
-
-    return result;
-}
-
-unsigned char isModeChange()
-{
-    unsigned char result = NO;
-
-    if (ac_chargingInfo[0]->SystemStatus != ac_chargingInfo[0]->PreviousSystemStatus) {
-        result = YES;
-        ac_chargingInfo[0]->PreviousSystemStatus = ac_chargingInfo[0]->SystemStatus;
-    }
-
-    return result;
-}
-
-void AcChargeTypeProcess()
-{
-    if (acgunCount > 0) {
-        //ac_chargingInfo[0]->SelfTest_Comp = YES;
-        //ac_chargingInfo[0]->IsModeChagned = PASS;
-        //---------------------------------------------
-        if (ac_chargingInfo[0]->SelfTest_Comp == NO) {
-            ac_chargingInfo[0]->IsModeChagned = NO;
-            GetFwVersion_AC();
-            GetAcModelName();
-        } else if (ac_chargingInfo[0]->SelfTest_Comp == YES) {
-            if (ac_chargingInfo[0]->IsModeChagned != PASS) {
-                ChangeToCsuMode();
-                return;
-            }
-            GetAcStatus();
-            GetAcAlarmCode();
-
-            byte _status = S_NONE;
-
-            if (ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsErrorOccur) {
-                _status = S_ALARM;
-            } else if (acStatus.CpStatus == AC_SYS_A || ac_chargingInfo[0]->IsErrorOccur) {
-                if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-                    _status = S_TERMINATING;
-                } else if (ac_chargingInfo[0]->SystemStatus >= S_TERMINATING) {
-                    if (GetTimeoutValue(_ac_charging_comp) >= 10000000 && acStatus.CpStatus == AC_SYS_A) {
-                        _status = S_IDLE;
-                    }
-                } else {
-                    _status = S_IDLE;
-                }
-            } else if (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING &&
-                       ac_chargingInfo[0]->SystemStatus < S_CHARGING) {
-                if (acStatus.CpStatus == AC_SYS_C && acStatus.RelayStatus == YES) {
-                    _status = S_CHARGING;
-                } else if (GetTimeoutValue(_ac_preparing) >= 30000000) {
-                    _status = S_IDLE;
-                }
-            } else if ((acStatus.CpStatus == AC_SYS_B || ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_B) &&
-                       ac_chargingInfo[0]->IsAvailable &&
-                       !ac_chargingInfo[0]->IsErrorOccur &&
-                       (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
-                        ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)) {
-                if (ac_chargingInfo[0]->RemoteStartFlag == YES) {
-                    PRINTF_FUNC("** AC Remote \n");
-                    ac_chargingInfo[0]->RemoteStartFlag = NO;
-                    strcpy((char *)ac_chargingInfo[0]->StartUserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-                    _status = S_PREPARNING;
-                } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
-                    PRINTF_FUNC("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
-                    strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-                    PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-                    _status = S_PREPARNING;
-                }
-            } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-                if (OcppRemoteStop(1)) {
-                    _status = S_TERMINATING;
-                }
-            }
-
-            //printf("_status = %d \n", _status);
-
-            if (_status != S_NONE && ac_chargingInfo[0]->SystemStatus != _status) {
-                ac_chargingInfo[0]->SystemStatus = _status;
-            }
-
-            // 設定限制最大充電電流 >= 6 ~ <= 32
-            switch (ac_chargingInfo[0]->SystemStatus) {
-            case S_IDLE:
-            case S_ALARM: {
-                if (isModeChange()) {
-                    ac_chargingInfo[0]->PresentChargedEnergy = 0.0;
-                    ac_chargingInfo[0]->PresentChargingVoltage = 0;
-                    ac_chargingInfo[0]->ChargingFee = 0.0;
-                    strcpy((char *)ac_chargingInfo[0]->StartDateTime, "");
-                    strcpy((char *)ac_chargingInfo[0]->StopDateTime, "");
-                    _beforeChargingTotalEnergy = 0.0;
-                }
-
-                ChangeLedStatus();
-            }
-            break;
-            case S_PREPARNING: {
-                if (isModeChange()) {
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-                    if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
-                        ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-                    }
-                    gettimeofday(&_ac_preparing, NULL);
-                }
-
-                if (GetChargingEnergy() == PASS) {
-                    //ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
-                    _beforeChargingTotalEnergy = acChargingEnergy.Energy;
-                }
-
-                SetLegacyReq(YES);
-                ChangeLedStatus();
-            }
-            break;
-            case S_CHARGING: {
-                if (isModeChange()) {
-                    ftime(&_ac_startChargingTime);
-                    OcppStartTransation(1);
-                    ChangeStartOrStopDateTime(YES);
-                    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-                }
-
-                if (GetChargingEnergy() == PASS) {
-                    if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0) {
-                        ac_chargingInfo[0]->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            ac_chargingInfo[0]->ChargingFee += ac_chargingInfo[0]->PresentChargedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
-                        }
-                    }
-
-                    _beforeChargingTotalEnergy = acChargingEnergy.Energy;
-                }
-
-                if (GetChargingCurrent() == PASS) {
-                    ac_chargingInfo[0]->PresentChargingPower = (((float)(AC_DEFAULT_VOL * acChargingCurrent.OuputCurrentL1) / 10) / 1000);
-                }
-
-                ftime(&_ac_endChargingTime);
-                ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
-                ac_chargingInfo[0]->PresentChargingVoltage = AC_DEFAULT_VOL;
-                ac_chargingInfo[0]->PresentChargingCurrent = ((float)acChargingCurrent.OuputCurrentL1 / 10);
-
-                // 用以判斷是否有在輸出
-                ac_chargingInfo[0]->IsCharging = acStatus.RelayStatus;
-
-                SetCpDuty(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent);
-                ChangeLedStatus();
-            }
-            break;
-            case S_TERMINATING: {
-                if (isModeChange()) {
-                    ChangeStartOrStopDateTime(NO);
-                    gettimeofday(&_ac_charging_comp, NULL);
-                }
-
-                SetLegacyReq(NO);
-                if (acStatus.RelayStatus == NO) {
-                    ac_chargingInfo[0]->SystemStatus = S_COMPLETE;
-                }
-            }
-            break;
-            case S_COMPLETE: {
-                if (isModeChange()) {
-                    gettimeofday(&_ac_charging_comp, NULL);
-                    ftime(&_ac_endChargingTime);
-                    if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL) {
-                        // AC 固定為第2把槍
-                        OcppStopTransation(1);
-                    }
-
-                    ChangeStartOrStopDateTime(NO);
-                    ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
-                }
-            }
-            break;
-            }
-        }
-    }
-}
-
-int main(void)
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-    acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-    // Open Uart5 for RB
-    Uart5Fd = InitComPort();
-    Initialization();
-    sleep(3);
-
-    if (Uart5Fd < 0) {
-        PRINTF_FUNC("(Internal) open port error. \n");
-        return 0;
-    }
-
-    outputRelay.relay_event.bits.AC_Contactor = 0x00;
-    outputRelay.relay_event.bits.CCS_Precharge = 0x00;
-    outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00;
-    outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
-    outputRelay.relay_event.bits.Gun1_P = 0x00;
-    outputRelay.relay_event.bits.Gun1_N = 0x00;
-    outputRelay.relay_event.bits.Gun2_N = 0x00;
-    outputRelay.relay_event.bits.Gun2_P = 0x00;
-    if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS) {
-        PRINTF_FUNC("Config_Relay_Output fail \n");
-    }
-
-    cur_led_color.Connect_1_Red = COLOR_MIN_LV;
-    cur_led_color.Connect_1_Green = COLOR_MIN_LV;
-    cur_led_color.Connect_1_Blue = COLOR_MIN_LV;
-    cur_led_color.Connect_2_Red = COLOR_MIN_LV;
-    cur_led_color.Connect_2_Green = COLOR_MIN_LV;
-    cur_led_color.Connect_2_Blue = COLOR_MIN_LV;
-
-    //bool printRelayStatus = true;
-    for (;;) {
-        bool isCharging = false;
-        // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-        if (ShmRelayModuleData->SelfTest_Comp == NO) {
-            GetFwAndHwVersion_Relay();
-            SetRtcData_Relay();
-            sleep(1);
-        }
-#ifndef NO_FAN_BOARD
-        if (ShmFanModuleData->SelfTest_Comp == NO) {
-            GetFwAndHwVersion_Fan();
-            SetModelName_Fan();
-            SetRtcData_Fan();
-            sleep(1);
-            gettimeofday(&_priority_time, NULL);
-        }
-#endif
-        // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
-        if (ShmLedModuleData->SelfTest_Comp == NO) {
-            // 自檢階段
-            //if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq <= _STEST_PSU_CAP)
-            //{
-            GetFwAndHwVersion_Led();
-            sleep(1);
-            gettimeofday(&_led_priority_time, NULL);
-            //}
-            /*else
-            {
-                // 自檢階段沒有問到版號
-                if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail == NO)
-                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES;
-            }*/
-        }
-
-        AcChargeTypeProcess();
-
-        if (ShmRelayModuleData->SelfTest_Comp == YES) {
-            // ==============優先權最高 10 ms ==============
-            // 輸出電壓
-            GetPersentOutputVol();
-
-#ifndef DD360
-            // 三相輸入電壓
-            GetPresentInputVol();
-            // 讀取當前 AC relay 狀態
-            regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-#endif
-            //GetRelayOutputStatus();
-
-            for (int i = 0; i < gunCount; i++) {
-                // Cable check (Set)
-                CableCheckDetected(i);
-
-                // check k1 k2 relay 狀態
-                CheckK1K2RelayOutput(i);
-
-                // 依據當前各槍的狀態選擇 搭上/放開 Relay
-                SetK1K2RelayStatus(i);
-
-#ifndef DD360
-                if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
-                    CheckPhaseLossStatus(i);
-                }
-
-                CheckAcInputOvpStatus(i);
-
-#endif
-                if (_chargingData[i]->SystemStatus == S_IDLE) {
-                    _chargingData[i]->RelayWeldingCheck = NO;
-                    _isRelayWelding[i] = NO;
-                }
-
-                if (_chargingData[i]->SystemStatus == S_BOOTING ||
-                        (_chargingData[i]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[i]->SystemStatus <= S_COMPLETE) ||
-                        (_chargingData[i]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[i]->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                        ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
-                        (ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG)) {
-                    _chargingData[i]->IsReadyToCharging = YES;
-                    isCharging = true;
-
-                    // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
-                    if (_chargingData[i]->Type == _Type_GB) {
-                        if (_chargingData[i]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                                _chargingData[i]->RelayWeldingCheck == NO) {
-                            CheckRelayWeldingStatus(i);
-                        }
-                    } else {
-                        _chargingData[i]->RelayWeldingCheck = YES;
-                    }
-
-                    if (_chargingData[i]->SystemStatus == S_CHARGING) {
-                        CheckOutputPowerOverCarReq(i);
-                        CheckOutputVolNoneMatchFire(i);
-                    } else {
-                        _isOutputNoneMatch[i] = NO;
-                    }
-                } else {
-                    _chargingData[i]->IsReadyToCharging = NO;
-                }
-            }
-            // Cable check (Get)
-            GetGfdAdc();
-
-            // 橋接 relay
-            //SetParalleRelayStatus();
-
-            // 搭上 AC Contactor
-//          if (isCharging)
-//              outputRelay.relay_event.bits.AC_Contactor = YES;
-//          else
-//              outputRelay.relay_event.bits.AC_Contactor = NO;
-
-            if (isCharging ||
-                    (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)) {
-                isStopChargingCount = false;
-                outputRelay.relay_event.bits.AC_Contactor = YES;
-            } else {
-                if (!isStopChargingCount) {
-                    gettimeofday(&_close_ac_contactor, NULL);
-                    isStopChargingCount = true;
-                } else {
-                    if ((outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
-                        outputRelay.relay_event.bits.AC_Contactor = NO;
-                    }
-                }
-            }
-
-            if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
-                outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
-            }
-
-            // 搭上/鬆開 Relay
-            if (IsNoneMatchRelayStatus()) {
-                if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay)) {
-                    //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-                    regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
-                    regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
-                    regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
-                    regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
-                    regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
-                    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;
-
-                    PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-                                regRelay.relay_event.bits.AC_Contactor,
-                                regRelay.relay_event.bits.Gun1_P,
-                                regRelay.relay_event.bits.Gun1_N,
-                                regRelay.relay_event.bits.Gun2_P,
-                                regRelay.relay_event.bits.Gun2_N,
-                                regRelay.relay_event.bits.CCS_Precharge,
-                                regRelay.relay_event.bits.Gun1_Parallel_P,
-                                regRelay.relay_event.bits.Gun1_Parallel_N);
-
-                }
-            }
-
-
-//          if(IsNoneMatchRelayStatus())
-//          {
-//              if (printRelayStatus)
-//              {
-////                    PRINTF_FUNC("Match Relay Target, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-////                            outputRelay.relay_event.bits.AC_Contactor,
-////                            outputRelay.relay_event.bits.Gun1_P,
-////                            outputRelay.relay_event.bits.Gun1_N,
-////                            outputRelay.relay_event.bits.Gun2_P,
-////                            outputRelay.relay_event.bits.Gun2_N,
-////                            outputRelay.relay_event.bits.CCS_Precharge,
-////                            outputRelay.relay_event.bits.Gun1_Parallel_P,
-////                            outputRelay.relay_event.bits.Gun1_Parallel_N);
-//              }
-//              printRelayStatus = false;
-//              if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
-//              {
-//                  PRINTF_FUNC("Match Relay Target, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-//                          outputRelay.relay_event.bits.AC_Contactor,
-//                          outputRelay.relay_event.bits.Gun1_P,
-//                          outputRelay.relay_event.bits.Gun1_N,
-//                          outputRelay.relay_event.bits.Gun2_P,
-//                          outputRelay.relay_event.bits.Gun2_N,
-//                          outputRelay.relay_event.bits.CCS_Precharge,
-//                          outputRelay.relay_event.bits.Gun1_Parallel_P,
-//                          outputRelay.relay_event.bits.Gun1_Parallel_N);
-//              }
-//          }
-//          else
-//          {
-//              if (!printRelayStatus)
-//              {
-//                  PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-//                          regRelay.relay_event.bits.AC_Contactor,
-//                          regRelay.relay_event.bits.Gun1_P,
-//                          regRelay.relay_event.bits.Gun1_N,
-//                          regRelay.relay_event.bits.Gun2_P,
-//                          regRelay.relay_event.bits.Gun2_N,
-//                          regRelay.relay_event.bits.CCS_Precharge,
-//                          regRelay.relay_event.bits.Gun1_Parallel_P,
-//                          regRelay.relay_event.bits.Gun1_Parallel_N);
-//              }
-//              printRelayStatus = true;
-//          }
-        }
-#if !defined NO_FAN_BOARD && !defined DD360ComBox
-        if (ShmFanModuleData->SelfTest_Comp == YES) {
-            if (GetTimeoutValue(_priority_time) / 1000 >= 1000) {
-                //GetPsuTempForFanSpeed();
-                GetFanSpeedByFunction();
-                GetFanSpeed();
-                ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
-                gettimeofday(&_priority_time, NULL);
-
-                ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-                ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-                ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-                ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-
-//              if (isCharging)
-//              {
-////                    if (ShmFanModuleData->PresentFan1Speed < MAX_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan2Speed < MAX_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan3Speed < MAX_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan4Speed < MAX_FAN_SPEED)
-////                    {
-////                        ShmFanModuleData->SetFan1Speed = MAX_FAN_SPEED;
-////                        ShmFanModuleData->SetFan2Speed = MAX_FAN_SPEED;
-////                        ShmFanModuleData->SetFan3Speed = MAX_FAN_SPEED;
-////                        ShmFanModuleData->SetFan4Speed = MAX_FAN_SPEED;
-////                    }
-//
-//                  // 在還沒問到 PSU 溫度~ 還是要有個最小轉速
-//                  ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
-//                  ShmFanModuleData->SetFan2Speed = MIN_FAN_SPEED;
-//                  ShmFanModuleData->SetFan3Speed = MIN_FAN_SPEED;
-//                  ShmFanModuleData->SetFan4Speed = MIN_FAN_SPEED;
-//
-//                  if (ShmFanModuleData->TestFanSpeed > 0)
-//                  {
-//                      ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-//                  }
-//              }
-//              else
-//              {
-////                    if (ShmFanModuleData->PresentFan1Speed > MIN_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan2Speed > MIN_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan3Speed > MIN_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan4Speed > MIN_FAN_SPEED)
-////                    {
-//                      ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
-//                      ShmFanModuleData->SetFan2Speed = MIN_FAN_SPEED;
-//                      ShmFanModuleData->SetFan3Speed = MIN_FAN_SPEED;
-//                      ShmFanModuleData->SetFan4Speed = MIN_FAN_SPEED;
-////                    }
-//
-//                  // 停止時,如溫度還是很高,則需要維持該轉速直到溫度降低
-//                  if (ShmFanModuleData->TestFanSpeed >= MAX_FAN_SPEED)
-//                  {
-//                      ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-//                  }
-//              }
-
-                //PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
-                SetFanModuleSpeed();
-            }
-        }
-#endif
-        if (ShmLedModuleData->SelfTest_Comp == YES) {
-            if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-                if (gunCount == 1) {
-                    SetLedColor(_chargingData[0], _chargingData[0]);
-                } else if (gunCount == 2) {
-                    SetLedColor(_chargingData[0], _chargingData[1]);
-                }
-
-                gettimeofday(&_led_priority_time, NULL);
-            }
-        }
-
-        usleep(10000);
-    }
-
-    return FAIL;
-}

+ 0 - 196
EVSE/Projects/DD360/Apps/Module_LcmContro.h

@@ -1,196 +0,0 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include 	<stdbool.h>
-#include	"../../define.h"
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-typedef unsigned char 			byte;
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct FanModuleData			*ShmFanModuleData;
-
-#define NO_DEFINE			255
-#define DEFAULT_AC_INDEX	2
-
-#define TIME_MAX_SEC		2592000 // 一個月,秒數
-#define POWER_MAX_KW		5000
-#define ENERGY_MAX_KWH		5000
-
-#define CMD_TITLE_1				0x5A
-#define CMD_TITLE_2				0xA5
-#define CMD_READ				0x80
-#define CMD_WRITE				0x81
-#define CMD_MULTI_WRITE			0x82
-#define CMD_MULTI_READ			0x83
-
-#define CMD_BACKLIGHT			0x01
-#define CMD_REGISTER			0x03
-
-enum _BATTERY_LEVEL_FOR_MAP
-{
-	_BATTERY_LEVEL_FOR_MAP_EMP = 0x00,
-	_BATTERY_LEVEL_FOR_MAP_LV1 = 0x01,
-	_BATTERY_LEVEL_FOR_MAP_LV2 = 0x02,
-	_BATTERY_LEVEL_FOR_MAP_LV3 = 0x03,
-	_BATTERY_LEVEL_FOR_MAP_LV4 = 0x04,
-	_BATTERY_LEVEL_FOR_MAP_LV5 = 0x05,
-};
-
-int _port;
-//char* pPortName = "/dev/ttyO2";
-char* pPortName = "/dev/ttyS3";
-char* moduleName = "DMT80480T070_09WT";
-byte _totalCount;
-byte acgunCount;
-struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
-
-byte ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-byte isDiffStatus = false;
-byte isChangeBattMap = false;
-// 當前選擇的槍號
-short _currentPage = _LCM_NONE;
-short _oldPage = _LCM_NONE;
-byte _gunIndex = 0;
-bool _wifi_conn_status = false;
-bool _battery_display_ani = false;
-byte _curPage_index = 0;
-bool _page_reload = false;
-
-// LCM - HW
-byte _everyPageRollChange = 0;
-short __conn_status = 0x0030;
-short __ethernet_status = 0x0032;
-short __3G4G_status = 0x0036;
-short __wifi_status = 0x003C;
-
-short __sel_gun_btn = 0x0040;
-short __ret_home_btn = 0x0042;
-short __stop_method_btn = 0x0044;
-
-short __qr_code = 0x0250;
-short __main_rfid = 0x0052;
-short __main_qr = 0x0054;
-short __main_app = 0x0056;
-
-short __plug_in_arrow = 0x0060;
-
-short __conn_line = 0x0066;
-
-short __gun_type_index = 0x0070;
-short __qr_code_pre = 0x0280;
-
-short __side_top = 0x0090;
-short __side_down = 0x0092;
-short __side_mid = 0x0094;
-
-short __conn_line_chag = 0x0096;
-short __batt_map = 0x0100;
-short __soc_value_charging = 0x0102;
-short __remain_time_map = 0x0106;
-short __power_map = 0x0108;
-short __energy_map = 0x010A;
-short __remain_time_tx = 0x0110;
-short __output_eng_tx = 0x0120;
-short __total_out_eng_tx = 0x0130;
-short __conn_line_comp = 0x0140;
-short __charging_fee_map = 0x0146;
-short __charging_fee_tx = 0x0150;
-
-short __money_by_rate = 0x0200;
-short __money_rate = 0x0220;
-short __money_rate_map = 0x0230;
-
-// ICON ID
-byte _disappear = 0;
-byte _disconnect = 1;
-byte _connect = 2;
-byte _warning = 3;
-byte _arrow_dark = 4;
-byte _arrow_light = 5;
-byte _3G4G_disconnect = 6;
-byte __3G4G_connect = 7;
-byte _wifi_disconnect = 8;
-byte _wifi_connect = 9;
-byte _logo = 10;
-byte _conn_map1 = 11;
-byte _conn_map2 = 12;
-byte _sel_gun_btn = 13;
-byte _back_home_btn = 14;
-byte _stop_charging_btn = 15;
-byte _stop_charging_btn_scan = 16;
-byte _chademo_dark = 17;
-byte _ccs_dark = 18;
-byte _gbt_dark = 19;
-byte _actype_dark = 20;
-byte _chademo_light = 21;
-byte _ccs_light = 22;
-byte _gbt_light = 23;
-byte _actype_light = 24;
-byte _main_none_rfid = 25;
-byte _main_rfid = 26;
-byte _main_none_app = 27;
-byte _main_app = 28;
-byte _main_none_qr = 29;
-byte _main_qr = 30;
-byte _charging_map1 = 31;
-byte _charging_map2 = 32;
-byte _battery_empty = 33;
-byte _battery_cap_20 = 34;
-byte _battery_cap_40 = 35;
-byte _battery_cap_60 = 36;
-byte _battery_cap_80 = 37;
-byte _battery_cap_100 = 38;
-byte _battery_map = 39;
-byte _power_map = 40;
-byte _time_map = 41;
-byte _complete_map = 42;
-byte _battery_soc_20 = 43;
-byte _battery_soc_40 = 44;
-byte _battery_soc_60 = 45;
-byte _battery_soc_80 = 46;
-byte _battery_soc_100 = 47;
-byte _battery_eng_map = 48;
-byte _money_map = 49;
-byte _elapse_time_map = 50;
-byte _charging_money = 51;
-byte _side_none_rfid = 52;
-byte _side_rfid = 53;
-byte _side_none_app = 54;
-byte _side_app = 55;
-byte _side_none_qr = 56;
-byte _side_qr = 57;
-byte _eth_disconnect = 58;
-byte _eth_connect = 59;

+ 0 - 1526
EVSE/Projects/DD360/Apps/Module_LcmControl.c

@@ -1,1526 +0,0 @@
-#include "ReModule_LcmControl.h"
-#include "Config.h"
-#include "AudiCust.h"
-
-static AudiCustInfo *gAudiCustInfo = NULL;
-bool needReloadQr = true;
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-char *getTimeString(void);
-
-//=================================
-// Common routine
-//=================================
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-char *getTimeString(void)
-{
-    char *result = malloc(21);
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-
-    return result;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //creat ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    //creat Audi customization info
-    if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmget select gun info NG \n");
-        return 0;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmat shmget select gun info \n");
-        return 0;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef ShmPrimaryMcuData
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    return result;
-}
-
-//==========================================
-// Open and Close RS232 and R/W
-//==========================================
-int CreateCommunicationLcmPort()
-{
-    int fd;
-    struct termios tios;
-
-    fd = open(pPortName, O_RDWR);
-    if (fd <= 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("open /dev/ttyS3 NG \n");
-#endif
-        return -1;
-    }
-    ioctl(fd, TCGETS, &tios);
-    tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
-    tios.c_lflag = 0;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char) 5;
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl(fd, TCSETS, &tios);
-
-    return fd;
-}
-
-void CloseCommunicationLcmPort()
-{
-    close(_port);
-}
-
-void WriteCmdToLcm(byte *cmd, byte cmdLen)
-{
-    int len = write(_port, cmd, cmdLen);
-    if (len >= sizeof(cmd)) {
-        //PRINTF_FUNC("Write cmd to LCM successfully. \n");
-    }
-}
-
-void ReadMsgFromLcm(byte *msg, byte readLen)
-{
-    read(_port, msg, readLen);
-
-    if (*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2) {
-        if (*(msg + 3) == CMD_WRITE) {
-            switch (*(msg + 4)) {
-            case CMD_REGISTER: {
-                // 頁面
-                strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
-            }
-            break;
-            }
-        } else if (*(msg + 3) == CMD_MULTI_READ) {
-//          switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
-//          {
-//              case BUTTON_GUN_INDEX:
-//              {
-//                  // 當前選的槍號
-//                  _curGunIndex = (*(msg + 8));
-//              }
-//              break;
-//          }
-        }
-    }
-}
-
-//================================================
-// Function
-//================================================
-void ChangeToOtherPage(short newPage)
-{
-    byte cmd[7];
-    memset(cmd, 0x00, sizeof(cmd));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x02 + sizeof(newPage);
-    cmd[3] = CMD_READ;
-    cmd[4] = CMD_REGISTER;
-    cmd[5] = newPage >> 8;
-    cmd[6] = newPage & 0x00FF;
-
-    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-    usleep(100000);
-}
-
-void ChangeBackLight(bool islight)
-{
-    byte value = 0x01;
-
-    if (islight) {
-        value = 0x20;
-    }
-    byte cmd[7];
-    memset(cmd, 0x00, sizeof(cmd));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03;
-    cmd[3] = CMD_READ;
-    cmd[4] = CMD_BACKLIGHT;
-    cmd[5] = value;
-
-    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-    usleep(100000);
-}
-
-void GetCurrentPage()
-{
-    byte cmd[6];
-    memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
-    memset(msg, 0x00, sizeof(msg));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03;              // 底下總長度
-    cmd[3] = CMD_WRITE;
-    cmd[4] = CMD_REGISTER;
-    cmd[5] = 0x02;
-
-    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-    usleep(100000);
-    ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
-}
-
-void DisplayValueToLcm(short address, byte *data, byte len)
-{
-    byte cmd[256];
-    memset(cmd, 0x00, sizeof(cmd));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03 + len;
-    cmd[3] = CMD_MULTI_WRITE;
-    cmd[4] = address >> 8;
-    cmd[5] = address & 0x00FF;
-
-    for (byte count = 0; count < len; count++) {
-        cmd[6 + count] = *(data + count);
-    }
-
-    WriteCmdToLcm(cmd, cmd[2] + 3);
-}
-
-void ChangeDisplay2Value(short address, short value)
-{
-    byte data[2];
-    data[0] = value >> 8;
-    data[1] = value & 0x00FF;
-
-    DisplayValueToLcm(address, data, sizeof(data));
-}
-
-void GetBtnStatus(short address, byte len)
-{
-    byte cmd[8];
-    memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
-    memset(msg, 0x00, sizeof(msg));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03 + len;
-    cmd[3] = CMD_MULTI_READ;
-    cmd[4] = address >> 8;
-    cmd[5] = address & 0x00FF;
-    cmd[6] = 0x00 + len;
-
-    WriteCmdToLcm(cmd, cmd[2] + 3);
-    usleep(100000);
-    ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
-}
-
-//================================================
-// Warning process
-//================================================
-void string2ByteArray(unsigned char *input, byte *output)
-{
-    int loop;
-    int i;
-
-    loop = 0;
-    i = 0;
-
-    while (input[loop] != '\0') {
-        output[i++] = input[loop++];
-    }
-    output[loop] = '\0';
-}
-
-void ChangeWarningFunc()
-{
-    byte cmd[7];
-    byte i = 0, j = 0;
-    //PRINTF_FUNC("ChangeWarningFunc \n");
-    // 最多一次五筆
-    //PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
-    //PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        memset(cmd, 0x00, sizeof(cmd));
-        if ((i) >= 5) {
-            break;
-        }
-
-        //error code
-        string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
-        DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
-        //警告標示
-        memset(cmd, 0x00, sizeof(cmd));
-
-        cmd[0] = 0x00;
-        cmd[1] = 0x01;
-        DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
-    }
-
-    memset(cmd, 0x00, sizeof(cmd));
-    for (; i < 5; i++) {
-        DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
-        DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
-    }
-#else
-    for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        memset(cmd, 0x00, sizeof(cmd));
-        if ((i - j) >= 5) {
-            break;
-        }
-        if (
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033900", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033901", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033902", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043627", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043628", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043622", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043623", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043624", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043625", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043626", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042241", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042242", 6) == 0)
-        ) {
-            j++;
-            continue;
-        }
-        //error code
-        string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
-        DisplayValueToLcm(0x0010 + ((i - j) * 6), cmd, sizeof(cmd));
-        //警告標示
-        memset(cmd, 0x00, sizeof(cmd));
-
-        cmd[0] = 0x00;
-        cmd[1] = 0x01;
-        DisplayValueToLcm(0x0002 + ((i - j) * 2), cmd, 2);
-    }
-
-    memset(cmd, 0x00, sizeof(cmd));
-    i = i - j;
-    for (; (i) < 5; i++) {
-        DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
-        DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
-    }
-
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-//================================================
-// QR Code process
-//================================================
-void ChangeQrCode_Idle(char *input)
-{
-#if defined DD360Audi
-    int len = strlen(input) + 3;
-    int loop = 0;
-    int i = 0, j = 0, k = 0, l = 0;
-    uint8_t qrUrl[128] = {0};
-    uint16_t urlLen = 0;
-    uint8_t cmd[len];
-    uint8_t tmpBuf[15] = {0};
-    //uint8_t tmpLen = sizeof(tmpBuf) - 1;
-
-    strncpy((char *)cmd, " ", len);
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-        l = loop - 1;
-        if (len >= 25) {
-            if (i >= 16 && i <= 19) {
-                tmpBuf[k++] = input[l];
-                //printf("tmpBuf = %s\r\n", tmpBuf);
-            } else if (i >= 21 && i <= 23) {
-                tmpBuf[k++] = input[l];
-            }
-        }
-    }
-    tmpBuf[k] = '\0';
-    //printf("tmpBuf = %s\r\n", tmpBuf);
-    j += sprintf((char *)&cmd[i], ":%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    cmd[len - 1] = '\0';
-    urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
-    qrUrl[urlLen] = '\0';
-    //printf("qr url = %s\r\n", qrUrl);
-    DisplayValueToLcm(__qr_code, qrUrl, urlLen);
-
-    j = 0;
-    j += sprintf((char *)&tmpBuf[k], "0%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    tmpBuf[k + j] = '\0';
-
-    //if (len < 25) {
-    //    strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-    //}
-    //tmpBuf[tmpLen] = '\0';
-    DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-
-    /*if (len > sizeof(tmpBuf)) {
-        strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-
-        memset(tmpBuf, 0, sizeof(tmpBuf));
-        strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    } else {
-        DisplayValueToLcm(__custStationIdL1, cmd, len);
-
-        strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    }*/
-
-#else
-    int len = strlen(input);
-    byte cmd[len];
-
-    int loop = 0;
-    int i = 0;
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-    }
-
-    DisplayValueToLcm(__qr_code, cmd, len);
-#endif defined DD360Audi
-}
-
-void ChangeQrCode_Charge(char *input)
-{
-#if defined DD360Audi
-    int len = strlen(input) + 3;
-    int loop = 0;
-    int i = 0, j = 0, k = 0, l = 0;
-    uint8_t qrUrl[128] = {0};
-    uint16_t urlLen = 0;
-    uint8_t cmd[len];
-    uint8_t tmpBuf[15] = {0};
-    //uint8_t tmpLen = sizeof(tmpBuf) - 1;
-
-    strncpy((char *)cmd, " ", len);
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-        l = loop - 1;
-        if (len >= 25) {
-            if (i >= 16 && i <= 19) {
-                tmpBuf[k++] = input[l];
-                //printf("tmpBuf = %s\r\n", tmpBuf);
-            } else if (i >= 21 && i <= 23) {
-                tmpBuf[k++] = input[l];
-            }
-        }
-    }
-    tmpBuf[k] = '\0';
-    //printf("tmpBuf = %s\r\n", tmpBuf);
-    j += sprintf((char *)&cmd[i], ":%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    cmd[len - 1] = '\0';
-    urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
-    qrUrl[urlLen] = '\0';
-    DisplayValueToLcm(__qr_code, qrUrl, urlLen);
-
-    j = 0;
-    j += sprintf((char *)&tmpBuf[k], "0%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    tmpBuf[k + j] = '\0';
-
-    if (len < 25) {
-        strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-    }
-    //tmpBuf[tmpLen] = '\0';
-    DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-    /*if (len > sizeof(tmpBuf)) {
-        strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-
-        memset(tmpBuf, 0, sizeof(tmpBuf));
-        strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    } else {
-        DisplayValueToLcm(__custStationIdL1, cmd, len);
-
-        strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    }*/
-
-#else
-    int len = strlen(input);
-    byte cmd[len];
-
-    int loop = 0;
-    int i = 0;
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-    }
-
-    DisplayValueToLcm(__qr_code_pre, cmd, len);
-#endif //defined DD360Audi
-}
-
-//================================================
-// Change current page
-//================================================
-void ChangeCurPage()
-{
-    //PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
-    if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex) {
-        _currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
-        ChangeToOtherPage(_currentPage);
-        _everyPageRollChange = 0;
-    }
-}
-
-//================================================
-// Main process
-//================================================
-byte demoCount = 0;
-void DemoFunction()
-{
-    if (demoCount == 0) {
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount = 6;
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[0][0], "000001", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[1][0], "000002", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[2][0], "000003", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[3][0], "000004", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[4][0], "000005", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[5][0], "000006", 7);
-    } else {
-        if (demoCount == 20) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_SELECT_GUN; //_LCM_IDLE; ////For Audi
-        } else if (demoCount == 80) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZING;
-        } else if (demoCount == 100) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_COMP;
-        } else if (demoCount == 120) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_FAIL;
-        } else if (demoCount == 140) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_PRE_CHARGE;
-        } else if (demoCount == 180) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_CHARGING;
-        }
-    }
-
-    if (demoCount < 180) {
-        demoCount++;
-    }
-}
-
-//================================================
-// Main process
-//================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return true;
-        }
-    }
-
-    return false;
-}
-
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
-{
-    if (target < AC_QUANTITY) {
-        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
-        return true;
-    }
-
-    return false;
-}
-
-/**
- * [ChangeBalanceValue :print balance information]
- * @Author
- * @DateTime 2020-11-26
- */
-static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
-{
-    byte cmd[10] = {0};
-    byte value[10] = {0};
-    uint8_t len = 0;
-    float balance = gAudiCustInfo->PricesInfo[index].Balance;
-
-    if ((balance) == (FAIL_BALANCE_PRICES)) {
-        balance = 0.00;
-    }
-
-    len += sprintf((char *) value, "%.2f", balance);
-    if (len < 6) {
-        sprintf((char *)&value[len], "%s",
-                (byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
-    }
-
-    value[sizeof(value) - 1] = '\0';
-
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(addr, cmd, sizeof(cmd));
-}
-
-void ChangeAcBattMapAndValue(short page)
-{
-    if (page == _LCM_CHARGING) {
-        if (isDiffStatus != _battery_display_ani) {
-            isChangeBattMap = false;
-            isDiffStatus = _battery_display_ani;
-        }
-
-        if (ac_chargingInfo[0]->IsCharging && !isChangeBattMap) {
-            isChangeBattMap = true;
-            if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
-                ChangeDisplay2Value(__batt_map, _battery_empty);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_EMP;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_20);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV1;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_40);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV2;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_60);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV3;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_80);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV4;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_100);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-            }
-        }
-    } else if (page == _LCM_COMPLETE) {
-        if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_20);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_20);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_40);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_60);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_80);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_100);
-        }
-    }
-
-    ChangeDisplay2Value(__soc_value_charging, _disappear);
-}
-
-void ChangeBattMapAndValue(short page, int soc)
-{
-//  srand(time(NULL));
-//  int min = 10;
-//  int max = 90;
-//  soc = rand() % (max - min + 1) + min;
-
-    if (page == _LCM_PRE_CHARGE) {
-        ChangeDisplay2Value(__batt_map_empty, _battery_empty);
-    } else if (page == _LCM_CHARGING) {
-        if (soc < 20) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_empty);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_20);
-            }
-        } else if (soc >= 20 && soc < 40) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_20);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_40);
-            }
-        } else if (soc >= 40 && soc < 60) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_40);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_60);
-            }
-        } else if (soc >= 60 && soc < 80) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_60);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_80);
-            }
-        } else if (soc >= 80 && soc <= 100) {
-            ChangeDisplay2Value(__batt_map, _battery_cap_100);
-        }
-    } else if (page == _LCM_COMPLETE) {
-        if (soc < 20) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_20);
-        } else if (soc >= 20 && soc < 40) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_40);
-        } else if (soc >= 40 && soc < 60) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_60);
-        } else if (soc >= 60 && soc < 80) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_80);
-        } else if (soc >= 80 && soc <= 100) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_100);
-        }
-    }
-
-    byte cmd[5];
-    byte value[5];
-
-    memset(cmd, 0x00, sizeof(cmd));
-    memset(value, 0x00, sizeof(value));
-    sprintf((char *)value, "%d%%", soc);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
-}
-
-void ChangeRemainTime(int sec)
-{
-    int h, m, s;
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-//  srand(time(NULL));
-//  int min = 0;
-//  int max = 65536;
-//  sec = rand() % (max - min + 1) + min;
-
-    h = (sec / 3600);
-    m = (sec - (3600 * h)) / 60;
-    s = (sec - (3600 * h) - (m * 60));
-    sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
-}
-
-void ChangeChargingEnergyValue(float energy)
-{
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-    if (energy >= 0.05) {
-        energy -= 0.05;
-    }
-    sprintf((char *) value, "%.1f kWh", energy);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
-}
-
-void ChangeChargingPowerValue(float pow)
-{
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-//  float min = 0.0;
-//  float max = 50;
-//  pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
-    sprintf((char *) value, "%.1f kW", pow);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
-}
-
-void ChangeChargingFeeValue(float fee)
-{
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-    sprintf((char *) value, "%.2f", fee);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
-}
-
-void DisplayMoneyRate(float money)
-{
-    byte cmd[8];
-    byte value[8];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-    sprintf((char *) value, "%.2f", money);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
-}
-
-void DisplayMoneyCur(byte *cur)
-{
-    byte cmd[10] = {0};
-    byte buf[10] = {0};
-    uint8_t len = 0;
-
-    *(cur + 3) = '\0';
-    memset(cmd, 0x00, sizeof(cmd));
-    len = sprintf((char *) buf, "%s/kWh", cur);
-    buf[len] = '\0';
-    string2ByteArray(buf, cmd);
-    DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
-}
-
-void RefreshPageAnimation(byte value)
-{
-    switch (_currentPage) {
-    case _LCM_IDLE: {
-
-    }
-    break;
-    case _LCM_WAIT_FOR_PLUG: {
-        if (_everyPageRollChange == 0) {
-            ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
-        } else if (_everyPageRollChange == 15) {
-            ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
-        }
-
-        _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
-    }
-    break;
-    case _LCM_PRE_CHARGE:
-    case _LCM_CHARGING:
-    case _LCM_COMPLETE: {
-        if (_currentPage == _LCM_PRE_CHARGE) {
-            if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
-                ChangeDisplay2Value(__conn_line, _conn_map1);
-            } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
-                ChangeDisplay2Value(__conn_line, _conn_map2);
-            }
-        } else if (_currentPage == _LCM_CHARGING) {
-            if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
-                ChangeDisplay2Value(__conn_line_chag, _charging_map1);
-            } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
-                ChangeDisplay2Value(__conn_line_chag, _charging_map2);
-            }
-        } else if (_currentPage == _LCM_COMPLETE) {
-            if (_everyPageRollChange == 0) {
-                ChangeDisplay2Value(__conn_line_comp, _complete_map);
-            }
-        }
-
-        _everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
-    }
-    break;
-    }
-}
-
-void RefreshConnStatus()
-{
-    // Wifi priority is higher than Ethernet
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    uint8_t i = 0;
-    unsigned char flag[4] = {0};
-
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        //printf("status code = %s\r\n", &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
-            flag[0] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043625", 6) == 0) {
-            //disconnected from AP through WiFi
-            flag[1] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043627", 6) == 0) { //wifi disabled
-            flag[1] = 2;
-            continue;
-        }
-
-        if ((memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033900", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033901", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033902", 6) == 0)) {
-            flag[2] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043626", 6) == 0) {
-            //disconnected from APN through 3G/4G
-            flag[3] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043628", 6) == 0) { //4g disabled
-            flag[3] = 2;
-            continue;
-        }
-    }
-
-    if (flag[0] == 1) {
-        ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
-    } else {
-        ChangeDisplay2Value(__ethernet_status, _eth_connect);
-    }
-
-    //ChangeDisplay2Value(__wifi_status, _disappear);
-    //ChangeDisplay2Value(__conn_status, _disappear);
-    //ChangeDisplay2Value(__3G4G_status, _disappear);
-
-    if (flag[1] == 1) {
-        ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
-    } else if (flag[1] == 2) {
-        ChangeDisplay2Value(__wifi_status, _disappear);
-    } else {
-        ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        ChangeDisplay2Value(__wifi_status, _wifi_connect);
-    }
-
-    if (flag[2] == 1) {
-        ChangeDisplay2Value(__conn_status, _disconnect);
-    } else {
-        ChangeDisplay2Value(__conn_status, _connect);
-    }
-
-    if (flag[1] == 2) {
-        ChangeDisplay2Value(__3G4G_status, _disappear);
-        if (flag[3] == 1) {
-            ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
-        } else if (flag[3] == 2) {
-            ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        } else {
-            ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
-        }
-    } else {
-        if (flag[3] == 1) {
-            ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
-        } else if (flag[3] == 2) {
-            ChangeDisplay2Value(__3G4G_status, _disappear);
-        } else {
-            ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
-        }
-    }
-#else
-    if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ||
-            ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP) {
-        _wifi_conn_status = true;
-        ChangeDisplay2Value(__wifi_status, _wifi_connect);
-        ChangeDisplay2Value(__ethernet_status, _disappear);
-    } else {
-        _wifi_conn_status = false;
-        ChangeDisplay2Value(__wifi_status, _disappear);
-    }
-
-    if (!_wifi_conn_status) {
-        if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ||
-                ShmSysConfigAndInfo->SysInfo.InternetConn == YES) {
-            ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
-        } else {
-            ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
-        }
-    }
-
-    // 連線到後台
-    if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES) {
-        ChangeDisplay2Value(__conn_status, _connect);
-    } else {
-        ChangeDisplay2Value(__conn_status, _disconnect);
-    }
-#endif //defined DD360 || defined DD360Audi
-}
-
-byte FirstPageChanged()
-{
-    byte result = NO;
-
-    if (_currentPage != _oldPage) {
-        result = YES;
-        _oldPage = _currentPage;
-    }
-
-    return result;
-}
-
-bool IsPageReloadChk()
-{
-    bool result = false;
-
-    if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
-        if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-            _curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-            result = true;
-        }
-    } else {
-        if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc) {
-            _curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
-            result = true;
-        }
-    }
-
-    return result;
-}
-
-void ProcessPageInfo()
-{
-    _page_reload = IsPageReloadChk();
-
-    switch (_currentPage) {
-#if defined DD360Audi
-    case _LCM_SELECT_GUN: ////For Audi
-        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == 0) {
-            ChangeDisplay2Value(__left_gun_map, _left_gun_enable_map);
-            ChangeDisplay2Value(__right_gun_map, _right_gun_disable_map);
-        } else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == 1) {
-            ChangeDisplay2Value(__left_gun_map, _left_gun_disable_map);
-            ChangeDisplay2Value(__right_gun_map, _right_gun_enable_map);
-        }
-        ChangeDisplay2Value(__add_chk_btn, _select_gun_btn);
-        break;
-#endif //defined DD360Audi
-
-    case _LCM_IDLE: {
-        if (ShmSysConfigAndInfo->SysConfig.isRFID) {
-            ChangeDisplay2Value(__main_rfid, _main_rfid);
-        } else {
-            ChangeDisplay2Value(__main_rfid, _main_none_rfid);
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
-            ChangeDisplay2Value(__main_qr, _main_qr);
-        } else {
-            ChangeDisplay2Value(__qr_code, _disappear);
-            ChangeDisplay2Value(__main_qr, _main_none_qr);
-            needReloadQr = true;
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.isAPP) {
-            ChangeDisplay2Value(__main_app, _main_app);
-        } else {
-            ChangeDisplay2Value(__main_app, _main_none_app);
-        }
-
-        //if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
-        if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
-            needReloadQr = false;
-            ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
-        }
-        //}
-    }
-    break;
-    case _LCM_AUTHORIZING:
-    case _LCM_AUTHORIZ_COMP:
-    case _LCM_AUTHORIZ_FAIL:
-    case _LCM_WAIT_FOR_PLUG: {
-        FirstPageChanged();
-#if defined DD360Audi
-        if (_currentPage == _LCM_AUTHORIZ_COMP) { ////For Audi
-            ChangeBalanceValue(__balance, ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-        }
-#endif //defined DD360Audi
-    }
-    break;
-    case _LCM_PRE_CHARGE:
-    case _LCM_CHARGING:
-    case _LCM_COMPLETE: {
-
-        bool isShowAc = false;
-        if (acgunCount > 0) {
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                isShowAc = true;
-                ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_light);
-
-                if (_currentPage == _LCM_CHARGING) {
-                    ChangeAcBattMapAndValue(_LCM_CHARGING);
-                    if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
-                            ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                    }
-
-                    if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == 0) {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
-                    } else {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
-                    }
-                } else if (_currentPage == _LCM_COMPLETE) {
-                    ChangeAcBattMapAndValue(_LCM_COMPLETE);
-                    if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
-                            ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
-
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
-                                ac_chargingInfo[0]->ChargingFee >= 0) {
-                            ChangeChargingFeeValue(ac_chargingInfo[0]->ChargingFee);
-                        }
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            ChangeChargingFeeValue(0);
-                        }
-                    }
-
-                    if (!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                        ChangeDisplay2Value(__charging_fee_map, _disappear);
-                        ChangeDisplay2Value(__charging_fee_tx, _disappear);
-                    } else {
-                        ChangeDisplay2Value(__charging_fee_map, _money_map);
-                    }
-                }
-            } else {
-                ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_dark);
-            }
-        } else {
-            ChangeDisplay2Value(__gun_type_index + (2 * 2), _disappear);
-        }
-
-        for (byte i = 0; i < _totalCount; i++) {
-            switch (_chargingInfoData[i]->Type) {
-            case _Type_Chademo: {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_light_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
-                    }
-                } else {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_dark_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
-                    }
-                }
-            }
-            break;
-            case _Type_GB: {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_light_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
-                    }
-                } else {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_dark_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
-                    }
-                }
-            }
-            break;
-            case _Type_CCS_2: {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_light_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
-                    }
-                } else {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_dark_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
-                    }
-                }
-            }
-            break;
-            }
-
-            if (_currentPage == _LCM_PRE_CHARGE && !isShowAc) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
-                    ChangeBattMapAndValue(_currentPage, _chargingInfoData[i]->EvBatterySoc);
-                }
-            } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
-                    ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
-                    if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
-                            _chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
-                            _chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-
-                    if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
-                            _chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                    }
-
-                    if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0) {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
-                    } else {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
-                    }
-                }
-            } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
-                    ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
-                    if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
-                            _chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
-                            _chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-#if 1
-                    if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
-                            _chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
-                                _chargingInfoData[i]->ChargingFee >= 0) {
-                            ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
-                            ChangeBalanceValue(__remain_balance, i);
-                        }
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            ChangeChargingFeeValue(0);
-                            ChangeBalanceValue(__remain_balance, i);
-                        }
-                    }
-#else
-                    ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-
-                    if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
-                            _chargingInfoData[i]->ChargingFee >= 0) {
-                        ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
-                        ChangeBalanceValue(__remain_balance, i);
-                    }
-#endif // 0
-                    if (!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                        ChangeDisplay2Value(__charging_fee_map, _disappear);
-                        ChangeDisplay2Value(__charging_fee_tx, _disappear);
-                    } else {
-                        ChangeDisplay2Value(__charging_fee_map, _money_map);
-                    }
-                }
-            }
-        }
-
-        // gun btn and QR code
-        if (_totalCount + acgunCount >= 2 && _currentPage) {
-            byte index = 0;
-            for (index = 0; index < _totalCount; index++) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index) {
-                    break;
-                }
-            }
-
-            if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
-                    _chargingInfoData[index]->SystemStatus == S_RESERVATION ||
-                    _chargingInfoData[index]->SystemStatus == S_BOOTING) {
-                if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
-                    if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
-                        needReloadQr = false;
-                        ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
-                    }
-                }
-            }
-        }
-    }
-    break;
-
-    case _LCM_FIX:
-        if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
-            ChangeDisplay2Value(_emergency_map, _emergency_disable_map);
-        } else {
-            ChangeDisplay2Value(_emergency_map, _disappear);
-        }
-        break;
-    }
-}
-
-void ChangeDisplayMoneyInfo()
-{
-    uint8_t curGun = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-
-    if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-        struct timeb csuTime;
-        struct tm *tmCSU;
-
-        ftime(&csuTime);
-        tmCSU = localtime(&csuTime.time);
-
-        ChangeDisplay2Value(__money_rate_map, _charging_money);
-        if (gAudiCustInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
-            DisplayMoneyRate(gAudiCustInfo->PricesInfo[curGun].UserPrices);
-        } else {
-            if (tmCSU->tm_hour <= 23) {
-                ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
-                DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
-            }
-
-            if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53) {
-                DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
-            }
-        }
-    } else {
-        ChangeDisplay2Value(__money_rate_map, _disappear);
-        ChangeDisplay2Value(__money_by_rate, _disappear);
-        ChangeDisplay2Value(__money_rate, _disappear);
-    }
-}
-
-void Initialization()
-{
-    bool isPass = false;
-    byte count = 5;
-    while (!isPass && count > 0) {
-        isPass = true;
-        for (byte _index = 0; _index < _totalCount; _index++) {
-            if (!FindChargingInfoData(_index, &_chargingInfoData[0])) {
-                DEBUG_ERROR("LcmComm (main) : FindChargingInfoData false \n");
-                isPass = false;
-                count--;
-                break;
-            }
-        }
-
-        sleep(1);
-    }
-
-    isPass = false;
-
-    if (acgunCount > 0) {
-        while (!isPass) {
-            isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
-                if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
-                    DEBUG_ERROR("LcmComm : FindAcChargingInfoData false \n");
-                    isPass = false;
-                    break;
-                }
-            }
-
-            sleep(1);
-        }
-    }
-
-    if (count == 0) {
-        PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
-    }
-}
-
-int main(void)
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    _port = CreateCommunicationLcmPort();
-    byte changeWarningPriority = 0;
-    byte curWarningCount = 255;
-    ChangeBackLight(true);
-    _totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-    acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-    Initialization();
-
-    //ChangeToOtherPage(_LCM_COMPLETE);
-    //return 0;
-
-    for (byte i = 0; i < 3; i++) {
-        ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
-    }
-
-    while (_port != -1) {
-        if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName) != 0x00) {
-            GetCurrentPage();
-            sleep(1);
-        } else {
-            //DemoFunction();
-
-            // Warning 處理
-            if (curWarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount) {
-                changeWarningPriority = 0;
-                ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
-                curWarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-                ChangeWarningFunc();
-            } else if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 5 && changeWarningPriority == 0) {
-                // 當有兩頁 Warning 則每隔三秒改變一次
-                if (ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0) {
-                    ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
-                } else {
-                    ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
-                }
-
-                ChangeWarningFunc();
-            }
-
-            // 頁面資訊處理
-            ProcessPageInfo();
-
-            // 網路 - wifi - 連線訊號處理
-            RefreshConnStatus();
-
-            // 換頁處理
-            ChangeCurPage();
-
-            RefreshPageAnimation(_everyPageRollChange);
-
-            //if (changeWarningPriority == 0) { ////For Audi
-            ChangeDisplayMoneyInfo();
-            //}
-
-            changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
-            changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
-            usleep(100000);
-        }
-    }
-
-    CloseCommunicationLcmPort();
-
-    return FAIL;
-}

+ 0 - 517
EVSE/Projects/DD360/Apps/Module_PrimaryComm.c

@@ -1,517 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "../../define.h"
-#include    "PrimaryComm.h"
-#include    <stdbool.h>
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
-typedef unsigned char       byte;
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-
-void trim(char *s);
-int mystrcmp(char *p1, char *p2);
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt);
-void split(char **arr, char *str, const char *del);
-
-int Uart1Fd;
-char *priPortName = "/dev/ttyS1";
-Ver ver;
-Gpio_in gpio_in;
-Rtc rtc;
-
-struct timeval _flash_time;
-byte flash = NO;
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-unsigned char ChillerSwitch;
-unsigned int ChillerOnTime;
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-//=================================
-// Common routine
-//=================================
-char *getTimeString(void)
-{
-    char *result = malloc(21);
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-
-    return result;
-}
-
-void trim(char *s)
-{
-    int i = 0, j, k, l = 0;
-
-    while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
-        i++;
-    }
-
-    j = strlen(s) - 1;
-    while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
-        j--;
-    }
-
-    if (i == 0 && j == strlen(s) - 1) { }
-    else if (i == 0) { s[j + 1] = '\0'; }
-    else {
-        for (k = i; k <= j; k++) { s[l++] = s[k]; }
-        s[l] = '\0';
-    }
-}
-
-int mystrcmp(char *p1, char *p2)
-{
-    while (*p1 == *p2) {
-        if (*p1 == '\0' || *p2 == '\0') {
-            break;
-        }
-        p1++;
-        p2++;
-    }
-    if (*p1 == '\0' && *p2 == '\0') {
-        return (PASS);
-    } else {
-        return (FAIL);
-    }
-}
-
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
-{
-    strncpy(dest, src + start, cnt);
-    dest[cnt] = 0;
-}
-
-void split(char **arr, char *str, const char *del)
-{
-    char *s = strtok(str, del);
-
-    while (s != NULL) {
-        *arr++ = s;
-        s = strtok(NULL, del);
-    }
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //creat ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef ShmPrimaryMcuData
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    return result;
-}
-
-//================================================
-// Function
-//================================================
-void GetFwAndHwVersion()
-{
-    if (Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) {
-        //PRINTF_FUNC("Primary FW Rev = %s \n", ver.Version_FW);
-        strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
-    }
-
-    if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-        ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
-}
-
-void GetInputGpioStatus()
-{
-    //PRINTF_FUNC("GetInputGpioStatus \n");
-    if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-        ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-#else
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
-        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
-#endif //!defined DD360 && !defined DD360Audi
-
-        ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
-
-        ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
-        ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
-        ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
-        /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
-        ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-        ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-        printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-        printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-        */
-        //PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
-        //PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
-        //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
-            DEBUG_ERROR("AC Mainbreaker occur. \n");
-        }
-#endif //!defined DD360 && !defined DD360Audi
-    }
-}
-
-void SetOutputGpio(byte flash)
-{
-    Gpio_out gpio;
-    gpio.Button_LED[0] = flash;
-    gpio.Button_LED[1] = flash;
-
-    gpio.System_LED[0] = 0x00;
-    gpio.System_LED[1] = 0x00;
-    gpio.System_LED[2] = 0x00;
-    gpio.System_LED[3] = 0x00;
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    if ((ChargingData[0]->PresentChargingCurrent) >= 150) {
-        ChillerSwitch = 1;
-        ChillerOnTime = time((time_t *)NULL);
-    } else {
-        if (ChillerSwitch == 1) {
-            if ((ChargingData[0]->PresentChargingCurrent) >= 100) {
-                ChillerSwitch = 1;
-                ChillerOnTime = time((time_t *)NULL);
-            } else {
-                if ((time((time_t *)NULL) - ChillerOnTime) >= 600) {
-                    ChillerSwitch = 0;
-                } else {
-                    ChillerSwitch = 1;
-                }
-            }
-        } else {
-            ChillerSwitch = 0;
-        }
-    }
-    gpio.AC_Connector = ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
-
-    //printf("ChargingData[0]->PresentChargingCurrent=%f,ChargingData[1]->PresentChargingCurrent=%f,ChillerSwitch=%d\n",ChargingData[0]->PresentChargingCurrent,ChargingData[1]->PresentChargingCurrent,ChillerSwitch);
-#else
-    gpio.AC_Connector = 0x00;
-#endif //defined DD360 || DD360Audi
-
-    gpio.AC_Breaker = 0x00;
-
-    if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS) {
-        //PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
-    } else {
-        //PRINTF_FUNC("SetOutputGpio fail. \n");
-    }
-}
-
-void SetRtcData()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-//  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//          tmCSU->tm_sec);
-
-    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-    if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS) {
-        //PRINTF_FUNC("SetRtc sucessfully. \n");
-    } else {
-        //PRINTF_FUNC("SetRtc fail. \n");
-    }
-}
-
-//================================================
-// Main process
-//================================================
-int InitComPort()
-{
-    int fd;
-    struct termios tios;
-
-    fd = open(priPortName, O_RDWR);
-    if (fd <= 0) {
-#ifdef SystemLogMessage
-        DEBUG_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;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char)1;
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl (fd, TCSETS, &tios);
-
-    return fd;
-}
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-int main(void)
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-        if (!FindChargingInfoData(_index, &ChargingData[0])) {
-            DEBUG_ERROR("FindChargingInfoData false \n");
-            break;
-        }
-    }
-    ChillerSwitch = 0;
-    Uart1Fd = InitComPort();
-    //PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
-
-    if (Uart1Fd < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
-#endif
-
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    SetRtcData();
-    gettimeofday(&_flash_time, NULL);
-    for (;;) {
-        if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
-            if ((GetTimeoutValue(_flash_time) / 1000) > 1000) {
-                if (flash == NO) {
-                    flash = YES;
-                } else {
-                    flash = NO;
-                }
-                SetOutputGpio(flash);
-                gettimeofday(&_flash_time, NULL);
-            }
-        } else {
-            if ((GetTimeoutValue(_flash_time) / 1000) > 5000) {
-                if (flash == NO) {
-                    flash = YES;
-                }
-
-                SetOutputGpio(flash);
-                gettimeofday(&_flash_time, NULL);
-            }
-        }
-
-        // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-        // 模組更新 FW 後,需重新做
-        if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
-            //PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
-            GetFwAndHwVersion();
-            sleep(1);
-            ShmPrimaryMcuData->SelfTest_Comp = PASS;
-        } else {
-            GetInputGpioStatus();
-        }
-
-        usleep(100000);
-    }
-
-    return FAIL;
-}

+ 102 - 113
EVSE/Projects/DD360/Apps/OutputTask.h

@@ -1,7 +1,7 @@
 /*
  * OutputTask.h
  *
- *  Created on: 2020¦~2¤ë25¤é
+ *  Created on: 2020年2月25日
  *      Author: 7564
  */
 
@@ -9,47 +9,47 @@
 #define OUTPUTTASK_H_
 
 
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
+#include    <sys/types.h>
+#include    <sys/ioctl.h>
+#include    <sys/socket.h>
+#include    <sys/ipc.h>
+#include    <sys/shm.h>
+#include    <sys/shm.h>
+#include    <sys/mman.h>
+#include    <linux/wireless.h>
+#include    <linux/can.h>
+#include    <linux/can/raw.h>
+#include    <arpa/inet.h>
+#include    <netinet/in.h>
+
+#include    <unistd.h>
+#include    <stdarg.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 #include    <unistd.h>
 #include    <fcntl.h>
 #include    <termios.h>
 #include    <errno.h>
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include 	<stdbool.h>
-
-#define ShmTestKey	2001
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-#define PRESS				1
-#define RELEASE				0
+#include    <errno.h>
+#include    <string.h>
+#include    <time.h>
+#include    <ctype.h>
+#include    <ifaddrs.h>
+#include    <stdbool.h>
+
+#define ShmTestKey  2001
+
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
+#define PRESS               1
+#define RELEASE             0
 #define MAX_PSU_QUANTITY        62
 
 int Uart1Fd = -1;
@@ -69,106 +69,95 @@ unsigned char isGetCount = NO;
 float VOLTAGE;
 float CURRENT;
 
-struct PsuModuleInfo
-{
-	unsigned int 	PSU_POWER_INFO;
-	float			PSU_VOLTAGE_INFO;
-	unsigned short	PSU_CURRENT_INFO;
+struct PsuModuleInfo {
+    unsigned int    PSU_POWER_INFO;
+    float           PSU_VOLTAGE_INFO;
+    unsigned short  PSU_CURRENT_INFO;
 };
 
-struct UnSafeData
-{
-	unsigned char 			PSU_COUNT;
-	struct PsuModuleInfo 	PsuModule[MAX_PSU_QUANTITY];
-	unsigned int 			PSU_POWER;
-	float					PSU_VOLTAGE;
-	unsigned short			PSU_CURRENT;
+struct UnSafeData {
+    unsigned char           PSU_COUNT;
+    struct PsuModuleInfo    PsuModule[MAX_PSU_QUANTITY];
+    unsigned int            PSU_POWER;
+    float                   PSU_VOLTAGE;
+    unsigned short          PSU_CURRENT;
 };
 
-struct UnSafeData			*UnSafeDataInfo;
+struct UnSafeData           *UnSafeDataInfo;
 
-typedef struct GPIO_IN
-{
-	unsigned char AC_Connector;
-	unsigned char AC_MainBreaker;
-	unsigned char SPD;
-	unsigned char Door_Open;
-	unsigned char GFD[2];
-	unsigned char AC_Drop;
-	unsigned char Emergency_IO;
-
-	unsigned char Emergency_Btn;
-	unsigned char Button[2];
-	unsigned char Key[4];
-}Gpio_in;
+typedef struct GPIO_IN {
+    unsigned char AC_Connector;
+    unsigned char AC_MainBreaker;
+    unsigned char SPD;
+    unsigned char Door_Open;
+    unsigned char GFD[2];
+    unsigned char AC_Drop;
+    unsigned char Emergency_IO;
+
+    unsigned char Emergency_Btn;
+    unsigned char Button[2];
+    unsigned char Key[4];
+} Gpio_in;
 
 Gpio_in gpio_in;
 
-enum CHARGING_MODE
-{
-	CHARGING_MODE_STOP = 			0x00,
-	CHARGING_MODE_START = 			0x01,
-	CHARGING_MODE_TERMINATING = 	0x10,
+enum CHARGING_MODE {
+    CHARGING_MODE_STOP =            0x00,
+    CHARGING_MODE_START =           0x01,
+    CHARGING_MODE_TERMINATING =     0x10,
 };
 
 unsigned char _charging_mode = CHARGING_MODE_STOP;
 
-int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *rx)
 {
-	int len;
-	tcflush(fd,TCIOFLUSH);
-	if(write(fd, cmd, cmd_len) >= cmd_len)
-	{
-		usleep(50000);
-		len = read(fd, rx, 512);
-	}
-	else
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
-		#endif
-	}
-
-	return len;
+    int len;
+    tcflush(fd, TCIOFLUSH);
+    if (write(fd, cmd, cmd_len) >= cmd_len) {
+        usleep(50000);
+        len = read(fd, rx, 512);
+    } else {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+#endif
+    }
+
+    return len;
 }
 
 unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, 0x0a, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 0)
-	{
-		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
-		{
-			chksum ^= rx[6+idx];
-		}
-
-		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
-		   (rx[2] == tx[1]) &&
-		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]))
-		{
-			Ret_Buf->Button[0] 			= (rx[7] >> 1) & 0x01;
-			Ret_Buf->Button[1] 			= (rx[7] >> 2) & 0x01;
-
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, 0x0a, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if (len > 0) {
+        for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
+            chksum ^= rx[6 + idx];
+        }
+
+        if ((chksum == rx[6 + (rx[4] | rx[5] << 8)]) &&
+                (rx[2] == tx[1]) &&
+                (rx[1] == tx[2]) &&
+                (rx[3] == tx[3])) {
+            Ret_Buf->Button[0]          = (rx[7] >> 1) & 0x01;
+            Ret_Buf->Button[1]          = (rx[7] >> 2) & 0x01;
+
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 void GetInputGpioStatus()
 {
-	if (Query_Gpio_Input(Uart1Fd, 0x04, &gpio_in) == PASS)
-	{
-		Button1 = gpio_in.Button[0];
-		Button2 = gpio_in.Button[1];
-	}
+    if (Query_Gpio_Input(Uart1Fd, 0x04, &gpio_in) == PASS) {
+        Button1 = gpio_in.Button[0];
+        Button2 = gpio_in.Button[1];
+    }
 }
 
 #endif /* OUTPUTTASK_H_ */

+ 0 - 76
EVSE/Projects/DD360/Apps/PrimaryComm.h

@@ -1,76 +0,0 @@
-#ifndef PRIMARYCOMM_H_
-#define PRIMARYCOMM_H_
-
-extern struct Address {
-    unsigned char Aux;
-    unsigned char Fan;
-    unsigned char Relay;
-    unsigned char IoExtend;
-    unsigned char Broadcast;
-} Addr;
-
-extern struct Command {
-    unsigned char query_FW_Ver;         //0x01
-    unsigned char query_HW_Ver;     //0x02
-    unsigned char query_Gpio_In;        //0x0a
-    unsigned char query_charging_power; // 0x2C
-
-    unsigned char config_Model_Name;            //0x83
-    unsigned char config_Gpio_Output;   //0x86
-    unsigned char config_Rtc_Data;      //0x87
-
-    unsigned char update_Start;     //0xe0
-    unsigned char update_Abort;     //0xe1
-    unsigned char update_Transfer;      //0xe2
-    unsigned char update_Finish;        //0xe3
-
-} Cmd;
-
-typedef struct Verion {
-    char Version_FW[16];
-    char Version_HW[16];
-} Ver;
-
-typedef struct GPIO_IN {
-    unsigned char AC_Connector;
-    unsigned char AC_MainBreaker;
-    unsigned char SPD;
-    unsigned char Door_Open;
-    unsigned char GFD[2];
-    unsigned char AC_Drop;
-    unsigned char Emergency_IO;
-
-    unsigned char Emergency_Btn;
-    unsigned char Button[2];
-    unsigned char Key[4];
-} Gpio_in;
-
-typedef struct GPIO_OUT {
-    unsigned char Button_LED[2];
-    unsigned char System_LED[4];
-    unsigned char AC_Connector;
-    unsigned char AC_Breaker;
-} Gpio_out;
-
-typedef struct RTC {
-    unsigned char RtcData[14];
-} Rtc;
-
-extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
-
-extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
-extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
-unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
-// 13 bytes
-// year : 4, month : 2, day : 2, hour : 2, min : 2, sec : 2
-//extern unsigned char Config_RTC();
-
-extern unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32);
-extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
-extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
-extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
-
-
-#endif /* PRIMARYCOMM_H_ */

+ 0 - 6608
EVSE/Projects/DD360/Apps/ReMain.c

@@ -1,6608 +0,0 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/timeb.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/mman.h>
-#include <linux/wireless.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdio.h>      /*標準輸入輸出定義*/
-#include <stdlib.h>     /*標準函數庫定義*/
-#include <unistd.h>     /*Unix 標準函數定義*/
-#include <fcntl.h>      /*檔控制定義*/
-#include <termios.h>    /*PPSIX 終端控制定義*/
-#include <errno.h>      /*錯誤號定義*/
-#include <errno.h>
-#include <string.h>
-#include <stdint.h>
-#include <time.h>
-#include <ctype.h>
-#include <ifaddrs.h>
-#include <math.h>
-#include "../../define.h"
-#include "Config.h"
-#include <stdbool.h>
-#include <dirent.h>
-#include "timeout.h"
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-#include "AudiCust.h"
-#endif //defined DD360Audi
-
-#define ARRAY_SIZE(A)                           (sizeof(A) / sizeof(A[0]))
-#define PASS                                    1
-#define FAIL                                    -1
-#define MODELNAME_FAIL                          0
-#define BUFFER_SIZE                             128
-#define YES                                     1
-#define NO                                      0
-#define NORMAL                                  0
-#define ABNORMAL                                1
-#define EQUAL                                   0
-#define BTN_RELEASE                             0
-#define BTN_PRESS                               1
-#define MAX_BUF                                 64
-#define MtdBlockSize                            0x600000
-#define SYSFS_GPIO_DIR                          "/sys/class/gpio"
-#define UPGRADE_FAN                             0x02
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-#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 NO_DEFINE                               255
-#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
-
-typedef struct StLedConfig {
-    //OutputDrvValue[0]
-    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
-    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
-    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
-    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
-    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
-    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
-    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
-    uint8_t Reserved: 1;                        //bit 7 reserved
-} LedConfig;
-
-char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-int whileLoopTime = 10000; // 10 ms
-int wtdFd = -1;
-byte _authorizeIndex = NO_DEFINE;
-
-bool IsAuthorizingMode();
-void ClearAuthorizedFlag();
-bool isDetectPlugin();
-void ClearDetectPluginFlag();
-int mystrcmp(unsigned char *p1, unsigned char *p2);
-
-long long DiffTimebWithNow(struct timeb ST);
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
-void ChargingTerminalProcess(byte gunIndex);
-void ChkPrimaryStatus();
-void StartSystemTimeoutDet(unsigned char flag);
-void StopSystemTimeoutDet();
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
-void StopGunInfoTimeoutDet(unsigned char gunIndex);
-int StoreLogMsg_1(const char *fmt, ...);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-void gpio_set_value(unsigned int gpio, unsigned int value);
-void PRINTF_FUNC(char *string, ...);
-void ChangeGunSelectByIndex(byte sel);
-void InformOcppErrOccur(byte codeType);
-
-void RecordAlarmCode(byte gunIndex, char *code);
-void RecordWarningCode(byte gunIndex, char *code);
-void ReleaseWarningCodeByString(byte gunIndex, char *code);
-void ReleaseAlarmCode(byte gunIndex);
-
-int DB_Open(sqlite3 *db);
-int DB_Insert_Record(sqlite3 *db, int gun_index);
-int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
-int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
-
-#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)
-#define log_error(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PsuData                  *ShmPsuData;
-struct CHAdeMOData              *ShmCHAdeMOData;
-struct GBTData                  *ShmGBTData;
-struct CcsData                  *ShmCcsData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-struct FanModuleData            *ShmFanModuleData;
-struct RelayModuleData          *ShmRelayModuleData;
-struct LedModuleData            *ShmLedModuleData;
-struct OCPP16Data               *ShmOCPP16Data;
-
-struct ChargingInfoData         *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData         *ac_chargingInfo[AC_QUANTITY];
-struct timeb                    startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeb                    endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-static AudiCustInfo             *gAudiCustInfo = NULL; //Jerry add
-#endif //defined DD360Audi
-
-// for initial index to check EV board type is correct
-byte _gunIndex = 0;
-byte _acgunIndex = 0;
-byte _chademoIndex = 0;
-byte _ccsIndex = 0;
-byte _gb_Index = 0;
-byte _ac_Index = 0;
-byte bd0_1_status = 0;
-byte bd0_2_status = 0;
-byte bd1_1_status = 0;
-byte bd1_2_status = 0;
-
-static uint8_t restartFlag = 0;
-
-bool isCardScan = false;
-bool isModelNameMatch = true;
-
-int rfidFd = -1;
-char *rfidPortName = "/dev/ttyS2";
-char *fwVersion = "V1.07.00.0000.00"; // "V0.16.00.0000.00";
-
-sqlite3 *localDb;
-bool isDb_ready;
-
-#if defined DD360Audi
-//------------------------------------------------------------------------------
-//--- share memory value ---
-//------------------------------------------------------------------------------
-static void changeLcmPage(uint8_t index)
-{
-    ShmSysConfigAndInfo->SysInfo.SystemPage = index;
-}
-
-static uint8_t getCurLcmPage(void)
-{
-    return ShmSysConfigAndInfo->SysInfo.SystemPage;
-}
-
-//------------------------------------------------------------------------------
-static void destroySelGun(uint8_t curGun)
-{
-    uint8_t i = 0;
-    uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-
-    //for status timeout
-    if (curGun == DESTROY_ALL_SEL) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
-        log_info("destroy all gun = %d, %d\r\n",
-                 gAudiCustInfo->SelGunInfo.LeftGun,
-                 gAudiCustInfo->SelGunInfo.RightGun);
-        for (i = 0; i < totalGun; i++) {
-            StopGunInfoTimeoutDet(i);
-            memset(&gAudiCustInfo->PricesInfo[i], 0, sizeof(PricesInfo));
-        }
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-        //changeLcmPage(_LCM_SELECT_GUN);
-        return;
-    }
-
-    //for charging timeout or complete
-    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
-        if (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
-                gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
-            changeLcmPage(_LCM_SELECT_GUN);
-        }
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
-        StopGunInfoTimeoutDet(LEFT_GUN_NUM);
-        if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
-            ClearAuthorizedFlag();
-        }
-
-        log_info("destroy left gun, cur page = %d\r\n", getCurLcmPage());
-        if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
-            log_info("clear left balance\r\n");
-            memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
-            gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
-        }
-    }
-
-    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
-        if (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
-                gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
-            changeLcmPage(_LCM_SELECT_GUN);
-        }
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-        StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
-        if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
-            ClearAuthorizedFlag();
-        }
-
-        log_info("destroy right gun, cur page = %d\r\n", getCurLcmPage());
-        if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
-            log_info("clear right balance\r\n");
-            memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
-            gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
-        }
-    }
-}
-
-static int waitRightGunPlugIt(uint8_t curGun)
-{
-    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    }
-
-    return FAIL;
-}
-
-static int waitLeftGunPlugIt(uint8_t curGun)
-{
-    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    }
-
-    return FAIL;
-}
-
-static void setSelGunWaitToAuthor(uint8_t curSel)
-{
-    if (curSel == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
-        //printf("setSelGunWaitToAuthor left\r\n");
-        StopGunInfoTimeoutDet(curSel);
-    } else if (curSel == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
-        //printf("setSelGunWaitToAuthor right\r\n");
-        StopGunInfoTimeoutDet(curSel);
-    }
-}
-
-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))) {
-        return PASS;
-    }
-
-    return FAIL;
-}
-
-static void confirmSelGun(uint8_t selGun)
-{
-    if (selGun == LEFT_GUN_NUM) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
-        StopGunInfoTimeoutDet(selGun);
-        //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
-        StopGunInfoTimeoutDet(selGun);
-        //printf("confirmSelGun right\r\n");
-    }
-
-    changeLcmPage(_LCM_IDLE);
-
-    StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
-}
-#endif // defined DD360Audi
-
-static void startPrimaryLedIndicatorCtrlFork(void)
-{
-    pid_t pid = fork();
-    if (pid == 0) {
-        uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-        uint8_t gunIndex = 0;
-        int isContinue = 1;
-        LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
-
-        while (isContinue) {
-            for (gunIndex = 0; gunIndex < totalGun; gunIndex++) {
-                //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
-                //printf("level = %d\r\n", ShmSysConfigAndInfo->SysWarningInfo.Level);
-                switch (chargingInfo[gunIndex]->SystemStatus) {
-                case S_BOOTING:
-                    if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
-                        //DoComm tcp disconnect
-                        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;
-                        }
-                        break;
-                    }
-
-                    pLedConfig->RedLED = YES;
-                    pLedConfig->YellowLED = YES;
-                    pLedConfig->GreenLED = YES;
-                    break;
-
-                case S_IDLE:
-                    //DoComm connected and system idle
-                    pLedConfig->RedLED = NO;
-                    pLedConfig->YellowLED = NO;
-                    pLedConfig->GreenLED = YES;
-                    break;
-
-                case S_RESERVATION:
-                case S_AUTHORIZING:
-                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:
-                    //precharging status
-                    if (pLedConfig->GreenLED == YES) {
-                        pLedConfig->GreenLED = NO;
-                    } else {
-                        pLedConfig->GreenLED = YES;
-                    }
-                    break;
-
-                case S_CHARGING:
-                    pLedConfig->RedLED = NO;
-                    if (pLedConfig->YellowLED == YES) {
-                        pLedConfig->YellowLED = NO;
-                    } else {
-                        pLedConfig->YellowLED = YES;
-                    }
-                    pLedConfig->GreenLED = NO;
-                    break;
-
-                case S_ALARM:
-                case S_TERMINATING:
-                case S_COMPLETE:
-                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        pLedConfig->YellowLED = NO;
-                        pLedConfig->GreenLED = NO;
-                        if (pLedConfig->RedLED == YES) {
-                            pLedConfig->RedLED = NO;
-                        } else {
-                            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 (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        if (pLedConfig->RedLED == YES) {
-                            pLedConfig->RedLED = NO;
-                        } else {
-                            pLedConfig->RedLED = YES;
-                        }
-                    }
-                    break;
-
-                case S_BOOKING:
-                case S_DEBUG:
-                case S_UPDATE:
-                case S_NONE:
-                    break;
-                }
-
-                usleep(500000);
-            }//switch
-        }//for
-    }//while
-}
-
-//================================================
-// initial can-bus
-//================================================
-int InitCanBus()
-{
-    int                     s0, nbytes;
-    struct timeval          tv;
-    struct ifreq            ifr0;
-    struct sockaddr_can     addr0;
-
-    system("/sbin/ip link set can0 down");
-    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-    system("/sbin/ip link set can0 up");
-
-    s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
-
-    tv.tv_sec = 0;
-    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
-    }
-
-    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;
-    bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
-    return s0;
-}
-
-//================================================
-// initial uart port
-//================================================
-char *_priPortName = "/dev/ttyS1";
-char *_485PortName = "/dev/ttyS5";
-
-int InitComPort(byte target)
-{
-    int fd;
-    struct termios tios;
-
-    if (target == UPGRADE_PRI) {
-        fd = open(_priPortName, O_RDWR);
-    } 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;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char)1;
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl (fd, TCSETS, &tios);
-
-    return fd;
-}
-
-//=================================
-// Common routine
-//=================================
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
-{
-    strncpy(dest, src + start, cnt);
-    dest[cnt] = 0;
-}
-
-int InitWatchDog()
-{
-    int fd;
-    system("/usr/bin/fuser -k /dev/watchdog");
-    sleep(1);
-    system("echo V > /dev/watchdog");
-    sleep(1);
-    fd = open("/dev/watchdog", O_RDWR);
-
-    if (fd <= 0) {
-        log_error("System watch dog initial fail.\r\n");
-    }
-    return fd;
-}
-
-int StoreLogMsg_1(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int mystrcmp(unsigned char *p1, unsigned char *p2)
-{
-    while (*p1 == *p2) {
-        if (*p1 == '\0' || *p2 == '\0') {
-            break;
-        }
-        p1++;
-        p2++;
-    }
-    if (*p1 == '\0' && *p2 == '\0') {
-        return (PASS);
-    } else {
-        return (FAIL);
-    }
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-    return (StopTime - StartTime);
-}
-
-bool CheckTimeOut(struct timeb ST)
-{
-    struct timeb ET;
-    unsigned int StartTime, StopTime;
-
-    ftime(&ET);
-    StartTime = (unsigned int) ST.time;
-    StopTime = (unsigned int) ET.time;
-    return (StopTime > StartTime) ? YES : NO;
-}
-
-void setChargerMode(byte gun_index, byte mode)
-{
-    chargingInfo[gun_index]->SystemStatus = mode;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    log_info("%s \n", buffer);
-}
-
-long long DiffTimebWithNow(struct timeb ST)
-{
-    //return milli-second
-    struct timeb ET;
-    long long StartTime, StopTime;
-
-    ftime(&ET);
-    StartTime = (long long)ST.time;
-    StopTime = (long long)ET.time;
-    return ((StopTime - StartTime) * 1000) + (ET.millitm - ST.millitm);
-}
-
-//==========================================
-// Log
-//==========================================
-void CheckFwSlotStatusLog()
-{
-    if (bd0_1_status == 0 && bd0_2_status == 1) {
-        PRINTF_FUNC("Connector 1 : Chademo");
-    } else if (bd0_1_status == 1 && bd0_2_status == 0) {
-        PRINTF_FUNC("Connector 1 : CCS");
-    } else if (bd0_1_status == 1 && bd0_2_status == 1) {
-        PRINTF_FUNC("Connector 1 : GB");
-    }
-
-    if (bd1_1_status == 0 && bd1_2_status == 1) {
-        PRINTF_FUNC("Connector 2 : Chademo");
-    } else if (bd1_1_status == 1 && bd1_2_status == 0) {
-        PRINTF_FUNC("Connector 2 : CCS");
-    } else if (bd1_1_status == 1 && bd1_2_status == 1) {
-        PRINTF_FUNC("Connector 2 : GB");
-    }
-}
-
-void CheckHwSlotStatusLog(byte index)
-{
-    if (chargingInfo[index]->Type == _Type_Chademo) {
-        PRINTF_FUNC("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
-                    index, chargingInfo[index]->Evboard_id);
-    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-        PRINTF_FUNC("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
-                    index, chargingInfo[index]->Evboard_id);
-    } else if (chargingInfo[index]->Type == _Type_GB) {
-        PRINTF_FUNC("Hw check : Connector %d, Type : GB, Evboard_id = %d \n",
-                    index, chargingInfo[index]->Evboard_id);
-    }
-}
-
-//==========================================
-// Check interface status
-//==========================================
-int isInterfaceUp(const char *interface)
-{
-    int result = FAIL;
-
-    FILE *fp;
-    char cmd[256];
-    char buf[512];
-
-    strcpy(cmd, "ifconfig");
-    fp = popen(cmd, "r");
-    if (fp != NULL) {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            if (strstr(buf, interface) > 0) {
-                result = PASS;
-            }
-        }
-    }
-    pclose(fp);
-
-    return result;
-}
-
-//=================================
-// Create all share memory
-//=================================
-int CreateShareMemory()
-{
-    int MeterSMId = FAIL;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0))  == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-
-    memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
-
-    //creat ShmPsuData
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmPsuData, 0, sizeof(struct PsuData));
-
-    if (CHAdeMO_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),  IPC_CREAT | 0777)) < 0) {
-            return FAIL;
-        } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-            return FAIL;
-        }
-        memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
-    }
-
-    if (GB_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),  IPC_CREAT | 0777)) < 0) {
-            return FAIL;
-        } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-            return FAIL;
-        }
-        memset(ShmGBTData, 0, sizeof(struct GBTData));
-    }
-
-    //creat ShmCcsData
-    if (CCS_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),  IPC_CREAT | 0777)) < 0) {
-            return FAIL;
-        } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-            return FAIL;
-        }
-        memset(ShmCcsData, 0, sizeof(struct CcsData));
-    }
-
-    //creat ShmPrimaryMcuData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
-
-    //creat ShmFanModuleData
-    if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
-
-    //creat ShmRelayModuleData
-    if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
-
-    if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
-
-    //creat ShmOCPP16Data
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    // memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    //creat Audi customization info
-    if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(gAudiCustInfo, 0, sizeof(AudiCustInfo));
-#endif //defined DD360Audi
-
-    return PASS;
-}
-
-//=================================
-// LCM Page
-//=================================
-void ChangeLcmByIndex(byte page_index)
-{
-    if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
-            page_index == _LCM_COMPLETE || page_index == _LCM_FIX) {
-        ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
-    }
-}
-
-//======================================================
-// Peripheral initial
-//======================================================
-void InitGPIO()
-{
-    /*****************0~3, 4 bank, bank x 32+ num*********************/
-    /***************************************************************/
-    /*************** GPIO 0 ***************************************/
-    /***************************************************************/
-    /* GPMC_AD8         =>  GPIO0_22 *//*ID BD1_1*/
-    system("echo 22 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio22/direction");
-    /* GPMC_AD9         =>  GPIO0_23 *//*ID BD1_2*/
-    system("echo 23 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio23/direction");
-    /* GPMC_AD10        =>  GPIO0_26 *//*IO BD1_1*/
-    system("echo 26 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio26/direction");
-    system("echo 1 > /sys/class/gpio/gpio26/value");
-    /* GPMC_AD11        =>  GPIO0_27 *//*IO BD1_2*/
-    system("echo 27 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio27/direction");
-    /* RMII1_REF_CLK        =>  GPIO0_29 *//*USB 0 OCP detection*/
-    system("echo 29 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio29/direction");
-    /*XDMA_EVENT_INTR0  =>  GPIO0_19 *//*AM_RFID_RST*/
-    system("echo 19 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio19/direction");
-    system("echo 1 > /sys/class/gpio/gpio19/value");
-    /*XDMA_EVENT_INTR1  =>  GPIO0_20 *//*AM_RFID_ICC*/
-    system("echo 20 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio20/direction");
-    /***************************************************************/
-    /*************** GPIO 1 ***************************************/
-    /***************************************************************/
-    /* GPMC_AD12    =>  GPIO1_12 *//*ID BD2_1*/
-    system("echo 44 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio44/direction");
-    /* GPMC_AD13    =>  GPIO1_13 *//*ID BD2_2*/
-    system("echo 45 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio45/direction");
-    /* GPMC_AD14    =>  GPIO1_14 *//*IO BD2_1*/
-    system("echo 46 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio46/direction");
-    system("echo 0 > /sys/class/gpio/gpio46/value");
-    /* GPMC_AD15    =>  GPIO1_15 *//*IO BD2_2*/
-    system("echo 47 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio47/direction");
-    /***************************************************************/
-    /*************** GPIO 2 ***************************************/
-    /***************************************************************/
-    /*LCD_AC_BIAS_EN    =>  GPIO2_25*//*RS-485 for module DE control*/
-    system("echo 89 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio89/direction");
-    system("echo 1 > /sys/class/gpio/gpio89/value");
-    /*LCD_HSYNC     =>  GPIO2_23*//*RS-485 for module RE control*/
-    system("echo 87 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio87/direction");
-    system("echo 0 > /sys/class/gpio/gpio87/value");
-    /*LCD_PCLK      =>  GPIO2_24*//*CCS communication board 1 proximity*/
-    system("echo 88 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio88/direction");
-    /*LCD_VSYNC     =>  GPIO2_22*//*CCS communication board 2 proximity*/
-    system("echo 86 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio86/direction");
-    /***************************************************************/
-    /*************** GPIO 3 ***************************************/
-    /***************************************************************/
-    /*MCASP0_FSX        =>  GPIO3_15*//*Emergency Stop button detect*/
-    system("echo 111 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio111/direction");
-    /*MCASP0_ACLKR  =>  GPIO3_18*//*USB1 OCP detect*/
-    system("echo 114 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio114/direction");
-    /*MCASP0_AHCLKR =>  GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
-    system("echo 113 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio113/direction");
-    /*MCASP0_ACLKX  =>  GPIO3_14*//*Ethernet PHY reset*/
-    system("echo 110 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio110/direction");
-    system("echo 0 > /sys/class/gpio/gpio110/value");
-    /* MCASP0_FSR       =>  GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
-    system("echo 115 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio115/direction");
-    system("echo 0 > /sys/class/gpio/gpio115/value");
-    /* MCASP0_AXR0  =>  GPIO3_16 *//*CSU board function OK indicator.*/
-    system("echo 112 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio112/direction");
-    system("echo 1 > /sys/class/gpio/gpio112/value");
-    /* MCASP0_AXR1  =>  GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
-    system("echo 116 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio116/direction");
-    system("echo 0 > /sys/class/gpio/gpio116/value");
-
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    /* (C14) EMU0.gpio3[7] */  /*CP open/short feature enable/disable, pull low for default enable*/
-    system("echo 103 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio103/direction");
-    system("echo 0 > /sys/class/gpio/gpio103/value");
-    /* (B14) EMU1.gpio3[8] */  /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
-    system("echo 104 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio104/direction");
-    system("echo 0 > /sys/class/gpio/gpio104/value");
-#endif //!defined DD360 && !defined DD360Audi
-
-    log_info("Initial GPIO OK");
-}
-
-int LoadSysConfigAndInfo(struct SysConfigData *ptr)
-{
-    int fd, wrd;
-    unsigned char *buf;
-    unsigned int ChkSum, ChkSumOrg;
-
-    if ((buf = malloc(MtdBlockSize)) == NULL) {
-        log_error("malloc buffer NG,rebooting..\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-    memset(buf, 0, MtdBlockSize);
-
-    //================================================
-    // Load configuration from mtdblock10
-    //================================================
-    fd = open("/dev/mtdblock10", O_RDWR);
-    if (fd < 0) {
-        free(buf);
-        log_error("open mtdblock10 NG,rebooting..\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-
-    wrd = read(fd, buf, MtdBlockSize);
-    close(fd);
-    if (wrd < MtdBlockSize) {
-        free(buf);
-        log_error("read SysConfigData data NG,rebooting..\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-    ChkSum = 0;
-    for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
-        ChkSum += buf[wrd];
-    }
-    memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
-
-    //================================================
-    // Load configuration from mtdblock11
-    //================================================
-    if (ChkSum != ChkSumOrg) {
-        log_error("Primary SysConfigData checksum NG, read backup\r\n");
-        fd = open("/dev/mtdblock11", O_RDWR);
-        if (fd < 0) {
-            free(buf);
-            log_error("open mtdblock11 (backup) NG,rebooting..\r\n");
-            if (ShmStatusCodeData != NULL) {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-            }
-            sleep(5);
-            system("reboot -f");
-            sleep(5);
-            system("reboot -f");
-        }
-
-        memset(buf, 0, MtdBlockSize);
-        wrd = read(fd, buf, MtdBlockSize);
-        close(fd);
-        if (wrd < MtdBlockSize) {
-            free(buf);
-            log_error("read backup SysConfigData data NG,rebooting..\r\n");
-            if (ShmStatusCodeData != NULL) {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-            }
-            sleep(5);
-            system("reboot -f");
-            sleep(5);
-            system("reboot -f");
-        }
-        ChkSum = 0;
-        for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
-            ChkSum += buf[wrd];
-        }
-        memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
-
-        //================================================
-        // Load configuration from mtdblock12 (Factory default)
-        //================================================
-        if (ChkSum != ChkSumOrg) {
-            log_error("backup SysConfigData checksum NG, read Factory default\r\n");
-            fd = open("/dev/mtdblock12", O_RDWR);
-            if (fd < 0) {
-                free(buf);
-                log_error("open mtdblock12 (Factory default) NG,rebooting..\r\n");
-                if (ShmStatusCodeData != NULL) {
-                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-                }
-                sleep(5);
-                system("reboot -f");
-                sleep(5);
-                system("reboot -f");
-            }
-            memset(buf, 0, MtdBlockSize);
-            wrd = read(fd, buf, MtdBlockSize);
-            close(fd);
-            if (wrd < MtdBlockSize) {
-                free(buf);
-                log_error("read factory default  SysConfigData data NG,rebooting..\r\n");
-                if (ShmStatusCodeData != NULL) {
-                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-                }
-                sleep(5);
-                system("reboot -f");
-                sleep(5);
-                system("reboot -f");
-            }
-            ChkSum = 0;
-            for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
-                ChkSum += buf[wrd];
-            }
-            memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
-            if (ChkSum != ChkSumOrg) {
-                log_error("factory default  SysConfigData checksum NG, restore factory default\r\n");
-                free(buf);
-                system("cd /root;./FactoryConfig -m");
-                system("sync");
-                sleep(5);
-                system("reboot -f");
-                sleep(5);
-                system("reboot -f");
-
-                return FAIL;
-            }
-        }
-    }
-
-    //load OK
-    memcpy((struct SysConfigData *)ptr, buf, sizeof(struct SysConfigData));
-    free(buf);
-    //log_info("Load SysConfigData OK\n");
-    return PASS;
-}
-
-int isRouteFail()
-{
-    int result = YES;
-    FILE *fp;
-    char buf[512];
-
-    fp = popen("route -n", "r");
-    if (fp != NULL) {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            if (strstr(buf, "eth0") != NULL) {
-                result = NO;
-            }
-        }
-    }
-    pclose(fp);
-
-    return result;
-}
-
-int isReachableInternet()
-{
-    int result = FAIL;
-    FILE *fp;
-    char cmd[256];
-    char buf[512];
-    char tmp[512];
-
-    strcpy(cmd, "ifconfig eth0");
-    fp = popen(cmd, "r");
-
-    if (fp != NULL) {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            if (strstr(buf, "inet addr:") > 0) {
-                sscanf(buf, "%*s%s", tmp);
-                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
-
-                if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL) {
-                    strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
-                }
-            }
-        }
-    }
-    pclose(fp);
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == NORMAL) {
-        result = FAIL;
-    } else {
-        result = PASS;
-    }
-#else
-    memset(buf, 0x00, sizeof(buf));
-    for (int 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) {
-            while (fgets(buf, sizeof(buf), fp) != NULL) {
-                if (strstr(buf, "transmitted") > 0) {
-                    //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
-
-                    if (strstr(buf, "100%") != NULL) {
-                    } else {
-                        result = PASS;
-                    }
-                    //DEBUG_INFO("%s",buf);
-                    //DEBUG_INFO("%s\n",tmp);
-                }
-            }
-        }
-        pclose(fp);
-    }
-
-#endif //defined DD360 || defined DD360Audi
-
-    return result;
-}
-
-void InitEthernet()
-{
-    char tmpbuf[256];
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    bool ethResult = false;
-    uint8_t cnt_pingDNS_Fail = 0;
-#endif //!defined DD360 && !defined DD360Audi
-
-    system("ifconfig eth0 down");// eth0 down
-    system("ifconfig eth1 down");// eth1 down
-    sleep(2);
-
-    // /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",
-            ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-            ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
-    //sprintf(tmpbuf,"/sbin/ifconfig eth0 192.168.100.10 netmask 255.255.255.0 up");
-    system(tmpbuf);
-
-    memset(tmpbuf, 0, 256);
-    sprintf(tmpbuf, "route add default gw %s eth0 ",
-            ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-    //sprintf(tmpbuf,"route add default gw 192.168.100.1 eth0 ");
-    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",
-            ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
-            ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
-    system(tmpbuf);
-
-    //Run DHCP client if enabled
-    system("killall udhcpc");
-    system("rm -rf /etc/resolv.conf");
-    system("echo nameserver 8.8.8.8 > /etc/resolv.conf");       //Google DNS server
-    system("echo nameserver 180.76.76.76 > /etc/resolv.conf");  //Baidu DNS server
-    //system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
-
-    if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
-        sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
-        system(tmpbuf);
-    }
-
-    //Upgrade system id to /etc/hostname
-    sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
-    system(tmpbuf);
-
-    pid_t pid = fork();
-    if (pid == 0) {
-        log_info("InitEthernet = %d\r\n", pid);
-        for (;;) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-            if (isRouteFail()) {
-                //PRINTF_FUNC("eth0 not in route, restart eht0. \n");
-                system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
-
-                if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
-                    InitialDHCP();
-                }
-            }
-
-            if (isReachableInternet() == PASS) {
-                ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
-                cnt_pingDNS_Fail = 0;
-            } else {
-                if (++cnt_pingDNS_Fail > 3) {
-                    ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
-                }
-            }
-
-            ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
-
-            if (ethResult == YES) {
-                system("/sbin/ifmetric eth0 0");
-
-                if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
-                        (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                    system("/sbin/ifmetric mlan0 1");
-                }
-
-                if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
-                        (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                    system("/sbin/ifmetric ppp0 2");
-                }
-            }
-
-            if (!ethResult &&
-                    ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
-                    (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' ||
-                     ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                //ethResult = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn;
-                ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
-
-                if (ethResult) {
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric eth0 1");
-                        system("/sbin/ifmetric mlan0 0");
-                    }
-
-
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric ppp0 2");
-                    }
-                }
-            }
-
-            if (!ethResult &&
-                    ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
-                    (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' ||
-                     ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                //ethResult = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn;
-                ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
-
-                if (ethResult) {
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric mlan0 2");
-                    }
-
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric eth0 1");
-                        system("/sbin/ifmetric ppp0 0");
-                    }
-                }
-            }
-
-            ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
-#else
-            isReachableInternet();
-#endif //!defined DD360 && !defined DD360
-
-            sleep(5);
-        }
-    }
-
-    log_info("Initial Ethernet OK\r\n");
-}
-
-int InitialRfidPort()
-{
-    int uartO2 = open(rfidPortName, O_RDWR);
-    struct termios tios;
-
-    if (uartO2 != FAIL) {
-        ioctl (uartO2, TCGETS, &tios);
-        tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
-        tios.c_lflag = 0;
-        tios.c_iflag = 0;
-        tios.c_oflag = 0;
-        tios.c_cc[VMIN] = 0;
-        tios.c_cc[VTIME] = (unsigned char) 1;
-        tios.c_lflag = 0;
-        tcflush(uartO2, TCIFLUSH);
-        ioctl(uartO2, TCSETS, &tios);
-    }
-
-    if (uartO2 < 0) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
-    }
-
-    return uartO2;
-}
-
-void GetMacAddress()
-{
-    for (byte index = 0; index < 2; index++) {
-        int fd;
-        struct ifreq ifr;
-        char tarEth[5];
-        char Mac[18];
-
-        sprintf(tarEth, "eth%d", index);
-        fd = socket(AF_INET, SOCK_DGRAM, 0);
-
-        ifr.ifr_addr.sa_family = AF_INET;
-        strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
-
-        ioctl(fd, SIOCGIFHWADDR, &ifr);
-        close(fd);
-
-        sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
-                ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
-                ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
-
-        if (index == 0) {
-            strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
-        } else {
-            strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
-        }
-    }
-}
-
-void GetFirmwareVersion()
-{
-    // Get CSU root file system version
-    sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
-
-    byte count = 0, chademo = 0, ccs = 0, gb = 0;
-    for (uint8_t idx = 0; idx < 3; idx++) {
-        if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'J') {
-            chademo++;
-            count++;
-        } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'G') {
-            gb++;
-            count++;
-        } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'U' ||
-                   ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'V' ||
-                   ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'E') {
-            ccs++;
-            count++;
-        }
-    }
-
-    if (count == 1) {
-        if (chademo > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
-        } else if (ccs > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
-        } else if (gb > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
-        }
-    } else {
-        if (chademo > 0 && ccs > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
-        } else if (chademo > 0 && gb > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
-        } else if (ccs > 0 && gb > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
-        }
-    }
-
-    // Get network option from model name
-    switch (ShmSysConfigAndInfo->SysConfig.ModelName[10]) {
-    case 'B':
-    case 'U':
-        //Blue tooth
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
-        break;
-    case 'W':
-        // WIFI
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
-        break;
-    case 'T':
-        // 3G/4G
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
-        break;
-    case 'D': //DS60-120 add
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
-        break;
-    default:
-        // LAN
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
-        break;
-    }
-    // Get rating power from model name
-    memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
-
-    // Get IEC or UL
-    char _buf[3] = {0};
-    memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
-
-    if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
-        ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
-        log_info("IEC model");
-    } else if (strcmp(_buf, "WU") == EQUAL) {
-        ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
-        log_info("UL model");
-    }
-}
-
-//DS60-120 add
-void InitialGunIndexToUnUse()
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
-    }
-
-    for (byte index = 0; index < AC_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index = NO_DEFINE;
-    }
-}
-
-void InitialShareMemoryInfo()
-{
-    FILE *fp;
-    char cmd[512];
-    char buf[512];
-
-    sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
-    sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
-    sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
-
-    ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
-    ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
-
-    ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
-    ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
-    ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
-    ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
-    ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
-    ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
-
-    sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
-    memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
-
-    sprintf(cmd, "/bin/uname -r");
-    fp = popen(cmd, "r");
-    if (fp == NULL) {
-        sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
-    } else {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            strcpy((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
-        }
-    }
-
-    // 雙槍 CCS + Chademo
-    GetFirmwareVersion();
-    //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
-
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
-    ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
-    ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
-    ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-
-    strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
-
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = NO; //DS60-120 Add
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = NO; //DS60-120 Add
-    ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = NO; //DS60-120 add
-
-    memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
-    memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
-    ShmPrimaryMcuData->SelfTest_Comp = NO;
-    ShmRelayModuleData->SelfTest_Comp = NO;
-    ShmFanModuleData->SelfTest_Comp = NO;
-    ShmLedModuleData->SelfTest_Comp = NO;
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
-    ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOTTING; //DS60-120 add
-
-    ShmFanModuleData->TestFanSpeed = 0;
-
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
-
-    //--- DS60-120 remove -----
-    /*char EvsePower[2];
-
-    EvsePower[2] = '\0';
-    unsigned short buf_pow = 0;
-    if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6) {
-        strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
-        if (strcmp(EvsePower, "15") == EQUAL) {
-            buf_pow = 150;
-        } else if (strcmp(EvsePower, "30") == EQUAL) {
-            buf_pow = 30;
-        } else if (strcmp(EvsePower, "60") == EQUAL) {
-            buf_pow = 60;
-        } else if (strcmp(EvsePower, "12") == EQUAL) {
-            buf_pow = 120;
-        } else if (strcmp(EvsePower, "18") == EQUAL) {
-            buf_pow = 180;
-        } else if (strcmp(EvsePower, "36") == EQUAL) {
-            buf_pow = 360;
-        }
-
-        ShmSysConfigAndInfo->SysConfig.RatingCurrent = (buf_pow / 30) * PSU_MIN_CUR;
-
-        if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower == 0 ||
-                ShmSysConfigAndInfo->SysConfig.MaxChargingPower > buf_pow) {
-            ShmSysConfigAndInfo->SysConfig.MaxChargingPower = buf_pow;
-        }
-    }
-    */
-    //--------------------------------------------------------------------------
-
-    InitialGunIndexToUnUse();//DS60-120 add
-
-    ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
-    ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
-
-    log_info("3InitialShareMemoryInfo done...\r\n");
-}
-
-int Initialization()
-{
-    // 初始化卡號驗證的 Flag
-    ClearAuthorizedFlag();
-    // 初始化插槍驗證的 Flag
-    ClearDetectPluginFlag();
-
-    // UART 2 for Rfid
-    rfidFd = InitialRfidPort();
-
-    int pinOut[2] = { 116, 115 };
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
-        chargingInfo[count]->RemoteStartFlag = NO;
-
-        if (chargingInfo[count]->Type == _Type_Chademo) {
-            gpio_set_value(pinOut[count], 0x00);
-            ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-        } else if (chargingInfo[count]->Type == _Type_GB) {
-            gpio_set_value(pinOut[count], 0x00);
-            ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-        } else if (chargingInfo[count]->Type == _Type_CCS_2) {
-            //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
-            if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                gpio_set_value(pinOut[1], 0x01);
-            } else {
-                gpio_set_value(pinOut[count], 0x01);
-            }
-            ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-            //}
-        }
-
-        strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
-    }
-
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
-        ac_chargingInfo[count]->RemoteStartFlag = NO;
-
-        if (ac_chargingInfo[count]->Type == _Type_AC) {
-            ac_chargingInfo[count]->SelfTest_Comp = NO;
-            strcpy((char *)ShmOCPP16Data->StatusNotification[count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount].ErrorCode, "NoError");
-        }
-    }
-
-    //PRINTF_FUNC("Initialization OK \n");
-    return PASS;
-}
-
-bool InitialSystemDefaultConfig()
-{
-    bool result = true;
-
-    LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
-    InitGPIO();
-    InitEthernet();
-    GetMacAddress();
-
-//  system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
-//  sleep(3);
-//  system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
-//  sleep(1);
-//  system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
-
-    return result;
-}
-
-bool DisplaySelfTestFailReason()
-{
-    bool result = false;
-
-    // RB、FB、407、EV 小板中有些板子無回應
-    if (ShmRelayModuleData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = true; }
-    if (ShmFanModuleData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = true; }
-    if (ShmPrimaryMcuData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = true; }
-    if (ShmLedModuleData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = true; }
-    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-        if (chargingInfo[index]->Type == _Type_Chademo) {
-            if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-            { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = true; }
-        } else if (chargingInfo[index]->Type == _Type_GB) {
-            if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-            { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = true; }
-        } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-            if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-                { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = true; }
-            }
-        }
-    }
-    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
-        // 先借 GBT 顯示
-        if (ac_chargingInfo[index]->SelfTest_Comp == NO)
-        { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = true; }
-    }
-
-    if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        // AC Contact 未搭上
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = true;
-        result = true;
-#endif //!defined DD360 && !defined DD360Audi
-    }
-#if 0
-    else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES) { //DS60-120 add
-        result = true;
-    }
-#endif //0
-    else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0) {
-        // PSU 通訊問題
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = true;
-        result = true;
-    }
-
-    return result;
-}
-
-void SelfTestRun()
-{
-    bool evInitFlag = false;
-
-    StartSystemTimeoutDet(Timeout_SelftestChk);
-    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
-
-    while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE //||
-            //GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL <= 20 //DS60-120 add
-          ) {
-        if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
-            return;
-        }
-
-        ChkPrimaryStatus();
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 //||
-                //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES //DS60-120 add
-           ) {
-            ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-            return;
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) {
-            if (ShmPsuData->Work_Step == _NO_WORKING ||
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL) {
-                ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-                return;
-            }
-
-            switch (ShmSysConfigAndInfo->SysInfo.SelfTestSeq) {
-            case _STEST_VERSION: {
-                if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
-                        ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
-                        && (ShmRelayModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Relay Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
-                    ShmRelayModuleData->SelfTest_Comp = YES;
-                }
-#if !defined NO_FAN_BOARD && !defined DD360ComBox
-                if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
-                        ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
-                        && (ShmFanModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Fan Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.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", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
-                    ShmPrimaryMcuData->SelfTest_Comp = YES;
-                }
-#if 0 //DS60-120 remove
-                if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev) != 0 ||
-                        ShmSysConfigAndInfo->SysInfo.LedModuleFwRev[0] != '\0')
-                        && (ShmLedModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("LED Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
-                    ShmLedModuleData->SelfTest_Comp = YES;
-                }
-#endif //0
-
-                // EV 小板
-                if (!evInitFlag) {
-                    evInitFlag = YES;
-                    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                        //log_info("index = %d, charging index = %d, type = %d\r\n",
-                        //         index,
-                        //         chargingInfo[index]->type_index,
-                        //         chargingInfo[index]->Type);
-                        if (chargingInfo[index]->Type == _Type_Chademo) {
-                            if ((strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
-                                    ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
-                                    //&& (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
-                               ) {
-                                log_info("CHAdeMO[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-                                ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
-                            } else {
-                                //PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-                                evInitFlag = NO;
-                            }
-                        } else if (chargingInfo[index]->Type == _Type_GB) {
-                            if ((strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
-                                    ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
-                                    //&& (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
-                               ) {
-                                log_info("GBT[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmGBTData->evse[chargingInfo[index]->type_index].version);
-                                ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
-                            } else {
-                                //PRINTF_FUNC("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-                                evInitFlag = NO;
-                            }
-                        } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-                            if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                                if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
-                                        ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
-                                        /*&&(ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp != YES)*/
-                                   ) {
-                                    log_info("CCS[%d] FW Rev = %s",
-                                             chargingInfo[index]->type_index,
-                                             ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
-                                    ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->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 (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
-                        if (ac_chargingInfo[index]->Type == _Type_AC) {
-                            if ((strlen((char *)ac_chargingInfo[index]->version) != 0 || ac_chargingInfo[index]->version[0] != '\0')
-                                    && (ac_chargingInfo[index]->SelfTest_Comp != YES)
-                               ) {
-                                log_info("AC connector[%d] FW Rev = %s", index, ac_chargingInfo[index]->version);
-                                ac_chargingInfo[index]->SelfTest_Comp = YES;
-                            } else {
-                                evInitFlag = NO;
-                            }
-                        }
-                    }
-                }
-
-                if ( ShmFanModuleData->SelfTest_Comp &&
-                        ShmRelayModuleData->SelfTest_Comp &&
-                        ShmPrimaryMcuData->SelfTest_Comp &&
-                        //ShmLedModuleData->SelfTest_Comp &&
-                        evInitFlag
-                   ) {
-                    ShmSysConfigAndInfo->SysInfo.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 (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES) {
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
-                    log_info("AC contactor self test OK");
-                }
-#else
-                ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
-                log_info("Waiting for DO communication");
-#endif //!defined DD360 && !defined DD360Audi
-            }
-            break;
-            case _STEST_PSU_DETECT: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
-                }
-#else
-                ShmSysConfigAndInfo->SysInfo.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);
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
-                    ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
-                }
-#else
-                //check the power limit from DO
-                ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
-                ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
-                log_info("Successful Self Test");
-#endif //defined DD360 && !defined DD360Audi
-            }
-            break;
-            }
-        } else {
-            break;
-        }
-
-        usleep(100000);
-    }
-}
-
-int SpawnTask()
-{
-    sleep(2);
-    system("/root/Module_EventLogging &");
-    system("/root/Module_PrimaryComm &");
-    system("/root/Module_EvComm &");
-    system("/root/Module_LcmControl &");
-    system("/root/Module_InternalComm &");
-    system("/root/Module_ProduceUtils &");
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    system("/root/DoComm &");
-#else
-    system("/root/Module_PsuComm &");
-
-    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
-        system("/root/OcppBackend &");
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
-        system("/root/Module_4g &");
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
-        system("/root/Module_Wifi &");
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') {
-        system("/root/Module_4g &");
-        system("/root/Module_Wifi &");
-    }
-#endif //defined DD360 || defined DD360Audi
-
-    return PASS;
-}
-
-int StoreUsrConfigData(struct SysConfigData *UsrData)
-{
-    int result = PASS;
-    int fd, wrd;
-    unsigned int i, Chk;
-    unsigned char *ptr, *BufTmp;
-
-    Chk = 0;
-    ptr = (unsigned char *)UsrData;
-    if ((BufTmp = malloc(MtdBlockSize)) != NULL) {
-        memset(BufTmp, 0, MtdBlockSize);
-        memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
-        for (i = 0; i < MtdBlockSize - 4; i++) {
-            Chk += *(ptr + i);
-        }
-
-        memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
-        fd = open("/dev/mtdblock10", O_RDWR);
-        if (fd > 0) {
-            wrd = write(fd, BufTmp, MtdBlockSize);
-            close(fd);
-            if (wrd >= MtdBlockSize) {
-                fd = open("/dev/mtdblock11", O_RDWR);
-                if (fd > 0) {
-                    wrd = write(fd, BufTmp, MtdBlockSize);
-                    close(fd);
-                    if (wrd < MtdBlockSize) {
-                        log_error("write /dev/mtdblock11(backup) NG\r\n");
-                        result = FAIL;
-                    }
-                } else {
-                    log_error("open /dev/mtdblock11(backup) NG\r\n");
-                    result = FAIL;
-                }
-            } else {
-                log_error("write /dev/mtdblock10 NG\r\n");
-                result = FAIL;
-            }
-
-        } else {
-            log_error("open /dev/mtdblock10 NG\r\n");
-            result = FAIL;
-        }
-    } else {
-        log_error("alloc BlockSize NG\r\n");
-        result = FAIL;
-    }
-
-    if (BufTmp != NULL) {
-        free(BufTmp);
-    }
-
-    return result;
-}
-
-//===============================================
-// Common Detect Chk - Stop Charging ?
-//===============================================
-int isEvBoardStopChargeFlag(byte gunIndex)
-{
-    //printf("StopChargeFlag = %d\r\n", chargingInfo[gunIndex]->StopChargeFlag);
-    return chargingInfo[gunIndex]->StopChargeFlag;
-}
-
-bool isEvBoardNormalStopChargeFlag(byte gunIndex)
-{
-    return chargingInfo[gunIndex]->NormalStopChargeFlag;
-}
-
-//===============================================
-// 掃描插槍狀況
-//===============================================
-void ClearDetectPluginFlag()
-{
-    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-
-    //DS60-120 add
-    for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-        if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
-            chargingInfo[gun_index]->RemoteStartFlag = NO;
-        }
-    }
-
-    if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
-        ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-    }
-}
-
-void DetectPluginStart()
-{
-    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
-}
-
-bool isDetectPlugin()
-{
-    if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
-        return YES;
-    }
-
-    return NO;
-}
-
-//===============================================
-// Common Detect Chk - Chademo
-//===============================================
-bool isEvGunLocked_chademo(byte gunIndex)
-{
-    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
-}
-
-bool isEvContactorWelding_chademo(byte gunIndex)
-{
-    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
-}
-
-bool isEvStopReq_chademo(byte gunIndex)
-{
-    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
-}
-
-bool isEvStopCharging_chademo(byte gunIndex)
-{
-    if (isEvGunLocked_chademo(gunIndex) == NO) {
-        // 無鎖槍 = 停止
-        PRINTF_FUNC("gun locked none (%d) \n", gunIndex);
-        return YES;
-    }
-
-    return NO;
-}
-
-byte isPrechargeStatus_chademo(byte gunIndex)
-{
-    byte result = 0x00;
-
-    result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-
-    return result;
-}
-//===============================================
-// Common Detect Chk - GB
-//===============================================
-bool isEvGunLocked_gb(byte gunIndex)
-{
-    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
-}
-
-bool isEvStopCharging_gb(byte gunIndex)
-{
-    if (isEvGunLocked_gb(gunIndex) == NO) {
-        // 無鎖槍 = 停止
-        PRINTF_FUNC("gun locked none. \n");
-        return YES;
-    }
-
-    return NO;
-}
-
-byte isPrechargeStatus_gb(byte gunIndex)
-{
-    byte result = 0x00;
-
-    result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-
-    return result;
-}
-
-//===============================================
-// Common Detect Chk - CCS
-//===============================================
-bool isEvGunLocked_ccs(byte gunIndex)
-{
-    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
-}
-
-byte isPrechargeStatus_ccs(byte gunIndex)
-{
-    byte result = 0x00;
-
-    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-        result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-    }
-
-    return result;
-}
-
-bool isEvStopCharging_ccs(byte gunIndex)
-{
-    if (isEvGunLocked_ccs(gunIndex) == NO) {
-        // 無鎖槍 = 停止
-        PRINTF_FUNC("gun locked none. \n");
-        return YES;
-    }
-
-    return NO;
-}
-
-//===============================================
-// Callback
-//===============================================
-void DisplayChargingInfo()
-{
-    PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
-    for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-        if (chargingInfo[i]->SystemStatus != S_IDLE &&
-                chargingInfo[i]->SystemStatus != S_RESERVATION) {
-            ChangeGunSelectByIndex(i);
-            return;
-        }
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
-            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
-            ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE) {
-        ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-    }
-
-    usleep(50000);
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-}
-
-void _AutoReturnTimeout()
-{
-    PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
-    if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
-        ClearDetectPluginFlag();
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
-        DetectPluginStart();
-    }
-    usleep(50000);
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-}
-
-void _SelfTestTimeout()
-{
-    if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE) {
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_ALARM);
-        }
-    }
-    ShmPsuData->Work_Step = _NO_WORKING;
-    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-    PRINTF_FUNC("Self test timeout. \n");
-}
-
-void _AuthorizedTimeout()
-{
-    if (IsAuthorizingMode()) {
-        PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
-        isCardScan = false;
-        //gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0; //Jerry add
-        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
-        //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
-        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-        ClearAuthorizedFlag();
-    }
-}
-
-void _DetectPlugInTimeout()
-{
-    PRINTF_FUNC("*********** _DetectPlugInTimeout *********** \n");
-    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-    ClearDetectPluginFlag();
-    //usleep(50000);
-    sleep(1); //Jerry add
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-}
-
-void _DetectEvChargingEnableTimeout(byte gunIndex)
-{
-    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-        if (!isEvGunLocked_chademo(gunIndex)) {
-            PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
-        if (!isEvGunLocked_ccs(gunIndex)) {
-            PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-        if (!isEvGunLocked_ccs(gunIndex)) {
-            PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
-        }
-    }
-    ChargingTerminalProcess(gunIndex);
-    _AutoReturnTimeout();
-}
-
-void _DetectEvseChargingEnableTimeout(byte gunIndex)
-{
-    PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
-    //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
-    {
-        setChargerMode(gunIndex, MODE_IDLE);
-        _AutoReturnTimeout();
-    }
-}
-
-void _PrepareTimeout(byte gunIndex)
-{
-    PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
-    _AutoReturnTimeout();
-}
-
-void _CcsPrechargeTimeout(byte gunIndex)
-{
-    PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
-}
-
-//===============================================
-// 取得卡號與卡號驗證
-//===============================================
-bool canStartCharging()
-{
-    char buf2[16] = "";
-    memset(buf2, 0, ARRAY_SIZE(buf2));
-
-    for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
-        sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
-    }
-    sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
-    // 因為無法得知實際的長度,所以只能用搜尋的方式
-    if (strcmp(buf2, "Accepted") == EQUAL) {
-        return true;
-    } else {
-
-    }
-
-    return false;
-}
-
-void AuthorizingStart()
-{
-    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
-    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
-}
-
-void ClearAuthorizedFlag()
-{
-    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
-    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
-}
-
-bool isAuthorizedComplete()
-{
-    if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == YES) {
-        return false;
-    }
-    return true;
-}
-
-bool IsAuthorizingMode()
-{
-    if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO) {
-        return false;
-    }
-
-    return true;
-}
-
-//===============================================
-// 紀錄 Alarm Code
-//===============================================
-void RecordAlarmCode(byte gunIndex, char *code)
-{
-    memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
-
-    if (strcmp(code, "012234") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES; }
-    if (strcmp(code, "012235") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES; }
-    if (strcmp(code, "012236") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES; }
-    if (strcmp(code, "012288") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES; }
-    if (strcmp(code, "012289") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES; }
-    if (strcmp(code, "012290") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES; }
-}
-
-void RecordWarningCode(byte gunIndex, char *code)
-{
-    memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, code, 6);
-
-    if (strcmp(code, "012296") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES; }
-    if (strcmp(code, "012297") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES; }
-    if (strcmp(code, "012298") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES; }
-}
-
-void ReleaseAlarmCode(byte gunIndex)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL &&
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES) {
-            memcpy(code, "012234", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL &&
-                   ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES) {
-            memcpy(code, "012289", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
-            ReleaseWarningCodeByString(gunIndex, "012296");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
-        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL &&
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES) {
-            memcpy(code, "012236", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL &&
-                   ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail == YES) {
-            memcpy(code, "012290", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
-            ReleaseWarningCodeByString(gunIndex, "012298");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL &&
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES) {
-            memcpy(code, "012235", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL &&
-                   ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES) {
-            memcpy(code, "012288", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
-            ReleaseWarningCodeByString(gunIndex, "012297");
-        }
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "012234", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO; }
-                    if (strncmp(code, "012289", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO; }
-
-                    if (strncmp(code, "012236", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO; }
-                    if (strncmp(code, "012290", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO; }
-
-                    if (strncmp(code, "012235", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO; }
-                    if (strncmp(code, "012288", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO; }
-                }
-            }
-        }
-    }
-
-    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
-            strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
-            strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012238", 6) == EQUAL ||
-            strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012304", 6) == EQUAL
-       ) {
-        memset(chargingInfo[gunIndex]->ConnectorAlarmCode, 0, sizeof(chargingInfo[gunIndex]->ConnectorAlarmCode));
-    }
-}
-
-void ReleaseWarningCodeByString(byte gunIndex, char *code)
-{
-    bool isCleanCheck = false;
-
-    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
-        memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-               ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
-        memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-               ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
-        memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                if (strncmp((char *)chargingInfo[index]->ConnectorWarningCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "012296", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO; }
-                    if (strncmp(code, "012297", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO; }
-                    if (strncmp(code, "012298", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO; }
-                }
-            }
-        }
-    }
-}
-//===============================================
-// EmergencyStop and Charging Stop
-//===============================================
-void ChargingTerminalProcess(byte gunIndex)
-{
-    setChargerMode(gunIndex, MODE_TERMINATING);
-}
-
-void ChargingAlarmProcess(byte gunIndex)
-{
-    setChargerMode(gunIndex, MODE_ALARM);
-}
-
-void AcChargingTerminalProcess()
-{
-    ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
-}
-
-void StopChargingProcessByString(byte level)
-{
-    if (level > ShmSysConfigAndInfo->SysWarningInfo.Level) {
-        ShmSysConfigAndInfo->SysWarningInfo.Level = level;
-    }
-}
-
-void ReleaseChargingProcessByString(byte level)
-{
-    if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level) {
-        ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
-    }
-}
-
-// 一般錯誤停止充電處理函式
-void BoardErrOccurByString(byte index, char *code)
-{
-    byte level = 1;
-    if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
-            (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-        if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO) {
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
-        }
-        ChargingTerminalProcess(index);
-    }
-
-    StopChargingProcessByString(level);
-}
-
-// 急停狀況的停止充電處理函式
-void EmcOccureByString(char *code)
-{
-    byte level = 2;
-    // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
-    // 其錯誤等級為 2
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    //DS60-120 remove
-    if (strncmp(code, "012251", 6) == EQUAL ||
-            strncmp(code, "012252", 6) == EQUAL ||
-            strncmp(code, "012238", 6) == EQUAL ||
-            strncmp(code, "042251", 6) == EQUAL ||
-            strncmp(code, "042252", 6) == EQUAL ||
-            strncmp(code, "012304", 6) == EQUAL ||
-            strncmp(code, "042200", 6) == EQUAL ||
-            strncmp(code, "042201", 6) == EQUAL ||
-            strncmp(code, "042202", 6) == EQUAL ||
-            strncmp(code, "042267", 6) == EQUAL)
-#endif //defined DD360 || defined DD360Audi
-    {
-        for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++) {
-            //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
-
-            if ((chargingInfo[gun]->SystemStatus > S_IDLE &&
-                    chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
-                    (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                     chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                //ChargingTerminalProcess(gun);
-                ChargingAlarmProcess(gun);
-            }
-        }
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-        StopChargingProcessByString(level);
-        InformOcppErrOccur(4);
-#endif //defined DD360 || defined DD360Audi
-    }
-}
-
-void ReleaseBoardErrOccurByString(byte index, char *code)
-{
-    bool isTrigger = false;
-    byte level = 1;
-
-    if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
-    }
-
-    if (isTrigger) {
-        ReleaseChargingProcessByString(level);
-    }
-}
-
-void ReleaseEmsOccureByString(byte index, char *code)
-{
-    bool isTrigger = false;
-    byte level = 2;
-
-    if (strncmp(code, "042251", 6) == 0 ) {
-        isTrigger = true;
-    } else if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
-    } else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
-    } else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
-    } else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
-    }
-
-    if (isTrigger) {
-        ReleaseChargingProcessByString(level);
-        InformOcppErrOccur(6);
-    }
-}
-
-//===============================================
-// 確認硬體 (按鈕) 狀態
-//===============================================
-bool leftBtnPush = false;
-bool rightBtnPush = false;
-
-void ChkPrimaryStatus()
-{
-    unsigned char Rtn;
-
-    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
-        Rtn = 0;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-            if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042251", 6) == 0) {
-                EmcOccureByString("042251");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042252", 6) == 0) {
-                EmcOccureByString("042252");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042200", 6) == 0) {
-                EmcOccureByString("042200");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042201", 6) == 0) {
-                EmcOccureByString("042201");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042202", 6) == 0) {
-                EmcOccureByString("042202");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
-                EmcOccureByString("012304");
-                Rtn = 1;
-            }
-        }
-        if (Rtn == 0) {
-            ReleaseEmsOccureByString(0, "042251");
-            ReleaseEmsOccureByString(0, "042252");
-            ReleaseEmsOccureByString(0, "042200");
-            ReleaseEmsOccureByString(0, "042201");
-            ReleaseEmsOccureByString(0, "042202");
-            ReleaseEmsOccureByString(0, "012304");
-        }
-    } else {
-        ReleaseEmsOccureByString(0, "042251");
-        ReleaseEmsOccureByString(0, "042252");
-        ReleaseEmsOccureByString(0, "042200");
-        ReleaseEmsOccureByString(0, "042201");
-        ReleaseEmsOccureByString(0, "042202");
-        ReleaseEmsOccureByString(0, "012304");
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
-        EmcOccureByString("012251");
-    } else {
-        ReleaseEmsOccureByString(0, "012251");
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
-        EmcOccureByString("012238");
-    } else {
-        ReleaseEmsOccureByString(0, "012238");
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
-    } else {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
-        EmcOccureByString("012252");
-    } else {
-        ReleaseEmsOccureByString(0, "012252");
-    }
-
-    //DS60-120 add
-    //if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
-    //        ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS) {
-    //    ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
-    //} else {
-    //    ShmSysConfigAndInfo->SysConfig.ShowInformation = NO;
-    //}
-
-    if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
-            !leftBtnPush
-#if defined DD360Audi
-            &&
-            getCurLcmPage() != _LCM_AUTHORIZING &&
-            getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
-            getCurLcmPage() != _LCM_AUTHORIZ_FAIL
-#endif //defined DD360Audi
-       ) {
-        if (!leftBtnPush) {
-            leftBtnPush = true;
-            PRINTF_FUNC("left btn down...............................%x\n",
-                        chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus);
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                switch (ac_chargingInfo[0]->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 (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-                        // 停止充電
-                        AcChargingTerminalProcess();
-                    }
-                }
-                break;
-                case S_COMPLETE:
-                {}
-                break;
-                }
-            }
-
-            switch (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-            case S_IDLE: {
-                if (isDetectPlugin()) {
-                    _DetectPlugInTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-#if defined DD360Audi
-                else {
-                    if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == PASS) {
-                        //printf("destroy gun = %d\r\n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                        destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                    } else {
-                        confirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                        PRINTF_FUNC("confirm select gun ............................... %d \n",
-                                    ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                    }
-                }
-#endif //defined DD360Audi
-            }
-            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 (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                    AcChargingTerminalProcess();
-                } else {
-                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                }
-            }
-            break;
-            case S_CHARGING: {
-                if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-                    // 停止充電
-                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                }
-            }
-            break;
-            case S_COMPLETE: {
-                // 回 IDLE
-                //PRINTF_FUNC("right btn down.................S_COMPLETE \n");
-                //chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
-            }
-            break;
-            }
-        }
-    } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
-        if (leftBtnPush) {
-            leftBtnPush = false;
-            //PRINTF_FUNC("left btn up............................... \n");
-        }
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
-            !rightBtnPush
-#if defined DD360Audi
-            &&
-            getCurLcmPage() != _LCM_IDLE &&
-            getCurLcmPage() != _LCM_AUTHORIZING &&
-            getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
-            getCurLcmPage() != _LCM_AUTHORIZ_FAIL &&
-            getCurLcmPage() != _LCM_WAIT_FOR_PLUG
-#endif //defined DD360Audi
-       ) {
-        if (!rightBtnPush) {
-            rightBtnPush = true;
-            //PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
-                    ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
-                ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            } else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
-                       ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
-                ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-            } else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
-                for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                    if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
-                            chargingInfo[_index]->SystemStatus != S_IDLE &&
-                            chargingInfo[_index]->SystemStatus != S_RESERVATION) {
-                        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
-                        ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                        return;
-                    }
-                }
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-                ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            } else {
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-                ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            }
-        }
-        PRINTF_FUNC("current select gun ............................... %d \n",
-                    ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
-        if (rightBtnPush) {
-            rightBtnPush = false;
-            //PRINTF_FUNC("right btn up............................... \n");
-        }
-    }
-}
-
-//===============================================
-// 確認各小板偵測的錯誤狀況
-//===============================================
-void CheckErrorOccurStatus(byte index)
-{
-    // 小板
-    if (chargingInfo[index]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            BoardErrOccurByString(index, "011012");
-        }
-//      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
-//          BoardErrOccurByString(index, "012234");
-    } else if (chargingInfo[index]->Type == _Type_GB) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
-            BoardErrOccurByString(index, "011016");
-        }
-//      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
-//          BoardErrOccurByString(index, "012236");
-    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-            BoardErrOccurByString(index, "011014");
-        }
-//      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
-//          BoardErrOccurByString(index, "012235");
-    }
-
-    // RB
-    if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
-            if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
-                ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
-                StopChargingProcessByString(2);
-                InformOcppErrOccur(13);
-            }
-
-            //DS60-120 add -----
-            if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
-                if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES) {
-                    memcpy(chargingInfo[index]->ConnectorAlarmCode, "012203", 6);
-                } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES) {
-                    memcpy(chargingInfo[index]->ConnectorAlarmCode, "012204", 6);
-                } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
-                    memcpy(chargingInfo[index]->ConnectorAlarmCode, "012205", 6);
-                }
-            }
-            //log_info("1 CheckErrorOccurStatus\r\n");
-            chargingInfo[index]->StopChargeFlag = YES;
-            //------------------------------------------------------------------
-        } else {
-            if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
-                ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-                ReleaseChargingProcessByString(2);
-                InformOcppErrOccur(6);
-            }
-        }
-    } else {
-        if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-            ReleaseChargingProcessByString(2);
-            InformOcppErrOccur(6);
-        }
-    }
-
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
-            StopChargingProcessByString(2);
-            InformOcppErrOccur(14);
-        }
-
-        //DS60-120 -----
-        if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
-            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES) {
-                memcpy(chargingInfo[index]->ConnectorAlarmCode, "012200", 6);
-            } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES) {
-                memcpy(chargingInfo[index]->ConnectorAlarmCode, "012201", 6);
-            } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
-                memcpy(chargingInfo[index]->ConnectorAlarmCode, "012202", 6);
-            }
-        }
-        //log_info("2 CheckErrorOccurStatus\r\n");
-        chargingInfo[index]->StopChargeFlag = YES;
-        //----------------------------------------------------------------------
-    } else {
-        if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-            ReleaseChargingProcessByString(2);
-            InformOcppErrOccur(6);
-        }
-    }
-
-    //DS60-120 ----
-    if (chargingInfo[index]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011011", 6);
-        } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011012", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012217", 6);
-        }
-    } else if (chargingInfo[index]->Type == _Type_GB) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011015", 6);
-        } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011016", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012221", 6);
-        }
-    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011013", 6);
-        } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011014", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012219", 6);
-        }
-    }
-    //--------------------------------------------------------------------------
-    if (strlen(chargingInfo[index]->ConnectorAlarmCode) == 0) {
-        //Primary
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012251", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012252", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012238", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012304", 6);
-        }
-    }
-}
-
-//===============================================
-// 確認 GPIO 狀態
-//===============================================
-void gpio_set_value(unsigned int gpio, unsigned int value)
-{
-    int fd;
-    char buf[MAX_BUF];
-
-    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
-    fd = open(buf, O_WRONLY);
-    if (fd < 0) {
-        perror("gpio/set-value");
-        return;
-    }
-
-    if (value) {
-        write(fd, "1", 2);
-    } else {
-        write(fd, "0", 2);
-    }
-
-    close(fd);
-}
-
-int gpio_get_value(unsigned int gpio, unsigned int *value)
-{
-    int fd;
-    char buf[MAX_BUF];
-    char ch;
-
-    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
-
-    fd = open(buf, O_RDONLY);
-    if (fd < 0) {
-        perror("gpio/get-value");
-        return fd;
-    }
-
-    read(fd, &ch, 1);
-
-    if (ch != '0') {
-        *value = 1;
-    } else {
-        *value = 0;
-    }
-
-    close(fd);
-    return 0;
-}
-
-void CheckGunTypeFromHw()
-{
-    uint8_t i = 0;
-    int pinIn[4] = {22, 23, 44, 45};
-    unsigned int gpioValue = 0;
-    unsigned char tmp[2] = {0};
-
-    log_info("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
-    for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
-        gpio_get_value(pinIn[i], &gpioValue);
-        switch (pinIn[i]) {
-        //right slot
-        case 22:
-            bd1_1_status = gpioValue;
-            break;
-        case 23:
-            bd1_2_status = gpioValue;
-            break;
-
-        //left slot
-        case 44:
-            bd0_1_status = gpioValue;
-            break;
-        case 45:
-            bd0_2_status = gpioValue;
-            break;
-        }
-    }
-
-#if 1 //DS60-120 remove
-    //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
-    //CcsChargingData [0至1] 分別為 Right至Left
-    //model name 槍順序左至右分別為Right至Left
-    tmp[1] = (bd0_1_status << 4 | bd0_2_status);
-    tmp[0] = (bd1_1_status << 4 | bd1_2_status);
-    for (i = 0; i < 2; i++) {
-        switch (tmp[i]) {
-        case 0x01:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
-            break;
-
-        case 0x10:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
-            break;
-
-        case 0x11:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
-            break;
-
-        case 0x00:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
-            break;
-        }
-    }
-#endif //0
-}
-
-void CheckGpioInStatus()
-{
-    int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
-    unsigned int gpioValue = 0;
-
-    for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
-        gpio_get_value(pinIn[i], &gpioValue);
-        if (gpioValue == 0x01) {
-            switch (pinIn[i]) {
-            // 小板緊急停止
-            case 47: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 1) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            BoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            BoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            case 27: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 3) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            BoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            BoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            }
-        } else {
-            switch (pinIn[i]) {
-            // 小板解除緊急停止
-            case 47: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 1) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            ReleaseBoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            ReleaseBoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            case 27: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 3) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            ReleaseBoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            ReleaseBoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            }
-        }
-    }
-}
-
-//===============================================
-// Main process
-//===============================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
-{
-    return ( _byte & mask_table[_bit] ) != 0x00;
-}
-
-// 設定 Byte 中某個 Bit的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-// value : 修改的值為 0 or 1
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
-{
-    if (value == 1) {
-        *_byte |= (1 << _bit);
-    } else if (value == 0) {
-        *_byte ^= (1 << _bit);
-    }
-}
-
-void UserScanFunction()
-{
-    bool idleReq = false;
-    unsigned char stopReq = 255;
-
-    // 當前非驗證的狀態
-    if (!IsAuthorizingMode()) {
-#if defined DD360Audi
-        //當前沒有選槍
-        if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == FAIL) { //Jerry add
-            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            return;
-        }
-#endif //defined DD360Audi
-
-        // 先判斷現在是否可以提供刷卡
-        // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
-        // 2. 停止充電
-        if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) {
-            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            return;
-        }
-
-        for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-            if (chargingInfo[i]->SystemStatus == S_CHARGING) {
-                stopReq = i;
-            }
-            if ((chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable) == YES ||
-                    (_acgunIndex > 0 && ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsAvailable)) {
-                idleReq = true;
-            }
-        }
-
-        if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-                ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-            stopReq = DEFAULT_AC_INDEX;
-        }
-
-        if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0) {
-            if (_acgunIndex > 0 && stopReq == DEFAULT_AC_INDEX && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                char value[32];
-
-                PRINTF_FUNC("ac stop charging \n");
-                PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
-                            ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
-                memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId,
-                       ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
-                    AcChargingTerminalProcess();
-                }
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            } else if (stopReq < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
-                       chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING &&
-                       (_acgunIndex <= 0 || (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE))) {
-                char value[32];
-
-                PRINTF_FUNC("stop charging \n");
-                PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
-                            chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
-                memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
-                       ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
-
-                // 同一張卡直接停掉
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
-                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                } else {
-                    // 進驗證
-                    if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                        _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
-                    } else {
-                        _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-                    }
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    StartSystemTimeoutDet(Timeout_AuthorizingForStop);
-                    AuthorizingStart();
-#else
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-#endif //!defined DD360 && !defined DD360Audi
-                }
-            } else if (idleReq) {
-                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
-                        stopReq != 255 &&
-                        ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
-                    idleReq = false;
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                } else if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-                           chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE) {
-                    PRINTF_FUNC("// LCM => Authorizing \n");
-#if defined DD360Audi
-                    setSelGunWaitToAuthor(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //Jerry add
-#endif //defined DD360Audi
-                    // LCM => Authorizing
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
-                    // 進入確認卡號狀態
-                    AuthorizingStart();
-                } else {
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                }
-            } else {
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            }
-        }
-    } else {
-        // 透過後臺停止充電的判斷
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
-                    ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-           ) {
-            // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
-                        ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
-                if (_authorizeIndex != NO_DEFINE) {
-                    // 先找 AC
-                    if (_authorizeIndex == DEFAULT_AC_INDEX) {
-                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
-                            AcChargingTerminalProcess();
-                        }
-                    } else {
-                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
-                            ChargingTerminalProcess(_authorizeIndex);
-                        }
-                    }
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    _authorizeIndex = NO_DEFINE;
-                }
-            } else {
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            }
-            ClearAuthorizedFlag();
-        } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
-                        ChargingTerminalProcess(_authorizeIndex);
-                        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                        ClearAuthorizedFlag();
-                        break;
-                    }
-                }
-            }
-        }
-    }
-}
-
-unsigned char isModeChange(unsigned char gun_index)
-{
-    unsigned char result = NO;
-
-    if (chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus) {
-        result = YES;
-        chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
-    }
-
-    return result;
-}
-
-void ScannerCardProcess()
-{
-    if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
-            ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
-        isCardScan = true;
-        // 處理刷卡及驗證卡號的動作
-        UserScanFunction();
-    }
-
-    if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING) {
-        StartSystemTimeoutDet(Timeout_Authorizing);
-
-        // 確認驗證卡號完成沒
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi
-           ) {
-            StopSystemTimeoutDet();
-            // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
-                // LCM => Authorize complete
-                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
-            } else {
-                // LCM => Authorize fail
-                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            }
-            ClearAuthorizedFlag();
-        } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
-                        ClearAuthorizedFlag();
-                        break;
-                    }
-                }
-            }
-        }
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL) {
-        StartSystemTimeoutDet(Timeout_VerifyFail);
-        isCardScan = false;
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
-        StartSystemTimeoutDet(Timeout_VerifyComp);
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
-        StartSystemTimeoutDet(Timeout_WaitPlug);
-    } else {
-        isCardScan = false;
-    }
-}
-
-bool AddGunInfoByConnector(byte typeValue, byte slots)
-{
-    bool result = true;
-
-    switch (typeValue) {
-    case '0': // none
-        break;
-    case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
-        break;
-    case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
-        break;
-    case '3': // IEC 62196-2 Type 2 Plug
-    case '4': // IEC 62196-2 Type 2 Socket
-        if (AC_QUANTITY > _ac_Index) {
-            ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
-
-            // AC 固定 index
-            ac_chargingInfo[_acgunIndex]->Index = 0;
-            ac_chargingInfo[_acgunIndex]->ReservationId = -1;
-            ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
-            ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
-            ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
-            ac_chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
-            ac_chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;  //DS60-120 add
-            _ac_Index++;
-            _acgunIndex++;
-        } else {
-            result = false;
-        }
-        break;
-    case '5': // GB/T AC Plug
-        break;
-    case '6': // GB/T AC Socket
-        break;
-    case 'J':
-    case 'K': { // CHAdeMO
-        if (CHAdeMO_QUANTITY > _chademoIndex) {
-            chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
-            chargingInfo[_gunIndex]->Index = _gunIndex;
-            chargingInfo[_gunIndex]->ReservationId = -1;
-            chargingInfo[_gunIndex]->slotsIndex = slots;
-            chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-            chargingInfo[_gunIndex]->Type = _Type_Chademo;
-            chargingInfo[_gunIndex]->type_index = _chademoIndex;
-            chargingInfo[_gunIndex]->IsAvailable = YES;
-            chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
-            chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;  //DS60-120 add
-            _chademoIndex++;
-            _gunIndex++;
-        } else {
-            result = false;
-        }
-    }
-    break;
-
-    case 'T': //Rema CCS1
-    case 'D': //Rema CCS2
-    case 'U': // CCS1 combo
-    case 'E': // CCS2 combo
-    case 'V': // Liquid CCS1 combo
-    case 'F': { // Liquid CCS2 combo
-        if (CCS_QUANTITY > _ccsIndex) {
-            chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
-
-            chargingInfo[_gunIndex]->Index = _gunIndex;
-            chargingInfo[_gunIndex]->ReservationId = -1;
-            chargingInfo[_gunIndex]->slotsIndex = slots;
-            chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-            chargingInfo[_gunIndex]->Type = _Type_CCS_2;
-            chargingInfo[_gunIndex]->type_index = _ccsIndex;
-            chargingInfo[_gunIndex]->IsAvailable = YES;
-            chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
-            chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
-            // 現階段預設為走 DIN70121
-            ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
-            _ccsIndex++;
-            _gunIndex++;
-        } else {
-            result = false;
-        }
-    }
-    break;
-    case 'G': { // GBT DC
-        if (GB_QUANTITY > _gb_Index) {
-            chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
-
-            chargingInfo[_gunIndex]->Index = _gunIndex;
-            chargingInfo[_gunIndex]->ReservationId = -1;
-            chargingInfo[_gunIndex]->slotsIndex = slots;
-            chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-            chargingInfo[_gunIndex]->Type = _Type_GB;
-            chargingInfo[_gunIndex]->type_index = _gb_Index;
-            chargingInfo[_gunIndex]->IsAvailable = YES;
-            chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
-            chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
-            _gb_Index++;
-            _gunIndex++;
-        } else {
-            result = false;
-        }
-    }
-    break;
-
-        //case 'D': // GBT DC x 2
-        //    break;
-    }
-    return result;
-}
-
-bool CheckConnectorTypeStatus()
-{
-    bool result = true;
-
-
-    //PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
-    //            bd0_1_status,
-    //            bd0_2_status,
-    //            bd1_1_status,
-    //            bd1_2_status);
-
-    if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9) {
-        //printf("1 CheckConnectorTypeStatus\r\n");
-        byte slots = 1;
-        for (byte typeIndex = 7; typeIndex <= 9; typeIndex++) {
-            if (!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots)) {
-                return false;
-            }
-
-            slots++;
-        }
-
-        // AC index 接在 DC 後面
-        //if (AC_QUANTITY > 0) {
-        if (_ac_Index > 0) { //DS60-120 add
-            ac_chargingInfo[0]->Index += _gunIndex;
-        }
-
-        ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
-        ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
-        log_info("DC connector Quality = %d, AC connector Quality = %d",
-                 ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
-                 ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
-        log_info("Type 0~3 = CHAdeMO, CCS, GB, AC");
-        if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
-                ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0) {
-            result = false;
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-            //DS60-120 add
-            bool isFind = false;
-            if (chargingInfo[0]->Type == _Type_Chademo) {
-                if ((bd0_1_status == 0 && bd0_2_status == 1) ||
-                        (bd1_1_status == 0 && bd1_2_status == 1)) {
-                    isFind = true;
-                }
-            } else if (chargingInfo[0]->Type == _Type_CCS_2) {
-                if ((bd0_1_status == 1 && bd0_2_status == 0) ||
-                        (bd1_1_status == 1 && bd1_2_status == 0)) {
-                    isFind = true;
-                }
-            } else if (chargingInfo[0]->Type == _Type_GB) {
-                if ((bd0_1_status == 1 && bd0_2_status == 1) ||
-                        (bd1_1_status == 1 && bd1_2_status == 1)) {
-                    isFind = true;
-                }
-            }
-
-            if (isFind) {
-                if (bd0_1_status == 1 || bd0_2_status == 1) {
-                    chargingInfo[0]->Evboard_id = 0x01;
-                }
-
-                if (bd1_1_status == 1 || bd1_2_status == 1) {
-                    chargingInfo[0]->Evboard_id = 0x02;
-                }
-                CheckHwSlotStatusLog(0);
-            } else {
-                result = false;
-            }
-            //chargingInfo[0]->Evboard_id = 0x01;
-            log_info("index = %d, Type = %d, Evboard_id = %d", 0, chargingInfo[0]->Type, chargingInfo[0]->Evboard_id);
-        } else {
-            char type = NO_DEFINE; //DS60-120 add
-
-            // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
-            for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++) {
-                if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1) {
-                    // 與硬體相同 type : Chademo
-                    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0) {
-                    // 與硬體相同 type : CCS
-                    if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1) {
-                    // 與硬體相同 type : GB
-                    if (chargingInfo[gunIndex]->Type == _Type_GB) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                }
-
-                if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1) {
-                    // 與硬體相同 type : Chademo
-                    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x02;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0) {
-                    // 與硬體相同 type : CCS
-                    if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x02;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1) {
-                    // 與硬體相同 type : GB
-                    if (chargingInfo[gunIndex]->Type == _Type_GB) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x02;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                }
-
-                log_info("index = %d, Type = %d, Evboard_id = %d",
-                         gunIndex,
-                         chargingInfo[gunIndex]->Type,
-                         chargingInfo[gunIndex]->Evboard_id);
-                CheckHwSlotStatusLog(gunIndex);
-
-                if (type == NO_DEFINE) {
-                    type = chargingInfo[gunIndex]->Type;
-                }
-
-                if (chargingInfo[gunIndex]->Evboard_id == 0x00) {
-                    result = false;
-                }
-            }
-        }
-    } else {
-        // Module Name 不正確 - 告警
-        result = false;
-    }
-
-    return result;
-}
-
-void KillTask()
-{
-    ChangeLcmByIndex(_LCM_FIX);
-    system("killall Module_EventLogging");
-    system("killall Module_PrimaryComm");
-    system("killall Module_EvComm");
-    system("killall Module_LcmControl");
-    system("killall Module_InternalComm");
-    //system("killall DoComm");
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    system("killall Module_PsuComm");
-    system("killall OcppBackend &");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-void KillTaskExceptPrimary()
-{
-    ChangeLcmByIndex(_LCM_FIX);
-    system("killall Module_EvComm");
-    system("killall Module_InternalComm");
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    system("killall Module_PsuComm");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-void KillAllTask()
-{
-    ChangeLcmByIndex(_LCM_FIX);
-    system("killall Module_EventLogging");
-    system("killall Module_PrimaryComm");
-    system("killall Module_EvComm");
-    system("killall Module_LcmControl");
-    system("killall Module_InternalComm");
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    system("killall Module_PsuComm");
-    system("killall OcppBackend &");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
-#else
-    system("killall DoComm");
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-int CheckUpdateProcess(void)
-{
-    //bool isPass = true;
-    uint8_t retSucc = 0;
-    uint8_t retFail = 0;
-    byte index = 0;
-    byte target = 0;
-    char *new_str = NULL;
-    unsigned char *ptr = NULL;
-    int fd = 0;
-    int CanFd = 0;
-    int uartFd = 0;
-    unsigned int Type = 0;
-    long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
-    DIR *d;
-    struct dirent *dir;
-
-    d = opendir("/mnt/");
-    if (d) {
-        while ((dir = readdir(d)) != NULL) {
-            if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
-                continue;
-            }
-
-            new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
-            //new_str[0] = '\0';
-            strcat(new_str, "/mnt/");
-            strcat(new_str, dir->d_name);
-            log_info("%s%s\r\n", "/mnt/", dir->d_name);
-            fd = open(new_str, O_RDONLY);
-            if (fd < 0) {
-                return FAIL;
-            }
-
-            ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
-            //memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
-
-            //get the image length
-            ImageLen = read(fd, ptr, MaxLen);
-            for (byte i = 0; i < 16; i++) {
-                if (ShmSysConfigAndInfo->SysConfig.ModelName[i] != ptr[i]) {
-                    return FAIL;
-                }
-            }
-
-            PRINTF_FUNC("model name check pass. \n");
-            if (ImageLen > 20) {
-                Type = (((unsigned int)ptr[16]) << 24 |
-                        ((unsigned int)ptr[17]) << 16 |
-                        ((unsigned int)ptr[18]) << 8  |
-                        ((unsigned int)ptr[19]));
-                PRINTF_FUNC("Typed...%x \r\n", Type);
-
-                switch (Type) {
-                case 0x10000001:
-                case 0x10000002:
-                case 0x10000003:
-                case 0x10000004:
-                case 0x10000005:
-                    if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-                        //return PASS;
-                        retSucc++;
-                    } else {
-                        PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                        //return FAIL;
-                        retFail++;
-                    }
-                    break;
-
-                case 0x10000007:
-                case 0x10000008:
-                case 0x10000009:
-                case 0x1000000A:
-                    //isPass = true;
-                    CanFd = InitCanBus();
-                    if (CanFd > 0) {
-                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                            //if (!isPass) {
-                            //    break;
-                            //}
-
-                            if (chargingInfo[index]->Type == _Type_CCS_2) {
-                                if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL) {
-                                    //isPass = false;
-                                    PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                                    retFail++;
-                                }
-                            }
-                        }
-                    } else {
-                        log_error("Upgrade CCS open CAN FD fail.\n");
-                        //isPass = false;
-                        return FAIL;
-                    }
-
-                    if (retFail != 0) {
-                        break;
-                    } else {
-                        retSucc++;
-                    }
-                    //return isPass;
-                    break;
-
-                case 0x10000006:
-                case 0x1000000D:
-                case 0x1000000E:
-                case 0x20000002:
-                case 0x10000014:
-                    // CSU_PRIMARY_CONTROLLER : 0x10000006
-                    target = 0x00;
-
-                    if (Type == 0x10000006) {
-                        target = UPGRADE_PRI;
-                    } else if (Type == 0x1000000D) {
-                        target = UPGRADE_RB;
-                    } else if (Type == 0x1000000E) {
-                        target = UPGRADE_FAN;
-                    } else if (Type == 0x20000002) {
-                        target = UPGRADE_AC;
-                    } else if (Type == 0x10000014) {
-                        target = UPGRADE_LED;
-                    }
-
-                    uartFd = InitComPort(target);
-
-                    if (Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-                        //return PASS;
-                        retSucc++;
-                    } else {
-                        PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                        //return FAIL;
-                        return FAIL;
-                    }
-
-                    if (uartFd > 0) {
-                        close(uartFd);
-                    }
-                    break;
-
-                case 0x1000000B:
-                case 0x1000000C:
-                    // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
-                    //bool isPass = true;
-                    CanFd = InitCanBus();
-                    if (CanFd > 0) {
-                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                            //if (!isPass) {
-                            //    break;
-                            //}
-
-                            if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
-                                    (Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB)) {
-                                if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-                                    //isPass = PASS;
-                                    retSucc++;
-                                } else {
-                                    PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                                    //isPass = FAIL;
-                                    retFail++;
-                                }
-                            }
-                        }
-                    } else {
-                        PRINTF_FUNC("Upgrad FD fail. \n");
-                        //isPass = false;
-                        return FAIL;
-                    }
-
-                    //return isPass;
-                    break;
-                }
-            }
-            free(new_str);
-            free(ptr);
-        }
-    }
-    free(dir);
-    closedir(d);
-
-    if (retFail != 0) {
-        return FAIL;
-    }
-
-    return PASS;
-}
-
-void CreateRfidFork()
-{
-    pid_t rfidRecPid;
-
-    rfidRecPid = fork();
-    log_info("CreateRfidFork = %d\r\n", rfidRecPid);
-    if (rfidRecPid == 0) {
-        while (true) {
-            // 刷卡判斷
-            RFID rfid;
-            if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
-                    !ShmSysConfigAndInfo->SysConfig.isRFID)
-            {}
-            else if (getRequestCardSN(rfidFd, 0, &rfid)) {
-                //log_info("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
-                if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0) {
-                    if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
-                        switch (rfid.snType) {
-                        case RFID_SN_TYPE_6BYTE:
-                            sprintf((char *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.UserId,
-                                    "%02X%02X%02X%02X",
-                                    rfid.currentCard[0], rfid.currentCard[1],
-                                    rfid.currentCard[2], rfid.currentCard[3]);
-                            break;
-                        }
-                    } else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG) {
-                        switch (rfid.snType) {
-                        case RFID_SN_TYPE_6BYTE:
-                            sprintf((char *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.UserId,
-                                    "%02X%02X%02X%02X",
-                                    rfid.currentCard[3], rfid.currentCard[2],
-                                    rfid.currentCard[1], rfid.currentCard[0]);
-                            break;
-                        }
-                    }
-                    log_info("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
-                }
-            }
-            usleep(500000);
-        }
-    }
-}
-
-void StartSystemTimeoutDet(unsigned char flag)
-{
-    if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag) {
-        gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-    }
-    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
-}
-
-void StopSystemTimeoutDet()
-{
-    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
-}
-
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
-{
-    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
-        if (chargingInfo[gunIndex]->TimeoutFlag != flag) {
-            gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
-        }
-        chargingInfo[gunIndex]->TimeoutFlag = flag;
-    }
-}
-
-void StopGunInfoTimeoutDet(unsigned char gunIndex)
-{
-    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
-        chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
-    }
-}
-
-void CheckConnectionTimeout()
-{
-    if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
-        _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
-    } else {
-        _connectionTimeout = CONN_PLUG_TIME_OUT;
-    }
-
-#if 0
-    if (system("pidof -s OcppBackend > /dev/null") != 0) {
-        _connectionTimeout = CONN_PLUG_TIME_OUT;
-    } else {
-        if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
-            _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
-            if (_connectionTimeout <= 0) {
-                _connectionTimeout = CONN_PLUG_TIME_OUT;
-            }
-        } else {
-            _connectionTimeout = CONN_PLUG_TIME_OUT;
-        }
-    }
-#endif //0
-}
-
-void CreateTimeoutFork()
-{
-    pid_t timeoutPid;
-
-    timeoutPid = fork();
-    log_info("CreateTimeoutFork = %d\r\n", timeoutPid);
-    if (timeoutPid == 0) {
-        gettimeofday(&_cmdSubPriority_time, NULL);
-        CheckConnectionTimeout();
-
-        while (1) {
-            if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
-                CheckConnectionTimeout();
-                gettimeofday(&_cmdSubPriority_time, NULL);
-            }
-
-            //printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
-            // 系統
-            switch (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag) {
-            case Timeout_SelftestChk:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
-                    _SelfTestTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(DESTROY_ALL_SEL); //jerry add
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_Authorizing:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
-                    _AuthorizedTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_VerifyFail:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
-                    _AutoReturnTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_VerifyComp:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
-                    _AutoReturnTimeout();
-                    StopSystemTimeoutDet();
-                }
-                break;
-            case Timeout_WaitPlug:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
-                    _DetectPlugInTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_ReturnToChargingGunDet: {
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
-#if defined DD360Audi
-                    if (getCurLcmPage() != _LCM_PRE_CHARGE &&
-                            getCurLcmPage() != _LCM_CHARGING &&
-                            getCurLcmPage() != _LCM_COMPLETE) {
-                        destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //jerry add
-
-                    }
-#endif //defined DD360Audi
-                    DisplayChargingInfo();
-                    StopSystemTimeoutDet();
-                }
-            }
-            break;
-            case Timeout_AuthorizingForStop: {
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ClearAuthorizedFlag();
-                    StopSystemTimeoutDet();
-                }
-            }
-            break;
-            }
-            // 各槍
-            for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-                //printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
-                switch (chargingInfo[gun_index]->TimeoutFlag) {
-                case Timeout_Preparing: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
-                        _PrepareTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_EvChargingDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
-                        _DetectEvChargingEnableTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_EvseChargingDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
-                        _DetectEvseChargingEnableTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_EvseCompleteDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_ForCcsPrechargeDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
-                        _CcsPrechargeTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-
-#if defined DD360Audi
-                case Timeout_SelectGun: //Jerry add
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
-                        log_info("Timeout_SelectGun\r\n");
-                        StopGunInfoTimeoutDet(gun_index);
-                        destroySelGun(gun_index); //jerry add
-                    }
-                    break;
-#endif //defined DD360Audi
-                }
-            }
-            sleep(1);
-        }
-    }
-}
-
-void GetSystemTime()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-    PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-                tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-                tmCSU->tm_sec);
-
-//  byte date[14];
-//
-//
-//       //sprintf(&date, "%d", );
-//
-//       date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
-
-//  date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
-//  date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
-//  date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
-//  date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
-//
-//  date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
-//  date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
-//
-//  date[6] = (tmCSU->tm_mday) / 10 % 10;
-//  date[7] = (tmCSU->tm_mday) / 1 % 10;
-//
-//  date[8] = (tmCSU->tm_hour) / 10 % 10;
-//  date[9] = (tmCSU->tm_hour) / 1 % 10;
-//
-//  date[10] = (tmCSU->tm_min) / 10 % 10;
-//  date[11] = (tmCSU->tm_min) / 1 % 10;
-//
-//  date[12] = (tmCSU->tm_sec) / 10 % 10;
-//  date[13] = (tmCSU->tm_sec) / 1 % 10;
-
-//  PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
-//          date[4], date[5], date[6], date[7],
-//          date[8], date[9], date[10], date[11],
-//          date[12], date[13]);
-}
-
-void CheckFactoryConfigFunction(void)
-{
-    char Buf[256] = {0};
-
-    if (ShmSysConfigAndInfo->SysInfo.FactoryConfiguration) {
-        sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
-                ShmSysConfigAndInfo->SysConfig.ModelName,
-                ShmSysConfigAndInfo->SysConfig.SerialNumber);
-        system(Buf);
-
-        system("rm -f /Storage/OCPP/OCPPConfiguration");
-        system("sync");
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-}
-
-void CheckFwUpdateFunction()
-{
-    //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
-    if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
-        log_info("ftp : update start. \n");
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_UPDATE);
-        }
-
-        byte updateResult = CheckUpdateProcess();
-
-        if (updateResult == PASS) {
-            log_info("ftp : update complete. \n");
-        } else if (updateResult == MODELNAME_FAIL) {
-            log_info("ftp : model name is none match. \n");
-            KillAllTask();
-            ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
-            sleep(5);
-            system("/usr/bin/run_evse_restart.sh");
-            return;
-        } else {
-            log_info("ftp : update fail. \n");
-        }
-
-        ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
-        sleep(5);
-        system("reboot -f");
-    } else if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
-        ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
-
-        if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
-            log_info("Backend : update start. \n");
-            strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
-            strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
-            ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-            KillTask();
-
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                setChargerMode(_index, MODE_UPDATE);
-            }
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
-                ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
-            }
-
-            byte updateResult = CheckUpdateProcess();
-
-            if (updateResult == PASS) {
-                log_info("Backend : update complete. \n");
-                strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
-            } else if (updateResult == MODELNAME_FAIL) {
-                log_info("Backend : model name is none match. \n");
-                KillAllTask();
-                strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
-                ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-                sleep(5);
-                system("/usr/bin/run_evse_restart.sh");
-                return;
-            } else {
-                log_info("Backend : update fail. \n");
-                strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
-            }
-
-            strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
-            ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-            sleep(5);
-            system("reboot -f");
-        }
-    }
-}
-
-//===============================================
-// Check reservation date is expired
-//===============================================
-int isReservationExpired(unsigned char gun_index)
-{
-    int result = NO;
-    struct tm expiredDate;
-    struct timeb expiredTime;
-
-    if (sscanf((char *) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
-               "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
-               &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
-               &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
-        expiredDate.tm_year -= 1900;
-        expiredDate.tm_mon -= 1;
-
-        expiredTime.time = mktime(&expiredDate);
-        if (!CheckTimeOut(expiredTime)) {
-            result = YES;
-        }
-    }
-
-    return result;
-}
-
-//===============================================
-// OCPP
-//===============================================
-void CheckOcppStatus()
-{
-    if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
-        ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
-    }
-
-    if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
-        bool canReset = true;
-        bool canHardReset = true; //DS60-120 add
-
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                if (chargingInfo[_index]->SystemStatus != S_IDLE &&
-                        chargingInfo[_index]->SystemStatus != S_RESERVATION &&
-                        chargingInfo[_index]->SystemStatus != S_MAINTAIN) {
-                    canReset = false;
-                    if (chargingInfo[_index]->SystemStatus >= S_REASSIGN &&
-                            chargingInfo[_index]->SystemStatus < S_TERMINATING) {
-                        canHardReset = false;
-                        ChargingTerminalProcess(_index);
-                        restartFlag = 1;
-                    }
-                }
-            }
-        }
-
-        if (canReset) {
-            ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
-            sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
-            if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
-                log_error("****** Hard Reboot ****** \n");
-                ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-                sleep(3);
-                system("reboot -f");
-            } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
-                log_error("****** Soft Reboot ****** \n");
-                ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-                sleep(3);
-                system("killall OcppBackend &");
-                KillAllTask();
-                system("/usr/bin/run_evse_restart.sh");
-            }
-        }
-    }
-}
-
-void OcppStartTransation(byte gunIndex)
-{
-    byte _OcppGunIndex = gunIndex;
-
-    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
-    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
-        _OcppGunIndex = 2;
-    }
-
-    if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
-    }
-
-    PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
-}
-
-void OcppStopTransation(byte gunIndex)
-{
-    byte _OcppGunIndex = gunIndex;
-
-    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
-    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
-        _OcppGunIndex = 2;
-    }
-
-    if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
-    }
-
-    PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
-}
-
-bool OcppRemoteStop(byte gunIndex)
-{
-    byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-
-    // 有 AC 槍的話
-    if (acDirIndex > 0 && gunIndex > 0) {
-        gunIndex += acDirIndex;
-    }
-
-    bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
-    }
-
-    return result;
-}
-
-bool WifiScheduleStop(byte gunIndex)
-{
-    bool result = false;
-
-    result = chargingInfo[gunIndex]->schedule.isTriggerStop;
-    chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
-
-    return result;
-}
-
-void OcppRemoteStartChk()
-{
-    if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
-    {}
-    else if (!isDetectPlugin()) {
-        // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
-        byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-
-        for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++) {
-            if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
-                if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
-                        ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
-                    ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-                    ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
-                    ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                    //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
-                    ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
-                    return;
-                }
-                ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-            }
-        }
-
-        byte threeGunIndex = 0;
-        byte dcIndex = 0;
-        bool isGunUsingStatus = false;
-
-        for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-            // 如果有 AC 槍,且 DC 槍也有兩把
-            if (acDirIndex == 1 && _index == 1) {
-                threeGunIndex = 1;
-            }
-
-            if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES) {
-                dcIndex = _index;
-            }
-
-            if (chargingInfo[_index]->SystemStatus != S_IDLE) {
-                isGunUsingStatus = true;
-            }
-        }
-
-        // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
-        if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
-            if (dcIndex == 0) {
-                threeGunIndex = 0;
-            }
-
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-            return;
-        }
-
-        if (dcIndex == 0) {
-            threeGunIndex = 0;
-        }
-
-        if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES) {
-            if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
-                    chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
-                chargingInfo[dcIndex]->RemoteStartFlag = YES;
-                ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
-                ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-                DetectPluginStart();
-#if defined DD360Audi
-                setSelGunWaitToAuthor(dcIndex); //Jerry add
-#endif //defined DD360Audi
-            }
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-        }
-    }
-}
-
-void ChkOcppStatus(byte gunIndex)
-{
-    if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
-            ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
-        ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
-        if (isReservationExpired(gunIndex)) {
-            PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
-            log_error("***************ChkOcppStatus : OcppReservedStatus******************** \n");
-            chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
-            chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
-        }
-        ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
-    }
-
-    if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
-            ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
-        ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
-        if (isReservationExpired(gunIndex)) {
-            PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
-            log_error("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
-            chargingInfo[gunIndex]->ReservationId = 0;
-            chargingInfo[gunIndex]->SystemStatus = S_IDLE;
-        }
-        ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
-    }
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
-        PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
-        log_error("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
-        if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
-            if (isDb_ready) {
-                DB_Update_Operactive(localDb, gunIndex, true);
-            }
-
-            chargingInfo[gunIndex]->IsAvailable = YES;
-            if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
-                    chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
-                    chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
-                setChargerMode(gunIndex, MODE_IDLE);
-            }
-        } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
-            if (isDb_ready) {
-                DB_Update_Operactive(localDb, gunIndex, false);
-            }
-
-            chargingInfo[gunIndex]->IsAvailable = NO;
-            if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
-                    chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
-                    chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
-                setChargerMode(gunIndex, MODE_MAINTAIN);
-            }
-        }
-    }
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
-        ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
-        if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
-                chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
-            // 充電中,需停止充電
-            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
-            ChargingTerminalProcess(gunIndex);
-        }
-        strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
-    }
-}
-
-bool CheckBackendChargingTimeout(byte gunIndex)
-{
-    bool result = false;
-
-    if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
-        if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60)) {
-                result = true;
-            }
-        }
-    } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-        // 隨插即充電的要看 offline
-        if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60)) {
-                result = true;
-            }
-        }
-    }
-
-    return result;
-}
-
-bool CheckBackendChargingEnergy(byte gunIndex)
-{
-    bool result = false;
-
-    if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
-        if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy) {
-                result = true;
-            }
-        }
-    } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-        // 隨插即充電的要看 offline
-        if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) {
-                result = true;
-            }
-        }
-    }
-
-    return result;
-}
-
-void InformOcppErrOccur(byte codeType)
-{
-    char _error[25];
-
-    switch (codeType) {
-    case 4: strcpy(_error, "InternalError"); break;
-    case 6: strcpy(_error, "NoError"); break;
-    case 7: strcpy(_error, "OtherError"); break;
-    case 13: strcpy(_error, "UnderVoltage"); break;
-    case 14: strcpy(_error, "OverVoltage"); break;
-    }
-
-    for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-        strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, _error);
-    }
-}
-
-//===============================================
-// SQLite3 related routine
-//===============================================
-int DB_Open(sqlite3 *db)
-{
-    int result = PASS;
-    char *errMsg = NULL;
-    char *createRecordSql = "CREATE TABLE IF NOT EXISTS charging_record("
-                            "idx integer primary key AUTOINCREMENT, "
-                            "reservationId text, "
-                            "transactionId text, "
-                            "startMethod text, "
-                            "userId text, "
-                            "dateTimeStart text, "
-                            "dateTimeStop text,"
-                            "socStart text, "
-                            "socStop text, "
-                            "chargeEnergy text, "
-                            "stopReason text"
-                            ");";
-
-    /*char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
-                         "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                         "`IsAvailable` TEXT NOT NULL, "
-                         "`connector` INTEGER NOT NULL, "
-                         "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
-    */
-    //DS60-120 add
-    char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
-                         "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                         "`item` TEXT NOT NULL, "
-                         "`connector` INTEGER NOT NULL, "
-                         "`val` TEXT NOT NULL, unique(item,connector) on conflict replace);";
-
-    char *createrecordSql = "CREATE TABLE IF NOT EXISTS `event_record` ( "
-                            "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                            "`occurDatetime` TEXT NOT NULL, "
-                            "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
-
-    char *createrebootSql = "CREATE TABLE IF NOT EXISTS `reboot_record` ( "
-                            "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                            "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local charging record database open successfully.\r\n");
-
-        if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened local charging record table successfully\n");
-        }
-
-        if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened local config table successfully\n");
-        }
-
-        //DS60-120
-        if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create local record table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened local record table successfully\n");
-        }
-
-        if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create reboot record table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened reboot record table successfully\n");
-        }
-        //-----
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Insert_Record(sqlite3 *db, int gun_index)
-{
-    int result = PASS;
-    char *errMsg = NULL;
-    char insertSql[1024];
-
-    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');",
-            chargingInfo[gun_index]->ReservationId, //DS60-120 add
-            ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
-            chargingInfo[gun_index]->StartMethod,
-            chargingInfo[gun_index]->StartUserId,
-            chargingInfo[gun_index]->StartDateTime,
-            chargingInfo[gun_index]->StopDateTime,
-            chargingInfo[gun_index]->EvBatteryStartSoc,
-            chargingInfo[gun_index]->EvBatterySoc,
-            chargingInfo[gun_index]->PresentChargedEnergy,
-            //DS60-120 remove
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
-            //ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
-            ShmOCPP16Data->StopTransaction[gun_index].StopReason);
-
-    //if (sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db)) {
-    if (sqlite3_open(DB_FILE, &db)) { //DS60-120 add
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local charging record database open successfully.\r\n");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Insert local charging record successfully\n");
-        }
-
-        //DS60-120 add
-        sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "delete local charging error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "delete local charging record successfully\n");
-        }
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
-{
-    uint8_t result = false;
-    char *errMsg = NULL;
-    char sqlStr[1024];
-    srand(time(NULL));
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "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
-        PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
-        if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "update config error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
-        }
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
-{
-    uint8_t result = true;
-    char *errMsg = NULL;
-    char sqlStr[1024];
-    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
-    //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local config query database open successfully.\r\n");
-        sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
-        if (rows > 0) {
-            for (int idxRow = 1; idxRow <= rows; idxRow++) {
-                if (strcmp(rs[(idxRow * cols) + 3], "0") == 0) {
-                    result = false;
-                }
-                PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
-            }
-        } else {
-            PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
-        }
-
-        sqlite3_free_table(rs);
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Reboot_Record(sqlite3 *db)
-{
-    int result = PASS;
-    char *errMsg = NULL;
-    char insertSql[256];
-
-    sprintf(insertSql, "insert into reboot_record(rebootDatetime) values(CURRENT_TIMESTAMP);");
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local charging record database open successfully.\n");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Insert reboot record error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Insert reboot record successfully\n");
-        }
-
-        sprintf(insertSql, "delete from reboot_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "delete reboot record error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "delete reboot record successfully\n");
-        }
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-//===============================================
-// Config process
-//===============================================
-void AddPlugInTimes(byte gunIndex)
-{
-    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-        ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
-    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-        ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
-    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
-        ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
-    }
-}
-
-void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
-{
-    char cmdBuf[32];
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-
-    sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
-            tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-            tmCSU->tm_sec);
-    if (isStart) {
-        strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
-    } else {
-        strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
-    }
-}
-
-void zipLogFiles()
-{
-    const char *logPath = "/Storage/SystemLog";
-    // 獲取目錄
-    DIR *pDir = opendir(logPath);
-    if (pDir != NULL) {
-        struct timeb csuTime;
-        struct tm *tmCSU;
-
-        ftime(&csuTime);
-        tmCSU = localtime(&csuTime.time);
-//      PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//          tmCSU->tm_sec);
-
-        // Read items inside the folder
-        struct dirent *pEntry = NULL;
-        while ((pEntry = readdir(pDir)) != NULL) {
-            if (strcmp(pEntry->d_name, ".") != 0 &&
-                    strcmp(pEntry->d_name, "..") != 0 &&
-                    strncmp(pEntry->d_name, "[", 1) == 0 &&
-                    strstr(pEntry->d_name, "tar") < 0) {
-                char yearC[5];
-                unsigned short year = 0;
-                char monthC[3];
-                unsigned short month = 0;
-
-                yearC[4] = '\0';
-                strncpy(yearC, pEntry->d_name + 1, 4);
-                monthC[2] = '\0';
-                strncpy(monthC, pEntry->d_name + 6, 2);
-
-                year = atoi(yearC);
-                month = atoi(monthC);
-
-                if (year != 0) {
-                    if (year < tmCSU->tm_year + 1900 ||
-                            (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1)) {
-                        log_info("tar file name : %s \n", pEntry->d_name);
-                        char file[256];
-
-                        memset(file, 0x00, sizeof(file));
-                        strcat(file, "tar zcvf ");
-                        strcat(file, logPath);
-                        strncat(file, "/", 1);
-                        strcat(file, pEntry->d_name);
-                        strcat(file, ".tar");
-                        strncat(file, " ", 1);
-                        strcat(file, logPath);
-                        strncat(file, "/", 1);
-                        strcat(file, pEntry->d_name);
-                        PRINTF_FUNC("zip = %s \n", file);
-                        system(file);
-                    }
-                }
-            }
-        }
-    }
-    // Close folder
-    closedir(pDir);
-}
-
-void ChangeGunSelectByIndex(byte sel)
-{
-    ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
-    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
-}
-
-void CheckIsAlternatvieByModelName()
-{
-    // 黑白機 ?
-    /*if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWWU301J0UT1PH") == EQUAL ||
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ET1PH") == EQUAL ||
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DSYE301J3EW2PH") == EQUAL ||
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UW1PH") == EQUAL) {
-      */
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W') { //DS60-120
-        // 壁掛
-        ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
-    } else {
-        ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
-    }
-}
-
-void StopProcessingLoop()
-{
-    for (;;) {
-        CheckFactoryConfigFunction();
-        CheckFwUpdateFunction();
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-            ChkPrimaryStatus();
-            if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0) {
-                PRINTF_FUNC("Soft reboot for retry self-tets (Primary). \n");
-                KillAllTask();
-                sleep(3);
-                system("/usr/bin/run_evse_restart.sh");
-                return;
-            }
-        }
-        sleep(1);
-    }
-}
-
-void CreateWatchdog()
-{
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO) {
-        wtdFd = InitWatchDog();
-
-        if (wtdFd < 0) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-    }
-}
-
-bool IsConnectorWholeIdle()
-{
-    bool result = true;
-
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
-        if (chargingInfo[count]->SystemStatus != S_IDLE &&
-                chargingInfo[count]->SystemStatus != S_RESERVATION) {
-            result = false;
-            break;
-        }
-    }
-
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
-        if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
-                ac_chargingInfo[count]->IsErrorOccur == NO) {
-            result = false;
-            break;
-        }
-    }
-
-    return result;
-}
-
-void ClearAlarmCodeWhenAcOff()
-{
-    if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
-    }
-}
-
-//==========================================
-// Check task processing
-//==========================================
-void CheckTask()
-{
-    /*+++ 20200908, vern, disable it for DD360 +++*/
-#if 0
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
-        if (system("pidof -s Module_4g > /dev/null") != 0) {
-            log_error("Module_4g not running, restart it.\r\n");
-            system("/root/Module_4g &");
-        }
-    } else if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
-        if (system("pidof -s Module_Wifi > /dev/null") != 0) {
-            log_error("Module_Wifi not running, restart it.\r\n");
-            system("/root/Module_Wifi &");
-        }
-    }
-
-    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
-        if (system("pidof -s OcppBackend > /dev/null") != 0) {
-            log_error("OcppBackend not running, restart it.\r\n");
-            system("/root/OcppBackend &");
-        }
-    }
-#endif
-    /*--- 20200908, vern, disable it for DD360 ---*/
-    if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
-        log_error("Module_ProduceUtils not running, restart it.\r\n");
-        system ("/root/Module_ProduceUtils &");
-    }
-}
-
-void InitialDHCP()
-{
-    char tmpbuf[256] = {0};
-
-    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 &",
-            ShmSysConfigAndInfo->SysConfig.SystemId);
-    system(tmpbuf);
-}
-
-//==========================================
-// Check Smart Charging Profile
-//==========================================
-int GetStartScheduleTime(unsigned char *time)
-{
-    int result = -1;
-    struct tm tmScheduleStart;
-    struct timeb tbScheduleStart;
-
-    if ((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6)) {
-        tmScheduleStart.tm_year -= 1900;
-        tmScheduleStart.tm_mon -= 1;
-        tbScheduleStart.time = mktime(&tmScheduleStart);
-        tbScheduleStart.millitm = 0;
-
-        result = DiffTimebWithNow(tbScheduleStart) / 1000;
-    }
-
-    return result;
-}
-
-void CheckSmartChargeProfile(byte _index)
-{
-    if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
-        // Get Charging Profile
-        ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
-        if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
-                ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
-           ) {
-            int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
-            byte _startCount = NO_DEFINE;
-            byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
-
-            for (byte _count = 0; _count < _maxCount; _count++) {
-                // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
-                if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
-                    if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
-                            ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
-                        _startCount = _count;
-                    }
-                }
-            }
-
-            PRINTF_FUNC("_startCount = %d \n", _startCount);
-            if (_startCount < _maxCount) {
-                //DS60-120 add
-                PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
-                chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
-                if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0) {
-                    chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
-                } else {
-                    chargingInfo[_index]->ChargingProfileCurrent = 0;
-                }
-
-                //DS60-120 remove
-                //PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
-                //chargingInfo[_index]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
-                //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * chargingInfo[_index]->EvBatterytargetVoltage / 100;
-
-                //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
-//              if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
-//              {
-//                  chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
-//              }
-            } else {
-                chargingInfo[_index]->ChargingProfilePower = -1;
-                chargingInfo[_index]->ChargingProfileCurrent = -1;
-            }
-        } else {
-            chargingInfo[_index]->ChargingProfilePower = -1;
-            chargingInfo[_index]->ChargingProfileCurrent = -1;
-        }
-
-        PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
-        PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
-    }
-//
-//      printf("-------------Schedule------------\n");
-//      printf("index = %d \n", _index);
-//      printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
-//      printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
-//      printf("----------SchedulePeriod---------\n");
-//      for (int v = 0; v < 10; v++)
-//      {
-//          printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
-//          printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
-//      }
-//      printf("---------------------------------\n");
-}
-
-void ChargingProfileFlat(byte _index)
-{
-    if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
-        if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
-            ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
-        }
-    }
-}
-
-void CheckReturnToChargingConn()
-{
-    if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG) {
-        bool isReturnTimeout = false;
-
-        for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
-            // 如果選的 DC 槍在充電~ 則 DC 槍不改變
-            if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-                if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
-                        (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                    isReturnTimeout = false;
-                    break;
-                }
-            } else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-                if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
-                        (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                    isReturnTimeout = true;
-                    StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-                }
-            }
-        }
-
-        // AC 槍
-        if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0) {
-            // 沒有選中 AC,且 AC 在充電中
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
-                    (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)) {
-                // 當前 DC 充電槍在 idle 狀態
-                if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
-                        chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION) {
-                    isReturnTimeout = true;
-                    StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-                }
-            } else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-                       ((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
-                        (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1))) {
-                // 當前 DC 充電槍在 idle 狀態
-                if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
-                        ac_chargingInfo[0]->SystemStatus == S_RESERVATION) {
-                    isReturnTimeout = true;
-                    StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-                }
-            }
-        }
-
-        if (!isReturnTimeout) {
-            StopSystemTimeoutDet();
-        }
-    }
-}
-
-bool GetStartChargingByAlterMode(byte _gun)
-{
-    bool result = true;
-
-    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
-            ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
-        for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++) {
-            if (_select != _gun) {
-                if (chargingInfo[_select]->SystemStatus != S_IDLE &&
-                        chargingInfo[_select]->SystemStatus != S_RESERVATION) {
-                    result = false;
-                    break;
-                }
-            }
-        }
-    }
-
-    return result;
-}
-
-void TheEndCharging(byte gun_index)
-{
-    ftime(&endChargingTime[gun_index]);
-    if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
-        chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-    }
-
-    chargingInfo[gun_index]->isRemoteStart = NO;
-
-    StopGunInfoTimeoutDet(gun_index);
-    StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
-    ChangeStartOrStopDateTime(NO, gun_index);
-    DB_Insert_Record(localDb, gun_index);
-}
-
-void UpdateErrorCodeToOcpp(byte index)
-{
-    uint8_t i = 0;
-
-    //if ((strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") == EQUAL) &&
-    //        (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") == EQUAL)
-    //   ) {
-    //    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-    //        if (strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012251", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012252", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012238", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042251", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042252", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042200", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042201", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042202", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == EQUAL) {
-    //            strncpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 6);
-    //            //log_info("1 %d = VendorErrorCode = %s\r\n", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
-    //            break;
-    //        }
-    //    }
-    //}
-
-    //log_info("%d = ConnectorAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->ConnectorAlarmCode);
-    //log_info("%d = EvConnAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->EvConnAlarmCode);
-    if (strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") != EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->ConnectorAlarmCode);
-    } else if (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") != EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->EvConnAlarmCode);
-    }
-
-    //log_info("2 %d = VendorErrorCode = %s\r\n", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
-}
-
-void AdjustChargerCurrent()
-{
-    ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
-
-    // 設定的電流~ 如超過可輸出的電流,則 bypass
-    if (ShmSysConfigAndInfo->SysConfig.RatingCurrent < ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent ||
-            ShmSysConfigAndInfo->SysConfig.RatingCurrent == 0) {
-        ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = 0;
-    }
-
-    PRINTF_FUNC ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
-                 ShmPsuData->SystemAvailablePower / 10,
-                 ShmPsuData->SystemAvailableCurrent / 10
-                );
-
-    PRINTF_FUNC ("Config : ChargingPower = %d, ChargingCurrent = %d",
-                 ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
-                 ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
-                );
-}
-
-#if METER_ENABLE
-void CheckStatusOfMeter()
-{
-    // 橋接如果搭上~ 則兩個電表都是使用狀態
-    // 如橋接沒有搭上~ 則視該火線 relay 狀態為電表使用狀態
-    if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
-        for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
-            ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
-        }
-    } else {
-        for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
-            if (chargingInfo[mIndex]->RelayKPK2Status == YES || chargingInfo[mIndex]->RelayK1K2Status) {
-                ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
-            } else {
-                ShmCsuMeterData->_meter[mIndex].isCalculation = NO;
-            }
-        }
-    }
-}
-
-void CheckRelayWeldingOrDrivingFault(byte gun_index)
-{
-    // relay welding fault then stop the charging process.
-    byte faultCode = RELAY_STATUS_ERROR_NONE;
-
-    if (gun_index == 0) {
-        if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
-                ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
-            faultCode = RELAY_STATUS_ERROR_WELDING;
-        } else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
-                   ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
-            faultCode = RELAY_STATUS_ERROR_DRIVING;
-        }
-    } else if (gun_index == 1) {
-        if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
-                ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
-            faultCode = RELAY_STATUS_ERROR_WELDING;
-        } else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
-                   ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
-            faultCode = RELAY_STATUS_ERROR_DRIVING;
-        }
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
-            !ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
-        // 橋接
-        if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
-                ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
-            faultCode = RELAY_STATUS_ERROR_WELDING;
-        } else if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
-                   ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
-            faultCode = RELAY_STATUS_ERROR_DRIVING;
-        }
-    }
-
-    if (faultCode == RELAY_STATUS_ERROR_WELDING) {
-        // welding
-        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
-        }
-
-        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
-        EmcOccureByString("");
-    } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
-        // driving
-        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
-        }
-
-        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
-        EmcOccureByString("");
-    } else {
-        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
-        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
-
-        bool isClear = false;
-        if (!relayDrivingCheck) {
-            if (chargingInfo[gun_index]->Type == _Type_Chademo &&
-                    ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_GB &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_CCS_2 &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
-            }
-        }
-
-
-        if (!relayWeldingCheck) {
-            if (chargingInfo[gun_index]->Type == _Type_Chademo &&
-                    ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_GB &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_CCS_2 &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
-            }
-        }
-
-        if (!relayDrivingCheck && !relayWeldingCheck && isClear) {
-            ReleaseChargingProcessByString(2);
-        }
-    }
-}
-
-bool PrecheckIsPass(byte gun_index)
-{
-    bool result = true;
-
-    // relay welding or driving 是反向
-    if (result) {
-        result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
-    }
-
-    return result;
-}
-#endif //METER_ENABLE
-
-void ResetDetAlarmStatus(byte gun)
-{
-    if (chargingInfo[gun]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
-        }
-    } else if (chargingInfo[gun]->Type == _Type_GB) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
-        }
-    } else if (chargingInfo[gun]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
-        }
-    }
-}
-
-static void powerCabinetPsuAlarmStatus(void)
-{
-    uint8_t i = 0;
-
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == 0) {
-            EmcOccureByString("042267");
-        }
-    }
-}
-
-static void autoStartChargingForComBox(uint8_t gunIndex)
-{
-#if defined DD360ComBox
-    if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
-            (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
-       ) {
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
-        strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
-    }
-#else
-    return;
-#endif //DD360ComBox
-}
-
-int main(void)
-{
-    uint8_t evBoardStopState = 0;
-
-    if (CreateShareMemory() == 0) {
-        log_error("CreatShareMemory NG\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-
-    log_info(" ****************  FileSystem Boot up ***************\n");
-    if (!InitialSystemDefaultConfig()) {
-        log_error("InitialSystemDefaultConfig NG \n");
-        //StopProcessingLoop();
-        sleep(5);
-        system("reboot -f");
-    }
-    CheckGunTypeFromHw();
-    CheckIsAlternatvieByModelName();
-    InitialShareMemoryInfo();
-    ChangeLcmByIndex(_LCM_INIT);
-    if (!CheckConnectorTypeStatus()) {
-        isModelNameMatch = false;
-    }
-
-    Initialization();
-    SpawnTask();
-    log_info("Spawned all Task");
-    if (!isModelNameMatch) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
-        ChangeLcmByIndex(_LCM_FIX);
-        // Module Name 與硬體對應不正確
-        log_error("Module Name & HW info none match. \n");
-        sleep(3);
-        KillAllTask();
-        StopProcessingLoop();
-    }
-    CreateTimeoutFork();
-    log_info("Start self test... \n");
-    startPrimaryLedIndicatorCtrlFork();
-    SelfTestRun();
-    StopSystemTimeoutDet();
-    log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
-             ShmSysConfigAndInfo->SysInfo.SelfTestSeq,
-             ShmPsuData->Work_Step);
-
-    if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
-            ShmPsuData->Work_Step == _NO_WORKING ||
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES //DS60-120 add
-       ) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
-            if (!DisplaySelfTestFailReason()) { //DS60-120 add
-                PRINTF_FUNC("Soft reboot for retry self-tets. \n");
-
-                sleep(3);
-                system("killall OcppBackend &");
-                KillAllTask();
-                system("/usr/bin/run_evse_restart.sh");
-            }
-        }
-
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_ALARM);
-        }
-        //ChangeLcmByIndex(_LCM_FIX);
-        sleep(3);
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) { //DS60-120 add
-            KillTaskExceptPrimary();
-        } else {
-            KillTask();
-        }
-        StopProcessingLoop();
-    } else {
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_IDLE);
-        }
-    }
-
-    // Local DB
-    if (DB_Open(localDb) != PASS) {
-        PRINTF_FUNC("DB_Open fail. \n");
-        isDb_ready = false;
-    } else {
-        isDb_ready = true;
-        for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-            chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
-        }
-        DB_Reboot_Record(localDb);
-    }
-    PRINTF_FUNC("===== Create DB End ===== \n");
-
-#if defined DD360Audi
-    ChangeLcmByIndex(_LCM_SELECT_GUN);
-#else
-    ChangeLcmByIndex(_LCM_IDLE);
-#endif //defined DD360Audi
-
-    sleep(1);
-    //***** 須新增的偵測 *****//
-    // 1. Thernal - 控制風扇轉速
-    // 2. ouput fuse - 控制風扇轉速
-    CreateRfidFork();
-    // Create Watchdog
-    //CreateWatchdog();
-    // Main loop
-
-    PRINTF_FUNC("===== Charger info ===== ");
-    PRINTF_FUNC("SW Version = %s", fwVersion);
-    PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
-    CheckFwSlotStatusLog();
-    AdjustChargerCurrent();
-    gettimeofday(&_cmdMainPriority_time, NULL);
-
-    for (;;) {
-        CheckOcppStatus();
-        ChkPrimaryStatus();
-        if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
-                ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet) {
-            CheckFactoryConfigFunction();
-
-            CheckFwUpdateFunction();
-        }
-
-        // OCPP 邏輯
-        OcppRemoteStartChk();
-        // 讀卡邏輯
-        ScannerCardProcess();
-        // 當 AC 沒有搭上時,清除一些錯誤碼
-        ClearAlarmCodeWhenAcOff();
-        // 確認是否要回到充電中的槍畫面邏輯判斷
-        CheckReturnToChargingConn();
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-        //確認Power cabinet PSU Status
-        powerCabinetPsuAlarmStatus();
-#endif // defined DD360 || defined DD360Audi
-
-        if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan) {
-            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
-        }
-
-        if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
-            CheckTask();
-
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                //if (chargingInfo[_index]->SystemStatus == S_CHARGING) {
-                //    CheckSmartChargeProfile(_index);
-                //}
-                if ((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                        chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
-                        (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                         chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                    if (chargingInfo[_index]->SystemStatus == S_CHARGING &&
-                            _ocppProfileChkFlag == 12) {
-                        ChargingProfileFlat(_index);
-                        _ocppProfileChkFlag = 0;
-                    } else if (chargingInfo[_index]->SystemStatus != S_CHARGING) {
-                        ChargingProfileFlat(_index);
-                        _ocppProfileChkFlag = 0;
-                    } else {
-                        _ocppProfileChkFlag++;
-                    }
-                }
-            }
-            gettimeofday(&_cmdMainPriority_time, NULL);
-        }
-
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            autoStartChargingForComBox(gun_index); //for DD360ComBox
-
-            CheckGpioInStatus();
-            CheckErrorOccurStatus(gun_index);
-            ChkOcppStatus(gun_index);
-
-            if ((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                    chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
-                    (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                     chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                CheckSmartChargeProfile(gun_index);
-            }
-
-            //PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
-            switch (chargingInfo[gun_index]->SystemStatus) {
-            case S_IDLE:
-                ReleaseAlarmCode(gun_index);
-
-                if (isModeChange(gun_index)) {
-                    log_info("S_IDLE================================== %x \n", gun_index);
-                    chargingInfo[gun_index]->PresentChargedDuration = 0;
-                    chargingInfo[gun_index]->RemainChargingDuration = 0;
-                    chargingInfo[gun_index]->PresentChargingVoltage = 0;//DS60-120 add
-                    chargingInfo[gun_index]->PresentChargingCurrent = 0;//DS60-120 add
-                    strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
-                    strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
-                    strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
-                    strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
-
-                    //Jerry add
-                    memset(&gAudiCustInfo->PricesInfo[gun_index], 0, sizeof(PricesInfo));
-                    gAudiCustInfo->PricesInfo[gun_index].Balance = FAIL_BALANCE_PRICES;
-#if defined DD360Audi
-                    destroySelGun(gun_index);
-#endif //defined DD360Audi
-                    ResetDetAlarmStatus(gun_index); //recovery OVP status code
-                    //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "");
-                }
-            case S_RESERVATION:
-                if (isModeChange(gun_index)) {
-                    log_info("S_RESERVATION....................%x \n", gun_index);
-                    ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
-                }
-
-                if (chargingInfo[gun_index]->IsAvailable == NO) {
-                    setChargerMode(gun_index, MODE_MAINTAIN);
-                }
-
-            case S_MAINTAIN:
-            case S_FAULT: {
-                if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                    if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
-                    } else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_IDLE &&
-                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_RESERVATION &&
-                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_MAINTAIN &&
-                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_FAULT) {
-                        if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING) {
-                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_COMPLETE;
-                        } else {
-#if defined DD360Audi
-                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-                        }
-                    }
-
-                    ClearDetectPluginFlag();
-//#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    UpdateErrorCodeToOcpp(gun_index);
-//#endif //!defined DD360 && !defined DD360Audi
-                    setChargerMode(gun_index, MODE_FAULT);
-                } else {
-#if 1
-                    if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
-#if defined DD360Audi
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-                        setChargerMode(gun_index, MODE_IDLE);
-                    }
-
-                    //if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX) {
-                    //    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;//_LCM_NONE; //Jerry add
-                    //    //for (byte g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++) {
-                    //    setChargerMode(gun_index, MODE_IDLE);
-                    //    //}
-                    //}
-#endif //0
-
-                    if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                        if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
-#else
-                        if (1)
-#endif //!defined DD360 && !defined DD360Audi
-                        {
-                            // 均充 -> 最大充
-                            if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
-                                if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE) {
-                                    log_info("=============Smart Charging============= Step 11 \n");
-                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
-                                }
-                            } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
-                                       ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
-                                log_info("=============Smart Charging============= Step 14 \n");
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
-                            } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
-                                ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                            }
-                        } else {
-                            ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                            ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                        }
-                    } else {
-                        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
-                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-#if defined DD360Audi
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
-#else
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
-#endif //
-                        }
-                    } else {
-                        // Idle 正常程序起點
-                        // 判斷是否有啟用檢查插槍
-                        if (isDetectPlugin()) {
-                            // 卡號驗證成功後,等待充電槍插入充電車
-                            if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
-                                if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
-                                        chargingInfo[gun_index]->IsAvailable) {
-                                    PRINTF_FUNC("-----------------1----------------- %d \n", gun_index);
-                                    chargingInfo[gun_index]->RemoteStartFlag = NO;
-                                    chargingInfo[gun_index]->isRemoteStart = YES; //DS60-120
-                                    ChangeGunSelectByIndex(gun_index);
-                                    AddPlugInTimes(gun_index);
-                                    setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                    strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
-                                    ClearDetectPluginFlag();
-                                    continue;
-                                }
-                            } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
-                                if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
-                                        chargingInfo[gun_index]->IsAvailable &&
-                                        chargingInfo[gun_index]->SystemStatus == S_IDLE
-#if defined DD360Audi
-                                        && (waitRightGunPlugIt(gun_index) == PASS ||
-                                            waitLeftGunPlugIt(gun_index) == PASS)
-#endif //defined DD360Audi
-                                   ) {
-                                    PRINTF_FUNC("-----------------2----------------- \n");
-                                    ChangeGunSelectByIndex(gun_index);
-                                    AddPlugInTimes(gun_index);
-                                    strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-                                    PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
-                                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                                    // 當前操作的槍號,進入 Preparing
-                                    setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                    ClearDetectPluginFlag();
-                                    continue;
-                                }
-                            }
-
-                            if (!isCardScan) {
-                                // LCM => Waiting for plugging
-                                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
-                            }
-                        } else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION) {
-                            if (!isReservationExpired(gun_index)) {
-                                chargingInfo[gun_index]->SystemStatus = S_IDLE;
-                            }
-                        } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
-                                   (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable)) {
-                            PRINTF_FUNC("-----------------3----------------- \n");
-                            bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
-
-                            if (isCanStartChargingFlag) {
-                                ChangeGunSelectByIndex(gun_index);
-                                AddPlugInTimes(gun_index);
-                                setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                ClearDetectPluginFlag();
-                                continue;
-                            }
-                        } else {
-                            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-#if defined DD360Audi
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
-#else
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
-#endif // defined DD360Audi
-                            }
-                        }
-                    } // Idle 正常程序終點
-                }
-            }
-            break;
-            case S_REASSIGN_CHECK: {
-                if (isModeChange(gun_index)) {
-                    log_info("S_REASSIGN_CHECK================================== %x \n", gun_index);
-#if defined DD360Audi
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-                    if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
-                        ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-                    }
-                    StopSystemTimeoutDet();
-                }
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                bool isRessign = false;
-                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
-                    if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
-                        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                            // 有其他槍已經分配好 psu 模塊
-                            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
-                                    chargingInfo[index]->SystemStatus >= S_PREPARNING &&
-                                    chargingInfo[index]->SystemStatus != S_MAINTAIN) {
-                                log_info("=============Smart Charging============= Step 1 \n");
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
-                                isRessign = true;
-                                break;
-                            }
-                        }
-                    } else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
-                               ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE) {
-                        // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
-                        if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
-                            if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
-                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
-                                log_info("=============Smart Charging============= Step 14 \n");
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
-                            } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
-                                ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                                continue;
-                            }
-                        }
-
-                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                        }
-                        continue;
-                    }
-                }
-#endif // !defined DD360 && !defined DD360Audi
-
-                if (0) { // if (isRessign)
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-                    setChargerMode(gun_index, MODE_PRECHARGE);
-#else
-                    setChargerMode(gun_index, MODE_REASSIGN);
-#endif //defined DD360 || defined DD360Audi
-                } else {
-                    setChargerMode(gun_index, MODE_PRECHARGE);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                }
-            }
-            break;
-            case S_REASSIGN: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
-                    gettimeofday(&_toAverage_time, NULL);
-                }
-
-                // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
-                // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
-                if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
-                        ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-                    if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging) {
-                        ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;//DS60-120 add
-                        setChargerMode(gun_index, MODE_PRECHARGE);
-                    } else {
-                        setChargerMode(gun_index, MODE_IDLE);
-                    }
-                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 add
-                } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
-                           ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
-                    PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
-                    ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                    //ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 remove
-                    ShmSysConfigAndInfo->SysInfo.CanAverageCharging = true; //DS60-120 add
-                }
-
-                //PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_PREPARNING: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
-                }
-
-                if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
-                        ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000) {
-                    //if ((chargingInfo[gun_index]->MaximumChargingVoltage > 0) && //DS60-120 remove
-                    //        (chargingInfo[gun_index]->AvailableChargingCurrent > 0) &&
-                    //        (chargingInfo[gun_index]->AvailableChargingPower > 0)) {
-                    setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
-                    //}
-                }
-
-                //DS60-120 add
-                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2) {
-                    bool oughtAver = true;
-                    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                        // 共同進入充電邏輯
-                        if (chargingInfo[index]->SystemStatus != S_PREPARNING) {
-                            oughtAver = false;
-                            break;
-                        }
-                    }
-
-                    if (oughtAver) {
-                        PRINTF_FUNC("********* Automatically change to aver mode ********** \n");
-                        ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_PREPARING_FOR_EV: { // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
-                if (isModeChange(gun_index)) {
-                    log_info("S_PREPARING_FOR_EV================================== %x \n", gun_index);
-                    //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
-                }
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    // 檢查車端的槍鎖是否為鎖上
-                    if (isEvGunLocked_chademo(gun_index) == YES) {
-                        setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    // 檢查車端的 charging enable 是否為 1
-                    if (isEvGunLocked_gb(gun_index) == YES) {
-                        setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    // 檢查車端的 charging enable 是否為 1
-                    if (isEvGunLocked_ccs(gun_index) == YES) {
-                        setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // LCM => Pre-charging
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_PREPARING_FOR_EVSE: { // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
-                if (isModeChange(gun_index)) {
-                    log_info("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
-                }
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8) {
-                        // 當前操作的槍號,進入 Charging
-                        setChargerMode(gun_index, MODE_CHARGING);
-                    }
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012234");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012296");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    // 檢查樁端的 GFD 結果
-                    //if (isPrechargeStatus_gb(gun_index) > 5 && isPrechargeStatus_gb(gun_index) < 9) {
-                    if (isPrechargeStatus_gb(gun_index) > 9) {
-                        setChargerMode(gun_index, MODE_CHARGING);
-                    }
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012236");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012298");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    // 檢查樁端的 GFD 結果
-                    if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
-                            chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)) {
-                        setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
-                    }
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012235");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012297");
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // LCM => Pre-charging
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_CHARGING: { // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
-                if (isModeChange(gun_index)) {
-                    log_info("S_CHARGING================================== %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    ftime(&startChargingTime[gun_index]);
-                    strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, ""); //DS60-120 add
-                    ChangeStartOrStopDateTime(YES, gun_index);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    OcppStartTransation(gun_index);
-#endif //!defined DD360 && !defined DD360Audi
-                }
-
-                if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf) {
-                    ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
-                }
-                ftime(&endChargingTime[gun_index]);
-                chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012234");
-                    }
-                    //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
-                    //    // UVP
-                    //    RecordAlarmCode(gun_index, "012289");
-                    //    ChargingTerminalProcess(gun_index);
-                    //}
-                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012296");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012236");
-                    }
-                    //else if (isPrechargeStatus_gb(gun_index) == 10 &&
-                    //           (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //            (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))) {
-                    //    // UVP
-                    //    RecordAlarmCode(gun_index, "012290");
-                    //    ChargingTerminalProcess(gun_index);
-                    //}
-                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012298");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012235");
-                    }
-                    //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
-                    //    // UVP
-                    //    RecordAlarmCode(gun_index, "012288");
-                    //    ChargingTerminalProcess(gun_index);
-                    //}
-                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012297");
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    //printf("%d evBoardStopState = %d\r\n", gun_index, evBoardStopState);
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index) ||
-                           CheckBackendChargingTimeout(gun_index) ||
-                           CheckBackendChargingEnergy(gun_index) ||
-                           strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
-
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // LCM => Charging
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_ALARM:
-            case S_TERMINATING: {
-                if (isModeChange(gun_index)) {
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
-                    }
-
-                    if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
-                        PRINTF_FUNC("================== S_ALARM (%x) ================ \n", gun_index);
-                        UpdateErrorCodeToOcpp(gun_index);
-
-                        if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
-                            OcppStopTransation(gun_index);
-                        }
-
-                        TheEndCharging(gun_index);
-                    } else {
-                        PRINTF_FUNC("================== S_TERMINATING (%x) ================ \n", gun_index);
-                    }
-
-                    //log_info ("terminating......................... %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                }
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gun_index) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                    //        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012234");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012296");
-                    }
-
-                    //if (isEvStopCharging_chademo(gun_index) == YES ||
-                    //        isPrechargeStatus_chademo(gun_index) <= 0) {
-                    //    setChargerMode(gun_index, MODE_COMPLETE);
-                    //}
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    //log_info("************ GB lock Status = %d, status = %d \n",
-                    //         isEvStopCharging_gb(gun_index),
-                    //         isPrechargeStatus_gb(gun_index));
-
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gun_index) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012236");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012298");
-                    }
-
-                    //if (isEvStopCharging_gb(gun_index) == YES ||
-                    //        isPrechargeStatus_gb(gun_index) <= 0) {
-                    //    setChargerMode(gun_index, MODE_COMPLETE);
-                    //}
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gun_index) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012235");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012297");
-                    }
-
-                    //if (isEvStopCharging_ccs(gun_index) == YES &&
-                    //        (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
-                    //         isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
-                    //    setChargerMode(gun_index, MODE_COMPLETE);
-                    //}
-                }
-
-                if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
-                    if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
-                            GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
-                        setChargerMode(gun_index, MODE_IDLE);
-                    }
-                } else {
-                    if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                        if (isEvStopCharging_chademo(gun_index) == YES ||
-                                isPrechargeStatus_chademo(gun_index) <= 0) {
-                            setChargerMode(gun_index, MODE_COMPLETE);
-                        }
-                    } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                        if (isEvStopCharging_gb(gun_index) == YES ||
-                                isPrechargeStatus_gb(gun_index) <= 0) {
-                            setChargerMode(gun_index, MODE_COMPLETE);
-                        }
-                    } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                        if (isEvStopCharging_ccs(gun_index) == YES &&
-                                (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
-                                 isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
-                            setChargerMode(gun_index, MODE_COMPLETE);
-                        }
-                    }
-                }
-
-                // 車端的停止
-                //if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                //    strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                //}
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_COMPLETE: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC ("complete......................... %x \n", gun_index);
-                    if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
-                        OcppStopTransation(gun_index);
-                    }
-
-                    TheEndCharging(gun_index);
-                    //ftime(&endChargingTime[gun_index]);
-                    //if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
-                    //    chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-                    //}
-
-                    //StopGunInfoTimeoutDet(gun_index);
-                    //StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
-                    //ChangeStartOrStopDateTime(NO, gun_index);
-                }
-
-                //if (((chargingInfo[gun_index]->ConnectorPlugIn == NO) ||
-                //        (restartFlag == 1)) &&
-                //        (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)) {
-                //    setChargerMode(gun_index, MODE_IDLE);
-                //    destroySelGun(gun_index); //Jerry add
-                //}
-
-                if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
-                        GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
-                    setChargerMode(gun_index, MODE_IDLE);
-#if defined DD360Audi
-                    destroySelGun(gun_index); //Jerry add
-#endif //defined DD360Audi
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_CCS_PRECHARGE_ST0: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
-                }
-
-                if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                    // GFD 錯誤停止
-                    RecordAlarmCode(gun_index, "012235");
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // 等待 EV 小板 (CCS) 通知可以開始 Precharge
-                // 切換 D+ Relay to Precharge Relay
-                if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40) {
-                    if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
-                        //if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
-                    {
-                        //PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
-                        if (isPrechargeStatus_ccs(gun_index) == 39) {
-                            PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
-                        } else if (isPrechargeStatus_ccs(gun_index) == 40) {
-                            PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
-                        }
-
-                        chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
-                    }
-                } else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46) {
-                    setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-                break;
-            }
-            case S_CCS_PRECHARGE_ST1: {
-                if (isModeChange(gun_index)) {
-                    log_info("CCS Precharge Processing 2....................%x \n", gun_index);
-                }
-
-                if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                    // GFD 錯誤停止
-                    RecordAlarmCode(gun_index, "012235");
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // 等待小板通知進入充電
-                // 切換 D+ Relay to Precharge Relay
-                if (chargingInfo[gun_index]->RelayK1K2Status == YES) {
-                    chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
-                    setChargerMode(gun_index, MODE_CHARGING);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-                break;
-            }
-            }
-        }
-
-#if defined DD360Audi
-        if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_SELECT_GUN) {
-#else
-        if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE) {
-#endif //defined DD360Audi
-            ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
-        } else {
-            bool dcPageRun = false;
-            if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                if  (ac_chargingInfo[0]->SystemStatus == S_IDLE) {
-                    ChangeLcmByIndex(_LCM_IDLE);
-                } else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING) {
-                    ChangeLcmByIndex(_LCM_PRE_CHARGE);
-                } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-                    ChangeLcmByIndex(_LCM_CHARGING);
-                } else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
-                           ac_chargingInfo[0]->SystemStatus == S_COMPLETE) {
-                    ChangeLcmByIndex(_LCM_COMPLETE);
-                } else {
-                    dcPageRun = true;
-                }
-            } else {
-                dcPageRun = true;
-            }
-
-            if (dcPageRun) {
-                ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
-            }
-        }
-
-        write(wtdFd, "a", 1);
-        usleep(whileLoopTime);
-    }
-
-    return FAIL;
-}

+ 60 - 49
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -6,44 +6,40 @@
  */
 
 
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    <stdbool.h>
-#include    "../../define.h"
-
-typedef unsigned char           byte;
-#define PASS                1
-#define FAIL                -1
-#define EQUAL               0
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define NO_DEFINE           255
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <stdint.h>
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+#include <stdbool.h>
+#include "../../define.h"
+#include "Config.h"
+
 #define DEFAULT_AC_INDEX    2
 
 #define AUTORUN_STEP1_TIME_START            140             // Minutes
@@ -57,8 +53,8 @@ typedef unsigned char           byte;
 #define STTY_US             "stty raw -echo -F "
 #define STTY_DEF            "stty -raw echo -F "
 
-byte _curAutoRunCount = 0;
-byte _usingAutoRun = 0;
+uint8_t _curAutoRunCount = 0;
+uint8_t _usingAutoRun = 0;
 struct timeval _autoTime;
 
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
@@ -84,23 +80,23 @@ char *msg = "state : get gun state (index) \n"
             "ver : ver of board (407 or index or rb or fan) \n"
             "ac : get ac relay state (x) \n";
 
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
             return true;
@@ -110,7 +106,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
     return false;
 }
 
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
+bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
 {
     if (target < AC_QUANTITY) {
         acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
@@ -525,8 +521,8 @@ void SetGFDMode(char *v1)
 
 void GetPsuTemp()
 {
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
             printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
         }
     }
@@ -566,7 +562,7 @@ void GetPsuInformation(char *v1, char *v2, char *v3)
         }
     } else if (strcmp(v1, "input") == 0) {
         for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
+            for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
                 printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
                        i, count,
                        ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
@@ -665,7 +661,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         _Current = atof(v3);
     }
 
-    unsigned char PreviousSystemStatus = 0xff;
+    uint8_t PreviousSystemStatus = 0xff;
     if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
         printf ("FindChargingInfoData error\n");
         return;
@@ -1099,6 +1095,21 @@ int main(void)
 
             // 槍狀態
             RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
+        } else if (strcmp(newString[0], "tempT") == 0) {
+
+            uint8_t _GunIndex = 0;
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                return 0;
+            }
+
+            if (strcmp(newString[1], "0") == 0) {
+                _chargingData[0]->ConnectorTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ConnectorTemp);
+            } else if (strcmp(newString[1], "1") == 0) {
+                _chargingData[1]->ConnectorTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
+            }
         } else {
             printf ("%s\n", msg);
         }

+ 1 - 1
EVSE/Projects/DD360/Apps/init.sh → EVSE/Projects/DD360/Apps/Script/init.sh

@@ -8,4 +8,4 @@ chmod 777 Module_PsuComm
 chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
-
+chmod 777 Module_DoComm

+ 40 - 0
EVSE/Projects/DD360/Apps/Script/kill.sh

@@ -0,0 +1,40 @@
+pkill Module_CSU;
+pkill Module_PrimaryComm;
+pkill Module_LcmControl;
+pkill Module_InternalComm;
+pkill Module_EventLogging;
+pkill Module_EvComm;
+pkill Module_PsuComm;
+pkill Module_4g;
+pkill Module_Wifi;
+pkill OcppBackend;
+pkill Module_ProduceUtils;
+pkill Module_DoComm;
+pkill main;
+
+ipcrm -M 0x000003e9;
+ipcrm -M 0x000003ed;
+ipcrm -M 0x000003ea;
+ipcrm -M 0x000003ec;
+ipcrm -M 0x000003ee;
+ipcrm -M 0x000003ef;
+ipcrm -M 0x000003f0;
+ipcrm -M 0x000003f3;
+ipcrm -M 0x000003f1;
+ipcrm -M 0x000003f6;
+
+ipcrm -M 0x000003e9;
+ipcrm -M 0x000003ed;
+ipcrm -M 0x000003ea;
+ipcrm -M 0x000003ec;
+ipcrm -M 0x000003ee;
+ipcrm -M 0x000003ef;
+ipcrm -M 0x000003f0;
+ipcrm -M 0x000003f3;
+ipcrm -M 0x000003f1;
+ipcrm -M 0x000003f6;
+ipcrm -M 0x000003eb;
+ipcrm -M 0x000003f2;
+ipcrm -M 0x000007d2;
+
+ipcs;

+ 0 - 0
EVSE/Projects/DD360/Apps/replaceOtherProject.sh → EVSE/Projects/DD360/Apps/Script/replaceOtherProject.sh


+ 0 - 0
EVSE/Projects/DD360/Apps/web.sh → EVSE/Projects/DD360/Apps/Script/web.sh


+ 19 - 16
EVSE/Projects/DD360/Apps/AudiCust.h → EVSE/Projects/DD360/Apps/SelectGun/SelectGun.h

@@ -1,28 +1,28 @@
-#ifndef _AUDI_CUSTOM_H_
-#define _AUDI_CUSTOM_H_
+#ifndef _SELECT_GUN_H_
+#define _SELECT_GUN_H_
 
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
 //--- //For Audi for Audi customization ---
 //------------------------------------------------------------------------------
-#define ShmAudiCustInfoKey                      1014
+#define ShmAudiCustInfoKey                      (1014)
 
-#define SEL_GUN_RELEASE                         0x00
-#define SEL_GUN_CONFIRM                         0x01
-#define SEL_GUN_ATHOR                           0x02
-#define SEL_GUN_PLUG_IT                         0x03
-//#define SEL_GUN_CHARGING                        0x04
-//#define SEL_GUN_CHARGING_COMP                   0x05
+#define SEL_GUN_RELEASE                         (0x00)
+#define SEL_GUN_CONFIRM                         (0x01)
+#define SEL_GUN_ATHOR                           (0x02)
+#define SEL_GUN_PLUG_IT                         (0x03)
+//#define SEL_GUN_CHARGING                        (0x04)
+//#define SEL_GUN_CHARGING_COMP                   (0x05)
 
-#define LEFT_GUN_NUM                            0
-#define RIGHT_GUN_NUM                           1
+#define LEFT_GUN_NUM                            (0)
+#define RIGHT_GUN_NUM                           (1)
 
-#define SEL_GUN_TIMEOUT                         120
+#define SEL_GUN_TIMEOUT                         (120)
 
-#define DESTROY_ALL_SEL                         0x03
+#define DESTROY_ALL_SEL                         (0x03)
 
-#define FAIL_BALANCE_PRICES                     -65535.00
+#define FAIL_BALANCE_PRICES                     (-65535.00)
 
 //------------------------------------------------------------------------------
 //--- remote control ---
@@ -79,11 +79,12 @@ typedef struct StPricesInfo {
 
 typedef struct StRemoteSetup {
     //uint8_t Execution;
+    uint8_t BtnStopCharging;
     uint16_t ConnectionTimeout;
     //float DefaultPrices;
     //OperativeInfo Operative;
     //StartCharge StartCharge;
-    uint8_t Reserved[2];
+    uint8_t Reserved;
 } RemoteSetup;
 
 typedef struct StAudiCustInfo {
@@ -91,6 +92,8 @@ typedef struct StAudiCustInfo {
     PricesInfo PricesInfo[2];
     RemoteSetup RemoteSetup;
     EthDevStatus EthDevStatus;
+    uint8_t AuthorStateFromCabinet;
+    uint8_t Reserved[3];
 } AudiCustInfo;
 
-#endif /* _AUDI_CUSTOM_H_ */
+#endif /* _SELECT_GUN_H_ */

BIN
EVSE/Projects/DD360/Apps/UnsafetyOutputTask


+ 60 - 0
EVSE/Projects/DD360/Apps/common.c

@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "Config.h"
+
+//------------------------------------------------------------------------------
+void trim(char *s)
+{
+    int i = 0, j, k, l = 0;
+
+    while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
+        i++;
+    }
+
+    j = strlen(s) - 1;
+    while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
+        j--;
+    }
+
+    if (i == 0 && j == strlen(s) - 1) { }
+    else if (i == 0) { s[j + 1] = '\0'; }
+    else {
+        for (k = i; k <= j; k++) { s[l++] = s[k]; }
+        s[l] = '\0';
+    }
+}
+
+int mystrcmp(char *p1, char *p2)
+{
+    while (*p1 == *p2) {
+        if (*p1 == '\0' || *p2 == '\0') {
+            break;
+        }
+        p1++;
+        p2++;
+    }
+    if (*p1 == '\0' && *p2 == '\0') {
+        return (PASS);
+    } else {
+        return (FAIL);
+    }
+}
+
+void substr(char *dest, const char *src, uint32_t start, uint32_t cnt)
+{
+    strncpy(dest, src + start, cnt);
+    dest[cnt] = 0;
+}
+
+void split(char **arr, char *str, const char *del)
+{
+    char *s = strtok(str, del);
+
+    while (s != NULL) {
+        *arr++ = s;
+        s = strtok(NULL, del);
+    }
+}

+ 13 - 0
EVSE/Projects/DD360/Apps/common.h

@@ -0,0 +1,13 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+void trim(char *s);
+int mystrcmp(char *p1, char *p2);
+void substr(char *dest, const char *src, uint32_t start, uint32_t cnt);
+void split(char **arr, char *str, const char *del);
+
+#endif /* _COMMON_H_ */

+ 0 - 276
EVSE/Projects/DD360/Apps/internalComm.h

@@ -1,276 +0,0 @@
-/*
- * internalComm.h
- *
- *  Created on: 2019¦~5¤ë7¤é
- *      Author: foluswen
- */
-
-#ifndef INTERNALCOMM_H_
-#define INTERNALCOMM_H_
-
-extern struct Address
-{
-	unsigned char Aux;
-	unsigned char Fan;
-	unsigned char Relay;
-	unsigned char AcPlug;
-	unsigned char Led;
-	unsigned char Broadcast;
-}Addr;
-
-extern struct Command
-{
-	unsigned char query_FW_Ver; 				//0x01
-	unsigned char query_HW_Ver; 				//0x02
-	unsigned char query_Present_InputVoltage;	//0x03
-	unsigned char query_Present_OutputVoltage;	//0x04
-	unsigned char query_Fan_Speed;				//0x05
-	unsigned char query_Temperature;			//0x06
-	unsigned char query_Aux_PowerVoltage;		//0x07
-	unsigned char query_Relay_Output;			//0x08
-	unsigned char query_Gfd_Adc;				//0x09
-	unsigned char query_Gpio_In;				//0x0a
-
-	unsigned char query_Model_Name;				//0x24
-	unsigned char query_ac_output_current;		//0x27
-	unsigned char query_ac_status;				//0x28
-	unsigned char query_ac_alarm_code;			//0x29
-
-	unsigned char query_ac_output_energy;		//0x2C
-
-	unsigned char config_Fan_Speed;			//0x81
-	unsigned char config_Model_Name;			//0x83
-	unsigned char config_Relay_Output;			//0x85
-	unsigned char config_Gpio_Output;			//0x86
-	unsigned char config_Rtc_Data;				//0x87
-	unsigned char config_ac_led_status;			//0x88
-
-	unsigned char config_ac_duty;			//0x89
-	unsigned char config_Legacy_Req;		//0x8A
-	unsigned char config_Gfd_Value;			//0x8B
-	unsigned char config_reset_mcu;			//0x8C
-
-	unsigned char config_csu_mode;			//0x90
-
-	unsigned char config_led_color;			//0x93
-
-	unsigned char update_Start;				//0xe0
-	unsigned char update_Abort;				//0xe1
-	unsigned char update_Transfer;				//0xe2
-	unsigned char update_Finish;				//0xe3
-
-}Cmd;
-
-typedef struct Verion
-{
-	char Version_FW[9];
-	char Version_HW[9];
-}Ver;
-
-typedef struct PRESENTINPUTVOLTAGE
-{
-	unsigned char inputType;	// 0x00: Line to Line       0x01: Line to Neutral
-	double L1N_L12;
-	double L2N_L23;
-	double L3N_L31;
-}PresentInputVoltage;
-
-typedef struct PRESENTOUTPUTVOLTAGE
-{
-	double behindFuse_Voltage_C1;
-	double behindRelay_Voltage_C1;
-	double behindFuse_Voltage_C2;
-	double behindRelay_Voltage_C2;
-}PresentOutputVoltage;
-
-typedef struct FANSPEED
-{
-	unsigned short int speed[8];
-}FanSpeed;
-
-typedef struct TEMPERATURE
-{
-	unsigned char temperature[8];
-}Temperature;
-
-typedef struct AUXPOWER
-{
-	unsigned char voltage[8];
-}AuxPower;
-
-typedef struct RELAY
-{
-	union
-	{
-		unsigned char relay_status[8];
-		struct
-		{
-			unsigned char AC_Contactor :1;		//bit 0
-			unsigned char CCS_Precharge :1;	//bit 1
-			unsigned char :1;  				//bit 2 reserved
-			unsigned char :1;					//bit 3 reserved
-			unsigned char :1;					//bit 4 reserved
-			unsigned char :1;					//bit 5 reserved
-			unsigned char :1;					//bit 6 reserved
-			unsigned char :1;					//bit 7 reserved
-
-			unsigned char Gun1_N :1;			//bit 0
-			unsigned char Gun1_P :1;			//bit 1
-			unsigned char Gun1_Parallel_N :1;  //bit 2
-			unsigned char Gun1_Parallel_P :1;	//bit 3
-			unsigned char :1;					//bit 4 reserved
-			unsigned char :1;					//bit 5 reserved
-			unsigned char :1;					//bit 6 reserved
-			unsigned char :1;					//bit 7 reserved
-
-			unsigned char Gun2_N :1;			//bit 0
-			unsigned char Gun2_P :1;			//bit 1
-			unsigned char :1; 					//bit 2 reserved
-			unsigned char :1;					//bit 3 reserved
-			unsigned char :1;					//bit 4 reserved
-			unsigned char :1;					//bit 5 reserved
-			unsigned char :1;					//bit 6 reserved
-			unsigned char :1;					//bit 7 reserved
-		}bits;
-	}relay_event;
-}Relay;
-
-typedef struct GFD
-{
-	unsigned short Resister_conn1;
-	unsigned short voltage_conn1;
-	unsigned char result_conn1;
-	unsigned char rb_step_1;
-
-	unsigned short Resister_conn2;
-	unsigned short voltage_conn2;
-	unsigned char result_conn2;
-	unsigned char rb_step_2;
-}Gfd;
-
-typedef struct Gfd_CONFIG
-{
-	unsigned char index;
-	unsigned char state;
-}Gfd_config;
-
-typedef struct GPIO_IN
-{
-	unsigned char AC_Connector;			// bit 0
-	unsigned char AC_MainBreaker;			// bit 1
-	unsigned char SPD;						// bit 2
-	unsigned char Door_Open;				// bit 3
-	unsigned char GFD[2];					// bit 4,5
-	unsigned char AC_Drop;					// bit 6
-
-	unsigned char Emergency_IO;			// bit 0
-
-	unsigned char Button_Emergency_Press;	// bit 0
-	unsigned char Button_On_Press;			// bit 1
-	unsigned char Button_Off_Press;		// bit 2
-	unsigned char Key_1_Press;				// bit 3
-	unsigned char Key_2_Press;				// bit 4
-	unsigned char Key_3_Press;				// bit 5
-	unsigned char Key_4_Press;				// bit 6
-}Gpio_in;
-
-typedef struct GPIO_OUT
-{
-	unsigned char AC_Connector;
-	unsigned char Button_LED[2];
-	unsigned char System_LED[4];
-}Gpio_out;
-
-typedef struct RTC
-{
-	unsigned char RtcData[14];
-}Rtc;
-
-typedef struct LED_Color
-{
-	unsigned char Connect_1_Red;
-	unsigned char Connect_1_Green;
-	unsigned char Connect_1_Blue;
-	unsigned char Connect_2_Red;
-	unsigned char Connect_2_Green;
-	unsigned char Connect_2_Blue;
-}Led_Color;
-
-typedef struct AC_Status
-{
-	unsigned char 		CpStatus;
-	unsigned short 		CurLimit;
-	short				PilotVol_P;
-	short				PilotVol_N;
-	unsigned char		LockStatus;
-	unsigned char		RelayStatus;
-	unsigned char		ShutterStatus;
-	unsigned char 		MeterStatus;
-	unsigned char 		PpStatus;
-	unsigned char 		MaxCurrent;
-	unsigned char		RotateSwitchStatus;
-}
-Ac_Status;
-
-typedef struct AC_LED_Status
-{
-	unsigned char 		ActionMode;
-	unsigned long		AcAlarmCode;
-}
-Ac_Led_Status;
-
-typedef struct AC_Alarm_Code
-{
-	unsigned int		AcAlarmCode;
-}
-Ac_Alarm_code;
-
-typedef struct AC_Charging_Energy
-{
-	unsigned int		Energy;
-}
-Ac_Charging_energy;
-
-typedef struct AC_Charging_Current
-{
-	unsigned short		OuputCurrentL1;
-	unsigned short		OuputCurrentL2;
-	unsigned short		OuputCurrentL3;
-}
-Ac_Charging_current;
-
-extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf);
-extern unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf);
-extern unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf);
-extern unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf);
-extern unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf);
-extern unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf);
-extern unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf);
-extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
-extern unsigned char Query_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
-
-extern unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf);
-extern unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf);
-extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
-extern unsigned char Config_Gfd_Value(unsigned char fd, unsigned char targetAddr, Gfd_config *Set_Buf);
-extern unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
-extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
-
-extern unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32);
-extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
-extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
-extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
-
-extern unsigned char Query_AC_Status(unsigned char fd, unsigned char targetAddr, Ac_Status *Ret_Buf);
-extern unsigned char Query_AC_Alarm_Code(unsigned char fd, unsigned char targetAddr, Ac_Alarm_code *Ret_Buf);
-extern unsigned char Query_Charging_Energy(unsigned char fd, unsigned char targetAddr, Ac_Charging_energy *Ret_Buf);
-extern unsigned char Query_Charging_Current(unsigned char fd, unsigned char targetAddr, Ac_Charging_current *Ret_Buf);
-extern unsigned char Config_LED_Status(unsigned char fd, unsigned char targetAddr, Ac_Led_Status *Ret_Buf);
-extern unsigned char Config_Legacy_Req(unsigned char fd, unsigned char targetAddr, unsigned char _switch);
-extern unsigned char Config_Ac_Duty(unsigned char fd, unsigned char targetAddr, unsigned char _value);
-extern unsigned char Config_CSU_Mode(unsigned char fd, unsigned char targetAddr);
-extern unsigned char Config_Reset_MCU(unsigned char fd, unsigned char targetAddr);
-extern unsigned char Config_Led_Color(unsigned char fd, unsigned char targetAddr, Led_Color *Ret_Buf);
-#endif /* INTERNALCOMM_H_ */

+ 0 - 39
EVSE/Projects/DD360/Apps/kill.sh

@@ -1,39 +0,0 @@
-pkill Module_CSU
-pkill Module_PrimaryComm
-pkill Module_LcmControl
-pkill Module_InternalComm
-pkill Module_EventLogging
-pkill Module_EvComm
-pkill Module_PsuComm
-pkill Module_4g
-pkill Module_Wifi
-pkill OcppBackend
-pkill Module_ProduceUtils
-pkill DoComm
-pkill main
-
-ipcrm -M 0x000003e9
-ipcrm -M 0x000003ed
-ipcrm -M 0x000003ea
-ipcrm -M 0x000003ec
-ipcrm -M 0x000003ee
-ipcrm -M 0x000003ef
-ipcrm -M 0x000003f0
-ipcrm -M 0x000003f3
-ipcrm -M 0x000003f1
-ipcrm -M 0x000003f6
-
-ipcrm -M 0x000003e9
-ipcrm -M 0x000003ed
-ipcrm -M 0x000003ea
-ipcrm -M 0x000003ec
-ipcrm -M 0x000003ee
-ipcrm -M 0x000003ef
-ipcrm -M 0x000003f0
-ipcrm -M 0x000003f3
-ipcrm -M 0x000003f1
-ipcrm -M 0x000003f6
-ipcrm -M 0x000003eb
-ipcrm -M 0x000003f2
-
-ipcs

Різницю між файлами не показано, бо вона завелика
+ 710 - 210
EVSE/Projects/DD360/Apps/main.c


+ 63 - 0
EVSE/Projects/DD360/Apps/main.h

@@ -0,0 +1,63 @@
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+//------------------------------------------------------------------------------
+#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 SYSFS_GPIO_DIR                          "/sys/class/gpio"
+#define UPGRADE_FAN                             0x02
+#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+#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 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 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)
+#define log_error(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
+typedef struct StLedConfig {
+    //OutputDrvValue[0]
+    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
+    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
+    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+    uint8_t Reserved: 1;                        //bit 7 reserved
+} LedConfig;
+
+#endif /* _MAIN_H_ */

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

@@ -59,5 +59,6 @@ unsigned short _connectionTimeout;
 // for main
 struct timeval _cmdMainPriority_time;
 struct timeval _toAverage_time;
-unsigned char _ocppProfileChkFlag;
+//uint8_t _ocppProfileChkFlag;
+
 #endif /* TIMEOUT_H_ */

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


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


+ 1 - 1
EVSE/Projects/DD360/output/init.sh

@@ -8,4 +8,4 @@ chmod 777 Module_PsuComm
 chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
-
+chmod 777 Module_DoComm

+ 1 - 1
EVSE/Projects/DD360/output/kill.sh

@@ -9,7 +9,7 @@ pkill Module_4g
 pkill Module_Wifi
 pkill OcppBackend
 pkill Module_ProduceUtils
-pkill DoComm
+pkill Module_DoComm
 pkill main
 
 ipcrm -M 0x000003e9

BIN
EVSE/Projects/DD360/output/main


+ 199 - 120
EVSE/Projects/DD360Audi/Apps/Config.h

@@ -7,49 +7,86 @@
 #ifndef CONFIG_H_
 #define CONFIG_H_
 
-#define ShmCsuMeterKey          2001
-#define ShmCommonKey            2002
-
-typedef unsigned char           byte;
-
-#define TOTAL_QUANTITY_GUN          4               //Max Count
-
-#define MODE_BOOT                   0
-#define MODE_IDLE                   1
-#define MODE_AUTHORIZING            2
-#define MODE_REASSIGN_CHECK         3
-#define MODE_REASSIGN               4
-#define MODE_PRECHARGE              5
-#define MODE_PREPARE_FOR_EV         6
-#define MODE_PREPARE_FOR_EVSE       7
-#define MODE_CHARGING               8
-#define MODE_TERMINATING            9
-#define MODE_COMPLETE               10
-#define MODE_ALARM                  11
-#define MODE_FAULT                  12
-#define MODE_RESERVATION            13
-#define MODE_BOOKING                14
-#define MODE_MAINTAIN               15
-#define MODE_DEBUG                  16
-#define MODE_CCS_PRECHARGE_STEP0    17  // ready for ccs precharge processing, For D+ relay to precharge relay
-#define MODE_CCS_PRECHARGE_STEP1    18  // waitting for ev board inform to enter to charging, For precharge relay to D+ relay
-#define MODE_UPDATE                 19
-
-#define GFD_WAIT            0
-#define GFD_PASS            1
-#define GFD_FAIL            2
-#define GFD_WARNING         3
-
-#define PRECHARGE_WAIT              0
-#define PRECHARGE_READY             1
-#define PRECHARGE_PRERELAY_PASS     2
-#define PRECHARGE_CHARELAY_PASS     3
-
-#define BOOTTING            0
-#define BOOT_COMPLETE       1
-
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//independent common share memory key
+//------------------------------------------------------------------------------
+#define ShmCsuMeterKey                          2001
+#define ShmCommonKey                            2002
+
+//------------------------------------------------------------------------------
+#define TOTAL_QUANTITY_GUN                      4               //Max Count
+
+//------------------------------------------------------------------------------
+//system  runtime state
+//------------------------------------------------------------------------------
+#define MODE_BOOT                               (0)
+#define MODE_IDLE                               (1)
+#define MODE_AUTHORIZING                        (2)
+#define MODE_REASSIGN_CHECK                     (3)
+#define MODE_REASSIGN                           (4)
+#define MODE_PRECHARGE                          (5)
+#define MODE_PREPARE_FOR_EV                     (6)
+#define MODE_PREPARE_FOR_EVSE                   (7)
+#define MODE_CHARGING                           (8)
+#define MODE_TERMINATING                        (9)
+#define MODE_COMPLETE                           (10)
+#define MODE_ALARM                              (11)
+#define MODE_FAULT                              (12)
+#define MODE_RESERVATION                        (13)
+#define MODE_BOOKING                            (14)
+#define MODE_MAINTAIN                           (15)
+#define MODE_DEBUG                              (16)
+#define MODE_CCS_PRECHARGE_STEP0                (17)  // ready for ccs precharge processing, For D+ relay to precharge relay
+#define MODE_CCS_PRECHARGE_STEP1                (18)  // waitting for ev board inform to enter to charging, For precharge relay to D+ relay
+#define MODE_UPDATE                             (19)
+
+#define GFD_WAIT                                (0)
+#define GFD_PASS                                (1)
+#define GFD_FAIL                                (2)
+#define GFD_WARNING                             (3)
+
+#define PRECHARGE_WAIT                          (0)
+#define PRECHARGE_READY                         (1)
+#define PRECHARGE_PRERELAY_PASS                 (2)
+#define PRECHARGE_CHARELAY_PASS                 (3)
+
+#define BOOTTING                                (0)
+#define BOOT_COMPLETE                           (1)
+
+//------------------------------------------------------------------------------
+//common define
+//------------------------------------------------------------------------------
+#define ARRAY_SIZE(A)                           (sizeof(A) / sizeof(A[0]))
+
+#define PASS                                    (1)
+#define FAIL                                    (-1)
+
+#define START                                   (1)
+#define STOP                                    (0)
+
+#define YES                                     (1)
+#define NO                                      (0)
+
+#define NORMAL                                  (0)
+#define ABNORMAL                                (1)
+
+#define EQUAL                                   (0)
+
+#define NO_DEFINE                               (255)
+
+//------------------------------------------------------------------------------
+//gun temperatures
+//------------------------------------------------------------------------------
+#define GUN_OTP_VALUE                           150
+#define GUN_OTP_RECOVERY                        140
+#define UNDEFINED_TEMP                          255
+
+//------------------------------------------------------------------------------
 enum _SYSTEM_STATUS {
-    S_BOOTING =                         0,
+    S_BOOTING = 0,
     S_IDLE,
     S_AUTHORIZING,
     S_REASSIGN_CHECK,
@@ -73,7 +110,7 @@ enum _SYSTEM_STATUS {
 };
 
 enum _AC_SYSTEM_STATUS {
-    AC_SYS_NONE =   0,
+    AC_SYS_NONE = 0,
     AC_SYS_A,
     AC_SYS_B,
     AC_SYS_C,
@@ -82,159 +119,201 @@ enum _AC_SYSTEM_STATUS {
 };
 
 enum _GUN_TYPE {
-    _Type_Chademo =         0,
+    _Type_Chademo = 0,
     _Type_CCS_2,
     _Type_GB,
     _Type_AC,
 };
 
 enum _LCM_INDEX {
-    _LCM_INIT =             0x00,
-    _LCM_IDLE =             0x01,
-    _LCM_AUTHORIZING =      0x02,
-    _LCM_AUTHORIZ_COMP =    0x03,
-    _LCM_AUTHORIZ_FAIL =    0x04,
-    _LCM_WAIT_FOR_PLUG =    0x05,
-    _LCM_PRE_CHARGE =       0x06,
-    _LCM_CHARGING =         0x07,
-    _LCM_COMPLETE =         0x08,
-    _LCM_FIX =              0x09,
-    _LCM_SELECT_GUN =       0x0A,
-    _LCM_NONE =             0xFF,
+    _LCM_INIT          = 0x00,
+    _LCM_IDLE          = 0x01,
+    _LCM_AUTHORIZING   = 0x02,
+    _LCM_AUTHORIZ_COMP = 0x03,
+    _LCM_AUTHORIZ_FAIL = 0x04,
+    _LCM_WAIT_FOR_PLUG = 0x05,
+    _LCM_PRE_CHARGE    = 0x06,
+    _LCM_CHARGING      = 0x07,
+    _LCM_COMPLETE      = 0x08,
+    _LCM_FIX           = 0x09,
+    _LCM_SELECT_GUN    = 0x0A,
+    _LCM_NONE          = 0xFF,
 };
 
 enum _SELF_TEST_SEQ {
-    _STEST_VERSION = 0x00,
+    _STEST_VERSION      = 0x00,
     _STEST_AC_CONTACTOR = 0x01,
-    _STEST_PSU_DETECT = 0x02,
-    _STEST_PSU_CAP = 0x03,
-    _STEST_FAIL = 0x04,
-    _STEST_COMPLETE = 0xEE,
+    _STEST_PSU_DETECT   = 0x02,
+    _STEST_PSU_CAP      = 0x03,
+    _STEST_FAIL         = 0x04,
+    _STEST_COMPLETE     = 0xEE,
 };
 
 enum _MODULE_PSU_WORK_STEP {
-    INITIAL_START       =       0,
-    GET_PSU_COUNT       =       1,
-    GET_SYS_CAP         =       2,
-    BOOTING_COMPLETE    =       3,
+    INITIAL_START    = 0,
+    GET_PSU_COUNT    = 1,
+    GET_SYS_CAP      = 2,
+    BOOTING_COMPLETE = 3,
 
-    _WORK_CHARGING      =       10,
+    _WORK_CHARGING   = 10,
 
-    _TEST_MODE          =       20,
+    _TEST_MODE       = 20,
 
-    _NO_WORKING         =       254,
-    _INIT_PSU_STATUS    =       255
+    _NO_WORKING      = 254,
+    _INIT_PSU_STATUS = 255,
 };
 
 enum _OFFLINE_POLICY {
-    _OFFLINE_POLICY_LOCAL_LIST = 0x00,
+    _OFFLINE_POLICY_LOCAL_LIST       = 0x00,
     _OFFLINE_POLICY_PHIHONG_RFID_TAG = 0x01,
-    _OFFLINE_POLICY_FREE_CHARGING = 0x02,
-    _OFFLINE_POLICY_NO_CHARGING = 0x03,
+    _OFFLINE_POLICY_FREE_CHARGING    = 0x02,
+    _OFFLINE_POLICY_NO_CHARGING      = 0x03,
 };
 
 enum _REASSIGNED_RESOURCE_STEP {
-    _REASSIGNED_NONE =              0,  //
-    _REASSIGNED_PREPARE_M_TO_A =    1,  // 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
-    _REASSIGNED_GET_NEW_CAP =       2,  // 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
-    _REASSIGNED_ADJUST_M_TO_A =     3,  // 模塊重新分配完成
-    _REASSIGNED_RELAY_M_TO_A =      4,  // 切斷橋接的 Relay
-
-    _REASSIGNED_PREPARE_A_TO_M =    11,
-    _REASSIGNED_ADJUST_A_TO_M =     12, // 模塊升壓
-    _REASSIGNED_RELAY_A_TO_M =      13, // 搭接橋接的 Relay
-    _REASSIGNED_WAITING =           14,
-    _REASSIGNED_COMP =              15
+    _REASSIGNED_NONE           = 0,  //
+    _REASSIGNED_PREPARE_M_TO_A = 1,  // 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
+    _REASSIGNED_GET_NEW_CAP    = 2,  // 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
+    _REASSIGNED_ADJUST_M_TO_A  = 3,  // 模塊重新分配完成
+    _REASSIGNED_RELAY_M_TO_A   = 4,  // 切斷橋接的 Relay
+
+    _REASSIGNED_PREPARE_A_TO_M = 11,
+    _REASSIGNED_ADJUST_A_TO_M  = 12, // 模塊升壓
+    _REASSIGNED_RELAY_A_TO_M   = 13, // 搭接橋接的 Relay
+    _REASSIGNED_WAITING        = 14,
+    _REASSIGNED_COMP           = 15,
 };
 
 enum _MAIN_CHARGING_MODE {
-    _MAIN_CHARGING_MODE_MAX = 0,
+    _MAIN_CHARGING_MODE_MAX  = 0,
     _MAIN_CHARGING_MODE_AVER = 1,
 };
 
 enum _EXTRA_ERR_PROCESS {
-    _EXTRA_ERR_PROCESS_NONE = 0,
+    _EXTRA_ERR_PROCESS_NONE  = 0,
     _EXTRA_ERR_PROCESS_INUVP = 1,
-    _EXTRA_ERR_PROCESS_INOVP = 2
+    _EXTRA_ERR_PROCESS_INOVP = 2,
 };
 
 enum _CHARGER_TYPE {
     _CHARGER_TYPE_IEC = 0,
-    _CHARGER_TYPE_UL = 1,
+    _CHARGER_TYPE_UL  = 1,
 };
 
 enum _SYS_WIFI_MODE {
     _SYS_WIFI_MODE_DISABLE = 0,
     _SYS_WIFI_MODE_STATION = 1,
-    _SYS_WIFI_MODE_AP = 2
+    _SYS_WIFI_MODE_AP      = 2,
 };
 
 enum _LED_INTENSITY_LV {
     _LED_INTENSITY_DARKEST   = 0,
     _LED_INTENSITY_MEDIUM    = 1,
-    _LED_INTENSITY_BRIGHTEST = 2
+    _LED_INTENSITY_BRIGHTEST = 2,
 };
 
 enum _CCS_COMM_PROTOCOL {
-    _CCS_COMM_V2GMessage_DIN70121       = 0x01,
-    _CCS_COMM_V2GMessage_ISO15118_2014  = 0x02,
-    _CCS_COMM_V2GMessage_ISO15118_2018  = 0x03
+    _CCS_COMM_V2GMessage_DIN70121      = 0x01,
+    _CCS_COMM_V2GMessage_ISO15118_2014 = 0x02,
+    _CCS_COMM_V2GMessage_ISO15118_2018 = 0x03
 };
 
 enum _ETHERNET_USAGE {
-    _ETHERNET_USAGE_NONE    = 0,
+    _ETHERNET_USAGE_NONE = 0,
     _ETHERNET_USAGE_LAN,
     _ETHERNET_USAGE_WIFI,
-    _ETHERNET_USAGE_3G_4g
+    _ETHERNET_USAGE_3G_4g,
 };
 
 enum _PRIMARY_CHECK_TAG {
-    _PRIMARY_CHECK_TAG_AC_CONTACT       = 0,
-    _PRIMARY_CHECK_TAG_MAIN_BREAKER     = 1,
+    _PRIMARY_CHECK_TAG_AC_CONTACT   = 0,
+    _PRIMARY_CHECK_TAG_MAIN_BREAKER = 1,
+};
+
+enum _CCS_VERSION_CHECK_TAG {
+    _CCS_VERSION_CHECK_TAG_V015S0 = 0,
+    _CCS_VERSION_CHECK_TAG_V013S0 = 1,
+};
+
+enum RELAY_STATUS_ERROR_INDEX {
+    RELAY_SMR1_P_STATUS = 0,
+    RELAY_SMR1_N_STATUS = 1,
+    RELAY_SMR2_P_STATUS = 2,
+    RELAY_SMR2_N_STATUS = 3,
+    RELAY_PARA_P_STATUS = 4,
+    RELAY_PARA_N_STATUS = 5,
+};
+
+enum RELAY_STATUS_ERROR_TYPE {
+    RELAY_STATUS_ERROR_NONE    = 0,
+    RELAY_STATUS_ERROR_WELDING = 10,
+    RELAY_STATUS_ERROR_DRIVING = 11,
 };
 
+//------------------------------------------------------------------------------
 struct StructMeter {
     float curMeterValue;
     float newMeterValue;
-    byte isCalculation;
+    uint8_t isCalculation;
     float _chargingValue;
     float _curTotalCharging;
 };
 
 struct MeterInformation {
     struct StructMeter _meter[2];
-    byte isWorking;
-};
-
-enum _CCS_VERSION_CHECK_TAG {
-    _CCS_VERSION_CHECK_TAG_V015S0       = 0,
-    _CCS_VERSION_CHECK_TAG_V013S0       = 1,
-};
-
-enum RELAY_STATUS_ERROR_INDEX {
-    RELAY_SMR1_P_STATUS =   0,
-    RELAY_SMR1_N_STATUS =   1,
-    RELAY_SMR2_P_STATUS =   2,
-    RELAY_SMR2_N_STATUS =   3,
-    RELAY_PARA_P_STATUS =   4,
-    RELAY_PARA_N_STATUS =   5,
-};
-
-enum RELAY_STATUS_ERROR_TYPE {
-    RELAY_STATUS_ERROR_NONE = 0,
-    RELAY_STATUS_ERROR_WELDING = 10,
-    RELAY_STATUS_ERROR_DRIVING = 11
+    uint8_t isWorking;
 };
 
 struct DcCommonInformation {
     // check if the guns are of the same type
-    byte SysGunAreSameType;
+    uint8_t SysGunAreSameType;
     // to check the ccs version
-    byte CcsVersion;
+    uint8_t CcsVersion;
     // for relay welding/driving check
     char RelayCheckStatus[6];
     char GunRelayWeldingOccur[2];
     char GunRelayDrivingOccur[2];
 };
 
+typedef union {
+    uint32_t GunErrMessage;
+    struct {
+        // Chademo
+        uint8_t ChaGfdTrip: 1;
+        uint8_t ChaUvpFail: 1;
+        uint8_t ChaConnectOTP: 1;
+        uint8_t ChaConnectOVP: 1;
+        uint8_t ChaGfdWarning: 1;
+        uint8_t ChaRelayWeldingFault: 1;
+        uint8_t ChaRelayDrivingFault: 1;
+        uint8_t ChaConnectTempSensorFail: 1;
+
+        // CCS
+        uint8_t CCSGfdTrip : 1;
+        uint8_t CCSUvpFail : 1;
+        uint8_t CCSConnectOTP : 1;
+        uint8_t CCSConnectOVP : 1;
+        uint8_t CCSGfdWarning : 1;
+        uint8_t CCSRelayWeldingFault : 1;
+        uint8_t CCSRelayDrivingFault : 1;
+        uint8_t CCSConnectTempSensorFail : 1;
+
+        // GBT
+        uint8_t GBTGfdTrip : 1;
+        uint8_t GBTUvpFail : 1;
+        uint8_t GBTConnectOTP : 1;
+        uint8_t GBTConnectOVP : 1;
+        uint8_t GBTGfdWarning : 1;
+        uint8_t GBTRelayWeldingFault : 1;
+        uint8_t GBTRelayDrivingFault : 1;
+        uint8_t GBTConnectTempSensorFail : 1;
+    } GunBits;
+} EvBoardErrMsg;
+
+typedef struct StDcCommonInfo {
+    uint8_t RebootCount;
+    EvBoardErrMsg ConnectErrList[2]; //connector error list, 0: left gun, 1: right gun
+    uint8_t Reserved[3];
+} DcCommonInfo;
+
 #endif /* CONFIG_H_ */

+ 0 - 1252
EVSE/Projects/DD360Audi/Apps/DoComm.c

@@ -1,1252 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/can.h>
-#include    <linux/can/raw.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-#include <signal.h>
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    "../../define.h"
-#include    "Config.h"
-
-//#define Debug
-
-#define DoIPAddress "192.168.100.1"
-#define DoTcpPort       36000
-#define TriggerMsgeNum      20
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-struct ApplicationPacket {
-    unsigned char Se;
-    unsigned char Id;
-    unsigned char Op;
-    unsigned char Len;
-    unsigned char RegisterNum;
-    unsigned char Data[250];
-};
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PsuData              *ShmPsuData;
-struct OCPP16Data               *ShmOCPP16Data;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-int                             TcpSock = 0;
-unsigned char                   PacketSe;
-struct ChargingInfoData         *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeb                    TriggerTimeUp[2][TriggerMsgeNum];
-struct WARNING_CODE_INFO        PreSysWarningInfo;
-int DisconnectFlag;
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-int InitShareMemory()
-{
-    int result = 1;
-    int MeterSMId;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-        result = 0;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-        result = 0;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-        result = 0;
-    }
-    //creat ShmPsuData
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPsuData NG \n");
-        result = 0;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPsuData NG \n");
-        result = 0;
-    }
-    //creat ShmOCPP16Data
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
-        result = 0;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-        result = 0;
-    }
-
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-        result = 0;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-        result = 0;
-    }
-    return result;
-}
-
-int CheckNetworkStatus()
-{
-    //printf("ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress=%s\n",ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
-    if (strstr(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, "192.168.100") != NULL) {
-        return 1;
-    } else {
-        return 0;
-    }
-}
-
-int TcpConnected()
-{
-    struct sockaddr_in dest;
-    struct timeval tv;
-    int flag;
-
-    if (TcpSock > 0) {
-        close(TcpSock);
-    }
-
-    if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-        DEBUG_ERROR("Open TCP socket NG");
-        return -1;
-    }
-    /*   flag=fcntl (TcpSock, F_GETFL, 0);
-       if(flag>=0)
-       {
-           flag |= O_NONBLOCK;
-           fcntl(TcpSock,F_SETFL, flag );
-       }*/
-    tv.tv_sec = 0;
-    tv.tv_usec = 100000;
-    setsockopt(TcpSock, SOL_SOCKET,  SO_RCVTIMEO, &tv, sizeof(struct timeval));
-    setsockopt(TcpSock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
-    flag = 1;
-    setsockopt(TcpSock, SOL_SOCKET, MSG_NOSIGNAL, &flag, sizeof(flag));
-
-    memset(&dest, 0, sizeof(dest));
-    dest.sin_family = AF_INET;
-    dest.sin_port = htons(DoTcpPort);
-    inet_aton(DoIPAddress, (struct in_addr *) &dest.sin_addr.s_addr);
-
-    if (connect(TcpSock, (struct sockaddr *) &dest, sizeof(dest)) != 0) {
-        close(TcpSock);
-        return -1;
-    }
-    return TcpSock;
-}
-void AddFaultCodeToBuf(unsigned char *Code)
-{
-    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, strlen(Code));
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
-    }
-}
-
-void RemoveFaultCodeToBuf(unsigned char *Code)
-{
-    unsigned char find = 0x01;
-    char _code[7];
-    sprintf(_code, "%s", Code);
-
-    // 把相關的錯誤碼一次移除,避免重複顯示
-    while (find) {
-        find = 0x00;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-            if (find == 0x00) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
-                    find = 0x01;
-                }
-            } else {
-                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
-            }
-        }
-
-        if (find) {
-            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
-        }
-    }
-}
-
-int StatusCodeProcessing(unsigned char *StatusCode)
-{
-    unsigned char Rtn = 0;
-    int ByteCount, BitCount;
-    unsigned char tmp, EventCodeTmp[7];
-
-    if (strlen(StatusCode) != 6) {
-        return 0;
-    }
-    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-    memcpy(EventCodeTmp, StatusCode, strlen(StatusCode));
-
-    if (*(StatusCode + 1) == 0x34) { //alarm from power cabinet itself
-        if (StatusCode[0] == 0x30) { //trigger
-            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], EventCodeTmp, 7) == 0) {
-                    Rtn = 1;
-                    break;
-                }
-            }
-            if (Rtn == 0) {
-                AddFaultCodeToBuf(EventCodeTmp);
-            }
-            Rtn = 1;
-        } else if (StatusCode[0] == 0x31) { //recovery
-            RemoveFaultCodeToBuf(EventCodeTmp);
-            Rtn = 1;
-        }
-    } else {
-        switch (*(StatusCode + 2)) {
-        case 0x31://Fault
-            for (ByteCount = 0; ByteCount < (sizeof(FaultStatusCode) / 6); ByteCount++) {
-                if (memcmp(FaultStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
-                    if (StatusCode[0] == 0x30) { //trigger
-                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] |= 1 << (ByteCount % 8);
-                    } else if (StatusCode[0] == 0x31) { //recovery
-                        ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount / 8] &= 0 << (ByteCount % 8);
-                    }
-                    Rtn = 1;
-                    break;
-                }
-            }
-            break;
-        case 0x32://Alarm
-            for (ByteCount = 0; ByteCount < (sizeof(AlarmStatusCode) / 6); ByteCount++) {
-                if (memcmp(AlarmStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
-
-                    if (StatusCode[0] == 0x30) { //trigger
-                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] |= 1 << (ByteCount % 8);
-                    } else if (StatusCode[0] == 0x31) { //recovery
-                        ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount / 8] &= 0 << (ByteCount % 8);
-                    }
-                    Rtn = 1;
-                    break;
-                }
-            }
-            break;
-        case 0x33://Information
-            for (ByteCount = 0; ByteCount < (sizeof(InfoStatusCode) / 6); ByteCount++) {
-                if (memcmp(InfoStatusCode[ByteCount] + 1, StatusCode + 1, 5) == 0) {
-                    if (StatusCode[0] == 0x30) { //trigger
-                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] |= 1 << (ByteCount % 8);
-                    } else if (StatusCode[0] == 0x31) { //recovery
-                        ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount / 8] &= 0 << (ByteCount % 8);
-                    }
-                    Rtn = 1;
-                    break;
-                }
-            }
-            break;
-        default:
-            break;
-        }
-    }
-
-    return Rtn;
-}
-
-int SendPacket(unsigned char Id, unsigned char Op, unsigned char RegNum, unsigned char DataLen, unsigned char *Data)
-{
-    int Rtn = 0, PacketLen, Tmp;
-    struct ApplicationPacket SendBuffer;
-    struct timeb ST, ET;
-
-    memset(&SendBuffer, 0, sizeof(struct ApplicationPacket));
-    SendBuffer.Se = (PacketSe++);
-    SendBuffer.Id = Id;
-    SendBuffer.Op = Op;
-    SendBuffer.Len = DataLen + 1;
-    SendBuffer.RegisterNum = RegNum;
-    if (DataLen > 0) {
-        memcpy(SendBuffer.Data, Data, DataLen);
-    }
-    PacketLen = SendBuffer.Len + 4;
-    ftime(&ST);
-    while (Rtn < PacketLen) {
-        Tmp = send(TcpSock, &SendBuffer + Rtn, PacketLen - Rtn, MSG_NOSIGNAL);
-        if (Tmp > 0) {
-            Rtn += Tmp;
-        }
-        ftime(&ET);
-        if (DiffTimeb(ST, ET) > 500) {
-            DisconnectFlag++;
-            if (DisconnectFlag >= 10) {
-                DisconnectFlag = 10;
-            }
-#ifdef Debug
-            printf("Send Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-                   Rtn, PacketLen, PacketSe, Id, Op, RegNum);
-#endif
-            return 0;
-        }
-    }
-    return Rtn;
-}
-
-int RecvPacket(unsigned char *DataLen, struct ApplicationPacket *Packet)
-{
-    int Rtn = 0, Tmp;
-    unsigned char TmpBuf[250];
-    struct timeb ST, ET;
-
-    memset(Packet, 0, sizeof(struct ApplicationPacket));
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    ftime(&ST);
-    while (Rtn < 5) {
-        Tmp = recv(TcpSock, TmpBuf + Rtn, 5 - Rtn, 0);
-        if (Tmp > 0) {
-            Rtn += Tmp;
-        }
-        ftime(&ET);
-        if (DiffTimeb(ST, ET) > 500) {
-            DisconnectFlag++;
-            if (DisconnectFlag >= 10) {
-                DisconnectFlag = 10;
-            }
-#ifdef Debug
-            printf("Recv Packet header Timeout(%d/5)(disconnect count=%d): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-                   Rtn, DisconnectFlag, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
-#endif
-            return 0;
-        }
-    }
-    if ((TmpBuf[0] > 255)/*||(TmpBuf[1]>2)*/ || (TmpBuf[2] > 3) || (TmpBuf[3] > 250)) {
-        DEBUG_INFO("Recv Wrong Packet header (%d/5): SE=%d, ID=%d, OP=%d, Len=%d, Reg=%d",
-                   Rtn, TmpBuf[0], TmpBuf[1], TmpBuf[2], TmpBuf[3], TmpBuf[4]);
-        return 0;
-    }
-    memcpy(Packet, TmpBuf, 5);
-    *DataLen = Packet->Len - 1;
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    Rtn = 0;
-    ftime(&ST);
-    while (Rtn < *DataLen) {
-        Tmp = recv(TcpSock, TmpBuf + Rtn, *DataLen - Rtn, 0);
-        if (Tmp > 0) {
-            Rtn += Tmp;
-        }
-        ftime(&ET);
-        if (DiffTimeb(ST, ET) > 500) {
-            DEBUG_INFO("Recv Packet Timeout(%d/%d): SE=%d, ID=%d, OP=%d, Reg=%d",
-                       Rtn, *DataLen, Packet->Se, Packet->Id, Packet->Op, Packet->RegisterNum);
-            return 0;
-        }
-    }
-    memcpy(Packet->Data, TmpBuf, *DataLen);
-    DisconnectFlag = 0;
-    return Rtn;
-}
-
-int WriteModelName()
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    memcpy(TmpBuf, ShmSysConfigAndInfo->SysConfig.ModelName, strlen(ShmSysConfigAndInfo->SysConfig.ModelName));
-    Tmp = (unsigned char)(ShmPrimaryMcuData->InputDet.bits.Key2 << 2 | ShmPrimaryMcuData->InputDet.bits.Key1 << 1 | ShmPrimaryMcuData->InputDet.bits.Key0);
-    TmpBuf[strlen(ShmSysConfigAndInfo->SysConfig.ModelName)] = Tmp; //Dispenser switch value
-#ifdef Debug
-    printf("WriteModelName(%s)(%d) => ", ShmSysConfigAndInfo->SysConfig.ModelName, Tmp);
-#endif
-    if (SendPacket(0xFF, 0x02, 0x01, strlen(ShmSysConfigAndInfo->SysConfig.ModelName) + 1, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("OK\n");
-#endif
-    return 1;
-}
-
-int ReadConnectorID()
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-#ifdef Debug
-    printf("ReadConnectorID => ");
-#endif
-    if (SendPacket(0xFF, 0x01, 0x02, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("OK (Left connector ID = %d, Right connector ID = %d)\n", PacketData.Data[1], PacketData.Data[2]);
-#endif
-    return 1;
-}
-
-int ReadDoStatus()
-{
-    unsigned char Tmp = 0, count, Rtn;
-    struct ApplicationPacket PacketData;
-    unsigned char StatusArray[20][6];
-    unsigned char EventCodeTmp[7];
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    memset(StatusArray, 0, sizeof(StatusArray));
-#ifdef Debug
-    printf("ReadDoStatus => ");
-#endif
-    if (SendPacket(0x01, 0x01, 0x03, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-    Tmp--;//decrase OK/NG byte
-    if (Tmp < 6) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
-            for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-                if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
-                    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                    memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
-                    RemoveFaultCodeToBuf(EventCodeTmp);
-                }
-            }
-        }
-#ifdef Debug
-        printf("no alarm (%d)\n", Tmp);
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("OK, (%d) ", Tmp);
-    //printf("PacketData.Se=%d\n",PacketData.Se);
-    //printf("PacketData.Id=%d\n",PacketData.Id);
-    //printf("PacketData.Op=%d\n",PacketData.Op);
-    //printf("PacketData.Len=%d\n",PacketData.Len);
-    //printf("PacketData.RegisterNum=%d\n",PacketData.RegisterNum);
-    //for(Rtn=0;Rtn<=PacketData.Len-1;Rtn++)
-    //printf("PacketData.Data[%d]=0x%x\n",Rtn,PacketData.Data[Rtn]);
-#endif
-    for (count = 0; count < Tmp; count += 6) {
-        //if((Tmp-count)<6)
-        strncpy(StatusArray[count / 6], (PacketData.Data + 1) + count, 6);
-        Rtn = 0;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-            if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count / 6], 6) == 0) {
-                Rtn = 1;
-                break;
-            }
-        }
-        if (Rtn == 0) {
-            AddFaultCodeToBuf(StatusArray[count / 6]);
-        }
-        //Rtn=StatusCodeProcessing(StatusArray[count/6]);
-#ifdef Debug
-        printf("(%d)(%s) = %s,  ", count / 6, Rtn == 1 ? "Process OK" : "Process NG", StatusArray[count / 6]);
-#endif
-    }
-    for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
-            Rtn = 0;
-            for (count = 0; count < (Tmp / 6); count++) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], StatusArray[count], 6) == 0) {
-                    Rtn = 1;
-                    break;
-                }
-            }
-            if (Rtn == 0) {
-                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                memcpy(EventCodeTmp, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i], sizeof(EventCodeTmp));
-                RemoveFaultCodeToBuf(EventCodeTmp);
-            }
-        }
-    }
-#ifdef Debug
-    printf("\n");
-#endif
-    return 1;
-}
-
-int WriteDdStatus()
-{
-    unsigned char Tmp = 0, count;
-    unsigned char TmpBuf[255], CurWarnCodeTmp[10][6], PreWarnCodeTmp[10][6];
-    struct ApplicationPacket PacketData;
-
-    if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) && (PreSysWarningInfo.WarningCount <= 0)) {
-        return -1;
-    }
-    memset(CurWarnCodeTmp, 0, sizeof(CurWarnCodeTmp));
-    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-    for (count = 0; count < Tmp; count++) {
-        memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], 6);
-    }
-    memset(PreWarnCodeTmp, 0, sizeof(PreWarnCodeTmp));
-    Tmp = PreSysWarningInfo.WarningCount;
-    for (count = 0; count < Tmp; count++) {
-        memcpy(PreWarnCodeTmp[count], PreSysWarningInfo.WarningCode[count], 6);
-    }
-    if (strcmp(CurWarnCodeTmp, PreWarnCodeTmp) == 0) {
-        return -1;
-    }
-
-
-    /*memset(TmpBuf,0,sizeof(TmpBuf));
-    Tmp=ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-    for(count=0;count<Tmp;count++)
-    {
-        memcpy(TmpBuf+(count*6),ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count],6);
-        #ifdef Debug
-        printf("WriteDdStatus(%d) = %s", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
-        #endif
-    }
-    if(SendPacket(0x01, 0x02, 0x04,strlen(TmpBuf), TmpBuf)<=0)
-        return -1;
-    */
-#ifdef Debug
-    printf("WriteDdStatus => ");
-#endif
-    if (SendPacket(0x01, 0x02, 0x04, strlen(CurWarnCodeTmp), CurWarnCodeTmp) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
-    memcpy(&PreSysWarningInfo, &(ShmSysConfigAndInfo->SysWarningInfo), sizeof(struct WARNING_CODE_INFO));
-#ifdef Debug
-    printf("OK,  ");
-    Tmp = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-    for (count = 0; count < Tmp; count++) {
-        printf("(%d)%s,  ", count, ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count]);
-    }
-    printf("\n");
-#endif
-    return 1;
-}
-
-int ReadChargingCapability(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-    float MaxVolt, MaxCurrent, MaxPower;
-
-#ifdef Debug
-    printf("Read Charging Capability => ");
-#endif
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    if (SendPacket(PlugNum, 0x01, 0x05, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-    MaxVolt = (float)(PacketData.Data[1] << 8 | PacketData.Data[2]);
-    MaxCurrent = (float)(PacketData.Data[3] << 8 | PacketData.Data[4]);
-    MaxPower = (float)(PacketData.Data[5] << 8 | PacketData.Data[6]);
-    if ((MaxVolt >= 0) && (MaxVolt <= 10000)) {
-        ChargingData[PlugNum - 1]->MaximumChargingVoltage = MaxVolt;
-    }
-    if ((MaxCurrent >= 0) && (MaxCurrent <= 5000)) {
-        ChargingData[PlugNum - 1]->AvailableChargingCurrent = MaxCurrent;
-    }
-    if ((MaxPower >= 0) && (MaxPower <= 3600)) {
-        ChargingData[PlugNum - 1]->AvailableChargingPower = MaxPower;
-    }
-#ifdef Debug
-    printf(" MaxVolt=%f, MaxCurrent=%f, MaxPower=%f,\n", MaxVolt, MaxCurrent, MaxPower);
-#endif
-    return 1;
-}
-
-int WriteChargingTarget(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-    float ChargingVolt, ChargingAmp;
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    ChargingVolt = ChargingData[PlugNum - 1]->EvBatterytargetVoltage;
-    ChargingAmp = ChargingData[PlugNum - 1]->EvBatterytargetCurrent;
-    ChargingVolt *= 10;
-    ChargingAmp *= 10;
-    TmpBuf[0] = ((unsigned short)ChargingVolt >> 8) & 0xFF;
-    TmpBuf[1] = ((unsigned short)ChargingVolt) & 0xFF;
-    TmpBuf[2] = ((unsigned short)ChargingAmp >> 8) & 0xFF;
-    TmpBuf[3] = ((unsigned short)ChargingAmp) & 0xFF;
-#ifdef Debug
-    printf("WriteChargingTarget(%d), EvBatterytargetVoltage=%f,EvBatteryMaxVoltage=%f => ",
-           PlugNum, ChargingData[PlugNum - 1]->EvBatterytargetVoltage, ChargingData[PlugNum - 1]->EvBatteryMaxVoltage);
-#endif
-    if (SendPacket(PlugNum, 0x02, 0x06, 4, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf("ChargingVolt=%f, ChargingAmp=%f\n", ChargingVolt / 10, ChargingAmp / 10);
-#endif
-
-    return 1;
-}
-int ReadSoftwareUpdate()
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    if (SendPacket(0x01, 0x01, 0x07, 0, PacketData.Data) <= 0) {
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-        return -1;
-    }
-    if (PacketData.Data[1] != 0x01) { //not update
-        return -1;
-    }
-    return PacketData.Data[1];
-}
-int WritePlugInStatus(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    TmpBuf[0] = ChargingData[PlugNum - 1]->ConnectorPlugIn;
-#ifdef Debug
-    printf("WritePlugInStatus(%d) =>", PlugNum);
-#endif
-    if (SendPacket(PlugNum, 0x02, 0x08, 1, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" %s\n", TmpBuf[0] == 1 ? "Plug-in" : "Un-plug");
-#endif
-
-    return 1;
-}
-
-int WriteConnectorState(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-
-    if (ChargingData[PlugNum - 1]->SystemStatus <= 2) {
-        TmpBuf[0] = 0;    //idle
-    } else if ((ChargingData[PlugNum - 1]->SystemStatus <= 7) || (ChargingData[PlugNum - 1]->SystemStatus == 17) || (ChargingData[PlugNum - 1]->SystemStatus == 18)) {
-        TmpBuf[0] = 1;    //preparing
-    } else if (ChargingData[PlugNum - 1]->SystemStatus == 8) {
-        TmpBuf[0] = 2;    //charging
-    } else if (ChargingData[PlugNum - 1]->SystemStatus == 9) {
-        TmpBuf[0] = 3;    //terminating
-    }
-
-#ifdef Debug
-    printf("WriteConnectorState(%d) SystemStatus=%d,TmpBuf[0]=%d => ", PlugNum, ChargingData[PlugNum - 1]->SystemStatus, TmpBuf[0]);
-#endif
-    if (SendPacket(PlugNum, 0x02, 0x09, 1, TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" %d\n", TmpBuf[0]);
-#endif
-
-    return 1;
-}
-
-int WriteUserID(unsigned char ConnectorID, unsigned char *UserID)
-{
-    unsigned char Tmp = 0;
-    unsigned char TmpBuf[255];
-    struct ApplicationPacket PacketData;
-
-    if (strlen(UserID) <= 0) {
-        return -1;
-    }
-    memset(TmpBuf, 0, sizeof(TmpBuf));
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-    strcpy(TmpBuf, UserID);
-#ifdef Debug
-    printf("WriteUserID(%d) => ", ConnectorID);
-#endif
-    if (SendPacket(ConnectorID, 0x02, 0x0A, strlen(TmpBuf), TmpBuf) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" StartUserId=%s, PacketData.Data[1]=%d\n", TmpBuf, PacketData.Data[1]);
-#endif
-    return PacketData.Data[1];
-}
-
-int ReadChargePermission(unsigned char PlugNum)
-{
-    unsigned char Tmp = 0;
-    struct ApplicationPacket PacketData;
-
-
-    memset(&PacketData, 0, sizeof(struct ApplicationPacket));
-#ifdef Debug
-    printf("ReadChargePermission[%d] => ", PlugNum);
-#endif
-    if (SendPacket(PlugNum, 0x01, 0x0B, 0, PacketData.Data) <= 0) {
-#ifdef Debug
-        printf("SendPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (RecvPacket(&Tmp, &PacketData) <= 0) {
-#ifdef Debug
-        printf("RecvPacket Fail\n");
-#endif
-        return -1;
-    }
-    if (PacketData.Data[0] != 1) { //!=OK
-#ifdef Debug
-        printf("NG\n");
-#endif
-        return -1;
-    }
-#ifdef Debug
-    printf(" %s\n", PacketData.Data[1] == 1 ? "Permitted" : "NOT permitted" );
-#endif
-
-    return PacketData.Data[1];
-}
-
-int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-int MessageTrigger(unsigned char connectorID)
-{
-    struct timeb  NowTime;
-    unsigned char Reg;
-    for (Reg = 0; Reg < TriggerMsgeNum; Reg++) {
-        ftime(&NowTime);
-        switch (Reg) {
-        case 3://ReadDoStatus
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (ReadDoStatus()) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        case 4://WriteDdStatus
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (WriteDdStatus()) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        /*case 5://ReadChargingCapability
-            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>200)
-            {
-                if(ReadChargingCapability(connectorID))
-                {
-                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
-                }
-            }
-            break;
-        case 6://WriteChargingTarget
-            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>100)
-            {
-                if(WriteChargingTarget(connectorID))
-                {
-                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
-                }
-            }
-            break;*/
-        case 8://WritePlugInStatus
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (WritePlugInStatus(connectorID)) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        case 9://WriteConnectorState
-            if (DiffTimeb(TriggerTimeUp[connectorID - 1][Reg], NowTime) > 1000) {
-                if (WriteConnectorState(connectorID)) {
-                    ftime(&TriggerTimeUp[connectorID - 1][Reg]);
-                }
-            }
-            break;
-        /*case 0x0B://ReadChargePermission
-            if(DiffTimeb(TriggerTimeUp[connectorID-1][Reg],NowTime)>1000)
-            {
-                if(ReadChargePermission(connectorID))
-                {
-                    ftime(&TriggerTimeUp[connectorID-1][Reg]);
-                }
-            }
-            break;*/
-        default:
-            break;
-        }
-    }
-}
-
-int main(int argc, char *argv[])
-{
-    unsigned char Tmp, PlugNum;
-    int Rtn;
-    struct timeb  AuthNowTime;
-
-    /**************** Initialization **********/
-    if (InitShareMemory() == 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-ReConnect:
-    memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
-    PacketSe = 0;
-    DisconnectFlag = 0;
-    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-        if (!FindChargingInfoData(_index, &ChargingData[0])) {
-            DEBUG_ERROR("FindChargingInfoData false \n");
-            break;
-        }
-    }
-
-    /**************** Check Network **********/
-    DEBUG_INFO("Check Dispenser Network Information");
-    while (!CheckNetworkStatus()) {
-        sleep(1);
-        if (DisconnectFlag >= 10) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Dispenser Network Information checked: IP=%s Netmask=%s, Gateway=%s",
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-
-    /**************** Power cabinet connection **********/
-    DEBUG_INFO("Connect to Power Cabinet");
-    while (TcpConnected() < 0) {
-        sleep(1);
-        if (DisconnectFlag >= 5) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Power cabinet connected(TcpSock=%d): IP=%s Netmask=%s, Gateway=%s",
-               TcpSock,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-
-    /**************** Write Model Name**********/
-    DEBUG_INFO("Write Model Name");
-    while (WriteModelName() < 0) {
-        sleep(1);
-        if (DisconnectFlag >= 5) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Write Model Name OK: %s", ShmSysConfigAndInfo->SysConfig.ModelName);
-
-    /**************** Get Connector ID**********/
-    DEBUG_INFO("Get Connector ID");
-    while (ReadConnectorID() < 0) {
-        sleep(1);
-        if (DisconnectFlag >= 5) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-        } else {
-            DisconnectFlag++;
-        }
-    }
-    DEBUG_INFO("Get Connector ID OK");
-    /*while(1)
-    {
-        //for self testin main.c
-        if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq >= _STEST_PSU_DETECT)
-        {
-            ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
-            break;
-        }
-    }*/
-    for (Tmp = 0; Tmp < TriggerMsgeNum; Tmp++) {
-        ftime(&TriggerTimeUp[0][Tmp]);
-        ftime(&TriggerTimeUp[1][Tmp]);
-        usleep(50000);
-    }
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 0;
-    DEBUG_INFO("Start Communication");
-    /**************** Data transmission**********/
-    while (1) {
-        if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
-            ftime(&AuthNowTime);
-            if (DiffTimeb(TriggerTimeUp[0][10], AuthNowTime) > 1000) {
-                Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
-                if (Rtn >= 0) {
-                    memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-                    if (Rtn == 0) {
-                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
-                    } else {
-                        strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
-                    }
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
-                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
-                    ShmPsuData->SystemAvailablePower = 0;
-                    ShmPsuData->SystemPresentPsuQuantity = 0;
-                }
-                ftime(&TriggerTimeUp[0][10]);
-            }
-        }
-
-        for (PlugNum = 1; PlugNum <= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; PlugNum++) {
-            //printf("ChargingData[PlugNum-1]->SystemStatus=%d\n",ChargingData[PlugNum-1]->SystemStatus);
-            //printf("ShmOCPP16Data->SpMsg.bits.AuthorizeReq=%d\n",ShmOCPP16Data->SpMsg.bits.AuthorizeReq);
-            //printf("ShmSysConfigAndInfo->SysInfo.AuthorizeFlag=%d\n",ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
-            //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-            //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-            switch (ChargingData[PlugNum - 1]->SystemStatus) {
-            case S_IDLE:
-            case S_RESERVATION:
-            case S_MAINTAIN:
-            case S_ALARM:
-            case S_AUTHORIZING:
-                if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) || (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == 1)) {
-                    ftime(&AuthNowTime);
-                    if (DiffTimeb(TriggerTimeUp[PlugNum - 1][10], AuthNowTime) > 1000) {
-                        Rtn = WriteUserID(ShmSysConfigAndInfo->SysInfo.CurGunSelected, ShmSysConfigAndInfo->SysConfig.UserId);
-                        if (Rtn >= 0) {
-                            memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0, sizeof(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
-                            if (Rtn == 0) {
-                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
-                            } else {
-                                strcpy(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
-                            }
-                            ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; //isAuthorizedComplete
-                            ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
-                            ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = 0;
-                            ShmPsuData->SystemAvailablePower = 0;
-                            ShmPsuData->SystemPresentPsuQuantity = 0;
-                            ftime(&TriggerTimeUp[PlugNum - 1][10]);
-
-                        }
-                        ftime(&TriggerTimeUp[PlugNum - 1][10]);
-                    }
-                }
-                /*if(ReadSoftwareUpdate())//0x07
-                {
-                    //firmware update
-                }*/
-                break;
-            case S_PREPARNING: //get permission
-                //printf("S_PREPARNING\n");
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if ((ReadChargePermission(PlugNum)) && (ReadChargingCapability(PlugNum))) {
-                        ShmPsuData->SystemAvailablePower = ChargingData[0]->AvailableChargingPower + ChargingData[1]->AvailableChargingPower;
-                        ShmPsuData->SystemPresentPsuQuantity = ShmPsuData->SystemAvailablePower / 30;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                break;
-            case S_PREPARING_FOR_EV://wait connector lock
-                //printf("S_PREPARING_FOR_EV\n");
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
-                    ReadChargingCapability(PlugNum);
-                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
-                }
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if (ReadChargePermission(PlugNum) == 0) {
-                        DEBUG_INFO("Stop charging by power cabinet's permission");
-                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                break;
-            case S_PREPARING_FOR_EVSE: //insaulation test
-            case S_CCS_PRECHARGE_ST0:
-            case S_CCS_PRECHARGE_ST1:
-                //printf("S_PREPARING_FOR_EVSE\n");
-                WriteChargingTarget(PlugNum);
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
-                    ReadChargingCapability(PlugNum);
-                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
-                }
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if (ReadChargePermission(PlugNum) == 0) {
-                        DEBUG_INFO("Stop charging by power cabinet's permission");
-                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                break;
-            case S_CHARGING: //charging
-            case S_TERMINATING:
-                //printf("S_CHARGING,S_TERMINATING\n");
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][5], AuthNowTime) > 1000) {
-                    ReadChargingCapability(PlugNum);
-                    ftime(&TriggerTimeUp[PlugNum - 1][5]);
-                }
-                ftime(&AuthNowTime);
-                if (DiffTimeb(TriggerTimeUp[PlugNum - 1][11], AuthNowTime) > 1000) {
-                    if (ReadChargePermission(PlugNum) == 0) {
-                        DEBUG_INFO("Stop charging by power cabinet's permission");
-                        ChargingData[PlugNum - 1]->StopChargeFlag = 1;
-                    }
-                    ftime(&TriggerTimeUp[PlugNum - 1][11]);
-                }
-                WriteChargingTarget(PlugNum);
-                //printf("ChargingData[%d]->FireChargingVoltage=%f\n",PlugNum,ChargingData[PlugNum-1]->FireChargingVoltage);
-                //printf("ChargingData[%d]->PresentChargingCurrent=%f\n",PlugNum,ChargingData[PlugNum-1]->PresentChargingCurrent);
-                break;
-            default:
-                break;
-            }//switch   case
-            MessageTrigger(PlugNum);
-        }//for connector #
-        if (DisconnectFlag >= 10) {
-            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == 0) {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = 1;
-                DEBUG_INFO("Disconnected from power cabinet...re-connecting");
-            }
-            goto ReConnect;
-        }
-    }//while(1)
-}

+ 0 - 196
EVSE/Projects/DD360Audi/Apps/Ev_Comm.c

@@ -1,196 +0,0 @@
-#include "Module_EvComm.h"
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<string.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-
-//================================================
-//================================================
-// CANBUS send cmd
-//================================================
-//================================================
-
-int PackageIdCmd(int cmd)
-{
-	return cmd | 0x80000000;
-}
-
-void SendCmdToEvboard(int cmd, byte *data, byte dataLen)
-{
-    struct can_frame frame;
-
-    frame.can_id = cmd;
-    frame.can_dlc = dataLen;
-    memcpy(frame.data, data, sizeof(frame.data));
-
-    write(CanFd, &frame, sizeof(struct can_frame));
-}
-
-void SetTargetAddr(byte *target_number, byte index)
-{
-	int id = PackageIdCmd(Ev_Cmd.address_assignment + index);
-	//printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
-	//cmd = cmd & CAN_EFF_MASK;
-
-	byte data[8];
-
-	data[0] = *target_number;
-	data[1] = *(target_number + 1);
-	data[2] = *(target_number + 2);
-	data[3] = *(target_number + 3);
-	data[4] = index;
-
-	SendCmdToEvboard(id, data, 5);
-}
-
-void GetFirmwareVersion(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void SyncRtcInfo(byte gun_index, byte toId, int epoch)
-{
-	int id = PackageIdCmd(Ev_Cmd.sync_rtc_info + toId);
-	byte data[8];
-
-	data[0] = epoch & 0xff;
-	data[1] = (epoch >> 8) & 0xff;
-	data[2] = (epoch >> 16) & 0xff;
-	data[3] = (epoch >> 24) & 0xff;
-
-	SendCmdToEvboard(id, data, 4);
-}
-
-void GetHardwareVersion(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.charging_permission + toId);
-	byte data[8];
-
-	data[0] = permissionStatus;
-	data[1] = aOutputPw & 0xff;
-	data[2] = (aOutputPw >> 8) & 0xff;
-	data[3] = aOutputCur & 0xff;
-	data[4] = (aOutputCur >> 8) & 0xff;
-	data[5] = aOutputVol & 0xff;
-	data[6] = (aOutputVol >> 8) & 0xff;
-	data[7] = 0xf0;
-
-	SendCmdToEvboard(id, data, sizeof(data));
-}
-
-void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2)
-{
-	int id = PackageIdCmd(Ev_Cmd.present_output_power);
-	byte data[8];
-
-	data[0] = outputVol_b1 & 0xff;
-	data[1] = (outputVol_b1 >> 8) & 0xff;
-	data[2] = outputCur_b1 & 0xff;
-	data[3] = (outputCur_b1 >> 8) & 0xff;
-	data[4] = outputVol_b2 & 0xff;
-	data[5] = (outputVol_b2 >> 8) & 0xff;
-	data[6] = outputCur_b2 & 0xff;
-	data[7] = (outputCur_b2 >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 8);
-}
-
-void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2)
-{
-	int id = PackageIdCmd(Ev_Cmd.present_output_cap);
-	byte data[8];
-
-	data[0] = aOutputPw_b1 & 0xff;
-	data[1] = (aOutputPw_b1 >> 8) & 0xff;
-	data[2] = aOutputCur_b1 & 0xff;
-	data[3] = (aOutputCur_b1 >> 8) & 0xff;
-	data[4] = aOutputPw_b2 & 0xff;
-	data[5] = (aOutputPw_b2 >> 8) & 0xff;
-	data[6] = aOutputCur_b2 & 0xff;
-	data[7] = (aOutputCur_b2 >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 8);
-}
-
-void GetOutputReq(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_output_req + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void GetEvBatteryInfo(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_battery_info + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId);
-	byte data[8];
-
-	data[0] = stopResult;
-	data[1] = *stopReason;
-	data[2] = *(stopReason + 1);
-	data[3] = *(stopReason + 2);
-	data[4] = *(stopReason + 3);
-	data[5] = *(stopReason + 4);
-	data[6] = *(stopReason + 5);
-
-	SendCmdToEvboard(id, data, 7);
-}
-
-void GetMiscellaneousInfo(byte gun_index, byte relayStatus, float power, float voltage, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId);
-	byte data[8];
-
-	int _power = power * 10;
-
-	data[0] = relayStatus;
-	data[1] = (int)_power & 0xff;
-	data[2] = ((int)_power >> 8) & 0xff;
-	data[3] = (int)voltage & 0xff;
-	data[4] = ((int)voltage >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 5);
-}
-
-void SetIsolationStatus(byte gun_index, byte result, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.isolation_status + toId);
-	byte data[8];
-
-	data[0] = result;
-	SendCmdToEvboard(id, data, 1);
-}
-
-void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId);
-	byte data[8];
-
-	data[0] = result;
-	SendCmdToEvboard(id, data, 1);
-}
-

+ 3 - 8
EVSE/Projects/DD360Audi/Apps/FactoryConfig.c

@@ -32,16 +32,11 @@
 #include    "Config.h"
 
 #define Debug
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
 #define OUTPUT_FLASH        0x01
 #define OUTPUT_FILE         0x02
 
 struct SysConfigData            SysConfig;
 
-int StoreLogMsg(const char *fmt, ...);
-
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -84,9 +79,9 @@ void helpOutput(void)
 /**************************************************************************************/
 int main(int argc, char *argv[])
 {
-    unsigned char outType = 0;
+    uint8_t outType = 0;
     unsigned int i, Chk, MtdBlockSize = 0x600000;
-    unsigned char *ptr;
+    uint8_t *ptr;
     int fd, wrd;
 
     ptr = malloc(MtdBlockSize);
@@ -134,7 +129,7 @@ int main(int argc, char *argv[])
     SysConfig.AcMaxChargingCurrent = 0;
     SysConfig.PhaseLossPolicy = 0;
     /*+++ 20200908, vern, modify it +++*/
-    /*for(unsigned char i = 0; i < 10; i++)
+    /*for(uint8_t i = 0; i < 10; i++)
         strcpy((char *)SysConfig.LocalWhiteCard, "");*/
     memset(SysConfig.LocalWhiteCard, 0, sizeof(SysConfig.LocalWhiteCard));
     /*--- 20200908, vern, modify it ---*/

+ 49 - 32
EVSE/Projects/DD360Audi/Apps/Makefile

@@ -7,9 +7,27 @@ OutputPath = ../output
 
 DEFINE = -D $(Project)
 
-CFLAGS = -O0 -g3 -Wall -c -fmessage-length=0
+CFLAGS = -O0 -g3 -Wall -fmessage-length=0
 TFLAGS = -lrt -lm -lpthread
 
+TOP = .
+
+INC_FLAGS += -I $(TOP)/ModuleInternalComm
+INC_FLAGS += -I $(TOP)/ModuleEvComm
+INC_FLAGS += -I $(TOP)/ModulePrimary
+INC_FLAGS += -I $(TOP)/ModuleLcmCtrl
+INC_FLAGS += -I $(TOP)/ModuleDoComm
+INC_FLAGS += -I $(TOP)/ModuleEventLog
+
+InternalCommLib = $(TOP)/ModuleInternalComm
+EvCommLib = $(TOP)/ModuleEvComm
+PrimaryLib = $(TOP)/ModulePrimary
+LcmLib = $(TOP)/ModuleLcmCtrl
+DoCommLib = $(TOP)/ModuleDoComm
+EventLogLib = $(TOP)/ModuleEventLog
+ScriptLib = $(TOP)/Script
+
+
 #define library variable
 Internal485ProtocolLib = -L $(ModularizationPath)/Internal485Protocol -lInternal485Protocol
 #PsuCommProtocolLib = -L $(ModularizationPath)/PsuCommProtocol -lPsuCommProtocol
@@ -38,69 +56,68 @@ apps: MainTask DoCommTask EvCommTask \
 			PrimaryCommTask ReadCmdlineTask UnsafetyOutputTool \
 				FactoryConfigApp OtherTools CleanExec
 
-LOG_INC = Log
-
 MainTask:
-	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -o main.o ReMain.c
-	$(CC) -D $(Project) -includeConfig.h $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -o timeout.o timeout.c
-	$(CC) $(TFLAGS) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
+	$(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) -D $(Project) -includeConfig.h $(CFLAGS) -o DoComm.o ReDoComm.c
-	$(CC) -o DoComm DoComm.o
+	$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
+	$(CC) -o Module_DoComm DoComm.o
 
 EvCommTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Ev_Comm.o Ev_Comm.c
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_EvComm.o ReModule_EvComm.c
-	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o
+	$(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) -D $(Project) -includeConfig.h $(SQLite3_H) $(CFLAGS) -o Module_EventLogging.o ReModule_EventLogging.c
+	$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
 	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3}
 
 InternalCommTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o internalComm.o internalComm.c
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_InternalComm.o ReModule_InternalComm.c
-	$(CC) -o Module_InternalComm Module_InternalComm.o internalComm.o
+	$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o internalComm.o $(InternalCommLib)/internalComm.c
+	$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o Module_InternalComm.o $(InternalCommLib)/Module_InternalComm.c
+	$(CC) $(TFLAGS) -o Module_InternalComm Module_InternalComm.o internalComm.o $(Lib_ModuleRelay)
 
 LcmControlTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_LcmControl.o ReModule_LcmControl.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
 	$(CC) -o Module_LcmControl Module_LcmControl.o
 
 PrimaryCommTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o Module_PrimaryComm.o ReModule_PrimaryComm.c
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o PrimaryComm.o PrimaryComm.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
 	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
 
 PsuCommTask:
-	$(CC) -D $(Project) $(InfypwrPsuComm_H) -includeConfig.h $(CFLAGS) -o Module_PsuComm.o Module_PsuComm.c
+	$(CC) $(DEFINE) $(InfypwrPsuComm_H) $(CFLAGS) -c -o Module_PsuComm.o Module_PsuComm.c
 	$(CC) -o Module_PsuComm Module_PsuComm.o $(InfypwrPsuComm_A)
 
 ReadCmdlineTask:
-	$(CC) -D $(Project) -includeConfig.h $(CFLAGS) -o ReadCmdline.o ReadCmdline.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o ReadCmdline.o ReadCmdline.c
 	$(CC) -o ReadCmdline ReadCmdline.o
 
 UnsafetyOutputTool:
-	$(CC) -D $(Project) $(InfypwrPsuComm_H) $(CFLAGS) -o OutputTask.o OutputTask.c
+	$(CC) $(DEFINE) $(InfypwrPsuComm_H) $(CFLAGS) -c -o OutputTask.o OutputTask.c
 	$(CC) -o UnsafetyOutputTask OutputTask.o $(InfypwrPsuComm_A)
 
 FactoryConfigApp:
 	@echo "===== Module_FactoryConfig_Task =================================="
 	rm -f FactoryConfig
-#	gcc -D $(Project) "-I../../" -o FactoryConfig "./FactoryConfig.c"
+#	gcc -D $(DEFINE) "-I../../" -o FactoryConfig "./FactoryConfig.c"
 #	mkdir -p /Storage/SystemLog
 #	./FactoryConfig -f;true
 #	cp /mnt/FactoryDefaultConfig.bin ../Images
 #	rm -f FactoryConfig;
-	$(CC) -D $(Project) $(CFLAGS) -o FactoryConfig.o FactoryConfig.c
+	$(CC) $(DEFINE) $(CFLAGS) -c -o FactoryConfig.o FactoryConfig.c
 	$(CC) -o FactoryConfig FactoryConfig.o
 
 OtherTools:
-	cp -f init.sh $(RootPath)
-	cp -f kill.sh $(RootPath)
-	cp -f web.sh $(RootPath)
+	cp -f $(ScriptLib)/init.sh $(RootPath)
+	cp -f $(ScriptLib)/kill.sh $(RootPath)
+	cp -f $(ScriptLib)/web.sh $(RootPath)
 	cp -f main $(RootPath)
-	cp -f DoComm $(RootPath)
+	cp -f Module_DoComm $(RootPath)
 	cp -f Module_EvComm $(RootPath)
 	cp -f Module_EventLogging $(RootPath)
 	cp -f Module_InternalComm $(RootPath)
@@ -112,11 +129,11 @@ OtherTools:
 	cp -f FactoryConfig $(RootPath)
 
 	if [ ! -d $(OutputPath) ]; then mkdir -p $(OutputPath); fi
-	cp -f init.sh $(OutputPath)
-	cp -f kill.sh $(OutputPath)
-	cp -f web.sh $(OutputPath)
+	cp -f $(ScriptLib)/init.sh $(OutputPath)
+	cp -f $(ScriptLib)/kill.sh $(OutputPath)
+	cp -f $(ScriptLib)/web.sh $(OutputPath)
 	cp -f main $(OutputPath)
-	cp -f DoComm $(OutputPath)
+	cp -f Module_DoComm $(OutputPath)
 	cp -f Module_EvComm $(OutputPath)
 	cp -f Module_EventLogging $(OutputPath)
 	cp -f Module_InternalComm $(OutputPath)
@@ -142,4 +159,4 @@ CleanExec:
 	#rm Module_PsuComm
 	rm ReadCmdline
 	rm FactoryConfig
-	rm DoComm
+	rm Module_DoComm

+ 143 - 119
EVSE/Projects/DD360ComBox/Apps/ReDoComm.c → EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -21,16 +21,16 @@
 #include <unistd.h>
 #include <signal.h>
 
-#include "../../define.h"
-#include "Config.h"
-#include "ReDoComm.h"
-#include "AudiCust.h"
-#include "timeout.h"
+#include "../../../define.h"
+#include "../Config.h"
+#include "../SelectGun/SelectGun.h"
+#include "../timeout.h"
+#include "DoComm.h"
 
 //------------------------------------------------------------------------------
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_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 int TcpSock = 0;
@@ -152,10 +152,10 @@ static void Hexdump(const void *p, size_t size)
 
     message_len += sprintf(&message[message_len], "\r\n");
 
-    DEBUG_INFO("%s", message);
+    log_info("%s", message);
 }
 
-static int string2ByteArray(char *input, byte *output)
+static int string2ByteArray(char *input, uint8_t *output)
 {
     int loop = 0;
     int i = 0;
@@ -170,7 +170,7 @@ static int string2ByteArray(char *input, byte *output)
 
 static void unixSocketSigPipeHandle(int sig)
 {
-    DEBUG_ERROR("socket packet error %x\r\n", sig);
+    log_error("socket packet error %x\r\n", sig);
 }
 
 static void InitSocketSigPipe(void)
@@ -199,7 +199,7 @@ static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
     size = send(fd, data, dataLen , 0);
     if ((size < 0) || (errno == EAGAIN)) {
         if (size < 0) {
-            DEBUG_ERROR("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
+            log_error("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
         }
     }
 
@@ -213,7 +213,7 @@ static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
 
     size = recv(fd, pdata, dataLen, MSG_WAITALL);
     if ((errno == EAGAIN) || (size < 0)) {
-        DEBUG_ERROR("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
+        log_error("Size = %d, EAGAIN error %d:%s\r\n", size, errno, strerror(errno));
     }
 
     return size;
@@ -225,7 +225,7 @@ static int getSO_ERROR(int fd)
     socklen_t len = sizeof err;
 
     if (-1 == getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &len)) {
-        DEBUG_ERROR("getSO_ERROR\r\n");
+        log_error("getSO_ERROR\r\n");
     }
 
     if (err) {
@@ -244,12 +244,12 @@ static void closeSocket(int fd)        // *not* the Windows closesocket()
     getSO_ERROR(fd); // first clear any errors, which can cause close to fail
     if (shutdown(fd, SHUT_RDWR) < 0) { // secondly, terminate the 'reliable' delivery
         if (errno != ENOTCONN && errno != EINVAL) { // SGI causes EINVAL
-            DEBUG_INFO("shutdown\r\n");
+            log_info("shutdown\r\n");
         }
     }
 
     if (close(fd) < 0) { // finally call close()
-        DEBUG_INFO("client socket close\r\n");
+        log_info("client socket close\r\n");
     }
 }
 
@@ -265,7 +265,7 @@ static int doCommConnToServer(void)
     //}
 
     if ((TcpSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-        DEBUG_ERROR("Open TCP socket NG");
+        log_error("Open TCP socket NG");
         return -1;
     }
 
@@ -399,7 +399,7 @@ static void setConfirmSelGun(uint8_t selGun)
 static int compareOpcode(uint8_t opCode)
 {
     if (opCode != OP_WAIT_RESPONSE) {
-        //DEBUG_ERROR("response operative code fail\r\n");
+        //log_error("response operative code fail\r\n");
         return FAIL;
     }
 
@@ -409,7 +409,7 @@ static int compareOpcode(uint8_t opCode)
 static int compareResult(uint8_t result)
 {
     if (result != COMMAND_RESULT_OK) {
-        //DEBUG_ERROR("response result fail\r\n");
+        //log_error("response result fail\r\n");
         return FAIL;
     }
 
@@ -419,7 +419,7 @@ static int compareResult(uint8_t result)
 static int compareRegister(uint8_t srcReg, uint8_t destReg)
 {
     if (srcReg != destReg) {
-        //DEBUG_ERROR("response register fail\r\n");
+        //log_error("response register fail\r\n");
         return FAIL;
     }
 
@@ -447,7 +447,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     struct tm *tm;
 
     if ((char *)&data[0] == '\0') {
-        DEBUG_ERROR("QR code date error\r\n");
+        log_error("QR code date error\r\n");
         return FAIL;
     }
 
@@ -471,7 +471,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     }
 
     //if ((char *)&data[len] == '\0') {
-    //    DEBUG_ERROR("power cabinet system date error\r\n");
+    //    log_error("power cabinet system date error\r\n");
     //    return FAIL;
     //}
 
@@ -479,7 +479,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     //if (strncmp((char *)localTime, (char *)&data[len], timeLen) != 0) {
     //    sprintf(cmdBuf, "date -s \"%s\" >> /dev/null", (char *)&data[len]);
     //    system(cmdBuf);
-    //    DEBUG_INFO("local time = %s, data time = %s\r\n", localTime, (char *)&data[len]);
+    //    log_info("local time = %s, data time = %s\r\n", localTime, (char *)&data[len]);
     //    ShmOCPP16Data->MsMsg.bits.ResetReq = YES;
     //    strcpy((char *)ShmOCPP16Data->Reset.Type, "Soft");
     //    sleep(3);
@@ -495,12 +495,12 @@ static int updateFirmwareHandle(uint8_t *imgName)
     char cmdBuf[1024] = {0};
 
     sprintf(cmdBuf, "/mnt/%s", imgName);
-    DEBUG_INFO("Program ready to check file %s\n", cmdBuf);
+    log_info("Program ready to check file %s\n", cmdBuf);
     if ( access(cmdBuf, F_OK) != -1) {
-        DEBUG_INFO("File '%s' exist.\n", cmdBuf);
+        log_info("File '%s' exist.\n", cmdBuf);
         ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = YES;
     } else {
-        DEBUG_INFO("File '%s' doesn't exist.\n", cmdBuf);
+        log_info("File '%s' doesn't exist.\n", cmdBuf);
         ret = FAIL;
     }
 
@@ -560,13 +560,13 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
         pMiscCmd = (MiscCommand *)data + i;
         cmd = ntohs(pMiscCmd->CMD);
         value = ntohl(*((uint32_t *)&pMiscCmd->Value[0]));
-        //DEBUG_INFO("misc command = %x, value = %d\r\n", cmd, value);
+        //log_info("misc command = %x, value = %d\r\n", cmd, value);
 
         switch (cmd) {
         //--- Execute parameter ---
         case MISC_CMD_CONNECOTOR_TIMEOUT:
             gAudiCustInfo->RemoteSetup.ConnectionTimeout = value;
-            DEBUG_INFO("connection timeout = %d\r\n", gAudiCustInfo->RemoteSetup.ConnectionTimeout);
+            log_info("connection timeout = %d\r\n", gAudiCustInfo->RemoteSetup.ConnectionTimeout);
             clearMiscCommand();
             break;
 
@@ -578,7 +578,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            DEBUG_INFO("change availability plugNum = %d, value = %d\r\n", plugNum, value);
+            log_info("change availability plugNum = %d, value = %d\r\n", plugNum, value);
             ShmOCPP16Data->CsMsg.bits[plugNum].ChangeAvailabilityReq = YES;
             if (value == YES) {
                 strcpy((char *)ShmOCPP16Data->ChangeAvailability[plugNum].Type, "Operative");
@@ -593,9 +593,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
         case MISC_CMD_DEFAULT_PRICES:
             prices = transPricesUnit((int)value);
-            DEBUG_INFO("default prices = %.2f\r\n", prices);
+            log_info("default prices = %.2f\r\n", prices);
 
-            ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = YES;
+            //ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = YES;
             for (j = 0; j < 24; j++) {
                 ShmSysConfigAndInfo->SysConfig.BillingData.Fee[j] = prices;
             }
@@ -609,7 +609,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 return FAIL;
             }
 
-            DEBUG_INFO("default currency = %s%c\r\n", (uint8_t *)Currency[value]);
+            log_info("default currency = %s%c\r\n", (uint8_t *)Currency[value]);
             ShmSysConfigAndInfo->SysConfig.BillingData.Currency = value;
             clearMiscCommand();
             break;
@@ -622,13 +622,13 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
 #if defined DD360Audi
             if (getConfirmSelectedGun(plugNum) == FAIL) {
-                DEBUG_INFO("Remote start not select gun\r\n");
+                log_info("Remote start not select gun\r\n");
                 break;
             }
 #endif //DD360Audi
 
             gAudiCustInfo->PricesInfo[plugNum].Balance = transPricesUnit((int)value);
-            DEBUG_INFO("%d misc balance = %.2f\r\n", plugNum, gAudiCustInfo->PricesInfo[plugNum].Balance);
+            log_info("%d misc balance = %.2f\r\n", plugNum, gAudiCustInfo->PricesInfo[plugNum].Balance);
             clearMiscCommand();
             break;
 
@@ -648,6 +648,14 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             gAudiCustInfo->EthDevStatus.FourG = value;
             break;
 
+        case MISC_CMD_BILLING_INFO:
+            ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
+            break;
+
+        case MISC_CMD_WEB_STOP_CHARGING:
+            gAudiCustInfo->RemoteSetup.BtnStopCharging = value;
+            break;
+
         //--- Control Dispenser ---
         case MISC_CMD_HARDWARE_REBOOT:
             if (value != YES) {
@@ -655,7 +663,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            DEBUG_INFO("Hardware reboot\r\n");
+            log_info("Hardware reboot\r\n");
             ShmOCPP16Data->MsMsg.bits.ResetReq = YES;
             strcpy((char *)ShmOCPP16Data->Reset.Type, "Hard");
             clearMiscCommand();
@@ -668,7 +676,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             clearMiscCommand();
-            DEBUG_INFO("Software reboot\r\n");
+            log_info("Software reboot\r\n");
             ShmOCPP16Data->MsMsg.bits.ResetReq = YES;
             strcpy((char *)ShmOCPP16Data->Reset.Type, "Soft");
             break;
@@ -680,11 +688,11 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 }
                 break;
             }
-            DEBUG_INFO("Remote start charging plugNum = %d\r\n", plugNum);
+            log_info("Remote start charging plugNum = %d\r\n", plugNum);
 
 #if defined DD360Audi
             if (getSelGunWaitToAuthor(plugNum) == FAIL) {
-                DEBUG_ERROR("Remote start gun already charging\r\n");
+                log_error("Remote start gun already charging\r\n");
                 break;
             }
 
@@ -829,12 +837,12 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         pricesInfo[plugNum].UserPrices = gAudiCustInfo->PricesInfo[plugNum].UserPrices;
         pricesInfo[plugNum].Balance = gAudiCustInfo->PricesInfo[plugNum].Balance;
 
-        DEBUG_INFO("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
-                   plugNum,
-                   gAudiCustInfo->PricesInfo[plugNum].UserPrices,
-                   ChargingData[plugNum]->ChargingFee,
-                   gAudiCustInfo->PricesInfo[plugNum].Balance,
-                   (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+        log_info("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
+                 plugNum,
+                 gAudiCustInfo->PricesInfo[plugNum].UserPrices,
+                 ChargingData[plugNum]->ChargingFee,
+                 gAudiCustInfo->PricesInfo[plugNum].Balance,
+                 (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
     }
 
     return PASS;
@@ -906,19 +914,18 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
     uint8_t remaindLen = 0;
     uint8_t statusCodeError = 0;
 
-    //if (dataLen <= 0) {
-    //    return FAIL;
-    //}
-
     if (dataLen > 0) {
+        Hexdump((uint8_t *)data, dataLen);
+
         remaindLen = dataLen % WARNING_CODE_SIZE;
 
         if (remaindLen != 0) {
+            log_info("fail status code length =  %d\r\n", dataLen);
             dataLen -= remaindLen;
         }
 
         if (dataLen < WARNING_CODE_SIZE) {
-            DEBUG_ERROR("fail status code length = %d\r\n", dataLen);
+            log_error("fail status code length = %d\r\n", dataLen);
             Hexdump(data, dataLen);
             if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
                 for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
@@ -939,17 +946,24 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
 
         for (count = 0; count < dataLen; count += WARNING_CODE_SIZE) {
             usleep(128);
+
+            if (strncmp((char *)&data[count + 1], "1", 1) != 0 &&
+                    strncmp((char *)&data[count + 1], "2", 1) != 0 &&
+                    strncmp((char *)&data[count + 1], "3", 1) != 0 &&
+                    (strncmp((char *)&data[count], "B", 1) != 0 &&
+                     strncmp((char *)&data[count + 1], "4", 1) != 0)
+               ) {
+                log_error("error status code = %s", (char *)&data[count]);
+                continue;
+            }
+
             // misc command status code handle
             if (strncmp((char *)&data[count], MISC_ST_MISC_CMD, WARNING_CODE_SIZE) == 0) {
-                //if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
                 gDoCommGblData.MiscCmd = REG_MISC_CONTROL;
-                //}
                 memset((char *)&data[count], 0, WARNING_CODE_SIZE);
                 continue;
             } else if (strncmp((char *)&data[count], MISC_ST_VERSION, WARNING_CODE_SIZE) == 0) {
-                //if (gDoCommGblData.MiscCmd != REG_REPORT_CSU_VERSION) {
                 gDoCommGblData.MiscCmd = REG_REPORT_CSU_VERSION;
-                //}
                 memset((char *)&data[count], 0, WARNING_CODE_SIZE);
                 continue;
             }
@@ -957,7 +971,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             if (CompareArrayIsZero((uint8_t *)&data[count], WARNING_CODE_SIZE) == true) {
                 memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
                 memcpy(EventCodeTmp, (char *)&data[count], sizeof(EventCodeTmp));
-                DEBUG_ERROR("error status = %s\r\n", EventCodeTmp);
+                log_error("error status = %s\r\n", EventCodeTmp);
                 continue;
             }
 
@@ -979,18 +993,15 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             }
             //Rtn=StatusCodeProcessing(StatusArray[count/6]);
         }
+    } else {
+        if (CompareArrayIsZero(data, WARNING_CODE_SIZE) == false) {
+            log_error("power cabinet status code data length is zero, but have data\r\n");
+            Hexdump((uint8_t *)data, WARNING_CODE_SIZE);
+        }
     }
 
     for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         usleep(128);
-        //if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
-        //        ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4') {
-        //    memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-        //    memcpy(EventCodeTmp,
-        //           ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
-        //           sizeof(EventCodeTmp));
-        //    removeFaultCodeToBuf(EventCodeTmp);
-        //}
 
         if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' || //from backend or power cabinet 0x33
                 (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
@@ -1045,9 +1056,9 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
     case REG_CONNECTOR_ID:
         gDoCommGblData.ConnectorID[0] = pCsuResult->Data.Data[0];
         gDoCommGblData.ConnectorID[1] = pCsuResult->Data.Data[1];
-        DEBUG_INFO("OK (Left connector ID = %d, Right connector ID = %d)\n",
-                   pCsuResult->Data.Data[0],
-                   pCsuResult->Data.Data[1]);
+        log_info("OK (Left connector ID = %d, Right connector ID = %d)\n",
+                 pCsuResult->Data.Data[0],
+                 pCsuResult->Data.Data[1]);
         break;
 
     case REG_POWER_CABINET_STATUS:
@@ -1089,18 +1100,21 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         break;
 
     case REG_USER_ID:
-        //DEBUG_INFO("%s\n", pCsuResult->Data.Data[0] == 1 ? "Accept" : "Reject" );
+        //log_info("%s\n", pCsuResult->Data.Data[0] == 1 ? "Accept" : "Reject" );
         //if (pCsuResult->Data.Data[0] <= 0) {
         //    return FAIL;
         //}
         if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
             return COMMAND_RESULT_NG;
         }
+
+        gAudiCustInfo->AuthorStateFromCabinet = pCsuResult->Data.Data[0];
+
         return pCsuResult->Data.Data[0];
         break;
 
     case REG_CHARGING_PERMISSION:
-        //DEBUG_INFO("id = %d, result = %s, action = %s\r\n",
+        //log_info("id = %d, result = %s, action = %s\r\n",
         //           pCsuResult->Head.ID,
         //           pCsuResult->Data.Result == 1 ? "OK" : "NG",
         //           pCsuResult->Data.Data[0] == 1 ? "Permitted" : "NOT permitted");
@@ -1166,21 +1180,21 @@ static int composeSocketData(int fd,
 
     //send command packet
     if ((size = sendTcpSocket(fd, (uint8_t *)&csuCmdPkt, sendPktLen)) < 0) {
-        DEBUG_ERROR("TCP socket send packet fail = %d\r\n", size);
+        log_error("TCP socket send packet fail = %d\r\n", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result head
     if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
-        DEBUG_ERROR("TCP socket RX head fail = %d\r\n", size);
+        log_error("TCP socket RX head fail = %d\r\n", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result raw data
     if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
-        DEBUG_ERROR("TCP socket RX data fail = %d\r\n", size);
+        log_error("TCP socket RX data fail = %d\r\n", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
@@ -1379,12 +1393,12 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
         if (strcmp(&vendorErrorCodeTmp[plugNum][0], "") == 0) {
             strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
             vendorErrorCodeTmp[plugNum][6] = '\0';
-            DEBUG_INFO("1 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+            log_info("1 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
         } else {
             if (strncmp(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE) != 0) {
                 strncpy(&vendorErrorCodeTmp[plugNum][0], (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode, WARNING_CODE_SIZE);
                 vendorErrorCodeTmp[plugNum][6] = '\0';
-                DEBUG_INFO("2 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
+                log_info("2 ID = %d, VendorErrorCode = %s\r\n", plugNum, (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
             }
         }
     }
@@ -1581,7 +1595,7 @@ static int CheckNetworkStatus(void)
     return 0;
 }
 
-static int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+static int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
     uint8_t index = 0;
 
@@ -1615,53 +1629,53 @@ static int InitShareMemory(void)
     int MeterSMId = 0;
 
     if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+        log_error("shmget ShmSysConfigAndInfo NG\n");
         result = 0;
     } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+        log_error("[shmat ShmSysConfigAndInfo NG\n");
         result = 0;
     }
 
     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+        log_error("shmget ShmStatusCodeData NG\n");
         result = 0;
     } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        log_error("shmat ShmStatusCodeData NG\n");
         result = 0;
     }
 
     //creat ShmPsuData
     if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPsuData NG \n");
+        log_error("shmget ShmPsuData NG \n");
         result = 0;
     } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPsuData NG \n");
+        log_error("shmat ShmPsuData NG \n");
         result = 0;
     }
 
     //creat ShmOCPP16Data
     if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0) {
-        DEBUG_ERROR("shmget ShmOCPP16Data NG \n");
+        log_error("shmget ShmOCPP16Data NG \n");
         result = 0;
     } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
+        log_error("shmat ShmOCPP16Data NG \n");
         result = 0;
     }
 
     if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+        log_error("shmget ShmPrimaryMcuData NG\n");
         result = 0;
     } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+        log_error("shmat ShmPrimaryMcuData NG\n");
         result = 0;
     }
 
     //creat Audi customization info
     if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmget select gun info NG \n");
+        log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
     } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmat shmget select gun info \n");
+        log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
 
@@ -1791,7 +1805,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             break;
 
         case REG_POWER_CABINET_STATUS:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 readPowerCabinetStatus(fd, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
@@ -1799,7 +1814,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             break;
 
         case REG_DISPENSER_STATUS:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 writeDispenserStatus(fd, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
@@ -1816,13 +1832,15 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
         //case REG_SOFTWARE_UPDATE:
         //    if (ChargingData[plugNum]->SystemStatus == S_IDLE) {
-        //        if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME * 10) {
+        //        if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > L OOP_RETRY_TIME||
+        //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0  * 1) {
         //            readSoftwareUpdate(fd);
         //            ftime(&gRegTimeUp[plugNum][curReg]);
         //        }
         //        while (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
         //            ftime(&NowTime);
-        //            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+        //            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowT ime) > LOOP_RETRY_TIME||
+        //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
         //                readSoftwareUpdate(fd);
         //            }
         //            usleep(128);
@@ -1832,7 +1850,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //    break;
 
         case REG_PLUG_IN_STATE:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 writePlugInStatus(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
@@ -1840,13 +1859,17 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             break;
 
         case REG_CONNECTOR_STATE:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 writeConnectorState(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
 
             //check misc command from power cabinet
             if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x\r\n", gDoCommGblData.MiscCmd);
+                }
                 curReg = gDoCommGblData.MiscCmd;
             } else {
                 curReg = REG_QRCODE_URL_INFO;
@@ -1877,7 +1900,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 //power up write dispenser version and get power cabinet system ID
                 if ((writeCsuModuleVersion(fd) == PASS) &&
                         (writeOtherModuleVersion(fd) == PASS) &&
-                        (readQRcodeURLAndSystemDate(fd) == PASS)) {
+                        (readQRcodeURLAndSystemDate(fd) == PASS)
+                   ) {
                     //gDoCommGblData.DisConnCount = 0;
                     isContinue = 0;
                 }
@@ -1907,7 +1931,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //    break;
 
         default:
-            DEBUG_ERROR("error curReg = %x\r\n", curReg);
+            log_error("error curReg = %x\r\n", curReg);
             gDoCommGblData.MiscCmd = 0;
             gDoCommGblData.DisConnCount = CHECK_NETWORK_FAIL_COUNT;
             isContinue = 0;
@@ -1995,9 +2019,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) == 0) {
-                DEBUG_INFO("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
-                           plugNum,
-                           REG_CHARGING_PERMISSION);
+                log_info("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
+                         plugNum,
+                         REG_CHARGING_PERMISSION);
                 ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
@@ -2024,9 +2048,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) == 0) {
-                DEBUG_INFO("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
-                           plugNum,
-                           REG_CHARGING_PERMISSION);
+                log_info("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
+                         plugNum,
+                         REG_CHARGING_PERMISSION);
                 ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
@@ -2050,9 +2074,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) == 0) {
-                DEBUG_INFO("Stop charging by power cabinet's permission = %d, %d\r\n",
-                           plugNum,
-                           REG_CHARGING_PERMISSION);
+                log_info("Stop charging by power cabinet's permission = %d, %d\r\n",
+                         plugNum,
+                         REG_CHARGING_PERMISSION);
                 ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
                 //printf("%d StopChargeFlag = %d\r\n", plugNum, ChargingData[plugNum]->StopChargeFlag);
             }
@@ -2090,33 +2114,33 @@ static int networkCreatePorcess(void)
     setTcpStatus(ABNORMAL);
 
     /**************** Check Network **********/
-    DEBUG_INFO("Check Dispenser Network Information");
+    log_info("Check Dispenser Network Information");
     while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE) {
         usleep(125);
     }
 
     while (!CheckNetworkStatus()) {
         calDisconnectCount(&gDoCommGblData.DisConnCount, CHECK_NETWORK_FAIL_COUNT);
-        DEBUG_ERROR("disconnect count = % d\r\n", gDoCommGblData.DisConnCount);
+        log_error("disconnect count = % d\r\n", gDoCommGblData.DisConnCount);
     }
-    DEBUG_INFO("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s",
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+    log_info("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s",
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
 
     /**************** Power cabinet connection **********/
-    DEBUG_INFO("Connect to Power Cabinet");
+    log_info("Connect to Power Cabinet");
     while ((fd = doCommConnToServer()) <= 0) {
         calDisconnectCount(&gDoCommGblData.DisConnCount, CONNECT_SERVER_FAIL_COUNT);
-        DEBUG_ERROR("disconnect count = %d, fd = %d\r\n", gDoCommGblData.DisConnCount, fd);
+        log_error("disconnect count = %d, fd = %d\r\n", gDoCommGblData.DisConnCount, fd);
     }
-    DEBUG_INFO("Power cabinet connected(fd = % d): IP = % s Netmask = % s, Gateway = % s",
-               fd,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-               ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+    log_info("Power cabinet connected(fd = % d): IP = % s Netmask = % s, Gateway = % s",
+             fd,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
+             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
     destroySelectGun(DESTROY_ALL_SEL);
@@ -2145,7 +2169,7 @@ int main(int argc, char *argv[])
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = YES;
         }
 
-        DEBUG_ERROR("DoComm Initial share memory fail\r\n");
+        log_error("DoComm Initial share memory fail\r\n");
         sleep(5);
 
         return 0;
@@ -2155,7 +2179,7 @@ int main(int argc, char *argv[])
 
     for (index = 0; index < totalConnCount; index++) {
         if (!FindChargingInfoData(index, &ChargingData[0])) {
-            DEBUG_ERROR("FindChargingInfoData false \n");
+            log_error("FindChargingInfoData false \n");
             break;
         }
         clearPricesInfo(index);
@@ -2197,7 +2221,7 @@ int main(int argc, char *argv[])
         }
 
         if (initDone == DISPENSER_SOCKET_RECONN) {
-            DEBUG_INFO("Disconnected from power cabinet...re-connecting");
+            log_info("Disconnected from power cabinet...re-connecting");
             setTcpStatus(ABNORMAL);
 
             gDoCommGblData.DisConnCount = 0;
@@ -2214,6 +2238,6 @@ int main(int argc, char *argv[])
             updateFirmwareProcess(fd, gDoCommGblData.ConnectorID[0], totalConnCount);
         }
 
-        usleep(1000);
+        usleep(10000);
     }
 }

+ 22 - 27
EVSE/Projects/DD360Audi/Apps/ReDoComm.h → EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h

@@ -1,6 +1,9 @@
 #ifndef _DO_COMM_H_
 #define _DO_COMM_H_
 
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
 //------------------------------------------------------------------------------
 //--- common define ---
 //------------------------------------------------------------------------------
@@ -31,19 +34,8 @@
 
 #define PRICES_UNIT                             0.01
 
-#define PASS                                    (1)
-#define FAIL                                    (-1)
-
-#define YES                                     (1)
-#define NO                                      (0)
-
-#define NO_DEFINE                               255
-
 #define LOOP_RETRY_TIME                         1000 //1 second
 
-#define NORMAL                                  0
-#define ABNORMAL                                1
-
 //------------------------------------------------------------------------------
 //--- dispenser ID ---
 //------------------------------------------------------------------------------
@@ -104,25 +96,27 @@
 //------------------------------------------------------------------------------
 //--- power cabinet misc command ---
 //------------------------------------------------------------------------------
-#define MISC_CMD_CONNECOTOR_TIMEOUT             0X0001
-#define MISC_CMD_OPERATIVE_STATE                0X0002
-#define MISC_CMD_DEFAULT_PRICES                 0x0003
-#define MISC_CMD_DEFAULT_CURRENCY               0x0004
-#define MISC_CMD_ACCOUNT_BALANCE                0x0005
+#define MISC_CMD_CONNECOTOR_TIMEOUT             (0X0001)
+#define MISC_CMD_OPERATIVE_STATE                (0X0002)
+#define MISC_CMD_DEFAULT_PRICES                 (0x0003)
+#define MISC_CMD_DEFAULT_CURRENCY               (0x0004)
+#define MISC_CMD_ACCOUNT_BALANCE                (0x0005)
 
-#define MISC_CMD_BACKEND_STATUS                 0x0006
-#define MISC_CMD_ETHERNET_STATUS                0x0007
-#define MISC_CMD_WIFI_STATUS                    0x0008
-#define MISC_CMD_4G_STATUS                      0x0009
+#define MISC_CMD_BACKEND_STATUS                 (0x0006)
+#define MISC_CMD_ETHERNET_STATUS                (0x0007)
+#define MISC_CMD_WIFI_STATUS                    (0x0008)
+#define MISC_CMD_4G_STATUS                      (0x0009)
+#define MISC_CMD_BILLING_INFO                   (0x000A)
+#define MISC_CMD_WEB_STOP_CHARGING              (0x000B)
 
-#define MISC_CMD_HARDWARE_REBOOT                0x0101
-#define MISC_CMD_SOFTWARE_RESTART               0x0102
-#define MISC_CMD_REMOTE_START_CHARGING          0x0103
-#define MISC_CMD_REMOTE_STOP_CHARGING           0x0104
-#define MISC_CMD_REMOTE_UNLOCK                  0x0105
+#define MISC_CMD_HARDWARE_REBOOT                (0x0101)
+#define MISC_CMD_SOFTWARE_RESTART               (0x0102)
+#define MISC_CMD_REMOTE_START_CHARGING          (0x0103)
+#define MISC_CMD_REMOTE_STOP_CHARGING           (0x0104)
+#define MISC_CMD_REMOTE_UNLOCK                  (0x0105)
 
-#define ST_UPDATE_FIRMWARE                      0x01
-#define ST_NO_UPDATE_FIRMWARE                   0x02
+#define ST_UPDATE_FIRMWARE                      (0x01)
+#define ST_NO_UPDATE_FIRMWARE                   (0x02)
 
 //------------------------------------------------------------------------------
 #pragma pack(push)
@@ -138,6 +132,7 @@ typedef struct StConnectorIDTable {
     uint8_t DcConnID1;
     uint8_t DcConnID2;
     uint8_t AcConnID;
+    uint8_t Reserved;
 } ConnectorIDTable;
 
 typedef struct StDoCommGlobalVar {

+ 198 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.c

@@ -0,0 +1,198 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <stdint.h>
+#include <string.h>
+
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+
+#include "Ev_Comm.h"
+#include "Module_EvComm.h"
+
+//------------------------------------------------------------------------------
+int PackageIdCmd(int cmd)
+{
+    return cmd | 0x80000000;
+}
+
+void SendCmdToEvboard(int cmd, uint8_t *data, uint8_t dataLen)
+{
+    int fd = GetCanFd();
+    struct can_frame frame;
+
+    frame.can_id = cmd;
+    frame.can_dlc = dataLen;
+    memcpy(frame.data, data, sizeof(frame.data));
+
+    write(fd, &frame, sizeof(struct can_frame));
+}
+
+//------------------------------------------------------------------------------
+void SetTargetAddr(uint8_t *target_number, uint8_t index)
+{
+    int id = PackageIdCmd(CMD_ADDR_ASSIGNMENT + index);
+    //printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
+    //cmd = cmd & CAN_EFF_MASK;
+
+    uint8_t data[8];
+
+    data[0] = *target_number;
+    data[1] = *(target_number + 1);
+    data[2] = *(target_number + 2);
+    data[3] = *(target_number + 3);
+    data[4] = index;
+
+    SendCmdToEvboard(id, data, 5);
+}
+
+void GetFirmwareVersion(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_FW_VER + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void GetHardwareVersion(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_HW_VER + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void SyncRtcInfo(uint8_t gun_index, uint8_t toId, int epoch)
+{
+    int id = PackageIdCmd(CMD_SYNC_RTC + toId);
+    uint8_t data[8];
+
+    data[0] = epoch & 0xff;
+    data[1] = (epoch >> 8) & 0xff;
+    data[2] = (epoch >> 16) & 0xff;
+    data[3] = (epoch >> 24) & 0xff;
+
+    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)
+{
+    int id = PackageIdCmd(CMD_CHARGING_PERMISSION + toId);
+    uint8_t data[8];
+
+    data[0] = permissionStatus;
+    data[1] = aOutputPw & 0xff;
+    data[2] = (aOutputPw >> 8) & 0xff;
+    data[3] = aOutputCur & 0xff;
+    data[4] = (aOutputCur >> 8) & 0xff;
+    data[5] = aOutputVol & 0xff;
+    data[6] = (aOutputVol >> 8) & 0xff;
+    data[7] = 0xf0;
+
+    SendCmdToEvboard(id, data, sizeof(data));
+}
+
+void SetPresentOutputPower(uint16_t outputVol_b1, uint16_t outputCur_b1, uint16_t outputVol_b2, uint16_t outputCur_b2)
+{
+    int id = PackageIdCmd(CMD_PRESENT_OUTPUT_POWER);
+    uint8_t data[8];
+
+    data[0] = outputVol_b1 & 0xff;
+    data[1] = (outputVol_b1 >> 8) & 0xff;
+    data[2] = outputCur_b1 & 0xff;
+    data[3] = (outputCur_b1 >> 8) & 0xff;
+    data[4] = outputVol_b2 & 0xff;
+    data[5] = (outputVol_b2 >> 8) & 0xff;
+    data[6] = outputCur_b2 & 0xff;
+    data[7] = (outputCur_b2 >> 8) & 0xff;
+
+    SendCmdToEvboard(id, data, 8);
+}
+
+void SetPresentOutputCapacity(uint16_t aOutputPw_b1, uint16_t aOutputCur_b1, uint16_t aOutputPw_b2, uint16_t aOutputCur_b2)
+{
+    int id = PackageIdCmd(CMD_PRESENT_OUTPUT_CAPABILITIES);
+    uint8_t data[8];
+
+    data[0] = aOutputPw_b1 & 0xff;
+    data[1] = (aOutputPw_b1 >> 8) & 0xff;
+    data[2] = aOutputCur_b1 & 0xff;
+    data[3] = (aOutputCur_b1 >> 8) & 0xff;
+    data[4] = aOutputPw_b2 & 0xff;
+    data[5] = (aOutputPw_b2 >> 8) & 0xff;
+    data[6] = aOutputCur_b2 & 0xff;
+    data[7] = (aOutputCur_b2 >> 8) & 0xff;
+
+    SendCmdToEvboard(id, data, 8);
+}
+
+void GetOutputReq(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_OUTPUT_REQ + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void GetEvBatteryInfo(uint8_t gun_index, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_BATTERY_INFO + toId);
+    uint8_t data[8];
+
+    SendCmdToEvboard(id, data, 0);
+}
+
+void EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_EVSE_STOP_CHARGING + toId);
+    uint8_t data[8];
+
+    data[0] = stopResult;
+    data[1] = *stopReason;
+    data[2] = *(stopReason + 1);
+    data[3] = *(stopReason + 2);
+    data[4] = *(stopReason + 3);
+    data[5] = *(stopReason + 4);
+    data[6] = *(stopReason + 5);
+
+    SendCmdToEvboard(id, data, 7);
+}
+
+void GetMiscellaneousInfo(uint8_t gun_index, uint8_t relayStatus, float power, float voltage, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_GET_MISC_INFO + toId);
+    uint8_t data[8];
+
+    int _power = power * 10;
+
+    data[0] = relayStatus;
+    data[1] = (int)_power & 0xff;
+    data[2] = ((int)_power >> 8) & 0xff;
+    data[3] = (int)voltage & 0xff;
+    data[4] = ((int)voltage >> 8) & 0xff;
+
+    SendCmdToEvboard(id, data, 5);
+}
+
+void SetIsolationStatus(uint8_t gun_index, uint8_t result, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_ISOLATION_STATUS + toId);
+    uint8_t data[8];
+
+    data[0] = result;
+    SendCmdToEvboard(id, data, 1);
+}
+
+void SetEvsePrechargeInfo(uint8_t gun_index, uint8_t result, uint8_t toId)
+{
+    int id = PackageIdCmd(CMD_EVSE_PRECHARGE + toId);
+    uint8_t data[8];
+
+    data[0] = result;
+    SendCmdToEvboard(id, data, 1);
+}
+

+ 62 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.h

@@ -0,0 +1,62 @@
+#ifndef _EV_COMM_H_
+#define _EV_COMM_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//EV command address
+//------------------------------------------------------------------------------
+#define CMD_NONE                                (0)
+#define CMD_ADDR_ASSIGNMENT                     (0x00000200)
+#define CMD_GET_FW_VER                          (0x00000400)
+#define CMD_GET_HW_VER                          (0x00000500)
+#define CMD_CHARGING_PERMISSION                 (0x00000600)
+#define CMD_PRESENT_OUTPUT_POWER                (0x00000700)
+#define CMD_PRESENT_OUTPUT_CAPABILITIES         (0x00000800)
+#define CMD_GET_OUTPUT_REQ                      (0x00000900)
+#define CMD_GET_BATTERY_INFO                    (0x00000A00)
+#define CMD_EVSE_STOP_CHARGING                  (0x00000C00)
+#define CMD_GET_MISC_INFO                       (0x00000D00)
+
+#define CMD_DOWNLOAD_REQ                        (0x00000E00)
+#define CMD_START_BLOCK_TRANS                   (0x00000F00)
+#define CMD_DATA_TRANS                          (0x00001000)
+#define CMD_DOWNLOAD_FINISH                     (0x00001100)
+
+#define CMD_ISOLATION_STATUS                    (0x00001200)
+#define CMD_SYNC_RTC                            (0x00001400)
+#define CMD_EVSE_PRECHARGE                      (0x00001500)
+
+// 車端主動
+#define ADDRESS_REQ                             (0x080001FF)
+#define NOTIFICATION_EV_STATUS                  (0x08000300)
+#define NOTIFICATION_EV_STOP                    (0x08000B00)
+// 車端回應
+#define ACK_EV_FW_VERSION                       (0x08000400)
+#define ACK_EV_HW_VERSION                       (0x08000500)
+#define ACK_GET_OUTPUT_REQ                      (0x08000900)
+#define ACK_GET_EV_BATTERY_INFO                 (0x08000A00)
+#define ACK_GET_MISCELLANEOUS_INFO              (0x08000D00)
+#define ACK_EVSE_ISOLATION_STATUS               (0x08001200)
+#define ACK_EVSE_PRECHAGE_INFO                  (0x08001500)
+
+//------------------------------------------------------------------------------
+// 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 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 EvseStopChargingEvent(uint8_t stopResult, uint8_t *stopReason, uint8_t toId);
+
+#endif /* _EV_COMM_H_ */

Різницю між файлами не показано, бо вона завелика
+ 361 - 181
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.c


+ 38 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.h

@@ -0,0 +1,38 @@
+#ifndef MODULE_EVCOMM_H_
+#define MODULE_EVCOMM_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+#define COMMUNICATION       2
+#define CHK_VOL_RANGE       50
+#define CHK_CUR_RANGE       20
+#define PLUG                1
+#define UNPLUG              0
+
+//------------------------------------------------------------------------------
+//DS60-120 add
+enum EV_LOG_INDEX {
+    EV_LOG_OUTPUT_CAP_POW = 0,
+    EV_LOG_OUTPUT_CAP_CUR = 1,
+    EV_LOG_NOW_OUTPUT_VOL = 2,
+    EV_LOG_NOW_OUTPUT_CUR = 3,
+    EV_LOG_EVSE_MAX_VOL   = 4,
+    EV_LOG_EVSE_MAX_CUR   = 5,
+    EV_LOG_MAX_BATT_VOL   = 6,
+    EV_LOG_REAL_CAP_POW   = 7,
+    EV_LOG_SOC            = 8,
+};
+
+//------------------------------------------------------------------------------
+typedef struct StChiilerTemp {
+    uint8_t Temp[2];
+    uint8_t Reserved[2];
+} ChillerTemp;
+
+//------------------------------------------------------------------------------
+int GetCanFd(void);
+
+#endif /* MODULE_EVCOMM_H_ */
+

+ 63 - 79
EVSE/Projects/DD360ComBox/Apps/ReModule_EventLogging.c → EVSE/Projects/DD360Audi/Apps/ModuleEventLog/Module_EventLogging.c

@@ -1,52 +1,47 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    "../../define.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include "../../../define.h"
+#include "../Config.h"
+
+//------------------------------------------------------------------------------
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 
 sqlite3 *localDb; //DS60-120 add
-#define DB_FILE             "/Storage/ChargeLog/localCgargingRecord.db" //DS60-120 add
 
-void PRINTF_FUNC(char *string, ...);
+//------------------------------------------------------------------------------
+#define DB_FILE             "/Storage/ChargeLog/localCgargingRecord.db" //DS60-120 add
 
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define EVENT_INFO(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
 
 int StoreLogMsg(const char *fmt, ...)
 {
@@ -134,17 +129,6 @@ int DiffTimeb(struct timeb ST, struct timeb ET)
     return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
 }
 
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
 //=================================
 // Common routine
 //=================================
@@ -189,7 +173,7 @@ int InitShareMemory()
 //================================================
 // Main process
 //================================================
-void AddFaultCodeToBuf(unsigned char *Code)
+void AddFaultCodeToBuf(uint8_t *Code)
 {
     if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
         memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
@@ -197,16 +181,16 @@ void AddFaultCodeToBuf(unsigned char *Code)
     }
 }
 
-void RemoveFaultCodeToBuf(unsigned char *Code)
+void RemoveFaultCodeToBuf(uint8_t *Code)
 {
-    unsigned char find = 0x01;
+    uint8_t find = 0x01;
     char _code[7];
     sprintf(_code, "%s", Code);
 
     // 把相關的錯誤碼一次移除,避免重複顯示
     while (find) {
         find = 0x00;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
             if (find == 0x00) {
                 if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
                     find = 0x01;
@@ -238,16 +222,16 @@ int DB_Open(sqlite3 *db) //DS60-120 add
 
     if (sqlite3_open(DB_FILE, &db)) {
         result = FAIL;
-        DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
+        log_error( "Can't open database: %s\n", sqlite3_errmsg(db));
         sqlite3_close(db);
     } else {
-        DEBUG_INFO( "Local event record database open successfully.\n");
+        log_info( "Local event record database open successfully.\n");
 
         if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
-            DEBUG_ERROR( "Create local event record table error message: %s\n", errMsg);
+            log_error( "Create local event record table error message: %s\n", errMsg);
         } else {
-            DEBUG_INFO( "Opened local event record table successfully\n");
+            log_info( "Opened local event record table successfully\n");
         }
 
         sqlite3_close(db);
@@ -266,23 +250,23 @@ int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode) //DS60-120 add
 
     if (sqlite3_open(DB_FILE, &db)) {
         result = FAIL;
-        DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(db));
         sqlite3_close(db);
     } else {
-        DEBUG_INFO( "Local event record database open successfully.\n");
+        log_info( "Local event record database open successfully.\n");
         if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
-            DEBUG_INFO( "Insert local event record error message: %s\n", errMsg);
+            log_info( "Insert local event record error message: %s\n", errMsg);
         } else {
-            DEBUG_INFO( "Insert local event record successfully\n");
+            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(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
-            DEBUG_INFO( "delete local event_record error message: %s\n", errMsg);
+            log_info( "delete local event_record error message: %s\n", errMsg);
         } else {
-            DEBUG_INFO( "delete local event record successfully\n");
+            log_info( "delete local event record successfully\n");
         }
 
         sqlite3_close(db);
@@ -294,10 +278,10 @@ int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode) //DS60-120 add
 int main(void)
 {
     int ByteCount, BitCount;
-    unsigned char tmp, EventCodeTmp[7];
+    uint8_t tmp, EventCodeTmp[7];
 
     if (InitShareMemory() == FAIL) {
-        DEBUG_ERROR("InitShareMemory NG\n");
+        log_error("InitShareMemory NG\n");
         if (ShmStatusCodeData != NULL) {
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
         }
@@ -316,16 +300,16 @@ int main(void)
                         memcpy(EventCodeTmp, FaultStatusCode[ByteCount * 8 + BitCount], sizeof(EventCodeTmp) - 1);
                         if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
                             //EventCodeTmp[0]=1;
-                            DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
+                            log_info("Recovery Fault Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1 << BitCount);
                             RemoveFaultCodeToBuf(EventCodeTmp);
                             EventCodeTmp[0] = '1';//DS60-120 add
                         } else {
-                            DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
+                            log_info("Fault Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1 << BitCount);
                             AddFaultCodeToBuf(EventCodeTmp);
                         }
-                        EVENT_INFO("%s\n", EventCodeTmp); //DS60-120 add
+                        event_info("%s\n", EventCodeTmp); //DS60-120 add
                         DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
                     }
                 }
@@ -342,16 +326,16 @@ int main(void)
                         memcpy(EventCodeTmp, AlarmStatusCode[ByteCount * 8 + BitCount], sizeof(EventCodeTmp) - 1);
                         if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
                             //EventCodeTmp[0]=1;
-                            DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
+                            log_info("Recovery Alarm Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1 << BitCount);
                             RemoveFaultCodeToBuf(EventCodeTmp);
                             EventCodeTmp[0] = '1';//DS60-120 add
                         } else {
-                            DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
+                            log_info("Alarm Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1 << BitCount);
                             AddFaultCodeToBuf(EventCodeTmp);
                         }
-                        EVENT_INFO("%s\n", EventCodeTmp); //DS60-120 add
+                        event_info("%s\n", EventCodeTmp); //DS60-120 add
                         DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
                     }
                 }
@@ -368,16 +352,16 @@ int main(void)
                         memcpy(EventCodeTmp, InfoStatusCode[ByteCount * 8 + BitCount], sizeof(EventCodeTmp) - 1);
                         if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
                             //EventCodeTmp[0]=1;
-                            DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
+                            log_info("Recovery Info Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1 << BitCount);
                             RemoveFaultCodeToBuf(EventCodeTmp);
                             EventCodeTmp[0] = '1';//DS60-120 add
                         } else {
-                            DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
+                            log_info("Info Code = %s\n", EventCodeTmp);
                             ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1 << BitCount);
                             AddFaultCodeToBuf(EventCodeTmp);
                         }
-                        EVENT_INFO("%s\n", EventCodeTmp); //DS60-120 add
+                        event_info("%s\n", EventCodeTmp); //DS60-120 add
                         DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
                     }
                 }

+ 171 - 248
EVSE/Projects/DD360/Apps/ReModule_InternalComm.c → EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.c

@@ -7,7 +7,6 @@
 #include <sys/socket.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
-#include <sys/shm.h>
 #include <sys/mman.h>
 #include <linux/wireless.h>
 #include <arpa/inet.h>
@@ -29,35 +28,12 @@
 #include <math.h>
 #include <stdbool.h>
 
-#include "../../define.h"
+#include "../../../define.h"
+#include "Module_InternalComm.h"
 #include "internalComm.h"
-#include "Config.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-#define STOP                0
-#define START               1
-#define RELAY_CHECK_TIME    5       // s
-#define OUTPUT_VOL_CHK_TIME 200     // ms
-#define TEN_MINUTES         600     // s
-//#define TEN_MINUTES           5
-#define ENV_TEMP_MIN        45
-#define ENV_TEMP_MAX        50
-#define DEFAULT_AC_INDEX    2
-#define EQUAL               0
-#define COLOR_MAX_LV        100
-#define COLOR_MIN_LV        0
-
-#define AC_DEFAULT_VOL      220
-
-#define NO_DEFINE           255
-#define NDEFAULT_AC_INDEX   2
-
-#define OVP_UVP_CHK_COUNT   3
+#include "../Config.h"
 
+//------------------------------------------------------------------------------
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 struct FanModuleData            *ShmFanModuleData;
@@ -67,54 +43,8 @@ struct PsuData                  *ShmPsuData;
 struct OCPP16Data               *ShmOCPP16Data;
 struct DcCommonInformation      *ShmDcCommonData;
 
-#define VIN_MAX_VOLTAGE_IEC         285 // 大於該值 : OVP
-#define VIN_MAX_REV_VOLTAGE_IEC     275 // 小於賦歸 OVP
-#define VIN_MIN_VOLTAGE_IEC         160 // 小於該值 : UVP
-#define VIN_MIN_REV_VOLTAGE_IEC     170 // 大於賦歸 UVP
-
-#define VIN_MAX_VOLTAGE_UL          315 // 大於該值 : OVP // 美規 (W)
-#define VIN_MAX_REV_VOLTAGE_UL      305 // 小於賦歸 OVP
-#define VIN_MIN_VOLTAGE_UL          210 // 小於該值 : UVP
-#define VIN_MIN_REV_VOLTAGE_UL      220 // 大於賦歸 UVP
-
-#define VIN_DROP_VOLTAGE    150 // 小於該值 : ac drop
-
-#define VOUT_MAX_VOLTAGE    995
-#define VOUT_MIN_VOLTAGE    150
-#define IOUT_MAX_CURRENT    50
-
-#define MAX_FAN_SPEED       14000
-#define MIN_FAN_SPEED       3000
-#define NORMAL_FAN_SPEED    7000
-
-// GFD Status
-#define GFD_IDLE            0
-#define GFD_CABLECHK        1
-#define GFD_PRECHARGE       2
-#define GFD_CHARGING        3
-
-// LED Intensity (rate)
-#define LED_INTENSITY_DARKEST       0.2
-#define LED_INTENSITY_MEDIUM        0.6
-#define LED_INTENSITY_BRIGHTEST     1
-
-// EE Spec
-#define LED_BRIGHTNESS_LV_HIGH      1
-#define LED_BRIGHTNESS_LV_MID       0.5
-#define LED_BRIGHTNESS_LV_LOW       0.2
-
-// 最小切換 Relay 電壓
-#define SELF_TO_CHANGE_RELAY_STATUS         600
-// 透過電壓確認 Relay 是否搭上的依據電壓
-#define CHECK_RELAY_STATUS                  300
-#define CHECK_RELAY_STATUS_GAP              100
-// 安全在停止充電程序中斷開 Relay 的電流
-#define SEFETY_SWITCH_RELAY_CUR             50//20 DS60-120 modify
-// 確認 Relay Welding 電壓
-#define RELAY_WELDING_DET                   300
-
-byte gunCount;
-byte acgunCount;
+uint8_t gunCount;
+uint8_t acgunCount;
 // 槍資訊
 struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
@@ -131,10 +61,10 @@ struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_
 // SMR1 *2 + SMR2 * 2 + Parallel * 2
 struct timeval _relayStateChkTimer[6]; //DS60-120 add
 
-byte _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
-byte _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
+uint8_t _threePhaseOvp[3] = {0, 0, 0}; //DS60-120 add
+uint8_t _threePhaseUvp[3] = {0, 0, 0}; //DS60-120 add
 
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData);
 
 int Uart5Fd;
 char *relayRs485PortName = "/dev/ttyS5";
@@ -153,7 +83,7 @@ struct timeb    _ac_endChargingTime;
 
 unsigned short _setFanSpeed = 0;
 float _beforeChargingTotalEnergy = 0.0;
-byte _checkLedChanged = 3;
+uint8_t _checkLedChanged = 3;
 
 Ver ver;
 PresentInputVoltage inputVoltage;
@@ -177,38 +107,27 @@ Ac_Alarm_code acAlarmCode;
 Ac_Charging_energy acChargingEnergy;
 Ac_Charging_current acChargingCurrent;
 
-#define AC_OVP                      1
-#define AC_UVP                      2
-#define AC_OCP                      4
-#define AC_OTP                      8
-#define AC_GMI_FAULT                16
-#define AC_CP_ERROR                 32
-#define AC_AC_LEAKAGE               64
-#define AC_DC_LEAKAGE               128
-#define AC_SYSTEM_SELFTEST_FAULT    256
-#define AC_HANDSHAKE_TIMEOUT        512
-#define AC_EMC_STOP                 1024
-#define AC_RELAY_WELDING            2048
-#define AC_GF_MODULE_FAULT          4096
-#define AC_SHUTTER_FAULT            8192
-#define AC_LOCKER_FAULT             16384
-#define AC_POWER_DROP               32768
-#define AC_CIRCUIT_SHORT            65536
-#define AC_ROTARY_SWITCH_FAULT      131072
-#define AC_RELAY_DRIVE_FAULT        262144
-
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-int _alarm_code[] = {AC_OVP, AC_UVP, AC_OCP, AC_OTP, AC_GMI_FAULT, AC_CP_ERROR, AC_AC_LEAKAGE
-                     , AC_DC_LEAKAGE, AC_SYSTEM_SELFTEST_FAULT, AC_HANDSHAKE_TIMEOUT, AC_EMC_STOP, AC_RELAY_WELDING
-                     , AC_GF_MODULE_FAULT, AC_SHUTTER_FAULT, AC_LOCKER_FAULT, AC_POWER_DROP, AC_CIRCUIT_SHORT
-                     , AC_ROTARY_SWITCH_FAULT, AC_RELAY_DRIVE_FAULT
-                    };
-
-int StoreLogMsg(const char *fmt, ...);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
+int _alarm_code[] = {
+    AC_OVP,
+    AC_UVP,
+    AC_OCP,
+    AC_OTP,
+    AC_GMI_FAULT,
+    AC_CP_ERROR,
+    AC_AC_LEAKAGE,
+    AC_DC_LEAKAGE,
+    AC_SYSTEM_SELFTEST_FAULT,
+    AC_HANDSHAKE_TIMEOUT,
+    AC_EMC_STOP,
+    AC_RELAY_WELDING,
+    AC_GF_MODULE_FAULT,
+    AC_SHUTTER_FAULT,
+    AC_LOCKER_FAULT,
+    AC_POWER_DROP,
+    AC_CIRCUIT_SHORT,
+    AC_ROTARY_SWITCH_FAULT,
+    AC_RELAY_DRIVE_FAULT
+};
 
 unsigned long GetTimeoutValue(struct timeval _sour_time)
 {
@@ -271,7 +190,7 @@ unsigned short MaxValue(unsigned short value1, unsigned short value2)
 //==========================================
 void GetFwAndHwVersion_Fan()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // FanModuleData
         strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
         // SystemInfo
@@ -279,7 +198,7 @@ void GetFwAndHwVersion_Fan()
         //log_info("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
     }
 
-    if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
+    if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // SystemInfo
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
@@ -288,7 +207,7 @@ void GetFwAndHwVersion_Fan()
 
 void GetFwAndHwVersion_Relay()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
         // RelayModuleData
         strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
         // SystemInfo
@@ -296,7 +215,7 @@ void GetFwAndHwVersion_Relay()
         //log_info("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
     }
 
-    if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
+    if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
         // SystemInfo
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
@@ -305,7 +224,7 @@ void GetFwAndHwVersion_Relay()
 
 void GetFwAndHwVersion_Led()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS) {
         // LedModuleData
         strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
         // SystemInfo
@@ -316,7 +235,7 @@ void GetFwAndHwVersion_Led()
         //log_info("GetFwAndHwVersion_Led fail \n");
     }
 
-//  if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
+//  if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
 //  {
 //      // SystemInfo
 //      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
@@ -326,7 +245,7 @@ void GetFwAndHwVersion_Led()
 
 void GetFwVersion_AC()
 {
-    if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS) {
+    if (Query_FW_Ver(Uart5Fd, ADDR_AC_PLUG, &ver) == PASS) {
         ac_chargingInfo[0]->SelfTest_Comp = YES;
         strcpy((char *) ac_chargingInfo[0]->version, ver.Version_FW);
     }
@@ -335,7 +254,7 @@ void GetFwVersion_AC()
 void GetAcModelName()
 {
     memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
-    if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
+    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
         log_info("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
     }
 }
@@ -371,14 +290,14 @@ void SetRtcData_Relay()
     rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
     rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
 
-    if (Config_Rtc_Data(Uart5Fd, Addr.Relay, &rtc) == PASS) {
+    if (Config_Rtc_Data(Uart5Fd, ADDR_RELAY, &rtc) == PASS) {
         //log_info("SetRtc (RB) sucessfully. \n");
     }
 }
 
 void SetModelName_Relay()
 {
-    if (Config_Model_Name(Uart5Fd, Addr.Relay, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(Uart5Fd, ADDR_RELAY, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
         //log_info("Set Model name (RB) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
     }
 }
@@ -414,22 +333,22 @@ void SetRtcData_Fan()
     rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
     rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
 
-    if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS) {
+    if (Config_Rtc_Data(Uart5Fd, ADDR_FAN, &rtc) == PASS) {
         //log_info("SetRtc (FB) sucessfully. \n");
     }
 }
 
 void SetModelName_Fan()
 {
-    if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(Uart5Fd, ADDR_FAN, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
         log_info("Set Model name PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
     }
 }
 
 // AC 三相輸入電壓
-void GetPresentInputVol()
+void GetPresentInputVol(void)
 {
-    if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS) {
+    if (Query_Present_InputVoltage(Uart5Fd, ADDR_RELAY, &inputVoltage) == PASS) {
         // resolution : 0.1
         ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
         ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
@@ -638,68 +557,65 @@ void GetPresentInputVol()
 }
 
 // 左右槍的 Relay 前後的輸出電壓
-void GetPersentOutputVol()
+void GetPersentOutputVol(void)
 {
-    if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS) {
-//      log_info("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-//      log_info("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
-//      log_info("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
-//      log_info("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
+    uint8_t index = 0;
 
-        //log_info("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-        //log_info("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+    if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
+        return;
+    }
 
-        ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
-        ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
-        ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
-        ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
+    //log_info("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+    //log_info("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
+    //log_info("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+    //log_info("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
 
-        for (int index = 0; index < gunCount; index++) {
-            if (index == 0) {
-                //if (_chargingData[index]->Evboard_id == 0x01) {
-                if (index == 0) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif //!defined DD360 && !defined DD360Audi
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+    //log_info("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+    //log_info("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
 
-                    //} else if (_chargingData[index]->Evboard_id == 0x02) {
-                } else if (index == 1) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif //!defined DD360 && !defined DD360Audi
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-                }
-            } else if (index == 1) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif //!defined DD360 && !defined DD360Audi
-                _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-            }
+    ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
+    ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
+    ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
+    ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
 
-            //unsigned short Ovp = 0;
-            //unsigned short Ocp = 0;
-            //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE]  // 最大輸出電壓與電池電壓最大值
-            //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]      // 最大輸出電流與需求電流最小值
-            if (_chargingData[index]->Type == _Type_Chademo) {
-                //Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
-                //Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
-            } else if (_chargingData[index]->Type == _Type_CCS_2) {
+    for (index = 0; index < gunCount; index++) {
+        switch (index) {
+        case 0:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+            _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
+            _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
+            _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-            }
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+            _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
+            break;
+
+        case 1:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+            _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
+            _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
+            _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
+            break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+            _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+            _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
+            break;
         }
+
+        //unsigned short Ovp = 0;
+        //unsigned short Ocp = 0;
+        //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE]  // 最大輸出電壓與電池電壓最大值
+        //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]      // 最大輸出電流與需求電流最小值
+        //if (_chargingData[index]->Type == _Type_Chademo) {
+        //    //Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
+        //    //Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
+        //} else if (_chargingData[index]->Type == _Type_CCS_2) {
+        //}
     }
 }
 
@@ -707,7 +623,7 @@ void GetPersentOutputVol()
 void GetFanSpeed()
 {
     //log_info("Get fan board speed \n");
-    if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS) {
+    if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
         ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
         ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
         ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
@@ -716,15 +632,15 @@ void GetFanSpeed()
 //      log_info("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
 //      log_info("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
 //      log_info("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
-        // Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
+        // Config_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed[0]);
         //SysInfoData (SystemFanRotaSpeed)
     }
 }
 
 // 讀取 Relay 狀態
-void GetRelayOutputStatus()
+void GetRelayOutputStatus(void)
 {
-    if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS) {
+    if (Query_Relay_Output(Uart5Fd, ADDR_RELAY, &regRelay) == PASS) {
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
         regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
 #endif //!defined DD360 && !defined DD360Audi
@@ -732,7 +648,7 @@ void GetRelayOutputStatus()
 }
 
 // 確認 K1 K2 relay 的狀態
-void CheckK1K2RelayOutput(byte index)
+void CheckK1K2RelayOutput(uint8_t index)
 {
     if (index == 0) {
         //if (_chargingData[index]->Evboard_id == 0x01) {
@@ -842,7 +758,7 @@ void GetGfdAdc()
     // define : 每 0.2 ~ 1 秒一次
     // occur : <= 75k 歐姆 @ 150 - 750 Vdc
     // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
-    if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS) {
+    if (Query_Gfd_Adc(Uart5Fd, ADDR_RELAY, &gfd_adc) == PASS) {
         for (gunIndex = 0; gunIndex < gunCount; gunIndex++) {
             if (_chargingData[gunIndex]->Type == 0x09 &&
                     !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag
@@ -911,7 +827,7 @@ void GetGfdAdc()
 
 void GetGpioInput()
 {
-    if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS) {
+    if (Query_Gpio_Input(Uart5Fd, ADDR_AUX, &gpio_in) == PASS) {
         // AC Contactor Status
         if (gpio_in.AC_MainBreaker == 1) {
             // AC Main Breaker ON
@@ -979,7 +895,7 @@ void GetGpioInput()
 // 5V 12V 24V 48V
 void GetAuxPower()
 {
-    if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS) {
+    if (Query_Aux_PowerVoltage(Uart5Fd, ADDR_FAN, &auxPower) == PASS) {
         ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
         ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
         //ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
@@ -1010,7 +926,7 @@ void SetFanModuleSpeed()
 
         _fanSpeed.speed[3] = _setFanSpeed;
 
-        if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS) {
+        if (Config_Fan_Speed(Uart5Fd, ADDR_FAN, &_fanSpeed) == PASS) {
             //log_info("successfully Fan\n");
         }
     }
@@ -1031,7 +947,7 @@ typedef struct StPreCharginState {
 //==========================================
 // Common Function
 //==========================================
-void SetK1K2RelayStatus(byte index)
+void SetK1K2RelayStatus(uint8_t index)
 {
     PreChargingState *pRegPreChargingState = NULL;
     PreChargingState *pOutputPreChargingState = NULL;
@@ -1048,7 +964,7 @@ void SetK1K2RelayStatus(byte index)
         return;
     }
 
-#if 0
+#if 1
     pRegPreChargingState = (PreChargingState *)&regRelay.relay_event.relay_status[0];
     pOutputPreChargingState = (PreChargingState *)&outputRelay.relay_event.relay_status[0];
     if (index == 0) {
@@ -1135,7 +1051,7 @@ void SetK1K2RelayStatus(byte index)
     }
 #endif //0
 
-#if 1
+#if 0
     if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE) {
         //if (_chargingData[index]->Evboard_id == 0x01) {
         if (index == 0) {
@@ -1259,7 +1175,7 @@ void SetK1K2RelayStatus(byte index)
 #endif //0
 }
 
-void CheckAcInputOvpStatus(byte index)
+void CheckAcInputOvpStatus(uint8_t index)
 {
     if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
@@ -1297,7 +1213,7 @@ void CheckAcInputOvpStatus(byte index)
     }
 }
 
-void CheckPhaseLossStatus(byte index)
+void CheckPhaseLossStatus(uint8_t index)
 {
     if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
@@ -1368,7 +1284,7 @@ void SetParalleRelayStatus(void)
 void CheckAlarmOccur()
 {
     bool isErr = false;
-    for (byte count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
+    for (uint8_t count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
         if (acAlarmCode.AcAlarmCode & _alarm_code[count]) {
             isErr = true;
             switch (_alarm_code[count]) {
@@ -1438,7 +1354,7 @@ bool IsNoneMatchLedColor()
 
 void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
 {
-    byte _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
+    uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
 
     if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
         _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
@@ -1558,7 +1474,7 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
     }
 
     if (_checkLedChanged > 0) {
-        if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS) {
+        if (Config_Led_Color(Uart5Fd, ADDR_LED, &led_color) == PASS) {
             _checkLedChanged--;
 
             cur_led_color.Connect_1_Red     = led_color.Connect_1_Red;
@@ -1572,6 +1488,7 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
         _checkLedChanged = 3;
     }
 }
+
 //==========================================
 // Init all share memory
 //==========================================
@@ -1650,7 +1567,7 @@ int InitComPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (byte)0;     // timeout 0.5 second
+    tios.c_cc[VTIME] = (uint8_t)0;     // timeout 0.5 second
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl (fd, TCSETS, &tios);
@@ -1661,9 +1578,9 @@ int InitComPort()
 //================================================
 // Main process
 //================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
                 == target) {
             chargingData[target] =
@@ -1672,7 +1589,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
                 == target) {
             chargingData[target] =
@@ -1681,7 +1598,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
                 == target) {
             chargingData[target] =
@@ -1693,7 +1610,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
     return false;
 }
 
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
+bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
 {
     if (target < AC_QUANTITY) {
         acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
@@ -1707,13 +1624,13 @@ void Initialization()
 {
     bool isPass = false;
 
-    for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++) {
+    for (uint8_t index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++) {
         outputRelay.relay_event.relay_status[index] = 0x00;
     }
 
     while (!isPass) {
         isPass = true;
-        for (byte _index = 0; _index < gunCount; _index++) {
+        for (uint8_t _index = 0; _index < gunCount; _index++) {
             if (!FindChargingInfoData(_index, &_chargingData[0])) {
                 log_error("InternalComm : FindChargingInfoData false \n");
                 isPass = false;
@@ -1729,7 +1646,7 @@ void Initialization()
     if (acgunCount > 0) {
         while (!isPass) {
             isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
+            for (uint8_t _index = 0; _index < acgunCount; _index++) {
                 if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
                     log_error("EvComm : FindAcChargingInfoData false \n");
                     isPass = false;
@@ -1835,20 +1752,20 @@ void CheckRelayStatusByADC()
     }
 }
 
-void SetGfdConfig(byte index, byte resister)
+void SetGfdConfig(uint8_t index, uint8_t resister)
 {
     gfd_config.index = index;
     gfd_config.state = resister;
 
     //log_info("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
-    if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS) {
+    if (Config_Gfd_Value(Uart5Fd, ADDR_RELAY, &gfd_config) == PASS) {
 //      log_info("Set reqVol = %f, resister = %d \n",
 //              gfd_config.reqVol,
 //              gfd_config.resister);
     }
 }
 
-void CableCheckDetected(byte index)
+void CableCheckDetected(uint8_t index)
 {
     // Cable Check
     // 當火線上的電壓 = 車端要求的電壓電流
@@ -1857,10 +1774,14 @@ void CableCheckDetected(byte index)
     // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
     // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
     // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
-    if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
-            (_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)) {
-        if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_TERMINATING) ||
-                (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+    if ((_chargingData[index]->Type >= _Type_Chademo &&
+            _chargingData[index]->Type <= _Type_GB) ||
+            (_chargingData[index]->Type == 0x09 &&
+             ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)) {
+        if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
+                _chargingData[index]->SystemStatus <= S_TERMINATING) ||
+                (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                 _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
             if (_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE &&
                     _chargingData[index]->RelayWeldingCheck == YES) {
                 SetGfdConfig(index, GFD_CABLECHK);
@@ -1875,14 +1796,15 @@ void CableCheckDetected(byte index)
                     SetGfdConfig(index, GFD_CHARGING);
                 }
             }
-        } else if (_chargingData[index]->SystemStatus == S_COMPLETE || _chargingData[index]->SystemStatus == S_PREPARNING
+        } else if (_chargingData[index]->SystemStatus == S_COMPLETE ||
+                   _chargingData[index]->SystemStatus == S_PREPARNING
                    || _chargingData[index]->SystemStatus == S_IDLE) {
             SetGfdConfig(index, GFD_IDLE);
         }
     }
 }
 
-void CheckOutputPowerOverCarReq(byte index)
+void CheckOutputPowerOverCarReq(uint8_t index)
 {
     float fireV = _chargingData[index]->FireChargingVoltage;
     float carV = _chargingData[index]->EvBatteryMaxVoltage * 10;
@@ -1921,7 +1843,7 @@ void CheckOutputPowerOverCarReq(byte index)
     }
 }
 
-void CheckOutputVolNoneMatchFire(byte index)
+void CheckOutputVolNoneMatchFire(uint8_t index)
 {
     if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
             (_chargingData[index]->Type == _Type_Chademo ||
@@ -1947,7 +1869,7 @@ void CheckOutputVolNoneMatchFire(byte index)
     }
 }
 
-void CheckRelayWeldingStatus(byte index)
+void CheckRelayWeldingStatus(uint8_t index)
 {
     if (!_isRelayWelding[index]) {
         if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
@@ -1979,8 +1901,8 @@ void GetPsuTempForFanSpeed()
 {
     char temp = 0;
 
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
             if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
                 temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
             }
@@ -2022,18 +1944,18 @@ void GetFanSpeedByFunction()
     // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
     unsigned int _maxPower = ShmPsuData->SystemAvailablePower;
     // 當前PSU輸出總 KW & PSU Temp :
-    unsigned char temp = 0;
+    uint8_t temp = 0;
     float power = 0;
 
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
             if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
                 temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
             }
         }
     }
 
-    for (byte gunIndex = 0; gunIndex < gunCount; gunIndex++) {
+    for (uint8_t gunIndex = 0; gunIndex < gunCount; gunIndex++) {
         power += (_chargingData[gunIndex]->PresentChargingPower * 10);
     }
 
@@ -2045,7 +1967,7 @@ void GetFanSpeedByFunction()
     if (temp > 0) {
         _temp_rate = (double)temp / 50;
     }
-    unsigned char _temp_diff = 0;
+    uint8_t _temp_diff = 0;
     if (temp > 45) {
         _temp_diff = temp - 70;
     }
@@ -2073,7 +1995,7 @@ void GetFanSpeedByFunction()
 
 void GetAcStatus()
 {
-    if (Query_AC_Status(Uart5Fd, Addr.AcPlug, &acStatus) == PASS) {
+    if (Query_AC_Status(Uart5Fd, ADDR_AC_PLUG, &acStatus) == PASS) {
         ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = acStatus.MaxCurrent;
 
         if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0) {
@@ -2102,19 +2024,19 @@ void GetAcStatus()
 
 void GetAcAlarmCode()
 {
-    if (Query_AC_Alarm_Code(Uart5Fd, Addr.AcPlug, &acAlarmCode) == PASS) {
+    if (Query_AC_Alarm_Code(Uart5Fd, ADDR_AC_PLUG, &acAlarmCode) == PASS) {
         CheckAlarmOccur();
     }
 }
 
-unsigned char GetChargingEnergy()
+uint8_t GetChargingEnergy()
 {
-    return Query_Charging_Energy(Uart5Fd, Addr.AcPlug, &acChargingEnergy);
+    return Query_Charging_Energy(Uart5Fd, ADDR_AC_PLUG, &acChargingEnergy);
 }
 
-unsigned char GetChargingCurrent()
+uint8_t GetChargingCurrent()
 {
-    return Query_Charging_Current(Uart5Fd, Addr.AcPlug, &acChargingCurrent);
+    return Query_Charging_Current(Uart5Fd, ADDR_AC_PLUG, &acChargingCurrent);
 }
 
 void ChangeLedStatus()
@@ -2127,30 +2049,30 @@ void ChangeLedStatus()
         ledStatus.ActionMode = 4;
     }
 
-    Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
+    Config_LED_Status(Uart5Fd, ADDR_AC_PLUG, &ledStatus);
 }
 
-void SetLegacyReq(byte _switch)
+void SetLegacyReq(uint8_t _switch)
 {
-    Config_Legacy_Req(Uart5Fd, Addr.AcPlug, _switch);
+    Config_Legacy_Req(Uart5Fd, ADDR_AC_PLUG, _switch);
 }
 
-void SetCpDuty(byte _value)
+void SetCpDuty(uint8_t _value)
 {
-    Config_Ac_Duty(Uart5Fd, Addr.AcPlug, _value);
+    Config_Ac_Duty(Uart5Fd, ADDR_AC_PLUG, _value);
 }
 
 void ChangeToCsuMode()
 {
-    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, Addr.AcPlug);
+    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, ADDR_AC_PLUG);
 
 //  if (ac_chargingInfo[0]->IsModeChagned == PASS)
 //  {
-//      Config_Reset_MCU(Uart5Fd, Addr.AcPlug);
+//      Config_Reset_MCU(Uart5Fd, ADDR_AC_PLUG);
 //  }
 }
 
-void ChangeStartOrStopDateTime(byte isStart)
+void ChangeStartOrStopDateTime(uint8_t isStart)
 {
     char cmdBuf[32];
     struct timeb csuTime;
@@ -2169,7 +2091,7 @@ void ChangeStartOrStopDateTime(byte isStart)
     }
 }
 
-void OcppStartTransation(byte gunIndex)
+void OcppStartTransation(uint8_t gunIndex)
 {
     if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
         strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
@@ -2181,7 +2103,7 @@ void OcppStartTransation(byte gunIndex)
     ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
 }
 
-void OcppStopTransation(byte gunIndex)
+void OcppStopTransation(uint8_t gunIndex)
 {
     if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
@@ -2193,7 +2115,7 @@ void OcppStopTransation(byte gunIndex)
     ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
 }
 
-bool OcppRemoteStop(byte gunIndex)
+bool OcppRemoteStop(uint8_t gunIndex)
 {
     bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
 
@@ -2205,9 +2127,9 @@ bool OcppRemoteStop(byte gunIndex)
     return result;
 }
 
-unsigned char isModeChange()
+uint8_t isModeChange()
 {
-    unsigned char result = NO;
+    uint8_t result = NO;
 
     if (ac_chargingInfo[0]->SystemStatus != ac_chargingInfo[0]->PreviousSystemStatus) {
         result = YES;
@@ -2235,7 +2157,7 @@ void AcChargeTypeProcess()
             GetAcStatus();
             GetAcAlarmCode();
 
-            byte _status = S_NONE;
+            uint8_t _status = S_NONE;
 
             if (ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsErrorOccur) {
                 _status = S_ALARM;
@@ -2388,7 +2310,7 @@ void AcChargeTypeProcess()
     }
 }
 
-void ResetDetAlarmStatus(byte gun)
+void ResetDetAlarmStatus(uint8_t gun)
 {
     if (_chargingData[gun]->Type == _Type_Chademo) {
         if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
@@ -2407,6 +2329,7 @@ void ResetDetAlarmStatus(byte gun)
 
 int main(void)
 {
+    uint8_t i = 0;
     if (InitShareMemory() == FAIL) {
         log_error("InitShareMemory NG\n");
         if (ShmStatusCodeData != NULL) {
@@ -2436,7 +2359,7 @@ int main(void)
     outputRelay.relay_event.bits.Gun1_N = 0x00;
     outputRelay.relay_event.bits.Gun2_N = 0x00;
     outputRelay.relay_event.bits.Gun2_P = 0x00;
-    if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS) {
+    if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay) != PASS) {
         log_info("Config_Relay_Output fail \n");
 
     }
@@ -2509,7 +2432,7 @@ int main(void)
             GetRelayOutputStatus();
 #endif //!defined DD360 && !defined DD360Audi
 
-            for (int i = 0; i < gunCount; i++) {
+            for (i = 0; i < gunCount; i++) {
                 // Cable check (Set)
                 CableCheckDetected(i);
 
@@ -2599,7 +2522,7 @@ int main(void)
 
             // 搭上/鬆開 Relay
             if (IsNoneMatchRelayStatus()) {
-                if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay)) {
+                if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
                     //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
                     regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
                     regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;

+ 92 - 0
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.h

@@ -0,0 +1,92 @@
+#ifndef _MODULE_INTERNAL_COMM_H_
+#define _MODULE_INTERNAL_COMM_H_
+
+//------------------------------------------------------------------------------
+#define RELAY_CHECK_TIME                        (5)       // s
+#define OUTPUT_VOL_CHK_TIME                     (200)     // ms
+#define TEN_MINUTES                             (600)     // s
+//#define TEN_MINUTES                             5
+#define ENV_TEMP_MIN                            (45)
+#define ENV_TEMP_MAX                            (50)
+#define DEFAULT_AC_INDEX                        (2)
+#define COLOR_MAX_LV                            (100)
+#define COLOR_MIN_LV                            (0)
+
+#define AC_DEFAULT_VOL                          (220)
+
+#define NDEFAULT_AC_INDEX                       (2)
+
+#define OVP_UVP_CHK_COUNT                       (3)
+
+#define VIN_MAX_VOLTAGE_IEC                     (285) // 大於該值 : OVP
+#define VIN_MAX_REV_VOLTAGE_IEC                 (275) // 小於賦歸 OVP
+#define VIN_MIN_VOLTAGE_IEC                     (160) // 小於該值 : UVP
+#define VIN_MIN_REV_VOLTAGE_IEC                 (170) // 大於賦歸 UVP
+
+#define VIN_MAX_VOLTAGE_UL                      (315) // 大於該值 : OVP // 美規 (W)
+#define VIN_MAX_REV_VOLTAGE_UL                  (305) // 小於賦歸 OVP
+#define VIN_MIN_VOLTAGE_UL                      (210) // 小於該值 : UVP
+#define VIN_MIN_REV_VOLTAGE_UL                  (220) // 大於賦歸 UVP
+
+#define VIN_DROP_VOLTAGE                        (150) // 小於該值 : ac drop
+
+#define VOUT_MAX_VOLTAGE                        (995)
+#define VOUT_MIN_VOLTAGE                        (150)
+#define IOUT_MAX_CURRENT                        (50)
+
+#define MAX_FAN_SPEED                           (14000)
+#define MIN_FAN_SPEED                           (3000)
+#define NORMAL_FAN_SPEED                        (7000)
+
+// GFD Status
+#define GFD_IDLE                                (0)
+#define GFD_CABLECHK                            (1)
+#define GFD_PRECHARGE                           (2)
+#define GFD_CHARGING                            (3)
+
+// LED Intensity (rate)
+#define LED_INTENSITY_DARKEST                   (0.2)
+#define LED_INTENSITY_MEDIUM                    (0.6)
+#define LED_INTENSITY_BRIGHTEST                 (1)
+
+// EE Spec
+#define LED_BRIGHTNESS_LV_HIGH                  (1)
+#define LED_BRIGHTNESS_LV_MID                   (0.5)
+#define LED_BRIGHTNESS_LV_LOW                   (0.2)
+
+// 最小切換 Relay 電壓
+#define SELF_TO_CHANGE_RELAY_STATUS             (600)
+// 透過電壓確認 Relay 是否搭上的依據電壓
+#define CHECK_RELAY_STATUS                      (300)
+#define CHECK_RELAY_STATUS_GAP                  (100)
+// 安全在停止充電程序中斷開 Relay 的電流
+#define SEFETY_SWITCH_RELAY_CUR                 (50)//20 DS60-120 modify
+// 確認 Relay Welding 電壓
+#define RELAY_WELDING_DET                       (300)
+
+#define AC_OVP                                  (1)
+#define AC_UVP                                  (2)
+#define AC_OCP                                  (4)
+#define AC_OTP                                  (8)
+#define AC_GMI_FAULT                            (16)
+#define AC_CP_ERROR                             (32)
+#define AC_AC_LEAKAGE                           (64)
+#define AC_DC_LEAKAGE                           (128)
+#define AC_SYSTEM_SELFTEST_FAULT                (256)
+#define AC_HANDSHAKE_TIMEOUT                    (512)
+#define AC_EMC_STOP                             (1024)
+#define AC_RELAY_WELDING                        (2048)
+#define AC_GF_MODULE_FAULT                      (4096)
+#define AC_SHUTTER_FAULT                        (8192)
+#define AC_LOCKER_FAULT                         (16384)
+#define AC_POWER_DROP                           (32768)
+#define AC_CIRCUIT_SHORT                        (65536)
+#define AC_ROTARY_SWITCH_FAULT                  (131072)
+#define AC_RELAY_DRIVE_FAULT                    (262144)
+
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
+#endif /* _MODULE_INTERNAL_COMM_H_ */

Різницю між файлами не показано, бо вона завелика
+ 299 - 345
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/internalComm.c


+ 251 - 0
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/internalComm.h

@@ -0,0 +1,251 @@
+/*
+ * internalComm.h
+ *
+ *  Created on: 2019年5月7日
+ *      Author: foluswen
+ */
+
+#ifndef _INTERNAL_COMM_H_
+#define _INTERNAL_COMM_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//address
+#define ADDR_AUX                                (0x01)
+#define ADDR_FAN                                (0x02)
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#define ADDR_RELAY                              (0x09)
+#else
+#define ADDR_RELAY                              (0x03)
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+#define ADDR_AC_PLUG                            (0x05)
+#define ADDR_LED                                (0x06)
+#define ADDR_BROADCAST                          (0xFF)
+
+//command
+#define CMD_QUERY_FW_VER                        (0x01)
+#define CMD_QUERY_HW_VER                        (0x02)
+#define CMD_QUERY_PRESENT_IN_VOL                (0x03)
+#define CMD_QUERY_PRESENT_OUT_VOL               (0x04)
+#define CMD_QUERY_FAN_SPEED                     (0x05)
+#define CMD_QUERY_TEMPERATURE                   (0x06)
+#define CMD_QUERY_AUX_POWER_VOL                 (0x07)
+#define CMD_QUERY_RELAY_OUTPUT                  (0x08)
+#define CMD_QUERY_GFD_ADC                       (0x09)
+#define CMD_QUERY_GPIO_IN                       (0x0a)
+#define CMD_QUERY_MODEL_NAME                    (0x24)
+#define CMD_QUERY_AC_OUTPUT_CURRENT             (0x27)
+#define CMD_QUERY_AC_STATUS                     (0x28)
+#define CMD_QUERY_AC_ALARM_CODE                 (0x29)
+#define CMD_QUERY_AC_OUTPUT_ENERGY              (0x2C)
+
+#define CMD_CONFIG_FAN_SPEED                    (0x81)
+#define CMD_CONFIG_MODEL_NAME                   (0x83)
+#define CMD_CONFIG_RELAY_OUTPUT                 (0x85)
+#define CMD_CONFIG_GPIO_OUTPUT                  (0x86)
+#define CMD_CONFIG_RTC_DATA                     (0x87)
+#define CMD_CONFIG_AC_LED_STATUS                (0x88)
+#define CMD_CONFIG_AC_DUTY                      (0x89)
+#define CMD_CONFIG_LEGACY_REQ                   (0x8A)
+#define CMD_CONFIG_GDF_VALUE                    (0x8B)
+#define CMD_CONFIG_RESET_MCU                    (0x8C)
+#define CMD_CONFIG_CSU_MODE                     (0x90)
+#define CMD_CONFIG_LEN_COLOR                    (0x93)
+
+#define CMD_UPDATE_START                        (0xe0)
+#define CMD_UPDATE_ABORT                        (0xe1)
+#define CMD_UPDATE_TRANSFER                     (0xe2)
+#define CMD_UPDATE_FINISH                       (0xe3)
+
+//------------------------------------------------------------------------------
+typedef struct Verion {
+    char Version_FW[9];
+    char Version_HW[9];
+} Ver;
+
+typedef struct PRESENTINPUTVOLTAGE {
+    uint8_t inputType;    // 0x00: Line to Line       0x01: Line to Neutral
+    double L1N_L12;
+    double L2N_L23;
+    double L3N_L31;
+} PresentInputVoltage;
+
+typedef struct PRESENTOUTPUTVOLTAGE {
+    double behindFuse_Voltage_C1;
+    double behindRelay_Voltage_C1;
+    double behindFuse_Voltage_C2;
+    double behindRelay_Voltage_C2;
+} PresentOutputVoltage;
+
+typedef struct FANSPEED {
+    uint16_t speed[8];
+} FanSpeed;
+
+typedef struct TEMPERATURE {
+    uint8_t temperature[8];
+} Temperature;
+
+typedef struct AUXPOWER {
+    uint8_t voltage[8];
+} AuxPower;
+
+typedef struct RELAY {
+    union {
+        uint8_t relay_status[8];
+        struct {
+            uint8_t AC_Contactor : 1;     //bit 0
+            uint8_t CCS_Precharge : 1; //bit 1
+            uint8_t : 1;              //bit 2 reserved
+            uint8_t : 1;                  //bit 3 reserved
+            uint8_t : 1;                  //bit 4 reserved
+            uint8_t : 1;                  //bit 5 reserved
+            uint8_t : 1;                  //bit 6 reserved
+            uint8_t : 1;                  //bit 7 reserved
+
+            uint8_t Gun1_N : 1;           //bit 0
+            uint8_t Gun1_P : 1;           //bit 1
+            uint8_t Gun1_Parallel_N : 1; //bit 2
+            uint8_t Gun1_Parallel_P : 1;  //bit 3
+            uint8_t : 1;                  //bit 4 reserved
+            uint8_t : 1;                  //bit 5 reserved
+            uint8_t : 1;                  //bit 6 reserved
+            uint8_t : 1;                  //bit 7 reserved
+
+            uint8_t Gun2_N : 1;           //bit 0
+            uint8_t Gun2_P : 1;           //bit 1
+            uint8_t : 1;                  //bit 2 reserved
+            uint8_t : 1;                  //bit 3 reserved
+            uint8_t : 1;                  //bit 4 reserved
+            uint8_t : 1;                  //bit 5 reserved
+            uint8_t : 1;                  //bit 6 reserved
+            uint8_t : 1;                  //bit 7 reserved
+        } bits;
+    } relay_event;
+} Relay;
+
+typedef struct GFD {
+    unsigned short Resister_conn1;
+    unsigned short voltage_conn1;
+    uint8_t result_conn1;
+    uint8_t rb_step_1;
+
+    unsigned short Resister_conn2;
+    unsigned short voltage_conn2;
+    uint8_t result_conn2;
+    uint8_t rb_step_2;
+} Gfd;
+
+typedef struct Gfd_CONFIG {
+    uint8_t index;
+    uint8_t state;
+} Gfd_config;
+
+typedef struct GPIO_IN {
+    uint8_t AC_Connector;         // bit 0
+    uint8_t AC_MainBreaker;           // bit 1
+    uint8_t SPD;                      // bit 2
+    uint8_t Door_Open;                // bit 3
+    uint8_t GFD[2];                   // bit 4,5
+    uint8_t AC_Drop;                  // bit 6
+
+    uint8_t Emergency_IO;         // bit 0
+
+    uint8_t Button_Emergency_Press;   // bit 0
+    uint8_t Button_On_Press;          // bit 1
+    uint8_t Button_Off_Press;     // bit 2
+    uint8_t Key_1_Press;              // bit 3
+    uint8_t Key_2_Press;              // bit 4
+    uint8_t Key_3_Press;              // bit 5
+    uint8_t Key_4_Press;              // bit 6
+} Gpio_in;
+
+typedef struct GPIO_OUT {
+    uint8_t AC_Connector;
+    uint8_t Button_LED[2];
+    uint8_t System_LED[4];
+} Gpio_out;
+
+typedef struct RTC {
+    uint8_t RtcData[14];
+} Rtc;
+
+typedef struct LED_Color {
+    uint8_t Connect_1_Red;
+    uint8_t Connect_1_Green;
+    uint8_t Connect_1_Blue;
+    uint8_t Connect_2_Red;
+    uint8_t Connect_2_Green;
+    uint8_t Connect_2_Blue;
+} Led_Color;
+
+typedef struct AC_Status {
+    uint8_t       CpStatus;
+    unsigned short      CurLimit;
+    short               PilotVol_P;
+    short               PilotVol_N;
+    uint8_t       LockStatus;
+    uint8_t       RelayStatus;
+    uint8_t       ShutterStatus;
+    uint8_t       MeterStatus;
+    uint8_t       PpStatus;
+    uint8_t       MaxCurrent;
+    uint8_t       RotateSwitchStatus;
+} Ac_Status;
+
+typedef struct AC_LED_Status {
+    uint8_t       ActionMode;
+    unsigned long       AcAlarmCode;
+} Ac_Led_Status;
+
+typedef struct AC_Alarm_Code {
+    uint32_t        AcAlarmCode;
+} Ac_Alarm_code;
+
+typedef struct AC_Charging_Energy {
+    uint32_t        Energy;
+} Ac_Charging_energy;
+
+typedef struct AC_Charging_Current {
+    unsigned short      OuputCurrentL1;
+    unsigned short      OuputCurrentL2;
+    unsigned short      OuputCurrentL3;
+} Ac_Charging_current;
+
+int Query_FW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_HW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_Present_InputVoltage(uint8_t fd, uint8_t targetAddr, PresentInputVoltage *Ret_Buf);
+int Query_Present_OutputVoltage(uint8_t fd, uint8_t targetAddr, PresentOutputVoltage *Ret_Buf);
+int Query_Fan_Speed(uint8_t fd, uint8_t targetAddr, FanSpeed *Ret_Buf);
+int Query_Temperature(uint8_t fd, uint8_t targetAddr, Temperature *Ret_Buf);
+int Query_Aux_PowerVoltage(uint8_t fd, uint8_t targetAddr, AuxPower *Ret_Buf);
+int Query_Relay_Output(uint8_t fd, uint8_t targetAddr, Relay *Ret_Buf);
+int Query_Gfd_Adc(uint8_t fd, uint8_t targetAddr, Gfd *Ret_Buf);
+int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf);
+int Query_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname);
+int Query_AC_Status(uint8_t fd, uint8_t targetAddr, Ac_Status *Ret_Buf);
+int Query_AC_Alarm_Code(uint8_t fd, uint8_t targetAddr, Ac_Alarm_code *Ret_Buf);
+int Query_Charging_Energy(uint8_t fd, uint8_t targetAddr, Ac_Charging_energy *Ret_Buf);
+int Query_Charging_Current(uint8_t fd, uint8_t targetAddr, Ac_Charging_current *Ret_Buf);
+
+int Config_Fan_Speed(uint8_t fd, uint8_t targetAddr, FanSpeed *Set_Buf);
+int Config_Relay_Output(uint8_t fd, uint8_t targetAddr, Relay *Set_Buf);
+int Config_Gpio_Output(uint8_t fd, uint8_t targetAddr, Gpio_out *Set_Buf);
+int Config_Gfd_Value(uint8_t fd, uint8_t targetAddr, Gfd_config *Set_Buf);
+int Config_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname);
+int Config_Rtc_Data(uint8_t fd, uint8_t targetAddr, Rtc *Set_Buf);
+
+int Config_LED_Status(uint8_t fd, uint8_t targetAddr, Ac_Led_Status *Ret_Buf);
+int Config_Legacy_Req(uint8_t fd, uint8_t targetAddr, uint8_t _switch);
+int Config_Ac_Duty(uint8_t fd, uint8_t targetAddr, uint8_t _value);
+int Config_CSU_Mode(uint8_t fd, uint8_t targetAddr);
+int Config_Reset_MCU(uint8_t fd, uint8_t targetAddr);
+int Config_Led_Color(uint8_t fd, uint8_t targetAddr, Led_Color *Ret_Buf);
+
+int Update_Start(uint8_t fd, uint8_t targetAddr, uint32_t crc32);
+int Update_Abord(uint8_t fd, uint8_t targetAddr);
+int Update_Transfer(uint8_t fd, uint8_t targetAddr, uint32_t startAddr, uint8_t *data, uint16_t length);
+int Update_Finish(uint8_t fd, uint8_t targetAddr);
+
+#endif /* _INTERNAL_COMM_H_ */

+ 114 - 127
EVSE/Projects/DD360Audi/Apps/ReModule_LcmControl.c → EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -1,21 +1,18 @@
-#include "ReModule_LcmControl.h"
-#include "Config.h"
-#include "AudiCust.h"
+#include <stdint.h>
+
+#include "Module_LcmControl.h"
+#include "../Config.h"
+#include "../SelectGun/SelectGun.h"
 
 static AudiCustInfo *gAudiCustInfo = NULL;
 bool needReloadQr = true;
 
 bool _isShow = false; //DS60-120 add
-byte _showInformIndex = 0; //DS60-120 add
-
-void PRINTF_FUNC(char *string, ...);
+uint8_t _showInformIndex = 0; //DS60-120 add
 
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-char *getTimeString(void);
+#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)
 
 //=================================
 // Common routine
@@ -65,17 +62,6 @@ char *getTimeString(void)
     return result;
 }
 
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
 //==========================================
 // Init all share memory
 //==========================================
@@ -87,12 +73,12 @@ int InitShareMemory()
     //creat ShmSysConfigAndInfo
     if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+        log_error("shmget ShmSysConfigAndInfo NG\n");
 #endif
         result = FAIL;
     } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+        log_error("shmat ShmSysConfigAndInfo NG\n");
 #endif
         result = FAIL;
     } else
@@ -101,12 +87,12 @@ int InitShareMemory()
     //creat ShmStatusCodeData
     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+        log_error("shmget ShmStatusCodeData NG\n");
 #endif
         result = FAIL;
     } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        log_error("shmat ShmStatusCodeData NG\n");
 #endif
         result = FAIL;
     } else
@@ -114,22 +100,22 @@ int InitShareMemory()
 
     //creat Audi customization info
     if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmget select gun info NG \n");
+        log_error("[main]CreatShareMemory:shmget select gun info NG \n");
         return 0;
     } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmat shmget select gun info \n");
+        log_error("[main]CreatShareMemory:shmat shmget select gun info \n");
         return 0;
     }
 
     //creat ShmStatusCodeData
     if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+        log_error("shmget ShmPrimaryMcuData NG\n");
 #endif
         result = FAIL;
     } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
 #ifdef ShmPrimaryMcuData
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+        log_error("shmat ShmPrimaryMcuData NG\n");
 #endif
         result = FAIL;
     }
@@ -148,7 +134,7 @@ int CreateCommunicationLcmPort()
     fd = open(pPortName, O_RDWR);
     if (fd <= 0) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("open /dev/ttyS3 NG \n");
+        log_error("open /dev/ttyS3 NG \n");
 #endif
         return -1;
     }
@@ -158,7 +144,7 @@ int CreateCommunicationLcmPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char) 5;
+    tios.c_cc[VTIME] = (uint8_t) 5;
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl(fd, TCSETS, &tios);
@@ -171,15 +157,15 @@ void CloseCommunicationLcmPort()
     close(_port);
 }
 
-void WriteCmdToLcm(byte *cmd, byte cmdLen)
+void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
 {
     int len = write(_port, cmd, cmdLen);
     if (len >= sizeof(cmd)) {
-        //PRINTF_FUNC("Write cmd to LCM successfully. \n");
+        //log_info("Write cmd to LCM successfully. \n");
     }
 }
 
-void ReadMsgFromLcm(byte *msg, byte readLen)
+void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
 {
     read(_port, msg, readLen);
 
@@ -211,7 +197,7 @@ void ReadMsgFromLcm(byte *msg, byte readLen)
 //================================================
 void ChangeToOtherPage(short newPage)
 {
-    byte cmd[7];
+    uint8_t cmd[7];
     memset(cmd, 0x00, sizeof(cmd));
 
     cmd[0] = CMD_TITLE_1;
@@ -228,12 +214,12 @@ void ChangeToOtherPage(short newPage)
 
 void ChangeBackLight(bool islight)
 {
-    byte value = 0x01;
+    uint8_t value = 0x01;
 
     if (islight) {
         value = 0x20;
     }
-    byte cmd[7];
+    uint8_t cmd[7];
     memset(cmd, 0x00, sizeof(cmd));
 
     cmd[0] = CMD_TITLE_1;
@@ -249,9 +235,9 @@ void ChangeBackLight(bool islight)
 
 void GetCurrentPage()
 {
-    byte cmd[6];
+    uint8_t cmd[6];
     memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
+    uint8_t msg[8];
     memset(msg, 0x00, sizeof(msg));
 
     cmd[0] = CMD_TITLE_1;
@@ -266,9 +252,9 @@ void GetCurrentPage()
     ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
 }
 
-void DisplayValueToLcm(short address, byte *data, byte len)
+void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
 {
-    byte cmd[256];
+    uint8_t cmd[256];
     memset(cmd, 0x00, sizeof(cmd));
 
     cmd[0] = CMD_TITLE_1;
@@ -278,7 +264,7 @@ void DisplayValueToLcm(short address, byte *data, byte len)
     cmd[4] = address >> 8;
     cmd[5] = address & 0x00FF;
 
-    for (byte count = 0; count < len; count++) {
+    for (uint8_t count = 0; count < len; count++) {
         cmd[6 + count] = *(data + count);
     }
 
@@ -287,18 +273,18 @@ void DisplayValueToLcm(short address, byte *data, byte len)
 
 void ChangeDisplay2Value(short address, short value)
 {
-    byte data[2];
+    uint8_t data[2];
     data[0] = value >> 8;
     data[1] = value & 0x00FF;
 
     DisplayValueToLcm(address, data, sizeof(data));
 }
 
-void GetBtnStatus(short address, byte len)
+void GetBtnStatus(short address, uint8_t len)
 {
-    byte cmd[8];
+    uint8_t cmd[8];
     memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
+    uint8_t msg[8];
     memset(msg, 0x00, sizeof(msg));
 
     cmd[0] = CMD_TITLE_1;
@@ -317,7 +303,7 @@ void GetBtnStatus(short address, byte len)
 //================================================
 // Warning process
 //================================================
-void string2ByteArray(unsigned char *input, byte *output)
+void string2ByteArray(uint8_t *input, uint8_t *output)
 {
     int loop;
     int i;
@@ -333,12 +319,13 @@ void string2ByteArray(unsigned char *input, byte *output)
 
 void ChangeWarningFunc()
 {
-    byte cmd[7];
-    byte i = 0, j = 0;
-    //PRINTF_FUNC("ChangeWarningFunc \n");
+    uint8_t cmd[7] = {0};
+    uint8_t i = 0;
+    //uint8_t j = 0;
+    //log_info("ChangeWarningFunc \n");
     // 最多一次五筆
-    //PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
-    //PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
+    //log_info("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
+    //log_info("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
 //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
     for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         memset(cmd, 0x00, sizeof(cmd));
@@ -475,7 +462,7 @@ void ChangeQrCode_Idle(char *input)
 
 #else
     int len = strlen(input);
-    byte cmd[len];
+    uint8_t cmd[len];
 
     int loop = 0;
     int i = 0;
@@ -550,7 +537,7 @@ void ChangeQrCode_Charge(char *input)
 
 #else
     int len = strlen(input);
-    byte cmd[len];
+    uint8_t cmd[len];
 
     int loop = 0;
     int i = 0;
@@ -568,7 +555,7 @@ void ChangeQrCode_Charge(char *input)
 //================================================
 void ChangeCurPage()
 {
-    //PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
+    //log_info("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
     if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex) {
         _currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
         ChangeToOtherPage(_currentPage);
@@ -579,7 +566,7 @@ void ChangeCurPage()
 //================================================
 // Main process
 //================================================
-byte demoCount = 0;
+uint8_t demoCount = 0;
 void DemoFunction()
 {
     if (demoCount == 0) {
@@ -614,23 +601,23 @@ void DemoFunction()
 //================================================
 // Main process
 //================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **_chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
             _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
             _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
             _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
             return true;
@@ -640,7 +627,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
     return false;
 }
 
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
+bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
 {
     if (target < AC_QUANTITY) {
         acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
@@ -657,8 +644,8 @@ bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingDat
  */
 static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
 {
-    byte cmd[10] = {0};
-    byte value[10] = {0};
+    uint8_t cmd[10] = {0};
+    uint8_t value[10] = {0};
     uint8_t len = 0;
     float balance = gAudiCustInfo->PricesInfo[index].Balance;
 
@@ -669,7 +656,7 @@ static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
     len += sprintf((char *) value, "%.2f", balance);
     if (len < 6) {
         sprintf((char *)&value[len], "%s",
-                (byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+                (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
     }
 
     value[sizeof(value) - 1] = '\0';
@@ -782,8 +769,8 @@ void ChangeBattMapAndValue(short page, int soc)
         }
     }
 
-    byte cmd[5];
-    byte value[5];
+    uint8_t cmd[5];
+    uint8_t value[5];
 
     memset(cmd, 0x00, sizeof(cmd));
     memset(value, 0x00, sizeof(value));
@@ -795,8 +782,8 @@ void ChangeBattMapAndValue(short page, int soc)
 void ChangeRemainTime(int sec)
 {
     int h, m, s;
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -815,8 +802,8 @@ void ChangeRemainTime(int sec)
 
 void ChangeChargingEnergyValue(float energy)
 {
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
     if (energy >= 0.05) {
@@ -829,8 +816,8 @@ void ChangeChargingEnergyValue(float energy)
 
 void ChangeChargingPowerValue(float pow)
 {
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -844,8 +831,8 @@ void ChangeChargingPowerValue(float pow)
 
 void ChangeChargingFeeValue(float fee)
 {
-    byte cmd[10];
-    byte value[10];
+    uint8_t cmd[10];
+    uint8_t value[10];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -856,8 +843,8 @@ void ChangeChargingFeeValue(float fee)
 
 void DisplayMoneyRate(float money)
 {
-    byte cmd[8];
-    byte value[8];
+    uint8_t cmd[8];
+    uint8_t value[8];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -866,10 +853,10 @@ void DisplayMoneyRate(float money)
     DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
 }
 
-void DisplayMoneyCur(byte *cur)
+void DisplayMoneyCur(uint8_t *cur)
 {
-    byte cmd[10] = {0};
-    byte buf[10] = {0};
+    uint8_t cmd[10] = {0};
+    uint8_t buf[10] = {0};
     uint8_t len = 0;
 
     *(cur + 3) = '\0';
@@ -880,7 +867,7 @@ void DisplayMoneyCur(byte *cur)
     DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
 }
 
-void RefreshPageAnimation(byte value)
+void RefreshPageAnimation(uint8_t value)
 {
     switch (_currentPage) {
     case _LCM_IDLE: {
@@ -994,7 +981,7 @@ void RefreshConnStatus()
         }
     }
 
-    //unsigned char flag[4] = {0};
+    //uint8_t flag[4] = {0};
 
     /*for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
         //printf("status code = %s\r\n", &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
@@ -1162,9 +1149,9 @@ void RefreshConnStatus()
 #endif //defined DD360 || defined DD360Audi
 }
 
-byte FirstPageChanged()
+uint8_t FirstPageChanged()
 {
-    byte result = NO;
+    uint8_t result = NO;
 
     if (_currentPage != _oldPage) {
         result = YES;
@@ -1214,10 +1201,10 @@ void ClearDisplayInfo()
     ChangeDisplay2Value(__fan_speed_value, _disappear);
 }
 
-void DisplayInfoCsuVer(bool isShow, unsigned char *modelName)
+void DisplayInfoCsuVer(bool isShow, uint8_t *modelName)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *)value, "CSU Ver >");
@@ -1231,10 +1218,10 @@ void DisplayInfoCsuVer(bool isShow, unsigned char *modelName)
     }
 }
 
-void ShowWifiMode(bool isShow, unsigned char mode)
+void ShowWifiMode(bool isShow, uint8_t mode)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Wifi Mo. >");
@@ -1255,10 +1242,10 @@ void ShowWifiMode(bool isShow, unsigned char mode)
     }
 }
 
-void DisplayInfoEthIp(bool isShow, unsigned char *ip)
+void DisplayInfoEthIp(bool isShow, uint8_t *ip)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Eth IP >");
@@ -1275,7 +1262,7 @@ void DisplayInfoEthIp(bool isShow, unsigned char *ip)
 void Show4GRssi(bool isShow, int dbValue)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "RSSI >");
@@ -1289,10 +1276,10 @@ void Show4GRssi(bool isShow, int dbValue)
     }
 }
 
-void DisplayInfoSN(bool isShow, unsigned char *sn)
+void DisplayInfoSN(bool isShow, uint8_t *sn)
 {
     if (isShow) {
-        byte value[30];
+        uint8_t value[30];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "SN >");
@@ -1309,7 +1296,7 @@ void DisplayInfoSN(bool isShow, unsigned char *sn)
 void ShowWifiRssi(bool isShow, int dbValue)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "RSSI >");
@@ -1323,10 +1310,10 @@ void ShowWifiRssi(bool isShow, int dbValue)
     }
 }
 
-void DisplayInfoGun1Ver(bool isShow, unsigned char *version)
+void DisplayInfoGun1Ver(bool isShow, uint8_t *version)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Ct1 Ver >");
@@ -1340,10 +1327,10 @@ void DisplayInfoGun1Ver(bool isShow, unsigned char *version)
     }
 }
 
-void Show4GMode(bool isShow, unsigned char mode)
+void Show4GMode(bool isShow, uint8_t mode)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "3/4G Mo. >");
@@ -1362,10 +1349,10 @@ void Show4GMode(bool isShow, unsigned char mode)
     }
 }
 
-void DisplayInfoGun2Ver(bool isShow, unsigned char *version)
+void DisplayInfoGun2Ver(bool isShow, uint8_t *version)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Ct2 Ver >");
@@ -1379,10 +1366,10 @@ void DisplayInfoGun2Ver(bool isShow, unsigned char *version)
     }
 }
 
-void Show4GIP(bool isShow, unsigned char *ip)
+void Show4GIP(bool isShow, uint8_t *ip)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "3/4G IP >");
@@ -1399,7 +1386,7 @@ void Show4GIP(bool isShow, unsigned char *ip)
 void DisplayInfoSpeed(bool isShow, unsigned int fan)
 {
     if (isShow) {
-        byte value[10];
+        uint8_t value[10];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Fan Spd >");
@@ -1413,10 +1400,10 @@ void DisplayInfoSpeed(bool isShow, unsigned int fan)
     }
 }
 
-void ShowWifiIP(bool isShow, unsigned char *ip)
+void ShowWifiIP(bool isShow, uint8_t *ip)
 {
     if (isShow) {
-        byte value[20];
+        uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
         strcpy((char *) value, "Wifi IP >");
@@ -1521,10 +1508,10 @@ void ProcessPageInfo()
         if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
             needReloadQr = false;
             if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO) {
-                //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+                //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
                 ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
             } else {
-                //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+                //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
                 ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
             }
             //ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
@@ -1533,7 +1520,7 @@ void ProcessPageInfo()
 
         //DS60-120 add
         bool isCharging = false;
-        for (byte i = 0; i < _totalCount; i++) {
+        for (uint8_t i = 0; i < _totalCount; i++) {
             if (_chargingInfoData[i]->SystemStatus == S_IDLE) {
                 continue;
             }
@@ -1566,7 +1553,7 @@ void ProcessPageInfo()
             // 新增隨插即充功能預設在等待插槍頁面在開啟
             ChangeDisplay2Value(__ret_home_btn, _disappear);
             bool isCharging = false;
-            for (byte i = 0; i < _totalCount; i++) {
+            for (uint8_t i = 0; i < _totalCount; i++) {
                 if (_chargingInfoData[i]->SystemStatus == S_IDLE) {
                     continue;
                 }
@@ -1589,7 +1576,7 @@ void ProcessPageInfo()
     case _LCM_CHARGING:
     case _LCM_COMPLETE: {
         bool isShowAc = false;
-        byte gunTargetIndex = 0;
+        uint8_t gunTargetIndex = 0;
 
         if (acgunCount > 0) {
             gunTargetIndex = 2;
@@ -1686,7 +1673,7 @@ void ProcessPageInfo()
         }
 
         gunTargetIndex = 0; //DS60-120 add
-        for (byte i = 0; i < _totalCount; i++) {
+        for (uint8_t i = 0; i < _totalCount; i++) {
             if (_totalCount == 1 && acgunCount <= 0) { //DS60-120 add
                 gunTargetIndex = 2;
             } else {
@@ -1832,7 +1819,7 @@ void ProcessPageInfo()
 
         // gun btn and QR code
         if (_totalCount + acgunCount >= 2 && _currentPage) {
-            byte index = 0;
+            uint8_t index = 0;
             for (index = 0; index < _totalCount; index++) {
                 if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index) {
                     break;
@@ -1847,10 +1834,10 @@ void ProcessPageInfo()
                         needReloadQr = false;
                         //ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId); //DS60-120 remove
                         if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO) {
-                            //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+                            //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
                             ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
                         } else {
-                            //byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+                            //uint8_t len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
                             ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
                         }
                     }
@@ -1893,7 +1880,7 @@ void ChangeDisplayMoneyInfo()
             }
 
             if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53) {
-                DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+                DisplayMoneyCur((uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
             }
 #if defined DD360Audi
         }
@@ -1908,12 +1895,12 @@ void ChangeDisplayMoneyInfo()
 void Initialization()
 {
     bool isPass = false;
-    byte count = 5;
+    uint8_t count = 5;
     while (!isPass && count > 0) {
         isPass = true;
-        for (byte _index = 0; _index < _totalCount; _index++) {
+        for (uint8_t _index = 0; _index < _totalCount; _index++) {
             if (!FindChargingInfoData(_index, &_chargingInfoData[0])) {
-                DEBUG_ERROR("LcmComm (main) : FindChargingInfoData false \n");
+                log_error("LcmComm (main) : FindChargingInfoData false \n");
                 isPass = false;
                 count--;
                 break;
@@ -1928,9 +1915,9 @@ void Initialization()
     if (acgunCount > 0) {
         while (!isPass) {
             isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
+            for (uint8_t _index = 0; _index < acgunCount; _index++) {
                 if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
-                    DEBUG_ERROR("LcmComm : FindAcChargingInfoData false \n");
+                    log_error("LcmComm : FindAcChargingInfoData false \n");
                     isPass = false;
                     break;
                 }
@@ -1941,14 +1928,14 @@ void Initialization()
     }
 
     if (count == 0) {
-        PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
+        log_info("LCM Initialization Gun Fail.............\n");
     }
 }
 
 //DS60-120 add
 void DefaultIconStatus()
 {
-    for (byte i = 0; i < 3; i++) {
+    for (uint8_t i = 0; i < 3; i++) {
         ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
     }
 
@@ -1963,7 +1950,7 @@ int main(void)
 {
     if (InitShareMemory() == FAIL) {
 #ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
+        log_error("InitShareMemory NG\n");
 #endif
         if (ShmStatusCodeData != NULL) {
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
@@ -1973,8 +1960,8 @@ int main(void)
     }
 
     _port = CreateCommunicationLcmPort();
-    byte changeWarningPriority = 0;
-    byte curWarningCount = 255;
+    uint8_t changeWarningPriority = 0;
+    uint8_t curWarningCount = 255;
     ChangeBackLight(true);
     _totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
     acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
@@ -1984,7 +1971,7 @@ int main(void)
     //ChangeToOtherPage(_LCM_COMPLETE);
     //return 0;
 
-    for (byte i = 0; i < 3; i++) {
+    for (uint8_t i = 0; i < 3; i++) {
         ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
     }
 

+ 90 - 99
EVSE/Projects/DD360/Apps/ReModule_LcmControl.h → EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -27,23 +27,14 @@
 #include <ctype.h>
 #include <ifaddrs.h>
 #include <stdbool.h>
-#include "../../define.h"
-#include "Config.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
-typedef unsigned char           byte;
+#include "../../../define.h"
+#include "../Config.h"
 
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 struct FanModuleData            *ShmFanModuleData;
 struct PrimaryMcuData           *ShmPrimaryMcuData;
 
-#define NO_DEFINE               255
 #define DEFAULT_AC_INDEX        2
 
 #define TIME_MAX_SEC            2592000 // 一個月,秒數
@@ -76,14 +67,14 @@ int _port;
 //char* pPortName         = "/dev/ttyO2";
 char *pPortName           = "/dev/ttyS3";
 char *moduleName          = "DMT80480T070_09WT";
-byte _totalCount;
-byte acgunCount;
+uint8_t _totalCount;
+uint8_t acgunCount;
 struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
 
-byte ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-byte isDiffStatus         = false;
-byte isChangeBattMap      = false;
+uint8_t ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
+uint8_t isDiffStatus         = false;
+uint8_t isChangeBattMap      = false;
 // 當前選擇的槍號
 #if defined DD360Audi
 short _currentPage        = _LCM_SELECT_GUN;
@@ -92,14 +83,14 @@ short _oldPage            = _LCM_SELECT_GUN;
 short _currentPage        = _LCM_NONE;
 short _oldPage            = _LCM_NONE;
 #endif //defined DD360Audi
-byte _gunIndex            = 0;
+uint8_t _gunIndex            = 0;
 bool _wifi_conn_status    = false;
 bool _battery_display_ani = false;
-byte _curPage_index       = 0;
+uint8_t _curPage_index       = 0;
 bool _page_reload         = false;
 
 // LCM - HW
-byte _everyPageRollChange    = 0;
+uint8_t _everyPageRollChange    = 0;
 short __conn_status          = 0x0030;
 short __ethernet_status      = 0x0032;
 short __3G4G_status          = 0x0036;
@@ -178,85 +169,85 @@ short __custStationIdL1      = 0x0450;
 short _emergency_map         = 0x011C;
 
 // ICON ID
-byte _disappear              = 0;
-byte _disconnect             = 1;
-byte _connect                = 2;
-byte _warning                = 3;
-byte _arrow_dark             = 4;
-byte _arrow_light            = 5;
-byte _3G4G_disconnect        = 6;
-byte __3G4G_connect          = 7;
-byte _wifi_disconnect        = 8;
-byte _wifi_connect           = 9;
-byte _logo                   = 10;
-byte _conn_map1              = 11;
-byte _conn_map2              = 12;
-byte _sel_gun_btn            = 13;
-byte _back_home_btn          = 14;
-byte _stop_charging_btn      = 15;
-byte _stop_charging_btn_scan = 16;
-byte _chademo_dark           = 17;
-byte _ccs_dark               = 18;
-byte _gbt_dark               = 19;
-byte _actype_dark            = 20;
-byte _chademo_light          = 21;
-byte _ccs_light              = 22;
-byte _gbt_light              = 23;
-byte _actype_light           = 24;
-byte _main_none_rfid         = 25;
-byte _main_rfid              = 26;
-byte _main_none_app          = 27;
-byte _main_app               = 28;
-byte _main_none_qr           = 29;
-byte _main_qr                = 30;
-byte _charging_map1          = 31;
-byte _charging_map2          = 32;
-byte _battery_empty          = 33;
-byte _battery_cap_20         = 34;
-byte _battery_cap_40         = 35;
-byte _battery_cap_60         = 36;
-byte _battery_cap_80         = 37;
-byte _battery_cap_100        = 38;
-byte _battery_map            = 39;
-byte _power_map              = 40;
-byte _time_map               = 41;
-byte _complete_map           = 42;
-byte _battery_soc_20         = 43;
-byte _battery_soc_40         = 44;
-byte _battery_soc_60         = 45;
-byte _battery_soc_80         = 46;
-byte _battery_soc_100        = 47;
-byte _battery_eng_map        = 48;
-byte _money_map              = 49;
-byte _elapse_time_map        = 50;
-byte _charging_money         = 51;
-//byte _side_none_rfid       = 52;
-//byte _side_rfid            = 53;
-//byte _side_none_app        = 54;
-//byte _side_app             = 55;
-//byte _side_none_qr         = 56;
-//byte _side_qr              = 57;
-byte _eth_disconnect         = 52; //58;
-byte _eth_connect            = 53; //59;
-
-byte _chademo_dark_cmp       = 54;
-byte _ccs_dark_cmp           = 55;
-byte _gbt_dark_cmp           = 56;
-byte _actype_dark_cmp        = 57;
-byte _chademo_light_cmp      = 58;
-byte _ccs_light_cmp          = 59;
-byte _gbt_light_cmp          = 60;
-byte _actype_light_cmp       = 61;
-
-byte _logo_cmp = 62;
-byte _battery_eng_trp_map = 63;
-byte _money_trp_map = 64;
-byte _elapse_time_trp_map = 65;
+uint8_t _disappear              = 0;
+uint8_t _disconnect             = 1;
+uint8_t _connect                = 2;
+uint8_t _warning                = 3;
+uint8_t _arrow_dark             = 4;
+uint8_t _arrow_light            = 5;
+uint8_t _3G4G_disconnect        = 6;
+uint8_t __3G4G_connect          = 7;
+uint8_t _wifi_disconnect        = 8;
+uint8_t _wifi_connect           = 9;
+uint8_t _logo                   = 10;
+uint8_t _conn_map1              = 11;
+uint8_t _conn_map2              = 12;
+uint8_t _sel_gun_btn            = 13;
+uint8_t _back_home_btn          = 14;
+uint8_t _stop_charging_btn      = 15;
+uint8_t _stop_charging_btn_scan = 16;
+uint8_t _chademo_dark           = 17;
+uint8_t _ccs_dark               = 18;
+uint8_t _gbt_dark               = 19;
+uint8_t _actype_dark            = 20;
+uint8_t _chademo_light          = 21;
+uint8_t _ccs_light              = 22;
+uint8_t _gbt_light              = 23;
+uint8_t _actype_light           = 24;
+uint8_t _main_none_rfid         = 25;
+uint8_t _main_rfid              = 26;
+uint8_t _main_none_app          = 27;
+uint8_t _main_app               = 28;
+uint8_t _main_none_qr           = 29;
+uint8_t _main_qr                = 30;
+uint8_t _charging_map1          = 31;
+uint8_t _charging_map2          = 32;
+uint8_t _battery_empty          = 33;
+uint8_t _battery_cap_20         = 34;
+uint8_t _battery_cap_40         = 35;
+uint8_t _battery_cap_60         = 36;
+uint8_t _battery_cap_80         = 37;
+uint8_t _battery_cap_100        = 38;
+uint8_t _battery_map            = 39;
+uint8_t _power_map              = 40;
+uint8_t _time_map               = 41;
+uint8_t _complete_map           = 42;
+uint8_t _battery_soc_20         = 43;
+uint8_t _battery_soc_40         = 44;
+uint8_t _battery_soc_60         = 45;
+uint8_t _battery_soc_80         = 46;
+uint8_t _battery_soc_100        = 47;
+uint8_t _battery_eng_map        = 48;
+uint8_t _money_map              = 49;
+uint8_t _elapse_time_map        = 50;
+uint8_t _charging_money         = 51;
+//uint8_t _side_none_rfid       = 52;
+//uint8_t _side_rfid            = 53;
+//uint8_t _side_none_app        = 54;
+//uint8_t _side_app             = 55;
+//uint8_t _side_none_qr         = 56;
+//uint8_t _side_qr              = 57;
+uint8_t _eth_disconnect         = 52; //58;
+uint8_t _eth_connect            = 53; //59;
+
+uint8_t _chademo_dark_cmp       = 54;
+uint8_t _ccs_dark_cmp           = 55;
+uint8_t _gbt_dark_cmp           = 56;
+uint8_t _actype_dark_cmp        = 57;
+uint8_t _chademo_light_cmp      = 58;
+uint8_t _ccs_light_cmp          = 59;
+uint8_t _gbt_light_cmp          = 60;
+uint8_t _actype_light_cmp       = 61;
+
+uint8_t _logo_cmp = 62;
+uint8_t _battery_eng_trp_map = 63;
+uint8_t _money_trp_map = 64;
+uint8_t _elapse_time_trp_map = 65;
 
 ////For Audi
-byte _left_gun_disable_map   = 66;
-byte _left_gun_enable_map    = 67;
-byte _right_gun_disable_map  = 68;
-byte _right_gun_enable_map   = 69;
-byte _select_gun_btn         = 70;
-byte _emergency_disable_map  = 72;
+uint8_t _left_gun_disable_map   = 66;
+uint8_t _left_gun_enable_map    = 67;
+uint8_t _right_gun_disable_map  = 68;
+uint8_t _right_gun_enable_map   = 69;
+uint8_t _select_gun_btn         = 70;
+uint8_t _emergency_disable_map  = 72;

+ 105 - 186
EVSE/Projects/DD360Audi/Apps/ReModule_PrimaryComm.c → EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -1,95 +1,49 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "../../define.h"
-#include    "PrimaryComm.h"
-#include    <stdbool.h>
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
-typedef struct StChillerInfo {
-    uint8_t ChillerSwitch;
-    uint32_t ChillerOnTime;
-    uint8_t Reserved[3];
-} ChillerInfo;
-
-typedef struct StLedConfig {
-    //OutputDrvValue[0]
-    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
-    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
-    uint8_t GreenLED: 1;                          //bit 2,    H: ON,      L:OFF
-    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
-    uint8_t RedLED: 1;                        //bit 4,    H: ON,      L:OFF
-    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
-    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
-    uint8_t Reserved: 1;                        //bit 7 reserved
-} LedConfig;
-
-typedef unsigned char       byte;
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-
-void trim(char *s);
-int mystrcmp(char *p1, char *p2);
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt);
-void split(char **arr, char *str, const char *del);
-
-int Uart1Fd;
-char *priPortName = "/dev/ttyS1";
-Ver ver;
-Gpio_in gpio_in;
-Rtc rtc;
-
-struct timeval _flash_time;
-byte flash = NO;
-byte gun_count; //DS60-120 add
-
-byte _curDeviceStatus[3] = {0, 0, 0}; //DS60-120 add
-byte _reCheckCount[3] = {0, 0, 0}; //DS60-120 add
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-unsigned char ChillerSwitch; //DS60-120 remove
-unsigned int ChillerOnTime; //DS60-120 remove
-#endif //defined DD360 || defined DD360Audi
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdbool.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+
+#include "../../../define.h"
+#include "../Config.h"
+#include "PrimaryComm.h"
+#include "Module_PrimaryComm.h"
+
+struct SysConfigAndInfo *ShmSysConfigAndInfo;
+struct StatusCodeData *ShmStatusCodeData;
+struct PrimaryMcuData *ShmPrimaryMcuData;
+
+const char *priPortName = "/dev/ttyS1";
+uint8_t gun_count; //DS60-120 add
 
-int StoreLogMsg(const char *fmt, ...);
-#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)
+struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
+//------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -148,59 +102,6 @@ char *getTimeString(void)
     return result;
 }
 
-void trim(char *s)
-{
-    int i = 0, j, k, l = 0;
-
-    while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
-        i++;
-    }
-
-    j = strlen(s) - 1;
-    while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
-        j--;
-    }
-
-    if (i == 0 && j == strlen(s) - 1) { }
-    else if (i == 0) { s[j + 1] = '\0'; }
-    else {
-        for (k = i; k <= j; k++) { s[l++] = s[k]; }
-        s[l] = '\0';
-    }
-}
-
-int mystrcmp(char *p1, char *p2)
-{
-    while (*p1 == *p2) {
-        if (*p1 == '\0' || *p2 == '\0') {
-            break;
-        }
-        p1++;
-        p2++;
-    }
-    if (*p1 == '\0' && *p2 == '\0') {
-        return (PASS);
-    } else {
-        return (FAIL);
-    }
-}
-
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
-{
-    strncpy(dest, src + start, cnt);
-    dest[cnt] = 0;
-}
-
-void split(char **arr, char *str, const char *del)
-{
-    char *s = strtok(str, del);
-
-    while (s != NULL) {
-        *arr++ = s;
-        s = strtok(NULL, del);
-    }
-}
-
 //==========================================
 // Init all share memory
 //==========================================
@@ -236,26 +137,32 @@ int InitShareMemory()
 //================================================
 // Function
 //================================================
-void GetFwAndHwVersion()
+void GetFwAndHwVersion(int fd)
 {
-    if (Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) {
+    Ver ver = {0};
+
+    if (Query_FW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS) {
         //log_info("Primary FW Rev = %s \n", ver.Version_FW);
         strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
         strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
     }
 
-    //if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+    //if (Query_HW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS)
     //    ;//log_info("Primary HW Rev  = %s \n", ver.Version_HW);
 }
 
-void GetInputGpioStatus()
+void GetInputGpioStatus(int fd)
 {
     uint8_t dispenserSwTmp = 0;
+    Gpio_in gpio_in = {0};
     static uint8_t dispenserSw = 0;
 
     //log_info("GetInputGpioStatus \n");
-    if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS) {
+    if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) == PASS) {
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+        static uint8_t _curDeviceStatus[3] = {0};
+        static uint8_t _reCheckCount[3] = {0};
+
         //DS60-120 add
         if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
             if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
@@ -366,7 +273,8 @@ static void checkChillerStatus(Gpio_out *gpio)
 {
     uint8_t gunIndex = 0;
     uint8_t chillerCount = 0;
-    static ChillerInfo fChillerInfo[2] = {0};
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+    static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
     Gpio_out *pGpio = (Gpio_out *)gpio;
 
     if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
@@ -385,34 +293,38 @@ static void checkChillerStatus(Gpio_out *gpio)
     }
 
     for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
-        if ((ChargingData[gunIndex]->PresentChargingCurrent) >= 150) {
-            fChillerInfo[gunIndex].ChillerSwitch = YES;
-            fChillerInfo[gunIndex].ChillerOnTime = time((time_t *)NULL);
+        pDcChargingInfo = (struct ChargingInfoData *)ChargingData[gunIndex];
+        pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
+
+        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) {
+            pChillerInfo->ChillerSwitch = YES;
+            pChillerInfo->ChillerOnTime = time((time_t *)NULL);
         } else {
-            if (fChillerInfo[gunIndex].ChillerSwitch == YES) {
-                if ((ChargingData[gunIndex]->PresentChargingCurrent) >= 100) {
-                    fChillerInfo[gunIndex].ChillerSwitch = YES;
-                    fChillerInfo[gunIndex].ChillerOnTime = time((time_t *)NULL);
+            if (pChillerInfo->ChillerSwitch == YES) {
+                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) {
+                    pChillerInfo->ChillerSwitch = YES;
+                    pChillerInfo->ChillerOnTime = time((time_t *)NULL);
                 } else {
-                    if ((time((time_t *)NULL) - fChillerInfo[gunIndex].ChillerOnTime) >= 600) {
-                        fChillerInfo[gunIndex].ChillerSwitch = NO;
+                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
+                        pChillerInfo->ChillerSwitch = NO;
                     } else {
-                        fChillerInfo[gunIndex].ChillerSwitch = YES;
+                        pChillerInfo->ChillerSwitch = YES;
                     }
                 }
             } else {
-                fChillerInfo[gunIndex].ChillerSwitch = NO;
+                pChillerInfo->ChillerSwitch = NO;
             }
         }
     }
 
-    pGpio->AC_Connector = fChillerInfo[gunIndex].ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
+    pGpio->AC_Connector = pChillerInfo->ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
 }
 
-void SetOutputGpio(uint8_t outputValue)
+void SetOutputGpio(int fd, uint8_t outputValue)
 {
     Gpio_out gpio;
     LedConfig *pLedConfig = (LedConfig *)&outputValue;
+    static uint8_t flash = NO;
 
     if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
         if (flash == NO) {
@@ -441,19 +353,24 @@ void SetOutputGpio(uint8_t outputValue)
 
     gpio.AC_Breaker = 0x00;
 
-    Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio);
+    Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
 }
 
-void SetRtcData()
+void SetRtcData(int fd)
 {
+    Rtc rtc = {0};
     struct timeb csuTime;
     struct tm *tmCSU;
 
     ftime(&csuTime);
     tmCSU = localtime(&csuTime.time);
-//  log_info("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//          tmCSU->tm_sec);
+    //log_info("Time : %04d-%02d-%02d %02d:%02d:%02d \n",
+    //         tmCSU->tm_year + 1900,
+    //         tmCSU->tm_mon + 1,
+    //         tmCSU->tm_mday,
+    //         tmCSU->tm_hour,
+    //         tmCSU->tm_min,
+    //         tmCSU->tm_sec);
 
     rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
     rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
@@ -475,16 +392,16 @@ void SetRtcData()
     rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
     rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
 
-    if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS) {
+    if (Config_Rtc_Data(fd, OP_ADDR_IO_EXTEND, &rtc) == PASS) {
         //log_info("SetRtc sucessfully. \n");
     } else {
         //log_info("SetRtc fail. \n");
     }
 }
 
-void SetModelName()
+void SetModelName(int fd)
 {
-    if (Config_Model_Name(Uart1Fd, Addr.IoExtend, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
     }
 }
 
@@ -509,7 +426,7 @@ int InitComPort()
     tios.c_iflag = 0;
     tios.c_oflag = 0;
     tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char)1;
+    tios.c_cc[VTIME] = (uint8_t)1;
     tios.c_lflag = 0;
     tcflush(fd, TCIFLUSH);
     ioctl (fd, TCSETS, &tios);
@@ -525,23 +442,23 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
-int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
             return 1;
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
             return 1;
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
             return 1;
@@ -556,7 +473,7 @@ void Initialization() //DS60-120 add
     bool isPass = false;
     while (!isPass) {
         isPass = true;
-        for (byte _index = 0; _index < gun_count; _index++) {
+        for (uint8_t _index = 0; _index < gun_count; _index++) {
             if (!FindChargingInfoData(_index, &ChargingData[0])) {
                 log_error("EvComm (main) : FindChargingInfoData false \n");
                 isPass = false;
@@ -569,6 +486,8 @@ void Initialization() //DS60-120 add
 
 int main(void)
 {
+    int Uart1Fd = -1;
+
     if (InitShareMemory() == FAIL) {
         log_error("InitShareMemory NG\r\n");
         if (ShmStatusCodeData != NULL) {
@@ -579,13 +498,13 @@ int main(void)
     }
 
     //DS60-120 remove
-    //for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+    //for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
     //    if (!FindChargingInfoData(_index, &ChargingData[0])) {
     //        log_error("FindChargingInfoData false \n");
     //        break;
     //    }
     //}
-    ChillerSwitch = 0;
+
     Uart1Fd = InitComPort();
     //log_info("407 Port id = %d \n", Uart1Fd);
 
@@ -597,29 +516,29 @@ int main(void)
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
         }
         sleep(5);
+
         return 0;
     }
 
-    SetRtcData();
-    SetModelName();//DS60-120 add
-    gettimeofday(&_flash_time, NULL);
-    //DS60-120 add
+    SetRtcData(Uart1Fd);
+    SetModelName(Uart1Fd);
+
     gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+
     Initialization();
-    byte _count = 0;
 
     for (;;) {
         // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
         // 模組更新 FW 後,需重新做
         if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
             //log_info("(407) Get Fw and Hw Ver. \n");
-            GetFwAndHwVersion();
+            GetFwAndHwVersion(Uart1Fd);
             sleep(1);
             ShmPrimaryMcuData->SelfTest_Comp = PASS;
         } else {
-            SetOutputGpio(ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
+            SetOutputGpio(Uart1Fd, ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
 
-            GetInputGpioStatus();
+            GetInputGpioStatus(Uart1Fd);
         }
 
         usleep(50000);

+ 34 - 0
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -0,0 +1,34 @@
+#ifndef _MODULE_PRIMARY_COMM_H_
+#define _MODULE_PRIMARY_COMM_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
+typedef struct StChillerInfo {
+    uint8_t ChillerSwitch;
+    uint32_t ChillerOnTime;
+    uint8_t Reserved[3];
+} ChillerInfo;
+
+typedef struct StLedConfig {
+    //OutputDrvValue[0]
+    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
+    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
+    uint8_t GreenLED: 1;                          //bit 2,    H: ON,      L:OFF
+    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
+    uint8_t RedLED: 1;                        //bit 4,    H: ON,      L:OFF
+    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
+    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
+    uint8_t Reserved: 1;                        //bit 7 reserved
+} LedConfig;
+
+//------------------------------------------------------------------------------
+int StoreLogMsg(const char *fmt, ...);
+
+#endif /* _MODULE_PRIMARY_COMM_H_ */

+ 96 - 100
EVSE/Projects/DD360ComBox/Apps/PrimaryComm.c → EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.c

@@ -1,41 +1,39 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "PrimaryComm.h"
-
-#define PASS                1
-#define FAIL                -1
-
-struct Address Addr = {0x01, 0x02, 0x03, 0x04, 0xFF};
-struct Command Cmd = {0x01, 0x02, 0x0a, 0x2C, 0x83, 0x86, 0x87, 0xe0, 0xe1, 0xe2, 0xe3};
-
-int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *rx)
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+#include "../Config.h"
+
+#include "Module_PrimaryComm.h"
+#include "PrimaryComm.h"
+
+//------------------------------------------------------------------------------
+int tranceive(int fd, uint8_t *cmd, uint8_t cmd_len, uint8_t *rx)
 {
     int len;
     //sleep(2); //required to make flush work, for some reason
@@ -44,21 +42,19 @@ int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *
         usleep(50000);
         len = read(fd, rx, 512);
     } else {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
-#endif
+        log_error("Serial command %s response fail.\n", cmd);
     }
 
     return len;
 }
 
-unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+int Query_FW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
-    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_FW_VER, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
+    uint8_t len = tranceive(fd, tx, sizeof(tx), rx);
 
     if (len > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -78,12 +74,12 @@ unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_
     return result;
 }
 
-unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+int Query_HW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_HW_VER, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     if (tranceive(fd, tx, sizeof(tx), rx) > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -103,13 +99,13 @@ unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_
     return result;
 }
 
-unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
+int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
-    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GPIO_IN, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
+    uint8_t len = tranceive(fd, tx, sizeof(tx), rx);
 
     if (len > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -143,12 +139,12 @@ unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_
     return result;
 }
 
-unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
+int Config_Gpio_Output(uint8_t fd, uint8_t targetAddr, Gpio_out *Set_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[9] = {0xaa, 0x00, targetAddr, CMD_CONFIG_GPIO_OUTPUT, 0x01, 0x00, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     for (int idx = 0; idx < 2; idx++) {
         tx[6] |= (Set_Buf->Button_LED[idx] ? 0x01 : 0x00) << (0 + idx);
@@ -184,15 +180,15 @@ unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpi
     return result;
 }
 
-unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
+int Config_Rtc_Data(uint8_t fd, uint8_t targetAddr, Rtc *Set_Buf)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
-                             Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
-                             Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]
-                           };
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[21] = { 0xaa, 0x00, targetAddr, CMD_CONFIG_RTC, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
+                       Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
+                       Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]
+                     };
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++) {
         chksum ^= tx[6 + idx];
@@ -217,14 +213,14 @@ unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *S
     return result;
 }
 
-unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname)
+int Config_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[21] = {0xaa, 0x00, targetAddr, Cmd.config_Model_Name, 0x0E, 0x00,
-                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-                           };
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[21] = {0xaa, 0x00, targetAddr, CMD_CONFIG_MODEL_NAME, 0x0E, 0x00,
+                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+                     };
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     memcpy(tx + 6, modelname, 14);
 
@@ -235,7 +231,7 @@ unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsi
 
 //  for(int i = 0; i < 21; i++)
 //              printf ("tx = %x \n", tx[i]);
-    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+    uint8_t len = tranceive(fd, tx, sizeof(tx), rx);
 //  for(int i = 0; i < len; i++)
 //                  printf ("rx = %x \n", rx[i]);
     if (len > 6) {
@@ -259,12 +255,12 @@ unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsi
 
     return result;
 }
-unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
+int Update_Start(uint8_t fd, uint8_t targetAddr, uint32_t crc32)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32 >> 0) & 0xff, (crc32 >> 8) & 0xff, (crc32 >> 16) & 0xff, (crc32 >> 24) & 0xff, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[11] = {0xaa, 0x00, targetAddr, CMD_UPDATE_START, 0x04, 0x00, (crc32 >> 0) & 0xff, (crc32 >> 8) & 0xff, (crc32 >> 16) & 0xff, (crc32 >> 24) & 0xff, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++) {
         chksum ^= tx[6 + idx];
@@ -290,12 +286,12 @@ unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned
     return result;
 }
 
-unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
+int Update_Abord(uint8_t fd, uint8_t targetAddr)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_ABORT, 0x04, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     if (tranceive(fd, tx, sizeof(tx), rx) > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
@@ -314,17 +310,17 @@ unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
     return result;
 }
 
-unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+int Update_Transfer(uint8_t fd, uint8_t targetAddr, uint32_t startAddr, uint8_t *data, uint16_t length)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[11 + length];
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[11 + length];
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     tx[0] = 0xaa;
     tx[1] = 0x00;
     tx[2] = targetAddr;
-    tx[3] = Cmd.update_Transfer;
+    tx[3] = CMD_UPDATE_TRANSFER;
     tx[4] = (4 + length) & 0xff;
     tx[5] = ((4 + length) >> 8) & 0xff;
     tx[6] = (startAddr >> 0) & 0xff;
@@ -355,12 +351,12 @@ unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsign
     return result;
 }
 
-unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
+int Update_Finish(uint8_t fd, uint8_t targetAddr)
 {
-    unsigned char result = FAIL;
-    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
-    unsigned char rx[512];
-    unsigned char chksum = 0x00;
+    uint8_t result = FAIL;
+    uint8_t tx[7] = {0xaa, 0x00, targetAddr, CMD_UPDATE_FINISH, 0x04, 0x00, 0x00};
+    uint8_t rx[512];
+    uint8_t chksum = 0x00;
 
     if (tranceive(fd, tx, sizeof(tx), rx) > 0) {
         for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {

+ 79 - 0
EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.h

@@ -0,0 +1,79 @@
+#ifndef PRIMARYCOMM_H_
+#define PRIMARYCOMM_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+// primary operative address
+//------------------------------------------------------------------------------
+#define OP_ADDR_AUX                             (0x01)
+#define OP_ADDR_FAN                             (0x02)
+#define OP_ADDR_RELAY                           (0x03)
+#define OP_ADDR_IO_EXTEND                       (0x04)
+#define OP_ADDR_BROADCAST                       (0xFF)
+
+//------------------------------------------------------------------------------
+// primary send packet command
+//------------------------------------------------------------------------------
+#define CMD_QUERY_FW_VER                        (0x01)
+#define CMD_QUERY_HW_VER                        (0x02)
+#define CMD_QUERY_GPIO_IN                       (0x0a)
+#define CMD_CONFIG_GPIO_OUTPUT                  (0x86)
+#define CMD_CONFIG_RTC                          (0x87)
+#define CMD_CONFIG_MODEL_NAME                   (0x83)
+#define CMD_UPDATE_START                        (0xe0)
+#define CMD_UPDATE_ABORT                        (0xe1)
+#define CMD_UPDATE_TRANSFER                     (0xe2)
+#define CMD_UPDATE_FINISH                       (0xe3)
+
+//------------------------------------------------------------------------------
+typedef struct Verion {
+    char Version_FW[16];
+    char Version_HW[16];
+} Ver;
+
+typedef struct GPIO_IN {
+    uint8_t AC_Connector;
+    uint8_t AC_MainBreaker;
+    uint8_t SPD;
+    uint8_t Door_Open;
+    uint8_t GFD[2];
+    uint8_t AC_Drop;
+    uint8_t Emergency_IO;
+
+    uint8_t Emergency_Btn;
+    uint8_t Button[2];
+    uint8_t Key[4];
+} Gpio_in;
+
+typedef struct GPIO_OUT {
+    uint8_t Button_LED[2];
+    uint8_t System_LED[4];
+    uint8_t AC_Connector;
+    uint8_t AC_Breaker;
+} Gpio_out;
+
+typedef struct RTC {
+    uint8_t RtcData[14];
+} Rtc;
+
+int Query_FW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_HW_Ver(uint8_t fd, uint8_t targetAddr, Ver *Ret_Buf);
+int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf);
+
+int Config_Gpio_Output(uint8_t fd, uint8_t targetAddr, Gpio_out *Set_Buf);
+int Config_Rtc_Data(uint8_t fd, uint8_t targetAddr, Rtc *Set_Buf);
+int Config_Model_Name(uint8_t fd, uint8_t targetAddr, uint8_t *modelname);
+// 13 bytes
+// year : 4, month : 2, day : 2, hour : 2, min : 2, sec : 2
+//int Config_RTC();
+
+int Update_Start(uint8_t fd, uint8_t targetAddr, uint32_t crc32);
+int Update_Abord(uint8_t fd, uint8_t targetAddr);
+int Update_Transfer(uint8_t fd, uint8_t targetAddr, uint32_t startAddr, uint8_t *data, uint16_t length);
+int Update_Finish(uint8_t fd, uint8_t targetAddr);
+
+
+#endif /* PRIMARYCOMM_H_ */

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


+ 0 - 0
EVSE/Projects/DD360Audi/Apps/Module_PsuComm.h → EVSE/Projects/DD360Audi/Apps/ModulePsuComm/Module_PsuComm.h


+ 0 - 2934
EVSE/Projects/DD360Audi/Apps/Module_EvComm.c

@@ -1,2934 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/can.h>
-#include    <linux/can/raw.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    "../../define.h"
-#include    "Module_EvComm.h"
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define START               1
-#define STOP                0
-#define YES                 1
-#define NO                  0
-#define EQUAL               0
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct FanModuleData            *ShmFanModuleData;
-struct CHAdeMOData              *ShmCHAdeMOData;
-struct GBTData                  *ShmGBTData;
-struct CcsData                  *ShmCcsData;
-
-byte gun_count;
-int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-float _pow_1 = 0;
-float _cur_1 = 0;
-float _pow_2 = 0;
-float _cur_2 = 0;
-
-float _outVol_1 = 0;
-float _outCur_1 = 0;
-float _outVol_2 = 0;
-float _outCur_2 = 0;
-
-// 限制最大充電電壓,因應不同 type 槍線來限制
-// Chademo : 500V, 125A,
-// GB : 750, 120A
-// CCS : 950V, 120A
-float maxChargingVol[2] = { 5000, 9500 };           // 限制最大充電電壓,如依照模塊則填上 0
-// 限制最大充電電流與能量透過 Web
-float maxChargingCur[2] = { 5000, 1200 };           // 限制最大充電電流,如依照模塊則填上 0
-float maxChargingPow = 0;                           // 限制最大充電能量,如依照模塊則填上 0
-
-// 槍資訊
-struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-struct Ev_Board_Cmd Ev_Cmd = {
-    0,
-    0x00000200,
-    0x00000400,
-    0x00000500,
-    0x00000600,
-    0x00000700,
-    0x00000800,
-    0x00000900,
-    0x00000A00,
-    0x00000C00,
-    0x00000D00,
-
-    0x00000E00,
-    0x00000F00,
-    0x00001000,
-    0x00001100,
-
-    0x00001200,
-    0x00001400,
-    0x00001500,
-};
-
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-
-void PRINTF_FUNC(char *string, ...);
-
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur);
-void GetMaxPowerMethod(byte index, float *pow);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
-//=================================
-// Common routine
-//=================================
-void getTimeString(char *buff)
-{
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-}
-
-bool CheckUniqNumber(byte value)
-{
-    for (byte index = 0; index < gun_count; index++) {
-        if (_chargingData[index]->Evboard_id == value) {
-            struct timeval _end_time;
-            gettimeofday(&_end_time, NULL);
-            unsigned long diff = 1000000 *  (_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
-            if (diff >= 3000000) {
-                gettimeofday(&_id_assign_time, NULL);
-                return true;
-            } else {
-                return false;
-            }
-        }
-    }
-
-    gettimeofday(&_id_assign_time, NULL);
-    return true;
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //initial ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    //initial ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    if (CHAdeMO_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),  IPC_CREAT | 0777)) < 0) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
-#endif
-            return FAIL;
-        } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
-#endif
-            return FAIL;
-        } else
-        {}
-    }
-    if (GB_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),  IPC_CREAT | 0777)) < 0) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("[shmget ShmGBTData NG \n");
-#endif
-            return FAIL;
-        } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmat ShmGBTData NG \n");
-#endif
-            return FAIL;
-        } else
-        {}
-    }
-
-    if (CCS_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),  IPC_CREAT | 0777)) < 0) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmget ShmCcsData NG \n");
-#endif
-            return FAIL;
-        } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-            DEBUG_ERROR("shmat ShmCcsData NG \n");
-#endif
-            return FAIL;
-        } else
-        {}
-    }
-
-    return result;
-}
-
-//================================================
-// initial can-bus
-//================================================
-int InitCanBus()
-{
-    int                     s0, nbytes;
-    struct timeval          tv;
-    struct ifreq            ifr0;
-    struct sockaddr_can     addr0;
-
-    system("/sbin/ip link set can0 down");
-    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-    system("/sbin/ip link set can0 up");
-
-    s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
-
-    tv.tv_sec = 0;
-    tv.tv_usec = 10000;
-    if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct  timeval)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Set SO_RCVTIMEO NG");
-#endif
-    }
-    nbytes = 40960;
-    if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Set SO_RCVBUF NG");
-#endif
-    }
-    nbytes = 40960;
-    if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Set SO_SNDBUF NG");
-#endif
-    }
-
-    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;
-    bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
-    return s0;
-}
-
-//================================================
-//================================================
-// CANBUS receive task
-//================================================
-//================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return true;
-        }
-    }
-
-    return false;
-}
-
-void AddrAssignment(byte *data)
-{
-    byte target_number[8];
-    byte index = 0x00;
-
-    memcpy(target_number, data, sizeof(target_number));
-    index = *(data + 4);
-
-    if (gun_count == 1) {
-        index = 0x01;
-    }
-//  if (CheckUniqNumber(index))
-    {
-        PRINTF_FUNC("EV board id = %x \n", index);
-//      PRINTF_FUNC("target_number[0] = %x \n", target_number[0]);
-//      PRINTF_FUNC("target_number[1] = %x \n", target_number[1]);
-//      PRINTF_FUNC("target_number[2] = %x \n", target_number[2]);
-//      PRINTF_FUNC("target_number[3] = %x \n", target_number[3]);
-//      PRINTF_FUNC("target_number[4] = %x \n", target_number[4]);
-
-        PRINTF_FUNC("SetTargetAddr = %d, type = %d \n", index, _chargingData[index - 1]->Type);
-        SetTargetAddr(target_number, index);
-    }
-}
-
-void ClearAbnormalStatus_Chademo(byte gun_index)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL) {
-        return;
-    }
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023700", 6) == EQUAL &&
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail == YES) {
-        memcpy(code, "023700", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023704", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun == YES) {
-        memcpy(code, "023704", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023705", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission == YES) {
-        memcpy(code, "023705", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023706", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility == YES) {
-        memcpy(code, "023706", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023707", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP == YES) {
-        memcpy(code, "023707", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023708", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP == YES) {
-        memcpy(code, "023708", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023709", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP == YES) {
-        memcpy(code, "023709", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023710", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff == YES) {
-        memcpy(code, "023710", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023711", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff == YES) {
-        memcpy(code, "023711", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023712", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition == YES) {
-        memcpy(code, "023712", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023713", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault == YES) {
-        memcpy(code, "023713", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023714", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError == YES) {
-        memcpy(code, "023714", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023715", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop == YES) {
-        memcpy(code, "023715", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023716", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken == YES) {
-        memcpy(code, "023716", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023717", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail == YES) {
-        memcpy(code, "023717", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023718", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive == YES) {
-        memcpy(code, "023718", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023719", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout == YES) {
-        memcpy(code, "023719", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023720", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout == YES) {
-        memcpy(code, "023720", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023721", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout == YES) {
-        memcpy(code, "023721", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023722", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout == YES) {
-        memcpy(code, "023722", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023723", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout == YES) {
-        memcpy(code, "023723", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023724", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout == YES) {
-        memcpy(code, "023724", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023725", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout == YES) {
-        memcpy(code, "023725", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023726", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V == YES) {
-        memcpy(code, "023726", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023727", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V == YES) {
-        memcpy(code, "023727", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023728", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop == YES) {
-        memcpy(code, "023728", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023729", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop == YES) {
-        memcpy(code, "023729", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023730", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
-        memcpy(code, "023730", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023731", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail == YES) {
-        memcpy(code, "023731", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023732", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard == YES) {
-        memcpy(code, "023732", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023733", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit == YES) {
-        memcpy(code, "023733", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023734", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit == YES) {
-        memcpy(code, "023734", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023735", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed == YES) {
-        memcpy(code, "023735", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023736", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown == YES) {
-        memcpy(code, "023736", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                PRINTF_FUNC("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-                if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "023700", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = NO; }
-                    if (strncmp(code, "023704", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = NO; }
-                    if (strncmp(code, "023705", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = NO; }
-                    if (strncmp(code, "023706", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = NO; }
-                    if (strncmp(code, "023707", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = NO; }
-                    if (strncmp(code, "023708", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = NO; }
-                    if (strncmp(code, "023709", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = NO; }
-                    if (strncmp(code, "023710", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = NO; }
-                    if (strncmp(code, "023711", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = NO; }
-                    if (strncmp(code, "023712", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = NO; }
-                    if (strncmp(code, "023713", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = NO; }
-                    if (strncmp(code, "023714", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = NO; }
-                    if (strncmp(code, "023715", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = NO; }
-                    if (strncmp(code, "023716", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = NO; }
-                    if (strncmp(code, "023717", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = NO; }
-                    if (strncmp(code, "023718", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = NO; }
-                    if (strncmp(code, "023719", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = NO; }
-                    if (strncmp(code, "023720", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = NO; }
-                    if (strncmp(code, "023721", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = NO; }
-                    if (strncmp(code, "023722", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = NO; }
-                    if (strncmp(code, "023723", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = NO; }
-                    if (strncmp(code, "023724", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = NO; }
-                    if (strncmp(code, "023725", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = NO; }
-                    if (strncmp(code, "023726", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = NO; }
-                    if (strncmp(code, "023727", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = NO; }
-                    if (strncmp(code, "023728", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = NO; }
-                    if (strncmp(code, "023729", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = NO; }
-                    if (strncmp(code, "023730", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO; }
-                    if (strncmp(code, "023731", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = NO; }
-                    if (strncmp(code, "023732", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = NO; }
-                    if (strncmp(code, "023733", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = NO; }
-                    if (strncmp(code, "023734", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = NO; }
-                    if (strncmp(code, "023735", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = NO; }
-                    if (strncmp(code, "023736", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = NO; }
-                }
-            }
-        }
-    }
-}
-
-void ClearAbnormalStatus_GB(byte gun_index)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL) {
-        return;
-    }
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023702", 6) == EQUAL &&
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail == YES) {
-        memcpy(code, "023702", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023900", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 == YES) {
-        memcpy(code, "023900", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023901", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL == YES) {
-        memcpy(code, "023901", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023902", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE == YES) {
-        memcpy(code, "023902", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023903", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT == YES) {
-        memcpy(code, "023903", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023904", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT == YES) {
-        memcpy(code, "023904", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023905", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT == YES) {
-        memcpy(code, "023905", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023906", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE == YES) {
-        memcpy(code, "023906", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023907", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE == YES) {
-        memcpy(code, "023907", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023908", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT == YES) {
-        memcpy(code, "023908", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023909", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V == YES) {
-        memcpy(code, "023909", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023910", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V == YES) {
-        memcpy(code, "023910", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023911", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD == YES) {
-        memcpy(code, "023911", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023912", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD == YES) {
-        memcpy(code, "023912", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023913", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL == YES) {
-        memcpy(code, "023913", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023914", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK == YES) {
-        memcpy(code, "023914", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023915", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT == YES) {
-        memcpy(code, "023915", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023916", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT == YES) {
-        memcpy(code, "023916", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023917", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT == YES) {
-        memcpy(code, "023917", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023918", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT == YES) {
-        memcpy(code, "023918", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023919", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V == YES) {
-        memcpy(code, "023919", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023930", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT == YES) {
-        memcpy(code, "023930", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023931", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT == YES) {
-        memcpy(code, "023931", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023932", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT == YES) {
-        memcpy(code, "023932", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023933", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT == YES) {
-        memcpy(code, "023933", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023934", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT == YES) {
-        memcpy(code, "023934", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023935", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT == YES) {
-        memcpy(code, "023935", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023936", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT == YES) {
-        memcpy(code, "023936", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023937", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT == YES) {
-        memcpy(code, "023937", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023938", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT == YES) {
-        memcpy(code, "023938", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023939", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT == YES) {
-        memcpy(code, "023939", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023940", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT == YES) {
-        memcpy(code, "023940", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023941", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT == YES) {
-        memcpy(code, "023941", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023942", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT == YES) {
-        memcpy(code, "023942", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023943", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT == YES) {
-        memcpy(code, "023943", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023944", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT == YES) {
-        memcpy(code, "023944", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023945", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT == YES) {
-        memcpy(code, "023945", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023946", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT == YES) {
-        memcpy(code, "023946", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023947", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT == YES) {
-        memcpy(code, "023947", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023950", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL == YES) {
-        memcpy(code, "023950", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023951", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL == YES) {
-        memcpy(code, "023951", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023952", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL == YES) {
-        memcpy(code, "023952", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023953", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST == YES) {
-        memcpy(code, "023953", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023954", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION == YES) {
-        memcpy(code, "023954", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023955", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP == YES) {
-        memcpy(code, "023955", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023956", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT == YES) {
-        memcpy(code, "023956", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023957", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR == YES) {
-        memcpy(code, "023957", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023958", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP == YES) {
-        memcpy(code, "023958", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023959", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER == YES) {
-        memcpy(code, "023959", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023960", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V == YES) {
-        memcpy(code, "023960", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023961", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 == YES) {
-        memcpy(code, "023961", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023962", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT == YES) {
-        memcpy(code, "023962", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023963", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE == YES) {
-        memcpy(code, "023963", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023964", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON == YES) {
-        memcpy(code, "023964", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023970", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE == YES) {
-        memcpy(code, "023970", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023971", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE == YES) {
-        memcpy(code, "023971", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023972", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC == YES) {
-        memcpy(code, "023972", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023973", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC == YES) {
-        memcpy(code, "023973", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023974", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT == YES) {
-        memcpy(code, "023974", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023975", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE == YES) {
-        memcpy(code, "023975", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023976", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE == YES) {
-        memcpy(code, "023976", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023977", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR == YES) {
-        memcpy(code, "023977", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                PRINTF_FUNC("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-                if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "023702", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = NO; }
-                    if (strncmp(code, "023900", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = NO; }
-                    if (strncmp(code, "023901", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = NO; }
-                    if (strncmp(code, "023902", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = NO; }
-                    if (strncmp(code, "023903", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = NO; }
-                    if (strncmp(code, "023904", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = NO; }
-                    if (strncmp(code, "023905", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = NO; }
-                    if (strncmp(code, "023906", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = NO; }
-                    if (strncmp(code, "023907", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = NO; }
-                    if (strncmp(code, "023908", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = NO; }
-                    if (strncmp(code, "023909", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = NO; }
-                    if (strncmp(code, "023910", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = NO; }
-                    if (strncmp(code, "023911", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = NO; }
-                    if (strncmp(code, "023912", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = NO; }
-                    if (strncmp(code, "023913", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = NO; }
-                    if (strncmp(code, "023914", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = NO; }
-                    if (strncmp(code, "023915", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = NO; }
-                    if (strncmp(code, "023916", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = NO; }
-                    if (strncmp(code, "023917", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = NO; }
-                    if (strncmp(code, "023918", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = NO; }
-                    if (strncmp(code, "023919", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = NO; }
-                    if (strncmp(code, "023930", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = NO; }
-                    if (strncmp(code, "023931", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = NO; }
-                    if (strncmp(code, "023932", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = NO; }
-                    if (strncmp(code, "023933", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = NO; }
-                    if (strncmp(code, "023934", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = NO; }
-                    if (strncmp(code, "023935", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = NO; }
-                    if (strncmp(code, "023936", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = NO; }
-                    if (strncmp(code, "023937", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = NO; }
-                    if (strncmp(code, "023938", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = NO; }
-                    if (strncmp(code, "023939", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = NO; }
-                    if (strncmp(code, "023940", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = NO; }
-                    if (strncmp(code, "023941", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = NO; }
-                    if (strncmp(code, "023942", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = NO; }
-                    if (strncmp(code, "023943", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = NO; }
-                    if (strncmp(code, "023944", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = NO; }
-                    if (strncmp(code, "023945", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = NO; }
-                    if (strncmp(code, "023946", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = NO; }
-                    if (strncmp(code, "023947", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = NO; }
-                    if (strncmp(code, "023950", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = NO; }
-                    if (strncmp(code, "023951", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = NO; }
-                    if (strncmp(code, "023952", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = NO; }
-                    if (strncmp(code, "023953", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST = NO; }
-                    if (strncmp(code, "023954", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION = NO; }
-                    if (strncmp(code, "023955", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = NO; }
-                    if (strncmp(code, "023956", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT = NO; }
-                    if (strncmp(code, "023957", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = NO; }
-                    if (strncmp(code, "023958", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP = NO; }
-                    if (strncmp(code, "023959", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER = NO; }
-                    if (strncmp(code, "023960", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V = NO; }
-                    if (strncmp(code, "023961", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 = NO; }
-                    if (strncmp(code, "023962", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT = NO; }
-                    if (strncmp(code, "023963", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = NO; }
-                    if (strncmp(code, "023964", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = NO; }
-                    if (strncmp(code, "023970", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = NO; }
-                    if (strncmp(code, "023971", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = NO; }
-                    if (strncmp(code, "023972", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = NO; }
-                    if (strncmp(code, "023973", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = NO; }
-                    if (strncmp(code, "023974", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT = NO; }
-                    if (strncmp(code, "023975", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = NO; }
-                    if (strncmp(code, "023976", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = NO; }
-                    if (strncmp(code, "023977", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = NO; }
-                }
-            }
-        }
-    }
-}
-
-void ClearAbnormalStatus_CCS(byte gun_index)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL) {
-        return;
-    }
-
-    if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023701", 6) == EQUAL &&
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail == YES) {
-        memcpy(code, "023701", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023737", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit == YES) {
-        memcpy(code, "023737", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023738", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition == YES) {
-        memcpy(code, "023738", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023739", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault == YES) {
-        memcpy(code, "023739", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023740", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction == YES) {
-        memcpy(code, "023740", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023741", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential == YES) {
-        memcpy(code, "023741", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023742", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange == YES) {
-        memcpy(code, "023742", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023743", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility == YES) {
-        memcpy(code, "023743", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023744", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent == YES) {
-        memcpy(code, "023744", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023745", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker == YES) {
-        memcpy(code, "023745", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023746", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData == YES) {
-        memcpy(code, "023746", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023747", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A == YES) {
-        memcpy(code, "023747", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023748", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B == YES) {
-        memcpy(code, "023748", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023749", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C == YES) {
-        memcpy(code, "023749", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023750", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 == YES) {
-        memcpy(code, "023750", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023751", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 == YES) {
-        memcpy(code, "023751", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023752", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 == YES) {
-        memcpy(code, "023752", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023753", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 == YES) {
-        memcpy(code, "023753", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023754", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 == YES) {
-        memcpy(code, "023754", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023755", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 == YES) {
-        memcpy(code, "023755", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023756", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 == YES) {
-        memcpy(code, "023756", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023757", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 == YES) {
-        memcpy(code, "023757", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023758", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError == YES) {
-        memcpy(code, "023758", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023759", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError == YES) {
-        memcpy(code, "023759", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023760", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession == YES) {
-        memcpy(code, "023760", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023761", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid == YES) {
-        memcpy(code, "023761", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023762", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid == YES) {
-        memcpy(code, "023762", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023763", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid == YES) {
-        memcpy(code, "023763", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023764", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid == YES) {
-        memcpy(code, "023764", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023765", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired == YES) {
-        memcpy(code, "023765", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023766", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid == YES) {
-        memcpy(code, "023766", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023767", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked == YES) {
-        memcpy(code, "023767", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023768", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable == YES) {
-        memcpy(code, "023768", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023769", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError == YES) {
-        memcpy(code, "023769", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023770", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError == YES) {
-        memcpy(code, "023770", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023771", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError == YES) {
-        memcpy(code, "023771", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023772", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled == YES) {
-        memcpy(code, "023772", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023773", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid == YES) {
-        memcpy(code, "023773", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023774", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode == YES) {
-        memcpy(code, "023774", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023775", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter == YES) {
-        memcpy(code, "023775", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023776", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid == YES) {
-        memcpy(code, "023776", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023777", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid == YES) {
-        memcpy(code, "023777", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023778", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow == YES) {
-        memcpy(code, "023778", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023779", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied == YES) {
-        memcpy(code, "023779", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023780", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid == YES) {
-        memcpy(code, "023780", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023781", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected == YES) {
-        memcpy(code, "023781", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023782", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError == YES) {
-        memcpy(code, "023782", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023783", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE == YES) {
-        memcpy(code, "023783", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023784", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop == YES) {
-        memcpy(code, "023784", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023785", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError == YES) {
-        memcpy(code, "023785", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023786", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError == YES) {
-        memcpy(code, "023786", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023787", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError == YES) {
-        memcpy(code, "023787", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023788", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort == YES) {
-        memcpy(code, "023788", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023789", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol == YES) {
-        memcpy(code, "023789", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023790", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted == YES) {
-        memcpy(code, "023790", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023791", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown == YES) {
-        memcpy(code, "023791", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023792", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke == YES) {
-        memcpy(code, "023792", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023793", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked == YES) {
-        memcpy(code, "023793", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023794", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked == YES) {
-        memcpy(code, "023794", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023795", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked == YES) {
-        memcpy(code, "023795", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023796", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked == YES) {
-        memcpy(code, "023796", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023797", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked == YES) {
-        memcpy(code, "023797", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023798", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked == YES) {
-        memcpy(code, "023798", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023799", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked == YES) {
-        memcpy(code, "023799", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023800", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked == YES) {
-        memcpy(code, "023800", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023801", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked == YES) {
-        memcpy(code, "023801", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023802", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked == YES) {
-        memcpy(code, "023802", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023803", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked == YES) {
-        memcpy(code, "023803", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023809", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init == YES) {
-        memcpy(code, "023809", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023810", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response == YES) {
-        memcpy(code, "023810", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023811", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence == YES) {
-        memcpy(code, "023811", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023812", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC == YES) {
-        memcpy(code, "023812", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023813", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc == YES) {
-        memcpy(code, "023813", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023814", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response == YES) {
-        memcpy(code, "023814", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023815", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session == YES) {
-        memcpy(code, "023815", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023816", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session == YES) {
-        memcpy(code, "023816", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023817", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle == YES) {
-        memcpy(code, "023817", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023818", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound == YES) {
-        memcpy(code, "023818", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023819", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq == YES) {
-        memcpy(code, "023819", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023823", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join == YES) {
-        memcpy(code, "023823", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023824", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join == YES) {
-        memcpy(code, "023824", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023825", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange == YES) {
-        memcpy(code, "023825", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023826", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification == YES) {
-        memcpy(code, "023826", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023832", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes == YES) {
-        memcpy(code, "023832", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023833", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes == YES) {
-        memcpy(code, "023833", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023834", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes == YES) {
-        memcpy(code, "023834", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023835", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes == YES) {
-        memcpy(code, "023835", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023836", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes == YES) {
-        memcpy(code, "023836", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023837", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes == YES) {
-        memcpy(code, "023837", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023838", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes == YES) {
-        memcpy(code, "023838", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023839", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes == YES) {
-        memcpy(code, "023839", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023840", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes == YES) {
-        memcpy(code, "023840", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023841", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes == YES) {
-        memcpy(code, "023841", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023842", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes == YES) {
-        memcpy(code, "023842", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023843", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes == YES) {
-        memcpy(code, "023843", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023844", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time == YES) {
-        memcpy(code, "023844", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023845", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time == YES) {
-        memcpy(code, "023845", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023846", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time == YES) {
-        memcpy(code, "023846", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023847", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time == YES) {
-        memcpy(code, "023847", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023848", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time == YES) {
-        memcpy(code, "023848", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023849", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time == YES) {
-        memcpy(code, "023849", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023850", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime == YES) {
-        memcpy(code, "023850", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023855", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO == YES) {
-        memcpy(code, "023855", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023856", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO == YES) {
-        memcpy(code, "023856", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023857", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO == YES) {
-        memcpy(code, "023857", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023858", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO == YES) {
-        memcpy(code, "023858", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023859", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT == YES) {
-        memcpy(code, "023859", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023860", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT == YES) {
-        memcpy(code, "023860", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023861", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT == YES) {
-        memcpy(code, "023861", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023862", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT == YES) {
-        memcpy(code, "023862", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023863", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO == YES) {
-        memcpy(code, "023863", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023864", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO == YES) {
-        memcpy(code, "023864", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023865", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST == YES) {
-        memcpy(code, "023865", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023866", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST == YES) {
-        memcpy(code, "023866", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023867", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER == YES) {
-        memcpy(code, "023867", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023868", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER == YES) {
-        memcpy(code, "023868", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023869", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER == YES) {
-        memcpy(code, "023869", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023870", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER == YES) {
-        memcpy(code, "023870", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023871", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH == YES) {
-        memcpy(code, "023871", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023872", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH == YES) {
-        memcpy(code, "023872", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023873", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS == YES) {
-        memcpy(code, "023873", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023874", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS == YES) {
-        memcpy(code, "023874", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023875", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO == YES) {
-        memcpy(code, "023875", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023876", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO == YES) {
-        memcpy(code, "023876", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023877", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO == YES) {
-        memcpy(code, "023877", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023878", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO == YES) {
-        memcpy(code, "023878", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023879", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO == YES) {
-        memcpy(code, "023879", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023880", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO == YES) {
-        memcpy(code, "023880", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023881", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence == YES) {
-        memcpy(code, "023881", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023882", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID == YES) {
-        memcpy(code, "023882", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023883", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error == YES) {
-        memcpy(code, "023883", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023884", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error == YES) {
-        memcpy(code, "023884", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023885", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error == YES) {
-        memcpy(code, "023885", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023886", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error == YES) {
-        memcpy(code, "023886", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023887", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error == YES) {
-        memcpy(code, "023887", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023888", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error == YES) {
-        memcpy(code, "023888", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023889", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error == YES) {
-        memcpy(code, "023889", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023890", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error == YES) {
-        memcpy(code, "023890", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023891", 6) == EQUAL &&
-               ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging == YES) {
-        memcpy(code, "023891", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-//  else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023892", 6) == EQUAL &&
-//          ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
-//  {
-//      memcpy(code, "023892", 6);
-//      memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-//      isCleanCheck = true;
-//  }
-    else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023893", 6) == EQUAL &&
-             ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey == YES) {
-        memcpy(code, "023893", 6);
-        memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                PRINTF_FUNC("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-                if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "023701", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = NO; }
-                    if (strncmp(code, "023737", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = NO; }
-                    if (strncmp(code, "023738", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = NO; }
-                    if (strncmp(code, "023739", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = NO; }
-                    if (strncmp(code, "023740", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = NO; }
-                    if (strncmp(code, "023741", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = NO; }
-                    if (strncmp(code, "023742", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = NO; }
-                    if (strncmp(code, "023743", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = NO; }
-                    if (strncmp(code, "023744", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = NO; }
-                    if (strncmp(code, "023745", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = NO; }
-                    if (strncmp(code, "023746", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = NO; }
-                    if (strncmp(code, "023747", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = NO; }
-                    if (strncmp(code, "023748", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = NO; }
-                    if (strncmp(code, "023749", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = NO; }
-                    if (strncmp(code, "023750", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = NO; }
-                    if (strncmp(code, "023751", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = NO; }
-                    if (strncmp(code, "023752", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = NO; }
-                    if (strncmp(code, "023753", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = NO; }
-                    if (strncmp(code, "023754", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = NO; }
-                    if (strncmp(code, "023755", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = NO; }
-                    if (strncmp(code, "023756", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = NO; }
-                    if (strncmp(code, "023757", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = NO; }
-                    if (strncmp(code, "023758", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = NO; }
-                    if (strncmp(code, "023759", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = NO; }
-                    if (strncmp(code, "023760", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = NO; }
-                    if (strncmp(code, "023761", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = NO; }
-                    if (strncmp(code, "023762", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = NO; }
-                    if (strncmp(code, "023763", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = NO; }
-                    if (strncmp(code, "023764", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = NO; }
-                    if (strncmp(code, "023765", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = NO; }
-                    if (strncmp(code, "023766", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = NO; }
-                    if (strncmp(code, "023767", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = NO; }
-                    if (strncmp(code, "023768", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = NO; }
-                    if (strncmp(code, "023769", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = NO; }
-                    if (strncmp(code, "023770", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = NO; }
-                    if (strncmp(code, "023771", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = NO; }
-                    if (strncmp(code, "023772", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = NO; }
-                    if (strncmp(code, "023773", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = NO; }
-                    if (strncmp(code, "023774", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = NO; }
-                    if (strncmp(code, "023775", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = NO; }
-                    if (strncmp(code, "023776", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = NO; }
-                    if (strncmp(code, "023777", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = NO; }
-                    if (strncmp(code, "023778", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = NO; }
-                    if (strncmp(code, "023779", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = NO; }
-                    if (strncmp(code, "023780", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = NO; }
-                    if (strncmp(code, "023781", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = NO; }
-                    if (strncmp(code, "023782", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = NO; }
-                    if (strncmp(code, "023783", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = NO; }
-                    if (strncmp(code, "023784", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = NO; }
-                    if (strncmp(code, "023785", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = NO; }
-                    if (strncmp(code, "023786", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = NO; }
-                    if (strncmp(code, "023787", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = NO; }
-                    if (strncmp(code, "023788", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = NO; }
-                    if (strncmp(code, "023789", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = NO; }
-                    if (strncmp(code, "023790", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = NO; }
-                    if (strncmp(code, "023791", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = NO; }
-                    if (strncmp(code, "023792", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = NO; }
-                    if (strncmp(code, "023793", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = NO; }
-                    if (strncmp(code, "023794", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = NO; }
-                    if (strncmp(code, "023795", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = NO; }
-                    if (strncmp(code, "023796", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = NO; }
-                    if (strncmp(code, "023797", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = NO; }
-                    if (strncmp(code, "023798", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = NO; }
-                    if (strncmp(code, "023799", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = NO; }
-                    if (strncmp(code, "023800", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = NO; }
-                    if (strncmp(code, "023801", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = NO; }
-                    if (strncmp(code, "023802", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = NO; }
-                    if (strncmp(code, "023803", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = NO; }
-                    if (strncmp(code, "023809", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = NO; }
-                    if (strncmp(code, "023810", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = NO; }
-                    if (strncmp(code, "023811", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = NO; }
-                    if (strncmp(code, "023812", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = NO; }
-                    if (strncmp(code, "023813", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = NO; }
-                    if (strncmp(code, "023814", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = NO; }
-                    if (strncmp(code, "023815", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = NO; }
-                    if (strncmp(code, "023816", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = NO; }
-                    if (strncmp(code, "023817", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = NO; }
-                    if (strncmp(code, "023818", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = NO; }
-                    if (strncmp(code, "023819", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = NO; }
-                    if (strncmp(code, "023823", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = NO; }
-                    if (strncmp(code, "023824", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = NO; }
-                    if (strncmp(code, "023825", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = NO; }
-                    if (strncmp(code, "023826", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = NO; }
-                    if (strncmp(code, "023832", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = NO; }
-                    if (strncmp(code, "023833", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = NO; }
-                    if (strncmp(code, "023834", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = NO; }
-                    if (strncmp(code, "023835", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = NO; }
-                    if (strncmp(code, "023836", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = NO; }
-                    if (strncmp(code, "023837", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = NO; }
-                    if (strncmp(code, "023838", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = NO; }
-                    if (strncmp(code, "023839", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = NO; }
-                    if (strncmp(code, "023840", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = NO; }
-                    if (strncmp(code, "023841", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = NO; }
-                    if (strncmp(code, "023842", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = NO; }
-                    if (strncmp(code, "023843", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = NO; }
-                    if (strncmp(code, "023844", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = NO; }
-                    if (strncmp(code, "023845", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = NO; }
-                    if (strncmp(code, "023846", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = NO; }
-                    if (strncmp(code, "023847", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = NO; }
-                    if (strncmp(code, "023848", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = NO; }
-                    if (strncmp(code, "023849", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = NO; }
-                    if (strncmp(code, "023850", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = NO; }
-                    if (strncmp(code, "023855", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = NO; }
-                    if (strncmp(code, "023856", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = NO; }
-                    if (strncmp(code, "023857", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = NO; }
-                    if (strncmp(code, "023858", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = NO; }
-                    if (strncmp(code, "023859", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = NO; }
-                    if (strncmp(code, "023860", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = NO; }
-                    if (strncmp(code, "023861", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = NO; }
-                    if (strncmp(code, "023862", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = NO; }
-                    if (strncmp(code, "023863", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = NO; }
-                    if (strncmp(code, "023864", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = NO; }
-                    if (strncmp(code, "023865", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = NO; }
-                    if (strncmp(code, "023866", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = NO; }
-                    if (strncmp(code, "023867", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = NO; }
-                    if (strncmp(code, "023868", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = NO; }
-                    if (strncmp(code, "023869", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = NO; }
-                    if (strncmp(code, "023870", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = NO; }
-                    if (strncmp(code, "023871", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = NO; }
-                    if (strncmp(code, "023872", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = NO; }
-                    if (strncmp(code, "023873", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = NO; }
-                    if (strncmp(code, "023874", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = NO; }
-                    if (strncmp(code, "023875", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = NO; }
-                    if (strncmp(code, "023876", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = NO; }
-                    if (strncmp(code, "023877", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = NO; }
-                    if (strncmp(code, "023878", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = NO; }
-                    if (strncmp(code, "023879", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = NO; }
-                    if (strncmp(code, "023880", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = NO; }
-                    if (strncmp(code, "023881", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = NO; }
-                    if (strncmp(code, "023882", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = NO; }
-                    if (strncmp(code, "023883", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = NO; }
-                    if (strncmp(code, "023884", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = NO; }
-                    if (strncmp(code, "023885", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = NO; }
-                    if (strncmp(code, "023886", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = NO; }
-                    if (strncmp(code, "023887", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = NO; }
-                    if (strncmp(code, "023888", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = NO; }
-                    if (strncmp(code, "023889", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = NO; }
-                    if (strncmp(code, "023890", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = NO; }
-                    if (strncmp(code, "023891", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = NO; }
-                    //if (strncmp(code, "023892", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = NO;
-                    if (strncmp(code, "023893", 6) == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey = NO; }
-                }
-            }
-        }
-    }
-}
-
-void AbnormalStopAnalysis(byte gun_index, byte *errCode)
-{
-    char string[7];
-    sprintf(string, "%d%d%d%d%d%d", *(errCode + 0), *(errCode + 1), *(errCode + 2), *(errCode + 3), *(errCode + 4), *(errCode + 5));
-
-    PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
-    if (strncmp(string, "000000", 6) == EQUAL ||
-            strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) != EQUAL) {
-        return;
-    }
-
-    memcpy(_chargingData[gun_index]->EvConnAlarmCode, string, 6);
-    PRINTF_FUNC("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s \n", _chargingData[gun_index]->EvConnAlarmCode);
-
-    if (strcmp(string, "023700") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = YES; }
-    if (strcmp(string, "023704") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = YES; }
-    if (strcmp(string, "023705") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = YES; }
-    if (strcmp(string, "023706") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = YES; }
-    if (strcmp(string, "023707") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = YES; }
-    if (strcmp(string, "023708") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = YES; }
-    if (strcmp(string, "023709") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = YES; }
-    if (strcmp(string, "023710") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = YES; }
-    if (strcmp(string, "023711") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = YES; }
-    if (strcmp(string, "023712") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = YES; }
-    if (strcmp(string, "023713") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = YES; }
-    if (strcmp(string, "023714") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = YES; }
-    if (strcmp(string, "023715") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = YES; }
-    if (strcmp(string, "023716") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = YES; }
-    if (strcmp(string, "023717") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = YES; }
-    if (strcmp(string, "023718") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = YES; }
-    if (strcmp(string, "023719") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = YES; }
-    if (strcmp(string, "023720") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = YES; }
-    if (strcmp(string, "023721") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = YES; }
-    if (strcmp(string, "023722") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = YES; }
-    if (strcmp(string, "023723") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = YES; }
-    if (strcmp(string, "023724") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = YES; }
-    if (strcmp(string, "023725") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = YES; }
-    if (strcmp(string, "023726") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = YES; }
-    if (strcmp(string, "023727") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = YES; }
-    if (strcmp(string, "023728") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = YES; }
-    if (strcmp(string, "023729") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = YES; }
-    if (strcmp(string, "023730") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES; }
-    if (strcmp(string, "023731") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = YES; }
-    if (strcmp(string, "023732") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = YES; }
-    if (strcmp(string, "023733") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = YES; }
-    if (strcmp(string, "023734") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = YES; }
-    if (strcmp(string, "023735") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = YES; }
-    if (strcmp(string, "023736") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = YES; }
-
-    if (strcmp(string, "023701") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = YES; }
-    if (strcmp(string, "023737") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = YES; }
-    if (strcmp(string, "023738") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = YES; }
-    if (strcmp(string, "023739") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = YES; }
-    if (strcmp(string, "023740") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = YES; }
-    if (strcmp(string, "023741") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = YES; }
-    if (strcmp(string, "023742") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = YES; }
-    if (strcmp(string, "023743") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = YES; }
-    if (strcmp(string, "023744") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = YES; }
-    if (strcmp(string, "023745") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = YES; }
-    if (strcmp(string, "023746") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = YES; }
-    if (strcmp(string, "023747") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = YES; }
-    if (strcmp(string, "023748") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = YES; }
-    if (strcmp(string, "023749") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = YES; }
-    if (strcmp(string, "023750") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = YES; }
-    if (strcmp(string, "023751") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = YES; }
-    if (strcmp(string, "023752") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = YES; }
-    if (strcmp(string, "023753") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = YES; }
-    if (strcmp(string, "023754") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = YES; }
-    if (strcmp(string, "023755") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = YES; }
-    if (strcmp(string, "023756") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = YES; }
-    if (strcmp(string, "023757") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = YES; }
-    if (strcmp(string, "023758") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = YES; }
-    if (strcmp(string, "023759") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = YES; }
-    if (strcmp(string, "023760") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = YES; }
-    if (strcmp(string, "023761") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = YES; }
-    if (strcmp(string, "023762") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = YES; }
-    if (strcmp(string, "023763") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = YES; }
-    if (strcmp(string, "023764") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = YES; }
-    if (strcmp(string, "023765") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = YES; }
-    if (strcmp(string, "023766") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = YES; }
-    if (strcmp(string, "023767") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = YES; }
-    if (strcmp(string, "023768") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = YES; }
-    if (strcmp(string, "023769") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = YES; }
-    if (strcmp(string, "023770") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = YES; }
-    if (strcmp(string, "023771") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = YES; }
-    if (strcmp(string, "023772") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = YES; }
-    if (strcmp(string, "023773") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = YES; }
-    if (strcmp(string, "023774") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = YES; }
-    if (strcmp(string, "023775") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = YES; }
-    if (strcmp(string, "023776") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = YES; }
-    if (strcmp(string, "023777") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = YES; }
-    if (strcmp(string, "023778") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = YES; }
-    if (strcmp(string, "023779") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = YES; }
-    if (strcmp(string, "023780") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = YES; }
-    if (strcmp(string, "023781") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = YES; }
-    if (strcmp(string, "023782") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = YES; }
-    if (strcmp(string, "023783") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = YES; }
-    if (strcmp(string, "023784") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = YES; }
-    if (strcmp(string, "023785") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = YES; }
-    if (strcmp(string, "023786") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = YES; }
-    if (strcmp(string, "023787") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = YES; }
-    if (strcmp(string, "023788") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = YES; }
-    if (strcmp(string, "023789") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = YES; }
-    if (strcmp(string, "023790") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = YES; }
-    if (strcmp(string, "023791") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = YES; }
-    if (strcmp(string, "023792") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = YES; }
-    if (strcmp(string, "023793") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = YES; }
-    if (strcmp(string, "023794") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = YES; }
-    if (strcmp(string, "023795") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = YES; }
-    if (strcmp(string, "023796") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = YES; }
-    if (strcmp(string, "023797") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = YES; }
-    if (strcmp(string, "023798") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = YES; }
-    if (strcmp(string, "023799") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = YES; }
-    if (strcmp(string, "023800") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = YES; }
-    if (strcmp(string, "023801") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = YES; }
-    if (strcmp(string, "023802") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = YES; }
-    if (strcmp(string, "023803") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = YES; }
-    if (strcmp(string, "023809") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = YES; }
-    if (strcmp(string, "023810") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = YES; }
-    if (strcmp(string, "023811") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = YES; }
-    if (strcmp(string, "023812") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = YES; }
-    if (strcmp(string, "023813") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = YES; }
-    if (strcmp(string, "023814") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = YES; }
-    if (strcmp(string, "023815") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = YES; }
-    if (strcmp(string, "023816") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = YES; }
-    if (strcmp(string, "023817") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = YES; }
-    if (strcmp(string, "023818") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = YES; }
-    if (strcmp(string, "023819") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = YES; }
-    if (strcmp(string, "023823") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = YES; }
-    if (strcmp(string, "023824") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = YES; }
-    if (strcmp(string, "023825") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = YES; }
-    if (strcmp(string, "023826") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = YES; }
-    if (strcmp(string, "023832") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = YES; }
-    if (strcmp(string, "023833") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = YES; }
-    if (strcmp(string, "023834") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = YES; }
-    if (strcmp(string, "023835") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = YES; }
-    if (strcmp(string, "023836") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = YES; }
-    if (strcmp(string, "023837") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = YES; }
-    if (strcmp(string, "023838") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = YES; }
-    if (strcmp(string, "023839") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = YES; }
-    if (strcmp(string, "023840") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = YES; }
-    if (strcmp(string, "023841") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = YES; }
-    if (strcmp(string, "023842") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = YES; }
-    if (strcmp(string, "023843") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = YES; }
-    if (strcmp(string, "023844") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = YES; }
-    if (strcmp(string, "023845") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = YES; }
-    if (strcmp(string, "023846") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = YES; }
-    if (strcmp(string, "023847") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = YES; }
-    if (strcmp(string, "023848") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = YES; }
-    if (strcmp(string, "023849") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = YES; }
-    if (strcmp(string, "023850") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = YES; }
-    if (strcmp(string, "023855") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = YES; }
-    if (strcmp(string, "023856") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = YES; }
-    if (strcmp(string, "023857") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = YES; }
-    if (strcmp(string, "023858") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = YES; }
-    if (strcmp(string, "023859") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = YES; }
-    if (strcmp(string, "023860") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = YES; }
-    if (strcmp(string, "023861") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = YES; }
-    if (strcmp(string, "023862") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = YES; }
-    if (strcmp(string, "023863") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = YES; }
-    if (strcmp(string, "023864") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = YES; }
-    if (strcmp(string, "023865") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = YES; }
-    if (strcmp(string, "023866") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = YES; }
-    if (strcmp(string, "023867") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = YES; }
-    if (strcmp(string, "023868") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = YES; }
-    if (strcmp(string, "023869") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = YES; }
-    if (strcmp(string, "023870") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = YES; }
-    if (strcmp(string, "023871") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = YES; }
-    if (strcmp(string, "023872") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = YES; }
-    if (strcmp(string, "023873") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = YES; }
-    if (strcmp(string, "023874") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = YES; }
-    if (strcmp(string, "023875") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = YES; }
-    if (strcmp(string, "023876") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = YES; }
-    if (strcmp(string, "023877") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = YES; }
-    if (strcmp(string, "023878") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = YES; }
-    if (strcmp(string, "023879") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = YES; }
-    if (strcmp(string, "023880") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = YES; }
-    if (strcmp(string, "023881") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = YES; }
-    if (strcmp(string, "023882") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = YES; }
-    if (strcmp(string, "023883") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = YES; }
-    if (strcmp(string, "023884") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = YES; }
-    if (strcmp(string, "023885") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = YES; }
-    if (strcmp(string, "023886") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = YES; }
-    if (strcmp(string, "023887") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = YES; }
-    if (strcmp(string, "023888") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = YES; }
-    if (strcmp(string, "023889") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = YES; }
-    if (strcmp(string, "023890") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = YES; }
-    if (strcmp(string, "023891") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = YES; }
-    if (strcmp(string, "023892") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = YES; }
-    if (strcmp(string, "023893") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey = YES; }
-
-    if (strcmp(string, "023702") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = YES; }
-    if (strcmp(string, "023900") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = YES; }
-    if (strcmp(string, "023901") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = YES; }
-    if (strcmp(string, "023902") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = YES; }
-    if (strcmp(string, "023903") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = YES; }
-    if (strcmp(string, "023904") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = YES; }
-    if (strcmp(string, "023905") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = YES; }
-    if (strcmp(string, "023906") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = YES; }
-    if (strcmp(string, "023907") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = YES; }
-    if (strcmp(string, "023908") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = YES; }
-    if (strcmp(string, "023909") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = YES; }
-    if (strcmp(string, "023910") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = YES; }
-    if (strcmp(string, "023911") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = YES; }
-    if (strcmp(string, "023912") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = YES; }
-    if (strcmp(string, "023913") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = YES; }
-    if (strcmp(string, "023914") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = YES; }
-    if (strcmp(string, "023915") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = YES; }
-    if (strcmp(string, "023916") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = YES; }
-    if (strcmp(string, "023917") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = YES; }
-    if (strcmp(string, "023918") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = YES; }
-    if (strcmp(string, "023919") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = YES; }
-    if (strcmp(string, "023930") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = YES; }
-    if (strcmp(string, "023931") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = YES; }
-    if (strcmp(string, "023932") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = YES; }
-    if (strcmp(string, "023933") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = YES; }
-    if (strcmp(string, "023934") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = YES; }
-    if (strcmp(string, "023935") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = YES; }
-    if (strcmp(string, "023936") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = YES; }
-    if (strcmp(string, "023937") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = YES; }
-    if (strcmp(string, "023938") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = YES; }
-    if (strcmp(string, "023939") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = YES; }
-    if (strcmp(string, "023940") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = YES; }
-    if (strcmp(string, "023941") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = YES; }
-    if (strcmp(string, "023942") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = YES; }
-    if (strcmp(string, "023943") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = YES; }
-    if (strcmp(string, "023944") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = YES; }
-    if (strcmp(string, "023945") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = YES; }
-    if (strcmp(string, "023946") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = YES; }
-    if (strcmp(string, "023947") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = YES; }
-    if (strcmp(string, "023950") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = YES; }
-    if (strcmp(string, "023951") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = YES; }
-    if (strcmp(string, "023952") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = YES; }
-    if (strcmp(string, "023953") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST = YES; }
-    if (strcmp(string, "023954") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION = YES; }
-    if (strcmp(string, "023955") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = YES; }
-    if (strcmp(string, "023956") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT = YES; }
-    if (strcmp(string, "023957") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = YES; }
-    if (strcmp(string, "023958") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP = YES; }
-    if (strcmp(string, "023959") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER = YES; }
-    if (strcmp(string, "023960") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V = YES; }
-    if (strcmp(string, "023961") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 = YES; }
-    if (strcmp(string, "023962") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT = YES; }
-    if (strcmp(string, "023963") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = YES; }
-    if (strcmp(string, "023964") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = YES; }
-    if (strcmp(string, "023970") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = YES; }
-    if (strcmp(string, "023971") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = YES; }
-    if (strcmp(string, "023972") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = YES; }
-    if (strcmp(string, "023973") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = YES; }
-    if (strcmp(string, "023974") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT = YES; }
-    if (strcmp(string, "023975") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = YES; }
-    if (strcmp(string, "023976") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = YES; }
-    if (strcmp(string, "023977") == EQUAL) { ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = YES; }
-}
-
-void CANReceiver()
-{
-    pid_t canRecPid;
-
-    canRecPid = fork();
-
-    if (canRecPid > 0) {
-        int nbytes;
-        struct can_frame frame;
-        int intCmd;
-
-        // 槍資訊
-        struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-        struct timeval _cmd_ack_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-        bool isPass = false;
-        gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-
-        while (!isPass) {
-            isPass = true;
-            for (byte _index = 0; _index < gun_count; _index++) {
-                if (!FindChargingInfoData(_index, &_chargingData[0])) {
-                    DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-                    isPass = false;
-                    break;
-                }
-            }
-
-            sleep(1);
-        }
-
-        for (byte _index = 0; _index < gun_count; _index++) {
-            gettimeofday(&_cmd_ack_timeout[_index], NULL);
-        }
-
-        while (1) {
-            memset(&frame, 0, sizeof(struct can_frame));
-            nbytes = read(CanFd, &frame, sizeof(struct can_frame));
-
-            for (byte _index = 0; _index < gun_count; _index++) {
-                if (GetTimeoutValue(_cmd_ack_timeout[_index]) >= 5000000) {
-                    // ACK timeout
-                    //PRINTF_FUNC("gun = %x, ack timeout \n", _index);
-                }
-            }
-
-            if (nbytes > 0) {
-                byte target;
-                byte targetGun = 0x00;
-                intCmd = (int) (frame.can_id & CAN_EFF_MASK);
-
-                if (intCmd == ADDRESS_REQ) {
-                    AddrAssignment(frame.data);
-                    continue;
-                }
-                intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
-                target = ((byte) (frame.can_id & 0x000000FF));      // 0x01 or 0x02
-
-                for (byte _index = 0; _index < gun_count; _index++) {
-                    if (_chargingData[_index]->Evboard_id == target) {
-                        targetGun = _index;
-                        break;
-                    }
-                }
-
-                if (targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) {
-                    PRINTF_FUNC("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
-                    continue;
-                }
-                if (intCmd == 256) {
-                    continue;
-                }
-
-                gettimeofday(&_cmd_ack_timeout[targetGun], NULL);
-                switch (intCmd) {
-                case NOTIFICATION_EV_STATUS: {
-                    if (_chargingData[targetGun]->ConnectorPlugIn != frame.data[0]) {
-                        PRINTF_FUNC("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
-                    }
-
-                    _chargingData[targetGun]->ConnectorPlugIn = frame.data[0];
-                    _chargingData[targetGun]->PilotVoltage = frame.data[1];
-
-                    //PRINTF_FUNC("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
-                    //PRINTF_FUNC("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
-                }
-                break;
-                case ACK_EV_FW_VERSION: {
-                    byte ver[16];
-
-                    memset(ver, 0, sizeof(ver));
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        memcpy(ver, frame.data, frame.can_dlc);
-                        memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-                        //PRINTF_FUNC("chademo ver. : %s\n", ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version);
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        memcpy(ver, frame.data, frame.can_dlc);
-                        memcpy(ShmGBTData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-                        //PRINTF_FUNC("gbt ver. : %s\n", ShmGBTData->evse[_chargingData[targetGun]->type_index].version);
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                            for (byte _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++) {
-                                /*if (_vCount % 2 == 0 && _vCount != 0)
-                                {
-                                    ver[_vCount + _vPoint] = 0x2E;
-                                    _vPoint++;
-                                }*/
-
-                                ver[_vCount + _vPoint] = frame.data[_vCount];
-                            }
-
-                            memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-                            ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-                            //PRINTF_FUNC("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version);
-                        }
-                    }
-
-                    if (targetGun == 0) {
-                        memset(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
-                        memcpy(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, ver, ARRAY_SIZE(ver));
-                    } else {
-                        memset(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
-                        memcpy(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, ver, ARRAY_SIZE(ver));
-                    }
-                }
-                break;
-                case ACK_EV_HW_VERSION: {
-                    //PRINTF_FUNC("Get EV HW = %s \n", frame.data);
-                }
-                break;
-                case ACK_GET_OUTPUT_REQ: {
-                    _chargingData[targetGun]->EvBatterySoc = frame.data[1];
-                    _chargingData[targetGun]->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
-                    _chargingData[targetGun]->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
-                    _chargingData[targetGun]->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
-
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        //if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
-                        {
-                            ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-                        }
-
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        //if (ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
-                        {
-                            ShmGBTData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-                        }
-
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                            ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-                        }
-                    }
-
-                    //PRINTF_FUNC("EvBatterytargetVoltage = %f \n", _chargingData[targetGun]->EvBatterytargetVoltage);
-                    //PRINTF_FUNC("EvBatterytargetCurrent = %f \n", _chargingData[targetGun]->EvBatterytargetCurrent);
-                    //PRINTF_FUNC("BatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
-                    //PRINTF_FUNC("CurrentRequest = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
-                }
-                break;
-                case ACK_GET_EV_BATTERY_INFO: {
-                    //_chargingData[target].EvACorDCcharging = frame.data[0];
-                    //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
-                    _chargingData[targetGun]->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
-                    //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
-                    //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
-                        ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
-
-                        //PRINTF_FUNC("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
-                        //PRINTF_FUNC("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
-                        //PRINTF_FUNC("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
-                        ShmGBTData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-
-                    }
-                }
-                break;
-                case ACK_GET_MISCELLANEOUS_INFO: {
-                    _chargingData[targetGun]->GunLocked = frame.data[0];
-                    _chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
-
-                    if (_chargingData[targetGun]->Type == _Type_Chademo) {
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
-                        ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-                    } else if (_chargingData[targetGun]->Type == _Type_GB) {
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
-                        ShmGBTData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-                    } else if (_chargingData[targetGun]->Type == _Type_CCS_2) {
-                        if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                            //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
-                            //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
-                        }
-                    }
-
-                    //PRINTF_FUNC("EvboardStatus = %x \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].EvboardStatus);
-                    //PRINTF_FUNC("ConnectorPlug locked = %x \n", frame.data[0]);
-                    //PRINTF_FUNC("ConnectorTemp 0= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureP);
-                    //PRINTF_FUNC("ConnectorTemp 1= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureN);
-                    //PRINTF_FUNC("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
-                }
-                break;
-                case ACK_EVSE_ISOLATION_STATUS: {}
-                    break;
-                case ACK_EVSE_PRECHAGE_INFO: {
-                    _chargingData[targetGun]->PrechargeStatus = frame.data[0];
-                }
-                break;
-                case NOTIFICATION_EV_STOP: {
-                    // 車端要求停止
-                    // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
-                    PRINTF_FUNC("(%d) NOTIFICATION_EV_STOP err level = %d-----------------------------\n", targetGun, frame.data[0]);
-                    //if (frame.data[0] == 0x02)
-                    {
-                        AbnormalStopAnalysis(targetGun, frame.data + 1);
-                    }
-                    _chargingData[targetGun]->StopChargeFlag = YES;
-                }
-                break;
-                default:
-                    PRINTF_FUNC("EV board = %d, Ack none defined. intCmd = %d  \n", targetGun, intCmd);
-                    break;
-                }
-            }
-            usleep(10000);
-        }
-    }
-}
-
-//================================================
-// Main process
-//================================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
-{
-    return ( _byte & mask_table[_bit] ) != 0x00;
-}
-
-bool IsConnectorPlugIn(struct ChargingInfoData *chargingData)
-{
-    return (chargingData->ConnectorPlugIn == 0x01) ? true : false;
-}
-
-void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-    float vol1 = 0, cur1 = 0;
-    float vol2 = 0, cur2 = 0;
-
-    vol1 = chargingData_1->FireChargingVoltage;
-    cur1 = (chargingData_1->PresentChargingCurrent * 10);
-    vol2 = chargingData_2->FireChargingVoltage;
-    cur2 = (chargingData_2->PresentChargingCurrent * 10);
-
-    if (_outVol_1 != vol1 ||
-            _outCur_1 != cur1 ||
-            _outVol_2 != vol2 ||
-            _outCur_2 != cur2) {
-        /*PRINTF_FUNC("G1 -> Output Vol = %f, Output Cur = %f -- G2 -> Output Vol = %f, Output Cur = %f \n",
-            vol1, cur1, vol2, cur2);
-        */
-        _outVol_1 = vol1; _outCur_1 = cur1; _outVol_2 = vol2; _outCur_2 = cur2;
-    }
-
-    SetPresentOutputPower(vol1, cur1, vol2, cur2);
-}
-
-void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-    float pow1 = 0, cur1 = 0;
-    float pow2 = 0, cur2 = 0;
-    float vol = 0;
-
-    pow1 = chargingData_1->AvailableChargingPower;
-    cur1 = chargingData_1->AvailableChargingCurrent;
-
-    vol = chargingData_1->MaximumChargingVoltage;
-#ifndef DD360
-    GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
-    GetMaxPowerMethod(chargingData_1->Index, &pow1);
-#endif
-
-    pow2 = chargingData_2->AvailableChargingPower;
-    cur2 = chargingData_2->AvailableChargingCurrent;
-    vol = chargingData_2->MaximumChargingVoltage;
-#ifndef DD360
-    GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
-    GetMaxPowerMethod(chargingData_2->Index, &pow2);
-#endif
-
-    if (_pow_1 != pow1 ||
-            _cur_1 != cur1 ||
-            _pow_2 != pow2 ||
-            _cur_2 != cur2) {
-        PRINTF_FUNC("To EV (Real) Power_1 = %f, Cur_1 = %f, Power_2 = %f, Cur_2 = %f \n",
-                    pow1, cur1, pow2, cur2);
-        _pow_1 = pow1; _cur_1 = cur1; _pow_2 = pow2; _cur_2 = cur2;
-        chargingData_1->RealMaxCurrent = _cur_1;
-        chargingData_1->RealMaxPower = pow1;
-
-        if (gun_count == 2) {
-            chargingData_2->RealMaxCurrent = cur2;
-            chargingData_2->RealMaxPower = pow2;
-        }
-    }
-
-    SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
-}
-
-void Initialization()
-{
-    bool isPass = false;
-    while (!isPass) {
-        isPass = true;
-        for (byte _index = 0; _index < gun_count; _index++) {
-            if (!FindChargingInfoData(_index, &_chargingData[0])) {
-                DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-                isPass = false;
-                break;
-            }
-        }
-        sleep(1);
-    }
-}
-
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
-{
-    if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol) {
-        *vol = maxChargingVol[index];
-    }
-
-    if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur) {
-        *cur = maxChargingCur[index];
-    }
-
-    if (_chargingData[index]->SystemStatus == S_CHARGING &&
-            _chargingData[index]->ChargingProfileCurrent > 0 &&
-            _chargingData[index]->ChargingProfileCurrent <= *cur) {
-        *cur = _chargingData[index]->ChargingProfileCurrent;
-    }
-}
-
-void GetMaxPowerMethod(byte index, float *pow)
-{
-    if (maxChargingPow != 0 && maxChargingPow <= *pow) {
-        *pow = maxChargingPow;
-    }
-
-    if (_chargingData[index]->SystemStatus == S_CHARGING &&
-            _chargingData[index]->ChargingProfilePower > 0 &&
-            _chargingData[index]->ChargingProfilePower <= *pow) {
-        *pow = _chargingData[index]->ChargingProfilePower;
-    }
-}
-
-time_t GetRtcInfoForEpoch()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-    struct tm t;
-    time_t result;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-
-    t.tm_year = tmCSU->tm_year;
-    t.tm_mon = tmCSU->tm_mon;
-    t.tm_mday = tmCSU->tm_mday;
-    t.tm_hour = tmCSU->tm_hour;
-    t.tm_min = tmCSU->tm_min;
-    t.tm_sec = tmCSU->tm_sec;
-    t.tm_isdst = -1;
-    result = mktime(&t);
-
-    return result;
-}
-
-byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
-{
-    byte result = NO;
-
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == 0x01) {
-        // 012251
-        *(reason + 5)  = 0;
-        *(reason + 4)  = 1;
-        *(reason + 3)  = 2;
-        *(reason + 2)  = 2;
-        *(reason + 1)  = 5;
-        *(reason + 0)  = 1;
-        result = YES;
-    }
-
-    if (_chargingData[gunIndex]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            // 011012
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 1;
-            *(reason + 2) = 0;
-            *(reason + 1) = 1;
-            *(reason + 0) = 2;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES) {
-            // 012289
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 8;
-            *(reason + 0) = 9;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES) {
-            // 012234
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 3;
-            *(reason + 0) = 4;
-            result = YES;
-        }
-    } else if (_chargingData[gunIndex]->Type == _Type_GB) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            // 012290
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 9;
-            *(reason + 0) = 0;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES) {
-            // 012236
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 3;
-            *(reason + 0) = 6;
-            result = YES;
-        }
-    } else if (_chargingData[gunIndex]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-            // 011014
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 1;
-            *(reason + 2) = 0;
-            *(reason + 1) = 1;
-            *(reason + 0) = 4;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES) {
-            // 012288
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 8;
-            *(reason + 0) = 8;
-            result = YES;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES) {
-            // 012235
-            *(reason + 5) = 0;
-            *(reason + 4) = 1;
-            *(reason + 3) = 2;
-            *(reason + 2) = 2;
-            *(reason + 1) = 3;
-            *(reason + 0) = 5;
-            result = YES;
-        }
-    }
-
-    return result;
-}
-
-int main(int argc, char *argv[])
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-    Initialization();
-    CanFd = InitCanBus();
-    CANReceiver();
-
-    byte priorityLow = 1;
-    time_t rtc = GetRtcInfoForEpoch();
-    while (CanFd) {
-        for (byte _index = 0; _index < gun_count; _index++) {
-            if (priorityLow == 1) {
-                // 優先權較低 - 只要有回應即不會再詢問
-                if (_chargingData[_index]->Type == _Type_Chademo &&
-                        ShmCHAdeMOData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS) {
-                    SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-                    GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-                } else if (_chargingData[_index]->Type == _Type_GB &&
-                           ShmGBTData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS) {
-                    SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-                    GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-                } else if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 &&
-                            ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].SelfTest_Comp != PASS) {
-                        SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-                        GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-                    }
-                }
-
-                // 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
-                //PRINTF_FUNC("GetMiscellaneousInfo. index = %d, Eid = %d \n", _index, _chargingData[_index]->Evboard_id);
-                GetMiscellaneousInfo(_index,
-                                     _chargingData[_index]->RelayK1K2Status,
-                                     _chargingData[_index]->PresentChargedEnergy,
-                                     (_chargingData[_index]->PresentChargingVoltage * 10),
-                                     _chargingData[_index]->Evboard_id);
-            }
-
-            switch (_chargingData[_index]->SystemStatus) {
-            case S_IDLE:
-            case S_RESERVATION:
-                if (_chargingData[_index]->Type == _Type_Chademo) {
-                    ClearAbnormalStatus_Chademo(_index);
-                } else if (_chargingData[_index]->Type == _Type_GB) {
-                    ClearAbnormalStatus_GB(_index);
-                } else if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    ClearAbnormalStatus_CCS(_index);
-                }
-
-                if (priorityLow == 1) {
-                    _chargingData[_index]->PresentChargedEnergy = 0;
-                    _chargingData[_index]->PresentChargingPower = 0;
-                    _chargingData[_index]->GroundFaultStatus = GFD_WAIT;
-                    _chargingData[_index]->RealRatingPower = 0;
-                    _chargingData[_index]->StopChargeFlag = NO;
-                    _chargingData[_index]->ChargingFee = 0.0;
-                    _chargingData[_index]->EvBatterySoc = 0;
-                    _chargingData[_index]->PresentChargingVoltage = 0;
-                    _chargingData[_index]->PresentChargingCurrent = 0;
-                    _chargingData[_index]->EvBatteryMaxVoltage = 0;
-
-                    chargingTime[_index] = 0;
-
-                    //maxChargingCur[_index] = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
-                    maxChargingPow = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
-                }
-                break;
-            case S_PREPARNING: {
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                _chargingData[_index]->PowerConsumption = 0;
-            }
-            break;
-            case S_PREPARING_FOR_EV: {
-                // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-//                  PRINTF_FUNC("PresentChargingVoltage = %f \n", _chargingData[_index]->PresentChargingVoltage);
-//                  PRINTF_FUNC("PresentChargingCurrent = %f \n", _chargingData[_index]->PresentChargingCurrent);
-//                  PRINTF_FUNC("AvailableChargingPower = %f \n", _chargingData[_index]->AvailableChargingPower);
-//                  PRINTF_FUNC("AvailableChargingCurrent = %f \n", _chargingData[_index]->AvailableChargingCurrent);
-//                  PRINTF_FUNC("MaximumChargingVoltage = %f \n", _chargingData[_index]->MaximumChargingVoltage);
-
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                if (priorityLow == 1) {
-                    float maxVol, maxCur;
-                    // 樁端輸出能力
-                    maxVol = _chargingData[_index]->MaximumChargingVoltage;
-                    maxCur = _chargingData[_index]->AvailableChargingCurrent;
-
-                    GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
-
-                    PRINTF_FUNC("To EV_%d Max_Vol = %f, Cap_Cur = %f, Cap_Pow = %f \n",
-                                _index, maxVol, maxCur, _chargingData[_index]->AvailableChargingPower);
-                    _chargingData[_index]->RealMaxVoltage = maxVol;
-
-                    SetChargingPermission(_index, START,
-                                          _chargingData[_index]->AvailableChargingPower,
-                                          maxCur,
-                                          maxVol,
-                                          _chargingData[_index]->Evboard_id);
-
-                    // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
-                    GetEvBatteryInfo(_index, _chargingData[_index]->Evboard_id);
-                }
-                gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
-            }
-            break;
-            case S_PREPARING_FOR_EVSE:
-            case S_CCS_PRECHARGE_ST0:
-            case S_CCS_PRECHARGE_ST1: {
-                // 開始確認車端是否同意開始充電
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                if (priorityLow % 5 == 1) {
-                    // 樁端輸出能力改變
-                    if (gun_count == 1) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
-                    } else if (gun_count == 2) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
-                    }
-                }
-                // 持續通知 Isolation 測試狀態
-                if (priorityLow == 1) {
-                    // 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
-//                      if (_chargingData[_index]->FireChargingVoltage >= 3500)
-//                          _chargingData[_index]->GroundFaultStatus = GFD_PASS;
-
-                    //PRINTF_FUNC("To EV_%d GFD = %d \n",   _index, _chargingData[_index]->GroundFaultStatus);
-                    //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
-                    {
-                        //if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
-                        unsigned char _result = _chargingData[_index]->GroundFaultStatus;
-
-                        // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
-                        if (_chargingData[_index]->Type == _Type_Chademo ||
-                                _chargingData[_index]->Type == _Type_GB) {
-                            if (_result == GFD_WARNING) {
-                                _result = GFD_PASS;
-                            }
-                        }
-
-                        if (_result == GFD_WARNING || _result == GFD_PASS) {
-                            if (((GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 12000 &&
-                                    _chargingData[_index]->RealRatingPower > 0) ||
-                                    (GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 14000) {
-                                PRINTF_FUNC("**********EvComm : _index= %d, RealRatingPower = %d \n",
-                                            _index, _chargingData[_index]->RealRatingPower);
-                                //_result = GFD_PASS;
-                            } else {
-                                _result = GFD_WAIT;
-                            }
-                        }
-
-                        SetIsolationStatus(_index, _result, _chargingData[_index]->Evboard_id);
-                    }
-
-                    if (_chargingData[_index]->SystemStatus == S_CCS_PRECHARGE_ST0 &&
-                            _chargingData[_index]->PrechargeStatus == PRECHARGE_READY) {
-                        SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, _chargingData[_index]->Evboard_id);
-                    }
-                }
-            }
-            break;
-            case S_CHARGING: {
-                // 計算 Power
-                _chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
-
-                if (chargingTime[_index] == 0 ||
-                        chargingTime[_index] > _chargingData[_index]->PresentChargedDuration) {
-                    chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-                } else {
-                    int passTime = _chargingData[_index]->PresentChargedDuration - chargingTime[_index];
-
-                    if (passTime > 0) {
-                        float changingPow = (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            _chargingData[_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
-                        }
-
-                        _chargingData[_index]->PresentChargedEnergy += changingPow;
-                        _chargingData[_index]->PowerConsumption += changingPow;
-                        chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-                    }
-                }
-
-                // 開始確認車端是否同意開始充電
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                // for test end
-                if (priorityLow % 5 == 0) {
-                    // 樁端輸出能力改變
-                    if (gun_count == 1) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
-                    } else if (gun_count == 2) {
-                        SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
-                    }
-                }
-
-                if (_chargingData[_index]->GroundFaultStatus == GFD_FAIL) {
-                    SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
-                } else if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
-                }
-
-                // GFD 失敗再通知
-                if (priorityLow == 1) {
-                    if (_chargingData[_index]->Type == _Type_CCS_2 &&
-                            _chargingData[_index]->PrechargeStatus == PRECHARGE_READY) {
-                        SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, _chargingData[_index]->Evboard_id);
-                    }
-                }
-            }
-            break;
-            case S_TERMINATING: {
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                // 槍鎖還在,則代表是樁端要求的停止
-                if (_chargingData[_index]->GunLocked == START ||
-                        _chargingData[_index]->Type == _Type_CCS_2) {
-                    byte normalStop = 0x01;
-                    byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
-                    if (GetStopChargingReasonByEvse(_index, stopReason)) {
-                        normalStop = 0x02;
-                    }
-
-                    EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);
-                }
-
-                if (_chargingData[_index]->Type == _Type_CCS_2) {
-                    SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
-                }
-
-                GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-            }
-            break;
-            case S_COMPLETE: {
-                // 設定當前輸出
-                if (gun_count == 1) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-                } else if (gun_count == 2) {
-                    SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-                }
-
-                if (priorityLow == 1) {
-                    float maxVol, maxCur;
-
-                    // 樁端輸出能力
-                    maxVol = _chargingData[_index]->MaximumChargingVoltage;
-                    maxCur = _chargingData[_index]->AvailableChargingCurrent;
-
-                    GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
-                    SetChargingPermission(_index, STOP,
-                                          _chargingData[_index]->AvailableChargingPower,
-                                          maxCur,
-                                          maxVol,
-                                          _chargingData[_index]->Evboard_id);
-                }
-            }
-            break;
-            }
-        }
-        priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
-        usleep(45000); //EV 小板通訊 (50 ms)
-    }
-    DEBUG_INFO("Module_EvComm : Can-bus port = %d \n", CanFd);
-    return FAIL;
-}

+ 0 - 88
EVSE/Projects/DD360Audi/Apps/Module_EvComm.h

@@ -1,88 +0,0 @@
-#ifndef MODULE_EVCOMM_H_
-#define MODULE_EVCOMM_H_
-
-#include    <stdbool.h>
-
-int CanFd;
-
-typedef unsigned char       byte;
-
-extern struct Ev_Board_Cmd {
-    int none;                           // 0
-    int address_assignment;             // 0x00000200
-    int get_firmware_ver;               // 0x00000400
-    int get_hardware_ver;               // 0x00000500
-    int charging_permission;            // 0x00000600
-    int present_output_power;           // 0x00000700
-    int present_output_cap;             // 0x00000800
-    int get_output_req;                 // 0x00000900
-    int get_battery_info;               // 0x00000A00
-    int evse_stop_charging;             // 0x00000C00
-    int get_miscellaneous_info;         // 0x00000D00
-
-    int download_req;                   // 0x00000E00
-    int start_block_transfer;           // 0x00000F00
-    int data_transfer;                  // 0x00001000
-    int download_finish;                // 0x00001100
-
-    int isolation_status;               // 0x00001200
-    int sync_rtc_info;                  // 0x00001400
-    int evse_precharge_info;            // 0x00001500
-} Ev_Cmd;
-
-extern struct Ev_Cmd_Dir {
-    unsigned short master_to_slave;
-    unsigned short slave_to_master;
-} Ev_Dir;
-
-struct timeval _id_assign_time;
-
-// Send msg to can-bus
-void SetTargetAddr(byte *target_number, byte index);
-
-void GetFirmwareVersion(byte gun_index, byte toId);
-void SyncRtcInfo(byte gun_index, byte toId, int epoch);
-void GetHardwareVersion(byte gun_index, byte toId);
-void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputVol, short aOutputCur, byte toId);
-void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2);
-void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2);
-void GetOutputReq(byte gun_index, byte toId);
-void GetEvBatteryInfo(byte gun_index, byte toId);
-void GetMiscellaneousInfo(byte gun_index, byte relayStatus, float power, float voltage, byte toId);
-void SetIsolationStatus(byte gun_index, byte result, byte toId);
-void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId);
-// 發送電樁主動停止充電結果及原因
-void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId);
-
-// Receive msg From can-bus.
-
-enum Receieve_PSU_msgf {
-    // 車端主動
-    ADDRESS_REQ =                       0x080001FF,
-    NOTIFICATION_EV_STATUS =            0x08000300,
-    NOTIFICATION_EV_STOP =              0x08000B00,
-
-    // 車端回應
-    ACK_EV_FW_VERSION =                 0x08000400,
-    ACK_EV_HW_VERSION =                 0x08000500,
-    ACK_GET_OUTPUT_REQ =                0x08000900,
-    ACK_GET_EV_BATTERY_INFO =           0x08000A00,
-    ACK_GET_MISCELLANEOUS_INFO =        0x08000D00,
-    ACK_EVSE_ISOLATION_STATUS =         0x08001200,
-    ACK_EVSE_PRECHAGE_INFO =            0x08001500,
-};
-
-//DS60-120 add
-enum EV_LOG_INDEX {
-    EV_LOG_OUTPUT_CAP_POW = 0,
-    EV_LOG_OUTPUT_CAP_CUR = 1,
-    EV_LOG_NOW_OUTPUT_VOL = 2,
-    EV_LOG_NOW_OUTPUT_CUR = 3,
-    EV_LOG_EVSE_MAX_VOL =   4,
-    EV_LOG_EVSE_MAX_CUR =   5,
-    EV_LOG_MAX_BATT_VOL =   6,
-    EV_LOG_REAL_CAP_POW =   7,
-    EV_LOG_SOC =            8
-};
-#endif /* MODULE_EVCOMM_H_ */
-

+ 0 - 324
EVSE/Projects/DD360Audi/Apps/Module_EventLogging.c

@@ -1,324 +0,0 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include	"../../define.h"
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-int StoreLogMsg(const char *fmt, ...)
-{
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-	//return milli-second
-	unsigned int StartTime,StopTime;
-
-	StartTime=(unsigned int)ST.time;
-	StopTime=(unsigned int)ET.time;
-	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-	va_list args;
-	char buffer[4096];
-	va_start(args, string);
-	vsnprintf(buffer, sizeof(buffer), string, args);
-	va_end(args);
-
-	DEBUG_INFO("%s \n", buffer);
-}
-
-//=================================
-// Common routine
-//=================================
-char* getTimeString(void)
-{
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
-
-	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-
-	return result;
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-	int result = PASS;
-	int MeterSMId;
-
-	//creat ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
-    {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
-		result = FAIL;
-	}
-    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	#ifdef SystemLogMessage
-    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-		#endif
-    	result = FAIL;
-   	 }
-    else
-    {}
-
-   	 //creat ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
-    {
-		#ifdef SystemLogMessage
-   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
-   		result = FAIL;
-	}
-    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	#ifdef SystemLogMessage
-    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-		#endif
-    	result = FAIL;
-   	}
-    else
-    {}
-
-    return result;
-}
-
-//================================================
-// Main process
-//================================================
-void AddFaultCodeToBuf(unsigned char *Code)
-{
-	if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10)
-	{
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
-		ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
-	}
-}
-
-void RemoveFaultCodeToBuf(unsigned char *Code)
-{
-	unsigned char find = 0x01;
-	char _code[7];
-	sprintf(_code,"%s", Code);
-
-	// 把相關的錯誤碼一次移除,避免重複顯示
-	while(find)
-	{
-		find = 0x00;
-		for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-		{
-			if (find == 0x00)
-			{
-				if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0)
-				{
-					find = 0x01;
-				}
-			}
-			else
-			{
-				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-					&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
-			}
-		}
-
-		if (find)
-		{
-			ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
-		}
-	}
-}
-
-int main(void)
-{
-	int ByteCount,BitCount;
-	unsigned char tmp, EventCodeTmp[7];
-
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	for(;;)
-	{
-		//check Fault Status
-		for(ByteCount=0;ByteCount<sizeof(ShmStatusCodeData->FaultCode.PreviousFaultVal);ByteCount++)
-		{
-			if(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,FaultStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
-
-		//check Alarm Status
-		for(ByteCount=0;ByteCount<sizeof(ShmStatusCodeData->AlarmCode.PreviousAlarmVal);ByteCount++)
-		{
-			if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
-
-		//check Info Status
-		for(ByteCount=0;ByteCount<sizeof(ShmStatusCodeData->InfoCode.PreviousInfoVal);ByteCount++)
-		{
-			if(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,InfoStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
-		usleep(500000);
-	}
-
-	return FAIL;
-}

+ 0 - 2409
EVSE/Projects/DD360Audi/Apps/Module_InternalComm.c

@@ -1,2409 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "../../define.h"
-#include    "internalComm.h"
-#include    <stdbool.h>
-
-#define AudiCustomized              1
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-#define TEN_MINUTES         600
-#define ENV_TEMP_MIN        45
-#define ENV_TEMP_MAX        50
-#define DEFAULT_AC_INDEX    2
-#define EQUAL               0
-#define COLOR_MAX_LV        100
-#define COLOR_MIN_LV        0
-
-#define AC_DEFAULT_VOL      220
-
-#define NO_DEFINE           255
-#define NDEFAULT_AC_INDEX   2
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct FanModuleData            *ShmFanModuleData;
-struct RelayModuleData          *ShmRelayModuleData;
-struct LedModuleData            *ShmLedModuleData;
-struct PsuData                  *ShmPsuData;
-struct OCPP16Data               *ShmOCPP16Data;
-
-#define VIN_MAX_VOLTAGE_IEC     285 // 大於該值 : OVP
-#define VIN_MIN_VOLTAGE_IEC     160 // 小於該值 : UVP
-#define VIN_MAX_VOLTAGE_UL      315 // 大於該值 : OVP // 美規 (W)
-#define VIN_MIN_VOLTAGE_UL      210 // 小於該值 : UVP
-
-#define VIN_DROP_VOLTAGE    150 // 小於該值 : ac drop
-
-#define VOUT_MAX_VOLTAGE    995
-#define VOUT_MIN_VOLTAGE    150
-#define IOUT_MAX_CURRENT    50
-
-#define MAX_FAN_SPEED       14000
-#define MIN_FAN_SPEED       3000
-#define NORMAL_FAN_SPEED    7000
-
-// GFD Status
-#define GFD_IDLE            0
-#define GFD_CABLECHK        1
-#define GFD_PRECHARGE       2
-#define GFD_CHARGING        3
-
-// LED Intensity (rate)
-#define LED_INTENSITY_DARKEST       0.2
-#define LED_INTENSITY_MEDIUM        0.6
-#define LED_INTENSITY_BRIGHTEST     1
-
-// EE Spec
-#define LED_BRIGHTNESS_LV_HIGH      1
-#define LED_BRIGHTNESS_LV_MID       0.5
-#define LED_BRIGHTNESS_LV_LOW       0.2
-
-// 最小切換 Relay 電壓
-#define SELF_TO_CHANGE_RELAY_STATUS         600
-// 透過電壓確認 Relay 是否搭上的依據電壓
-#define CHECK_RELAY_STATUS                  300
-#define CHECK_RELAY_STATUS_GAP              100
-// 安全在停止充電程序中斷開 Relay 的電流
-#define SEFETY_SWITCH_RELAY_CUR             20
-// 確認 Relay Welding 電壓
-#define RELAY_WELDING_DET                   300
-
-byte gunCount;
-byte acgunCount;
-// 槍資訊
-struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
-
-bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
-
-int Uart5Fd;
-char *relayRs485PortName = "/dev/ttyS5";
-unsigned short fanSpeedSmoothValue = 500;
-
-bool isStopChargingCount = false;
-struct timeval _close_ac_contactor;
-
-struct timeval _priority_time;
-struct timeval _led_priority_time;
-
-struct timeval  _ac_charging_comp;
-struct timeval  _ac_preparing;
-struct timeb    _ac_startChargingTime;
-struct timeb    _ac_endChargingTime;
-
-unsigned short _setFanSpeed = 0;
-float _beforeChargingTotalEnergy = 0.0;
-byte _checkLedChanged = 3;
-
-Ver ver;
-PresentInputVoltage inputVoltage;
-PresentOutputVoltage outputVoltage;
-FanSpeed fanSpeed;
-Temperature temperature;
-AuxPower auxPower;
-Gfd gfd_adc;
-Gfd_config gfd_config;
-Gpio_in gpio_in;
-Gpio_out gpio_out;
-Relay outputRelay;
-Relay regRelay;
-Rtc rtc;
-Led_Color cur_led_color;
-Led_Color led_color;
-
-Ac_Status acStatus;
-Ac_Led_Status ledStatus;
-Ac_Alarm_code acAlarmCode;
-Ac_Charging_energy acChargingEnergy;
-Ac_Charging_current acChargingCurrent;
-
-#define AC_OVP                      1
-#define AC_UVP                      2
-#define AC_OCP                      4
-#define AC_OTP                      8
-#define AC_GMI_FAULT                16
-#define AC_CP_ERROR                 32
-#define AC_AC_LEAKAGE               64
-#define AC_DC_LEAKAGE               128
-#define AC_SYSTEM_SELFTEST_FAULT    256
-#define AC_HANDSHAKE_TIMEOUT        512
-#define AC_EMC_STOP                 1024
-#define AC_RELAY_WELDING            2048
-#define AC_GF_MODULE_FAULT          4096
-#define AC_SHUTTER_FAULT            8192
-#define AC_LOCKER_FAULT             16384
-#define AC_POWER_DROP               32768
-#define AC_CIRCUIT_SHORT            65536
-#define AC_ROTARY_SWITCH_FAULT      131072
-#define AC_RELAY_DRIVE_FAULT        262144
-
-int _alarm_code[] = {AC_OVP, AC_UVP, AC_OCP, AC_OTP, AC_GMI_FAULT, AC_CP_ERROR, AC_AC_LEAKAGE
-                     , AC_DC_LEAKAGE, AC_SYSTEM_SELFTEST_FAULT, AC_HANDSHAKE_TIMEOUT, AC_EMC_STOP, AC_RELAY_WELDING
-                     , AC_GF_MODULE_FAULT, AC_SHUTTER_FAULT, AC_LOCKER_FAULT, AC_POWER_DROP, AC_CIRCUIT_SHORT
-                     , AC_ROTARY_SWITCH_FAULT, AC_RELAY_DRIVE_FAULT
-                    };
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int) ST.time;
-    StopTime = (unsigned int) ET.time;
-    //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-    return (StopTime - StartTime);
-}
-
-unsigned short MaxValue(unsigned short value1, unsigned short value2)
-{
-    return value1 >= value2 ? value1 : value2;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
-//==========================================
-// Communication Function
-//==========================================
-void GetFwAndHwVersion_Fan()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
-        // FanModuleData
-        strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
-    }
-
-    if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS) {
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
-    }
-}
-
-void GetFwAndHwVersion_Relay()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
-        // RelayModuleData
-        strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
-    }
-
-    if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS) {
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
-    }
-}
-
-void GetFwAndHwVersion_Led()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS) {
-        // LedModuleData
-        strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
-        // SystemInfo
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, ver.Version_FW);
-        //PRINTF_FUNC("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
-        //ShmLedModuleData->SelfTest_Comp = YES;
-    } else {
-        //PRINTF_FUNC("GetFwAndHwVersion_Led fail \n");
-    }
-
-//  if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
-//  {
-//      // SystemInfo
-//      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
-//      //PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
-//  }
-}
-
-void GetFwVersion_AC()
-{
-    if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS) {
-        ac_chargingInfo[0]->SelfTest_Comp = YES;
-        strcpy((char *) ac_chargingInfo[0]->version, ver.Version_FW);
-    }
-}
-
-void GetAcModelName()
-{
-    memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
-    if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
-        PRINTF_FUNC("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
-    }
-}
-
-void SetRtcData_Relay()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-    //  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-    //          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-    //          tmCSU->tm_sec);
-
-    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-    if (Config_Rtc_Data(Uart5Fd, Addr.Relay, &rtc) == PASS) {
-        //PRINTF_FUNC("SetRtc (RB) sucessfully. \n");
-    }
-}
-
-void SetRtcData_Fan()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-    //  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-    //          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-    //          tmCSU->tm_sec);
-
-    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-    if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS) {
-        //PRINTF_FUNC("SetRtc (FB) sucessfully. \n");
-    }
-}
-
-void SetModelName_Fan()
-{
-    if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-        PRINTF_FUNC("Set Model name PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
-    }
-}
-
-// AC 三相輸入電壓
-void GetPresentInputVol()
-{
-    if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS) {
-        // resolution : 0.1
-        ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
-        ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
-        ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
-
-        //********************************************************************************************************//
-#ifndef DD360
-        // Vin (UVP)
-        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
-            if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
-            }
-        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
-            if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
-                PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
-                PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
-                PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
-            }
-        }
-        //********************************************************************************************************//
-        // Vin (OVP)
-        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
-            if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
-                PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
-            }
-        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
-            if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
-                PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
-            }
-
-            if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
-                PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
-            }
-
-            if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
-                PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
-            } else {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
-            }
-        }
-#endif
-    }
-}
-
-// 左右槍的 Relay 前後的輸出電壓
-void GetPersentOutputVol()
-{
-    if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS) {
-//      PRINTF_FUNC("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-//      PRINTF_FUNC("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
-//      PRINTF_FUNC("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
-//      PRINTF_FUNC("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
-
-        //PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
-        //PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
-
-        ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
-        ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
-        ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
-        ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
-
-        for (int index = 0; index < gunCount; index++) {
-            if (index == 0) {
-                if (_chargingData[index]->Evboard_id == 0x01) {
-#ifndef DD360
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun1FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
-
-                } else if (_chargingData[index]->Evboard_id == 0x02) {
-#ifndef DD360
-                    _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                    _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                    _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                    _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif
-                    _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-                }
-            } else if (index == 1) {
-#ifndef DD360
-                _chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
-#else
-                _chargingData[index]->PresentChargingCurrent = ShmRelayModuleData->Gun2FuseOutputVolt / 10;
-                _chargingData[index]->PresentChargingVoltage = _chargingData[index]->FireChargingVoltage / 10;
-                _chargingData[index]->FuseChargingVoltage = _chargingData[index]->FireChargingVoltage;
-#endif
-                _chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
-            }
-
-            //unsigned short Ovp = 0;
-            //unsigned short Ocp = 0;
-            //Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE]  // 最大輸出電壓與電池電壓最大值
-            //Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]      // 最大輸出電流與需求電流最小值
-            if (_chargingData[index]->Type == _Type_Chademo) {
-                //Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
-                //Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
-            } else if (_chargingData[index]->Type == _Type_CCS_2) {
-
-            }
-        }
-    }
-}
-
-// 風扇速度
-void GetFanSpeed()
-{
-    //PRINTF_FUNC("Get fan board speed \n");
-    if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS) {
-        ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
-        ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
-        ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
-        ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
-//      PRINTF_FUNC("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
-//      PRINTF_FUNC("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
-//      PRINTF_FUNC("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
-//      PRINTF_FUNC("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
-        // Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
-        //SysInfoData (SystemFanRotaSpeed)
-    }
-}
-
-// 讀取 Relay 狀態
-void GetRelayOutputStatus()
-{
-    if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS) {
-#ifndef DD360
-        regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-#endif
-    }
-}
-
-// 確認 K1 K2 relay 的狀態
-void CheckK1K2RelayOutput(byte index)
-{
-    if (index == 0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-            if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES) {
-                _chargingData[index]->RelayK1K2Status = YES;
-            } else {
-                _chargingData[index]->RelayK1K2Status = NO;
-            }
-
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (gunCount == 1) {
-#ifndef DD360
-                    if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
-                        _chargingData[index]->RelayKPK2Status = YES;
-                    } else {
-                        _chargingData[index]->RelayKPK2Status = NO;
-                    }
-#else
-                    if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                        _chargingData[index]->RelayKPK2Status = YES;
-                    } else {
-                        _chargingData[index]->RelayKPK2Status = NO;
-                    }
-#endif
-                } else {
-                    if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                        _chargingData[index]->RelayKPK2Status = YES;
-                    } else {
-                        _chargingData[index]->RelayKPK2Status = NO;
-                    }
-                }
-            }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-            if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES) {
-                _chargingData[index]->RelayK1K2Status = YES;
-            } else {
-                _chargingData[index]->RelayK1K2Status = NO;
-            }
-
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-#ifndef DD360
-                if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    _chargingData[index]->RelayKPK2Status = YES;
-                } else {
-                    _chargingData[index]->RelayKPK2Status = NO;
-                }
-#else
-                if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                    _chargingData[index]->RelayKPK2Status = YES;
-                } else {
-                    _chargingData[index]->RelayKPK2Status = NO;
-                }
-#endif
-            }
-        }
-    } else if (index == 1) {
-        if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES) {
-            _chargingData[index]->RelayK1K2Status = YES;
-        } else {
-            _chargingData[index]->RelayK1K2Status = NO;
-        }
-
-        if (_chargingData[index]->Type == _Type_CCS_2) {
-#ifndef DD360
-            if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
-                _chargingData[index]->RelayKPK2Status = YES;
-            } else {
-                _chargingData[index]->RelayKPK2Status = NO;
-            }
-#else
-            if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-                _chargingData[index]->RelayKPK2Status = YES;
-            } else {
-                _chargingData[index]->RelayKPK2Status = NO;
-            }
-#endif
-        }
-    }
-
-    /*if (regRelay.relay_event.bits.Gun1_Parallel_N == YES && regRelay.relay_event.bits.Gun1_Parallel_P == YES)
-        ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
-    else
-        ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;*/
-    ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
-
-//  PRINTF_FUNC("Check Relay Output. index = %d, RelayKPK2Status = %d, BridgeRelayStatus = %d \n",
-//          index, _chargingData[index]->RelayKPK2Status, ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus);
-}
-
-void GetGfdAdc()
-{
-    // define : 每 0.2 ~ 1 秒一次
-    // occur : <= 75k 歐姆 @ 150 - 750 Vdc
-    // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
-    if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS) {
-        for (int i = 0; i < gunCount; i++) {
-            if (_chargingData[i]->Type == 0x09 && !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag) {
-                if ((_chargingData[i]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE) {
-                    _chargingData[i]->GroundFaultStatus = GFD_PASS;
-                }
-                continue;
-            }
-
-            if (i == 0) {
-                if (gfd_adc.result_conn1 == GFD_WARNING) {
-                    gfd_adc.result_conn1 = GFD_PASS;
-                }
-                _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn1;
-//              PRINTF_FUNC("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
-//                      _chargingData[i]->GroundFaultStatus, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                if (_chargingData[i]->GroundFaultStatus == GFD_FAIL) {
-                    PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
-                                i, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                } else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
-                           _chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                    if (_chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                        PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
-                                    i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                    }
-                }
-            } else if (i == 1) {
-                if (gfd_adc.result_conn2 == GFD_WARNING) {
-                    gfd_adc.result_conn2 = GFD_PASS;
-                }
-                _chargingData[i]->GroundFaultStatus = gfd_adc.result_conn2;
-                if (_chargingData[i]->GroundFaultStatus == GFD_FAIL) {
-                    PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
-                                i, gfd_adc.rb_step_2, gfd_adc.Resister_conn2, gfd_adc.voltage_conn2);
-                } else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
-                           _chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                    if (_chargingData[i]->GroundFaultStatus == GFD_WARNING) {
-                        PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
-                                    i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
-                    }
-                }
-            }
-        }
-    }
-}
-
-void GetGpioInput()
-{
-    if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS) {
-        // AC Contactor Status
-        if (gpio_in.AC_MainBreaker == 1) {
-            // AC Main Breaker ON
-            PRINTF_FUNC("RB AC Main Breaker. \n");
-        }
-
-        if (gpio_in.SPD == 1) {
-            // SPD (雷擊保護) ON
-            PRINTF_FUNC("RB SPD. \n");
-        }
-
-        if (gpio_in.Door_Open == 1) {
-            // Door Open
-            PRINTF_FUNC("RB Door Open. \n");
-        }
-
-        if (gpio_in.GFD[0] == 1) {
-            // GFD_1 Trigger
-        }
-
-        if (gpio_in.GFD[1] == 1) {
-            // GFD_2 Trigger
-        }
-
-        if (gpio_in.AC_Drop == 1) {
-            // AC Drop
-            PRINTF_FUNC("RB AC Drop. \n");
-        }
-
-        if (gpio_in.Emergency_IO == 1) {
-            // Emergency IO ON
-            PRINTF_FUNC("RB Emergency IO ON. \n");
-        }
-
-        if (gpio_in.Button_Emergency_Press == 1) {
-            // Emergency button Press
-        }
-
-        if (gpio_in.Button_On_Press == 1) {
-            // On button Press
-        }
-
-        if (gpio_in.Button_Off_Press == 1) {
-            // Off button Press
-        }
-
-        if (gpio_in.Key_1_Press == 1) {
-            // key 1 press
-        }
-
-        if (gpio_in.Key_2_Press == 1) {
-            // key 2 press
-        }
-
-        if (gpio_in.Key_3_Press == 1) {
-            // key 3 press
-        }
-
-        if (gpio_in.Key_4_Press == 1) {
-            // key 4 press
-        }
-    }
-}
-
-// 5V 12V 24V 48V
-void GetAuxPower()
-{
-    if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS) {
-        ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
-        ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
-        //ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
-        //ShmSysConfigAndInfo->SysInfo.AuxPower5V = auxPower.voltage[6];
-        // aux power voltage
-        //PRINTF_FUNC("aux1 = %x, \n", auxPower.voltage[0]);
-        //PRINTF_FUNC("aux2 = %x, \n", auxPower.voltage[1]);
-    }
-}
-
-void SetFanModuleSpeed()
-{
-    {
-        FanSpeed _fanSpeed;
-
-        _setFanSpeed += fanSpeedSmoothValue;
-
-        if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed) {
-            _setFanSpeed = ShmFanModuleData->SetFan1Speed;
-        }
-
-        //printf("_setFanSpeed = %d \n", _setFanSpeed);
-        _fanSpeed.speed[0] = _setFanSpeed;
-
-        _fanSpeed.speed[1] = _setFanSpeed;
-
-        _fanSpeed.speed[2] = _setFanSpeed;
-
-        _fanSpeed.speed[3] = _setFanSpeed;
-
-        if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS) {
-            //PRINTF_FUNC("successfully Fan\n");
-        }
-    }
-}
-
-//==========================================
-// Common Function
-//==========================================
-void SetK1K2RelayStatus(byte index)
-{
-    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) {
-            outputRelay.relay_event.bits.Gun1_P = YES;
-        }
-        return;
-    }
-
-    if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-            if (regRelay.relay_event.bits.Gun1_P == YES) {
-                outputRelay.relay_event.bits.Gun1_P = NO;
-            } else if (regRelay.relay_event.bits.Gun1_N == YES) {
-                outputRelay.relay_event.bits.Gun1_N = NO;
-            }
-
-            if (gunCount == 1 && _chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    outputRelay.relay_event.bits.CCS_Precharge = NO;
-                }
-            }
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-            if (regRelay.relay_event.bits.Gun2_P == YES) {
-                outputRelay.relay_event.bits.Gun2_P = NO;
-            } else if (regRelay.relay_event.bits.Gun2_N == YES) {
-                outputRelay.relay_event.bits.Gun2_N = NO;
-            }
-
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    outputRelay.relay_event.bits.CCS_Precharge = NO;
-                }
-            }
-        }
-    } else if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                _chargingData[index]->SystemStatus <= S_CHARGING)) {
-        if (_chargingData[index]->RelayWeldingCheck == YES) {
-            if (_chargingData[index]->Evboard_id == 0x01) {
-                if (regRelay.relay_event.bits.Gun1_N == NO) {
-                    outputRelay.relay_event.bits.Gun1_N = YES;
-                } else if (regRelay.relay_event.bits.Gun1_P == NO) {
-                    outputRelay.relay_event.bits.Gun1_P = YES;
-                }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
-                if (regRelay.relay_event.bits.Gun2_N == NO) {
-                    outputRelay.relay_event.bits.Gun2_N = YES;
-                } else if (regRelay.relay_event.bits.Gun2_P == NO) {
-                    outputRelay.relay_event.bits.Gun2_P = YES;
-                }
-            }
-        }
-    } else if ((_chargingData[index]->SystemStatus >= S_TERMINATING &&
-                _chargingData[index]->SystemStatus <= S_COMPLETE)) {
-        if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
-            if (_chargingData[index]->Evboard_id == 0x01) {
-                if (regRelay.relay_event.bits.Gun1_P == YES) {
-                    outputRelay.relay_event.bits.Gun1_P = NO;
-                } else if (regRelay.relay_event.bits.Gun1_N == YES) {
-                    outputRelay.relay_event.bits.Gun1_N = NO;
-                }
-            } else if (_chargingData[index]->Evboard_id == 0x02) {
-                if (regRelay.relay_event.bits.Gun2_P == YES) {
-                    outputRelay.relay_event.bits.Gun2_P = NO;
-                } else if (regRelay.relay_event.bits.Gun2_N == YES) {
-                    outputRelay.relay_event.bits.Gun2_N = NO;
-                }
-            }
-        }
-    } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (gunCount == 1) {
-                    if (regRelay.relay_event.bits.CCS_Precharge == NO) {
-                        outputRelay.relay_event.bits.CCS_Precharge = YES;
-                    } else if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                        outputRelay.relay_event.bits.Gun1_P = NO;
-                    }
-                }
-            }
-#endif
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.CCS_Precharge == NO) {
-                    outputRelay.relay_event.bits.CCS_Precharge = YES;
-                } else if (regRelay.relay_event.bits.CCS_Precharge == YES) {
-                    outputRelay.relay_event.bits.Gun2_P = NO;
-                }
-            }
-#endif
-        }
-    } else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1) {
-        if (_chargingData[index]->Evboard_id == 0x01) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (gunCount == 1) {
-                    if (regRelay.relay_event.bits.Gun1_P == NO) {
-                        outputRelay.relay_event.bits.Gun1_P = YES;
-                    } else if (regRelay.relay_event.bits.Gun1_P == YES) {
-                        outputRelay.relay_event.bits.CCS_Precharge = NO;
-                    }
-                }
-            }
-#endif
-        } else if (_chargingData[index]->Evboard_id == 0x02) {
-#ifndef DD360
-            if (_chargingData[index]->Type == _Type_CCS_2) {
-                if (regRelay.relay_event.bits.Gun2_P == NO) {
-                    outputRelay.relay_event.bits.Gun2_P = YES;
-                } else if (regRelay.relay_event.bits.Gun2_P == YES) {
-                    outputRelay.relay_event.bits.CCS_Precharge = NO;
-                }
-            }
-#endif
-        }
-    }
-}
-
-void CheckAcInputOvpStatus(byte index)
-{
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
-//      if ((_chargingData[index]->SystemStatus >= S_PREPARNING && _chargingData[index]->SystemStatus <= S_CHARGING) ||
-//              (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-//      {
-//          if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
-//          {
-//              if (_psuInputVolR > VIN_MAX_VOLTAGE_IEC ||
-//                      _psuInputVolS > VIN_MAX_VOLTAGE_IEC ||
-//                      _psuInputVolT > VIN_MAX_VOLTAGE_IEC)
-//              {
-//                  PRINTF_FUNC("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
-//                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
-//              }
-//
-//          }
-//          else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
-//          {
-//              if (_psuInputVolR > VIN_MAX_VOLTAGE_UL ||
-//                      _psuInputVolS > VIN_MAX_VOLTAGE_UL ||
-//                      _psuInputVolT > VIN_MAX_VOLTAGE_UL)
-//              {
-//                  PRINTF_FUNC("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
-//                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
-//              }
-//          }
-//      }
-//      else
-        DEBUG_INFO("CheckAcInputOvpStatus\r\n");
-        _chargingData[index]->StopChargeFlag = YES;
-    }
-}
-
-void CheckPhaseLossStatus(byte index)
-{
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
-        DEBUG_INFO("CheckPhaseLossStatus\r\n");
-        _chargingData[index]->StopChargeFlag = YES;
-    }
-}
-
-void SetParalleRelayStatus()
-{
-    // 之後雙槍單模機種,橋接都會上
-    if (gunCount >= 2) {
-        if (_chargingData[0]->SystemStatus == S_BOOTING || _chargingData[1]->SystemStatus == S_BOOTING ||
-                (_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)) {
-            // 初始化~ 不搭橋接
-            if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
-                outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
-            } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
-                outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
-            }
-        } else {
-            if (_chargingData[0]->IsReadyToCharging == YES ||
-                    _chargingData[1]->IsReadyToCharging == YES) {
-                // ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
-                if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
-                    if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A) {
-                        // 最大充 - 搭上橋接
-                        if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
-                        }
-                    } else {
-                        // 平均充 - 不搭
-                        if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
-                        }
-                    }
-                } else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-                    if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M) {
-                        // 平均充 - 不搭
-                        if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
-                        }
-                    } else {
-                        // 最大充 - 搭上橋接
-                        if (regRelay.relay_event.bits.Gun1_Parallel_N == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
-                        } else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
-                            outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
-                        }
-                    }
-                }
-            }
-        }
-    }
-}
-
-void CheckAlarmOccur()
-{
-    bool isErr = false;
-    for (byte count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
-        if (acAlarmCode.AcAlarmCode & _alarm_code[count]) {
-            isErr = true;
-            switch (_alarm_code[count]) {
-            case AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = YES; break;
-            case AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = YES; break;
-            case AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = YES; break;
-            case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = YES; break;
-            case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = YES; break;
-            case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = YES; break;
-            case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
-            case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
-            case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = YES; break;
-            case AC_HANDSHAKE_TIMEOUT: break;
-            //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES; break;
-            case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = YES; break;
-            case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = YES; break;
-            case AC_SHUTTER_FAULT: break;
-            case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = YES; break;
-            case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = YES; break;
-            case AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = YES; break;
-            case AC_ROTARY_SWITCH_FAULT: break;
-            case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = YES; break;
-            }
-        } else {
-            switch (_alarm_code[count]) {
-            case AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = NO; break;
-            case AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = NO; break;
-            case AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = NO; break;
-            case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = NO; break;
-            case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = NO; break;
-            case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = NO; break;
-            case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
-            case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO; break;
-            case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = NO; break;
-            case AC_HANDSHAKE_TIMEOUT: break;
-            //case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO; break;
-            case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = NO; break;
-            case AC_GF_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = NO; break;
-            case AC_SHUTTER_FAULT: break;
-            case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = NO; break;
-            case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = NO; break;
-            case AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = NO; break;
-            case AC_ROTARY_SWITCH_FAULT:  break;
-            case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = NO; break;
-            }
-        }
-    }
-
-    ac_chargingInfo[0]->IsErrorOccur = isErr;
-}
-
-bool IsNoneMatchLedColor()
-{
-    bool result = false;
-
-    if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
-            cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
-            cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
-            cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
-            cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
-            cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue) {
-        result = true;
-    }
-
-    return result;
-}
-
-void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-    byte _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
-
-    if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
-        _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
-    } else if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
-        _colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
-    }
-
-    //printf("chargingData_1->SystemStatus=%d\n",chargingData_1->SystemStatus);
-    //printf("chargingData_2->SystemStatus=%d\n",chargingData_2->SystemStatus);
-    //printf("ShmSysConfigAndInfo->SysWarningInfo.Level=%d\n",ShmSysConfigAndInfo->SysWarningInfo.Level);
-    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-        led_color.Connect_1_Green = COLOR_MIN_LV;
-        led_color.Connect_1_Blue = COLOR_MIN_LV;
-        led_color.Connect_1_Red = _colorBuf;
-        led_color.Connect_2_Green = COLOR_MIN_LV;
-        led_color.Connect_2_Blue = COLOR_MIN_LV;
-        led_color.Connect_2_Red = _colorBuf;
-    } else {
-        if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
-            if ((chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION) &&
-                    (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION)) {
-#ifdef AudiCustomized
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = _colorBuf;
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = _colorBuf;
-#else
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = COLOR_MIN_LV;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = COLOR_MIN_LV;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-#endif
-            } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                       (chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                led_color.Connect_1_Green = COLOR_MIN_LV;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-                led_color.Connect_2_Green = COLOR_MIN_LV;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-            }
-        } else {
-            if (chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION) {
-#ifdef AudiCustomized
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = _colorBuf;
-#else
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = COLOR_MIN_LV;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-#endif
-            } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                led_color.Connect_1_Green = COLOR_MIN_LV;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-            }
-
-            // --------------------------------------------------------------------------
-            if (chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION) {
-#ifdef AudiCustomized
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = _colorBuf;
-#else
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = COLOR_MIN_LV;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-#endif
-            } else if ((chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                led_color.Connect_2_Green = COLOR_MIN_LV;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-            }
-        }
-    }
-    if (_checkLedChanged > 0) {
-        if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS) {
-            _checkLedChanged--;
-
-            cur_led_color.Connect_1_Red     = led_color.Connect_1_Red;
-            cur_led_color.Connect_1_Green   = led_color.Connect_1_Green;
-            cur_led_color.Connect_1_Blue    = led_color.Connect_1_Blue;
-            cur_led_color.Connect_2_Red     = led_color.Connect_2_Red;
-            cur_led_color.Connect_2_Green   = led_color.Connect_2_Green;
-            cur_led_color.Connect_2_Blue    = led_color.Connect_2_Blue;
-        }
-    } else if (IsNoneMatchLedColor()) {
-        _checkLedChanged = 3;
-    }
-}
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    }
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmFanModuleData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmFanModuleData NG\n");
-#endif
-        result = FAIL;
-    }
-    memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
-
-    if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmRelayModuleData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmRelayModuleData NG\n");
-#endif
-        result = FAIL;
-    }
-    memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
-
-    if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmLedModuleData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmLedModuleData NG\n");
-#endif
-        result = FAIL;
-    }
-    memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
-
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPsuData NG \n");
-#endif
-        result = FAIL;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmPsuData NG \n");
-#endif
-        result = FAIL;
-    }
-
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-#endif
-        result = FAIL;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
-#endif
-        result = FAIL;
-    }
-
-    return result;
-}
-
-int InitComPort()
-{
-    int fd;
-    struct termios tios;
-
-    fd = open(relayRs485PortName, O_RDWR);
-    if (fd <= 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("Module_InternalComm. InitComPort NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        return -1;
-    }
-    ioctl (fd, TCGETS, &tios);
-    tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
-    tios.c_lflag = 0;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (byte)0;     // timeout 0.5 second
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl (fd, TCSETS, &tios);
-
-    return fd;
-}
-
-//================================================
-// Main process
-//================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
-                == target) {
-            chargingData[target] =
-                &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
-                == target) {
-            chargingData[target] =
-                &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
-                == target) {
-            chargingData[target] =
-                &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return true;
-        }
-    }
-
-    return false;
-}
-
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
-{
-    if (target < AC_QUANTITY) {
-        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
-        return true;
-    }
-
-    return false;
-}
-
-void Initialization()
-{
-    bool isPass = false;
-
-    for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++) {
-        outputRelay.relay_event.relay_status[index] = 0x00;
-    }
-
-    while (!isPass) {
-        isPass = true;
-        for (byte _index = 0; _index < gunCount; _index++) {
-            if (!FindChargingInfoData(_index, &_chargingData[0])) {
-                DEBUG_ERROR("InternalComm : FindChargingInfoData false \n");
-                isPass = false;
-                break;
-            }
-        }
-
-        sleep(1);
-    }
-
-    isPass = false;
-
-    if (acgunCount > 0) {
-        while (!isPass) {
-            isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
-                if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
-                    DEBUG_ERROR("EvComm : FindAcChargingInfoData false \n");
-                    isPass = false;
-                    break;
-                }
-            }
-
-            sleep(1);
-        }
-    }
-}
-
-bool IsNoneMatchRelayStatus()
-{
-    bool result = false;
-
-    if (/*(regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
-        (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||*/
-        (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
-        (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
-        (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
-        (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N)/* ||
-        (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)*/) {
-        if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
-            PRINTF_FUNC("AC Contact Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
-            PRINTF_FUNC("CCS Precharge Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
-            PRINTF_FUNC("SMR1:D+ Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
-            PRINTF_FUNC("SMR1:D- Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
-            PRINTF_FUNC("SMR2:D+ Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
-            PRINTF_FUNC("SMR2:D- Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
-            PRINTF_FUNC("Parallel:D+ Relay none match. \n");
-        }
-        if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
-            PRINTF_FUNC("Parallel:D- Relay none match. \n");
-        }
-
-        result = true;
-    }
-
-    return result;
-}
-
-void MatchRelayStatus()
-{
-    // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
-    //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
-#ifndef DD360
-    ShmSysConfigAndInfo->SysInfo.AcContactorStatus  = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
-#endif
-    regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
-    regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
-    regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
-    regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
-    regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
-    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;
-}
-
-void CheckRelayStatusByADC()
-{
-    if (ShmRelayModuleData->Gun1FuseOutputVolt > 0 && ShmRelayModuleData->Gun1RelayOutputVolt > 0 &&
-            (ShmRelayModuleData->Gun1FuseOutputVolt == ShmRelayModuleData->Gun1RelayOutputVolt)) {
-        // Relay 前後電壓一致
-        _chargingData[0]->RelayK1K2Status = 0x01;
-    } else {
-        _chargingData[0]->RelayK1K2Status = 0x00;
-    }
-
-    if (ShmRelayModuleData->Gun2FuseOutputVolt > 0 && ShmRelayModuleData->Gun2RelayOutputVolt > 0 &&
-            (ShmRelayModuleData->Gun2FuseOutputVolt == ShmRelayModuleData->Gun2RelayOutputVolt)) {
-        // Relay 前後電壓一致
-        _chargingData[1]->RelayK1K2Status = 0x01;
-    } else {
-        _chargingData[1]->RelayK1K2Status = 0x00;
-    }
-}
-
-void SetGfdConfig(byte index, byte resister)
-{
-    gfd_config.index = index;
-    gfd_config.state = resister;
-
-    //PRINTF_FUNC("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
-    if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS) {
-//      PRINTF_FUNC("Set reqVol = %f, resister = %d \n",
-//              gfd_config.reqVol,
-//              gfd_config.resister);
-    }
-}
-
-void CableCheckDetected(byte index)
-{
-    // Cable Check
-    // 當火線上的電壓 = 車端要求的電壓電流
-    // _chargingData[targetGun]->EvBatterytargetVoltage
-    // 才可以開始偵測 1s
-    // Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
-    // Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
-    // SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
-    if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
-            (_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)) {
-        if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_TERMINATING) ||
-                (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-            if (_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE &&
-                    _chargingData[index]->RelayWeldingCheck == YES) {
-                SetGfdConfig(index, GFD_CABLECHK);
-            } else if (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                       _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1) {
-                SetGfdConfig(index, GFD_PRECHARGE);
-            } else if (_chargingData[index]->SystemStatus >= S_CHARGING &&
-                       _chargingData[index]->SystemStatus <= S_TERMINATING) {
-                if (_chargingData[index]->Type == _Type_GB || _chargingData[index]->Type == _Type_Chademo) {
-                    SetGfdConfig(index, GFD_IDLE);
-                } else {
-                    SetGfdConfig(index, GFD_CHARGING);
-                }
-            }
-        } else if (_chargingData[index]->SystemStatus == S_COMPLETE || _chargingData[index]->SystemStatus == S_PREPARNING
-                   || _chargingData[index]->SystemStatus == S_IDLE) {
-            SetGfdConfig(index, GFD_IDLE);
-        }
-    }
-}
-
-void CheckOutputPowerOverCarReq(byte index)
-{
-    float fireV = _chargingData[index]->FireChargingVoltage;
-    float carV = _chargingData[index]->EvBatterytargetVoltage * 10;
-
-    if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
-            (_chargingData[index]->Type == _Type_Chademo ||
-             _chargingData[index]->Type == _Type_CCS_2 ||
-             _chargingData[index]->Type == _Type_GB)) {
-        if (fireV >= (carV + (carV * 0.1))) {
-            PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                        _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
-            DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
-                        _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
-            _chargingData[index]->StopChargeFlag = YES;
-        }
-    }
-}
-
-void CheckOutputVolNoneMatchFire(byte index)
-{
-    if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
-            (_chargingData[index]->Type == _Type_Chademo ||
-             _chargingData[index]->Type == _Type_CCS_2 ||
-             _chargingData[index]->Type == _Type_GB)) {
-        if (((_chargingData[index]->PresentChargingVoltage * 10) < _chargingData[index]->FireChargingVoltage - 300) ||
-                ((_chargingData[index]->PresentChargingVoltage * 10) > _chargingData[index]->FireChargingVoltage + 300)) {
-            if (!_isOutputNoneMatch[index]) {
-                _isOutputNoneMatch[index] = YES;
-                gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
-            } else {
-                if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
-                    /*PRINTF_FUNC("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
-                            index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
-                    DEBUG_ERROR("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f \n",
-                            index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
-                    _chargingData[index]->StopChargeFlag = YES;*/
-                }
-            }
-        } else {
-            _isOutputNoneMatch[index] = NO;
-        }
-    }
-}
-
-void CheckRelayWeldingStatus(byte index)
-{
-    if (!_isRelayWelding[index]) {
-        if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
-            gettimeofday(&_checkRelayWeldingTimer[index], NULL);
-            _isRelayWelding[index] = YES;
-        }
-    } else {
-        if ((GetTimeoutValue(_checkRelayWeldingTimer[index]) / 1000) >= 1000) {
-            _chargingData[index]->RelayWeldingCheck = YES;
-            return;
-        }
-
-        if (_chargingData[index]->FireChargingVoltage >= VOUT_MIN_VOLTAGE) {
-            if (_chargingData[index]->Type == _Type_Chademo) {
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
-            } else if (_chargingData[index]->Type == _Type_GB) {
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
-            } else if (_chargingData[index]->Type == _Type_CCS_2) {
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
-            }
-
-            PRINTF_FUNC("CheckRelayWeldingStatus : fail \n");
-            _chargingData[index]->StopChargeFlag = YES;
-        }
-    }
-}
-
-void GetPsuTempForFanSpeed()
-{
-    char temp = 0;
-
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
-            if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
-                temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
-            }
-        }
-    }
-
-    ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = temp;
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO) {
-        if (ShmFanModuleData->TestFanSpeed == NORMAL_FAN_SPEED) {
-            if (temp >= ENV_TEMP_MAX) {
-                ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
-            }
-        } else if (ShmFanModuleData->TestFanSpeed == MAX_FAN_SPEED) {
-            if (temp <= ENV_TEMP_MIN) {
-                ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
-            }
-        } else {
-            ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
-        }
-    }
-}
-
-void GetFanSpeedByFunction()
-{
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        return;
-    }
-
-    // 風控修改 :
-    // ******************************************************* //
-    //
-    //       當前PSU輸出總 KW       PSU Temp
-    // 30 x -------------------- x ---------- + 14 x (PSU Temp - 45)
-    //       當前樁最大功率 KW         45
-    //
-    // ******************************************************* //
-
-    // 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
-    unsigned int _maxPower = ShmPsuData->SystemAvailablePower;
-    // 當前PSU輸出總 KW & PSU Temp :
-    unsigned char temp = 0;
-    float power = 0;
-
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
-            if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp) {
-                temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
-            }
-        }
-        power += (_chargingData[index]->PresentChargingPower * 10);
-    }
-
-    double _pw_rate = 0;
-    if (_maxPower > 0) {
-        _pw_rate = power / (double)_maxPower;
-    }
-    double _temp_rate = 0;
-    if (temp > 0) {
-        _temp_rate = (double)temp / 45;
-    }
-    unsigned char _temp_diff = 0;
-    if (temp > 45) {
-        _temp_diff = temp - 45;
-    }
-
-    ShmFanModuleData->TestFanSpeed = ((30 * _pw_rate * _temp_rate + 14 * _temp_diff) / 100) * MAX_FAN_SPEED;
-
-    if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED) {
-        ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
-    }
-
-    if (ShmFanModuleData->TestFanSpeed < 0) {
-        ShmFanModuleData->TestFanSpeed = 0;
-    }
-//
-//  printf("power = %f \n", power);
-//  printf("_maxPower = %d \n", _maxPower);
-//  printf("temp = %d \n", temp);
-//
-//  printf("_pw_rate = %f \n", _pw_rate);
-//  printf("_temp_rate = %f \n", _temp_rate);
-//  printf("_temp_diff = %d \n", _temp_diff);
-//  printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
-//  printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
-}
-
-void GetAcStatus()
-{
-    if (Query_AC_Status(Uart5Fd, Addr.AcPlug, &acStatus) == PASS) {
-        ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = acStatus.MaxCurrent;
-
-        if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0) {
-            ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
-        }
-
-        ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
-        //  PRINTF_FUNC("CpStatus = %d \n", acStatus.CpStatus);
-        //              printf("CurLimit = %d \n", acStatus.CurLimit);
-        //              printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
-        //              printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
-        //              printf("LockStatus = %d \n", acStatus.LockStatus);
-        //              printf("RelayStatus = %d \n", acStatus.RelayStatus);
-        //              printf("ShutterStatus = %d \n", acStatus.ShutterStatus);
-        //              printf("MeterStatus = %d \n", acStatus.MeterStatus);
-        //              printf("PpStatus = %d \n", acStatus.PpStatus);
-        //              printf("MaxCurrent = %d \n", acStatus.MaxCurrent);
-        //              printf("RotateSwitchStatus = %d \n", acStatus.RelayStatus);
-        //              printf("============================== \n");
-        //
-        //              ac_chargingInfo[0]->SystemStatus = acStatus.CpStatus;
-    }
-//  else
-//      PRINTF_FUNC("GetAcStatus return fail. \n");
-}
-
-void GetAcAlarmCode()
-{
-    if (Query_AC_Alarm_Code(Uart5Fd, Addr.AcPlug, &acAlarmCode) == PASS) {
-        CheckAlarmOccur();
-    }
-}
-
-unsigned char GetChargingEnergy()
-{
-    return Query_Charging_Energy(Uart5Fd, Addr.AcPlug, &acChargingEnergy);
-}
-
-unsigned char GetChargingCurrent()
-{
-    return Query_Charging_Current(Uart5Fd, Addr.AcPlug, &acChargingCurrent);
-}
-
-void ChangeLedStatus()
-{
-    if (ac_chargingInfo[0]->SystemStatus == S_IDLE) {
-        ledStatus.ActionMode = 1;
-    } else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING) {
-        ledStatus.ActionMode = 3;
-    } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-        ledStatus.ActionMode = 4;
-    }
-
-    Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
-}
-
-void SetLegacyReq(byte _switch)
-{
-    Config_Legacy_Req(Uart5Fd, Addr.AcPlug, _switch);
-}
-
-void SetCpDuty(byte _value)
-{
-    Config_Ac_Duty(Uart5Fd, Addr.AcPlug, _value);
-}
-
-void ChangeToCsuMode()
-{
-    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, Addr.AcPlug);
-
-//  if (ac_chargingInfo[0]->IsModeChagned == PASS)
-//  {
-//      Config_Reset_MCU(Uart5Fd, Addr.AcPlug);
-//  }
-}
-
-void ChangeStartOrStopDateTime(byte isStart)
-{
-    char cmdBuf[32];
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-
-    sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
-            tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-            tmCSU->tm_sec);
-    if (isStart) {
-        strcpy((char *)ac_chargingInfo[0]->StartDateTime, cmdBuf);
-    } else {
-        strcpy((char *)ac_chargingInfo[0]->StopDateTime, cmdBuf);
-    }
-}
-
-void OcppStartTransation(byte gunIndex)
-{
-    if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
-    }
-
-    PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
-}
-
-void OcppStopTransation(byte gunIndex)
-{
-    if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
-    }
-
-    PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
-}
-
-bool OcppRemoteStop(byte gunIndex)
-{
-    bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
-    }
-
-    return result;
-}
-
-unsigned char isModeChange()
-{
-    unsigned char result = NO;
-
-    if (ac_chargingInfo[0]->SystemStatus != ac_chargingInfo[0]->PreviousSystemStatus) {
-        result = YES;
-        ac_chargingInfo[0]->PreviousSystemStatus = ac_chargingInfo[0]->SystemStatus;
-    }
-
-    return result;
-}
-
-void AcChargeTypeProcess()
-{
-    if (acgunCount > 0) {
-        //ac_chargingInfo[0]->SelfTest_Comp = YES;
-        //ac_chargingInfo[0]->IsModeChagned = PASS;
-        //---------------------------------------------
-        if (ac_chargingInfo[0]->SelfTest_Comp == NO) {
-            ac_chargingInfo[0]->IsModeChagned = NO;
-            GetFwVersion_AC();
-            GetAcModelName();
-        } else if (ac_chargingInfo[0]->SelfTest_Comp == YES) {
-            if (ac_chargingInfo[0]->IsModeChagned != PASS) {
-                ChangeToCsuMode();
-                return;
-            }
-            GetAcStatus();
-            GetAcAlarmCode();
-
-            byte _status = S_NONE;
-
-            if (ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsErrorOccur) {
-                _status = S_ALARM;
-            } else if (acStatus.CpStatus == AC_SYS_A || ac_chargingInfo[0]->IsErrorOccur) {
-                if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-                    _status = S_TERMINATING;
-                } else if (ac_chargingInfo[0]->SystemStatus >= S_TERMINATING) {
-                    if (GetTimeoutValue(_ac_charging_comp) >= 10000000 && acStatus.CpStatus == AC_SYS_A) {
-                        _status = S_IDLE;
-                    }
-                } else {
-                    _status = S_IDLE;
-                }
-            } else if (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING &&
-                       ac_chargingInfo[0]->SystemStatus < S_CHARGING) {
-                if (acStatus.CpStatus == AC_SYS_C && acStatus.RelayStatus == YES) {
-                    _status = S_CHARGING;
-                } else if (GetTimeoutValue(_ac_preparing) >= 30000000) {
-                    _status = S_IDLE;
-                }
-            } else if ((acStatus.CpStatus == AC_SYS_B || ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_B) &&
-                       ac_chargingInfo[0]->IsAvailable &&
-                       !ac_chargingInfo[0]->IsErrorOccur &&
-                       (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
-                        ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)) {
-                if (ac_chargingInfo[0]->RemoteStartFlag == YES) {
-                    PRINTF_FUNC("** AC Remote \n");
-                    ac_chargingInfo[0]->RemoteStartFlag = NO;
-                    strcpy((char *)ac_chargingInfo[0]->StartUserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-                    _status = S_PREPARNING;
-                } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
-                    PRINTF_FUNC("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
-                    strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-                    PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-                    _status = S_PREPARNING;
-                }
-            } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-                if (OcppRemoteStop(1)) {
-                    _status = S_TERMINATING;
-                }
-            }
-
-            //printf("_status = %d \n", _status);
-
-            if (_status != S_NONE && ac_chargingInfo[0]->SystemStatus != _status) {
-                ac_chargingInfo[0]->SystemStatus = _status;
-            }
-
-            // 設定限制最大充電電流 >= 6 ~ <= 32
-            switch (ac_chargingInfo[0]->SystemStatus) {
-            case S_IDLE:
-            case S_ALARM: {
-                if (isModeChange()) {
-                    ac_chargingInfo[0]->PresentChargedEnergy = 0.0;
-                    ac_chargingInfo[0]->PresentChargingVoltage = 0;
-                    ac_chargingInfo[0]->ChargingFee = 0.0;
-                    strcpy((char *)ac_chargingInfo[0]->StartDateTime, "");
-                    strcpy((char *)ac_chargingInfo[0]->StopDateTime, "");
-                    _beforeChargingTotalEnergy = 0.0;
-                }
-
-                ChangeLedStatus();
-            }
-            break;
-            case S_PREPARNING: {
-                if (isModeChange()) {
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-                    if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
-                        ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-                    }
-                    gettimeofday(&_ac_preparing, NULL);
-                }
-
-                if (GetChargingEnergy() == PASS) {
-                    //ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
-                    _beforeChargingTotalEnergy = acChargingEnergy.Energy;
-                }
-
-                SetLegacyReq(YES);
-                ChangeLedStatus();
-            }
-            break;
-            case S_CHARGING: {
-                if (isModeChange()) {
-                    ftime(&_ac_startChargingTime);
-                    OcppStartTransation(1);
-                    ChangeStartOrStopDateTime(YES);
-                    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-                }
-
-                if (GetChargingEnergy() == PASS) {
-                    if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0) {
-                        ac_chargingInfo[0]->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            ac_chargingInfo[0]->ChargingFee += ac_chargingInfo[0]->PresentChargedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
-                        }
-                    }
-
-                    _beforeChargingTotalEnergy = acChargingEnergy.Energy;
-                }
-
-                if (GetChargingCurrent() == PASS) {
-                    ac_chargingInfo[0]->PresentChargingPower = (((float)(AC_DEFAULT_VOL * acChargingCurrent.OuputCurrentL1) / 10) / 1000);
-                }
-
-                ftime(&_ac_endChargingTime);
-                ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
-                ac_chargingInfo[0]->PresentChargingVoltage = AC_DEFAULT_VOL;
-                ac_chargingInfo[0]->PresentChargingCurrent = ((float)acChargingCurrent.OuputCurrentL1 / 10);
-
-                // 用以判斷是否有在輸出
-                ac_chargingInfo[0]->IsCharging = acStatus.RelayStatus;
-
-                SetCpDuty(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent);
-                ChangeLedStatus();
-            }
-            break;
-            case S_TERMINATING: {
-                if (isModeChange()) {
-                    ChangeStartOrStopDateTime(NO);
-                    gettimeofday(&_ac_charging_comp, NULL);
-                }
-
-                SetLegacyReq(NO);
-                if (acStatus.RelayStatus == NO) {
-                    ac_chargingInfo[0]->SystemStatus = S_COMPLETE;
-                }
-            }
-            break;
-            case S_COMPLETE: {
-                if (isModeChange()) {
-                    gettimeofday(&_ac_charging_comp, NULL);
-                    ftime(&_ac_endChargingTime);
-                    if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL) {
-                        // AC 固定為第2把槍
-                        OcppStopTransation(1);
-                    }
-
-                    ChangeStartOrStopDateTime(NO);
-                    ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
-                }
-            }
-            break;
-            }
-        }
-    }
-}
-
-int main(void)
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-    acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-    // Open Uart5 for RB
-    Uart5Fd = InitComPort();
-    Initialization();
-    sleep(3);
-
-    if (Uart5Fd < 0) {
-        PRINTF_FUNC("(Internal) open port error. \n");
-        return 0;
-    }
-
-    outputRelay.relay_event.bits.AC_Contactor = 0x00;
-    outputRelay.relay_event.bits.CCS_Precharge = 0x00;
-    outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00;
-    outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
-    outputRelay.relay_event.bits.Gun1_P = 0x00;
-    outputRelay.relay_event.bits.Gun1_N = 0x00;
-    outputRelay.relay_event.bits.Gun2_N = 0x00;
-    outputRelay.relay_event.bits.Gun2_P = 0x00;
-    if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS) {
-        PRINTF_FUNC("Config_Relay_Output fail \n");
-    }
-
-    cur_led_color.Connect_1_Red = COLOR_MIN_LV;
-    cur_led_color.Connect_1_Green = COLOR_MIN_LV;
-    cur_led_color.Connect_1_Blue = COLOR_MIN_LV;
-    cur_led_color.Connect_2_Red = COLOR_MIN_LV;
-    cur_led_color.Connect_2_Green = COLOR_MIN_LV;
-    cur_led_color.Connect_2_Blue = COLOR_MIN_LV;
-
-    //bool printRelayStatus = true;
-    for (;;) {
-        bool isCharging = false;
-        // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-        if (ShmRelayModuleData->SelfTest_Comp == NO) {
-            GetFwAndHwVersion_Relay();
-            SetRtcData_Relay();
-            sleep(1);
-        }
-#ifndef NO_FAN_BOARD
-        if (ShmFanModuleData->SelfTest_Comp == NO) {
-            GetFwAndHwVersion_Fan();
-            SetModelName_Fan();
-            SetRtcData_Fan();
-            sleep(1);
-            gettimeofday(&_priority_time, NULL);
-        }
-#endif
-        // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
-        if (ShmLedModuleData->SelfTest_Comp == NO) {
-            // 自檢階段
-            //if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq <= _STEST_PSU_CAP)
-            //{
-            GetFwAndHwVersion_Led();
-            sleep(1);
-            gettimeofday(&_led_priority_time, NULL);
-            //}
-            /*else
-            {
-                // 自檢階段沒有問到版號
-                if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail == NO)
-                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES;
-            }*/
-        }
-
-        AcChargeTypeProcess();
-
-        if (ShmRelayModuleData->SelfTest_Comp == YES) {
-            // ==============優先權最高 10 ms ==============
-            // 輸出電壓
-            GetPersentOutputVol();
-
-#ifndef DD360
-            // 三相輸入電壓
-            GetPresentInputVol();
-            // 讀取當前 AC relay 狀態
-            regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-#endif
-            //GetRelayOutputStatus();
-
-            for (int i = 0; i < gunCount; i++) {
-                // Cable check (Set)
-                CableCheckDetected(i);
-
-                // check k1 k2 relay 狀態
-                CheckK1K2RelayOutput(i);
-
-                // 依據當前各槍的狀態選擇 搭上/放開 Relay
-                SetK1K2RelayStatus(i);
-
-#ifndef DD360
-                if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
-                    CheckPhaseLossStatus(i);
-                }
-
-                CheckAcInputOvpStatus(i);
-
-#endif
-                if (_chargingData[i]->SystemStatus == S_IDLE) {
-                    _chargingData[i]->RelayWeldingCheck = NO;
-                    _isRelayWelding[i] = NO;
-                }
-
-                if (_chargingData[i]->SystemStatus == S_BOOTING ||
-                        (_chargingData[i]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[i]->SystemStatus <= S_COMPLETE) ||
-                        (_chargingData[i]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[i]->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                        ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
-                        (ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG)) {
-                    _chargingData[i]->IsReadyToCharging = YES;
-                    isCharging = true;
-
-                    // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
-                    if (_chargingData[i]->Type == _Type_GB) {
-                        if (_chargingData[i]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                                _chargingData[i]->RelayWeldingCheck == NO) {
-                            CheckRelayWeldingStatus(i);
-                        }
-                    } else {
-                        _chargingData[i]->RelayWeldingCheck = YES;
-                    }
-
-                    if (_chargingData[i]->SystemStatus == S_CHARGING) {
-                        CheckOutputPowerOverCarReq(i);
-                        CheckOutputVolNoneMatchFire(i);
-                    } else {
-                        _isOutputNoneMatch[i] = NO;
-                    }
-                } else {
-                    _chargingData[i]->IsReadyToCharging = NO;
-                }
-            }
-            // Cable check (Get)
-            GetGfdAdc();
-
-            // 橋接 relay
-            //SetParalleRelayStatus();
-
-            // 搭上 AC Contactor
-//          if (isCharging)
-//              outputRelay.relay_event.bits.AC_Contactor = YES;
-//          else
-//              outputRelay.relay_event.bits.AC_Contactor = NO;
-
-            if (isCharging ||
-                    (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)) {
-                isStopChargingCount = false;
-                outputRelay.relay_event.bits.AC_Contactor = YES;
-            } else {
-                if (!isStopChargingCount) {
-                    gettimeofday(&_close_ac_contactor, NULL);
-                    isStopChargingCount = true;
-                } else {
-                    if ((outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
-                        outputRelay.relay_event.bits.AC_Contactor = NO;
-                    }
-                }
-            }
-
-            if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
-                outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
-            }
-
-            // 搭上/鬆開 Relay
-            if (IsNoneMatchRelayStatus()) {
-                if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay)) {
-                    //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-                    regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
-                    regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
-                    regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
-                    regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
-                    regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
-                    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;
-
-                    PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-                                regRelay.relay_event.bits.AC_Contactor,
-                                regRelay.relay_event.bits.Gun1_P,
-                                regRelay.relay_event.bits.Gun1_N,
-                                regRelay.relay_event.bits.Gun2_P,
-                                regRelay.relay_event.bits.Gun2_N,
-                                regRelay.relay_event.bits.CCS_Precharge,
-                                regRelay.relay_event.bits.Gun1_Parallel_P,
-                                regRelay.relay_event.bits.Gun1_Parallel_N);
-
-                }
-            }
-
-
-//          if(IsNoneMatchRelayStatus())
-//          {
-//              if (printRelayStatus)
-//              {
-////                    PRINTF_FUNC("Match Relay Target, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-////                            outputRelay.relay_event.bits.AC_Contactor,
-////                            outputRelay.relay_event.bits.Gun1_P,
-////                            outputRelay.relay_event.bits.Gun1_N,
-////                            outputRelay.relay_event.bits.Gun2_P,
-////                            outputRelay.relay_event.bits.Gun2_N,
-////                            outputRelay.relay_event.bits.CCS_Precharge,
-////                            outputRelay.relay_event.bits.Gun1_Parallel_P,
-////                            outputRelay.relay_event.bits.Gun1_Parallel_N);
-//              }
-//              printRelayStatus = false;
-//              if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
-//              {
-//                  PRINTF_FUNC("Match Relay Target, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-//                          outputRelay.relay_event.bits.AC_Contactor,
-//                          outputRelay.relay_event.bits.Gun1_P,
-//                          outputRelay.relay_event.bits.Gun1_N,
-//                          outputRelay.relay_event.bits.Gun2_P,
-//                          outputRelay.relay_event.bits.Gun2_N,
-//                          outputRelay.relay_event.bits.CCS_Precharge,
-//                          outputRelay.relay_event.bits.Gun1_Parallel_P,
-//                          outputRelay.relay_event.bits.Gun1_Parallel_N);
-//              }
-//          }
-//          else
-//          {
-//              if (!printRelayStatus)
-//              {
-//                  PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-//                          regRelay.relay_event.bits.AC_Contactor,
-//                          regRelay.relay_event.bits.Gun1_P,
-//                          regRelay.relay_event.bits.Gun1_N,
-//                          regRelay.relay_event.bits.Gun2_P,
-//                          regRelay.relay_event.bits.Gun2_N,
-//                          regRelay.relay_event.bits.CCS_Precharge,
-//                          regRelay.relay_event.bits.Gun1_Parallel_P,
-//                          regRelay.relay_event.bits.Gun1_Parallel_N);
-//              }
-//              printRelayStatus = true;
-//          }
-        }
-#if !defined NO_FAN_BOARD && !defined DD360ComBox
-        if (ShmFanModuleData->SelfTest_Comp == YES) {
-            if (GetTimeoutValue(_priority_time) / 1000 >= 1000) {
-                //GetPsuTempForFanSpeed();
-                GetFanSpeedByFunction();
-                GetFanSpeed();
-                ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
-                gettimeofday(&_priority_time, NULL);
-
-                ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-                ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-                ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-                ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-
-//              if (isCharging)
-//              {
-////                    if (ShmFanModuleData->PresentFan1Speed < MAX_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan2Speed < MAX_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan3Speed < MAX_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan4Speed < MAX_FAN_SPEED)
-////                    {
-////                        ShmFanModuleData->SetFan1Speed = MAX_FAN_SPEED;
-////                        ShmFanModuleData->SetFan2Speed = MAX_FAN_SPEED;
-////                        ShmFanModuleData->SetFan3Speed = MAX_FAN_SPEED;
-////                        ShmFanModuleData->SetFan4Speed = MAX_FAN_SPEED;
-////                    }
-//
-//                  // 在還沒問到 PSU 溫度~ 還是要有個最小轉速
-//                  ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
-//                  ShmFanModuleData->SetFan2Speed = MIN_FAN_SPEED;
-//                  ShmFanModuleData->SetFan3Speed = MIN_FAN_SPEED;
-//                  ShmFanModuleData->SetFan4Speed = MIN_FAN_SPEED;
-//
-//                  if (ShmFanModuleData->TestFanSpeed > 0)
-//                  {
-//                      ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-//                  }
-//              }
-//              else
-//              {
-////                    if (ShmFanModuleData->PresentFan1Speed > MIN_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan2Speed > MIN_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan3Speed > MIN_FAN_SPEED ||
-////                        ShmFanModuleData->PresentFan4Speed > MIN_FAN_SPEED)
-////                    {
-//                      ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
-//                      ShmFanModuleData->SetFan2Speed = MIN_FAN_SPEED;
-//                      ShmFanModuleData->SetFan3Speed = MIN_FAN_SPEED;
-//                      ShmFanModuleData->SetFan4Speed = MIN_FAN_SPEED;
-////                    }
-//
-//                  // 停止時,如溫度還是很高,則需要維持該轉速直到溫度降低
-//                  if (ShmFanModuleData->TestFanSpeed >= MAX_FAN_SPEED)
-//                  {
-//                      ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-//                      ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-//                  }
-//              }
-
-                //PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
-                SetFanModuleSpeed();
-            }
-        }
-#endif
-        if (ShmLedModuleData->SelfTest_Comp == YES) {
-            if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-                if (gunCount == 1) {
-                    SetLedColor(_chargingData[0], _chargingData[0]);
-                } else if (gunCount == 2) {
-                    SetLedColor(_chargingData[0], _chargingData[1]);
-                }
-
-                gettimeofday(&_led_priority_time, NULL);
-            }
-        }
-
-        usleep(10000);
-    }
-
-    return FAIL;
-}

+ 0 - 196
EVSE/Projects/DD360Audi/Apps/Module_LcmContro.h

@@ -1,196 +0,0 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include 	<stdbool.h>
-#include	"../../define.h"
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-typedef unsigned char 			byte;
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct FanModuleData			*ShmFanModuleData;
-
-#define NO_DEFINE			255
-#define DEFAULT_AC_INDEX	2
-
-#define TIME_MAX_SEC		2592000 // 一個月,秒數
-#define POWER_MAX_KW		5000
-#define ENERGY_MAX_KWH		5000
-
-#define CMD_TITLE_1				0x5A
-#define CMD_TITLE_2				0xA5
-#define CMD_READ				0x80
-#define CMD_WRITE				0x81
-#define CMD_MULTI_WRITE			0x82
-#define CMD_MULTI_READ			0x83
-
-#define CMD_BACKLIGHT			0x01
-#define CMD_REGISTER			0x03
-
-enum _BATTERY_LEVEL_FOR_MAP
-{
-	_BATTERY_LEVEL_FOR_MAP_EMP = 0x00,
-	_BATTERY_LEVEL_FOR_MAP_LV1 = 0x01,
-	_BATTERY_LEVEL_FOR_MAP_LV2 = 0x02,
-	_BATTERY_LEVEL_FOR_MAP_LV3 = 0x03,
-	_BATTERY_LEVEL_FOR_MAP_LV4 = 0x04,
-	_BATTERY_LEVEL_FOR_MAP_LV5 = 0x05,
-};
-
-int _port;
-//char* pPortName = "/dev/ttyO2";
-char* pPortName = "/dev/ttyS3";
-char* moduleName = "DMT80480T070_09WT";
-byte _totalCount;
-byte acgunCount;
-struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
-
-byte ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-byte isDiffStatus = false;
-byte isChangeBattMap = false;
-// 當前選擇的槍號
-short _currentPage = _LCM_NONE;
-short _oldPage = _LCM_NONE;
-byte _gunIndex = 0;
-bool _wifi_conn_status = false;
-bool _battery_display_ani = false;
-byte _curPage_index = 0;
-bool _page_reload = false;
-
-// LCM - HW
-byte _everyPageRollChange = 0;
-short __conn_status = 0x0030;
-short __ethernet_status = 0x0032;
-short __3G4G_status = 0x0036;
-short __wifi_status = 0x003C;
-
-short __sel_gun_btn = 0x0040;
-short __ret_home_btn = 0x0042;
-short __stop_method_btn = 0x0044;
-
-short __qr_code = 0x0250;
-short __main_rfid = 0x0052;
-short __main_qr = 0x0054;
-short __main_app = 0x0056;
-
-short __plug_in_arrow = 0x0060;
-
-short __conn_line = 0x0066;
-
-short __gun_type_index = 0x0070;
-short __qr_code_pre = 0x0280;
-
-short __side_top = 0x0090;
-short __side_down = 0x0092;
-short __side_mid = 0x0094;
-
-short __conn_line_chag = 0x0096;
-short __batt_map = 0x0100;
-short __soc_value_charging = 0x0102;
-short __remain_time_map = 0x0106;
-short __power_map = 0x0108;
-short __energy_map = 0x010A;
-short __remain_time_tx = 0x0110;
-short __output_eng_tx = 0x0120;
-short __total_out_eng_tx = 0x0130;
-short __conn_line_comp = 0x0140;
-short __charging_fee_map = 0x0146;
-short __charging_fee_tx = 0x0150;
-
-short __money_by_rate = 0x0200;
-short __money_rate = 0x0220;
-short __money_rate_map = 0x0230;
-
-// ICON ID
-byte _disappear = 0;
-byte _disconnect = 1;
-byte _connect = 2;
-byte _warning = 3;
-byte _arrow_dark = 4;
-byte _arrow_light = 5;
-byte _3G4G_disconnect = 6;
-byte __3G4G_connect = 7;
-byte _wifi_disconnect = 8;
-byte _wifi_connect = 9;
-byte _logo = 10;
-byte _conn_map1 = 11;
-byte _conn_map2 = 12;
-byte _sel_gun_btn = 13;
-byte _back_home_btn = 14;
-byte _stop_charging_btn = 15;
-byte _stop_charging_btn_scan = 16;
-byte _chademo_dark = 17;
-byte _ccs_dark = 18;
-byte _gbt_dark = 19;
-byte _actype_dark = 20;
-byte _chademo_light = 21;
-byte _ccs_light = 22;
-byte _gbt_light = 23;
-byte _actype_light = 24;
-byte _main_none_rfid = 25;
-byte _main_rfid = 26;
-byte _main_none_app = 27;
-byte _main_app = 28;
-byte _main_none_qr = 29;
-byte _main_qr = 30;
-byte _charging_map1 = 31;
-byte _charging_map2 = 32;
-byte _battery_empty = 33;
-byte _battery_cap_20 = 34;
-byte _battery_cap_40 = 35;
-byte _battery_cap_60 = 36;
-byte _battery_cap_80 = 37;
-byte _battery_cap_100 = 38;
-byte _battery_map = 39;
-byte _power_map = 40;
-byte _time_map = 41;
-byte _complete_map = 42;
-byte _battery_soc_20 = 43;
-byte _battery_soc_40 = 44;
-byte _battery_soc_60 = 45;
-byte _battery_soc_80 = 46;
-byte _battery_soc_100 = 47;
-byte _battery_eng_map = 48;
-byte _money_map = 49;
-byte _elapse_time_map = 50;
-byte _charging_money = 51;
-byte _side_none_rfid = 52;
-byte _side_rfid = 53;
-byte _side_none_app = 54;
-byte _side_app = 55;
-byte _side_none_qr = 56;
-byte _side_qr = 57;
-byte _eth_disconnect = 58;
-byte _eth_connect = 59;

+ 0 - 1526
EVSE/Projects/DD360Audi/Apps/Module_LcmControl.c

@@ -1,1526 +0,0 @@
-#include "ReModule_LcmControl.h"
-#include "Config.h"
-#include "AudiCust.h"
-
-static AudiCustInfo *gAudiCustInfo = NULL;
-bool needReloadQr = true;
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-char *getTimeString(void);
-
-//=================================
-// Common routine
-//=================================
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-char *getTimeString(void)
-{
-    char *result = malloc(21);
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-
-    return result;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //creat ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else
-    {}
-
-    //creat Audi customization info
-    if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmget select gun info NG \n");
-        return 0;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        DEBUG_ERROR("[main]CreatShareMemory:shmat shmget select gun info \n");
-        return 0;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef ShmPrimaryMcuData
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    return result;
-}
-
-//==========================================
-// Open and Close RS232 and R/W
-//==========================================
-int CreateCommunicationLcmPort()
-{
-    int fd;
-    struct termios tios;
-
-    fd = open(pPortName, O_RDWR);
-    if (fd <= 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("open /dev/ttyS3 NG \n");
-#endif
-        return -1;
-    }
-    ioctl(fd, TCGETS, &tios);
-    tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
-    tios.c_lflag = 0;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char) 5;
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl(fd, TCSETS, &tios);
-
-    return fd;
-}
-
-void CloseCommunicationLcmPort()
-{
-    close(_port);
-}
-
-void WriteCmdToLcm(byte *cmd, byte cmdLen)
-{
-    int len = write(_port, cmd, cmdLen);
-    if (len >= sizeof(cmd)) {
-        //PRINTF_FUNC("Write cmd to LCM successfully. \n");
-    }
-}
-
-void ReadMsgFromLcm(byte *msg, byte readLen)
-{
-    read(_port, msg, readLen);
-
-    if (*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2) {
-        if (*(msg + 3) == CMD_WRITE) {
-            switch (*(msg + 4)) {
-            case CMD_REGISTER: {
-                // 頁面
-                strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
-            }
-            break;
-            }
-        } else if (*(msg + 3) == CMD_MULTI_READ) {
-//          switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
-//          {
-//              case BUTTON_GUN_INDEX:
-//              {
-//                  // 當前選的槍號
-//                  _curGunIndex = (*(msg + 8));
-//              }
-//              break;
-//          }
-        }
-    }
-}
-
-//================================================
-// Function
-//================================================
-void ChangeToOtherPage(short newPage)
-{
-    byte cmd[7];
-    memset(cmd, 0x00, sizeof(cmd));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x02 + sizeof(newPage);
-    cmd[3] = CMD_READ;
-    cmd[4] = CMD_REGISTER;
-    cmd[5] = newPage >> 8;
-    cmd[6] = newPage & 0x00FF;
-
-    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-    usleep(100000);
-}
-
-void ChangeBackLight(bool islight)
-{
-    byte value = 0x01;
-
-    if (islight) {
-        value = 0x20;
-    }
-    byte cmd[7];
-    memset(cmd, 0x00, sizeof(cmd));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03;
-    cmd[3] = CMD_READ;
-    cmd[4] = CMD_BACKLIGHT;
-    cmd[5] = value;
-
-    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-    usleep(100000);
-}
-
-void GetCurrentPage()
-{
-    byte cmd[6];
-    memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
-    memset(msg, 0x00, sizeof(msg));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03;              // 底下總長度
-    cmd[3] = CMD_WRITE;
-    cmd[4] = CMD_REGISTER;
-    cmd[5] = 0x02;
-
-    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-    usleep(100000);
-    ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
-}
-
-void DisplayValueToLcm(short address, byte *data, byte len)
-{
-    byte cmd[256];
-    memset(cmd, 0x00, sizeof(cmd));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03 + len;
-    cmd[3] = CMD_MULTI_WRITE;
-    cmd[4] = address >> 8;
-    cmd[5] = address & 0x00FF;
-
-    for (byte count = 0; count < len; count++) {
-        cmd[6 + count] = *(data + count);
-    }
-
-    WriteCmdToLcm(cmd, cmd[2] + 3);
-}
-
-void ChangeDisplay2Value(short address, short value)
-{
-    byte data[2];
-    data[0] = value >> 8;
-    data[1] = value & 0x00FF;
-
-    DisplayValueToLcm(address, data, sizeof(data));
-}
-
-void GetBtnStatus(short address, byte len)
-{
-    byte cmd[8];
-    memset(cmd, 0x00, sizeof(cmd));
-    byte msg[8];
-    memset(msg, 0x00, sizeof(msg));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03 + len;
-    cmd[3] = CMD_MULTI_READ;
-    cmd[4] = address >> 8;
-    cmd[5] = address & 0x00FF;
-    cmd[6] = 0x00 + len;
-
-    WriteCmdToLcm(cmd, cmd[2] + 3);
-    usleep(100000);
-    ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
-}
-
-//================================================
-// Warning process
-//================================================
-void string2ByteArray(unsigned char *input, byte *output)
-{
-    int loop;
-    int i;
-
-    loop = 0;
-    i = 0;
-
-    while (input[loop] != '\0') {
-        output[i++] = input[loop++];
-    }
-    output[loop] = '\0';
-}
-
-void ChangeWarningFunc()
-{
-    byte cmd[7];
-    byte i = 0, j = 0;
-    //PRINTF_FUNC("ChangeWarningFunc \n");
-    // 最多一次五筆
-    //PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
-    //PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        memset(cmd, 0x00, sizeof(cmd));
-        if ((i) >= 5) {
-            break;
-        }
-
-        //error code
-        string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
-        DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
-        //警告標示
-        memset(cmd, 0x00, sizeof(cmd));
-
-        cmd[0] = 0x00;
-        cmd[1] = 0x01;
-        DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
-    }
-
-    memset(cmd, 0x00, sizeof(cmd));
-    for (; i < 5; i++) {
-        DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
-        DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
-    }
-#else
-    for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        memset(cmd, 0x00, sizeof(cmd));
-        if ((i - j) >= 5) {
-            break;
-        }
-        if (
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033900", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033901", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033902", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043627", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043628", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043622", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043623", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043624", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043625", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043626", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042241", 6) == 0) ||
-            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042242", 6) == 0)
-        ) {
-            j++;
-            continue;
-        }
-        //error code
-        string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
-        DisplayValueToLcm(0x0010 + ((i - j) * 6), cmd, sizeof(cmd));
-        //警告標示
-        memset(cmd, 0x00, sizeof(cmd));
-
-        cmd[0] = 0x00;
-        cmd[1] = 0x01;
-        DisplayValueToLcm(0x0002 + ((i - j) * 2), cmd, 2);
-    }
-
-    memset(cmd, 0x00, sizeof(cmd));
-    i = i - j;
-    for (; (i) < 5; i++) {
-        DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
-        DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
-    }
-
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-//================================================
-// QR Code process
-//================================================
-void ChangeQrCode_Idle(char *input)
-{
-#if defined DD360Audi
-    int len = strlen(input) + 3;
-    int loop = 0;
-    int i = 0, j = 0, k = 0, l = 0;
-    uint8_t qrUrl[128] = {0};
-    uint16_t urlLen = 0;
-    uint8_t cmd[len];
-    uint8_t tmpBuf[15] = {0};
-    //uint8_t tmpLen = sizeof(tmpBuf) - 1;
-
-    strncpy((char *)cmd, " ", len);
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-        l = loop - 1;
-        if (len >= 25) {
-            if (i >= 16 && i <= 19) {
-                tmpBuf[k++] = input[l];
-                //printf("tmpBuf = %s\r\n", tmpBuf);
-            } else if (i >= 21 && i <= 23) {
-                tmpBuf[k++] = input[l];
-            }
-        }
-    }
-    tmpBuf[k] = '\0';
-    //printf("tmpBuf = %s\r\n", tmpBuf);
-    j += sprintf((char *)&cmd[i], ":%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    cmd[len - 1] = '\0';
-    urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
-    qrUrl[urlLen] = '\0';
-    //printf("qr url = %s\r\n", qrUrl);
-    DisplayValueToLcm(__qr_code, qrUrl, urlLen);
-
-    j = 0;
-    j += sprintf((char *)&tmpBuf[k], "0%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    tmpBuf[k + j] = '\0';
-
-    //if (len < 25) {
-    //    strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-    //}
-    //tmpBuf[tmpLen] = '\0';
-    DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-
-    /*if (len > sizeof(tmpBuf)) {
-        strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-
-        memset(tmpBuf, 0, sizeof(tmpBuf));
-        strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    } else {
-        DisplayValueToLcm(__custStationIdL1, cmd, len);
-
-        strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    }*/
-
-#else
-    int len = strlen(input);
-    byte cmd[len];
-
-    int loop = 0;
-    int i = 0;
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-    }
-
-    DisplayValueToLcm(__qr_code, cmd, len);
-#endif defined DD360Audi
-}
-
-void ChangeQrCode_Charge(char *input)
-{
-#if defined DD360Audi
-    int len = strlen(input) + 3;
-    int loop = 0;
-    int i = 0, j = 0, k = 0, l = 0;
-    uint8_t qrUrl[128] = {0};
-    uint16_t urlLen = 0;
-    uint8_t cmd[len];
-    uint8_t tmpBuf[15] = {0};
-    //uint8_t tmpLen = sizeof(tmpBuf) - 1;
-
-    strncpy((char *)cmd, " ", len);
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-        l = loop - 1;
-        if (len >= 25) {
-            if (i >= 16 && i <= 19) {
-                tmpBuf[k++] = input[l];
-                //printf("tmpBuf = %s\r\n", tmpBuf);
-            } else if (i >= 21 && i <= 23) {
-                tmpBuf[k++] = input[l];
-            }
-        }
-    }
-    tmpBuf[k] = '\0';
-    //printf("tmpBuf = %s\r\n", tmpBuf);
-    j += sprintf((char *)&cmd[i], ":%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    cmd[len - 1] = '\0';
-    urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
-    qrUrl[urlLen] = '\0';
-    DisplayValueToLcm(__qr_code, qrUrl, urlLen);
-
-    j = 0;
-    j += sprintf((char *)&tmpBuf[k], "0%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
-    tmpBuf[k + j] = '\0';
-
-    if (len < 25) {
-        strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-    }
-    //tmpBuf[tmpLen] = '\0';
-    DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-    /*if (len > sizeof(tmpBuf)) {
-        strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
-
-        memset(tmpBuf, 0, sizeof(tmpBuf));
-        strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    } else {
-        DisplayValueToLcm(__custStationIdL1, cmd, len);
-
-        strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
-        tmpBuf[tmpLen] = '\0';
-        DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
-    }*/
-
-#else
-    int len = strlen(input);
-    byte cmd[len];
-
-    int loop = 0;
-    int i = 0;
-
-    while (input[loop] != '\0') {
-        cmd[i++] = input[loop++];
-    }
-
-    DisplayValueToLcm(__qr_code_pre, cmd, len);
-#endif //defined DD360Audi
-}
-
-//================================================
-// Change current page
-//================================================
-void ChangeCurPage()
-{
-    //PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
-    if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex) {
-        _currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
-        ChangeToOtherPage(_currentPage);
-        _everyPageRollChange = 0;
-    }
-}
-
-//================================================
-// Main process
-//================================================
-byte demoCount = 0;
-void DemoFunction()
-{
-    if (demoCount == 0) {
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount = 6;
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[0][0], "000001", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[1][0], "000002", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[2][0], "000003", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[3][0], "000004", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[4][0], "000005", 7);
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[5][0], "000006", 7);
-    } else {
-        if (demoCount == 20) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_SELECT_GUN; //_LCM_IDLE; ////For Audi
-        } else if (demoCount == 80) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZING;
-        } else if (demoCount == 100) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_COMP;
-        } else if (demoCount == 120) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_FAIL;
-        } else if (demoCount == 140) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_PRE_CHARGE;
-        } else if (demoCount == 180) {
-            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_CHARGING;
-        }
-    }
-
-    if (demoCount < 180) {
-        demoCount++;
-    }
-}
-
-//================================================
-// Main process
-//================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return true;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return true;
-        }
-    }
-
-    return false;
-}
-
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
-{
-    if (target < AC_QUANTITY) {
-        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
-        return true;
-    }
-
-    return false;
-}
-
-/**
- * [ChangeBalanceValue :print balance information]
- * @Author
- * @DateTime 2020-11-26
- */
-static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
-{
-    byte cmd[10] = {0};
-    byte value[10] = {0};
-    uint8_t len = 0;
-    float balance = gAudiCustInfo->PricesInfo[index].Balance;
-
-    if ((balance) == (FAIL_BALANCE_PRICES)) {
-        balance = 0.00;
-    }
-
-    len += sprintf((char *) value, "%.2f", balance);
-    if (len < 6) {
-        sprintf((char *)&value[len], "%s",
-                (byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
-    }
-
-    value[sizeof(value) - 1] = '\0';
-
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(addr, cmd, sizeof(cmd));
-}
-
-void ChangeAcBattMapAndValue(short page)
-{
-    if (page == _LCM_CHARGING) {
-        if (isDiffStatus != _battery_display_ani) {
-            isChangeBattMap = false;
-            isDiffStatus = _battery_display_ani;
-        }
-
-        if (ac_chargingInfo[0]->IsCharging && !isChangeBattMap) {
-            isChangeBattMap = true;
-            if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
-                ChangeDisplay2Value(__batt_map, _battery_empty);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_EMP;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_20);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV1;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_40);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV2;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_60);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV3;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_80);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV4;
-            } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_100);
-                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-            }
-        }
-    } else if (page == _LCM_COMPLETE) {
-        if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_20);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_20);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_40);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_60);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_80);
-        } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_100);
-        }
-    }
-
-    ChangeDisplay2Value(__soc_value_charging, _disappear);
-}
-
-void ChangeBattMapAndValue(short page, int soc)
-{
-//  srand(time(NULL));
-//  int min = 10;
-//  int max = 90;
-//  soc = rand() % (max - min + 1) + min;
-
-    if (page == _LCM_PRE_CHARGE) {
-        ChangeDisplay2Value(__batt_map_empty, _battery_empty);
-    } else if (page == _LCM_CHARGING) {
-        if (soc < 20) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_empty);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_20);
-            }
-        } else if (soc >= 20 && soc < 40) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_20);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_40);
-            }
-        } else if (soc >= 40 && soc < 60) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_40);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_60);
-            }
-        } else if (soc >= 60 && soc < 80) {
-            if (_battery_display_ani) {
-                ChangeDisplay2Value(__batt_map, _battery_cap_60);
-            } else {
-                ChangeDisplay2Value(__batt_map, _battery_cap_80);
-            }
-        } else if (soc >= 80 && soc <= 100) {
-            ChangeDisplay2Value(__batt_map, _battery_cap_100);
-        }
-    } else if (page == _LCM_COMPLETE) {
-        if (soc < 20) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_20);
-        } else if (soc >= 20 && soc < 40) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_40);
-        } else if (soc >= 40 && soc < 60) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_60);
-        } else if (soc >= 60 && soc < 80) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_80);
-        } else if (soc >= 80 && soc <= 100) {
-            ChangeDisplay2Value(__batt_map, _battery_soc_100);
-        }
-    }
-
-    byte cmd[5];
-    byte value[5];
-
-    memset(cmd, 0x00, sizeof(cmd));
-    memset(value, 0x00, sizeof(value));
-    sprintf((char *)value, "%d%%", soc);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
-}
-
-void ChangeRemainTime(int sec)
-{
-    int h, m, s;
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-//  srand(time(NULL));
-//  int min = 0;
-//  int max = 65536;
-//  sec = rand() % (max - min + 1) + min;
-
-    h = (sec / 3600);
-    m = (sec - (3600 * h)) / 60;
-    s = (sec - (3600 * h) - (m * 60));
-    sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
-}
-
-void ChangeChargingEnergyValue(float energy)
-{
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-    if (energy >= 0.05) {
-        energy -= 0.05;
-    }
-    sprintf((char *) value, "%.1f kWh", energy);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
-}
-
-void ChangeChargingPowerValue(float pow)
-{
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-//  float min = 0.0;
-//  float max = 50;
-//  pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
-    sprintf((char *) value, "%.1f kW", pow);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
-}
-
-void ChangeChargingFeeValue(float fee)
-{
-    byte cmd[10];
-    byte value[10];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-    sprintf((char *) value, "%.2f", fee);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
-}
-
-void DisplayMoneyRate(float money)
-{
-    byte cmd[8];
-    byte value[8];
-
-    memset(cmd, 0x00, sizeof(cmd));
-
-    sprintf((char *) value, "%.2f", money);
-    string2ByteArray(value, cmd);
-    DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
-}
-
-void DisplayMoneyCur(byte *cur)
-{
-    byte cmd[10] = {0};
-    byte buf[10] = {0};
-    uint8_t len = 0;
-
-    *(cur + 3) = '\0';
-    memset(cmd, 0x00, sizeof(cmd));
-    len = sprintf((char *) buf, "%s/kWh", cur);
-    buf[len] = '\0';
-    string2ByteArray(buf, cmd);
-    DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
-}
-
-void RefreshPageAnimation(byte value)
-{
-    switch (_currentPage) {
-    case _LCM_IDLE: {
-
-    }
-    break;
-    case _LCM_WAIT_FOR_PLUG: {
-        if (_everyPageRollChange == 0) {
-            ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
-        } else if (_everyPageRollChange == 15) {
-            ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
-        }
-
-        _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
-    }
-    break;
-    case _LCM_PRE_CHARGE:
-    case _LCM_CHARGING:
-    case _LCM_COMPLETE: {
-        if (_currentPage == _LCM_PRE_CHARGE) {
-            if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
-                ChangeDisplay2Value(__conn_line, _conn_map1);
-            } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
-                ChangeDisplay2Value(__conn_line, _conn_map2);
-            }
-        } else if (_currentPage == _LCM_CHARGING) {
-            if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
-                ChangeDisplay2Value(__conn_line_chag, _charging_map1);
-            } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
-                ChangeDisplay2Value(__conn_line_chag, _charging_map2);
-            }
-        } else if (_currentPage == _LCM_COMPLETE) {
-            if (_everyPageRollChange == 0) {
-                ChangeDisplay2Value(__conn_line_comp, _complete_map);
-            }
-        }
-
-        _everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
-    }
-    break;
-    }
-}
-
-void RefreshConnStatus()
-{
-    // Wifi priority is higher than Ethernet
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    uint8_t i = 0;
-    unsigned char flag[4] = {0};
-
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        //printf("status code = %s\r\n", &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
-            flag[0] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043625", 6) == 0) {
-            //disconnected from AP through WiFi
-            flag[1] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043627", 6) == 0) { //wifi disabled
-            flag[1] = 2;
-            continue;
-        }
-
-        if ((memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033900", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033901", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033902", 6) == 0)) {
-            flag[2] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043626", 6) == 0) {
-            //disconnected from APN through 3G/4G
-            flag[3] = 1;
-            continue;
-        }
-
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043628", 6) == 0) { //4g disabled
-            flag[3] = 2;
-            continue;
-        }
-    }
-
-    if (flag[0] == 1) {
-        ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
-    } else {
-        ChangeDisplay2Value(__ethernet_status, _eth_connect);
-    }
-
-    //ChangeDisplay2Value(__wifi_status, _disappear);
-    //ChangeDisplay2Value(__conn_status, _disappear);
-    //ChangeDisplay2Value(__3G4G_status, _disappear);
-
-    if (flag[1] == 1) {
-        ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
-    } else if (flag[1] == 2) {
-        ChangeDisplay2Value(__wifi_status, _disappear);
-    } else {
-        ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        ChangeDisplay2Value(__wifi_status, _wifi_connect);
-    }
-
-    if (flag[2] == 1) {
-        ChangeDisplay2Value(__conn_status, _disconnect);
-    } else {
-        ChangeDisplay2Value(__conn_status, _connect);
-    }
-
-    if (flag[1] == 2) {
-        ChangeDisplay2Value(__3G4G_status, _disappear);
-        if (flag[3] == 1) {
-            ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
-        } else if (flag[3] == 2) {
-            ChangeDisplay2Value(__3G4G_move_status, _disappear);
-        } else {
-            ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
-        }
-    } else {
-        if (flag[3] == 1) {
-            ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
-        } else if (flag[3] == 2) {
-            ChangeDisplay2Value(__3G4G_status, _disappear);
-        } else {
-            ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
-        }
-    }
-#else
-    if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ||
-            ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP) {
-        _wifi_conn_status = true;
-        ChangeDisplay2Value(__wifi_status, _wifi_connect);
-        ChangeDisplay2Value(__ethernet_status, _disappear);
-    } else {
-        _wifi_conn_status = false;
-        ChangeDisplay2Value(__wifi_status, _disappear);
-    }
-
-    if (!_wifi_conn_status) {
-        if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ||
-                ShmSysConfigAndInfo->SysInfo.InternetConn == YES) {
-            ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
-        } else {
-            ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
-        }
-    }
-
-    // 連線到後台
-    if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES) {
-        ChangeDisplay2Value(__conn_status, _connect);
-    } else {
-        ChangeDisplay2Value(__conn_status, _disconnect);
-    }
-#endif //defined DD360 || defined DD360Audi
-}
-
-byte FirstPageChanged()
-{
-    byte result = NO;
-
-    if (_currentPage != _oldPage) {
-        result = YES;
-        _oldPage = _currentPage;
-    }
-
-    return result;
-}
-
-bool IsPageReloadChk()
-{
-    bool result = false;
-
-    if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
-        if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-            _curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-            result = true;
-        }
-    } else {
-        if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc) {
-            _curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
-            result = true;
-        }
-    }
-
-    return result;
-}
-
-void ProcessPageInfo()
-{
-    _page_reload = IsPageReloadChk();
-
-    switch (_currentPage) {
-#if defined DD360Audi
-    case _LCM_SELECT_GUN: ////For Audi
-        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == 0) {
-            ChangeDisplay2Value(__left_gun_map, _left_gun_enable_map);
-            ChangeDisplay2Value(__right_gun_map, _right_gun_disable_map);
-        } else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == 1) {
-            ChangeDisplay2Value(__left_gun_map, _left_gun_disable_map);
-            ChangeDisplay2Value(__right_gun_map, _right_gun_enable_map);
-        }
-        ChangeDisplay2Value(__add_chk_btn, _select_gun_btn);
-        break;
-#endif //defined DD360Audi
-
-    case _LCM_IDLE: {
-        if (ShmSysConfigAndInfo->SysConfig.isRFID) {
-            ChangeDisplay2Value(__main_rfid, _main_rfid);
-        } else {
-            ChangeDisplay2Value(__main_rfid, _main_none_rfid);
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
-            ChangeDisplay2Value(__main_qr, _main_qr);
-        } else {
-            ChangeDisplay2Value(__qr_code, _disappear);
-            ChangeDisplay2Value(__main_qr, _main_none_qr);
-            needReloadQr = true;
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.isAPP) {
-            ChangeDisplay2Value(__main_app, _main_app);
-        } else {
-            ChangeDisplay2Value(__main_app, _main_none_app);
-        }
-
-        //if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
-        if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
-            needReloadQr = false;
-            ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
-        }
-        //}
-    }
-    break;
-    case _LCM_AUTHORIZING:
-    case _LCM_AUTHORIZ_COMP:
-    case _LCM_AUTHORIZ_FAIL:
-    case _LCM_WAIT_FOR_PLUG: {
-        FirstPageChanged();
-#if defined DD360Audi
-        if (_currentPage == _LCM_AUTHORIZ_COMP) { ////For Audi
-            ChangeBalanceValue(__balance, ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-        }
-#endif //defined DD360Audi
-    }
-    break;
-    case _LCM_PRE_CHARGE:
-    case _LCM_CHARGING:
-    case _LCM_COMPLETE: {
-
-        bool isShowAc = false;
-        if (acgunCount > 0) {
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                isShowAc = true;
-                ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_light);
-
-                if (_currentPage == _LCM_CHARGING) {
-                    ChangeAcBattMapAndValue(_LCM_CHARGING);
-                    if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
-                            ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                    }
-
-                    if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == 0) {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
-                    } else {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
-                    }
-                } else if (_currentPage == _LCM_COMPLETE) {
-                    ChangeAcBattMapAndValue(_LCM_COMPLETE);
-                    if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
-                            ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-
-                    if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
-                            ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
-
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
-                                ac_chargingInfo[0]->ChargingFee >= 0) {
-                            ChangeChargingFeeValue(ac_chargingInfo[0]->ChargingFee);
-                        }
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            ChangeChargingFeeValue(0);
-                        }
-                    }
-
-                    if (!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                        ChangeDisplay2Value(__charging_fee_map, _disappear);
-                        ChangeDisplay2Value(__charging_fee_tx, _disappear);
-                    } else {
-                        ChangeDisplay2Value(__charging_fee_map, _money_map);
-                    }
-                }
-            } else {
-                ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_dark);
-            }
-        } else {
-            ChangeDisplay2Value(__gun_type_index + (2 * 2), _disappear);
-        }
-
-        for (byte i = 0; i < _totalCount; i++) {
-            switch (_chargingInfoData[i]->Type) {
-            case _Type_Chademo: {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_light_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
-                    }
-                } else {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_dark_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
-                    }
-                }
-            }
-            break;
-            case _Type_GB: {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_light_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
-                    }
-                } else {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_dark_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
-                    }
-                }
-            }
-            break;
-            case _Type_CCS_2: {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_light_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
-                    }
-                } else {
-                    if (_currentPage == _LCM_COMPLETE) {
-                        ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_dark_cmp);
-                    } else {
-                        ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
-                    }
-                }
-            }
-            break;
-            }
-
-            if (_currentPage == _LCM_PRE_CHARGE && !isShowAc) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
-                    ChangeBattMapAndValue(_currentPage, _chargingInfoData[i]->EvBatterySoc);
-                }
-            } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
-                    ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
-                    if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
-                            _chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
-                            _chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-
-                    if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
-                            _chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                    }
-
-                    if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0) {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
-                    } else {
-                        ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
-                    }
-                }
-            } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
-                    ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
-                    if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
-                            _chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC) {
-                        ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
-                    } else {
-                        ChangeRemainTime(0);
-                    }
-
-                    if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
-                            _chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW) {
-                        ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
-                    } else {
-                        ChangeChargingPowerValue(0);
-                    }
-#if 1
-                    if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
-                            _chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
-                        ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
-                                _chargingInfoData[i]->ChargingFee >= 0) {
-                            ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
-                            ChangeBalanceValue(__remain_balance, i);
-                        }
-                    } else {
-                        ChangeChargingEnergyValue(0);
-                        if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                            ChangeChargingFeeValue(0);
-                            ChangeBalanceValue(__remain_balance, i);
-                        }
-                    }
-#else
-                    ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-
-                    if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
-                            _chargingInfoData[i]->ChargingFee >= 0) {
-                        ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
-                        ChangeBalanceValue(__remain_balance, i);
-                    }
-#endif // 0
-                    if (!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-                        ChangeDisplay2Value(__charging_fee_map, _disappear);
-                        ChangeDisplay2Value(__charging_fee_tx, _disappear);
-                    } else {
-                        ChangeDisplay2Value(__charging_fee_map, _money_map);
-                    }
-                }
-            }
-        }
-
-        // gun btn and QR code
-        if (_totalCount + acgunCount >= 2 && _currentPage) {
-            byte index = 0;
-            for (index = 0; index < _totalCount; index++) {
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index) {
-                    break;
-                }
-            }
-
-            if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
-                    _chargingInfoData[index]->SystemStatus == S_RESERVATION ||
-                    _chargingInfoData[index]->SystemStatus == S_BOOTING) {
-                if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
-                    if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
-                        needReloadQr = false;
-                        ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
-                    }
-                }
-            }
-        }
-    }
-    break;
-
-    case _LCM_FIX:
-        if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
-            ChangeDisplay2Value(_emergency_map, _emergency_disable_map);
-        } else {
-            ChangeDisplay2Value(_emergency_map, _disappear);
-        }
-        break;
-    }
-}
-
-void ChangeDisplayMoneyInfo()
-{
-    uint8_t curGun = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-
-    if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
-        struct timeb csuTime;
-        struct tm *tmCSU;
-
-        ftime(&csuTime);
-        tmCSU = localtime(&csuTime.time);
-
-        ChangeDisplay2Value(__money_rate_map, _charging_money);
-        if (gAudiCustInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
-            DisplayMoneyRate(gAudiCustInfo->PricesInfo[curGun].UserPrices);
-        } else {
-            if (tmCSU->tm_hour <= 23) {
-                ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
-                DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
-            }
-
-            if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53) {
-                DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
-            }
-        }
-    } else {
-        ChangeDisplay2Value(__money_rate_map, _disappear);
-        ChangeDisplay2Value(__money_by_rate, _disappear);
-        ChangeDisplay2Value(__money_rate, _disappear);
-    }
-}
-
-void Initialization()
-{
-    bool isPass = false;
-    byte count = 5;
-    while (!isPass && count > 0) {
-        isPass = true;
-        for (byte _index = 0; _index < _totalCount; _index++) {
-            if (!FindChargingInfoData(_index, &_chargingInfoData[0])) {
-                DEBUG_ERROR("LcmComm (main) : FindChargingInfoData false \n");
-                isPass = false;
-                count--;
-                break;
-            }
-        }
-
-        sleep(1);
-    }
-
-    isPass = false;
-
-    if (acgunCount > 0) {
-        while (!isPass) {
-            isPass = true;
-            for (byte _index = 0; _index < acgunCount; _index++) {
-                if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
-                    DEBUG_ERROR("LcmComm : FindAcChargingInfoData false \n");
-                    isPass = false;
-                    break;
-                }
-            }
-
-            sleep(1);
-        }
-    }
-
-    if (count == 0) {
-        PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
-    }
-}
-
-int main(void)
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    _port = CreateCommunicationLcmPort();
-    byte changeWarningPriority = 0;
-    byte curWarningCount = 255;
-    ChangeBackLight(true);
-    _totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-    acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-    Initialization();
-
-    //ChangeToOtherPage(_LCM_COMPLETE);
-    //return 0;
-
-    for (byte i = 0; i < 3; i++) {
-        ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
-    }
-
-    while (_port != -1) {
-        if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName) != 0x00) {
-            GetCurrentPage();
-            sleep(1);
-        } else {
-            //DemoFunction();
-
-            // Warning 處理
-            if (curWarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount) {
-                changeWarningPriority = 0;
-                ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
-                curWarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-                ChangeWarningFunc();
-            } else if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 5 && changeWarningPriority == 0) {
-                // 當有兩頁 Warning 則每隔三秒改變一次
-                if (ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0) {
-                    ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
-                } else {
-                    ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
-                }
-
-                ChangeWarningFunc();
-            }
-
-            // 頁面資訊處理
-            ProcessPageInfo();
-
-            // 網路 - wifi - 連線訊號處理
-            RefreshConnStatus();
-
-            // 換頁處理
-            ChangeCurPage();
-
-            RefreshPageAnimation(_everyPageRollChange);
-
-            //if (changeWarningPriority == 0) { ////For Audi
-            ChangeDisplayMoneyInfo();
-            //}
-
-            changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
-            changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
-            usleep(100000);
-        }
-    }
-
-    CloseCommunicationLcmPort();
-
-    return FAIL;
-}

+ 0 - 517
EVSE/Projects/DD360Audi/Apps/Module_PrimaryComm.c

@@ -1,517 +0,0 @@
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    "../../define.h"
-#include    "PrimaryComm.h"
-#include    <stdbool.h>
-
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define PASS                1
-#define FAIL                -1
-#define YES                 1
-#define NO                  0
-
-typedef unsigned char       byte;
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-
-void trim(char *s);
-int mystrcmp(char *p1, char *p2);
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt);
-void split(char **arr, char *str, const char *del);
-
-int Uart1Fd;
-char *priPortName = "/dev/ttyS1";
-Ver ver;
-Gpio_in gpio_in;
-Rtc rtc;
-
-struct timeval _flash_time;
-byte flash = NO;
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-unsigned char ChillerSwitch;
-unsigned int ChillerOnTime;
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    DEBUG_INFO("%s \n", buffer);
-}
-//=================================
-// Common routine
-//=================================
-char *getTimeString(void)
-{
-    char *result = malloc(21);
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-
-    return result;
-}
-
-void trim(char *s)
-{
-    int i = 0, j, k, l = 0;
-
-    while ((s[i] == ' ') || (s[i] == '\t') || (s[i] == '\n')) {
-        i++;
-    }
-
-    j = strlen(s) - 1;
-    while ((s[j] == ' ') || (s[j] == '\t') || (s[j] == '\n')) {
-        j--;
-    }
-
-    if (i == 0 && j == strlen(s) - 1) { }
-    else if (i == 0) { s[j + 1] = '\0'; }
-    else {
-        for (k = i; k <= j; k++) { s[l++] = s[k]; }
-        s[l] = '\0';
-    }
-}
-
-int mystrcmp(char *p1, char *p2)
-{
-    while (*p1 == *p2) {
-        if (*p1 == '\0' || *p2 == '\0') {
-            break;
-        }
-        p1++;
-        p2++;
-    }
-    if (*p1 == '\0' && *p2 == '\0') {
-        return (PASS);
-    } else {
-        return (FAIL);
-    }
-}
-
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
-{
-    strncpy(dest, src + start, cnt);
-    dest[cnt] = 0;
-}
-
-void split(char **arr, char *str, const char *del)
-{
-    char *s = strtok(str, del);
-
-    while (s != NULL) {
-        *arr++ = s;
-        s = strtok(NULL, del);
-    }
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //creat ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-#endif
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-#ifdef ShmPrimaryMcuData
-        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-#endif
-        result = FAIL;
-    }
-
-    return result;
-}
-
-//================================================
-// Function
-//================================================
-void GetFwAndHwVersion()
-{
-    if (Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS) {
-        //PRINTF_FUNC("Primary FW Rev = %s \n", ver.Version_FW);
-        strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
-    }
-
-    if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-        ;//PRINTF_FUNC("Primary HW Rev  = %s \n", ver.Version_HW);
-}
-
-void GetInputGpioStatus()
-{
-    //PRINTF_FUNC("GetInputGpioStatus \n");
-    if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-        ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-#else
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
-        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
-#endif //!defined DD360 && !defined DD360Audi
-
-        ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
-
-        ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
-        ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
-        ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
-        /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
-        ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-        ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-        printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-        printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-        */
-        //PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
-        //PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
-        //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
-            DEBUG_ERROR("AC Mainbreaker occur. \n");
-        }
-#endif //!defined DD360 && !defined DD360Audi
-    }
-}
-
-void SetOutputGpio(byte flash)
-{
-    Gpio_out gpio;
-    gpio.Button_LED[0] = flash;
-    gpio.Button_LED[1] = flash;
-
-    gpio.System_LED[0] = 0x00;
-    gpio.System_LED[1] = 0x00;
-    gpio.System_LED[2] = 0x00;
-    gpio.System_LED[3] = 0x00;
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    if ((ChargingData[0]->PresentChargingCurrent) >= 150) {
-        ChillerSwitch = 1;
-        ChillerOnTime = time((time_t *)NULL);
-    } else {
-        if (ChillerSwitch == 1) {
-            if ((ChargingData[0]->PresentChargingCurrent) >= 100) {
-                ChillerSwitch = 1;
-                ChillerOnTime = time((time_t *)NULL);
-            } else {
-                if ((time((time_t *)NULL) - ChillerOnTime) >= 600) {
-                    ChillerSwitch = 0;
-                } else {
-                    ChillerSwitch = 1;
-                }
-            }
-        } else {
-            ChillerSwitch = 0;
-        }
-    }
-    gpio.AC_Connector = ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
-
-    //printf("ChargingData[0]->PresentChargingCurrent=%f,ChargingData[1]->PresentChargingCurrent=%f,ChillerSwitch=%d\n",ChargingData[0]->PresentChargingCurrent,ChargingData[1]->PresentChargingCurrent,ChillerSwitch);
-#else
-    gpio.AC_Connector = 0x00;
-#endif //defined DD360 || DD360Audi
-
-    gpio.AC_Breaker = 0x00;
-
-    if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS) {
-        //PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
-    } else {
-        //PRINTF_FUNC("SetOutputGpio fail. \n");
-    }
-}
-
-void SetRtcData()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-//  PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//          tmCSU->tm_sec);
-
-    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
-
-    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
-
-    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
-
-    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
-
-    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
-
-    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
-
-    if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS) {
-        //PRINTF_FUNC("SetRtc sucessfully. \n");
-    } else {
-        //PRINTF_FUNC("SetRtc fail. \n");
-    }
-}
-
-//================================================
-// Main process
-//================================================
-int InitComPort()
-{
-    int fd;
-    struct termios tios;
-
-    fd = open(priPortName, O_RDWR);
-    if (fd <= 0) {
-#ifdef SystemLogMessage
-        DEBUG_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;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char)1;
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl (fd, TCSETS, &tios);
-
-    return fd;
-}
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-int main(void)
-{
-    if (InitShareMemory() == FAIL) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitShareMemory NG\n");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-        if (!FindChargingInfoData(_index, &ChargingData[0])) {
-            DEBUG_ERROR("FindChargingInfoData false \n");
-            break;
-        }
-    }
-    ChillerSwitch = 0;
-    Uart1Fd = InitComPort();
-    //PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
-
-    if (Uart1Fd < 0) {
-#ifdef SystemLogMessage
-        DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
-#endif
-
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    SetRtcData();
-    gettimeofday(&_flash_time, NULL);
-    for (;;) {
-        if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
-            if ((GetTimeoutValue(_flash_time) / 1000) > 1000) {
-                if (flash == NO) {
-                    flash = YES;
-                } else {
-                    flash = NO;
-                }
-                SetOutputGpio(flash);
-                gettimeofday(&_flash_time, NULL);
-            }
-        } else {
-            if ((GetTimeoutValue(_flash_time) / 1000) > 5000) {
-                if (flash == NO) {
-                    flash = YES;
-                }
-
-                SetOutputGpio(flash);
-                gettimeofday(&_flash_time, NULL);
-            }
-        }
-
-        // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-        // 模組更新 FW 後,需重新做
-        if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
-            //PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
-            GetFwAndHwVersion();
-            sleep(1);
-            ShmPrimaryMcuData->SelfTest_Comp = PASS;
-        } else {
-            GetInputGpioStatus();
-        }
-
-        usleep(100000);
-    }
-
-    return FAIL;
-}

+ 102 - 113
EVSE/Projects/DD360Audi/Apps/OutputTask.h

@@ -1,7 +1,7 @@
 /*
  * OutputTask.h
  *
- *  Created on: 2020¦~2¤ë25¤é
+ *  Created on: 2020年2月25日
  *      Author: 7564
  */
 
@@ -9,47 +9,47 @@
 #define OUTPUTTASK_H_
 
 
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
+#include    <sys/time.h>
+#include    <sys/timeb.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
+#include    <sys/types.h>
+#include    <sys/ioctl.h>
+#include    <sys/socket.h>
+#include    <sys/ipc.h>
+#include    <sys/shm.h>
+#include    <sys/shm.h>
+#include    <sys/mman.h>
+#include    <linux/wireless.h>
+#include    <linux/can.h>
+#include    <linux/can/raw.h>
+#include    <arpa/inet.h>
+#include    <netinet/in.h>
+
+#include    <unistd.h>
+#include    <stdarg.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 #include    <unistd.h>
 #include    <fcntl.h>
 #include    <termios.h>
 #include    <errno.h>
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include 	<stdbool.h>
-
-#define ShmTestKey	2001
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-#define PRESS				1
-#define RELEASE				0
+#include    <errno.h>
+#include    <string.h>
+#include    <time.h>
+#include    <ctype.h>
+#include    <ifaddrs.h>
+#include    <stdbool.h>
+
+#define ShmTestKey  2001
+
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
+#define PRESS               1
+#define RELEASE             0
 #define MAX_PSU_QUANTITY        62
 
 int Uart1Fd = -1;
@@ -69,106 +69,95 @@ unsigned char isGetCount = NO;
 float VOLTAGE;
 float CURRENT;
 
-struct PsuModuleInfo
-{
-	unsigned int 	PSU_POWER_INFO;
-	float			PSU_VOLTAGE_INFO;
-	unsigned short	PSU_CURRENT_INFO;
+struct PsuModuleInfo {
+    unsigned int    PSU_POWER_INFO;
+    float           PSU_VOLTAGE_INFO;
+    unsigned short  PSU_CURRENT_INFO;
 };
 
-struct UnSafeData
-{
-	unsigned char 			PSU_COUNT;
-	struct PsuModuleInfo 	PsuModule[MAX_PSU_QUANTITY];
-	unsigned int 			PSU_POWER;
-	float					PSU_VOLTAGE;
-	unsigned short			PSU_CURRENT;
+struct UnSafeData {
+    unsigned char           PSU_COUNT;
+    struct PsuModuleInfo    PsuModule[MAX_PSU_QUANTITY];
+    unsigned int            PSU_POWER;
+    float                   PSU_VOLTAGE;
+    unsigned short          PSU_CURRENT;
 };
 
-struct UnSafeData			*UnSafeDataInfo;
+struct UnSafeData           *UnSafeDataInfo;
 
-typedef struct GPIO_IN
-{
-	unsigned char AC_Connector;
-	unsigned char AC_MainBreaker;
-	unsigned char SPD;
-	unsigned char Door_Open;
-	unsigned char GFD[2];
-	unsigned char AC_Drop;
-	unsigned char Emergency_IO;
-
-	unsigned char Emergency_Btn;
-	unsigned char Button[2];
-	unsigned char Key[4];
-}Gpio_in;
+typedef struct GPIO_IN {
+    unsigned char AC_Connector;
+    unsigned char AC_MainBreaker;
+    unsigned char SPD;
+    unsigned char Door_Open;
+    unsigned char GFD[2];
+    unsigned char AC_Drop;
+    unsigned char Emergency_IO;
+
+    unsigned char Emergency_Btn;
+    unsigned char Button[2];
+    unsigned char Key[4];
+} Gpio_in;
 
 Gpio_in gpio_in;
 
-enum CHARGING_MODE
-{
-	CHARGING_MODE_STOP = 			0x00,
-	CHARGING_MODE_START = 			0x01,
-	CHARGING_MODE_TERMINATING = 	0x10,
+enum CHARGING_MODE {
+    CHARGING_MODE_STOP =            0x00,
+    CHARGING_MODE_START =           0x01,
+    CHARGING_MODE_TERMINATING =     0x10,
 };
 
 unsigned char _charging_mode = CHARGING_MODE_STOP;
 
-int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+int tranceive(int fd, unsigned char *cmd, unsigned char cmd_len, unsigned char *rx)
 {
-	int len;
-	tcflush(fd,TCIOFLUSH);
-	if(write(fd, cmd, cmd_len) >= cmd_len)
-	{
-		usleep(50000);
-		len = read(fd, rx, 512);
-	}
-	else
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
-		#endif
-	}
-
-	return len;
+    int len;
+    tcflush(fd, TCIOFLUSH);
+    if (write(fd, cmd, cmd_len) >= cmd_len) {
+        usleep(50000);
+        len = read(fd, rx, 512);
+    } else {
+#ifdef SystemLogMessage
+        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+#endif
+    }
+
+    return len;
 }
 
 unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, 0x0a, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 0)
-	{
-		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
-		{
-			chksum ^= rx[6+idx];
-		}
-
-		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
-		   (rx[2] == tx[1]) &&
-		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]))
-		{
-			Ret_Buf->Button[0] 			= (rx[7] >> 1) & 0x01;
-			Ret_Buf->Button[1] 			= (rx[7] >> 2) & 0x01;
-
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, 0x0a, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if (len > 0) {
+        for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++) {
+            chksum ^= rx[6 + idx];
+        }
+
+        if ((chksum == rx[6 + (rx[4] | rx[5] << 8)]) &&
+                (rx[2] == tx[1]) &&
+                (rx[1] == tx[2]) &&
+                (rx[3] == tx[3])) {
+            Ret_Buf->Button[0]          = (rx[7] >> 1) & 0x01;
+            Ret_Buf->Button[1]          = (rx[7] >> 2) & 0x01;
+
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 void GetInputGpioStatus()
 {
-	if (Query_Gpio_Input(Uart1Fd, 0x04, &gpio_in) == PASS)
-	{
-		Button1 = gpio_in.Button[0];
-		Button2 = gpio_in.Button[1];
-	}
+    if (Query_Gpio_Input(Uart1Fd, 0x04, &gpio_in) == PASS) {
+        Button1 = gpio_in.Button[0];
+        Button2 = gpio_in.Button[1];
+    }
 }
 
 #endif /* OUTPUTTASK_H_ */

+ 0 - 76
EVSE/Projects/DD360Audi/Apps/PrimaryComm.h

@@ -1,76 +0,0 @@
-#ifndef PRIMARYCOMM_H_
-#define PRIMARYCOMM_H_
-
-extern struct Address {
-    unsigned char Aux;
-    unsigned char Fan;
-    unsigned char Relay;
-    unsigned char IoExtend;
-    unsigned char Broadcast;
-} Addr;
-
-extern struct Command {
-    unsigned char query_FW_Ver;         //0x01
-    unsigned char query_HW_Ver;     //0x02
-    unsigned char query_Gpio_In;        //0x0a
-    unsigned char query_charging_power; // 0x2C
-
-    unsigned char config_Model_Name;            //0x83
-    unsigned char config_Gpio_Output;   //0x86
-    unsigned char config_Rtc_Data;      //0x87
-
-    unsigned char update_Start;     //0xe0
-    unsigned char update_Abort;     //0xe1
-    unsigned char update_Transfer;      //0xe2
-    unsigned char update_Finish;        //0xe3
-
-} Cmd;
-
-typedef struct Verion {
-    char Version_FW[16];
-    char Version_HW[16];
-} Ver;
-
-typedef struct GPIO_IN {
-    unsigned char AC_Connector;
-    unsigned char AC_MainBreaker;
-    unsigned char SPD;
-    unsigned char Door_Open;
-    unsigned char GFD[2];
-    unsigned char AC_Drop;
-    unsigned char Emergency_IO;
-
-    unsigned char Emergency_Btn;
-    unsigned char Button[2];
-    unsigned char Key[4];
-} Gpio_in;
-
-typedef struct GPIO_OUT {
-    unsigned char Button_LED[2];
-    unsigned char System_LED[4];
-    unsigned char AC_Connector;
-    unsigned char AC_Breaker;
-} Gpio_out;
-
-typedef struct RTC {
-    unsigned char RtcData[14];
-} Rtc;
-
-extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
-
-extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
-extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
-unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
-// 13 bytes
-// year : 4, month : 2, day : 2, hour : 2, min : 2, sec : 2
-//extern unsigned char Config_RTC();
-
-extern unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32);
-extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
-extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
-extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
-
-
-#endif /* PRIMARYCOMM_H_ */

+ 0 - 6608
EVSE/Projects/DD360Audi/Apps/ReMain.c

@@ -1,6608 +0,0 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/timeb.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/mman.h>
-#include <linux/wireless.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdio.h>      /*標準輸入輸出定義*/
-#include <stdlib.h>     /*標準函數庫定義*/
-#include <unistd.h>     /*Unix 標準函數定義*/
-#include <fcntl.h>      /*檔控制定義*/
-#include <termios.h>    /*PPSIX 終端控制定義*/
-#include <errno.h>      /*錯誤號定義*/
-#include <errno.h>
-#include <string.h>
-#include <stdint.h>
-#include <time.h>
-#include <ctype.h>
-#include <ifaddrs.h>
-#include <math.h>
-#include "../../define.h"
-#include "Config.h"
-#include <stdbool.h>
-#include <dirent.h>
-#include "timeout.h"
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-#include "AudiCust.h"
-#endif //defined DD360Audi
-
-#define ARRAY_SIZE(A)                           (sizeof(A) / sizeof(A[0]))
-#define PASS                                    1
-#define FAIL                                    -1
-#define MODELNAME_FAIL                          0
-#define BUFFER_SIZE                             128
-#define YES                                     1
-#define NO                                      0
-#define NORMAL                                  0
-#define ABNORMAL                                1
-#define EQUAL                                   0
-#define BTN_RELEASE                             0
-#define BTN_PRESS                               1
-#define MAX_BUF                                 64
-#define MtdBlockSize                            0x600000
-#define SYSFS_GPIO_DIR                          "/sys/class/gpio"
-#define UPGRADE_FAN                             0x02
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-#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 NO_DEFINE                               255
-#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
-
-typedef struct StLedConfig {
-    //OutputDrvValue[0]
-    uint8_t LeftButtonLed: 1;                   //bit 0,    H: ON,      L:OFF
-    uint8_t RightButtonLed: 1;                  //bit 1,    H: ON,      L:OFF
-    uint8_t GreenLED: 1;                        //bit 2,    H: ON,      L:OFF
-    uint8_t YellowLED: 1;                       //bit 3,    H: ON,      L:OFF
-    uint8_t RedLED: 1;                          //bit 4,    H: ON,      L:OFF
-    uint8_t SystemLed4: 1;                      //bit 5,    H: ON,      L:OFF
-    uint8_t AcContactor: 1;                     //bit 6,    H: ON,      L:OFF
-    uint8_t Reserved: 1;                        //bit 7 reserved
-} LedConfig;
-
-char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-int whileLoopTime = 10000; // 10 ms
-int wtdFd = -1;
-byte _authorizeIndex = NO_DEFINE;
-
-bool IsAuthorizingMode();
-void ClearAuthorizedFlag();
-bool isDetectPlugin();
-void ClearDetectPluginFlag();
-int mystrcmp(unsigned char *p1, unsigned char *p2);
-
-long long DiffTimebWithNow(struct timeb ST);
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
-void ChargingTerminalProcess(byte gunIndex);
-void ChkPrimaryStatus();
-void StartSystemTimeoutDet(unsigned char flag);
-void StopSystemTimeoutDet();
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
-void StopGunInfoTimeoutDet(unsigned char gunIndex);
-int StoreLogMsg_1(const char *fmt, ...);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-void gpio_set_value(unsigned int gpio, unsigned int value);
-void PRINTF_FUNC(char *string, ...);
-void ChangeGunSelectByIndex(byte sel);
-void InformOcppErrOccur(byte codeType);
-
-void RecordAlarmCode(byte gunIndex, char *code);
-void RecordWarningCode(byte gunIndex, char *code);
-void ReleaseWarningCodeByString(byte gunIndex, char *code);
-void ReleaseAlarmCode(byte gunIndex);
-
-int DB_Open(sqlite3 *db);
-int DB_Insert_Record(sqlite3 *db, int gun_index);
-int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
-int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
-
-#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)
-#define log_error(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct PsuData                  *ShmPsuData;
-struct CHAdeMOData              *ShmCHAdeMOData;
-struct GBTData                  *ShmGBTData;
-struct CcsData                  *ShmCcsData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
-struct FanModuleData            *ShmFanModuleData;
-struct RelayModuleData          *ShmRelayModuleData;
-struct LedModuleData            *ShmLedModuleData;
-struct OCPP16Data               *ShmOCPP16Data;
-
-struct ChargingInfoData         *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData         *ac_chargingInfo[AC_QUANTITY];
-struct timeb                    startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeb                    endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-static AudiCustInfo             *gAudiCustInfo = NULL; //Jerry add
-#endif //defined DD360Audi
-
-// for initial index to check EV board type is correct
-byte _gunIndex = 0;
-byte _acgunIndex = 0;
-byte _chademoIndex = 0;
-byte _ccsIndex = 0;
-byte _gb_Index = 0;
-byte _ac_Index = 0;
-byte bd0_1_status = 0;
-byte bd0_2_status = 0;
-byte bd1_1_status = 0;
-byte bd1_2_status = 0;
-
-static uint8_t restartFlag = 0;
-
-bool isCardScan = false;
-bool isModelNameMatch = true;
-
-int rfidFd = -1;
-char *rfidPortName = "/dev/ttyS2";
-char *fwVersion = "V1.07.00.0000.00"; // "V0.16.00.0000.00";
-
-sqlite3 *localDb;
-bool isDb_ready;
-
-#if defined DD360Audi
-//------------------------------------------------------------------------------
-//--- share memory value ---
-//------------------------------------------------------------------------------
-static void changeLcmPage(uint8_t index)
-{
-    ShmSysConfigAndInfo->SysInfo.SystemPage = index;
-}
-
-static uint8_t getCurLcmPage(void)
-{
-    return ShmSysConfigAndInfo->SysInfo.SystemPage;
-}
-
-//------------------------------------------------------------------------------
-static void destroySelGun(uint8_t curGun)
-{
-    uint8_t i = 0;
-    uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-
-    //for status timeout
-    if (curGun == DESTROY_ALL_SEL) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
-        log_info("destroy all gun = %d, %d\r\n",
-                 gAudiCustInfo->SelGunInfo.LeftGun,
-                 gAudiCustInfo->SelGunInfo.RightGun);
-        for (i = 0; i < totalGun; i++) {
-            StopGunInfoTimeoutDet(i);
-            memset(&gAudiCustInfo->PricesInfo[i], 0, sizeof(PricesInfo));
-        }
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-        //changeLcmPage(_LCM_SELECT_GUN);
-        return;
-    }
-
-    //for charging timeout or complete
-    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
-        if (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
-                gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
-            changeLcmPage(_LCM_SELECT_GUN);
-        }
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
-        StopGunInfoTimeoutDet(LEFT_GUN_NUM);
-        if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
-            ClearAuthorizedFlag();
-        }
-
-        log_info("destroy left gun, cur page = %d\r\n", getCurLcmPage());
-        if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
-            log_info("clear left balance\r\n");
-            memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
-            gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
-        }
-    }
-
-    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
-        if (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
-                gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
-            changeLcmPage(_LCM_SELECT_GUN);
-        }
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-        StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
-        if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
-            ClearAuthorizedFlag();
-        }
-
-        log_info("destroy right gun, cur page = %d\r\n", getCurLcmPage());
-        if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
-            log_info("clear right balance\r\n");
-            memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
-            gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
-        }
-    }
-}
-
-static int waitRightGunPlugIt(uint8_t curGun)
-{
-    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    }
-
-    return FAIL;
-}
-
-static int waitLeftGunPlugIt(uint8_t curGun)
-{
-    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    }
-
-    return FAIL;
-}
-
-static void setSelGunWaitToAuthor(uint8_t curSel)
-{
-    if (curSel == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
-        //printf("setSelGunWaitToAuthor left\r\n");
-        StopGunInfoTimeoutDet(curSel);
-    } else if (curSel == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
-        //printf("setSelGunWaitToAuthor right\r\n");
-        StopGunInfoTimeoutDet(curSel);
-    }
-}
-
-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))) {
-        return PASS;
-    }
-
-    return FAIL;
-}
-
-static void confirmSelGun(uint8_t selGun)
-{
-    if (selGun == LEFT_GUN_NUM) {
-        gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
-        StopGunInfoTimeoutDet(selGun);
-        //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM) {
-        gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
-        StopGunInfoTimeoutDet(selGun);
-        //printf("confirmSelGun right\r\n");
-    }
-
-    changeLcmPage(_LCM_IDLE);
-
-    StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
-}
-#endif // defined DD360Audi
-
-static void startPrimaryLedIndicatorCtrlFork(void)
-{
-    pid_t pid = fork();
-    if (pid == 0) {
-        uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-        uint8_t gunIndex = 0;
-        int isContinue = 1;
-        LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
-
-        while (isContinue) {
-            for (gunIndex = 0; gunIndex < totalGun; gunIndex++) {
-                //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
-                //printf("level = %d\r\n", ShmSysConfigAndInfo->SysWarningInfo.Level);
-                switch (chargingInfo[gunIndex]->SystemStatus) {
-                case S_BOOTING:
-                    if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
-                        //DoComm tcp disconnect
-                        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;
-                        }
-                        break;
-                    }
-
-                    pLedConfig->RedLED = YES;
-                    pLedConfig->YellowLED = YES;
-                    pLedConfig->GreenLED = YES;
-                    break;
-
-                case S_IDLE:
-                    //DoComm connected and system idle
-                    pLedConfig->RedLED = NO;
-                    pLedConfig->YellowLED = NO;
-                    pLedConfig->GreenLED = YES;
-                    break;
-
-                case S_RESERVATION:
-                case S_AUTHORIZING:
-                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:
-                    //precharging status
-                    if (pLedConfig->GreenLED == YES) {
-                        pLedConfig->GreenLED = NO;
-                    } else {
-                        pLedConfig->GreenLED = YES;
-                    }
-                    break;
-
-                case S_CHARGING:
-                    pLedConfig->RedLED = NO;
-                    if (pLedConfig->YellowLED == YES) {
-                        pLedConfig->YellowLED = NO;
-                    } else {
-                        pLedConfig->YellowLED = YES;
-                    }
-                    pLedConfig->GreenLED = NO;
-                    break;
-
-                case S_ALARM:
-                case S_TERMINATING:
-                case S_COMPLETE:
-                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        pLedConfig->YellowLED = NO;
-                        pLedConfig->GreenLED = NO;
-                        if (pLedConfig->RedLED == YES) {
-                            pLedConfig->RedLED = NO;
-                        } else {
-                            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 (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                        if (pLedConfig->RedLED == YES) {
-                            pLedConfig->RedLED = NO;
-                        } else {
-                            pLedConfig->RedLED = YES;
-                        }
-                    }
-                    break;
-
-                case S_BOOKING:
-                case S_DEBUG:
-                case S_UPDATE:
-                case S_NONE:
-                    break;
-                }
-
-                usleep(500000);
-            }//switch
-        }//for
-    }//while
-}
-
-//================================================
-// initial can-bus
-//================================================
-int InitCanBus()
-{
-    int                     s0, nbytes;
-    struct timeval          tv;
-    struct ifreq            ifr0;
-    struct sockaddr_can     addr0;
-
-    system("/sbin/ip link set can0 down");
-    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-    system("/sbin/ip link set can0 up");
-
-    s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
-
-    tv.tv_sec = 0;
-    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
-    }
-
-    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;
-    bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
-    return s0;
-}
-
-//================================================
-// initial uart port
-//================================================
-char *_priPortName = "/dev/ttyS1";
-char *_485PortName = "/dev/ttyS5";
-
-int InitComPort(byte target)
-{
-    int fd;
-    struct termios tios;
-
-    if (target == UPGRADE_PRI) {
-        fd = open(_priPortName, O_RDWR);
-    } 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;
-    tios.c_iflag = 0;
-    tios.c_oflag = 0;
-    tios.c_cc[VMIN] = 0;
-    tios.c_cc[VTIME] = (unsigned char)1;
-    tios.c_lflag = 0;
-    tcflush(fd, TCIFLUSH);
-    ioctl (fd, TCSETS, &tios);
-
-    return fd;
-}
-
-//=================================
-// Common routine
-//=================================
-void substr(char *dest, const char *src, unsigned int start, unsigned int cnt)
-{
-    strncpy(dest, src + start, cnt);
-    dest[cnt] = 0;
-}
-
-int InitWatchDog()
-{
-    int fd;
-    system("/usr/bin/fuser -k /dev/watchdog");
-    sleep(1);
-    system("echo V > /dev/watchdog");
-    sleep(1);
-    fd = open("/dev/watchdog", O_RDWR);
-
-    if (fd <= 0) {
-        log_error("System watch dog initial fail.\r\n");
-    }
-    return fd;
-}
-
-int StoreLogMsg_1(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s \n", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int mystrcmp(unsigned char *p1, unsigned char *p2)
-{
-    while (*p1 == *p2) {
-        if (*p1 == '\0' || *p2 == '\0') {
-            break;
-        }
-        p1++;
-        p2++;
-    }
-    if (*p1 == '\0' && *p2 == '\0') {
-        return (PASS);
-    } else {
-        return (FAIL);
-    }
-}
-
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
-    return (StopTime - StartTime);
-}
-
-bool CheckTimeOut(struct timeb ST)
-{
-    struct timeb ET;
-    unsigned int StartTime, StopTime;
-
-    ftime(&ET);
-    StartTime = (unsigned int) ST.time;
-    StopTime = (unsigned int) ET.time;
-    return (StopTime > StartTime) ? YES : NO;
-}
-
-void setChargerMode(byte gun_index, byte mode)
-{
-    chargingInfo[gun_index]->SystemStatus = mode;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-    va_list args;
-    char buffer[4096];
-    va_start(args, string);
-    vsnprintf(buffer, sizeof(buffer), string, args);
-    va_end(args);
-
-    log_info("%s \n", buffer);
-}
-
-long long DiffTimebWithNow(struct timeb ST)
-{
-    //return milli-second
-    struct timeb ET;
-    long long StartTime, StopTime;
-
-    ftime(&ET);
-    StartTime = (long long)ST.time;
-    StopTime = (long long)ET.time;
-    return ((StopTime - StartTime) * 1000) + (ET.millitm - ST.millitm);
-}
-
-//==========================================
-// Log
-//==========================================
-void CheckFwSlotStatusLog()
-{
-    if (bd0_1_status == 0 && bd0_2_status == 1) {
-        PRINTF_FUNC("Connector 1 : Chademo");
-    } else if (bd0_1_status == 1 && bd0_2_status == 0) {
-        PRINTF_FUNC("Connector 1 : CCS");
-    } else if (bd0_1_status == 1 && bd0_2_status == 1) {
-        PRINTF_FUNC("Connector 1 : GB");
-    }
-
-    if (bd1_1_status == 0 && bd1_2_status == 1) {
-        PRINTF_FUNC("Connector 2 : Chademo");
-    } else if (bd1_1_status == 1 && bd1_2_status == 0) {
-        PRINTF_FUNC("Connector 2 : CCS");
-    } else if (bd1_1_status == 1 && bd1_2_status == 1) {
-        PRINTF_FUNC("Connector 2 : GB");
-    }
-}
-
-void CheckHwSlotStatusLog(byte index)
-{
-    if (chargingInfo[index]->Type == _Type_Chademo) {
-        PRINTF_FUNC("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
-                    index, chargingInfo[index]->Evboard_id);
-    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-        PRINTF_FUNC("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
-                    index, chargingInfo[index]->Evboard_id);
-    } else if (chargingInfo[index]->Type == _Type_GB) {
-        PRINTF_FUNC("Hw check : Connector %d, Type : GB, Evboard_id = %d \n",
-                    index, chargingInfo[index]->Evboard_id);
-    }
-}
-
-//==========================================
-// Check interface status
-//==========================================
-int isInterfaceUp(const char *interface)
-{
-    int result = FAIL;
-
-    FILE *fp;
-    char cmd[256];
-    char buf[512];
-
-    strcpy(cmd, "ifconfig");
-    fp = popen(cmd, "r");
-    if (fp != NULL) {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            if (strstr(buf, interface) > 0) {
-                result = PASS;
-            }
-        }
-    }
-    pclose(fp);
-
-    return result;
-}
-
-//=================================
-// Create all share memory
-//=================================
-int CreateShareMemory()
-{
-    int MeterSMId = FAIL;
-
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0))  == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
-
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-
-    memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
-
-    //creat ShmPsuData
-    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmPsuData, 0, sizeof(struct PsuData));
-
-    if (CHAdeMO_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),  IPC_CREAT | 0777)) < 0) {
-            return FAIL;
-        } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-            return FAIL;
-        }
-        memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
-    }
-
-    if (GB_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),  IPC_CREAT | 0777)) < 0) {
-            return FAIL;
-        } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-            return FAIL;
-        }
-        memset(ShmGBTData, 0, sizeof(struct GBTData));
-    }
-
-    //creat ShmCcsData
-    if (CCS_QUANTITY > 0) {
-        if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),  IPC_CREAT | 0777)) < 0) {
-            return FAIL;
-        } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-            return FAIL;
-        }
-        memset(ShmCcsData, 0, sizeof(struct CcsData));
-    }
-
-    //creat ShmPrimaryMcuData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
-
-    //creat ShmFanModuleData
-    if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
-
-    //creat ShmRelayModuleData
-    if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
-
-    if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
-
-    //creat ShmOCPP16Data
-    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    // memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    //creat Audi customization info
-    if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
-        return FAIL;
-    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        return FAIL;
-    }
-    memset(gAudiCustInfo, 0, sizeof(AudiCustInfo));
-#endif //defined DD360Audi
-
-    return PASS;
-}
-
-//=================================
-// LCM Page
-//=================================
-void ChangeLcmByIndex(byte page_index)
-{
-    if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
-            page_index == _LCM_COMPLETE || page_index == _LCM_FIX) {
-        ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
-    }
-}
-
-//======================================================
-// Peripheral initial
-//======================================================
-void InitGPIO()
-{
-    /*****************0~3, 4 bank, bank x 32+ num*********************/
-    /***************************************************************/
-    /*************** GPIO 0 ***************************************/
-    /***************************************************************/
-    /* GPMC_AD8         =>  GPIO0_22 *//*ID BD1_1*/
-    system("echo 22 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio22/direction");
-    /* GPMC_AD9         =>  GPIO0_23 *//*ID BD1_2*/
-    system("echo 23 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio23/direction");
-    /* GPMC_AD10        =>  GPIO0_26 *//*IO BD1_1*/
-    system("echo 26 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio26/direction");
-    system("echo 1 > /sys/class/gpio/gpio26/value");
-    /* GPMC_AD11        =>  GPIO0_27 *//*IO BD1_2*/
-    system("echo 27 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio27/direction");
-    /* RMII1_REF_CLK        =>  GPIO0_29 *//*USB 0 OCP detection*/
-    system("echo 29 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio29/direction");
-    /*XDMA_EVENT_INTR0  =>  GPIO0_19 *//*AM_RFID_RST*/
-    system("echo 19 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio19/direction");
-    system("echo 1 > /sys/class/gpio/gpio19/value");
-    /*XDMA_EVENT_INTR1  =>  GPIO0_20 *//*AM_RFID_ICC*/
-    system("echo 20 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio20/direction");
-    /***************************************************************/
-    /*************** GPIO 1 ***************************************/
-    /***************************************************************/
-    /* GPMC_AD12    =>  GPIO1_12 *//*ID BD2_1*/
-    system("echo 44 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio44/direction");
-    /* GPMC_AD13    =>  GPIO1_13 *//*ID BD2_2*/
-    system("echo 45 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio45/direction");
-    /* GPMC_AD14    =>  GPIO1_14 *//*IO BD2_1*/
-    system("echo 46 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio46/direction");
-    system("echo 0 > /sys/class/gpio/gpio46/value");
-    /* GPMC_AD15    =>  GPIO1_15 *//*IO BD2_2*/
-    system("echo 47 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio47/direction");
-    /***************************************************************/
-    /*************** GPIO 2 ***************************************/
-    /***************************************************************/
-    /*LCD_AC_BIAS_EN    =>  GPIO2_25*//*RS-485 for module DE control*/
-    system("echo 89 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio89/direction");
-    system("echo 1 > /sys/class/gpio/gpio89/value");
-    /*LCD_HSYNC     =>  GPIO2_23*//*RS-485 for module RE control*/
-    system("echo 87 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio87/direction");
-    system("echo 0 > /sys/class/gpio/gpio87/value");
-    /*LCD_PCLK      =>  GPIO2_24*//*CCS communication board 1 proximity*/
-    system("echo 88 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio88/direction");
-    /*LCD_VSYNC     =>  GPIO2_22*//*CCS communication board 2 proximity*/
-    system("echo 86 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio86/direction");
-    /***************************************************************/
-    /*************** GPIO 3 ***************************************/
-    /***************************************************************/
-    /*MCASP0_FSX        =>  GPIO3_15*//*Emergency Stop button detect*/
-    system("echo 111 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio111/direction");
-    /*MCASP0_ACLKR  =>  GPIO3_18*//*USB1 OCP detect*/
-    system("echo 114 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio114/direction");
-    /*MCASP0_AHCLKR =>  GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
-    system("echo 113 > /sys/class/gpio/export");
-    system("echo \"in\" > /sys/class/gpio/gpio113/direction");
-    /*MCASP0_ACLKX  =>  GPIO3_14*//*Ethernet PHY reset*/
-    system("echo 110 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio110/direction");
-    system("echo 0 > /sys/class/gpio/gpio110/value");
-    /* MCASP0_FSR       =>  GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
-    system("echo 115 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio115/direction");
-    system("echo 0 > /sys/class/gpio/gpio115/value");
-    /* MCASP0_AXR0  =>  GPIO3_16 *//*CSU board function OK indicator.*/
-    system("echo 112 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio112/direction");
-    system("echo 1 > /sys/class/gpio/gpio112/value");
-    /* MCASP0_AXR1  =>  GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
-    system("echo 116 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio116/direction");
-    system("echo 0 > /sys/class/gpio/gpio116/value");
-
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    /* (C14) EMU0.gpio3[7] */  /*CP open/short feature enable/disable, pull low for default enable*/
-    system("echo 103 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio103/direction");
-    system("echo 0 > /sys/class/gpio/gpio103/value");
-    /* (B14) EMU1.gpio3[8] */  /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
-    system("echo 104 > /sys/class/gpio/export");
-    system("echo \"out\" > /sys/class/gpio/gpio104/direction");
-    system("echo 0 > /sys/class/gpio/gpio104/value");
-#endif //!defined DD360 && !defined DD360Audi
-
-    log_info("Initial GPIO OK");
-}
-
-int LoadSysConfigAndInfo(struct SysConfigData *ptr)
-{
-    int fd, wrd;
-    unsigned char *buf;
-    unsigned int ChkSum, ChkSumOrg;
-
-    if ((buf = malloc(MtdBlockSize)) == NULL) {
-        log_error("malloc buffer NG,rebooting..\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-    memset(buf, 0, MtdBlockSize);
-
-    //================================================
-    // Load configuration from mtdblock10
-    //================================================
-    fd = open("/dev/mtdblock10", O_RDWR);
-    if (fd < 0) {
-        free(buf);
-        log_error("open mtdblock10 NG,rebooting..\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-
-    wrd = read(fd, buf, MtdBlockSize);
-    close(fd);
-    if (wrd < MtdBlockSize) {
-        free(buf);
-        log_error("read SysConfigData data NG,rebooting..\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-    ChkSum = 0;
-    for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
-        ChkSum += buf[wrd];
-    }
-    memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
-
-    //================================================
-    // Load configuration from mtdblock11
-    //================================================
-    if (ChkSum != ChkSumOrg) {
-        log_error("Primary SysConfigData checksum NG, read backup\r\n");
-        fd = open("/dev/mtdblock11", O_RDWR);
-        if (fd < 0) {
-            free(buf);
-            log_error("open mtdblock11 (backup) NG,rebooting..\r\n");
-            if (ShmStatusCodeData != NULL) {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-            }
-            sleep(5);
-            system("reboot -f");
-            sleep(5);
-            system("reboot -f");
-        }
-
-        memset(buf, 0, MtdBlockSize);
-        wrd = read(fd, buf, MtdBlockSize);
-        close(fd);
-        if (wrd < MtdBlockSize) {
-            free(buf);
-            log_error("read backup SysConfigData data NG,rebooting..\r\n");
-            if (ShmStatusCodeData != NULL) {
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-            }
-            sleep(5);
-            system("reboot -f");
-            sleep(5);
-            system("reboot -f");
-        }
-        ChkSum = 0;
-        for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
-            ChkSum += buf[wrd];
-        }
-        memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
-
-        //================================================
-        // Load configuration from mtdblock12 (Factory default)
-        //================================================
-        if (ChkSum != ChkSumOrg) {
-            log_error("backup SysConfigData checksum NG, read Factory default\r\n");
-            fd = open("/dev/mtdblock12", O_RDWR);
-            if (fd < 0) {
-                free(buf);
-                log_error("open mtdblock12 (Factory default) NG,rebooting..\r\n");
-                if (ShmStatusCodeData != NULL) {
-                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-                }
-                sleep(5);
-                system("reboot -f");
-                sleep(5);
-                system("reboot -f");
-            }
-            memset(buf, 0, MtdBlockSize);
-            wrd = read(fd, buf, MtdBlockSize);
-            close(fd);
-            if (wrd < MtdBlockSize) {
-                free(buf);
-                log_error("read factory default  SysConfigData data NG,rebooting..\r\n");
-                if (ShmStatusCodeData != NULL) {
-                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-                }
-                sleep(5);
-                system("reboot -f");
-                sleep(5);
-                system("reboot -f");
-            }
-            ChkSum = 0;
-            for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
-                ChkSum += buf[wrd];
-            }
-            memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
-            if (ChkSum != ChkSumOrg) {
-                log_error("factory default  SysConfigData checksum NG, restore factory default\r\n");
-                free(buf);
-                system("cd /root;./FactoryConfig -m");
-                system("sync");
-                sleep(5);
-                system("reboot -f");
-                sleep(5);
-                system("reboot -f");
-
-                return FAIL;
-            }
-        }
-    }
-
-    //load OK
-    memcpy((struct SysConfigData *)ptr, buf, sizeof(struct SysConfigData));
-    free(buf);
-    //log_info("Load SysConfigData OK\n");
-    return PASS;
-}
-
-int isRouteFail()
-{
-    int result = YES;
-    FILE *fp;
-    char buf[512];
-
-    fp = popen("route -n", "r");
-    if (fp != NULL) {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            if (strstr(buf, "eth0") != NULL) {
-                result = NO;
-            }
-        }
-    }
-    pclose(fp);
-
-    return result;
-}
-
-int isReachableInternet()
-{
-    int result = FAIL;
-    FILE *fp;
-    char cmd[256];
-    char buf[512];
-    char tmp[512];
-
-    strcpy(cmd, "ifconfig eth0");
-    fp = popen(cmd, "r");
-
-    if (fp != NULL) {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            if (strstr(buf, "inet addr:") > 0) {
-                sscanf(buf, "%*s%s", tmp);
-                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
-
-                if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL) {
-                    strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
-                }
-            }
-        }
-    }
-    pclose(fp);
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == NORMAL) {
-        result = FAIL;
-    } else {
-        result = PASS;
-    }
-#else
-    memset(buf, 0x00, sizeof(buf));
-    for (int 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) {
-            while (fgets(buf, sizeof(buf), fp) != NULL) {
-                if (strstr(buf, "transmitted") > 0) {
-                    //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
-
-                    if (strstr(buf, "100%") != NULL) {
-                    } else {
-                        result = PASS;
-                    }
-                    //DEBUG_INFO("%s",buf);
-                    //DEBUG_INFO("%s\n",tmp);
-                }
-            }
-        }
-        pclose(fp);
-    }
-
-#endif //defined DD360 || defined DD360Audi
-
-    return result;
-}
-
-void InitEthernet()
-{
-    char tmpbuf[256];
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    bool ethResult = false;
-    uint8_t cnt_pingDNS_Fail = 0;
-#endif //!defined DD360 && !defined DD360Audi
-
-    system("ifconfig eth0 down");// eth0 down
-    system("ifconfig eth1 down");// eth1 down
-    sleep(2);
-
-    // /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",
-            ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-            ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
-    //sprintf(tmpbuf,"/sbin/ifconfig eth0 192.168.100.10 netmask 255.255.255.0 up");
-    system(tmpbuf);
-
-    memset(tmpbuf, 0, 256);
-    sprintf(tmpbuf, "route add default gw %s eth0 ",
-            ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-    //sprintf(tmpbuf,"route add default gw 192.168.100.1 eth0 ");
-    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",
-            ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
-            ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
-    system(tmpbuf);
-
-    //Run DHCP client if enabled
-    system("killall udhcpc");
-    system("rm -rf /etc/resolv.conf");
-    system("echo nameserver 8.8.8.8 > /etc/resolv.conf");       //Google DNS server
-    system("echo nameserver 180.76.76.76 > /etc/resolv.conf");  //Baidu DNS server
-    //system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
-
-    if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
-        sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
-        system(tmpbuf);
-    }
-
-    //Upgrade system id to /etc/hostname
-    sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
-    system(tmpbuf);
-
-    pid_t pid = fork();
-    if (pid == 0) {
-        log_info("InitEthernet = %d\r\n", pid);
-        for (;;) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-            if (isRouteFail()) {
-                //PRINTF_FUNC("eth0 not in route, restart eht0. \n");
-                system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
-
-                if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
-                    InitialDHCP();
-                }
-            }
-
-            if (isReachableInternet() == PASS) {
-                ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
-                cnt_pingDNS_Fail = 0;
-            } else {
-                if (++cnt_pingDNS_Fail > 3) {
-                    ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
-                }
-            }
-
-            ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
-
-            if (ethResult == YES) {
-                system("/sbin/ifmetric eth0 0");
-
-                if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
-                        (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                    system("/sbin/ifmetric mlan0 1");
-                }
-
-                if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
-                        (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                    system("/sbin/ifmetric ppp0 2");
-                }
-            }
-
-            if (!ethResult &&
-                    ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
-                    (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' ||
-                     ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                //ethResult = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn;
-                ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
-
-                if (ethResult) {
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric eth0 1");
-                        system("/sbin/ifmetric mlan0 0");
-                    }
-
-
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric ppp0 2");
-                    }
-                }
-            }
-
-            if (!ethResult &&
-                    ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
-                    (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' ||
-                     ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                //ethResult = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn;
-                ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
-
-                if (ethResult) {
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric mlan0 2");
-                    }
-
-                    if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
-                            (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric eth0 1");
-                        system("/sbin/ifmetric ppp0 0");
-                    }
-                }
-            }
-
-            ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
-#else
-            isReachableInternet();
-#endif //!defined DD360 && !defined DD360
-
-            sleep(5);
-        }
-    }
-
-    log_info("Initial Ethernet OK\r\n");
-}
-
-int InitialRfidPort()
-{
-    int uartO2 = open(rfidPortName, O_RDWR);
-    struct termios tios;
-
-    if (uartO2 != FAIL) {
-        ioctl (uartO2, TCGETS, &tios);
-        tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
-        tios.c_lflag = 0;
-        tios.c_iflag = 0;
-        tios.c_oflag = 0;
-        tios.c_cc[VMIN] = 0;
-        tios.c_cc[VTIME] = (unsigned char) 1;
-        tios.c_lflag = 0;
-        tcflush(uartO2, TCIFLUSH);
-        ioctl(uartO2, TCSETS, &tios);
-    }
-
-    if (uartO2 < 0) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
-    }
-
-    return uartO2;
-}
-
-void GetMacAddress()
-{
-    for (byte index = 0; index < 2; index++) {
-        int fd;
-        struct ifreq ifr;
-        char tarEth[5];
-        char Mac[18];
-
-        sprintf(tarEth, "eth%d", index);
-        fd = socket(AF_INET, SOCK_DGRAM, 0);
-
-        ifr.ifr_addr.sa_family = AF_INET;
-        strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
-
-        ioctl(fd, SIOCGIFHWADDR, &ifr);
-        close(fd);
-
-        sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
-                ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
-                ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
-
-        if (index == 0) {
-            strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
-        } else {
-            strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
-        }
-    }
-}
-
-void GetFirmwareVersion()
-{
-    // Get CSU root file system version
-    sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
-
-    byte count = 0, chademo = 0, ccs = 0, gb = 0;
-    for (uint8_t idx = 0; idx < 3; idx++) {
-        if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'J') {
-            chademo++;
-            count++;
-        } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'G') {
-            gb++;
-            count++;
-        } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'U' ||
-                   ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'V' ||
-                   ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'E') {
-            ccs++;
-            count++;
-        }
-    }
-
-    if (count == 1) {
-        if (chademo > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
-        } else if (ccs > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
-        } else if (gb > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
-        }
-    } else {
-        if (chademo > 0 && ccs > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
-        } else if (chademo > 0 && gb > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
-        } else if (ccs > 0 && gb > 0) {
-            ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
-        }
-    }
-
-    // Get network option from model name
-    switch (ShmSysConfigAndInfo->SysConfig.ModelName[10]) {
-    case 'B':
-    case 'U':
-        //Blue tooth
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
-        break;
-    case 'W':
-        // WIFI
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
-        break;
-    case 'T':
-        // 3G/4G
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
-        break;
-    case 'D': //DS60-120 add
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
-        break;
-    default:
-        // LAN
-        ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
-        break;
-    }
-    // Get rating power from model name
-    memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
-
-    // Get IEC or UL
-    char _buf[3] = {0};
-    memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
-
-    if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
-        ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
-        log_info("IEC model");
-    } else if (strcmp(_buf, "WU") == EQUAL) {
-        ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
-        log_info("UL model");
-    }
-}
-
-//DS60-120 add
-void InitialGunIndexToUnUse()
-{
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
-    }
-
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
-    }
-
-    for (byte index = 0; index < GB_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
-    }
-
-    for (byte index = 0; index < AC_QUANTITY; index++) {
-        ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index = NO_DEFINE;
-    }
-}
-
-void InitialShareMemoryInfo()
-{
-    FILE *fp;
-    char cmd[512];
-    char buf[512];
-
-    sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
-    sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
-    sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
-
-    ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
-    ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
-
-    ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
-    ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
-    ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
-    ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
-    ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
-    ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
-    ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
-
-    sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
-    memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
-
-    sprintf(cmd, "/bin/uname -r");
-    fp = popen(cmd, "r");
-    if (fp == NULL) {
-        sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
-    } else {
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
-            strcpy((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
-        }
-    }
-
-    // 雙槍 CCS + Chademo
-    GetFirmwareVersion();
-    //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
-
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
-    sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
-    ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
-    ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
-    ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
-    ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-
-    strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
-
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = NO; //DS60-120 Add
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = NO; //DS60-120 Add
-    ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = NO; //DS60-120 add
-
-    memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
-    memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
-    ShmPrimaryMcuData->SelfTest_Comp = NO;
-    ShmRelayModuleData->SelfTest_Comp = NO;
-    ShmFanModuleData->SelfTest_Comp = NO;
-    ShmLedModuleData->SelfTest_Comp = NO;
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
-    ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOTTING; //DS60-120 add
-
-    ShmFanModuleData->TestFanSpeed = 0;
-
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
-
-    //--- DS60-120 remove -----
-    /*char EvsePower[2];
-
-    EvsePower[2] = '\0';
-    unsigned short buf_pow = 0;
-    if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6) {
-        strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
-        if (strcmp(EvsePower, "15") == EQUAL) {
-            buf_pow = 150;
-        } else if (strcmp(EvsePower, "30") == EQUAL) {
-            buf_pow = 30;
-        } else if (strcmp(EvsePower, "60") == EQUAL) {
-            buf_pow = 60;
-        } else if (strcmp(EvsePower, "12") == EQUAL) {
-            buf_pow = 120;
-        } else if (strcmp(EvsePower, "18") == EQUAL) {
-            buf_pow = 180;
-        } else if (strcmp(EvsePower, "36") == EQUAL) {
-            buf_pow = 360;
-        }
-
-        ShmSysConfigAndInfo->SysConfig.RatingCurrent = (buf_pow / 30) * PSU_MIN_CUR;
-
-        if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower == 0 ||
-                ShmSysConfigAndInfo->SysConfig.MaxChargingPower > buf_pow) {
-            ShmSysConfigAndInfo->SysConfig.MaxChargingPower = buf_pow;
-        }
-    }
-    */
-    //--------------------------------------------------------------------------
-
-    InitialGunIndexToUnUse();//DS60-120 add
-
-    ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
-    ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
-
-    log_info("3InitialShareMemoryInfo done...\r\n");
-}
-
-int Initialization()
-{
-    // 初始化卡號驗證的 Flag
-    ClearAuthorizedFlag();
-    // 初始化插槍驗證的 Flag
-    ClearDetectPluginFlag();
-
-    // UART 2 for Rfid
-    rfidFd = InitialRfidPort();
-
-    int pinOut[2] = { 116, 115 };
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
-        chargingInfo[count]->RemoteStartFlag = NO;
-
-        if (chargingInfo[count]->Type == _Type_Chademo) {
-            gpio_set_value(pinOut[count], 0x00);
-            ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-        } else if (chargingInfo[count]->Type == _Type_GB) {
-            gpio_set_value(pinOut[count], 0x00);
-            ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-        } else if (chargingInfo[count]->Type == _Type_CCS_2) {
-            //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
-            if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                gpio_set_value(pinOut[1], 0x01);
-            } else {
-                gpio_set_value(pinOut[count], 0x01);
-            }
-            ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-            //}
-        }
-
-        strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
-    }
-
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
-        ac_chargingInfo[count]->RemoteStartFlag = NO;
-
-        if (ac_chargingInfo[count]->Type == _Type_AC) {
-            ac_chargingInfo[count]->SelfTest_Comp = NO;
-            strcpy((char *)ShmOCPP16Data->StatusNotification[count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount].ErrorCode, "NoError");
-        }
-    }
-
-    //PRINTF_FUNC("Initialization OK \n");
-    return PASS;
-}
-
-bool InitialSystemDefaultConfig()
-{
-    bool result = true;
-
-    LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
-    InitGPIO();
-    InitEthernet();
-    GetMacAddress();
-
-//  system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
-//  sleep(3);
-//  system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
-//  sleep(1);
-//  system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
-
-    return result;
-}
-
-bool DisplaySelfTestFailReason()
-{
-    bool result = false;
-
-    // RB、FB、407、EV 小板中有些板子無回應
-    if (ShmRelayModuleData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = true; }
-    if (ShmFanModuleData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = true; }
-    if (ShmPrimaryMcuData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = true; }
-    if (ShmLedModuleData->SelfTest_Comp == NO)
-    { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = true; }
-    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-        if (chargingInfo[index]->Type == _Type_Chademo) {
-            if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-            { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = true; }
-        } else if (chargingInfo[index]->Type == _Type_GB) {
-            if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-            { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = true; }
-        } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-            if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-                { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = true; }
-            }
-        }
-    }
-    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
-        // 先借 GBT 顯示
-        if (ac_chargingInfo[index]->SelfTest_Comp == NO)
-        { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = true; }
-    }
-
-    if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        // AC Contact 未搭上
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = true;
-        result = true;
-#endif //!defined DD360 && !defined DD360Audi
-    }
-#if 0
-    else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES) { //DS60-120 add
-        result = true;
-    }
-#endif //0
-    else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0) {
-        // PSU 通訊問題
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = true;
-        result = true;
-    }
-
-    return result;
-}
-
-void SelfTestRun()
-{
-    bool evInitFlag = false;
-
-    StartSystemTimeoutDet(Timeout_SelftestChk);
-    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
-
-    while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE //||
-            //GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL <= 20 //DS60-120 add
-          ) {
-        if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
-            return;
-        }
-
-        ChkPrimaryStatus();
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 //||
-                //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES //DS60-120 add
-           ) {
-            ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-            return;
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) {
-            if (ShmPsuData->Work_Step == _NO_WORKING ||
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL) {
-                ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-                return;
-            }
-
-            switch (ShmSysConfigAndInfo->SysInfo.SelfTestSeq) {
-            case _STEST_VERSION: {
-                if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
-                        ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
-                        && (ShmRelayModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Relay Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
-                    ShmRelayModuleData->SelfTest_Comp = YES;
-                }
-#if !defined NO_FAN_BOARD && !defined DD360ComBox
-                if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
-                        ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
-                        && (ShmFanModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("Fan Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.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", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
-                    ShmPrimaryMcuData->SelfTest_Comp = YES;
-                }
-#if 0 //DS60-120 remove
-                if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev) != 0 ||
-                        ShmSysConfigAndInfo->SysInfo.LedModuleFwRev[0] != '\0')
-                        && (ShmLedModuleData->SelfTest_Comp != YES)
-                   ) {
-                    log_info("LED Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
-                    ShmLedModuleData->SelfTest_Comp = YES;
-                }
-#endif //0
-
-                // EV 小板
-                if (!evInitFlag) {
-                    evInitFlag = YES;
-                    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                        //log_info("index = %d, charging index = %d, type = %d\r\n",
-                        //         index,
-                        //         chargingInfo[index]->type_index,
-                        //         chargingInfo[index]->Type);
-                        if (chargingInfo[index]->Type == _Type_Chademo) {
-                            if ((strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
-                                    ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
-                                    //&& (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
-                               ) {
-                                log_info("CHAdeMO[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-                                ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
-                            } else {
-                                //PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-                                evInitFlag = NO;
-                            }
-                        } else if (chargingInfo[index]->Type == _Type_GB) {
-                            if ((strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
-                                    ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
-                                    //&& (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
-                               ) {
-                                log_info("GBT[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmGBTData->evse[chargingInfo[index]->type_index].version);
-                                ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
-                            } else {
-                                //PRINTF_FUNC("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-                                evInitFlag = NO;
-                            }
-                        } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-                            if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                                if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
-                                        ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
-                                        /*&&(ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp != YES)*/
-                                   ) {
-                                    log_info("CCS[%d] FW Rev = %s",
-                                             chargingInfo[index]->type_index,
-                                             ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
-                                    ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->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 (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
-                        if (ac_chargingInfo[index]->Type == _Type_AC) {
-                            if ((strlen((char *)ac_chargingInfo[index]->version) != 0 || ac_chargingInfo[index]->version[0] != '\0')
-                                    && (ac_chargingInfo[index]->SelfTest_Comp != YES)
-                               ) {
-                                log_info("AC connector[%d] FW Rev = %s", index, ac_chargingInfo[index]->version);
-                                ac_chargingInfo[index]->SelfTest_Comp = YES;
-                            } else {
-                                evInitFlag = NO;
-                            }
-                        }
-                    }
-                }
-
-                if ( ShmFanModuleData->SelfTest_Comp &&
-                        ShmRelayModuleData->SelfTest_Comp &&
-                        ShmPrimaryMcuData->SelfTest_Comp &&
-                        //ShmLedModuleData->SelfTest_Comp &&
-                        evInitFlag
-                   ) {
-                    ShmSysConfigAndInfo->SysInfo.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 (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES) {
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
-                    log_info("AC contactor self test OK");
-                }
-#else
-                ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
-                log_info("Waiting for DO communication");
-#endif //!defined DD360 && !defined DD360Audi
-            }
-            break;
-            case _STEST_PSU_DETECT: {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
-                }
-#else
-                ShmSysConfigAndInfo->SysInfo.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);
-                    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
-                    ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
-                }
-#else
-                //check the power limit from DO
-                ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
-                ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
-                log_info("Successful Self Test");
-#endif //defined DD360 && !defined DD360Audi
-            }
-            break;
-            }
-        } else {
-            break;
-        }
-
-        usleep(100000);
-    }
-}
-
-int SpawnTask()
-{
-    sleep(2);
-    system("/root/Module_EventLogging &");
-    system("/root/Module_PrimaryComm &");
-    system("/root/Module_EvComm &");
-    system("/root/Module_LcmControl &");
-    system("/root/Module_InternalComm &");
-    system("/root/Module_ProduceUtils &");
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    system("/root/DoComm &");
-#else
-    system("/root/Module_PsuComm &");
-
-    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
-        system("/root/OcppBackend &");
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
-        system("/root/Module_4g &");
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
-        system("/root/Module_Wifi &");
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') {
-        system("/root/Module_4g &");
-        system("/root/Module_Wifi &");
-    }
-#endif //defined DD360 || defined DD360Audi
-
-    return PASS;
-}
-
-int StoreUsrConfigData(struct SysConfigData *UsrData)
-{
-    int result = PASS;
-    int fd, wrd;
-    unsigned int i, Chk;
-    unsigned char *ptr, *BufTmp;
-
-    Chk = 0;
-    ptr = (unsigned char *)UsrData;
-    if ((BufTmp = malloc(MtdBlockSize)) != NULL) {
-        memset(BufTmp, 0, MtdBlockSize);
-        memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
-        for (i = 0; i < MtdBlockSize - 4; i++) {
-            Chk += *(ptr + i);
-        }
-
-        memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
-        fd = open("/dev/mtdblock10", O_RDWR);
-        if (fd > 0) {
-            wrd = write(fd, BufTmp, MtdBlockSize);
-            close(fd);
-            if (wrd >= MtdBlockSize) {
-                fd = open("/dev/mtdblock11", O_RDWR);
-                if (fd > 0) {
-                    wrd = write(fd, BufTmp, MtdBlockSize);
-                    close(fd);
-                    if (wrd < MtdBlockSize) {
-                        log_error("write /dev/mtdblock11(backup) NG\r\n");
-                        result = FAIL;
-                    }
-                } else {
-                    log_error("open /dev/mtdblock11(backup) NG\r\n");
-                    result = FAIL;
-                }
-            } else {
-                log_error("write /dev/mtdblock10 NG\r\n");
-                result = FAIL;
-            }
-
-        } else {
-            log_error("open /dev/mtdblock10 NG\r\n");
-            result = FAIL;
-        }
-    } else {
-        log_error("alloc BlockSize NG\r\n");
-        result = FAIL;
-    }
-
-    if (BufTmp != NULL) {
-        free(BufTmp);
-    }
-
-    return result;
-}
-
-//===============================================
-// Common Detect Chk - Stop Charging ?
-//===============================================
-int isEvBoardStopChargeFlag(byte gunIndex)
-{
-    //printf("StopChargeFlag = %d\r\n", chargingInfo[gunIndex]->StopChargeFlag);
-    return chargingInfo[gunIndex]->StopChargeFlag;
-}
-
-bool isEvBoardNormalStopChargeFlag(byte gunIndex)
-{
-    return chargingInfo[gunIndex]->NormalStopChargeFlag;
-}
-
-//===============================================
-// 掃描插槍狀況
-//===============================================
-void ClearDetectPluginFlag()
-{
-    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-
-    //DS60-120 add
-    for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-        if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
-            chargingInfo[gun_index]->RemoteStartFlag = NO;
-        }
-    }
-
-    if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
-        ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-    }
-}
-
-void DetectPluginStart()
-{
-    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
-}
-
-bool isDetectPlugin()
-{
-    if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
-        return YES;
-    }
-
-    return NO;
-}
-
-//===============================================
-// Common Detect Chk - Chademo
-//===============================================
-bool isEvGunLocked_chademo(byte gunIndex)
-{
-    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
-}
-
-bool isEvContactorWelding_chademo(byte gunIndex)
-{
-    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
-}
-
-bool isEvStopReq_chademo(byte gunIndex)
-{
-    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
-}
-
-bool isEvStopCharging_chademo(byte gunIndex)
-{
-    if (isEvGunLocked_chademo(gunIndex) == NO) {
-        // 無鎖槍 = 停止
-        PRINTF_FUNC("gun locked none (%d) \n", gunIndex);
-        return YES;
-    }
-
-    return NO;
-}
-
-byte isPrechargeStatus_chademo(byte gunIndex)
-{
-    byte result = 0x00;
-
-    result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-
-    return result;
-}
-//===============================================
-// Common Detect Chk - GB
-//===============================================
-bool isEvGunLocked_gb(byte gunIndex)
-{
-    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
-}
-
-bool isEvStopCharging_gb(byte gunIndex)
-{
-    if (isEvGunLocked_gb(gunIndex) == NO) {
-        // 無鎖槍 = 停止
-        PRINTF_FUNC("gun locked none. \n");
-        return YES;
-    }
-
-    return NO;
-}
-
-byte isPrechargeStatus_gb(byte gunIndex)
-{
-    byte result = 0x00;
-
-    result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-
-    return result;
-}
-
-//===============================================
-// Common Detect Chk - CCS
-//===============================================
-bool isEvGunLocked_ccs(byte gunIndex)
-{
-    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
-}
-
-byte isPrechargeStatus_ccs(byte gunIndex)
-{
-    byte result = 0x00;
-
-    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-        result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-    }
-
-    return result;
-}
-
-bool isEvStopCharging_ccs(byte gunIndex)
-{
-    if (isEvGunLocked_ccs(gunIndex) == NO) {
-        // 無鎖槍 = 停止
-        PRINTF_FUNC("gun locked none. \n");
-        return YES;
-    }
-
-    return NO;
-}
-
-//===============================================
-// Callback
-//===============================================
-void DisplayChargingInfo()
-{
-    PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
-    for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-        if (chargingInfo[i]->SystemStatus != S_IDLE &&
-                chargingInfo[i]->SystemStatus != S_RESERVATION) {
-            ChangeGunSelectByIndex(i);
-            return;
-        }
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
-            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
-            ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE) {
-        ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-    }
-
-    usleep(50000);
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-}
-
-void _AutoReturnTimeout()
-{
-    PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
-    if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
-        ClearDetectPluginFlag();
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
-        DetectPluginStart();
-    }
-    usleep(50000);
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-}
-
-void _SelfTestTimeout()
-{
-    if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE) {
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_ALARM);
-        }
-    }
-    ShmPsuData->Work_Step = _NO_WORKING;
-    ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-    PRINTF_FUNC("Self test timeout. \n");
-}
-
-void _AuthorizedTimeout()
-{
-    if (IsAuthorizingMode()) {
-        PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
-        isCardScan = false;
-        //gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0; //Jerry add
-        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
-        //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
-        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-        ClearAuthorizedFlag();
-    }
-}
-
-void _DetectPlugInTimeout()
-{
-    PRINTF_FUNC("*********** _DetectPlugInTimeout *********** \n");
-    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-    ClearDetectPluginFlag();
-    //usleep(50000);
-    sleep(1); //Jerry add
-#if defined DD360Audi
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-}
-
-void _DetectEvChargingEnableTimeout(byte gunIndex)
-{
-    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-        if (!isEvGunLocked_chademo(gunIndex)) {
-            PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
-        if (!isEvGunLocked_ccs(gunIndex)) {
-            PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-        if (!isEvGunLocked_ccs(gunIndex)) {
-            PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
-        }
-    }
-    ChargingTerminalProcess(gunIndex);
-    _AutoReturnTimeout();
-}
-
-void _DetectEvseChargingEnableTimeout(byte gunIndex)
-{
-    PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
-    //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
-    {
-        setChargerMode(gunIndex, MODE_IDLE);
-        _AutoReturnTimeout();
-    }
-}
-
-void _PrepareTimeout(byte gunIndex)
-{
-    PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
-    _AutoReturnTimeout();
-}
-
-void _CcsPrechargeTimeout(byte gunIndex)
-{
-    PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
-    setChargerMode(gunIndex, MODE_IDLE);
-}
-
-//===============================================
-// 取得卡號與卡號驗證
-//===============================================
-bool canStartCharging()
-{
-    char buf2[16] = "";
-    memset(buf2, 0, ARRAY_SIZE(buf2));
-
-    for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
-        sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
-    }
-    sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
-    // 因為無法得知實際的長度,所以只能用搜尋的方式
-    if (strcmp(buf2, "Accepted") == EQUAL) {
-        return true;
-    } else {
-
-    }
-
-    return false;
-}
-
-void AuthorizingStart()
-{
-    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
-    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
-}
-
-void ClearAuthorizedFlag()
-{
-    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
-    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
-}
-
-bool isAuthorizedComplete()
-{
-    if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == YES) {
-        return false;
-    }
-    return true;
-}
-
-bool IsAuthorizingMode()
-{
-    if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO) {
-        return false;
-    }
-
-    return true;
-}
-
-//===============================================
-// 紀錄 Alarm Code
-//===============================================
-void RecordAlarmCode(byte gunIndex, char *code)
-{
-    memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
-
-    if (strcmp(code, "012234") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES; }
-    if (strcmp(code, "012235") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES; }
-    if (strcmp(code, "012236") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES; }
-    if (strcmp(code, "012288") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES; }
-    if (strcmp(code, "012289") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES; }
-    if (strcmp(code, "012290") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES; }
-}
-
-void RecordWarningCode(byte gunIndex, char *code)
-{
-    memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, code, 6);
-
-    if (strcmp(code, "012296") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES; }
-    if (strcmp(code, "012297") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES; }
-    if (strcmp(code, "012298") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES; }
-}
-
-void ReleaseAlarmCode(byte gunIndex)
-{
-    bool isCleanCheck = false;
-    char code[7];
-
-    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL &&
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES) {
-            memcpy(code, "012234", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL &&
-                   ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES) {
-            memcpy(code, "012289", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
-            ReleaseWarningCodeByString(gunIndex, "012296");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
-        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL &&
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES) {
-            memcpy(code, "012236", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL &&
-                   ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail == YES) {
-            memcpy(code, "012290", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
-            ReleaseWarningCodeByString(gunIndex, "012298");
-        }
-    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL &&
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES) {
-            memcpy(code, "012235", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL &&
-                   ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES) {
-            memcpy(code, "012288", 6);
-            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-            isCleanCheck = true;
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
-            ReleaseWarningCodeByString(gunIndex, "012297");
-        }
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "012234", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO; }
-                    if (strncmp(code, "012289", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO; }
-
-                    if (strncmp(code, "012236", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO; }
-                    if (strncmp(code, "012290", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO; }
-
-                    if (strncmp(code, "012235", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO; }
-                    if (strncmp(code, "012288", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO; }
-                }
-            }
-        }
-    }
-
-    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
-            strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
-            strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012238", 6) == EQUAL ||
-            strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012304", 6) == EQUAL
-       ) {
-        memset(chargingInfo[gunIndex]->ConnectorAlarmCode, 0, sizeof(chargingInfo[gunIndex]->ConnectorAlarmCode));
-    }
-}
-
-void ReleaseWarningCodeByString(byte gunIndex, char *code)
-{
-    bool isCleanCheck = false;
-
-    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
-        memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-               ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
-        memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-        isCleanCheck = true;
-    } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-               ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
-        memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-        isCleanCheck = true;
-    }
-
-    if (isCleanCheck) {
-        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-            if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                if (strncmp((char *)chargingInfo[index]->ConnectorWarningCode, code, 6) != EQUAL) {
-                    if (strncmp(code, "012296", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO; }
-                    if (strncmp(code, "012297", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO; }
-                    if (strncmp(code, "012298", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO; }
-                }
-            }
-        }
-    }
-}
-//===============================================
-// EmergencyStop and Charging Stop
-//===============================================
-void ChargingTerminalProcess(byte gunIndex)
-{
-    setChargerMode(gunIndex, MODE_TERMINATING);
-}
-
-void ChargingAlarmProcess(byte gunIndex)
-{
-    setChargerMode(gunIndex, MODE_ALARM);
-}
-
-void AcChargingTerminalProcess()
-{
-    ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
-}
-
-void StopChargingProcessByString(byte level)
-{
-    if (level > ShmSysConfigAndInfo->SysWarningInfo.Level) {
-        ShmSysConfigAndInfo->SysWarningInfo.Level = level;
-    }
-}
-
-void ReleaseChargingProcessByString(byte level)
-{
-    if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level) {
-        ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
-    }
-}
-
-// 一般錯誤停止充電處理函式
-void BoardErrOccurByString(byte index, char *code)
-{
-    byte level = 1;
-    if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
-            (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-        if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO) {
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
-        }
-        ChargingTerminalProcess(index);
-    }
-
-    StopChargingProcessByString(level);
-}
-
-// 急停狀況的停止充電處理函式
-void EmcOccureByString(char *code)
-{
-    byte level = 2;
-    // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
-    // 其錯誤等級為 2
-
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-    //DS60-120 remove
-    if (strncmp(code, "012251", 6) == EQUAL ||
-            strncmp(code, "012252", 6) == EQUAL ||
-            strncmp(code, "012238", 6) == EQUAL ||
-            strncmp(code, "042251", 6) == EQUAL ||
-            strncmp(code, "042252", 6) == EQUAL ||
-            strncmp(code, "012304", 6) == EQUAL ||
-            strncmp(code, "042200", 6) == EQUAL ||
-            strncmp(code, "042201", 6) == EQUAL ||
-            strncmp(code, "042202", 6) == EQUAL ||
-            strncmp(code, "042267", 6) == EQUAL)
-#endif //defined DD360 || defined DD360Audi
-    {
-        for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++) {
-            //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
-
-            if ((chargingInfo[gun]->SystemStatus > S_IDLE &&
-                    chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
-                    (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                     chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                //ChargingTerminalProcess(gun);
-                ChargingAlarmProcess(gun);
-            }
-        }
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-        StopChargingProcessByString(level);
-        InformOcppErrOccur(4);
-#endif //defined DD360 || defined DD360Audi
-    }
-}
-
-void ReleaseBoardErrOccurByString(byte index, char *code)
-{
-    bool isTrigger = false;
-    byte level = 1;
-
-    if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
-    }
-
-    if (isTrigger) {
-        ReleaseChargingProcessByString(level);
-    }
-}
-
-void ReleaseEmsOccureByString(byte index, char *code)
-{
-    bool isTrigger = false;
-    byte level = 2;
-
-    if (strncmp(code, "042251", 6) == 0 ) {
-        isTrigger = true;
-    } else if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
-    } else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
-    } else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
-    } else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
-        isTrigger = true;
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
-    }
-
-    if (isTrigger) {
-        ReleaseChargingProcessByString(level);
-        InformOcppErrOccur(6);
-    }
-}
-
-//===============================================
-// 確認硬體 (按鈕) 狀態
-//===============================================
-bool leftBtnPush = false;
-bool rightBtnPush = false;
-
-void ChkPrimaryStatus()
-{
-    unsigned char Rtn;
-
-    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
-        Rtn = 0;
-        for (unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-            if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042251", 6) == 0) {
-                EmcOccureByString("042251");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042252", 6) == 0) {
-                EmcOccureByString("042252");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042200", 6) == 0) {
-                EmcOccureByString("042200");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042201", 6) == 0) {
-                EmcOccureByString("042201");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042202", 6) == 0) {
-                EmcOccureByString("042202");
-                Rtn = 1;
-            } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
-                EmcOccureByString("012304");
-                Rtn = 1;
-            }
-        }
-        if (Rtn == 0) {
-            ReleaseEmsOccureByString(0, "042251");
-            ReleaseEmsOccureByString(0, "042252");
-            ReleaseEmsOccureByString(0, "042200");
-            ReleaseEmsOccureByString(0, "042201");
-            ReleaseEmsOccureByString(0, "042202");
-            ReleaseEmsOccureByString(0, "012304");
-        }
-    } else {
-        ReleaseEmsOccureByString(0, "042251");
-        ReleaseEmsOccureByString(0, "042252");
-        ReleaseEmsOccureByString(0, "042200");
-        ReleaseEmsOccureByString(0, "042201");
-        ReleaseEmsOccureByString(0, "042202");
-        ReleaseEmsOccureByString(0, "012304");
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
-        EmcOccureByString("012251");
-    } else {
-        ReleaseEmsOccureByString(0, "012251");
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
-        EmcOccureByString("012238");
-    } else {
-        ReleaseEmsOccureByString(0, "012238");
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
-    } else {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
-        EmcOccureByString("012252");
-    } else {
-        ReleaseEmsOccureByString(0, "012252");
-    }
-
-    //DS60-120 add
-    //if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
-    //        ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS) {
-    //    ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
-    //} else {
-    //    ShmSysConfigAndInfo->SysConfig.ShowInformation = NO;
-    //}
-
-    if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
-            !leftBtnPush
-#if defined DD360Audi
-            &&
-            getCurLcmPage() != _LCM_AUTHORIZING &&
-            getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
-            getCurLcmPage() != _LCM_AUTHORIZ_FAIL
-#endif //defined DD360Audi
-       ) {
-        if (!leftBtnPush) {
-            leftBtnPush = true;
-            PRINTF_FUNC("left btn down...............................%x\n",
-                        chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus);
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                switch (ac_chargingInfo[0]->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 (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-                        // 停止充電
-                        AcChargingTerminalProcess();
-                    }
-                }
-                break;
-                case S_COMPLETE:
-                {}
-                break;
-                }
-            }
-
-            switch (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
-            case S_IDLE: {
-                if (isDetectPlugin()) {
-                    _DetectPlugInTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-#if defined DD360Audi
-                else {
-                    if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == PASS) {
-                        //printf("destroy gun = %d\r\n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                        destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                    } else {
-                        confirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                        PRINTF_FUNC("confirm select gun ............................... %d \n",
-                                    ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                    }
-                }
-#endif //defined DD360Audi
-            }
-            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 (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                    AcChargingTerminalProcess();
-                } else {
-                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                }
-            }
-            break;
-            case S_CHARGING: {
-                if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-                    // 停止充電
-                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                }
-            }
-            break;
-            case S_COMPLETE: {
-                // 回 IDLE
-                //PRINTF_FUNC("right btn down.................S_COMPLETE \n");
-                //chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
-            }
-            break;
-            }
-        }
-    } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
-        if (leftBtnPush) {
-            leftBtnPush = false;
-            //PRINTF_FUNC("left btn up............................... \n");
-        }
-    }
-
-    if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
-            !rightBtnPush
-#if defined DD360Audi
-            &&
-            getCurLcmPage() != _LCM_IDLE &&
-            getCurLcmPage() != _LCM_AUTHORIZING &&
-            getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
-            getCurLcmPage() != _LCM_AUTHORIZ_FAIL &&
-            getCurLcmPage() != _LCM_WAIT_FOR_PLUG
-#endif //defined DD360Audi
-       ) {
-        if (!rightBtnPush) {
-            rightBtnPush = true;
-            //PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
-                    ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
-                ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            } else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
-                       ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
-                ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-            } else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
-                for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                    if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
-                            chargingInfo[_index]->SystemStatus != S_IDLE &&
-                            chargingInfo[_index]->SystemStatus != S_RESERVATION) {
-                        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
-                        ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                        return;
-                    }
-                }
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-                ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            } else {
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-                ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-            }
-        }
-        PRINTF_FUNC("current select gun ............................... %d \n",
-                    ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
-        if (rightBtnPush) {
-            rightBtnPush = false;
-            //PRINTF_FUNC("right btn up............................... \n");
-        }
-    }
-}
-
-//===============================================
-// 確認各小板偵測的錯誤狀況
-//===============================================
-void CheckErrorOccurStatus(byte index)
-{
-    // 小板
-    if (chargingInfo[index]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            BoardErrOccurByString(index, "011012");
-        }
-//      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
-//          BoardErrOccurByString(index, "012234");
-    } else if (chargingInfo[index]->Type == _Type_GB) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
-            BoardErrOccurByString(index, "011016");
-        }
-//      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
-//          BoardErrOccurByString(index, "012236");
-    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-            BoardErrOccurByString(index, "011014");
-        }
-//      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
-//          BoardErrOccurByString(index, "012235");
-    }
-
-    // RB
-    if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
-                ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
-            if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
-                ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
-                StopChargingProcessByString(2);
-                InformOcppErrOccur(13);
-            }
-
-            //DS60-120 add -----
-            if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
-                if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES) {
-                    memcpy(chargingInfo[index]->ConnectorAlarmCode, "012203", 6);
-                } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES) {
-                    memcpy(chargingInfo[index]->ConnectorAlarmCode, "012204", 6);
-                } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
-                    memcpy(chargingInfo[index]->ConnectorAlarmCode, "012205", 6);
-                }
-            }
-            //log_info("1 CheckErrorOccurStatus\r\n");
-            chargingInfo[index]->StopChargeFlag = YES;
-            //------------------------------------------------------------------
-        } else {
-            if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
-                ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-                ReleaseChargingProcessByString(2);
-                InformOcppErrOccur(6);
-            }
-        }
-    } else {
-        if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-            ReleaseChargingProcessByString(2);
-            InformOcppErrOccur(6);
-        }
-    }
-
-    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
-            StopChargingProcessByString(2);
-            InformOcppErrOccur(14);
-        }
-
-        //DS60-120 -----
-        if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
-            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES) {
-                memcpy(chargingInfo[index]->ConnectorAlarmCode, "012200", 6);
-            } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES) {
-                memcpy(chargingInfo[index]->ConnectorAlarmCode, "012201", 6);
-            } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
-                memcpy(chargingInfo[index]->ConnectorAlarmCode, "012202", 6);
-            }
-        }
-        //log_info("2 CheckErrorOccurStatus\r\n");
-        chargingInfo[index]->StopChargeFlag = YES;
-        //----------------------------------------------------------------------
-    } else {
-        if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
-            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-            ReleaseChargingProcessByString(2);
-            InformOcppErrOccur(6);
-        }
-    }
-
-    //DS60-120 ----
-    if (chargingInfo[index]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011011", 6);
-        } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011012", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012217", 6);
-        }
-    } else if (chargingInfo[index]->Type == _Type_GB) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011015", 6);
-        } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011016", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012221", 6);
-        }
-    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011013", 6);
-        } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "011014", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012219", 6);
-        }
-    }
-    //--------------------------------------------------------------------------
-    if (strlen(chargingInfo[index]->ConnectorAlarmCode) == 0) {
-        //Primary
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012251", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012252", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012238", 6);
-        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
-            memcpy(chargingInfo[index]->ConnectorAlarmCode, "012304", 6);
-        }
-    }
-}
-
-//===============================================
-// 確認 GPIO 狀態
-//===============================================
-void gpio_set_value(unsigned int gpio, unsigned int value)
-{
-    int fd;
-    char buf[MAX_BUF];
-
-    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
-    fd = open(buf, O_WRONLY);
-    if (fd < 0) {
-        perror("gpio/set-value");
-        return;
-    }
-
-    if (value) {
-        write(fd, "1", 2);
-    } else {
-        write(fd, "0", 2);
-    }
-
-    close(fd);
-}
-
-int gpio_get_value(unsigned int gpio, unsigned int *value)
-{
-    int fd;
-    char buf[MAX_BUF];
-    char ch;
-
-    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
-
-    fd = open(buf, O_RDONLY);
-    if (fd < 0) {
-        perror("gpio/get-value");
-        return fd;
-    }
-
-    read(fd, &ch, 1);
-
-    if (ch != '0') {
-        *value = 1;
-    } else {
-        *value = 0;
-    }
-
-    close(fd);
-    return 0;
-}
-
-void CheckGunTypeFromHw()
-{
-    uint8_t i = 0;
-    int pinIn[4] = {22, 23, 44, 45};
-    unsigned int gpioValue = 0;
-    unsigned char tmp[2] = {0};
-
-    log_info("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
-    for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
-        gpio_get_value(pinIn[i], &gpioValue);
-        switch (pinIn[i]) {
-        //right slot
-        case 22:
-            bd1_1_status = gpioValue;
-            break;
-        case 23:
-            bd1_2_status = gpioValue;
-            break;
-
-        //left slot
-        case 44:
-            bd0_1_status = gpioValue;
-            break;
-        case 45:
-            bd0_2_status = gpioValue;
-            break;
-        }
-    }
-
-#if 1 //DS60-120 remove
-    //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
-    //CcsChargingData [0至1] 分別為 Right至Left
-    //model name 槍順序左至右分別為Right至Left
-    tmp[1] = (bd0_1_status << 4 | bd0_2_status);
-    tmp[0] = (bd1_1_status << 4 | bd1_2_status);
-    for (i = 0; i < 2; i++) {
-        switch (tmp[i]) {
-        case 0x01:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
-            break;
-
-        case 0x10:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
-            break;
-
-        case 0x11:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
-            break;
-
-        case 0x00:
-            log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
-            break;
-        }
-    }
-#endif //0
-}
-
-void CheckGpioInStatus()
-{
-    int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
-    unsigned int gpioValue = 0;
-
-    for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
-        gpio_get_value(pinIn[i], &gpioValue);
-        if (gpioValue == 0x01) {
-            switch (pinIn[i]) {
-            // 小板緊急停止
-            case 47: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 1) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            BoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            BoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            case 27: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 3) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            BoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            BoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            }
-        } else {
-            switch (pinIn[i]) {
-            // 小板解除緊急停止
-            case 47: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 1) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            ReleaseBoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            ReleaseBoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            case 27: {
-                for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-                    if (chargingInfo[i]->slotsIndex == 3) {
-                        if (chargingInfo[i]->Type == _Type_Chademo) {
-                            ReleaseBoardErrOccurByString(i, "023730");
-                        } else if (chargingInfo[i]->Type == _Type_CCS_2) {
-                            ReleaseBoardErrOccurByString(i, "013627");
-                        }
-                        break;
-                    }
-                }
-            }
-            break;
-            }
-        }
-    }
-}
-
-//===============================================
-// Main process
-//===============================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
-{
-    return ( _byte & mask_table[_bit] ) != 0x00;
-}
-
-// 設定 Byte 中某個 Bit的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-// value : 修改的值為 0 or 1
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
-{
-    if (value == 1) {
-        *_byte |= (1 << _bit);
-    } else if (value == 0) {
-        *_byte ^= (1 << _bit);
-    }
-}
-
-void UserScanFunction()
-{
-    bool idleReq = false;
-    unsigned char stopReq = 255;
-
-    // 當前非驗證的狀態
-    if (!IsAuthorizingMode()) {
-#if defined DD360Audi
-        //當前沒有選槍
-        if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == FAIL) { //Jerry add
-            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            return;
-        }
-#endif //defined DD360Audi
-
-        // 先判斷現在是否可以提供刷卡
-        // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
-        // 2. 停止充電
-        if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) {
-            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            return;
-        }
-
-        for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
-            if (chargingInfo[i]->SystemStatus == S_CHARGING) {
-                stopReq = i;
-            }
-            if ((chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable) == YES ||
-                    (_acgunIndex > 0 && ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsAvailable)) {
-                idleReq = true;
-            }
-        }
-
-        if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-                ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-            stopReq = DEFAULT_AC_INDEX;
-        }
-
-        if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0) {
-            if (_acgunIndex > 0 && stopReq == DEFAULT_AC_INDEX && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                char value[32];
-
-                PRINTF_FUNC("ac stop charging \n");
-                PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
-                            ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
-                memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId,
-                       ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
-                    AcChargingTerminalProcess();
-                }
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            } else if (stopReq < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
-                       chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING &&
-                       (_acgunIndex <= 0 || (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE))) {
-                char value[32];
-
-                PRINTF_FUNC("stop charging \n");
-                PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
-                            chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
-                memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
-                       ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
-
-                // 同一張卡直接停掉
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
-                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                } else {
-                    // 進驗證
-                    if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-                        _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
-                    } else {
-                        _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-                    }
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    StartSystemTimeoutDet(Timeout_AuthorizingForStop);
-                    AuthorizingStart();
-#else
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-#endif //!defined DD360 && !defined DD360Audi
-                }
-            } else if (idleReq) {
-                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
-                        stopReq != 255 &&
-                        ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
-                    idleReq = false;
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                } else if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-                           chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE) {
-                    PRINTF_FUNC("// LCM => Authorizing \n");
-#if defined DD360Audi
-                    setSelGunWaitToAuthor(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //Jerry add
-#endif //defined DD360Audi
-                    // LCM => Authorizing
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
-                    // 進入確認卡號狀態
-                    AuthorizingStart();
-                } else {
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                }
-            } else {
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            }
-        }
-    } else {
-        // 透過後臺停止充電的判斷
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
-                    ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-           ) {
-            // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
-                        ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
-                if (_authorizeIndex != NO_DEFINE) {
-                    // 先找 AC
-                    if (_authorizeIndex == DEFAULT_AC_INDEX) {
-                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
-                            AcChargingTerminalProcess();
-                        }
-                    } else {
-                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-                                strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
-                            ChargingTerminalProcess(_authorizeIndex);
-                        }
-                    }
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    _authorizeIndex = NO_DEFINE;
-                }
-            } else {
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            }
-            ClearAuthorizedFlag();
-        } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
-                        ChargingTerminalProcess(_authorizeIndex);
-                        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                        ClearAuthorizedFlag();
-                        break;
-                    }
-                }
-            }
-        }
-    }
-}
-
-unsigned char isModeChange(unsigned char gun_index)
-{
-    unsigned char result = NO;
-
-    if (chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus) {
-        result = YES;
-        chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
-    }
-
-    return result;
-}
-
-void ScannerCardProcess()
-{
-    if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
-            ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
-        isCardScan = true;
-        // 處理刷卡及驗證卡號的動作
-        UserScanFunction();
-    }
-
-    if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING) {
-        StartSystemTimeoutDet(Timeout_Authorizing);
-
-        // 確認驗證卡號完成沒
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi
-           ) {
-            StopSystemTimeoutDet();
-            // 判斷後台回覆狀態
-            if (canStartCharging()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi
-               ) {
-                // LCM => Authorize complete
-                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
-            } else {
-                // LCM => Authorize fail
-                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            }
-            ClearAuthorizedFlag();
-        } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (int i = 0; i < 10; i++) {
-                if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
-                    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
-                        ClearAuthorizedFlag();
-                        break;
-                    }
-                }
-            }
-        }
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL) {
-        StartSystemTimeoutDet(Timeout_VerifyFail);
-        isCardScan = false;
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
-        StartSystemTimeoutDet(Timeout_VerifyComp);
-    } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
-        StartSystemTimeoutDet(Timeout_WaitPlug);
-    } else {
-        isCardScan = false;
-    }
-}
-
-bool AddGunInfoByConnector(byte typeValue, byte slots)
-{
-    bool result = true;
-
-    switch (typeValue) {
-    case '0': // none
-        break;
-    case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
-        break;
-    case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
-        break;
-    case '3': // IEC 62196-2 Type 2 Plug
-    case '4': // IEC 62196-2 Type 2 Socket
-        if (AC_QUANTITY > _ac_Index) {
-            ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
-
-            // AC 固定 index
-            ac_chargingInfo[_acgunIndex]->Index = 0;
-            ac_chargingInfo[_acgunIndex]->ReservationId = -1;
-            ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
-            ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
-            ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
-            ac_chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
-            ac_chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;  //DS60-120 add
-            _ac_Index++;
-            _acgunIndex++;
-        } else {
-            result = false;
-        }
-        break;
-    case '5': // GB/T AC Plug
-        break;
-    case '6': // GB/T AC Socket
-        break;
-    case 'J':
-    case 'K': { // CHAdeMO
-        if (CHAdeMO_QUANTITY > _chademoIndex) {
-            chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
-            chargingInfo[_gunIndex]->Index = _gunIndex;
-            chargingInfo[_gunIndex]->ReservationId = -1;
-            chargingInfo[_gunIndex]->slotsIndex = slots;
-            chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-            chargingInfo[_gunIndex]->Type = _Type_Chademo;
-            chargingInfo[_gunIndex]->type_index = _chademoIndex;
-            chargingInfo[_gunIndex]->IsAvailable = YES;
-            chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
-            chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;  //DS60-120 add
-            _chademoIndex++;
-            _gunIndex++;
-        } else {
-            result = false;
-        }
-    }
-    break;
-
-    case 'T': //Rema CCS1
-    case 'D': //Rema CCS2
-    case 'U': // CCS1 combo
-    case 'E': // CCS2 combo
-    case 'V': // Liquid CCS1 combo
-    case 'F': { // Liquid CCS2 combo
-        if (CCS_QUANTITY > _ccsIndex) {
-            chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
-
-            chargingInfo[_gunIndex]->Index = _gunIndex;
-            chargingInfo[_gunIndex]->ReservationId = -1;
-            chargingInfo[_gunIndex]->slotsIndex = slots;
-            chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-            chargingInfo[_gunIndex]->Type = _Type_CCS_2;
-            chargingInfo[_gunIndex]->type_index = _ccsIndex;
-            chargingInfo[_gunIndex]->IsAvailable = YES;
-            chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
-            chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
-            // 現階段預設為走 DIN70121
-            ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
-            _ccsIndex++;
-            _gunIndex++;
-        } else {
-            result = false;
-        }
-    }
-    break;
-    case 'G': { // GBT DC
-        if (GB_QUANTITY > _gb_Index) {
-            chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
-
-            chargingInfo[_gunIndex]->Index = _gunIndex;
-            chargingInfo[_gunIndex]->ReservationId = -1;
-            chargingInfo[_gunIndex]->slotsIndex = slots;
-            chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-            chargingInfo[_gunIndex]->Type = _Type_GB;
-            chargingInfo[_gunIndex]->type_index = _gb_Index;
-            chargingInfo[_gunIndex]->IsAvailable = YES;
-            chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
-            chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
-            _gb_Index++;
-            _gunIndex++;
-        } else {
-            result = false;
-        }
-    }
-    break;
-
-        //case 'D': // GBT DC x 2
-        //    break;
-    }
-    return result;
-}
-
-bool CheckConnectorTypeStatus()
-{
-    bool result = true;
-
-
-    //PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
-    //            bd0_1_status,
-    //            bd0_2_status,
-    //            bd1_1_status,
-    //            bd1_2_status);
-
-    if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9) {
-        //printf("1 CheckConnectorTypeStatus\r\n");
-        byte slots = 1;
-        for (byte typeIndex = 7; typeIndex <= 9; typeIndex++) {
-            if (!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots)) {
-                return false;
-            }
-
-            slots++;
-        }
-
-        // AC index 接在 DC 後面
-        //if (AC_QUANTITY > 0) {
-        if (_ac_Index > 0) { //DS60-120 add
-            ac_chargingInfo[0]->Index += _gunIndex;
-        }
-
-        ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
-        ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
-        log_info("DC connector Quality = %d, AC connector Quality = %d",
-                 ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
-                 ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
-        log_info("Type 0~3 = CHAdeMO, CCS, GB, AC");
-        if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
-                ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0) {
-            result = false;
-        }
-
-        if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-            //DS60-120 add
-            bool isFind = false;
-            if (chargingInfo[0]->Type == _Type_Chademo) {
-                if ((bd0_1_status == 0 && bd0_2_status == 1) ||
-                        (bd1_1_status == 0 && bd1_2_status == 1)) {
-                    isFind = true;
-                }
-            } else if (chargingInfo[0]->Type == _Type_CCS_2) {
-                if ((bd0_1_status == 1 && bd0_2_status == 0) ||
-                        (bd1_1_status == 1 && bd1_2_status == 0)) {
-                    isFind = true;
-                }
-            } else if (chargingInfo[0]->Type == _Type_GB) {
-                if ((bd0_1_status == 1 && bd0_2_status == 1) ||
-                        (bd1_1_status == 1 && bd1_2_status == 1)) {
-                    isFind = true;
-                }
-            }
-
-            if (isFind) {
-                if (bd0_1_status == 1 || bd0_2_status == 1) {
-                    chargingInfo[0]->Evboard_id = 0x01;
-                }
-
-                if (bd1_1_status == 1 || bd1_2_status == 1) {
-                    chargingInfo[0]->Evboard_id = 0x02;
-                }
-                CheckHwSlotStatusLog(0);
-            } else {
-                result = false;
-            }
-            //chargingInfo[0]->Evboard_id = 0x01;
-            log_info("index = %d, Type = %d, Evboard_id = %d", 0, chargingInfo[0]->Type, chargingInfo[0]->Evboard_id);
-        } else {
-            char type = NO_DEFINE; //DS60-120 add
-
-            // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
-            for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++) {
-                if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1) {
-                    // 與硬體相同 type : Chademo
-                    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0) {
-                    // 與硬體相同 type : CCS
-                    if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1) {
-                    // 與硬體相同 type : GB
-                    if (chargingInfo[gunIndex]->Type == _Type_GB) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                }
-
-                if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1) {
-                    // 與硬體相同 type : Chademo
-                    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x02;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0) {
-                    // 與硬體相同 type : CCS
-                    if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x02;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1) {
-                    // 與硬體相同 type : GB
-                    if (chargingInfo[gunIndex]->Type == _Type_GB) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x02;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
-                        chargingInfo[gunIndex]->Evboard_id = 0x01;
-                    }
-                }
-
-                log_info("index = %d, Type = %d, Evboard_id = %d",
-                         gunIndex,
-                         chargingInfo[gunIndex]->Type,
-                         chargingInfo[gunIndex]->Evboard_id);
-                CheckHwSlotStatusLog(gunIndex);
-
-                if (type == NO_DEFINE) {
-                    type = chargingInfo[gunIndex]->Type;
-                }
-
-                if (chargingInfo[gunIndex]->Evboard_id == 0x00) {
-                    result = false;
-                }
-            }
-        }
-    } else {
-        // Module Name 不正確 - 告警
-        result = false;
-    }
-
-    return result;
-}
-
-void KillTask()
-{
-    ChangeLcmByIndex(_LCM_FIX);
-    system("killall Module_EventLogging");
-    system("killall Module_PrimaryComm");
-    system("killall Module_EvComm");
-    system("killall Module_LcmControl");
-    system("killall Module_InternalComm");
-    //system("killall DoComm");
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    system("killall Module_PsuComm");
-    system("killall OcppBackend &");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-void KillTaskExceptPrimary()
-{
-    ChangeLcmByIndex(_LCM_FIX);
-    system("killall Module_EvComm");
-    system("killall Module_InternalComm");
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    system("killall Module_PsuComm");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-void KillAllTask()
-{
-    ChangeLcmByIndex(_LCM_FIX);
-    system("killall Module_EventLogging");
-    system("killall Module_PrimaryComm");
-    system("killall Module_EvComm");
-    system("killall Module_LcmControl");
-    system("killall Module_InternalComm");
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    system("killall Module_PsuComm");
-    system("killall OcppBackend &");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
-#else
-    system("killall DoComm");
-#endif //!defined DD360 && !defined DD360Audi
-}
-
-int CheckUpdateProcess(void)
-{
-    //bool isPass = true;
-    uint8_t retSucc = 0;
-    uint8_t retFail = 0;
-    byte index = 0;
-    byte target = 0;
-    char *new_str = NULL;
-    unsigned char *ptr = NULL;
-    int fd = 0;
-    int CanFd = 0;
-    int uartFd = 0;
-    unsigned int Type = 0;
-    long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
-    DIR *d;
-    struct dirent *dir;
-
-    d = opendir("/mnt/");
-    if (d) {
-        while ((dir = readdir(d)) != NULL) {
-            if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
-                continue;
-            }
-
-            new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
-            //new_str[0] = '\0';
-            strcat(new_str, "/mnt/");
-            strcat(new_str, dir->d_name);
-            log_info("%s%s\r\n", "/mnt/", dir->d_name);
-            fd = open(new_str, O_RDONLY);
-            if (fd < 0) {
-                return FAIL;
-            }
-
-            ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
-            //memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
-
-            //get the image length
-            ImageLen = read(fd, ptr, MaxLen);
-            for (byte i = 0; i < 16; i++) {
-                if (ShmSysConfigAndInfo->SysConfig.ModelName[i] != ptr[i]) {
-                    return FAIL;
-                }
-            }
-
-            PRINTF_FUNC("model name check pass. \n");
-            if (ImageLen > 20) {
-                Type = (((unsigned int)ptr[16]) << 24 |
-                        ((unsigned int)ptr[17]) << 16 |
-                        ((unsigned int)ptr[18]) << 8  |
-                        ((unsigned int)ptr[19]));
-                PRINTF_FUNC("Typed...%x \r\n", Type);
-
-                switch (Type) {
-                case 0x10000001:
-                case 0x10000002:
-                case 0x10000003:
-                case 0x10000004:
-                case 0x10000005:
-                    if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-                        //return PASS;
-                        retSucc++;
-                    } else {
-                        PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                        //return FAIL;
-                        retFail++;
-                    }
-                    break;
-
-                case 0x10000007:
-                case 0x10000008:
-                case 0x10000009:
-                case 0x1000000A:
-                    //isPass = true;
-                    CanFd = InitCanBus();
-                    if (CanFd > 0) {
-                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                            //if (!isPass) {
-                            //    break;
-                            //}
-
-                            if (chargingInfo[index]->Type == _Type_CCS_2) {
-                                if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL) {
-                                    //isPass = false;
-                                    PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                                    retFail++;
-                                }
-                            }
-                        }
-                    } else {
-                        log_error("Upgrade CCS open CAN FD fail.\n");
-                        //isPass = false;
-                        return FAIL;
-                    }
-
-                    if (retFail != 0) {
-                        break;
-                    } else {
-                        retSucc++;
-                    }
-                    //return isPass;
-                    break;
-
-                case 0x10000006:
-                case 0x1000000D:
-                case 0x1000000E:
-                case 0x20000002:
-                case 0x10000014:
-                    // CSU_PRIMARY_CONTROLLER : 0x10000006
-                    target = 0x00;
-
-                    if (Type == 0x10000006) {
-                        target = UPGRADE_PRI;
-                    } else if (Type == 0x1000000D) {
-                        target = UPGRADE_RB;
-                    } else if (Type == 0x1000000E) {
-                        target = UPGRADE_FAN;
-                    } else if (Type == 0x20000002) {
-                        target = UPGRADE_AC;
-                    } else if (Type == 0x10000014) {
-                        target = UPGRADE_LED;
-                    }
-
-                    uartFd = InitComPort(target);
-
-                    if (Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-                        //return PASS;
-                        retSucc++;
-                    } else {
-                        PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                        //return FAIL;
-                        return FAIL;
-                    }
-
-                    if (uartFd > 0) {
-                        close(uartFd);
-                    }
-                    break;
-
-                case 0x1000000B:
-                case 0x1000000C:
-                    // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
-                    //bool isPass = true;
-                    CanFd = InitCanBus();
-                    if (CanFd > 0) {
-                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                            //if (!isPass) {
-                            //    break;
-                            //}
-
-                            if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
-                                    (Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB)) {
-                                if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
-                                    //isPass = PASS;
-                                    retSucc++;
-                                } else {
-                                    PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
-                                    //isPass = FAIL;
-                                    retFail++;
-                                }
-                            }
-                        }
-                    } else {
-                        PRINTF_FUNC("Upgrad FD fail. \n");
-                        //isPass = false;
-                        return FAIL;
-                    }
-
-                    //return isPass;
-                    break;
-                }
-            }
-            free(new_str);
-            free(ptr);
-        }
-    }
-    free(dir);
-    closedir(d);
-
-    if (retFail != 0) {
-        return FAIL;
-    }
-
-    return PASS;
-}
-
-void CreateRfidFork()
-{
-    pid_t rfidRecPid;
-
-    rfidRecPid = fork();
-    log_info("CreateRfidFork = %d\r\n", rfidRecPid);
-    if (rfidRecPid == 0) {
-        while (true) {
-            // 刷卡判斷
-            RFID rfid;
-            if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
-                    !ShmSysConfigAndInfo->SysConfig.isRFID)
-            {}
-            else if (getRequestCardSN(rfidFd, 0, &rfid)) {
-                //log_info("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
-                if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0) {
-                    if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
-                        switch (rfid.snType) {
-                        case RFID_SN_TYPE_6BYTE:
-                            sprintf((char *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.UserId,
-                                    "%02X%02X%02X%02X",
-                                    rfid.currentCard[0], rfid.currentCard[1],
-                                    rfid.currentCard[2], rfid.currentCard[3]);
-                            break;
-                        }
-                    } else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG) {
-                        switch (rfid.snType) {
-                        case RFID_SN_TYPE_6BYTE:
-                            sprintf((char *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.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 *) ShmSysConfigAndInfo->SysConfig.UserId,
-                                    "%02X%02X%02X%02X",
-                                    rfid.currentCard[3], rfid.currentCard[2],
-                                    rfid.currentCard[1], rfid.currentCard[0]);
-                            break;
-                        }
-                    }
-                    log_info("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
-                }
-            }
-            usleep(500000);
-        }
-    }
-}
-
-void StartSystemTimeoutDet(unsigned char flag)
-{
-    if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag) {
-        gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-    }
-    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
-}
-
-void StopSystemTimeoutDet()
-{
-    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
-}
-
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
-{
-    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
-        if (chargingInfo[gunIndex]->TimeoutFlag != flag) {
-            gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
-        }
-        chargingInfo[gunIndex]->TimeoutFlag = flag;
-    }
-}
-
-void StopGunInfoTimeoutDet(unsigned char gunIndex)
-{
-    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
-        chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
-    }
-}
-
-void CheckConnectionTimeout()
-{
-    if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
-        _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
-    } else {
-        _connectionTimeout = CONN_PLUG_TIME_OUT;
-    }
-
-#if 0
-    if (system("pidof -s OcppBackend > /dev/null") != 0) {
-        _connectionTimeout = CONN_PLUG_TIME_OUT;
-    } else {
-        if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
-            _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
-            if (_connectionTimeout <= 0) {
-                _connectionTimeout = CONN_PLUG_TIME_OUT;
-            }
-        } else {
-            _connectionTimeout = CONN_PLUG_TIME_OUT;
-        }
-    }
-#endif //0
-}
-
-void CreateTimeoutFork()
-{
-    pid_t timeoutPid;
-
-    timeoutPid = fork();
-    log_info("CreateTimeoutFork = %d\r\n", timeoutPid);
-    if (timeoutPid == 0) {
-        gettimeofday(&_cmdSubPriority_time, NULL);
-        CheckConnectionTimeout();
-
-        while (1) {
-            if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
-                CheckConnectionTimeout();
-                gettimeofday(&_cmdSubPriority_time, NULL);
-            }
-
-            //printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
-            // 系統
-            switch (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag) {
-            case Timeout_SelftestChk:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
-                    _SelfTestTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(DESTROY_ALL_SEL); //jerry add
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_Authorizing:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
-                    _AuthorizedTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_VerifyFail:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
-                    _AutoReturnTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_VerifyComp:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
-                    _AutoReturnTimeout();
-                    StopSystemTimeoutDet();
-                }
-                break;
-            case Timeout_WaitPlug:
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
-                    _DetectPlugInTimeout();
-                    StopSystemTimeoutDet();
-#if defined DD360Audi
-                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-#endif //defined DD360Audi
-                }
-                break;
-            case Timeout_ReturnToChargingGunDet: {
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
-#if defined DD360Audi
-                    if (getCurLcmPage() != _LCM_PRE_CHARGE &&
-                            getCurLcmPage() != _LCM_CHARGING &&
-                            getCurLcmPage() != _LCM_COMPLETE) {
-                        destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //jerry add
-
-                    }
-#endif //defined DD360Audi
-                    DisplayChargingInfo();
-                    StopSystemTimeoutDet();
-                }
-            }
-            break;
-            case Timeout_AuthorizingForStop: {
-                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ClearAuthorizedFlag();
-                    StopSystemTimeoutDet();
-                }
-            }
-            break;
-            }
-            // 各槍
-            for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-                //printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
-                switch (chargingInfo[gun_index]->TimeoutFlag) {
-                case Timeout_Preparing: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
-                        _PrepareTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_EvChargingDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
-                        _DetectEvChargingEnableTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_EvseChargingDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
-                        _DetectEvseChargingEnableTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_EvseCompleteDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-                case Timeout_ForCcsPrechargeDet: {
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
-                        _CcsPrechargeTimeout(gun_index);
-                        StopGunInfoTimeoutDet(gun_index);
-#if defined DD360Audi
-                        destroySelGun(gun_index); //jerry add
-#endif //defined DD360Audi
-                    }
-                }
-                break;
-
-#if defined DD360Audi
-                case Timeout_SelectGun: //Jerry add
-                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
-                        log_info("Timeout_SelectGun\r\n");
-                        StopGunInfoTimeoutDet(gun_index);
-                        destroySelGun(gun_index); //jerry add
-                    }
-                    break;
-#endif //defined DD360Audi
-                }
-            }
-            sleep(1);
-        }
-    }
-}
-
-void GetSystemTime()
-{
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-    PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-                tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-                tmCSU->tm_sec);
-
-//  byte date[14];
-//
-//
-//       //sprintf(&date, "%d", );
-//
-//       date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
-
-//  date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
-//  date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
-//  date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
-//  date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
-//
-//  date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
-//  date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
-//
-//  date[6] = (tmCSU->tm_mday) / 10 % 10;
-//  date[7] = (tmCSU->tm_mday) / 1 % 10;
-//
-//  date[8] = (tmCSU->tm_hour) / 10 % 10;
-//  date[9] = (tmCSU->tm_hour) / 1 % 10;
-//
-//  date[10] = (tmCSU->tm_min) / 10 % 10;
-//  date[11] = (tmCSU->tm_min) / 1 % 10;
-//
-//  date[12] = (tmCSU->tm_sec) / 10 % 10;
-//  date[13] = (tmCSU->tm_sec) / 1 % 10;
-
-//  PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
-//          date[4], date[5], date[6], date[7],
-//          date[8], date[9], date[10], date[11],
-//          date[12], date[13]);
-}
-
-void CheckFactoryConfigFunction(void)
-{
-    char Buf[256] = {0};
-
-    if (ShmSysConfigAndInfo->SysInfo.FactoryConfiguration) {
-        sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
-                ShmSysConfigAndInfo->SysConfig.ModelName,
-                ShmSysConfigAndInfo->SysConfig.SerialNumber);
-        system(Buf);
-
-        system("rm -f /Storage/OCPP/OCPPConfiguration");
-        system("sync");
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-}
-
-void CheckFwUpdateFunction()
-{
-    //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
-    if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
-        log_info("ftp : update start. \n");
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_UPDATE);
-        }
-
-        byte updateResult = CheckUpdateProcess();
-
-        if (updateResult == PASS) {
-            log_info("ftp : update complete. \n");
-        } else if (updateResult == MODELNAME_FAIL) {
-            log_info("ftp : model name is none match. \n");
-            KillAllTask();
-            ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
-            sleep(5);
-            system("/usr/bin/run_evse_restart.sh");
-            return;
-        } else {
-            log_info("ftp : update fail. \n");
-        }
-
-        ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
-        sleep(5);
-        system("reboot -f");
-    } else if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
-        ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
-
-        if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
-            log_info("Backend : update start. \n");
-            strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
-            strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
-            ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-            KillTask();
-
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                setChargerMode(_index, MODE_UPDATE);
-            }
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
-                ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
-            }
-
-            byte updateResult = CheckUpdateProcess();
-
-            if (updateResult == PASS) {
-                log_info("Backend : update complete. \n");
-                strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
-            } else if (updateResult == MODELNAME_FAIL) {
-                log_info("Backend : model name is none match. \n");
-                KillAllTask();
-                strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
-                ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-                sleep(5);
-                system("/usr/bin/run_evse_restart.sh");
-                return;
-            } else {
-                log_info("Backend : update fail. \n");
-                strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
-            }
-
-            strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
-            ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-            sleep(5);
-            system("reboot -f");
-        }
-    }
-}
-
-//===============================================
-// Check reservation date is expired
-//===============================================
-int isReservationExpired(unsigned char gun_index)
-{
-    int result = NO;
-    struct tm expiredDate;
-    struct timeb expiredTime;
-
-    if (sscanf((char *) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
-               "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
-               &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
-               &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
-        expiredDate.tm_year -= 1900;
-        expiredDate.tm_mon -= 1;
-
-        expiredTime.time = mktime(&expiredDate);
-        if (!CheckTimeOut(expiredTime)) {
-            result = YES;
-        }
-    }
-
-    return result;
-}
-
-//===============================================
-// OCPP
-//===============================================
-void CheckOcppStatus()
-{
-    if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
-        ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
-    }
-
-    if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
-        bool canReset = true;
-        bool canHardReset = true; //DS60-120 add
-
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                if (chargingInfo[_index]->SystemStatus != S_IDLE &&
-                        chargingInfo[_index]->SystemStatus != S_RESERVATION &&
-                        chargingInfo[_index]->SystemStatus != S_MAINTAIN) {
-                    canReset = false;
-                    if (chargingInfo[_index]->SystemStatus >= S_REASSIGN &&
-                            chargingInfo[_index]->SystemStatus < S_TERMINATING) {
-                        canHardReset = false;
-                        ChargingTerminalProcess(_index);
-                        restartFlag = 1;
-                    }
-                }
-            }
-        }
-
-        if (canReset) {
-            ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
-            sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
-            if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
-                log_error("****** Hard Reboot ****** \n");
-                ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-                sleep(3);
-                system("reboot -f");
-            } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
-                log_error("****** Soft Reboot ****** \n");
-                ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-                sleep(3);
-                system("killall OcppBackend &");
-                KillAllTask();
-                system("/usr/bin/run_evse_restart.sh");
-            }
-        }
-    }
-}
-
-void OcppStartTransation(byte gunIndex)
-{
-    byte _OcppGunIndex = gunIndex;
-
-    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
-    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
-        _OcppGunIndex = 2;
-    }
-
-    if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
-    }
-
-    PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
-}
-
-void OcppStopTransation(byte gunIndex)
-{
-    byte _OcppGunIndex = gunIndex;
-
-    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
-    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
-        _OcppGunIndex = 2;
-    }
-
-    if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
-    } else {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
-    }
-
-    PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
-    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
-}
-
-bool OcppRemoteStop(byte gunIndex)
-{
-    byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-
-    // 有 AC 槍的話
-    if (acDirIndex > 0 && gunIndex > 0) {
-        gunIndex += acDirIndex;
-    }
-
-    bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
-        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
-    }
-
-    return result;
-}
-
-bool WifiScheduleStop(byte gunIndex)
-{
-    bool result = false;
-
-    result = chargingInfo[gunIndex]->schedule.isTriggerStop;
-    chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
-
-    return result;
-}
-
-void OcppRemoteStartChk()
-{
-    if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
-    {}
-    else if (!isDetectPlugin()) {
-        // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
-        byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-
-        for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++) {
-            if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
-                if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
-                        ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
-                    ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-                    ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
-                    ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                    //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
-                    ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
-                    return;
-                }
-                ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-            }
-        }
-
-        byte threeGunIndex = 0;
-        byte dcIndex = 0;
-        bool isGunUsingStatus = false;
-
-        for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-            // 如果有 AC 槍,且 DC 槍也有兩把
-            if (acDirIndex == 1 && _index == 1) {
-                threeGunIndex = 1;
-            }
-
-            if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES) {
-                dcIndex = _index;
-            }
-
-            if (chargingInfo[_index]->SystemStatus != S_IDLE) {
-                isGunUsingStatus = true;
-            }
-        }
-
-        // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
-        if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
-            if (dcIndex == 0) {
-                threeGunIndex = 0;
-            }
-
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-            return;
-        }
-
-        if (dcIndex == 0) {
-            threeGunIndex = 0;
-        }
-
-        if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES) {
-            if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
-                    chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
-                chargingInfo[dcIndex]->RemoteStartFlag = YES;
-                ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
-                ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-                DetectPluginStart();
-#if defined DD360Audi
-                setSelGunWaitToAuthor(dcIndex); //Jerry add
-#endif //defined DD360Audi
-            }
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-        }
-    }
-}
-
-void ChkOcppStatus(byte gunIndex)
-{
-    if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
-            ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
-        ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
-        if (isReservationExpired(gunIndex)) {
-            PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
-            log_error("***************ChkOcppStatus : OcppReservedStatus******************** \n");
-            chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
-            chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
-        }
-        ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
-    }
-
-    if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
-            ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
-        ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
-        if (isReservationExpired(gunIndex)) {
-            PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
-            log_error("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
-            chargingInfo[gunIndex]->ReservationId = 0;
-            chargingInfo[gunIndex]->SystemStatus = S_IDLE;
-        }
-        ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
-    }
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
-        PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
-        log_error("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
-        if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
-            if (isDb_ready) {
-                DB_Update_Operactive(localDb, gunIndex, true);
-            }
-
-            chargingInfo[gunIndex]->IsAvailable = YES;
-            if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
-                    chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
-                    chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
-                setChargerMode(gunIndex, MODE_IDLE);
-            }
-        } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
-            if (isDb_ready) {
-                DB_Update_Operactive(localDb, gunIndex, false);
-            }
-
-            chargingInfo[gunIndex]->IsAvailable = NO;
-            if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
-                    chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
-                    chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
-                setChargerMode(gunIndex, MODE_MAINTAIN);
-            }
-        }
-    }
-
-    if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
-        ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
-        if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
-                chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
-            // 充電中,需停止充電
-            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
-            ChargingTerminalProcess(gunIndex);
-        }
-        strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
-        ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
-    }
-}
-
-bool CheckBackendChargingTimeout(byte gunIndex)
-{
-    bool result = false;
-
-    if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
-        if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60)) {
-                result = true;
-            }
-        }
-    } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-        // 隨插即充電的要看 offline
-        if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60)) {
-                result = true;
-            }
-        }
-    }
-
-    return result;
-}
-
-bool CheckBackendChargingEnergy(byte gunIndex)
-{
-    bool result = false;
-
-    if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
-        if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy) {
-                result = true;
-            }
-        }
-    } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
-        // 隨插即充電的要看 offline
-        if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) {
-            if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) {
-                result = true;
-            }
-        }
-    }
-
-    return result;
-}
-
-void InformOcppErrOccur(byte codeType)
-{
-    char _error[25];
-
-    switch (codeType) {
-    case 4: strcpy(_error, "InternalError"); break;
-    case 6: strcpy(_error, "NoError"); break;
-    case 7: strcpy(_error, "OtherError"); break;
-    case 13: strcpy(_error, "UnderVoltage"); break;
-    case 14: strcpy(_error, "OverVoltage"); break;
-    }
-
-    for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-        strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, _error);
-    }
-}
-
-//===============================================
-// SQLite3 related routine
-//===============================================
-int DB_Open(sqlite3 *db)
-{
-    int result = PASS;
-    char *errMsg = NULL;
-    char *createRecordSql = "CREATE TABLE IF NOT EXISTS charging_record("
-                            "idx integer primary key AUTOINCREMENT, "
-                            "reservationId text, "
-                            "transactionId text, "
-                            "startMethod text, "
-                            "userId text, "
-                            "dateTimeStart text, "
-                            "dateTimeStop text,"
-                            "socStart text, "
-                            "socStop text, "
-                            "chargeEnergy text, "
-                            "stopReason text"
-                            ");";
-
-    /*char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
-                         "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                         "`IsAvailable` TEXT NOT NULL, "
-                         "`connector` INTEGER NOT NULL, "
-                         "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
-    */
-    //DS60-120 add
-    char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
-                         "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                         "`item` TEXT NOT NULL, "
-                         "`connector` INTEGER NOT NULL, "
-                         "`val` TEXT NOT NULL, unique(item,connector) on conflict replace);";
-
-    char *createrecordSql = "CREATE TABLE IF NOT EXISTS `event_record` ( "
-                            "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                            "`occurDatetime` TEXT NOT NULL, "
-                            "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
-
-    char *createrebootSql = "CREATE TABLE IF NOT EXISTS `reboot_record` ( "
-                            "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-                            "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local charging record database open successfully.\r\n");
-
-        if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened local charging record table successfully\n");
-        }
-
-        if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened local config table successfully\n");
-        }
-
-        //DS60-120
-        if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create local record table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened local record table successfully\n");
-        }
-
-        if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Create reboot record table error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Opened reboot record table successfully\n");
-        }
-        //-----
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Insert_Record(sqlite3 *db, int gun_index)
-{
-    int result = PASS;
-    char *errMsg = NULL;
-    char insertSql[1024];
-
-    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');",
-            chargingInfo[gun_index]->ReservationId, //DS60-120 add
-            ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
-            chargingInfo[gun_index]->StartMethod,
-            chargingInfo[gun_index]->StartUserId,
-            chargingInfo[gun_index]->StartDateTime,
-            chargingInfo[gun_index]->StopDateTime,
-            chargingInfo[gun_index]->EvBatteryStartSoc,
-            chargingInfo[gun_index]->EvBatterySoc,
-            chargingInfo[gun_index]->PresentChargedEnergy,
-            //DS60-120 remove
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
-            //ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-            //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
-            ShmOCPP16Data->StopTransaction[gun_index].StopReason);
-
-    //if (sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db)) {
-    if (sqlite3_open(DB_FILE, &db)) { //DS60-120 add
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local charging record database open successfully.\r\n");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Insert local charging record successfully\n");
-        }
-
-        //DS60-120 add
-        sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "delete local charging error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "delete local charging record successfully\n");
-        }
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
-{
-    uint8_t result = false;
-    char *errMsg = NULL;
-    char sqlStr[1024];
-    srand(time(NULL));
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "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
-        PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
-        if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "update config error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
-        }
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
-{
-    uint8_t result = true;
-    char *errMsg = NULL;
-    char sqlStr[1024];
-    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
-    //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local config query database open successfully.\r\n");
-        sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
-        if (rows > 0) {
-            for (int idxRow = 1; idxRow <= rows; idxRow++) {
-                if (strcmp(rs[(idxRow * cols) + 3], "0") == 0) {
-                    result = false;
-                }
-                PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
-            }
-        } else {
-            PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
-        }
-
-        sqlite3_free_table(rs);
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-int DB_Reboot_Record(sqlite3 *db)
-{
-    int result = PASS;
-    char *errMsg = NULL;
-    char insertSql[256];
-
-    sprintf(insertSql, "insert into reboot_record(rebootDatetime) values(CURRENT_TIMESTAMP);");
-
-    if (sqlite3_open(DB_FILE, &db)) {
-        result = FAIL;
-        PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
-        sqlite3_close(db);
-    } else {
-        PRINTF_FUNC( "Local charging record database open successfully.\n");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "Insert reboot record error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "Insert reboot record successfully\n");
-        }
-
-        sprintf(insertSql, "delete from reboot_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
-        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
-            result = FAIL;
-            PRINTF_FUNC( "delete reboot record error message: %s\n", errMsg);
-        } else {
-            PRINTF_FUNC( "delete reboot record successfully\n");
-        }
-
-        sqlite3_close(db);
-    }
-
-    return result;
-}
-
-//===============================================
-// Config process
-//===============================================
-void AddPlugInTimes(byte gunIndex)
-{
-    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
-        ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
-    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
-        ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
-    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
-        ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
-    }
-}
-
-void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
-{
-    char cmdBuf[32];
-    struct timeb csuTime;
-    struct tm *tmCSU;
-
-    ftime(&csuTime);
-    tmCSU = localtime(&csuTime.time);
-
-    sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
-            tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-            tmCSU->tm_sec);
-    if (isStart) {
-        strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
-    } else {
-        strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
-    }
-}
-
-void zipLogFiles()
-{
-    const char *logPath = "/Storage/SystemLog";
-    // 獲取目錄
-    DIR *pDir = opendir(logPath);
-    if (pDir != NULL) {
-        struct timeb csuTime;
-        struct tm *tmCSU;
-
-        ftime(&csuTime);
-        tmCSU = localtime(&csuTime.time);
-//      PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//          tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//          tmCSU->tm_sec);
-
-        // Read items inside the folder
-        struct dirent *pEntry = NULL;
-        while ((pEntry = readdir(pDir)) != NULL) {
-            if (strcmp(pEntry->d_name, ".") != 0 &&
-                    strcmp(pEntry->d_name, "..") != 0 &&
-                    strncmp(pEntry->d_name, "[", 1) == 0 &&
-                    strstr(pEntry->d_name, "tar") < 0) {
-                char yearC[5];
-                unsigned short year = 0;
-                char monthC[3];
-                unsigned short month = 0;
-
-                yearC[4] = '\0';
-                strncpy(yearC, pEntry->d_name + 1, 4);
-                monthC[2] = '\0';
-                strncpy(monthC, pEntry->d_name + 6, 2);
-
-                year = atoi(yearC);
-                month = atoi(monthC);
-
-                if (year != 0) {
-                    if (year < tmCSU->tm_year + 1900 ||
-                            (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1)) {
-                        log_info("tar file name : %s \n", pEntry->d_name);
-                        char file[256];
-
-                        memset(file, 0x00, sizeof(file));
-                        strcat(file, "tar zcvf ");
-                        strcat(file, logPath);
-                        strncat(file, "/", 1);
-                        strcat(file, pEntry->d_name);
-                        strcat(file, ".tar");
-                        strncat(file, " ", 1);
-                        strcat(file, logPath);
-                        strncat(file, "/", 1);
-                        strcat(file, pEntry->d_name);
-                        PRINTF_FUNC("zip = %s \n", file);
-                        system(file);
-                    }
-                }
-            }
-        }
-    }
-    // Close folder
-    closedir(pDir);
-}
-
-void ChangeGunSelectByIndex(byte sel)
-{
-    ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
-    ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
-}
-
-void CheckIsAlternatvieByModelName()
-{
-    // 黑白機 ?
-    /*if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWWU301J0UT1PH") == EQUAL ||
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ET1PH") == EQUAL ||
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DSYE301J3EW2PH") == EQUAL ||
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UW1PH") == EQUAL) {
-      */
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W') { //DS60-120
-        // 壁掛
-        ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
-    } else {
-        ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
-    }
-}
-
-void StopProcessingLoop()
-{
-    for (;;) {
-        CheckFactoryConfigFunction();
-        CheckFwUpdateFunction();
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-            ChkPrimaryStatus();
-            if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0) {
-                PRINTF_FUNC("Soft reboot for retry self-tets (Primary). \n");
-                KillAllTask();
-                sleep(3);
-                system("/usr/bin/run_evse_restart.sh");
-                return;
-            }
-        }
-        sleep(1);
-    }
-}
-
-void CreateWatchdog()
-{
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO) {
-        wtdFd = InitWatchDog();
-
-        if (wtdFd < 0) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-        }
-    }
-}
-
-bool IsConnectorWholeIdle()
-{
-    bool result = true;
-
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
-        if (chargingInfo[count]->SystemStatus != S_IDLE &&
-                chargingInfo[count]->SystemStatus != S_RESERVATION) {
-            result = false;
-            break;
-        }
-    }
-
-    for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
-        if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
-                ac_chargingInfo[count]->IsErrorOccur == NO) {
-            result = false;
-            break;
-        }
-    }
-
-    return result;
-}
-
-void ClearAlarmCodeWhenAcOff()
-{
-    if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
-    }
-}
-
-//==========================================
-// Check task processing
-//==========================================
-void CheckTask()
-{
-    /*+++ 20200908, vern, disable it for DD360 +++*/
-#if 0
-    if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
-        if (system("pidof -s Module_4g > /dev/null") != 0) {
-            log_error("Module_4g not running, restart it.\r\n");
-            system("/root/Module_4g &");
-        }
-    } else if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
-        if (system("pidof -s Module_Wifi > /dev/null") != 0) {
-            log_error("Module_Wifi not running, restart it.\r\n");
-            system("/root/Module_Wifi &");
-        }
-    }
-
-    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
-            strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
-        if (system("pidof -s OcppBackend > /dev/null") != 0) {
-            log_error("OcppBackend not running, restart it.\r\n");
-            system("/root/OcppBackend &");
-        }
-    }
-#endif
-    /*--- 20200908, vern, disable it for DD360 ---*/
-    if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
-        log_error("Module_ProduceUtils not running, restart it.\r\n");
-        system ("/root/Module_ProduceUtils &");
-    }
-}
-
-void InitialDHCP()
-{
-    char tmpbuf[256] = {0};
-
-    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 &",
-            ShmSysConfigAndInfo->SysConfig.SystemId);
-    system(tmpbuf);
-}
-
-//==========================================
-// Check Smart Charging Profile
-//==========================================
-int GetStartScheduleTime(unsigned char *time)
-{
-    int result = -1;
-    struct tm tmScheduleStart;
-    struct timeb tbScheduleStart;
-
-    if ((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6)) {
-        tmScheduleStart.tm_year -= 1900;
-        tmScheduleStart.tm_mon -= 1;
-        tbScheduleStart.time = mktime(&tmScheduleStart);
-        tbScheduleStart.millitm = 0;
-
-        result = DiffTimebWithNow(tbScheduleStart) / 1000;
-    }
-
-    return result;
-}
-
-void CheckSmartChargeProfile(byte _index)
-{
-    if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
-        // Get Charging Profile
-        ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
-        if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
-                ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
-           ) {
-            int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
-            byte _startCount = NO_DEFINE;
-            byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
-
-            for (byte _count = 0; _count < _maxCount; _count++) {
-                // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
-                if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
-                    if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
-                            ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
-                        _startCount = _count;
-                    }
-                }
-            }
-
-            PRINTF_FUNC("_startCount = %d \n", _startCount);
-            if (_startCount < _maxCount) {
-                //DS60-120 add
-                PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
-                chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
-                if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0) {
-                    chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
-                } else {
-                    chargingInfo[_index]->ChargingProfileCurrent = 0;
-                }
-
-                //DS60-120 remove
-                //PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
-                //chargingInfo[_index]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
-                //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * chargingInfo[_index]->EvBatterytargetVoltage / 100;
-
-                //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
-//              if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
-//              {
-//                  chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
-//              }
-            } else {
-                chargingInfo[_index]->ChargingProfilePower = -1;
-                chargingInfo[_index]->ChargingProfileCurrent = -1;
-            }
-        } else {
-            chargingInfo[_index]->ChargingProfilePower = -1;
-            chargingInfo[_index]->ChargingProfileCurrent = -1;
-        }
-
-        PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
-        PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
-    }
-//
-//      printf("-------------Schedule------------\n");
-//      printf("index = %d \n", _index);
-//      printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
-//      printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
-//      printf("----------SchedulePeriod---------\n");
-//      for (int v = 0; v < 10; v++)
-//      {
-//          printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
-//          printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
-//      }
-//      printf("---------------------------------\n");
-}
-
-void ChargingProfileFlat(byte _index)
-{
-    if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
-        if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
-            ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
-        }
-    }
-}
-
-void CheckReturnToChargingConn()
-{
-    if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
-            ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG) {
-        bool isReturnTimeout = false;
-
-        for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
-            // 如果選的 DC 槍在充電~ 則 DC 槍不改變
-            if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-                if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
-                        (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                    isReturnTimeout = false;
-                    break;
-                }
-            } else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-                if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
-                        (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                    isReturnTimeout = true;
-                    StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-                }
-            }
-        }
-
-        // AC 槍
-        if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0) {
-            // 沒有選中 AC,且 AC 在充電中
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
-                    (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)) {
-                // 當前 DC 充電槍在 idle 狀態
-                if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
-                        chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION) {
-                    isReturnTimeout = true;
-                    StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-                }
-            } else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-                       ((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
-                        (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1))) {
-                // 當前 DC 充電槍在 idle 狀態
-                if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
-                        ac_chargingInfo[0]->SystemStatus == S_RESERVATION) {
-                    isReturnTimeout = true;
-                    StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-                }
-            }
-        }
-
-        if (!isReturnTimeout) {
-            StopSystemTimeoutDet();
-        }
-    }
-}
-
-bool GetStartChargingByAlterMode(byte _gun)
-{
-    bool result = true;
-
-    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
-            ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
-        for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++) {
-            if (_select != _gun) {
-                if (chargingInfo[_select]->SystemStatus != S_IDLE &&
-                        chargingInfo[_select]->SystemStatus != S_RESERVATION) {
-                    result = false;
-                    break;
-                }
-            }
-        }
-    }
-
-    return result;
-}
-
-void TheEndCharging(byte gun_index)
-{
-    ftime(&endChargingTime[gun_index]);
-    if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
-        chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-    }
-
-    chargingInfo[gun_index]->isRemoteStart = NO;
-
-    StopGunInfoTimeoutDet(gun_index);
-    StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
-    ChangeStartOrStopDateTime(NO, gun_index);
-    DB_Insert_Record(localDb, gun_index);
-}
-
-void UpdateErrorCodeToOcpp(byte index)
-{
-    uint8_t i = 0;
-
-    //if ((strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") == EQUAL) &&
-    //        (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") == EQUAL)
-    //   ) {
-    //    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-    //        if (strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012251", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012252", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012238", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042251", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042252", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042200", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042201", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042202", 6) == EQUAL ||
-    //                strncmp((char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == EQUAL) {
-    //            strncpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 6);
-    //            //log_info("1 %d = VendorErrorCode = %s\r\n", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
-    //            break;
-    //        }
-    //    }
-    //}
-
-    //log_info("%d = ConnectorAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->ConnectorAlarmCode);
-    //log_info("%d = EvConnAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->EvConnAlarmCode);
-    if (strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") != EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->ConnectorAlarmCode);
-    } else if (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") != EQUAL) {
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
-        strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->EvConnAlarmCode);
-    }
-
-    //log_info("2 %d = VendorErrorCode = %s\r\n", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
-}
-
-void AdjustChargerCurrent()
-{
-    ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
-
-    // 設定的電流~ 如超過可輸出的電流,則 bypass
-    if (ShmSysConfigAndInfo->SysConfig.RatingCurrent < ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent ||
-            ShmSysConfigAndInfo->SysConfig.RatingCurrent == 0) {
-        ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = 0;
-    }
-
-    PRINTF_FUNC ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
-                 ShmPsuData->SystemAvailablePower / 10,
-                 ShmPsuData->SystemAvailableCurrent / 10
-                );
-
-    PRINTF_FUNC ("Config : ChargingPower = %d, ChargingCurrent = %d",
-                 ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
-                 ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
-                );
-}
-
-#if METER_ENABLE
-void CheckStatusOfMeter()
-{
-    // 橋接如果搭上~ 則兩個電表都是使用狀態
-    // 如橋接沒有搭上~ 則視該火線 relay 狀態為電表使用狀態
-    if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
-        for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
-            ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
-        }
-    } else {
-        for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
-            if (chargingInfo[mIndex]->RelayKPK2Status == YES || chargingInfo[mIndex]->RelayK1K2Status) {
-                ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
-            } else {
-                ShmCsuMeterData->_meter[mIndex].isCalculation = NO;
-            }
-        }
-    }
-}
-
-void CheckRelayWeldingOrDrivingFault(byte gun_index)
-{
-    // relay welding fault then stop the charging process.
-    byte faultCode = RELAY_STATUS_ERROR_NONE;
-
-    if (gun_index == 0) {
-        if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
-                ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
-            faultCode = RELAY_STATUS_ERROR_WELDING;
-        } else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
-                   ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
-            faultCode = RELAY_STATUS_ERROR_DRIVING;
-        }
-    } else if (gun_index == 1) {
-        if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
-                ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
-            faultCode = RELAY_STATUS_ERROR_WELDING;
-        } else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
-                   ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
-            faultCode = RELAY_STATUS_ERROR_DRIVING;
-        }
-    }
-
-    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
-            !ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
-        // 橋接
-        if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
-                ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
-            faultCode = RELAY_STATUS_ERROR_WELDING;
-        } else if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
-                   ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
-            faultCode = RELAY_STATUS_ERROR_DRIVING;
-        }
-    }
-
-    if (faultCode == RELAY_STATUS_ERROR_WELDING) {
-        // welding
-        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
-        }
-
-        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
-        EmcOccureByString("");
-    } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
-        // driving
-        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
-        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
-        }
-
-        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
-        EmcOccureByString("");
-    } else {
-        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
-        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
-
-        bool isClear = false;
-        if (!relayDrivingCheck) {
-            if (chargingInfo[gun_index]->Type == _Type_Chademo &&
-                    ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_GB &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_CCS_2 &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
-            }
-        }
-
-
-        if (!relayWeldingCheck) {
-            if (chargingInfo[gun_index]->Type == _Type_Chademo &&
-                    ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_GB &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
-            } else if (chargingInfo[gun_index]->Type == _Type_CCS_2 &&
-                       ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding == YES) {
-                isClear = true;
-                ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
-            }
-        }
-
-        if (!relayDrivingCheck && !relayWeldingCheck && isClear) {
-            ReleaseChargingProcessByString(2);
-        }
-    }
-}
-
-bool PrecheckIsPass(byte gun_index)
-{
-    bool result = true;
-
-    // relay welding or driving 是反向
-    if (result) {
-        result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
-    }
-
-    return result;
-}
-#endif //METER_ENABLE
-
-void ResetDetAlarmStatus(byte gun)
-{
-    if (chargingInfo[gun]->Type == _Type_Chademo) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
-        }
-    } else if (chargingInfo[gun]->Type == _Type_GB) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
-        }
-    } else if (chargingInfo[gun]->Type == _Type_CCS_2) {
-        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
-        }
-    }
-}
-
-static void powerCabinetPsuAlarmStatus(void)
-{
-    uint8_t i = 0;
-
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == 0) {
-            EmcOccureByString("042267");
-        }
-    }
-}
-
-static void autoStartChargingForComBox(uint8_t gunIndex)
-{
-#if defined DD360ComBox
-    if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
-            (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
-       ) {
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
-        strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
-    }
-#else
-    return;
-#endif //DD360ComBox
-}
-
-int main(void)
-{
-    uint8_t evBoardStopState = 0;
-
-    if (CreateShareMemory() == 0) {
-        log_error("CreatShareMemory NG\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        system("reboot -f");
-        sleep(5);
-        system("reboot -f");
-    }
-
-    log_info(" ****************  FileSystem Boot up ***************\n");
-    if (!InitialSystemDefaultConfig()) {
-        log_error("InitialSystemDefaultConfig NG \n");
-        //StopProcessingLoop();
-        sleep(5);
-        system("reboot -f");
-    }
-    CheckGunTypeFromHw();
-    CheckIsAlternatvieByModelName();
-    InitialShareMemoryInfo();
-    ChangeLcmByIndex(_LCM_INIT);
-    if (!CheckConnectorTypeStatus()) {
-        isModelNameMatch = false;
-    }
-
-    Initialization();
-    SpawnTask();
-    log_info("Spawned all Task");
-    if (!isModelNameMatch) {
-        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
-        ChangeLcmByIndex(_LCM_FIX);
-        // Module Name 與硬體對應不正確
-        log_error("Module Name & HW info none match. \n");
-        sleep(3);
-        KillAllTask();
-        StopProcessingLoop();
-    }
-    CreateTimeoutFork();
-    log_info("Start self test... \n");
-    startPrimaryLedIndicatorCtrlFork();
-    SelfTestRun();
-    StopSystemTimeoutDet();
-    log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
-             ShmSysConfigAndInfo->SysInfo.SelfTestSeq,
-             ShmPsuData->Work_Step);
-
-    if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
-            ShmPsuData->Work_Step == _NO_WORKING ||
-            ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES //DS60-120 add
-       ) {
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
-            if (!DisplaySelfTestFailReason()) { //DS60-120 add
-                PRINTF_FUNC("Soft reboot for retry self-tets. \n");
-
-                sleep(3);
-                system("killall OcppBackend &");
-                KillAllTask();
-                system("/usr/bin/run_evse_restart.sh");
-            }
-        }
-
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_ALARM);
-        }
-        //ChangeLcmByIndex(_LCM_FIX);
-        sleep(3);
-        if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) { //DS60-120 add
-            KillTaskExceptPrimary();
-        } else {
-            KillTask();
-        }
-        StopProcessingLoop();
-    } else {
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            setChargerMode(gun_index, MODE_IDLE);
-        }
-    }
-
-    // Local DB
-    if (DB_Open(localDb) != PASS) {
-        PRINTF_FUNC("DB_Open fail. \n");
-        isDb_ready = false;
-    } else {
-        isDb_ready = true;
-        for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-            chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
-        }
-        DB_Reboot_Record(localDb);
-    }
-    PRINTF_FUNC("===== Create DB End ===== \n");
-
-#if defined DD360Audi
-    ChangeLcmByIndex(_LCM_SELECT_GUN);
-#else
-    ChangeLcmByIndex(_LCM_IDLE);
-#endif //defined DD360Audi
-
-    sleep(1);
-    //***** 須新增的偵測 *****//
-    // 1. Thernal - 控制風扇轉速
-    // 2. ouput fuse - 控制風扇轉速
-    CreateRfidFork();
-    // Create Watchdog
-    //CreateWatchdog();
-    // Main loop
-
-    PRINTF_FUNC("===== Charger info ===== ");
-    PRINTF_FUNC("SW Version = %s", fwVersion);
-    PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
-    CheckFwSlotStatusLog();
-    AdjustChargerCurrent();
-    gettimeofday(&_cmdMainPriority_time, NULL);
-
-    for (;;) {
-        CheckOcppStatus();
-        ChkPrimaryStatus();
-        if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
-                ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet) {
-            CheckFactoryConfigFunction();
-
-            CheckFwUpdateFunction();
-        }
-
-        // OCPP 邏輯
-        OcppRemoteStartChk();
-        // 讀卡邏輯
-        ScannerCardProcess();
-        // 當 AC 沒有搭上時,清除一些錯誤碼
-        ClearAlarmCodeWhenAcOff();
-        // 確認是否要回到充電中的槍畫面邏輯判斷
-        CheckReturnToChargingConn();
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-        //確認Power cabinet PSU Status
-        powerCabinetPsuAlarmStatus();
-#endif // defined DD360 || defined DD360Audi
-
-        if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan) {
-            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
-        }
-
-        if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
-            CheckTask();
-
-            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-                //if (chargingInfo[_index]->SystemStatus == S_CHARGING) {
-                //    CheckSmartChargeProfile(_index);
-                //}
-                if ((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                        chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
-                        (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                         chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                    if (chargingInfo[_index]->SystemStatus == S_CHARGING &&
-                            _ocppProfileChkFlag == 12) {
-                        ChargingProfileFlat(_index);
-                        _ocppProfileChkFlag = 0;
-                    } else if (chargingInfo[_index]->SystemStatus != S_CHARGING) {
-                        ChargingProfileFlat(_index);
-                        _ocppProfileChkFlag = 0;
-                    } else {
-                        _ocppProfileChkFlag++;
-                    }
-                }
-            }
-            gettimeofday(&_cmdMainPriority_time, NULL);
-        }
-
-        for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
-            autoStartChargingForComBox(gun_index); //for DD360ComBox
-
-            CheckGpioInStatus();
-            CheckErrorOccurStatus(gun_index);
-            ChkOcppStatus(gun_index);
-
-            if ((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                    chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
-                    (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                     chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                CheckSmartChargeProfile(gun_index);
-            }
-
-            //PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
-            switch (chargingInfo[gun_index]->SystemStatus) {
-            case S_IDLE:
-                ReleaseAlarmCode(gun_index);
-
-                if (isModeChange(gun_index)) {
-                    log_info("S_IDLE================================== %x \n", gun_index);
-                    chargingInfo[gun_index]->PresentChargedDuration = 0;
-                    chargingInfo[gun_index]->RemainChargingDuration = 0;
-                    chargingInfo[gun_index]->PresentChargingVoltage = 0;//DS60-120 add
-                    chargingInfo[gun_index]->PresentChargingCurrent = 0;//DS60-120 add
-                    strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
-                    strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
-                    strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
-                    strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
-
-                    //Jerry add
-                    memset(&gAudiCustInfo->PricesInfo[gun_index], 0, sizeof(PricesInfo));
-                    gAudiCustInfo->PricesInfo[gun_index].Balance = FAIL_BALANCE_PRICES;
-#if defined DD360Audi
-                    destroySelGun(gun_index);
-#endif //defined DD360Audi
-                    ResetDetAlarmStatus(gun_index); //recovery OVP status code
-                    //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "");
-                }
-            case S_RESERVATION:
-                if (isModeChange(gun_index)) {
-                    log_info("S_RESERVATION....................%x \n", gun_index);
-                    ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
-                }
-
-                if (chargingInfo[gun_index]->IsAvailable == NO) {
-                    setChargerMode(gun_index, MODE_MAINTAIN);
-                }
-
-            case S_MAINTAIN:
-            case S_FAULT: {
-                if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                    if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
-                    } else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_IDLE &&
-                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_RESERVATION &&
-                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_MAINTAIN &&
-                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_FAULT) {
-                        if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING) {
-                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_COMPLETE;
-                        } else {
-#if defined DD360Audi
-                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-                        }
-                    }
-
-                    ClearDetectPluginFlag();
-//#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    UpdateErrorCodeToOcpp(gun_index);
-//#endif //!defined DD360 && !defined DD360Audi
-                    setChargerMode(gun_index, MODE_FAULT);
-                } else {
-#if 1
-                    if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
-#if defined DD360Audi
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-                        setChargerMode(gun_index, MODE_IDLE);
-                    }
-
-                    //if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX) {
-                    //    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;//_LCM_NONE; //Jerry add
-                    //    //for (byte g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++) {
-                    //    setChargerMode(gun_index, MODE_IDLE);
-                    //    //}
-                    //}
-#endif //0
-
-                    if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                        if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
-#else
-                        if (1)
-#endif //!defined DD360 && !defined DD360Audi
-                        {
-                            // 均充 -> 最大充
-                            if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
-                                if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE) {
-                                    log_info("=============Smart Charging============= Step 11 \n");
-                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
-                                }
-                            } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
-                                       ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
-                                log_info("=============Smart Charging============= Step 14 \n");
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
-                            } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
-                                ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                            }
-                        } else {
-                            ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                            ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                        }
-                    } else {
-                        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                    }
-
-                    if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
-                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-#if defined DD360Audi
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
-#else
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
-#endif //
-                        }
-                    } else {
-                        // Idle 正常程序起點
-                        // 判斷是否有啟用檢查插槍
-                        if (isDetectPlugin()) {
-                            // 卡號驗證成功後,等待充電槍插入充電車
-                            if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
-                                if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
-                                        chargingInfo[gun_index]->IsAvailable) {
-                                    PRINTF_FUNC("-----------------1----------------- %d \n", gun_index);
-                                    chargingInfo[gun_index]->RemoteStartFlag = NO;
-                                    chargingInfo[gun_index]->isRemoteStart = YES; //DS60-120
-                                    ChangeGunSelectByIndex(gun_index);
-                                    AddPlugInTimes(gun_index);
-                                    setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                    strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
-                                    ClearDetectPluginFlag();
-                                    continue;
-                                }
-                            } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
-                                if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
-                                        chargingInfo[gun_index]->IsAvailable &&
-                                        chargingInfo[gun_index]->SystemStatus == S_IDLE
-#if defined DD360Audi
-                                        && (waitRightGunPlugIt(gun_index) == PASS ||
-                                            waitLeftGunPlugIt(gun_index) == PASS)
-#endif //defined DD360Audi
-                                   ) {
-                                    PRINTF_FUNC("-----------------2----------------- \n");
-                                    ChangeGunSelectByIndex(gun_index);
-                                    AddPlugInTimes(gun_index);
-                                    strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-                                    PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
-                                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                                    // 當前操作的槍號,進入 Preparing
-                                    setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                    ClearDetectPluginFlag();
-                                    continue;
-                                }
-                            }
-
-                            if (!isCardScan) {
-                                // LCM => Waiting for plugging
-                                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
-                            }
-                        } else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION) {
-                            if (!isReservationExpired(gun_index)) {
-                                chargingInfo[gun_index]->SystemStatus = S_IDLE;
-                            }
-                        } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
-                                   (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable)) {
-                            PRINTF_FUNC("-----------------3----------------- \n");
-                            bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
-
-                            if (isCanStartChargingFlag) {
-                                ChangeGunSelectByIndex(gun_index);
-                                AddPlugInTimes(gun_index);
-                                setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                ClearDetectPluginFlag();
-                                continue;
-                            }
-                        } else {
-                            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-#if defined DD360Audi
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
-#else
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
-#endif // defined DD360Audi
-                            }
-                        }
-                    } // Idle 正常程序終點
-                }
-            }
-            break;
-            case S_REASSIGN_CHECK: {
-                if (isModeChange(gun_index)) {
-                    log_info("S_REASSIGN_CHECK================================== %x \n", gun_index);
-#if defined DD360Audi
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-#else
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
-                    if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
-                        ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-                    }
-                    StopSystemTimeoutDet();
-                }
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                bool isRessign = false;
-                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
-                    if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
-                        for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                            // 有其他槍已經分配好 psu 模塊
-                            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
-                                    chargingInfo[index]->SystemStatus >= S_PREPARNING &&
-                                    chargingInfo[index]->SystemStatus != S_MAINTAIN) {
-                                log_info("=============Smart Charging============= Step 1 \n");
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
-                                isRessign = true;
-                                break;
-                            }
-                        }
-                    } else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
-                               ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE) {
-                        // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
-                        if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
-                            if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
-                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
-                                log_info("=============Smart Charging============= Step 14 \n");
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
-                            } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
-                                ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                                continue;
-                            }
-                        }
-
-                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                        }
-                        continue;
-                    }
-                }
-#endif // !defined DD360 && !defined DD360Audi
-
-                if (0) { // if (isRessign)
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
-                    setChargerMode(gun_index, MODE_PRECHARGE);
-#else
-                    setChargerMode(gun_index, MODE_REASSIGN);
-#endif //defined DD360 || defined DD360Audi
-                } else {
-                    setChargerMode(gun_index, MODE_PRECHARGE);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                }
-            }
-            break;
-            case S_REASSIGN: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
-                    gettimeofday(&_toAverage_time, NULL);
-                }
-
-                // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
-                // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
-                if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
-                        ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
-                    if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging) {
-                        ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;//DS60-120 add
-                        setChargerMode(gun_index, MODE_PRECHARGE);
-                    } else {
-                        setChargerMode(gun_index, MODE_IDLE);
-                    }
-                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 add
-                } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
-                           ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
-                    PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
-                    ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                    //ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 remove
-                    ShmSysConfigAndInfo->SysInfo.CanAverageCharging = true; //DS60-120 add
-                }
-
-                //PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_PREPARNING: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
-                }
-
-                if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
-                        ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000) {
-                    //if ((chargingInfo[gun_index]->MaximumChargingVoltage > 0) && //DS60-120 remove
-                    //        (chargingInfo[gun_index]->AvailableChargingCurrent > 0) &&
-                    //        (chargingInfo[gun_index]->AvailableChargingPower > 0)) {
-                    setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
-                    //}
-                }
-
-                //DS60-120 add
-                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2) {
-                    bool oughtAver = true;
-                    for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
-                        // 共同進入充電邏輯
-                        if (chargingInfo[index]->SystemStatus != S_PREPARNING) {
-                            oughtAver = false;
-                            break;
-                        }
-                    }
-
-                    if (oughtAver) {
-                        PRINTF_FUNC("********* Automatically change to aver mode ********** \n");
-                        ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-                        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_PREPARING_FOR_EV: { // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
-                if (isModeChange(gun_index)) {
-                    log_info("S_PREPARING_FOR_EV================================== %x \n", gun_index);
-                    //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
-                }
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    // 檢查車端的槍鎖是否為鎖上
-                    if (isEvGunLocked_chademo(gun_index) == YES) {
-                        setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    // 檢查車端的 charging enable 是否為 1
-                    if (isEvGunLocked_gb(gun_index) == YES) {
-                        setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    // 檢查車端的 charging enable 是否為 1
-                    if (isEvGunLocked_ccs(gun_index) == YES) {
-                        setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // LCM => Pre-charging
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_PREPARING_FOR_EVSE: { // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
-                if (isModeChange(gun_index)) {
-                    log_info("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
-                }
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8) {
-                        // 當前操作的槍號,進入 Charging
-                        setChargerMode(gun_index, MODE_CHARGING);
-                    }
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012234");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012296");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    // 檢查樁端的 GFD 結果
-                    //if (isPrechargeStatus_gb(gun_index) > 5 && isPrechargeStatus_gb(gun_index) < 9) {
-                    if (isPrechargeStatus_gb(gun_index) > 9) {
-                        setChargerMode(gun_index, MODE_CHARGING);
-                    }
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012236");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012298");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    // 檢查樁端的 GFD 結果
-                    if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
-                            chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)) {
-                        setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
-                    }
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012235");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012297");
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // LCM => Pre-charging
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_CHARGING: { // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
-                if (isModeChange(gun_index)) {
-                    log_info("S_CHARGING================================== %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    ftime(&startChargingTime[gun_index]);
-                    strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, ""); //DS60-120 add
-                    ChangeStartOrStopDateTime(YES, gun_index);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    OcppStartTransation(gun_index);
-#endif //!defined DD360 && !defined DD360Audi
-                }
-
-                if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf) {
-                    ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
-                }
-                ftime(&endChargingTime[gun_index]);
-                chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012234");
-                    }
-                    //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
-                    //    // UVP
-                    //    RecordAlarmCode(gun_index, "012289");
-                    //    ChargingTerminalProcess(gun_index);
-                    //}
-                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012296");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012236");
-                    }
-                    //else if (isPrechargeStatus_gb(gun_index) == 10 &&
-                    //           (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //            (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))) {
-                    //    // UVP
-                    //    RecordAlarmCode(gun_index, "012290");
-                    //    ChargingTerminalProcess(gun_index);
-                    //}
-                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012298");
-                    }
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012235");
-                    }
-                    //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
-                    //    // UVP
-                    //    RecordAlarmCode(gun_index, "012288");
-                    //    ChargingTerminalProcess(gun_index);
-                    //}
-                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012297");
-                    }
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    //printf("%d evBoardStopState = %d\r\n", gun_index, evBoardStopState);
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                    }
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index) ||
-                           CheckBackendChargingTimeout(gun_index) ||
-                           CheckBackendChargingEnergy(gun_index) ||
-                           strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
-
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // LCM => Charging
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_ALARM:
-            case S_TERMINATING: {
-                if (isModeChange(gun_index)) {
-                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
-                    }
-
-                    if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
-                        PRINTF_FUNC("================== S_ALARM (%x) ================ \n", gun_index);
-                        UpdateErrorCodeToOcpp(gun_index);
-
-                        if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
-                            OcppStopTransation(gun_index);
-                        }
-
-                        TheEndCharging(gun_index);
-                    } else {
-                        PRINTF_FUNC("================== S_TERMINATING (%x) ================ \n", gun_index);
-                    }
-
-                    //log_info ("terminating......................... %x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                }
-
-                if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gun_index) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                    //        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012234");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012296");
-                    }
-
-                    //if (isEvStopCharging_chademo(gun_index) == YES ||
-                    //        isPrechargeStatus_chademo(gun_index) <= 0) {
-                    //    setChargerMode(gun_index, MODE_COMPLETE);
-                    //}
-                } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                    //log_info("************ GB lock Status = %d, status = %d \n",
-                    //         isEvStopCharging_gb(gun_index),
-                    //         isPrechargeStatus_gb(gun_index));
-
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gun_index) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012236");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012298");
-                    }
-
-                    //if (isEvStopCharging_gb(gun_index) == YES ||
-                    //        isPrechargeStatus_gb(gun_index) <= 0) {
-                    //    setChargerMode(gun_index, MODE_COMPLETE);
-                    //}
-                } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gun_index) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gun_index, "012235");
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordWarningCode(gun_index, "012297");
-                    }
-
-                    //if (isEvStopCharging_ccs(gun_index) == YES &&
-                    //        (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
-                    //         isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
-                    //    setChargerMode(gun_index, MODE_COMPLETE);
-                    //}
-                }
-
-                if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
-                    if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
-                            GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
-                        setChargerMode(gun_index, MODE_IDLE);
-                    }
-                } else {
-                    if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-                        if (isEvStopCharging_chademo(gun_index) == YES ||
-                                isPrechargeStatus_chademo(gun_index) <= 0) {
-                            setChargerMode(gun_index, MODE_COMPLETE);
-                        }
-                    } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-                        if (isEvStopCharging_gb(gun_index) == YES ||
-                                isPrechargeStatus_gb(gun_index) <= 0) {
-                            setChargerMode(gun_index, MODE_COMPLETE);
-                        }
-                    } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-                        if (isEvStopCharging_ccs(gun_index) == YES &&
-                                (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
-                                 isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
-                            setChargerMode(gun_index, MODE_COMPLETE);
-                        }
-                    }
-                }
-
-                // 車端的停止
-                //if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                //    strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                //}
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_COMPLETE: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC ("complete......................... %x \n", gun_index);
-                    if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
-                        OcppStopTransation(gun_index);
-                    }
-
-                    TheEndCharging(gun_index);
-                    //ftime(&endChargingTime[gun_index]);
-                    //if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
-                    //    chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-                    //}
-
-                    //StopGunInfoTimeoutDet(gun_index);
-                    //StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
-                    //ChangeStartOrStopDateTime(NO, gun_index);
-                }
-
-                //if (((chargingInfo[gun_index]->ConnectorPlugIn == NO) ||
-                //        (restartFlag == 1)) &&
-                //        (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)) {
-                //    setChargerMode(gun_index, MODE_IDLE);
-                //    destroySelGun(gun_index); //Jerry add
-                //}
-
-                if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
-                        GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
-                    setChargerMode(gun_index, MODE_IDLE);
-#if defined DD360Audi
-                    destroySelGun(gun_index); //Jerry add
-#endif //defined DD360Audi
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-            }
-            break;
-            case S_CCS_PRECHARGE_ST0: {
-                if (isModeChange(gun_index)) {
-                    PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
-                }
-
-                if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                    // GFD 錯誤停止
-                    RecordAlarmCode(gun_index, "012235");
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // 等待 EV 小板 (CCS) 通知可以開始 Precharge
-                // 切換 D+ Relay to Precharge Relay
-                if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40) {
-                    if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
-                        //if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
-                    {
-                        //PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
-                        if (isPrechargeStatus_ccs(gun_index) == 39) {
-                            PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
-                        } else if (isPrechargeStatus_ccs(gun_index) == 40) {
-                            PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
-                        }
-
-                        chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
-                    }
-                } else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46) {
-                    setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-                break;
-            }
-            case S_CCS_PRECHARGE_ST1: {
-                if (isModeChange(gun_index)) {
-                    log_info("CCS Precharge Processing 2....................%x \n", gun_index);
-                }
-
-                if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
-                    // GFD 錯誤停止
-                    RecordAlarmCode(gun_index, "012235");
-                }
-
-                if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
-                    // 板端要求停止 (錯誤)
-                    if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
-                        ChargingAlarmProcess(gun_index);
-                    } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
-                        ChargingTerminalProcess(gun_index);
-                    }
-
-                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止 (正常)
-                    ChargingTerminalProcess(gun_index);
-                } else if (OcppRemoteStop(gun_index) == YES ||
-                           WifiScheduleStop(gun_index)) {
-                    // 後臺要求停止
-                    ChargingTerminalProcess(gun_index);
-                }
-
-                // 等待小板通知進入充電
-                // 切換 D+ Relay to Precharge Relay
-                if (chargingInfo[gun_index]->RelayK1K2Status == YES) {
-                    chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
-                    setChargerMode(gun_index, MODE_CHARGING);
-                }
-
-                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
-                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-                    // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-                }
-                break;
-            }
-            }
-        }
-
-#if defined DD360Audi
-        if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_SELECT_GUN) {
-#else
-        if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE) {
-#endif //defined DD360Audi
-            ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
-        } else {
-            bool dcPageRun = false;
-            if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
-                if  (ac_chargingInfo[0]->SystemStatus == S_IDLE) {
-                    ChangeLcmByIndex(_LCM_IDLE);
-                } else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING) {
-                    ChangeLcmByIndex(_LCM_PRE_CHARGE);
-                } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
-                    ChangeLcmByIndex(_LCM_CHARGING);
-                } else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
-                           ac_chargingInfo[0]->SystemStatus == S_COMPLETE) {
-                    ChangeLcmByIndex(_LCM_COMPLETE);
-                } else {
-                    dcPageRun = true;
-                }
-            } else {
-                dcPageRun = true;
-            }
-
-            if (dcPageRun) {
-                ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
-            }
-        }
-
-        write(wtdFd, "a", 1);
-        usleep(whileLoopTime);
-    }
-
-    return FAIL;
-}

+ 60 - 49
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -6,44 +6,40 @@
  */
 
 
-#include    <sys/time.h>
-#include    <sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include    <sys/types.h>
-#include    <sys/ioctl.h>
-#include    <sys/socket.h>
-#include    <sys/ipc.h>
-#include    <sys/shm.h>
-#include    <sys/shm.h>
-#include    <sys/mman.h>
-#include    <linux/wireless.h>
-#include    <arpa/inet.h>
-#include    <netinet/in.h>
-
-#include    <unistd.h>
-#include    <stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include    <errno.h>
-#include    <string.h>
-#include    <time.h>
-#include    <ctype.h>
-#include    <ifaddrs.h>
-#include    <math.h>
-#include    <stdbool.h>
-#include    "../../define.h"
-
-typedef unsigned char           byte;
-#define PASS                1
-#define FAIL                -1
-#define EQUAL               0
-#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
-#define NO_DEFINE           255
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <stdint.h>
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+#include <stdbool.h>
+#include "../../define.h"
+#include "Config.h"
+
 #define DEFAULT_AC_INDEX    2
 
 #define AUTORUN_STEP1_TIME_START            140             // Minutes
@@ -57,8 +53,8 @@ typedef unsigned char           byte;
 #define STTY_US             "stty raw -echo -F "
 #define STTY_DEF            "stty -raw echo -F "
 
-byte _curAutoRunCount = 0;
-byte _usingAutoRun = 0;
+uint8_t _curAutoRunCount = 0;
+uint8_t _usingAutoRun = 0;
 struct timeval _autoTime;
 
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
@@ -84,23 +80,23 @@ char *msg = "state : get gun state (index) \n"
             "ver : ver of board (407 or index or rb or fan) \n"
             "ac : get ac relay state (x) \n";
 
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
-    for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < CCS_QUANTITY; index++) {
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
             return true;
         }
     }
 
-    for (byte index = 0; index < GB_QUANTITY; index++) {
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
         if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
             chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
             return true;
@@ -110,7 +106,7 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
     return false;
 }
 
-bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
+bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
 {
     if (target < AC_QUANTITY) {
         acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
@@ -525,8 +521,8 @@ void SetGFDMode(char *v1)
 
 void GetPsuTemp()
 {
-    for (byte index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
             printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
         }
     }
@@ -566,7 +562,7 @@ void GetPsuInformation(char *v1, char *v2, char *v3)
         }
     } else if (strcmp(v1, "input") == 0) {
         for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
+            for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
                 printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
                        i, count,
                        ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
@@ -665,7 +661,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         _Current = atof(v3);
     }
 
-    unsigned char PreviousSystemStatus = 0xff;
+    uint8_t PreviousSystemStatus = 0xff;
     if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
         printf ("FindChargingInfoData error\n");
         return;
@@ -1099,6 +1095,21 @@ int main(void)
 
             // 槍狀態
             RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
+        } else if (strcmp(newString[0], "tempT") == 0) {
+
+            uint8_t _GunIndex = 0;
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                return 0;
+            }
+
+            if (strcmp(newString[1], "0") == 0) {
+                _chargingData[0]->ConnectorTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ConnectorTemp);
+            } else if (strcmp(newString[1], "1") == 0) {
+                _chargingData[1]->ConnectorTemp = atoi(newString[2]);
+                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
+            }
         } else {
             printf ("%s\n", msg);
         }

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/init.sh → EVSE/Projects/DD360Audi/Apps/Script/init.sh

@@ -8,4 +8,4 @@ chmod 777 Module_PsuComm
 chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
-
+chmod 777 Module_DoComm

+ 40 - 0
EVSE/Projects/DD360Audi/Apps/Script/kill.sh

@@ -0,0 +1,40 @@
+pkill Module_CSU;
+pkill Module_PrimaryComm;
+pkill Module_LcmControl;
+pkill Module_InternalComm;
+pkill Module_EventLogging;
+pkill Module_EvComm;
+pkill Module_PsuComm;
+pkill Module_4g;
+pkill Module_Wifi;
+pkill OcppBackend;
+pkill Module_ProduceUtils;
+pkill Module_DoComm;
+pkill main;
+
+ipcrm -M 0x000003e9;
+ipcrm -M 0x000003ed;
+ipcrm -M 0x000003ea;
+ipcrm -M 0x000003ec;
+ipcrm -M 0x000003ee;
+ipcrm -M 0x000003ef;
+ipcrm -M 0x000003f0;
+ipcrm -M 0x000003f3;
+ipcrm -M 0x000003f1;
+ipcrm -M 0x000003f6;
+
+ipcrm -M 0x000003e9;
+ipcrm -M 0x000003ed;
+ipcrm -M 0x000003ea;
+ipcrm -M 0x000003ec;
+ipcrm -M 0x000003ee;
+ipcrm -M 0x000003ef;
+ipcrm -M 0x000003f0;
+ipcrm -M 0x000003f3;
+ipcrm -M 0x000003f1;
+ipcrm -M 0x000003f6;
+ipcrm -M 0x000003eb;
+ipcrm -M 0x000003f2;
+ipcrm -M 0x000007d2;
+
+ipcs;

+ 0 - 0
EVSE/Projects/DD360Audi/Apps/replaceOtherProject.sh → EVSE/Projects/DD360Audi/Apps/Script/replaceOtherProject.sh


Деякі файли не було показано, через те що забагато файлів було змінено