Przeglądaj źródła

2021-11-25 / Simon Xue

Action
1. Complete DD360UCar program flow but not including LCM.

Files
As follow commit history

Image version : V2.00.XX.XXXX.XX
Simon Xue 3 lat temu
rodzic
commit
c7b5709098
27 zmienionych plików z 2117 dodań i 5636 usunięć
  1. 2 109
      EVSE/Projects/DD360UCar/Apps/CSU/Ethernet.c
  2. 169 449
      EVSE/Projects/DD360UCar/Apps/CSU/OCPP.c
  3. 89 108
      EVSE/Projects/DD360UCar/Apps/CSU/RFID.c
  4. 5 28
      EVSE/Projects/DD360UCar/Apps/CSU/SelfTest.c
  5. 107 461
      EVSE/Projects/DD360UCar/Apps/CSU/WatchDog.c
  6. 6 7
      EVSE/Projects/DD360UCar/Apps/CSU/main.h
  7. 47 4
      EVSE/Projects/DD360UCar/Apps/Config.h
  8. 2 1
      EVSE/Projects/DD360UCar/Apps/DataBase/DataBase.c
  9. 1 4
      EVSE/Projects/DD360UCar/Apps/Log/log.c
  10. 0 1
      EVSE/Projects/DD360UCar/Apps/ModuleChkSysTask/Module_ChkSysTask.c
  11. 18 20
      EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.c
  12. 20 20
      EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.h
  13. 29 29
      EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvTxComm.c
  14. 3 3
      EVSE/Projects/DD360UCar/Apps/ModuleEventLog/Module_EventLogging.c
  15. 0 2488
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/FanBoard.c
  16. 17 17
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/RelayBoard.c
  17. 1 1
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/internalComm.h
  18. 108 150
      EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.c
  19. 10 211
      EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.h
  20. 8 25
      EVSE/Projects/DD360UCar/Apps/ModulePrimary/Module_PrimaryComm.h
  21. 1427 1468
      EVSE/Projects/DD360UCar/Apps/ReadCmdline.c
  22. 24 15
      EVSE/Projects/DD360UCar/Apps/Readme.md
  23. BIN
      EVSE/Projects/DD360UCar/Apps/ShareMemory/shmMem.h
  24. 10 6
      EVSE/Projects/DD360UCar/Apps/common.c
  25. 4 5
      EVSE/Projects/DD360UCar/Apps/simulation.h
  26. 8 6
      build_rootfs_copy.sh
  27. 2 0
      copy_project_from_D.sh

+ 2 - 109
EVSE/Projects/DD360UCar/Apps/CSU/Ethernet.c

@@ -109,7 +109,6 @@ static int isReachableInternet(void)
 
     pclose(fp);
 
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
     if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == NORMAL) {
         result = FAIL;
     } else {
@@ -117,31 +116,7 @@ static int isReachableInternet(void)
     }
 
     return result;
-#endif //defined DD360 || defined DD360Audi
-
-    memset(buf, 0x00, sizeof(buf));
-
-    for (idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
-        sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
-        fp = popen(cmd, "r");
-        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",tmp);
-                }
-            }
-        }
-        pclose(fp);
-    }
 
-    return result;
 }
 
 void InitEthernet(void)
@@ -205,95 +180,13 @@ void InitEthernet(void)
 
     pid_t pid = fork();
     if (pid == 0) {
-        log_info("InitEthernet = %d", pid);
+        //log_info("InitEthernet = %d", pid);
 
         for (;;) {
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+
             isReachableInternet();
             sleep(5);
             continue;
-#endif //!defined DD360 && !defined DD360
-
-            if (isRouteFail()) {
-                //log_info("eth0 not in route, restart eht0. ");
-                system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
-
-                if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
-                    InitialDHCP();
-                }
-            }
-
-            if (isReachableInternet() == PASS) {
-                pSysInfo->ethInternetConn = YES;
-                cnt_pingDNS_Fail = 0;
-            } else {
-                if (++cnt_pingDNS_Fail > 3) {
-                    pSysInfo->ethInternetConn = NO;
-                }
-            }
-
-            ethResult = pSysInfo->ethInternetConn;
-
-            if (ethResult == YES) {
-                system("/sbin/ifmetric eth0 0");
-
-                if ((pSysConfig->ModelName[10] == 'W') ||
-                        (pSysConfig->ModelName[10] == 'D')) {
-                    system("/sbin/ifmetric mlan0 1");
-                }
-
-                if ((pSysConfig->ModelName[10] == 'T') ||
-                        (pSysConfig->ModelName[10] == 'D')) {
-                    system("/sbin/ifmetric ppp0 2");
-                }
-            }
-
-            if (!ethResult &&
-                    pSysConfig->AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
-                    (pSysConfig->ModelName[10] == 'W' ||
-                     pSysConfig->ModelName[10] == 'D')) {
-                //ethResult = pSysConfig->AthInterface.WifiNetworkConn;
-                ethResult = pInfoCode->InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
-
-                if (ethResult) {
-                    if ((pSysConfig->ModelName[10] == 'W') ||
-                            (pSysConfig->ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric eth0 1");
-                        system("/sbin/ifmetric mlan0 0");
-                    }
-
-
-                    if ((pSysConfig->ModelName[10] == 'T') ||
-                            (pSysConfig->ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric ppp0 2");
-                    }
-                }
-            }
-
-            if (!ethResult &&
-                    pSysConfig->TelecomInterface.TelcomEnabled == YES &&
-                    (pSysConfig->ModelName[10] == 'T' ||
-                     pSysConfig->ModelName[10] == 'D')) {
-                //ethResult = pSysConfig->TelecomInterface.TelcomNetworkConn;
-                ethResult = pInfoCode->InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
-
-                if (ethResult) {
-                    if ((pSysConfig->ModelName[10] == 'W') ||
-                            (pSysConfig->ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric mlan0 2");
-                    }
-
-                    if ((pSysConfig->ModelName[10] == 'T') ||
-                            (pSysConfig->ModelName[10] == 'D')) {
-                        system("/sbin/ifmetric eth0 1");
-                        system("/sbin/ifmetric ppp0 0");
-                    }
-                }
-            }
-
-            pSysInfo->InternetConn = ethResult;
-
-            sleep(5);
         }
     }
 

+ 169 - 449
EVSE/Projects/DD360UCar/Apps/CSU/OCPP.c

@@ -10,7 +10,10 @@
 
 #include "../SelectGun/SelectGun.h"
 #include "main.h"
-
+#include "../timeout.h"
+struct SysInfoData *pSysInfo = NULL;
+struct ChargingInfoData *pDcChargingInfo = NULL;
+struct SysConfigData *pSysConfig = NULL;
 //------------------------------------------------------------------------------
 typedef struct StLedConfig {
     //OutputDrvValue[0]
@@ -24,310 +27,159 @@ typedef struct StLedConfig {
     uint8_t Reserved: 1;                        //bit 7 reserved
 } LedConfig;
 
+
 //------------------------------------------------------------------------------
-static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
+void ChangeLCM(uint8_t page)
 {
-    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->YellowLED == YES ||
-                pLedConfig->GreenLED == YES) {
-            pLedConfig->RedLED = NO;
-            pLedConfig->YellowLED = NO;
-            pLedConfig->GreenLED = NO;
-        } else {
-            pLedConfig->RedLED = YES;
-            pLedConfig->YellowLED = YES;
-            pLedConfig->GreenLED = YES;
-        }
+    pSysInfo->SystemPage = page;
+}
+// ***********************************
+// Enter LCM Page
+// ***********************************
+void EnterViewPage()
+{
+    ChangeLCM(_LCM_VIEW);
+    StopSystemTimeoutDet();
+}
+void EnterAuthorizePage(uint8_t gunIndex)
+{
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+    log_info("Select Gun(%d) in Authorizing",gunIndex);
+    ChangeGunSelectByIndex(gunIndex);
+    confirmSelGun(gunIndex);
+    ChangeLCM(_LCM_START_SCAN);
+    strcpy((char *)pSysConfig->UserId, "");
+    setChargerMode(gunIndex,MODE_AUTHORIZING);
+    StartSystemTimeoutDet(Timeout_ReturnViewPage);
+}
+void EnterLinkErrorPage()
+{
+    StopSystemTimeoutDet();
+    //StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
+    ChangeLCM(_LCM_LINK_ERROR);
+    StartSystemTimeoutDet(Timeout_ReturnViewPage);
+    //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_LinkError);
+}
+void EnterDetailViewPage(uint8_t gunIndex)
+{
+    log_info("Show Gun(%d) Detail View",gunIndex);
+    ChangeGunSelectByIndex(gunIndex);
+    ChangeLCM(_LCM_DETAIL_VIEW);
+    StartGunInfoTimeoutDet(gunIndex,Timeout_DetailView);
+}
+void EnterAuthorizeStopPage()
+{
+    log_info("Select Gun(%d) in Stopping",pSysInfo->CurGunSelected);
+    StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
+    strcpy((char *)pSysConfig->UserId, "");
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    if (pDcChargingInfo->isRemoteStart) {
+        pSysInfo->SystemPage = _LCM_STOP_APP;
+    } else {
+        pSysInfo->SystemPage = _LCM_STOP_RFID;
     }
-
-    return ret;
+    StartSystemTimeoutDet(Timeout_ReturnViewPage);
 }
-
-void PrimaryLedIndicatorCtrlFork(void)
+void EnterSummaryPage()
 {
-#if !defined DD360ComBox
-    return;
-#endif //!defined DD360ComBox
-
-    pid_t pid = fork();
-    if (pid == 0) {
-        uint8_t gunIndex = 0;
-        int isContinue = 1;
-
-        struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-        struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-        struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
-        struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
-        struct ChargingInfoData *pDcChargingInfo = NULL;
-
-        LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
-
-        while (isContinue) {
-            for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-
-                if (pSysWarning->Level == WARN_LV_ER) {
-                    if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                        usleep(500000);
-                        continue;
-                    }
-
-                    pLedConfig->YellowLED = NO;
-                    pLedConfig->GreenLED = NO;
-                    pLedConfig->RedLED = YES;
-                    usleep(500000);
-                    continue;
-                }
-
-                //log_info("led indicator status = %d", pDcChargingInfo->SystemStatus);
-                //printf("level = %d", pSysWarning->Level);
-                switch (pDcChargingInfo->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;
-#ifdef DD360ComBox
-                    pLedConfig->YellowLED = YES;
-#else
-                    if (pLedConfig->YellowLED == YES) {
-                        pLedConfig->YellowLED = NO;
-                    } else {
-                        pLedConfig->YellowLED = YES;
-                    }
-#endif
-                    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 (pSysWarning->Level == WARN_LV_ER) {
-                    //    pLedConfig->YellowLED = NO;
-                    //    pLedConfig->GreenLED = NO;
-                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                    //        break;
-                    //    }
-                    //    pLedConfig->RedLED = YES;
-                    //} else {
-                    pLedConfig->RedLED = NO;
-#ifdef DD360ComBox
-                    if (pLedConfig->YellowLED == YES) {
-                        pLedConfig->YellowLED = NO;
-                    } else {
-                        pLedConfig->YellowLED = YES;
-                    }
-#else
-                        pLedConfig->YellowLED = YES;
-#endif
-                    pLedConfig->GreenLED = NO;
-                    //}
-                    break;
-
-                case S_MAINTAIN:
-                case S_FAULT:
-                case S_UPDATE:
-                    pLedConfig->YellowLED = NO;
-                    pLedConfig->GreenLED = NO;
-                    pLedConfig->RedLED = YES;
-                    //if (pSysWarning->Level == WARN_LV_ER) {
-                    //    if (checkCabinetEthConnectState(pLedConfig) == YES) {
-                    //        break;
-                    //    }
-                    //    pLedConfig->RedLED = YES;
-                    //}
-                    break;
-
-                case S_BOOKING:
-                case S_DEBUG:
-                case S_NONE:
-                    break;
-                }//switch
-            }//for
-            usleep(500000);
-        }//while
-    }//fork
+    StopSystemTimeoutDet();
+    log_info("Showing Summary Page");
+    pSysInfo->SystemPage = _LCM_SUMMARY;
+    StartSystemTimeoutDet(Timeout_ReturnViewPage);
 }
-
-//------------------------------------------------------------------------------
-static void checkChargingInfoByDC(uint8_t systemStatus)
+// *****************************
+// Enter System status
+// *****************************
+void ReturnIDLE(uint8_t gunIndex)
 {
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-
-    switch (systemStatus) {
-    case S_IDLE:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
-            destroySelGun(pSysInfo->CurGunSelected);
-            
-        } else {
-            if( pSysConfig->isAuthrizeByEVCCID && pSysInfo->ConnectorPage == _LCM_PRE_CHARGE) {
-                _evccidlinktimeout(pSysInfo->CurGunSelected);
-                pDcChargingInfo->isEVCCIDVerify = true;
-                break;
+    log_info("Gun(%d) return to IDLE",gunIndex);
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+    EnterViewPage();
+    setChargerMode(gunIndex,MODE_IDLE);
+    destroySelGun(gunIndex);
+}
+void ReturnAuthorize()
+{
+    StopSystemTimeoutDet();
+    EnterAuthorizePage(pSysInfo->CurGunSelected);
+}
+void CheckLeftButton()
+{
+    uint8_t gunIndex = 0;
+    switch (pSysInfo->SystemPage) {
+        case _LCM_VIEW:
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
+            if(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
+                EnterAuthorizePage(LEFT_GUN_NUM);
+            } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+                EnterDetailViewPage(LEFT_GUN_NUM);
             }
-#if !defined DD360Audi
             break;
-#endif //!defined DD360Audi
-
-            if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
-                //printf("destroy gun = %d", pSysInfo->CurGunSelected);
-                destroySelGun(pSysInfo->CurGunSelected);
-            } else {
-                confirmSelGun(pSysInfo->CurGunSelected);
-                log_info("confirm select gun ............................... %d ",
-                         pSysInfo->CurGunSelected);
-            }
-        }
-        break;
-
-    case S_REASSIGN_CHECK:
-    case S_REASSIGN:
-    case S_PREPARNING:
-    case S_PREPARING_FOR_EV:
-    case S_PREPARING_FOR_EVSE:
-    case S_CCS_PRECHARGE_ST0:
-    case S_CCS_PRECHARGE_ST1:
-        // 取消充電
-        if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
-            AcChargingTerminalProcess();
-        } else {
-            ChargingTerminalProcess(pSysInfo->CurGunSelected);
-        }
-        break;
-
-    case S_CHARGING:
-        if (pSysConfig->StopChargingByButton == YES ||
-                pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
-            // 停止充電
-            ChargingTerminalProcess(pSysInfo->CurGunSelected);
-        }
-        break;
-
-    case S_COMPLETE:
-        break;
+        case _LCM_START_SCAN:
+        case _LCM_START_AUTHORIZE_FAIL:
+        case _LCM_LINK_ERROR:
+        	ReturnIDLE(pSysInfo->CurGunSelected);
+            break;
+        case _LCM_DETAIL_VIEW:
+        case _LCM_STOP_RFID:
+        case _LCM_STOP_APP:
+        case _LCM_STOP_RFID_FAIL:
+            EnterViewPage();
+        	break;
+        case _LCM_SUMMARY:
+            log_info("Return View Page");
+            ReturnIDLE(pSysInfo->CurGunSelected);
+            break;
+        case _LCM_ERROR:
+        	ReturnIDLE(pSysInfo->CurGunSelected);
+            break;
     }
 }
-
-static void checkChargingInfoByAC(void)
+void CheckRightButton()
 {
-    struct ChargingInfoData *pAcChargingInfo = NULL;
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-
-    if (pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
-        return;
-    }
-
-    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-    switch (pAcChargingInfo->SystemStatus) {
-    case S_IDLE:
-        if (isDetectPlugin()) {
-            _DetectPlugInTimeout();
-            StopSystemTimeoutDet();
-        }
-        break;
-
-    case S_REASSIGN_CHECK:
-    case S_REASSIGN:
-    case S_PREPARNING:
-    case S_PREPARING_FOR_EV:
-    case S_PREPARING_FOR_EVSE:
-    case S_CCS_PRECHARGE_ST0:
-    case S_CCS_PRECHARGE_ST1:
-        // 取消充電
-        AcChargingTerminalProcess();
-        break;
-
-    case S_CHARGING:
-        if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
-            // 停止充電
-            AcChargingTerminalProcess();
-        }
-        break;
-
-    case S_COMPLETE:
-        break;
+    uint8_t gunIndex = 0;
+
+    switch (pSysInfo->SystemPage) {
+        case _LCM_VIEW:
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
+            if(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
+                EnterAuthorizePage(RIGHT_GUN_NUM);
+            } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+                EnterDetailViewPage(RIGHT_GUN_NUM);
+            }
+            break;
+        case _LCM_START_AUTHORIZE_FAIL:
+            ReturnAuthorize();
+            break;
+        case _LCM_WAIT_PLUGIN:
+            EnterLinkErrorPage();
+        	break;
+        case _LCM_LINK_ERROR:
+            ReturnAuthorize();
+            break;
+        case _LCM_DETAIL_VIEW:
+            EnterAuthorizeStopPage();
+            break;
+        case _LCM_STOP_RFID_FAIL:
+            EnterAuthorizeStopPage();
+            break;
+        case _LCM_WAIT_PLUGOUT:
+            EnterSummaryPage();
+            break;
+        case _LCM_ERROR:
+        	ReturnIDLE(pSysInfo->CurGunSelected);
+            break;
     }
+    
 }
-
-void ChkPrimaryStatus(void)
+void CheckPrimaryWarm(void)
 {
-    static bool leftBtnPush = false;
-    static bool rightBtnPush = false;
     uint8_t i = 0;
     uint8_t Rtn = 0;
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
-    struct ChargingInfoData *pDcChargingInfo = NULL;
     DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
-
     if (pSysWarning->WarningCount > 0) {
         Rtn = 0;
         for (i = 0; i < pSysWarning->WarningCount; i++) {
@@ -418,171 +270,39 @@ void ChkPrimaryStatus(void)
     } 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;
-    //}
-
-    if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
-            !leftBtnPush
-#if defined DD360Audi
-            &&
-            pSysInfo->SystemPage != _LCM_AUTHORIZING &&
-            pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
-            pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL
-#endif //defined DD360Audi
-       ) {
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-
-        if (!leftBtnPush) {
-            leftBtnPush = true;
-            log_info("left btn down...............................%x",
-                     pDcChargingInfo->SystemStatus);
-            checkChargingInfoByAC();
-            checkChargingInfoByDC(pDcChargingInfo->SystemStatus);
-#if 0
-            if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
-                pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-                switch (pAcChargingInfo->SystemStatus) {
-                case S_IDLE:
-                    if (isDetectPlugin()) {
-                        _DetectPlugInTimeout();
-                        StopSystemTimeoutDet();
-                    }
-                    break;
-
-                case S_REASSIGN_CHECK:
-                case S_REASSIGN:
-                case S_PREPARNING:
-                case S_PREPARING_FOR_EV:
-                case S_PREPARING_FOR_EVSE:
-                case S_CCS_PRECHARGE_ST0:
-                case S_CCS_PRECHARGE_ST1:
-                    // 取消充電
-                    AcChargingTerminalProcess();
-                    break;
-
-                case S_CHARGING:
-                    if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
-                        // 停止充電
-                        AcChargingTerminalProcess();
-                    }
-                    break;
-
-                case S_COMPLETE:
-                    break;
-                }
-            }
-            switch (pDcChargingInfo->SystemStatus) {
-            case S_IDLE:
-                if (isDetectPlugin()) {
-                    _DetectPlugInTimeout();
-                    StopSystemTimeoutDet();
-                    destroySelGun(pSysInfo->CurGunSelected);
-                }             else {
-#if defined DD360Audi
-                    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == PASS) {
-                        //printf("destroy gun = %d", pSysInfo->CurGunSelected);
-                        destroySelGun(pSysInfo->CurGunSelected);
-                    } else {
-                        confirmSelGun(pSysInfo->CurGunSelected);
-                        log_info("confirm select gun ............................... %d ",
-                                 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 ");
-                //pDcChargingInfo->SystemStatus = S_IDLE;
-                break;
-            }
-#endif //0
-        }
-    } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
-        if (leftBtnPush) {
-            leftBtnPush = false;
-            //log_info("left btn up............................... ");
-        }
+}
+void ChkPrimaryStatus(void)
+{
+    static bool leftBtnPush = false;
+    static bool rightBtnPush = false;
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    // Check Primary Board status
+    CheckPrimaryWarm();
+    if ((pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+            && pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
+        log_info("Offline policy no charge");
+        return;;
     }
-
-    if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
-            !rightBtnPush
-#if defined DD360Audi
-            &&
-            pSysInfo->SystemPage != _LCM_IDLE &&
-            pSysInfo->SystemPage != _LCM_AUTHORIZING &&
-            pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
-            pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL &&
-            pSysInfo->SystemPage != _LCM_WAIT_FOR_PLUG
-#endif //defined DD360Audi
-       ) {
-        if (!rightBtnPush) {
-            rightBtnPush = true;
-            //log_info("right btn down............................... %d ", 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++) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-                    if (pDcChargingInfo->SystemStatus != S_BOOTING &&
-                            pDcChargingInfo->SystemStatus != S_IDLE &&
-                            pDcChargingInfo->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 ",
-                 pSysInfo->CurGunSelected);
-    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
-        if (rightBtnPush) {
-            rightBtnPush = false;
-            //log_info("right btn up............................... ");
-        }
+    // Press Left Button
+    if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush ) {
+        leftBtnPush = true;
+        CheckLeftButton();
+        log_info("left btn down...............................%x %x %x",
+                pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE && leftBtnPush) {
+        leftBtnPush = false;
+    }
+    // Press Right Button
+    if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush ) {
+        rightBtnPush = true;
+        CheckRightButton();
+        log_info("right btn down...............................%x %x %x",
+               pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus, pSysInfo->SystemPage);
+    } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE && rightBtnPush) {
+        rightBtnPush = false;
     }
 }

+ 89 - 108
EVSE/Projects/DD360UCar/Apps/CSU/RFID.c

@@ -38,28 +38,24 @@ static bool canStartCharging(void)
     return false;
 }
 
-static void isAutorCompleteHandle(uint8_t *authorizeIndex)
+bool isAutorCompleteHandle(/*uint8_t *authorizeIndex*/)
 {
-    uint8_t i = 0;
+   // uint8_t i = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct ChargingInfoData *pDcChargingInfo = NULL;
+    //struct ChargingInfoData *pDcChargingInfo = NULL;
+    //struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
 
     // 透過後臺停止充電的判斷
-    if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-            || (pSysInfo->OcppConnStatus == NO &&
-                pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-#endif //!defined DD360 && !defined DD360Audi
-       ) {
-
+    if (isAuthorizedComplete()) {
         // 判斷後台回覆狀態
         if (canStartCharging() == false) {
             strcpy((char *)pSysConfig->UserId, "");
             ClearAuthorizedFlag();
-
-            return;
         }
-
+        return true;
+    }
+    return false;
+/*
         if (*(authorizeIndex) != NO_DEFINE) {
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(*(authorizeIndex));
 
@@ -78,7 +74,8 @@ static void isAutorCompleteHandle(uint8_t *authorizeIndex)
         }
 
         ClearAuthorizedFlag();
-    } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
+
+    } /*else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
         // 白名單驗證
         for (i = 0; i < 10; i++) {
             if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
@@ -93,9 +90,37 @@ static void isAutorCompleteHandle(uint8_t *authorizeIndex)
                 break;
             }
         }
-    }
+    }*/
 }
 
+bool RfidStopCharging(void)
+{
+    //當前沒有選槍
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL ) {
+        strcpy((char *)pSysConfig->UserId, "");
+        return false;
+    }
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    if (pDcChargingInfo->isRemoteStart) {
+
+    } else {
+        if (strcmp((char *)pSysConfig->UserId, (char *)pDcChargingInfo->StartUserId) == EQUAL) {
+
+            ChargingTerminalProcess(pSysInfo->CurGunSelected);
+            strcpy((char *)pSysConfig->UserId, "");
+            log_info("index = %d, card number = %s, UserId = %s ",
+                     pSysInfo->CurGunSelected,
+                     pDcChargingInfo->StartUserId,
+                     pSysConfig->UserId);
+            return true;
+        } else {
+            return false;
+        }
+    }
+    return false;
+}
 static void UserScanFunction(void)
 {
     bool idleReq = false;
@@ -111,7 +136,7 @@ static void UserScanFunction(void)
 
     // 當前非驗證的狀態
     if (IsAuthorizingMode()) {
-        isAutorCompleteHandle(&_authorizeIndex);
+        isAutorCompleteHandle(/*&_authorizeIndex*/);
     }
 
     //當前沒有選槍
@@ -119,20 +144,16 @@ static void UserScanFunction(void)
         strcpy((char *)pSysConfig->UserId, "");
         return;
     }
-    /*
-    if (pSysConfig->EVCCID_Authorize) {
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-        if (strcmp( (char *)pSysConfig->UserId, (char *) pDcChargingInfo->EVCCID) != EQUAL )
-            return;
-    }*/
+
     // 先判斷現在是否可以提供刷卡
     // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
     // 2. 停止充電
-    if (pSysInfo->PageIndex == _LCM_FIX) {
+    //if (pSysInfo->PageIndex == _LCM_ERROR) {
+    if (pSysInfo->SystemPage == _LCM_MAINTAIN) {
         strcpy((char *)pSysConfig->UserId, "");
         return;
     }
-
+    /*
     for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
@@ -140,10 +161,10 @@ static void UserScanFunction(void)
             stopReq = i;
         }
 
-        if ((pDcChargingInfo->SystemStatus == S_IDLE &&
+        if ((pDcChargingInfo->SystemStatus == S_AUTHORIZING &&
                 pDcChargingInfo->IsAvailable == YES) ||
                 (pGunIndexInfo->AcGunIndex > 0 &&
-                 pAcChargingInfo->SystemStatus == S_IDLE &&
+                 pAcChargingInfo->SystemStatus == S_AUTHORIZING &&
                  pAcChargingInfo->IsAvailable)
            ) {
             idleReq = true;
@@ -155,14 +176,14 @@ static void UserScanFunction(void)
             pAcChargingInfo->SystemStatus == S_CHARGING) {
         stopReq = DEFAULT_AC_INDEX;
     }
-
+     */
     if (strlen((char *)pSysConfig->UserId) <= 0) {
         return;
     }
 
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-
-    if (pGunIndexInfo->AcGunIndex > 0 &&
+    // Stop Charging For AC
+    /*if (pGunIndexInfo->AcGunIndex > 0 &&
             stopReq == DEFAULT_AC_INDEX &&
             pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
         log_info("ac stop charging ");
@@ -185,26 +206,9 @@ static void UserScanFunction(void)
                 (pGunIndexInfo->AcGunIndex > 0 &&
                  pSysInfo->CurGunSelectedByAc == NO_DEFINE))
               ) {
-        log_info("stop charging ");
-        log_info("index = %d, card number = %s, UserId = %s ",
-                 pSysInfo->CurGunSelected,
-                 pDcChargingInfo->StartUserId,
-                 pSysConfig->UserId);
-
-        memset(value, 0, sizeof(value));
-        memcpy(value,
-               (uint8_t *)pDcChargingInfo->StartUserId,
-               ARRAY_SIZE(pDcChargingInfo->StartUserId));
-
-        // 同一張卡直接停掉
-        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-            ChargingTerminalProcess(pSysInfo->CurGunSelected);
-            strcpy((char *)pSysConfig->UserId, "");
-
+    	// Stop Charging
+        if (RfidStopCharging())
             return;
-        }
-
-        // 進驗證
         if (pGunIndexInfo->AcGunIndex > 0 &&
                 pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
             _authorizeIndex = pSysInfo->CurGunSelectedByAc;
@@ -212,15 +216,9 @@ static void UserScanFunction(void)
             _authorizeIndex = pSysInfo->CurGunSelected;
         }
 
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
         strcpy((char *)pSysConfig->UserId, "");
-
         return;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
-
-        StartSystemTimeoutDet(Timeout_AuthorizingForStop);
 
-        AuthorizingStart();
     } else if (idleReq) {
         if (pSysConfig->TotalConnectorCount > 1 &&
                 stopReq != 255 &&
@@ -229,19 +227,17 @@ static void UserScanFunction(void)
             strcpy((char *)pSysConfig->UserId, "");
         } else if ((pGunIndexInfo->AcGunIndex > 0 &&
                     pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-                   pDcChargingInfo->SystemStatus == S_IDLE) {
+                   pDcChargingInfo->SystemStatus == S_AUTHORIZING) {*/
+    if (pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
             log_info("// LCM => Authorizing");
 
             setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
 
             // LCM => Authorizing
-            pSysInfo->SystemPage = _LCM_AUTHORIZING;
+            pSysInfo->SystemPage = _LCM_START_AUTHORIZING;
 
             // 進入確認卡號狀態
             AuthorizingStart();
-        } else {
-            strcpy((char *)pSysConfig->UserId, "");
-        }
     } else {
         strcpy((char *)pSysConfig->UserId, "");
     }
@@ -258,17 +254,42 @@ void SetIsCardScan(bool value)
 {
     isCardScan = value;
 }
-
+void AuthorizeToCharge()
+{
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+    if(!isAuthorizedComplete())
+        StartSystemTimeoutDet(Timeout_Authorizing);
+    else {
+        //StopSystemTimeoutDet();
+        StartSystemTimeoutDet(Timeout_WaitBalance);
+        if (ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance != FAIL_BALANCE_PRICES) {
+            StopSystemTimeoutDet();
+            // 判斷後台回覆狀態
+            if (canStartCharging()) {
+            // LCM => Authorize complete
+                pSysInfo->SystemPage = _LCM_WAIT_PLUGIN;
+                log_info("Wait Gun(%d) plugin",pSysInfo->CurGunSelected);
+                DetectPluginStart();
+                log_info("Gun(%d) Balance: %f",pSysInfo->CurGunSelected,
+                        ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
+            } else {
+                // LCM => Authorize fail
+                pSysInfo->SystemPage = _LCM_START_AUTHORIZE_FAIL;
+                strcpy((char *)pSysConfig->UserId, "");
+            }
+        }
+        ClearAuthorizedFlag();
+    }
+}
 void ScannerCardProcess(void)
 {
-    int i = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
-    SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
 
-    if (!isDetectPlugin() &&
-            !isCardScan &&
+    if (!isDetectPlugin() && pSysInfo->SystemPage == _LCM_START_SCAN &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
         isCardScan = true;
@@ -276,52 +297,12 @@ void ScannerCardProcess(void)
         UserScanFunction();
     }
 
-    if (pSysInfo->PageIndex == _LCM_AUTHORIZING) {
-        if(!isAuthorizedComplete())
-            StartSystemTimeoutDet(Timeout_Authorizing);
-
-        //printf("isAuthorizedComplete = %d, %f", isAuthorizedComplete(), ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
-        // 確認驗證卡號完成沒
-        if (isAuthorizedComplete()
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
-#endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
-           ) {
-                //StopSystemTimeoutDet();
-                StartSystemTimeoutDet(Timeout_WaitBalance);
-                if (ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance != FAIL_BALANCE_PRICES) {
-                    StopSystemTimeoutDet();
-                    // 判斷後台回覆狀態
-                    if (canStartCharging()) {
-                    // LCM => Authorize complete
-                    pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
-                    } else {
-                    // LCM => Authorize fail
-                    pSysInfo->SystemPage = _LCM_AUTHORIZ_FAIL;
-                    strcpy((char *)pSysConfig->UserId, "");
-                }
-
-            } ClearAuthorizedFlag();
-        } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
-            // 白名單驗證
-            for (i = 0; i < 10; i++) {
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
-                    continue;
-                }
-
-                if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                    pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
-                    ClearAuthorizedFlag();
-                    break;
-                }
-            }
-        }
-    } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_FAIL) {
+    if (pSysInfo->SystemPage == _LCM_START_AUTHORIZING) {
+        AuthorizeToCharge();
+    } else if (pSysInfo->SystemPage == _LCM_START_AUTHORIZE_FAIL) {
         StartSystemTimeoutDet(Timeout_VerifyFail);
         isCardScan = false;
-    } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
-        StartSystemTimeoutDet(Timeout_VerifyComp);
-    } else if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
+    } else if (pSysInfo->SystemPage == _LCM_WAIT_PLUGIN) {
         StartSystemTimeoutDet(Timeout_WaitPlug);
     } else {
         isCardScan = false;

+ 5 - 28
EVSE/Projects/DD360UCar/Apps/CSU/SelfTest.c

@@ -74,7 +74,7 @@ void SelfTestRun(void)
         case _STEST_VERSION:
             if(isRelayBypass == YES && ShmRelayModuleData->SelfTest_Comp != YES)
             {
-                log_info("Relay Board Bypass");
+                //log_info("Relay Board Bypass");
                 ShmRelayModuleData->SelfTest_Comp = YES;
             }
             if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
@@ -147,9 +147,9 @@ void SelfTestRun(void)
                                     ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
                                     /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
                                ) {
-                             //   log_info("CCS[%d] FW Rev = %s",
-                             //            pDcChargingInfo->type_index,
-                             //            ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
+                                //log_info("CCS[%d] FW Rev = %s",
+                                //         pDcChargingInfo->type_index,
+                                //         ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
                                 ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
                             } else {
                                 //log_info("CCS[%d] ccs fw lose...... %s \n",
@@ -169,7 +169,7 @@ void SelfTestRun(void)
                                 pAcChargingInfo->version[0] != '\0')
                                 && (pAcChargingInfo->SelfTest_Comp != YES)
                            ) {
-                            log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
+                            //log_info("AC connector[%d] FW Rev = %s", index, pAcChargingInfo->version);
                             pAcChargingInfo->SelfTest_Comp = YES;
                         } else {
                             evInitFlag = NO;
@@ -190,47 +190,24 @@ void SelfTestRun(void)
         case _STEST_AC_CONTACTOR:
             //ShmPsuData->Work_Step = _TEST_COMPLETE;
             // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
             pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
             //log_info("Waiting for DO communication");
             break;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
-
-            if (pSysInfo->AcContactorStatus == YES) {
-                pSysInfo->SelfTestSeq = _STEST_PSU_DETECT;
-                log_info("AC contactor self test OK");
-            }
-            break;
 
         case _STEST_PSU_DETECT:
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
             pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
             break;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
-
-            if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
-                pSysInfo->SelfTestSeq = _STEST_PSU_CAP;
-            }
-            break;
 
         case _STEST_PSU_CAP:
             // 此測試是要確認當前總輸出能力
             // 如果沒有 PSU 模組請 bypass
 
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
             //check the power limit from DO
             pSysInfo->SelfTestSeq = _STEST_COMPLETE;
             pSysInfo->BootingStatus = BOOT_COMPLETE;
             log_info("Successful Self Test");
             break;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-            if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
-                sleep(1);
-                pSysInfo->SelfTestSeq = _STEST_COMPLETE;
-                pSysInfo->BootingStatus = BOOT_COMPLETE;
-            }
-            break;
         }
 
         usleep(100000);

Plik diff jest za duży
+ 107 - 461
EVSE/Projects/DD360UCar/Apps/CSU/WatchDog.c


+ 6 - 7
EVSE/Projects/DD360UCar/Apps/CSU/main.h

@@ -12,11 +12,7 @@
 #define MAX_BUF                                 (64)
 #define SYSFS_GPIO_DIR                          "/sys/class/gpio"
 #define UPGRADE_FAN                             (0x02)
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
 #define UPGRADE_RB                              (0x09) //0x09 for DD360 dispenser
-#else
-#define UPGRADE_RB                              (0x03) //other module use
-#endif //defined DD360 ||defined DD360Audi || defined DD360ComBox
 #define UPGRADE_PRI                             (0x04)
 #define UPGRADE_AC                              (0x05)
 #define UPGRADE_LED                             (0x06)
@@ -31,11 +27,12 @@
 
 #define uSEC_VAL                                (1000000)
 #define SELFTEST_TIMEOUT                        (60)//45
+#define RETURN_VIEWPAGE_TIMEOUT                 (120)
 #define AUTHORIZE_TIMEOUT                       (30)//30
 #define BALANCE_TIMEOUT                         (15)//15
-#define AUTHORIZE_COMP_TIMEOUT                  (3)
-#define AUTHORIZE_FAIL_TIMEOUT                  (3)
+#define AUTHORIZE_FAIL_TIMEOUT                  (120)
 #define AUTHORIZE_STOP_TIMEOUT                  (30)
+#define LINKERROR_TIMEOUT						(120)
 #define RETURN_TO_CHARGING_PAGE                 (30)
 #define GUN_PREPARE_TIMEOUT                     (30)
 #define GUN_EV_WAIT_TIMEOUT                     (120)
@@ -43,7 +40,9 @@
 #define GUN_COMP_WAIT_TIMEOUT                   (10)
 #define GUN_PRECHARGING_TIMEOUT                 (60)
 #define EVCCID_LINK_TIMEOUT                     (120)
-
+#define CONN_PLUG_TIMEOUT                       (40)
+#define DETAILVIEW_TIMEOUT                      (30)
+#define TERMINATING_TIMEOUT                     (120)
 #define WHILE_LOOP_TIME                         (10000)
 
 //#define log_info(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)

+ 47 - 4
EVSE/Projects/DD360UCar/Apps/Config.h

@@ -135,7 +135,14 @@ enum _GUN_TYPE {
     _Type_GB,
     _Type_AC,
 };
-
+enum _CCS_GUN_TYPE {
+    _TYPE_CCS_NONE  = 0,
+    _TYPE_CCS1_Natural,
+    _TYPE_CCS1_Liquid,
+    _TYPE_CCS2_Natural,
+    _TYPE_CCS2_Liquid,
+};
+/*
 enum _LCM_INDEX {
     _LCM_INIT          = 0x00,
     _LCM_IDLE          = 0x01,
@@ -148,11 +155,47 @@ enum _LCM_INDEX {
     _LCM_COMPLETE      = 0x08,
     _LCM_FIX           = 0x09,
     _LCM_SELECT_GUN    = 0x0A,
-    _LCM_EMERGENCY     = 0x0B,
-    _LCM_DISCONNECT    = 0x0C,
     _LCM_NONE          = 0xFF,
 };
-
+*/
+enum _LCM_UAR_INDEX {
+
+    _LCM_VIEW                   = 0x0A,
+    _LCM_START_SCAN             = 0x01,
+    _LCM_START_AUTHORIZING      = 0x02,
+    _LCM_START_AUTHORIZE_FAIL   = 0x03,
+    _LCM_WAIT_PLUGIN            = 0x04,
+    _LCM_PRECHARGE              = 0x05,
+    _LCM_LINK_ERROR             = 0x06,
+    _LCM_DETAIL_VIEW            = 0x07,
+    _LCM_STOP_RFID              = 0x08,
+    _LCM_STOP_APP               = 0x09,
+    _LCM_STOP_RFID_FAIL         = 0x00,
+    _LCM_STOPPING               = 0x0B,
+    _LCM_WAIT_PLUGOUT           = 0x0C,
+    _LCM_SUMMARY                = 0x0D,
+    _LCM_MAINTAIN               = 0x0E,
+    _LCM_ERROR                  = 0x0F,
+
+    /*
+    _LCM_VIEW                   = _LCM_SELECT_GUN,
+    _LCM_START_SCAN             = _LCM_IDLE,
+    _LCM_START_AUTHORIZING      = _LCM_AUTHORIZING,
+    _LCM_START_AUTHORIZE_FAIL   = _LCM_AUTHORIZ_FAIL,
+    _LCM_WAIT_PLUGIN            = _LCM_WAIT_FOR_PLUG,
+    _LCM_PRECHARGE              = _LCM_PRE_CHARGE,
+    _LCM_LINK_ERROR             = _LCM_AUTHORIZ_FAIL,
+    _LCM_DETAIL_VIEW            = _LCM_SELECT_GUN,
+    _LCM_STOP_RFID              = _LCM_IDLE,
+    _LCM_STOP_APP               = _LCM_IDLE,
+    _LCM_STOP_RFID_FAIL         = _LCM_AUTHORIZ_FAIL,
+    _LCM_STOPPING               = _LCM_PRE_CHARGE,
+    _LCM_WAIT_PLUGOUT           = _LCM_WAIT_FOR_PLUG,
+    _LCM_SUMMARY                = _LCM_COMPLETE,
+    _LCM_MAINTAIN               = _LCM_FIX,
+    _LCM_ERROR                  = _LCM_FIX,
+    */
+};
 enum _SELF_TEST_SEQ {
     _STEST_VERSION      = 0x00,
     _STEST_AC_CONTACTOR = 0x01,

+ 2 - 1
EVSE/Projects/DD360UCar/Apps/DataBase/DataBase.c

@@ -117,7 +117,7 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
     #define GENERAL_GUN_QUANTITY	0
     #define PSU_QUANTITY            2
     #define ONE_CONNECTOR_USE       0
-#elif defined DD360 || defined DD360Audi || defined DD360ComBox
+#elif defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
     #define MAX_PSU_QUANTITY        62
     #define CHAdeMO_QUANTITY        2
     #define CCS_QUANTITY            2
@@ -654,6 +654,7 @@ struct ChargingInfoData
     unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
     unsigned char       Replug_flag;
     unsigned char       isEVCCIDVerify;
+    unsigned char       CCSGunType;
 };
 
 typedef union

+ 1 - 4
EVSE/Projects/DD360UCar/Apps/Log/log.c

@@ -39,7 +39,6 @@ PrimaryLib = $(TOP)/ModulePrimary
 LcmLib = $(TOP)/ModuleLcmCtrl
 DoCommLib = $(TOP)/ModuleDoComm
 EventLogLib = $(TOP)/ModuleEventLog
-SelectGunLib = $(TOP)/SelectGun
 ScriptLib = $(TOP)/Script
 
 
@@ -67,9 +66,7 @@ InfypwrPsuComm_A = $(ModularizationPath)/libInfypwr_PsuCommObj.a
 COMMON_OBJ_FILES = common.o \
 					$(DefineLib)/define.o \
 					$(ShmMemLib)/shmMem.o \
-					$(LogLib)/log.o \
-					$(SelectGunLib)/SelectGun.o \
-
+					$(LogLib)/log.o 
 
 MAIN_OBJ_FILES = $(COMMON_OBJ_FILES) $(DataBaseLib)/DataBase.o \
 					$(CSULib)/main.o  $(CSULib)/Primary.o $(CSULib)/WatchDog.o $(CSULib)/ZipFile.o \

+ 0 - 1
EVSE/Projects/DD360UCar/Apps/ModuleChkSysTask/Module_ChkSysTask.c

@@ -191,7 +191,6 @@ void CheckSystemTaskAlive()
 {
     unsigned char lostId = CheckSystemTask(ShmSysConfigAndInfo->SysInfo.SystemPage);
     if (lostId != 0) {
-        log_error("Check task(%d) lost",lostId);
         if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost == NO) {
            if (lostId == _SYSTEM_TASK_LOST_ITEM_MAIN)
                log_error("System task lost (CSU). ");

+ 18 - 20
EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.c

@@ -673,7 +673,6 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             log_info("Remote start charging plugNum = %d", plugNum);
 
-#if defined DD360Audi
             if (getSelGunWaitToAuthor(plugNum) == FAIL) {
                 log_error("Remote start gun already charging");
                 break;
@@ -687,7 +686,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     strcpy((char *)pSysConfig->UserId, "");
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                    pSysInfo->SystemPage = _LCM_VIEW;
                     GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
@@ -699,7 +698,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     strcpy((char *)pSysConfig->UserId, "");
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                    pSysInfo->SystemPage = _LCM_VIEW;
                     GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
@@ -707,10 +706,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 pSysInfo->CurGunSelected = (plugNum);
                 pSysInfo->CurGunSelectedByAc = NO_DEFINE;
             }
-#else
-            pSysInfo->CurGunSelected = (plugNum);
-            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-#endif //DD360Audi
+
             setConfirmSelGun(pSysInfo->CurGunSelected);
 
             ShmOCPP16Data->CsMsg.bits[plugNum].RemoteStartTransactionReq = YES;
@@ -728,7 +724,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             strcpy((char *)pSysConfig->UserId, "");
             pSysInfo->WaitForPlugit = NO;
-            pSysInfo->SystemPage = _LCM_SELECT_GUN;
+            pSysInfo->SystemPage = _LCM_VIEW;
             GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
             pSysInfo->SystemTimeoutFlag = Timeout_None;
             destroySelectGun(plugNum);
@@ -748,7 +744,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 ClearDetectPluginFlag();
                 strcpy((char *)pSysConfig->UserId, "");
                 pSysInfo->WaitForPlugit = NO;
-                pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                pSysInfo->SystemPage = _LCM_VIEW;
                 GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                 pSysInfo->SystemTimeoutFlag = Timeout_None;
                 destroySelectGun(plugNum);
@@ -1708,7 +1704,7 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
 #if defined DD360Audi
     gunID = gDoCommGblData.ConnectorID[pSysInfo->CurGunSelected];
     //gunID = gDoCommGblData.ConnectorID[plugNum];
-    if (pSysConfig->AuthorisationMode) {
+    if (pSysConfig->AutoAuth_Disable) {
         gunID = ID_REGISTER;
         ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
     }
@@ -2109,17 +2105,19 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         }
 
         ftime(&AuthNowTime);
-        if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
-                DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
-           ) {
-            if (readChargePermission(fd, gunID) == 0) {
-                log_info("Stop charging by power cabinet's permission = %d, %d",
-                         plugNum,
-                         REG_CHARGING_PERMISSION);
-                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
-                //printf("%d StopChargeFlag = %d\n", plugNum, pDcChargingInfo->StopChargeFlag);
+        if (pDcChargingInfo->SystemStatus != S_TERMINATING) {
+            if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
+               ) {
+                if (readChargePermission(fd, gunID) == 0) {
+                    log_info("Stop charging by power cabinet's permission = %d, %d",
+                             plugNum,
+                             REG_CHARGING_PERMISSION);
+                    pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                    //printf("%d StopChargeFlag = %d\n", plugNum, pDcChargingInfo->StopChargeFlag);
+                }
+                ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
             }
-            ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
         writeChargingTarget(fd, plugNum, gunID);
 

+ 20 - 20
EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.h

@@ -337,7 +337,7 @@ void CANReceiver(int fd)
                         log_info("Conn %d, Plugin. ", targetGun);
                         pDcChargingInfo->isEVCCIDVerify = false;
 #ifdef DD360Audi                       
-                        if (pSysConfig->isAuthrizeByEVCCID)
+                        if (pSysConfig->EVCCID_Authorize)
                             pSysInfo->CurGunSelected = targetGun;
 #endif                        
                     } else if (frame.data[0] == UNPLUG) {
@@ -644,25 +644,25 @@ void CANReceiver(int fd)
                 break;
             case ACK_EVCCID_REQ:
 
-                        if (frame.can_dlc > 0 && strcmp ( (char *)pDcChargingInfo->EVCCID, "" ) == EQUAL &&
-                            pDcChargingInfo->Type == _Type_CCS_2)
-                        {
-                            {
-                                memset (
-                                        ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
-                                        0,
-                                        sizeof(ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID) );
-                                memcpy (
-                                        ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
-                                        frame.data, frame.can_dlc );
-                            }
-
-                            sprintf ( (char *) pDcChargingInfo->EVCCID, "%.2x%.2x%.2x%.2x%.2x%.2x", frame.data [0],
-                                    frame.data [1], frame.data [2], frame.data [3], frame.data [4], frame.data [5] );
-
-                            pDcChargingInfo->EVCCID [17] = '\0';
-                            log_info( "************* Gun %d->EVCCID = %s ************* ", targetGun, pDcChargingInfo->EVCCID );
-                        }
+                if (frame.can_dlc > 0 && strcmp ( (char *)pDcChargingInfo->EVCCID, "" ) == EQUAL &&
+                    pDcChargingInfo->Type == _Type_CCS_2)
+                {
+                    {
+                        memset (
+                                ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
+                                0,
+                                sizeof(ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID) );
+                        memcpy (
+                                ShmCcsData->V2GMessage_DIN70121 [pDcChargingInfo->type_index].SessionSetupRequest.EVCCID,
+                                frame.data, frame.can_dlc );
+                    }
+
+                    sprintf ( (char *) pDcChargingInfo->EVCCID, "%.2x%.2x%.2x%.2x%.2x%.2x", frame.data [0],
+                            frame.data [1], frame.data [2], frame.data [3], frame.data [4], frame.data [5] );
+
+                    pDcChargingInfo->EVCCID [17] = '\0';
+                    log_info( "Gun %d->EVCCID = %s ", targetGun, pDcChargingInfo->EVCCID );
+                }
                 break;
             default:
                 log_info("EV board = %d, Ack none defined. intCmd = %d  ", targetGun, intCmd);

+ 29 - 29
EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -302,6 +302,29 @@ static void setCurrentOutput(void)
     }
 }
 
+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 SetPresentChargingOutputCap(void)
 {
     float pow1 = 0, cur1 = 0;
@@ -317,17 +340,17 @@ static void SetPresentChargingOutputCap(void)
         chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
     }
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     float vol = 0;
 #endif //!defined DD360 && !defined DD360Audi
 
     pow1 = chargingData_1->AvailableChargingPower;
     cur1 = chargingData_1->AvailableChargingCurrent;
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     vol = chargingData_1->MaximumChargingVoltage;
     GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
-    GetMaxPowerMethod(chargingData_1->Index, &pow1);
+    //GetMaxPowerMethod(chargingData_1->Index, &pow1);
 #endif //!defined DD360 && !defined DD360Audi
 
     //DS60-120 add
@@ -349,10 +372,10 @@ static void SetPresentChargingOutputCap(void)
     pow2 = chargingData_2->AvailableChargingPower;
     cur2 = chargingData_2->AvailableChargingCurrent;
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     vol = chargingData_2->MaximumChargingVoltage;
     GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
-    GetMaxPowerMethod(chargingData_2->Index, &pow2);
+    //GetMaxPowerMethod(chargingData_2->Index, &pow2);
 #endif //!defined DD360 && !defined DD360Audi
 
     //DS60-120 add
@@ -402,29 +425,6 @@ static void SetPresentChargingOutputCap(void)
     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 uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
 {
     PcPsuOutput *pPcPsuOutput = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[gunIndex];
@@ -782,7 +782,7 @@ int main(int argc, char *argv[])
                 if (pDcChargingInfo->Type == _Type_Chademo) {
 
                     ClearAbnormalStatus_Chademo(gunIndex);
-                    if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
+                    if (pSysInfo->PageIndex == _LCM_WAIT_PLUGIN) {
                         if (!chkChademoPermission[gunIndex]) {
                             chkChademoPermission[gunIndex] = true;
                             gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);

+ 3 - 3
EVSE/Projects/DD360UCar/Apps/ModuleEventLog/Module_EventLogging.c

@@ -363,8 +363,8 @@ void AcPlugTask(int uartFD)
         } else if ((acStatus.CpStatus == AC_SYS_B || pAcChargingInfo->ConnectorPlugIn == AC_SYS_B) &&
                    pAcChargingInfo->IsAvailable &&
                    !pAcChargingInfo->IsErrorOccur &&
-                   (pSysInfo->WaitForPlugit == YES /*||
-                    pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE*/)) {
+                   (pSysInfo->WaitForPlugit == YES ||
+                    pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE)) {
             if (pAcChargingInfo->RemoteStartFlag == YES) {
                 log_info("** AC Remote \n");
                 pAcChargingInfo->RemoteStartFlag = NO;
@@ -409,7 +409,7 @@ void AcPlugTask(int uartFD)
         break;
         case S_PREPARNING: {
             if (isModeChange()) {
-                pSysInfo->SystemPage = _LCM_NONE;
+                pSysInfo->SystemPage = _LCM_VIEW;
                 pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
                 if (pSysInfo->OrderCharging != NO_DEFINE) {
                     pSysInfo->OrderCharging = NO_DEFINE;

+ 0 - 2488
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/FanBoard.c

@@ -1,2488 +0,0 @@
-#include <sys/time.h>
-#include <sys/timeb.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/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;
-}

+ 17 - 17
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/RelayBoard.c

@@ -142,7 +142,7 @@ static bool IsNoneMatchRelayStatus(void)
     bool result = false;
 
     if (
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
         (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
@@ -150,7 +150,7 @@ static bool IsNoneMatchRelayStatus(void)
         (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
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
         ||
         (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)
@@ -159,7 +159,7 @@ static bool IsNoneMatchRelayStatus(void)
         result = true;
     }
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) {
         log_info("AC Contact Relay none match. ");
     }
@@ -197,7 +197,7 @@ static bool IsNoneMatchRelayStatus(void)
         StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
     }
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) {
         //log_info("Parallel:D+ Relay none match. ");
         StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
@@ -218,7 +218,7 @@ static bool IsNoneMatchRelayStatus(void)
 
 static void SetParalleRelayStatus(void)
 {
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
     return;
 #endif //!defined  DD360 || !defined DD360Audi || !defined DD360ComBox
 
@@ -599,7 +599,7 @@ void SetK1K2RelayStatus(uint8_t index)
         break;
 
     case S_CCS_PRECHARGE_ST0:
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
         break;
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
@@ -617,7 +617,7 @@ void SetK1K2RelayStatus(uint8_t index)
         break;
 
     case S_CCS_PRECHARGE_ST1:
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
         break;
 #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
@@ -653,7 +653,7 @@ void CheckK1K2RelayOutput(uint8_t index)
         }
 
         if (pDcChargingInfo->Type == _Type_CCS_2) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
             if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES) {
                 pDcChargingInfo->RelayKPK2Status = YES;
             } else {
@@ -678,7 +678,7 @@ void CheckK1K2RelayOutput(uint8_t index)
         }
 
         if (pDcChargingInfo->Type == _Type_CCS_2) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
             if (regRelay.relay_event.bits.Gun2_N == YES &&
                     regRelay.relay_event.bits.CCS_Precharge == YES) {
                 pDcChargingInfo->RelayKPK2Status = YES;
@@ -696,7 +696,7 @@ void CheckK1K2RelayOutput(uint8_t index)
         break;
     }
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     //DS60-120 add
     if (pSysInfo->BridgeRelayStatus == YES) {
         if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
@@ -798,7 +798,7 @@ void CableCheckDetected(uint8_t index)
 void GetRelayOutputStatus(void)
 {
     if (Query_Relay_Output(Uart5Fd, ADDR_RELAY, &regRelay) == PASS) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
         regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
 #endif //!defined DD360 && !defined DD360Audi
     }
@@ -1050,7 +1050,7 @@ void GetPersentOutputVol(void)
 
         switch (targetID) {
         case 0x01:
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
             pDcChargingInfo->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
             pDcChargingInfo->PresentChargingCurrent = ((float)ShmRelayModuleData->Gun1FuseOutputVolt) / 10;
             pDcChargingInfo->PresentChargingVoltage = ((float)pDcChargingInfo->FireChargingVoltage) / 10;
@@ -1624,7 +1624,7 @@ static void LEDBoardSelfTest(void)
         return;
     }
 
-#if defined DD360 ||defined DD360Audi
+#if defined DD360 ||defined DD360Audi || defined DD360UCar
     GetFwAndHwVersion_Led();
     sleep(1);
     gettimeofday(&_led_priority_time, NULL);
@@ -1740,7 +1740,7 @@ void RelayBoardTask(int uartFD)
                 // 輸出電壓
                 GetPersentOutputVol();
 
-    #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+    #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
                 // 三相輸入電壓
                 GetPresentInputVol();
     #endif //!defined DD360 && !defined DD360Audi
@@ -1764,7 +1764,7 @@ void RelayBoardTask(int uartFD)
                     // 依據當前各槍的狀態選擇 搭上/放開 Relay
                     SetK1K2RelayStatus(i);
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
                     if (pSysConfig->PhaseLossPolicy == YES) {
                         CheckPhaseLossStatus(i);
                     }
@@ -1787,8 +1787,8 @@ void RelayBoardTask(int uartFD)
                             (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)
+                            (pSysInfo->PageIndex >=  _LCM_START_AUTHORIZING &&
+                             pSysInfo->PageIndex <= _LCM_WAIT_PLUGIN)
                        ) {
                         pDcChargingInfo->IsReadyToCharging = YES;
                         isCharging = true;

+ 1 - 1
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/internalComm.h

@@ -15,7 +15,7 @@
 //address
 #define ADDR_AUX                                (0x01)
 #define ADDR_FAN                                (0x02)
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
 #define ADDR_RELAY                              (0x09)
 #else
 #define ADDR_RELAY                              (0x03)

+ 108 - 150
EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -48,13 +48,9 @@ uint8_t ac_ani_battery_level    = _BATTERY_LEVEL_FOR_MAP_LV5;
 uint8_t isDiffStatus            = false;
 uint8_t isChangeBattMap         = false;
 // 當前選擇的槍號
-#if defined DD360Audi
-short _currentPage              = _LCM_SELECT_GUN;
-short _oldPage                  = _LCM_SELECT_GUN;
-#else
-short _currentPage              = _LCM_NONE;
-short _oldPage                  = _LCM_NONE;
-#endif //defined DD360Audi
+short _currentPage              = _LCM_VIEW;
+short _oldPage                  = _LCM_VIEW;
+
 uint8_t _gunIndex               = 0;
 bool _wifi_conn_status          = false;
 bool _battery_display_ani       = false;
@@ -225,21 +221,9 @@ uint8_t _select_gun_btn         = 70;
 uint8_t _emergency_disable_map  = 72;
 // For replug
 struct timespec showReplugStrTimer;
-struct timespec showFullTargetTimer;
-short __show_StatusString_value_1 = 0x0460;
-short __show_StatusString_value_2 = 0x0462;
-uint8_t _showfulltarget_1       = 73;
-uint8_t _showfulltarget_2       = 74;
-uint8_t _showReplugStr_1        = 75;
-uint8_t _showReplugStr_2        = 76;
-// Select Gun for Audi
-short __show_selectgun_value    = 0x0464;
-uint8_t _showselectgun_left     = 77;
-uint8_t _showselectgun_right    = 78;
-// Wait for gun plugin Audi
-short __show_waitgunplug_value    = 0x0468;
-uint8_t _showwaitgunplug_left     = 80;
-uint8_t _showwaitgunplug_right    = 81;
+short __show_replugString_value = 0x0460;
+uint8_t _showReplugStr_1 = 74;
+uint8_t _showReplugStr_2 = 75;
 
 //#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)
@@ -813,17 +797,17 @@ void DemoFunction()
         memcpy(&pSysWarning->WarningCode[5][0], "000006", 7);
     } else {
         if (demoCount == 20) {
-            pSysInfo->PageIndex = _LCM_IDLE;
+            pSysInfo->PageIndex = _LCM_VIEW;
         } else if (demoCount == 80) {
-            pSysInfo->PageIndex = _LCM_AUTHORIZING;
+            pSysInfo->PageIndex = _LCM_START_AUTHORIZING;
         } else if (demoCount == 100) {
-            pSysInfo->PageIndex = _LCM_AUTHORIZ_COMP;
+            //pSysInfo->PageIndex = _LCM_AUTHORIZ_COMP;
         } else if (demoCount == 120) {
-            pSysInfo->PageIndex = _LCM_AUTHORIZ_FAIL;
+            pSysInfo->PageIndex = _LCM_WAIT_PLUGIN;
         } else if (demoCount == 140) {
-            pSysInfo->PageIndex = _LCM_PRE_CHARGE;
+            pSysInfo->PageIndex =  _LCM_LINK_ERROR;
         } else if (demoCount == 180) {
-            pSysInfo->PageIndex = _LCM_CHARGING;
+            pSysInfo->PageIndex = _LCM_DETAIL_VIEW;
         }
     }
 
@@ -886,37 +870,14 @@ void RunReplugStringFunction(bool isRun)
     if (isRun) {
         int time = GetTimeoutValue(&showReplugStrTimer);
         if (time >=1 && time <2) {
-            ChangeDisplay2Value(__show_StatusString_value_1, _showReplugStr_1);
-            ChangeDisplay2Value(__show_StatusString_value_2, _showReplugStr_2);
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_1);
         } else if (time < 1) {
-            ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
-            ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
+            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_2);
         } else
             GetTimespecFunc(&showReplugStrTimer);
 
-    } else {
-        ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
-        ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
-    }
-}
-void RunFullTargetFunction(bool isRun)
-{
-    if (isRun) {
-        int time = GetTimeoutValue(&showFullTargetTimer);
-        if (time >=1 && time <2) {
-            ChangeDisplay2Value(__show_StatusString_value_1, _showfulltarget_1 );
-            ChangeDisplay2Value(__show_StatusString_value_2, _showfulltarget_2);
-        } else if (time < 1) {
-            ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
-            ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
-
-        } else
-            GetTimespecFunc(&showFullTargetTimer);
-
-    } else {
-        ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
-        ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
-    }
+    } else
+        ChangeDisplay2Value(__show_replugString_value, _disappear);
 }
 
 /**
@@ -951,7 +912,7 @@ void ChangeAcBattMapAndValue(short page)
 {
     pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
 
-    if (page == _LCM_CHARGING) {
+    if (page == _LCM_VIEW) {
         if (isDiffStatus != _battery_display_ani) {
             isChangeBattMap = false;
             isDiffStatus = _battery_display_ani;
@@ -979,7 +940,7 @@ void ChangeAcBattMapAndValue(short page)
                 ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
             }
         }
-    } else if (page == _LCM_COMPLETE) {
+    } else if (page == _LCM_SUMMARY) {
         if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
             ChangeDisplay2Value(__batt_map, _battery_soc_20);
         } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
@@ -1005,9 +966,9 @@ void ChangeBattMapAndValue(short page, int soc)
 //  int max = 90;
 //  soc = rand() % (max - min + 1) + min;
 
-    if (page == _LCM_PRE_CHARGE) {
+    if (page == _LCM_PRECHARGE) {
         ChangeDisplay2Value(__batt_map_empty, _battery_empty);
-    } else if (page == _LCM_CHARGING) {
+    } else if (page == _LCM_VIEW) {
         if (soc < 20) {
             if (_battery_display_ani) {
                 ChangeDisplay2Value(__batt_map, _battery_empty);
@@ -1039,7 +1000,7 @@ void ChangeBattMapAndValue(short page, int soc)
                 ChangeDisplay2Value(__batt_map, _battery_cap_100);
             }
         }
-    } else if (page == _LCM_COMPLETE) {
+    } else if (page == _LCM_SUMMARY) {
         if (soc < 20) {
             ChangeDisplay2Value(__batt_map, _battery_soc_20);
         } else if (soc >= 20 && soc < 40) {
@@ -1154,11 +1115,11 @@ void DisplayMoneyCur(uint8_t *cur)
 void RefreshPageAnimation(uint8_t value)
 {
     switch (_currentPage) {
-    case _LCM_IDLE: {
+    case _LCM_VIEW: {
 
     }
     break;
-    case _LCM_WAIT_FOR_PLUG: {
+    case _LCM_WAIT_PLUGIN: {
         if (_everyPageRollChange == 0) {
             ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
         } else if (_everyPageRollChange == 15) {
@@ -1168,22 +1129,21 @@ void RefreshPageAnimation(uint8_t value)
         _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
     }
     break;
-    case _LCM_PRE_CHARGE:
-    case _LCM_CHARGING:
-    case _LCM_COMPLETE: {
-        if (_currentPage == _LCM_PRE_CHARGE) {
+    case _LCM_PRECHARGE:
+    case _LCM_SUMMARY: {
+        if (_currentPage == _LCM_PRECHARGE) {
             if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
                 ChangeDisplay2Value(__conn_line, _conn_map1);
             } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
                 ChangeDisplay2Value(__conn_line, _conn_map2);
             }
-        } else if (_currentPage == _LCM_CHARGING) {
+        } else if (_currentPage == _LCM_VIEW) {
             if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
                 ChangeDisplay2Value(__conn_line_chag, _charging_map1);
             } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
                 ChangeDisplay2Value(__conn_line_chag, _charging_map2);
             }
-        } else if (_currentPage == _LCM_COMPLETE) {
+        } else if (_currentPage == _LCM_SUMMARY) {
             if (_everyPageRollChange == 0) {
                 ChangeDisplay2Value(__conn_line_comp, _complete_map);
             }
@@ -1198,13 +1158,13 @@ void RefreshPageAnimation(uint8_t value)
 void RefreshConnStatus()
 {
     // Wifi priority is higher than Ethernet
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+#if defined DD360 ||defined DD360Audi || defined DD360ComBox || defined DD360UCar
     uint8_t i = 0;
-    uint8_t ethstatus = 0;
+    uint8_t ehtStatus = 0;
 
     for (i = 0; i < pSysWarning->WarningCount; i++) {
         if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
-            ethstatus = 1;
+            ehtStatus = 1;
             //if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             //    ShmSelectGunInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
             //}
@@ -1220,7 +1180,7 @@ void RefreshConnStatus()
         ChangeDisplay2Value(__conn_status, _disconnect);
     }
 
-    if (ethstatus == 1) {
+    if (ehtStatus == 1) {
         if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
         }
@@ -1352,12 +1312,40 @@ void RefreshConnStatus()
     */
 #else
 // eth
+    /*
     if (pSysInfo->ethInternetConn == YES) {
         ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
     } else {
         ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
     }
+    */
+    uint8_t ehtStatus = 0;
+    int i;
+    for (i = 0; i < pSysWarning->WarningCount; i++) {
+        if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
+            ehtStatus = 1;
+            //if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+            //    ShmSelectGunInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
+            //}
+            break;
+        }
+    }
 
+    if (ehtStatus == 1) {
+        if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+            ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
+        }
+    } else {
+        if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
+            ChangeDisplay2Value(__ethernet_status, _eth_connect);
+        }
+        //if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_DISABLE) {
+        //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_USE) {
+        //    ChangeDisplay2Value(__ethernet_status, _eth_connect);
+        //} else if (ShmSelectGunInfo->EthDevStatus.Ethernet == DEV_ST_ENABLE_NO_USE) {
+        //    ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
+        //}
+    }
     // Wifi
     if ((pSysConfig->ModelName[10] == 'W' ||
             pSysConfig->ModelName[10] == 'D') &&
@@ -1743,9 +1731,6 @@ void ProcessPageInfo()
 {
     _page_reload = IsPageReloadChk();
     pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
-    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
-    uint8_t i;
 
     // 隨插即充 - 可省略該按鈕 //DS60-120 add
     if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
@@ -1758,8 +1743,8 @@ void ProcessPageInfo()
     }
 
     switch (_currentPage) {
-#if defined DD360Audi
-    case _LCM_SELECT_GUN: ////For Audi
+    case _LCM_VIEW: ////For Audi
+    case _LCM_DETAIL_VIEW:
         if (pSysInfo->CurGunSelected == 0) {
             ChangeDisplay2Value(__left_gun_map, _left_gun_enable_map);
             ChangeDisplay2Value(__right_gun_map, _right_gun_disable_map);
@@ -1769,9 +1754,10 @@ void ProcessPageInfo()
         }
         ChangeDisplay2Value(__add_chk_btn, _select_gun_btn);
         break;
-#endif //defined DD360Audi
 
-    case _LCM_IDLE: {
+    case _LCM_START_SCAN:
+    case _LCM_STOP_RFID:
+    case _LCM_STOP_APP:
         if (pSysConfig->isRFID) {
             ChangeDisplay2Value(__main_rfid, _main_rfid);
         } else {
@@ -1791,12 +1777,7 @@ void ProcessPageInfo()
         } else {
             ChangeDisplay2Value(__main_app, _main_none_app);
         }
-#if defined DD360Audi
-        if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
-            ChangeDisplay2Value(__show_selectgun_value, _showselectgun_left);
-        else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
-            ChangeDisplay2Value(__show_selectgun_value, _showselectgun_right);
-#endif
+
         //if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
         if (pSysConfig->isQRCode) {
             needReloadQr = false;
@@ -1828,27 +1809,16 @@ void ProcessPageInfo()
         } else {
             ChangeDisplay2Value(__sel_gun_btn, _disappear);
         }
-    }
-    break;
-    case _LCM_AUTHORIZING:
-    case _LCM_AUTHORIZ_COMP:
-    case _LCM_AUTHORIZ_FAIL: {
+        break;
+    case _LCM_START_AUTHORIZING:
+    case _LCM_START_AUTHORIZE_FAIL:
+    case _LCM_STOP_RFID_FAIL:
+    case _LCM_LINK_ERROR:
         //case _LCM_WAIT_FOR_PLUG: {
         FirstPageChanged();
-#if defined DD360Audi
-        if (_currentPage == _LCM_AUTHORIZ_COMP) { ////For Audi
-            ChangeBalanceValue(__balance, pSysInfo->CurGunSelected);
-        }
-#endif //defined DD360Audi
-    }
-    break;
-    case _LCM_WAIT_FOR_PLUG: {
- #if defined DD360Audi
-        if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
-            ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_left);
-        else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
-            ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_right);
-#endif
+        break;
+    case _LCM_WAIT_PLUGIN:
+    case _LCM_WAIT_PLUGOUT:
         FirstPageChanged();
         if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
             // 新增隨插即充功能預設在等待插槍頁面在開啟
@@ -1873,11 +1843,10 @@ void ProcessPageInfo()
         } else {
             ChangeDisplay2Value(__sel_gun_btn, _disappear);
         }
-    }
-    break;
-    case _LCM_PRE_CHARGE:
-    case _LCM_CHARGING:
-    case _LCM_COMPLETE: {
+        break;
+    case _LCM_PRECHARGE:
+    case _LCM_STOPPING:
+    case _LCM_SUMMARY: {
         bool isShowAc = false;
         uint8_t gunTargetIndex = 0;
 
@@ -1886,14 +1855,14 @@ void ProcessPageInfo()
             if (pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
                 isShowAc = true;
                 //ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_light); //DS60-120 remove
-                if (_currentPage == _LCM_COMPLETE) {
+                if (_currentPage == _LCM_SUMMARY) {
                     ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_light_cmp);
                 } else {
                     ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_light);
                 }
 
-                if (_currentPage == _LCM_CHARGING) {
-                    ChangeAcBattMapAndValue(_LCM_CHARGING);
+                if (_currentPage == _LCM_VIEW) {
+                    ChangeAcBattMapAndValue(_LCM_VIEW);
                     if (pAcChargingInfo->PresentChargedDuration >= 0 &&
                             pAcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
                         ChangeRemainTime(pAcChargingInfo->PresentChargedDuration);
@@ -1921,8 +1890,8 @@ void ProcessPageInfo()
                     } else {
                         ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
                     }
-                } else if (_currentPage == _LCM_COMPLETE) {
-                    ChangeAcBattMapAndValue(_LCM_COMPLETE);
+                } else if (_currentPage == _LCM_SUMMARY) {
+                    ChangeAcBattMapAndValue(_LCM_SUMMARY);
                     if (pAcChargingInfo->PresentChargedDuration >= 0 &&
                             pAcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
                         ChangeRemainTime(pAcChargingInfo->PresentChargedDuration);
@@ -1961,7 +1930,7 @@ void ProcessPageInfo()
                 }
             } else {
                 //ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_dark); //DS60-120 remove
-                if (_currentPage == _LCM_COMPLETE) {
+                if (_currentPage == _LCM_SUMMARY) {
                     ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_dark_cmp);
                 } else {
                     ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_dark);
@@ -1989,13 +1958,13 @@ void ProcessPageInfo()
             switch (pDcChargingInfo->Type) {
             case _Type_Chademo: {
                 if (pSysInfo->CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
+                    if (_currentPage == _LCM_SUMMARY) {
                         ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_light_cmp);
                     } else {
                         ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
                     }
                 } else {
-                    if (_currentPage == _LCM_COMPLETE) {
+                    if (_currentPage == _LCM_SUMMARY) {
                         ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_dark_cmp);
                     } else {
                         ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
@@ -2005,13 +1974,13 @@ void ProcessPageInfo()
             break;
             case _Type_GB: {
                 if (pSysInfo->CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
+                    if (_currentPage == _LCM_SUMMARY) {
                         ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_light_cmp);
                     } else {
                         ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
                     }
                 } else {
-                    if (_currentPage == _LCM_COMPLETE) {
+                    if (_currentPage == _LCM_SUMMARY) {
                         ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_dark_cmp);
                     } else {
                         ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
@@ -2021,13 +1990,13 @@ void ProcessPageInfo()
             break;
             case _Type_CCS_2: {
                 if (pSysInfo->CurGunSelected == i && !isShowAc) {
-                    if (_currentPage == _LCM_COMPLETE) {
+                    if (_currentPage == _LCM_SUMMARY) {
                         ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_light_cmp);
                     } else {
                         ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
                     }
                 } else {
-                    if (_currentPage == _LCM_COMPLETE) {
+                    if (_currentPage == _LCM_SUMMARY) {
                         ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_dark_cmp);
                     } else {
                         ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
@@ -2037,13 +2006,13 @@ void ProcessPageInfo()
             break;
             }
 
-            if (_currentPage == _LCM_PRE_CHARGE && !isShowAc) {
+            if (_currentPage == _LCM_PRECHARGE && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
                     ChangeBattMapAndValue(_currentPage, pDcChargingInfo->EvBatterySoc);
                 }
-            } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
+            } else if (_currentPage == _LCM_VIEW && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
-                    ChangeBattMapAndValue(_LCM_CHARGING, pDcChargingInfo->EvBatterySoc);
+                    ChangeBattMapAndValue(_LCM_VIEW, pDcChargingInfo->EvBatterySoc);
                     if (pDcChargingInfo->PresentChargedDuration >= 0 &&
                             pDcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
                         ChangeRemainTime(pDcChargingInfo->PresentChargedDuration);
@@ -2072,9 +2041,9 @@ void ProcessPageInfo()
                         ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
                     }
                 }
-            } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
+            } else if (_currentPage == _LCM_SUMMARY && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
-                    ChangeBattMapAndValue(_LCM_COMPLETE, pDcChargingInfo->EvBatterySoc);
+                    ChangeBattMapAndValue(_LCM_SUMMARY, pDcChargingInfo->EvBatterySoc);
                     if (pDcChargingInfo->PresentChargedDuration >= 0 &&
                             pDcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
                         ChangeRemainTime(pDcChargingInfo->PresentChargedDuration);
@@ -2122,16 +2091,12 @@ void ProcessPageInfo()
                     }
 #ifdef DD360Audi
                     // Warming Occur in prepare or precharing state, turn into complete mode
-                    if (pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason) {
-                        RunFullTargetFunction(true);
+                    if (pDcChargingInfo->Replug_flag) {
+                        RunReplugStringFunction(true);
                     } else {
-                        RunFullTargetFunction(false);
-                        if (pDcChargingInfo->Replug_flag) {
-                            RunReplugStringFunction(true);
-                        } else {
-                            RunReplugStringFunction(false);
-                        }
+                        RunReplugStringFunction(false);
                     }
+#else
 #endif					
                 }
             }
@@ -2168,23 +2133,15 @@ void ProcessPageInfo()
         }
     }
     break;
-    case _LCM_FIX:
-#if defined DD360Audi
-        // For Emergency Button
+
+    case _LCM_ERROR:
+    case _LCM_MAINTAIN:
+        // AUDI_LCM_CHANGE
         if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
-            ChangeToOtherPage(_LCM_EMERGENCY);
-            break;
-        }
-        // For Network Disconnect
-        for (i = 0; i < pSysWarning->WarningCount; i++) {
-            if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0 || 
-                memcmp(&pSysWarning->WarningCode[i][0], "042304", 6) == 0) {
-                ChangeToOtherPage(_LCM_DISCONNECT);
-            break;
-            }
+            ChangeDisplay2Value(_emergency_map, _emergency_disable_map);
+        } else {
+            ChangeDisplay2Value(_emergency_map, _disappear);
         }
-#endif
-
         break;
     }
 }
@@ -2356,6 +2313,7 @@ int main(void)
 
                 ChangeWarningFunc();
             }
+
             // 頁面資訊處理
             ProcessPageInfo();
 
@@ -2384,7 +2342,7 @@ int main(void)
     }
 
 #ifndef DD360ComBox
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
 #endif
     log_info("Close LCM Uart Port");
     CloseCommunicationLcmPort();

+ 10 - 211
EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -53,108 +53,6 @@ uint8_t Door_count = 0;
 uint8_t EmgBtn_flag = 0;
 uint8_t Door_flag = 0;
 
-//struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-//------------------------------------------------------------------------------
-/*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 (pSysConfig->SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s ", 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;
-}
-*/
-
-#if 0 //non use
-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;
-}
-
-//=================================
-// Common routine
-//=================================
-char *getTimeString(void)
-{
-    char *result = malloc(21);
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]",
-            (1900 + p->tm_year),
-            (1 + p->tm_mon),
-            p->tm_mday,
-            p->tm_hour,
-            p->tm_hour,
-            p->tm_sec);
-
-    return result;
-}
-#endif //0
-
-//==========================================
-// Init all share memory
-//==========================================
-/*int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //creat ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    return result;
-}
-*/
 
 //================================================
 // Function
@@ -185,9 +83,7 @@ void GetInputGpioStatus(int fd)
     }
 
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-#ifdef DD360ComBox
-    EmgBtn_flag = 0;
-#else
+
     if (gpio_in.Emergency_Btn && (EmgBtn_flag != gpio_in.Emergency_Btn))
     {
             EmgBtn_count++;
@@ -202,7 +98,7 @@ void GetInputGpioStatus(int fd)
             EmgBtn_count = 0;
         }
     }
-#endif
+
     ShmPrimaryMcuData->InputDet.bits.EmergencyButton = EmgBtn_flag;
 
     dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
@@ -223,7 +119,7 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
     ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
 
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+
     if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
             (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
             (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
@@ -236,16 +132,13 @@ void GetInputGpioStatus(int fd)
         pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
     }
 
-#if defined DD360ComBox
-    Door_flag = 0;
-#else
     if (Door_flag == gpio_in.Door_Open) {
         Door_count++;
         if (Door_count == 3 ) {
             Door_count = 0;
             Door_flag = gpio_in.Door_Open;
         }
-    } else { 
+    } else {
         Door_flag = gpio_in.Door_Open;
         Door_count = 0;
     }
@@ -265,12 +158,10 @@ void GetInputGpioStatus(int fd)
         }
     }
     */
-#endif 
-#if defined DD360ComBox
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = Door_flag;
-#else
+
+
     ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~Door_flag;
-#endif
+
 
 /*
     log_info("Emergency Button Count = %d , Emergency flag = %d",
@@ -285,56 +176,8 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
 
     return;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
-
-    static uint8_t _curDeviceStatus[3] = {0};
-    static uint8_t _reCheckCount[3] = {0};
-
-    //DS60-120 add
-    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
-        if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
-            _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
-            pSysInfo->AcContactorStatus =
-                ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
-                    gpio_in.AC_Connector;
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
-        }
-    } else {
-        _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
-    }
 
-    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
-        if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
-            _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
-            ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
-        }
-    } else {
-        _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
-    }
-    //pSysInfo->AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-    //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-
-    ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-
-    /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d",
-    ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-    ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-    printf("pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d", pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-    printf("pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d", pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-    */
-    //log_info("left = %d ", ShmPrimaryMcuData->InputDet.bits.Button1);
-    //log_info("right = %d ", ShmPrimaryMcuData->InputDet.bits.Button2);
-    //log_info("pSysInfo->AcContactorStatus = %d ", pSysInfo->AcContactorStatus);
-    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
-        log_error("AC Mainbreaker occur. ");
-    }
+
 }
 
 static void checkChillerStatus(Gpio_out *gpio)
@@ -386,7 +229,7 @@ static void checkChillerStatus(Gpio_out *gpio)
                 pChillerInfo->ChillerSwitch = NO;
             }
         }
-#if 0
+/*
         if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
             pChillerInfo->ChillerSwitch = YES;
             pChillerInfo->ChillerOnTime = time((time_t *)NULL);
@@ -406,7 +249,7 @@ static void checkChillerStatus(Gpio_out *gpio)
                 pChillerInfo->ChillerSwitch = NO;
             }
         }
-#endif
+*/
     }
 
     uint8_t _chillerNeedOn = NO;
@@ -522,9 +365,7 @@ int InitComPort()
 
     fd = open(priPortName, O_RDWR);
     if (fd <= 0) {
-#ifdef SystemLogMessage
         log_error("open 407 Communication port NG ");
-#endif
         return -1;
     }
     ioctl (fd, TCGETS, &tios);
@@ -549,48 +390,6 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
-//int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-//{
-//    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
-//        if (pSysInfo->ChademoChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->ChademoChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
-//        if (pSysInfo->CcsChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->CcsChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
-//        if (pSysInfo->GbChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->GbChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    return 0;
-//}
-
-//void Initialization() //DS60-120 add
-//{
-//    bool isPass = false;
-//    while (!isPass) {
-//        isPass = true;
-//        for (uint8_t _index = 0; _index < gun_count; _index++) {
-//            if (!FindChargingInfoData(_index, &ChargingData[0])) {
-//                log_error("EvComm (main) : FindChargingInfoData false ");
-//                isPass = false;
-//                break;
-//            }
-//        }
-//        sleep(1);
-//    }
-//}
-
 static bool IsPrimaryProcessNeedPause(void)
 {
     bool _pause = false;

+ 8 - 25
EVSE/Projects/DD360UCar/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -20,11 +20,7 @@ struct ChargingInfoData *pAcChargingInfo = NULL;
 static struct ChargingInfoData *pDcChargingInfo = NULL;
 #define MODELNAME_FAIL                          (0)
 #define UPGRADE_FAN                             (0x02)
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
 #define UPGRADE_RB                              (0x09) //0x09 for DD360 dispenser
-#else
-#define UPGRADE_RB                              (0x03) //other module use
-#endif //defined DD360 ||defined DD360Audi || defined DD360ComBox
 #define UPGRADE_PRI                             (0x04)
 #define UPGRADE_AC                              (0x05)
 #define UPGRADE_LED                             (0x06)
@@ -37,28 +33,20 @@ static char *_485PortName = "/dev/ttyS5";
 
 void KillAllTask(void)
 {
-    pSysInfo->PageIndex = _LCM_FIX;
+    pSysInfo->PageIndex = _LCM_MAINTAIN;
 
     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_DoComm");
     return ;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
-
-    system("killall Module_PsuComm");
-    system("killall OcppBackend &");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
 }
 
 void KillTask(void)
 {
-    pSysInfo->PageIndex = _LCM_FIX;
+    pSysInfo->PageIndex = _LCM_MAINTAIN;
 
     system("killall Module_EventLogging");
     system("killall Module_PrimaryComm");
@@ -66,14 +54,8 @@ void KillTask(void)
     system("killall Module_LcmControl");
     system("killall Module_InternalComm");
     //system("killall Module_DoComm");
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
     return ;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
 
-    system("killall Module_PsuComm");
-    system("killall OcppBackend &");
-    system("killall Module_4g &");
-    system("killall Module_Wifi &");
 }
 void setChargerMode(uint8_t gunIndex, uint8_t mode)
 {
@@ -128,12 +110,13 @@ bool IsConnectorWholeIdle()
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
 
         if (pDcChargingInfo->SystemStatus != S_IDLE &&
-                pDcChargingInfo->SystemStatus != S_RESERVATION) {
+                pDcChargingInfo->SystemStatus != S_RESERVATION &&
+                pDcChargingInfo->SystemStatus != S_MAINTAIN) {
             result = false;
             break;
         }
     }
-
+/*
     for (uint8_t count = 0; count < pSysConfig->AcConnectorCount; count++) {
         pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
 
@@ -143,7 +126,7 @@ bool IsConnectorWholeIdle()
             break;
         }
     }
-
+*/
     return result;
 }
 
@@ -417,7 +400,7 @@ void CheckFwUpdateFunction(void)
     if (pSysInfo->FirmwareUpdate == YES) {
         log_info("ftp : update start. ");
         TryCloseWatchdog();
-        pSysInfo->SystemPage = _LCM_FIX;
+        pSysInfo->SystemPage = _LCM_MAINTAIN;
         for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
             setChargerMode(gun_index, MODE_UPDATE);
         }
@@ -502,7 +485,7 @@ int main(int argc, char *argv[])
     ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
    
     while (1) {
-        if (IsConnectorWholeIdle() || (pSysInfo->PageIndex == _LCM_FIX) )
+        if (IsConnectorWholeIdle())
             CheckFwUpdateFunction();
         sleep(3);
     } //while

+ 1427 - 1468
EVSE/Projects/DD360UCar/Apps/ReadCmdline.c

@@ -1,1468 +1,1427 @@
-/*
- * Main.c
- *
- *  Created on: 2019年8月6日
- *      Author: 7564
- */
-
-
-#include <sys/time.h>
-#include <sys/timeb.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/shm.h>
-#include <sys/mman.h>
-#include <linux/wireless.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdio.h>      /*標準輸入輸出定義*/
-#include <stdlib.h>     /*標準函數庫定義*/
-#include <stdint.h>
-#include <unistd.h>     /*Unix 標準函數定義*/
-#include <fcntl.h>      /*檔控制定義*/
-#include <termios.h>    /*PPSIX 終端控制定義*/
-#include <errno.h>      /*錯誤號定義*/
-#include <errno.h>
-#include <string.h>
-#include <time.h>
-#include <ctype.h>
-#include <ifaddrs.h>
-#include <math.h>
-#include <stdbool.h>
-
-#include "./ShareMemory/shmMem.h"
-#include "./Define/define.h"
-#include "./SelectGun/SelectGun.h"
-#include "Config.h"
-
-//------------------------------------------------------------------------------
-#define CMD_KEY_WAIT                                (1)
-#define CMD_KEY_DONT_WAIT                           (0)
-
-#define DEFAULT_AC_INDEX                            (2)
-
-#define AUTORUN_STEP1_TIME_START                    (140)             // Minutes
-#define AUTORUN_STEP1_TIME_END                      (150)
-#define AUTORUN_STEP2_TIME_START                    (210)
-#define AUTORUN_STEP2_TIME_END                      (410)
-#define AUTORUN_END_TIME                            (480)
-#define AUTORUN_CYCLE_COUNT                         (30)
-
-#define TTY_PATH                                    "/dev/tty"
-#define STTY_US                                     "stty raw -echo -F "
-#define STTY_DEF                                    "stty -raw echo -F "
-
-//------------------------------------------------------------------------------
-uint8_t _curAutoRunCount = 0;
-uint8_t _usingAutoRun = 0;
-struct timeval _autoTime;
-
-static struct SysConfigData *pSysConfig = NULL;
-static struct SysInfoData *pSysInfo = NULL;
-static struct WARNING_CODE_INFO *pSysWarning = NULL;
-
-static struct AlarmCodeData *pAlarmCode = NULL;
-
-static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
-static struct CHAdeMOData *ShmCHAdeMOData = NULL;
-static struct CcsData *ShmCcsData = NULL;
-static struct GBTData *ShmGBTData = NULL;
-static struct FanModuleData *ShmFanModuleData = NULL;
-static struct RelayModuleData *ShmRelayModuleData = NULL;
-static struct LedModuleData *ShmLedModuleData = NULL;
-static struct PsuData *ShmPsuData = NULL;
-static struct OCPP16Data *ShmOCPP16Data = NULL;
-static SelectGunInfo *ShmSelectGunInfo = NULL;
-static DcCommonInfo *ShmDcCommonData = NULL;
-
-static struct ChargingInfoData *pDcChargingInfo = NULL;
-static struct ChargingInfoData *pAcChargingInfo = NULL;
-
-static char newString[8][16] = {0};
-
-//------------------------------------------------------------------------------
-static 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;
-}
-
-static void get_char(char *word)
-{
-    fd_set rfds;
-    struct timeval tv;
-
-    FD_ZERO(&rfds);
-    FD_SET(0, &rfds);
-    tv.tv_sec = 0;
-    tv.tv_usec = 10; //wait input timout time
-
-    //if input
-    if (select(1, &rfds, NULL, NULL, &tv) > 0) {
-        fgets(word, 128, stdin);
-    }
-}
-
-static uint8_t helpCmd(void)
-{
-    if (strcmp(newString[0], "?") == 0 ||
-            strcmp(newString[0], "help") == 0 ||
-            strcmp(newString[0], "h") == 0) {
-        return YES;
-    }
-
-    return NO;
-}
-
-static uint8_t exitCmd(void)
-{
-    if (strcmp(newString[0], "c") == EQUAL ||
-            strcmp(newString[0], "C") == EQUAL ||
-            strncmp(&newString[0][0], "exit", 4) == EQUAL
-       ) {
-        return YES;
-    }
-
-    return NO;
-}
-
-static uint8_t readCmdKey(uint8_t state)
-{
-    char word[128] = {0};
-    int i = 0, j = 0, ctr = 0;
-
-    memset(word, 0, sizeof(word));
-    if (state == CMD_KEY_WAIT) {
-        fgets(word, sizeof(word), stdin);
-    } else if (state == CMD_KEY_DONT_WAIT) {
-        get_char(word);
-
-        if (strlen(word) == 0) {
-            //usleep(50000);
-            return NO;
-        }
-    }
-
-    memset(newString, 0, sizeof(newString));
-
-    strcpy(newString[1], "-1");
-    strcpy(newString[2], "-1");
-    for (i = 0; i <= (strlen(word)); i++) {
-        if (word[i] == ' ' ||
-                word[i] == '\0' ||
-                word[i] == '\r' ||
-                word[i] == '\n' ||
-                word[i] == 10) {
-            newString[ctr][j] = '\0';
-            ctr++;
-            j = 0;
-        } else {
-            newString[ctr][j] = word[i];
-            j++;
-        }
-    }
-
-    return YES;
-}
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return (_end_time.tv_sec - _sour_time.tv_sec);
-}
-
-void RunStatusProc(char *v1, char *v2)
-{
-    printf("OrderCharging = %d \n", pSysInfo->OrderCharging);
-    printf("WaitForPlugit = %d \n", pSysInfo->WaitForPlugit);
-    if (strcmp(v1, "ac") == 0) {
-        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
-        //    printf("FindChargingInfoData (AC) false \n");
-        //}
-        printf("AC Status = %d \n", pAcChargingInfo->ConnectorPlugIn);
-        return;
-    }
-
-    int _index = atoi(v1);
-
-    if (_index <= 1) {
-        //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-        //    printf ("FindChargingInfoData error\n");
-        //    return;
-        //}
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-            // get
-            printf ("index = %x, status = %x (%d)\n",
-                    _index,
-                    pDcChargingInfo->SystemStatus,
-                    pDcChargingInfo->IsAvailable);
-            printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
-                    pSysInfo->SystemTimeoutFlag, pSysInfo->PageIndex);
-        } else {
-            // set
-            pDcChargingInfo->SystemStatus = atoi(v2);
-        }
-    } else {
-        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
-        //    printf("FindChargingInfoData (AC) false \n");
-        //}
-        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-            // get
-            printf ("AC Type, status = %x (%d)\n",
-                    pAcChargingInfo->SystemStatus,
-                    pAcChargingInfo->IsAvailable);
-        } else {
-            // set
-            pAcChargingInfo->SystemStatus = atoi(v2);
-        }
-    }
-}
-
-void RunCardProc(char *v1, char *v2)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        if (pSysInfo->WaitForPlugit) {
-            pSysInfo->WaitForPlugit = 0x00;
-            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
-        } else {
-            pSysInfo->WaitForPlugit = 0x01;
-            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
-        }
-    } else {
-        strcpy((char *)pSysConfig->UserId, "");
-        memcpy((char *)pSysConfig->UserId, v1, strlen(v1));
-        pSysConfig->UserId[strlen(v1)] = '\0';
-        printf("StartUserId = %s \n", pSysConfig->UserId);
-    }
-}
-
-void RunGunPlugitProc(char *v1, char *v2)
-{
-    if (strcmp(v1, "ac") == 0) {
-        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
-        //    printf("FindChargingInfoData (AC) false \n");
-        //}
-        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-            // get
-            printf("ConnectorPlugIn = %d \n", pAcChargingInfo->ConnectorPlugIn);
-        } else {
-            // set
-            pAcChargingInfo->ConnectorPlugIn = atoi(v2);
-        }
-        return;
-    }
-
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-        // get
-        printf("index = %x, plug it = %x\n",
-               _index,
-               pDcChargingInfo->ConnectorPlugIn);
-    } else {
-        // set
-        pDcChargingInfo->ConnectorPlugIn = atoi(v2);
-    }
-}
-
-void GetGunLockStatusProc(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) {
-        pDcChargingInfo->GunLocked = atoi(v2);
-    }
-
-    printf("Gun Locked Status = %d \n", pDcChargingInfo->GunLocked);
-}
-
-void SetSystemIDProc()
-{
-    char *systemId = "Alston_Test";
-    memcpy(&pSysConfig->SystemId, systemId, strlen(systemId));
-}
-
-void RunSelfProc()
-{
-    printf("self test status = %x\n", pSysInfo->SelfTestSeq);
-}
-
-void GetFwVerProc(void)
-{
-    int _index = 0;
-    int isContinue = 1;
-    char *usageMsg = "Usage:\n"
-                     "      model\n"
-                     "      407\n"
-                     "      conn index, ex: conn 0 | 1\n"
-                     "      relay\n"
-                     "      fan\n"
-                     "      dc\n"
-                     "      led\n"
-                     "      ac\n"
-                     "      exit | c | C\n"
-                     "      help | ? | h\n";
-
-    while (isContinue) {
-        if (readCmdKey(CMD_KEY_WAIT) == NO) {
-            continue;
-        }
-
-        if (strcmp(newString[0], "407") == 0) {
-            printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
-        } else if (strcmp(newString[0], "model") == 0) {
-            printf("ModelName = %s\r\n", pSysConfig->ModelName);
-        } else if (strcmp(newString[0], "conn") == 0) {
-            if (strcmp(newString[1], "-1") == 0  ||
-                    strcmp(newString[1], "") == 0 ||
-                    atoi(newString[1]) >= pSysConfig->TotalConnectorCount
-               ) {
-                printf("index over flow\r\n");
-                continue;
-            }
-
-            _index = atoi(newString[1]);
-
-            if (_index == 0) {
-                printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
-            } else if (_index == 1) {
-                printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
-            }
-        } else if (strcmp(newString[0], "relay") == 0) {
-            printf("RB Version = %s \n", pSysInfo->RelayModuleFwRev);
-        } else if (strcmp(newString[0], "fan") == 0) {
-            printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev);
-        } else if (strcmp(newString[0], "dc") == 0) {
-            printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
-        } else if (strcmp(newString[0], "led") == 0) {
-            printf("LED Version = %s \n", pSysInfo->LedModuleFwRev);
-        } else if (strcmp(newString[0], "ac") == 0) {
-            pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-            printf("AC Version = %s \n", pAcChargingInfo->version);
-        } else if (exitCmd() == YES) {
-            return;
-        } else if (helpCmd() == YES) {
-            printf ("%s\n", usageMsg);
-        }
-
-    }//while
-}
-
-void CreateOneError(char *v1)
-{
-    int value = atoi(v1);
-
-    pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = value;
-    pSysConfig->BillingData.isBilling = value;
-}
-
-void GetAuthorizeFlag(char *v1)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        printf("AuthorizeFlag = %d \n", pSysInfo->AuthorizeFlag);
-    } else {
-        pSysInfo->AuthorizeFlag = atoi(v1);
-    }
-}
-
-void GetRelayStatus(char *v1)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    printf("RelayK1K2Status = %d \n", pDcChargingInfo->RelayK1K2Status);
-    printf("RelayKPK2Status = %d \n", pDcChargingInfo->RelayKPK2Status);
-}
-
-void FwUpdateFlagProc()
-{
-    pSysInfo->FirmwareUpdate = 0x01;
-}
-
-void CheckAcStatus(char *v1)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        printf("AC Status = %d \n", pSysInfo->AcContactorStatus);
-    }
-}
-
-void SetCableChkStatus(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    pDcChargingInfo->GroundFaultStatus = atoi(v2);
-}
-
-void SetChargingInfoCCID(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    memcpy(pDcChargingInfo->EVCCID, v2, 8);
-    pDcChargingInfo->EVCCID[8] = '\0';
-}
-
-void SetPowerValue(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    float _Current = atof(v2);
-
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    // 盲沖的時候才允許使用~
-    if (pDcChargingInfo->Type != 9) {
-        return;
-    }
-
-    pDcChargingInfo->EvBatterytargetCurrent = _Current;
-}
-
-void GetSystemInfo()
-{
-    printf ("ModelName = %s \n", pSysConfig->ModelName);
-    printf ("SerialNumber = %s \n", pSysConfig->SerialNumber);
-    printf ("InternetConn = %d \n", pSysInfo->InternetConn);
-
-    printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
-            pSysConfig->MaxChargingPower,
-            pSysConfig->MaxChargingCurrent);
-}
-
-void ChangeGunNum()
-{
-    if (pSysInfo->CurGunSelected + 1 < pSysConfig->TotalConnectorCount) {
-        pSysInfo->CurGunSelected += 1;
-        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-    } else if (pSysConfig->AcConnectorCount > 0 &&
-               pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
-        pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
-    } else {
-        pSysInfo->CurGunSelected = 0;
-        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-    }
-}
-
-void GetGunSelectedNum(char *v1)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        if (AC_QUANTITY > 0 &&
-                pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
-            printf("connector select changed = AC \n");
-        } else {
-            printf("connector selected = %d \n", pSysInfo->CurGunSelected);
-        }
-    } else {
-        int _index = atoi(v1);
-        if (_index <= 1) {
-            pSysInfo->CurGunSelected = _index;
-            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-            printf("connector select changed = %d \n", _index);
-        } else if (AC_QUANTITY > 0) {
-            pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
-            printf("connector select changed = AC \n");
-        }
-    }
-}
-
-void SetFanSpeed(char *v1)
-{
-    int speed = atoi(v1);
-
-    ShmFanModuleData->TestFanSpeed = speed;
-}
-
-void GetFanSpeed()
-{
-    printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
-    printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
-    printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
-    printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
-}
-
-void SetDebugMode(char *v1)
-{
-    int mode = atoi(v1);
-
-    pSysConfig->SwitchDebugFlag = mode;
-}
-
-void SetGFDMode(char *v1)
-{
-    int mode = atoi(v1);
-
-    pSysConfig->AlwaysGfdFlag = mode;
-}
-
-void GetPsuTemp()
-{
-    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
-            printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
-        }
-    }
-}
-
-void GetAcInputVol()
-{
-    printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
-           pSysInfo->InputVoltageR,
-           pSysInfo->InputVoltageS,
-           pSysInfo->InputVoltageT);
-}
-
-void GetPsuInformation(char *v1, char *v2, char *v3)
-{
-    printf("**********************AC Contact needed*************************\n");
-    if (strcmp(v1, "count") == 0) {
-        for (int i = 0; i < 4; i++) {
-            printf("Group Index = %d, Module Count = %d \n",
-                   i,
-                   ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
-        }
-    } else if (strcmp(v1, "ver") == 0) {
-        for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++) {
-            printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
-                   i, ShmPsuData->PsuVersion[i].FwPrimaryVersion,
-                   ShmPsuData->PsuVersion[i].FwSecondVersion);
-        }
-
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++) {
-                printf("Group Index = %d, Psu Index = %d, Version = %s \n",
-                       i,
-                       j,
-                       ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
-            }
-        }
-    } else if (strcmp(v1, "cap") == 0) {
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            printf("Group Index = %d, MaxCur = %d, Power = %d \n",
-                   i,
-                   ShmPsuData->PsuGroup[i].GroupAvailableCurrent,
-                   ShmPsuData->PsuGroup[i].GroupAvailablePower);
-        }
-    } else if (strcmp(v1, "input") == 0) {
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
-                printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
-                       i,
-                       count,
-                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
-                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
-                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
-            }
-        }
-    } else if (strcmp(v1, "output") == 0) {
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
-                   i,
-                   ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage,
-                   ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
-        }
-
-        for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-            //if (!FindChargingInfoData(i, &_chargingData[0])) {
-            //    printf ("FindChargingInfoData error\n");
-            //    continue;
-            //}
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
-
-            printf("Form RB : Group Index = %d, OutputV = %f \n",
-                   i,
-                   pDcChargingInfo->FireChargingVoltage);
-        }
-    } else if (strcmp(v1, "test") == 0) {
-        int mode = atoi(v2);
-
-        if (mode >= _TEST_MODE && mode <= _TEST_MODE) {
-            ShmPsuData->Work_Step = mode;
-        }
-    } else if (strcmp(v1, "out") == 0) {
-        float vol = atof(v2);
-        float cur = atof(v3);
-
-        if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
-            //if (!FindChargingInfoData(0, &_chargingData[0])) {
-            //    printf ("FindChargingInfoData error\n");
-            //    return;
-            //}
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(0);
-
-            pDcChargingInfo->EvBatterytargetVoltage = vol;
-            pDcChargingInfo->EvBatterytargetCurrent = cur;
-        }
-    }
-    printf("*************************************************\n");
-}
-
-void GetConnectorCapInfo(char *v1)
-{
-    int _GunIndex = atoi(v1);
-
-    //if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-    printf ("Charger Max Current = %d, Max Power = %d \n",
-            pSysConfig->MaxChargingCurrent * 10,
-            pSysConfig->MaxChargingPower * 10);
-
-    printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
-            _GunIndex,
-            pDcChargingInfo->RealMaxPower,
-            pDcChargingInfo->RealMaxVoltage,
-            pDcChargingInfo->RealMaxCurrent);
-}
-
-static void setConfirmSelGun(uint8_t selGun)
-{
-    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
-        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
-        //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
-        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
-        //printf("confirmSelGun right\r\n");
-    }
-}
-
-void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
-{
-    int _GunIndex;
-    uint8_t gunIndex = 0;
-    uint8_t stopChg = 0;
-    uint8_t curGun = 0;
-    int isContinue = 1;
-    float _Voltage;
-    float _Current;
-    uint8_t PreviousSystemStatus[2] = {0xff};
-    char *usageMsg = "Usage:\n"
-                     "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
-                     "       chg    <voltage> <current>            ex: chg 500 100\n"
-                     "       c      <index>                        ex: c 0\n"
-                     "       help | ? | h\n"
-                     "\r\n";
-
-    if (strcmp(v1, "auto") == EQUAL) {
-        _usingAutoRun = 0x01;
-        _GunIndex = 0;
-        _Voltage = 500;
-        _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage;
-    } else {
-        _usingAutoRun = 0x00;
-        _GunIndex = atoi(v1);
-        _Voltage = atof(v2);
-        _Current = atof(v3);
-    }
-
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-    printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-           pSysConfig->MaxChargingPower,
-           _Voltage,
-           _Current);
-
-    if (_Voltage > 1000 || _Voltage < 50) {
-        printf ("Input Voltage over range\n");
-        return;
-    }
-
-    //kill ev task
-    system("killall Module_EvComm");
-
-    pSysInfo->CurGunSelected = _GunIndex;
-
-    while (isContinue) {
-
-        curGun = pSysInfo->CurGunSelected;
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-
-        //fix gun 1
-        switch (pDcChargingInfo->SystemStatus) {
-        case S_IDLE:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-#if defined DD360Audi
-                setConfirmSelGun(curGun);
-#endif //defined DD360Audi
-
-                strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
-                pDcChargingInfo->ConnectorPlugIn = 1;
-                printf ("[UnconditionalCharge - S_IDLE]\n");
-                pDcChargingInfo->Type = 9;
-
-            }
-            if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
-                pSysInfo->StartToChargingFlag = 0x01;
-                pDcChargingInfo->SystemStatus = S_PREPARNING;
-            }
-            break;
-
-        case S_PREPARNING:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_PREPARNIN]\n");
-
-                //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
-                printf ("wait find module\n");
-
-            }
-            //main 會在此階段判斷以下資料跳到下一個 state
-            //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次  AC_Contactor
-            //ShmPsuData->SystemPresentPsuQuantity;
-            //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
-            //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
-            //_chargingData[gun_index]->AvailableChargingPower;
-
-            //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
-            //sleep(10);
-
-            //清除 main timeout 機制
-            pDcChargingInfo->TimeoutFlag = 0;
-            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            pDcChargingInfo->Type = 9;
-            break;
-
-        case S_PREPARING_FOR_EV:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
-                printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
-
-            }
-            //清除 main timeout 機制
-            pDcChargingInfo->TimeoutFlag = 0;
-            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            pDcChargingInfo->Type = 9;
-
-            //充電電壓電流
-            pDcChargingInfo->EvBatterySoc             = 50;
-            pDcChargingInfo->EvBatterytargetVoltage   = 500;
-            pDcChargingInfo->EvBatterytargetCurrent   = 2;
-            pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
-            //確定模組己升壓完成
-            //if(pDcChargingInfo->PresentChargingVoltage <=  (3000+500) &&
-            //  pDcChargingInfo->PresentChargingVoltage >=  (3000-500) )
-            {
-                printf ("Precharge Done = %f \n",
-                        pDcChargingInfo->PresentChargingVoltage);
-                //EV done
-                pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE;
-            }
-            break;
-
-        case S_PREPARING_FOR_EVSE:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
-
-            }
-            //printf ("tar vol = %d \n", _Voltage);
-            //printf ("tar cur = %d \n", _Current);
-
-            //清除 main timeout 機制
-            pDcChargingInfo->TimeoutFlag = 0;
-            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            pDcChargingInfo->Type = 9;
-
-            //充電電壓電流
-            pDcChargingInfo->EvBatterySoc = 50;
-            pDcChargingInfo->EvBatterytargetVoltage = 500;
-            pDcChargingInfo->EvBatterytargetCurrent = 2;
-            pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-            //printf ("tar vol_ = %d \n", pDcChargingInfo->EvBatterytargetVoltage);
-            // printf ("tar cur_ = %d \n", pDcChargingInfo->EvBatterytargetCurrent);
-
-            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
-            //確定模組己升壓完成
-            if (pDcChargingInfo->GroundFaultStatus == 0x01 ||
-                    pDcChargingInfo->GroundFaultStatus == 0x03) {
-                printf ("First Ground Fault State (%d)\n",
-                        pDcChargingInfo->GroundFaultStatus);
-                printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage);
-                sleep(5);
-                //EV done
-                pDcChargingInfo->SystemStatus = S_CHARGING;
-            } else if (pDcChargingInfo->GroundFaultStatus > 0x02) {
-                printf ("First Ground Fault check Fail (%d)\n",
-                        pDcChargingInfo->GroundFaultStatus);
-                pDcChargingInfo->SystemStatus = S_TERMINATING;
-            }
-            break;
-
-        case S_CHARGING:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                if (_usingAutoRun == 0x00) {
-                    //充電電壓電流
-                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
-                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
-                } else {
-                    _curAutoRunCount = 0;
-                    gettimeofday(&_autoTime, NULL);
-                }
-
-                pDcChargingInfo->EvBatterySoc = 50;
-                pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-                printf ("[UnconditionalCharge - S_CHARGING]\n");
-            }
-
-            if (_usingAutoRun == 0x01) {
-                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
-                        (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
-                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
-                         (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
-                   ) {
-                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
-                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
-                } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
-                    _curAutoRunCount++;
-                    if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
-                        pDcChargingInfo->SystemStatus = S_TERMINATING;
-                    } else {
-                        gettimeofday(&_autoTime, NULL);
-                    }
-                } else {
-                    pDcChargingInfo->EvBatterytargetVoltage = 0;
-                    pDcChargingInfo->EvBatterytargetCurrent = 0;
-                }
-            }
-
-//              printf("out : vol = %f, cur = %f \n",
-//                      pDcChargingInfo->EvBatterytargetVoltage,
-//                      pDcChargingInfo->EvBatterytargetCurrent);
-            //ev task do this
-            pDcChargingInfo->PresentChargingPower =
-                ((float)((pDcChargingInfo->PresentChargingVoltage) *
-                         (pDcChargingInfo->PresentChargingCurrent)) / 1000);
-
-            if (pDcChargingInfo->GroundFaultStatus == 0x02) {
-                printf ("Charging Ground Fault check Fail (%d)\n",
-                        pDcChargingInfo->GroundFaultStatus);
-                pDcChargingInfo->SystemStatus = S_TERMINATING;
-            }
-            break;
-
-        case S_TERMINATING:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_TERMINATING]\n");
-                //無阻塞偵測 keybaord 結束
-                system(STTY_DEF TTY_PATH);
-            }
-
-            pDcChargingInfo->SystemStatus = S_COMPLETE;
-            break;
-
-        case S_COMPLETE:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_COMPLETE]\n");
-            }
-
-            PreviousSystemStatus[curGun] = 0xFF;
-            stopChg = 0;
-            for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-                if (PreviousSystemStatus[gunIndex] == 0xFF) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-                    pDcChargingInfo->SystemStatus = S_IDLE;
-                } else {
-                    pSysInfo->CurGunSelected = gunIndex;
-                }
-
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-                if (pDcChargingInfo->SystemStatus == S_IDLE) {
-                    stopChg++;
-                }
-            }
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-            pDcChargingInfo->PresentChargingPower = 0;
-
-            if (stopChg == pSysConfig->TotalConnectorCount) {
-                system("/root/Module_EvComm &");
-                sleep(3);
-
-                for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-                    pDcChargingInfo->SystemStatus = S_IDLE;
-                }
-                return;
-            }
-            break;
-        }
-
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
-            continue;
-        }
-
-        if (strcmp(newString[0], "strchg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0 ||
-                    strcmp(newString[2], "-1") == 0 ||
-                    strcmp(newString[2], "") == 0
-               ) {
-                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
-                continue;
-            }
-
-            if (atoi(newString[1]) == pSysInfo->CurGunSelected) {
-                continue;
-            }
-
-            _GunIndex = atoi((char *)newString[1]);
-            _Voltage = atof((char *)newString[2]);
-            _Current = atof((char *)newString[3]);
-
-            printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-                    pSysConfig->MaxChargingPower,
-                    _Voltage,
-                    _Current);
-
-            if (_Voltage > 1000 || _Voltage < 50) {
-                _Voltage = 200;
-                printf ("Input Voltage over range\n");
-                continue;
-            }
-
-            pSysInfo->CurGunSelected = _GunIndex;
-            strcpy((char *)pSysConfig->UserId, "");
-        } else if (strcmp(newString[0], "chg") == 0) {
-            if (strcmp(newString[1], "-1") == 0) {
-                continue;
-            }
-
-            if (strcmp(newString[2], "-1") == 0 ||
-                    strcmp(newString[2], "") == 0) {
-                continue;
-            }
-
-            if (strcmp(newString[3], "-1") == 0 ||
-                    strcmp(newString[3], "") == 0) {
-                continue;
-            }
-
-            _GunIndex = atoi((char *)newString[1]);
-            float _vol = atof(newString[2]);
-            float _cur = atof(newString[3]);
-
-            if (_cur <= 0 || _cur <= 0) {
-                continue;
-            }
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-            printf("reset vol = %f, cur = %f \n", _vol, _cur);
-            pDcChargingInfo->EvBatterytargetVoltage = _vol;
-            pDcChargingInfo->EvBatterytargetCurrent = _cur;
-        } else if (strcmp(newString[0], "c") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                printf("argc 1 is error parameter\r\n");
-                continue;
-            }
-
-            if (atoi((char *)newString[1]) != -1) {
-                pSysInfo->CurGunSelected = atoi((char *)newString[1]);
-            }
-            printf("stop \n\r");
-
-            pSysInfo->StartToChargingFlag = 0x00;
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected);
-
-            pDcChargingInfo->SystemStatus = S_TERMINATING;
-        } else if (helpCmd() == YES) {
-            printf("%s\n", usageMsg);
-        }
-
-        usleep(100000);
-    }
-}
-
-int printTimeMsg(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);
-
-    sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-            tm->tm_hour,
-            tm->tm_min,
-            tm->tm_sec,
-            SeqEndTime.millitm,
-            buffer);
-    printf("%s", Buf);
-
-    return rc;
-}
-
-static void resdGunAndChillerTemp(void)
-{
-    int isContinue = 1;
-    uint8_t i = 0;
-    uint32_t sleepTime = 500000;
-    uint32_t loopTime = 1000;
-    struct timeb showTime;
-    struct timeb nowTime;
-
-    char *usageMsg = "Usage:\n"
-                     "       t <index>: loop time, ex: t 1\n"
-                     "       exit | c | C: exit test\n"
-                     "       h | help | ?: show usage message\n"
-                     "\r\n";
-
-    ftime(&showTime);
-
-    while (isContinue) {
-        ftime(&nowTime);
-
-        if (DiffTimeb(showTime, nowTime) > loopTime ||
-                DiffTimeb(showTime, nowTime) < 0) {
-            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
-
-                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
-                             i,
-                             pDcChargingInfo->ConnectorTemp,
-                             pDcChargingInfo->ChillerTemp,
-                             ShmDcCommonData->ConnectorTemp[i][0],
-                             ShmDcCommonData->ConnectorTemp[i][1],
-                             ShmDcCommonData->SystemTemp[0],
-                             ShmDcCommonData->SystemTemp[1],
-                             ShmDcCommonData->SystemTemp[2],
-                             ShmDcCommonData->SystemTemp[3]);
-            }//for
-            ftime(&showTime);
-        }
-
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
-            usleep(sleepTime);
-            continue;
-        }
-
-        if (strcmp(newString[0], "t") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0 ||
-                    atoi((char *)newString[1]) > 255
-               ) {
-                printf("argc 1 is error parameter\r\n");
-                continue;
-            }
-
-            loopTime = ((atoi((char *)newString[1])) * 1000);
-            printf("loopTime = %d\r\n", loopTime);
-            ftime(&showTime);
-            continue;
-        } else if (exitCmd() == YES) {
-            return;
-        } else if (helpCmd() == YES) {
-            printf ("%s\n", usageMsg);
-        }
-
-        usleep(sleepTime);
-    }//while
-}
-static void writeOTPTemp(void)
-{
-    uint8_t _GunIndex = 0;
-    int isContinue = 1;
-    uint32_t sleepTime = 500000;
-    char *usageMsg = "Usage:\n"
-                     "       OTP  <temp_recovery>  <temp>, ex: OTP 140 150\n"
-                     "       exit | c | C\n"
-                     "       help | ? | h\n"
-                     "\r\n";
-
-    while (isContinue) {
-        if (readCmdKey(CMD_KEY_WAIT) == NO) {
-            sleep(sleepTime);
-            continue;
-        }
-
-        if (helpCmd() == YES) {
-            printf ("%s\n", usageMsg);
-            continue;
-        } else if (exitCmd() == YES) {
-            sleep(1);
-            return;
-        } 
-        if (strcmp(newString[0], "OTP") != 0) {
-            printf("argc 1 is error parameter\r\n");
-            continue;
-        }
-
-        if (atoi(newString[1]) > 255 ||
-                atoi(newString[1]) == -1) {
-            printf("Recovey temperature value overflow\r\n");
-            continue;
-        }
-
-        if (atoi(newString[2]) > 255 ||
-                atoi(newString[2]) == -1) {
-            printf("Recovey temperature value overflow\r\n");
-            continue;
-        }
-
-        pSysInfo->OTPTempR = atoi(newString[1]);
-        pSysInfo->OTPTemp = atoi(newString[2]);
-
-        printf("OTP Recovery Temp set:%d\n",pSysInfo->OTPTempR);
-        printf("OTP Temp set:%d\n",pSysInfo->OTPTemp);
-        usleep(sleepTime);
-    }//while
-}
-
-static void writeGunAndChillerTemp(void)
-{
-    uint8_t _GunIndex = 0;
-    int isContinue = 1;
-    uint32_t sleepTime = 500000;
-    char *usageMsg = "Usage:\n"
-                     "       conn    <index> <temp>, ex: conn 0 150\n"
-                     "       chiller <index> <temp>, ex: chiller 0 150\n"
-                     "       tempR\n"
-                     "       exit | c | C\n"
-                     "       help | ? | h\n"
-                     "\r\n";
-
-    ShmDcCommonData->TestTemperature = YES;
-
-    while (isContinue) {
-        if (readCmdKey(CMD_KEY_WAIT) == NO) {
-            sleep(sleepTime);
-            continue;
-        }
-
-        if (helpCmd() == YES) {
-            printf ("%s\n", usageMsg);
-            continue;
-        } else if (exitCmd() == YES) {
-            ShmDcCommonData->TestTemperature = NO;
-            sleep(1);
-            return;
-        } else if (strcmp(newString[0], "tempR") == 0) {
-            resdGunAndChillerTemp();
-        }
-
-        if ((strcmp(newString[0], "chiller") != 0) &&
-                (strcmp(newString[1], "-1") == 0 ||
-                 strcmp(newString[1], "") == 0)
-           ) {
-            printf("argc 1 is error parameter\r\n");
-            continue;
-        }
-
-        if (atoi(newString[2]) > 255 ||
-                atoi(newString[2]) == -1) {
-            printf("temperature value overflow\r\n");
-            continue;
-        }
-
-        _GunIndex = atoi((char *)newString[1]);
-
-        if (_GunIndex >= pSysConfig->TotalConnectorCount) {
-            printf("gun index over total connector\r\n");
-            continue;
-        }
-
-        if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值
-            if (_GunIndex >= 1) {
-                _GunIndex = 0; //只會有一個水冷機
-            }
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-            pDcChargingInfo->ChillerTemp = atoi(newString[2]);
-            printf("set %d chiller temperature = %d\r\n",
-                   _GunIndex,
-                   pDcChargingInfo->ChillerTemp);
-        } else if (strcmp(newString[0], "conn") == 0) {//修改槍頭溫度值
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-            pDcChargingInfo->ConnectorTemp = atoi(newString[2]);
-            printf("set %d connector temp = %d\r\n",
-                   _GunIndex,
-                   pDcChargingInfo->ConnectorTemp);
-        }
-
-        usleep(sleepTime);
-    }//while
-}
-
-int main(void)
-{
-    uint8_t _GunIndex = 0;
-    int isContinue = 1;
-    char *usageMsg = "Usage:\n"
-                     "       state <index>                     : get gun state\n"
-                     "       card                              : scanning card (x)\n"
-                     "       gun <index>                       : get gun plugit state\n"
-                     "       lock <index>                      : get gun locked state\n"
-                     "       sysid                             : test system ID\n"
-                     "       self                              : self test state (x)\n"
-                     "       version | v | -v                  : version of board (407 or relay or other)\n"
-                     "       update                            : update firmware\n"
-                     "       ac                                : get ac relay state (x) \n"
-                     "       cable <index> <state>             : set ground fault state\n"
-                     "       pow <index> <power>               : set power value\n"
-                     "       model                             : get system information\n"
-                     "       temp                              : get PSU temperature\n"
-                     "       fan <speed>                       : set fan board speed\n"
-                     "       strchg <auto>                     : auto test charging\n"
-                     "       strchg <index> <voltage <current> : select gun test charging\n"
-                     "       tempW                             : write connector header and Chiller temperature\r\n"
-                     "       tempR                             : print connector header and chiller temperature\r\n"
-                     "       OTP                               : Write OTP temperature\r\n"
-                     "\r\n";
-
-    if (CreateAllCsuShareMemory() == FAIL) {
-        printf("create share memory error\r\n");
-        return FAIL;
-    }
-
-    MappingGunChargingInfo("ReadCmdline Task");
-
-    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();
-
-    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
-    ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
-    ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
-    ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
-    ShmPsuData = (struct PsuData *)GetShmPsuData();
-    ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
-    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
-
-//    for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
-//        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-//        pDcChargingInfo->SystemStatus = S_IDLE;
-//    }
-
-    while (isContinue) {
-        if (readCmdKey(CMD_KEY_WAIT) == NO) {
-            continue;
-        }
-
-        if (strcmp(newString[0], "state") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // 槍狀態
-            RunStatusProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "card") == 0) {
-            // 刷卡狀態
-            RunCardProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "gun") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // 插槍狀態
-            RunGunPlugitProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "lock") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // 插槍狀態
-            GetGunLockStatusProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "sysid") == 0) {
-            // 測試 sys id
-            SetSystemIDProc();
-        } else if (strcmp(newString[0], "self") == 0) {
-            // CSU 自我檢測狀態
-            RunSelfProc(newString[1]);
-        } else if (strcmp(newString[0], "version") == 0 ||
-                   strcmp(newString[0], "v") == 0 ||
-                   strcmp(newString[0], "-v") == 0) {
-            //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-            //    continue;
-            //}
-            // 取 FW 版號
-            GetFwVerProc();
-        } else if (strcmp(newString[0], "update") == 0) {
-            // 更新
-            FwUpdateFlagProc(newString[1]);
-        } else if (strcmp(newString[0], "ac") == 0) {
-            // AC contactor 狀態
-            CheckAcStatus(newString[1]);
-        } else if (strcmp(newString[0], "cable") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // cable check pass
-            SetCableChkStatus(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "pow") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                continue;
-            }
-            // cable check pass
-            SetPowerValue(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "model") == 0) {
-            GetSystemInfo();
-        } else if (strcmp(newString[0], "select") == 0) {
-            // 取得 / 設定 當前選的槍號
-            GetGunSelectedNum(newString[1]);
-        } else if (strcmp(newString[0], "change") == 0) {
-            // 模擬按鈕改變選槍
-            ChangeGunNum();
-        } else if (strcmp(newString[0], "fan") == 0) {
-            // 設定風扇速度
-            SetFanSpeed(newString[1]);
-        } else if (strcmp(newString[0], "speed") == 0) {
-            // 取得風扇速度
-            GetFanSpeed();
-        } else if (strcmp(newString[0], "debug") == 0) {
-            // 設定 debug mode
-            SetDebugMode(newString[1]);
-        } else if (strcmp(newString[0], "gfd") == 0) {
-            // 設定盲沖使用 GFD 功能
-            SetGFDMode(newString[1]);
-        } else if (strcmp(newString[0], "temp") == 0) {
-            // 取得 PSU 溫度
-            GetPsuTemp();
-        } else if (strcmp(newString[0], "acin") == 0) {
-            // 取得三向輸入電壓
-            GetAcInputVol();
-        } else if (strcmp(newString[0], "psu") == 0) {
-            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                printf ("PSU : Param fail..Please retry again......\n");
-                continue;
-            }
-            // 取得 PSU 資訊
-            GetPsuInformation(newString[1], newString[2], newString[3]);
-        } else if (strcmp(newString[0], "cap") == 0) {
-            GetConnectorCapInfo(newString[1]);
-        } else if (strcmp(newString[0], "error") == 0) {
-            CreateOneError(newString[1]);
-        } else if (strcmp(newString[0], "auth") == 0) {
-            GetAuthorizeFlag(newString[1]);
-        } else if (strcmp(newString[0], "relay") == 0) {
-            GetRelayStatus(newString[1]);
-        } else if (strcmp(newString[0], "ccid") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
-                    strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
-                printf ("Input ccid fail.\n");
-                continue;
-            }
-            SetChargingInfoCCID(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "strchg") == 0) {
-            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
-            if (strcmp(newString[1], "auto") == 0) {
-                newString[2][0] = 0;
-                newString[3][0] = 0;
-            } else if (strcmp(newString[1], "-1") == 0 ||
-                       strcmp(newString[1], "") == 0   ||
-                       strcmp(newString[2], "-1") == 0 ||
-                       strcmp(newString[2], "") == 0) {
-                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
-                continue;
-            }
-
-            // 槍狀態
-            RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
-        } else if (strcmp(newString[0], "tempW") == 0) { //測試槍頭和水冷機溫度
-            writeGunAndChillerTemp();
-        } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
-            resdGunAndChillerTemp();
-        } else if (strcmp(newString[0], "OTP") == 0) { //測試槍頭和水冷機溫度
-            writeOTPTemp();
-        } else {
-            printf("%s\n", usageMsg);
-        }
-
-        sleep(1);
-    }//while
-
-    return 0;
-}
+/*
+ * Main.c
+ *
+ *  Created on: 2019年8月6日
+ *      Author: 7564
+ */
+
+
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <stdint.h>
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+#include <stdbool.h>
+
+#include "./ShareMemory/shmMem.h"
+#include "./Define/define.h"
+#include "./SelectGun/SelectGun.h"
+#include "Config.h"
+#include "./CSU/main.h"
+
+//------------------------------------------------------------------------------
+#define CMD_KEY_WAIT                                (1)
+#define CMD_KEY_DONT_WAIT                           (0)
+
+#define DEFAULT_AC_INDEX                            (2)
+
+#define AUTORUN_STEP1_TIME_START                    (140)             // Minutes
+#define AUTORUN_STEP1_TIME_END                      (150)
+#define AUTORUN_STEP2_TIME_START                    (210)
+#define AUTORUN_STEP2_TIME_END                      (410)
+#define AUTORUN_END_TIME                            (480)
+#define AUTORUN_CYCLE_COUNT                         (30)
+
+#define TTY_PATH                                    "/dev/tty"
+#define STTY_US                                     "stty raw -echo -F "
+#define STTY_DEF                                    "stty -raw echo -F "
+
+//------------------------------------------------------------------------------
+uint8_t _curAutoRunCount = 0;
+uint8_t _usingAutoRun = 0;
+struct timeval _autoTime;
+
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+static struct WARNING_CODE_INFO *pSysWarning = NULL;
+
+static struct AlarmCodeData *pAlarmCode = NULL;
+
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct CcsData *ShmCcsData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct FanModuleData *ShmFanModuleData = NULL;
+static struct RelayModuleData *ShmRelayModuleData = NULL;
+static struct LedModuleData *ShmLedModuleData = NULL;
+static struct PsuData *ShmPsuData = NULL;
+static struct OCPP16Data *ShmOCPP16Data = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
+
+static struct ChargingInfoData *pDcChargingInfo = NULL;
+static struct ChargingInfoData *pAcChargingInfo = NULL;
+
+static char newString[8][16] = {0};
+
+//------------------------------------------------------------------------------
+static 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;
+}
+
+static void get_char(char *word)
+{
+    fd_set rfds;
+    struct timeval tv;
+
+    FD_ZERO(&rfds);
+    FD_SET(0, &rfds);
+    tv.tv_sec = 0;
+    tv.tv_usec = 10; //wait input timout time
+
+    //if input
+    if (select(1, &rfds, NULL, NULL, &tv) > 0) {
+        fgets(word, 128, stdin);
+    }
+}
+
+static uint8_t helpCmd(void)
+{
+    if (strcmp(newString[0], "?") == 0 ||
+            strcmp(newString[0], "help") == 0 ||
+            strcmp(newString[0], "h") == 0) {
+        return YES;
+    }
+
+    return NO;
+}
+
+static uint8_t exitCmd(void)
+{
+    if (strcmp(newString[0], "c") == EQUAL ||
+            strcmp(newString[0], "C") == EQUAL ||
+            strncmp(&newString[0][0], "exit", 4) == EQUAL
+       ) {
+        return YES;
+    }
+
+    return NO;
+}
+
+static uint8_t readCmdKey(uint8_t state)
+{
+    char word[128] = {0};
+    int i = 0, j = 0, ctr = 0;
+
+    memset(word, 0, sizeof(word));
+    if (state == CMD_KEY_WAIT) {
+        fgets(word, sizeof(word), stdin);
+    } else if (state == CMD_KEY_DONT_WAIT) {
+        get_char(word);
+
+        if (strlen(word) == 0) {
+            //usleep(50000);
+            return NO;
+        }
+    }
+
+    memset(newString, 0, sizeof(newString));
+
+    strcpy(newString[1], "-1");
+    strcpy(newString[2], "-1");
+    for (i = 0; i <= (strlen(word)); i++) {
+        if (word[i] == ' ' ||
+                word[i] == '\0' ||
+                word[i] == '\r' ||
+                word[i] == '\n' ||
+                word[i] == 10) {
+            newString[ctr][j] = '\0';
+            ctr++;
+            j = 0;
+        } else {
+            newString[ctr][j] = word[i];
+            j++;
+        }
+    }
+
+    return YES;
+}
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+    struct timeval _end_time;
+    gettimeofday(&_end_time, NULL);
+
+    return (_end_time.tv_sec - _sour_time.tv_sec);
+}
+
+void RunStatusProc(char *v1, char *v2)
+{
+    printf("OrderCharging = %d \n", pSysInfo->OrderCharging);
+    printf("WaitForPlugit = %d \n", pSysInfo->WaitForPlugit);
+    if (strcmp(v1, "ac") == 0) {
+        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
+        //    printf("FindChargingInfoData (AC) false \n");
+        //}
+        printf("AC Status = %d \n", pAcChargingInfo->ConnectorPlugIn);
+        return;
+    }
+
+    int _index = atoi(v1);
+
+    if (_index <= 1) {
+        //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+        //    printf ("FindChargingInfoData error\n");
+        //    return;
+        //}
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+            // get
+            printf ("index = %x, status = %x (%d)\n",
+                    _index,
+                    pDcChargingInfo->SystemStatus,
+                    pDcChargingInfo->IsAvailable);
+            printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
+                    pSysInfo->SystemTimeoutFlag, pSysInfo->PageIndex);
+        } else {
+            // set
+            pDcChargingInfo->SystemStatus = atoi(v2);
+        }
+    } else {
+        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
+        //    printf("FindChargingInfoData (AC) false \n");
+        //}
+        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+            // get
+            printf ("AC Type, status = %x (%d)\n",
+                    pAcChargingInfo->SystemStatus,
+                    pAcChargingInfo->IsAvailable);
+        } else {
+            // set
+            pAcChargingInfo->SystemStatus = atoi(v2);
+        }
+    }
+}
+
+void RunCardProc(char *v1, char *v2)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        if (pSysInfo->WaitForPlugit) {
+            pSysInfo->WaitForPlugit = 0x00;
+            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
+        } else {
+            pSysInfo->WaitForPlugit = 0x01;
+            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
+        }
+    } else {
+        strcpy((char *)pSysConfig->UserId, "");
+        memcpy((char *)pSysConfig->UserId, v1, strlen(v1));
+        pSysConfig->UserId[strlen(v1)] = '\0';
+        printf("StartUserId = %s \n", pSysConfig->UserId);
+    }
+}
+
+void RunGunPlugitProc(char *v1, char *v2)
+{
+    if (strcmp(v1, "ac") == 0) {
+        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
+        //    printf("FindChargingInfoData (AC) false \n");
+        //}
+        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+            // get
+            printf("ConnectorPlugIn = %d \n", pAcChargingInfo->ConnectorPlugIn);
+        } else {
+            // set
+            pAcChargingInfo->ConnectorPlugIn = atoi(v2);
+        }
+        return;
+    }
+
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+        // get
+        printf("index = %x, plug it = %x\n",
+               _index,
+               pDcChargingInfo->ConnectorPlugIn);
+    } else {
+        // set
+        pDcChargingInfo->ConnectorPlugIn = atoi(v2);
+    }
+}
+
+void GetGunLockStatusProc(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) {
+        pDcChargingInfo->GunLocked = atoi(v2);
+    }
+
+    printf("Gun Locked Status = %d \n", pDcChargingInfo->GunLocked);
+}
+
+void SetSystemIDProc()
+{
+    char *systemId = "Alston_Test";
+    memcpy(&pSysConfig->SystemId, systemId, strlen(systemId));
+}
+
+void RunSelfProc()
+{
+    printf("self test status = %x\n", pSysInfo->SelfTestSeq);
+}
+
+void GetFwVerProc(void)
+{
+    int _index = 0;
+    int isContinue = 1;
+    char *usageMsg = "Usage:\n"
+                     "      model\n"
+                     "      407\n"
+                     "      conn index, ex: conn 0 | 1\n"
+                     "      relay\n"
+                     "      fan\n"
+                     "      dc\n"
+                     "      led\n"
+                     "      ac\n"
+                     "      exit | c | C\n"
+                     "      help | ? | h\n";
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            continue;
+        }
+
+        if (strcmp(newString[0], "407") == 0) {
+            printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
+        } else if (strcmp(newString[0], "model") == 0) {
+            printf("ModelName = %s\r\n", pSysConfig->ModelName);
+        } else if (strcmp(newString[0], "conn") == 0) {
+            if (strcmp(newString[1], "-1") == 0  ||
+                    strcmp(newString[1], "") == 0 ||
+                    atoi(newString[1]) >= pSysConfig->TotalConnectorCount
+               ) {
+                printf("index over flow\r\n");
+                continue;
+            }
+
+            _index = atoi(newString[1]);
+
+            if (_index == 0) {
+                printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
+            } else if (_index == 1) {
+                printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
+            }
+        } else if (strcmp(newString[0], "relay") == 0) {
+            printf("RB Version = %s \n", pSysInfo->RelayModuleFwRev);
+        } else if (strcmp(newString[0], "fan") == 0) {
+            printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev);
+        } else if (strcmp(newString[0], "dc") == 0) {
+            printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
+        } else if (strcmp(newString[0], "led") == 0) {
+            printf("LED Version = %s \n", pSysInfo->LedModuleFwRev);
+        } else if (strcmp(newString[0], "ac") == 0) {
+            pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+            printf("AC Version = %s \n", pAcChargingInfo->version);
+        } else if (exitCmd() == YES) {
+            return;
+        } else if (helpCmd() == YES) {
+            printf ("%s\n", usageMsg);
+        }
+
+    }//while
+}
+
+void CreateOneError(char *v1)
+{
+    int value = atoi(v1);
+
+    pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = value;
+    pSysConfig->BillingData.isBilling = value;
+}
+
+void GetAuthorizeFlag(char *v1)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        printf("AuthorizeFlag = %d \n", pSysInfo->AuthorizeFlag);
+    } else {
+        pSysInfo->AuthorizeFlag = atoi(v1);
+    }
+}
+
+void GetRelayStatus(char *v1)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    printf("RelayK1K2Status = %d \n", pDcChargingInfo->RelayK1K2Status);
+    printf("RelayKPK2Status = %d \n", pDcChargingInfo->RelayKPK2Status);
+}
+
+void FwUpdateFlagProc()
+{
+    pSysInfo->FirmwareUpdate = 0x01;
+}
+
+void CheckAcStatus(char *v1)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        printf("AC Status = %d \n", pSysInfo->AcContactorStatus);
+    }
+}
+
+void SetCableChkStatus(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    pDcChargingInfo->GroundFaultStatus = atoi(v2);
+}
+
+void SetChargingInfoCCID(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    memcpy(pDcChargingInfo->EVCCID, v2, 8);
+    pDcChargingInfo->EVCCID[8] = '\0';
+}
+
+void SetPowerValue(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    float _Current = atof(v2);
+
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    // 盲沖的時候才允許使用~
+    if (pDcChargingInfo->Type != 9) {
+        return;
+    }
+
+    pDcChargingInfo->EvBatterytargetCurrent = _Current;
+}
+
+void GetSystemInfo()
+{
+    printf ("ModelName = %s \n", pSysConfig->ModelName);
+    printf ("SerialNumber = %s \n", pSysConfig->SerialNumber);
+    printf ("InternetConn = %d \n", pSysInfo->InternetConn);
+
+    printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
+            pSysConfig->MaxChargingPower,
+            pSysConfig->MaxChargingCurrent);
+}
+
+void ChangeGunNum()
+{
+    if (pSysInfo->CurGunSelected + 1 < pSysConfig->TotalConnectorCount) {
+        pSysInfo->CurGunSelected += 1;
+        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
+    } else if (pSysConfig->AcConnectorCount > 0 &&
+               pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
+        pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+    } else {
+        pSysInfo->CurGunSelected = 0;
+        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
+    }
+}
+
+void GetGunSelectedNum(char *v1)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        if (AC_QUANTITY > 0 &&
+                pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+            printf("connector select changed = AC \n");
+        } else {
+            printf("connector selected = %d \n", pSysInfo->CurGunSelected);
+        }
+    } else {
+        int _index = atoi(v1);
+        if (_index <= 1) {
+            pSysInfo->CurGunSelected = _index;
+            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
+            printf("connector select changed = %d \n", _index);
+        } else if (AC_QUANTITY > 0) {
+            pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+            printf("connector select changed = AC \n");
+        }
+    }
+}
+
+void SetFanSpeed(char *v1)
+{
+    int speed = atoi(v1);
+
+    ShmFanModuleData->TestFanSpeed = speed;
+}
+
+void GetFanSpeed()
+{
+    printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
+    printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
+    printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
+    printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
+}
+
+void SetDebugMode(char *v1)
+{
+    int mode = atoi(v1);
+
+    pSysConfig->SwitchDebugFlag = mode;
+}
+
+void SetGFDMode(char *v1)
+{
+    int mode = atoi(v1);
+
+    pSysConfig->AlwaysGfdFlag = mode;
+}
+
+void GetPsuTemp()
+{
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+            printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
+        }
+    }
+}
+
+void GetAcInputVol()
+{
+    printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
+           pSysInfo->InputVoltageR,
+           pSysInfo->InputVoltageS,
+           pSysInfo->InputVoltageT);
+}
+
+void GetPsuInformation(char *v1, char *v2, char *v3)
+{
+    printf("**********************AC Contact needed*************************\n");
+    if (strcmp(v1, "count") == 0) {
+        for (int i = 0; i < 4; i++) {
+            printf("Group Index = %d, Module Count = %d \n",
+                   i,
+                   ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
+        }
+    } else if (strcmp(v1, "ver") == 0) {
+        for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++) {
+            printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
+                   i, ShmPsuData->PsuVersion[i].FwPrimaryVersion,
+                   ShmPsuData->PsuVersion[i].FwSecondVersion);
+        }
+
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++) {
+                printf("Group Index = %d, Psu Index = %d, Version = %s \n",
+                       i,
+                       j,
+                       ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
+            }
+        }
+    } else if (strcmp(v1, "cap") == 0) {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            printf("Group Index = %d, MaxCur = %d, Power = %d \n",
+                   i,
+                   ShmPsuData->PsuGroup[i].GroupAvailableCurrent,
+                   ShmPsuData->PsuGroup[i].GroupAvailablePower);
+        }
+    } else if (strcmp(v1, "input") == 0) {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
+                printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
+                       i,
+                       count,
+                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
+                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
+                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
+            }
+        }
+    } else if (strcmp(v1, "output") == 0) {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
+                   i,
+                   ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage,
+                   ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
+        }
+
+        for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+            //if (!FindChargingInfoData(i, &_chargingData[0])) {
+            //    printf ("FindChargingInfoData error\n");
+            //    continue;
+            //}
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+            printf("Form RB : Group Index = %d, OutputV = %f \n",
+                   i,
+                   pDcChargingInfo->FireChargingVoltage);
+        }
+    } else if (strcmp(v1, "test") == 0) {
+        int mode = atoi(v2);
+
+        if (mode >= _TEST_MODE && mode <= _TEST_MODE) {
+            ShmPsuData->Work_Step = mode;
+        }
+    } else if (strcmp(v1, "out") == 0) {
+        float vol = atof(v2);
+        float cur = atof(v3);
+
+        if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
+            //if (!FindChargingInfoData(0, &_chargingData[0])) {
+            //    printf ("FindChargingInfoData error\n");
+            //    return;
+            //}
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+
+            pDcChargingInfo->EvBatterytargetVoltage = vol;
+            pDcChargingInfo->EvBatterytargetCurrent = cur;
+        }
+    }
+    printf("*************************************************\n");
+}
+
+void GetConnectorCapInfo(char *v1)
+{
+    int _GunIndex = atoi(v1);
+
+    //if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+    printf ("Charger Max Current = %d, Max Power = %d \n",
+            pSysConfig->MaxChargingCurrent * 10,
+            pSysConfig->MaxChargingPower * 10);
+
+    printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
+            _GunIndex,
+            pDcChargingInfo->RealMaxPower,
+            pDcChargingInfo->RealMaxVoltage,
+            pDcChargingInfo->RealMaxCurrent);
+}
+
+static void setConfirmSelGun(uint8_t selGun)
+{
+    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+        //printf("confirmSelGun left\r\n");
+    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+        //printf("confirmSelGun right\r\n");
+    }
+}
+
+void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
+{
+    int _GunIndex;
+    uint8_t gunIndex = 0;
+    uint8_t stopChg = 0;
+    uint8_t curGun = 0;
+    int isContinue = 1;
+    float _Voltage;
+    float _Current;
+    uint8_t PreviousSystemStatus[2] = {0xff};
+    char *usageMsg = "Usage:\n"
+                     "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
+                     "       chg    <voltage> <current>            ex: chg 500 100\n"
+                     "       c      <index>                        ex: c 0\n"
+                     "       help | ? | h\n"
+                     "\r\n";
+
+    if (strcmp(v1, "auto") == EQUAL) {
+        _usingAutoRun = 0x01;
+        _GunIndex = 0;
+        _Voltage = 500;
+        _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage;
+    } else {
+        _usingAutoRun = 0x00;
+        _GunIndex = atoi(v1);
+        _Voltage = atof(v2);
+        _Current = atof(v3);
+    }
+
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+    printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+           pSysConfig->MaxChargingPower,
+           _Voltage,
+           _Current);
+
+    if (_Voltage > 1000 || _Voltage < 50) {
+        printf ("Input Voltage over range\n");
+        return;
+    }
+
+    //kill ev task
+    system("killall Module_EvComm");
+
+    pSysInfo->CurGunSelected = _GunIndex;
+
+    while (isContinue) {
+
+        curGun = pSysInfo->CurGunSelected;
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
+
+        //fix gun 1
+        switch (pDcChargingInfo->SystemStatus) {
+        case S_IDLE:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+#if defined DD360Audi
+                setConfirmSelGun(curGun);
+#endif //defined DD360Audi
+
+                strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
+                pDcChargingInfo->ConnectorPlugIn = 1;
+                printf ("[UnconditionalCharge - S_IDLE]\n");
+                pDcChargingInfo->Type = 9;
+
+            }
+            if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
+                pSysInfo->StartToChargingFlag = 0x01;
+                pDcChargingInfo->SystemStatus = S_PREPARNING;
+            }
+            break;
+
+        case S_PREPARNING:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_PREPARNIN]\n");
+
+                //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
+                printf ("wait find module\n");
+
+            }
+            //main 會在此階段判斷以下資料跳到下一個 state
+            //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次  AC_Contactor
+            //ShmPsuData->SystemPresentPsuQuantity;
+            //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
+            //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
+            //_chargingData[gun_index]->AvailableChargingPower;
+
+            //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
+            //sleep(10);
+
+            //清除 main timeout 機制
+            pDcChargingInfo->TimeoutFlag = 0;
+            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+            pDcChargingInfo->Type = 9;
+            break;
+
+        case S_PREPARING_FOR_EV:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
+                printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
+
+            }
+            //清除 main timeout 機制
+            pDcChargingInfo->TimeoutFlag = 0;
+            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+            pDcChargingInfo->Type = 9;
+
+            //充電電壓電流
+            pDcChargingInfo->EvBatterySoc             = 50;
+            pDcChargingInfo->EvBatterytargetVoltage   = 500;
+            pDcChargingInfo->EvBatterytargetCurrent   = 2;
+            pDcChargingInfo->AvailableChargingCurrent = 1000;
+
+            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
+            //確定模組己升壓完成
+            //if(pDcChargingInfo->PresentChargingVoltage <=  (3000+500) &&
+            //  pDcChargingInfo->PresentChargingVoltage >=  (3000-500) )
+            {
+                printf ("Precharge Done = %f \n",
+                        pDcChargingInfo->PresentChargingVoltage);
+                //EV done
+                pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE;
+            }
+            break;
+
+        case S_PREPARING_FOR_EVSE:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
+
+            }
+            //printf ("tar vol = %d \n", _Voltage);
+            //printf ("tar cur = %d \n", _Current);
+
+            //清除 main timeout 機制
+            pDcChargingInfo->TimeoutFlag = 0;
+            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+            pDcChargingInfo->Type = 9;
+
+            //充電電壓電流
+            pDcChargingInfo->EvBatterySoc = 50;
+            pDcChargingInfo->EvBatterytargetVoltage = 500;
+            pDcChargingInfo->EvBatterytargetCurrent = 2;
+            pDcChargingInfo->AvailableChargingCurrent = 1000;
+
+            //printf ("tar vol_ = %d \n", pDcChargingInfo->EvBatterytargetVoltage);
+            // printf ("tar cur_ = %d \n", pDcChargingInfo->EvBatterytargetCurrent);
+
+            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
+            //確定模組己升壓完成
+            if (pDcChargingInfo->GroundFaultStatus == 0x01 ||
+                    pDcChargingInfo->GroundFaultStatus == 0x03) {
+                printf ("First Ground Fault State (%d)\n",
+                        pDcChargingInfo->GroundFaultStatus);
+                printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage);
+                sleep(5);
+                //EV done
+                pDcChargingInfo->SystemStatus = S_CHARGING;
+            } else if (pDcChargingInfo->GroundFaultStatus > 0x02) {
+                printf ("First Ground Fault check Fail (%d)\n",
+                        pDcChargingInfo->GroundFaultStatus);
+                pDcChargingInfo->SystemStatus = S_TERMINATING;
+            }
+            break;
+
+        case S_CHARGING:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                if (_usingAutoRun == 0x00) {
+                    //充電電壓電流
+                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
+                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
+                } else {
+                    _curAutoRunCount = 0;
+                    gettimeofday(&_autoTime, NULL);
+                }
+
+                pDcChargingInfo->EvBatterySoc = 50;
+                pDcChargingInfo->AvailableChargingCurrent = 1000;
+
+                printf ("[UnconditionalCharge - S_CHARGING]\n");
+            }
+
+            if (_usingAutoRun == 0x01) {
+                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
+                        (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
+                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
+                         (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
+                   ) {
+                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
+                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
+                } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
+                    _curAutoRunCount++;
+                    if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
+                        pDcChargingInfo->SystemStatus = S_TERMINATING;
+                    } else {
+                        gettimeofday(&_autoTime, NULL);
+                    }
+                } else {
+                    pDcChargingInfo->EvBatterytargetVoltage = 0;
+                    pDcChargingInfo->EvBatterytargetCurrent = 0;
+                }
+            }
+
+//              printf("out : vol = %f, cur = %f \n",
+//                      pDcChargingInfo->EvBatterytargetVoltage,
+//                      pDcChargingInfo->EvBatterytargetCurrent);
+            //ev task do this
+            pDcChargingInfo->PresentChargingPower =
+                ((float)((pDcChargingInfo->PresentChargingVoltage) *
+                         (pDcChargingInfo->PresentChargingCurrent)) / 1000);
+
+            if (pDcChargingInfo->GroundFaultStatus == 0x02) {
+                printf ("Charging Ground Fault check Fail (%d)\n",
+                        pDcChargingInfo->GroundFaultStatus);
+                pDcChargingInfo->SystemStatus = S_TERMINATING;
+            }
+            break;
+
+        case S_TERMINATING:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_TERMINATING]\n");
+                //無阻塞偵測 keybaord 結束
+                system(STTY_DEF TTY_PATH);
+            }
+
+            pDcChargingInfo->SystemStatus = S_COMPLETE;
+            break;
+
+        case S_COMPLETE:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_COMPLETE]\n");
+            }
+
+            PreviousSystemStatus[curGun] = 0xFF;
+            stopChg = 0;
+            for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+                if (PreviousSystemStatus[gunIndex] == 0xFF) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
+                    pDcChargingInfo->SystemStatus = S_IDLE;
+                } else {
+                    pSysInfo->CurGunSelected = gunIndex;
+                }
+
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+                if (pDcChargingInfo->SystemStatus == S_IDLE) {
+                    stopChg++;
+                }
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
+            pDcChargingInfo->PresentChargingPower = 0;
+
+            if (stopChg == pSysConfig->TotalConnectorCount) {
+                system("/root/Module_EvComm &");
+                sleep(3);
+
+                for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+                    pDcChargingInfo->SystemStatus = S_IDLE;
+                }
+                return;
+            }
+            break;
+        }
+
+        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+            continue;
+        }
+
+        if (strcmp(newString[0], "strchg") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0 ||
+                    strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0
+               ) {
+                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
+                continue;
+            }
+
+            if (atoi(newString[1]) == pSysInfo->CurGunSelected) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            _Voltage = atof((char *)newString[2]);
+            _Current = atof((char *)newString[3]);
+
+            printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+                    pSysConfig->MaxChargingPower,
+                    _Voltage,
+                    _Current);
+
+            if (_Voltage > 1000 || _Voltage < 50) {
+                _Voltage = 200;
+                printf ("Input Voltage over range\n");
+                continue;
+            }
+
+            pSysInfo->CurGunSelected = _GunIndex;
+            strcpy((char *)pSysConfig->UserId, "");
+        } else if (strcmp(newString[0], "chg") == 0) {
+            if (strcmp(newString[1], "-1") == 0) {
+                continue;
+            }
+
+            if (strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0) {
+                continue;
+            }
+
+            if (strcmp(newString[3], "-1") == 0 ||
+                    strcmp(newString[3], "") == 0) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            float _vol = atof(newString[2]);
+            float _cur = atof(newString[3]);
+
+            if (_cur <= 0 || _cur <= 0) {
+                continue;
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+            printf("reset vol = %f, cur = %f \n", _vol, _cur);
+            pDcChargingInfo->EvBatterytargetVoltage = _vol;
+            pDcChargingInfo->EvBatterytargetCurrent = _cur;
+        } else if (strcmp(newString[0], "c") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            if (atoi((char *)newString[1]) != -1) {
+                pSysInfo->CurGunSelected = atoi((char *)newString[1]);
+            }
+            printf("stop \n\r");
+
+            pSysInfo->StartToChargingFlag = 0x00;
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected);
+
+            pDcChargingInfo->SystemStatus = S_TERMINATING;
+        } else if (helpCmd() == YES) {
+            printf("%s\n", usageMsg);
+        }
+
+        usleep(100000);
+    }
+}
+
+int printTimeMsg(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);
+
+    sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+            tm->tm_hour,
+            tm->tm_min,
+            tm->tm_sec,
+            SeqEndTime.millitm,
+            buffer);
+    printf("%s", Buf);
+
+    return rc;
+}
+
+static void resdGunAndChillerTemp(void)
+{
+    int isContinue = 1;
+    uint8_t i = 0;
+    uint32_t sleepTime = 500000;
+    uint32_t loopTime = 1000;
+    struct timeb showTime;
+    struct timeb nowTime;
+
+    char *usageMsg = "Usage:\n"
+                     "       t <index>: loop time, ex: t 1\n"
+                     "       exit | c | C: exit test\n"
+                     "       h | help | ?: show usage message\n"
+                     "\r\n";
+
+    ftime(&showTime);
+
+    while (isContinue) {
+        ftime(&nowTime);
+
+        if (DiffTimeb(showTime, nowTime) > loopTime ||
+                DiffTimeb(showTime, nowTime) < 0) {
+            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
+                             i,
+                             pDcChargingInfo->ConnectorTemp,
+                             pDcChargingInfo->ChillerTemp,
+                             ShmDcCommonData->ConnectorTemp[i][0],
+                             ShmDcCommonData->ConnectorTemp[i][1],
+                             ShmDcCommonData->SystemTemp[0],
+                             ShmDcCommonData->SystemTemp[1],
+                             ShmDcCommonData->SystemTemp[2],
+                             ShmDcCommonData->SystemTemp[3]);
+            }//for
+            ftime(&showTime);
+        }
+
+        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+            usleep(sleepTime);
+            continue;
+        }
+
+        if (strcmp(newString[0], "t") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0 ||
+                    atoi((char *)newString[1]) > 255
+               ) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            loopTime = ((atoi((char *)newString[1])) * 1000);
+            printf("loopTime = %d\r\n", loopTime);
+            ftime(&showTime);
+            continue;
+        } else if (exitCmd() == YES) {
+            return;
+        } else if (helpCmd() == YES) {
+            printf ("%s\n", usageMsg);
+        }
+
+        usleep(sleepTime);
+    }//while
+}
+
+static void writeGunAndChillerTemp(void)
+{
+    uint8_t _GunIndex = 0;
+    int isContinue = 1;
+    uint32_t sleepTime = 500000;
+    char *usageMsg = "Usage:\n"
+                     "       conn    <index> <temp>, ex: conn 0 150\n"
+                     "       chiller <index> <temp>, ex: chiller 0 150\n"
+                     "       tempR\n"
+                     "       exit | c | C\n"
+                     "       help | ? | h\n"
+                     "\r\n";
+
+    ShmDcCommonData->TestTemperature = YES;
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            sleep(sleepTime);
+            continue;
+        }
+
+        if (helpCmd() == YES) {
+            printf ("%s\n", usageMsg);
+            continue;
+        } else if (exitCmd() == YES) {
+            ShmDcCommonData->TestTemperature = NO;
+            sleep(1);
+            return;
+        } else if (strcmp(newString[0], "tempR") == 0) {
+            resdGunAndChillerTemp();
+        }
+
+        if ((strcmp(newString[0], "chiller") != 0) &&
+                (strcmp(newString[1], "-1") == 0 ||
+                 strcmp(newString[1], "") == 0)
+           ) {
+            printf("argc 1 is error parameter\r\n");
+            continue;
+        }
+
+        if (atoi(newString[2]) > 255 ||
+                atoi(newString[2]) == -1) {
+            printf("temperature value overflow\r\n");
+            continue;
+        }
+
+        _GunIndex = atoi((char *)newString[1]);
+
+        if (_GunIndex >= pSysConfig->TotalConnectorCount) {
+            printf("gun index over total connector\r\n");
+            continue;
+        }
+
+        if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值
+            if (_GunIndex >= 1) {
+                _GunIndex = 0; //只會有一個水冷機
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+            pDcChargingInfo->ChillerTemp = atoi(newString[2]);
+            printf("set %d chiller temperature = %d\r\n",
+                   _GunIndex,
+                   pDcChargingInfo->ChillerTemp);
+        } else if (strcmp(newString[0], "conn") == 0) {//修改槍頭溫度值
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+            pDcChargingInfo->ConnectorTemp = atoi(newString[2]);
+            printf("set %d connector temp = %d\r\n",
+                   _GunIndex,
+                   pDcChargingInfo->ConnectorTemp);
+        }
+
+        usleep(sleepTime);
+    }//while
+}
+
+int main(void)
+{
+    uint8_t _GunIndex = 0;
+    int isContinue = 1;
+    char *usageMsg = "Usage:\n"
+                     "       state <index>                     : get gun state\n"
+                     "       card                              : scanning card (x)\n"
+                     "       gun <index>                       : get gun plugit state\n"
+                     "       lock <index>                      : get gun locked state\n"
+                     "       sysid                             : test system ID\n"
+                     "       self                              : self test state (x)\n"
+                     "       version | v | -v                  : version of board (407 or relay or other)\n"
+                     "       update                            : update firmware\n"
+                     "       ac                                : get ac relay state (x) \n"
+                     "       cable <index> <state>             : set ground fault state\n"
+                     "       pow <index> <power>               : set power value\n"
+                     "       model                             : get system information\n"
+                     "       temp                              : get PSU temperature\n"
+                     "       fan <speed>                       : set fan board speed\n"
+                     "       strchg <auto>                     : auto test charging\n"
+                     "       strchg <index> <voltage <current> : select gun test charging\n"
+                     "       tempW                             : write connector header and Chiller temperature\r\n"
+                     "       tempR                             : print connector header and chiller temperature\r\n"
+    			     "       btnl                              : press left button\n"
+    			  	 "       btnr                              : press right button\n"
+                     "\r\n";
+
+    if (CreateAllCsuShareMemory() == FAIL) {
+        printf("create share memory error\r\n");
+        return FAIL;
+    }
+
+    MappingGunChargingInfo("ReadCmdline Task");
+
+    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();
+
+    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+    ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
+    ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
+    ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
+    ShmPsuData = (struct PsuData *)GetShmPsuData();
+    ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+
+//    for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
+//        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+//        pDcChargingInfo->SystemStatus = S_IDLE;
+//    }
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            continue;
+        }
+
+        if (strcmp(newString[0], "state") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // 槍狀態
+            RunStatusProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "card") == 0) {
+            // 刷卡狀態
+            RunCardProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "gun") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // 插槍狀態
+            RunGunPlugitProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "lock") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // 插槍狀態
+            GetGunLockStatusProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "sysid") == 0) {
+            // 測試 sys id
+            SetSystemIDProc();
+        } else if (strcmp(newString[0], "self") == 0) {
+            // CSU 自我檢測狀態
+            RunSelfProc(newString[1]);
+        } else if (strcmp(newString[0], "version") == 0 ||
+                   strcmp(newString[0], "v") == 0 ||
+                   strcmp(newString[0], "-v") == 0) {
+            //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+            //    continue;
+            //}
+            // 取 FW 版號
+            GetFwVerProc();
+        } else if (strcmp(newString[0], "update") == 0) {
+            // 更新
+            FwUpdateFlagProc(newString[1]);
+        } else if (strcmp(newString[0], "ac") == 0) {
+            // AC contactor 狀態
+            CheckAcStatus(newString[1]);
+        } else if (strcmp(newString[0], "cable") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // cable check pass
+            SetCableChkStatus(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "pow") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                continue;
+            }
+            // cable check pass
+            SetPowerValue(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "model") == 0) {
+            GetSystemInfo();
+        } else if (strcmp(newString[0], "select") == 0) {
+            // 取得 / 設定 當前選的槍號
+            GetGunSelectedNum(newString[1]);
+        } else if (strcmp(newString[0], "change") == 0) {
+            // 模擬按鈕改變選槍
+            ChangeGunNum();
+        } else if (strcmp(newString[0], "fan") == 0) {
+            // 設定風扇速度
+            SetFanSpeed(newString[1]);
+        } else if (strcmp(newString[0], "speed") == 0) {
+            // 取得風扇速度
+            GetFanSpeed();
+        } else if (strcmp(newString[0], "debug") == 0) {
+            // 設定 debug mode
+            SetDebugMode(newString[1]);
+        } else if (strcmp(newString[0], "gfd") == 0) {
+            // 設定盲沖使用 GFD 功能
+            SetGFDMode(newString[1]);
+        } else if (strcmp(newString[0], "temp") == 0) {
+            // 取得 PSU 溫度
+            GetPsuTemp();
+        } else if (strcmp(newString[0], "acin") == 0) {
+            // 取得三向輸入電壓
+            GetAcInputVol();
+        } else if (strcmp(newString[0], "psu") == 0) {
+            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf ("PSU : Param fail..Please retry again......\n");
+                continue;
+            }
+            // 取得 PSU 資訊
+            GetPsuInformation(newString[1], newString[2], newString[3]);
+        } else if (strcmp(newString[0], "cap") == 0) {
+            GetConnectorCapInfo(newString[1]);
+        } else if (strcmp(newString[0], "error") == 0) {
+            CreateOneError(newString[1]);
+        } else if (strcmp(newString[0], "auth") == 0) {
+            GetAuthorizeFlag(newString[1]);
+        } else if (strcmp(newString[0], "relay") == 0) {
+            GetRelayStatus(newString[1]);
+        } else if (strcmp(newString[0], "ccid") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
+                    strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+                printf ("Input ccid fail.\n");
+                continue;
+            }
+            SetChargingInfoCCID(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "strchg") == 0) {
+            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
+            if (strcmp(newString[1], "auto") == 0) {
+                newString[2][0] = 0;
+                newString[3][0] = 0;
+            } else if (strcmp(newString[1], "-1") == 0 ||
+                       strcmp(newString[1], "") == 0   ||
+                       strcmp(newString[2], "-1") == 0 ||
+                       strcmp(newString[2], "") == 0) {
+                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
+                continue;
+            }
+
+            // 槍狀態
+            RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
+        } else if (strcmp(newString[0], "tempW") == 0) { //測試槍頭和水冷機溫度
+            writeGunAndChillerTemp();
+        } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
+            resdGunAndChillerTemp();
+        } else if (strcmp(newString[0], "btnl") == 0) {
+        	ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_PRESS;
+        	sleep(1);
+        	ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_RELEASE;
+        } else if (strcmp(newString[0], "btnr") == 0) {
+        	ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_PRESS;
+        	sleep(1);
+        	ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_RELEASE;
+        } else {
+            printf("%s\n", usageMsg);
+        }
+
+        sleep(1);
+    }//while
+
+    return 0;
+}

+ 24 - 15
EVSE/Projects/DD360UCar/Apps/Readme.md

@@ -504,11 +504,9 @@ void InitialShareMemoryInfo(void)
 
     memset(pSysInfo->FanModuleFwRev, 0, ARRAY_SIZE(pSysInfo->FanModuleFwRev));
     memset(pSysInfo->RelayModuleFwRev, 0, ARRAY_SIZE(pSysInfo->RelayModuleFwRev));
-#if defined DD360Audi
-    pSysInfo->SystemPage = _LCM_SELECT_GUN;
-#else
-    pSysInfo->SystemPage = _LCM_NONE;
-#endif //defined DD360Audi
+
+    pSysInfo->SystemPage = _LCM_VIEW;
+
     pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
     pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
     pSysInfo->CurGunSelectedByAc = NO_DEFINE;
@@ -550,7 +548,7 @@ int InitSelectGunShmMem(void)
 {
     int MeterSMId = FAIL;
 
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     return;
 #endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
 
@@ -765,7 +763,7 @@ void ClearAllShmMemParameter(void)
     //memset(ShmCsuMeterInfo, 0, sizeof(struct MeterInformation));
     memset(ShmDcCommonData, 0, sizeof(DcCommonInfo));
 
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+#if defined DD360 || defined DD360Audi || defined DD360ComBox || defined DD360UCar
     memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
 
     for (i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
@@ -880,7 +878,10 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
 
     case '6': // GB/T AC Socket
         break;
-
+    case '7': // CCS2 AC plug
+        break;
+    case '8': // Type E Socket
+        break;
     //DC Gun Type --------------------------------------------------------------
     case 'J':  // CHAdeMO
     case 'K':  // CHAdeMO 200A
@@ -905,16 +906,15 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
         }
         break;
 
+    case 'V': // Liquid CCS1 combo
+    case 'F': // Liquid CCS2 combo
     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
     case 'M': // 80A CCS2
     case 'N': // 80A CCS1
-    case 'P': // Phoenix CCS2 500A 水冷
-    case 'R': // Phoenix CCS1 500A 水冷
+    case 'P': // 急電弓
         if (CCS_QUANTITY > gGunIndexInfo.CcsIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[gGunIndexInfo.CcsIndex];
 
@@ -934,16 +934,25 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
                 gGunIndexInfo.CcsIndex++;
                 gGunIndexInfo.DcGunIndex++;
             }
-            if(typeValue == 'P')
-            {
+            if(typeValue == 'P') {
                 pDcChargingInfo->PantographFlag = YES;
-            }
+            } else if (typeValue == 'V') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Liquid;
+            } else if (typeValue == 'F') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Liquid;
+            } else if (typeValue == 'T' || typeValue == 'U' || typeValue == 'N') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Natural;
+            } else if (typeValue == 'D' || typeValue == 'E' || typeValue == 'M') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Natural;
+            } else
+                pDcChargingInfo->CCSGunType = _TYPE_CCS_NONE;
         } else {
             result = false;
         }
         break;
 
     case 'G':  // GBT DC
+    case 'B': // GBT YG PT100
         if (GB_QUANTITY > gGunIndexInfo.GbIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex];
 

BIN
EVSE/Projects/DD360UCar/Apps/ShareMemory/shmMem.h


+ 10 - 6
EVSE/Projects/DD360UCar/Apps/common.c

@@ -53,6 +53,7 @@ void SetFaultTest()
 {
     pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = NO;
     pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = NO;
+    pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = NORMAL;
     pSysWarning->Level = WARN_LV_NL;
 
 }
@@ -61,22 +62,18 @@ void SetSelfTest(bool status)
     uint8_t index = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-    struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
 
-    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();
     ShmRelayModuleData->SelfTest_Comp = status;
 
     if (status) {
         strcpy((char*)pSysInfo->RelayModuleFwRev,SIM_VERSION);
         strcpy((char*)pSysInfo->FanModuleFwRev,SIM_VERSION);
-        strcpy((char*)ShmPrimaryMcuData->version,SIM_VERSION);
+        strcpy((char*)pSysInfo->CsuPrimFwRev,SIM_VERSION);
         for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
             if (pDcChargingInfo->Type == _Type_Chademo) {
@@ -98,7 +95,7 @@ void main()
 
     if (CreateAllCsuShareMemory() == FAIL) {
         printf("create share memory error");
-        return FAIL;
+        return;
     }
 
     MappingGunChargingInfo("Simulation Task");
@@ -128,13 +125,20 @@ void main()
             case S_REASSIGN:
                 break;
             case S_PREPARNING:
+                //ShmPsuData->SystemPresentPsuQuantity = 500;
+                //ShmPsuData->SystemAvailablePower = 500;
                 break;
             case S_PREPARING_FOR_EV:
+                pDcChargingInfo->GunLocked = START;
                 break;
             case S_PREPARING_FOR_EVSE:
+                pDcChargingInfo->GroundFaultStatus = GFD_PASS;
                 break;
             case S_CCS_PRECHARGE_ST0:
             case S_CCS_PRECHARGE_ST1:
+                ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus = 45;
+                sleep(1);
+                pDcChargingInfo->RelayK1K2Status = YES;
                 break;
 
             case S_CHARGING:

+ 4 - 5
EVSE/Projects/DD360UCar/Apps/simulation.h

@@ -32,18 +32,14 @@
 #include    <ctype.h>
 #include    <ifaddrs.h>
 
-//------------------------------------------------------------------------------
-#define CONN_PLUG_TIME_OUT                      (40)
-
 //------------------------------------------------------------------------------
 enum Timeout_flag {
     Timeout_None                   = 0,
     Timeout_SelftestChk            = 1,
     Timeout_Authorizing            = 2,
     Timeout_VerifyFail             = 3,
-    Timeout_VerifyComp             = 4,
+    Timeout_ReturnViewPage         = 4,
     Timeout_WaitPlug               = 5,
-
     Timeout_Preparing              = 6,
     Timeout_EvChargingDet          = 7,
     Timeout_EvseChargingDet        = 8,
@@ -54,6 +50,9 @@ enum Timeout_flag {
     Timeout_SelectGun              = 13,
     Timeout_WaitBalance            = 14,
     Timeout_EVCCID_Link            = 15,
+	Timeout_LinkError              = 16,
+	Timeout_DetailView             = 17,
+	Timeout_Terminating            = 18,
 };
 
 //------------------------------------------------------------------------------

+ 8 - 6
build_rootfs_copy.sh

@@ -2,10 +2,12 @@
 sudo rm /dev/ram*
 sleep 3
 rm /mnt/e/Temp/IMAGE/*
-sudo make DD360Audi-rootfs
-cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360Audi/Images/* /mnt/e/Image/DD360Audi/
-sudo make DD360-rootfs
-cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360/Images/* /mnt/e/Image/DD360/
-sudo make DD360ComBox-rootfs
-cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360ComBox/Images/* /mnt/e/Image/DD360ComBox/
+#sudo make DD360Audi-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360Audi/Images/* /mnt/e/Image/DD360Audi/
+#sudo make DD360-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360/Images/* /mnt/e/Image/DD360/
+#sudo make DD360ComBox-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360ComBox/Images/* /mnt/e/Image/DD360ComBox/
+sudo make DD360UCar-rootfs
+cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360UCar/Images/* /mnt/e/Image/DD360UCar/
 

+ 2 - 0
copy_project_from_D.sh

@@ -0,0 +1,2 @@
+#!/bin/bash
+sudo cp -r /mnt/d/Phihong/Project/DD360UCar/Apps/* /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360UCar/Apps

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików