Pārlūkot izejas kodu

2021.06.02 / Jerry Wang

Actions:
1. Add check relay welding and driving function.

Files:
1. As follow as commit history.
Jerry_Wang 3 gadi atpakaļ
vecāks
revīzija
2b6c8c09ef
100 mainītis faili ar 33936 papildinājumiem un 4022 dzēšanām
  1. 17 0
      EVSE/Projects/DD360/Apps/CSU/AcPlug.c
  2. 0 0
      EVSE/Projects/DD360/Apps/CSU/Gpio.c
  3. 939 0
      EVSE/Projects/DD360/Apps/CSU/OCPP.c
  4. 488 0
      EVSE/Projects/DD360/Apps/CSU/Primary.c
  5. 320 0
      EVSE/Projects/DD360/Apps/CSU/RFID.c
  6. 303 0
      EVSE/Projects/DD360/Apps/CSU/TimeTask.c
  7. 271 0
      EVSE/Projects/DD360/Apps/CSU/Update.c
  8. 0 0
      EVSE/Projects/DD360/Apps/CSU/WatchDog.c
  9. 62 0
      EVSE/Projects/DD360/Apps/CSU/ZipFile.c
  10. 27 24
      EVSE/Projects/DD360/Apps/Config.h
  11. 253 0
      EVSE/Projects/DD360/Apps/DataBase/DataBase.c
  12. 5 0
      EVSE/Projects/DD360/Apps/DataBase/DataBase.h
  13. 7 0
      EVSE/Projects/DD360/Apps/DebugLog.md
  14. 63 0
      EVSE/Projects/DD360/Apps/Log/log.c
  15. 12 0
      EVSE/Projects/DD360/Apps/Log/log.h
  16. 48 10
      EVSE/Projects/DD360/Apps/Makefile
  17. 913 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCCS.c
  18. 247 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCHA.c
  19. 415 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalGBT.c
  20. 291 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalState.c
  21. 1 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.h
  22. 44 16
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.c
  23. 7 5
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.h
  24. 553 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  25. 1014 0
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  26. 56 28
      EVSE/Projects/DD360/Apps/ModuleInternalComm/AcPlug.c
  27. 16 10
      EVSE/Projects/DD360/Apps/ModuleInternalComm/FanBoard.c
  28. 35 22
      EVSE/Projects/DD360/Apps/ModuleInternalComm/LEDlight.c
  29. 26 1392
      EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.c
  30. 5 0
      EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.h
  31. 2488 0
      EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalCommOrg.c
  32. 360 178
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  33. 3 3
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c
  34. 12 6
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  35. 5 3
      EVSE/Projects/DD360/Apps/Readme.md
  36. 1 1
      EVSE/Projects/DD360/Apps/Script/createDefine.sh
  37. 4 0
      EVSE/Projects/DD360/Apps/Script/replaceOtherDD360Project.sh
  38. 194 0
      EVSE/Projects/DD360/Apps/SelectGun/SelectGun.c
  39. 9 0
      EVSE/Projects/DD360/Apps/SelectGun/SelectGun.h
  40. 72 31
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c
  41. 2 0
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.h
  42. 356 282
      EVSE/Projects/DD360/Apps/main.c
  43. 15 0
      EVSE/Projects/DD360/Apps/main.h
  44. 7009 0
      EVSE/Projects/DD360/Apps/mainNew.c
  45. 17 0
      EVSE/Projects/DD360Audi/Apps/CSU/AcPlug.c
  46. 0 0
      EVSE/Projects/DD360Audi/Apps/CSU/Gpio.c
  47. 939 0
      EVSE/Projects/DD360Audi/Apps/CSU/OCPP.c
  48. 488 0
      EVSE/Projects/DD360Audi/Apps/CSU/Primary.c
  49. 320 0
      EVSE/Projects/DD360Audi/Apps/CSU/RFID.c
  50. 303 0
      EVSE/Projects/DD360Audi/Apps/CSU/TimeTask.c
  51. 271 0
      EVSE/Projects/DD360Audi/Apps/CSU/Update.c
  52. 0 0
      EVSE/Projects/DD360Audi/Apps/CSU/WatchDog.c
  53. 62 0
      EVSE/Projects/DD360Audi/Apps/CSU/ZipFile.c
  54. 27 24
      EVSE/Projects/DD360Audi/Apps/Config.h
  55. 253 0
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c
  56. 5 0
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.h
  57. 7 0
      EVSE/Projects/DD360Audi/Apps/DebugLog.md
  58. 63 0
      EVSE/Projects/DD360Audi/Apps/Log/log.c
  59. 12 0
      EVSE/Projects/DD360Audi/Apps/Log/log.h
  60. 48 10
      EVSE/Projects/DD360Audi/Apps/Makefile
  61. 913 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCCS.c
  62. 247 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCHA.c
  63. 415 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalGBT.c
  64. 291 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalState.c
  65. 1 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.h
  66. 44 16
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.c
  67. 7 5
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.h
  68. 553 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  69. 1014 0
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  70. 56 28
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/AcPlug.c
  71. 16 10
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/FanBoard.c
  72. 35 22
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/LEDlight.c
  73. 26 1392
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.c
  74. 5 0
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.h
  75. 2488 0
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalCommOrg.c
  76. 360 178
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  77. 3 3
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c
  78. 12 6
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  79. 5 3
      EVSE/Projects/DD360Audi/Apps/Readme.md
  80. 1 1
      EVSE/Projects/DD360Audi/Apps/Script/createDefine.sh
  81. 4 0
      EVSE/Projects/DD360Audi/Apps/Script/replaceOtherDD360Project.sh
  82. 194 0
      EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.c
  83. 9 0
      EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.h
  84. 72 31
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c
  85. 2 0
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.h
  86. 356 282
      EVSE/Projects/DD360Audi/Apps/main.c
  87. 15 0
      EVSE/Projects/DD360Audi/Apps/main.h
  88. 7009 0
      EVSE/Projects/DD360Audi/Apps/mainNew.c
  89. BIN
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  90. BIN
      EVSE/Projects/DD360Audi/output/DoComm
  91. BIN
      EVSE/Projects/DD360Audi/output/FactoryConfig
  92. BIN
      EVSE/Projects/DD360Audi/output/Module_DoComm
  93. BIN
      EVSE/Projects/DD360Audi/output/Module_EvComm
  94. BIN
      EVSE/Projects/DD360Audi/output/Module_EventLogging
  95. BIN
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  96. BIN
      EVSE/Projects/DD360Audi/output/Module_LcmControl
  97. BIN
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  98. BIN
      EVSE/Projects/DD360Audi/output/Module_ProduceUtils
  99. BIN
      EVSE/Projects/DD360Audi/output/ReadCmdline
  100. BIN
      EVSE/Projects/DD360Audi/output/main

+ 17 - 0
EVSE/Projects/DD360/Apps/CSU/AcPlug.c

@@ -0,0 +1,17 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+void AcChargingTerminalProcess(void)
+{
+    struct ChargingInfoData *pAcChargingInfoData = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    pAcChargingInfoData->SystemStatus = MODE_TERMINATING;
+}

+ 0 - 0
EVSE/Projects/DD360/Apps/CSU/Gpio.c


+ 939 - 0
EVSE/Projects/DD360/Apps/CSU/OCPP.c

@@ -0,0 +1,939 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+#include <time.h>
+#include <unistd.h>
+
+//------------------------------------------------------------------------------
+int opcc_chk_reserve_expired(byte gun_index)
+{
+    int result = NO;
+    struct tm expiredDate;
+    struct timeb expiredTime;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        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;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (sscanf((char *) ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,
+                   "%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 routine
+//===============================================
+void ocpp_process_start()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        system("/root/OcppBackend &");
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        system("/root/OcppBackend20 &");
+    }
+}
+
+void ocpp_auto_response_BootNotification()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
+            ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES) {
+            ShmOCPP20Data->SpMsg.bits.BootNotificationConf = NO;
+        }
+    }
+}
+
+bool ocpp_is_resPass_StartTransationConf(byte gun_index)
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf;
+    }
+
+    return result;
+}
+
+void ocpp_auto_response_StartTransationConf(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf) {
+            ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf) {
+            ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = NO;
+        }
+    }
+}
+
+void ocpp_auto_response_ReserveConf(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
+    }
+}
+
+bool ocpp_chk_authrization_cmd()
+{
+    char buf2[16] = "";
+    memset(buf2, 0, ARRAY_SIZE(buf2));
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        sprintf(buf2, "%s",   ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        sprintf(buf2, "%s",   ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
+    }
+    // 因為無法得知實際的長度,所以只能用搜尋的方式
+    if (strcmp(buf2, "Accepted") == EQUAL) {
+        return true;
+    }
+
+    return false;
+}
+
+bool opcc_sub_get_reset_req()
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->MsMsg.bits.ResetReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->MsMsg.bits.ResetReq;
+    }
+
+    return result;
+}
+
+void ocpp_sub_run_reset(bool canReset)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+            sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
+            ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            system("reboot -f");
+        } else if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+            sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
+            ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            KillAllTask();
+            system("/usr/bin/run_evse_restart.sh");
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+            sprintf((char *)ShmOCPP20Data->Reset.Response_status, "Accepted");
+            ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            system("reboot -f");
+        } else if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "OnIdle") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+            sprintf((char *)ShmOCPP20Data->Reset.Response_status, "Accepted");
+            ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            KillAllTask();
+            system("/usr/bin/run_evse_restart.sh");
+        }
+    }
+}
+
+void ocpp_chk_reset_cmd()
+{
+    if (opcc_sub_get_reset_req()) {
+        bool canReset = true;
+
+        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) {
+                        // Reset 系統先停止充電
+                        ChargingTerminalProcess(_index);
+                    }
+                }
+            }
+        }
+
+        if (canReset) {
+            // Reset -> change status to maintain.
+            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+                setChargerMode(_index, MODE_MAINTAIN);
+            }
+            ChangeLcmByIndex(_LCM_FIX);
+        }
+
+        ocpp_sub_run_reset(canReset);
+    }
+}
+
+void ocpp_chk_reserved_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+                ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
+            ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+            if (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************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 (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                chargingInfo[gunIndex]->ReservationId = 0;
+                chargingInfo[gunIndex]->SystemStatus = S_IDLE;
+            }
+            ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+                ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
+            ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+            if (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+                chargingInfo[gunIndex]->ReservationId = ShmOCPP20Data->ReserveNow[gunIndex].id;
+                chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
+            }
+            ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
+        }
+
+        if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
+                ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
+            ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
+            if (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                chargingInfo[gunIndex]->ReservationId = 0;
+                chargingInfo[gunIndex]->SystemStatus = S_IDLE;
+            }
+            ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
+        }
+    }
+}
+
+void ocpp_chk_availability_cmd(byte gunIndex)
+{
+    byte type = 0; // 0 : none, 1 : operative, 2 inoperative
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
+            PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+            DEBUG_ERROR_MSG("***************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);
+                }
+
+                type = 1;
+            } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
+                if (isDb_ready) {
+                    DB_Update_Operactive(localDb, gunIndex, false);
+                }
+
+                type = 2;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
+            PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+            DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+            ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
+            if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Operative") == EQUAL) {
+                if (isDb_ready) {
+                    DB_Update_Operactive(localDb, gunIndex, true);
+                }
+
+                type = 1;
+            } else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Inoperative") == EQUAL) {
+                if (isDb_ready) {
+                    DB_Update_Operactive(localDb, gunIndex, false);
+                }
+
+                type = 2;
+            }
+        }
+    }
+
+    if (type == 1) {
+        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 (type == 2) {
+        chargingInfo[gunIndex]->IsAvailable = NO;
+        if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
+                chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
+                chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
+            setChargerMode(gunIndex, MODE_MAINTAIN);
+        }
+    }
+}
+
+void ocpp_chk_unlock_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
+            ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
+            if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
+                    chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
+                // Unlocked - 充電中,需停止充電
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
+                ChargingTerminalProcess(gunIndex);
+            }
+            strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
+            ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
+            ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
+            if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
+                    chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
+                // Unlocked - 充電中,需停止充電
+                strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "UnlockCommand");
+                ChargingTerminalProcess(gunIndex);
+            }
+            strcpy((char *)ShmOCPP20Data->UnlockConnector[gunIndex].Response_status, "Unlocked");
+            ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
+        }
+    }
+}
+
+bool ocpp_chk_remoteStop_cmd(byte gunIndex)
+{
+    byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+    // 有 AC 槍的話
+    if (acDirIndex > 0 && gunIndex > 0) {
+        gunIndex += acDirIndex;
+    }
+
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq;
+    }
+
+    if (result) {
+        DEBUG_INFO_MSG("Remote Stop by OCPP (%d) \n", gunIndex);
+        if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
+            ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
+        } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "Remote");
+            ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq = NO;
+        }
+    }
+
+    return result;
+}
+
+bool ocpp_sub_get_remote_start_transaction_req(byte gun_index)
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq;
+    }
+
+    if (result) {
+        strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,
+               (char *)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag);
+    }
+
+    return result;
+}
+
+void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStartTransactionReq = result;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStartTransactionReq = result;
+    }
+}
+
+void ocpp_chk_remoteStart_cmd()
+{
+    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 (ocpp_sub_get_remote_start_transaction_req(acDirIndex)) {
+                if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
+                        ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
+                    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;
+                }
+                ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
+            }
+        }
+
+        byte threeGunIndex = 0;
+        byte dcIndex = 0;
+        bool isGunUsingStatus = false;
+        byte scheduleIndex = 0;
+
+        for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+            // 如果有 AC 槍,且 DC 槍也有兩把
+            if (acDirIndex == 1 && _index == 1) {
+                threeGunIndex = 1;
+            }
+
+            if (ocpp_sub_get_remote_start_transaction_req(_index + threeGunIndex)) {
+                dcIndex = _index;
+            }
+
+            if (chargingInfo[_index]->SystemStatus != S_IDLE) {
+                isGunUsingStatus = true;
+            }
+
+            if (chargingInfo[_index]->schedule.isTriggerStart) {
+                scheduleIndex = _index;
+            }
+        }
+
+        // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
+        if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
+            if (dcIndex == 0) {
+                threeGunIndex = 0;
+            }
+
+            ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
+            return;
+        }
+
+        if (dcIndex == 0) {
+            threeGunIndex = 0;
+        }
+
+        if (ocpp_sub_get_remote_start_transaction_req(dcIndex + threeGunIndex)) {
+            if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
+                    chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
+                chargingInfo[dcIndex]->RemoteStartFlag = YES;
+                ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+                //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
+                DetectPluginStart();
+            }
+            ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
+        } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
+            if (chargingInfo[scheduleIndex]->SystemStatus == S_IDLE ||
+                    chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
+                chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
+                ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+                DetectPluginStart();
+            }
+            chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
+        }
+    }
+}
+
+void ocpp_chk_update_cmd()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
+            ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
+
+            if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
+                DEBUG_INFO_MSG("Backend : update start. \n");
+                sleep(2);
+                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) {
+                    DEBUG_INFO_MSG("Backend : update complete. \n");
+                    strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+                } else if (updateResult == MODELNAME_FAIL) {
+                    DEBUG_INFO_MSG("Backend : model name is none match. \n");
+                    strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+                    ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+                    sleep(5);
+                    KillAllTask();
+                    system("/usr/bin/run_evse_restart.sh");
+                    return;
+                } else {
+                    DEBUG_INFO_MSG("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");
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES) {
+            ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = NO;
+
+            if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL) {
+                DEBUG_INFO_MSG("Backend : update start. \n");
+                sleep(2);
+                strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "");
+                strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing");
+                ShmOCPP20Data->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) {
+                    DEBUG_INFO_MSG("Backend : update complete. \n");
+                    strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
+                } else if (updateResult == MODELNAME_FAIL) {
+                    DEBUG_INFO_MSG("Backend : model name is none match. \n");
+                    strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
+                    ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+                    sleep(5);
+                    KillAllTask();
+                    system("/usr/bin/run_evse_restart.sh");
+                    return;
+                } else {
+                    DEBUG_INFO_MSG("Backend : update fail. \n");
+                    strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
+                }
+
+                strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
+                ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+                sleep(5);
+                system("reboot -f");
+            }
+        }
+    }
+}
+
+bool ocpp_chk_invalid_id_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE")) {
+            if (strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
+                    strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
+                    strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
+                return true;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE")) {
+            if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Blocked") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Expired") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Invalid") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Unknown") == EQUAL) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+bool ocpp_chk_profileConf_cmd(byte _index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
+            ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
+            return true;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
+            ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
+            return true;
+        }
+    }
+
+    return false;
+}
+
+void ocpp_lift_profileReq_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
+            if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
+                ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
+            if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
+                ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
+            }
+        }
+    }
+}
+
+void ocpp_set_startTransation_cmd(byte gunIndex)
+{
+    byte _OcppGunIndex = gunIndex;
+
+    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
+        _OcppGunIndex = 2;
+    }
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        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;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        } else {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
+        }
+
+        PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
+    }
+}
+
+void ocpp_set_stopTransation_cmd(byte gunIndex)
+{
+    byte _OcppGunIndex = gunIndex;
+
+    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
+        _OcppGunIndex = 2;
+    }
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        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;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        } else {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
+        }
+
+        PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
+    }
+}
+
+void ocpp_set_errorCode_cmd(byte gunIndex, char *errString)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, errString);
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+
+    }
+}
+
+void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, reason);
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "") == EQUAL) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, reason);
+        }
+    }
+}
+
+void ocpp_set_authorizeReq_cmd(byte value)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->SpMsg.bits.AuthorizeReq = value;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->SpMsg.bits.AuthorizeReq = value;
+    }
+}
+
+void ocpp_set_authorizeConf_cmd(byte value)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->SpMsg.bits.AuthorizeConf = value;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->SpMsg.bits.AuthorizeConf = value;
+    }
+}
+
+void ocpp_set_errCode_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "InternalError");
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->ConnectorAlarmCode);
+        } else if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "OtherError");
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->EvConnAlarmCode);
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+
+    }
+}
+
+void ocpp_clear_errorCode_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError");
+        }
+
+        if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+
+    }
+}
+
+void ocpp_clear_idTag_cmd(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "");
+    }
+}
+
+void ocpp_clear_stopReason(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
+    }
+}
+
+unsigned short _ocpp_get_connect_timeout()
+{
+    uint16_t result = (TIMEOUT_SPEC_HANDSHAKING / 1000);
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
+            result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+        }
+    }
+
+    else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "") != 0) {
+            result = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
+        }
+    }
+
+    return result;
+}
+
+bool _ocpp_get_disconnect_policy()
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE") == EQUAL &&
+                strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == EQUAL) {
+            result = true;
+        }
+    }
+
+    else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL &&
+                strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL) {
+            result = true;
+        }
+    }
+
+    return result;
+}
+
+bool ocpp_get_authorize_conf()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        return ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        return ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
+    }
+
+    return false;
+}
+
+bool ocpp_get_startTransation_req(byte gunIndex)
+{
+    bool result = false;
+
+    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CpMsg.bits[gunIndex].TransactionEventReq;
+    }
+
+    return result;
+}
+
+void ocpp_chargingProfile_process(byte _index)
+{
+    int _time = 0;
+    int _startCount = NO_DEFINE;
+    int _maxCount = 0;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
+                ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES) {
+            _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+            _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
+            _startCount = NO_DEFINE;
+
+            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("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
+            if (_startCount < _maxCount) {
+                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 * ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
+                if (chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
+                        chargingInfo[_index]->PresentChargingVoltage > 0) {
+                    chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
+                } else {
+                    chargingInfo[_index]->ChargingProfileCurrent = 0;
+                }
+            } else {
+                chargingInfo[_index]->ChargingProfilePower = -1;
+                chargingInfo[_index]->ChargingProfileCurrent = -1;
+            }
+        } else {
+            chargingInfo[_index]->ChargingProfilePower = -1;
+            chargingInfo[_index]->ChargingProfileCurrent = -1;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[_index].chargingProfileKind, "Absolute") == EQUAL &&
+                ShmOCPP20Data->SmartChargingProfile[_index].id == YES) {
+            _time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].startSchedule);
+            _maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod);
+            _startCount = NO_DEFINE;
+
+            for (byte _count = 0; _count < _maxCount; _count++) {
+                // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+                if (_time >= ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod) {
+                    if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
+                            ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR) {
+                        _startCount = _count;
+                    }
+                }
+            }
+
+            PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
+            if (_startCount < _maxCount) {
+                PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit);
+                chargingInfo[_index]->ChargingProfilePower = ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].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;
+                }
+            } else {
+                chargingInfo[_index]->ChargingProfilePower = -1;
+                chargingInfo[_index]->ChargingProfileCurrent = -1;
+            }
+        } else {
+            chargingInfo[_index]->ChargingProfilePower = -1;
+            chargingInfo[_index]->ChargingProfileCurrent = -1;
+        }
+    } else {
+        chargingInfo[_index]->ChargingProfilePower = -1;
+        chargingInfo[_index]->ChargingProfileCurrent = -1;
+    }
+
+    PRINTF_FUNC("Profile : ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
+    PRINTF_FUNC("Profile : ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
+}

+ 488 - 0
EVSE/Projects/DD360/Apps/CSU/Primary.c

@@ -0,0 +1,488 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+#include "../SelectGun/SelectGun.h"
+#include "../main.h"
+
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
+{
+    uint8_t ret = NO;
+    LedConfig *pLedConfig = (LedConfig *)ledConfig;
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
+        ret = YES;
+        if (pLedConfig->RedLED == YES) {
+            pLedConfig->RedLED = NO;
+        } else {
+            pLedConfig->RedLED = YES;
+        }
+    }
+
+    return ret;
+}
+
+void PrimaryLedIndicatorCtrlFork(void)
+{
+#if !defined DD360ComBox
+    return;
+#endif //!defined DD360ComBox
+
+    pid_t pid = fork();
+    if (pid == 0) {
+        uint8_t gunIndex = 0;
+        int isContinue = 1;
+        LedConfig *pLedConfig = NULL;
+        struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+        struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+        struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+        struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+        struct ChargingInfoData *pDcChargingInfoData = NULL;
+
+        pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
+
+        while (isContinue) {
+            for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+                pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+                //printf("led indicator status = %d\r\n", pDcChargingInfoData->SystemStatus);
+                //printf("level = %d\r\n", pSysWarningInfo->Level);
+                switch (pDcChargingInfoData->SystemStatus) {
+                case S_BOOTING:
+                    if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+                        //Module_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:
+                    //Module_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:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        break;
+                    }
+
+                    pLedConfig->RedLED = YES;
+                    break;
+
+                case S_TERMINATING:
+                case S_COMPLETE:
+                    if (pSysWarningInfo->Level == 2) {
+                        pLedConfig->YellowLED = NO;
+                        pLedConfig->GreenLED = NO;
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        pLedConfig->RedLED = YES;
+                    } else {
+                        pLedConfig->RedLED = NO;
+                        pLedConfig->YellowLED = YES;
+                        pLedConfig->GreenLED = NO;
+                    }
+                    break;
+
+                case S_MAINTAIN:
+                case S_FAULT:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    if (pSysWarningInfo->Level == 2) {
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        pLedConfig->RedLED = YES;
+                    }
+                    break;
+
+                case S_BOOKING:
+                case S_DEBUG:
+                case S_UPDATE:
+                case S_NONE:
+                    break;
+                }//switch
+
+            } //for
+            usleep(500000);
+        } //while
+    } //fork
+}
+
+//------------------------------------------------------------------------------
+// 急停狀況的停止充電處理函式
+void EmcOccureByString(char *code)
+{
+    uint8_t level = 2;
+    uint8_t gunIndex = 0;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct ChargingInfoData *pDcChargingInfoData = NULL;
+
+
+    // 嚴重的急停有以下幾種 : 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 (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+            pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+            //strncpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, code, 6);
+
+            if ((pDcChargingInfoData->SystemStatus > S_IDLE &&
+                    pDcChargingInfoData->SystemStatus < S_TERMINATING) ||
+                    (pDcChargingInfoData->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                     pDcChargingInfoData->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                //ChargingTerminalProcess(gunIndex);
+                ChargingAlarmProcess(gunIndex);
+            }
+        }
+//#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+        StopChargingProcessByString(level);
+        //InformOcppErrOccur(4);
+//#endif //defined DD360 || defined DD360Audi
+    }
+}
+
+void ReleaseEmsOccureByString(uint8_t index, char *code)
+{
+    bool isTrigger = false;
+    uint8_t level = 2;
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (strncmp(code, "042251", 6) == 0 ) {
+        isTrigger = true;
+    } else if (strncmp(code, "012251", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
+    } else if (strncmp(code, "012252", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
+    } else if (strncmp(code, "012237", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
+    } else if (strncmp(code, "012238", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
+    }
+
+    if (isTrigger) {
+        ReleaseChargingProcessByString(level);
+        InformOcppErrOccur(6);
+    }
+}
+
+void ChkPrimaryStatus(void)
+{
+    uint8_t Rtn;
+    static bool leftBtnPush = false;
+    static bool rightBtnPush = false;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+    struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    struct ChargingInfoData *pDcChargingInfoData = NULL;
+    struct ChargingInfoData *pAcChargingInfoData = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    if (pSysWarningInfo->WarningCount > 0) {
+        Rtn = 0;
+        for (uint8_t i = 0; i < pSysWarningInfo->WarningCount; i++) {
+            if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042251", 6) == 0) {
+                EmcOccureByString("042251");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042252", 6) == 0) {
+                EmcOccureByString("042252");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042200", 6) == 0) {
+                EmcOccureByString("042200");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042201", 6) == 0) {
+                EmcOccureByString("042201");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042202", 6) == 0) {
+                EmcOccureByString("042202");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->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) {
+        pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = YES;
+        EmcOccureByString("012251");
+    } else {
+        ReleaseEmsOccureByString(0, "012251");
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
+        pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = YES;
+        EmcOccureByString("012238");
+    } else {
+        ReleaseEmsOccureByString(0, "012238");
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
+        pAlarmCode->AlarmEvents.bits.SpdTrip = YES;
+    } else {
+        pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
+        pAlarmCode->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) {
+    //    pSysConfig->ShowInformation = YES;
+    //} else {
+    //    pSysConfig->ShowInformation = NO;
+    //}
+
+    pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+
+    if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
+            !leftBtnPush &&
+            WaitAuthorPageState()
+       ) {
+        if (!leftBtnPush) {
+            leftBtnPush = true;
+            log_info("left btn down...............................%x\n", pDcChargingInfoData->SystemStatus);
+            if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+                switch (pAcChargingInfoData->SystemStatus) {
+                case S_IDLE:
+                    if (isDetectPlugin()) {
+                        _DetectPlugInTimeout();
+                        StopSystemTimeoutDet();
+                    }
+                    break;
+
+                case S_REASSIGN_CHECK:
+                case S_REASSIGN:
+                case S_PREPARNING:
+                case S_PREPARING_FOR_EV:
+                case S_PREPARING_FOR_EVSE:
+                case S_CCS_PRECHARGE_ST0:
+                case S_CCS_PRECHARGE_ST1:
+                    // 取消充電
+                    AcChargingTerminalProcess();
+                    break;
+
+                case S_CHARGING:
+                    if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+                        // 停止充電
+                        AcChargingTerminalProcess();
+                    }
+                    break;
+
+                case S_COMPLETE:
+                    break;
+                }
+            }
+
+            switch (pDcChargingInfoData->SystemStatus) {
+            case S_IDLE:
+                if (isDetectPlugin()) {
+                    _DetectPlugInTimeout();
+                    StopSystemTimeoutDet();
+#if defined DD360Audi
+                    destroySelGun(pSysInfo->CurGunSelected);
+#endif //defined DD360Audi
+                }
+#if defined DD360Audi
+                else {
+                    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
+                        //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
+                        destroySelGun(pSysInfo->CurGunSelected);
+                    } else {
+                        confirmSelGun(pSysInfo->CurGunSelected);
+                        log_info("confirm select gun ............................... %d \n",
+                                 pSysInfo->CurGunSelected);
+                    }
+                }
+#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 (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+                    AcChargingTerminalProcess();
+                } else {
+                    ChargingTerminalProcess(pSysInfo->CurGunSelected);
+                }
+                break;
+
+            case S_CHARGING:
+                if (pSysConfig->StopChargingByButton == YES ||
+                        pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+                    // 停止充電
+                    ChargingTerminalProcess(pSysInfo->CurGunSelected);
+                }
+                break;
+
+            case S_COMPLETE:
+                // 回 IDLE
+                //log_info("right btn down.................S_COMPLETE \n");
+                //pDcChargingInfoData->SystemStatus = S_IDLE;
+                break;
+            }
+        }
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
+        if (leftBtnPush) {
+            leftBtnPush = false;
+            //log_info("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;
+            //log_info("right btn down............................... %d \n", pSysInfo->CurGunSelected);
+            if (pSysInfo->CurGunSelected + 1 <
+                    pSysConfig->TotalConnectorCount &&
+                    pSysInfo->IsAlternatvieConf == NO) {
+                pSysInfo->CurGunSelected++;
+                ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+            } else if (pSysConfig->AcConnectorCount > 0 &&
+                       pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
+                pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+            } else if (pSysInfo->IsAlternatvieConf == YES) {
+                for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
+                    pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+                    if (pDcChargingInfoData->SystemStatus != S_BOOTING &&
+                            pDcChargingInfoData->SystemStatus != S_IDLE &&
+                            pDcChargingInfoData->SystemStatus != S_RESERVATION) {
+                        pSysInfo->CurGunSelected = _index;
+                        ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+                        return;
+                    }
+                }
+                pSysInfo->CurGunSelected = 0;
+                ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+            } else {
+                pSysInfo->CurGunSelected = 0;
+                ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+            }
+        }
+        log_info("current select gun ............................... %d \n",
+                 pSysInfo->CurGunSelected);
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
+        if (rightBtnPush) {
+            rightBtnPush = false;
+            //log_info("right btn up............................... \n");
+        }
+    }
+}

+ 320 - 0
EVSE/Projects/DD360/Apps/CSU/RFID.c

@@ -0,0 +1,320 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+static void UserScanFunction(void)
+{
+    bool idleReq = false;
+    uint8_t 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 (uint8_t 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];
+
+                log_info("ac stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
+                         ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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];
+
+                log_info("stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n",
+                         ShmSysConfigAndInfo->SysInfo.CurGunSelected,
+                         chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
+                         ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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) {
+                    log_info("// 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;
+                    }
+                }
+            }
+        }
+    }
+}
+
+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
+#else
+                && gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance != FAIL_BALANCE_PRICES
+#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;
+    }
+}
+
+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);
+        }
+    }
+}

+ 303 - 0
EVSE/Projects/DD360/Apps/CSU/TimeTask.c

@@ -0,0 +1,303 @@
+
+void _CcsPrechargeTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _CcsPrechargeTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+}
+
+void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
+    //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
+    {
+        setChargerMode(gunIndex, MODE_IDLE);
+        _AutoReturnTimeout();
+    }
+}
+
+void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
+{
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        if (!isEvGunLocked_chademo(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
+        }
+    }
+    ChargingTerminalProcess(gunIndex);
+    _AutoReturnTimeout();
+}
+
+void _PrepareTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _PrepareTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
+    _AutoReturnTimeout();
+}
+
+void ClearAuthorizedFlag()
+{
+    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
+    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+}
+
+void DisplayChargingInfo()
+{
+    log_info("*********** DisplayChargingInfo *********** \n");
+    for (uint8_t 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 _DetectPlugInTimeout()
+{
+    log_info("*********** _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 _AutoReturnTimeout()
+{
+    log_info("*********** _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 StopSystemTimeoutDet()
+{
+    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
+    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+}
+
+void _SelfTestTimeout()
+{
+    if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE) {
+        for (uint8_t 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;
+    log_info("Self test timeout. \n");
+}
+
+void CheckConnectionTimeout(void)
+{
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
+        _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
+    } else {
+        _connectionTimeout = CONN_PLUG_TIME_OUT;
+    }
+
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+    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;
+        }
+    }
+}
+
+void CreateTimeoutFork(void)
+{
+    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();
+                    destroySelGun(DESTROY_ALL_SEL); //jerry add
+                }
+                break;
+
+            case Timeout_Authorizing:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
+                    _AuthorizedTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                break;
+
+            case Timeout_VerifyFail:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                    _AutoReturnTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                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();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+                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;
+
+            } //switch
+
+            // 各槍
+            for (uint8_t 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);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
+                        _DetectEvChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
+                        _DetectEvseChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseCompleteDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_ForCcsPrechargeDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
+                        _CcsPrechargeTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_SelectGun: //Jerry add
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+                } //switch
+            } //for
+            sleep(1);
+        }//while
+    }
+}

+ 271 - 0
EVSE/Projects/DD360/Apps/CSU/Update.c

@@ -0,0 +1,271 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+int CheckUpdateProcess(void)
+{
+    //bool isPass = true;
+    uint8_t retSucc = 0;
+    uint8_t retFail = 0;
+    uint8_t index = 0;
+    uint8_t target = 0;
+    char *new_str = NULL;
+    uint8_t *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;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    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 (uint8_t i = 0; i < 16; i++) {
+                if (pSysConfig->ModelName[i] != ptr[i]) {
+                    return FAIL;
+                }
+            }
+
+            log_info("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]));
+                log_info("Typed...%x \r\n", Type);
+
+                switch (Type) {
+                case 0x10000001:
+                case 0x10000002:
+                case 0x10000003:
+                case 0x10000004:
+                case 0x10000005:
+                    if (Upgrade_Flash(Type, new_str, (char *)pSysConfig->ModelName) == PASS) {
+                        //return PASS;
+                        retSucc++;
+                    } else {
+                        log_info("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 < pSysConfig->TotalConnectorCount; index++) {
+                            //if (!isPass) {
+                            //    break;
+                            //}
+
+                            if (chargingInfo[index]->Type == _Type_CCS_2) {
+                                if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)pSysConfig->ModelName) == FAIL) {
+                                    //isPass = false;
+                                    log_info("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 *)pSysConfig->ModelName) == PASS) {
+                        //return PASS;
+                        retSucc++;
+                    } else {
+                        log_info("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 < pSysConfig->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 *)pSysConfig->ModelName) == PASS) {
+                                    //isPass = PASS;
+                                    retSucc++;
+                                } else {
+                                    log_info("Upgrade %x Failed\r\n", Type);
+                                    //isPass = FAIL;
+                                    retFail++;
+                                }
+                            }
+                        }
+                    } else {
+                        log_info("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 CheckFwUpdateFunction(void)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    //log_info("pSysInfo->FirmwareUpdate = %d \n", pSysInfo->FirmwareUpdate);
+    if (pSysInfo->FirmwareUpdate == YES) {
+        log_info("ftp : update start. \n");
+        for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
+            setChargerMode(gun_index, MODE_UPDATE);
+        }
+
+        uint8_t 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();
+            pSysInfo->FirmwareUpdate = NO;
+            sleep(5);
+            system("/usr/bin/run_evse_restart.sh");
+            return;
+        } else {
+            log_info("ftp : update fail. \n");
+        }
+
+        pSysInfo->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 (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
+                setChargerMode(_index, MODE_UPDATE);
+            }
+            for (uint8_t _index = 0; _index < pSysConfig->AcConnectorCount; _index++) {
+                ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
+            }
+
+            uint8_t 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");
+        }
+    }
+}

+ 0 - 0
EVSE/Projects/DD360/Apps/CSU/WatchDog.c


+ 62 - 0
EVSE/Projects/DD360/Apps/CSU/ZipFile.c

@@ -0,0 +1,62 @@
+
+void zipLogFiles(void)
+{
+    const char *logPath = "/Storage/SystemLog";
+    // 獲取目錄
+    DIR *pDir = opendir(logPath);
+    if (pDir != NULL) {
+        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);
+
+        // 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);
+                        log_info("zip = %s \n", file);
+                        system(file);
+                    }
+                }
+            }
+        }
+    }
+    // Close folder
+    closedir(pDir);
+}

+ 27 - 24
EVSE/Projects/DD360/Apps/Config.h

@@ -251,29 +251,29 @@ enum RELAY_STATUS_ERROR_TYPE {
 };
 
 //------------------------------------------------------------------------------
-struct StructMeter {
-    float curMeterValue;
-    float newMeterValue;
-    uint8_t isCalculation;
-    float _chargingValue;
-    float _curTotalCharging;
-};
-
-struct MeterInformation {
-    struct StructMeter _meter[2];
-    uint8_t isWorking;
-};
-
-struct DcCommonInformation {
-    // check if the guns are of the same type
-    uint8_t SysGunAreSameType;
-    // to check the ccs version
-    uint8_t CcsVersion;
-    // for relay welding/driving check
-    char RelayCheckStatus[6];
-    char GunRelayWeldingOccur[2];
-    char GunRelayDrivingOccur[2];
-};
+//struct StructMeter {
+//    float curMeterValue;
+//    float newMeterValue;
+//    uint8_t isCalculation;
+//    float _chargingValue;
+//    float _curTotalCharging;
+//};
+
+//struct MeterInformation {
+//    struct StructMeter _meter[2];
+//    uint8_t isWorking;
+//};
+
+//struct DcCommonInformation {
+//    // check if the guns are of the same type
+//    uint8_t SysGunAreSameType;
+//    // to check the ccs version
+//    uint8_t CcsVersion;
+//    // for relay welding/driving check
+//    char RelayCheckStatus[6];
+//    char GunRelayWeldingOccur[2];
+//    char GunRelayDrivingOccur[2];
+//};
 
 typedef union {
     uint32_t GunErrMessage;
@@ -312,8 +312,11 @@ typedef union {
 
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
+    uint8_t CcsVersion;
     EvBoardErrMsg ConnectErrList[2]; //connector error list, 0: left gun, 1: right gun
-    uint8_t Reserved[3];
+    uint8_t CheckRelayStatus[6]; //check Relay welding or driving fault
+    uint8_t GunRelayWeldingOccur[2];
+    uint8_t GunRelayDrivingOccur[2];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 253 - 0
EVSE/Projects/DD360/Apps/DataBase/DataBase.c

@@ -0,0 +1,253 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+
+        if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local charging record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local charging record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local config table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local config table successfully\n");
+        }
+
+        //DS60-120
+        if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create reboot record table error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert local charging record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete local charging error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
+
+        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
+        sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
+        log_info("sqlStr= %s\r\n", sqlStr);
+        if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "update config error message: %s\n", errMsg);
+        } else {
+            log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+        }
+
+        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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "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;
+                }
+                log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
+            }
+        } else {
+            log_info("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;
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "delete reboot record successfully\n");
+        }
+
+        sqlite3_close(db);
+    }
+
+    return result;
+}

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

@@ -0,0 +1,5 @@
+#ifndef _DATA_BASE_H_
+#define _DATA_BASE_H_
+
+
+#endif /* _DATA_BASE_H_ */

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

@@ -0,0 +1,7 @@
+2021/05/25
+1. Add detected chiller temperature and stop charging when it exceeds 90°C.
+2. Fix multi dispenser reboot, DHCP IP address conflict issue.
+3. Fix the GFD test failed and the alarm code was not recorded.
+4. Fix ccs OVP status code not release issue.
+5. Add to complete the registration but did not get the balance to restart DoComm.
+6. Add button stop charging function.

+ 63 - 0
EVSE/Projects/DD360/Apps/Log/log.c

@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <unistd.h>
+#include <time.h>
+#include <stdarg.h>
+
+#include <sys/timeb.h>
+
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+#include "log.h"
+
+//------------------------------------------------------------------------------
+#define YES                                     1
+#define NO                                      0
+
+//------------------------------------------------------------------------------
+int StoreLogMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256] = {0};
+    char buffer[4096] = {0};
+    int rc = -1;
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    va_start(args, fmt);
+    rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    if (pSysConfig->SwitchDebugFlag == YES) {
+        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                SeqEndTime.millitm,
+                buffer);
+        printf("%s\r\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;
+}

+ 12 - 0
EVSE/Projects/DD360/Apps/Log/log.h

@@ -0,0 +1,12 @@
+#ifndef _LOG_H_
+#define _LOG_H_
+
+//------------------------------------------------------------------------------
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
+int StoreLogMsg(const char *fmt, ...);
+
+#endif /* _LOG_H_ */

+ 48 - 10
EVSE/Projects/DD360/Apps/Makefile

@@ -12,6 +12,10 @@ TFLAGS = -lrt -lm -lpthread
 
 TOP = .
 
+INC_FLAGS += -I $(TOP)/Define
+INC_FLAGS += -I $(TOP)/Log
+INC_FLAGS += -I $(TOP)/ShareMemory
+INC_FLAGS += -I $(TOP)/CSU
 INC_FLAGS += -I $(TOP)/ModuleInternalComm
 INC_FLAGS += -I $(TOP)/ModuleEvComm
 INC_FLAGS += -I $(TOP)/ModulePrimary
@@ -20,13 +24,16 @@ INC_FLAGS += -I $(TOP)/ModuleDoComm
 INC_FLAGS += -I $(TOP)/ModuleEventLog
 
 DefineLib = $(TOP)/Define
+LogLib = $(TOP)/Log
 ShmMemLib = $(TOP)/ShareMemory
+CSULib = $(TOP)/CSU
 InternalCommLib = $(TOP)/ModuleInternalComm
 EvCommLib = $(TOP)/ModuleEvComm
 PrimaryLib = $(TOP)/ModulePrimary
 LcmLib = $(TOP)/ModuleLcmCtrl
 DoCommLib = $(TOP)/ModuleDoComm
 EventLogLib = $(TOP)/ModuleEventLog
+SelectGunLib = $(TOP)/SelectGun
 ScriptLib = $(TOP)/Script
 
 
@@ -50,15 +57,46 @@ RatedCurrent_H = -include$(ModularizationPath)/Module_RatedCurrent.h
 InfypwrPsuComm_H = -include$(ModularizationPath)/Infypwr_PsuCommObj.h
 InfypwrPsuComm_A = $(ModularizationPath)/libInfypwr_PsuCommObj.a
 
+#common lib
+COMMON_OBJ_FILES = common.o \
+					$(DefineLib)/define.o \
+					$(ShmMemLib)/shmMem.o \
+					$(LogLib)/log.o \
+					$(SelectGunLib)/SelectGun.o
+#main
+MAIN_OBJ_FILES = $(COMMON_OBJ_FILES) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(Lib_Module_RatedCurrent) \
+					main.o $(CSULib)/Primary.o
+MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
+#internal comm lib
+INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o $(InternalCommLib)/Module_InternalComm.o \
+							$(InternalCommLib)/FanBoard.o $(InternalCommLib)/LEDlight.o $(InternalCommLib)/RelayBoard.o \
+								$(InternalCommLib)/AcPlug.o
+INTERNALCOMM_SRC_FILES = $(patsubst %.o, %.c, $(INTERNALCOMM_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
+#EV comm lib
+EVCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(RatedCurrent_H) $(EvCommLib)/Module_EvTxComm.o \
+					$(EvCommLib)/Module_EvRxComm.o $(EvCommLib)/Ev_Comm.o $(EvCommLib)/AbnormalCCS.o \
+						$(EvCommLib)/AbnormalCHA.o $(EvCommLib)/AbnormalGBT.o $(EvCommLib)/AbnormalState.o
+EVCOMM_SRC_FILES = $(patsubst %.o, %.c, $(EVCOMM_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
+
 all: CopyFile apps
-#apps: Module_CSU Module_EvComm Module_EventLogging Module_InternalComm Module_LcmControl Module_PrimaryComm Module_PsuComm
-# ReadCmdline kill.sh
+
 apps: MainTask DoCommTask EvCommTask \
 		EventLoggingTask InternalCommTask LcmControlTask \
 			PrimaryCommTask ReadCmdlineTask UnsafetyOutputTool \
 				FactoryConfigApp OtherTools CleanExec
 
 MainTask:
+	#$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) ${Lib_Module_RFID} \
+	#	 ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent) -o main
 	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
 	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
 	$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c
@@ -70,9 +108,10 @@ DoCommTask:
 	$(CC) -o Module_DoComm DoComm.o define.o
 
 EvCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
-	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
+	$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
+	#$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
 
 EventLoggingTask:
 	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
@@ -80,11 +119,10 @@ EventLoggingTask:
 	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
 
 InternalCommTask:
-	#$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o ShmMem.o $(ShmMemLib)/shmMem.c
-	#$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o Relay.o $(InternalCommLib)/Relay.c ShmMem.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)
+	$(CC) $(DEFINE) $(INTERNALCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_InternalComm
+	#$(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) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c

+ 913 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCCS.c

@@ -0,0 +1,913 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+void ClearAbnormalStatus_CCS(uint8_t gun_index)
+{
+    bool isCleanCheck = false;
+    char code[7];
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
+        return;
+    }
+
+    if (true) {
+        if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "012219", 6) == EQUAL &&
+                pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
+            memcpy(code, "012219", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023701", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEvCommFail == YES) {
+            memcpy(code, "023701", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023737", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit == YES) {
+            memcpy(code, "023737", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023738", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVShiftPosition == YES) {
+            memcpy(code, "023738", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023739", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargerConnectorLockFault == YES) {
+            memcpy(code, "023739", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023740", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVRESSMalfunction == YES) {
+            memcpy(code, "023740", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023741", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingCurrentdifferential == YES) {
+            memcpy(code, "023741", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023742", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingVoltageOutOfRange == YES) {
+            memcpy(code, "023742", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023743", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingSystemIncompatibility == YES) {
+            memcpy(code, "023743", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023744", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEmergencyEvent == YES) {
+            memcpy(code, "023744", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023745", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsBreaker == YES) {
+            memcpy(code, "023745", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023746", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoData == YES) {
+            memcpy(code, "023746", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023747", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_A == YES) {
+            memcpy(code, "023747", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023748", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_B == YES) {
+            memcpy(code, "023748", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023749", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_C == YES) {
+            memcpy(code, "023749", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023750", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_1 == YES) {
+            memcpy(code, "023750", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023751", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_2 == YES) {
+            memcpy(code, "023751", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023752", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_3 == YES) {
+            memcpy(code, "023752", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023753", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_1 == YES) {
+            memcpy(code, "023753", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023754", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_2 == YES) {
+            memcpy(code, "023754", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023755", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_3 == YES) {
+            memcpy(code, "023755", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023756", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_4 == YES) {
+            memcpy(code, "023756", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023757", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_5 == YES) {
+            memcpy(code, "023757", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023758", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSequenceError == YES) {
+            memcpy(code, "023758", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023759", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSignatureError == YES) {
+            memcpy(code, "023759", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023760", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsUnknownSession == YES) {
+            memcpy(code, "023760", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023761", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServiceIDInvalid == YES) {
+            memcpy(code, "023761", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023762", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPaymentSelectionInvalid == YES) {
+            memcpy(code, "023762", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023763", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsIdentificationSelectionInvalid == YES) {
+            memcpy(code, "023763", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023764", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServiceSelectionInvalid == YES) {
+            memcpy(code, "023764", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023765", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateExpired == YES) {
+            memcpy(code, "023765", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023766", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateNotYetValid == YES) {
+            memcpy(code, "023766", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023767", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateRevoked == YES) {
+            memcpy(code, "023767", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023768", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoCertificateAvailable == YES) {
+            memcpy(code, "023768", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023769", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertChainError == YES) {
+            memcpy(code, "023769", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023770", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertValidationError == YES) {
+            memcpy(code, "023770", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023771", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertVerificationError == YES) {
+            memcpy(code, "023771", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023772", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContractCanceled == YES) {
+            memcpy(code, "023772", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023773", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChallengeInvalid == YES) {
+            memcpy(code, "023773", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023774", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsWrongEnergyTransferMode == YES) {
+            memcpy(code, "023774", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023775", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsWrongChargeParameter == YES) {
+            memcpy(code, "023775", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023776", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingProfileInvalid == YES) {
+            memcpy(code, "023776", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023777", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTariffSelectionInvalid == YES) {
+            memcpy(code, "023777", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023778", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVSEPresentVoltageToLow == YES) {
+            memcpy(code, "023778", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023779", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPowerDeliveryNotApplied == YES) {
+            memcpy(code, "023779", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023780", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMeteringSignatureNotValid == YES) {
+            memcpy(code, "023780", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023781", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoChargeServiceSelected == YES) {
+            memcpy(code, "023781", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023782", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContactorError == YES) {
+            memcpy(code, "023782", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023783", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE == YES) {
+            memcpy(code, "023783", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023784", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsGAChargeStop == YES) {
+            memcpy(code, "023784", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023785", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsAlignmentError == YES) {
+            memcpy(code, "023785", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023786", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsACDError == YES) {
+            memcpy(code, "023786", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023787", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsAssociationError == YES) {
+            memcpy(code, "023787", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023788", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVSEChargeAbort == YES) {
+            memcpy(code, "023788", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023789", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoSupportedAppProtocol == YES) {
+            memcpy(code, "023789", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023790", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContractNotAccepted == YES) {
+            memcpy(code, "023790", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023791", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMOUnknown == YES) {
+            memcpy(code, "023791", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023792", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_Prov_CertificateRevoke == YES) {
+            memcpy(code, "023792", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023793", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked == YES) {
+            memcpy(code, "023793", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023794", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked == YES) {
+            memcpy(code, "023794", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023795", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked == YES) {
+            memcpy(code, "023795", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023796", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_Prov_CertificateRevoked == YES) {
+            memcpy(code, "023796", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023797", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked == YES) {
+            memcpy(code, "023797", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023798", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked == YES) {
+            memcpy(code, "023798", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023799", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_RootCA_CertificateRevoked == YES) {
+            memcpy(code, "023799", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023800", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_Prov_CertificateRevoked == YES) {
+            memcpy(code, "023800", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023801", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked == YES) {
+            memcpy(code, "023801", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023802", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked == YES) {
+            memcpy(code, "023802", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023803", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked == YES) {
+            memcpy(code, "023803", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023809", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_SLAC_init == YES) {
+            memcpy(code, "023809", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023810", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_match_response == YES) {
+            memcpy(code, "023810", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023811", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_match_sequence == YES) {
+            memcpy(code, "023811", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023812", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_match_MNBC == YES) {
+            memcpy(code, "023812", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023813", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_avg_atten_calc == YES) {
+            memcpy(code, "023813", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023814", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_match_response == YES) {
+            memcpy(code, "023814", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023815", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_match_session == YES) {
+            memcpy(code, "023815", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023816", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_assoc_session == YES) {
+            memcpy(code, "023816", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023817", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_vald_toggle == YES) {
+            memcpy(code, "023817", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023818", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound == YES) {
+            memcpy(code, "023818", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023819", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq == YES) {
+            memcpy(code, "023819", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023823", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsUDP_TT_match_join == YES) {
+            memcpy(code, "023823", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023824", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTCP_TT_match_join == YES) {
+            memcpy(code, "023824", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023825", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_amp_map_exchange == YES) {
+            memcpy(code, "023825", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023826", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_link_ready_notification == YES) {
+            memcpy(code, "023826", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023832", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSupportedAppProtocolRes == YES) {
+            memcpy(code, "023832", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023833", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSessionSetupRes == YES) {
+            memcpy(code, "023833", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023834", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServiceDiscoveryRes == YES) {
+            memcpy(code, "023834", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023835", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServicePaymentSelectionRes == YES) {
+            memcpy(code, "023835", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023836", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContractAuthenticationRes == YES) {
+            memcpy(code, "023836", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023837", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargeParameterDiscoveryRes == YES) {
+            memcpy(code, "023837", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023838", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPowerDeliveryRes == YES) {
+            memcpy(code, "023838", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023839", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCableCheckRes == YES) {
+            memcpy(code, "023839", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023840", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPreChargeRes == YES) {
+            memcpy(code, "023840", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023841", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCurrentDemandRes == YES) {
+            memcpy(code, "023841", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023842", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsWeldingDetectionRes == YES) {
+            memcpy(code, "023842", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023843", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSessionStopRes == YES) {
+            memcpy(code, "023843", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023844", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSequence_Time == YES) {
+            memcpy(code, "023844", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023845", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsReadyToCharge_Performance_Time == YES) {
+            memcpy(code, "023845", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023846", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCommunicationSetup_Performance_Time == YES) {
+            memcpy(code, "023846", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023847", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCableCheck_Performance_Time == YES) {
+            memcpy(code, "023847", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023848", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPState_Detection_Time == YES) {
+            memcpy(code, "023848", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023849", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPOscillator_Retain_Time == YES) {
+            memcpy(code, "023849", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023850", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime == YES) {
+            memcpy(code, "023850", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023855", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO == YES) {
+            memcpy(code, "023855", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023856", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO == YES) {
+            memcpy(code, "023856", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023857", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO == YES) {
+            memcpy(code, "023857", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023858", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO == YES) {
+            memcpy(code, "023858", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023859", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EV_STOP_EVENT == YES) {
+            memcpy(code, "023859", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023860", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EV_STOP_EVENT == YES) {
+            memcpy(code, "023860", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023861", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_STOP_EVENT == YES) {
+            memcpy(code, "023861", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023862", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_STOP_EVENT == YES) {
+            memcpy(code, "023862", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023863", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_GET_MISC_INFO == YES) {
+            memcpy(code, "023863", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023864", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_GET_MISC_INFO == YES) {
+            memcpy(code, "023864", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023865", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST == YES) {
+            memcpy(code, "023865", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023866", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST == YES) {
+            memcpy(code, "023866", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023867", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER == YES) {
+            memcpy(code, "023867", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023868", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER == YES) {
+            memcpy(code, "023868", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023869", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_DATA_TRANSFER == YES) {
+            memcpy(code, "023869", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023870", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_DATA_TRANSFER == YES) {
+            memcpy(code, "023870", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023871", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_FINISH == YES) {
+            memcpy(code, "023871", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023872", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_FINISH == YES) {
+            memcpy(code, "023872", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023873", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_ISOLATION_STATUS == YES) {
+            memcpy(code, "023873", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023874", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_ISOLATION_STATUS == YES) {
+            memcpy(code, "023874", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023875", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_CONNECTOR_INFO == YES) {
+            memcpy(code, "023875", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023876", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_CONNECTOR_INFO == YES) {
+            memcpy(code, "023876", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023877", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_RTC_INFO == YES) {
+            memcpy(code, "023877", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023878", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_RTC_INFO == YES) {
+            memcpy(code, "023878", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023879", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO == YES) {
+            memcpy(code, "023879", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023880", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO == YES) {
+            memcpy(code, "023880", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023881", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMSG_Sequence == YES) {
+            memcpy(code, "023881", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023882", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID == YES) {
+            memcpy(code, "023882", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023883", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsDIN_Msg_Decode_Error == YES) {
+            memcpy(code, "023883", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023884", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsDIN_Msg_Encode_Error == YES) {
+            memcpy(code, "023884", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023885", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO1_Msg_Decode_Error == YES) {
+            memcpy(code, "023885", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023886", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO1_Msg_Encode_Error == YES) {
+            memcpy(code, "023886", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023887", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO2_Msg_Decode_Error == YES) {
+            memcpy(code, "023887", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023888", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO2_Msg_Encode_Error == YES) {
+            memcpy(code, "023888", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023889", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCpStatus_Error == YES) {
+            memcpy(code, "023889", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023890", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error == YES) {
+            memcpy(code, "023890", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023891", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccNotReadyForCharging == YES) {
+            memcpy(code, "023891", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+//  else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023892", 6) == EQUAL &&
+//          pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
+//  {
+//      memcpy(code, "023892", 6);
+//      memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+//      isCleanCheck = true;
+//  }
+        else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023893", 6) == EQUAL &&
+                 pInfoCode->InfoEvents.bits.CcsSeccFailForQCA7000SetKey == YES) {
+            memcpy(code, "023893", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023979", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.EV_Full_Charging == YES) {
+            memcpy(code, "023979", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023983", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason == YES) {
+            memcpy(code, "023983", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+            if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                log_info("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
+                         index,
+                         pDcChargingInfo->EvConnAlarmCode,
+                         code);
+
+                if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+                    if (strncmp(code, "012219", 6) == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO; }
+
+                    if (strncmp(code, "023701", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = NO; }
+                    if (strncmp(code, "023737", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit = NO; }
+                    if (strncmp(code, "023738", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVShiftPosition = NO; }
+                    if (strncmp(code, "023739", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargerConnectorLockFault = NO; }
+                    if (strncmp(code, "023740", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVRESSMalfunction = NO; }
+                    if (strncmp(code, "023741", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingCurrentdifferential = NO; }
+                    if (strncmp(code, "023742", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingVoltageOutOfRange = NO; }
+                    if (strncmp(code, "023743", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingSystemIncompatibility = NO; }
+                    if (strncmp(code, "023744", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEmergencyEvent = NO; }
+                    if (strncmp(code, "023745", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsBreaker = NO; }
+                    if (strncmp(code, "023746", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoData = NO; }
+                    if (strncmp(code, "023747", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_A = NO; }
+                    if (strncmp(code, "023748", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_B = NO; }
+                    if (strncmp(code, "023749", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_C = NO; }
+                    if (strncmp(code, "023750", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_1 = NO; }
+                    if (strncmp(code, "023751", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_2 = NO; }
+                    if (strncmp(code, "023752", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_3 = NO; }
+                    if (strncmp(code, "023753", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_1 = NO; }
+                    if (strncmp(code, "023754", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_2 = NO; }
+                    if (strncmp(code, "023755", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_3 = NO; }
+                    if (strncmp(code, "023756", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_4 = NO; }
+                    if (strncmp(code, "023757", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_5 = NO; }
+                    if (strncmp(code, "023758", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequenceError = NO; }
+                    if (strncmp(code, "023759", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSignatureError = NO; }
+                    if (strncmp(code, "023760", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnknownSession = NO; }
+                    if (strncmp(code, "023761", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceIDInvalid = NO; }
+                    if (strncmp(code, "023762", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPaymentSelectionInvalid = NO; }
+                    if (strncmp(code, "023763", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsIdentificationSelectionInvalid = NO; }
+                    if (strncmp(code, "023764", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceSelectionInvalid = NO; }
+                    if (strncmp(code, "023765", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateExpired = NO; }
+                    if (strncmp(code, "023766", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotYetValid = NO; }
+                    if (strncmp(code, "023767", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateRevoked = NO; }
+                    if (strncmp(code, "023768", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoCertificateAvailable = NO; }
+                    if (strncmp(code, "023769", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertChainError = NO; }
+                    if (strncmp(code, "023770", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertValidationError = NO; }
+                    if (strncmp(code, "023771", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertVerificationError = NO; }
+                    if (strncmp(code, "023772", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractCanceled = NO; }
+                    if (strncmp(code, "023773", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChallengeInvalid = NO; }
+                    if (strncmp(code, "023774", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongEnergyTransferMode = NO; }
+                    if (strncmp(code, "023775", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongChargeParameter = NO; }
+                    if (strncmp(code, "023776", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingProfileInvalid = NO; }
+                    if (strncmp(code, "023777", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTariffSelectionInvalid = NO; }
+                    if (strncmp(code, "023778", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEPresentVoltageToLow = NO; }
+                    if (strncmp(code, "023779", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryNotApplied = NO; }
+                    if (strncmp(code, "023780", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMeteringSignatureNotValid = NO; }
+                    if (strncmp(code, "023781", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoChargeServiceSelected = NO; }
+                    if (strncmp(code, "023782", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContactorError = NO; }
+                    if (strncmp(code, "023783", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = NO; }
+                    if (strncmp(code, "023784", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsGAChargeStop = NO; }
+                    if (strncmp(code, "023785", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsAlignmentError = NO; }
+                    if (strncmp(code, "023786", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsACDError = NO; }
+                    if (strncmp(code, "023787", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsAssociationError = NO; }
+                    if (strncmp(code, "023788", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEChargeAbort = NO; }
+                    if (strncmp(code, "023789", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoSupportedAppProtocol = NO; }
+                    if (strncmp(code, "023790", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractNotAccepted = NO; }
+                    if (strncmp(code, "023791", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMOUnknown = NO; }
+                    if (strncmp(code, "023792", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = NO; }
+                    if (strncmp(code, "023793", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = NO; }
+                    if (strncmp(code, "023794", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = NO; }
+                    if (strncmp(code, "023795", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = NO; }
+                    if (strncmp(code, "023796", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_Prov_CertificateRevoked = NO; }
+                    if (strncmp(code, "023797", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = NO; }
+                    if (strncmp(code, "023798", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = NO; }
+                    if (strncmp(code, "023799", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = NO; }
+                    if (strncmp(code, "023800", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = NO; }
+                    if (strncmp(code, "023801", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = NO; }
+                    if (strncmp(code, "023802", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = NO; }
+                    if (strncmp(code, "023803", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = NO; }
+                    if (strncmp(code, "023809", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_SLAC_init = NO; }
+                    if (strncmp(code, "023810", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_match_response = NO; }
+                    if (strncmp(code, "023811", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_sequence = NO; }
+                    if (strncmp(code, "023812", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_match_MNBC = NO; }
+                    if (strncmp(code, "023813", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = NO; }
+                    if (strncmp(code, "023814", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_response = NO; }
+                    if (strncmp(code, "023815", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_match_session = NO; }
+                    if (strncmp(code, "023816", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_assoc_session = NO; }
+                    if (strncmp(code, "023817", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_vald_toggle = NO; }
+                    if (strncmp(code, "023818", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = NO; }
+                    if (strncmp(code, "023819", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = NO; }
+                    if (strncmp(code, "023823", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsUDP_TT_match_join = NO; }
+                    if (strncmp(code, "023824", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTCP_TT_match_join = NO; }
+                    if (strncmp(code, "023825", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_amp_map_exchange = NO; }
+                    if (strncmp(code, "023826", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_link_ready_notification = NO; }
+                    if (strncmp(code, "023832", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSupportedAppProtocolRes = NO; }
+                    if (strncmp(code, "023833", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionSetupRes = NO; }
+                    if (strncmp(code, "023834", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceDiscoveryRes = NO; }
+                    if (strncmp(code, "023835", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServicePaymentSelectionRes = NO; }
+                    if (strncmp(code, "023836", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractAuthenticationRes = NO; }
+                    if (strncmp(code, "023837", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargeParameterDiscoveryRes = NO; }
+                    if (strncmp(code, "023838", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryRes = NO; }
+                    if (strncmp(code, "023839", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheckRes = NO; }
+                    if (strncmp(code, "023840", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPreChargeRes = NO; }
+                    if (strncmp(code, "023841", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCurrentDemandRes = NO; }
+                    if (strncmp(code, "023842", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsWeldingDetectionRes = NO; }
+                    if (strncmp(code, "023843", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionStopRes = NO; }
+                    if (strncmp(code, "023844", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequence_Time = NO; }
+                    if (strncmp(code, "023845", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsReadyToCharge_Performance_Time = NO; }
+                    if (strncmp(code, "023846", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCommunicationSetup_Performance_Time = NO; }
+                    if (strncmp(code, "023847", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheck_Performance_Time = NO; }
+                    if (strncmp(code, "023848", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPState_Detection_Time = NO; }
+                    if (strncmp(code, "023849", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPOscillator_Retain_Time = NO; }
+                    if (strncmp(code, "023850", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = NO; }
+                    if (strncmp(code, "023855", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = NO; }
+                    if (strncmp(code, "023856", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = NO; }
+                    if (strncmp(code, "023857", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = NO; }
+                    if (strncmp(code, "023858", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = NO; }
+                    if (strncmp(code, "023859", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EV_STOP_EVENT = NO; }
+                    if (strncmp(code, "023860", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EV_STOP_EVENT = NO; }
+                    if (strncmp(code, "023861", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = NO; }
+                    if (strncmp(code, "023862", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = NO; }
+                    if (strncmp(code, "023863", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_MISC_INFO = NO; }
+                    if (strncmp(code, "023864", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_MISC_INFO = NO; }
+                    if (strncmp(code, "023865", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = NO; }
+                    if (strncmp(code, "023866", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = NO; }
+                    if (strncmp(code, "023867", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = NO; }
+                    if (strncmp(code, "023868", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = NO; }
+                    if (strncmp(code, "023869", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DATA_TRANSFER = NO; }
+                    if (strncmp(code, "023870", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DATA_TRANSFER = NO; }
+                    if (strncmp(code, "023871", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = NO; }
+                    if (strncmp(code, "023872", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = NO; }
+                    if (strncmp(code, "023873", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_ISOLATION_STATUS = NO; }
+                    if (strncmp(code, "023874", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_ISOLATION_STATUS = NO; }
+                    if (strncmp(code, "023875", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_CONNECTOR_INFO = NO; }
+                    if (strncmp(code, "023876", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_CONNECTOR_INFO = NO; }
+                    if (strncmp(code, "023877", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_RTC_INFO = NO; }
+                    if (strncmp(code, "023878", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_RTC_INFO = NO; }
+                    if (strncmp(code, "023879", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = NO; }
+                    if (strncmp(code, "023880", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = NO; }
+                    if (strncmp(code, "023881", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMSG_Sequence = NO; }
+                    if (strncmp(code, "023882", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = NO; }
+                    if (strncmp(code, "023883", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Decode_Error = NO; }
+                    if (strncmp(code, "023884", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Encode_Error = NO; }
+                    if (strncmp(code, "023885", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Decode_Error = NO; }
+                    if (strncmp(code, "023886", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Encode_Error = NO; }
+                    if (strncmp(code, "023887", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Decode_Error = NO; }
+                    if (strncmp(code, "023888", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Encode_Error = NO; }
+                    if (strncmp(code, "023889", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCpStatus_Error = NO; }
+                    if (strncmp(code, "023890", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = NO; }
+                    if (strncmp(code, "023891", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccNotReadyForCharging = NO; }
+                    //if (strncmp(code, "023892", 6) == EQUAL) pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = NO;
+                    if (strncmp(code, "023893", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccFailForQCA7000SetKey = NO; }
+
+                    if (strncmp(code, "023979", 6) == EQUAL) { pInfoCode->InfoEvents.bits.EV_Full_Charging = NO; }
+                    if (strncmp(code, "023983", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason = NO; }
+                }
+            }
+        }
+    }
+}

+ 247 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalCHA.c

@@ -0,0 +1,247 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+void ClearAbnormalStatus_Chademo(uint8_t gun_index)
+{
+    bool isCleanCheck = false;
+    char code[7];
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
+        return;
+    }
+
+    if (true) {
+        if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023700", 6) == EQUAL &&
+                pInfoCode->InfoEvents.bits.ChademoEvCommFail == YES) {
+            memcpy(code, "023700", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023704", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryMalfun == YES) {
+            memcpy(code, "023704", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023705", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoNoPermission == YES) {
+            memcpy(code, "023705", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023706", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryIncompatibility == YES) {
+            memcpy(code, "023706", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023707", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryOVP == YES) {
+            memcpy(code, "023707", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023708", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryUVP == YES) {
+            memcpy(code, "023708", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023709", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryOTP == YES) {
+            memcpy(code, "023709", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023710", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryCurrentDiff == YES) {
+            memcpy(code, "023710", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023711", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryVoltageDiff == YES) {
+            memcpy(code, "023711", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023712", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoShiftPosition == YES) {
+            memcpy(code, "023712", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023713", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryOtherFault == YES) {
+            memcpy(code, "023713", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023714", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargingSystemError == YES) {
+            memcpy(code, "023714", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023715", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoEvNormalStop == YES) {
+            memcpy(code, "023715", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023716", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoTempSensorBroken == YES) {
+            memcpy(code, "023716", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023717", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoConnectorLockFail == YES) {
+            memcpy(code, "023717", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023718", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoD1OnNoReceive == YES) {
+            memcpy(code, "023718", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023719", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsKtoJTimeout == YES) {
+            memcpy(code, "023719", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023720", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsChargeAllowTimeout == YES) {
+            memcpy(code, "023720", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023721", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoWaitGfdTimeout == YES) {
+            memcpy(code, "023721", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023722", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsEvRelayTimeout == YES) {
+            memcpy(code, "023722", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023723", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsReqCurrentTimeout == YES) {
+            memcpy(code, "023723", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023724", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsKtoJOffTimeout == YES) {
+            memcpy(code, "023724", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023725", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsEvRelayOffTimeout == YES) {
+            memcpy(code, "023725", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023726", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoAdcMoreThan10V == YES) {
+            memcpy(code, "023726", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023727", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoAdcMoreThan20V == YES) {
+            memcpy(code, "023727", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023728", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsChargeBeforeStop == YES) {
+            memcpy(code, "023728", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023729", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargerGetNormalStop == YES) {
+            memcpy(code, "023729", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023730", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
+            memcpy(code, "023730", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023731", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoIsolationResultFail == YES) {
+            memcpy(code, "023731", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023732", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoMissLinkWithMotherBoard == YES) {
+            memcpy(code, "023732", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023733", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoOutputVolMoreThanLimit == YES) {
+            memcpy(code, "023733", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023734", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoReqCurrentMoreThanLimit == YES) {
+            memcpy(code, "023734", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023735", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed == YES) {
+            memcpy(code, "023735", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023736", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown == YES) {
+            memcpy(code, "023736", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+            if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                log_info("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
+                         index,
+                         pDcChargingInfo->EvConnAlarmCode,
+                         code);
+
+                if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+                    if (strncmp(code, "023700", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvCommFail = NO; }
+                    if (strncmp(code, "023704", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryMalfun = NO; }
+                    if (strncmp(code, "023705", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoNoPermission = NO; }
+                    if (strncmp(code, "023706", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryIncompatibility = NO; }
+                    if (strncmp(code, "023707", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOVP = NO; }
+                    if (strncmp(code, "023708", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryUVP = NO; }
+                    if (strncmp(code, "023709", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOTP = NO; }
+                    if (strncmp(code, "023710", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryCurrentDiff = NO; }
+                    if (strncmp(code, "023711", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryVoltageDiff = NO; }
+                    if (strncmp(code, "023712", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoShiftPosition = NO; }
+                    if (strncmp(code, "023713", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOtherFault = NO; }
+                    if (strncmp(code, "023714", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargingSystemError = NO; }
+                    if (strncmp(code, "023715", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvNormalStop = NO; }
+                    if (strncmp(code, "023716", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoTempSensorBroken = NO; }
+                    if (strncmp(code, "023717", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoConnectorLockFail = NO; }
+                    if (strncmp(code, "023718", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoD1OnNoReceive = NO; }
+                    if (strncmp(code, "023719", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJTimeout = NO; }
+                    if (strncmp(code, "023720", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeAllowTimeout = NO; }
+                    if (strncmp(code, "023721", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoWaitGfdTimeout = NO; }
+                    if (strncmp(code, "023722", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayTimeout = NO; }
+                    if (strncmp(code, "023723", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsReqCurrentTimeout = NO; }
+                    if (strncmp(code, "023724", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJOffTimeout = NO; }
+                    if (strncmp(code, "023725", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayOffTimeout = NO; }
+                    if (strncmp(code, "023726", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan10V = NO; }
+                    if (strncmp(code, "023727", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan20V = NO; }
+                    if (strncmp(code, "023728", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeBeforeStop = NO; }
+                    if (strncmp(code, "023729", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetNormalStop = NO; }
+                    if (strncmp(code, "023730", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = NO; }
+                    if (strncmp(code, "023731", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoIsolationResultFail = NO; }
+                    if (strncmp(code, "023732", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoMissLinkWithMotherBoard = NO; }
+                    if (strncmp(code, "023733", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoOutputVolMoreThanLimit = NO; }
+                    if (strncmp(code, "023734", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReqCurrentMoreThanLimit = NO; }
+                    if (strncmp(code, "023735", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = NO; }
+                    if (strncmp(code, "023736", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown = NO; }
+                }
+            }
+        }
+    }
+}

+ 415 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalGBT.c

@@ -0,0 +1,415 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+void ClearAbnormalStatus_GB(uint8_t gun_index)
+{
+    bool isCleanCheck = false;
+    char code[7];
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
+        return;
+    }
+
+    if (true) {
+        if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023702", 6) == EQUAL &&
+                pInfoCode->InfoEvents.bits.GbEvCommFail == YES) {
+            memcpy(code, "023702", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023900", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 == YES) {
+            memcpy(code, "023900", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023901", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL == YES) {
+            memcpy(code, "023901", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023902", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE == YES) {
+            memcpy(code, "023902", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023903", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT == YES) {
+            memcpy(code, "023903", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023904", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT == YES) {
+            memcpy(code, "023904", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023905", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT == YES) {
+            memcpy(code, "023905", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023906", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE == YES) {
+            memcpy(code, "023906", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023907", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE == YES) {
+            memcpy(code, "023907", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023908", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT == YES) {
+            memcpy(code, "023908", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023909", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V == YES) {
+            memcpy(code, "023909", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023910", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V == YES) {
+            memcpy(code, "023910", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023911", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD == YES) {
+            memcpy(code, "023911", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023912", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD == YES) {
+            memcpy(code, "023912", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023913", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL == YES) {
+            memcpy(code, "023913", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023914", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK == YES) {
+            memcpy(code, "023914", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023915", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT == YES) {
+            memcpy(code, "023915", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023916", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT == YES) {
+            memcpy(code, "023916", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023917", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT == YES) {
+            memcpy(code, "023917", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023918", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT == YES) {
+            memcpy(code, "023918", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023919", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V == YES) {
+            memcpy(code, "023919", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023930", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT == YES) {
+            memcpy(code, "023930", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023931", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT == YES) {
+            memcpy(code, "023931", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023932", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT == YES) {
+            memcpy(code, "023932", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023933", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT == YES) {
+            memcpy(code, "023933", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023934", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT == YES) {
+            memcpy(code, "023934", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023935", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT == YES) {
+            memcpy(code, "023935", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023936", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT == YES) {
+            memcpy(code, "023936", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023937", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT == YES) {
+            memcpy(code, "023937", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023938", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT == YES) {
+            memcpy(code, "023938", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023939", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT == YES) {
+            memcpy(code, "023939", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023940", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT == YES) {
+            memcpy(code, "023940", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023941", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT == YES) {
+            memcpy(code, "023941", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023942", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT == YES) {
+            memcpy(code, "023942", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023943", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT == YES) {
+            memcpy(code, "023943", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023944", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT == YES) {
+            memcpy(code, "023944", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023945", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT == YES) {
+            memcpy(code, "023945", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023946", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT == YES) {
+            memcpy(code, "023946", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023947", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT == YES) {
+            memcpy(code, "023947", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023950", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL == YES) {
+            memcpy(code, "023950", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023951", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL == YES) {
+            memcpy(code, "023951", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023952", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL == YES) {
+            memcpy(code, "023952", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023953", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_GET_CST == YES) {
+            memcpy(code, "023953", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023954", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_ISOLATION == YES) {
+            memcpy(code, "023954", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023955", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP == YES) {
+            memcpy(code, "023955", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023956", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_COMPONENT == YES) {
+            memcpy(code, "023956", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023957", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR == YES) {
+            memcpy(code, "023957", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023958", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTP == YES) {
+            memcpy(code, "023958", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023959", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTHER == YES) {
+            memcpy(code, "023959", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023960", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_HIGH_V == YES) {
+            memcpy(code, "023960", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023961", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CC2 == YES) {
+            memcpy(code, "023961", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023962", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CURRENT == YES) {
+            memcpy(code, "023962", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023963", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_VOLTAGE == YES) {
+            memcpy(code, "023963", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023964", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON == YES) {
+            memcpy(code, "023964", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023970", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE == YES) {
+            memcpy(code, "023970", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023971", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE == YES) {
+            memcpy(code, "023971", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023972", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC == YES) {
+            memcpy(code, "023972", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023973", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC == YES) {
+            memcpy(code, "023973", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023974", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CURRENT == YES) {
+            memcpy(code, "023974", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023975", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE == YES) {
+            memcpy(code, "023975", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023976", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_ISOLATE == YES) {
+            memcpy(code, "023976", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023977", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR == YES) {
+            memcpy(code, "023977", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+            if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                log_info("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
+                         index,
+                         pDcChargingInfo->EvConnAlarmCode,
+                         code);
+
+                if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+                    if (strncmp(code, "023702", 6) == EQUAL) { pInfoCode->InfoEvents.bits.GbEvCommFail = NO; }
+                    if (strncmp(code, "023900", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = NO; }
+                    if (strncmp(code, "023901", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = NO; }
+                    if (strncmp(code, "023902", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = NO; }
+                    if (strncmp(code, "023903", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = NO; }
+                    if (strncmp(code, "023904", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = NO; }
+                    if (strncmp(code, "023905", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = NO; }
+                    if (strncmp(code, "023906", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = NO; }
+                    if (strncmp(code, "023907", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = NO; }
+                    if (strncmp(code, "023908", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = NO; }
+                    if (strncmp(code, "023909", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = NO; }
+                    if (strncmp(code, "023910", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = NO; }
+                    if (strncmp(code, "023911", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = NO; }
+                    if (strncmp(code, "023912", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = NO; }
+                    if (strncmp(code, "023913", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = NO; }
+                    if (strncmp(code, "023914", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = NO; }
+                    if (strncmp(code, "023915", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = NO; }
+                    if (strncmp(code, "023916", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = NO; }
+                    if (strncmp(code, "023917", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = NO; }
+                    if (strncmp(code, "023918", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = NO; }
+                    if (strncmp(code, "023919", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = NO; }
+                    if (strncmp(code, "023930", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = NO; }
+                    if (strncmp(code, "023931", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = NO; }
+                    if (strncmp(code, "023932", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = NO; }
+                    if (strncmp(code, "023933", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = NO; }
+                    if (strncmp(code, "023934", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = NO; }
+                    if (strncmp(code, "023935", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = NO; }
+                    if (strncmp(code, "023936", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = NO; }
+                    if (strncmp(code, "023937", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = NO; }
+                    if (strncmp(code, "023938", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = NO; }
+                    if (strncmp(code, "023939", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = NO; }
+                    if (strncmp(code, "023940", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = NO; }
+                    if (strncmp(code, "023941", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = NO; }
+                    if (strncmp(code, "023942", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = NO; }
+                    if (strncmp(code, "023943", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = NO; }
+                    if (strncmp(code, "023944", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = NO; }
+                    if (strncmp(code, "023945", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = NO; }
+                    if (strncmp(code, "023946", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = NO; }
+                    if (strncmp(code, "023947", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = NO; }
+                    if (strncmp(code, "023950", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = NO; }
+                    if (strncmp(code, "023951", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = NO; }
+                    if (strncmp(code, "023952", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = NO; }
+                    if (strncmp(code, "023953", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_GET_CST = NO; }
+                    if (strncmp(code, "023954", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_ISOLATION = NO; }
+                    if (strncmp(code, "023955", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = NO; }
+                    if (strncmp(code, "023956", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_COMPONENT = NO; }
+                    if (strncmp(code, "023957", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = NO; }
+                    if (strncmp(code, "023958", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTP = NO; }
+                    if (strncmp(code, "023959", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTHER = NO; }
+                    if (strncmp(code, "023960", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_HIGH_V = NO; }
+                    if (strncmp(code, "023961", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CC2 = NO; }
+                    if (strncmp(code, "023962", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CURRENT = NO; }
+                    if (strncmp(code, "023963", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = NO; }
+                    if (strncmp(code, "023964", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = NO; }
+                    if (strncmp(code, "023970", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = NO; }
+                    if (strncmp(code, "023971", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = NO; }
+                    if (strncmp(code, "023972", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = NO; }
+                    if (strncmp(code, "023973", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = NO; }
+                    if (strncmp(code, "023974", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CURRENT = NO; }
+                    if (strncmp(code, "023975", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = NO; }
+                    if (strncmp(code, "023976", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = NO; }
+                    if (strncmp(code, "023977", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = NO; }
+                }
+            }
+        }
+    }
+}

+ 291 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/AbnormalState.c

@@ -0,0 +1,291 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
+{
+    char string[7];
+
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+
+    sprintf(string, "%d%d%d%d%d%d",
+            *(errCode + 0),
+            *(errCode + 1),
+            *(errCode + 2),
+            *(errCode + 3),
+            *(errCode + 4),
+            *(errCode + 5));
+    //iflog_info("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
+
+    if (strncmp(string, "000000", 6) == EQUAL ||
+            strncmp(string, "023979", 6) == EQUAL) {
+        return false;
+    }
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
+        return true;
+    }
+
+    memcpy(pDcChargingInfo->EvConnAlarmCode, string, 6);
+    log_info("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s\n", pDcChargingInfo->EvConnAlarmCode);
+    //OVP error
+    if (strcmp(string, "012217") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES; }
+    if (strcmp(string, "012219") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES; }
+    if (strcmp(string, "012221") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES; }
+
+    if (strcmp(string, "023700") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvCommFail = YES; }
+    if (strcmp(string, "023704") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryMalfun = YES; }
+    if (strcmp(string, "023705") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoNoPermission = YES; }
+    if (strcmp(string, "023706") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryIncompatibility = YES; }
+    if (strcmp(string, "023707") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOVP = YES; }
+    if (strcmp(string, "023708") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryUVP = YES; }
+    if (strcmp(string, "023709") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOTP = YES; }
+    if (strcmp(string, "023710") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryCurrentDiff = YES; }
+    if (strcmp(string, "023711") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryVoltageDiff = YES; }
+    if (strcmp(string, "023712") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoShiftPosition = YES; }
+    if (strcmp(string, "023713") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOtherFault = YES; }
+    if (strcmp(string, "023714") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargingSystemError = YES; }
+    if (strcmp(string, "023715") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvNormalStop = YES; }
+    if (strcmp(string, "023716") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoTempSensorBroken = YES; }
+    if (strcmp(string, "023717") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoConnectorLockFail = YES; }
+    if (strcmp(string, "023718") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoD1OnNoReceive = YES; }
+    if (strcmp(string, "023719") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJTimeout = YES; }
+    if (strcmp(string, "023720") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeAllowTimeout = YES; }
+    if (strcmp(string, "023721") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoWaitGfdTimeout = YES; }
+    if (strcmp(string, "023722") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayTimeout = YES; }
+    if (strcmp(string, "023723") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsReqCurrentTimeout = YES; }
+    if (strcmp(string, "023724") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJOffTimeout = YES; }
+    if (strcmp(string, "023725") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayOffTimeout = YES; }
+    if (strcmp(string, "023726") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan10V = YES; }
+    if (strcmp(string, "023727") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan20V = YES; }
+    if (strcmp(string, "023728") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeBeforeStop = YES; }
+    if (strcmp(string, "023729") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetNormalStop = YES; }
+    if (strcmp(string, "023730") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = YES; }
+    if (strcmp(string, "023731") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoIsolationResultFail = YES; }
+    if (strcmp(string, "023732") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoMissLinkWithMotherBoard = YES; }
+    if (strcmp(string, "023733") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoOutputVolMoreThanLimit = YES; }
+    if (strcmp(string, "023734") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReqCurrentMoreThanLimit = YES; }
+    if (strcmp(string, "023735") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = YES; }
+    if (strcmp(string, "023736") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown = YES; }
+
+    if (strcmp(string, "012288") == EQUAL) { pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES; }
+
+    if (strcmp(string, "023701") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = YES; }
+    if (strcmp(string, "023737") == EQUAL) { pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit = YES; }
+    if (strcmp(string, "023738") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVShiftPosition = YES; }
+    if (strcmp(string, "023739") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargerConnectorLockFault = YES; }
+    if (strcmp(string, "023740") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVRESSMalfunction = YES; }
+    if (strcmp(string, "023741") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingCurrentdifferential = YES; }
+    if (strcmp(string, "023742") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingVoltageOutOfRange = YES; }
+    if (strcmp(string, "023743") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingSystemIncompatibility = YES; }
+    if (strcmp(string, "023744") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEmergencyEvent = YES; }
+    if (strcmp(string, "023745") == EQUAL) { pInfoCode->InfoEvents.bits.CcsBreaker = YES; }
+    if (strcmp(string, "023746") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoData = YES; }
+    if (strcmp(string, "023747") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_A = YES; }
+    if (strcmp(string, "023748") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_B = YES; }
+    if (strcmp(string, "023749") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_C = YES; }
+    if (strcmp(string, "023750") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_1 = YES; }
+    if (strcmp(string, "023751") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_2 = YES; }
+    if (strcmp(string, "023752") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_3 = YES; }
+    if (strcmp(string, "023753") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_1 = YES; }
+    if (strcmp(string, "023754") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_2 = YES; }
+    if (strcmp(string, "023755") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_3 = YES; }
+    if (strcmp(string, "023756") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_4 = YES; }
+    if (strcmp(string, "023757") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_5 = YES; }
+    if (strcmp(string, "023758") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequenceError = YES; }
+    if (strcmp(string, "023759") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSignatureError = YES; }
+    if (strcmp(string, "023760") == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnknownSession = YES; }
+    if (strcmp(string, "023761") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceIDInvalid = YES; }
+    if (strcmp(string, "023762") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPaymentSelectionInvalid = YES; }
+    if (strcmp(string, "023763") == EQUAL) { pInfoCode->InfoEvents.bits.CcsIdentificationSelectionInvalid = YES; }
+    if (strcmp(string, "023764") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceSelectionInvalid = YES; }
+    if (strcmp(string, "023765") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateExpired = YES; }
+    if (strcmp(string, "023766") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotYetValid = YES; }
+    if (strcmp(string, "023767") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateRevoked = YES; }
+    if (strcmp(string, "023768") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoCertificateAvailable = YES; }
+    if (strcmp(string, "023769") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertChainError = YES; }
+    if (strcmp(string, "023770") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertValidationError = YES; }
+    if (strcmp(string, "023771") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertVerificationError = YES; }
+    if (strcmp(string, "023772") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractCanceled = YES; }
+    if (strcmp(string, "023773") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChallengeInvalid = YES; }
+    if (strcmp(string, "023774") == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongEnergyTransferMode = YES; }
+    if (strcmp(string, "023775") == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongChargeParameter = YES; }
+    if (strcmp(string, "023776") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingProfileInvalid = YES; }
+    if (strcmp(string, "023777") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTariffSelectionInvalid = YES; }
+    if (strcmp(string, "023778") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEPresentVoltageToLow = YES; }
+    if (strcmp(string, "023779") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryNotApplied = YES; }
+    if (strcmp(string, "023780") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMeteringSignatureNotValid = YES; }
+    if (strcmp(string, "023781") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoChargeServiceSelected = YES; }
+    if (strcmp(string, "023782") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContactorError = YES; }
+    if (strcmp(string, "023783") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = YES; }
+    if (strcmp(string, "023784") == EQUAL) { pInfoCode->InfoEvents.bits.CcsGAChargeStop = YES; }
+    if (strcmp(string, "023785") == EQUAL) { pInfoCode->InfoEvents.bits.CcsAlignmentError = YES; }
+    if (strcmp(string, "023786") == EQUAL) { pInfoCode->InfoEvents.bits.CcsACDError = YES; }
+    if (strcmp(string, "023787") == EQUAL) { pInfoCode->InfoEvents.bits.CcsAssociationError = YES; }
+    if (strcmp(string, "023788") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEChargeAbort = YES; }
+    if (strcmp(string, "023789") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoSupportedAppProtocol = YES; }
+    if (strcmp(string, "023790") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractNotAccepted = YES; }
+    if (strcmp(string, "023791") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMOUnknown = YES; }
+    if (strcmp(string, "023792") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = YES; }
+    if (strcmp(string, "023793") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = YES; }
+    if (strcmp(string, "023794") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = YES; }
+    if (strcmp(string, "023795") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = YES; }
+    if (strcmp(string, "023796") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_Prov_CertificateRevoked = YES; }
+    if (strcmp(string, "023797") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = YES; }
+    if (strcmp(string, "023798") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = YES; }
+    if (strcmp(string, "023799") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = YES; }
+    if (strcmp(string, "023800") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = YES; }
+    if (strcmp(string, "023801") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = YES; }
+    if (strcmp(string, "023802") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = YES; }
+    if (strcmp(string, "023803") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = YES; }
+    if (strcmp(string, "023809") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_SLAC_init = YES; }
+    if (strcmp(string, "023810") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_match_response = YES; }
+    if (strcmp(string, "023811") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_sequence = YES; }
+    if (strcmp(string, "023812") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_match_MNBC = YES; }
+    if (strcmp(string, "023813") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = YES; }
+    if (strcmp(string, "023814") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_response = YES; }
+    if (strcmp(string, "023815") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_match_session = YES; }
+    if (strcmp(string, "023816") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_assoc_session = YES; }
+    if (strcmp(string, "023817") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_vald_toggle = YES; }
+    if (strcmp(string, "023818") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = YES; }
+    if (strcmp(string, "023819") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = YES; }
+    if (strcmp(string, "023823") == EQUAL) { pInfoCode->InfoEvents.bits.CcsUDP_TT_match_join = YES; }
+    if (strcmp(string, "023824") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTCP_TT_match_join = YES; }
+    if (strcmp(string, "023825") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_amp_map_exchange = YES; }
+    if (strcmp(string, "023826") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_link_ready_notification = YES; }
+    if (strcmp(string, "023832") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSupportedAppProtocolRes = YES; }
+    if (strcmp(string, "023833") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionSetupRes = YES; }
+    if (strcmp(string, "023834") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceDiscoveryRes = YES; }
+    if (strcmp(string, "023835") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServicePaymentSelectionRes = YES; }
+    if (strcmp(string, "023836") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractAuthenticationRes = YES; }
+    if (strcmp(string, "023837") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargeParameterDiscoveryRes = YES; }
+    if (strcmp(string, "023838") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryRes = YES; }
+    if (strcmp(string, "023839") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheckRes = YES; }
+    if (strcmp(string, "023840") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPreChargeRes = YES; }
+    if (strcmp(string, "023841") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCurrentDemandRes = YES; }
+    if (strcmp(string, "023842") == EQUAL) { pInfoCode->InfoEvents.bits.CcsWeldingDetectionRes = YES; }
+    if (strcmp(string, "023843") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionStopRes = YES; }
+    if (strcmp(string, "023844") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequence_Time = YES; }
+    if (strcmp(string, "023845") == EQUAL) { pInfoCode->InfoEvents.bits.CcsReadyToCharge_Performance_Time = YES; }
+    if (strcmp(string, "023846") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCommunicationSetup_Performance_Time = YES; }
+    if (strcmp(string, "023847") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheck_Performance_Time = YES; }
+    if (strcmp(string, "023848") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPState_Detection_Time = YES; }
+    if (strcmp(string, "023849") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPOscillator_Retain_Time = YES; }
+    if (strcmp(string, "023850") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = YES; }
+    if (strcmp(string, "023855") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = YES; }
+    if (strcmp(string, "023856") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = YES; }
+    if (strcmp(string, "023857") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = YES; }
+    if (strcmp(string, "023858") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = YES; }
+    if (strcmp(string, "023859") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EV_STOP_EVENT = YES; }
+    if (strcmp(string, "023860") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EV_STOP_EVENT = YES; }
+    if (strcmp(string, "023861") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = YES; }
+    if (strcmp(string, "023862") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = YES; }
+    if (strcmp(string, "023863") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_MISC_INFO = YES; }
+    if (strcmp(string, "023864") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_MISC_INFO = YES; }
+    if (strcmp(string, "023865") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = YES; }
+    if (strcmp(string, "023866") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = YES; }
+    if (strcmp(string, "023867") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = YES; }
+    if (strcmp(string, "023868") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = YES; }
+    if (strcmp(string, "023869") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DATA_TRANSFER = YES; }
+    if (strcmp(string, "023870") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DATA_TRANSFER = YES; }
+    if (strcmp(string, "023871") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = YES; }
+    if (strcmp(string, "023872") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = YES; }
+    if (strcmp(string, "023873") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_ISOLATION_STATUS = YES; }
+    if (strcmp(string, "023874") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_ISOLATION_STATUS = YES; }
+    if (strcmp(string, "023875") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_CONNECTOR_INFO = YES; }
+    if (strcmp(string, "023876") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_CONNECTOR_INFO = YES; }
+    if (strcmp(string, "023877") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_RTC_INFO = YES; }
+    if (strcmp(string, "023878") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_RTC_INFO = YES; }
+    if (strcmp(string, "023879") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = YES; }
+    if (strcmp(string, "023880") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = YES; }
+    if (strcmp(string, "023881") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMSG_Sequence = YES; }
+    if (strcmp(string, "023882") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = YES; }
+    if (strcmp(string, "023883") == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Decode_Error = YES; }
+    if (strcmp(string, "023884") == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Encode_Error = YES; }
+    if (strcmp(string, "023885") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Decode_Error = YES; }
+    if (strcmp(string, "023886") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Encode_Error = YES; }
+    if (strcmp(string, "023887") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Decode_Error = YES; }
+    if (strcmp(string, "023888") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Encode_Error = YES; }
+    if (strcmp(string, "023889") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCpStatus_Error = YES; }
+    if (strcmp(string, "023890") == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = YES; }
+    if (strcmp(string, "023891") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccNotReadyForCharging = YES; }
+    if (strcmp(string, "023892") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = YES; }
+    if (strcmp(string, "023893") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccFailForQCA7000SetKey = YES; }
+
+    if (strcmp(string, "023702") == EQUAL) { pInfoCode->InfoEvents.bits.GbEvCommFail = YES; }
+    if (strcmp(string, "023900") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = YES; }
+    if (strcmp(string, "023901") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = YES; }
+    if (strcmp(string, "023902") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = YES; }
+    if (strcmp(string, "023903") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = YES; }
+    if (strcmp(string, "023904") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = YES; }
+    if (strcmp(string, "023905") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = YES; }
+    if (strcmp(string, "023906") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = YES; }
+    if (strcmp(string, "023907") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = YES; }
+    if (strcmp(string, "023908") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = YES; }
+    if (strcmp(string, "023909") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = YES; }
+    if (strcmp(string, "023910") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = YES; }
+    if (strcmp(string, "023911") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = YES; }
+    if (strcmp(string, "023912") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = YES; }
+    if (strcmp(string, "023913") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = YES; }
+    if (strcmp(string, "023914") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = YES; }
+    if (strcmp(string, "023915") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = YES; }
+    if (strcmp(string, "023916") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = YES; }
+    if (strcmp(string, "023917") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = YES; }
+    if (strcmp(string, "023918") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = YES; }
+    if (strcmp(string, "023919") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = YES; }
+    if (strcmp(string, "023930") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = YES; }
+    if (strcmp(string, "023931") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = YES; }
+    if (strcmp(string, "023932") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = YES; }
+    if (strcmp(string, "023933") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = YES; }
+    if (strcmp(string, "023934") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = YES; }
+    if (strcmp(string, "023935") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = YES; }
+    if (strcmp(string, "023936") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = YES; }
+    if (strcmp(string, "023937") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = YES; }
+    if (strcmp(string, "023938") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = YES; }
+    if (strcmp(string, "023939") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = YES; }
+    if (strcmp(string, "023940") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = YES; }
+    if (strcmp(string, "023941") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = YES; }
+    if (strcmp(string, "023942") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = YES; }
+    if (strcmp(string, "023943") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = YES; }
+    if (strcmp(string, "023944") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = YES; }
+    if (strcmp(string, "023945") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = YES; }
+    if (strcmp(string, "023946") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = YES; }
+    if (strcmp(string, "023947") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = YES; }
+    if (strcmp(string, "023950") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = YES; }
+    if (strcmp(string, "023951") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = YES; }
+    if (strcmp(string, "023952") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = YES; }
+    if (strcmp(string, "023953") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_GET_CST = YES; }
+    if (strcmp(string, "023954") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_ISOLATION = YES; }
+    if (strcmp(string, "023955") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = YES; }
+    if (strcmp(string, "023956") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_COMPONENT = YES; }
+    if (strcmp(string, "023957") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = YES; }
+    if (strcmp(string, "023958") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTP = YES; }
+    if (strcmp(string, "023959") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTHER = YES; }
+    if (strcmp(string, "023960") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_HIGH_V = YES; }
+    if (strcmp(string, "023961") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CC2 = YES; }
+    if (strcmp(string, "023962") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CURRENT = YES; }
+    if (strcmp(string, "023963") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = YES; }
+    if (strcmp(string, "023964") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = YES; }
+    if (strcmp(string, "023970") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = YES; }
+    if (strcmp(string, "023971") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = YES; }
+    if (strcmp(string, "023972") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = YES; }
+    if (strcmp(string, "023973") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = YES; }
+    if (strcmp(string, "023974") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CURRENT = YES; }
+    if (strcmp(string, "023975") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = YES; }
+    if (strcmp(string, "023976") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = YES; }
+    if (strcmp(string, "023977") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = YES; }
+
+    if (strcmp(string, "023979") == EQUAL) { pInfoCode->InfoEvents.bits.EV_Full_Charging = YES; }
+    if (strcmp(string, "023983") == EQUAL) { pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason = YES; }
+
+    return true;
+}

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

@@ -32,6 +32,7 @@
 #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)

+ 44 - 16
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.c

@@ -255,10 +255,11 @@ int InitShareMemory()
 //================================================
 int InitCanBus()
 {
-    int                     s0, nbytes;
-    struct timeval          tv;
-    struct ifreq            ifr0;
-    struct sockaddr_can     addr0;
+    int s0, nbytes;
+    struct timeval tv;
+    struct ifreq ifr0;
+    struct sockaddr_can addr0;
+    struct can_filter rxfilter[3];
 
     system("/sbin/ip link set can0 down");
     system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
@@ -268,17 +269,20 @@ int InitCanBus()
 
     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
@@ -286,11 +290,23 @@ int InitCanBus()
 #endif
     }
 
+    rxfilter[0].can_id = 0x01;
+    rxfilter[0].can_mask = 0x000000FF;
+    rxfilter[1].can_id = 0x02;
+    rxfilter[1].can_mask = 0x000000FF;
+    rxfilter[2].can_id = 0x01FF;
+    rxfilter[2].can_mask = 0x00000FFF;
+    if (setsockopt(s0, SOL_CAN_RAW, CAN_RAW_FILTER,
+                   &rxfilter, sizeof(struct can_filter) * 3) < 0) {
+        log_error("RX setsockopt CAN_RAW_FILTER failed");
+    }
+
     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;
 }
 
@@ -2211,29 +2227,26 @@ static float ReadAdcVolt(uint8_t AdcChannel)
     //AIN2=CCS_Proximity/2
     //AIN3=pilot voltage
     int fd = -1;
-    uint8_t str[64];
-    uint8_t AdcValue[4];
+    uint8_t str[64] = {0};
+    uint8_t AdcValue[4] = {0};
 
     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;
+    return (1.8 * atoi((int)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;
@@ -2325,7 +2338,7 @@ void CANReceiver()
                 intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
 
                 target = ((uint8_t) (frame.can_id & 0x000000FF));      // 0x01 or 0x02
-
+                //log_info("target id = %d\r\n", target);
                 for (uint8_t _index = 0; _index < gun_count; _index++) {                    // 假設有找到回應的 Index
                     if (_chargingData[_index]->Evboard_id == target) {
                         targetGun = _index;
@@ -2516,35 +2529,50 @@ void CANReceiver()
                         //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
                     }
                     }*/
-
+#if 1
                     //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]);
+
+                        //log_info("%d chiller Temp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                        //         targetGun,
+                        //         chiilerTemp.Temp[0],
+                        //         chiilerTemp.Temp[1],
+                        //         frame.data[1],
+                        //         frame.data[2]);
                     } else if (targetGun == 1 &&
                                ((strncmp((char *)&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]);
+
+                        //log_info("%d chillerTemp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                        //         targetGun,
+                        //         chiilerTemp.Temp[0],
+                        //         chiilerTemp.Temp[1],
+                        //         frame.data[1],
+                        //         frame.data[2]);
                     } else {
                         _chargingData[targetGun]->ConnectorTemp = returnConnectTemp(frame.data[1], frame.data[2]);
-                        //log_info("connector temperature = %d\r\n", _chargingData[targetGun]->ConnectorTemp);
+                        //log_info("connector temperature = %d\r\n",
+                        //         _chargingData[targetGun]->ConnectorTemp);
                     }
-
+#endif //0
                     //log_info("EvboardStatus = %x \n",
                     //         ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus);
                     //log_info("ConnectorPlug locked = %x \n",

+ 7 - 5
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvComm.h

@@ -5,11 +5,11 @@
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
-#define COMMUNICATION       2
-#define CHK_VOL_RANGE       50
-#define CHK_CUR_RANGE       20
-#define PLUG                1
-#define UNPLUG              0
+#define COMMUNICATION                           (2)
+#define CHK_VOL_RANGE                           (50)
+#define CHK_CUR_RANGE                           (20)
+#define PLUG                                    (1)
+#define UNPLUG                                  (0)
 
 //------------------------------------------------------------------------------
 //DS60-120 add
@@ -33,6 +33,8 @@ typedef struct StChiilerTemp {
 
 //------------------------------------------------------------------------------
 int GetCanFd(void);
+float GetMaxChargingVol(uint8_t index);
+float GetMaxCharginigCur(uint8_t index);
 
 #endif /* MODULE_EVCOMM_H_ */
 

+ 553 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -0,0 +1,553 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+#include "Ev_Comm.h"
+#include "Module_EvComm.h"
+
+//------------------------------------------------------------------------------
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+static struct WARNING_CODE_INFO *pSysWarning = NULL;
+static struct AlarmCodeData *pAlarmCode = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct CcsData *ShmCcsData = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
+
+//------------------------------------------------------------------------------
+extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
+
+//------------------------------------------------------------------------------
+static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
+        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;
+    }
+
+    //先取得第一個非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 getMaxConnectTemp(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((int)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)
+    }
+}
+
+
+static void AddrAssignment(uint8_t *data)
+{
+    uint8_t target_number[8];
+    uint8_t index = 0x00;
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+
+    memcpy(target_number, data, sizeof(target_number));
+    index = *(data + 4);
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        index = 0x01;
+    }
+
+    //if (CheckUniqNumber(index)) {
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index - 1);
+    //DS60-120 add
+    if (pDcChargingInfo->Type == _Type_Chademo) {
+        log_info("Set EV board info : (Chademo) TargetAddr = %d \n", index);
+    } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+        log_info("Set EV board info : (CCS) TargetAddr = %d \n", index);
+    } else if (pDcChargingInfo->Type == _Type_GB) {
+        log_info("Set EV board info : (GB) TargetAddr = %d \n", index);
+    }
+    //log_info("EV board id = %x \n", index); //DS60-120 remove
+
+    //log_info("target_number[0] = %x \n", target_number[0]);
+    //log_info("target_number[1] = %x \n", target_number[1]);
+    //log_info("target_number[2] = %x \n", target_number[2]);
+    //log_info("target_number[3] = %x \n", target_number[3]);
+    //log_info("target_number[4] = %x \n", target_number[4]);
+
+    log_info("SetTargetAddr = %d, type = %d \n", index, pDcChargingInfo->Type);
+    SetTargetAddr(target_number, index);
+    //}
+}
+
+
+void CANReceiver(int fd)
+{
+    pid_t canRecPid;
+
+    canRecPid = fork();
+
+    if (canRecPid == 0) {
+        int isContinue = 1;
+        int nbytes;
+        int intCmd;
+        uint8_t _index = 0;
+        uint8_t recvID = 0;
+        uint8_t targetGun = 0x00;
+        uint8_t gunTypeIndex = 0;
+        uint8_t ver[16] = {0};
+        struct can_frame frame;
+        ChillerTemp chiilerTemp = {0};
+        struct ChargingInfoData *pDcChargingInfo = NULL;
+
+        pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+        pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+        pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+        pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+        ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
+        ShmGBTData = (struct GBTData *)GetShmGBTData();
+        ShmCcsData = (struct CcsData *)GetShmCcsData();
+        ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonInfo();
+
+        while (isContinue) {
+            memset(&frame, 0, sizeof(struct can_frame));
+            nbytes = read(fd, &frame, sizeof(struct can_frame));
+            if (nbytes <= 0) {
+                usleep(10000);
+                continue;
+            }
+
+            recvID = 0;
+            targetGun = 0x00;
+            intCmd = (int) (frame.can_id & CAN_EFF_MASK);
+
+            if (intCmd == ADDRESS_REQ) {
+                //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
+                AddrAssignment(frame.data);
+                continue;
+            }
+
+            intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
+
+            recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
+
+            for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {                    // 假設有找到回應的 Index
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+                //if (gun_count == 1 &&
+                //        _chargingData[_index]->Type == _Type_CCS_2 &&
+                //        ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+                //    target -= 1;
+                //}
+
+                if (pDcChargingInfo->Evboard_id == recvID) {
+                    targetGun = _index;
+                    break;
+                }
+            }
+
+            if (targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) {
+                log_info("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
+                usleep(10000);
+                continue;
+            }
+            //else if (gun_count == 1 && targetGun == 0 && findIndex == 1 &&
+            //           ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+            //    // 這樣的條件下~ 也是單槍 CCS 舊版本的狀況 : 因為舊版 CCS 不會 timeout, then send request id
+            //    ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
+            //}
+
+            if (intCmd == 256) {
+                log_info("EvComm command = 256");
+                usleep(10000);
+                continue;
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
+            gunTypeIndex = pDcChargingInfo->type_index;
+            //log_info("intCmd = %x\r\n", intCmd);
+            switch (intCmd) {
+            case NOTIFICATION_EV_STATUS:
+                if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
+                    if (frame.data[0] == PLUG) {
+                        log_info("Conn %d, Plugin. \n", targetGun);
+                    } else if (frame.data[0] == UNPLUG) {
+                        log_info("Conn %d, Unplug. \n", targetGun);
+                    } else {
+                        log_info("Conn %d, None Check. (%d) \n", targetGun, frame.data[0]);
+                    }
+                }
+
+                pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                pDcChargingInfo->PilotVoltage = frame.data[1];
+
+                //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x \n",
+                //         targetGun,
+                //         pDcChargingInfo->ConnectorPlugIn,
+                //         frame.data[0]);
+
+                //log_info("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
+                break;
+
+            case ACK_EV_FW_VERSION:
+                memset(ver, 0, sizeof(ver));
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+                    memcpy(ver, frame.data, frame.can_dlc);
+                    memcpy(ShmCHAdeMOData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
+                    ShmCHAdeMOData->evse[gunTypeIndex].SelfTest_Comp = PASS;
+                    //log_info("chademo ver. : %s\n", ShmCHAdeMOData->evse[gunTypeIndex].version);
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    memcpy(ver, frame.data, frame.can_dlc);
+                    memcpy(ShmGBTData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
+                    ShmGBTData->evse[gunTypeIndex].SelfTest_Comp = PASS;
+                    //log_info("gbt ver. : %s\n", ShmGBTData->evse[gunTypeIndex].version);
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                        memcpy(ver, frame.data, frame.can_dlc); //DS60-120 add
+
+                        //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;
+                            _vPoint++;
+                        }*/
+
+                        //ver[_vCount + _vPoint] = frame.data[_vCount];
+                        //}
+
+                        memcpy(&ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
+                        ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].SelfTest_Comp = PASS;
+                        //log_info("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version);
+                    }
+                }
+
+                if (targetGun == 0) {
+                    memset(pSysInfo->Connector1FwRev,
+                           0,
+                           sizeof(pSysInfo->Connector1FwRev));
+                    memcpy(pSysInfo->Connector1FwRev, ver, ARRAY_SIZE(ver));
+                } else if (targetGun == 1) {
+                    memset(pSysInfo->Connector2FwRev,
+                           0,
+                           sizeof(pSysInfo->Connector2FwRev));
+                    memcpy(pSysInfo->Connector2FwRev, ver, ARRAY_SIZE(ver));
+                }
+                break;
+
+            case ACK_EV_HW_VERSION:
+                //log_info("Get EV HW = %s \n", frame.data);
+                break;
+
+            case ACK_GET_OUTPUT_REQ:
+                //DS60-120 add
+                if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
+                        pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+                        (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                    if (pDcChargingInfo->EvBatteryStartSoc <= 0) {
+                        pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
+                    }
+
+                    if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
+                        pDcChargingInfo->EvBatterySoc = frame.data[1];
+                    }
+                }
+                //pDcChargingInfo->EvBatterySoc = frame.data[1]; //DS60-120 remove
+
+                //Jerry add set voltage limit
+                pDcChargingInfo->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
+                if (pDcChargingInfo->EvBatterytargetVoltage > (GetMaxChargingVol(targetGun) * 0.1)) {
+                    pDcChargingInfo->EvBatterytargetVoltage = (GetMaxChargingVol(targetGun) * 0.1);
+                }
+                //printf("id = %d, EvBatterytargetVoltage = %.2f\r\n", targetGun, pDcChargingInfo->EvBatterytargetVoltage);
+
+                //Jerry add set currency limit
+                pDcChargingInfo->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
+                if (pDcChargingInfo->EvBatterytargetCurrent > (GetMaxCharginigCur(targetGun) * 0.1)) {
+                    pDcChargingInfo->EvBatterytargetCurrent = (GetMaxCharginigCur(targetGun) * 0.1);
+                }
+                //printf("id = %d, EvBatterytargetCurrent = %.2f\r\n", targetGun, pDcChargingInfo->EvBatterytargetCurrent);
+
+                pDcChargingInfo->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
+                //printf("RemainChargingDuration = %d\r\n",  pDcChargingInfo->RemainChargingDuration);
+
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+                    //if (ShmCHAdeMOData->ev[gunTypeIndex].EvDetection != frame.data[0])
+                    {
+                        ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
+                    }
+
+                    ShmCHAdeMOData->ev[gunTypeIndex].EvDetection = frame.data[0];
+                    ShmCHAdeMOData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
+                    ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
+                    ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    //if (ShmGBTData->ev[gunTypeIndex].EvDetection != frame.data[0])
+                    {
+                        ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
+                    }
+
+                    ShmGBTData->ev[gunTypeIndex].EvDetection = frame.data[0];
+                    ShmGBTData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
+                    ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
+                    ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                        ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
+                    }
+                }
+
+                //log_info("EvBatterytargetVoltage = %f \n", pDcChargingInfo->EvBatterytargetVoltage);
+                //log_info("EvBatterytargetCurrent = %f \n", pDcChargingInfo->EvBatterytargetCurrent);
+                //log_info("BatteryVoltage = %d \n",
+                //         ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
+                //log_info("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];
+                pDcChargingInfo->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 (pDcChargingInfo->Type == _Type_Chademo) {
+                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
+
+                    //log_info("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
+                    //log_info("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
+                    //log_info("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
+                }
+                //else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                //}
+                break;
+
+            case ACK_GET_MISCELLANEOUS_INFO:
+                pDcChargingInfo->GunLocked = frame.data[0];
+                pDcChargingInfo->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+                    ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
+                    ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
+                    ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
+                    ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
+                    ShmGBTData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
+                }
+                /*else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                    //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureP = frame.data[1];
+                    //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureN = frame.data[2];
+                }
+                }*/
+#if 1
+                //memset((uint8_t)&chiilerTemp, 0, sizeof(ChillerTemp));
+                if (targetGun == 0 &&
+                        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+                   ) {
+                    getChillerTemperature(&chiilerTemp);
+
+                    pDcChargingInfo->ConnectorTemp = getMaxConnectTempAndChiller(
+                                                         frame.data[1],
+                                                         frame.data[2],
+                                                         chiilerTemp.Temp[0],
+                                                         chiilerTemp.Temp[1]);
+
+                    //log_info("%d chiller Temp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                    //         targetGun,
+                    //         chiilerTemp.Temp[0],
+                    //         chiilerTemp.Temp[1],
+                    //         frame.data[1],
+                    //         frame.data[2]);
+                } else if (targetGun == 1 &&
+                           ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                          ) {
+                    getChillerTemperature(&chiilerTemp);
+
+                    pDcChargingInfo->ConnectorTemp = getMaxConnectTempAndChiller(
+                                                         frame.data[1],
+                                                         frame.data[2],
+                                                         chiilerTemp.Temp[0],
+                                                         chiilerTemp.Temp[1]);
+
+                    //log_info("%d chillerTemp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                    //         targetGun,
+                    //         chiilerTemp.Temp[0],
+                    //         chiilerTemp.Temp[1],
+                    //         frame.data[1],
+                    //         frame.data[2]);
+                } else {
+                    pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
+                    //log_info("connector temperature = %d\r\n",
+                    //         pDcChargingInfo->ConnectorTemp);
+                }
+#endif //0
+                //log_info("EvboardStatus = %x \n",
+                //         ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
+                //log_info("ConnectorPlug locked = %x \n",
+                //         frame.data[0]);
+
+                //if (frame.data[1] >= GUN_OTP_VALUE ||
+                //        frame.data[2] >= GUN_OTP_VALUE ||
+                //        chiilerTemp.Temp[0] >= GUN_OTP_VALUE ||
+                //        chiilerTemp.Temp[1] >= GUN_OTP_VALUE) {
+                //    log_info("Conn %d Temp 0= %d, Temp 1 = %d, chillerTemp1 = %d, chillerTemp2 = %d\r\n",
+                //             targetGun,
+                //             frame.data[1],
+                //             frame.data[2],
+                //             chiilerTemp.Temp[0],
+                //             chiilerTemp.Temp[1]);
+                //}
+                //log_info("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
+                break;
+
+            case ACK_EVSE_ISOLATION_STATUS:
+                break;
+
+            case ACK_EVSE_PRECHAGE_INFO:
+                pDcChargingInfo->PrechargeStatus = frame.data[0];
+                break;
+
+            case NOTIFICATION_EV_STOP:
+                // 車端要求停止
+                if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && //DS60-120 add
+                        pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
+                        (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                    // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
+                    log_info("(%d) NOTIFICATION_EV_STOP err level = %d-----------------------------\n",
+                             targetGun,
+                             frame.data[0]);
+                    if (frame.data[0] == 0x02) {
+                        if (AbnormalStopAnalysis(targetGun, frame.data + 1) == true) {
+                            pDcChargingInfo->StopChargeFlag = YES;
+                        } else {
+                            pDcChargingInfo->NormalStopChargeFlag = YES;
+                        }
+                    } else {
+                        AbnormalStopAnalysis(targetGun, frame.data + 1);
+                        pDcChargingInfo->NormalStopChargeFlag = YES;
+                    }
+                }
+                break;
+
+            default:
+                log_info("EV board = %d, Ack none defined. intCmd = %d  \n", targetGun, intCmd);
+                break;
+            }//switch
+
+            usleep(10000);
+        }//while
+    }
+}

+ 1014 - 0
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -0,0 +1,1014 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/timeb.h>
+#include <sys/time.h>
+
+#include <net/if.h>
+
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+#include "Ev_Comm.h"
+#include "Module_EvComm.h"
+
+//------------------------------------------------------------------------------
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+
+static struct FaultCodeData *pFaultCode = NULL;
+static struct AlarmCodeData *pAlarmCode = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct CcsData *ShmCcsData = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
+
+// 限制最大充電電壓,因應不同 type 槍線來限制
+// Chademo : 500V, 125A,
+// GB : 750, 120A
+// CCS : 950V, 120A
+//DS60-120 add
+//static double chademoVol = 5000;
+//static double ccsVol = 9500;
+//static double gbVol = 7500;
+static float maxChargingVol[2] = { 0, 0 };       // 限制最大充電電壓,如依照模塊則填上 0
+// 限制最大充電電流與能量透過 Web
+static float maxChargingCur[2] = { 0, 0 };         // 限制最大充電電流,如依照模塊則填上 0
+static float maxChargingPow = 0;                   // 限制最大充電能量,如依照模塊則填上 0
+
+static float LogInfo[2][10]; //DS60-120 add
+static int CanFd = -1;
+
+//------------------------------------------------------------------------------
+extern void CANReceiver(int fd);
+extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
+extern void ClearAbnormalStatus_GB(uint8_t gun_index);
+extern void ClearAbnormalStatus_CCS(uint8_t gun_index);
+
+//------------------------------------------------------------------------------
+int GetCanFd(void)
+{
+    return CanFd;
+}
+
+uint32_t 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 InitCanBus(void)
+{
+    int s0, nbytes;
+    struct timeval tv;
+    struct ifreq ifr0;
+    struct sockaddr_can addr0;
+    struct can_filter rxfilter[3];
+
+    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
+    }
+
+    rxfilter[0].can_id = 0x01;
+    rxfilter[0].can_mask = 0x000000FF;
+    rxfilter[1].can_id = 0x02;
+    rxfilter[1].can_mask = 0x000000FF;
+    rxfilter[2].can_id = 0x01FF;
+    rxfilter[2].can_mask = 0x00000FFF;
+    if (setsockopt(s0, SOL_CAN_RAW, CAN_RAW_FILTER,
+                   &rxfilter, sizeof(struct can_filter) * 3) < 0) {
+        log_error("RX setsockopt CAN_RAW_FILTER failed");
+    }
+
+    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;
+}
+
+float GetMaxChargingVol(uint8_t index)
+{
+    return maxChargingVol[index];
+}
+
+float GetMaxCharginigCur(uint8_t index)
+{
+    return maxChargingCur[index];
+}
+
+static void SendCommunicationOnly(uint8_t index)
+{
+    struct ChargingInfoData *pDcCharginigInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+    uint8_t targetID = pDcCharginigInfo->Evboard_id;
+
+    if (pSysConfig->TotalConnectorCount == 1 &&
+            pDcCharginigInfo->Type == _Type_CCS_2 &&
+            ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+        targetID += 1;
+    }
+
+    SetChargingPermission(index,
+                          COMMUNICATION,
+                          pDcCharginigInfo->AvailableChargingPower,
+                          0,
+                          0,
+                          targetID);
+}
+
+static void SendStopOnly(uint8_t index)
+{
+    struct ChargingInfoData *pDcCharginigInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+    uint8_t targetID = pDcCharginigInfo->Evboard_id;
+
+    if (pSysConfig->TotalConnectorCount == 1 &&
+            pDcCharginigInfo->Type == _Type_CCS_2 &&
+            ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+        targetID += 1;
+    }
+
+    SetChargingPermission(index,
+                          STOP,
+                          pDcCharginigInfo->AvailableChargingPower,
+                          0,
+                          0,
+                          targetID);
+}
+
+static uint8_t GetStopChargingReasonByEvse(uint8_t gunIndex, uint8_t *reason)
+{
+    uint8_t result = NO;
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+    if (pAlarmCode->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 (pDcChargingInfo->Type == _Type_Chademo) {
+        if (pFaultCode->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 (pAlarmCode->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 (pAlarmCode->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 (pDcChargingInfo->Type == _Type_GB) {
+        if (pFaultCode->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 (pAlarmCode->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 (pDcChargingInfo->Type == _Type_CCS_2) {
+        if (pFaultCode->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 (pAlarmCode->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 (pAlarmCode->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;
+}
+
+static void setCurrentOutput(void)
+{
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        //chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+
+        if (chargingData_1->FireChargingVoltage <= 500) { //DS60-120 add
+            chargingData_1->PresentChargingCurrent = 0;
+        }
+
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+
+        if (chargingData_1->FireChargingVoltage <= 500) { //DS60-120 add
+            chargingData_1->PresentChargingCurrent = 0;
+        }
+
+        if (chargingData_2->FireChargingVoltage <= 500) {
+            chargingData_2->PresentChargingCurrent = 0;
+        }
+    }
+}
+
+static void SetPresentChargingOutputCap(void)
+{
+    float pow1 = 0, cur1 = 0;
+    float pow2 = 0, cur2 = 0;
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+    }
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    float vol = 0;
+#endif //!defined DD360 && !defined DD360Audi
+
+    pow1 = chargingData_1->AvailableChargingPower;
+    cur1 = chargingData_1->AvailableChargingCurrent;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    vol = chargingData_1->MaximumChargingVoltage;
+    GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
+    GetMaxPowerMethod(chargingData_1->Index, &pow1);
+#endif //!defined DD360 && !defined DD360Audi
+
+    //DS60-120 add
+    if (pow1 <= 0) {
+        cur1 = 0;
+    } else {
+        if (chargingData_1->SystemStatus == S_CHARGING &&
+                chargingData_1->FireChargingVoltage > 1500) {
+            float maxCur = 0;
+            maxCur = (pow1 * 1000) / chargingData_1->FireChargingVoltage;
+
+            if (maxCur * 10 <= cur1) {
+                //log_info("Gun1 -> MaxCharging Current = %f, Cap Current = %f \n", (maxCur * 10), cur1);
+                cur1 = maxCur * 10;
+            }
+        }
+    }
+
+    pow2 = chargingData_2->AvailableChargingPower;
+    cur2 = chargingData_2->AvailableChargingCurrent;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    vol = chargingData_2->MaximumChargingVoltage;
+    GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
+    GetMaxPowerMethod(chargingData_2->Index, &pow2);
+#endif //!defined DD360 && !defined DD360Audi
+
+    //DS60-120 add
+    if (pow2 <= 0) {
+        cur2 = 0;
+    } else {
+        if (chargingData_2->SystemStatus == S_CHARGING &&
+                chargingData_2->FireChargingVoltage > 1500) {
+            float maxCur = 0;
+            maxCur = (pow2 * 1000) / chargingData_2->FireChargingVoltage;
+
+            if (maxCur * 10 <= cur2) {
+                //log_info("Gun2 -> MaxCharging Current = %f, Cap Current = %f \n", (maxCur * 10), cur2);
+                cur2 = maxCur * 10;
+            }
+        }
+    }
+
+    //DS60-120 add
+    if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 ||
+            LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
+            (LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 5 ||
+             LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1 + 5) ||
+            (LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <= pow2 - 5 ||
+             LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >= pow2 + 5) ||
+            (LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <= cur2 - 5 ||
+             LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5)
+       ) {
+        //log_info("----------------------------------------------------- \n");
+        log_info("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f\r\n",
+                 pow1 / 10, cur1 / 10, pow2 / 10, cur2 / 10);
+        //log_info("----------------------------------------------------- \n");
+
+        LogInfo[0][EV_LOG_OUTPUT_CAP_POW] = pow1;
+        LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;
+        LogInfo[1][EV_LOG_OUTPUT_CAP_POW] = pow2;
+        LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] = cur2;
+        chargingData_1->RealMaxCurrent = cur1;
+        chargingData_1->RealMaxPower = pow1;
+
+        if (pSysConfig->TotalConnectorCount == 2) {
+            chargingData_2->RealMaxCurrent = cur2;
+            chargingData_2->RealMaxPower = pow2;
+        }
+    }
+
+    SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
+}
+
+static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
+{
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+    if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol) {
+        *vol = maxChargingVol[index];
+    }
+
+    if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur) {
+        *cur = maxChargingCur[index];
+    }
+
+    if (((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
+            pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+             pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) &&
+            pDcChargingInfo->ChargingProfileCurrent >= 0 &&
+            pDcChargingInfo->ChargingProfileCurrent <= *cur
+       ) {
+        *cur = pDcChargingInfo->ChargingProfileCurrent;
+    }
+}
+
+static void SetPresentChargingOutputPower(void)
+{
+    float vol1 = 0, cur1 = 0;
+    float vol2 = 0, cur2 = 0;
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+    }
+
+    vol1 = chargingData_1->FireChargingVoltage;
+    cur1 = (chargingData_1->PresentChargingCurrent * 10);
+    vol2 = chargingData_2->FireChargingVoltage;
+    cur2 = (chargingData_2->PresentChargingCurrent * 10);
+
+    //DS60-120 add
+    if ((LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
+            (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] <= vol1 - CHK_VOL_RANGE) ||
+            (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] >= cur1 + CHK_CUR_RANGE) ||
+            (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] <= cur1 - CHK_CUR_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] >= vol2 + CHK_VOL_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] <= vol2 - CHK_VOL_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
+       ) {
+        log_info("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f\r\n",
+                 vol1 / 10,
+                 cur1 / 10,
+                 vol2 / 10,
+                 cur2 / 10);
+
+        LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
+        LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
+        LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] = vol2;
+        LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] = cur2;
+    }
+    //if (_outVol_1 != vol1 ||
+    //        _outCur_1 != cur1 ||
+    //        _outVol_2 != vol2 ||
+    //        _outCur_2 != cur2) {
+    /*log_info("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);
+}
+
+static void checkConnectorOVPState(uint8_t gunIndex)
+{
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+    // 避免槍溫偵測誤判
+    static uint8_t gunTempAllowCount[2] = {0, 0};
+    bool isOTP = false;
+
+    switch (pDcChargingInfo->Type) {
+    case _Type_Chademo:
+        if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP) {
+            isOTP = true;
+        }
+        break;
+
+    case _Type_CCS_2:
+        if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP) {
+            isOTP = true;
+        }
+        break;
+
+    case _Type_GB:
+        if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP) {
+            isOTP = true;
+        }
+        break;
+    }
+
+    if (isOTP) {
+        if (gunTempAllowCount[gunIndex] >= 2) {
+            pDcChargingInfo->StopChargeFlag = YES;
+        } else {
+            gunTempAllowCount[gunIndex] += 1;
+        }
+    } else {
+        gunTempAllowCount[gunIndex] = 0;
+    }
+}
+
+static time_t GetRtcInfoForEpoch(void)
+{
+    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;
+}
+
+static void FormatVoltageAndCurrent(void)
+{
+    uint8_t gunIndex = 0;
+    ParsingRatedCur parsingRatedCur = {0};
+    RateCurInfo *pRatedCurInfo = NULL;
+
+    if (RatedCurrentParsing((char *)pSysConfig->ModelName, &parsingRatedCur) != PASS) {
+        log_error("Parsing rated current failed\r\n");
+        return;
+    }
+
+    maxChargingPow = parsingRatedCur.Power;
+
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[gunIndex];
+
+        maxChargingVol[gunIndex] = pRatedCurInfo->Voltage;
+        maxChargingCur[gunIndex] = pRatedCurInfo->Current;
+
+        log_info("Conn %d GunType = %d, MaxVol = %f, MaxCur = %f \n",
+                 gunIndex,
+                 pRatedCurInfo->GunType,
+                 maxChargingVol[gunIndex],
+                 maxChargingCur[gunIndex]);
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    bool chkChademoPermission[2] = {false};
+    int isContinue = 1;
+    uint8_t gunIndex = 0;
+    uint8_t typeIndex = 0;
+    uint8_t priorityLow = 1;
+    uint8_t SendErrorCount[2] = { 0, 0};
+    uint32_t _timeBuf = 0;
+    uint32_t chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {0};
+    struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    time_t rtc = {0};
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
+    }
+
+    MappingGunChargingInfo("EvComm Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonInfo();
+    ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
+    ShmGBTData = (struct GBTData *)GetShmGBTData();
+    ShmCcsData = (struct CcsData *)GetShmCcsData();
+
+    CanFd = InitCanBus();
+
+    FormatVoltageAndCurrent();
+
+    CANReceiver(CanFd);
+
+    rtc = GetRtcInfoForEpoch();
+
+    while (isContinue) {
+        for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+            typeIndex = pDcChargingInfo->type_index;
+
+            if (priorityLow == 1) {
+                // 優先權較低 - 只要有回應即不會再詢問
+                if (pDcChargingInfo->Type == _Type_Chademo &&
+                        ShmCHAdeMOData->evse[typeIndex].SelfTest_Comp != PASS) {
+                    SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
+                    GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
+                } else if (pDcChargingInfo->Type == _Type_GB &&
+                           ShmGBTData->evse[typeIndex].SelfTest_Comp != PASS) {
+                    SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
+                    GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 &&
+                            ShmCcsData->V2GMessage_DIN70121[typeIndex].SelfTest_Comp != PASS) {
+                        SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
+                        GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
+                    }
+                }
+
+                // 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
+                //log_info("GetMiscellaneousInfo. index = %d, Eid = %d \n", gunIndex, pDcChargingInfo->Evboard_id);
+                GetMiscellaneousInfo(gunIndex,
+                                     pDcChargingInfo->RelayK1K2Status,
+                                     pDcChargingInfo->PresentChargedEnergy,
+                                     (pDcChargingInfo->PresentChargingVoltage * 10),
+                                     pDcChargingInfo->Evboard_id);
+
+                checkConnectorOVPState(gunIndex);
+            }
+
+            switch (pDcChargingInfo->SystemStatus) {
+            case S_IDLE:
+            case S_RESERVATION:
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+
+                    ClearAbnormalStatus_Chademo(gunIndex);
+                    if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
+                        if (!chkChademoPermission[gunIndex]) {
+                            chkChademoPermission[gunIndex] = true;
+                            gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                            SendCommunicationOnly(gunIndex);
+                        } else {
+                            _timeBuf = GetTimeoutValue(_chk_chademo_permission_timeout[gunIndex]);
+
+                            if (_timeBuf < 0) {
+                                gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                            } else {
+                                if (_timeBuf / 1000 > 10000) {
+                                    SendCommunicationOnly(gunIndex);
+                                    gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                                }
+                            }
+                        }
+                    } else if (chkChademoPermission[gunIndex]) {
+                        chkChademoPermission[gunIndex] = false;
+                        SendStopOnly(gunIndex);
+                    }
+
+                    if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP == NO) {
+                        pDcChargingInfo->StopChargeFlag = NO;
+                    }
+
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    ClearAbnormalStatus_GB(gunIndex);
+
+                    if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP == NO) {
+                        pDcChargingInfo->StopChargeFlag = NO;
+                    }
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    ClearAbnormalStatus_CCS(gunIndex);
+
+                    if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO) {
+                        pDcChargingInfo->StopChargeFlag = NO;
+                    }
+                }
+
+                if (priorityLow == 1) {
+                    pDcChargingInfo->PresentChargedEnergy = 0;
+                    pDcChargingInfo->PresentChargingPower = 0;
+                    pDcChargingInfo->GroundFaultStatus = GFD_WAIT;
+                    pDcChargingInfo->RealRatingPower = 0;
+                    pDcChargingInfo->StopChargeFlag = NO;
+                    pDcChargingInfo->NormalStopChargeFlag = NO;//DS60-120 add
+                    pDcChargingInfo->ChargingFee = 0.0;
+                    pDcChargingInfo->EvBatterySoc = 0;
+                    pDcChargingInfo->EvBatteryStartSoc = 0; //DS60-120 add
+                    pDcChargingInfo->EvBatteryMaxVoltage = 0; //DS60-120 add
+                    pDcChargingInfo->ChargingProfilePower = -1; //DS60-120 add
+                    pDcChargingInfo->ChargingProfileCurrent = -1; //DS60-120 add
+
+                    if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) { //DS60-120 add
+
+                        pDcChargingInfo->PresentChargingVoltage = 0;
+                        pDcChargingInfo->PresentChargingCurrent = 0;
+                        pDcChargingInfo->EvBatteryMaxVoltage = 0;
+                    }
+
+                    chargingTime[gunIndex] = 0;
+                    //maxChargingCur[gunIndex] = pSysConfig->MaxChargingCurrent * 10;
+                    //maxChargingPow = (pSysConfig->MaxChargingPower * 10);
+                    //DS60-120 add
+                    SendErrorCount[gunIndex] = 0;
+
+                    //maxChargingPow = pSysConfig->MaxChargingPower * 10;
+                    // ShmPsuData->SystemAvailablePower 已是 * 10
+                    //maxChargingPow = ShmPsuData->SystemAvailablePower;
+                    if (pSysConfig->MaxChargingPower * 10 != 0 &&
+                            pSysConfig->MaxChargingPower * 10 < maxChargingPow) {
+                        maxChargingPow = pSysConfig->MaxChargingPower * 10;
+                    }
+
+                    LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = 0;
+                    LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = 0;
+                    LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] = 0;
+                    LogInfo[gunIndex][EV_LOG_SOC] = 0;
+
+                    SetPresentChargingOutputPower();
+                }
+                break;
+
+            case S_PREPARNING:
+                chkChademoPermission[gunIndex] = false; //DS60-120 add
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                pDcChargingInfo->PowerConsumption = 0;
+                break;
+
+            case S_PREPARING_FOR_EV:
+                // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+//                  log_info("PresentChargingVoltage = %f \n", pDcChargingInfo->PresentChargingVoltage);
+//                  log_info("PresentChargingCurrent = %f \n", pDcChargingInfo->PresentChargingCurrent);
+//                  log_info("AvailableChargingPower = %f \n", pDcChargingInfo->AvailableChargingPower);
+//                  log_info("AvailableChargingCurrent = %f \n", pDcChargingInfo->AvailableChargingCurrent);
+//                  log_info("MaximumChargingVoltage = %f \n", pDcChargingInfo->MaximumChargingVoltage);
+
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                if (priorityLow == 1) {
+                    float maxVol, maxCur;
+                    // 樁端輸出能力
+                    maxVol = pDcChargingInfo->MaximumChargingVoltage;
+                    maxCur = pDcChargingInfo->AvailableChargingCurrent;
+
+                    GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+
+                    //DS60-120 add
+                    if (LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] != maxVol ||
+                            LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] != maxCur) {
+                        LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = maxVol;
+                        LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = maxCur;
+
+                        log_info("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f \n",
+                                 gunIndex, maxVol / 10, maxCur / 10, pDcChargingInfo->AvailableChargingPower / 10);
+                    }
+                    //log_info("To EV_%d Max_Vol = %f, Cap_Cur = %f, Cap_Pow = %f \n",
+                    //            gunIndex, maxVol, maxCur, pDcChargingInfo->AvailableChargingPower);
+
+                    pDcChargingInfo->RealMaxVoltage = maxVol;
+
+                    SetChargingPermission(gunIndex,
+                                          START,
+                                          pDcChargingInfo->AvailableChargingPower,
+                                          maxCur,
+                                          maxVol,
+                                          pDcChargingInfo->Evboard_id);
+
+                    // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+                    GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id);
+                }
+
+                gettimeofday(&_chk_ratingPower_timeout[gunIndex], NULL);
+                break;
+
+            case S_PREPARING_FOR_EVSE:
+            case S_CCS_PRECHARGE_ST0:
+            case S_CCS_PRECHARGE_ST1:
+                // 開始確認車端是否同意開始充電
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                if (priorityLow % 5 == 1) {
+                    // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+                    GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id); //DS60-120 add
+
+                    // 樁端輸出能力改變
+                    SetPresentChargingOutputCap();
+                }
+
+                //DS60-120 add
+                if (LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] != pDcChargingInfo->EvBatteryMaxVoltage) {
+                    LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] = pDcChargingInfo->EvBatteryMaxVoltage;
+                    log_info("index = %d, Ev Maximum Battery Voltage = %f \n",
+                             gunIndex,
+                             pDcChargingInfo->EvBatteryMaxVoltage);
+                }
+
+                if (LogInfo[gunIndex][EV_LOG_SOC] != pDcChargingInfo->EvBatterySoc) {
+                    LogInfo[gunIndex][EV_LOG_SOC] = pDcChargingInfo->EvBatterySoc;
+                    log_info("index = %d, SOC = %d \n",
+                             gunIndex,
+                             pDcChargingInfo->EvBatterySoc);
+                }
+
+                // 持續通知 Isolation 測試狀態
+                if (priorityLow == 1) {
+                    // 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
+//                      if (_chargingData[_index]->FireChargingVoltage >= 3500)
+//                         pDcChargingInfo->GroundFaultStatus = GFD_PASS;
+
+                    //log_info("To EV_%d GFD = %d \n",   _index,pDcChargingInfo->GroundFaultStatus);
+                    //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
+                    {
+                        //if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
+                        uint8_t _result = pDcChargingInfo->GroundFaultStatus;
+
+                        // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
+                        if (pDcChargingInfo->Type == _Type_Chademo ||
+                                pDcChargingInfo->Type == _Type_GB) {
+                            if (_result == GFD_WARNING) {
+                                _result = GFD_PASS;
+                            }
+                        }
+
+                        if (_result == GFD_WARNING || _result == GFD_PASS) {
+                            if (((GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 12000 &&
+                                    pDcChargingInfo->RealRatingPower > 0) ||
+                                    (GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 14000) {
+                                //log_info("**********EvComm : gunIndex= %d, RealRatingPower = %d \n",
+                                //            gunIndex,pDcChargingInfo->RealRatingPower);
+                                //_result = GFD_PASS;
+
+                                //DS60-120 add
+                                if (LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] != pDcChargingInfo->RealRatingPower) {
+                                    LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] = pDcChargingInfo->RealRatingPower;
+                                    log_info("Conn %d, RealRatingPower = %d \n",
+                                             gunIndex,
+                                             pDcChargingInfo->RealRatingPower);
+
+                                }
+                            } else {
+                                _result = GFD_WAIT;
+                            }
+                        }
+
+                        SetIsolationStatus(gunIndex, _result, pDcChargingInfo->Evboard_id);
+                    }
+
+                    if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 &&
+                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
+                        SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
+                    }
+                }
+                break;
+
+            case S_CHARGING:
+                // 計算 Power
+                pDcChargingInfo->PresentChargingPower =
+                    ((float)((pDcChargingInfo->PresentChargingVoltage) *
+                             (pDcChargingInfo->PresentChargingCurrent)) / 1000);
+
+                //DS60-120 remove
+                if (chargingTime[gunIndex] == 0 ||
+                        chargingTime[gunIndex] > pDcChargingInfo->PresentChargedDuration) {
+                    chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
+                } else {
+                    int passTime = pDcChargingInfo->PresentChargedDuration - chargingTime[gunIndex];
+
+                    if (passTime > 0) {
+                        float changingPow = (pDcChargingInfo->PresentChargingPower) * passTime / 3600;
+                        if (pSysConfig->BillingData.isBilling) {
+                            pDcChargingInfo->ChargingFee += changingPow * pSysConfig->BillingData.Cur_fee;
+                        }
+
+                        pDcChargingInfo->PresentChargedEnergy += changingPow;
+                        pDcChargingInfo->PowerConsumption += changingPow;
+                        chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
+                    }
+                }
+
+                // 開始確認車端是否同意開始充電
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                // for test end
+                if (priorityLow % 5 == 0) {
+                    // 樁端輸出能力改變
+                    SetPresentChargingOutputCap();
+                }
+
+                if ((pDcChargingInfo->GroundFaultStatus == GFD_FAIL) ||
+                        (pDcChargingInfo->Type == _Type_CCS_2)) {
+                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                }
+                /*
+                else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                }*/
+
+                // GFD 失敗再通知
+                if (priorityLow == 1) {
+                    if (pDcChargingInfo->Type == _Type_CCS_2 &&
+                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
+                        SetEvsePrechargeInfo(gunIndex, PRECHARGE_CHARELAY_PASS, pDcChargingInfo->Evboard_id);
+                    }
+                }
+                break;
+
+            case S_ALARM:
+            case S_TERMINATING:
+                // 設定當前輸出
+                setCurrentOutput();
+                SetPresentChargingOutputPower();
+
+                // 槍鎖還在,則代表是樁端要求的停止
+                if (pDcChargingInfo->GunLocked == START ||
+                        pDcChargingInfo->Type == _Type_CCS_2) {
+                    uint8_t normalStop = 0x01;
+                    uint8_t stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+                    if (GetStopChargingReasonByEvse(gunIndex, stopReason)) {
+                        normalStop = 0x02;
+                    }
+
+                    EvseStopChargingEvent(normalStop, stopReason, pDcChargingInfo->Evboard_id);
+                    SendErrorCount[gunIndex] += 1; //DS60-120 add
+                }
+
+                if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                }
+
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+                //DS60-120 add
+                if (pDcChargingInfo->SystemStatus == S_ALARM) {
+                    if (priorityLow == 1) {
+                        float maxVol, maxCur;
+
+                        // 樁端輸出能力
+                        maxVol = pDcChargingInfo->MaximumChargingVoltage;
+                        maxCur = pDcChargingInfo->AvailableChargingCurrent;
+
+                        GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+                        SetChargingPermission(gunIndex,
+                                              STOP,
+                                              pDcChargingInfo->AvailableChargingPower,
+                                              maxCur,
+                                              maxVol,
+                                              pDcChargingInfo->Evboard_id);
+                    }
+                }
+                break;
+
+            case S_COMPLETE:
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                if (priorityLow == 1) {
+                    float maxVol, maxCur;
+
+                    // 樁端輸出能力
+                    maxVol = pDcChargingInfo->MaximumChargingVoltage;
+                    maxCur = pDcChargingInfo->AvailableChargingCurrent;
+
+                    GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+                    SetChargingPermission(gunIndex,
+                                          STOP,
+                                          pDcChargingInfo->AvailableChargingPower,
+                                          maxCur,
+                                          maxVol,
+                                          pDcChargingInfo->Evboard_id);
+
+                    //DS60-120 add
+                    //if (pDcChargingInfo->EvBatterySoc >= 100) {
+                    //    //滿電,則直接清掉錯誤
+                    //    if (pDcChargingInfo->Type == _Type_Chademo) {
+                    //        ClearAbnormalStatus_Chademo(gunIndex);
+                    //    } else if (pDcChargingInfo->Type == _Type_GB) {
+                    //        ClearAbnormalStatus_GB(gunIndex);
+                    //    } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    //        ClearAbnormalStatus_CCS(gunIndex);
+                    //    }
+                    //}
+                }
+                break;
+            }//switch
+        }//for
+
+        priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
+        usleep(50000);
+    }//while
+
+    return 0;
+}

+ 56 - 28
EVSE/Projects/DD360/Apps/ModuleInternalComm/AcPlug.c

@@ -4,21 +4,23 @@
 #include <stdint.h>
 #include <time.h>
 
+#include <unistd.h>
 #include <sys/time.h>
 #include <sys/timeb.h>
 
+#include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
 //------------------------------------------------------------------------------
 static struct SysConfigData *pSysConfig = NULL;
 static struct SysInfoData *pSysInfo = NULL;
-static struct WARNING_CODE_INFO *pSysWarning = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct InfoCodeData *pInfoCode = NULL;
-static struct FaultcodeData *pFaultCode = NULL;
+static struct FaultCodeData *pFaultCode = NULL;
 static struct OCPP16Data *ShmOCPP16Data = NULL;
 
 static int Uart5Fd = 0;
@@ -57,6 +59,32 @@ static int _alarm_code[] = {
 };
 
 //------------------------------------------------------------------------------
+static void OcppStopTransation(uint8_t gunIndex)
+{
+    struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    if (strcmp((char *)pAcChargingInfo->StartUserId, "") == EQUAL) {
+        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag,
+               (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+    } else {
+        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag,
+               (char *)pAcChargingInfo->StartUserId);
+    }
+
+    log_info("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
+}
+
+static void SetCpDuty(uint8_t _value)
+{
+    Config_Ac_Duty(Uart5Fd, ADDR_AC_PLUG, _value);
+}
+
+static uint8_t GetChargingCurrent(void)
+{
+    return Query_Charging_Current(Uart5Fd, ADDR_AC_PLUG, &acChargingCurrent);
+}
+
 static uint8_t GetChargingEnergy(void)
 {
     return Query_Charging_Energy(Uart5Fd, ADDR_AC_PLUG, &acChargingEnergy);
@@ -152,6 +180,7 @@ static void CheckAlarmOccur(void)
 {
     bool isErr = false;
     uint8_t count = 0;
+    struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
     for (count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
         if (acAlarmCode.AcAlarmCode & _alarm_code[count]) {
@@ -202,7 +231,7 @@ static void CheckAlarmOccur(void)
         }
     }
 
-    ac_chargingInfo[0]->IsErrorOccur = isErr;
+    pAcChargingInfo->IsErrorOccur = isErr;
 }
 
 static void GetAcAlarmCode(void)
@@ -258,9 +287,9 @@ static void ChangeToCsuMode(void)
 
 static void GetAcModelName(void)
 {
-    memset(SysConfig->AcModelName, 0, sizeof(SysConfig->AcModelName));
-    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, SysConfig->AcModelName) == PASS) {
-        log_info("ac model name = %s \n", SysConfig->AcModelName);
+    memset(pSysConfig->AcModelName, 0, sizeof(pSysConfig->AcModelName));
+    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, pSysConfig->AcModelName) == PASS) {
+        log_info("ac model name = %s \n", pSysConfig->AcModelName);
     }
 }
 
@@ -277,14 +306,11 @@ static void GetFwVersion_AC(void)
 
 void AcPlugTask(int uartFD)
 {
-    if (acgunCount <= 0) {
-        return;
-    }
+    static float _beforeChargingTotalEnergy = 0.0;
 
-    if (CreateAllCsuShareMemory() == FAIL) {
-        log_error("Fan Board create share memory failed\r\n");
+    if (pSysConfig->AcConnectorCount <= 0) {
+        return;
     }
-    MappingGunChargingInfo("Fan Board Task");
 
     //share memory mapping
     pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
@@ -296,6 +322,8 @@ void AcPlugTask(int uartFD)
 
     struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
+    Uart5Fd = uartFD;
+
     //pAcChargingInfo->SelfTest_Comp = YES;
     //pAcChargingInfo->IsModeChagned = PASS;
     //---------------------------------------------
@@ -335,20 +363,20 @@ void AcPlugTask(int uartFD)
         } else if ((acStatus.CpStatus == AC_SYS_B || pAcChargingInfo->ConnectorPlugIn == AC_SYS_B) &&
                    pAcChargingInfo->IsAvailable &&
                    !pAcChargingInfo->IsErrorOccur &&
-                   (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
-                    SysConfig->AuthorisationMode == AUTH_MODE_DISABLE)) {
+                   (pSysInfo->WaitForPlugit == YES ||
+                    pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE)) {
             if (pAcChargingInfo->RemoteStartFlag == YES) {
                 log_info("** AC Remote \n");
                 pAcChargingInfo->RemoteStartFlag = NO;
                 strcpy((char *)pAcChargingInfo->StartUserId, "");
-                ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                pSysInfo->WaitForPlugit = NO;
                 _status = S_PREPARNING;
-            } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
-                log_info("** UserId = %s \n", SysConfig->UserId);
-                strcpy((char *)pAcChargingInfo->StartUserId, (char *)SysConfig->UserId);
+            } else if (pSysInfo->OrderCharging == NO_DEFINE) {
+                log_info("** UserId = %s \n", pSysConfig->UserId);
+                strcpy((char *)pAcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
                 log_info("** CardNumber = %s \n", pAcChargingInfo->StartUserId);
-                strcpy((char *)SysConfig->UserId, "");
-                ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                strcpy((char *)pSysConfig->UserId, "");
+                pSysInfo->WaitForPlugit = NO;
                 _status = S_PREPARNING;
             }
         } else if (pAcChargingInfo->SystemStatus == S_CHARGING) {
@@ -381,10 +409,10 @@ void AcPlugTask(int uartFD)
         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;
+                pSysInfo->SystemPage = _LCM_NONE;
+                pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+                if (pSysInfo->OrderCharging != NO_DEFINE) {
+                    pSysInfo->OrderCharging = NO_DEFINE;
                 }
                 gettimeofday(&_ac_preparing, NULL);
             }
@@ -403,14 +431,14 @@ void AcPlugTask(int uartFD)
                 ftime(&_ac_startChargingTime);
                 OcppStartTransation(1);
                 ChangeStartOrStopDateTime(YES);
-                ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+                pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
             }
 
             if (GetChargingEnergy() == PASS) {
                 if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0) {
                     pAcChargingInfo->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
-                    if (SysConfig->BillingData.isBilling) {
-                        pAcChargingInfo->ChargingFee += pAcChargingInfo->PresentChargedEnergy * SysConfig->BillingData.Cur_fee;
+                    if (pSysConfig->BillingData.isBilling) {
+                        pAcChargingInfo->ChargingFee += pAcChargingInfo->PresentChargedEnergy * pSysConfig->BillingData.Cur_fee;
                     }
                 }
 
@@ -429,7 +457,7 @@ void AcPlugTask(int uartFD)
             // 用以判斷是否有在輸出
             pAcChargingInfo->IsCharging = acStatus.RelayStatus;
 
-            SetCpDuty(SysConfig->AcMaxChargingCurrent);
+            SetCpDuty(pSysConfig->AcMaxChargingCurrent);
             ChangeLedStatus();
         }
         break;

+ 16 - 10
EVSE/Projects/DD360/Apps/ModuleInternalComm/FanBoard.c

@@ -3,12 +3,14 @@
 #include <string.h>
 #include <stdint.h>
 #include <time.h>
+#include <unistd.h>
 
 #include <sys/time.h>
 #include <sys/timeb.h>
 
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
@@ -22,6 +24,9 @@ static struct PsuData *ShmPsuData = NULL;
 static int Uart5Fd = 0;
 static struct timeval gFanBoardRunTimer;
 
+static uint16_t _setFanSpeed = 0;
+static uint16_t fanSpeedSmoothValue = 500;
+
 //------------------------------------------------------------------------------
 static void SetFanModuleSpeed(void)
 {
@@ -52,6 +57,8 @@ static void SetFanModuleSpeed(void)
 // 風扇速度
 static void GetFanSpeed(void)
 {
+    FanSpeed fanSpeed = {0};
+
     //log_info("Get fan board speed \n");
     if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
         ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
@@ -93,6 +100,7 @@ static void GetFanSpeedByFunction(void)
     float power = 0;
     double _pw_rate = 0;
     double _temp_rate = 0;
+    struct ChargingInfoData *pDcChargingInfo = NULL;
 
     for (index = 0; index < ShmPsuData->GroupCount; index++) {
         for (count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
@@ -102,8 +110,10 @@ static void GetFanSpeedByFunction(void)
         }
     }
 
-    for (gunIndex = 0; gunIndex < gunCount; gunIndex++) {
-        power += (_chargingData[gunIndex]->PresentChargingPower * 10);
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+        power += (pDcChargingInfo->PresentChargingPower * 10);
     }
 
     if (_maxPower > 0) {
@@ -143,7 +153,7 @@ static void SetRtcData_Fan(void)
 {
     struct timeb csuTime;
     struct tm *tmCSU;
-    RTC rtc = {0};
+    Rtc rtc = {0};
 
     ftime(&csuTime);
     tmCSU = localtime(&csuTime.time);
@@ -209,7 +219,7 @@ static void fanBoardPorcess(void)
     }
 
     if (ShmFanModuleData->SelfTest_Comp == YES ||
-            strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+            strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
             pSysInfo->FanModuleFwRev[0] != '\0') {
         ShmFanModuleData->SelfTest_Comp = YES;
 
@@ -217,7 +227,7 @@ static void fanBoardPorcess(void)
             //GetPsuTempForFanSpeed();
             GetFanSpeedByFunction();
             GetFanSpeed();
-            ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
+            pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
 
             ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
@@ -254,11 +264,6 @@ void FanBoardTask(int uartFD)
     if (pid == 0) {
         int isContinue = 1;
 
-        if (CreateAllCsuShareMemory() == FAIL) {
-            log_error("Fan Board create share memory failed\r\n");
-        }
-        MappingGunChargingInfo("Fan Board Task");
-
         //share memory mapping
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -272,6 +277,7 @@ void FanBoardTask(int uartFD)
             fanBoardSelfTest();
 
             fanBoardPorcess();
+            usleep(100000);
         }
     }
 }

+ 35 - 22
EVSE/Projects/DD360/Apps/ModuleInternalComm/LEDBoard.c → EVSE/Projects/DD360/Apps/ModuleInternalComm/LEDlight.c

@@ -4,11 +4,14 @@
 #include <stdint.h>
 #include <time.h>
 
+#include <unistd.h>
 #include <sys/time.h>
 #include <sys/timeb.h>
 
+#include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
@@ -43,11 +46,22 @@ static bool IsNoneMatchLedColor(void)
     return result;
 }
 
-static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+//static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+static void SetLedColor(void)
 {
     static uint8_t _checkLedChanged = 3;
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
     uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
 
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+    }
+
     if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
         _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
     } else if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
@@ -65,7 +79,7 @@ static void SetLedColor(struct ChargingInfoData *chargingData_1, struct Charging
         led_color.Connect_2_Blue = COLOR_MIN_LV;
         led_color.Connect_2_Red = _colorBuf;
     } else {
-        if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
+        if (pSysInfo->IsAlternatvieConf) {
             if ((chargingData_1->SystemStatus == S_BOOTING ||
                     chargingData_1->SystemStatus == S_IDLE ||
                     chargingData_1->SystemStatus == S_RESERVATION) &&
@@ -183,12 +197,14 @@ static void SetLedColor(struct ChargingInfoData *chargingData_1, struct Charging
 
 static void GetFwAndHwVersion_Led(void)
 {
+    Ver ver = {0};
+
     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);
-        //log_info("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
+        strcpy((char *) pSysInfo->LedModuleFwRev, ver.Version_FW);
+        log_info("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
         ShmLedModuleData->SelfTest_Comp = YES;
     } else {
         //log_info("GetFwAndHwVersion_Led fail \n");
@@ -197,32 +213,31 @@ static void GetFwAndHwVersion_Led(void)
 //  if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
 //  {
 //      // SystemInfo
-//      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+//      strcpy((char *) pSysInfo->RelayModuleHwRev, ver.Version_FW);
 //      //log_info("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
 //  }
 }
 
 static void LEDBoardProcess(void)
 {
-    struct ChargingInfoData *pDcChargingInfo0 = NULL;
-    struct ChargingInfoData *pDcChargingInfo1 = NULL;
+    //struct ChargingInfoData *pDcChargingInfo0 = NULL;
+    //struct ChargingInfoData *pDcChargingInfo1 = NULL;
 
     if (ShmLedModuleData->SelfTest_Comp == NO) {
         return;
     }
 
     if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-        if (pSysConfig->TotalConnectorCount == 1) {
-            pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-
-            SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
-        } else if (pSysConfig->TotalConnectorCount == 2) {
-            pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-            pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
-
-            SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
-        }
 
+        //if (pSysConfig->TotalConnectorCount == 1) {
+        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
+        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
+        //} else if (pSysConfig->TotalConnectorCount == 2) {
+        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
+        //    pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
+        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
+        //}
+        SetLedColor();
         gettimeofday(&_led_priority_time, NULL);
     }
 }
@@ -266,20 +281,18 @@ void LEDBoardTask(int uartFD)
     if (pid == 0) {
         int isContinue = 1;
 
-        if (CreateAllCsuShareMemory() == FAIL) {
-            log_error("LED Board create share memory failed\r\n");
-        }
-        MappingGunChargingInfo("LED Board Task");
-
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
 
         pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
         ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
+        Uart5Fd = uartFD;
 
         while (isContinue) {
             LEDBoardSelfTest();
+            LEDBoardProcess();
+            usleep(100000);
         }
     }
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 26 - 1392
EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.c


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

@@ -5,6 +5,7 @@
 #define RELAY_CHECK_TIME                        (5)       // s
 #define OUTPUT_VOL_CHK_TIME                     (200)     // ms
 #define TEN_MINUTES                             (600)     // s
+#define FORCE_STOP_TIME                         (30)
 //#define TEN_MINUTES                             5
 #define ENV_TEMP_MIN                            (45)
 #define ENV_TEMP_MAX                            (50)
@@ -102,4 +103,8 @@ typedef struct StPreCharginState {
     uint8_t Reserved: 6;
 } PreChargingState;
 
+//------------------------------------------------------------------------------
+uint32_t GetTimeoutValue(struct timeval _sour_time);
+int DiffTimeb(struct timeb ST, struct timeb ET);
+
 #endif /* _MODULE_INTERNAL_COMM_H_ */

+ 2488 - 0
EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalCommOrg.c

@@ -0,0 +1,2488 @@
+#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/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/define.h"
+#include "Module_InternalComm.h"
+#include "internalComm.h"
+#include "../Config.h"
+
+//------------------------------------------------------------------------------
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct FanModuleData            *ShmFanModuleData;
+struct RelayModuleData          *ShmRelayModuleData;
+struct LedModuleData            *ShmLedModuleData;
+struct PsuData                  *ShmPsuData;
+struct OCPP16Data               *ShmOCPP16Data;
+DcCommonInfo                    *ShmDcCommonData;
+
+uint8_t gunCount;
+uint8_t 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 _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
+struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
+
+// SMR1 *2 + SMR2 * 2 + Parallel * 2
+struct timeval _relayStateChkTimer[6]; //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(uint8_t 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;
+uint8_t _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;
+
+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
+};
+
+uint8_t getCommTargetID(uint8_t index)
+{
+    uint8_t targetID = 0;
+
+    if (gunCount == 1) {
+        if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "0", 1) != 0) {
+            targetID = 0x01;
+        } else if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "0", 1) != 0) {
+            targetID = 0x02;
+        }
+    } else {
+        targetID = _chargingData[index]->Evboard_id;
+    }
+
+    return targetID;
+}
+
+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;
+}
+
+//==========================================
+// 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);
+        //log_info("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);
+        //log_info("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);
+        //log_info("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);
+        //log_info("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);
+        //log_info("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
+        ShmLedModuleData->SelfTest_Comp = YES;
+    } else {
+        //log_info("GetFwAndHwVersion_Led fail \n");
+    }
+
+//  if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
+//  {
+//      // SystemInfo
+//      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+//      //log_info("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
+//  }
+}
+
+void GetFwVersion_AC()
+{
+    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);
+    }
+}
+
+void GetAcModelName()
+{
+    memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
+    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
+        log_info("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
+    }
+}
+
+void SetRtcData_Relay()
+{
+    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);
+
+    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) {
+        //log_info("SetRtc (RB) sucessfully. \n");
+    }
+}
+
+void SetModelName_Relay()
+{
+    if (Config_Model_Name(Uart5Fd, ADDR_RELAY, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+        //log_info("Set Model name (RB) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+    }
+}
+
+void SetRtcData_Fan()
+{
+    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);
+
+    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) {
+        //log_info("SetRtc (FB) sucessfully. \n");
+    }
+}
+
+void SetModelName_Fan()
+{
+    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)
+{
+    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;
+
+        //********************************************************************************************************//
+        // Vin (UVP)
+        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO) {
+                if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
+                    log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[0] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
+                    _threePhaseUvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO) {
+                if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
+                    log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[1] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
+                    _threePhaseUvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO) {
+                if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
+                    log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
+                    _threePhaseUvp[2] = 0;
+                }
+            }
+        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO) {
+                if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
+                    log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[0] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
+                    _threePhaseUvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO) {
+                if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
+                    log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[1] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
+                    _threePhaseUvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO) {
+                if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
+                    log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
+                    _threePhaseUvp[2] = 0;
+                }
+            }
+        }
+
+        //********************************************************************************************************//
+        // Vin (OVP)
+        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO) {
+                if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
+                    log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[0] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
+                    _threePhaseOvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO) {
+                if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
+                    log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[1] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
+                    _threePhaseOvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO) {
+                if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
+                    log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
+                    _threePhaseOvp[2] = 0;
+                }
+            }
+        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO) {
+                if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
+                    log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[0] += 0;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
+                    _threePhaseOvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO) {
+                if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
+                    log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[1] += 0;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
+                    _threePhaseOvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO) {
+                if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
+                    log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
+                    _threePhaseOvp[2] = 0;
+                }
+            }
+        }
+    }
+}
+
+// 左右槍的 Relay 前後的輸出電壓
+void GetPersentOutputVol(void)
+{
+    uint8_t index = 0;
+    uint8_t targetID = 0;
+
+    if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
+        return;
+    }
+
+    //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);
+
+    //log_info("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+    //log_info("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 (index = 0; index < gunCount; index++) {
+        targetID = getCommTargetID(index);
+
+        switch (targetID) {
+        case 0x01:
+#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 0x02:
+#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) {
+        //}
+    }
+}
+
+// 風扇速度
+void GetFanSpeed()
+{
+    //log_info("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];
+//      log_info("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
+//      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]);
+        //SysInfoData (SystemFanRotaSpeed)
+    }
+}
+
+// 讀取 Relay 狀態
+void GetRelayOutputStatus(void)
+{
+    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
+    }
+}
+
+// 確認 K1 K2 relay 的狀態
+void CheckK1K2RelayOutput(uint8_t index)
+{
+    uint8_t targetID = 0;
+
+    targetID = getCommTargetID(index);
+
+    switch (targetID) {
+    case 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 !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            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 //!defined DD360 && !defined DD360Audi
+        }
+        break;
+
+    case 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) {
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            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 //!defined DD360 && !defined DD360Audi
+        }
+        break;
+    }
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    //DS60-120 add
+    if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
+        if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
+                regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
+            ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
+        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 = YES;
+#endif //!defined DD360 && !defined DD360Audi
+}
+
+void GetGfdAdc()
+{
+    int gunIndex = 0;
+    uint8_t targetID = 0;
+
+    // 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 (gunIndex = 0; gunIndex < gunCount; gunIndex++) {
+            if (_chargingData[gunIndex]->Type == 0x09 &&
+                    !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag
+               ) {
+                if ((_chargingData[gunIndex]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE) {
+                    _chargingData[gunIndex]->GroundFaultStatus = GFD_PASS;
+                }
+                continue;
+            }
+
+            targetID = getCommTargetID(gunIndex);
+
+            if (targetID == 0x01) {
+                if (gfd_adc.result_conn1 == GFD_WARNING) {
+                    gfd_adc.result_conn1 = GFD_PASS;
+                }
+
+                _chargingData[gunIndex]->GroundFaultStatus = gfd_adc.result_conn1;
+                //log_info("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
+                //            _chargingData[gunIndex]->GroundFaultStatus,
+                //            gfd_adc.rb_step_1,
+                //            gfd_adc.Resister_conn1,
+                //            gfd_adc.voltage_conn1);
+                if (_chargingData[gunIndex]->GroundFaultStatus == GFD_FAIL) {
+                    log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
+                             gunIndex,
+                             gfd_adc.rb_step_1,
+                             gfd_adc.Resister_conn1,
+                             gfd_adc.voltage_conn1);
+
+                } else if (_chargingData[gunIndex]->GroundFaultStatus == GFD_PASS ||
+                           _chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING
+                          ) {
+                    if (_chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING) {
+                        log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+                                 gunIndex,
+                                 _chargingData[gunIndex]->GroundFaultStatus,
+                                 gfd_adc.Resister_conn1,
+                                 gfd_adc.voltage_conn1);
+                    }
+                }
+            } else if (targetID == 0x02) {
+                if (gfd_adc.result_conn2 == GFD_WARNING) {
+                    gfd_adc.result_conn2 = GFD_PASS;
+                }
+                _chargingData[gunIndex]->GroundFaultStatus = gfd_adc.result_conn2;
+                if (_chargingData[gunIndex]->GroundFaultStatus == GFD_FAIL) {
+                    log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
+                             gunIndex,
+                             gfd_adc.rb_step_2,
+                             gfd_adc.Resister_conn2,
+                             gfd_adc.voltage_conn2);
+                } else if (_chargingData[gunIndex]->GroundFaultStatus == GFD_PASS ||
+                           _chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING
+                          ) {
+                    if (_chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING) {
+                        log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+                                 gunIndex,
+                                 _chargingData[gunIndex]->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
+            log_info("RB AC Main Breaker. \n");
+        }
+
+        if (gpio_in.SPD == 1) {
+            // SPD (雷擊保護) ON
+            log_info("RB SPD. \n");
+        }
+
+        if (gpio_in.Door_Open == 1) {
+            // Door Open
+            log_info("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
+            log_info("RB AC Drop. \n");
+        }
+
+        if (gpio_in.Emergency_IO == 1) {
+            // Emergency IO ON
+            log_info("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
+        //log_info("aux1 = %x, \n", auxPower.voltage[0]);
+        //log_info("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) {
+            //log_info("successfully Fan\n");
+        }
+    }
+}
+
+//==========================================
+// Common Function
+//==========================================
+void SetK1K2RelayStatus(uint8_t index)
+{
+    uint8_t targetID = 0;
+    PreChargingState *pRegPreChargingState = NULL;
+    PreChargingState *pOutputPreChargingState = NULL;
+    GunPNState *pRegGunPNState = NULL;
+    GunPNState *pOutputGunPNState = NULL;
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)_chargingData[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;
+    }
+
+    targetID = getCommTargetID(index);
+
+    pRegPreChargingState = (PreChargingState *)&regRelay.relay_event.relay_status[0];
+    pOutputPreChargingState = (PreChargingState *)&outputRelay.relay_event.relay_status[0];
+    if (targetID == 0x01) {
+        pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[1];
+        pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[1];
+    } else if (targetID == 0x02) {
+        pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[2];
+        pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[2];
+    }
+
+    switch (pDcChargingInfo->SystemStatus) {
+    case S_BOOTING:
+    case S_IDLE:
+    case S_AUTHORIZING:
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+        if (pRegGunPNState->GunP == YES) {
+            pOutputGunPNState->GunP = NO;
+        } else if (pRegGunPNState->GunN == YES) {
+            pOutputGunPNState->GunN = NO;
+        }
+
+        if (targetID == 0x02 && pDcChargingInfo->Type == _Type_CCS_2) {
+            if (pRegPreChargingState->CcsPrecharge == YES) {
+                pOutputPreChargingState->CcsPrecharge = NO;
+            }
+        }
+        break;
+
+    case S_PREPARING_FOR_EVSE:
+    case S_CHARGING:
+        //if (pDcChargingInfo->RelayWeldingCheck != YES) {
+        //    break;
+        //}
+
+        if (pRegGunPNState->GunN == NO) {
+            pOutputGunPNState->GunN = YES;
+        } else if (pRegGunPNState->GunP == NO) {
+            pOutputGunPNState->GunP = YES;
+        }
+        break;
+
+    case S_TERMINATING:
+    case S_COMPLETE:
+    case S_ALARM:
+        if ((pDcChargingInfo->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
+            if (pRegGunPNState->GunP == YES) {
+                pOutputGunPNState->GunP = NO;
+            } else if (pRegGunPNState->GunN == YES) {
+                pOutputGunPNState->GunN = NO;
+            }
+        }
+        break;
+
+    case S_CCS_PRECHARGE_ST0:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+        break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+            if (pRegPreChargingState->CcsPrecharge == NO) {
+                pOutputPreChargingState->CcsPrecharge = YES;
+            } else if (pRegPreChargingState->CcsPrecharge == YES) {
+                pRegGunPNState->GunP = NO;
+            }
+        }
+        break;
+
+    case S_CCS_PRECHARGE_ST1:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+        break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+            if (pRegGunPNState->GunP == NO) {
+                pOutputGunPNState->GunP = YES;
+            } else if (pRegGunPNState->GunP == YES) {
+                pOutputPreChargingState->CcsPrecharge = NO;
+            }
+        }
+        break;
+    }
+}
+
+void CheckAcInputOvpStatus(uint8_t 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)
+//              {
+//                  log_info("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)
+//              {
+//                  log_info("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
+//                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
+//                  _chargingData[index]->StopChargeFlag = YES;
+//              }
+//          }
+//      }
+//      else
+        //log_info("CheckAcInputOvpStatus\r\n");
+        _chargingData[index]->StopChargeFlag = YES;
+    }
+}
+
+void CheckPhaseLossStatus(uint8_t index)
+{
+    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
+        //log_info("CheckPhaseLossStatus\r\n");
+        _chargingData[index]->StopChargeFlag = YES;
+    }
+}
+
+void SetParalleRelayStatus(void)
+{
+#if defined  DD360 || defined DD360Audi || defined DD360ComBox
+    return;
+#endif //!defined  DD360 || !defined DD360Audi || !defined DD360ComBox
+
+    // 之後雙槍單模機種,橋接都會上
+    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 (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]) {
+            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)
+{
+    uint8_t _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)) {
+#if defined DD360Audi
+                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 ||
+                    chargingData_1->SystemStatus == S_MAINTAIN) {
+
+                if (chargingData_1->IsAvailable == NO) { //For Audi
+                    led_color.Connect_1_Green = COLOR_MIN_LV;
+                    led_color.Connect_1_Blue = COLOR_MIN_LV;
+                    led_color.Connect_1_Red = _colorBuf;
+                } else {
+#if defined DD360Audi
+                    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 ||
+                    chargingData_2->SystemStatus == S_MAINTAIN) {
+                if (chargingData_2->IsAvailable == NO) {
+                    led_color.Connect_2_Green = COLOR_MIN_LV;
+                    led_color.Connect_2_Blue = COLOR_MIN_LV;
+                    led_color.Connect_2_Red = _colorBuf;
+                } else {
+#if defined DD360Audi
+                    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) {
+        result = FAIL;
+    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+    memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
+
+    if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+    memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
+
+    if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+    memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
+
+    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    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;
+}
+
+int InitComPort()
+{
+    int fd;
+    struct termios tios;
+
+    fd = open(relayRs485PortName, O_RDWR);
+    if (fd <= 0) {
+#ifdef SystemLogMessage
+        log_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] = (uint8_t)0;     // timeout 0.5 second
+    tios.c_lflag = 0;
+    tcflush(fd, TCIFLUSH);
+    ioctl (fd, TCSETS, &tios);
+
+    return fd;
+}
+
+//================================================
+// Main process
+//================================================
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
+{
+    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 (uint8_t index = 0; index < CCS_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
+                == target) {
+            chargingData[target] =
+                &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+            return true;
+        }
+    }
+
+    for (uint8_t 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(uint8_t target, struct ChargingInfoData **acChargingData)
+{
+    if (target < AC_QUANTITY) {
+        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
+        return true;
+    }
+
+    return false;
+}
+
+void Initialization()
+{
+    bool isPass = false;
+
+    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 (uint8_t _index = 0; _index < gunCount; _index++) {
+            if (!FindChargingInfoData(_index, &_chargingData[0])) {
+                log_error("InternalComm : FindChargingInfoData false \n");
+                isPass = false;
+                break;
+            }
+        }
+
+        sleep(1);
+    }
+
+    isPass = false;
+
+    if (acgunCount > 0) {
+        while (!isPass) {
+            isPass = true;
+            for (uint8_t _index = 0; _index < acgunCount; _index++) {
+                if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
+                    log_error("EvComm : FindAcChargingInfoData false \n");
+                    isPass = false;
+                    break;
+                }
+            }
+
+            sleep(1);
+        }
+    }
+}
+
+bool IsNoneMatchRelayStatus()
+{
+    bool result = false;
+
+    if (
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+        (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
+        (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
+#endif //!defined DD360 && !defined DD360Audi
+        (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)
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+        ||
+        (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)
+#endif //!defined DD360 && !defined DD360Audi
+    ) {
+        /*if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
+            log_info("AC Contact Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
+            log_info("CCS Precharge Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
+            log_info("SMR1:D+ Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
+            log_info("SMR1:D- Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
+            log_info("SMR2:D+ Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
+            log_info("SMR2:D- Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
+            log_info("Parallel:D+ Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
+            log_info("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;
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    ShmSysConfigAndInfo->SysInfo.AcContactorStatus  = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+#endif //!defined DD360 && !defined DD360Audi
+
+    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(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) {
+//      log_info("Set reqVol = %f, resister = %d \n",
+//              gfd_config.reqVol,
+//              gfd_config.resister);
+    }
+}
+
+void CableCheckDetected(uint8_t index)
+{
+    uint8_t targetID = 0;
+    // 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 (gunCount == 1) {
+        if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "0", 1) != 0) {
+            targetID = 0;
+        } else if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "0", 1) != 0) {
+            targetID = 1;
+        }
+    } else {
+        targetID = index;
+    }
+
+    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(targetID, GFD_CABLECHK);
+            } else if (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                       _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1) {
+                SetGfdConfig(targetID, 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(targetID, GFD_IDLE);
+                } else {
+                    SetGfdConfig(targetID, GFD_CHARGING);
+                }
+            }
+        } else if (_chargingData[index]->SystemStatus == S_COMPLETE ||
+                   _chargingData[index]->SystemStatus == S_PREPARNING
+                   || _chargingData[index]->SystemStatus == S_IDLE) {
+            SetGfdConfig(targetID, GFD_IDLE);
+        }
+    }
+}
+
+void CheckOutputPowerOverCarReq(uint8_t index)
+{
+    float fireV = _chargingData[index]->FireChargingVoltage;
+    float carV = _chargingData[index]->EvBatteryMaxVoltage * 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.02))) {
+            if (!_isOvpChkTimeFlag[index]) {
+                if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
+                    gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
+                    _isOvpChkTimeFlag[index] = YES;
+                }
+            } else {
+                log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
+                         _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
+                log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
+                          _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
+                if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
+                    //if (_chargingData[index]->Type == _Type_Chademo) {
+                    //    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
+                    //} else if (_chargingData[index]->Type == _Type_CCS_2) {
+                    //    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
+                    //} else if (_chargingData[index]->Type == _Type_GB) {
+                    //    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
+                    //}
+                    if (_chargingData[index]->Type == _Type_Chademo) {
+                        ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
+                        if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
+                            memcpy(_chargingData[index]->ConnectorAlarmCode, "012217", 6);
+                        }
+                    } else if (_chargingData[index]->Type == _Type_CCS_2) {
+                        ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
+                        if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
+                            memcpy(_chargingData[index]->ConnectorAlarmCode, "012219", 6);
+                        }
+                    } else if (_chargingData[index]->Type == _Type_GB) {
+                        ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = YES;
+                        if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
+                            memcpy(_chargingData[index]->ConnectorAlarmCode, "012221", 6);
+                        }
+                    }
+
+                    _chargingData[index]->StopChargeFlag = YES;
+                }
+            }
+        } else {
+            if (_isOvpChkTimeFlag[index] == YES) {
+                _isOvpChkTimeFlag[index] = NO;
+            }
+        }
+    }
+}
+
+void CheckOutputVolNoneMatchFire(uint8_t 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) {
+                    /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
+                            index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
+                    log_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(uint8_t 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;
+            }
+
+            log_info("CheckRelayWeldingStatus : fail \n");
+            _chargingData[index]->StopChargeFlag = YES;
+        }
+    }
+}
+
+void GetPsuTempForFanSpeed()
+{
+    char temp = 0;
+
+    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;
+            }
+        }
+    }
+
+    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 :
+    uint8_t temp = 0;
+    float power = 0;
+
+    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 (uint8_t gunIndex = 0; gunIndex < gunCount; gunIndex++) {
+        power += (_chargingData[gunIndex]->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 / 50;
+    }
+    uint8_t _temp_diff = 0;
+    if (temp > 45) {
+        _temp_diff = temp - 70;
+    }
+
+    ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _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_AC_PLUG, &acStatus) == PASS) {
+        ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = acStatus.MaxCurrent;
+
+        if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0) {
+            ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
+        }
+
+        ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
+        //  log_info("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
+//      log_info("GetAcStatus return fail. \n");
+}
+
+void GetAcAlarmCode()
+{
+    if (Query_AC_Alarm_Code(Uart5Fd, ADDR_AC_PLUG, &acAlarmCode) == PASS) {
+        CheckAlarmOccur();
+    }
+}
+
+uint8_t GetChargingEnergy()
+{
+    return Query_Charging_Energy(Uart5Fd, ADDR_AC_PLUG, &acChargingEnergy);
+}
+
+uint8_t GetChargingCurrent()
+{
+    return Query_Charging_Current(Uart5Fd, ADDR_AC_PLUG, &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_AC_PLUG, &ledStatus);
+}
+
+void SetLegacyReq(uint8_t _switch)
+{
+    Config_Legacy_Req(Uart5Fd, ADDR_AC_PLUG, _switch);
+}
+
+void SetCpDuty(uint8_t _value)
+{
+    Config_Ac_Duty(Uart5Fd, ADDR_AC_PLUG, _value);
+}
+
+void ChangeToCsuMode()
+{
+    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, ADDR_AC_PLUG);
+
+//  if (ac_chargingInfo[0]->IsModeChagned == PASS)
+//  {
+//      Config_Reset_MCU(Uart5Fd, ADDR_AC_PLUG);
+//  }
+}
+
+void ChangeStartOrStopDateTime(uint8_t 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(uint8_t 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);
+    }
+
+    log_info("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
+}
+
+void OcppStopTransation(uint8_t 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);
+    }
+
+    log_info("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
+}
+
+bool OcppRemoteStop(uint8_t 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;
+}
+
+uint8_t isModeChange()
+{
+    uint8_t 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();
+
+            uint8_t _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) {
+                    log_info("** 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) {
+                    log_info("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
+                    strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+                    log_info("** 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;
+            }
+        }
+    }
+}
+
+void ResetDetAlarmStatus(uint8_t gun)
+{
+    if (_chargingData[gun]->Type == _Type_Chademo) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
+        }
+    } else if (_chargingData[gun]->Type == _Type_GB) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
+        }
+    } else if (_chargingData[gun]->Type == _Type_CCS_2) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
+        }
+    }
+}
+
+int main(void)
+{
+    uint8_t i = 0;
+    if (InitShareMemory() == FAIL) {
+        log_error("InitShareMemory NG\n");
+        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(1);
+
+    if (Uart5Fd < 0) {
+        log_info("(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) {
+        log_info("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();
+            SetModelName_Relay(); //DS60-120 add
+            SetRtcData_Relay();
+            sleep(1);
+        }
+
+#if !defined NO_FAN_BOARD && !defined DD360ComBox
+        if (ShmFanModuleData->SelfTest_Comp == NO) {
+            GetFwAndHwVersion_Fan();
+            SetModelName_Fan();
+            SetRtcData_Fan();
+            sleep(1);
+            gettimeofday(&_priority_time, NULL);
+        }
+#endif //NO_FAN_BOARD
+
+#if !defined DD360ComBox
+        // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
+        if (ShmLedModuleData->SelfTest_Comp == NO) {
+#if defined DD360 ||defined DD360Audi
+            GetFwAndHwVersion_Led();
+            sleep(1);
+            gettimeofday(&_led_priority_time, NULL);
+#else
+            // 自檢階段
+            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;
+                }
+            }
+#endif //defined DD360 || defined DD360Audi
+        }
+#endif //!defined DD360ComBox
+
+        AcChargeTypeProcess();
+
+        if (ShmRelayModuleData->SelfTest_Comp == YES) {
+            // ==============優先權最高 10 ms ==============
+            // 輸出電壓
+            GetPersentOutputVol();
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            // 三相輸入電壓
+            GetPresentInputVol();
+            // 讀取當前 AC relay 狀態
+            regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+
+            GetRelayOutputStatus();
+#endif //!defined DD360 && !defined DD360Audi
+
+            for (i = 0; i < gunCount; i++) {
+                // Cable check (Set)
+                CableCheckDetected(i);
+
+                // check k1 k2 relay 狀態
+                CheckK1K2RelayOutput(i);
+
+                // 依據當前各槍的狀態選擇 搭上/放開 Relay
+                SetK1K2RelayStatus(i);
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+                if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
+                    CheckPhaseLossStatus(i);
+                }
+
+                CheckAcInputOvpStatus(i);
+#endif //!defined DD360 && !defined DD360Audi
+
+                if (_chargingData[i]->SystemStatus == S_IDLE) {
+                    _chargingData[i]->RelayWeldingCheck = NO;
+                    _isRelayWelding[i] = NO;
+                    _isOvpChkTimeFlag[i] = NO;
+                    ResetDetAlarmStatus(i); //DS60-120 add
+                }
+
+                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;
+
+                    //log_info("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 !defined NO_FAN_BOARD && !defined DD360ComBox
+        if (ShmFanModuleData->SelfTest_Comp == YES ||
+                strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+                ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0') {
+            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;
+
+                //log_info("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
+                SetFanModuleSpeed();
+            }
+        }
+#endif //NO_FAN_BOARD
+
+#if !defined DD360ComBox
+        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);
+            }
+        }
+#endif //defined DD360ComBox
+
+        usleep(10000);
+    }
+
+    return FAIL;
+}

+ 360 - 178
EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c

@@ -3,12 +3,14 @@
 #include <string.h>
 #include <stdint.h>
 #include <time.h>
+#include <unistd.h>
 
 #include <sys/time.h>
 #include <sys/timeb.h>
 
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
@@ -18,16 +20,18 @@ static struct SysInfoData *pSysInfo = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct RelayModuleData *ShmRelayModuleData = NULL;
 static struct PsuData *ShmPsuData = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
 
 static Relay outputRelay = {0};
 static Relay regRelay = {0};
 static int Uart5Fd = 0;
 
-static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
-static bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 static bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
 static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
@@ -35,15 +39,62 @@ static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTIT
 static struct timeval _close_ac_contactor;
 
 //------------------------------------------------------------------------------
-uint32_t GetTimeoutValue(struct timeval _sour_time)
+static void RunForceStopProcess(void)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    static bool isCriticalStop = NO;
+    static struct timeval  _psuCriticalStop;
+    uint32_t _timebuf;
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    if (isCriticalStop == NO) {
+        isCriticalStop = YES;
+        gettimeofday(&_psuCriticalStop, NULL);
+    } else {
+        _timebuf = GetTimeoutValue(_psuCriticalStop);
+
+        if (_timebuf < 0) {
+            gettimeofday(&_psuCriticalStop, NULL);
+        } else {
+            if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000)) {
+                isCriticalStop = NO;
+                pAlarmCode->AlarmEvents.bits.PsuFailureAlarm = NORMAL;
+            }
+        }
+    }
 }
 
-uint8_t getCommTargetID(uint8_t index)
+static void StopCheckRelayInfo(uint8_t _chkIndex)
+{
+    if (ShmDcCommonData->CheckRelayStatus[_chkIndex] != STOP) {
+        ShmDcCommonData->CheckRelayStatus[_chkIndex] = STOP;
+    }
+}
+
+static void StartCheckRelayInfo(uint8_t _chkIndex, uint8_t toState)
+{
+    // SMR1 *2 + SMR2 * 2 + Parallel * 2
+    static time_t lastCheckRelayStateTimer[6] = {0};
+    time_t nowTime = {0};
+    //uint8_t *pCheckRelayState = (uint8_t *)ShmDcCommonData->CheckRelayStatus[_chkIndex];
+
+    if (ShmDcCommonData->CheckRelayStatus[_chkIndex] == STOP) {
+        time(&lastCheckRelayStateTimer[_chkIndex]);
+        ShmDcCommonData->CheckRelayStatus[_chkIndex] = START;
+    } else {
+        time(&nowTime);
+
+        if (nowTime - lastCheckRelayStateTimer[_chkIndex] >= 1) {
+            //log_info("relay welding or driving fault = %d \n", _chkIndex);
+            if (toState == 1) {
+                ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
+            } else {
+                ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
+            }
+            lastCheckRelayStateTimer[_chkIndex] = nowTime;
+        }
+    }
+}
+
+static uint8_t getCommTargetID(uint8_t index)
 {
     uint8_t targetID = 0;
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
@@ -61,7 +112,23 @@ uint8_t getCommTargetID(uint8_t index)
     return targetID;
 }
 
-bool IsNoneMatchRelayStatus(void)
+static void MatchRelayStatus(void)
+{
+    // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
+    //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+    //pSysInfo->AcContactorStatus =
+    //    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;
+}
+
+static bool IsNoneMatchRelayStatus(void)
 {
     bool result = false;
 
@@ -80,47 +147,69 @@ bool IsNoneMatchRelayStatus(void)
         (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N)
 #endif //!defined DD360 && !defined DD360Audi
     ) {
-        /*if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
-            log_info("AC Contact Relay none match. \n");
-        }
+        result = true;
+    }
 
-        if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
-            log_info("CCS Precharge Relay none match. \n");
-        }
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
+        log_info("AC Contact Relay none match. \n");
+    }
 
-        if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
-            log_info("SMR1:D+ Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
+        log_info("CCS Precharge Relay none match. \n");
+    }
+#endif //
 
-        if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
-            log_info("SMR1:D- Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
+        //log_info("SMR1:D+ Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR1_P_STATUS, outputRelay.relay_event.bits.Gun1_P);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR1_P_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
-            log_info("SMR2:D+ Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
+        //log_info("SMR1:D- Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR1_N_STATUS, outputRelay.relay_event.bits.Gun1_N);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR1_N_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
-            log_info("SMR2:D- Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
+        //log_info("SMR2:D+ Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR2_P_STATUS, outputRelay.relay_event.bits.Gun2_P);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR2_P_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
-            log_info("Parallel:D+ Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
+        //log_info("SMR2:D- Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR2_N_STATUS, outputRelay.relay_event.bits.Gun2_N);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
-            log_info("Parallel:D- Relay none match. \n");
-        }*/
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
+        //log_info("Parallel:D+ Relay none match. \n");
+        StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
+    } else {
+        StopCheckRelayInfo(RELAY_PARA_P_STATUS);
+    }
 
-        result = true;
+    if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
+        //log_info("Parallel:D- Relay none match. \n");
+        StartCheckRelayInfo(RELAY_PARA_N_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_N);
+    } else {
+        StopCheckRelayInfo(RELAY_PARA_N_STATUS);
     }
+#endif //
 
     return result;
 }
 
-void SetParalleRelayStatus(void)
+static void SetParalleRelayStatus(void)
 {
-#if defined  DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
     return;
 #endif //!defined  DD360 || !defined DD360Audi || !defined DD360ComBox
 
@@ -179,7 +268,7 @@ void SetParalleRelayStatus(void)
     }
 }
 
-void GetGfdAdc(void)
+static void GetGfdAdc(void)
 {
     int gunIndex = 0;
     uint8_t targetID = 0;
@@ -205,9 +294,9 @@ void GetGfdAdc(void)
             targetID = getCommTargetID(gunIndex);
 
             if (targetID == 0x01) {
-                if (gfd_adc.result_conn1 == GFD_WARNING) {
-                    gfd_adc.result_conn1 = GFD_PASS;
-                }
+                //if (gfd_adc.result_conn1 == GFD_WARNING) {
+                //    gfd_adc.result_conn1 = GFD_PASS;
+                //}
 
                 pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn1;
                 //log_info("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
@@ -234,9 +323,9 @@ void GetGfdAdc(void)
                     }
                 }
             } else if (targetID == 0x02) {
-                if (gfd_adc.result_conn2 == GFD_WARNING) {
-                    gfd_adc.result_conn2 = GFD_PASS;
-                }
+                //if (gfd_adc.result_conn2 == GFD_WARNING) {
+                //    gfd_adc.result_conn2 = GFD_PASS;
+                //}
                 pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn2;
                 if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
                     log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
@@ -327,8 +416,8 @@ void CheckAcInputOvpStatus(uint8_t index)
     if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
             pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
             pAlarmCode->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 ((pDcChargingInfo->SystemStatus >= S_PREPARNING && pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+//              (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
 //      {
 //          if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC)
 //          {
@@ -338,7 +427,7 @@ void CheckAcInputOvpStatus(uint8_t index)
 //              {
 //                  log_info("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
 //                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
+//                  pDcChargingInfo->StopChargeFlag = YES;
 //              }
 //
 //          }
@@ -350,7 +439,7 @@ void CheckAcInputOvpStatus(uint8_t index)
 //              {
 //                  log_info("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
 //                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
+//                  pDcChargingInfo->StopChargeFlag = YES;
 //              }
 //          }
 //      }
@@ -360,6 +449,34 @@ void CheckAcInputOvpStatus(uint8_t index)
     }
 }
 
+//void CheckOutputVolNoneMatchFire(uint8_t index)
+//{
+//    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+//
+//    if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
+//            (pDcChargingInfo->Type == _Type_Chademo ||
+//             pDcChargingInfo->Type == _Type_CCS_2 ||
+//             pDcChargingInfo->Type == _Type_GB)) {
+//        if (((pDcChargingInfo->PresentChargingVoltage * 10) < pDcChargingInfo->FireChargingVoltage - 300) ||
+//                ((pDcChargingInfo->PresentChargingVoltage * 10) > pDcChargingInfo->FireChargingVoltage + 300)) {
+//            if (!_isOutputNoneMatch[index]) {
+//                _isOutputNoneMatch[index] = YES;
+//                gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
+//            } else {
+//                if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
+//                    /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
+//                            index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
+//                    log_error("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f \n",
+//                            index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
+//                    pDcChargingInfo->StopChargeFlag = YES;*/
+//                }
+//            }
+//        } else {
+//            _isOutputNoneMatch[index] = NO;
+//        }
+//    }
+//}
+
 void CheckPhaseLossStatus(uint8_t index)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
@@ -453,13 +570,13 @@ void SetK1K2RelayStatus(uint8_t index)
         break;
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
-            if (pRegPreChargingState->CcsPrecharge == NO) {
-                pOutputPreChargingState->CcsPrecharge = YES;
-            } else if (pRegPreChargingState->CcsPrecharge == YES) {
-                pRegGunPNState->GunP = NO;
-            }
-        }
+        //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+        //    if (pRegPreChargingState->CcsPrecharge == NO) {
+        //        pOutputPreChargingState->CcsPrecharge = YES;
+        //    } else if (pRegPreChargingState->CcsPrecharge == YES) {
+        //        pRegGunPNState->GunP = NO;
+        //    }
+        //}
         break;
 
     case S_CCS_PRECHARGE_ST1:
@@ -467,13 +584,13 @@ void SetK1K2RelayStatus(uint8_t index)
         break;
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
-            if (pRegGunPNState->GunP == NO) {
-                pOutputGunPNState->GunP = YES;
-            } else if (pRegGunPNState->GunP == YES) {
-                pOutputPreChargingState->CcsPrecharge = NO;
-            }
-        }
+        //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+        //    if (pRegGunPNState->GunP == NO) {
+        //        pOutputGunPNState->GunP = YES;
+        //    } else if (pRegGunPNState->GunP == YES) {
+        //        pOutputPreChargingState->CcsPrecharge = NO;
+        //    }
+        //}
         break;
     }
 }
@@ -603,9 +720,10 @@ void CableCheckDetected(uint8_t index)
                 (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
                  pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
            ) {
-            if ((pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) &&
-                    (pDcChargingInfo->RelayWeldingCheck == YES)
-               ) {
+            //if ((pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) &&
+            //        (pDcChargingInfo->RelayWeldingCheck == YES)
+            //   ) {
+            if (pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) {
                 SetGfdConfig(targetID, GFD_CABLECHK);
             } else if ((pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0) &&
                        (pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
@@ -987,7 +1105,7 @@ void GetFwAndHwVersion_Relay(void)
     }
 }
 
-void outputRelayInit(int fd)
+static void outputRelayInit(int fd)
 {
     memset((uint8_t *)&outputRelay, 0, sizeof(Relay));
 
@@ -996,7 +1114,7 @@ void outputRelayInit(int fd)
     }
 }
 
-void RelayBoardTaask(int uartFD)
+void RelayBoardTask(int uartFD)
 {
     pid_t pid = fork();
 
@@ -1004,21 +1122,17 @@ void RelayBoardTaask(int uartFD)
         bool isCharging = false;
         bool isStopChargingCount = false;
         uint8_t i = 0;
-        int fd = GetInternalFd();
         int isContinue = 1;
         struct ChargingInfoData *pDcChargingInfo = NULL;
 
-        if (CreateAllCsuShareMemory() == FAIL) {
-            log_error("Relay Board create share memory failed\r\n");
-        }
-        MappingGunChargingInfo("Relay Board Task");
-
         //share memory mapping
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
         ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
         ShmPsuData = (struct PsuData *)GetShmPsuData();
+        ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonInfo();
+        ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
 
         Uart5Fd = uartFD;
 
@@ -1032,138 +1146,206 @@ void RelayBoardTaask(int uartFD)
                 SetModelName_Relay(); //DS60-120 add
                 SetRtcData_Relay();
                 sleep(1);
-            } else {
-                // ==============優先權最高 10 ms ==============
-                // 輸出電壓
-                GetPersentOutputVol();
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                // 三相輸入電壓
-                GetPresentInputVol();
-                // 讀取當前 AC relay 狀態
-                regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
+                continue;
+            }
 
-                GetRelayOutputStatus();
+            // ==============優先權最高 10 ms ==============
+            // 輸出電壓
+            GetPersentOutputVol();
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            // 三相輸入電壓
+            GetPresentInputVol();
 #endif //!defined DD360 && !defined DD360Audi
 
-                for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+            // 讀取當前 AC relay 狀態
+            regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
 
-                    // Cable check (Set)
-                    CableCheckDetected(i);
+            GetRelayOutputStatus();
 
-                    // check k1 k2 relay 狀態
-                    CheckK1K2RelayOutput(i);
+            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
-                    // 依據當前各槍的狀態選擇 搭上/放開 Relay
-                    SetK1K2RelayStatus(i);
+                // Cable check (Set)
+                CableCheckDetected(i);
+
+                // check k1 k2 relay 狀態
+                CheckK1K2RelayOutput(i);
+
+                // 依據當前各槍的狀態選擇 搭上/放開 Relay
+                SetK1K2RelayStatus(i);
 
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    if (pSysConfig->PhaseLossPolicy == YES) {
-                        CheckPhaseLossStatus(i);
-                    }
+                if (pSysConfig->PhaseLossPolicy == YES) {
+                    CheckPhaseLossStatus(i);
+                }
 
-                    CheckAcInputOvpStatus(i);
+                CheckAcInputOvpStatus(i);
 #endif //!defined DD360 && !defined DD360Audi
 
-                    if (pDcChargingInfo->SystemStatus == S_IDLE) {
-                        pDcChargingInfo->RelayWeldingCheck = NO;
-                        _isRelayWelding[i] = NO;
-                        _isOvpChkTimeFlag[i] = NO;
-                        ResetDetAlarmStatus(i); //DS60-120 add
-                    }
+                if (pDcChargingInfo->SystemStatus == S_IDLE ||
+                        pDcChargingInfo->SystemStatus == S_RESERVATION ||
+                        pDcChargingInfo->SystemStatus == S_MAINTAIN) {
+                    //pDcChargingInfo->RelayWeldingCheck = NO;
+                    //_isRelayWelding[i] = NO;
+                    _isOvpChkTimeFlag[i] = NO;
+                    //ResetDetAlarmStatus(i); //DS60-120 add
+                }
 
-                    if (pDcChargingInfo->SystemStatus == S_BOOTING ||
-                            (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
-                             pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
-                            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                             pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                            pSysInfo->WaitForPlugit == YES ||
-                            (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
-                             pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)) {
-                        pDcChargingInfo->IsReadyToCharging = YES;
-                        isCharging = true;
-
-                        // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
-                        //if (pDcChargingInfo->Type == _Type_GB) {
-                        //    if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                        //            pDcChargingInfo->RelayWeldingCheck == NO) {
-                        //        CheckRelayWeldingStatus(i);
-                        //    }
-                        //} else {
-                        pDcChargingInfo->RelayWeldingCheck = YES;
-                        //}
-
-                        if (pDcChargingInfo->SystemStatus == S_CHARGING) {
-                            CheckOutputPowerOverCarReq(i);
-                            //CheckOutputVolNoneMatchFire(i);
-                        } else {
-                            _isOutputNoneMatch[i] = NO;
-                        }
-                    } else {
-                        pDcChargingInfo->IsReadyToCharging = NO;
+                if (pDcChargingInfo->SystemStatus == S_BOOTING ||
+                        (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
+                         pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
+                        (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
+                        pSysInfo->WaitForPlugit == YES ||
+                        (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
+                         pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)
+                   ) {
+                    pDcChargingInfo->IsReadyToCharging = YES;
+                    isCharging = true;
+
+                    // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
+                    //if (pDcChargingInfo->Type == _Type_GB) {
+                    //    if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
+                    //            pDcChargingInfo->RelayWeldingCheck == NO) {
+                    //        CheckRelayWeldingStatus(i);
+                    //    }
+                    //} else {
+                    //pDcChargingInfo->RelayWeldingCheck = YES;
+                    //}
+
+                    if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+                        CheckOutputPowerOverCarReq(i);
+                        //CheckOutputVolNoneMatchFire(i);
                     }
+                    /*else {
+                        _isOutputNoneMatch[i] = NO;
+                    }*/
+                } else {
+                    pDcChargingInfo->IsReadyToCharging = NO;
                 }
+            }
 
-                // Cable check (Get)
-                GetGfdAdc();
+            // Cable check (Get)
+            GetGfdAdc();
 
-                // 橋接 relay
-                SetParalleRelayStatus();
+            // 橋接 relay
+            SetParalleRelayStatus();
 
-                // 搭上 AC Contactor
-                //if (isCharging) {
-                //    outputRelay.relay_event.bits.AC_Contactor = YES;
-                //} else {
-                //    outputRelay.relay_event.bits.AC_Contactor = NO;
-                //}
+            // 搭上 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;
+            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 (!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 ((outputRelay.relay_event.bits.AC_Contactor == YES &&
+                            GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
+                        outputRelay.relay_event.bits.AC_Contactor = NO;
                     }
                 }
+            }
+
+            if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
+                outputRelay.relay_event.bits.AC_Contactor = NO;
+            }
+
+            if (pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == ABNORMAL) {
+                RunForceStopProcess();
+                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 = pSysInfo->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;
+
+                    //MatchRelayStatus();
+                    //log_info("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 (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
-                    outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
                 }
+            } /*else {
+                    log_info("======== Relay Status Start========\n");
+                    if (regRelay.relay_event.bits.AC_Contactor == YES) {
+                        log_info("AC Power : ON \n");
+                    } else {
+                        log_info("AC Power : OFF \n");
+                    }
 
-                // 搭上/鬆開 Relay
-                if (IsNoneMatchRelayStatus()) {
-                    if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
-                        //regRelay.relay_event.bits.AC_Contactor = pSysInfo->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;
-
-                        //log_info("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 (regRelay.relay_event.bits.Gun1_P == YES) {
+                        log_info("Conn1(+) : ON \n");
+                    } else {
+                        log_info("Conn1(+) : OFF \n");
+                    }
 
+                    if (regRelay.relay_event.bits.Gun1_N == YES) {
+                        log_info("Conn1(-) : ON \n");
+                    } else {
+                        log_info("Conn1(-) : OFF \n");
                     }
-                }
-            }
+
+                    if (regRelay.relay_event.bits.Gun2_P == YES) {
+                        log_info("Conn2(+) : ON \n");
+                    } else {
+                        log_info("Conn2(+) : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.Gun2_N == YES) {
+                        log_info("Conn2(-) : ON \n");
+                    } else {
+                        log_info("Conn2(-) : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.CCS_Precharge == YES) {
+                        log_info("Precharge : ON \n");
+                    } else {
+                        log_info("Precharge : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
+                        log_info("Parallel(+) : ON \n");
+                    } else {
+                        log_info("Parallel(+) : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
+                        log_info("Parallel(-) : ON \n");
+                    } else {
+                        log_info("Parallel(-) : OFF \n");
+                    }
+                    log_info("======== Relay Status End========\n");
+                }*/
         }
         usleep(100000);
     }

+ 3 - 3
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -295,16 +295,16 @@ static void checkChillerStatus(Gpio_out *gpio)
         pDcChargingInfo = (struct ChargingInfoData *)ChargingData[gunIndex];
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
-        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) {
+        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
             pChillerInfo->ChillerSwitch = YES;
             pChillerInfo->ChillerOnTime = time((time_t *)NULL);
         } else {
             if (pChillerInfo->ChillerSwitch == YES) {
-                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) {
+                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) { //判斷如果還是大於100A不變動
                     pChillerInfo->ChillerSwitch = YES;
                     pChillerInfo->ChillerOnTime = time((time_t *)NULL);
                 } else {
-                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
+                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) { //5分鐘後停止
                         pChillerInfo->ChillerSwitch = NO;
                     } else {
                         pChillerInfo->ChillerSwitch = YES;

+ 12 - 6
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -1119,16 +1119,22 @@ 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) {
+                uint8_t _GunIndex = 0;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
                 _chargingData[0]->ConnectorTemp = atoi(newString[2]);
                 printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ConnectorTemp);
             } else if (strcmp(newString[1], "1") == 0) {
+                uint8_t _GunIndex = 1;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
                 _chargingData[1]->ConnectorTemp = atoi(newString[2]);
                 printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
             }

+ 5 - 3
EVSE/Projects/DD360/Apps/Readme.md

@@ -1,7 +1,9 @@
 ## merge master
-   在merge master後,需要在執行一次DD360Audi/Apps/Script/createDefine.sh
-   因DD360相關的projects不是使用Projects/define.h,compoler 沒問題後
-   需要執行replaceOtherDD360Project.sh
+    1. merge master,fixed conflict完成。
+    2. 執行DD360Audi/Apps/Script/createDefine.sh
+    3. compiler 確認沒有問題。
+    4. 執行DD360Audi/Apps/Script/replaceOtherDD360Project.sh
+    5. 重新commit。
 
 ## DD360 和 DD360ComBox 都是用DD360Audi開發和修改,完成後,執行
    DD360Audi/Apps/Script/replaceOtherDD360Project.sh

+ 1 - 1
EVSE/Projects/DD360/Apps/Script/createDefine.sh

@@ -17,7 +17,7 @@ InfoCode="char InfoStatusCode\[384\]\[6\]";
 
 finalString="#endif // DEFINE_H_";
 
-count=500;
+count=512;
 
 rm -rf $workPath/define.h;
 rm -rf $workPath/define.c;

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

@@ -9,3 +9,7 @@ cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360/ModelNameLis
 rm -rf $ProjectPath/DD360ComBox/Apps/;
 cp -r  $ProjectPath/DD360Audi/Apps/  $ProjectPath/DD360ComBox/Apps;
 cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360ComBox/ModelNameList.txt;
+
+git add $ProjectPath/DD360;
+git add $ProjectPath/DD360Audi;
+git add $ProjectPath/DD360ComBox;

+ 194 - 0
EVSE/Projects/DD360/Apps/SelectGun/SelectGun.c

@@ -0,0 +1,194 @@
+#if 0
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+#include "../timeout.h"
+#include "../main.h"
+
+#include "SelectGun.h"
+
+//------------------------------------------------------------------------------
+int WaitAuthorPageState(void)
+{
+    int ret = FAIL;
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+#if !defined DD360Audi
+    return PASS;
+#endif //!defined DD360Audi
+
+    if (pSysInfo->SystemPage != _LCM_AUTHORIZING &&
+            pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
+            pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL) {
+        ret = PASS;
+    }
+
+    return ret;
+}
+
+void destroySelGun(uint8_t curGun)
+{
+    uint8_t i = 0;
+
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+    struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+
+    //for status timeout
+    if (curGun == DESTROY_ALL_SEL) {
+        pSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
+        pSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+        log_info("destroy all gun = %d, %d\r\n",
+                 pSelectGunInfo->SelGunInfo.LeftGun,
+                 pSelectGunInfo->SelGunInfo.RightGun);
+        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+            StopGunInfoTimeoutDet(i);
+            memset(&pSelectGunInfo->PricesInfo[i], 0, sizeof(PricesInfo));
+        }
+        pSysInfo->CurGunSelected = 0;
+        strcpy((char *)pSysConfig->UserId, "");
+        //changeLcmPage(_LCM_SELECT_GUN);
+        return;
+    }
+
+    //for charging timeout or complete
+    if ((curGun == LEFT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
+        if (pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
+                pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
+            pSysInfo->SystemPage = _LCM_SELECT_GUN;
+        }
+        pSelectGunInfo->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", pSysInfo->SystemPage);
+        //if (pSysInfo->SystemPage == pSysInfo->SystemPage) {
+        log_info("clear left balance\r\n");
+        memset(&pSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
+        pSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
+        //}
+    }
+
+    if ((curGun == RIGHT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
+        if (pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
+                pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
+            pSysInfo->SystemPage = _LCM_SELECT_GUN;
+        }
+        pSelectGunInfo->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", pSysInfo->SystemPage);
+        //if (pSysInfo->SystemPage == pSysInfo->SystemPage) {
+        log_info("clear right balance\r\n");
+        memset(&pSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
+        pSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
+        //}
+    }
+}
+
+int waitRightGunPlugIt(uint8_t curGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+
+    if ((curGun == RIGHT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+int waitLeftGunPlugIt(uint8_t curGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if ((curGun == LEFT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+void setSelGunWaitToAuthor(uint8_t curSel)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if (curSel == LEFT_GUN_NUM && pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
+        pSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
+        //printf("setSelGunWaitToAuthor left\r\n");
+        StopGunInfoTimeoutDet(curSel);
+    } else if (curSel == RIGHT_GUN_NUM && pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
+        pSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
+        //printf("setSelGunWaitToAuthor right\r\n");
+        StopGunInfoTimeoutDet(curSel);
+    }
+}
+
+int getConfirmSelectedGun(uint8_t curSel)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if (((curSel == LEFT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
+            ((curSel == RIGHT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+void confirmSelGun(uint8_t selGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if (selGun == LEFT_GUN_NUM) {
+        pSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+        StopGunInfoTimeoutDet(selGun);
+        //printf("confirmSelGun left\r\n");
+    } else if (selGun == RIGHT_GUN_NUM) {
+        pSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+        StopGunInfoTimeoutDet(selGun);
+        //printf("confirmSelGun right\r\n");
+    }
+
+    pSysInfo->SystemPage = _LCM_IDLE;
+
+    StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
+}
+#endif //0

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

@@ -96,4 +96,13 @@ typedef struct StAudiCustInfo {
     uint8_t Reserved[2];
 } SelectGunInfo;
 
+//------------------------------------------------------------------------------
+//int WaitAuthorPageState(void);
+//void destroySelGun(uint8_t curGun);
+//int waitRightGunPlugIt(uint8_t curGun);
+//int waitLeftGunPlugIt(uint8_t curGun);
+//void setSelGunWaitToAuthor(uint8_t curSel);
+//int getConfirmSelectedGun(uint8_t curSel);
+//void confirmSelGun(uint8_t selGun);
+
 #endif /* _SELECT_GUN_H_ */

+ 72 - 31
EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c

@@ -12,40 +12,64 @@
 //#include "../AudiCust.h"
 #include "../SelectGun/SelectGun.h"
 #include "../common.h"
-//#include "../log/log.h"
+#include "../Log/log.h"
 #include "../Config.h"
 #include "shmMem.h"
 
 //------------------------------------------------------------------------------
 static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
-//static struct SysInfoData *ShmSysInfoData           = NULL;
-//static struct SysConfigData *ShmSysConfigData       = NULL;
-//static struct WARNING_CODE_INFO *SysWarningInfo     = NULL;
+//static struct SysInfoData *ShmSysInfoData = NULL;
+//static struct SysConfigData *ShmSysConfigData = NULL;
+//static struct WARNING_CODE_INFO *SysWarningInfo = NULL;
 
-static struct StatusCodeData *ShmStatusCodeData     = NULL;
-//static struct AlarmCodeData *ShmAlarmCodeData       = NULL;
-//static struct FaultCodeData *ShmFaultCodeData       = NULL;
-//static struct InfoCodeData  *ShmInfoCodeData        = NULL;
+static struct StatusCodeData *ShmStatusCodeData = NULL;
+//static struct AlarmCodeData *ShmAlarmCodeData = NULL;
+//static struct FaultCodeData *ShmFaultCodeData = NULL;
+//static struct InfoCodeData  *ShmInfoCodeData = NULL;
 
-static struct PsuData *ShmPsuData                   = NULL;
+static struct PsuData *ShmPsuData = NULL;
 
-static struct CHAdeMOData *ShmCHAdeMOData           = NULL;
-static struct GBTData *ShmGBTData                   = NULL;
-static struct CcsData *ShmCcsData                   = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct CcsData *ShmCcsData = NULL;
 
-static struct PrimaryMcuData *ShmPrimaryMcuData     = NULL;
-static struct FanModuleData *ShmFanModuleData       = NULL;
-static struct RelayModuleData *ShmRelayModuleData   = NULL;
-static struct LedModuleData *ShmLedModuleData       = NULL;
-static struct OCPP16Data *ShmOCPP16Data             = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static struct FanModuleData *ShmFanModuleData = NULL;
+static struct RelayModuleData *ShmRelayModuleData = NULL;
+static struct LedModuleData *ShmLedModuleData = NULL;
+static struct OCPP16Data *ShmOCPP16Data = NULL;
 
-static SelectGunInfo *ShmSelectGunInfo              = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
+static DcCommonInfo *ShmDcCommonInfo = NULL;
 
 static struct ChargingInfoData *DcChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {NULL};
 static struct ChargingInfoData *AcChargingData[AC_QUANTITY] = {NULL};
 
 static GunIndexInfo gGunIndexInfo = {0};
 
+//struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+//struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+//struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+//struct AlarmCodeData *pAlarmCode =(struct AlarmCodeData *)GetShmAlarmCodeData();
+//struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+//struct FaultCodeData *pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+
+//struct PsuData *ShmPsuData = (struct PsuData *)GetShmPsuData();
+
+//struct CHAdeMOData *ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
+//struct GBTData *ShmGBTData = (struct GBTData *)GetShmGBTData();
+//struct CcsData *ShmCcsData = (struct CcsData *)GetShmCcsData();
+
+//struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+//struct FanModuleData *ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
+//struct RelayModuleData *ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
+//struct LedModuleData *ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
+//struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+
+//SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+//DcCommonInfo *ShmDcCommonInfo = (DcCommonInfo *)GetShmDcCommonInfo();
+
 //------------------------------------------------------------------------------
 void *GetGunIndexInfo(void)
 {
@@ -282,6 +306,15 @@ void *GetShmSelectGunInfo(void)
     return ShmSelectGunInfo;
 }
 
+void *GetShmDcCommonInfo(void)
+{
+    if (ShmDcCommonInfo == NULL) {
+        return NULL;
+    }
+
+    return ShmDcCommonInfo;
+}
+
 //------------------------------------------------------------------------------
 /*static void initialGunIndexToUnUse(void)
 {
@@ -519,18 +552,18 @@ int InitSelectGunShmMem(void)
     return PASS;
 }
 
-//int InitCommonShmMem(void)
-//{
-//    int MeterSMId = FAIL;
-//
-//    if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0) {
-//        return FAIL;
-//    } else if ((ShmDcCommonInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-//        return FAIL;
-//    }
-//
-//    return PASS;
-//}
+int InitCommonShmMem(void)
+{
+    int MeterSMId = FAIL;
+
+    if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
+        return FAIL;
+    } else if ((ShmDcCommonInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        return FAIL;
+    }
+
+    return PASS;
+}
 
 //int InitCSUMeterShmMem(void)
 //{
@@ -717,7 +750,7 @@ void ClearAllShmMemParameter(void)
     //memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
 
     //memset(ShmCsuMeterInfo, 0, sizeof(struct MeterInformation));
-    //memset(ShmDcCommonInfo, 0, sizeof(struct DcCommonInformation));
+    memset(ShmDcCommonInfo, 0, sizeof(DcCommonInfo));
 
 #if defined DD360 || defined DD360Audi || defined DD360ComBox
     memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
@@ -953,6 +986,7 @@ bool MappingGunChargingInfo(char *whichTask)
                  pSysConfig->TotalConnectorCount,
                  pSysConfig->AcConnectorCount);
     }
+
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
         findDcChargingInfoData(gunIndex);
     }
@@ -1027,6 +1061,13 @@ int CreateAllCsuShareMemory(void)
         return ret;
     }
 
+    if ((ret = InitSelectGunShmMem()) == FAIL) {
+        return ret;
+    }
+
+    if ((ret = InitCommonShmMem()) == FAIL) {
+        return ret;
+    }
     //ClearAllShmMemParameter();
 
     //MappingChargingInfoData();

+ 2 - 0
EVSE/Projects/DD360/Apps/ShareMemory/shmMem.h

@@ -66,6 +66,8 @@ void MappingChargingInfoData(void);
 
 void *GetShmSelectGunInfo(void);
 
+void *GetShmDcCommonInfo(void);
+
 
 int InitSelectGunShmMem(void);
 #endif /* _CSU_SHARE_MEMORY_H_ */

+ 356 - 282
EVSE/Projects/DD360/Apps/main.c

@@ -306,6 +306,7 @@ static void checkGunOTPState(uint8_t _index)
     case _Type_CCS_2:
         // CCS 不管甚麼輸出都會有槍溫偵測!!~
         if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            ResetChargerAlarmCode(_index, "011019");
             if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
                 RecordAlarmCode(_index, "012230");
             } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
@@ -313,7 +314,7 @@ static void checkGunOTPState(uint8_t _index)
                 ResetChargerAlarmCode(_index, "012230");
             }
 
-            ResetChargerAlarmCode(_index, "011019");
+            //ResetChargerAlarmCode(_index, "011019");
         } else {
             // 沒接上 Sensor or 異常
             RecordAlarmCode(_index, "011019");
@@ -1333,19 +1334,19 @@ int isRouteFail()
     return result;
 }
 
-static void eth0Down(void)
-{
-    char cmdbuf[256] = {0};
-
-    sprintf(cmdbuf, "/sbin/ifconfig eth0 down");
-}
-
-static void eth0Up(void)
-{
-    char cmdbuf[256] = {0};
+//static void eth0Down(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 down");
+//}
 
-    sprintf(cmdbuf, "/sbin/ifconfig eth0 %s up", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
-}
+//static void eth0Up(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 %s up", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
+//}
 
 int isReachableInternet()
 {
@@ -1834,6 +1835,13 @@ void InitialShareMemoryInfo()
 
     InitialGunIndexToUnUse();//DS60-120 add
 
+    //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
+    //ShmDcCommonData->psuKeepCommunication = NO;
+    //ShmDcCommonData->acContactSwitch = NO;
+    ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
+    ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
+    //ShmDcCommonData->LcmFwVersion = 0;
+
     ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
     ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
 
@@ -2600,30 +2608,39 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
 
 void RecordAlarmCode(uint8_t gunIndex, char *code)
 {
-    strncpy((char *)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; }
-
-    if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES; }
-    if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES; }
-    if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES; }
-    if (strcmp(code, "012296") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES; }
-    if (strcmp(code, "012297") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES; }
-    if (strcmp(code, "012298") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES; }
-    if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES; }
-    if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES; }
-    if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES; }
-    if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES; }
-    if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES; }
-    if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES; }
-    if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
-    if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
-    if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL) {
+        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; }
+
+    if (strcmp(code, "012234") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES; }
+    else if (strcmp(code, "012235") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES; }
+    else if (strcmp(code, "012236") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES; }
+    else if (strcmp(code, "012288") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES; }
+    else if (strcmp(code, "012289") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES; }
+    else if (strcmp(code, "012290") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES; }
+
+    else if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES; }
+    else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES; }
+    else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES; }
+    else if (strcmp(code, "012296") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES; }
+    else if (strcmp(code, "012297") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES; }
+    else if (strcmp(code, "012298") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES; }
+    else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES; }
+    else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES; }
+    else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES; }
+    else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES; }
+    else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES; }
+    else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES; }
+    else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
 }
 
 void RecordWarningCode(uint8_t gunIndex, char *code)
@@ -2637,6 +2654,7 @@ void RecordWarningCode(uint8_t gunIndex, char *code)
 
 void ReleaseAlarmCode(uint8_t gunIndex)
 {
+#if 0
     bool isCleanCheck = false;
     char code[7];
 
@@ -2715,6 +2733,59 @@ void ReleaseAlarmCode(uint8_t gunIndex)
             }
         }
     }
+#endif //0
+
+    // 回 idle 後主要清除  GFD Trip、UVP、OVP、GFD Warning
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL) {
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+        }
+    }
+
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    }
 
     if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
             strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
@@ -2863,16 +2934,20 @@ void ReleaseEmsOccureByString(uint8_t index, char *code)
 
     if (strncmp(code, "042251", 6) == 0 ) {
         isTrigger = true;
-    } else if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
+    } 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) {
+    } 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) {
+    } 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) {
+    } else if (strncmp(code, "012238", 6) == 0 &&
+               ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
         isTrigger = true;
         ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
     }
@@ -3126,6 +3201,7 @@ void ChkPrimaryStatus()
 //===============================================
 void CheckErrorOccurStatus(uint8_t index)
 {
+#if 0
     // 小板
     if (chargingInfo[index]->Type == _Type_Chademo) {
         if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
@@ -3146,6 +3222,7 @@ void CheckErrorOccurStatus(uint8_t index)
 //      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
 //          BoardErrOccurByString(index, "012235");
     }
+#endif //0
 
     // RB
     if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
@@ -3217,31 +3294,31 @@ void CheckErrorOccurStatus(uint8_t index)
     }
 
     //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 (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((char *)chargingInfo[index]->ConnectorAlarmCode) == 0) {
@@ -4017,6 +4094,7 @@ int CheckUpdateProcess(void)
     uint8_t retFail = 0;
     uint8_t index = 0;
     uint8_t target = 0;
+    char Buf[256];
     char *new_str = NULL;
     uint8_t *ptr = NULL;
     int fd = 0;
@@ -4083,14 +4161,41 @@ int CheckUpdateProcess(void)
                 case 0x10000008:
                 case 0x10000009:
                 case 0x1000000A:
+                    CanFd = InitCanBus();
+                    if (CanFd > 0) {
+                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
+                            if (chargingInfo[index]->Type == _Type_CCS_2) {
+                                uint8_t targetID = chargingInfo[index]->Evboard_id;
+
+                                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1 &&
+                                        ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+                                    targetID += 1;
+                                }
+
+                                system("echo 3 > /proc/sys/vm/drop_caches");
+                                sleep(2);
+                                log_info("Upgrade CCS Processing..target id = %d \n", targetID);
+                                if (Upgrade_CCS(CanFd, Type, targetID, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL) {
+                                    log_info("Upgrade CCS Failed \n");
+                                    retFail++;
+                                } else {
+                                    retSucc++;
+                                }
+                            }
+                        }
+                        close(CanFd);
+                    }
+                    memset(Buf, 0, sizeof(Buf));
+                    sprintf(Buf, "rm -rvf /mnt/%s", new_str);
+                    system(Buf);
                     //isPass = true;
+#if 0
                     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;
@@ -4111,6 +4216,7 @@ int CheckUpdateProcess(void)
                         retSucc++;
                     }
                     //return isPass;
+#endif //0
                     break;
 
                 case 0x10000006:
@@ -5634,35 +5740,14 @@ void TheEndCharging(uint8_t gun_index)
 
 void UpdateErrorCodeToOcpp(uint8_t 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) {
+        //if (strlen((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) {
+        //} else if (strlen((char *)chargingInfo[index]->EvConnAlarmCode) == EQUAL) {
         strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
         strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->EvConnAlarmCode);
     }
@@ -5691,45 +5776,100 @@ void AdjustChargerCurrent()
              );
 }
 
-#if METER_ENABLE
-void CheckStatusOfMeter()
+void ResetDetAlarmStatus(uint8_t gun)
 {
-    // 橋接如果搭上~ 則兩個電表都是使用狀態
-    // 如橋接沒有搭上~ 則視該火線 relay 狀態為電表使用狀態
-    if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
-        for (uint8_t mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
-            ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
+    if (chargingInfo[gun]->Type == _Type_Chademo) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
         }
-    } else {
-        for (uint8_t 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;
-            }
+    } 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;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    return;
+#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
+
+    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
+    return ;
+#endif //!defined DD360ComBox
+
+    if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
+            (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
+       ) {
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
+        strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
+    }
+}
+
+static bool PrecheckIsPass(uint8_t gun_index)
+{
+    bool result = true;
+
+    // relay welding or driving 是反向
+    result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
+
+    return result;
+}
+
+static void ReviewCriticalAlarm(void)
+{
+    if (ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
+            ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
+            ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
+            ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
+            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo
+       ) {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = 2;
+    } else {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
     }
 }
 
-void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
+static void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
 {
     // relay welding fault then stop the charging process.
     uint8_t 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) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[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) {
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[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) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[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) {
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
             faultCode = RELAY_STATUS_ERROR_DRIVING;
         }
     }
@@ -5737,11 +5877,11 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
     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) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[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) {
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
             faultCode = RELAY_STATUS_ERROR_DRIVING;
         }
     }
@@ -5749,11 +5889,11 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
     if (faultCode == RELAY_STATUS_ERROR_WELDING) {
         // welding
         if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
+            RecordAlarmCode(gun_index, "011011");
         } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
+            RecordAlarmCode(gun_index, "011015");
         } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
+            RecordAlarmCode(gun_index, "011013");
         }
 
         ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
@@ -5761,11 +5901,11 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
     } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
         // driving
         if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
+            RecordAlarmCode(gun_index, "011012");
         } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
+            RecordAlarmCode(gun_index, "011016");
         } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
+            RecordAlarmCode(gun_index, "011014");
         }
 
         ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
@@ -5774,105 +5914,19 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
         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(uint8_t gun_index)
-{
-    bool result = true;
-
-    // relay welding or driving 是反向
-    if (result) {
-        result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
-    }
-
-    return result;
-}
-#endif //METER_ENABLE
-
-void ResetDetAlarmStatus(uint8_t 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;
-
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    return;
-#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
-
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == 0) {
-            EmcOccureByString("042267");
+        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
+            ResetChargerAlarmCode(gun_index, "011012");
+            ResetChargerAlarmCode(gun_index, "011011");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            ResetChargerAlarmCode(gun_index, "011014");
+            ResetChargerAlarmCode(gun_index, "011013");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            ResetChargerAlarmCode(gun_index, "011016");
+            ResetChargerAlarmCode(gun_index, "011015");
         }
     }
 }
 
-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;
@@ -6042,16 +6096,23 @@ int main(void)
             gettimeofday(&_cmdMainPriority_time, NULL);
         }
 
+        // 確認當前錯誤 Level = 2 ?
+        ReviewCriticalAlarm();
         gEvBoardErr.GunErrMessage = 0;
 
         for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
             autoStartChargingForComBox(gun_index); //for DD360ComBox
 
+            CheckGpioInStatus();
+
+            CheckErrorOccurStatus(gun_index);
+
+            // 確認 Relay Welding or Driving Fault
+            CheckRelayWeldingOrDrivingFault(gun_index);
+
             // 收集各槍的錯誤狀態
             collectError(gun_index);
 
-            CheckGpioInStatus();
-            CheckErrorOccurStatus(gun_index);
             ChkOcppStatus(gun_index);
 
             if ((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
@@ -6171,84 +6232,97 @@ int main(void)
                         ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
                     }
 
-                    if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
-                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
+                    if (PrecheckIsPass(gun_index)) {
+
+                        if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+                            setChargerMode(gun_index, MODE_IDLE);
+                        }
+
+                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
+                            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
 #if defined DD360Audi
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
+                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
 #else
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
+                                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) {
-                                    log_info("-----------------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
+                            }
+                        } else {
+                            // Idle 正常程序起點
+                            // 判斷是否有啟用檢查插槍
+                            if (isDetectPlugin()) {
+                                // 卡號驗證成功後,等待充電槍插入充電車
+                                if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
+                                    if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
+                                            chargingInfo[gun_index]->IsAvailable) {
+                                        log_info("-----------------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)
+                                            && (waitRightGunPlugIt(gun_index) == PASS ||
+                                                waitLeftGunPlugIt(gun_index) == PASS)
 #endif //defined DD360Audi
-                                   ) {
-                                    log_info("-----------------2----------------- \n");
+                                       ) {
+                                        log_info("-----------------2----------------- \n");
+                                        ChangeGunSelectByIndex(gun_index);
+                                        AddPlugInTimes(gun_index);
+                                        strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+                                        log_info("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)) {
+                                log_info("-----------------3----------------- \n");
+                                bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
+
+                                if (isCanStartChargingFlag) {
                                     ChangeGunSelectByIndex(gun_index);
                                     AddPlugInTimes(gun_index);
-                                    strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-                                    log_info("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)) {
-                            log_info("-----------------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) {
+                            } else {
+                                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
 #if defined DD360Audi
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
+                                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
 #else
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
+                                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
 #endif // defined DD360Audi
+                                }
                             }
+                        } // Idle 正常程序終點
+                    } else {
+                        setChargerMode(gun_index, MODE_FAULT);
+                        if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
                         }
-                    } // Idle 正常程序終點
+                    }// PrecheckIsPass()
                 }
             }
             break;

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

@@ -60,4 +60,19 @@ typedef struct StLedConfig {
     uint8_t Reserved: 1;                        //bit 7 reserved
 } LedConfig;
 
+//------------------------------------------------------------------------------
+bool isDetectPlugin();
+void _DetectPlugInTimeout();
+void StopSystemTimeoutDet();
+
+void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag);
+void StopGunInfoTimeoutDet(uint8_t gunIndex);
+
+void ClearAuthorizedFlag();
+
+void ChargingAlarmProcess(uint8_t gunIndex);
+void StopChargingProcessByString(uint8_t level);
+
+void AcChargingTerminalProcess();
+
 #endif /* _MAIN_H_ */

+ 7009 - 0
EVSE/Projects/DD360/Apps/mainNew.c

@@ -0,0 +1,7009 @@
+#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/define.h"
+#include <stdbool.h>
+#include <dirent.h>
+
+#include "Config.h"
+#include "main.h"
+#include "common.h"
+#include "timeout.h"
+
+#include "./Log/log.h"
+
+#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+#include "./SelectGun/SelectGun.h"
+#endif //defined DD360Audi
+
+//------------------------------------------------------------------------------
+char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
+uint8_t mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+int whileLoopTime = 10000; // 10 ms
+int wtdFd = -1;
+uint8_t _authorizeIndex = NO_DEFINE;
+
+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;
+DcCommonInfo                    *ShmDcCommonData;
+
+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 SelectGunInfo             *gAudiCustInfo = NULL; //Jerry add
+#endif //defined DD360Audi
+
+// for initial index to check EV board type is correct
+uint8_t _gunIndex = 0;
+uint8_t _acgunIndex = 0;
+uint8_t _chademoIndex = 0;
+uint8_t _ccsIndex = 0;
+uint8_t _gb_Index = 0;
+uint8_t _ac_Index = 0;
+uint8_t bd0_1_status = 0;
+uint8_t bd0_2_status = 0;
+uint8_t bd1_1_status = 0;
+uint8_t 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.08.00.0000.00"; // "V0.16.00.0000.00";
+
+sqlite3 *localDb;
+bool isDb_ready;
+
+EvBoardErrMsg gEvBoardErr = {0};
+
+//------------------------------------------------------------------------------
+bool IsAuthorizingMode();
+void ClearAuthorizedFlag();
+void ClearDetectPluginFlag();
+
+long long DiffTimebWithNow(struct timeb ST);
+uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
+void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
+void ChargingTerminalProcess(uint8_t gunIndex);
+void ChkPrimaryStatus();
+void StartSystemTimeoutDet(uint8_t flag);
+void StopSystemTimeoutDet();
+void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag);
+void StopGunInfoTimeoutDet(uint8_t 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 ChangeGunSelectByIndex(uint8_t sel);
+//void InformOcppErrOccur(uint8_t codeType);
+
+void RecordAlarmCode(uint8_t gunIndex, char *code);
+void RecordWarningCode(uint8_t gunIndex, char *code);
+void ReleaseWarningCodeByString(uint8_t gunIndex, char *code);
+void ReleaseAlarmCode(uint8_t gunIndex);
+void ResetChargerAlarmCode(uint8_t gunIndex, char *code);
+
+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);
+
+#if 0
+//------------------------------------------------------------------------------
+//--- 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;
+
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    //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 !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+static int waitLeftGunPlugIt(uint8_t curGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+static void setSelGunWaitToAuthor(uint8_t curSel)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    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 !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    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 !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    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 //0
+
+static void checkGunOTPState(uint8_t _index)
+{
+    switch (chargingInfo[_index]->Type) {
+    case _Type_Chademo:
+        if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012229");
+            } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+                       chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012229");
+            }
+        } else {
+            // 沒接上 Sensor or 異常
+            //RecordAlarmCode(_index, "011018");
+            ResetChargerAlarmCode(_index, "012229");
+        }
+        break;
+
+    case _Type_CCS_2:
+        // CCS 不管甚麼輸出都會有槍溫偵測!!~
+        if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            ResetChargerAlarmCode(_index, "011019");
+            if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012230");
+            } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+                       chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012230");
+            }
+
+            //ResetChargerAlarmCode(_index, "011019");
+        } else {
+            // 沒接上 Sensor or 異常
+            RecordAlarmCode(_index, "011019");
+            ResetChargerAlarmCode(_index, "012230");
+        }
+        break;
+
+    case _Type_GB:
+        if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012231");
+            } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+                       chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012231");
+            }
+        } else {
+            // 沒接上 Sensor or 異常
+            RecordAlarmCode(_index, "011020");
+            ResetChargerAlarmCode(_index, "012231");
+        }
+        break;
+    }
+}
+
+static void collectError(uint8_t gunIndex)
+{
+    gEvBoardErr.GunErrMessage |= ShmDcCommonData->ConnectErrList[gunIndex].GunErrMessage;
+}
+
+static void checkGBTAlarmState(uint8_t gunType)
+{
+    // GFD Trip
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
+    }
+
+    // UVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
+    }
+
+    // OTP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = NO;
+    }
+
+    // OVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
+    }
+
+    // GFD Warning
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
+    }
+
+    // Relay Welding
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
+    }
+
+    // Relay Driving
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
+    }
+
+    // Connect temp Sensor broken
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = NO;
+    }
+}
+
+static void checkCCSAlarmState(uint8_t gunType)
+{
+    // GFD Trip
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
+    }
+
+    // UVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
+    }
+
+    // OTP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = NO;
+    }
+
+    // OVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
+    }
+
+    // GFD Warning
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
+    }
+
+    // Relay Welding
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
+    }
+
+    // Relay Driving
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
+    }
+
+    // Connect temp Sensor broken
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
+    }
+}
+
+static void checkChaDeMoAlarmState(uint8_t gunType)
+{
+    // GFD Trip
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
+    }
+
+    // UVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
+    }
+
+    // OTP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = NO;
+    }
+
+    // OVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
+    }
+
+    // GFD Warning
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
+    }
+
+    // Relay Welding
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
+    }
+
+    // Relay Driving
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
+    }
+
+    // Connect temp Sensor broken
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
+    }
+}
+
+static void checkEvBoardAlarmState(uint8_t gunType)
+{
+    switch (gunType) {
+    case _Type_Chademo:
+        checkChaDeMoAlarmState(gunType);
+        break;
+
+    case _Type_CCS_2:
+        checkCCSAlarmState(gunType);
+        break;
+
+    case _Type_GB:
+        checkGBTAlarmState(gunType);
+        break;
+    }
+}
+
+static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
+{
+    uint8_t ret = NO;
+    LedConfig *pLedConfig = (LedConfig *)ledConfig;
+
+    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
+        ret = YES;
+        if (pLedConfig->RedLED == YES) {
+            pLedConfig->RedLED = NO;
+        } else {
+            pLedConfig->RedLED = YES;
+        }
+    }
+
+    return ret;
+}
+
+static void startPrimaryLedIndicatorCtrlFork(void)
+{
+#if !defined DD360ComBox
+    return;
+#endif //!defined DD360ComBox
+
+    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) {
+                        //Module_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:
+                    //Module_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:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        break;
+                    }
+
+                    pLedConfig->RedLED = YES;
+                    break;
+
+                case S_TERMINATING:
+                case S_COMPLETE:
+                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                        pLedConfig->YellowLED = NO;
+                        pLedConfig->GreenLED = NO;
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        pLedConfig->RedLED = YES;
+                    } else {
+                        pLedConfig->RedLED = NO;
+                        pLedConfig->YellowLED = YES;
+                        pLedConfig->GreenLED = NO;
+                    }
+                    break;
+
+                case S_MAINTAIN:
+                case S_FAULT:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        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(uint8_t 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] = (uint8_t)1;
+    tios.c_lflag = 0;
+    tcflush(fd, TCIFLUSH);
+    ioctl (fd, TCSETS, &tios);
+
+    return fd;
+}
+
+//=================================
+// Common routine
+//=================================
+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;
+}
+
+#if 0
+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;
+}
+#endif //0
+
+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 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(uint8_t gun_index, uint8_t mode)
+{
+    chargingInfo[gun_index]->SystemStatus = mode;
+}
+
+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) {
+        log_info("Connector 1 : Chademo");
+    } else if (bd0_1_status == 1 && bd0_2_status == 0) {
+        log_info("Connector 1 : CCS");
+    } else if (bd0_1_status == 1 && bd0_2_status == 1) {
+        log_info("Connector 1 : GB");
+    }
+
+    if (bd1_1_status == 0 && bd1_2_status == 1) {
+        log_info("Connector 2 : Chademo");
+    } else if (bd1_1_status == 1 && bd1_2_status == 0) {
+        log_info("Connector 2 : CCS");
+    } else if (bd1_1_status == 1 && bd1_2_status == 1) {
+        log_info("Connector 2 : GB");
+    }
+}
+
+void CheckHwSlotStatusLog(uint8_t index)
+{
+    if (chargingInfo[index]->Type == _Type_Chademo) {
+        log_info("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
+                 index, chargingInfo[index]->Evboard_id);
+    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
+        log_info("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
+                 index, chargingInfo[index]->Evboard_id);
+    } else if (chargingInfo[index]->Type == _Type_GB) {
+        log_info("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()
+{
+    uint8_t rebootCount = 0;
+
+    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(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
+        return FAIL;
+    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        return FAIL;
+    }
+    memset(gAudiCustInfo, 0, sizeof(SelectGunInfo));
+#endif //defined DD360Audi
+
+    if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
+        return FAIL;
+    } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        return FAIL;
+    }
+
+    if (ShmDcCommonData->RebootCount == 1) {
+        rebootCount = ShmDcCommonData->RebootCount;
+    }
+    memset(ShmDcCommonData, 0, sizeof(DcCommonInfo));
+
+    ShmDcCommonData->RebootCount = rebootCount;
+
+    return PASS;
+}
+
+//=================================
+// LCM Page
+//=================================
+void ChangeLcmByIndex(uint8_t 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;
+    uint8_t *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;
+}
+
+//static void eth0Down(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 down");
+//}
+
+//static void eth0Up(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 %s up", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
+//}
+
+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()) {
+                //log_info("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] = (uint8_t) 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 (uint8_t 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);
+
+    uint8_t 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 (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
+        ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
+    }
+
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
+        ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
+    }
+
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
+        ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
+    }
+
+    for (uint8_t 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
+
+    ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
+    ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
+
+    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 (uint8_t 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 (uint8_t 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");
+        }
+    }
+
+    //log_info("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 (uint8_t 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 (uint8_t 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 (uint8_t 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 {
+                                //log_info("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 {
+                                //log_info("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 (uint8_t 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/Module_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;
+    uint8_t *ptr, *BufTmp;
+
+    Chk = 0;
+    ptr = (uint8_t *)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(uint8_t gunIndex)
+{
+    //printf("StopChargeFlag = %d\r\n", chargingInfo[gunIndex]->StopChargeFlag);
+    return chargingInfo[gunIndex]->StopChargeFlag;
+}
+
+bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
+{
+    return chargingInfo[gunIndex]->NormalStopChargeFlag;
+}
+
+//===============================================
+// 掃描插槍狀況
+//===============================================
+void ClearDetectPluginFlag()
+{
+    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+
+    //DS60-120 add
+    for (uint8_t 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(uint8_t gunIndex)
+{
+    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
+}
+
+bool isEvContactorWelding_chademo(uint8_t gunIndex)
+{
+    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
+}
+
+bool isEvStopReq_chademo(uint8_t gunIndex)
+{
+    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
+}
+
+bool isEvStopCharging_chademo(uint8_t gunIndex)
+{
+    if (isEvGunLocked_chademo(gunIndex) == NO) {
+        // 無鎖槍 = 停止
+        log_info("gun locked none (%d) \n", gunIndex);
+        return YES;
+    }
+
+    return NO;
+}
+
+uint8_t isPrechargeStatus_chademo(uint8_t gunIndex)
+{
+    uint8_t result = 0x00;
+
+    result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+    return result;
+}
+//===============================================
+// Common Detect Chk - GB
+//===============================================
+bool isEvGunLocked_gb(uint8_t gunIndex)
+{
+    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
+}
+
+bool isEvStopCharging_gb(uint8_t gunIndex)
+{
+    if (isEvGunLocked_gb(gunIndex) == NO) {
+        // 無鎖槍 = 停止
+        log_info("gun locked none. \n");
+        return YES;
+    }
+
+    return NO;
+}
+
+uint8_t isPrechargeStatus_gb(uint8_t gunIndex)
+{
+    uint8_t result = 0x00;
+
+    result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+    return result;
+}
+
+//===============================================
+// Common Detect Chk - CCS
+//===============================================
+bool isEvGunLocked_ccs(uint8_t gunIndex)
+{
+    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
+}
+
+uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
+{
+    uint8_t result = 0x00;
+
+    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+        result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+    }
+
+    return result;
+}
+
+bool isEvStopCharging_ccs(uint8_t gunIndex)
+{
+    if (isEvGunLocked_ccs(gunIndex) == NO) {
+        // 無鎖槍 = 停止
+        log_info("gun locked none. \n");
+        return YES;
+    }
+
+    return NO;
+}
+
+//===============================================
+// Callback
+//===============================================
+void DisplayChargingInfo()
+{
+    log_info("*********** DisplayChargingInfo *********** \n");
+    for (uint8_t 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()
+{
+    log_info("*********** _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 (uint8_t 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;
+    log_info("Self test timeout. \n");
+}
+
+void _AuthorizedTimeout()
+{
+    if (IsAuthorizingMode()) {
+        log_info("*********** _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()
+{
+    log_info("*********** _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(uint8_t gunIndex)
+{
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        if (!isEvGunLocked_chademo(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
+        }
+    }
+    ChargingTerminalProcess(gunIndex);
+    _AutoReturnTimeout();
+}
+
+void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
+    //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
+    {
+        setChargerMode(gunIndex, MODE_IDLE);
+        _AutoReturnTimeout();
+    }
+}
+
+void _PrepareTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _PrepareTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
+    _AutoReturnTimeout();
+}
+
+void _CcsPrechargeTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _CcsPrechargeTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+}
+
+//===============================================
+// 取得卡號與卡號驗證
+//===============================================
+bool canStartCharging()
+{
+    char buf2[16] = "";
+    memset(buf2, 0, ARRAY_SIZE(buf2));
+
+    for (uint8_t 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 ResetChargerAlarmCode(uint8_t gunIndex, char *code)
+{
+    if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO; }
+    else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO; }
+    else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO; }
+    else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO; }
+    else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO; }
+    else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO; }
+    else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO; }
+    else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO; }
+    else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO; }
+    else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO; }
+    else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO; }
+    else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO; }
+
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012229", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012230", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012231", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011011", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011013", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011015", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011012", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011014", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011016", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011018", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011019", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL) {
+            strncpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+        }
+    }
+}
+
+void RecordAlarmCode(uint8_t gunIndex, char *code)
+{
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL) {
+        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; }
+
+    if (strcmp(code, "012234") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES; }
+    else if (strcmp(code, "012235") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES; }
+    else if (strcmp(code, "012236") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES; }
+    else if (strcmp(code, "012288") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES; }
+    else if (strcmp(code, "012289") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES; }
+    else if (strcmp(code, "012290") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES; }
+
+    else if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES; }
+    else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES; }
+    else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES; }
+    else if (strcmp(code, "012296") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES; }
+    else if (strcmp(code, "012297") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES; }
+    else if (strcmp(code, "012298") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES; }
+    else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES; }
+    else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES; }
+    else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES; }
+    else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES; }
+    else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES; }
+    else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES; }
+    else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
+}
+
+void RecordWarningCode(uint8_t 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(uint8_t gunIndex)
+{
+#if 0
+    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 (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
+            memcpy(code, "012217", 6);
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    } 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 (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
+            memcpy(code, "012221", 6);
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    } 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");
+        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
+            memcpy(code, "012219", 6);
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t 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, "012217", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = 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, "012221", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = 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(code, "012219", 6) == EQUAL) {ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;}
+                }
+            }
+        }
+    }
+#endif //0
+
+    // 回 idle 後主要清除  GFD Trip、UVP、OVP、GFD Warning
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL) {
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+        }
+    }
+
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    }
+
+    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(uint8_t 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 (uint8_t 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(uint8_t gunIndex)
+{
+    setChargerMode(gunIndex, MODE_TERMINATING);
+}
+
+void ChargingAlarmProcess(uint8_t gunIndex)
+{
+    setChargerMode(gunIndex, MODE_ALARM);
+}
+
+void AcChargingTerminalProcess()
+{
+    ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
+}
+
+void StopChargingProcessByString(uint8_t level)
+{
+    if (level > ShmSysConfigAndInfo->SysWarningInfo.Level) {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = level;
+    }
+}
+
+void ReleaseChargingProcessByString(uint8_t level)
+{
+    if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level) {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
+    }
+}
+
+// 一般錯誤停止充電處理函式
+void BoardErrOccurByString(uint8_t index, char *code)
+{
+    uint8_t 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);
+}
+
+#if 0
+// 急停狀況的停止充電處理函式
+void EmcOccureByString(char *code)
+{
+    uint8_t 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 (uint8_t 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
+    }
+}
+#endif //0
+
+void ReleaseBoardErrOccurByString(uint8_t index, char *code)
+{
+    bool isTrigger = false;
+    uint8_t 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);
+    }
+}
+
+#if 0
+void ReleaseEmsOccureByString(uint8_t index, char *code)
+{
+    bool isTrigger = false;
+    uint8_t 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);
+    }
+}
+#endif //0
+
+#if 0
+//===============================================
+// 確認硬體 (按鈕) 狀態
+//===============================================
+bool leftBtnPush = false;
+bool rightBtnPush = false;
+
+void ChkPrimaryStatus()
+{
+    uint8_t Rtn;
+
+    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
+        Rtn = 0;
+        for (uint8_t 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;
+            log_info("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();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+#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);
+                        log_info("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.StopChargingByButton == YES ||
+                        ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
+                    // 停止充電
+                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+            }
+            break;
+            case S_COMPLETE: {
+                // 回 IDLE
+                //log_info("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;
+            //log_info("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;
+            //log_info("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 (uint8_t _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);
+            }
+        }
+        log_info("current select gun ............................... %d \n",
+                 ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
+        if (rightBtnPush) {
+            rightBtnPush = false;
+            //log_info("right btn up............................... \n");
+        }
+    }
+}
+#endif //0
+
+//===============================================
+// 確認各小板偵測的錯誤狀況
+//===============================================
+void CheckErrorOccurStatus(uint8_t 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((char *)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;
+    uint8_t 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
+//===============================================
+// 檢查 uint8_t 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit)
+{
+    return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+// 設定 Byte 中某個 Bit的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+// value : 修改的值為 0 or 1
+void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value)
+{
+    if (value == 1) {
+        *_byte |= (1 << _bit);
+    } else if (value == 0) {
+        *_byte ^= (1 << _bit);
+    }
+}
+
+void UserScanFunction()
+{
+    bool idleReq = false;
+    uint8_t 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 (uint8_t 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];
+
+                log_info("ac stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
+                         ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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];
+
+                log_info("stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n",
+                         ShmSysConfigAndInfo->SysInfo.CurGunSelected,
+                         chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
+                         ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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) {
+                    log_info("// 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;
+                    }
+                }
+            }
+        }
+    }
+}
+
+uint8_t isModeChange(uint8_t gun_index)
+{
+    uint8_t 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
+#else
+                && gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance != FAIL_BALANCE_PRICES
+#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(uint8_t typeValue, uint8_t 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;
+
+
+    //log_info("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");
+        uint8_t slots = 1;
+        for (uint8_t 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 (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "0", 1) != 0) {
+                //    if (bd0_1_status == 1 || bd0_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x01;
+                //    } else if (bd1_1_status == 1 || bd1_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x02;
+                //    }
+                //} else if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "0", 1) != 0) {
+                //    if (bd0_1_status == 1 || bd0_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x01;
+                //    } else if (bd1_1_status == 1 || bd1_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x02;
+                //    }
+                //} else {
+                //    chargingInfo[0]->Evboard_id = 0x01;
+                //}
+
+                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 (uint8_t 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 Module_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 Module_DoComm");
+#endif //!defined DD360 && !defined DD360Audi
+}
+
+int CheckUpdateProcess(void)
+{
+    //bool isPass = true;
+    uint8_t retSucc = 0;
+    uint8_t retFail = 0;
+    uint8_t index = 0;
+    uint8_t target = 0;
+    char *new_str = NULL;
+    uint8_t *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 (uint8_t i = 0; i < 16; i++) {
+                if (ShmSysConfigAndInfo->SysConfig.ModelName[i] != ptr[i]) {
+                    return FAIL;
+                }
+            }
+
+            log_info("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]));
+                log_info("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 {
+                        log_info("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;
+                                    log_info("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 {
+                        log_info("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 {
+                                    log_info("Upgrade %x Failed\r\n", Type);
+                                    //isPass = FAIL;
+                                    retFail++;
+                                }
+                            }
+                        }
+                    } else {
+                        log_info("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(uint8_t 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(uint8_t gunIndex, uint8_t flag)
+{
+    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+        if (chargingInfo[gunIndex]->TimeoutFlag != flag) {
+            gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
+        }
+        chargingInfo[gunIndex]->TimeoutFlag = flag;
+    }
+}
+
+void StopGunInfoTimeoutDet(uint8_t gunIndex)
+{
+    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+        chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
+    }
+}
+
+void CheckConnectionTimeout(void)
+{
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
+        _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
+    } else {
+        _connectionTimeout = CONN_PLUG_TIME_OUT;
+    }
+
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+    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;
+        }
+    }
+}
+
+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();
+                    destroySelGun(DESTROY_ALL_SEL); //jerry add
+                }
+                break;
+
+            case Timeout_Authorizing:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
+                    _AuthorizedTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                break;
+
+            case Timeout_VerifyFail:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                    _AutoReturnTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                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();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+                break;
+
+            case Timeout_ReturnToChargingGunDet:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
+#if defined DD360Audi
+                    if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_PRE_CHARGE &&
+                            ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_CHARGING &&
+                            ShmSysConfigAndInfo->SysInfo.SystemPage != _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 (uint8_t 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);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
+                        _DetectEvChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
+                        _DetectEvseChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseCompleteDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_ForCcsPrechargeDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
+                        _CcsPrechargeTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                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;
+                }
+            }
+            sleep(1);
+        }
+    }
+}
+
+void GetSystemTime()
+{
+    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);
+
+//  uint8_t 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;
+
+//  log_info("%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()
+{
+    //log_info("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
+    if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
+        log_info("ftp : update start. \n");
+        for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            setChargerMode(gun_index, MODE_UPDATE);
+        }
+
+        uint8_t 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 (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+                setChargerMode(_index, MODE_UPDATE);
+            }
+            for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
+                ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
+            }
+
+            uint8_t 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(uint8_t 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(void)
+{
+    bool canReset = true;
+    //bool canHardReset = true; //DS60-120 add
+
+    if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
+        ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
+    }
+
+    if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
+        if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
+            for (uint8_t _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(uint8_t gunIndex)
+{
+    uint8_t _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);
+    }
+
+    log_info("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
+}
+
+void OcppStopTransation(uint8_t gunIndex)
+{
+    uint8_t _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);
+    }
+
+    log_info("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
+}
+
+bool OcppRemoteStop(uint8_t gunIndex)
+{
+    uint8_t 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(uint8_t 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
+        uint8_t acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+        for (uint8_t 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;
+            }
+        }
+
+        uint8_t threeGunIndex = 0;
+        uint8_t dcIndex = 0;
+        bool isGunUsingStatus = false;
+
+        for (uint8_t _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(uint8_t gunIndex)
+{
+    if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+            ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
+        ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+        if (isReservationExpired(gunIndex)) {
+            log_info("***************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)) {
+            log_info("***************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) {
+        log_info("***************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(uint8_t 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(uint8_t 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(uint8_t 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 (uint8_t 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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+
+        if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local charging record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local charging record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local config table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local config table successfully\n");
+        }
+
+        //DS60-120
+        if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create reboot record table error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert local charging record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete local charging error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
+
+        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
+        sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
+        log_info("sqlStr= %s\r\n", sqlStr);
+        if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "update config error message: %s\n", errMsg);
+        } else {
+            log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+        }
+
+        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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "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;
+                }
+                log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
+            }
+        } else {
+            log_info("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;
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "delete reboot record successfully\n");
+        }
+
+        sqlite3_close(db);
+    }
+
+    return result;
+}
+
+//===============================================
+// Config process
+//===============================================
+void AddPlugInTimes(uint8_t 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(uint8_t isStart, uint8_t 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);
+//      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);
+
+        // 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);
+                        log_info("zip = %s \n", file);
+                        system(file);
+                    }
+                }
+            }
+        }
+    }
+    // Close folder
+    closedir(pDir);
+}
+
+void ChangeGunSelectByIndex(uint8_t 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) {
+                log_info("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 (uint8_t count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
+        if (chargingInfo[count]->SystemStatus != S_IDLE &&
+                chargingInfo[count]->SystemStatus != S_RESERVATION) {
+            result = false;
+            break;
+        }
+    }
+
+    for (uint8_t 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(uint8_t *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(uint8_t _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);
+            uint8_t _startCount = NO_DEFINE;
+            uint8_t _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
+
+            for (uint8_t _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;
+                    }
+                }
+            }
+
+            log_info("_startCount = %d \n", _startCount);
+            if (_startCount < _maxCount) {
+                //DS60-120 add
+                log_info("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
+                //log_info("*********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;
+        }
+
+        log_info("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
+        log_info("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(uint8_t _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 (uint8_t 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(uint8_t _gun)
+{
+    bool result = true;
+
+    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
+            ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
+        for (uint8_t _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(uint8_t 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(uint8_t 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) {
+        //if (strlen((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) {
+        //} else if (strlen((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;
+    }
+
+    log_info ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
+              ShmPsuData->SystemAvailablePower / 10,
+              ShmPsuData->SystemAvailableCurrent / 10
+             );
+
+    log_info ("Config : ChargingPower = %d, ChargingCurrent = %d",
+              ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+              ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
+             );
+}
+
+void ResetDetAlarmStatus(uint8_t 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;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    return;
+#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
+
+    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
+    return ;
+#endif //!defined DD360ComBox
+
+    if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
+            (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
+       ) {
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
+        strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
+    }
+}
+
+static bool PrecheckIsPass(uint8_t gun_index)
+{
+    bool result = false;
+
+    // relay welding or driving 是反向
+    result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
+
+    return result;
+}
+
+static void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
+{
+    // relay welding fault then stop the charging process.
+    uint8_t faultCode = RELAY_STATUS_ERROR_NONE;
+
+    if (gun_index == 0) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
+            faultCode = RELAY_STATUS_ERROR_WELDING;
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
+            faultCode = RELAY_STATUS_ERROR_DRIVING;
+        }
+    } else if (gun_index == 1) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
+            faultCode = RELAY_STATUS_ERROR_WELDING;
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
+            faultCode = RELAY_STATUS_ERROR_DRIVING;
+        }
+    }
+
+    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
+            !ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
+        // 橋接
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
+            faultCode = RELAY_STATUS_ERROR_WELDING;
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[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) {
+            RecordAlarmCode(gun_index, "011011");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            RecordAlarmCode(gun_index, "011015");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            RecordAlarmCode(gun_index, "011013");
+        }
+
+        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
+        EmcOccureByString("");
+    } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
+        // driving
+        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
+            RecordAlarmCode(gun_index, "011012");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            RecordAlarmCode(gun_index, "011016");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            RecordAlarmCode(gun_index, "011014");
+        }
+
+        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
+        EmcOccureByString("");
+    } else {
+        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
+        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
+
+        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
+            ResetChargerAlarmCode(gun_index, "011012");
+            ResetChargerAlarmCode(gun_index, "011011");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            ResetChargerAlarmCode(gun_index, "011014");
+            ResetChargerAlarmCode(gun_index, "011013");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            ResetChargerAlarmCode(gun_index, "011016");
+            ResetChargerAlarmCode(gun_index, "011015");
+        }
+    }
+}
+
+int main(void)
+{
+    uint8_t evBoardStopState = 0;
+    uint8_t _ocppProfileChkFlag;
+
+    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
+                log_info("Soft reboot for retry self-tets. \n");
+
+                sleep(3);
+                system("killall OcppBackend &");
+                KillAllTask();
+                system("/usr/bin/run_evse_restart.sh");
+            }
+        }
+
+        for (uint8_t 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 (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            setChargerMode(gun_index, MODE_IDLE);
+        }
+    }
+
+    // Local DB
+    if (DB_Open(localDb) != PASS) {
+        log_info("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);
+    }
+    log_info("===== 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
+
+    log_info("===== Charger info ===== ");
+    log_info("SW Version = %s", fwVersion);
+    log_info("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();
+
+        //確認Power cabinet PSU Status
+        powerCabinetPsuAlarmStatus();
+
+        if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan) {
+            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+        }
+
+        if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
+            CheckTask();
+
+            for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _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++;
+                    }
+                }
+                checkGunOTPState(_index); //check gun OTP
+            }
+            gettimeofday(&_cmdMainPriority_time, NULL);
+        }
+
+        gEvBoardErr.GunErrMessage = 0;
+
+        for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            autoStartChargingForComBox(gun_index); //for DD360ComBox
+
+            CheckGpioInStatus();
+
+            // 確認 Relay Welding or Driving Fault
+            CheckRelayWeldingOrDrivingFault(gun_index);
+
+            // 收集各槍的錯誤狀態
+            collectError(gun_index);
+
+            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);
+            }
+
+            //log_info("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;
+                    destroySelGun(gun_index);
+                    ResetDetAlarmStatus(gun_index); //recovery OVP status code
+                    if (gAudiCustInfo->AuthorStateFromCabinet[gun_index] == YES) {
+                        gAudiCustInfo->AuthorStateFromCabinet[gun_index] = NO;
+                    }
+                    //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 (uint8_t 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 (PrecheckIsPass(gun_index)) {
+
+                        if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+                            setChargerMode(gun_index, MODE_IDLE);
+                        }
+
+                        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) {
+                                        log_info("-----------------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
+                                       ) {
+                                        log_info("-----------------2----------------- \n");
+                                        ChangeGunSelectByIndex(gun_index);
+                                        AddPlugInTimes(gun_index);
+                                        strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+                                        log_info("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)) {
+                                log_info("-----------------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 正常程序終點
+                    } else {
+                        setChargerMode(gun_index, MODE_FAULT);
+                        if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
+                        }
+                    }// PrecheckIsPass()
+                }
+            }
+            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)) {
+                    log_info("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) {
+                    log_info("=============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
+                }
+
+                //log_info("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)) {
+                    log_info("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 (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
+                        // 共同進入充電邏輯
+                        if (chargingInfo[index]->SystemStatus != S_PREPARNING) {
+                            oughtAver = false;
+                            break;
+                        }
+                    }
+
+                    if (oughtAver) {
+                        log_info("********* 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) {
+                        log_info("================== S_ALARM (%x) ================ \n", gun_index);
+                        UpdateErrorCodeToOcpp(gun_index);
+
+                        if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
+                            OcppStopTransation(gun_index);
+                        }
+
+                        TheEndCharging(gun_index);
+                    } else {
+                        log_info("================== 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)) {
+                    log_info ("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)) {
+                    log_info("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)
+                    {
+                        //log_info("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        if (isPrechargeStatus_ccs(gun_index) == 39) {
+                            log_info("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        } else if (isPrechargeStatus_ccs(gun_index) == 40) {
+                            log_info("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);
+            }
+        }
+
+        for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            checkEvBoardAlarmState(chargingInfo[gun_index]->Type);
+        }
+
+        write(wtdFd, "a", 1);
+        usleep(whileLoopTime);
+    }
+
+    return FAIL;
+}

+ 17 - 0
EVSE/Projects/DD360Audi/Apps/CSU/AcPlug.c

@@ -0,0 +1,17 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+void AcChargingTerminalProcess(void)
+{
+    struct ChargingInfoData *pAcChargingInfoData = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    pAcChargingInfoData->SystemStatus = MODE_TERMINATING;
+}

+ 0 - 0
EVSE/Projects/DD360Audi/Apps/CSU/Gpio.c


+ 939 - 0
EVSE/Projects/DD360Audi/Apps/CSU/OCPP.c

@@ -0,0 +1,939 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+#include <time.h>
+#include <unistd.h>
+
+//------------------------------------------------------------------------------
+int opcc_chk_reserve_expired(byte gun_index)
+{
+    int result = NO;
+    struct tm expiredDate;
+    struct timeb expiredTime;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        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;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (sscanf((char *) ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,
+                   "%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 routine
+//===============================================
+void ocpp_process_start()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        system("/root/OcppBackend &");
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        system("/root/OcppBackend20 &");
+    }
+}
+
+void ocpp_auto_response_BootNotification()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
+            ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES) {
+            ShmOCPP20Data->SpMsg.bits.BootNotificationConf = NO;
+        }
+    }
+}
+
+bool ocpp_is_resPass_StartTransationConf(byte gun_index)
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf;
+    }
+
+    return result;
+}
+
+void ocpp_auto_response_StartTransationConf(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf) {
+            ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf) {
+            ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = NO;
+        }
+    }
+}
+
+void ocpp_auto_response_ReserveConf(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
+    }
+}
+
+bool ocpp_chk_authrization_cmd()
+{
+    char buf2[16] = "";
+    memset(buf2, 0, ARRAY_SIZE(buf2));
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        sprintf(buf2, "%s",   ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        sprintf(buf2, "%s",   ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
+    }
+    // 因為無法得知實際的長度,所以只能用搜尋的方式
+    if (strcmp(buf2, "Accepted") == EQUAL) {
+        return true;
+    }
+
+    return false;
+}
+
+bool opcc_sub_get_reset_req()
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->MsMsg.bits.ResetReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->MsMsg.bits.ResetReq;
+    }
+
+    return result;
+}
+
+void ocpp_sub_run_reset(bool canReset)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+            sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
+            ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            system("reboot -f");
+        } else if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+            sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
+            ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            KillAllTask();
+            system("/usr/bin/run_evse_restart.sh");
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+            sprintf((char *)ShmOCPP20Data->Reset.Response_status, "Accepted");
+            ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            system("reboot -f");
+        } else if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "OnIdle") == EQUAL) {
+            DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+            sprintf((char *)ShmOCPP20Data->Reset.Response_status, "Accepted");
+            ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
+            ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
+            sleep(3);
+            KillAllTask();
+            system("/usr/bin/run_evse_restart.sh");
+        }
+    }
+}
+
+void ocpp_chk_reset_cmd()
+{
+    if (opcc_sub_get_reset_req()) {
+        bool canReset = true;
+
+        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) {
+                        // Reset 系統先停止充電
+                        ChargingTerminalProcess(_index);
+                    }
+                }
+            }
+        }
+
+        if (canReset) {
+            // Reset -> change status to maintain.
+            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+                setChargerMode(_index, MODE_MAINTAIN);
+            }
+            ChangeLcmByIndex(_LCM_FIX);
+        }
+
+        ocpp_sub_run_reset(canReset);
+    }
+}
+
+void ocpp_chk_reserved_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+                ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
+            ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+            if (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************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 (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                chargingInfo[gunIndex]->ReservationId = 0;
+                chargingInfo[gunIndex]->SystemStatus = S_IDLE;
+            }
+            ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+                ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
+            ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+            if (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+                chargingInfo[gunIndex]->ReservationId = ShmOCPP20Data->ReserveNow[gunIndex].id;
+                chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
+            }
+            ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
+        }
+
+        if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
+                ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
+            ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
+            if (opcc_chk_reserve_expired(gunIndex)) {
+                PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+                chargingInfo[gunIndex]->ReservationId = 0;
+                chargingInfo[gunIndex]->SystemStatus = S_IDLE;
+            }
+            ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
+        }
+    }
+}
+
+void ocpp_chk_availability_cmd(byte gunIndex)
+{
+    byte type = 0; // 0 : none, 1 : operative, 2 inoperative
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
+            PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+            DEBUG_ERROR_MSG("***************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);
+                }
+
+                type = 1;
+            } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
+                if (isDb_ready) {
+                    DB_Update_Operactive(localDb, gunIndex, false);
+                }
+
+                type = 2;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
+            PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+            DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+            ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
+            if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Operative") == EQUAL) {
+                if (isDb_ready) {
+                    DB_Update_Operactive(localDb, gunIndex, true);
+                }
+
+                type = 1;
+            } else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Inoperative") == EQUAL) {
+                if (isDb_ready) {
+                    DB_Update_Operactive(localDb, gunIndex, false);
+                }
+
+                type = 2;
+            }
+        }
+    }
+
+    if (type == 1) {
+        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 (type == 2) {
+        chargingInfo[gunIndex]->IsAvailable = NO;
+        if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
+                chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
+                chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
+            setChargerMode(gunIndex, MODE_MAINTAIN);
+        }
+    }
+}
+
+void ocpp_chk_unlock_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
+            ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
+            if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
+                    chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
+                // Unlocked - 充電中,需停止充電
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
+                ChargingTerminalProcess(gunIndex);
+            }
+            strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
+            ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
+            ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
+            if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
+                    chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
+                // Unlocked - 充電中,需停止充電
+                strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "UnlockCommand");
+                ChargingTerminalProcess(gunIndex);
+            }
+            strcpy((char *)ShmOCPP20Data->UnlockConnector[gunIndex].Response_status, "Unlocked");
+            ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
+        }
+    }
+}
+
+bool ocpp_chk_remoteStop_cmd(byte gunIndex)
+{
+    byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+    // 有 AC 槍的話
+    if (acDirIndex > 0 && gunIndex > 0) {
+        gunIndex += acDirIndex;
+    }
+
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq;
+    }
+
+    if (result) {
+        DEBUG_INFO_MSG("Remote Stop by OCPP (%d) \n", gunIndex);
+        if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
+            ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
+        } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "Remote");
+            ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq = NO;
+        }
+    }
+
+    return result;
+}
+
+bool ocpp_sub_get_remote_start_transaction_req(byte gun_index)
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq;
+    }
+
+    if (result) {
+        strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,
+               (char *)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag);
+    }
+
+    return result;
+}
+
+void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStartTransactionReq = result;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStartTransactionReq = result;
+    }
+}
+
+void ocpp_chk_remoteStart_cmd()
+{
+    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 (ocpp_sub_get_remote_start_transaction_req(acDirIndex)) {
+                if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
+                        ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
+                    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;
+                }
+                ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
+            }
+        }
+
+        byte threeGunIndex = 0;
+        byte dcIndex = 0;
+        bool isGunUsingStatus = false;
+        byte scheduleIndex = 0;
+
+        for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+            // 如果有 AC 槍,且 DC 槍也有兩把
+            if (acDirIndex == 1 && _index == 1) {
+                threeGunIndex = 1;
+            }
+
+            if (ocpp_sub_get_remote_start_transaction_req(_index + threeGunIndex)) {
+                dcIndex = _index;
+            }
+
+            if (chargingInfo[_index]->SystemStatus != S_IDLE) {
+                isGunUsingStatus = true;
+            }
+
+            if (chargingInfo[_index]->schedule.isTriggerStart) {
+                scheduleIndex = _index;
+            }
+        }
+
+        // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
+        if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
+            if (dcIndex == 0) {
+                threeGunIndex = 0;
+            }
+
+            ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
+            return;
+        }
+
+        if (dcIndex == 0) {
+            threeGunIndex = 0;
+        }
+
+        if (ocpp_sub_get_remote_start_transaction_req(dcIndex + threeGunIndex)) {
+            if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
+                    chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
+                chargingInfo[dcIndex]->RemoteStartFlag = YES;
+                ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+                //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
+                DetectPluginStart();
+            }
+            ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
+        } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
+            if (chargingInfo[scheduleIndex]->SystemStatus == S_IDLE ||
+                    chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
+                chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
+                ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+                DetectPluginStart();
+            }
+            chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
+        }
+    }
+}
+
+void ocpp_chk_update_cmd()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
+            ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
+
+            if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
+                DEBUG_INFO_MSG("Backend : update start. \n");
+                sleep(2);
+                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) {
+                    DEBUG_INFO_MSG("Backend : update complete. \n");
+                    strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+                } else if (updateResult == MODELNAME_FAIL) {
+                    DEBUG_INFO_MSG("Backend : model name is none match. \n");
+                    strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+                    ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+                    sleep(5);
+                    KillAllTask();
+                    system("/usr/bin/run_evse_restart.sh");
+                    return;
+                } else {
+                    DEBUG_INFO_MSG("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");
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES) {
+            ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = NO;
+
+            if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL) {
+                DEBUG_INFO_MSG("Backend : update start. \n");
+                sleep(2);
+                strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "");
+                strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing");
+                ShmOCPP20Data->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) {
+                    DEBUG_INFO_MSG("Backend : update complete. \n");
+                    strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
+                } else if (updateResult == MODELNAME_FAIL) {
+                    DEBUG_INFO_MSG("Backend : model name is none match. \n");
+                    strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
+                    ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+                    sleep(5);
+                    KillAllTask();
+                    system("/usr/bin/run_evse_restart.sh");
+                    return;
+                } else {
+                    DEBUG_INFO_MSG("Backend : update fail. \n");
+                    strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
+                }
+
+                strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
+                ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+                sleep(5);
+                system("reboot -f");
+            }
+        }
+    }
+}
+
+bool ocpp_chk_invalid_id_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE")) {
+            if (strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
+                    strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
+                    strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
+                return true;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE")) {
+            if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Blocked") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Expired") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Invalid") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
+                    strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Unknown") == EQUAL) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+bool ocpp_chk_profileConf_cmd(byte _index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
+            ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
+            return true;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
+            ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
+            return true;
+        }
+    }
+
+    return false;
+}
+
+void ocpp_lift_profileReq_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
+            if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
+                ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
+            }
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO) {
+            if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO) {
+                ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
+            }
+        }
+    }
+}
+
+void ocpp_set_startTransation_cmd(byte gunIndex)
+{
+    byte _OcppGunIndex = gunIndex;
+
+    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
+        _OcppGunIndex = 2;
+    }
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        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;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        } else {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
+        }
+
+        PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
+    }
+}
+
+void ocpp_set_stopTransation_cmd(byte gunIndex)
+{
+    byte _OcppGunIndex = gunIndex;
+
+    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+    if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
+        _OcppGunIndex = 2;
+    }
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        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;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        } else {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
+        }
+
+        PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+        ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
+    }
+}
+
+void ocpp_set_errorCode_cmd(byte gunIndex, char *errString)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, errString);
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+
+    }
+}
+
+void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, reason);
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "") == EQUAL) {
+            strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, reason);
+        }
+    }
+}
+
+void ocpp_set_authorizeReq_cmd(byte value)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->SpMsg.bits.AuthorizeReq = value;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->SpMsg.bits.AuthorizeReq = value;
+    }
+}
+
+void ocpp_set_authorizeConf_cmd(byte value)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        ShmOCPP16Data->SpMsg.bits.AuthorizeConf = value;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        ShmOCPP20Data->SpMsg.bits.AuthorizeConf = value;
+    }
+}
+
+void ocpp_set_errCode_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "InternalError");
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->ConnectorAlarmCode);
+        } else if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "OtherError");
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->EvConnAlarmCode);
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+
+    }
+}
+
+void ocpp_clear_errorCode_cmd(byte gunIndex)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError");
+        }
+
+        if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "") != EQUAL) {
+            strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+
+    }
+}
+
+void ocpp_clear_idTag_cmd(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "");
+    }
+}
+
+void ocpp_clear_stopReason(byte gun_index)
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
+    }
+}
+
+unsigned short _ocpp_get_connect_timeout()
+{
+    uint16_t result = (TIMEOUT_SPEC_HANDSHAKING / 1000);
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
+            result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+        }
+    }
+
+    else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "") != 0) {
+            result = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
+        }
+    }
+
+    return result;
+}
+
+bool _ocpp_get_disconnect_policy()
+{
+    bool result = false;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE") == EQUAL &&
+                strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == EQUAL) {
+            result = true;
+        }
+    }
+
+    else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL &&
+                strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL) {
+            result = true;
+        }
+    }
+
+    return result;
+}
+
+bool ocpp_get_authorize_conf()
+{
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        return ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        return ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
+    }
+
+    return false;
+}
+
+bool ocpp_get_startTransation_req(byte gunIndex)
+{
+    bool result = false;
+
+    // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        result = ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq;
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        result = ShmOCPP20Data->CpMsg.bits[gunIndex].TransactionEventReq;
+    }
+
+    return result;
+}
+
+void ocpp_chargingProfile_process(byte _index)
+{
+    int _time = 0;
+    int _startCount = NO_DEFINE;
+    int _maxCount = 0;
+
+    if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {
+        if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
+                ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES) {
+            _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+            _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
+            _startCount = NO_DEFINE;
+
+            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("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
+            if (_startCount < _maxCount) {
+                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 * ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
+                if (chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
+                        chargingInfo[_index]->PresentChargingVoltage > 0) {
+                    chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
+                } else {
+                    chargingInfo[_index]->ChargingProfileCurrent = 0;
+                }
+            } else {
+                chargingInfo[_index]->ChargingProfilePower = -1;
+                chargingInfo[_index]->ChargingProfileCurrent = -1;
+            }
+        } else {
+            chargingInfo[_index]->ChargingProfilePower = -1;
+            chargingInfo[_index]->ChargingProfileCurrent = -1;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20) {
+        if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[_index].chargingProfileKind, "Absolute") == EQUAL &&
+                ShmOCPP20Data->SmartChargingProfile[_index].id == YES) {
+            _time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].startSchedule);
+            _maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod);
+            _startCount = NO_DEFINE;
+
+            for (byte _count = 0; _count < _maxCount; _count++) {
+                // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+                if (_time >= ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod) {
+                    if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
+                            ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR) {
+                        _startCount = _count;
+                    }
+                }
+            }
+
+            PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
+            if (_startCount < _maxCount) {
+                PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit);
+                chargingInfo[_index]->ChargingProfilePower = ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].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;
+                }
+            } else {
+                chargingInfo[_index]->ChargingProfilePower = -1;
+                chargingInfo[_index]->ChargingProfileCurrent = -1;
+            }
+        } else {
+            chargingInfo[_index]->ChargingProfilePower = -1;
+            chargingInfo[_index]->ChargingProfileCurrent = -1;
+        }
+    } else {
+        chargingInfo[_index]->ChargingProfilePower = -1;
+        chargingInfo[_index]->ChargingProfileCurrent = -1;
+    }
+
+    PRINTF_FUNC("Profile : ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
+    PRINTF_FUNC("Profile : ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
+}

+ 488 - 0
EVSE/Projects/DD360Audi/Apps/CSU/Primary.c

@@ -0,0 +1,488 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+#include "../SelectGun/SelectGun.h"
+#include "../main.h"
+
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
+{
+    uint8_t ret = NO;
+    LedConfig *pLedConfig = (LedConfig *)ledConfig;
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
+        ret = YES;
+        if (pLedConfig->RedLED == YES) {
+            pLedConfig->RedLED = NO;
+        } else {
+            pLedConfig->RedLED = YES;
+        }
+    }
+
+    return ret;
+}
+
+void PrimaryLedIndicatorCtrlFork(void)
+{
+#if !defined DD360ComBox
+    return;
+#endif //!defined DD360ComBox
+
+    pid_t pid = fork();
+    if (pid == 0) {
+        uint8_t gunIndex = 0;
+        int isContinue = 1;
+        LedConfig *pLedConfig = NULL;
+        struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+        struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+        struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+        struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+        struct ChargingInfoData *pDcChargingInfoData = NULL;
+
+        pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
+
+        while (isContinue) {
+            for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+                pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+                //printf("led indicator status = %d\r\n", pDcChargingInfoData->SystemStatus);
+                //printf("level = %d\r\n", pSysWarningInfo->Level);
+                switch (pDcChargingInfoData->SystemStatus) {
+                case S_BOOTING:
+                    if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+                        //Module_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:
+                    //Module_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:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        break;
+                    }
+
+                    pLedConfig->RedLED = YES;
+                    break;
+
+                case S_TERMINATING:
+                case S_COMPLETE:
+                    if (pSysWarningInfo->Level == 2) {
+                        pLedConfig->YellowLED = NO;
+                        pLedConfig->GreenLED = NO;
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        pLedConfig->RedLED = YES;
+                    } else {
+                        pLedConfig->RedLED = NO;
+                        pLedConfig->YellowLED = YES;
+                        pLedConfig->GreenLED = NO;
+                    }
+                    break;
+
+                case S_MAINTAIN:
+                case S_FAULT:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    if (pSysWarningInfo->Level == 2) {
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        pLedConfig->RedLED = YES;
+                    }
+                    break;
+
+                case S_BOOKING:
+                case S_DEBUG:
+                case S_UPDATE:
+                case S_NONE:
+                    break;
+                }//switch
+
+            } //for
+            usleep(500000);
+        } //while
+    } //fork
+}
+
+//------------------------------------------------------------------------------
+// 急停狀況的停止充電處理函式
+void EmcOccureByString(char *code)
+{
+    uint8_t level = 2;
+    uint8_t gunIndex = 0;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct ChargingInfoData *pDcChargingInfoData = NULL;
+
+
+    // 嚴重的急停有以下幾種 : 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 (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+            pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+            //strncpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, code, 6);
+
+            if ((pDcChargingInfoData->SystemStatus > S_IDLE &&
+                    pDcChargingInfoData->SystemStatus < S_TERMINATING) ||
+                    (pDcChargingInfoData->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                     pDcChargingInfoData->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                //ChargingTerminalProcess(gunIndex);
+                ChargingAlarmProcess(gunIndex);
+            }
+        }
+//#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+        StopChargingProcessByString(level);
+        //InformOcppErrOccur(4);
+//#endif //defined DD360 || defined DD360Audi
+    }
+}
+
+void ReleaseEmsOccureByString(uint8_t index, char *code)
+{
+    bool isTrigger = false;
+    uint8_t level = 2;
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    if (strncmp(code, "042251", 6) == 0 ) {
+        isTrigger = true;
+    } else if (strncmp(code, "012251", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
+    } else if (strncmp(code, "012252", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
+    } else if (strncmp(code, "012237", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
+    } else if (strncmp(code, "012238", 6) == 0 &&
+               pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
+        isTrigger = true;
+        pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
+    }
+
+    if (isTrigger) {
+        ReleaseChargingProcessByString(level);
+        InformOcppErrOccur(6);
+    }
+}
+
+void ChkPrimaryStatus(void)
+{
+    uint8_t Rtn;
+    static bool leftBtnPush = false;
+    static bool rightBtnPush = false;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    struct WARNING_CODE_INFO *pSysWarningInfo = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+    struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    struct ChargingInfoData *pDcChargingInfoData = NULL;
+    struct ChargingInfoData *pAcChargingInfoData = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    if (pSysWarningInfo->WarningCount > 0) {
+        Rtn = 0;
+        for (uint8_t i = 0; i < pSysWarningInfo->WarningCount; i++) {
+            if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042251", 6) == 0) {
+                EmcOccureByString("042251");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042252", 6) == 0) {
+                EmcOccureByString("042252");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042200", 6) == 0) {
+                EmcOccureByString("042200");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042201", 6) == 0) {
+                EmcOccureByString("042201");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->WarningCode[i][0], "042202", 6) == 0) {
+                EmcOccureByString("042202");
+                Rtn = 1;
+            } else if (memcmp(&pSysWarningInfo->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) {
+        pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = YES;
+        EmcOccureByString("012251");
+    } else {
+        ReleaseEmsOccureByString(0, "012251");
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
+        pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = YES;
+        EmcOccureByString("012238");
+    } else {
+        ReleaseEmsOccureByString(0, "012238");
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
+        pAlarmCode->AlarmEvents.bits.SpdTrip = YES;
+    } else {
+        pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
+        pAlarmCode->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) {
+    //    pSysConfig->ShowInformation = YES;
+    //} else {
+    //    pSysConfig->ShowInformation = NO;
+    //}
+
+    pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+
+    if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
+            !leftBtnPush &&
+            WaitAuthorPageState()
+       ) {
+        if (!leftBtnPush) {
+            leftBtnPush = true;
+            log_info("left btn down...............................%x\n", pDcChargingInfoData->SystemStatus);
+            if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+                switch (pAcChargingInfoData->SystemStatus) {
+                case S_IDLE:
+                    if (isDetectPlugin()) {
+                        _DetectPlugInTimeout();
+                        StopSystemTimeoutDet();
+                    }
+                    break;
+
+                case S_REASSIGN_CHECK:
+                case S_REASSIGN:
+                case S_PREPARNING:
+                case S_PREPARING_FOR_EV:
+                case S_PREPARING_FOR_EVSE:
+                case S_CCS_PRECHARGE_ST0:
+                case S_CCS_PRECHARGE_ST1:
+                    // 取消充電
+                    AcChargingTerminalProcess();
+                    break;
+
+                case S_CHARGING:
+                    if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+                        // 停止充電
+                        AcChargingTerminalProcess();
+                    }
+                    break;
+
+                case S_COMPLETE:
+                    break;
+                }
+            }
+
+            switch (pDcChargingInfoData->SystemStatus) {
+            case S_IDLE:
+                if (isDetectPlugin()) {
+                    _DetectPlugInTimeout();
+                    StopSystemTimeoutDet();
+#if defined DD360Audi
+                    destroySelGun(pSysInfo->CurGunSelected);
+#endif //defined DD360Audi
+                }
+#if defined DD360Audi
+                else {
+                    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
+                        //printf("destroy gun = %d\r\n", pSysInfo->CurGunSelected);
+                        destroySelGun(pSysInfo->CurGunSelected);
+                    } else {
+                        confirmSelGun(pSysInfo->CurGunSelected);
+                        log_info("confirm select gun ............................... %d \n",
+                                 pSysInfo->CurGunSelected);
+                    }
+                }
+#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 (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+                    AcChargingTerminalProcess();
+                } else {
+                    ChargingTerminalProcess(pSysInfo->CurGunSelected);
+                }
+                break;
+
+            case S_CHARGING:
+                if (pSysConfig->StopChargingByButton == YES ||
+                        pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+                    // 停止充電
+                    ChargingTerminalProcess(pSysInfo->CurGunSelected);
+                }
+                break;
+
+            case S_COMPLETE:
+                // 回 IDLE
+                //log_info("right btn down.................S_COMPLETE \n");
+                //pDcChargingInfoData->SystemStatus = S_IDLE;
+                break;
+            }
+        }
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
+        if (leftBtnPush) {
+            leftBtnPush = false;
+            //log_info("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;
+            //log_info("right btn down............................... %d \n", pSysInfo->CurGunSelected);
+            if (pSysInfo->CurGunSelected + 1 <
+                    pSysConfig->TotalConnectorCount &&
+                    pSysInfo->IsAlternatvieConf == NO) {
+                pSysInfo->CurGunSelected++;
+                ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+            } else if (pSysConfig->AcConnectorCount > 0 &&
+                       pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
+                pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+            } else if (pSysInfo->IsAlternatvieConf == YES) {
+                for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
+                    pDcChargingInfoData = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+                    if (pDcChargingInfoData->SystemStatus != S_BOOTING &&
+                            pDcChargingInfoData->SystemStatus != S_IDLE &&
+                            pDcChargingInfoData->SystemStatus != S_RESERVATION) {
+                        pSysInfo->CurGunSelected = _index;
+                        ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+                        return;
+                    }
+                }
+                pSysInfo->CurGunSelected = 0;
+                ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+            } else {
+                pSysInfo->CurGunSelected = 0;
+                ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+            }
+        }
+        log_info("current select gun ............................... %d \n",
+                 pSysInfo->CurGunSelected);
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
+        if (rightBtnPush) {
+            rightBtnPush = false;
+            //log_info("right btn up............................... \n");
+        }
+    }
+}

+ 320 - 0
EVSE/Projects/DD360Audi/Apps/CSU/RFID.c

@@ -0,0 +1,320 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+static void UserScanFunction(void)
+{
+    bool idleReq = false;
+    uint8_t 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 (uint8_t 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];
+
+                log_info("ac stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
+                         ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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];
+
+                log_info("stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n",
+                         ShmSysConfigAndInfo->SysInfo.CurGunSelected,
+                         chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
+                         ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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) {
+                    log_info("// 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;
+                    }
+                }
+            }
+        }
+    }
+}
+
+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
+#else
+                && gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance != FAIL_BALANCE_PRICES
+#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;
+    }
+}
+
+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);
+        }
+    }
+}

+ 303 - 0
EVSE/Projects/DD360Audi/Apps/CSU/TimeTask.c

@@ -0,0 +1,303 @@
+
+void _CcsPrechargeTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _CcsPrechargeTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+}
+
+void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
+    //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
+    {
+        setChargerMode(gunIndex, MODE_IDLE);
+        _AutoReturnTimeout();
+    }
+}
+
+void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
+{
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        if (!isEvGunLocked_chademo(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
+        }
+    }
+    ChargingTerminalProcess(gunIndex);
+    _AutoReturnTimeout();
+}
+
+void _PrepareTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _PrepareTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
+    _AutoReturnTimeout();
+}
+
+void ClearAuthorizedFlag()
+{
+    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
+    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+}
+
+void DisplayChargingInfo()
+{
+    log_info("*********** DisplayChargingInfo *********** \n");
+    for (uint8_t 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 _DetectPlugInTimeout()
+{
+    log_info("*********** _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 _AutoReturnTimeout()
+{
+    log_info("*********** _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 StopSystemTimeoutDet()
+{
+    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
+    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+}
+
+void _SelfTestTimeout()
+{
+    if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE) {
+        for (uint8_t 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;
+    log_info("Self test timeout. \n");
+}
+
+void CheckConnectionTimeout(void)
+{
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
+        _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
+    } else {
+        _connectionTimeout = CONN_PLUG_TIME_OUT;
+    }
+
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+    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;
+        }
+    }
+}
+
+void CreateTimeoutFork(void)
+{
+    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();
+                    destroySelGun(DESTROY_ALL_SEL); //jerry add
+                }
+                break;
+
+            case Timeout_Authorizing:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
+                    _AuthorizedTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                break;
+
+            case Timeout_VerifyFail:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                    _AutoReturnTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                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();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+                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;
+
+            } //switch
+
+            // 各槍
+            for (uint8_t 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);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
+                        _DetectEvChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
+                        _DetectEvseChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseCompleteDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_ForCcsPrechargeDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
+                        _CcsPrechargeTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_SelectGun: //Jerry add
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+                } //switch
+            } //for
+            sleep(1);
+        }//while
+    }
+}

+ 271 - 0
EVSE/Projects/DD360Audi/Apps/CSU/Update.c

@@ -0,0 +1,271 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+int CheckUpdateProcess(void)
+{
+    //bool isPass = true;
+    uint8_t retSucc = 0;
+    uint8_t retFail = 0;
+    uint8_t index = 0;
+    uint8_t target = 0;
+    char *new_str = NULL;
+    uint8_t *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;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    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 (uint8_t i = 0; i < 16; i++) {
+                if (pSysConfig->ModelName[i] != ptr[i]) {
+                    return FAIL;
+                }
+            }
+
+            log_info("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]));
+                log_info("Typed...%x \r\n", Type);
+
+                switch (Type) {
+                case 0x10000001:
+                case 0x10000002:
+                case 0x10000003:
+                case 0x10000004:
+                case 0x10000005:
+                    if (Upgrade_Flash(Type, new_str, (char *)pSysConfig->ModelName) == PASS) {
+                        //return PASS;
+                        retSucc++;
+                    } else {
+                        log_info("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 < pSysConfig->TotalConnectorCount; index++) {
+                            //if (!isPass) {
+                            //    break;
+                            //}
+
+                            if (chargingInfo[index]->Type == _Type_CCS_2) {
+                                if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)pSysConfig->ModelName) == FAIL) {
+                                    //isPass = false;
+                                    log_info("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 *)pSysConfig->ModelName) == PASS) {
+                        //return PASS;
+                        retSucc++;
+                    } else {
+                        log_info("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 < pSysConfig->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 *)pSysConfig->ModelName) == PASS) {
+                                    //isPass = PASS;
+                                    retSucc++;
+                                } else {
+                                    log_info("Upgrade %x Failed\r\n", Type);
+                                    //isPass = FAIL;
+                                    retFail++;
+                                }
+                            }
+                        }
+                    } else {
+                        log_info("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 CheckFwUpdateFunction(void)
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+    //log_info("pSysInfo->FirmwareUpdate = %d \n", pSysInfo->FirmwareUpdate);
+    if (pSysInfo->FirmwareUpdate == YES) {
+        log_info("ftp : update start. \n");
+        for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
+            setChargerMode(gun_index, MODE_UPDATE);
+        }
+
+        uint8_t 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();
+            pSysInfo->FirmwareUpdate = NO;
+            sleep(5);
+            system("/usr/bin/run_evse_restart.sh");
+            return;
+        } else {
+            log_info("ftp : update fail. \n");
+        }
+
+        pSysInfo->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 (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
+                setChargerMode(_index, MODE_UPDATE);
+            }
+            for (uint8_t _index = 0; _index < pSysConfig->AcConnectorCount; _index++) {
+                ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
+            }
+
+            uint8_t 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");
+        }
+    }
+}

+ 0 - 0
EVSE/Projects/DD360Audi/Apps/CSU/WatchDog.c


+ 62 - 0
EVSE/Projects/DD360Audi/Apps/CSU/ZipFile.c

@@ -0,0 +1,62 @@
+
+void zipLogFiles(void)
+{
+    const char *logPath = "/Storage/SystemLog";
+    // 獲取目錄
+    DIR *pDir = opendir(logPath);
+    if (pDir != NULL) {
+        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);
+
+        // 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);
+                        log_info("zip = %s \n", file);
+                        system(file);
+                    }
+                }
+            }
+        }
+    }
+    // Close folder
+    closedir(pDir);
+}

+ 27 - 24
EVSE/Projects/DD360Audi/Apps/Config.h

@@ -251,29 +251,29 @@ enum RELAY_STATUS_ERROR_TYPE {
 };
 
 //------------------------------------------------------------------------------
-struct StructMeter {
-    float curMeterValue;
-    float newMeterValue;
-    uint8_t isCalculation;
-    float _chargingValue;
-    float _curTotalCharging;
-};
-
-struct MeterInformation {
-    struct StructMeter _meter[2];
-    uint8_t isWorking;
-};
-
-struct DcCommonInformation {
-    // check if the guns are of the same type
-    uint8_t SysGunAreSameType;
-    // to check the ccs version
-    uint8_t CcsVersion;
-    // for relay welding/driving check
-    char RelayCheckStatus[6];
-    char GunRelayWeldingOccur[2];
-    char GunRelayDrivingOccur[2];
-};
+//struct StructMeter {
+//    float curMeterValue;
+//    float newMeterValue;
+//    uint8_t isCalculation;
+//    float _chargingValue;
+//    float _curTotalCharging;
+//};
+
+//struct MeterInformation {
+//    struct StructMeter _meter[2];
+//    uint8_t isWorking;
+//};
+
+//struct DcCommonInformation {
+//    // check if the guns are of the same type
+//    uint8_t SysGunAreSameType;
+//    // to check the ccs version
+//    uint8_t CcsVersion;
+//    // for relay welding/driving check
+//    char RelayCheckStatus[6];
+//    char GunRelayWeldingOccur[2];
+//    char GunRelayDrivingOccur[2];
+//};
 
 typedef union {
     uint32_t GunErrMessage;
@@ -312,8 +312,11 @@ typedef union {
 
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
+    uint8_t CcsVersion;
     EvBoardErrMsg ConnectErrList[2]; //connector error list, 0: left gun, 1: right gun
-    uint8_t Reserved[3];
+    uint8_t CheckRelayStatus[6]; //check Relay welding or driving fault
+    uint8_t GunRelayWeldingOccur[2];
+    uint8_t GunRelayDrivingOccur[2];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 253 - 0
EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c

@@ -0,0 +1,253 @@
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+
+//------------------------------------------------------------------------------
+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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+
+        if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local charging record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local charging record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local config table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local config table successfully\n");
+        }
+
+        //DS60-120
+        if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create reboot record table error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert local charging record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete local charging error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
+
+        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
+        sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
+        log_info("sqlStr= %s\r\n", sqlStr);
+        if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "update config error message: %s\n", errMsg);
+        } else {
+            log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+        }
+
+        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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "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;
+                }
+                log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
+            }
+        } else {
+            log_info("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;
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "delete reboot record successfully\n");
+        }
+
+        sqlite3_close(db);
+    }
+
+    return result;
+}

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

@@ -0,0 +1,5 @@
+#ifndef _DATA_BASE_H_
+#define _DATA_BASE_H_
+
+
+#endif /* _DATA_BASE_H_ */

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

@@ -0,0 +1,7 @@
+2021/05/25
+1. Add detected chiller temperature and stop charging when it exceeds 90°C.
+2. Fix multi dispenser reboot, DHCP IP address conflict issue.
+3. Fix the GFD test failed and the alarm code was not recorded.
+4. Fix ccs OVP status code not release issue.
+5. Add to complete the registration but did not get the balance to restart DoComm.
+6. Add button stop charging function.

+ 63 - 0
EVSE/Projects/DD360Audi/Apps/Log/log.c

@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <unistd.h>
+#include <time.h>
+#include <stdarg.h>
+
+#include <sys/timeb.h>
+
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+#include "log.h"
+
+//------------------------------------------------------------------------------
+#define YES                                     1
+#define NO                                      0
+
+//------------------------------------------------------------------------------
+int StoreLogMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256] = {0};
+    char buffer[4096] = {0};
+    int rc = -1;
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    va_start(args, fmt);
+    rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    if (pSysConfig->SwitchDebugFlag == YES) {
+        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                SeqEndTime.millitm,
+                buffer);
+        printf("%s\r\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;
+}

+ 12 - 0
EVSE/Projects/DD360Audi/Apps/Log/log.h

@@ -0,0 +1,12 @@
+#ifndef _LOG_H_
+#define _LOG_H_
+
+//------------------------------------------------------------------------------
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
+int StoreLogMsg(const char *fmt, ...);
+
+#endif /* _LOG_H_ */

+ 48 - 10
EVSE/Projects/DD360Audi/Apps/Makefile

@@ -12,6 +12,10 @@ TFLAGS = -lrt -lm -lpthread
 
 TOP = .
 
+INC_FLAGS += -I $(TOP)/Define
+INC_FLAGS += -I $(TOP)/Log
+INC_FLAGS += -I $(TOP)/ShareMemory
+INC_FLAGS += -I $(TOP)/CSU
 INC_FLAGS += -I $(TOP)/ModuleInternalComm
 INC_FLAGS += -I $(TOP)/ModuleEvComm
 INC_FLAGS += -I $(TOP)/ModulePrimary
@@ -20,13 +24,16 @@ INC_FLAGS += -I $(TOP)/ModuleDoComm
 INC_FLAGS += -I $(TOP)/ModuleEventLog
 
 DefineLib = $(TOP)/Define
+LogLib = $(TOP)/Log
 ShmMemLib = $(TOP)/ShareMemory
+CSULib = $(TOP)/CSU
 InternalCommLib = $(TOP)/ModuleInternalComm
 EvCommLib = $(TOP)/ModuleEvComm
 PrimaryLib = $(TOP)/ModulePrimary
 LcmLib = $(TOP)/ModuleLcmCtrl
 DoCommLib = $(TOP)/ModuleDoComm
 EventLogLib = $(TOP)/ModuleEventLog
+SelectGunLib = $(TOP)/SelectGun
 ScriptLib = $(TOP)/Script
 
 
@@ -50,15 +57,46 @@ RatedCurrent_H = -include$(ModularizationPath)/Module_RatedCurrent.h
 InfypwrPsuComm_H = -include$(ModularizationPath)/Infypwr_PsuCommObj.h
 InfypwrPsuComm_A = $(ModularizationPath)/libInfypwr_PsuCommObj.a
 
+#common lib
+COMMON_OBJ_FILES = common.o \
+					$(DefineLib)/define.o \
+					$(ShmMemLib)/shmMem.o \
+					$(LogLib)/log.o \
+					$(SelectGunLib)/SelectGun.o
+#main
+MAIN_OBJ_FILES = $(COMMON_OBJ_FILES) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(Lib_Module_RatedCurrent) \
+					main.o $(CSULib)/Primary.o
+MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
+#internal comm lib
+INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o $(InternalCommLib)/Module_InternalComm.o \
+							$(InternalCommLib)/FanBoard.o $(InternalCommLib)/LEDlight.o $(InternalCommLib)/RelayBoard.o \
+								$(InternalCommLib)/AcPlug.o
+INTERNALCOMM_SRC_FILES = $(patsubst %.o, %.c, $(INTERNALCOMM_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
+#EV comm lib
+EVCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(RatedCurrent_H) $(EvCommLib)/Module_EvTxComm.o \
+					$(EvCommLib)/Module_EvRxComm.o $(EvCommLib)/Ev_Comm.o $(EvCommLib)/AbnormalCCS.o \
+						$(EvCommLib)/AbnormalCHA.o $(EvCommLib)/AbnormalGBT.o $(EvCommLib)/AbnormalState.o
+EVCOMM_SRC_FILES = $(patsubst %.o, %.c, $(EVCOMM_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
+
 all: CopyFile apps
-#apps: Module_CSU Module_EvComm Module_EventLogging Module_InternalComm Module_LcmControl Module_PrimaryComm Module_PsuComm
-# ReadCmdline kill.sh
+
 apps: MainTask DoCommTask EvCommTask \
 		EventLoggingTask InternalCommTask LcmControlTask \
 			PrimaryCommTask ReadCmdlineTask UnsafetyOutputTool \
 				FactoryConfigApp OtherTools CleanExec
 
 MainTask:
+	#$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) ${Lib_Module_RFID} \
+	#	 ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent) -o main
 	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o main.o main.c
 	$(CC) $(DEFINE) $(SQLite3_H) $(ModuleUpgrade_H) $(RFID_H) $(RatedCurrent_H) $(CFLAGS) -c -o timeout.o timeout.c
 	$(CC) $(DEFINE) $(CFLAGS) -c -o common.o common.c
@@ -70,9 +108,10 @@ DoCommTask:
 	$(CC) -o Module_DoComm DoComm.o define.o
 
 EvCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
-	$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
-	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
+	$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Ev_Comm.o $(EvCommLib)/Ev_Comm.c
+	#$(CC) $(DEFINE) $(CFLAGS) $(RatedCurrent_H) -c -o Module_EvComm.o $(EvCommLib)/Module_EvComm.c
+	#$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
 
 EventLoggingTask:
 	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
@@ -80,11 +119,10 @@ EventLoggingTask:
 	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
 
 InternalCommTask:
-	#$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o ShmMem.o $(ShmMemLib)/shmMem.c
-	#$(CC) $(DEFINE) $(CFLAGS) $(ModuleRelay_H) -c -o Relay.o $(InternalCommLib)/Relay.c ShmMem.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)
+	$(CC) $(DEFINE) $(INTERNALCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_InternalComm
+	#$(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) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c

+ 913 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCCS.c

@@ -0,0 +1,913 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+void ClearAbnormalStatus_CCS(uint8_t gun_index)
+{
+    bool isCleanCheck = false;
+    char code[7];
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
+        return;
+    }
+
+    if (true) {
+        if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "012219", 6) == EQUAL &&
+                pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
+            memcpy(code, "012219", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023701", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEvCommFail == YES) {
+            memcpy(code, "023701", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023737", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit == YES) {
+            memcpy(code, "023737", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023738", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVShiftPosition == YES) {
+            memcpy(code, "023738", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023739", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargerConnectorLockFault == YES) {
+            memcpy(code, "023739", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023740", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVRESSMalfunction == YES) {
+            memcpy(code, "023740", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023741", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingCurrentdifferential == YES) {
+            memcpy(code, "023741", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023742", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingVoltageOutOfRange == YES) {
+            memcpy(code, "023742", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023743", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingSystemIncompatibility == YES) {
+            memcpy(code, "023743", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023744", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEmergencyEvent == YES) {
+            memcpy(code, "023744", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023745", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsBreaker == YES) {
+            memcpy(code, "023745", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023746", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoData == YES) {
+            memcpy(code, "023746", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023747", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_A == YES) {
+            memcpy(code, "023747", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023748", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_B == YES) {
+            memcpy(code, "023748", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023749", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_C == YES) {
+            memcpy(code, "023749", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023750", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_1 == YES) {
+            memcpy(code, "023750", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023751", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_2 == YES) {
+            memcpy(code, "023751", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023752", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_3 == YES) {
+            memcpy(code, "023752", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023753", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_1 == YES) {
+            memcpy(code, "023753", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023754", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_2 == YES) {
+            memcpy(code, "023754", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023755", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_3 == YES) {
+            memcpy(code, "023755", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023756", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_4 == YES) {
+            memcpy(code, "023756", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023757", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_5 == YES) {
+            memcpy(code, "023757", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023758", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSequenceError == YES) {
+            memcpy(code, "023758", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023759", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSignatureError == YES) {
+            memcpy(code, "023759", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023760", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsUnknownSession == YES) {
+            memcpy(code, "023760", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023761", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServiceIDInvalid == YES) {
+            memcpy(code, "023761", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023762", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPaymentSelectionInvalid == YES) {
+            memcpy(code, "023762", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023763", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsIdentificationSelectionInvalid == YES) {
+            memcpy(code, "023763", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023764", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServiceSelectionInvalid == YES) {
+            memcpy(code, "023764", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023765", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateExpired == YES) {
+            memcpy(code, "023765", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023766", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateNotYetValid == YES) {
+            memcpy(code, "023766", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023767", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateRevoked == YES) {
+            memcpy(code, "023767", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023768", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoCertificateAvailable == YES) {
+            memcpy(code, "023768", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023769", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertChainError == YES) {
+            memcpy(code, "023769", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023770", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertValidationError == YES) {
+            memcpy(code, "023770", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023771", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertVerificationError == YES) {
+            memcpy(code, "023771", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023772", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContractCanceled == YES) {
+            memcpy(code, "023772", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023773", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChallengeInvalid == YES) {
+            memcpy(code, "023773", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023774", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsWrongEnergyTransferMode == YES) {
+            memcpy(code, "023774", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023775", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsWrongChargeParameter == YES) {
+            memcpy(code, "023775", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023776", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargingProfileInvalid == YES) {
+            memcpy(code, "023776", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023777", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTariffSelectionInvalid == YES) {
+            memcpy(code, "023777", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023778", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVSEPresentVoltageToLow == YES) {
+            memcpy(code, "023778", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023779", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPowerDeliveryNotApplied == YES) {
+            memcpy(code, "023779", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023780", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMeteringSignatureNotValid == YES) {
+            memcpy(code, "023780", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023781", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoChargeServiceSelected == YES) {
+            memcpy(code, "023781", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023782", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContactorError == YES) {
+            memcpy(code, "023782", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023783", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE == YES) {
+            memcpy(code, "023783", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023784", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsGAChargeStop == YES) {
+            memcpy(code, "023784", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023785", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsAlignmentError == YES) {
+            memcpy(code, "023785", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023786", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsACDError == YES) {
+            memcpy(code, "023786", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023787", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsAssociationError == YES) {
+            memcpy(code, "023787", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023788", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsEVSEChargeAbort == YES) {
+            memcpy(code, "023788", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023789", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsNoSupportedAppProtocol == YES) {
+            memcpy(code, "023789", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023790", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContractNotAccepted == YES) {
+            memcpy(code, "023790", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023791", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMOUnknown == YES) {
+            memcpy(code, "023791", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023792", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_Prov_CertificateRevoke == YES) {
+            memcpy(code, "023792", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023793", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked == YES) {
+            memcpy(code, "023793", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023794", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked == YES) {
+            memcpy(code, "023794", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023795", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked == YES) {
+            memcpy(code, "023795", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023796", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_Prov_CertificateRevoked == YES) {
+            memcpy(code, "023796", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023797", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked == YES) {
+            memcpy(code, "023797", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023798", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked == YES) {
+            memcpy(code, "023798", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023799", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMO_RootCA_CertificateRevoked == YES) {
+            memcpy(code, "023799", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023800", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_Prov_CertificateRevoked == YES) {
+            memcpy(code, "023800", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023801", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked == YES) {
+            memcpy(code, "023801", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023802", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked == YES) {
+            memcpy(code, "023802", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023803", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked == YES) {
+            memcpy(code, "023803", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023809", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_SLAC_init == YES) {
+            memcpy(code, "023809", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023810", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_match_response == YES) {
+            memcpy(code, "023810", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023811", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_match_sequence == YES) {
+            memcpy(code, "023811", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023812", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_match_MNBC == YES) {
+            memcpy(code, "023812", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023813", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_avg_atten_calc == YES) {
+            memcpy(code, "023813", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023814", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_match_response == YES) {
+            memcpy(code, "023814", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023815", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_match_session == YES) {
+            memcpy(code, "023815", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023816", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_assoc_session == YES) {
+            memcpy(code, "023816", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023817", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_vald_toggle == YES) {
+            memcpy(code, "023817", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023818", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound == YES) {
+            memcpy(code, "023818", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023819", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq == YES) {
+            memcpy(code, "023819", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023823", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsUDP_TT_match_join == YES) {
+            memcpy(code, "023823", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023824", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTCP_TT_match_join == YES) {
+            memcpy(code, "023824", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023825", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_amp_map_exchange == YES) {
+            memcpy(code, "023825", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023826", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_link_ready_notification == YES) {
+            memcpy(code, "023826", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023832", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSupportedAppProtocolRes == YES) {
+            memcpy(code, "023832", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023833", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSessionSetupRes == YES) {
+            memcpy(code, "023833", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023834", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServiceDiscoveryRes == YES) {
+            memcpy(code, "023834", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023835", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsServicePaymentSelectionRes == YES) {
+            memcpy(code, "023835", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023836", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsContractAuthenticationRes == YES) {
+            memcpy(code, "023836", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023837", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsChargeParameterDiscoveryRes == YES) {
+            memcpy(code, "023837", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023838", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPowerDeliveryRes == YES) {
+            memcpy(code, "023838", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023839", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCableCheckRes == YES) {
+            memcpy(code, "023839", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023840", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsPreChargeRes == YES) {
+            memcpy(code, "023840", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023841", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCurrentDemandRes == YES) {
+            memcpy(code, "023841", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023842", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsWeldingDetectionRes == YES) {
+            memcpy(code, "023842", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023843", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSessionStopRes == YES) {
+            memcpy(code, "023843", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023844", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSequence_Time == YES) {
+            memcpy(code, "023844", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023845", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsReadyToCharge_Performance_Time == YES) {
+            memcpy(code, "023845", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023846", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCommunicationSetup_Performance_Time == YES) {
+            memcpy(code, "023846", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023847", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCableCheck_Performance_Time == YES) {
+            memcpy(code, "023847", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023848", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPState_Detection_Time == YES) {
+            memcpy(code, "023848", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023849", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCPOscillator_Retain_Time == YES) {
+            memcpy(code, "023849", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023850", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime == YES) {
+            memcpy(code, "023850", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023855", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO == YES) {
+            memcpy(code, "023855", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023856", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO == YES) {
+            memcpy(code, "023856", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023857", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO == YES) {
+            memcpy(code, "023857", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023858", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO == YES) {
+            memcpy(code, "023858", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023859", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EV_STOP_EVENT == YES) {
+            memcpy(code, "023859", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023860", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EV_STOP_EVENT == YES) {
+            memcpy(code, "023860", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023861", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_STOP_EVENT == YES) {
+            memcpy(code, "023861", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023862", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_STOP_EVENT == YES) {
+            memcpy(code, "023862", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023863", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_GET_MISC_INFO == YES) {
+            memcpy(code, "023863", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023864", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_GET_MISC_INFO == YES) {
+            memcpy(code, "023864", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023865", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST == YES) {
+            memcpy(code, "023865", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023866", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST == YES) {
+            memcpy(code, "023866", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023867", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER == YES) {
+            memcpy(code, "023867", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023868", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER == YES) {
+            memcpy(code, "023868", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023869", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_DATA_TRANSFER == YES) {
+            memcpy(code, "023869", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023870", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_DATA_TRANSFER == YES) {
+            memcpy(code, "023870", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023871", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_FINISH == YES) {
+            memcpy(code, "023871", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023872", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_FINISH == YES) {
+            memcpy(code, "023872", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023873", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_ISOLATION_STATUS == YES) {
+            memcpy(code, "023873", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023874", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_ISOLATION_STATUS == YES) {
+            memcpy(code, "023874", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023875", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_CONNECTOR_INFO == YES) {
+            memcpy(code, "023875", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023876", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_CONNECTOR_INFO == YES) {
+            memcpy(code, "023876", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023877", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_RTC_INFO == YES) {
+            memcpy(code, "023877", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023878", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_RTC_INFO == YES) {
+            memcpy(code, "023878", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023879", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO == YES) {
+            memcpy(code, "023879", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023880", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO == YES) {
+            memcpy(code, "023880", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023881", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsMSG_Sequence == YES) {
+            memcpy(code, "023881", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023882", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID == YES) {
+            memcpy(code, "023882", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023883", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsDIN_Msg_Decode_Error == YES) {
+            memcpy(code, "023883", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023884", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsDIN_Msg_Encode_Error == YES) {
+            memcpy(code, "023884", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023885", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO1_Msg_Decode_Error == YES) {
+            memcpy(code, "023885", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023886", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO1_Msg_Encode_Error == YES) {
+            memcpy(code, "023886", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023887", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO2_Msg_Decode_Error == YES) {
+            memcpy(code, "023887", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023888", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsISO2_Msg_Encode_Error == YES) {
+            memcpy(code, "023888", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023889", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsCpStatus_Error == YES) {
+            memcpy(code, "023889", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023890", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error == YES) {
+            memcpy(code, "023890", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023891", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.CcsSeccNotReadyForCharging == YES) {
+            memcpy(code, "023891", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+//  else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023892", 6) == EQUAL &&
+//          pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
+//  {
+//      memcpy(code, "023892", 6);
+//      memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+//      isCleanCheck = true;
+//  }
+        else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023893", 6) == EQUAL &&
+                 pInfoCode->InfoEvents.bits.CcsSeccFailForQCA7000SetKey == YES) {
+            memcpy(code, "023893", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023979", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.EV_Full_Charging == YES) {
+            memcpy(code, "023979", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023983", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason == YES) {
+            memcpy(code, "023983", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+            if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                log_info("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
+                         index,
+                         pDcChargingInfo->EvConnAlarmCode,
+                         code);
+
+                if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+                    if (strncmp(code, "012219", 6) == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO; }
+
+                    if (strncmp(code, "023701", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = NO; }
+                    if (strncmp(code, "023737", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit = NO; }
+                    if (strncmp(code, "023738", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVShiftPosition = NO; }
+                    if (strncmp(code, "023739", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargerConnectorLockFault = NO; }
+                    if (strncmp(code, "023740", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVRESSMalfunction = NO; }
+                    if (strncmp(code, "023741", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingCurrentdifferential = NO; }
+                    if (strncmp(code, "023742", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingVoltageOutOfRange = NO; }
+                    if (strncmp(code, "023743", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingSystemIncompatibility = NO; }
+                    if (strncmp(code, "023744", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEmergencyEvent = NO; }
+                    if (strncmp(code, "023745", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsBreaker = NO; }
+                    if (strncmp(code, "023746", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoData = NO; }
+                    if (strncmp(code, "023747", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_A = NO; }
+                    if (strncmp(code, "023748", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_B = NO; }
+                    if (strncmp(code, "023749", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_C = NO; }
+                    if (strncmp(code, "023750", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_1 = NO; }
+                    if (strncmp(code, "023751", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_2 = NO; }
+                    if (strncmp(code, "023752", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_3 = NO; }
+                    if (strncmp(code, "023753", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_1 = NO; }
+                    if (strncmp(code, "023754", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_2 = NO; }
+                    if (strncmp(code, "023755", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_3 = NO; }
+                    if (strncmp(code, "023756", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_4 = NO; }
+                    if (strncmp(code, "023757", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_5 = NO; }
+                    if (strncmp(code, "023758", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequenceError = NO; }
+                    if (strncmp(code, "023759", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSignatureError = NO; }
+                    if (strncmp(code, "023760", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnknownSession = NO; }
+                    if (strncmp(code, "023761", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceIDInvalid = NO; }
+                    if (strncmp(code, "023762", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPaymentSelectionInvalid = NO; }
+                    if (strncmp(code, "023763", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsIdentificationSelectionInvalid = NO; }
+                    if (strncmp(code, "023764", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceSelectionInvalid = NO; }
+                    if (strncmp(code, "023765", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateExpired = NO; }
+                    if (strncmp(code, "023766", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotYetValid = NO; }
+                    if (strncmp(code, "023767", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateRevoked = NO; }
+                    if (strncmp(code, "023768", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoCertificateAvailable = NO; }
+                    if (strncmp(code, "023769", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertChainError = NO; }
+                    if (strncmp(code, "023770", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertValidationError = NO; }
+                    if (strncmp(code, "023771", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertVerificationError = NO; }
+                    if (strncmp(code, "023772", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractCanceled = NO; }
+                    if (strncmp(code, "023773", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChallengeInvalid = NO; }
+                    if (strncmp(code, "023774", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongEnergyTransferMode = NO; }
+                    if (strncmp(code, "023775", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongChargeParameter = NO; }
+                    if (strncmp(code, "023776", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingProfileInvalid = NO; }
+                    if (strncmp(code, "023777", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTariffSelectionInvalid = NO; }
+                    if (strncmp(code, "023778", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEPresentVoltageToLow = NO; }
+                    if (strncmp(code, "023779", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryNotApplied = NO; }
+                    if (strncmp(code, "023780", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMeteringSignatureNotValid = NO; }
+                    if (strncmp(code, "023781", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoChargeServiceSelected = NO; }
+                    if (strncmp(code, "023782", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContactorError = NO; }
+                    if (strncmp(code, "023783", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = NO; }
+                    if (strncmp(code, "023784", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsGAChargeStop = NO; }
+                    if (strncmp(code, "023785", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsAlignmentError = NO; }
+                    if (strncmp(code, "023786", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsACDError = NO; }
+                    if (strncmp(code, "023787", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsAssociationError = NO; }
+                    if (strncmp(code, "023788", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEChargeAbort = NO; }
+                    if (strncmp(code, "023789", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoSupportedAppProtocol = NO; }
+                    if (strncmp(code, "023790", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractNotAccepted = NO; }
+                    if (strncmp(code, "023791", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMOUnknown = NO; }
+                    if (strncmp(code, "023792", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = NO; }
+                    if (strncmp(code, "023793", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = NO; }
+                    if (strncmp(code, "023794", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = NO; }
+                    if (strncmp(code, "023795", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = NO; }
+                    if (strncmp(code, "023796", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_Prov_CertificateRevoked = NO; }
+                    if (strncmp(code, "023797", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = NO; }
+                    if (strncmp(code, "023798", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = NO; }
+                    if (strncmp(code, "023799", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = NO; }
+                    if (strncmp(code, "023800", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = NO; }
+                    if (strncmp(code, "023801", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = NO; }
+                    if (strncmp(code, "023802", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = NO; }
+                    if (strncmp(code, "023803", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = NO; }
+                    if (strncmp(code, "023809", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_SLAC_init = NO; }
+                    if (strncmp(code, "023810", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_match_response = NO; }
+                    if (strncmp(code, "023811", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_sequence = NO; }
+                    if (strncmp(code, "023812", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_match_MNBC = NO; }
+                    if (strncmp(code, "023813", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = NO; }
+                    if (strncmp(code, "023814", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_response = NO; }
+                    if (strncmp(code, "023815", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_match_session = NO; }
+                    if (strncmp(code, "023816", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_assoc_session = NO; }
+                    if (strncmp(code, "023817", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_vald_toggle = NO; }
+                    if (strncmp(code, "023818", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = NO; }
+                    if (strncmp(code, "023819", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = NO; }
+                    if (strncmp(code, "023823", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsUDP_TT_match_join = NO; }
+                    if (strncmp(code, "023824", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTCP_TT_match_join = NO; }
+                    if (strncmp(code, "023825", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_amp_map_exchange = NO; }
+                    if (strncmp(code, "023826", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_link_ready_notification = NO; }
+                    if (strncmp(code, "023832", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSupportedAppProtocolRes = NO; }
+                    if (strncmp(code, "023833", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionSetupRes = NO; }
+                    if (strncmp(code, "023834", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceDiscoveryRes = NO; }
+                    if (strncmp(code, "023835", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsServicePaymentSelectionRes = NO; }
+                    if (strncmp(code, "023836", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractAuthenticationRes = NO; }
+                    if (strncmp(code, "023837", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargeParameterDiscoveryRes = NO; }
+                    if (strncmp(code, "023838", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryRes = NO; }
+                    if (strncmp(code, "023839", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheckRes = NO; }
+                    if (strncmp(code, "023840", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsPreChargeRes = NO; }
+                    if (strncmp(code, "023841", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCurrentDemandRes = NO; }
+                    if (strncmp(code, "023842", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsWeldingDetectionRes = NO; }
+                    if (strncmp(code, "023843", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionStopRes = NO; }
+                    if (strncmp(code, "023844", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequence_Time = NO; }
+                    if (strncmp(code, "023845", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsReadyToCharge_Performance_Time = NO; }
+                    if (strncmp(code, "023846", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCommunicationSetup_Performance_Time = NO; }
+                    if (strncmp(code, "023847", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheck_Performance_Time = NO; }
+                    if (strncmp(code, "023848", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPState_Detection_Time = NO; }
+                    if (strncmp(code, "023849", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPOscillator_Retain_Time = NO; }
+                    if (strncmp(code, "023850", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = NO; }
+                    if (strncmp(code, "023855", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = NO; }
+                    if (strncmp(code, "023856", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = NO; }
+                    if (strncmp(code, "023857", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = NO; }
+                    if (strncmp(code, "023858", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = NO; }
+                    if (strncmp(code, "023859", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EV_STOP_EVENT = NO; }
+                    if (strncmp(code, "023860", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EV_STOP_EVENT = NO; }
+                    if (strncmp(code, "023861", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = NO; }
+                    if (strncmp(code, "023862", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = NO; }
+                    if (strncmp(code, "023863", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_MISC_INFO = NO; }
+                    if (strncmp(code, "023864", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_MISC_INFO = NO; }
+                    if (strncmp(code, "023865", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = NO; }
+                    if (strncmp(code, "023866", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = NO; }
+                    if (strncmp(code, "023867", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = NO; }
+                    if (strncmp(code, "023868", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = NO; }
+                    if (strncmp(code, "023869", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DATA_TRANSFER = NO; }
+                    if (strncmp(code, "023870", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DATA_TRANSFER = NO; }
+                    if (strncmp(code, "023871", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = NO; }
+                    if (strncmp(code, "023872", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = NO; }
+                    if (strncmp(code, "023873", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_ISOLATION_STATUS = NO; }
+                    if (strncmp(code, "023874", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_ISOLATION_STATUS = NO; }
+                    if (strncmp(code, "023875", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_CONNECTOR_INFO = NO; }
+                    if (strncmp(code, "023876", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_CONNECTOR_INFO = NO; }
+                    if (strncmp(code, "023877", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_RTC_INFO = NO; }
+                    if (strncmp(code, "023878", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_RTC_INFO = NO; }
+                    if (strncmp(code, "023879", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = NO; }
+                    if (strncmp(code, "023880", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = NO; }
+                    if (strncmp(code, "023881", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsMSG_Sequence = NO; }
+                    if (strncmp(code, "023882", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = NO; }
+                    if (strncmp(code, "023883", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Decode_Error = NO; }
+                    if (strncmp(code, "023884", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Encode_Error = NO; }
+                    if (strncmp(code, "023885", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Decode_Error = NO; }
+                    if (strncmp(code, "023886", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Encode_Error = NO; }
+                    if (strncmp(code, "023887", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Decode_Error = NO; }
+                    if (strncmp(code, "023888", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Encode_Error = NO; }
+                    if (strncmp(code, "023889", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsCpStatus_Error = NO; }
+                    if (strncmp(code, "023890", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = NO; }
+                    if (strncmp(code, "023891", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccNotReadyForCharging = NO; }
+                    //if (strncmp(code, "023892", 6) == EQUAL) pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = NO;
+                    if (strncmp(code, "023893", 6) == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccFailForQCA7000SetKey = NO; }
+
+                    if (strncmp(code, "023979", 6) == EQUAL) { pInfoCode->InfoEvents.bits.EV_Full_Charging = NO; }
+                    if (strncmp(code, "023983", 6) == EQUAL) { pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason = NO; }
+                }
+            }
+        }
+    }
+}

+ 247 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalCHA.c

@@ -0,0 +1,247 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+void ClearAbnormalStatus_Chademo(uint8_t gun_index)
+{
+    bool isCleanCheck = false;
+    char code[7];
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
+        return;
+    }
+
+    if (true) {
+        if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023700", 6) == EQUAL &&
+                pInfoCode->InfoEvents.bits.ChademoEvCommFail == YES) {
+            memcpy(code, "023700", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023704", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryMalfun == YES) {
+            memcpy(code, "023704", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023705", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoNoPermission == YES) {
+            memcpy(code, "023705", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023706", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryIncompatibility == YES) {
+            memcpy(code, "023706", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023707", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryOVP == YES) {
+            memcpy(code, "023707", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023708", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryUVP == YES) {
+            memcpy(code, "023708", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023709", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryOTP == YES) {
+            memcpy(code, "023709", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023710", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryCurrentDiff == YES) {
+            memcpy(code, "023710", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023711", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryVoltageDiff == YES) {
+            memcpy(code, "023711", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023712", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoShiftPosition == YES) {
+            memcpy(code, "023712", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023713", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBatteryOtherFault == YES) {
+            memcpy(code, "023713", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023714", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargingSystemError == YES) {
+            memcpy(code, "023714", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023715", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoEvNormalStop == YES) {
+            memcpy(code, "023715", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023716", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoTempSensorBroken == YES) {
+            memcpy(code, "023716", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023717", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoConnectorLockFail == YES) {
+            memcpy(code, "023717", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023718", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoD1OnNoReceive == YES) {
+            memcpy(code, "023718", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023719", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsKtoJTimeout == YES) {
+            memcpy(code, "023719", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023720", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsChargeAllowTimeout == YES) {
+            memcpy(code, "023720", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023721", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoWaitGfdTimeout == YES) {
+            memcpy(code, "023721", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023722", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsEvRelayTimeout == YES) {
+            memcpy(code, "023722", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023723", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsReqCurrentTimeout == YES) {
+            memcpy(code, "023723", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023724", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsKtoJOffTimeout == YES) {
+            memcpy(code, "023724", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023725", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsEvRelayOffTimeout == YES) {
+            memcpy(code, "023725", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023726", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoAdcMoreThan10V == YES) {
+            memcpy(code, "023726", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023727", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoAdcMoreThan20V == YES) {
+            memcpy(code, "023727", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023728", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoBmsChargeBeforeStop == YES) {
+            memcpy(code, "023728", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023729", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargerGetNormalStop == YES) {
+            memcpy(code, "023729", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023730", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
+            memcpy(code, "023730", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023731", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoIsolationResultFail == YES) {
+            memcpy(code, "023731", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023732", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoMissLinkWithMotherBoard == YES) {
+            memcpy(code, "023732", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023733", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoOutputVolMoreThanLimit == YES) {
+            memcpy(code, "023733", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023734", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoReqCurrentMoreThanLimit == YES) {
+            memcpy(code, "023734", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023735", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed == YES) {
+            memcpy(code, "023735", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023736", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown == YES) {
+            memcpy(code, "023736", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+            if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                log_info("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
+                         index,
+                         pDcChargingInfo->EvConnAlarmCode,
+                         code);
+
+                if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+                    if (strncmp(code, "023700", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvCommFail = NO; }
+                    if (strncmp(code, "023704", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryMalfun = NO; }
+                    if (strncmp(code, "023705", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoNoPermission = NO; }
+                    if (strncmp(code, "023706", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryIncompatibility = NO; }
+                    if (strncmp(code, "023707", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOVP = NO; }
+                    if (strncmp(code, "023708", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryUVP = NO; }
+                    if (strncmp(code, "023709", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOTP = NO; }
+                    if (strncmp(code, "023710", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryCurrentDiff = NO; }
+                    if (strncmp(code, "023711", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryVoltageDiff = NO; }
+                    if (strncmp(code, "023712", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoShiftPosition = NO; }
+                    if (strncmp(code, "023713", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOtherFault = NO; }
+                    if (strncmp(code, "023714", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargingSystemError = NO; }
+                    if (strncmp(code, "023715", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvNormalStop = NO; }
+                    if (strncmp(code, "023716", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoTempSensorBroken = NO; }
+                    if (strncmp(code, "023717", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoConnectorLockFail = NO; }
+                    if (strncmp(code, "023718", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoD1OnNoReceive = NO; }
+                    if (strncmp(code, "023719", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJTimeout = NO; }
+                    if (strncmp(code, "023720", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeAllowTimeout = NO; }
+                    if (strncmp(code, "023721", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoWaitGfdTimeout = NO; }
+                    if (strncmp(code, "023722", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayTimeout = NO; }
+                    if (strncmp(code, "023723", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsReqCurrentTimeout = NO; }
+                    if (strncmp(code, "023724", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJOffTimeout = NO; }
+                    if (strncmp(code, "023725", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayOffTimeout = NO; }
+                    if (strncmp(code, "023726", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan10V = NO; }
+                    if (strncmp(code, "023727", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan20V = NO; }
+                    if (strncmp(code, "023728", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeBeforeStop = NO; }
+                    if (strncmp(code, "023729", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetNormalStop = NO; }
+                    if (strncmp(code, "023730", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = NO; }
+                    if (strncmp(code, "023731", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoIsolationResultFail = NO; }
+                    if (strncmp(code, "023732", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoMissLinkWithMotherBoard = NO; }
+                    if (strncmp(code, "023733", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoOutputVolMoreThanLimit = NO; }
+                    if (strncmp(code, "023734", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReqCurrentMoreThanLimit = NO; }
+                    if (strncmp(code, "023735", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = NO; }
+                    if (strncmp(code, "023736", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown = NO; }
+                }
+            }
+        }
+    }
+}

+ 415 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalGBT.c

@@ -0,0 +1,415 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+void ClearAbnormalStatus_GB(uint8_t gun_index)
+{
+    bool isCleanCheck = false;
+    char code[7];
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) == EQUAL) {
+        return;
+    }
+
+    if (true) {
+        if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023702", 6) == EQUAL &&
+                pInfoCode->InfoEvents.bits.GbEvCommFail == YES) {
+            memcpy(code, "023702", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023900", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 == YES) {
+            memcpy(code, "023900", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023901", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL == YES) {
+            memcpy(code, "023901", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023902", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE == YES) {
+            memcpy(code, "023902", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023903", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT == YES) {
+            memcpy(code, "023903", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023904", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT == YES) {
+            memcpy(code, "023904", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023905", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT == YES) {
+            memcpy(code, "023905", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023906", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE == YES) {
+            memcpy(code, "023906", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023907", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE == YES) {
+            memcpy(code, "023907", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023908", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT == YES) {
+            memcpy(code, "023908", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023909", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V == YES) {
+            memcpy(code, "023909", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023910", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V == YES) {
+            memcpy(code, "023910", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023911", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD == YES) {
+            memcpy(code, "023911", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023912", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD == YES) {
+            memcpy(code, "023912", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023913", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL == YES) {
+            memcpy(code, "023913", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023914", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK == YES) {
+            memcpy(code, "023914", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023915", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT == YES) {
+            memcpy(code, "023915", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023916", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT == YES) {
+            memcpy(code, "023916", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023917", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT == YES) {
+            memcpy(code, "023917", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023918", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT == YES) {
+            memcpy(code, "023918", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023919", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V == YES) {
+            memcpy(code, "023919", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023930", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT == YES) {
+            memcpy(code, "023930", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023931", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT == YES) {
+            memcpy(code, "023931", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023932", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT == YES) {
+            memcpy(code, "023932", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023933", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT == YES) {
+            memcpy(code, "023933", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023934", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT == YES) {
+            memcpy(code, "023934", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023935", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT == YES) {
+            memcpy(code, "023935", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023936", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT == YES) {
+            memcpy(code, "023936", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023937", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT == YES) {
+            memcpy(code, "023937", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023938", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT == YES) {
+            memcpy(code, "023938", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023939", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT == YES) {
+            memcpy(code, "023939", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023940", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT == YES) {
+            memcpy(code, "023940", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023941", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT == YES) {
+            memcpy(code, "023941", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023942", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT == YES) {
+            memcpy(code, "023942", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023943", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT == YES) {
+            memcpy(code, "023943", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023944", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT == YES) {
+            memcpy(code, "023944", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023945", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT == YES) {
+            memcpy(code, "023945", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023946", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT == YES) {
+            memcpy(code, "023946", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023947", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT == YES) {
+            memcpy(code, "023947", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023950", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL == YES) {
+            memcpy(code, "023950", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023951", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL == YES) {
+            memcpy(code, "023951", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023952", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL == YES) {
+            memcpy(code, "023952", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023953", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_GET_CST == YES) {
+            memcpy(code, "023953", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023954", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_ISOLATION == YES) {
+            memcpy(code, "023954", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023955", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP == YES) {
+            memcpy(code, "023955", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023956", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_COMPONENT == YES) {
+            memcpy(code, "023956", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023957", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR == YES) {
+            memcpy(code, "023957", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023958", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTP == YES) {
+            memcpy(code, "023958", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023959", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTHER == YES) {
+            memcpy(code, "023959", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023960", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_HIGH_V == YES) {
+            memcpy(code, "023960", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023961", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CC2 == YES) {
+            memcpy(code, "023961", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023962", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CURRENT == YES) {
+            memcpy(code, "023962", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023963", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BST_VOLTAGE == YES) {
+            memcpy(code, "023963", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023964", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON == YES) {
+            memcpy(code, "023964", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023970", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE == YES) {
+            memcpy(code, "023970", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023971", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE == YES) {
+            memcpy(code, "023971", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023972", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC == YES) {
+            memcpy(code, "023972", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023973", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC == YES) {
+            memcpy(code, "023973", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023974", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CURRENT == YES) {
+            memcpy(code, "023974", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023975", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE == YES) {
+            memcpy(code, "023975", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023976", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_ISOLATE == YES) {
+            memcpy(code, "023976", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        } else if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "023977", 6) == EQUAL &&
+                   pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR == YES) {
+            memcpy(code, "023977", 6);
+            memcpy(pDcChargingInfo->EvConnAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+            if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                log_info("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
+                         index,
+                         pDcChargingInfo->EvConnAlarmCode,
+                         code);
+
+                if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
+                    if (strncmp(code, "023702", 6) == EQUAL) { pInfoCode->InfoEvents.bits.GbEvCommFail = NO; }
+                    if (strncmp(code, "023900", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = NO; }
+                    if (strncmp(code, "023901", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = NO; }
+                    if (strncmp(code, "023902", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = NO; }
+                    if (strncmp(code, "023903", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = NO; }
+                    if (strncmp(code, "023904", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = NO; }
+                    if (strncmp(code, "023905", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = NO; }
+                    if (strncmp(code, "023906", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = NO; }
+                    if (strncmp(code, "023907", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = NO; }
+                    if (strncmp(code, "023908", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = NO; }
+                    if (strncmp(code, "023909", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = NO; }
+                    if (strncmp(code, "023910", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = NO; }
+                    if (strncmp(code, "023911", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = NO; }
+                    if (strncmp(code, "023912", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = NO; }
+                    if (strncmp(code, "023913", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = NO; }
+                    if (strncmp(code, "023914", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = NO; }
+                    if (strncmp(code, "023915", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = NO; }
+                    if (strncmp(code, "023916", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = NO; }
+                    if (strncmp(code, "023917", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = NO; }
+                    if (strncmp(code, "023918", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = NO; }
+                    if (strncmp(code, "023919", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = NO; }
+                    if (strncmp(code, "023930", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = NO; }
+                    if (strncmp(code, "023931", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = NO; }
+                    if (strncmp(code, "023932", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = NO; }
+                    if (strncmp(code, "023933", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = NO; }
+                    if (strncmp(code, "023934", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = NO; }
+                    if (strncmp(code, "023935", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = NO; }
+                    if (strncmp(code, "023936", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = NO; }
+                    if (strncmp(code, "023937", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = NO; }
+                    if (strncmp(code, "023938", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = NO; }
+                    if (strncmp(code, "023939", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = NO; }
+                    if (strncmp(code, "023940", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = NO; }
+                    if (strncmp(code, "023941", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = NO; }
+                    if (strncmp(code, "023942", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = NO; }
+                    if (strncmp(code, "023943", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = NO; }
+                    if (strncmp(code, "023944", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = NO; }
+                    if (strncmp(code, "023945", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = NO; }
+                    if (strncmp(code, "023946", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = NO; }
+                    if (strncmp(code, "023947", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = NO; }
+                    if (strncmp(code, "023950", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = NO; }
+                    if (strncmp(code, "023951", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = NO; }
+                    if (strncmp(code, "023952", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = NO; }
+                    if (strncmp(code, "023953", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_GET_CST = NO; }
+                    if (strncmp(code, "023954", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_ISOLATION = NO; }
+                    if (strncmp(code, "023955", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = NO; }
+                    if (strncmp(code, "023956", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_COMPONENT = NO; }
+                    if (strncmp(code, "023957", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = NO; }
+                    if (strncmp(code, "023958", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTP = NO; }
+                    if (strncmp(code, "023959", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTHER = NO; }
+                    if (strncmp(code, "023960", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_HIGH_V = NO; }
+                    if (strncmp(code, "023961", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CC2 = NO; }
+                    if (strncmp(code, "023962", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CURRENT = NO; }
+                    if (strncmp(code, "023963", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = NO; }
+                    if (strncmp(code, "023964", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = NO; }
+                    if (strncmp(code, "023970", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = NO; }
+                    if (strncmp(code, "023971", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = NO; }
+                    if (strncmp(code, "023972", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = NO; }
+                    if (strncmp(code, "023973", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = NO; }
+                    if (strncmp(code, "023974", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CURRENT = NO; }
+                    if (strncmp(code, "023975", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = NO; }
+                    if (strncmp(code, "023976", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = NO; }
+                    if (strncmp(code, "023977", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = NO; }
+                }
+            }
+        }
+    }
+}

+ 291 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/AbnormalState.c

@@ -0,0 +1,291 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
+#include "../Define/define.h"
+
+//------------------------------------------------------------------------------
+bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
+{
+    char string[7];
+
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun_index);
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+
+    sprintf(string, "%d%d%d%d%d%d",
+            *(errCode + 0),
+            *(errCode + 1),
+            *(errCode + 2),
+            *(errCode + 3),
+            *(errCode + 4),
+            *(errCode + 5));
+    //iflog_info("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
+
+    if (strncmp(string, "000000", 6) == EQUAL ||
+            strncmp(string, "023979", 6) == EQUAL) {
+        return false;
+    }
+
+    if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
+        return true;
+    }
+
+    memcpy(pDcChargingInfo->EvConnAlarmCode, string, 6);
+    log_info("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s\n", pDcChargingInfo->EvConnAlarmCode);
+    //OVP error
+    if (strcmp(string, "012217") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES; }
+    if (strcmp(string, "012219") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES; }
+    if (strcmp(string, "012221") == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES; }
+
+    if (strcmp(string, "023700") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvCommFail = YES; }
+    if (strcmp(string, "023704") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryMalfun = YES; }
+    if (strcmp(string, "023705") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoNoPermission = YES; }
+    if (strcmp(string, "023706") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryIncompatibility = YES; }
+    if (strcmp(string, "023707") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOVP = YES; }
+    if (strcmp(string, "023708") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryUVP = YES; }
+    if (strcmp(string, "023709") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOTP = YES; }
+    if (strcmp(string, "023710") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryCurrentDiff = YES; }
+    if (strcmp(string, "023711") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryVoltageDiff = YES; }
+    if (strcmp(string, "023712") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoShiftPosition = YES; }
+    if (strcmp(string, "023713") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryOtherFault = YES; }
+    if (strcmp(string, "023714") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargingSystemError = YES; }
+    if (strcmp(string, "023715") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvNormalStop = YES; }
+    if (strcmp(string, "023716") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoTempSensorBroken = YES; }
+    if (strcmp(string, "023717") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoConnectorLockFail = YES; }
+    if (strcmp(string, "023718") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoD1OnNoReceive = YES; }
+    if (strcmp(string, "023719") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJTimeout = YES; }
+    if (strcmp(string, "023720") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeAllowTimeout = YES; }
+    if (strcmp(string, "023721") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoWaitGfdTimeout = YES; }
+    if (strcmp(string, "023722") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayTimeout = YES; }
+    if (strcmp(string, "023723") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsReqCurrentTimeout = YES; }
+    if (strcmp(string, "023724") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsKtoJOffTimeout = YES; }
+    if (strcmp(string, "023725") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsEvRelayOffTimeout = YES; }
+    if (strcmp(string, "023726") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan10V = YES; }
+    if (strcmp(string, "023727") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoAdcMoreThan20V = YES; }
+    if (strcmp(string, "023728") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBmsChargeBeforeStop = YES; }
+    if (strcmp(string, "023729") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetNormalStop = YES; }
+    if (strcmp(string, "023730") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = YES; }
+    if (strcmp(string, "023731") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoIsolationResultFail = YES; }
+    if (strcmp(string, "023732") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoMissLinkWithMotherBoard = YES; }
+    if (strcmp(string, "023733") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoOutputVolMoreThanLimit = YES; }
+    if (strcmp(string, "023734") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReqCurrentMoreThanLimit = YES; }
+    if (strcmp(string, "023735") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = YES; }
+    if (strcmp(string, "023736") == EQUAL) { pInfoCode->InfoEvents.bits.ChademoChargeRemainCountDown = YES; }
+
+    if (strcmp(string, "012288") == EQUAL) { pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES; }
+
+    if (strcmp(string, "023701") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEvCommFail = YES; }
+    if (strcmp(string, "023737") == EQUAL) { pInfoCode->InfoEvents.bits.CcsRESTemperatureInhibit = YES; }
+    if (strcmp(string, "023738") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVShiftPosition = YES; }
+    if (strcmp(string, "023739") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargerConnectorLockFault = YES; }
+    if (strcmp(string, "023740") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVRESSMalfunction = YES; }
+    if (strcmp(string, "023741") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingCurrentdifferential = YES; }
+    if (strcmp(string, "023742") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingVoltageOutOfRange = YES; }
+    if (strcmp(string, "023743") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingSystemIncompatibility = YES; }
+    if (strcmp(string, "023744") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEmergencyEvent = YES; }
+    if (strcmp(string, "023745") == EQUAL) { pInfoCode->InfoEvents.bits.CcsBreaker = YES; }
+    if (strcmp(string, "023746") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoData = YES; }
+    if (strcmp(string, "023747") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_A = YES; }
+    if (strcmp(string, "023748") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_B = YES; }
+    if (strcmp(string, "023749") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_DIN_C = YES; }
+    if (strcmp(string, "023750") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_1 = YES; }
+    if (strcmp(string, "023751") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_2 = YES; }
+    if (strcmp(string, "023752") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_ISO_3 = YES; }
+    if (strcmp(string, "023753") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_1 = YES; }
+    if (strcmp(string, "023754") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_2 = YES; }
+    if (strcmp(string, "023755") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_3 = YES; }
+    if (strcmp(string, "023756") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_4 = YES; }
+    if (strcmp(string, "023757") == EQUAL) { pInfoCode->InfoEvents.bits.Ccsreserved_by_OEM_5 = YES; }
+    if (strcmp(string, "023758") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequenceError = YES; }
+    if (strcmp(string, "023759") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSignatureError = YES; }
+    if (strcmp(string, "023760") == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnknownSession = YES; }
+    if (strcmp(string, "023761") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceIDInvalid = YES; }
+    if (strcmp(string, "023762") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPaymentSelectionInvalid = YES; }
+    if (strcmp(string, "023763") == EQUAL) { pInfoCode->InfoEvents.bits.CcsIdentificationSelectionInvalid = YES; }
+    if (strcmp(string, "023764") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceSelectionInvalid = YES; }
+    if (strcmp(string, "023765") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateExpired = YES; }
+    if (strcmp(string, "023766") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotYetValid = YES; }
+    if (strcmp(string, "023767") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateRevoked = YES; }
+    if (strcmp(string, "023768") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoCertificateAvailable = YES; }
+    if (strcmp(string, "023769") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertChainError = YES; }
+    if (strcmp(string, "023770") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertValidationError = YES; }
+    if (strcmp(string, "023771") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertVerificationError = YES; }
+    if (strcmp(string, "023772") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractCanceled = YES; }
+    if (strcmp(string, "023773") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChallengeInvalid = YES; }
+    if (strcmp(string, "023774") == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongEnergyTransferMode = YES; }
+    if (strcmp(string, "023775") == EQUAL) { pInfoCode->InfoEvents.bits.CcsWrongChargeParameter = YES; }
+    if (strcmp(string, "023776") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargingProfileInvalid = YES; }
+    if (strcmp(string, "023777") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTariffSelectionInvalid = YES; }
+    if (strcmp(string, "023778") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEPresentVoltageToLow = YES; }
+    if (strcmp(string, "023779") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryNotApplied = YES; }
+    if (strcmp(string, "023780") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMeteringSignatureNotValid = YES; }
+    if (strcmp(string, "023781") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoChargeServiceSelected = YES; }
+    if (strcmp(string, "023782") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContactorError = YES; }
+    if (strcmp(string, "023783") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = YES; }
+    if (strcmp(string, "023784") == EQUAL) { pInfoCode->InfoEvents.bits.CcsGAChargeStop = YES; }
+    if (strcmp(string, "023785") == EQUAL) { pInfoCode->InfoEvents.bits.CcsAlignmentError = YES; }
+    if (strcmp(string, "023786") == EQUAL) { pInfoCode->InfoEvents.bits.CcsACDError = YES; }
+    if (strcmp(string, "023787") == EQUAL) { pInfoCode->InfoEvents.bits.CcsAssociationError = YES; }
+    if (strcmp(string, "023788") == EQUAL) { pInfoCode->InfoEvents.bits.CcsEVSEChargeAbort = YES; }
+    if (strcmp(string, "023789") == EQUAL) { pInfoCode->InfoEvents.bits.CcsNoSupportedAppProtocol = YES; }
+    if (strcmp(string, "023790") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractNotAccepted = YES; }
+    if (strcmp(string, "023791") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMOUnknown = YES; }
+    if (strcmp(string, "023792") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = YES; }
+    if (strcmp(string, "023793") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = YES; }
+    if (strcmp(string, "023794") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = YES; }
+    if (strcmp(string, "023795") == EQUAL) { pInfoCode->InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = YES; }
+    if (strcmp(string, "023796") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_Prov_CertificateRevoked = YES; }
+    if (strcmp(string, "023797") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = YES; }
+    if (strcmp(string, "023798") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = YES; }
+    if (strcmp(string, "023799") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = YES; }
+    if (strcmp(string, "023800") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = YES; }
+    if (strcmp(string, "023801") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = YES; }
+    if (strcmp(string, "023802") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = YES; }
+    if (strcmp(string, "023803") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = YES; }
+    if (strcmp(string, "023809") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_SLAC_init = YES; }
+    if (strcmp(string, "023810") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_match_response = YES; }
+    if (strcmp(string, "023811") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_sequence = YES; }
+    if (strcmp(string, "023812") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_match_MNBC = YES; }
+    if (strcmp(string, "023813") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = YES; }
+    if (strcmp(string, "023814") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_match_response = YES; }
+    if (strcmp(string, "023815") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_match_session = YES; }
+    if (strcmp(string, "023816") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_assoc_session = YES; }
+    if (strcmp(string, "023817") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_vald_toggle = YES; }
+    if (strcmp(string, "023818") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = YES; }
+    if (strcmp(string, "023819") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = YES; }
+    if (strcmp(string, "023823") == EQUAL) { pInfoCode->InfoEvents.bits.CcsUDP_TT_match_join = YES; }
+    if (strcmp(string, "023824") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTCP_TT_match_join = YES; }
+    if (strcmp(string, "023825") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_amp_map_exchange = YES; }
+    if (strcmp(string, "023826") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_link_ready_notification = YES; }
+    if (strcmp(string, "023832") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSupportedAppProtocolRes = YES; }
+    if (strcmp(string, "023833") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionSetupRes = YES; }
+    if (strcmp(string, "023834") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServiceDiscoveryRes = YES; }
+    if (strcmp(string, "023835") == EQUAL) { pInfoCode->InfoEvents.bits.CcsServicePaymentSelectionRes = YES; }
+    if (strcmp(string, "023836") == EQUAL) { pInfoCode->InfoEvents.bits.CcsContractAuthenticationRes = YES; }
+    if (strcmp(string, "023837") == EQUAL) { pInfoCode->InfoEvents.bits.CcsChargeParameterDiscoveryRes = YES; }
+    if (strcmp(string, "023838") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPowerDeliveryRes = YES; }
+    if (strcmp(string, "023839") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheckRes = YES; }
+    if (strcmp(string, "023840") == EQUAL) { pInfoCode->InfoEvents.bits.CcsPreChargeRes = YES; }
+    if (strcmp(string, "023841") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCurrentDemandRes = YES; }
+    if (strcmp(string, "023842") == EQUAL) { pInfoCode->InfoEvents.bits.CcsWeldingDetectionRes = YES; }
+    if (strcmp(string, "023843") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSessionStopRes = YES; }
+    if (strcmp(string, "023844") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSequence_Time = YES; }
+    if (strcmp(string, "023845") == EQUAL) { pInfoCode->InfoEvents.bits.CcsReadyToCharge_Performance_Time = YES; }
+    if (strcmp(string, "023846") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCommunicationSetup_Performance_Time = YES; }
+    if (strcmp(string, "023847") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCableCheck_Performance_Time = YES; }
+    if (strcmp(string, "023848") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPState_Detection_Time = YES; }
+    if (strcmp(string, "023849") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCPOscillator_Retain_Time = YES; }
+    if (strcmp(string, "023850") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = YES; }
+    if (strcmp(string, "023855") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = YES; }
+    if (strcmp(string, "023856") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = YES; }
+    if (strcmp(string, "023857") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = YES; }
+    if (strcmp(string, "023858") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = YES; }
+    if (strcmp(string, "023859") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EV_STOP_EVENT = YES; }
+    if (strcmp(string, "023860") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EV_STOP_EVENT = YES; }
+    if (strcmp(string, "023861") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = YES; }
+    if (strcmp(string, "023862") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = YES; }
+    if (strcmp(string, "023863") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_GET_MISC_INFO = YES; }
+    if (strcmp(string, "023864") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_GET_MISC_INFO = YES; }
+    if (strcmp(string, "023865") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = YES; }
+    if (strcmp(string, "023866") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = YES; }
+    if (strcmp(string, "023867") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = YES; }
+    if (strcmp(string, "023868") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = YES; }
+    if (strcmp(string, "023869") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DATA_TRANSFER = YES; }
+    if (strcmp(string, "023870") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DATA_TRANSFER = YES; }
+    if (strcmp(string, "023871") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = YES; }
+    if (strcmp(string, "023872") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = YES; }
+    if (strcmp(string, "023873") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_ISOLATION_STATUS = YES; }
+    if (strcmp(string, "023874") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_ISOLATION_STATUS = YES; }
+    if (strcmp(string, "023875") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_CONNECTOR_INFO = YES; }
+    if (strcmp(string, "023876") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_CONNECTOR_INFO = YES; }
+    if (strcmp(string, "023877") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_RTC_INFO = YES; }
+    if (strcmp(string, "023878") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_RTC_INFO = YES; }
+    if (strcmp(string, "023879") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = YES; }
+    if (strcmp(string, "023880") == EQUAL) { pInfoCode->InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = YES; }
+    if (strcmp(string, "023881") == EQUAL) { pInfoCode->InfoEvents.bits.CcsMSG_Sequence = YES; }
+    if (strcmp(string, "023882") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = YES; }
+    if (strcmp(string, "023883") == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Decode_Error = YES; }
+    if (strcmp(string, "023884") == EQUAL) { pInfoCode->InfoEvents.bits.CcsDIN_Msg_Encode_Error = YES; }
+    if (strcmp(string, "023885") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Decode_Error = YES; }
+    if (strcmp(string, "023886") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO1_Msg_Encode_Error = YES; }
+    if (strcmp(string, "023887") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Decode_Error = YES; }
+    if (strcmp(string, "023888") == EQUAL) { pInfoCode->InfoEvents.bits.CcsISO2_Msg_Encode_Error = YES; }
+    if (strcmp(string, "023889") == EQUAL) { pInfoCode->InfoEvents.bits.CcsCpStatus_Error = YES; }
+    if (strcmp(string, "023890") == EQUAL) { pInfoCode->InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = YES; }
+    if (strcmp(string, "023891") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccNotReadyForCharging = YES; }
+    if (strcmp(string, "023892") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = YES; }
+    if (strcmp(string, "023893") == EQUAL) { pInfoCode->InfoEvents.bits.CcsSeccFailForQCA7000SetKey = YES; }
+
+    if (strcmp(string, "023702") == EQUAL) { pInfoCode->InfoEvents.bits.GbEvCommFail = YES; }
+    if (strcmp(string, "023900") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = YES; }
+    if (strcmp(string, "023901") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = YES; }
+    if (strcmp(string, "023902") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = YES; }
+    if (strcmp(string, "023903") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = YES; }
+    if (strcmp(string, "023904") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = YES; }
+    if (strcmp(string, "023905") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = YES; }
+    if (strcmp(string, "023906") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = YES; }
+    if (strcmp(string, "023907") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = YES; }
+    if (strcmp(string, "023908") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = YES; }
+    if (strcmp(string, "023909") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = YES; }
+    if (strcmp(string, "023910") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = YES; }
+    if (strcmp(string, "023911") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = YES; }
+    if (strcmp(string, "023912") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = YES; }
+    if (strcmp(string, "023913") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = YES; }
+    if (strcmp(string, "023914") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = YES; }
+    if (strcmp(string, "023915") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = YES; }
+    if (strcmp(string, "023916") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = YES; }
+    if (strcmp(string, "023917") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = YES; }
+    if (strcmp(string, "023918") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = YES; }
+    if (strcmp(string, "023919") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = YES; }
+    if (strcmp(string, "023930") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = YES; }
+    if (strcmp(string, "023931") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = YES; }
+    if (strcmp(string, "023932") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = YES; }
+    if (strcmp(string, "023933") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = YES; }
+    if (strcmp(string, "023934") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = YES; }
+    if (strcmp(string, "023935") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = YES; }
+    if (strcmp(string, "023936") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = YES; }
+    if (strcmp(string, "023937") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = YES; }
+    if (strcmp(string, "023938") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = YES; }
+    if (strcmp(string, "023939") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = YES; }
+    if (strcmp(string, "023940") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = YES; }
+    if (strcmp(string, "023941") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = YES; }
+    if (strcmp(string, "023942") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = YES; }
+    if (strcmp(string, "023943") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = YES; }
+    if (strcmp(string, "023944") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = YES; }
+    if (strcmp(string, "023945") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = YES; }
+    if (strcmp(string, "023946") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = YES; }
+    if (strcmp(string, "023947") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = YES; }
+    if (strcmp(string, "023950") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = YES; }
+    if (strcmp(string, "023951") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = YES; }
+    if (strcmp(string, "023952") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = YES; }
+    if (strcmp(string, "023953") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_GET_CST = YES; }
+    if (strcmp(string, "023954") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_ISOLATION = YES; }
+    if (strcmp(string, "023955") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = YES; }
+    if (strcmp(string, "023956") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_COMPONENT = YES; }
+    if (strcmp(string, "023957") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = YES; }
+    if (strcmp(string, "023958") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTP = YES; }
+    if (strcmp(string, "023959") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_OTHER = YES; }
+    if (strcmp(string, "023960") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_HIGH_V = YES; }
+    if (strcmp(string, "023961") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CC2 = YES; }
+    if (strcmp(string, "023962") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_CURRENT = YES; }
+    if (strcmp(string, "023963") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = YES; }
+    if (strcmp(string, "023964") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = YES; }
+    if (strcmp(string, "023970") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = YES; }
+    if (strcmp(string, "023971") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = YES; }
+    if (strcmp(string, "023972") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = YES; }
+    if (strcmp(string, "023973") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = YES; }
+    if (strcmp(string, "023974") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_CURRENT = YES; }
+    if (strcmp(string, "023975") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = YES; }
+    if (strcmp(string, "023976") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = YES; }
+    if (strcmp(string, "023977") == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = YES; }
+
+    if (strcmp(string, "023979") == EQUAL) { pInfoCode->InfoEvents.bits.EV_Full_Charging = YES; }
+    if (strcmp(string, "023983") == EQUAL) { pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason = YES; }
+
+    return true;
+}

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

@@ -32,6 +32,7 @@
 #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)

+ 44 - 16
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.c

@@ -255,10 +255,11 @@ int InitShareMemory()
 //================================================
 int InitCanBus()
 {
-    int                     s0, nbytes;
-    struct timeval          tv;
-    struct ifreq            ifr0;
-    struct sockaddr_can     addr0;
+    int s0, nbytes;
+    struct timeval tv;
+    struct ifreq ifr0;
+    struct sockaddr_can addr0;
+    struct can_filter rxfilter[3];
 
     system("/sbin/ip link set can0 down");
     system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
@@ -268,17 +269,20 @@ int InitCanBus()
 
     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
@@ -286,11 +290,23 @@ int InitCanBus()
 #endif
     }
 
+    rxfilter[0].can_id = 0x01;
+    rxfilter[0].can_mask = 0x000000FF;
+    rxfilter[1].can_id = 0x02;
+    rxfilter[1].can_mask = 0x000000FF;
+    rxfilter[2].can_id = 0x01FF;
+    rxfilter[2].can_mask = 0x00000FFF;
+    if (setsockopt(s0, SOL_CAN_RAW, CAN_RAW_FILTER,
+                   &rxfilter, sizeof(struct can_filter) * 3) < 0) {
+        log_error("RX setsockopt CAN_RAW_FILTER failed");
+    }
+
     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;
 }
 
@@ -2211,29 +2227,26 @@ static float ReadAdcVolt(uint8_t AdcChannel)
     //AIN2=CCS_Proximity/2
     //AIN3=pilot voltage
     int fd = -1;
-    uint8_t str[64];
-    uint8_t AdcValue[4];
+    uint8_t str[64] = {0};
+    uint8_t AdcValue[4] = {0};
 
     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;
+    return (1.8 * atoi((int)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;
@@ -2325,7 +2338,7 @@ void CANReceiver()
                 intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
 
                 target = ((uint8_t) (frame.can_id & 0x000000FF));      // 0x01 or 0x02
-
+                //log_info("target id = %d\r\n", target);
                 for (uint8_t _index = 0; _index < gun_count; _index++) {                    // 假設有找到回應的 Index
                     if (_chargingData[_index]->Evboard_id == target) {
                         targetGun = _index;
@@ -2516,35 +2529,50 @@ void CANReceiver()
                         //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
                     }
                     }*/
-
+#if 1
                     //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]);
+
+                        //log_info("%d chiller Temp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                        //         targetGun,
+                        //         chiilerTemp.Temp[0],
+                        //         chiilerTemp.Temp[1],
+                        //         frame.data[1],
+                        //         frame.data[2]);
                     } else if (targetGun == 1 &&
                                ((strncmp((char *)&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]);
+
+                        //log_info("%d chillerTemp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                        //         targetGun,
+                        //         chiilerTemp.Temp[0],
+                        //         chiilerTemp.Temp[1],
+                        //         frame.data[1],
+                        //         frame.data[2]);
                     } else {
                         _chargingData[targetGun]->ConnectorTemp = returnConnectTemp(frame.data[1], frame.data[2]);
-                        //log_info("connector temperature = %d\r\n", _chargingData[targetGun]->ConnectorTemp);
+                        //log_info("connector temperature = %d\r\n",
+                        //         _chargingData[targetGun]->ConnectorTemp);
                     }
-
+#endif //0
                     //log_info("EvboardStatus = %x \n",
                     //         ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus);
                     //log_info("ConnectorPlug locked = %x \n",

+ 7 - 5
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvComm.h

@@ -5,11 +5,11 @@
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
-#define COMMUNICATION       2
-#define CHK_VOL_RANGE       50
-#define CHK_CUR_RANGE       20
-#define PLUG                1
-#define UNPLUG              0
+#define COMMUNICATION                           (2)
+#define CHK_VOL_RANGE                           (50)
+#define CHK_CUR_RANGE                           (20)
+#define PLUG                                    (1)
+#define UNPLUG                                  (0)
 
 //------------------------------------------------------------------------------
 //DS60-120 add
@@ -33,6 +33,8 @@ typedef struct StChiilerTemp {
 
 //------------------------------------------------------------------------------
 int GetCanFd(void);
+float GetMaxChargingVol(uint8_t index);
+float GetMaxCharginigCur(uint8_t index);
 
 #endif /* MODULE_EVCOMM_H_ */
 

+ 553 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -0,0 +1,553 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+#include "Ev_Comm.h"
+#include "Module_EvComm.h"
+
+//------------------------------------------------------------------------------
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+static struct WARNING_CODE_INFO *pSysWarning = NULL;
+static struct AlarmCodeData *pAlarmCode = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct CcsData *ShmCcsData = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
+
+//------------------------------------------------------------------------------
+extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
+
+//------------------------------------------------------------------------------
+static uint8_t getMaxConnectTempAndChiller(uint8_t headTemp1, uint8_t headTemp2,
+        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;
+    }
+
+    //先取得第一個非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 getMaxConnectTemp(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((int)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)
+    }
+}
+
+
+static void AddrAssignment(uint8_t *data)
+{
+    uint8_t target_number[8];
+    uint8_t index = 0x00;
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+
+    memcpy(target_number, data, sizeof(target_number));
+    index = *(data + 4);
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        index = 0x01;
+    }
+
+    //if (CheckUniqNumber(index)) {
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index - 1);
+    //DS60-120 add
+    if (pDcChargingInfo->Type == _Type_Chademo) {
+        log_info("Set EV board info : (Chademo) TargetAddr = %d \n", index);
+    } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+        log_info("Set EV board info : (CCS) TargetAddr = %d \n", index);
+    } else if (pDcChargingInfo->Type == _Type_GB) {
+        log_info("Set EV board info : (GB) TargetAddr = %d \n", index);
+    }
+    //log_info("EV board id = %x \n", index); //DS60-120 remove
+
+    //log_info("target_number[0] = %x \n", target_number[0]);
+    //log_info("target_number[1] = %x \n", target_number[1]);
+    //log_info("target_number[2] = %x \n", target_number[2]);
+    //log_info("target_number[3] = %x \n", target_number[3]);
+    //log_info("target_number[4] = %x \n", target_number[4]);
+
+    log_info("SetTargetAddr = %d, type = %d \n", index, pDcChargingInfo->Type);
+    SetTargetAddr(target_number, index);
+    //}
+}
+
+
+void CANReceiver(int fd)
+{
+    pid_t canRecPid;
+
+    canRecPid = fork();
+
+    if (canRecPid == 0) {
+        int isContinue = 1;
+        int nbytes;
+        int intCmd;
+        uint8_t _index = 0;
+        uint8_t recvID = 0;
+        uint8_t targetGun = 0x00;
+        uint8_t gunTypeIndex = 0;
+        uint8_t ver[16] = {0};
+        struct can_frame frame;
+        ChillerTemp chiilerTemp = {0};
+        struct ChargingInfoData *pDcChargingInfo = NULL;
+
+        pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+        pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+        pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+        pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+        ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
+        ShmGBTData = (struct GBTData *)GetShmGBTData();
+        ShmCcsData = (struct CcsData *)GetShmCcsData();
+        ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonInfo();
+
+        while (isContinue) {
+            memset(&frame, 0, sizeof(struct can_frame));
+            nbytes = read(fd, &frame, sizeof(struct can_frame));
+            if (nbytes <= 0) {
+                usleep(10000);
+                continue;
+            }
+
+            recvID = 0;
+            targetGun = 0x00;
+            intCmd = (int) (frame.can_id & CAN_EFF_MASK);
+
+            if (intCmd == ADDRESS_REQ) {
+                //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
+                AddrAssignment(frame.data);
+                continue;
+            }
+
+            intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
+
+            recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
+
+            for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {                    // 假設有找到回應的 Index
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+                //if (gun_count == 1 &&
+                //        _chargingData[_index]->Type == _Type_CCS_2 &&
+                //        ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+                //    target -= 1;
+                //}
+
+                if (pDcChargingInfo->Evboard_id == recvID) {
+                    targetGun = _index;
+                    break;
+                }
+            }
+
+            if (targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) {
+                log_info("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
+                usleep(10000);
+                continue;
+            }
+            //else if (gun_count == 1 && targetGun == 0 && findIndex == 1 &&
+            //           ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+            //    // 這樣的條件下~ 也是單槍 CCS 舊版本的狀況 : 因為舊版 CCS 不會 timeout, then send request id
+            //    ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
+            //}
+
+            if (intCmd == 256) {
+                log_info("EvComm command = 256");
+                usleep(10000);
+                continue;
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
+            gunTypeIndex = pDcChargingInfo->type_index;
+            //log_info("intCmd = %x\r\n", intCmd);
+            switch (intCmd) {
+            case NOTIFICATION_EV_STATUS:
+                if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
+                    if (frame.data[0] == PLUG) {
+                        log_info("Conn %d, Plugin. \n", targetGun);
+                    } else if (frame.data[0] == UNPLUG) {
+                        log_info("Conn %d, Unplug. \n", targetGun);
+                    } else {
+                        log_info("Conn %d, None Check. (%d) \n", targetGun, frame.data[0]);
+                    }
+                }
+
+                pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                pDcChargingInfo->PilotVoltage = frame.data[1];
+
+                //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x \n",
+                //         targetGun,
+                //         pDcChargingInfo->ConnectorPlugIn,
+                //         frame.data[0]);
+
+                //log_info("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
+                break;
+
+            case ACK_EV_FW_VERSION:
+                memset(ver, 0, sizeof(ver));
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+                    memcpy(ver, frame.data, frame.can_dlc);
+                    memcpy(ShmCHAdeMOData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
+                    ShmCHAdeMOData->evse[gunTypeIndex].SelfTest_Comp = PASS;
+                    //log_info("chademo ver. : %s\n", ShmCHAdeMOData->evse[gunTypeIndex].version);
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    memcpy(ver, frame.data, frame.can_dlc);
+                    memcpy(ShmGBTData->evse[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
+                    ShmGBTData->evse[gunTypeIndex].SelfTest_Comp = PASS;
+                    //log_info("gbt ver. : %s\n", ShmGBTData->evse[gunTypeIndex].version);
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                        memcpy(ver, frame.data, frame.can_dlc); //DS60-120 add
+
+                        //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;
+                            _vPoint++;
+                        }*/
+
+                        //ver[_vCount + _vPoint] = frame.data[_vCount];
+                        //}
+
+                        memcpy(&ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
+                        ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].SelfTest_Comp = PASS;
+                        //log_info("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version);
+                    }
+                }
+
+                if (targetGun == 0) {
+                    memset(pSysInfo->Connector1FwRev,
+                           0,
+                           sizeof(pSysInfo->Connector1FwRev));
+                    memcpy(pSysInfo->Connector1FwRev, ver, ARRAY_SIZE(ver));
+                } else if (targetGun == 1) {
+                    memset(pSysInfo->Connector2FwRev,
+                           0,
+                           sizeof(pSysInfo->Connector2FwRev));
+                    memcpy(pSysInfo->Connector2FwRev, ver, ARRAY_SIZE(ver));
+                }
+                break;
+
+            case ACK_EV_HW_VERSION:
+                //log_info("Get EV HW = %s \n", frame.data);
+                break;
+
+            case ACK_GET_OUTPUT_REQ:
+                //DS60-120 add
+                if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
+                        pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+                        (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                    if (pDcChargingInfo->EvBatteryStartSoc <= 0) {
+                        pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
+                    }
+
+                    if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
+                        pDcChargingInfo->EvBatterySoc = frame.data[1];
+                    }
+                }
+                //pDcChargingInfo->EvBatterySoc = frame.data[1]; //DS60-120 remove
+
+                //Jerry add set voltage limit
+                pDcChargingInfo->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
+                if (pDcChargingInfo->EvBatterytargetVoltage > (GetMaxChargingVol(targetGun) * 0.1)) {
+                    pDcChargingInfo->EvBatterytargetVoltage = (GetMaxChargingVol(targetGun) * 0.1);
+                }
+                //printf("id = %d, EvBatterytargetVoltage = %.2f\r\n", targetGun, pDcChargingInfo->EvBatterytargetVoltage);
+
+                //Jerry add set currency limit
+                pDcChargingInfo->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
+                if (pDcChargingInfo->EvBatterytargetCurrent > (GetMaxCharginigCur(targetGun) * 0.1)) {
+                    pDcChargingInfo->EvBatterytargetCurrent = (GetMaxCharginigCur(targetGun) * 0.1);
+                }
+                //printf("id = %d, EvBatterytargetCurrent = %.2f\r\n", targetGun, pDcChargingInfo->EvBatterytargetCurrent);
+
+                pDcChargingInfo->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
+                //printf("RemainChargingDuration = %d\r\n",  pDcChargingInfo->RemainChargingDuration);
+
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+                    //if (ShmCHAdeMOData->ev[gunTypeIndex].EvDetection != frame.data[0])
+                    {
+                        ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
+                    }
+
+                    ShmCHAdeMOData->ev[gunTypeIndex].EvDetection = frame.data[0];
+                    ShmCHAdeMOData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
+                    ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
+                    ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    //if (ShmGBTData->ev[gunTypeIndex].EvDetection != frame.data[0])
+                    {
+                        ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
+                    }
+
+                    ShmGBTData->ev[gunTypeIndex].EvDetection = frame.data[0];
+                    ShmGBTData->ev[gunTypeIndex].SOC = pDcChargingInfo->EvBatterySoc;
+                    ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
+                    ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                        ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
+                    }
+                }
+
+                //log_info("EvBatterytargetVoltage = %f \n", pDcChargingInfo->EvBatterytargetVoltage);
+                //log_info("EvBatterytargetCurrent = %f \n", pDcChargingInfo->EvBatterytargetCurrent);
+                //log_info("BatteryVoltage = %d \n",
+                //         ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
+                //log_info("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];
+                pDcChargingInfo->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 (pDcChargingInfo->Type == _Type_Chademo) {
+                    ShmCHAdeMOData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmCHAdeMOData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
+
+                    //log_info("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
+                    //log_info("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
+                    //log_info("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    ShmGBTData->ev[gunTypeIndex].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+                    ShmGBTData->ev[gunTypeIndex].MaxiBatteryVoltage = pDcChargingInfo->EvBatteryMaxVoltage;
+                }
+                //else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                //}
+                break;
+
+            case ACK_GET_MISCELLANEOUS_INFO:
+                pDcChargingInfo->GunLocked = frame.data[0];
+                pDcChargingInfo->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+                    ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
+                    ShmCHAdeMOData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
+                    ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureP = frame.data[1];
+                    ShmGBTData->evse[gunTypeIndex].ConnectorTemperatureN = frame.data[2];
+                    ShmGBTData->evse[gunTypeIndex].EvboardStatus = frame.data[7];
+                }
+                /*else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                    //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureP = frame.data[1];
+                    //ShmCcsData->V2GMessage_DIN70121[gunTypeIndex]. .ConnectorTemperatureN = frame.data[2];
+                }
+                }*/
+#if 1
+                //memset((uint8_t)&chiilerTemp, 0, sizeof(ChillerTemp));
+                if (targetGun == 0 &&
+                        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+                         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0))
+                   ) {
+                    getChillerTemperature(&chiilerTemp);
+
+                    pDcChargingInfo->ConnectorTemp = getMaxConnectTempAndChiller(
+                                                         frame.data[1],
+                                                         frame.data[2],
+                                                         chiilerTemp.Temp[0],
+                                                         chiilerTemp.Temp[1]);
+
+                    //log_info("%d chiller Temp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                    //         targetGun,
+                    //         chiilerTemp.Temp[0],
+                    //         chiilerTemp.Temp[1],
+                    //         frame.data[1],
+                    //         frame.data[2]);
+                } else if (targetGun == 1 &&
+                           ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+                            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0))
+                          ) {
+                    getChillerTemperature(&chiilerTemp);
+
+                    pDcChargingInfo->ConnectorTemp = getMaxConnectTempAndChiller(
+                                                         frame.data[1],
+                                                         frame.data[2],
+                                                         chiilerTemp.Temp[0],
+                                                         chiilerTemp.Temp[1]);
+
+                    //log_info("%d chillerTemp1 = %d, temp2 = %d, head Temp1 = %d, Temp2 = %d\r\n",
+                    //         targetGun,
+                    //         chiilerTemp.Temp[0],
+                    //         chiilerTemp.Temp[1],
+                    //         frame.data[1],
+                    //         frame.data[2]);
+                } else {
+                    pDcChargingInfo->ConnectorTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
+                    //log_info("connector temperature = %d\r\n",
+                    //         pDcChargingInfo->ConnectorTemp);
+                }
+#endif //0
+                //log_info("EvboardStatus = %x \n",
+                //         ShmCHAdeMOData->evse[gunTypeIndex].EvboardStatus);
+                //log_info("ConnectorPlug locked = %x \n",
+                //         frame.data[0]);
+
+                //if (frame.data[1] >= GUN_OTP_VALUE ||
+                //        frame.data[2] >= GUN_OTP_VALUE ||
+                //        chiilerTemp.Temp[0] >= GUN_OTP_VALUE ||
+                //        chiilerTemp.Temp[1] >= GUN_OTP_VALUE) {
+                //    log_info("Conn %d Temp 0= %d, Temp 1 = %d, chillerTemp1 = %d, chillerTemp2 = %d\r\n",
+                //             targetGun,
+                //             frame.data[1],
+                //             frame.data[2],
+                //             chiilerTemp.Temp[0],
+                //             chiilerTemp.Temp[1]);
+                //}
+                //log_info("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
+                break;
+
+            case ACK_EVSE_ISOLATION_STATUS:
+                break;
+
+            case ACK_EVSE_PRECHAGE_INFO:
+                pDcChargingInfo->PrechargeStatus = frame.data[0];
+                break;
+
+            case NOTIFICATION_EV_STOP:
+                // 車端要求停止
+                if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && //DS60-120 add
+                        pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
+                        (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                    // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
+                    log_info("(%d) NOTIFICATION_EV_STOP err level = %d-----------------------------\n",
+                             targetGun,
+                             frame.data[0]);
+                    if (frame.data[0] == 0x02) {
+                        if (AbnormalStopAnalysis(targetGun, frame.data + 1) == true) {
+                            pDcChargingInfo->StopChargeFlag = YES;
+                        } else {
+                            pDcChargingInfo->NormalStopChargeFlag = YES;
+                        }
+                    } else {
+                        AbnormalStopAnalysis(targetGun, frame.data + 1);
+                        pDcChargingInfo->NormalStopChargeFlag = YES;
+                    }
+                }
+                break;
+
+            default:
+                log_info("EV board = %d, Ack none defined. intCmd = %d  \n", targetGun, intCmd);
+                break;
+            }//switch
+
+            usleep(10000);
+        }//while
+    }
+}

+ 1014 - 0
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -0,0 +1,1014 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/timeb.h>
+#include <sys/time.h>
+
+#include <net/if.h>
+
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+#include "Ev_Comm.h"
+#include "Module_EvComm.h"
+
+//------------------------------------------------------------------------------
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+
+static struct FaultCodeData *pFaultCode = NULL;
+static struct AlarmCodeData *pAlarmCode = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct CcsData *ShmCcsData = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
+
+// 限制最大充電電壓,因應不同 type 槍線來限制
+// Chademo : 500V, 125A,
+// GB : 750, 120A
+// CCS : 950V, 120A
+//DS60-120 add
+//static double chademoVol = 5000;
+//static double ccsVol = 9500;
+//static double gbVol = 7500;
+static float maxChargingVol[2] = { 0, 0 };       // 限制最大充電電壓,如依照模塊則填上 0
+// 限制最大充電電流與能量透過 Web
+static float maxChargingCur[2] = { 0, 0 };         // 限制最大充電電流,如依照模塊則填上 0
+static float maxChargingPow = 0;                   // 限制最大充電能量,如依照模塊則填上 0
+
+static float LogInfo[2][10]; //DS60-120 add
+static int CanFd = -1;
+
+//------------------------------------------------------------------------------
+extern void CANReceiver(int fd);
+extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
+extern void ClearAbnormalStatus_GB(uint8_t gun_index);
+extern void ClearAbnormalStatus_CCS(uint8_t gun_index);
+
+//------------------------------------------------------------------------------
+int GetCanFd(void)
+{
+    return CanFd;
+}
+
+uint32_t 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 InitCanBus(void)
+{
+    int s0, nbytes;
+    struct timeval tv;
+    struct ifreq ifr0;
+    struct sockaddr_can addr0;
+    struct can_filter rxfilter[3];
+
+    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
+    }
+
+    rxfilter[0].can_id = 0x01;
+    rxfilter[0].can_mask = 0x000000FF;
+    rxfilter[1].can_id = 0x02;
+    rxfilter[1].can_mask = 0x000000FF;
+    rxfilter[2].can_id = 0x01FF;
+    rxfilter[2].can_mask = 0x00000FFF;
+    if (setsockopt(s0, SOL_CAN_RAW, CAN_RAW_FILTER,
+                   &rxfilter, sizeof(struct can_filter) * 3) < 0) {
+        log_error("RX setsockopt CAN_RAW_FILTER failed");
+    }
+
+    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;
+}
+
+float GetMaxChargingVol(uint8_t index)
+{
+    return maxChargingVol[index];
+}
+
+float GetMaxCharginigCur(uint8_t index)
+{
+    return maxChargingCur[index];
+}
+
+static void SendCommunicationOnly(uint8_t index)
+{
+    struct ChargingInfoData *pDcCharginigInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+    uint8_t targetID = pDcCharginigInfo->Evboard_id;
+
+    if (pSysConfig->TotalConnectorCount == 1 &&
+            pDcCharginigInfo->Type == _Type_CCS_2 &&
+            ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+        targetID += 1;
+    }
+
+    SetChargingPermission(index,
+                          COMMUNICATION,
+                          pDcCharginigInfo->AvailableChargingPower,
+                          0,
+                          0,
+                          targetID);
+}
+
+static void SendStopOnly(uint8_t index)
+{
+    struct ChargingInfoData *pDcCharginigInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+    uint8_t targetID = pDcCharginigInfo->Evboard_id;
+
+    if (pSysConfig->TotalConnectorCount == 1 &&
+            pDcCharginigInfo->Type == _Type_CCS_2 &&
+            ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+        targetID += 1;
+    }
+
+    SetChargingPermission(index,
+                          STOP,
+                          pDcCharginigInfo->AvailableChargingPower,
+                          0,
+                          0,
+                          targetID);
+}
+
+static uint8_t GetStopChargingReasonByEvse(uint8_t gunIndex, uint8_t *reason)
+{
+    uint8_t result = NO;
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+    if (pAlarmCode->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 (pDcChargingInfo->Type == _Type_Chademo) {
+        if (pFaultCode->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 (pAlarmCode->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 (pAlarmCode->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 (pDcChargingInfo->Type == _Type_GB) {
+        if (pFaultCode->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 (pAlarmCode->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 (pDcChargingInfo->Type == _Type_CCS_2) {
+        if (pFaultCode->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 (pAlarmCode->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 (pAlarmCode->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;
+}
+
+static void setCurrentOutput(void)
+{
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        //chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+
+        if (chargingData_1->FireChargingVoltage <= 500) { //DS60-120 add
+            chargingData_1->PresentChargingCurrent = 0;
+        }
+
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+
+        if (chargingData_1->FireChargingVoltage <= 500) { //DS60-120 add
+            chargingData_1->PresentChargingCurrent = 0;
+        }
+
+        if (chargingData_2->FireChargingVoltage <= 500) {
+            chargingData_2->PresentChargingCurrent = 0;
+        }
+    }
+}
+
+static void SetPresentChargingOutputCap(void)
+{
+    float pow1 = 0, cur1 = 0;
+    float pow2 = 0, cur2 = 0;
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+    }
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    float vol = 0;
+#endif //!defined DD360 && !defined DD360Audi
+
+    pow1 = chargingData_1->AvailableChargingPower;
+    cur1 = chargingData_1->AvailableChargingCurrent;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    vol = chargingData_1->MaximumChargingVoltage;
+    GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
+    GetMaxPowerMethod(chargingData_1->Index, &pow1);
+#endif //!defined DD360 && !defined DD360Audi
+
+    //DS60-120 add
+    if (pow1 <= 0) {
+        cur1 = 0;
+    } else {
+        if (chargingData_1->SystemStatus == S_CHARGING &&
+                chargingData_1->FireChargingVoltage > 1500) {
+            float maxCur = 0;
+            maxCur = (pow1 * 1000) / chargingData_1->FireChargingVoltage;
+
+            if (maxCur * 10 <= cur1) {
+                //log_info("Gun1 -> MaxCharging Current = %f, Cap Current = %f \n", (maxCur * 10), cur1);
+                cur1 = maxCur * 10;
+            }
+        }
+    }
+
+    pow2 = chargingData_2->AvailableChargingPower;
+    cur2 = chargingData_2->AvailableChargingCurrent;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    vol = chargingData_2->MaximumChargingVoltage;
+    GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
+    GetMaxPowerMethod(chargingData_2->Index, &pow2);
+#endif //!defined DD360 && !defined DD360Audi
+
+    //DS60-120 add
+    if (pow2 <= 0) {
+        cur2 = 0;
+    } else {
+        if (chargingData_2->SystemStatus == S_CHARGING &&
+                chargingData_2->FireChargingVoltage > 1500) {
+            float maxCur = 0;
+            maxCur = (pow2 * 1000) / chargingData_2->FireChargingVoltage;
+
+            if (maxCur * 10 <= cur2) {
+                //log_info("Gun2 -> MaxCharging Current = %f, Cap Current = %f \n", (maxCur * 10), cur2);
+                cur2 = maxCur * 10;
+            }
+        }
+    }
+
+    //DS60-120 add
+    if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 ||
+            LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
+            (LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 5 ||
+             LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1 + 5) ||
+            (LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <= pow2 - 5 ||
+             LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >= pow2 + 5) ||
+            (LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <= cur2 - 5 ||
+             LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5)
+       ) {
+        //log_info("----------------------------------------------------- \n");
+        log_info("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f\r\n",
+                 pow1 / 10, cur1 / 10, pow2 / 10, cur2 / 10);
+        //log_info("----------------------------------------------------- \n");
+
+        LogInfo[0][EV_LOG_OUTPUT_CAP_POW] = pow1;
+        LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;
+        LogInfo[1][EV_LOG_OUTPUT_CAP_POW] = pow2;
+        LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] = cur2;
+        chargingData_1->RealMaxCurrent = cur1;
+        chargingData_1->RealMaxPower = pow1;
+
+        if (pSysConfig->TotalConnectorCount == 2) {
+            chargingData_2->RealMaxCurrent = cur2;
+            chargingData_2->RealMaxPower = pow2;
+        }
+    }
+
+    SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
+}
+
+static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
+{
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+
+    if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol) {
+        *vol = maxChargingVol[index];
+    }
+
+    if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur) {
+        *cur = maxChargingCur[index];
+    }
+
+    if (((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
+            pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+             pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) &&
+            pDcChargingInfo->ChargingProfileCurrent >= 0 &&
+            pDcChargingInfo->ChargingProfileCurrent <= *cur
+       ) {
+        *cur = pDcChargingInfo->ChargingProfileCurrent;
+    }
+}
+
+static void SetPresentChargingOutputPower(void)
+{
+    float vol1 = 0, cur1 = 0;
+    float vol2 = 0, cur2 = 0;
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
+
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+    }
+
+    vol1 = chargingData_1->FireChargingVoltage;
+    cur1 = (chargingData_1->PresentChargingCurrent * 10);
+    vol2 = chargingData_2->FireChargingVoltage;
+    cur2 = (chargingData_2->PresentChargingCurrent * 10);
+
+    //DS60-120 add
+    if ((LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
+            (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] <= vol1 - CHK_VOL_RANGE) ||
+            (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] >= cur1 + CHK_CUR_RANGE) ||
+            (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] <= cur1 - CHK_CUR_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] >= vol2 + CHK_VOL_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] <= vol2 - CHK_VOL_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) ||
+            (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
+       ) {
+        log_info("G1 -> Output Vol = %.1f, Output Cur = %.1f -- G2 -> Output Vol = %.1f, Output Cur = %.1f\r\n",
+                 vol1 / 10,
+                 cur1 / 10,
+                 vol2 / 10,
+                 cur2 / 10);
+
+        LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] = vol1;
+        LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] = cur1;
+        LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] = vol2;
+        LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] = cur2;
+    }
+    //if (_outVol_1 != vol1 ||
+    //        _outCur_1 != cur1 ||
+    //        _outVol_2 != vol2 ||
+    //        _outCur_2 != cur2) {
+    /*log_info("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);
+}
+
+static void checkConnectorOVPState(uint8_t gunIndex)
+{
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+    // 避免槍溫偵測誤判
+    static uint8_t gunTempAllowCount[2] = {0, 0};
+    bool isOTP = false;
+
+    switch (pDcChargingInfo->Type) {
+    case _Type_Chademo:
+        if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP) {
+            isOTP = true;
+        }
+        break;
+
+    case _Type_CCS_2:
+        if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP) {
+            isOTP = true;
+        }
+        break;
+
+    case _Type_GB:
+        if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP) {
+            isOTP = true;
+        }
+        break;
+    }
+
+    if (isOTP) {
+        if (gunTempAllowCount[gunIndex] >= 2) {
+            pDcChargingInfo->StopChargeFlag = YES;
+        } else {
+            gunTempAllowCount[gunIndex] += 1;
+        }
+    } else {
+        gunTempAllowCount[gunIndex] = 0;
+    }
+}
+
+static time_t GetRtcInfoForEpoch(void)
+{
+    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;
+}
+
+static void FormatVoltageAndCurrent(void)
+{
+    uint8_t gunIndex = 0;
+    ParsingRatedCur parsingRatedCur = {0};
+    RateCurInfo *pRatedCurInfo = NULL;
+
+    if (RatedCurrentParsing((char *)pSysConfig->ModelName, &parsingRatedCur) != PASS) {
+        log_error("Parsing rated current failed\r\n");
+        return;
+    }
+
+    maxChargingPow = parsingRatedCur.Power;
+
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[gunIndex];
+
+        maxChargingVol[gunIndex] = pRatedCurInfo->Voltage;
+        maxChargingCur[gunIndex] = pRatedCurInfo->Current;
+
+        log_info("Conn %d GunType = %d, MaxVol = %f, MaxCur = %f \n",
+                 gunIndex,
+                 pRatedCurInfo->GunType,
+                 maxChargingVol[gunIndex],
+                 maxChargingCur[gunIndex]);
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    bool chkChademoPermission[2] = {false};
+    int isContinue = 1;
+    uint8_t gunIndex = 0;
+    uint8_t typeIndex = 0;
+    uint8_t priorityLow = 1;
+    uint8_t SendErrorCount[2] = { 0, 0};
+    uint32_t _timeBuf = 0;
+    uint32_t chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {0};
+    struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    time_t rtc = {0};
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
+    }
+
+    MappingGunChargingInfo("EvComm Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonInfo();
+    ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
+    ShmGBTData = (struct GBTData *)GetShmGBTData();
+    ShmCcsData = (struct CcsData *)GetShmCcsData();
+
+    CanFd = InitCanBus();
+
+    FormatVoltageAndCurrent();
+
+    CANReceiver(CanFd);
+
+    rtc = GetRtcInfoForEpoch();
+
+    while (isContinue) {
+        for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+            typeIndex = pDcChargingInfo->type_index;
+
+            if (priorityLow == 1) {
+                // 優先權較低 - 只要有回應即不會再詢問
+                if (pDcChargingInfo->Type == _Type_Chademo &&
+                        ShmCHAdeMOData->evse[typeIndex].SelfTest_Comp != PASS) {
+                    SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
+                    GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
+                } else if (pDcChargingInfo->Type == _Type_GB &&
+                           ShmGBTData->evse[typeIndex].SelfTest_Comp != PASS) {
+                    SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
+                    GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 &&
+                            ShmCcsData->V2GMessage_DIN70121[typeIndex].SelfTest_Comp != PASS) {
+                        SyncRtcInfo(gunIndex, pDcChargingInfo->Evboard_id, (int)rtc);
+                        GetFirmwareVersion(gunIndex, pDcChargingInfo->Evboard_id);
+                    }
+                }
+
+                // 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
+                //log_info("GetMiscellaneousInfo. index = %d, Eid = %d \n", gunIndex, pDcChargingInfo->Evboard_id);
+                GetMiscellaneousInfo(gunIndex,
+                                     pDcChargingInfo->RelayK1K2Status,
+                                     pDcChargingInfo->PresentChargedEnergy,
+                                     (pDcChargingInfo->PresentChargingVoltage * 10),
+                                     pDcChargingInfo->Evboard_id);
+
+                checkConnectorOVPState(gunIndex);
+            }
+
+            switch (pDcChargingInfo->SystemStatus) {
+            case S_IDLE:
+            case S_RESERVATION:
+                if (pDcChargingInfo->Type == _Type_Chademo) {
+
+                    ClearAbnormalStatus_Chademo(gunIndex);
+                    if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
+                        if (!chkChademoPermission[gunIndex]) {
+                            chkChademoPermission[gunIndex] = true;
+                            gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                            SendCommunicationOnly(gunIndex);
+                        } else {
+                            _timeBuf = GetTimeoutValue(_chk_chademo_permission_timeout[gunIndex]);
+
+                            if (_timeBuf < 0) {
+                                gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                            } else {
+                                if (_timeBuf / 1000 > 10000) {
+                                    SendCommunicationOnly(gunIndex);
+                                    gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                                }
+                            }
+                        }
+                    } else if (chkChademoPermission[gunIndex]) {
+                        chkChademoPermission[gunIndex] = false;
+                        SendStopOnly(gunIndex);
+                    }
+
+                    if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP == NO) {
+                        pDcChargingInfo->StopChargeFlag = NO;
+                    }
+
+                } else if (pDcChargingInfo->Type == _Type_GB) {
+                    ClearAbnormalStatus_GB(gunIndex);
+
+                    if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP == NO) {
+                        pDcChargingInfo->StopChargeFlag = NO;
+                    }
+                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    ClearAbnormalStatus_CCS(gunIndex);
+
+                    if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP == NO) {
+                        pDcChargingInfo->StopChargeFlag = NO;
+                    }
+                }
+
+                if (priorityLow == 1) {
+                    pDcChargingInfo->PresentChargedEnergy = 0;
+                    pDcChargingInfo->PresentChargingPower = 0;
+                    pDcChargingInfo->GroundFaultStatus = GFD_WAIT;
+                    pDcChargingInfo->RealRatingPower = 0;
+                    pDcChargingInfo->StopChargeFlag = NO;
+                    pDcChargingInfo->NormalStopChargeFlag = NO;//DS60-120 add
+                    pDcChargingInfo->ChargingFee = 0.0;
+                    pDcChargingInfo->EvBatterySoc = 0;
+                    pDcChargingInfo->EvBatteryStartSoc = 0; //DS60-120 add
+                    pDcChargingInfo->EvBatteryMaxVoltage = 0; //DS60-120 add
+                    pDcChargingInfo->ChargingProfilePower = -1; //DS60-120 add
+                    pDcChargingInfo->ChargingProfileCurrent = -1; //DS60-120 add
+
+                    if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) { //DS60-120 add
+
+                        pDcChargingInfo->PresentChargingVoltage = 0;
+                        pDcChargingInfo->PresentChargingCurrent = 0;
+                        pDcChargingInfo->EvBatteryMaxVoltage = 0;
+                    }
+
+                    chargingTime[gunIndex] = 0;
+                    //maxChargingCur[gunIndex] = pSysConfig->MaxChargingCurrent * 10;
+                    //maxChargingPow = (pSysConfig->MaxChargingPower * 10);
+                    //DS60-120 add
+                    SendErrorCount[gunIndex] = 0;
+
+                    //maxChargingPow = pSysConfig->MaxChargingPower * 10;
+                    // ShmPsuData->SystemAvailablePower 已是 * 10
+                    //maxChargingPow = ShmPsuData->SystemAvailablePower;
+                    if (pSysConfig->MaxChargingPower * 10 != 0 &&
+                            pSysConfig->MaxChargingPower * 10 < maxChargingPow) {
+                        maxChargingPow = pSysConfig->MaxChargingPower * 10;
+                    }
+
+                    LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = 0;
+                    LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = 0;
+                    LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] = 0;
+                    LogInfo[gunIndex][EV_LOG_SOC] = 0;
+
+                    SetPresentChargingOutputPower();
+                }
+                break;
+
+            case S_PREPARNING:
+                chkChademoPermission[gunIndex] = false; //DS60-120 add
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                pDcChargingInfo->PowerConsumption = 0;
+                break;
+
+            case S_PREPARING_FOR_EV:
+                // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+//                  log_info("PresentChargingVoltage = %f \n", pDcChargingInfo->PresentChargingVoltage);
+//                  log_info("PresentChargingCurrent = %f \n", pDcChargingInfo->PresentChargingCurrent);
+//                  log_info("AvailableChargingPower = %f \n", pDcChargingInfo->AvailableChargingPower);
+//                  log_info("AvailableChargingCurrent = %f \n", pDcChargingInfo->AvailableChargingCurrent);
+//                  log_info("MaximumChargingVoltage = %f \n", pDcChargingInfo->MaximumChargingVoltage);
+
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                if (priorityLow == 1) {
+                    float maxVol, maxCur;
+                    // 樁端輸出能力
+                    maxVol = pDcChargingInfo->MaximumChargingVoltage;
+                    maxCur = pDcChargingInfo->AvailableChargingCurrent;
+
+                    GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+
+                    //DS60-120 add
+                    if (LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] != maxVol ||
+                            LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] != maxCur) {
+                        LogInfo[gunIndex][EV_LOG_EVSE_MAX_VOL] = maxVol;
+                        LogInfo[gunIndex][EV_LOG_EVSE_MAX_CUR] = maxCur;
+
+                        log_info("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f \n",
+                                 gunIndex, maxVol / 10, maxCur / 10, pDcChargingInfo->AvailableChargingPower / 10);
+                    }
+                    //log_info("To EV_%d Max_Vol = %f, Cap_Cur = %f, Cap_Pow = %f \n",
+                    //            gunIndex, maxVol, maxCur, pDcChargingInfo->AvailableChargingPower);
+
+                    pDcChargingInfo->RealMaxVoltage = maxVol;
+
+                    SetChargingPermission(gunIndex,
+                                          START,
+                                          pDcChargingInfo->AvailableChargingPower,
+                                          maxCur,
+                                          maxVol,
+                                          pDcChargingInfo->Evboard_id);
+
+                    // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+                    GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id);
+                }
+
+                gettimeofday(&_chk_ratingPower_timeout[gunIndex], NULL);
+                break;
+
+            case S_PREPARING_FOR_EVSE:
+            case S_CCS_PRECHARGE_ST0:
+            case S_CCS_PRECHARGE_ST1:
+                // 開始確認車端是否同意開始充電
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                if (priorityLow % 5 == 1) {
+                    // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+                    GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id); //DS60-120 add
+
+                    // 樁端輸出能力改變
+                    SetPresentChargingOutputCap();
+                }
+
+                //DS60-120 add
+                if (LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] != pDcChargingInfo->EvBatteryMaxVoltage) {
+                    LogInfo[gunIndex][EV_LOG_MAX_BATT_VOL] = pDcChargingInfo->EvBatteryMaxVoltage;
+                    log_info("index = %d, Ev Maximum Battery Voltage = %f \n",
+                             gunIndex,
+                             pDcChargingInfo->EvBatteryMaxVoltage);
+                }
+
+                if (LogInfo[gunIndex][EV_LOG_SOC] != pDcChargingInfo->EvBatterySoc) {
+                    LogInfo[gunIndex][EV_LOG_SOC] = pDcChargingInfo->EvBatterySoc;
+                    log_info("index = %d, SOC = %d \n",
+                             gunIndex,
+                             pDcChargingInfo->EvBatterySoc);
+                }
+
+                // 持續通知 Isolation 測試狀態
+                if (priorityLow == 1) {
+                    // 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
+//                      if (_chargingData[_index]->FireChargingVoltage >= 3500)
+//                         pDcChargingInfo->GroundFaultStatus = GFD_PASS;
+
+                    //log_info("To EV_%d GFD = %d \n",   _index,pDcChargingInfo->GroundFaultStatus);
+                    //if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
+                    {
+                        //if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
+                        uint8_t _result = pDcChargingInfo->GroundFaultStatus;
+
+                        // GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
+                        if (pDcChargingInfo->Type == _Type_Chademo ||
+                                pDcChargingInfo->Type == _Type_GB) {
+                            if (_result == GFD_WARNING) {
+                                _result = GFD_PASS;
+                            }
+                        }
+
+                        if (_result == GFD_WARNING || _result == GFD_PASS) {
+                            if (((GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 12000 &&
+                                    pDcChargingInfo->RealRatingPower > 0) ||
+                                    (GetTimeoutValue(_chk_ratingPower_timeout[gunIndex]) / 1000) > 14000) {
+                                //log_info("**********EvComm : gunIndex= %d, RealRatingPower = %d \n",
+                                //            gunIndex,pDcChargingInfo->RealRatingPower);
+                                //_result = GFD_PASS;
+
+                                //DS60-120 add
+                                if (LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] != pDcChargingInfo->RealRatingPower) {
+                                    LogInfo[gunIndex][EV_LOG_REAL_CAP_POW] = pDcChargingInfo->RealRatingPower;
+                                    log_info("Conn %d, RealRatingPower = %d \n",
+                                             gunIndex,
+                                             pDcChargingInfo->RealRatingPower);
+
+                                }
+                            } else {
+                                _result = GFD_WAIT;
+                            }
+                        }
+
+                        SetIsolationStatus(gunIndex, _result, pDcChargingInfo->Evboard_id);
+                    }
+
+                    if (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 &&
+                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
+                        SetEvsePrechargeInfo(gunIndex, PRECHARGE_PRERELAY_PASS, pDcChargingInfo->Evboard_id);
+                    }
+                }
+                break;
+
+            case S_CHARGING:
+                // 計算 Power
+                pDcChargingInfo->PresentChargingPower =
+                    ((float)((pDcChargingInfo->PresentChargingVoltage) *
+                             (pDcChargingInfo->PresentChargingCurrent)) / 1000);
+
+                //DS60-120 remove
+                if (chargingTime[gunIndex] == 0 ||
+                        chargingTime[gunIndex] > pDcChargingInfo->PresentChargedDuration) {
+                    chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
+                } else {
+                    int passTime = pDcChargingInfo->PresentChargedDuration - chargingTime[gunIndex];
+
+                    if (passTime > 0) {
+                        float changingPow = (pDcChargingInfo->PresentChargingPower) * passTime / 3600;
+                        if (pSysConfig->BillingData.isBilling) {
+                            pDcChargingInfo->ChargingFee += changingPow * pSysConfig->BillingData.Cur_fee;
+                        }
+
+                        pDcChargingInfo->PresentChargedEnergy += changingPow;
+                        pDcChargingInfo->PowerConsumption += changingPow;
+                        chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
+                    }
+                }
+
+                // 開始確認車端是否同意開始充電
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                // for test end
+                if (priorityLow % 5 == 0) {
+                    // 樁端輸出能力改變
+                    SetPresentChargingOutputCap();
+                }
+
+                if ((pDcChargingInfo->GroundFaultStatus == GFD_FAIL) ||
+                        (pDcChargingInfo->Type == _Type_CCS_2)) {
+                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                }
+                /*
+                else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                }*/
+
+                // GFD 失敗再通知
+                if (priorityLow == 1) {
+                    if (pDcChargingInfo->Type == _Type_CCS_2 &&
+                            pDcChargingInfo->PrechargeStatus == PRECHARGE_READY) {
+                        SetEvsePrechargeInfo(gunIndex, PRECHARGE_CHARELAY_PASS, pDcChargingInfo->Evboard_id);
+                    }
+                }
+                break;
+
+            case S_ALARM:
+            case S_TERMINATING:
+                // 設定當前輸出
+                setCurrentOutput();
+                SetPresentChargingOutputPower();
+
+                // 槍鎖還在,則代表是樁端要求的停止
+                if (pDcChargingInfo->GunLocked == START ||
+                        pDcChargingInfo->Type == _Type_CCS_2) {
+                    uint8_t normalStop = 0x01;
+                    uint8_t stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+                    if (GetStopChargingReasonByEvse(gunIndex, stopReason)) {
+                        normalStop = 0x02;
+                    }
+
+                    EvseStopChargingEvent(normalStop, stopReason, pDcChargingInfo->Evboard_id);
+                    SendErrorCount[gunIndex] += 1; //DS60-120 add
+                }
+
+                if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    SetIsolationStatus(gunIndex, pDcChargingInfo->GroundFaultStatus, pDcChargingInfo->Evboard_id);
+                }
+
+                GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
+
+                //DS60-120 add
+                if (pDcChargingInfo->SystemStatus == S_ALARM) {
+                    if (priorityLow == 1) {
+                        float maxVol, maxCur;
+
+                        // 樁端輸出能力
+                        maxVol = pDcChargingInfo->MaximumChargingVoltage;
+                        maxCur = pDcChargingInfo->AvailableChargingCurrent;
+
+                        GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+                        SetChargingPermission(gunIndex,
+                                              STOP,
+                                              pDcChargingInfo->AvailableChargingPower,
+                                              maxCur,
+                                              maxVol,
+                                              pDcChargingInfo->Evboard_id);
+                    }
+                }
+                break;
+
+            case S_COMPLETE:
+                // 設定當前輸出
+                SetPresentChargingOutputPower();
+
+                if (priorityLow == 1) {
+                    float maxVol, maxCur;
+
+                    // 樁端輸出能力
+                    maxVol = pDcChargingInfo->MaximumChargingVoltage;
+                    maxCur = pDcChargingInfo->AvailableChargingCurrent;
+
+                    GetMaxVolAndCurMethod(gunIndex, &maxVol, &maxCur);
+                    SetChargingPermission(gunIndex,
+                                          STOP,
+                                          pDcChargingInfo->AvailableChargingPower,
+                                          maxCur,
+                                          maxVol,
+                                          pDcChargingInfo->Evboard_id);
+
+                    //DS60-120 add
+                    //if (pDcChargingInfo->EvBatterySoc >= 100) {
+                    //    //滿電,則直接清掉錯誤
+                    //    if (pDcChargingInfo->Type == _Type_Chademo) {
+                    //        ClearAbnormalStatus_Chademo(gunIndex);
+                    //    } else if (pDcChargingInfo->Type == _Type_GB) {
+                    //        ClearAbnormalStatus_GB(gunIndex);
+                    //    } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+                    //        ClearAbnormalStatus_CCS(gunIndex);
+                    //    }
+                    //}
+                }
+                break;
+            }//switch
+        }//for
+
+        priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
+        usleep(50000);
+    }//while
+
+    return 0;
+}

+ 56 - 28
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/AcPlug.c

@@ -4,21 +4,23 @@
 #include <stdint.h>
 #include <time.h>
 
+#include <unistd.h>
 #include <sys/time.h>
 #include <sys/timeb.h>
 
+#include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
 //------------------------------------------------------------------------------
 static struct SysConfigData *pSysConfig = NULL;
 static struct SysInfoData *pSysInfo = NULL;
-static struct WARNING_CODE_INFO *pSysWarning = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct InfoCodeData *pInfoCode = NULL;
-static struct FaultcodeData *pFaultCode = NULL;
+static struct FaultCodeData *pFaultCode = NULL;
 static struct OCPP16Data *ShmOCPP16Data = NULL;
 
 static int Uart5Fd = 0;
@@ -57,6 +59,32 @@ static int _alarm_code[] = {
 };
 
 //------------------------------------------------------------------------------
+static void OcppStopTransation(uint8_t gunIndex)
+{
+    struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+    if (strcmp((char *)pAcChargingInfo->StartUserId, "") == EQUAL) {
+        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag,
+               (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+    } else {
+        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag,
+               (char *)pAcChargingInfo->StartUserId);
+    }
+
+    log_info("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
+}
+
+static void SetCpDuty(uint8_t _value)
+{
+    Config_Ac_Duty(Uart5Fd, ADDR_AC_PLUG, _value);
+}
+
+static uint8_t GetChargingCurrent(void)
+{
+    return Query_Charging_Current(Uart5Fd, ADDR_AC_PLUG, &acChargingCurrent);
+}
+
 static uint8_t GetChargingEnergy(void)
 {
     return Query_Charging_Energy(Uart5Fd, ADDR_AC_PLUG, &acChargingEnergy);
@@ -152,6 +180,7 @@ static void CheckAlarmOccur(void)
 {
     bool isErr = false;
     uint8_t count = 0;
+    struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
     for (count = 0; count < sizeof(_alarm_code) / sizeof(_alarm_code[0]); count++) {
         if (acAlarmCode.AcAlarmCode & _alarm_code[count]) {
@@ -202,7 +231,7 @@ static void CheckAlarmOccur(void)
         }
     }
 
-    ac_chargingInfo[0]->IsErrorOccur = isErr;
+    pAcChargingInfo->IsErrorOccur = isErr;
 }
 
 static void GetAcAlarmCode(void)
@@ -258,9 +287,9 @@ static void ChangeToCsuMode(void)
 
 static void GetAcModelName(void)
 {
-    memset(SysConfig->AcModelName, 0, sizeof(SysConfig->AcModelName));
-    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, SysConfig->AcModelName) == PASS) {
-        log_info("ac model name = %s \n", SysConfig->AcModelName);
+    memset(pSysConfig->AcModelName, 0, sizeof(pSysConfig->AcModelName));
+    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, pSysConfig->AcModelName) == PASS) {
+        log_info("ac model name = %s \n", pSysConfig->AcModelName);
     }
 }
 
@@ -277,14 +306,11 @@ static void GetFwVersion_AC(void)
 
 void AcPlugTask(int uartFD)
 {
-    if (acgunCount <= 0) {
-        return;
-    }
+    static float _beforeChargingTotalEnergy = 0.0;
 
-    if (CreateAllCsuShareMemory() == FAIL) {
-        log_error("Fan Board create share memory failed\r\n");
+    if (pSysConfig->AcConnectorCount <= 0) {
+        return;
     }
-    MappingGunChargingInfo("Fan Board Task");
 
     //share memory mapping
     pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
@@ -296,6 +322,8 @@ void AcPlugTask(int uartFD)
 
     struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
+    Uart5Fd = uartFD;
+
     //pAcChargingInfo->SelfTest_Comp = YES;
     //pAcChargingInfo->IsModeChagned = PASS;
     //---------------------------------------------
@@ -335,20 +363,20 @@ void AcPlugTask(int uartFD)
         } else if ((acStatus.CpStatus == AC_SYS_B || pAcChargingInfo->ConnectorPlugIn == AC_SYS_B) &&
                    pAcChargingInfo->IsAvailable &&
                    !pAcChargingInfo->IsErrorOccur &&
-                   (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
-                    SysConfig->AuthorisationMode == AUTH_MODE_DISABLE)) {
+                   (pSysInfo->WaitForPlugit == YES ||
+                    pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE)) {
             if (pAcChargingInfo->RemoteStartFlag == YES) {
                 log_info("** AC Remote \n");
                 pAcChargingInfo->RemoteStartFlag = NO;
                 strcpy((char *)pAcChargingInfo->StartUserId, "");
-                ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                pSysInfo->WaitForPlugit = NO;
                 _status = S_PREPARNING;
-            } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
-                log_info("** UserId = %s \n", SysConfig->UserId);
-                strcpy((char *)pAcChargingInfo->StartUserId, (char *)SysConfig->UserId);
+            } else if (pSysInfo->OrderCharging == NO_DEFINE) {
+                log_info("** UserId = %s \n", pSysConfig->UserId);
+                strcpy((char *)pAcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
                 log_info("** CardNumber = %s \n", pAcChargingInfo->StartUserId);
-                strcpy((char *)SysConfig->UserId, "");
-                ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                strcpy((char *)pSysConfig->UserId, "");
+                pSysInfo->WaitForPlugit = NO;
                 _status = S_PREPARNING;
             }
         } else if (pAcChargingInfo->SystemStatus == S_CHARGING) {
@@ -381,10 +409,10 @@ void AcPlugTask(int uartFD)
         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;
+                pSysInfo->SystemPage = _LCM_NONE;
+                pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+                if (pSysInfo->OrderCharging != NO_DEFINE) {
+                    pSysInfo->OrderCharging = NO_DEFINE;
                 }
                 gettimeofday(&_ac_preparing, NULL);
             }
@@ -403,14 +431,14 @@ void AcPlugTask(int uartFD)
                 ftime(&_ac_startChargingTime);
                 OcppStartTransation(1);
                 ChangeStartOrStopDateTime(YES);
-                ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+                pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
             }
 
             if (GetChargingEnergy() == PASS) {
                 if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0) {
                     pAcChargingInfo->PresentChargedEnergy += (acChargingEnergy.Energy - _beforeChargingTotalEnergy) / 100;
-                    if (SysConfig->BillingData.isBilling) {
-                        pAcChargingInfo->ChargingFee += pAcChargingInfo->PresentChargedEnergy * SysConfig->BillingData.Cur_fee;
+                    if (pSysConfig->BillingData.isBilling) {
+                        pAcChargingInfo->ChargingFee += pAcChargingInfo->PresentChargedEnergy * pSysConfig->BillingData.Cur_fee;
                     }
                 }
 
@@ -429,7 +457,7 @@ void AcPlugTask(int uartFD)
             // 用以判斷是否有在輸出
             pAcChargingInfo->IsCharging = acStatus.RelayStatus;
 
-            SetCpDuty(SysConfig->AcMaxChargingCurrent);
+            SetCpDuty(pSysConfig->AcMaxChargingCurrent);
             ChangeLedStatus();
         }
         break;

+ 16 - 10
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/FanBoard.c

@@ -3,12 +3,14 @@
 #include <string.h>
 #include <stdint.h>
 #include <time.h>
+#include <unistd.h>
 
 #include <sys/time.h>
 #include <sys/timeb.h>
 
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
@@ -22,6 +24,9 @@ static struct PsuData *ShmPsuData = NULL;
 static int Uart5Fd = 0;
 static struct timeval gFanBoardRunTimer;
 
+static uint16_t _setFanSpeed = 0;
+static uint16_t fanSpeedSmoothValue = 500;
+
 //------------------------------------------------------------------------------
 static void SetFanModuleSpeed(void)
 {
@@ -52,6 +57,8 @@ static void SetFanModuleSpeed(void)
 // 風扇速度
 static void GetFanSpeed(void)
 {
+    FanSpeed fanSpeed = {0};
+
     //log_info("Get fan board speed \n");
     if (Query_Fan_Speed(Uart5Fd, ADDR_FAN, &fanSpeed) == PASS) {
         ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
@@ -93,6 +100,7 @@ static void GetFanSpeedByFunction(void)
     float power = 0;
     double _pw_rate = 0;
     double _temp_rate = 0;
+    struct ChargingInfoData *pDcChargingInfo = NULL;
 
     for (index = 0; index < ShmPsuData->GroupCount; index++) {
         for (count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
@@ -102,8 +110,10 @@ static void GetFanSpeedByFunction(void)
         }
     }
 
-    for (gunIndex = 0; gunIndex < gunCount; gunIndex++) {
-        power += (_chargingData[gunIndex]->PresentChargingPower * 10);
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+
+        power += (pDcChargingInfo->PresentChargingPower * 10);
     }
 
     if (_maxPower > 0) {
@@ -143,7 +153,7 @@ static void SetRtcData_Fan(void)
 {
     struct timeb csuTime;
     struct tm *tmCSU;
-    RTC rtc = {0};
+    Rtc rtc = {0};
 
     ftime(&csuTime);
     tmCSU = localtime(&csuTime.time);
@@ -209,7 +219,7 @@ static void fanBoardPorcess(void)
     }
 
     if (ShmFanModuleData->SelfTest_Comp == YES ||
-            strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+            strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
             pSysInfo->FanModuleFwRev[0] != '\0') {
         ShmFanModuleData->SelfTest_Comp = YES;
 
@@ -217,7 +227,7 @@ static void fanBoardPorcess(void)
             //GetPsuTempForFanSpeed();
             GetFanSpeedByFunction();
             GetFanSpeed();
-            ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
+            pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
 
             ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
@@ -254,11 +264,6 @@ void FanBoardTask(int uartFD)
     if (pid == 0) {
         int isContinue = 1;
 
-        if (CreateAllCsuShareMemory() == FAIL) {
-            log_error("Fan Board create share memory failed\r\n");
-        }
-        MappingGunChargingInfo("Fan Board Task");
-
         //share memory mapping
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -272,6 +277,7 @@ void FanBoardTask(int uartFD)
             fanBoardSelfTest();
 
             fanBoardPorcess();
+            usleep(100000);
         }
     }
 }

+ 35 - 22
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/LEDBoard.c → EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/LEDlight.c

@@ -4,11 +4,14 @@
 #include <stdint.h>
 #include <time.h>
 
+#include <unistd.h>
 #include <sys/time.h>
 #include <sys/timeb.h>
 
+#include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
@@ -43,11 +46,22 @@ static bool IsNoneMatchLedColor(void)
     return result;
 }
 
-static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+//static void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+static void SetLedColor(void)
 {
     static uint8_t _checkLedChanged = 3;
+    struct ChargingInfoData *chargingData_1 = NULL;
+    struct ChargingInfoData *chargingData_2 = NULL;
     uint8_t _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
 
+    if (pSysConfig->TotalConnectorCount == 1) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+    } else if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+        chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
+    }
+
     if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_DARKEST) {
         _colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
     } else if (pSysConfig->LedInfo.Intensity == _LED_INTENSITY_MEDIUM) {
@@ -65,7 +79,7 @@ static void SetLedColor(struct ChargingInfoData *chargingData_1, struct Charging
         led_color.Connect_2_Blue = COLOR_MIN_LV;
         led_color.Connect_2_Red = _colorBuf;
     } else {
-        if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
+        if (pSysInfo->IsAlternatvieConf) {
             if ((chargingData_1->SystemStatus == S_BOOTING ||
                     chargingData_1->SystemStatus == S_IDLE ||
                     chargingData_1->SystemStatus == S_RESERVATION) &&
@@ -183,12 +197,14 @@ static void SetLedColor(struct ChargingInfoData *chargingData_1, struct Charging
 
 static void GetFwAndHwVersion_Led(void)
 {
+    Ver ver = {0};
+
     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);
-        //log_info("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
+        strcpy((char *) pSysInfo->LedModuleFwRev, ver.Version_FW);
+        log_info("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
         ShmLedModuleData->SelfTest_Comp = YES;
     } else {
         //log_info("GetFwAndHwVersion_Led fail \n");
@@ -197,32 +213,31 @@ static void GetFwAndHwVersion_Led(void)
 //  if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
 //  {
 //      // SystemInfo
-//      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+//      strcpy((char *) pSysInfo->RelayModuleHwRev, ver.Version_FW);
 //      //log_info("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
 //  }
 }
 
 static void LEDBoardProcess(void)
 {
-    struct ChargingInfoData *pDcChargingInfo0 = NULL;
-    struct ChargingInfoData *pDcChargingInfo1 = NULL;
+    //struct ChargingInfoData *pDcChargingInfo0 = NULL;
+    //struct ChargingInfoData *pDcChargingInfo1 = NULL;
 
     if (ShmLedModuleData->SelfTest_Comp == NO) {
         return;
     }
 
     if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-        if (pSysConfig->TotalConnectorCount == 1) {
-            pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-
-            SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
-        } else if (pSysConfig->TotalConnectorCount == 2) {
-            pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-            pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
-
-            SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
-        }
 
+        //if (pSysConfig->TotalConnectorCount == 1) {
+        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
+        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
+        //} else if (pSysConfig->TotalConnectorCount == 2) {
+        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
+        //    pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
+        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
+        //}
+        SetLedColor();
         gettimeofday(&_led_priority_time, NULL);
     }
 }
@@ -266,20 +281,18 @@ void LEDBoardTask(int uartFD)
     if (pid == 0) {
         int isContinue = 1;
 
-        if (CreateAllCsuShareMemory() == FAIL) {
-            log_error("LED Board create share memory failed\r\n");
-        }
-        MappingGunChargingInfo("LED Board Task");
-
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
 
         pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
         ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
+        Uart5Fd = uartFD;
 
         while (isContinue) {
             LEDBoardSelfTest();
+            LEDBoardProcess();
+            usleep(100000);
         }
     }
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 26 - 1392
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.c


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

@@ -5,6 +5,7 @@
 #define RELAY_CHECK_TIME                        (5)       // s
 #define OUTPUT_VOL_CHK_TIME                     (200)     // ms
 #define TEN_MINUTES                             (600)     // s
+#define FORCE_STOP_TIME                         (30)
 //#define TEN_MINUTES                             5
 #define ENV_TEMP_MIN                            (45)
 #define ENV_TEMP_MAX                            (50)
@@ -102,4 +103,8 @@ typedef struct StPreCharginState {
     uint8_t Reserved: 6;
 } PreChargingState;
 
+//------------------------------------------------------------------------------
+uint32_t GetTimeoutValue(struct timeval _sour_time);
+int DiffTimeb(struct timeb ST, struct timeb ET);
+
 #endif /* _MODULE_INTERNAL_COMM_H_ */

+ 2488 - 0
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalCommOrg.c

@@ -0,0 +1,2488 @@
+#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/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/define.h"
+#include "Module_InternalComm.h"
+#include "internalComm.h"
+#include "../Config.h"
+
+//------------------------------------------------------------------------------
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct FanModuleData            *ShmFanModuleData;
+struct RelayModuleData          *ShmRelayModuleData;
+struct LedModuleData            *ShmLedModuleData;
+struct PsuData                  *ShmPsuData;
+struct OCPP16Data               *ShmOCPP16Data;
+DcCommonInfo                    *ShmDcCommonData;
+
+uint8_t gunCount;
+uint8_t 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 _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
+struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
+
+// SMR1 *2 + SMR2 * 2 + Parallel * 2
+struct timeval _relayStateChkTimer[6]; //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(uint8_t 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;
+uint8_t _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;
+
+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
+};
+
+uint8_t getCommTargetID(uint8_t index)
+{
+    uint8_t targetID = 0;
+
+    if (gunCount == 1) {
+        if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "0", 1) != 0) {
+            targetID = 0x01;
+        } else if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "0", 1) != 0) {
+            targetID = 0x02;
+        }
+    } else {
+        targetID = _chargingData[index]->Evboard_id;
+    }
+
+    return targetID;
+}
+
+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;
+}
+
+//==========================================
+// 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);
+        //log_info("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);
+        //log_info("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);
+        //log_info("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);
+        //log_info("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);
+        //log_info("GetFwAndHwVersion_Led s1 = %s \n", ver.Version_FW);
+        ShmLedModuleData->SelfTest_Comp = YES;
+    } else {
+        //log_info("GetFwAndHwVersion_Led fail \n");
+    }
+
+//  if (Query_HW_Ver(Uart5Fd, ADDR_LED, &ver) == PASS)
+//  {
+//      // SystemInfo
+//      strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+//      //log_info("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
+//  }
+}
+
+void GetFwVersion_AC()
+{
+    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);
+    }
+}
+
+void GetAcModelName()
+{
+    memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
+    if (Query_Model_Name(Uart5Fd, ADDR_AC_PLUG, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS) {
+        log_info("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
+    }
+}
+
+void SetRtcData_Relay()
+{
+    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);
+
+    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) {
+        //log_info("SetRtc (RB) sucessfully. \n");
+    }
+}
+
+void SetModelName_Relay()
+{
+    if (Config_Model_Name(Uart5Fd, ADDR_RELAY, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+        //log_info("Set Model name (RB) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+    }
+}
+
+void SetRtcData_Fan()
+{
+    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);
+
+    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) {
+        //log_info("SetRtc (FB) sucessfully. \n");
+    }
+}
+
+void SetModelName_Fan()
+{
+    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)
+{
+    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;
+
+        //********************************************************************************************************//
+        // Vin (UVP)
+        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO) {
+                if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC) {
+                    log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[0] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
+                    _threePhaseUvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO) {
+                if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC) {
+                    log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[1] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
+                    _threePhaseUvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO) {
+                if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC) {
+                    log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
+                    _threePhaseUvp[2] = 0;
+                }
+            }
+        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO) {
+                if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL) {
+                    log_info("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[0] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
+                    _threePhaseUvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO) {
+                if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL) {
+                    log_info("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[1] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
+                    _threePhaseUvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO) {
+                if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL) {
+                    log_info("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+                    } else {
+                        _threePhaseUvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
+                    _threePhaseUvp[2] = 0;
+                }
+            }
+        }
+
+        //********************************************************************************************************//
+        // Vin (OVP)
+        if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO) {
+                if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC) {
+                    log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[0] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
+                    _threePhaseOvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO) {
+                if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC) {
+                    log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[1] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
+                    _threePhaseOvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO) {
+                if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC) {
+                    log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
+                    _threePhaseOvp[2] = 0;
+                }
+            }
+        } else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL) {
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO) {
+                if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL) {
+                    log_info("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+                    if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[0] += 0;
+                    }
+                }
+            } else {
+                if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
+                    _threePhaseOvp[0] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO) {
+                if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL) {
+                    log_info("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+                    if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[1] += 0;
+                    }
+                }
+            } else {
+                if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
+                    _threePhaseOvp[1] = 0;
+                }
+            }
+
+            if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO) {
+                if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL) {
+                    log_info("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+                    if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT) {
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+                    } else {
+                        _threePhaseOvp[2] += 1;
+                    }
+                }
+            } else {
+                if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL) {
+                    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
+                    _threePhaseOvp[2] = 0;
+                }
+            }
+        }
+    }
+}
+
+// 左右槍的 Relay 前後的輸出電壓
+void GetPersentOutputVol(void)
+{
+    uint8_t index = 0;
+    uint8_t targetID = 0;
+
+    if (Query_Present_OutputVoltage(Uart5Fd, ADDR_RELAY, &outputVoltage) != PASS) {
+        return;
+    }
+
+    //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);
+
+    //log_info("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+    //log_info("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 (index = 0; index < gunCount; index++) {
+        targetID = getCommTargetID(index);
+
+        switch (targetID) {
+        case 0x01:
+#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 0x02:
+#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) {
+        //}
+    }
+}
+
+// 風扇速度
+void GetFanSpeed()
+{
+    //log_info("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];
+//      log_info("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
+//      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]);
+        //SysInfoData (SystemFanRotaSpeed)
+    }
+}
+
+// 讀取 Relay 狀態
+void GetRelayOutputStatus(void)
+{
+    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
+    }
+}
+
+// 確認 K1 K2 relay 的狀態
+void CheckK1K2RelayOutput(uint8_t index)
+{
+    uint8_t targetID = 0;
+
+    targetID = getCommTargetID(index);
+
+    switch (targetID) {
+    case 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 !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            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 //!defined DD360 && !defined DD360Audi
+        }
+        break;
+
+    case 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) {
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            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 //!defined DD360 && !defined DD360Audi
+        }
+        break;
+    }
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    //DS60-120 add
+    if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
+        if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
+                regRelay.relay_event.bits.Gun1_Parallel_P == NO) {
+            ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
+        }
+    } else if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
+        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 = YES;
+#endif //!defined DD360 && !defined DD360Audi
+}
+
+void GetGfdAdc()
+{
+    int gunIndex = 0;
+    uint8_t targetID = 0;
+
+    // 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 (gunIndex = 0; gunIndex < gunCount; gunIndex++) {
+            if (_chargingData[gunIndex]->Type == 0x09 &&
+                    !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag
+               ) {
+                if ((_chargingData[gunIndex]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE) {
+                    _chargingData[gunIndex]->GroundFaultStatus = GFD_PASS;
+                }
+                continue;
+            }
+
+            targetID = getCommTargetID(gunIndex);
+
+            if (targetID == 0x01) {
+                if (gfd_adc.result_conn1 == GFD_WARNING) {
+                    gfd_adc.result_conn1 = GFD_PASS;
+                }
+
+                _chargingData[gunIndex]->GroundFaultStatus = gfd_adc.result_conn1;
+                //log_info("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
+                //            _chargingData[gunIndex]->GroundFaultStatus,
+                //            gfd_adc.rb_step_1,
+                //            gfd_adc.Resister_conn1,
+                //            gfd_adc.voltage_conn1);
+                if (_chargingData[gunIndex]->GroundFaultStatus == GFD_FAIL) {
+                    log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
+                             gunIndex,
+                             gfd_adc.rb_step_1,
+                             gfd_adc.Resister_conn1,
+                             gfd_adc.voltage_conn1);
+
+                } else if (_chargingData[gunIndex]->GroundFaultStatus == GFD_PASS ||
+                           _chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING
+                          ) {
+                    if (_chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING) {
+                        log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+                                 gunIndex,
+                                 _chargingData[gunIndex]->GroundFaultStatus,
+                                 gfd_adc.Resister_conn1,
+                                 gfd_adc.voltage_conn1);
+                    }
+                }
+            } else if (targetID == 0x02) {
+                if (gfd_adc.result_conn2 == GFD_WARNING) {
+                    gfd_adc.result_conn2 = GFD_PASS;
+                }
+                _chargingData[gunIndex]->GroundFaultStatus = gfd_adc.result_conn2;
+                if (_chargingData[gunIndex]->GroundFaultStatus == GFD_FAIL) {
+                    log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
+                             gunIndex,
+                             gfd_adc.rb_step_2,
+                             gfd_adc.Resister_conn2,
+                             gfd_adc.voltage_conn2);
+                } else if (_chargingData[gunIndex]->GroundFaultStatus == GFD_PASS ||
+                           _chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING
+                          ) {
+                    if (_chargingData[gunIndex]->GroundFaultStatus == GFD_WARNING) {
+                        log_info("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+                                 gunIndex,
+                                 _chargingData[gunIndex]->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
+            log_info("RB AC Main Breaker. \n");
+        }
+
+        if (gpio_in.SPD == 1) {
+            // SPD (雷擊保護) ON
+            log_info("RB SPD. \n");
+        }
+
+        if (gpio_in.Door_Open == 1) {
+            // Door Open
+            log_info("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
+            log_info("RB AC Drop. \n");
+        }
+
+        if (gpio_in.Emergency_IO == 1) {
+            // Emergency IO ON
+            log_info("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
+        //log_info("aux1 = %x, \n", auxPower.voltage[0]);
+        //log_info("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) {
+            //log_info("successfully Fan\n");
+        }
+    }
+}
+
+//==========================================
+// Common Function
+//==========================================
+void SetK1K2RelayStatus(uint8_t index)
+{
+    uint8_t targetID = 0;
+    PreChargingState *pRegPreChargingState = NULL;
+    PreChargingState *pOutputPreChargingState = NULL;
+    GunPNState *pRegGunPNState = NULL;
+    GunPNState *pOutputGunPNState = NULL;
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)_chargingData[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;
+    }
+
+    targetID = getCommTargetID(index);
+
+    pRegPreChargingState = (PreChargingState *)&regRelay.relay_event.relay_status[0];
+    pOutputPreChargingState = (PreChargingState *)&outputRelay.relay_event.relay_status[0];
+    if (targetID == 0x01) {
+        pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[1];
+        pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[1];
+    } else if (targetID == 0x02) {
+        pRegGunPNState = (GunPNState *)&regRelay.relay_event.relay_status[2];
+        pOutputGunPNState = (GunPNState *)&outputRelay.relay_event.relay_status[2];
+    }
+
+    switch (pDcChargingInfo->SystemStatus) {
+    case S_BOOTING:
+    case S_IDLE:
+    case S_AUTHORIZING:
+    case S_REASSIGN_CHECK:
+    case S_REASSIGN:
+    case S_PREPARNING:
+    case S_PREPARING_FOR_EV:
+        if (pRegGunPNState->GunP == YES) {
+            pOutputGunPNState->GunP = NO;
+        } else if (pRegGunPNState->GunN == YES) {
+            pOutputGunPNState->GunN = NO;
+        }
+
+        if (targetID == 0x02 && pDcChargingInfo->Type == _Type_CCS_2) {
+            if (pRegPreChargingState->CcsPrecharge == YES) {
+                pOutputPreChargingState->CcsPrecharge = NO;
+            }
+        }
+        break;
+
+    case S_PREPARING_FOR_EVSE:
+    case S_CHARGING:
+        //if (pDcChargingInfo->RelayWeldingCheck != YES) {
+        //    break;
+        //}
+
+        if (pRegGunPNState->GunN == NO) {
+            pOutputGunPNState->GunN = YES;
+        } else if (pRegGunPNState->GunP == NO) {
+            pOutputGunPNState->GunP = YES;
+        }
+        break;
+
+    case S_TERMINATING:
+    case S_COMPLETE:
+    case S_ALARM:
+        if ((pDcChargingInfo->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR) {
+            if (pRegGunPNState->GunP == YES) {
+                pOutputGunPNState->GunP = NO;
+            } else if (pRegGunPNState->GunN == YES) {
+                pOutputGunPNState->GunN = NO;
+            }
+        }
+        break;
+
+    case S_CCS_PRECHARGE_ST0:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+        break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+            if (pRegPreChargingState->CcsPrecharge == NO) {
+                pOutputPreChargingState->CcsPrecharge = YES;
+            } else if (pRegPreChargingState->CcsPrecharge == YES) {
+                pRegGunPNState->GunP = NO;
+            }
+        }
+        break;
+
+    case S_CCS_PRECHARGE_ST1:
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+        break;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+            if (pRegGunPNState->GunP == NO) {
+                pOutputGunPNState->GunP = YES;
+            } else if (pRegGunPNState->GunP == YES) {
+                pOutputPreChargingState->CcsPrecharge = NO;
+            }
+        }
+        break;
+    }
+}
+
+void CheckAcInputOvpStatus(uint8_t 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)
+//              {
+//                  log_info("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)
+//              {
+//                  log_info("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
+//                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
+//                  _chargingData[index]->StopChargeFlag = YES;
+//              }
+//          }
+//      }
+//      else
+        //log_info("CheckAcInputOvpStatus\r\n");
+        _chargingData[index]->StopChargeFlag = YES;
+    }
+}
+
+void CheckPhaseLossStatus(uint8_t index)
+{
+    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
+        //log_info("CheckPhaseLossStatus\r\n");
+        _chargingData[index]->StopChargeFlag = YES;
+    }
+}
+
+void SetParalleRelayStatus(void)
+{
+#if defined  DD360 || defined DD360Audi || defined DD360ComBox
+    return;
+#endif //!defined  DD360 || !defined DD360Audi || !defined DD360ComBox
+
+    // 之後雙槍單模機種,橋接都會上
+    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 (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]) {
+            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)
+{
+    uint8_t _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)) {
+#if defined DD360Audi
+                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 ||
+                    chargingData_1->SystemStatus == S_MAINTAIN) {
+
+                if (chargingData_1->IsAvailable == NO) { //For Audi
+                    led_color.Connect_1_Green = COLOR_MIN_LV;
+                    led_color.Connect_1_Blue = COLOR_MIN_LV;
+                    led_color.Connect_1_Red = _colorBuf;
+                } else {
+#if defined DD360Audi
+                    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 ||
+                    chargingData_2->SystemStatus == S_MAINTAIN) {
+                if (chargingData_2->IsAvailable == NO) {
+                    led_color.Connect_2_Green = COLOR_MIN_LV;
+                    led_color.Connect_2_Blue = COLOR_MIN_LV;
+                    led_color.Connect_2_Red = _colorBuf;
+                } else {
+#if defined DD360Audi
+                    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) {
+        result = FAIL;
+    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+    memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
+
+    if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+    memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
+
+    if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+    memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
+
+    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0) {
+        result = FAIL;
+    } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        result = FAIL;
+    }
+
+    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;
+}
+
+int InitComPort()
+{
+    int fd;
+    struct termios tios;
+
+    fd = open(relayRs485PortName, O_RDWR);
+    if (fd <= 0) {
+#ifdef SystemLogMessage
+        log_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] = (uint8_t)0;     // timeout 0.5 second
+    tios.c_lflag = 0;
+    tcflush(fd, TCIFLUSH);
+    ioctl (fd, TCSETS, &tios);
+
+    return fd;
+}
+
+//================================================
+// Main process
+//================================================
+bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
+{
+    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 (uint8_t index = 0; index < CCS_QUANTITY; index++) {
+        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
+                == target) {
+            chargingData[target] =
+                &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+            return true;
+        }
+    }
+
+    for (uint8_t 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(uint8_t target, struct ChargingInfoData **acChargingData)
+{
+    if (target < AC_QUANTITY) {
+        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
+        return true;
+    }
+
+    return false;
+}
+
+void Initialization()
+{
+    bool isPass = false;
+
+    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 (uint8_t _index = 0; _index < gunCount; _index++) {
+            if (!FindChargingInfoData(_index, &_chargingData[0])) {
+                log_error("InternalComm : FindChargingInfoData false \n");
+                isPass = false;
+                break;
+            }
+        }
+
+        sleep(1);
+    }
+
+    isPass = false;
+
+    if (acgunCount > 0) {
+        while (!isPass) {
+            isPass = true;
+            for (uint8_t _index = 0; _index < acgunCount; _index++) {
+                if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
+                    log_error("EvComm : FindAcChargingInfoData false \n");
+                    isPass = false;
+                    break;
+                }
+            }
+
+            sleep(1);
+        }
+    }
+}
+
+bool IsNoneMatchRelayStatus()
+{
+    bool result = false;
+
+    if (
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+        (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
+        (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
+#endif //!defined DD360 && !defined DD360Audi
+        (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)
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+        ||
+        (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)
+#endif //!defined DD360 && !defined DD360Audi
+    ) {
+        /*if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
+            log_info("AC Contact Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
+            log_info("CCS Precharge Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
+            log_info("SMR1:D+ Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
+            log_info("SMR1:D- Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
+            log_info("SMR2:D+ Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
+            log_info("SMR2:D- Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
+            log_info("Parallel:D+ Relay none match. \n");
+        }
+
+        if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
+            log_info("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;
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    ShmSysConfigAndInfo->SysInfo.AcContactorStatus  = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+#endif //!defined DD360 && !defined DD360Audi
+
+    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(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) {
+//      log_info("Set reqVol = %f, resister = %d \n",
+//              gfd_config.reqVol,
+//              gfd_config.resister);
+    }
+}
+
+void CableCheckDetected(uint8_t index)
+{
+    uint8_t targetID = 0;
+    // 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 (gunCount == 1) {
+        if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "0", 1) != 0) {
+            targetID = 0;
+        } else if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "0", 1) != 0) {
+            targetID = 1;
+        }
+    } else {
+        targetID = index;
+    }
+
+    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(targetID, GFD_CABLECHK);
+            } else if (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                       _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1) {
+                SetGfdConfig(targetID, 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(targetID, GFD_IDLE);
+                } else {
+                    SetGfdConfig(targetID, GFD_CHARGING);
+                }
+            }
+        } else if (_chargingData[index]->SystemStatus == S_COMPLETE ||
+                   _chargingData[index]->SystemStatus == S_PREPARNING
+                   || _chargingData[index]->SystemStatus == S_IDLE) {
+            SetGfdConfig(targetID, GFD_IDLE);
+        }
+    }
+}
+
+void CheckOutputPowerOverCarReq(uint8_t index)
+{
+    float fireV = _chargingData[index]->FireChargingVoltage;
+    float carV = _chargingData[index]->EvBatteryMaxVoltage * 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.02))) {
+            if (!_isOvpChkTimeFlag[index]) {
+                if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
+                    gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
+                    _isOvpChkTimeFlag[index] = YES;
+                }
+            } else {
+                log_info("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
+                         _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
+                log_error("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
+                          _chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10));
+                if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME) {
+                    //if (_chargingData[index]->Type == _Type_Chademo) {
+                    //    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
+                    //} else if (_chargingData[index]->Type == _Type_CCS_2) {
+                    //    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
+                    //} else if (_chargingData[index]->Type == _Type_GB) {
+                    //    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
+                    //}
+                    if (_chargingData[index]->Type == _Type_Chademo) {
+                        ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
+                        if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
+                            memcpy(_chargingData[index]->ConnectorAlarmCode, "012217", 6);
+                        }
+                    } else if (_chargingData[index]->Type == _Type_CCS_2) {
+                        ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
+                        if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
+                            memcpy(_chargingData[index]->ConnectorAlarmCode, "012219", 6);
+                        }
+                    } else if (_chargingData[index]->Type == _Type_GB) {
+                        ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = YES;
+                        if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
+                            memcpy(_chargingData[index]->ConnectorAlarmCode, "012221", 6);
+                        }
+                    }
+
+                    _chargingData[index]->StopChargeFlag = YES;
+                }
+            }
+        } else {
+            if (_isOvpChkTimeFlag[index] == YES) {
+                _isOvpChkTimeFlag[index] = NO;
+            }
+        }
+    }
+}
+
+void CheckOutputVolNoneMatchFire(uint8_t 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) {
+                    /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
+                            index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
+                    log_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(uint8_t 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;
+            }
+
+            log_info("CheckRelayWeldingStatus : fail \n");
+            _chargingData[index]->StopChargeFlag = YES;
+        }
+    }
+}
+
+void GetPsuTempForFanSpeed()
+{
+    char temp = 0;
+
+    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;
+            }
+        }
+    }
+
+    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 :
+    uint8_t temp = 0;
+    float power = 0;
+
+    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 (uint8_t gunIndex = 0; gunIndex < gunCount; gunIndex++) {
+        power += (_chargingData[gunIndex]->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 / 50;
+    }
+    uint8_t _temp_diff = 0;
+    if (temp > 45) {
+        _temp_diff = temp - 70;
+    }
+
+    ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _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_AC_PLUG, &acStatus) == PASS) {
+        ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = acStatus.MaxCurrent;
+
+        if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0) {
+            ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
+        }
+
+        ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
+        //  log_info("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
+//      log_info("GetAcStatus return fail. \n");
+}
+
+void GetAcAlarmCode()
+{
+    if (Query_AC_Alarm_Code(Uart5Fd, ADDR_AC_PLUG, &acAlarmCode) == PASS) {
+        CheckAlarmOccur();
+    }
+}
+
+uint8_t GetChargingEnergy()
+{
+    return Query_Charging_Energy(Uart5Fd, ADDR_AC_PLUG, &acChargingEnergy);
+}
+
+uint8_t GetChargingCurrent()
+{
+    return Query_Charging_Current(Uart5Fd, ADDR_AC_PLUG, &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_AC_PLUG, &ledStatus);
+}
+
+void SetLegacyReq(uint8_t _switch)
+{
+    Config_Legacy_Req(Uart5Fd, ADDR_AC_PLUG, _switch);
+}
+
+void SetCpDuty(uint8_t _value)
+{
+    Config_Ac_Duty(Uart5Fd, ADDR_AC_PLUG, _value);
+}
+
+void ChangeToCsuMode()
+{
+    ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, ADDR_AC_PLUG);
+
+//  if (ac_chargingInfo[0]->IsModeChagned == PASS)
+//  {
+//      Config_Reset_MCU(Uart5Fd, ADDR_AC_PLUG);
+//  }
+}
+
+void ChangeStartOrStopDateTime(uint8_t 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(uint8_t 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);
+    }
+
+    log_info("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
+}
+
+void OcppStopTransation(uint8_t 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);
+    }
+
+    log_info("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
+}
+
+bool OcppRemoteStop(uint8_t 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;
+}
+
+uint8_t isModeChange()
+{
+    uint8_t 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();
+
+            uint8_t _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) {
+                    log_info("** 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) {
+                    log_info("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
+                    strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+                    log_info("** 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;
+            }
+        }
+    }
+}
+
+void ResetDetAlarmStatus(uint8_t gun)
+{
+    if (_chargingData[gun]->Type == _Type_Chademo) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
+        }
+    } else if (_chargingData[gun]->Type == _Type_GB) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
+        }
+    } else if (_chargingData[gun]->Type == _Type_CCS_2) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
+        }
+    }
+}
+
+int main(void)
+{
+    uint8_t i = 0;
+    if (InitShareMemory() == FAIL) {
+        log_error("InitShareMemory NG\n");
+        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(1);
+
+    if (Uart5Fd < 0) {
+        log_info("(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) {
+        log_info("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();
+            SetModelName_Relay(); //DS60-120 add
+            SetRtcData_Relay();
+            sleep(1);
+        }
+
+#if !defined NO_FAN_BOARD && !defined DD360ComBox
+        if (ShmFanModuleData->SelfTest_Comp == NO) {
+            GetFwAndHwVersion_Fan();
+            SetModelName_Fan();
+            SetRtcData_Fan();
+            sleep(1);
+            gettimeofday(&_priority_time, NULL);
+        }
+#endif //NO_FAN_BOARD
+
+#if !defined DD360ComBox
+        // 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
+        if (ShmLedModuleData->SelfTest_Comp == NO) {
+#if defined DD360 ||defined DD360Audi
+            GetFwAndHwVersion_Led();
+            sleep(1);
+            gettimeofday(&_led_priority_time, NULL);
+#else
+            // 自檢階段
+            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;
+                }
+            }
+#endif //defined DD360 || defined DD360Audi
+        }
+#endif //!defined DD360ComBox
+
+        AcChargeTypeProcess();
+
+        if (ShmRelayModuleData->SelfTest_Comp == YES) {
+            // ==============優先權最高 10 ms ==============
+            // 輸出電壓
+            GetPersentOutputVol();
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            // 三相輸入電壓
+            GetPresentInputVol();
+            // 讀取當前 AC relay 狀態
+            regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+
+            GetRelayOutputStatus();
+#endif //!defined DD360 && !defined DD360Audi
+
+            for (i = 0; i < gunCount; i++) {
+                // Cable check (Set)
+                CableCheckDetected(i);
+
+                // check k1 k2 relay 狀態
+                CheckK1K2RelayOutput(i);
+
+                // 依據當前各槍的狀態選擇 搭上/放開 Relay
+                SetK1K2RelayStatus(i);
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+                if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
+                    CheckPhaseLossStatus(i);
+                }
+
+                CheckAcInputOvpStatus(i);
+#endif //!defined DD360 && !defined DD360Audi
+
+                if (_chargingData[i]->SystemStatus == S_IDLE) {
+                    _chargingData[i]->RelayWeldingCheck = NO;
+                    _isRelayWelding[i] = NO;
+                    _isOvpChkTimeFlag[i] = NO;
+                    ResetDetAlarmStatus(i); //DS60-120 add
+                }
+
+                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;
+
+                    //log_info("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 !defined NO_FAN_BOARD && !defined DD360ComBox
+        if (ShmFanModuleData->SelfTest_Comp == YES ||
+                strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+                ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0') {
+            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;
+
+                //log_info("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
+                SetFanModuleSpeed();
+            }
+        }
+#endif //NO_FAN_BOARD
+
+#if !defined DD360ComBox
+        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);
+            }
+        }
+#endif //defined DD360ComBox
+
+        usleep(10000);
+    }
+
+    return FAIL;
+}

+ 360 - 178
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c

@@ -3,12 +3,14 @@
 #include <string.h>
 #include <stdint.h>
 #include <time.h>
+#include <unistd.h>
 
 #include <sys/time.h>
 #include <sys/timeb.h>
 
 #include "../ShareMemory/shmMem.h"
 #include "../Config.h"
+#include "../Log/log.h"
 #include "Module_InternalComm.h"
 #include "internalComm.h"
 
@@ -18,16 +20,18 @@ static struct SysInfoData *pSysInfo = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct RelayModuleData *ShmRelayModuleData = NULL;
 static struct PsuData *ShmPsuData = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
 
 static Relay outputRelay = {0};
 static Relay regRelay = {0};
 static int Uart5Fd = 0;
 
-static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
-static bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 static bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
 static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
@@ -35,15 +39,62 @@ static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTIT
 static struct timeval _close_ac_contactor;
 
 //------------------------------------------------------------------------------
-uint32_t GetTimeoutValue(struct timeval _sour_time)
+static void RunForceStopProcess(void)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    static bool isCriticalStop = NO;
+    static struct timeval  _psuCriticalStop;
+    uint32_t _timebuf;
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    if (isCriticalStop == NO) {
+        isCriticalStop = YES;
+        gettimeofday(&_psuCriticalStop, NULL);
+    } else {
+        _timebuf = GetTimeoutValue(_psuCriticalStop);
+
+        if (_timebuf < 0) {
+            gettimeofday(&_psuCriticalStop, NULL);
+        } else {
+            if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000)) {
+                isCriticalStop = NO;
+                pAlarmCode->AlarmEvents.bits.PsuFailureAlarm = NORMAL;
+            }
+        }
+    }
 }
 
-uint8_t getCommTargetID(uint8_t index)
+static void StopCheckRelayInfo(uint8_t _chkIndex)
+{
+    if (ShmDcCommonData->CheckRelayStatus[_chkIndex] != STOP) {
+        ShmDcCommonData->CheckRelayStatus[_chkIndex] = STOP;
+    }
+}
+
+static void StartCheckRelayInfo(uint8_t _chkIndex, uint8_t toState)
+{
+    // SMR1 *2 + SMR2 * 2 + Parallel * 2
+    static time_t lastCheckRelayStateTimer[6] = {0};
+    time_t nowTime = {0};
+    //uint8_t *pCheckRelayState = (uint8_t *)ShmDcCommonData->CheckRelayStatus[_chkIndex];
+
+    if (ShmDcCommonData->CheckRelayStatus[_chkIndex] == STOP) {
+        time(&lastCheckRelayStateTimer[_chkIndex]);
+        ShmDcCommonData->CheckRelayStatus[_chkIndex] = START;
+    } else {
+        time(&nowTime);
+
+        if (nowTime - lastCheckRelayStateTimer[_chkIndex] >= 1) {
+            //log_info("relay welding or driving fault = %d \n", _chkIndex);
+            if (toState == 1) {
+                ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
+            } else {
+                ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
+            }
+            lastCheckRelayStateTimer[_chkIndex] = nowTime;
+        }
+    }
+}
+
+static uint8_t getCommTargetID(uint8_t index)
 {
     uint8_t targetID = 0;
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
@@ -61,7 +112,23 @@ uint8_t getCommTargetID(uint8_t index)
     return targetID;
 }
 
-bool IsNoneMatchRelayStatus(void)
+static void MatchRelayStatus(void)
+{
+    // 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
+    //regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+    //pSysInfo->AcContactorStatus =
+    //    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;
+}
+
+static bool IsNoneMatchRelayStatus(void)
 {
     bool result = false;
 
@@ -80,47 +147,69 @@ bool IsNoneMatchRelayStatus(void)
         (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N)
 #endif //!defined DD360 && !defined DD360Audi
     ) {
-        /*if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
-            log_info("AC Contact Relay none match. \n");
-        }
+        result = true;
+    }
 
-        if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
-            log_info("CCS Precharge Relay none match. \n");
-        }
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
+        log_info("AC Contact Relay none match. \n");
+    }
 
-        if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
-            log_info("SMR1:D+ Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) {
+        log_info("CCS Precharge Relay none match. \n");
+    }
+#endif //
 
-        if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
-            log_info("SMR1:D- Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) {
+        //log_info("SMR1:D+ Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR1_P_STATUS, outputRelay.relay_event.bits.Gun1_P);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR1_P_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
-            log_info("SMR2:D+ Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) {
+        //log_info("SMR1:D- Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR1_N_STATUS, outputRelay.relay_event.bits.Gun1_N);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR1_N_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
-            log_info("SMR2:D- Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) {
+        //log_info("SMR2:D+ Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR2_P_STATUS, outputRelay.relay_event.bits.Gun2_P);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR2_P_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
-            log_info("Parallel:D+ Relay none match. \n");
-        }
+    if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) {
+        //log_info("SMR2:D- Relay none match. \n");
+        StartCheckRelayInfo(RELAY_SMR2_N_STATUS, outputRelay.relay_event.bits.Gun2_N);
+    } else {
+        StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
+    }
 
-        if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
-            log_info("Parallel:D- Relay none match. \n");
-        }*/
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
+        //log_info("Parallel:D+ Relay none match. \n");
+        StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
+    } else {
+        StopCheckRelayInfo(RELAY_PARA_P_STATUS);
+    }
 
-        result = true;
+    if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N) {
+        //log_info("Parallel:D- Relay none match. \n");
+        StartCheckRelayInfo(RELAY_PARA_N_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_N);
+    } else {
+        StopCheckRelayInfo(RELAY_PARA_N_STATUS);
     }
+#endif //
 
     return result;
 }
 
-void SetParalleRelayStatus(void)
+static void SetParalleRelayStatus(void)
 {
-#if defined  DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
     return;
 #endif //!defined  DD360 || !defined DD360Audi || !defined DD360ComBox
 
@@ -179,7 +268,7 @@ void SetParalleRelayStatus(void)
     }
 }
 
-void GetGfdAdc(void)
+static void GetGfdAdc(void)
 {
     int gunIndex = 0;
     uint8_t targetID = 0;
@@ -205,9 +294,9 @@ void GetGfdAdc(void)
             targetID = getCommTargetID(gunIndex);
 
             if (targetID == 0x01) {
-                if (gfd_adc.result_conn1 == GFD_WARNING) {
-                    gfd_adc.result_conn1 = GFD_PASS;
-                }
+                //if (gfd_adc.result_conn1 == GFD_WARNING) {
+                //    gfd_adc.result_conn1 = GFD_PASS;
+                //}
 
                 pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn1;
                 //log_info("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
@@ -234,9 +323,9 @@ void GetGfdAdc(void)
                     }
                 }
             } else if (targetID == 0x02) {
-                if (gfd_adc.result_conn2 == GFD_WARNING) {
-                    gfd_adc.result_conn2 = GFD_PASS;
-                }
+                //if (gfd_adc.result_conn2 == GFD_WARNING) {
+                //    gfd_adc.result_conn2 = GFD_PASS;
+                //}
                 pDcChargingInfo->GroundFaultStatus = gfd_adc.result_conn2;
                 if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
                     log_info("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
@@ -327,8 +416,8 @@ void CheckAcInputOvpStatus(uint8_t index)
     if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
             pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
             pAlarmCode->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 ((pDcChargingInfo->SystemStatus >= S_PREPARNING && pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+//              (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
 //      {
 //          if (pSysInfo->ChargerType == _CHARGER_TYPE_IEC)
 //          {
@@ -338,7 +427,7 @@ void CheckAcInputOvpStatus(uint8_t index)
 //              {
 //                  log_info("IEC _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
 //                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
+//                  pDcChargingInfo->StopChargeFlag = YES;
 //              }
 //
 //          }
@@ -350,7 +439,7 @@ void CheckAcInputOvpStatus(uint8_t index)
 //              {
 //                  log_info("UL _psuInputVolR = %f, _psuInputVolS = %f, _psuInputVolT = %f \n",
 //                          _psuInputVolR, _psuInputVolS, _psuInputVolT);
-//                  _chargingData[index]->StopChargeFlag = YES;
+//                  pDcChargingInfo->StopChargeFlag = YES;
 //              }
 //          }
 //      }
@@ -360,6 +449,34 @@ void CheckAcInputOvpStatus(uint8_t index)
     }
 }
 
+//void CheckOutputVolNoneMatchFire(uint8_t index)
+//{
+//    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+//
+//    if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
+//            (pDcChargingInfo->Type == _Type_Chademo ||
+//             pDcChargingInfo->Type == _Type_CCS_2 ||
+//             pDcChargingInfo->Type == _Type_GB)) {
+//        if (((pDcChargingInfo->PresentChargingVoltage * 10) < pDcChargingInfo->FireChargingVoltage - 300) ||
+//                ((pDcChargingInfo->PresentChargingVoltage * 10) > pDcChargingInfo->FireChargingVoltage + 300)) {
+//            if (!_isOutputNoneMatch[index]) {
+//                _isOutputNoneMatch[index] = YES;
+//                gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
+//            } else {
+//                if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
+//                    /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
+//                            index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
+//                    log_error("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f \n",
+//                            index, (pDcChargingInfo->PresentChargingVoltage * 10), pDcChargingInfo->FireChargingVoltage);
+//                    pDcChargingInfo->StopChargeFlag = YES;*/
+//                }
+//            }
+//        } else {
+//            _isOutputNoneMatch[index] = NO;
+//        }
+//    }
+//}
+
 void CheckPhaseLossStatus(uint8_t index)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
@@ -453,13 +570,13 @@ void SetK1K2RelayStatus(uint8_t index)
         break;
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
-            if (pRegPreChargingState->CcsPrecharge == NO) {
-                pOutputPreChargingState->CcsPrecharge = YES;
-            } else if (pRegPreChargingState->CcsPrecharge == YES) {
-                pRegGunPNState->GunP = NO;
-            }
-        }
+        //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+        //    if (pRegPreChargingState->CcsPrecharge == NO) {
+        //        pOutputPreChargingState->CcsPrecharge = YES;
+        //    } else if (pRegPreChargingState->CcsPrecharge == YES) {
+        //        pRegGunPNState->GunP = NO;
+        //    }
+        //}
         break;
 
     case S_CCS_PRECHARGE_ST1:
@@ -467,13 +584,13 @@ void SetK1K2RelayStatus(uint8_t index)
         break;
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-        if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
-            if (pRegGunPNState->GunP == NO) {
-                pOutputGunPNState->GunP = YES;
-            } else if (pRegGunPNState->GunP == YES) {
-                pOutputPreChargingState->CcsPrecharge = NO;
-            }
-        }
+        //if (pDcChargingInfo->Type == _Type_CCS_2 && targetID == 0x02) {
+        //    if (pRegGunPNState->GunP == NO) {
+        //        pOutputGunPNState->GunP = YES;
+        //    } else if (pRegGunPNState->GunP == YES) {
+        //        pOutputPreChargingState->CcsPrecharge = NO;
+        //    }
+        //}
         break;
     }
 }
@@ -603,9 +720,10 @@ void CableCheckDetected(uint8_t index)
                 (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
                  pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
            ) {
-            if ((pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) &&
-                    (pDcChargingInfo->RelayWeldingCheck == YES)
-               ) {
+            //if ((pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) &&
+            //        (pDcChargingInfo->RelayWeldingCheck == YES)
+            //   ) {
+            if (pDcChargingInfo->SystemStatus == S_PREPARING_FOR_EVSE) {
                 SetGfdConfig(targetID, GFD_CABLECHK);
             } else if ((pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0) &&
                        (pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
@@ -987,7 +1105,7 @@ void GetFwAndHwVersion_Relay(void)
     }
 }
 
-void outputRelayInit(int fd)
+static void outputRelayInit(int fd)
 {
     memset((uint8_t *)&outputRelay, 0, sizeof(Relay));
 
@@ -996,7 +1114,7 @@ void outputRelayInit(int fd)
     }
 }
 
-void RelayBoardTaask(int uartFD)
+void RelayBoardTask(int uartFD)
 {
     pid_t pid = fork();
 
@@ -1004,21 +1122,17 @@ void RelayBoardTaask(int uartFD)
         bool isCharging = false;
         bool isStopChargingCount = false;
         uint8_t i = 0;
-        int fd = GetInternalFd();
         int isContinue = 1;
         struct ChargingInfoData *pDcChargingInfo = NULL;
 
-        if (CreateAllCsuShareMemory() == FAIL) {
-            log_error("Relay Board create share memory failed\r\n");
-        }
-        MappingGunChargingInfo("Relay Board Task");
-
         //share memory mapping
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
         ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
         ShmPsuData = (struct PsuData *)GetShmPsuData();
+        ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonInfo();
+        ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
 
         Uart5Fd = uartFD;
 
@@ -1032,138 +1146,206 @@ void RelayBoardTaask(int uartFD)
                 SetModelName_Relay(); //DS60-120 add
                 SetRtcData_Relay();
                 sleep(1);
-            } else {
-                // ==============優先權最高 10 ms ==============
-                // 輸出電壓
-                GetPersentOutputVol();
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                // 三相輸入電壓
-                GetPresentInputVol();
-                // 讀取當前 AC relay 狀態
-                regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
+                continue;
+            }
 
-                GetRelayOutputStatus();
+            // ==============優先權最高 10 ms ==============
+            // 輸出電壓
+            GetPersentOutputVol();
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+            // 三相輸入電壓
+            GetPresentInputVol();
 #endif //!defined DD360 && !defined DD360Audi
 
-                for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+            // 讀取當前 AC relay 狀態
+            regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
 
-                    // Cable check (Set)
-                    CableCheckDetected(i);
+            GetRelayOutputStatus();
 
-                    // check k1 k2 relay 狀態
-                    CheckK1K2RelayOutput(i);
+            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
-                    // 依據當前各槍的狀態選擇 搭上/放開 Relay
-                    SetK1K2RelayStatus(i);
+                // Cable check (Set)
+                CableCheckDetected(i);
+
+                // check k1 k2 relay 狀態
+                CheckK1K2RelayOutput(i);
+
+                // 依據當前各槍的狀態選擇 搭上/放開 Relay
+                SetK1K2RelayStatus(i);
 
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                    if (pSysConfig->PhaseLossPolicy == YES) {
-                        CheckPhaseLossStatus(i);
-                    }
+                if (pSysConfig->PhaseLossPolicy == YES) {
+                    CheckPhaseLossStatus(i);
+                }
 
-                    CheckAcInputOvpStatus(i);
+                CheckAcInputOvpStatus(i);
 #endif //!defined DD360 && !defined DD360Audi
 
-                    if (pDcChargingInfo->SystemStatus == S_IDLE) {
-                        pDcChargingInfo->RelayWeldingCheck = NO;
-                        _isRelayWelding[i] = NO;
-                        _isOvpChkTimeFlag[i] = NO;
-                        ResetDetAlarmStatus(i); //DS60-120 add
-                    }
+                if (pDcChargingInfo->SystemStatus == S_IDLE ||
+                        pDcChargingInfo->SystemStatus == S_RESERVATION ||
+                        pDcChargingInfo->SystemStatus == S_MAINTAIN) {
+                    //pDcChargingInfo->RelayWeldingCheck = NO;
+                    //_isRelayWelding[i] = NO;
+                    _isOvpChkTimeFlag[i] = NO;
+                    //ResetDetAlarmStatus(i); //DS60-120 add
+                }
 
-                    if (pDcChargingInfo->SystemStatus == S_BOOTING ||
-                            (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
-                             pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
-                            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                             pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                            pSysInfo->WaitForPlugit == YES ||
-                            (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
-                             pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)) {
-                        pDcChargingInfo->IsReadyToCharging = YES;
-                        isCharging = true;
-
-                        // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
-                        //if (pDcChargingInfo->Type == _Type_GB) {
-                        //    if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
-                        //            pDcChargingInfo->RelayWeldingCheck == NO) {
-                        //        CheckRelayWeldingStatus(i);
-                        //    }
-                        //} else {
-                        pDcChargingInfo->RelayWeldingCheck = YES;
-                        //}
-
-                        if (pDcChargingInfo->SystemStatus == S_CHARGING) {
-                            CheckOutputPowerOverCarReq(i);
-                            //CheckOutputVolNoneMatchFire(i);
-                        } else {
-                            _isOutputNoneMatch[i] = NO;
-                        }
-                    } else {
-                        pDcChargingInfo->IsReadyToCharging = NO;
+                if (pDcChargingInfo->SystemStatus == S_BOOTING ||
+                        (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
+                         pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
+                        (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+                         pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
+                        pSysInfo->WaitForPlugit == YES ||
+                        (pSysInfo->PageIndex >= _LCM_AUTHORIZING &&
+                         pSysInfo->PageIndex <= _LCM_WAIT_FOR_PLUG)
+                   ) {
+                    pDcChargingInfo->IsReadyToCharging = YES;
+                    isCharging = true;
+
+                    // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
+                    //if (pDcChargingInfo->Type == _Type_GB) {
+                    //    if (pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
+                    //            pDcChargingInfo->RelayWeldingCheck == NO) {
+                    //        CheckRelayWeldingStatus(i);
+                    //    }
+                    //} else {
+                    //pDcChargingInfo->RelayWeldingCheck = YES;
+                    //}
+
+                    if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+                        CheckOutputPowerOverCarReq(i);
+                        //CheckOutputVolNoneMatchFire(i);
                     }
+                    /*else {
+                        _isOutputNoneMatch[i] = NO;
+                    }*/
+                } else {
+                    pDcChargingInfo->IsReadyToCharging = NO;
                 }
+            }
 
-                // Cable check (Get)
-                GetGfdAdc();
+            // Cable check (Get)
+            GetGfdAdc();
 
-                // 橋接 relay
-                SetParalleRelayStatus();
+            // 橋接 relay
+            SetParalleRelayStatus();
 
-                // 搭上 AC Contactor
-                //if (isCharging) {
-                //    outputRelay.relay_event.bits.AC_Contactor = YES;
-                //} else {
-                //    outputRelay.relay_event.bits.AC_Contactor = NO;
-                //}
+            // 搭上 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;
+            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 (!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 ((outputRelay.relay_event.bits.AC_Contactor == YES &&
+                            GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000))) {
+                        outputRelay.relay_event.bits.AC_Contactor = NO;
                     }
                 }
+            }
+
+            if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
+                outputRelay.relay_event.bits.AC_Contactor = NO;
+            }
+
+            if (pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == ABNORMAL) {
+                RunForceStopProcess();
+                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 = pSysInfo->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;
+
+                    //MatchRelayStatus();
+                    //log_info("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 (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
-                    outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
                 }
+            } /*else {
+                    log_info("======== Relay Status Start========\n");
+                    if (regRelay.relay_event.bits.AC_Contactor == YES) {
+                        log_info("AC Power : ON \n");
+                    } else {
+                        log_info("AC Power : OFF \n");
+                    }
 
-                // 搭上/鬆開 Relay
-                if (IsNoneMatchRelayStatus()) {
-                    if (Config_Relay_Output(Uart5Fd, ADDR_RELAY, &outputRelay)) {
-                        //regRelay.relay_event.bits.AC_Contactor = pSysInfo->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;
-
-                        //log_info("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 (regRelay.relay_event.bits.Gun1_P == YES) {
+                        log_info("Conn1(+) : ON \n");
+                    } else {
+                        log_info("Conn1(+) : OFF \n");
+                    }
 
+                    if (regRelay.relay_event.bits.Gun1_N == YES) {
+                        log_info("Conn1(-) : ON \n");
+                    } else {
+                        log_info("Conn1(-) : OFF \n");
                     }
-                }
-            }
+
+                    if (regRelay.relay_event.bits.Gun2_P == YES) {
+                        log_info("Conn2(+) : ON \n");
+                    } else {
+                        log_info("Conn2(+) : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.Gun2_N == YES) {
+                        log_info("Conn2(-) : ON \n");
+                    } else {
+                        log_info("Conn2(-) : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.CCS_Precharge == YES) {
+                        log_info("Precharge : ON \n");
+                    } else {
+                        log_info("Precharge : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.Gun1_Parallel_P == YES) {
+                        log_info("Parallel(+) : ON \n");
+                    } else {
+                        log_info("Parallel(+) : OFF \n");
+                    }
+
+                    if (regRelay.relay_event.bits.Gun1_Parallel_N == YES) {
+                        log_info("Parallel(-) : ON \n");
+                    } else {
+                        log_info("Parallel(-) : OFF \n");
+                    }
+                    log_info("======== Relay Status End========\n");
+                }*/
         }
         usleep(100000);
     }

+ 3 - 3
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -295,16 +295,16 @@ static void checkChillerStatus(Gpio_out *gpio)
         pDcChargingInfo = (struct ChargingInfoData *)ChargingData[gunIndex];
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
-        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) {
+        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
             pChillerInfo->ChillerSwitch = YES;
             pChillerInfo->ChillerOnTime = time((time_t *)NULL);
         } else {
             if (pChillerInfo->ChillerSwitch == YES) {
-                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) {
+                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) { //判斷如果還是大於100A不變動
                     pChillerInfo->ChillerSwitch = YES;
                     pChillerInfo->ChillerOnTime = time((time_t *)NULL);
                 } else {
-                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
+                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) { //5分鐘後停止
                         pChillerInfo->ChillerSwitch = NO;
                     } else {
                         pChillerInfo->ChillerSwitch = YES;

+ 12 - 6
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -1119,16 +1119,22 @@ 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) {
+                uint8_t _GunIndex = 0;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
                 _chargingData[0]->ConnectorTemp = atoi(newString[2]);
                 printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ConnectorTemp);
             } else if (strcmp(newString[1], "1") == 0) {
+                uint8_t _GunIndex = 1;
+                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                    printf ("FindChargingInfoData error\n");
+                    return 0;
+                }
+
                 _chargingData[1]->ConnectorTemp = atoi(newString[2]);
                 printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
             }

+ 5 - 3
EVSE/Projects/DD360Audi/Apps/Readme.md

@@ -1,7 +1,9 @@
 ## merge master
-   在merge master後,需要在執行一次DD360Audi/Apps/Script/createDefine.sh
-   因DD360相關的projects不是使用Projects/define.h,compoler 沒問題後
-   需要執行replaceOtherDD360Project.sh
+    1. merge master,fixed conflict完成。
+    2. 執行DD360Audi/Apps/Script/createDefine.sh
+    3. compiler 確認沒有問題。
+    4. 執行DD360Audi/Apps/Script/replaceOtherDD360Project.sh
+    5. 重新commit。
 
 ## DD360 和 DD360ComBox 都是用DD360Audi開發和修改,完成後,執行
    DD360Audi/Apps/Script/replaceOtherDD360Project.sh

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/Script/createDefine.sh

@@ -17,7 +17,7 @@ InfoCode="char InfoStatusCode\[384\]\[6\]";
 
 finalString="#endif // DEFINE_H_";
 
-count=500;
+count=512;
 
 rm -rf $workPath/define.h;
 rm -rf $workPath/define.c;

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

@@ -9,3 +9,7 @@ cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360/ModelNameLis
 rm -rf $ProjectPath/DD360ComBox/Apps/;
 cp -r  $ProjectPath/DD360Audi/Apps/  $ProjectPath/DD360ComBox/Apps;
 cp -r  $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360ComBox/ModelNameList.txt;
+
+git add $ProjectPath/DD360;
+git add $ProjectPath/DD360Audi;
+git add $ProjectPath/DD360ComBox;

+ 194 - 0
EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.c

@@ -0,0 +1,194 @@
+#if 0
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <string.h>
+#include <stdint.h>
+
+#include "../Config.h"
+#include "../Log/log.h"
+#include "../Define/define.h"
+#include "../ShareMemory/shmMem.h"
+#include "../timeout.h"
+#include "../main.h"
+
+#include "SelectGun.h"
+
+//------------------------------------------------------------------------------
+int WaitAuthorPageState(void)
+{
+    int ret = FAIL;
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+
+#if !defined DD360Audi
+    return PASS;
+#endif //!defined DD360Audi
+
+    if (pSysInfo->SystemPage != _LCM_AUTHORIZING &&
+            pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
+            pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL) {
+        ret = PASS;
+    }
+
+    return ret;
+}
+
+void destroySelGun(uint8_t curGun)
+{
+    uint8_t i = 0;
+
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+    struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+
+    //for status timeout
+    if (curGun == DESTROY_ALL_SEL) {
+        pSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
+        pSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
+        log_info("destroy all gun = %d, %d\r\n",
+                 pSelectGunInfo->SelGunInfo.LeftGun,
+                 pSelectGunInfo->SelGunInfo.RightGun);
+        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+            StopGunInfoTimeoutDet(i);
+            memset(&pSelectGunInfo->PricesInfo[i], 0, sizeof(PricesInfo));
+        }
+        pSysInfo->CurGunSelected = 0;
+        strcpy((char *)pSysConfig->UserId, "");
+        //changeLcmPage(_LCM_SELECT_GUN);
+        return;
+    }
+
+    //for charging timeout or complete
+    if ((curGun == LEFT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
+        if (pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
+                pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
+            pSysInfo->SystemPage = _LCM_SELECT_GUN;
+        }
+        pSelectGunInfo->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", pSysInfo->SystemPage);
+        //if (pSysInfo->SystemPage == pSysInfo->SystemPage) {
+        log_info("clear left balance\r\n");
+        memset(&pSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
+        pSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
+        //}
+    }
+
+    if ((curGun == RIGHT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
+        if (pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
+                pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
+            pSysInfo->SystemPage = _LCM_SELECT_GUN;
+        }
+        pSelectGunInfo->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", pSysInfo->SystemPage);
+        //if (pSysInfo->SystemPage == pSysInfo->SystemPage) {
+        log_info("clear right balance\r\n");
+        memset(&pSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
+        pSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
+        //}
+    }
+}
+
+int waitRightGunPlugIt(uint8_t curGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+
+    if ((curGun == RIGHT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+int waitLeftGunPlugIt(uint8_t curGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if ((curGun == LEFT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+void setSelGunWaitToAuthor(uint8_t curSel)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if (curSel == LEFT_GUN_NUM && pSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
+        pSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
+        //printf("setSelGunWaitToAuthor left\r\n");
+        StopGunInfoTimeoutDet(curSel);
+    } else if (curSel == RIGHT_GUN_NUM && pSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
+        pSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
+        //printf("setSelGunWaitToAuthor right\r\n");
+        StopGunInfoTimeoutDet(curSel);
+    }
+}
+
+int getConfirmSelectedGun(uint8_t curSel)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if (((curSel == LEFT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
+            ((curSel == RIGHT_GUN_NUM) && (pSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+void confirmSelGun(uint8_t selGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    SelectGunInfo *pSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //Jerry add
+
+    if (selGun == LEFT_GUN_NUM) {
+        pSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+        StopGunInfoTimeoutDet(selGun);
+        //printf("confirmSelGun left\r\n");
+    } else if (selGun == RIGHT_GUN_NUM) {
+        pSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+        StopGunInfoTimeoutDet(selGun);
+        //printf("confirmSelGun right\r\n");
+    }
+
+    pSysInfo->SystemPage = _LCM_IDLE;
+
+    StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
+}
+#endif //0

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

@@ -96,4 +96,13 @@ typedef struct StAudiCustInfo {
     uint8_t Reserved[2];
 } SelectGunInfo;
 
+//------------------------------------------------------------------------------
+//int WaitAuthorPageState(void);
+//void destroySelGun(uint8_t curGun);
+//int waitRightGunPlugIt(uint8_t curGun);
+//int waitLeftGunPlugIt(uint8_t curGun);
+//void setSelGunWaitToAuthor(uint8_t curSel);
+//int getConfirmSelectedGun(uint8_t curSel);
+//void confirmSelGun(uint8_t selGun);
+
 #endif /* _SELECT_GUN_H_ */

+ 72 - 31
EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c

@@ -12,40 +12,64 @@
 //#include "../AudiCust.h"
 #include "../SelectGun/SelectGun.h"
 #include "../common.h"
-//#include "../log/log.h"
+#include "../Log/log.h"
 #include "../Config.h"
 #include "shmMem.h"
 
 //------------------------------------------------------------------------------
 static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
-//static struct SysInfoData *ShmSysInfoData           = NULL;
-//static struct SysConfigData *ShmSysConfigData       = NULL;
-//static struct WARNING_CODE_INFO *SysWarningInfo     = NULL;
+//static struct SysInfoData *ShmSysInfoData = NULL;
+//static struct SysConfigData *ShmSysConfigData = NULL;
+//static struct WARNING_CODE_INFO *SysWarningInfo = NULL;
 
-static struct StatusCodeData *ShmStatusCodeData     = NULL;
-//static struct AlarmCodeData *ShmAlarmCodeData       = NULL;
-//static struct FaultCodeData *ShmFaultCodeData       = NULL;
-//static struct InfoCodeData  *ShmInfoCodeData        = NULL;
+static struct StatusCodeData *ShmStatusCodeData = NULL;
+//static struct AlarmCodeData *ShmAlarmCodeData = NULL;
+//static struct FaultCodeData *ShmFaultCodeData = NULL;
+//static struct InfoCodeData  *ShmInfoCodeData = NULL;
 
-static struct PsuData *ShmPsuData                   = NULL;
+static struct PsuData *ShmPsuData = NULL;
 
-static struct CHAdeMOData *ShmCHAdeMOData           = NULL;
-static struct GBTData *ShmGBTData                   = NULL;
-static struct CcsData *ShmCcsData                   = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct CcsData *ShmCcsData = NULL;
 
-static struct PrimaryMcuData *ShmPrimaryMcuData     = NULL;
-static struct FanModuleData *ShmFanModuleData       = NULL;
-static struct RelayModuleData *ShmRelayModuleData   = NULL;
-static struct LedModuleData *ShmLedModuleData       = NULL;
-static struct OCPP16Data *ShmOCPP16Data             = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static struct FanModuleData *ShmFanModuleData = NULL;
+static struct RelayModuleData *ShmRelayModuleData = NULL;
+static struct LedModuleData *ShmLedModuleData = NULL;
+static struct OCPP16Data *ShmOCPP16Data = NULL;
 
-static SelectGunInfo *ShmSelectGunInfo              = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
+static DcCommonInfo *ShmDcCommonInfo = NULL;
 
 static struct ChargingInfoData *DcChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {NULL};
 static struct ChargingInfoData *AcChargingData[AC_QUANTITY] = {NULL};
 
 static GunIndexInfo gGunIndexInfo = {0};
 
+//struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+//struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+//struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+//struct AlarmCodeData *pAlarmCode =(struct AlarmCodeData *)GetShmAlarmCodeData();
+//struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+//struct FaultCodeData *pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+
+//struct PsuData *ShmPsuData = (struct PsuData *)GetShmPsuData();
+
+//struct CHAdeMOData *ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
+//struct GBTData *ShmGBTData = (struct GBTData *)GetShmGBTData();
+//struct CcsData *ShmCcsData = (struct CcsData *)GetShmCcsData();
+
+//struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+//struct FanModuleData *ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
+//struct RelayModuleData *ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
+//struct LedModuleData *ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
+//struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+
+//SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+//DcCommonInfo *ShmDcCommonInfo = (DcCommonInfo *)GetShmDcCommonInfo();
+
 //------------------------------------------------------------------------------
 void *GetGunIndexInfo(void)
 {
@@ -282,6 +306,15 @@ void *GetShmSelectGunInfo(void)
     return ShmSelectGunInfo;
 }
 
+void *GetShmDcCommonInfo(void)
+{
+    if (ShmDcCommonInfo == NULL) {
+        return NULL;
+    }
+
+    return ShmDcCommonInfo;
+}
+
 //------------------------------------------------------------------------------
 /*static void initialGunIndexToUnUse(void)
 {
@@ -519,18 +552,18 @@ int InitSelectGunShmMem(void)
     return PASS;
 }
 
-//int InitCommonShmMem(void)
-//{
-//    int MeterSMId = FAIL;
-//
-//    if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0) {
-//        return FAIL;
-//    } else if ((ShmDcCommonInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-//        return FAIL;
-//    }
-//
-//    return PASS;
-//}
+int InitCommonShmMem(void)
+{
+    int MeterSMId = FAIL;
+
+    if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
+        return FAIL;
+    } else if ((ShmDcCommonInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        return FAIL;
+    }
+
+    return PASS;
+}
 
 //int InitCSUMeterShmMem(void)
 //{
@@ -717,7 +750,7 @@ void ClearAllShmMemParameter(void)
     //memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
 
     //memset(ShmCsuMeterInfo, 0, sizeof(struct MeterInformation));
-    //memset(ShmDcCommonInfo, 0, sizeof(struct DcCommonInformation));
+    memset(ShmDcCommonInfo, 0, sizeof(DcCommonInfo));
 
 #if defined DD360 || defined DD360Audi || defined DD360ComBox
     memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
@@ -953,6 +986,7 @@ bool MappingGunChargingInfo(char *whichTask)
                  pSysConfig->TotalConnectorCount,
                  pSysConfig->AcConnectorCount);
     }
+
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
         findDcChargingInfoData(gunIndex);
     }
@@ -1027,6 +1061,13 @@ int CreateAllCsuShareMemory(void)
         return ret;
     }
 
+    if ((ret = InitSelectGunShmMem()) == FAIL) {
+        return ret;
+    }
+
+    if ((ret = InitCommonShmMem()) == FAIL) {
+        return ret;
+    }
     //ClearAllShmMemParameter();
 
     //MappingChargingInfoData();

+ 2 - 0
EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.h

@@ -66,6 +66,8 @@ void MappingChargingInfoData(void);
 
 void *GetShmSelectGunInfo(void);
 
+void *GetShmDcCommonInfo(void);
+
 
 int InitSelectGunShmMem(void);
 #endif /* _CSU_SHARE_MEMORY_H_ */

+ 356 - 282
EVSE/Projects/DD360Audi/Apps/main.c

@@ -306,6 +306,7 @@ static void checkGunOTPState(uint8_t _index)
     case _Type_CCS_2:
         // CCS 不管甚麼輸出都會有槍溫偵測!!~
         if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            ResetChargerAlarmCode(_index, "011019");
             if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
                 RecordAlarmCode(_index, "012230");
             } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
@@ -313,7 +314,7 @@ static void checkGunOTPState(uint8_t _index)
                 ResetChargerAlarmCode(_index, "012230");
             }
 
-            ResetChargerAlarmCode(_index, "011019");
+            //ResetChargerAlarmCode(_index, "011019");
         } else {
             // 沒接上 Sensor or 異常
             RecordAlarmCode(_index, "011019");
@@ -1333,19 +1334,19 @@ int isRouteFail()
     return result;
 }
 
-static void eth0Down(void)
-{
-    char cmdbuf[256] = {0};
-
-    sprintf(cmdbuf, "/sbin/ifconfig eth0 down");
-}
-
-static void eth0Up(void)
-{
-    char cmdbuf[256] = {0};
+//static void eth0Down(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 down");
+//}
 
-    sprintf(cmdbuf, "/sbin/ifconfig eth0 %s up", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
-}
+//static void eth0Up(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 %s up", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
+//}
 
 int isReachableInternet()
 {
@@ -1834,6 +1835,13 @@ void InitialShareMemoryInfo()
 
     InitialGunIndexToUnUse();//DS60-120 add
 
+    //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
+    //ShmDcCommonData->psuKeepCommunication = NO;
+    //ShmDcCommonData->acContactSwitch = NO;
+    ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
+    ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
+    //ShmDcCommonData->LcmFwVersion = 0;
+
     ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
     ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
 
@@ -2600,30 +2608,39 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
 
 void RecordAlarmCode(uint8_t gunIndex, char *code)
 {
-    strncpy((char *)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; }
-
-    if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES; }
-    if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES; }
-    if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES; }
-    if (strcmp(code, "012296") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES; }
-    if (strcmp(code, "012297") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES; }
-    if (strcmp(code, "012298") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES; }
-    if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES; }
-    if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES; }
-    if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES; }
-    if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES; }
-    if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES; }
-    if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES; }
-    if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
-    if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
-    if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL) {
+        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; }
+
+    if (strcmp(code, "012234") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES; }
+    else if (strcmp(code, "012235") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES; }
+    else if (strcmp(code, "012236") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES; }
+    else if (strcmp(code, "012288") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES; }
+    else if (strcmp(code, "012289") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES; }
+    else if (strcmp(code, "012290") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES; }
+
+    else if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES; }
+    else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES; }
+    else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES; }
+    else if (strcmp(code, "012296") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES; }
+    else if (strcmp(code, "012297") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES; }
+    else if (strcmp(code, "012298") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES; }
+    else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES; }
+    else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES; }
+    else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES; }
+    else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES; }
+    else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES; }
+    else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES; }
+    else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
 }
 
 void RecordWarningCode(uint8_t gunIndex, char *code)
@@ -2637,6 +2654,7 @@ void RecordWarningCode(uint8_t gunIndex, char *code)
 
 void ReleaseAlarmCode(uint8_t gunIndex)
 {
+#if 0
     bool isCleanCheck = false;
     char code[7];
 
@@ -2715,6 +2733,59 @@ void ReleaseAlarmCode(uint8_t gunIndex)
             }
         }
     }
+#endif //0
+
+    // 回 idle 後主要清除  GFD Trip、UVP、OVP、GFD Warning
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL) {
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+        }
+    }
+
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    }
 
     if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
             strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
@@ -2863,16 +2934,20 @@ void ReleaseEmsOccureByString(uint8_t index, char *code)
 
     if (strncmp(code, "042251", 6) == 0 ) {
         isTrigger = true;
-    } else if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
+    } 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) {
+    } 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) {
+    } 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) {
+    } else if (strncmp(code, "012238", 6) == 0 &&
+               ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
         isTrigger = true;
         ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
     }
@@ -3126,6 +3201,7 @@ void ChkPrimaryStatus()
 //===============================================
 void CheckErrorOccurStatus(uint8_t index)
 {
+#if 0
     // 小板
     if (chargingInfo[index]->Type == _Type_Chademo) {
         if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
@@ -3146,6 +3222,7 @@ void CheckErrorOccurStatus(uint8_t index)
 //      else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
 //          BoardErrOccurByString(index, "012235");
     }
+#endif //0
 
     // RB
     if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
@@ -3217,31 +3294,31 @@ void CheckErrorOccurStatus(uint8_t index)
     }
 
     //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 (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((char *)chargingInfo[index]->ConnectorAlarmCode) == 0) {
@@ -4017,6 +4094,7 @@ int CheckUpdateProcess(void)
     uint8_t retFail = 0;
     uint8_t index = 0;
     uint8_t target = 0;
+    char Buf[256];
     char *new_str = NULL;
     uint8_t *ptr = NULL;
     int fd = 0;
@@ -4083,14 +4161,41 @@ int CheckUpdateProcess(void)
                 case 0x10000008:
                 case 0x10000009:
                 case 0x1000000A:
+                    CanFd = InitCanBus();
+                    if (CanFd > 0) {
+                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
+                            if (chargingInfo[index]->Type == _Type_CCS_2) {
+                                uint8_t targetID = chargingInfo[index]->Evboard_id;
+
+                                if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1 &&
+                                        ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
+                                    targetID += 1;
+                                }
+
+                                system("echo 3 > /proc/sys/vm/drop_caches");
+                                sleep(2);
+                                log_info("Upgrade CCS Processing..target id = %d \n", targetID);
+                                if (Upgrade_CCS(CanFd, Type, targetID, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL) {
+                                    log_info("Upgrade CCS Failed \n");
+                                    retFail++;
+                                } else {
+                                    retSucc++;
+                                }
+                            }
+                        }
+                        close(CanFd);
+                    }
+                    memset(Buf, 0, sizeof(Buf));
+                    sprintf(Buf, "rm -rvf /mnt/%s", new_str);
+                    system(Buf);
                     //isPass = true;
+#if 0
                     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;
@@ -4111,6 +4216,7 @@ int CheckUpdateProcess(void)
                         retSucc++;
                     }
                     //return isPass;
+#endif //0
                     break;
 
                 case 0x10000006:
@@ -5634,35 +5740,14 @@ void TheEndCharging(uint8_t gun_index)
 
 void UpdateErrorCodeToOcpp(uint8_t 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) {
+        //if (strlen((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) {
+        //} else if (strlen((char *)chargingInfo[index]->EvConnAlarmCode) == EQUAL) {
         strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
         strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->EvConnAlarmCode);
     }
@@ -5691,45 +5776,100 @@ void AdjustChargerCurrent()
              );
 }
 
-#if METER_ENABLE
-void CheckStatusOfMeter()
+void ResetDetAlarmStatus(uint8_t gun)
 {
-    // 橋接如果搭上~ 則兩個電表都是使用狀態
-    // 如橋接沒有搭上~ 則視該火線 relay 狀態為電表使用狀態
-    if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
-        for (uint8_t mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++) {
-            ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
+    if (chargingInfo[gun]->Type == _Type_Chademo) {
+        if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
         }
-    } else {
-        for (uint8_t 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;
-            }
+    } 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;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    return;
+#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
+
+    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
+    return ;
+#endif //!defined DD360ComBox
+
+    if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
+            (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
+       ) {
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
+        strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
+    }
+}
+
+static bool PrecheckIsPass(uint8_t gun_index)
+{
+    bool result = true;
+
+    // relay welding or driving 是反向
+    result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
+
+    return result;
+}
+
+static void ReviewCriticalAlarm(void)
+{
+    if (ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
+            ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
+            ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
+            ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
+            ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm ||
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo
+       ) {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = 2;
+    } else {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
     }
 }
 
-void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
+static void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
 {
     // relay welding fault then stop the charging process.
     uint8_t 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) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[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) {
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[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) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[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) {
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
             faultCode = RELAY_STATUS_ERROR_DRIVING;
         }
     }
@@ -5737,11 +5877,11 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
     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) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[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) {
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
             faultCode = RELAY_STATUS_ERROR_DRIVING;
         }
     }
@@ -5749,11 +5889,11 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
     if (faultCode == RELAY_STATUS_ERROR_WELDING) {
         // welding
         if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
+            RecordAlarmCode(gun_index, "011011");
         } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
+            RecordAlarmCode(gun_index, "011015");
         } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
+            RecordAlarmCode(gun_index, "011013");
         }
 
         ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
@@ -5761,11 +5901,11 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
     } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
         // driving
         if (chargingInfo[gun_index]->Type == _Type_Chademo) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
+            RecordAlarmCode(gun_index, "011012");
         } else if (chargingInfo[gun_index]->Type == _Type_GB) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
+            RecordAlarmCode(gun_index, "011016");
         } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
+            RecordAlarmCode(gun_index, "011014");
         }
 
         ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
@@ -5774,105 +5914,19 @@ void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
         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(uint8_t gun_index)
-{
-    bool result = true;
-
-    // relay welding or driving 是反向
-    if (result) {
-        result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
-    }
-
-    return result;
-}
-#endif //METER_ENABLE
-
-void ResetDetAlarmStatus(uint8_t 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;
-
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-    return;
-#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
-
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
-        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == 0) {
-            EmcOccureByString("042267");
+        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
+            ResetChargerAlarmCode(gun_index, "011012");
+            ResetChargerAlarmCode(gun_index, "011011");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            ResetChargerAlarmCode(gun_index, "011014");
+            ResetChargerAlarmCode(gun_index, "011013");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            ResetChargerAlarmCode(gun_index, "011016");
+            ResetChargerAlarmCode(gun_index, "011015");
         }
     }
 }
 
-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;
@@ -6042,16 +6096,23 @@ int main(void)
             gettimeofday(&_cmdMainPriority_time, NULL);
         }
 
+        // 確認當前錯誤 Level = 2 ?
+        ReviewCriticalAlarm();
         gEvBoardErr.GunErrMessage = 0;
 
         for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
             autoStartChargingForComBox(gun_index); //for DD360ComBox
 
+            CheckGpioInStatus();
+
+            CheckErrorOccurStatus(gun_index);
+
+            // 確認 Relay Welding or Driving Fault
+            CheckRelayWeldingOrDrivingFault(gun_index);
+
             // 收集各槍的錯誤狀態
             collectError(gun_index);
 
-            CheckGpioInStatus();
-            CheckErrorOccurStatus(gun_index);
             ChkOcppStatus(gun_index);
 
             if ((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
@@ -6171,84 +6232,97 @@ int main(void)
                         ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
                     }
 
-                    if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
-                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
+                    if (PrecheckIsPass(gun_index)) {
+
+                        if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+                            setChargerMode(gun_index, MODE_IDLE);
+                        }
+
+                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
+                            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
 #if defined DD360Audi
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
+                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
 #else
-                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
+                                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) {
-                                    log_info("-----------------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
+                            }
+                        } else {
+                            // Idle 正常程序起點
+                            // 判斷是否有啟用檢查插槍
+                            if (isDetectPlugin()) {
+                                // 卡號驗證成功後,等待充電槍插入充電車
+                                if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
+                                    if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
+                                            chargingInfo[gun_index]->IsAvailable) {
+                                        log_info("-----------------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)
+                                            && (waitRightGunPlugIt(gun_index) == PASS ||
+                                                waitLeftGunPlugIt(gun_index) == PASS)
 #endif //defined DD360Audi
-                                   ) {
-                                    log_info("-----------------2----------------- \n");
+                                       ) {
+                                        log_info("-----------------2----------------- \n");
+                                        ChangeGunSelectByIndex(gun_index);
+                                        AddPlugInTimes(gun_index);
+                                        strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+                                        log_info("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)) {
+                                log_info("-----------------3----------------- \n");
+                                bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
+
+                                if (isCanStartChargingFlag) {
                                     ChangeGunSelectByIndex(gun_index);
                                     AddPlugInTimes(gun_index);
-                                    strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-                                    log_info("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)) {
-                            log_info("-----------------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) {
+                            } else {
+                                if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
 #if defined DD360Audi
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
+                                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
 #else
-                                ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
+                                    ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
 #endif // defined DD360Audi
+                                }
                             }
+                        } // Idle 正常程序終點
+                    } else {
+                        setChargerMode(gun_index, MODE_FAULT);
+                        if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
                         }
-                    } // Idle 正常程序終點
+                    }// PrecheckIsPass()
                 }
             }
             break;

+ 15 - 0
EVSE/Projects/DD360Audi/Apps/main.h

@@ -60,4 +60,19 @@ typedef struct StLedConfig {
     uint8_t Reserved: 1;                        //bit 7 reserved
 } LedConfig;
 
+//------------------------------------------------------------------------------
+bool isDetectPlugin();
+void _DetectPlugInTimeout();
+void StopSystemTimeoutDet();
+
+void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag);
+void StopGunInfoTimeoutDet(uint8_t gunIndex);
+
+void ClearAuthorizedFlag();
+
+void ChargingAlarmProcess(uint8_t gunIndex);
+void StopChargingProcessByString(uint8_t level);
+
+void AcChargingTerminalProcess();
+
 #endif /* _MAIN_H_ */

+ 7009 - 0
EVSE/Projects/DD360Audi/Apps/mainNew.c

@@ -0,0 +1,7009 @@
+#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/define.h"
+#include <stdbool.h>
+#include <dirent.h>
+
+#include "Config.h"
+#include "main.h"
+#include "common.h"
+#include "timeout.h"
+
+#include "./Log/log.h"
+
+#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+#include "./SelectGun/SelectGun.h"
+#endif //defined DD360Audi
+
+//------------------------------------------------------------------------------
+char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
+uint8_t mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+int whileLoopTime = 10000; // 10 ms
+int wtdFd = -1;
+uint8_t _authorizeIndex = NO_DEFINE;
+
+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;
+DcCommonInfo                    *ShmDcCommonData;
+
+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 SelectGunInfo             *gAudiCustInfo = NULL; //Jerry add
+#endif //defined DD360Audi
+
+// for initial index to check EV board type is correct
+uint8_t _gunIndex = 0;
+uint8_t _acgunIndex = 0;
+uint8_t _chademoIndex = 0;
+uint8_t _ccsIndex = 0;
+uint8_t _gb_Index = 0;
+uint8_t _ac_Index = 0;
+uint8_t bd0_1_status = 0;
+uint8_t bd0_2_status = 0;
+uint8_t bd1_1_status = 0;
+uint8_t 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.08.00.0000.00"; // "V0.16.00.0000.00";
+
+sqlite3 *localDb;
+bool isDb_ready;
+
+EvBoardErrMsg gEvBoardErr = {0};
+
+//------------------------------------------------------------------------------
+bool IsAuthorizingMode();
+void ClearAuthorizedFlag();
+void ClearDetectPluginFlag();
+
+long long DiffTimebWithNow(struct timeb ST);
+uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
+void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
+void ChargingTerminalProcess(uint8_t gunIndex);
+void ChkPrimaryStatus();
+void StartSystemTimeoutDet(uint8_t flag);
+void StopSystemTimeoutDet();
+void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag);
+void StopGunInfoTimeoutDet(uint8_t 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 ChangeGunSelectByIndex(uint8_t sel);
+//void InformOcppErrOccur(uint8_t codeType);
+
+void RecordAlarmCode(uint8_t gunIndex, char *code);
+void RecordWarningCode(uint8_t gunIndex, char *code);
+void ReleaseWarningCodeByString(uint8_t gunIndex, char *code);
+void ReleaseAlarmCode(uint8_t gunIndex);
+void ResetChargerAlarmCode(uint8_t gunIndex, char *code);
+
+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);
+
+#if 0
+//------------------------------------------------------------------------------
+//--- 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;
+
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    //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 !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+static int waitLeftGunPlugIt(uint8_t curGun)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+        return PASS;
+    }
+
+    return FAIL;
+}
+
+static void setSelGunWaitToAuthor(uint8_t curSel)
+{
+#if !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    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 !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    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 !defined DD360Audi
+    return;
+#endif //!defined DD360Audi
+
+    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 //0
+
+static void checkGunOTPState(uint8_t _index)
+{
+    switch (chargingInfo[_index]->Type) {
+    case _Type_Chademo:
+        if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012229");
+            } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+                       chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012229");
+            }
+        } else {
+            // 沒接上 Sensor or 異常
+            //RecordAlarmCode(_index, "011018");
+            ResetChargerAlarmCode(_index, "012229");
+        }
+        break;
+
+    case _Type_CCS_2:
+        // CCS 不管甚麼輸出都會有槍溫偵測!!~
+        if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            ResetChargerAlarmCode(_index, "011019");
+            if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012230");
+            } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+                       chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012230");
+            }
+
+            //ResetChargerAlarmCode(_index, "011019");
+        } else {
+            // 沒接上 Sensor or 異常
+            RecordAlarmCode(_index, "011019");
+            ResetChargerAlarmCode(_index, "012230");
+        }
+        break;
+
+    case _Type_GB:
+        if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
+            if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
+                RecordAlarmCode(_index, "012231");
+            } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+                       chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
+                ResetChargerAlarmCode(_index, "012231");
+            }
+        } else {
+            // 沒接上 Sensor or 異常
+            RecordAlarmCode(_index, "011020");
+            ResetChargerAlarmCode(_index, "012231");
+        }
+        break;
+    }
+}
+
+static void collectError(uint8_t gunIndex)
+{
+    gEvBoardErr.GunErrMessage |= ShmDcCommonData->ConnectErrList[gunIndex].GunErrMessage;
+}
+
+static void checkGBTAlarmState(uint8_t gunType)
+{
+    // GFD Trip
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
+    }
+
+    // UVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
+    }
+
+    // OTP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = NO;
+    }
+
+    // OVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
+    }
+
+    // GFD Warning
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
+    }
+
+    // Relay Welding
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
+    }
+
+    // Relay Driving
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
+    }
+
+    // Connect temp Sensor broken
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = NO;
+    }
+}
+
+static void checkCCSAlarmState(uint8_t gunType)
+{
+    // GFD Trip
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
+    }
+
+    // UVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
+    }
+
+    // OTP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = NO;
+    }
+
+    // OVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
+    }
+
+    // GFD Warning
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
+    }
+
+    // Relay Welding
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
+    }
+
+    // Relay Driving
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
+    }
+
+    // Connect temp Sensor broken
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
+    }
+}
+
+static void checkChaDeMoAlarmState(uint8_t gunType)
+{
+    // GFD Trip
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
+    }
+
+    // UVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
+    }
+
+    // OTP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = NO;
+    }
+
+    // OVP
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
+    }
+
+    // GFD Warning
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
+    } else {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
+    }
+
+    // Relay Welding
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
+    }
+
+    // Relay Driving
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
+    }
+
+    // Connect temp Sensor broken
+    if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
+    } else {
+        ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
+    }
+}
+
+static void checkEvBoardAlarmState(uint8_t gunType)
+{
+    switch (gunType) {
+    case _Type_Chademo:
+        checkChaDeMoAlarmState(gunType);
+        break;
+
+    case _Type_CCS_2:
+        checkCCSAlarmState(gunType);
+        break;
+
+    case _Type_GB:
+        checkGBTAlarmState(gunType);
+        break;
+    }
+}
+
+static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
+{
+    uint8_t ret = NO;
+    LedConfig *pLedConfig = (LedConfig *)ledConfig;
+
+    if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
+        ret = YES;
+        if (pLedConfig->RedLED == YES) {
+            pLedConfig->RedLED = NO;
+        } else {
+            pLedConfig->RedLED = YES;
+        }
+    }
+
+    return ret;
+}
+
+static void startPrimaryLedIndicatorCtrlFork(void)
+{
+#if !defined DD360ComBox
+    return;
+#endif //!defined DD360ComBox
+
+    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) {
+                        //Module_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:
+                    //Module_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:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+
+                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                        break;
+                    }
+
+                    pLedConfig->RedLED = YES;
+                    break;
+
+                case S_TERMINATING:
+                case S_COMPLETE:
+                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                        pLedConfig->YellowLED = NO;
+                        pLedConfig->GreenLED = NO;
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        pLedConfig->RedLED = YES;
+                    } else {
+                        pLedConfig->RedLED = NO;
+                        pLedConfig->YellowLED = YES;
+                        pLedConfig->GreenLED = NO;
+                    }
+                    break;
+
+                case S_MAINTAIN:
+                case S_FAULT:
+                    pLedConfig->YellowLED = NO;
+                    pLedConfig->GreenLED = NO;
+                    if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
+                        if (checkCabinetEthConnectState(pLedConfig) == YES) {
+                            break;
+                        }
+
+                        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(uint8_t 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] = (uint8_t)1;
+    tios.c_lflag = 0;
+    tcflush(fd, TCIFLUSH);
+    ioctl (fd, TCSETS, &tios);
+
+    return fd;
+}
+
+//=================================
+// Common routine
+//=================================
+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;
+}
+
+#if 0
+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;
+}
+#endif //0
+
+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 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(uint8_t gun_index, uint8_t mode)
+{
+    chargingInfo[gun_index]->SystemStatus = mode;
+}
+
+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) {
+        log_info("Connector 1 : Chademo");
+    } else if (bd0_1_status == 1 && bd0_2_status == 0) {
+        log_info("Connector 1 : CCS");
+    } else if (bd0_1_status == 1 && bd0_2_status == 1) {
+        log_info("Connector 1 : GB");
+    }
+
+    if (bd1_1_status == 0 && bd1_2_status == 1) {
+        log_info("Connector 2 : Chademo");
+    } else if (bd1_1_status == 1 && bd1_2_status == 0) {
+        log_info("Connector 2 : CCS");
+    } else if (bd1_1_status == 1 && bd1_2_status == 1) {
+        log_info("Connector 2 : GB");
+    }
+}
+
+void CheckHwSlotStatusLog(uint8_t index)
+{
+    if (chargingInfo[index]->Type == _Type_Chademo) {
+        log_info("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
+                 index, chargingInfo[index]->Evboard_id);
+    } else if (chargingInfo[index]->Type == _Type_CCS_2) {
+        log_info("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
+                 index, chargingInfo[index]->Evboard_id);
+    } else if (chargingInfo[index]->Type == _Type_GB) {
+        log_info("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()
+{
+    uint8_t rebootCount = 0;
+
+    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(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
+        return FAIL;
+    } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        return FAIL;
+    }
+    memset(gAudiCustInfo, 0, sizeof(SelectGunInfo));
+#endif //defined DD360Audi
+
+    if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
+        return FAIL;
+    } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        return FAIL;
+    }
+
+    if (ShmDcCommonData->RebootCount == 1) {
+        rebootCount = ShmDcCommonData->RebootCount;
+    }
+    memset(ShmDcCommonData, 0, sizeof(DcCommonInfo));
+
+    ShmDcCommonData->RebootCount = rebootCount;
+
+    return PASS;
+}
+
+//=================================
+// LCM Page
+//=================================
+void ChangeLcmByIndex(uint8_t 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;
+    uint8_t *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;
+}
+
+//static void eth0Down(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 down");
+//}
+
+//static void eth0Up(void)
+//{
+//    char cmdbuf[256] = {0};
+//
+//    sprintf(cmdbuf, "/sbin/ifconfig eth0 %s up", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
+//}
+
+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()) {
+                //log_info("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] = (uint8_t) 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 (uint8_t 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);
+
+    uint8_t 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 (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
+        ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
+    }
+
+    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
+        ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
+    }
+
+    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
+        ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
+    }
+
+    for (uint8_t 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
+
+    ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
+    ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
+
+    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 (uint8_t 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 (uint8_t 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");
+        }
+    }
+
+    //log_info("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 (uint8_t 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 (uint8_t 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 (uint8_t 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 {
+                                //log_info("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 {
+                                //log_info("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 (uint8_t 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/Module_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;
+    uint8_t *ptr, *BufTmp;
+
+    Chk = 0;
+    ptr = (uint8_t *)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(uint8_t gunIndex)
+{
+    //printf("StopChargeFlag = %d\r\n", chargingInfo[gunIndex]->StopChargeFlag);
+    return chargingInfo[gunIndex]->StopChargeFlag;
+}
+
+bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
+{
+    return chargingInfo[gunIndex]->NormalStopChargeFlag;
+}
+
+//===============================================
+// 掃描插槍狀況
+//===============================================
+void ClearDetectPluginFlag()
+{
+    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+
+    //DS60-120 add
+    for (uint8_t 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(uint8_t gunIndex)
+{
+    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
+}
+
+bool isEvContactorWelding_chademo(uint8_t gunIndex)
+{
+    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
+}
+
+bool isEvStopReq_chademo(uint8_t gunIndex)
+{
+    return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
+}
+
+bool isEvStopCharging_chademo(uint8_t gunIndex)
+{
+    if (isEvGunLocked_chademo(gunIndex) == NO) {
+        // 無鎖槍 = 停止
+        log_info("gun locked none (%d) \n", gunIndex);
+        return YES;
+    }
+
+    return NO;
+}
+
+uint8_t isPrechargeStatus_chademo(uint8_t gunIndex)
+{
+    uint8_t result = 0x00;
+
+    result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+    return result;
+}
+//===============================================
+// Common Detect Chk - GB
+//===============================================
+bool isEvGunLocked_gb(uint8_t gunIndex)
+{
+    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
+}
+
+bool isEvStopCharging_gb(uint8_t gunIndex)
+{
+    if (isEvGunLocked_gb(gunIndex) == NO) {
+        // 無鎖槍 = 停止
+        log_info("gun locked none. \n");
+        return YES;
+    }
+
+    return NO;
+}
+
+uint8_t isPrechargeStatus_gb(uint8_t gunIndex)
+{
+    uint8_t result = 0x00;
+
+    result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+    return result;
+}
+
+//===============================================
+// Common Detect Chk - CCS
+//===============================================
+bool isEvGunLocked_ccs(uint8_t gunIndex)
+{
+    return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
+}
+
+uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
+{
+    uint8_t result = 0x00;
+
+    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+        result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+    }
+
+    return result;
+}
+
+bool isEvStopCharging_ccs(uint8_t gunIndex)
+{
+    if (isEvGunLocked_ccs(gunIndex) == NO) {
+        // 無鎖槍 = 停止
+        log_info("gun locked none. \n");
+        return YES;
+    }
+
+    return NO;
+}
+
+//===============================================
+// Callback
+//===============================================
+void DisplayChargingInfo()
+{
+    log_info("*********** DisplayChargingInfo *********** \n");
+    for (uint8_t 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()
+{
+    log_info("*********** _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 (uint8_t 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;
+    log_info("Self test timeout. \n");
+}
+
+void _AuthorizedTimeout()
+{
+    if (IsAuthorizingMode()) {
+        log_info("*********** _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()
+{
+    log_info("*********** _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(uint8_t gunIndex)
+{
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        if (!isEvGunLocked_chademo(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        if (!isEvGunLocked_ccs(gunIndex)) {
+            log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
+        }
+    }
+    ChargingTerminalProcess(gunIndex);
+    _AutoReturnTimeout();
+}
+
+void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
+    //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
+    {
+        setChargerMode(gunIndex, MODE_IDLE);
+        _AutoReturnTimeout();
+    }
+}
+
+void _PrepareTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _PrepareTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
+    _AutoReturnTimeout();
+}
+
+void _CcsPrechargeTimeout(uint8_t gunIndex)
+{
+    log_info("*********** _CcsPrechargeTimeout ***********\n");
+    setChargerMode(gunIndex, MODE_IDLE);
+}
+
+//===============================================
+// 取得卡號與卡號驗證
+//===============================================
+bool canStartCharging()
+{
+    char buf2[16] = "";
+    memset(buf2, 0, ARRAY_SIZE(buf2));
+
+    for (uint8_t 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 ResetChargerAlarmCode(uint8_t gunIndex, char *code)
+{
+    if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO; }
+    else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO; }
+    else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO; }
+    else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO; }
+    else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO; }
+    else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO; }
+    else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO; }
+    else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO; }
+    else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO; }
+    else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO; }
+    else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO; }
+    else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO; }
+
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012229", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012230", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012231", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011011", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011013", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011015", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011012", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011014", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011016", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011018", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011019", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL) {
+            strncpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+        }
+    }
+}
+
+void RecordAlarmCode(uint8_t gunIndex, char *code)
+{
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL) {
+        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; }
+
+    if (strcmp(code, "012234") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES; }
+    else if (strcmp(code, "012235") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES; }
+    else if (strcmp(code, "012236") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES; }
+    else if (strcmp(code, "012288") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES; }
+    else if (strcmp(code, "012289") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES; }
+    else if (strcmp(code, "012290") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES; }
+
+    else if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES; }
+    else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES; }
+    else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES; }
+    else if (strcmp(code, "012296") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES; }
+    else if (strcmp(code, "012297") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES; }
+    else if (strcmp(code, "012298") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES; }
+    else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES; }
+    else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES; }
+    else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES; }
+    else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES; }
+    else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES; }
+    else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES; }
+    else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
+    else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
+}
+
+void RecordWarningCode(uint8_t 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(uint8_t gunIndex)
+{
+#if 0
+    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 (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
+            memcpy(code, "012217", 6);
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    } 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 (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
+            memcpy(code, "012221", 6);
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    } 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");
+        } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
+            memcpy(code, "012219", 6);
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            isCleanCheck = true;
+        }
+    }
+
+    if (isCleanCheck) {
+        for (uint8_t 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, "012217", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = 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, "012221", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = 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(code, "012219", 6) == EQUAL) {ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;}
+                }
+            }
+        }
+    }
+#endif //0
+
+    // 回 idle 後主要清除  GFD Trip、UVP、OVP、GFD Warning
+    if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
+                strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL) {
+            memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+        }
+    }
+
+    if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
+        ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
+
+        if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
+            if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
+                    strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL) {
+                memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+            }
+        }
+    }
+
+    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(uint8_t 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 (uint8_t 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(uint8_t gunIndex)
+{
+    setChargerMode(gunIndex, MODE_TERMINATING);
+}
+
+void ChargingAlarmProcess(uint8_t gunIndex)
+{
+    setChargerMode(gunIndex, MODE_ALARM);
+}
+
+void AcChargingTerminalProcess()
+{
+    ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
+}
+
+void StopChargingProcessByString(uint8_t level)
+{
+    if (level > ShmSysConfigAndInfo->SysWarningInfo.Level) {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = level;
+    }
+}
+
+void ReleaseChargingProcessByString(uint8_t level)
+{
+    if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level) {
+        ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
+    }
+}
+
+// 一般錯誤停止充電處理函式
+void BoardErrOccurByString(uint8_t index, char *code)
+{
+    uint8_t 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);
+}
+
+#if 0
+// 急停狀況的停止充電處理函式
+void EmcOccureByString(char *code)
+{
+    uint8_t 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 (uint8_t 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
+    }
+}
+#endif //0
+
+void ReleaseBoardErrOccurByString(uint8_t index, char *code)
+{
+    bool isTrigger = false;
+    uint8_t 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);
+    }
+}
+
+#if 0
+void ReleaseEmsOccureByString(uint8_t index, char *code)
+{
+    bool isTrigger = false;
+    uint8_t 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);
+    }
+}
+#endif //0
+
+#if 0
+//===============================================
+// 確認硬體 (按鈕) 狀態
+//===============================================
+bool leftBtnPush = false;
+bool rightBtnPush = false;
+
+void ChkPrimaryStatus()
+{
+    uint8_t Rtn;
+
+    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
+        Rtn = 0;
+        for (uint8_t 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;
+            log_info("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();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+#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);
+                        log_info("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.StopChargingByButton == YES ||
+                        ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
+                    // 停止充電
+                    ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+            }
+            break;
+            case S_COMPLETE: {
+                // 回 IDLE
+                //log_info("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;
+            //log_info("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;
+            //log_info("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 (uint8_t _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);
+            }
+        }
+        log_info("current select gun ............................... %d \n",
+                 ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
+        if (rightBtnPush) {
+            rightBtnPush = false;
+            //log_info("right btn up............................... \n");
+        }
+    }
+}
+#endif //0
+
+//===============================================
+// 確認各小板偵測的錯誤狀況
+//===============================================
+void CheckErrorOccurStatus(uint8_t 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((char *)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;
+    uint8_t 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
+//===============================================
+// 檢查 uint8_t 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit)
+{
+    return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+// 設定 Byte 中某個 Bit的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+// value : 修改的值為 0 or 1
+void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value)
+{
+    if (value == 1) {
+        *_byte |= (1 << _bit);
+    } else if (value == 0) {
+        *_byte ^= (1 << _bit);
+    }
+}
+
+void UserScanFunction()
+{
+    bool idleReq = false;
+    uint8_t 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 (uint8_t 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];
+
+                log_info("ac stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
+                         ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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];
+
+                log_info("stop charging \n");
+                log_info("index = %d, card number = %s, UserId = %s \n",
+                         ShmSysConfigAndInfo->SysInfo.CurGunSelected,
+                         chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
+                         ShmSysConfigAndInfo->SysConfig.UserId);
+                memcpy(value, (uint8_t *)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) {
+                    log_info("// 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;
+                    }
+                }
+            }
+        }
+    }
+}
+
+uint8_t isModeChange(uint8_t gun_index)
+{
+    uint8_t 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
+#else
+                && gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance != FAIL_BALANCE_PRICES
+#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(uint8_t typeValue, uint8_t 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;
+
+
+    //log_info("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");
+        uint8_t slots = 1;
+        for (uint8_t 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 (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "0", 1) != 0) {
+                //    if (bd0_1_status == 1 || bd0_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x01;
+                //    } else if (bd1_1_status == 1 || bd1_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x02;
+                //    }
+                //} else if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "0", 1) != 0) {
+                //    if (bd0_1_status == 1 || bd0_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x01;
+                //    } else if (bd1_1_status == 1 || bd1_2_status == 1) {
+                //        chargingInfo[0]->Evboard_id = 0x02;
+                //    }
+                //} else {
+                //    chargingInfo[0]->Evboard_id = 0x01;
+                //}
+
+                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 (uint8_t 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 Module_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 Module_DoComm");
+#endif //!defined DD360 && !defined DD360Audi
+}
+
+int CheckUpdateProcess(void)
+{
+    //bool isPass = true;
+    uint8_t retSucc = 0;
+    uint8_t retFail = 0;
+    uint8_t index = 0;
+    uint8_t target = 0;
+    char *new_str = NULL;
+    uint8_t *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 (uint8_t i = 0; i < 16; i++) {
+                if (ShmSysConfigAndInfo->SysConfig.ModelName[i] != ptr[i]) {
+                    return FAIL;
+                }
+            }
+
+            log_info("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]));
+                log_info("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 {
+                        log_info("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;
+                                    log_info("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 {
+                        log_info("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 {
+                                    log_info("Upgrade %x Failed\r\n", Type);
+                                    //isPass = FAIL;
+                                    retFail++;
+                                }
+                            }
+                        }
+                    } else {
+                        log_info("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(uint8_t 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(uint8_t gunIndex, uint8_t flag)
+{
+    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+        if (chargingInfo[gunIndex]->TimeoutFlag != flag) {
+            gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
+        }
+        chargingInfo[gunIndex]->TimeoutFlag = flag;
+    }
+}
+
+void StopGunInfoTimeoutDet(uint8_t gunIndex)
+{
+    if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+        chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
+    }
+}
+
+void CheckConnectionTimeout(void)
+{
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
+        _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
+    } else {
+        _connectionTimeout = CONN_PLUG_TIME_OUT;
+    }
+
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+    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;
+        }
+    }
+}
+
+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();
+                    destroySelGun(DESTROY_ALL_SEL); //jerry add
+                }
+                break;
+
+            case Timeout_Authorizing:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
+                    _AuthorizedTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                break;
+
+            case Timeout_VerifyFail:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                    _AutoReturnTimeout();
+                    StopSystemTimeoutDet();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                    if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
+                        gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
+                        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
+                        log_error("Author timeout restart DoComm\r\n");
+                        system("killall Module_DoComm");
+                        sleep(1);
+                        system("/root/Module_DoComm &");
+                    }
+                }
+                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();
+                    destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+                }
+                break;
+
+            case Timeout_ReturnToChargingGunDet:
+                if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
+#if defined DD360Audi
+                    if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_PRE_CHARGE &&
+                            ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_CHARGING &&
+                            ShmSysConfigAndInfo->SysInfo.SystemPage != _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 (uint8_t 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);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
+                        _DetectEvChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseChargingDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
+                        _DetectEvseChargingEnableTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_EvseCompleteDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                case Timeout_ForCcsPrechargeDet:
+                    if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
+                        _CcsPrechargeTimeout(gun_index);
+                        StopGunInfoTimeoutDet(gun_index);
+                        destroySelGun(gun_index); //jerry add
+                    }
+                    break;
+
+                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;
+                }
+            }
+            sleep(1);
+        }
+    }
+}
+
+void GetSystemTime()
+{
+    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);
+
+//  uint8_t 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;
+
+//  log_info("%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()
+{
+    //log_info("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
+    if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
+        log_info("ftp : update start. \n");
+        for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            setChargerMode(gun_index, MODE_UPDATE);
+        }
+
+        uint8_t 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 (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
+                setChargerMode(_index, MODE_UPDATE);
+            }
+            for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
+                ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
+            }
+
+            uint8_t 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(uint8_t 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(void)
+{
+    bool canReset = true;
+    //bool canHardReset = true; //DS60-120 add
+
+    if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
+        ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
+    }
+
+    if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
+        if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
+            for (uint8_t _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(uint8_t gunIndex)
+{
+    uint8_t _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);
+    }
+
+    log_info("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
+}
+
+void OcppStopTransation(uint8_t gunIndex)
+{
+    uint8_t _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);
+    }
+
+    log_info("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
+    ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
+}
+
+bool OcppRemoteStop(uint8_t gunIndex)
+{
+    uint8_t 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(uint8_t 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
+        uint8_t acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+        for (uint8_t 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;
+            }
+        }
+
+        uint8_t threeGunIndex = 0;
+        uint8_t dcIndex = 0;
+        bool isGunUsingStatus = false;
+
+        for (uint8_t _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(uint8_t gunIndex)
+{
+    if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+            ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
+        ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+        if (isReservationExpired(gunIndex)) {
+            log_info("***************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)) {
+            log_info("***************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) {
+        log_info("***************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(uint8_t 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(uint8_t 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(uint8_t 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 (uint8_t 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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+
+        if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local charging record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local charging record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local config table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local config table successfully\n");
+        }
+
+        //DS60-120
+        if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create local record table error message: %s\n", errMsg);
+        } else {
+            log_info( "Opened local record table successfully\n");
+        }
+
+        if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Create reboot record table error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\r\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert local charging record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete local charging error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
+
+        //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
+        sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
+        log_info("sqlStr= %s\r\n", sqlStr);
+        if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "update config error message: %s\n", errMsg);
+        } else {
+            log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+        }
+
+        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;
+        log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "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;
+                }
+                log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
+            }
+        } else {
+            log_info("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;
+        log_info( "Can't open database: %s\n", sqlite3_errmsg(db));
+        sqlite3_close(db);
+    } else {
+        log_info( "Local charging record database open successfully.\n");
+        if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info( "Insert reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "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;
+            log_info( "delete reboot record error message: %s\n", errMsg);
+        } else {
+            log_info( "delete reboot record successfully\n");
+        }
+
+        sqlite3_close(db);
+    }
+
+    return result;
+}
+
+//===============================================
+// Config process
+//===============================================
+void AddPlugInTimes(uint8_t 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(uint8_t isStart, uint8_t 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);
+//      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);
+
+        // 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);
+                        log_info("zip = %s \n", file);
+                        system(file);
+                    }
+                }
+            }
+        }
+    }
+    // Close folder
+    closedir(pDir);
+}
+
+void ChangeGunSelectByIndex(uint8_t 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) {
+                log_info("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 (uint8_t count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
+        if (chargingInfo[count]->SystemStatus != S_IDLE &&
+                chargingInfo[count]->SystemStatus != S_RESERVATION) {
+            result = false;
+            break;
+        }
+    }
+
+    for (uint8_t 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(uint8_t *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(uint8_t _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);
+            uint8_t _startCount = NO_DEFINE;
+            uint8_t _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
+
+            for (uint8_t _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;
+                    }
+                }
+            }
+
+            log_info("_startCount = %d \n", _startCount);
+            if (_startCount < _maxCount) {
+                //DS60-120 add
+                log_info("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
+                //log_info("*********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;
+        }
+
+        log_info("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
+        log_info("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(uint8_t _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 (uint8_t 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(uint8_t _gun)
+{
+    bool result = true;
+
+    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
+            ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
+        for (uint8_t _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(uint8_t 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(uint8_t 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) {
+        //if (strlen((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) {
+        //} else if (strlen((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;
+    }
+
+    log_info ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
+              ShmPsuData->SystemAvailablePower / 10,
+              ShmPsuData->SystemAvailableCurrent / 10
+             );
+
+    log_info ("Config : ChargingPower = %d, ChargingCurrent = %d",
+              ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+              ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
+             );
+}
+
+void ResetDetAlarmStatus(uint8_t 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;
+
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    return;
+#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
+
+    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
+    return ;
+#endif //!defined DD360ComBox
+
+    if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
+            (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
+       ) {
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
+        strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
+    }
+}
+
+static bool PrecheckIsPass(uint8_t gun_index)
+{
+    bool result = false;
+
+    // relay welding or driving 是反向
+    result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
+
+    return result;
+}
+
+static void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
+{
+    // relay welding fault then stop the charging process.
+    uint8_t faultCode = RELAY_STATUS_ERROR_NONE;
+
+    if (gun_index == 0) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
+            faultCode = RELAY_STATUS_ERROR_WELDING;
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
+            faultCode = RELAY_STATUS_ERROR_DRIVING;
+        }
+    } else if (gun_index == 1) {
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
+            faultCode = RELAY_STATUS_ERROR_WELDING;
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
+            faultCode = RELAY_STATUS_ERROR_DRIVING;
+        }
+    }
+
+    if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
+            !ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
+        // 橋接
+        if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+                ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
+            faultCode = RELAY_STATUS_ERROR_WELDING;
+        } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+                   ShmDcCommonData->CheckRelayStatus[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) {
+            RecordAlarmCode(gun_index, "011011");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            RecordAlarmCode(gun_index, "011015");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            RecordAlarmCode(gun_index, "011013");
+        }
+
+        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
+        EmcOccureByString("");
+    } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
+        // driving
+        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
+            RecordAlarmCode(gun_index, "011012");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            RecordAlarmCode(gun_index, "011016");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            RecordAlarmCode(gun_index, "011014");
+        }
+
+        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
+        EmcOccureByString("");
+    } else {
+        ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
+        ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
+
+        if (chargingInfo[gun_index]->Type == _Type_Chademo) {
+            ResetChargerAlarmCode(gun_index, "011012");
+            ResetChargerAlarmCode(gun_index, "011011");
+        } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+            ResetChargerAlarmCode(gun_index, "011014");
+            ResetChargerAlarmCode(gun_index, "011013");
+        } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+            ResetChargerAlarmCode(gun_index, "011016");
+            ResetChargerAlarmCode(gun_index, "011015");
+        }
+    }
+}
+
+int main(void)
+{
+    uint8_t evBoardStopState = 0;
+    uint8_t _ocppProfileChkFlag;
+
+    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
+                log_info("Soft reboot for retry self-tets. \n");
+
+                sleep(3);
+                system("killall OcppBackend &");
+                KillAllTask();
+                system("/usr/bin/run_evse_restart.sh");
+            }
+        }
+
+        for (uint8_t 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 (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            setChargerMode(gun_index, MODE_IDLE);
+        }
+    }
+
+    // Local DB
+    if (DB_Open(localDb) != PASS) {
+        log_info("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);
+    }
+    log_info("===== 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
+
+    log_info("===== Charger info ===== ");
+    log_info("SW Version = %s", fwVersion);
+    log_info("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();
+
+        //確認Power cabinet PSU Status
+        powerCabinetPsuAlarmStatus();
+
+        if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan) {
+            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+        }
+
+        if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
+            CheckTask();
+
+            for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _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++;
+                    }
+                }
+                checkGunOTPState(_index); //check gun OTP
+            }
+            gettimeofday(&_cmdMainPriority_time, NULL);
+        }
+
+        gEvBoardErr.GunErrMessage = 0;
+
+        for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            autoStartChargingForComBox(gun_index); //for DD360ComBox
+
+            CheckGpioInStatus();
+
+            // 確認 Relay Welding or Driving Fault
+            CheckRelayWeldingOrDrivingFault(gun_index);
+
+            // 收集各槍的錯誤狀態
+            collectError(gun_index);
+
+            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);
+            }
+
+            //log_info("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;
+                    destroySelGun(gun_index);
+                    ResetDetAlarmStatus(gun_index); //recovery OVP status code
+                    if (gAudiCustInfo->AuthorStateFromCabinet[gun_index] == YES) {
+                        gAudiCustInfo->AuthorStateFromCabinet[gun_index] = NO;
+                    }
+                    //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 (uint8_t 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 (PrecheckIsPass(gun_index)) {
+
+                        if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+                            setChargerMode(gun_index, MODE_IDLE);
+                        }
+
+                        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) {
+                                        log_info("-----------------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
+                                       ) {
+                                        log_info("-----------------2----------------- \n");
+                                        ChangeGunSelectByIndex(gun_index);
+                                        AddPlugInTimes(gun_index);
+                                        strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+                                        log_info("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)) {
+                                log_info("-----------------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 正常程序終點
+                    } else {
+                        setChargerMode(gun_index, MODE_FAULT);
+                        if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
+                        }
+                    }// PrecheckIsPass()
+                }
+            }
+            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)) {
+                    log_info("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) {
+                    log_info("=============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
+                }
+
+                //log_info("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)) {
+                    log_info("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 (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
+                        // 共同進入充電邏輯
+                        if (chargingInfo[index]->SystemStatus != S_PREPARNING) {
+                            oughtAver = false;
+                            break;
+                        }
+                    }
+
+                    if (oughtAver) {
+                        log_info("********* 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) {
+                        log_info("================== S_ALARM (%x) ================ \n", gun_index);
+                        UpdateErrorCodeToOcpp(gun_index);
+
+                        if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
+                            OcppStopTransation(gun_index);
+                        }
+
+                        TheEndCharging(gun_index);
+                    } else {
+                        log_info("================== 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)) {
+                    log_info ("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)) {
+                    log_info("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)
+                    {
+                        //log_info("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        if (isPrechargeStatus_ccs(gun_index) == 39) {
+                            log_info("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        } else if (isPrechargeStatus_ccs(gun_index) == 40) {
+                            log_info("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);
+            }
+        }
+
+        for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
+            checkEvBoardAlarmState(chargingInfo[gun_index]->Type);
+        }
+
+        write(wtdFd, "a", 1);
+        usleep(whileLoopTime);
+    }
+
+    return FAIL;
+}

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


BIN
EVSE/Projects/DD360Audi/output/DoComm


BIN
EVSE/Projects/DD360Audi/output/FactoryConfig


BIN
EVSE/Projects/DD360Audi/output/Module_DoComm


BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN
EVSE/Projects/DD360Audi/output/Module_EventLogging


BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN
EVSE/Projects/DD360Audi/output/Module_LcmControl


BIN
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Audi/output/Module_ProduceUtils


BIN
EVSE/Projects/DD360Audi/output/ReadCmdline


BIN
EVSE/Projects/DD360Audi/output/main


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels