Эх сурвалжийг харах

2022-07-25 / Simon Xue

Action:
1. [Mod] Connect timer calcuate by board timer.
2. [Mod] Seperate plugin timer according to each gun status.
3. [Mod] LCM PAGE won't show one gun in charing and other gun in
precharing page. Only show Precharging  page.

Files
As the following commit history files

Image Version: V2.09.XX.XXXX.XX
Simon Xue 2 жил өмнө
parent
commit
17b29f9e15
38 өөрчлөгдсөн 316 нэмэгдсэн , 229 устгасан
  1. 5 5
      EVSE/Projects/DD360UCar/Apps/CSU/OCPP.c
  2. 4 4
      EVSE/Projects/DD360UCar/Apps/CSU/Primary.c
  3. 11 11
      EVSE/Projects/DD360UCar/Apps/CSU/RFID.c
  4. 147 111
      EVSE/Projects/DD360UCar/Apps/CSU/main.c
  5. 3 3
      EVSE/Projects/DD360UCar/Apps/CSU/main.h
  6. 1 0
      EVSE/Projects/DD360UCar/Apps/Config.h
  7. 0 1
      EVSE/Projects/DD360UCar/Apps/DataBase/DataBase.c
  8. 16 11
      EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.c
  9. 18 11
      EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvTxComm.c
  10. 5 5
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/AcPlug.c
  11. 3 3
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/FanBoard.c
  12. 4 4
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/LEDlight.c
  13. 14 4
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/Module_InternalComm.c
  14. 2 1
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/Module_InternalComm.h
  15. 19 19
      EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/RelayBoard.c
  16. 9 5
      EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.c
  17. 8 4
      EVSE/Projects/DD360UCar/Apps/ModulePrimary/Module_PrimaryComm.c
  18. 8 6
      EVSE/Projects/DD360UCar/Apps/ModulePsuComm/Module_PsuComm.c
  19. 4 4
      EVSE/Projects/DD360UCar/Apps/ModulePsuComm/Module_PsuComm.h
  20. 15 6
      EVSE/Projects/DD360UCar/Apps/OutputTask.c
  21. 1 1
      EVSE/Projects/DD360UCar/Apps/OutputTask.h
  22. 16 7
      EVSE/Projects/DD360UCar/Apps/ReadCmdline.c
  23. BIN
      EVSE/Projects/DD360UCar/Apps/UnsafetyOutputTask
  24. 3 3
      EVSE/Projects/DD360UCar/Apps/timeout.h
  25. BIN
      EVSE/Projects/DD360UCar/Images/ramdisk.gz
  26. BIN
      EVSE/Projects/DD360UCar/output/FactoryConfig
  27. BIN
      EVSE/Projects/DD360UCar/output/Module_ChkSysTask
  28. BIN
      EVSE/Projects/DD360UCar/output/Module_DoComm
  29. BIN
      EVSE/Projects/DD360UCar/output/Module_EvComm
  30. BIN
      EVSE/Projects/DD360UCar/output/Module_EventLogging
  31. BIN
      EVSE/Projects/DD360UCar/output/Module_InternalComm
  32. BIN
      EVSE/Projects/DD360UCar/output/Module_LcmControl
  33. BIN
      EVSE/Projects/DD360UCar/output/Module_LcmWistronControl
  34. BIN
      EVSE/Projects/DD360UCar/output/Module_PrimaryComm
  35. BIN
      EVSE/Projects/DD360UCar/output/Module_UpdateFW
  36. BIN
      EVSE/Projects/DD360UCar/output/ReadCmdline
  37. BIN
      EVSE/Projects/DD360UCar/output/UnsafetyOutputTask
  38. BIN
      EVSE/Projects/DD360UCar/output/main

+ 5 - 5
EVSE/Projects/DD360UCar/Apps/CSU/OCPP.c

@@ -405,7 +405,7 @@ void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result)
         ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStartTransactionReq = result;
     }
 }
-
+/*
 void ocpp_chk_remoteStart_cmd()
 {
     if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
@@ -422,7 +422,7 @@ void ocpp_chk_remoteStart_cmd()
                     ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                     //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
                     //ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
+                    DetectPluginStart(ac_index);
                     return;
                 }
                 ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
@@ -473,7 +473,7 @@ void ocpp_chk_remoteStart_cmd()
                 chargingInfo[dcIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
                 //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
-                DetectPluginStart();
+                DetectPluginStart(dcIndex);
             }
             ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
         } else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart) {
@@ -481,13 +481,13 @@ void ocpp_chk_remoteStart_cmd()
                     chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION) {
                 chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
                 ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-                DetectPluginStart();
+                DetectPluginStart(dcIndex);
             }
             chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
         }
     }
 }
-
+*/
 void ocpp_chk_update_cmd()
 {
     if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16) {

+ 4 - 4
EVSE/Projects/DD360UCar/Apps/CSU/Primary.c

@@ -45,7 +45,7 @@ void EnterAuthorizePage(uint8_t gunIndex)
 {
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
     log_info("Select Gun(%d) in Authorizing",gunIndex);
-    ClearDetectPluginFlag();
+    ClearDetectPluginFlag(gunIndex);
     ChangeGunSelectByIndex(gunIndex);
     confirmSelGun(gunIndex);
     ChangeLCM(_LCM_START_SCAN);
@@ -131,7 +131,7 @@ void showConfirmStopPage(uint8_t gunIndex)
 void CheckLeftButton()
 {
     DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
-    uint8_t gunIndex = 0;
+
     pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
     switch (pSysInfo->SystemPage) {
         case _LCM_VIEW:
@@ -208,7 +208,6 @@ void CheckLeftButton()
 }
 void CheckRightButton()
 {
-    uint8_t gunIndex = 0;
     DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
     switch (pSysInfo->SystemPage) {
@@ -243,8 +242,9 @@ void CheckRightButton()
             ReturnAuthorize();
             break;
         case _LCM_WAIT_PLUGIN:
-            if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM)
+            if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM) {
                 ReturnIDLE(RIGHT_GUN_NUM);
+            }
         	break;
         case _LCM_LINK_ERROR:
             if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM) {

+ 11 - 11
EVSE/Projects/DD360UCar/Apps/CSU/RFID.c

@@ -124,16 +124,16 @@ bool RfidStopCharging(void)
 }
 static void UserScanFunction(void)
 {
-    bool idleReq = false;
-    uint8_t i = 0;
-    uint8_t stopReq = NO_DEFINE;
-    char value[32] = {0};
-    static uint8_t _authorizeIndex = NO_DEFINE;
+    //bool idleReq = false;
+    //uint8_t i = 0;
+    //uint8_t stopReq = NO_DEFINE;
+    //char value[32] = {0};
+    //static uint8_t _authorizeIndex = NO_DEFINE;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-    struct ChargingInfoData *pAcChargingInfo =  (struct ChargingInfoData *)GetAcChargingInfoData(0);
+    //struct ChargingInfoData *pAcChargingInfo =  (struct ChargingInfoData *)GetAcChargingInfoData(0);
     struct ChargingInfoData *pDcChargingInfo = NULL;
-    GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
+    //GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
     // 當前非驗證的狀態
     if (IsAuthorizingMode()) {
@@ -275,7 +275,7 @@ void AuthorizeToCharge()
                 if (!pDcChargingInfo->ConnectorPlugIn)
                     pSysInfo->SystemPage = _LCM_WAIT_PLUGIN;
                 log_info("Wait Gun(%d) plugin",pSysInfo->CurGunSelected);
-                DetectPluginStart();
+                DetectPluginStart(pSysInfo->CurGunSelected);
                 log_info("Gun(%d) Balance: %f",pSysInfo->CurGunSelected,
                         ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
             } else {
@@ -295,7 +295,7 @@ void ScannerCardProcess(void)
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
 
-    if (!isDetectPlugin() && pSysInfo->SystemPage == _LCM_START_SCAN &&
+    if (!isDetectPlugin(pSysInfo->CurGunSelected) && pSysInfo->SystemPage == _LCM_START_SCAN &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
         isCardScan = true;
@@ -308,8 +308,8 @@ void ScannerCardProcess(void)
     } else if (pSysInfo->SystemPage == _LCM_START_AUTHORIZE_FAIL) {
         StartSystemTimeoutDet(Timeout_VerifyFail);
         isCardScan = false;
-    } else if (pSysInfo->SystemPage == _LCM_WAIT_PLUGIN) {
-        StartSystemTimeoutDet(Timeout_WaitPlug);
+    //} else if (pSysInfo->SystemPage == _LCM_WAIT_PLUGIN) {
+    //    StartSystemTimeoutDet(Timeout_WaitPlug);
     } else {
         isCardScan = false;
     }

+ 147 - 111
EVSE/Projects/DD360UCar/Apps/CSU/main.c

@@ -88,12 +88,12 @@ char* DebugVersion = "V2.09.00";      // Software debug version
 bool isDb_ready;
 
 //------------------------------------------------------------------------------
-void ClearDetectPluginFlag();
+void ClearDetectPluginFlag(int gunIndex);
 
 long long DiffTimebWithNow(struct timeb ST);
 uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
 void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
+unsigned long GetTimeoutValue(struct timespec _start_time);
 void GetClockTime(struct timespec *_now_time, void *null);
 unsigned long GetClockTimeoutValue(struct timespec _start_time);
 void gpio_set_value(unsigned int gpio, unsigned int value);
@@ -758,19 +758,39 @@ static void checkEvBoardAlarmState(uint8_t gunType)
     }
 }
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+unsigned long GetSecTimeoutValue(struct timespec _start_time)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000) + ((unsigned long)((ts_end.tv_nsec / 1000000) - (_start_time.tv_nsec / 1000000)));
+    /*
+    printf("\r\n TimeInterval: %ld.%09ld - %ld.%09ld = %ld.%03ld ms",
+        ts_end.tv_sec, ts_end.tv_nsec,  _start_time.tv_sec, _start_time.tv_nsec,
+        (ret / 1000), (ret % 1000));
+    */
+    ret /= 1000;
+
+    return ret;
 }
 
 void GetClockTime(struct timespec *_now_time, void *null)
 {
     clock_gettime(CLOCK_MONOTONIC, _now_time);
 }
+unsigned long GetTimeoutValue(struct timespec _start_time)
+{
+    struct timespec ts_end;
+    unsigned long ret = 0;
 
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
+
+    return ret;
+}
 // return value unit: 1us
 unsigned long GetClockTimeoutValue(struct timespec _start_time)
 {
@@ -1201,7 +1221,7 @@ int Initialization(void)
     ClearAuthorizedFlag();
 
     // 初始化插槍驗證的 Flag
-    ClearDetectPluginFlag();
+    ClearDetectPluginFlag(pSysInfo->CurGunSelected);
 
     for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
@@ -1347,34 +1367,30 @@ bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
 //===============================================
 // 掃描插槍狀況
 //===============================================
-void ClearDetectPluginFlag(void)
+void ClearDetectPluginFlag(int gunIndex)
 {
-    uint8_t gunIndex = 0;
-    pSysInfo->WaitForPlugit = NO;
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
 
-    //DS60-120 add
-    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-        /*
-        if (pDcChargingInfo->RemoteStartFlag == YES) {
-            pDcChargingInfo->RemoteStartFlag = NO;
-        }
-        */
+    if (pDcChargingInfo->RemoteStartFlag == YES) {
+        pDcChargingInfo->RemoteStartFlag = NO;
     }
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
+
 
     if (pSysInfo->OrderCharging != NO_DEFINE) {
         pSysInfo->OrderCharging = NO_DEFINE;
     }
 }
 
-void DetectPluginStart()
+void DetectPluginStart(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = YES;
+    //pSysInfo->WaitForPlugit = YES;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
 }
 
-bool isDetectPlugin()
+bool isDetectPlugin(int gunIndex)
 {
-    if (pSysInfo->WaitForPlugit == YES) {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
         return true;
     }
 
@@ -1469,7 +1485,7 @@ bool isEvGunLocked_ccs(uint8_t gunIndex)
 
 uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
 {
-    uint8_t result = 0x00;
+
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
     return ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;
@@ -1529,7 +1545,7 @@ void _AutoReturnTimeout(void)
         pDcChargingInfo->SystemStatus = S_ALARM;
         //pSysInfo->SystemPage = _LCM_ERROR;
         pSysInfo->SystemPage = _LCM_MAINTAIN;
-        ClearDetectPluginFlag();
+        ClearDetectPluginFlag(pSysInfo->CurGunSelected);
     } else if (pSysInfo->SystemPage ==_LCM_START_AUTHORIZE_FAIL) {
         pSysInfo->SystemPage = _LCM_START_SCAN;
         StartSystemTimeoutDet(Timeout_ReturnViewPage);
@@ -1566,16 +1582,17 @@ void _AuthorizedTimeout(void)
     //}
 }
 
-void _DetectPlugInTimeout(void)
+void _DetectPlugInTimeout(int gunIndex)
 {
     log_info("*********** _DetectPlugInTimeout *********** ");
     strcpy((char *)pSysConfig->UserId, "");
-    StopSystemTimeoutDet();
-    pSysInfo->SystemPage = _LCM_LINK_ERROR;
-    StartSystemTimeoutDet(Timeout_ReturnViewPage);
-    ClearDetectPluginFlag();
-	//setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
-    //systemPageRestoreInit();
+
+    //pSysInfo->SystemPage = _LCM_LINK_ERROR;
+    //StartSystemTimeoutDet(Timeout_ReturnViewPage);
+    ClearDetectPluginFlag(gunIndex);
+	setChargerMode(gunIndex, S_IDLE);
+    if (pSysInfo->CurGunSelected == gunIndex)
+        systemPageRestoreInit();
 }
 
 void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
@@ -2458,7 +2475,7 @@ void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
 
     if (gunIndex < pSysConfig->TotalConnectorCount) {
         if (pDcChargingInfo->TimeoutFlag != flag) {
-            gettimeofday(&pDcChargingInfo->TimeoutTimer, NULL);
+            GetClockTime(&pDcChargingInfo->ConnectorTimeout, NULL);
             //log_info("Set Gun%d Timeout Flag %d", gunIndex,flag);
         }
         pDcChargingInfo->TimeoutFlag = flag;
@@ -2498,7 +2515,7 @@ void CreateTimeoutFork(void)
 
     timeoutPid = fork();
     if (timeoutPid == 0) {
-        gettimeofday(&_cmdSubPriority_time, NULL);
+        GetClockTime(&_cmdSubPriority_time, NULL);
         CheckConnectionTimeout();
 
         //log_info("Timeout Fork Child's PID is %d", getpid());
@@ -2506,7 +2523,7 @@ void CreateTimeoutFork(void)
         while (1) {
             if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
                 CheckConnectionTimeout();
-                gettimeofday(&_cmdSubPriority_time, NULL);
+                GetClockTime(&_cmdSubPriority_time, NULL);
             }
             //if (pSysInfo->SystemTimeoutFlag != 0)
             //log_info("Timeout ***********SystemTimeoutFlag = %d(%d) ********",pSysInfo->SystemTimeoutFlag,
@@ -2581,13 +2598,6 @@ void CreateTimeoutFork(void)
                 }
                 break;
 
-            case Timeout_WaitPlug:
-                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
-                    _DetectPlugInTimeout();
-
-                    //destroySelGun(pSysInfo->CurGunSelected);
-                }
-                break;
 /*
             case Timeout_ReturnToChargingGunDet:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
@@ -2623,17 +2633,17 @@ void CreateTimeoutFork(void)
                 /*
                 if (pDcChargingInfo->TimeoutFlag != 0)
                 log_info("Timeout ***********GunTimeoutFlag = %d(%d) ********",pDcChargingInfo->TimeoutFlag,
-                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL);
+                        GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL);
                         */
                 switch (pDcChargingInfo->TimeoutFlag) {
                 case Timeout_EVCCID_Link:
-                if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= EVCCID_LINK_TIMEOUT) {
+                if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= EVCCID_LINK_TIMEOUT) {
                     _evccidlinktimeout(gunIndex);
                 	}
                 break;
 
                 case Timeout_Preparing:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
                         _PrepareTimeout(gunIndex);
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
@@ -2641,7 +2651,7 @@ void CreateTimeoutFork(void)
                     break;
 
                 case Timeout_EvChargingDet:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
                         _DetectEvChargingEnableTimeout(gunIndex);
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
@@ -2649,7 +2659,7 @@ void CreateTimeoutFork(void)
                     break;
 
                 case Timeout_EvseChargingDet:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
                         _DetectEvseChargingEnableTimeout(gunIndex);
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
@@ -2657,14 +2667,14 @@ void CreateTimeoutFork(void)
                     break;
 
                 case Timeout_EvseCompleteDet:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
                     }
                     break;
 
                 case Timeout_ForCcsPrechargeDet:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
                         _CcsPrechargeTimeout(gunIndex);
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
@@ -2672,7 +2682,7 @@ void CreateTimeoutFork(void)
                     break;
                     /*
                 case Timeout_SelectGun: //Jerry add
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
                         log_info("Timeout_SelectGun");
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
@@ -2680,21 +2690,21 @@ void CreateTimeoutFork(void)
                     break;
                     */
                 case Timeout_PlugOut:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= PLUGOUT_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= PLUGOUT_TIMEOUT) {
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
                         setChargerMode(gunIndex, S_IDLE);
                     }
                     break;
                 case Timeout_GunAuthorizePage:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_AUTHORIZE_PAGE) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= GUN_AUTHORIZE_PAGE) {
                         StopGunInfoTimeoutDet(gunIndex);
                         destroySelGun(gunIndex); //jerry add
                         pDcChargingInfo->SystemStatus = S_IDLE;
                     }
                     break;
                 case Timeout_Terminating:
-                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TERMINATING_TIMEOUT) {
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= TERMINATING_TIMEOUT) {
                         StopGunInfoTimeoutDet(gunIndex);
                         pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
 
@@ -2703,6 +2713,14 @@ void CreateTimeoutFork(void)
                         setChargerMode(gunIndex, S_COMPLETE);
                     }
                     break;
+
+                case Timeout_WaitPlug:
+                    if (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL >= _connectionTimeout) {
+                        StopGunInfoTimeoutDet(gunIndex);
+                        _DetectPlugInTimeout(gunIndex);
+                        destroySelGun(gunIndex);
+                    }
+                    break;
                 }
             }
             sleep(1);
@@ -2860,36 +2878,35 @@ void OcppRemoteStartChk()
 {
     if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
 
-    } else if (!isDetectPlugin()) {
+    } else {
         // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
         uint8_t acDirIndex = pSysConfig->AcConnectorCount;
+        if (!isDetectPlugin(acDirIndex)) {
+            for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
+                pAcChargingInfo = (struct ChargingInfoData*)GetAcChargingInfoData(ac_index);
 
-        for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
-            pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(ac_index);
-
-            if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
-                if (pAcChargingInfo->SystemStatus == S_IDLE ||
+                if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
+                    if (pAcChargingInfo->SystemStatus == S_IDLE ||
                         pAcChargingInfo->SystemStatus == S_RESERVATION) {
+                        ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
+                        pAcChargingInfo->RemoteStartFlag = YES;
+                        pSysInfo->OrderCharging = YES;
+                        //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
+                        ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
+                        DetectPluginStart(acDirIndex);
+                        return;
+                    }
                     ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-                    pAcChargingInfo->RemoteStartFlag = YES;
-                    pSysInfo->OrderCharging = YES;
-                    //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
-                    ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-                    DetectPluginStart();
-                    return;
                 }
-                ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
             }
         }
-
-        uint8_t threeGunIndex = 0;
-        uint8_t dcIndex = 0;
-        bool isGunUsingStatus = false;
-        bool _remotestarting = false;
+        //uint8_t threeGunIndex = 0;
+        //uint8_t dcIndex = 0;
+        //bool isGunUsingStatus = false;
 
         for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
+            /*
             // 如果有 AC 槍,且 DC 槍也有兩把
             if (acDirIndex == 1 && _index == 1) {
                 threeGunIndex = 1;
@@ -2903,7 +2920,7 @@ void OcppRemoteStartChk()
                 isGunUsingStatus = true;
             }
             if (pDcChargingInfo->RemoteStartFlag == YES) {
-            	_remotestarting = true;
+                //_remotestarting = true;
             }
         }
 
@@ -2920,24 +2937,26 @@ void OcppRemoteStartChk()
         if (dcIndex == 0) {
             threeGunIndex = 0;
         }
+        */
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
 
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(dcIndex);
-
-        if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES &&
-        		!_remotestarting ) {
-            if (pDcChargingInfo->SystemStatus == S_IDLE ||
-            		pDcChargingInfo->SystemStatus == S_AUTHORIZING ||
+            if (ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq == YES &&
+                !isDetectPlugin(_index)) {
+                if (pDcChargingInfo->SystemStatus == S_IDLE ||
+                    pDcChargingInfo->SystemStatus == MODE_AUTHORIZING ||
                     pDcChargingInfo->SystemStatus == S_RESERVATION) {
-                pDcChargingInfo->RemoteStartFlag = YES;
-                pSysInfo->OrderCharging = YES;
-                //pDcChargingInfo->SystemStatus = S_AUTHORIZING;
-                //pSysInfo->OrderCharging = gunIndex;
-                ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
-                DetectPluginStart();
-                setSelGunWaitToAuthor(dcIndex);
-                log_info("Ocpp Remote Start Pass");
+                    pDcChargingInfo->RemoteStartFlag = YES;
+                    //ShmDcCommonData->is_RemoteStart[_index] = TRUE;
+                    //pSysInfo->OrderCharging = YES;
+                    //pDcChargingInfo->SystemStatus = S_AUTHORIZING;
+                    //pSysInfo->OrderCharging = gunIndex;
+                    ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
+                    DetectPluginStart(_index);
+                    setSelGunWaitToAuthor(_index);
+                    log_info("Ocpp Remote Start Gun%d Pass", _index);
+                }
+                ShmOCPP16Data->CsMsg.bits[_index].RemoteStartTransactionReq = NO;
             }
-            ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
         }
     }
 }
@@ -3110,7 +3129,6 @@ void ChangeStartOrStopDateTime(uint8_t isStart, uint8_t gunIndex)
 }
 void GetChargeTranscationDateTime(uint8_t gunIndex)
 {
-    char cmdBuf[32];
     struct timeb csuTime;
     struct tm* tmCSU;
 
@@ -3827,7 +3845,7 @@ void ResetIdleData(uint8_t gunIndex)
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
     ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
     ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-
+    float powerconsumption = ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption;
     pDcChargingInfo->PresentChargedDuration = 0;
     pDcChargingInfo->RemainChargingDuration = 0;
     pDcChargingInfo->PresentChargingVoltage = 0;//DS60-120 add
@@ -3841,11 +3859,13 @@ void ResetIdleData(uint8_t gunIndex)
     ShmDcCommonData->isIntoCharge[gunIndex] = FALSE;
     ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
 
-    ClearDetectPluginFlag();
+    ClearDetectPluginFlag(gunIndex);
     //Jerry add
     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
     memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
-    DB_Get_PowerConsumption(gunIndex);
+
+    ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = powerconsumption;
+
     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
     destroySelGun(gunIndex);
     ResetDetAlarmStatus(gunIndex); //recovery OVP status code
@@ -3874,7 +3894,7 @@ void CheckErrorCode(uint8_t gunIndex)
             systemPageRestoreInit();
         }
     }
-    ClearDetectPluginFlag();
+    ClearDetectPluginFlag(gunIndex);
     if (pDcChargingInfo->SystemStatus != S_FAULT)
     {
         UpdateErrorCodeToOcpp(gunIndex);
@@ -3939,7 +3959,6 @@ int main(void)
     bool isModelNameMatch = true;
     uint8_t _ocppProfileChkFlag;
     uint8_t gunIndex = 0;
-    uint8_t isplugin[2] = {0};
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error");
         return FAIL;
@@ -4058,16 +4077,15 @@ int main(void)
 
     CheckFwSlotStatusLog();
     //AdjustChargerCurrent();
-    gettimeofday(&_cmdMainPriority_time, NULL);
+    GetClockTime(&_cmdMainPriority_time, NULL);
 
-    GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
+    //GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
     CheckTaskAlive();
 
     CreateWatchdog();
-    int is_idle = TRUE;
-    time_t ShowEVStatusTimer[2] = { 0 };
-    int EVStatus[2];
+    int is_prepare0 = FALSE;
+    int is_prepare1 = FALSE;
     pSysInfo->OTPTemp = GUN_OTP_VALUE;
     pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
 
@@ -4115,26 +4133,42 @@ int main(void)
                 }
                 checkGunOTPState(gunIndex); //check gun OTP
             }
-            gettimeofday(&_cmdMainPriority_time, NULL);
+            GetClockTime(&_cmdMainPriority_time, NULL);
         }
 
         gEvBoardErr.GunErrMessage = 0; //清除系統執行中的錯誤訊息
         gChillerTempErr.TempErrMsg = 0;//清除系統執行中的錯誤訊息
-        is_idle = TRUE;
+        is_prepare0 = FALSE;
+        is_prepare1 = FALSE;
         for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
             // 重新收集各槍的錯誤狀態
             collectError(gunIndex);
             checkEvBoardAlarmState(pDcChargingInfo->Type);
-            if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
-                pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
+            if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
+                pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EVSE) ||
                 pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
                 pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
-                is_idle = FALSE;
+                (gunIndex == LEFT_GUN_NUM) ? (is_prepare0 = TRUE) : (is_prepare1 = TRUE);
             }
-
         }
-
+        // 檢查是否有槍處於Preparing & precharging 狀態
+        if (is_prepare0 && !is_prepare1) {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus != S_AUTHORIZING)
+                pSysInfo->CurGunSelected = LEFT_GUN_NUM;
+            else if (pDcChargingInfo->SystemStatus == S_AUTHORIZING) {
+                pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
+            }
+        } else if (!is_prepare0 && is_prepare1) {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
+            if (pDcChargingInfo->SystemStatus != S_AUTHORIZING)
+                pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
+            else if (pDcChargingInfo->SystemStatus == S_AUTHORIZING) {
+                pSysInfo->CurGunSelected = LEFT_GUN_NUM;
+            }
+        }
+        ////////////////////////////////////////
         checkChillerAlarmState();
 
         // 確認當前錯誤 Level = 2 ?
@@ -4243,7 +4277,8 @@ CheckStatus:
                 // 隨插即充
                 //autoStartCharging(gunIndex);
 
-                if (isDetectPlugin() && pSysInfo->SystemPage != _LCM_LINK_ERROR) {
+                if (isDetectPlugin(gunIndex) && pSysInfo->SystemPage != _LCM_LINK_ERROR) {
+                    StartGunInfoTimeoutDet(gunIndex, Timeout_WaitPlug);
                     // 卡號驗證成功後,等待充電槍插入充電車
                     if (pDcChargingInfo->RemoteStartFlag == YES) {
                         if (pDcChargingInfo->ConnectorPlugIn == YES &&
@@ -4256,7 +4291,7 @@ CheckStatus:
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             StopGunInfoTimeoutDet(gunIndex);
                             strcpy((char *)pDcChargingInfo->StartUserId, "");
-                            ClearDetectPluginFlag();
+                            ClearDetectPluginFlag(gunIndex);
                             continue;
                         }
                     } else if (pSysInfo->OrderCharging == NO_DEFINE) {
@@ -4279,7 +4314,7 @@ CheckStatus:
                             // 當前操作的槍號,進入 Preparing
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             StopGunInfoTimeoutDet(gunIndex);
-                            ClearDetectPluginFlag();
+                            ClearDetectPluginFlag(gunIndex);
                             continue;
                         }
                     }
@@ -4321,7 +4356,7 @@ CheckStatus:
 
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 1000000) {
+                        GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) >= 1000000) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 
@@ -4458,7 +4493,8 @@ CheckStatus:
                     ftime(&startChargingTime[gunIndex]);
                     strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
                     ChangeStartOrStopDateTime(YES, gunIndex);
-                    pSysInfo->SystemPage = _LCM_VIEW;
+                    if (pSysInfo->CurGunSelected == gunIndex)
+                        pSysInfo->SystemPage = _LCM_VIEW;
                     ShmDcCommonData->isIntoCharge[gunIndex] = TRUE;
                 }
 

+ 3 - 3
EVSE/Projects/DD360UCar/Apps/CSU/main.h

@@ -65,8 +65,8 @@
 //} LedConfig;
 
 //------------------------------------------------------------------------------
-bool isDetectPlugin(void);
-void _DetectPlugInTimeout(void);
+bool isDetectPlugin(int gunIndex);
+void _DetectPlugInTimeout(int gunIndex);
 void _evccidlinktimeout(uint8_t gunIndex);
 void StartSystemTimeoutDet(uint8_t flag);
 void StopSystemTimeoutDet(void);
@@ -78,7 +78,7 @@ void AuthorizingStart(void);
 bool IsAuthorizingMode(void);
 bool isAuthorizedComplete(void);
 void ClearAuthorizedFlag(void);
-void ClearDetectPluginFlag(void);
+void ClearDetectPluginFlag(int gunIndex);
 
 void ChargingAlarmProcess(uint8_t gunIndex);
 void StopChargingProcessByString(uint8_t level);

+ 1 - 0
EVSE/Projects/DD360UCar/Apps/Config.h

@@ -420,6 +420,7 @@ typedef struct StGunInfo {
     char ChargeStopTime[32];
     char ChargeDuration[32];
     uint8_t withChiller;      //是否有水冷機
+    uint8_t WaitForPlugit;    // 等待插槍FLAG
 } GunInfo;
 
 typedef struct Psu_VersionInfo{

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

@@ -319,7 +319,6 @@ int DB_Get_PowerConsumption(uint8_t gunIndex)
             for (int idxRow = 1; idxRow <= rows; idxRow++) {
                 ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = atof(rs[(idxRow * cols) + 2]);
                 log_info("Query connector-%d PowerConsumption: %s", gunIndex, rs[(idxRow * cols) + 2]);
-                
             }
         } else {
             log_info("Query connector-%d fail, set default value to operactive.", gunIndex);

+ 16 - 11
EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.c

@@ -61,7 +61,8 @@ static unsigned int LedIntensity = 0;
 static int TimeZoneOffset = 0;
 int RxLen;
 char Rxdata[1024];
-uint8_t _isplugin;
+
+uint8_t _isplugin[2] = { 0 };
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -500,6 +501,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     struct timeb SeqEndTime;
     struct tm *tm;
     char _setTime[50];
+    int is_idle = TRUE;
     uint8_t cmdBuf[128];
     if ((char *)&data[0] == '\0') {
         log_error("QR code date error");
@@ -519,13 +521,16 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
 
     //copy QR code string
     memset(ShmDcCommonData->QRCodeString, '\0', sizeof(ShmDcCommonData->QRCodeString));
-    //printf("data =  %s", data);
-    //len =
 
+    // 充電槍IDLE時才更新系統時間
+    for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+        if (pDcChargingInfo->SystemStatus != S_IDLE)
+            is_idle = FALSE;
+    }
     string2ByteArray((char *)data, (uint8_t *)ShmDcCommonData->QRCodeString);
     string2Date((char*)data, (uint8_t*)_setTime);
-    //printf("SystemId =  %s", pSysConfig->SystemId);
-    if (!timecmp(localTime, _setTime)) {
+    if (!timecmp(localTime, _setTime) && is_idle) {
         //log_info("Set Timer:%s Time Zone:%d", _setTime,ShmDcCommonData->TZOffset);
         sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
         system((char*)cmdBuf);
@@ -1773,13 +1778,13 @@ static int readChargingTimeStamp(int fd, uint8_t id)
 
     return ret;
 }
-static int writeWaitPlugItState(int fd, uint8_t id)
+static int writeWaitPlugItState(int fd, uint8_t id, uint8_t gunIndex)
 {
     int ret = PASS;
-    uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-    if (_isplugin != pSysInfo->WaitForPlugit) {
-        log_info("Wait for plug:%s", pSysInfo->WaitForPlugit == 0 ? "disable" : "enable");
-        _isplugin = pSysInfo->WaitForPlugit;
+    uint8_t data[2] = { ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit, 0 };
+    if (_isplugin[gunIndex] != ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit) {
+        //log_info("Wait Gun%d for plug:%s", gunIndex, ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin[gunIndex] = ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit;
     }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
@@ -2786,7 +2791,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
            ) {
-            writeWaitPlugItState(fd, gunID);
+            writeWaitPlugItState(fd, gunID, plugNum);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
         /*

+ 18 - 11
EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -67,13 +67,20 @@ int GetCanFd(void)
 {
     return CanFd;
 }
-
-uint32_t GetTimeoutValue(struct timeval _sour_time)
+void GetClockTime(struct timespec* _now_time, void* null)
+{
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+unsigned long GetTimeoutValue(struct timespec _start_time)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    return ret;
 }
 
 int InitCanBus(void)
@@ -693,8 +700,8 @@ int main(int argc, char *argv[])
     uint32_t _timeBuf = 0;
     uint32_t chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {0};
     float maxVol, maxCur;
-    struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-    struct timeval _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct timespec _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct timespec _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
     time_t rtc = {0};
     struct ChargingInfoData *pDcChargingInfo = NULL;
     struct timeb waitChargingTime;
@@ -792,17 +799,17 @@ int main(int argc, char *argv[])
                     if (pSysInfo->PageIndex == _LCM_WAIT_PLUGIN) {
                         if (!chkChademoPermission[gunIndex]) {
                             chkChademoPermission[gunIndex] = true;
-                            gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                            GetClockTime(&_chk_chademo_permission_timeout[gunIndex], NULL);
                             SendCommunicationOnly(gunIndex);
                         } else {
                             _timeBuf = GetTimeoutValue(_chk_chademo_permission_timeout[gunIndex]);
 
                             if (_timeBuf < 0) {
-                                gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                                GetClockTime(&_chk_chademo_permission_timeout[gunIndex], NULL);
                             } else {
                                 if (_timeBuf / 1000 > 10000) {
                                     SendCommunicationOnly(gunIndex);
-                                    gettimeofday(&_chk_chademo_permission_timeout[gunIndex], NULL);
+                                    GetClockTime(&_chk_chademo_permission_timeout[gunIndex], NULL);
                                 }
                             }
                         }
@@ -943,7 +950,7 @@ int main(int argc, char *argv[])
                     GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id);
                 }
 
-                gettimeofday(&_chk_ratingPower_timeout[gunIndex], NULL);
+                GetClockTime(&_chk_ratingPower_timeout[gunIndex], NULL);
                 break;
 
             case S_PREPARING_FOR_EVSE:

+ 5 - 5
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/AcPlug.c

@@ -25,8 +25,8 @@ static struct OCPP16Data *ShmOCPP16Data = NULL;
 
 static int Uart5Fd = 0;
 
-static struct timeval  _ac_charging_comp;
-static struct timeval  _ac_preparing;
+static struct timespec  _ac_charging_comp;
+static struct timespec  _ac_preparing;
 static struct timeb    _ac_startChargingTime;
 static struct timeb    _ac_endChargingTime;
 
@@ -414,7 +414,7 @@ void AcPlugTask(int uartFD)
                 if (pSysInfo->OrderCharging != NO_DEFINE) {
                     pSysInfo->OrderCharging = NO_DEFINE;
                 }
-                gettimeofday(&_ac_preparing, NULL);
+                GetClockTime(&_ac_preparing, NULL);
             }
 
             if (GetChargingEnergy() == PASS) {
@@ -464,7 +464,7 @@ void AcPlugTask(int uartFD)
         case S_TERMINATING: {
             if (isModeChange()) {
                 ChangeStartOrStopDateTime(NO);
-                gettimeofday(&_ac_charging_comp, NULL);
+                GetClockTime(&_ac_charging_comp, NULL);
             }
 
             SetLegacyReq(NO);
@@ -475,7 +475,7 @@ void AcPlugTask(int uartFD)
         break;
         case S_COMPLETE: {
             if (isModeChange()) {
-                gettimeofday(&_ac_charging_comp, NULL);
+                GetClockTime(&_ac_charging_comp, NULL);
                 ftime(&_ac_endChargingTime);
                 if (strcmp((char *)pAcChargingInfo->StartDateTime, "") != EQUAL) {
                     // AC 固定為第2把槍

+ 3 - 3
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/FanBoard.c

@@ -22,7 +22,7 @@ static struct FanModuleData *ShmFanModuleData = NULL;
 static struct PsuData *ShmPsuData = NULL;
 
 static int Uart5Fd = 0;
-static struct timeval gFanBoardRunTimer;
+static struct timespec gFanBoardRunTimer;
 
 static uint16_t _setFanSpeed = 0;
 static uint16_t fanSpeedSmoothValue = 500;
@@ -229,7 +229,7 @@ static void fanBoardPorcess(void)
             GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
-            gettimeofday(&gFanBoardRunTimer, NULL);
+            GetClockTime(&gFanBoardRunTimer, NULL);
 
             ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
@@ -252,7 +252,7 @@ static void fanBoardSelfTest(void)
     SetModelName_Fan();
     SetRtcData_Fan();
     sleep(1);
-    gettimeofday(&gFanBoardRunTimer, NULL);
+    GetClockTime(&gFanBoardRunTimer, NULL);
 }
 
 void FanBoardTask(int uartFD)

+ 4 - 4
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/LEDlight.c

@@ -27,7 +27,7 @@ static int Uart5Fd = 0;
 static Led_Color cur_led_color = {COLOR_MIN_LV};
 static Led_Color led_color;
 
-static struct timeval _led_priority_time;
+static struct timespec _led_priority_time;
 
 //------------------------------------------------------------------------------
 static bool IsNoneMatchLedColor(void)
@@ -255,7 +255,7 @@ static void LEDBoardProcess(void)
         //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
         //}
         SetLedColor();
-        gettimeofday(&_led_priority_time, NULL);
+        GetClockTime(&_led_priority_time, NULL);
     }
 }
 
@@ -269,7 +269,7 @@ static void LEDBoardSelfTest(void)
 #if defined DD360 ||defined DD360Audi
     GetFwAndHwVersion_Led();
     sleep(1);
-    gettimeofday(&_led_priority_time, NULL);
+    GetClockTime(&_led_priority_time, NULL);
 
     return;
 #endif //defined DD360 || defined DD360Audi
@@ -278,7 +278,7 @@ static void LEDBoardSelfTest(void)
     if (pSysInfo->SelfTestSeq <= _STEST_PSU_CAP) {
         GetFwAndHwVersion_Led();
         sleep(1);
-        gettimeofday(&_led_priority_time, NULL);
+        GetClockTime(&_led_priority_time, NULL);
     } else {
         // 自檢階段沒有問到版號
         if (pAlarmCode->AlarmEvents.bits.LedboardStestFail == NO) {

+ 14 - 4
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/Module_InternalComm.c

@@ -11,6 +11,7 @@
 #include <sys/timeb.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
+#include <time.h>
 
 #include "../Config.h"
 #include "../Log/log.h"
@@ -38,12 +39,21 @@ int DiffTimeb(struct timeb ST, struct timeb ET)
     return (StopTime - StartTime);
 }
 
-uint32_t GetTimeoutValue(struct timeval _sour_time)
+void GetClockTime(struct timespec* _now_time, void* null)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
+unsigned long GetTimeoutValue(struct timespec _start_time)
+{
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    return ret;
 }
 
 static int Init485ComPort(void)

+ 2 - 1
EVSE/Projects/DD360UCar/Apps/ModuleInternalComm/Module_InternalComm.h

@@ -104,7 +104,8 @@ typedef struct StPreCharginState {
 } PreChargingState;
 
 //------------------------------------------------------------------------------
-uint32_t GetTimeoutValue(struct timeval _sour_time);
+unsigned long GetTimeoutValue(struct timespec _start_time);
+void GetClockTime(struct timespec* _now_time, void* null);
 int DiffTimeb(struct timeb ST, struct timeb ET);
 
 #endif /* _MODULE_INTERNAL_COMM_H_ */

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

@@ -29,13 +29,13 @@ static struct FanModuleData *ShmFanModuleData = NULL;
 static Relay outputRelay = {0};
 static Relay regRelay = {0};
 static int Uart5Fd = 0;
-static struct timeval gFanBoardRunTimer;
+static struct timespec gFanBoardRunTimer;
 static uint16_t _setFanSpeed = 0;
 static uint16_t fanSpeedSmoothValue = 500;
 
 static Led_Color cur_led_color = {COLOR_MIN_LV};
 static Led_Color led_color;
-static struct timeval _led_priority_time;
+static struct timespec _led_priority_time;
 
 //static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 //static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
@@ -44,26 +44,26 @@ static struct timeval _led_priority_time;
 //static struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 static bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
-static struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
+static struct timespec _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //DS60-120 add
 
 static void SetLedColor(void);
-static struct timeval _close_ac_contactor;
+static struct timespec _close_ac_contactor;
 
 //------------------------------------------------------------------------------
 static void RunForceStopProcess(void)
 {
     static bool isCriticalStop = NO;
-    static struct timeval  _psuCriticalStop;
+    static struct timespec  _psuCriticalStop;
     uint32_t _timebuf;
 
     if (isCriticalStop == NO) {
         isCriticalStop = YES;
-        gettimeofday(&_psuCriticalStop, NULL);
+        GetClockTime(&_psuCriticalStop, NULL);
     } else {
         _timebuf = GetTimeoutValue(_psuCriticalStop);
 
         if (_timebuf < 0) {
-            gettimeofday(&_psuCriticalStop, NULL);
+            GetClockTime(&_psuCriticalStop, NULL);
         } else {
             if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000)) {
                 isCriticalStop = NO;
@@ -83,11 +83,11 @@ static void StopCheckRelayInfo(uint8_t _chkIndex)
 static void StartCheckRelayInfo(uint8_t _chkIndex, uint8_t toState)
 {
     // SMR1 *2 + SMR2 * 2 + Parallel * 2
-    static struct timeval lastCheckRelayStateTimer[6] = {0};
+    static struct timespec lastCheckRelayStateTimer[6] = {0};
     //uint8_t *pCheckRelayState = (uint8_t *)ShmDcCommonData->CheckRelayStatus[_chkIndex];
 
     if (ShmDcCommonData->CheckRelayStatus[_chkIndex] == STOP) {
-        gettimeofday(&lastCheckRelayStateTimer[_chkIndex], NULL);
+        GetClockTime(&lastCheckRelayStateTimer[_chkIndex], NULL);
         ShmDcCommonData->CheckRelayStatus[_chkIndex] = START;
     } else {
         if ((GetTimeoutValue(lastCheckRelayStateTimer[_chkIndex]) / 1000000) >= 1) {
@@ -97,7 +97,7 @@ static void StartCheckRelayInfo(uint8_t _chkIndex, uint8_t toState)
             } else {
                 ShmDcCommonData->CheckRelayStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
             }
-            gettimeofday(&lastCheckRelayStateTimer[_chkIndex], NULL);
+            GetClockTime(&lastCheckRelayStateTimer[_chkIndex], NULL);
         }
     }
 }
@@ -372,7 +372,7 @@ void CheckOutputPowerOverCarReq(uint8_t index)
         if (fireV >= (carV + (carV * 0.02))) {
             if (!_isOvpChkTimeFlag[index]) {
                 if ((pDcChargingInfo->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10) {
-                    gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
+                    GetClockTime(&_checkOutputVolProtectTimer[index], NULL);
                     _isOvpChkTimeFlag[index] = YES;
                 }
             } else {
@@ -476,7 +476,7 @@ void CheckAcInputOvpStatus(uint8_t index)
 //                ((pDcChargingInfo->PresentChargingVoltage * 10) > pDcChargingInfo->FireChargingVoltage + 300)) {
 //            if (!_isOutputNoneMatch[index]) {
 //                _isOutputNoneMatch[index] = YES;
-//                gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
+//                GetClockTime(&_checkOutputNoneMatchTimer[index], NULL);
 //            } else {
 //                if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000) {
 //                    /*log_info("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f ",
@@ -1400,7 +1400,7 @@ static void fanBoardSelfTest(void)
     SetModelName_Fan();
     SetRtcData_Fan();
     sleep(1);
-    gettimeofday(&gFanBoardRunTimer, NULL);
+    GetClockTime(&gFanBoardRunTimer, NULL);
     ShmDcCommonData->FanDisconnectTime = time((time_t*)NULL);
 }
 
@@ -1420,7 +1420,7 @@ static void fanBoardPorcess(void)
             //GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
-            gettimeofday(&gFanBoardRunTimer, NULL);
+            GetClockTime(&gFanBoardRunTimer, NULL);
             /*
             ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
@@ -1681,7 +1681,7 @@ static void LEDBoardSelfTest(void)
 #if defined DD360 ||defined DD360Audi || defined DD360UCar
     GetFwAndHwVersion_Led();
     sleep(1);
-    gettimeofday(&_led_priority_time, NULL);
+    GetClockTime(&_led_priority_time, NULL);
 
     return;
 #endif //defined DD360 || defined DD360Audi
@@ -1690,7 +1690,7 @@ static void LEDBoardSelfTest(void)
     if (pSysInfo->SelfTestSeq <= _STEST_PSU_CAP) {
         GetFwAndHwVersion_Led();
         sleep(1);
-        gettimeofday(&_led_priority_time, NULL);
+        GetClockTime(&_led_priority_time, NULL);
     } else {
         // 自檢階段沒有問到版號
         if (pAlarmCode->AlarmEvents.bits.LedboardStestFail == NO) {
@@ -1720,7 +1720,7 @@ static void LEDBoardProcess(void)
         //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
         //}
         SetLedColor();
-        gettimeofday(&_led_priority_time, NULL);
+        GetClockTime(&_led_priority_time, NULL);
     }
 }
 
@@ -1843,7 +1843,7 @@ void RelayBoardTask(int uartFD)
                              pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
                             (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
                              pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                            pSysInfo->WaitForPlugit == YES ||
+                             ShmDcCommonData->pGunInfo[i].WaitForPlugit == YES ||
                             (pSysInfo->PageIndex >=  _LCM_START_AUTHORIZING &&
                              pSysInfo->PageIndex <= _LCM_WAIT_PLUGIN)
                        ) {
@@ -1889,7 +1889,7 @@ void RelayBoardTask(int uartFD)
                     outputRelay.relay_event.bits.AC_Contactor = YES;
                 } else {
                     if (!isStopChargingCount) {
-                        gettimeofday(&_close_ac_contactor, NULL);
+                        GetClockTime(&_close_ac_contactor, NULL);
                         isStopChargingCount = true;
                     } else {
                         if ((outputRelay.relay_event.bits.AC_Contactor == YES &&

+ 9 - 5
EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -900,19 +900,23 @@ void ShowCountDownTimer()
     else
         DisplayValueToLcm(_Count_Down_Time, (uint8_t *)value, sizeof(value));
 }
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+unsigned long GetTimeoutValue(struct timespec _start_time)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    return ret;
 }
 void ShowGunCountDownTimer()
 {
     int min,sec;
     uint8_t value[10] = {0};
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-    int tm = 120 - (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL);
+    int tm = 120 - (GetTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL);
     // GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL
     min = tm/60;
     sec = tm%60;

+ 8 - 4
EVSE/Projects/DD360UCar/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -393,12 +393,16 @@ int InitComPort()
     return fd;
 }
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+unsigned long GetTimeoutValue(struct timespec _start_time)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    struct timespec ts_end;
+    unsigned long ret = 0;
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
+
+    return ret;
 }
 
 static bool IsPrimaryProcessNeedPause(void)

+ 8 - 6
EVSE/Projects/DD360UCar/Apps/ModulePsuComm/Module_PsuComm.c

@@ -39,14 +39,16 @@ int StoreLogMsg(const char *fmt, ...);
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+unsigned long GetTimeoutValue(struct timespec _start_time)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+	struct timespec ts_end;
+	unsigned long ret = 0;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+	ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
 
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+	return ret;
 }
 
 int StoreLogMsg(const char *fmt, ...)

+ 4 - 4
EVSE/Projects/DD360UCar/Apps/ModulePsuComm/Module_PsuComm.h

@@ -40,11 +40,11 @@ unsigned char _gunCount;
 struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 bool isStartOutputSwitch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
-struct timeval _cmdSubPriority_time;
-struct timeval _derating_time;
-struct timeval _max_time;
+struct timespec _cmdSubPriority_time;
+struct timespec _derating_time;
+struct timespec _max_time;
 
-struct timeval _test_time;
+struct timespec _test_time;
 
 bool isCharging = false;
 bool isWaitingAver = false;

+ 15 - 6
EVSE/Projects/DD360UCar/Apps/OutputTask.c

@@ -36,12 +36,21 @@ int InitComPort()
 	return fd;
 }
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+void GetClockTime(struct timespec* _now_time, void* null)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+	clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
+unsigned long GetTimeoutValue(struct timespec _start_time)
+{
+	struct timespec ts_end;
+	unsigned long ret = 0;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+	ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
 
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+	return ret;
 }
 
 void ShowMainMsg()
@@ -263,7 +272,7 @@ int main(void)
 	}
 
 	sleep(5);
-	gettimeofday(&_cmdSubPriority_time, NULL);
+	GetClockTime(&_cmdSubPriority_time, NULL);
 	VOLTAGE = 0.0;
 	CURRENT = 0.0;
 
@@ -347,7 +356,7 @@ int main(void)
 			{
 				printf("Step 1 : GetModuleCount...... \n");
 				GetModuleCount(SYSTEM_CMD);
-				gettimeofday(&_cmdSubPriority_time, NULL);
+				GetClockTime(&_cmdSubPriority_time, NULL);
 			}
 		}
 		else if (time < 5000)

+ 1 - 1
EVSE/Projects/DD360UCar/Apps/OutputTask.h

@@ -56,7 +56,7 @@ int Uart1Fd = -1;
 char *priPortName = "/dev/ttyS1";
 
 bool libInitialize = false;
-struct timeval _cmdSubPriority_time;
+struct timespec _cmdSubPriority_time;
 
 unsigned char Button1 = RELEASE;
 unsigned char Button2 = RELEASE;

+ 16 - 7
EVSE/Projects/DD360UCar/Apps/ReadCmdline.c

@@ -65,7 +65,7 @@
 //------------------------------------------------------------------------------
 uint8_t _curAutoRunCount = 0;
 uint8_t _usingAutoRun = 0;
-struct timeval _autoTime;
+struct timespec _autoTime;
 
 static struct SysConfigData *pSysConfig = NULL;
 static struct SysInfoData *pSysInfo = NULL;
@@ -180,12 +180,21 @@ static uint8_t readCmdKey(uint8_t state)
     return YES;
 }
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+void GetClockTime(struct timespec* _now_time, void* null)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
+unsigned long GetTimeoutValue(struct timespec _start_time)
+{
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec / 1000)));
 
-    return (_end_time.tv_sec - _sour_time.tv_sec);
+    return ret;
 }
 
 void RunStatusProc(char *v1, char *v2)
@@ -819,7 +828,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                     pDcChargingInfo->EvBatterytargetCurrent = _Current;
                 } else {
                     _curAutoRunCount = 0;
-                    gettimeofday(&_autoTime, NULL);
+                    GetClockTime(&_autoTime, NULL);
                 }
 
                 pDcChargingInfo->EvBatterySoc = 50;
@@ -841,7 +850,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                     if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
                         pDcChargingInfo->SystemStatus = S_TERMINATING;
                     } else {
-                        gettimeofday(&_autoTime, NULL);
+                        GetClockTime(&_autoTime, NULL);
                     }
                 } else {
                     pDcChargingInfo->EvBatterytargetVoltage = 0;

BIN
EVSE/Projects/DD360UCar/Apps/UnsafetyOutputTask


+ 3 - 3
EVSE/Projects/DD360UCar/Apps/timeout.h

@@ -58,12 +58,12 @@ enum Timeout_flag {
 
 //------------------------------------------------------------------------------
 // for timeout fork
-struct timeval _cmdSubPriority_time;
+struct timespec _cmdSubPriority_time;
 unsigned short _connectionTimeout;
 
 // for main
-struct timeval _cmdMainPriority_time;
-struct timeval _toAverage_time;
+struct timespec _cmdMainPriority_time;
+struct timespec _toAverage_time;
 //uint8_t _ocppProfileChkFlag;
 
 #endif /* TIMEOUT_H_ */

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


BIN
EVSE/Projects/DD360UCar/output/FactoryConfig


BIN
EVSE/Projects/DD360UCar/output/Module_ChkSysTask


BIN
EVSE/Projects/DD360UCar/output/Module_DoComm


BIN
EVSE/Projects/DD360UCar/output/Module_EvComm


BIN
EVSE/Projects/DD360UCar/output/Module_EventLogging


BIN
EVSE/Projects/DD360UCar/output/Module_InternalComm


BIN
EVSE/Projects/DD360UCar/output/Module_LcmControl


BIN
EVSE/Projects/DD360UCar/output/Module_LcmWistronControl


BIN
EVSE/Projects/DD360UCar/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360UCar/output/Module_UpdateFW


BIN
EVSE/Projects/DD360UCar/output/ReadCmdline


BIN
EVSE/Projects/DD360UCar/output/UnsafetyOutputTask


BIN
EVSE/Projects/DD360UCar/output/main