Преглед на файлове

2022-12-28 / Simon Xue

Action:
1. [Mod] DD360ComBox test finish and release.

As the following commit history.

Image Version: V1.24.XX.XXXX.XX
Simon Xue преди 2 години
родител
ревизия
ff22e6a1e7
променени са 60 файла, в които са добавени 2667 реда и са изтрити 1191 реда
  1. 2 0
      EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c
  2. 29 134
      EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c
  3. 96 9
      EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c
  4. 3 3
      EVSE/Projects/DD360ComBox/Apps/CSU/SelfTest.c
  5. 494 157
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  6. 4 1
      EVSE/Projects/DD360ComBox/Apps/CSU/main.h
  7. 165 9
      EVSE/Projects/DD360ComBox/Apps/Config.h
  8. 190 1
      EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.c
  9. 6 0
      EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.h
  10. 507 464
      EVSE/Projects/DD360ComBox/Apps/Define/define.h
  11. 4 4
      EVSE/Projects/DD360ComBox/Apps/Log/log.h
  12. 9 4
      EVSE/Projects/DD360ComBox/Apps/Makefile
  13. 13 1
      EVSE/Projects/DD360ComBox/Apps/ModuleChkSysTask/Module_ChkSysTask.c
  14. 2 0
      EVSE/Projects/DD360ComBox/Apps/ModuleChkSysTask/Module_ChkSysTask.h
  15. 166 13
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c
  16. 12 0
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h
  17. 2 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCCS.c
  18. 2 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCHA.c
  19. 2 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalGBT.c
  20. 5 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalState.c
  21. 52 25
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c
  22. 168 5
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c
  23. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModuleEventLog/Module_EventLogging.c
  24. 3 3
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/Module_InternalComm.h
  25. 62 10
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c
  26. 63 35
      EVSE/Projects/DD360ComBox/Apps/ModuleLcmCtrl/Module_LcmControl.c
  27. 204 261
      EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.c
  28. 1 1
      EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.h
  29. 2 1
      EVSE/Projects/DD360ComBox/Apps/ModulePrimary/PrimaryComm.c
  30. 24 3
      EVSE/Projects/DD360ComBox/Apps/ModuleUpdateFW/Module_UpdateFW.c
  31. BIN
      EVSE/Projects/DD360ComBox/Apps/Module_ChkSysTask
  32. BIN
      EVSE/Projects/DD360ComBox/Apps/Module_DoComm
  33. BIN
      EVSE/Projects/DD360ComBox/Apps/Module_EvComm
  34. BIN
      EVSE/Projects/DD360ComBox/Apps/Module_EventLogging
  35. BIN
      EVSE/Projects/DD360ComBox/Apps/Module_InternalComm
  36. BIN
      EVSE/Projects/DD360ComBox/Apps/Module_UpdateFW
  37. 326 32
      EVSE/Projects/DD360ComBox/Apps/ReadCmdline.c
  38. 2 0
      EVSE/Projects/DD360ComBox/Apps/Script/init.sh
  39. 2 0
      EVSE/Projects/DD360ComBox/Apps/Script/kill.sh
  40. 0 4
      EVSE/Projects/DD360ComBox/Apps/Script/replaceOtherDD360Project.sh
  41. 36 5
      EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c
  42. 1 1
      EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.h
  43. BIN
      EVSE/Projects/DD360ComBox/Apps/UnsafetyOutputTask
  44. BIN
      EVSE/Projects/DD360ComBox/Apps/main
  45. 3 0
      EVSE/Projects/DD360ComBox/Apps/timeout.h
  46. BIN
      EVSE/Projects/DD360ComBox/Images/ramdisk.gz
  47. BIN
      EVSE/Projects/DD360ComBox/output/FactoryConfig
  48. BIN
      EVSE/Projects/DD360ComBox/output/Module_ChkSysTask
  49. BIN
      EVSE/Projects/DD360ComBox/output/Module_DoComm
  50. BIN
      EVSE/Projects/DD360ComBox/output/Module_EvComm
  51. BIN
      EVSE/Projects/DD360ComBox/output/Module_EventLogging
  52. BIN
      EVSE/Projects/DD360ComBox/output/Module_InternalComm
  53. BIN
      EVSE/Projects/DD360ComBox/output/Module_LcmControl
  54. BIN
      EVSE/Projects/DD360ComBox/output/Module_PrimaryComm
  55. BIN
      EVSE/Projects/DD360ComBox/output/Module_UpdateFW
  56. BIN
      EVSE/Projects/DD360ComBox/output/ReadCmdline
  57. BIN
      EVSE/Projects/DD360ComBox/output/UnsafetyOutputTask
  58. 2 0
      EVSE/Projects/DD360ComBox/output/init.sh
  59. 2 0
      EVSE/Projects/DD360ComBox/output/kill.sh
  60. BIN
      EVSE/Projects/DD360ComBox/output/main

+ 2 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/Ethernet.c

@@ -186,6 +186,8 @@ void InitEthernet(void)
     log_info("%s",tmpbuf);
     system(tmpbuf);
 
+    //system("/sbin/ifconfig lo up");
+
     //Run DHCP client if enabled
     system("killall udhcpc");
     system("rm -rf /etc/resolv.conf");

+ 29 - 134
EVSE/Projects/DD360ComBox/Apps/CSU/Primary.c

@@ -59,7 +59,7 @@ void PrimaryLedIndicatorCtrlFork(void)
     if (pid == 0) {
         uint8_t gunIndex = 0;
         int isContinue = 1;
-
+        log_info("Primary Fork Child's PID is %d", getpid());
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
@@ -272,54 +272,13 @@ static void checkChargingInfoByDC(uint8_t systemStatus)
     }
 }
 
-static void checkChargingInfoByAC(void)
-{
-    struct ChargingInfoData *pAcChargingInfo = NULL;
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-
-    if (pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
-        return;
-    }
-
-    pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-    switch (pAcChargingInfo->SystemStatus) {
-    case S_IDLE:
-        if (isDetectPlugin(pSysInfo->CurGunSelected)) {
-            _DetectPlugInTimeout(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:
-        // 取消充電
-        AcChargingTerminalProcess();
-        break;
-
-    case S_CHARGING:
-        if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
-            // 停止充電
-            AcChargingTerminalProcess();
-        }
-        break;
-
-    case S_COMPLETE:
-        break;
-    }
-}
-
 void ChkPrimaryStatus(void)
 {
     static bool leftBtnPush = false;
     static bool rightBtnPush = false;
     uint8_t i = 0;
     uint8_t Rtn = 0;
+    uint8_t _setGun = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
@@ -415,6 +374,13 @@ void ChkPrimaryStatus(void)
         ReleaseEmsOccureByString(0, "012251");
     }
 
+    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+        pAlarmCode->AlarmEvents.bits.ChillerAlarmFail = YES;
+        EmcOccureByString("012348");
+    } else {
+        ReleaseEmsOccureByString(0, "012348");
+    }
+    
     if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
         pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = YES;
         EmcOccureByString("012238");
@@ -457,93 +423,7 @@ void ChkPrimaryStatus(void)
             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) {
@@ -551,24 +431,38 @@ void ChkPrimaryStatus(void)
             //log_info("left btn up............................... ");
         }
     }
+    bool isCharging = false;
+    for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+        if (pDcChargingInfo->SystemStatus == S_IDLE) {
+            continue;
+        }
 
+        isCharging = true;
+        break;
+    }
     if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
             !rightBtnPush &&
 #if defined DD360Audi
             pSysInfo->SystemPage != _LCM_IDLE &&
+            pSysInfo->SystemPage != _LCM_WAIT_FOR_PLUG &&
 #endif
             pSysInfo->SystemPage != _LCM_AUTHORIZING &&
             pSysInfo->SystemPage != _LCM_AUTHORIZ_COMP &&
-            pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL &&
-            pSysInfo->SystemPage != _LCM_WAIT_FOR_PLUG
+            pSysInfo->SystemPage != _LCM_AUTHORIZ_FAIL
        ) {
         if (!rightBtnPush) {
+            if (pSysInfo->SystemPage == _LCM_WAIT_FOR_PLUG && !isCharging) {
+                return;
+            }
             rightBtnPush = true;
-            //log_info("right btn down............................... %d ", pSysInfo->CurGunSelected);
+            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;
@@ -586,12 +480,13 @@ void ChkPrimaryStatus(void)
                 }
                 pSysInfo->CurGunSelected = 0;
                 ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
+                */
             } else {
                 pSysInfo->CurGunSelected = 0;
                 ChangeGunSelectByIndex(pSysInfo->CurGunSelected);
             }
-            log_info("current select gun ............................... %d ",
-                     pSysInfo->CurGunSelected);
+            //log_info("current select gun ............................... %d ",
+            //         pSysInfo->CurGunSelected);
         }
 
     } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {

+ 96 - 9
EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c

@@ -231,7 +231,7 @@ static void UserScanFunction(void)
         } else if ((pGunIndexInfo->AcGunIndex > 0 &&
                     pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
                    pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
-            log_info("// LCM => Authorizing");
+            log_info("// LCM => Authorizing ID:%s",(char *)pSysConfig->UserId);
 
             setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
 
@@ -268,8 +268,11 @@ void ScannerCardProcess(void)
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
     ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
-
+#if defined DD360Audi
     if (!isDetectPlugin(pSysInfo->CurGunSelected) &&
+#else
+    if ((!isDetectPlugin(LEFT_GUN_NUM) || !isDetectPlugin(RIGHT_GUN_NUM)) &&
+#endif
             !isCardScan &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
@@ -278,16 +281,18 @@ void ScannerCardProcess(void)
         UserScanFunction();
     }
 
-    if (pSysInfo->PageIndex == _LCM_AUTHORIZING) {
+    if (pSysInfo->SystemPage == _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);
@@ -305,26 +310,26 @@ void ScannerCardProcess(void)
                 }
 
             } 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) {
                     continue;
                 }
-
                 if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
+                    log_info("Local White Card [%d]:%s", i, pSysConfig->LocalWhiteCard[i]);
                     pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
                     ClearAuthorizedFlag();
                     break;
                 }
             }
-        }
-    } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_FAIL) {
+        }*/
+    } else if (pSysInfo->SystemPage == _LCM_AUTHORIZ_FAIL) {
         StartSystemTimeoutDet(Timeout_VerifyFail);
         isCardScan = false;
-    } else if (pSysInfo->PageIndex == _LCM_AUTHORIZ_COMP) {
+    } else if (pSysInfo->SystemPage == _LCM_AUTHORIZ_COMP) {
         StartSystemTimeoutDet(Timeout_VerifyComp);
-    } else if (pSysInfo->PageIndex == _LCM_WAIT_FOR_PLUG) {
+    } else if (pSysInfo->SystemPage == _LCM_WAIT_FOR_PLUG) {
         //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected, Timeout_WaitPlug);
     } else {
         isCardScan = false;
@@ -393,6 +398,7 @@ void CreateRfidFork(void)
 
             if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
                 switch (rfid.snType) {
+#if defined DD360Audi
                 case RFID_SN_TYPE_6BYTE:
                     sprintf((char *) pSysConfig->UserId,
                             "%02X%02X%02X%02X%02X%02X",
@@ -423,9 +429,50 @@ void CreateRfidFork(void)
                             rfid.currentCard[0], rfid.currentCard[1],
                             rfid.currentCard[2], rfid.currentCard[3]);
                     break;
+#else
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[5], rfid.currentCard[4],
+                        rfid.currentCard[3], rfid.currentCard[2],
+                        rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[6], rfid.currentCard[5],
+                        rfid.currentCard[4], rfid.currentCard[3],
+                        rfid.currentCard[2], rfid.currentCard[1],
+                        rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_8BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[7], rfid.currentCard[6],
+                        rfid.currentCard[5], rfid.currentCard[4],
+                        rfid.currentCard[3], rfid.currentCard[2],
+                        rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[9], rfid.currentCard[8],
+                        rfid.currentCard[7], rfid.currentCard[6],
+                        rfid.currentCard[5], rfid.currentCard[4],
+                        rfid.currentCard[3], rfid.currentCard[2],
+                        rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X",
+                        rfid.currentCard[3], rfid.currentCard[2],
+                        rfid.currentCard[1], rfid.currentCard[0]);
+                    break;
+#endif
                 }
             } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
                 switch (rfid.snType) {
+#if defined DD360Audi
                 case RFID_SN_TYPE_6BYTE:
                     sprintf((char *) pSysConfig->UserId,
                             "%02X%02X%02X%02X%02X%02X",
@@ -456,6 +503,46 @@ void CreateRfidFork(void)
                             rfid.currentCard[3], rfid.currentCard[2],
                             rfid.currentCard[1], rfid.currentCard[0]);
                     break;
+#else
+                case RFID_SN_TYPE_6BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[0], rfid.currentCard[1],
+                        rfid.currentCard[2], rfid.currentCard[3],
+                        rfid.currentCard[4], rfid.currentCard[5]);
+                    break;
+                case RFID_SN_TYPE_7BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[0], rfid.currentCard[1],
+                        rfid.currentCard[2], rfid.currentCard[3],
+                        rfid.currentCard[4], rfid.currentCard[5],
+                        rfid.currentCard[6]);
+                    break;
+                case RFID_SN_TYPE_8BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[0], rfid.currentCard[1],
+                        rfid.currentCard[2], rfid.currentCard[3],
+                        rfid.currentCard[4], rfid.currentCard[5],
+                        rfid.currentCard[6], rfid.currentCard[7]);
+                    break;
+                case RFID_SN_TYPE_10BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+                        rfid.currentCard[0], rfid.currentCard[1],
+                        rfid.currentCard[2], rfid.currentCard[3],
+                        rfid.currentCard[4], rfid.currentCard[5],
+                        rfid.currentCard[6], rfid.currentCard[7],
+                        rfid.currentCard[8], rfid.currentCard[9]);
+                    break;
+                case RFID_SN_TYPE_4BYTE:
+                    sprintf((char*)pSysConfig->UserId,
+                        "%02X%02X%02X%02X",
+                        rfid.currentCard[0], rfid.currentCard[1],
+                        rfid.currentCard[2], rfid.currentCard[3]);
+                    break;
+#endif
                 }
             }
             log_info("card number = %s", pSysConfig->UserId);

+ 3 - 3
EVSE/Projects/DD360ComBox/Apps/CSU/SelfTest.c

@@ -53,12 +53,12 @@ void SelfTestRun(void)
         }
         
         ChkPrimaryStatus(); //確認硬體有無錯誤,如急停按鈕或門有打開
-
+        /*
         if (pSysWarning->Level == WARN_LV_ER) {
             pSysInfo->SelfTestSeq = _STEST_FAIL;
             return;
         }
-
+        */
         if (pSysConfig->TotalConnectorCount <= 0) {
             pSysInfo->SelfTestSeq = _STEST_FAIL;
             return;
@@ -102,7 +102,7 @@ void SelfTestRun(void)
                     (ShmPrimaryMcuData->SelfTest_Comp != YES)
                ) {
                 //log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
-                ShmPrimaryMcuData->SelfTest_Comp = YES;
+                //ShmPrimaryMcuData->SelfTest_Comp = YES;
             }
 
             // EV 小板

Файловите разлики са ограничени, защото са твърде много
+ 494 - 157
EVSE/Projects/DD360ComBox/Apps/CSU/main.c


+ 4 - 1
EVSE/Projects/DD360ComBox/Apps/CSU/main.h

@@ -44,7 +44,10 @@
 #define GUN_PRECHARGING_TIMEOUT                 (60)
 #define EVCCID_LINK_TIMEOUT                     (120)
 #define PRECHARGING_TTIMEOUT                    (60)
-
+#define RETURN_VIEWPAGE_TIMEOUT                 (30)
+#define HELP_PAGE_TIMEOUT                       (30)
+#define LANGUAGE_PAGE_TIMEOUT                   (30)
+#define CONN_PLUG_TIMEOUT                       (40)
 #define WHILE_LOOP_TIME                         (10000)
 
 //#define log_info(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)

+ 165 - 9
EVSE/Projects/DD360ComBox/Apps/Config.h

@@ -60,6 +60,8 @@
 #define BOOTTING                                (0)
 #define BOOT_COMPLETE                           (1)
 
+#define POWER_SAVE_MODE                         (1)
+
 //------------------------------------------------------------------------------
 //common define
 //------------------------------------------------------------------------------
@@ -96,6 +98,9 @@
 #define WARN_LV_ER                              (2) //emergency state
 
 //------------------------------------------------------------------------------
+
+#define DC_CONNECTOR_COUNT          2
+
 enum _SYSTEM_STATUS {
     S_BOOTING = 0,
     S_IDLE,
@@ -163,6 +168,23 @@ enum _LCM_INDEX {
     _LCM_NONE          = 0xFF,
 };
 
+enum _LCM_WISTRON_INDEX {
+    _PAGE_INIT = 0x00,
+    _PAGE_VIEW,
+    _PAGE_LANGUAGE,
+    _PAGE_SELECT_PAY,
+    _PAGE_AUTHORIZING,
+    _PAGE_AUTHORIZE_COMPLETE,
+    _PAGE_AUTHORIZE_FAIL,
+    _PAGE_PLUGIN_FAIL,
+    _PAGE_STOP_CHARGING,
+    _PAGE_SUMMARY,
+    _PAGE_HELP,
+    _PAGE_ALARM,
+    _PAGE_MAINTAIN,
+    _PAGE_EMG_BTN,
+
+};
 enum _SELF_TEST_SEQ {
     _STEST_VERSION      = 0x00,
     _STEST_AC_CONTACTOR = 0x01,
@@ -293,6 +315,51 @@ enum _CREDITCARD_STATUS {
 	_CREDITCARD_SETTLEMENT,
 	_CREDITCARD_START,
 };
+enum _DERATING_TEMP {
+    STAGE1_GUN_DERATING_TEMP = 140,
+    STAGE2_GUN_DERATING_TEMP = 145,
+};
+
+enum _TILT_SENSOR_STEP {
+    _TILT_SENSOR_STEP_NONE,
+    _TILT_SENSOR_STEP_PIN_ON,
+    _TILT_SENSOR_STEP_PIN_WAIT,
+    _TILT_SENSOR_STEP_PIN_OFF,
+    _TILT_SENSOR_STEP_PIN_FINISH,
+};
+// Meter OCMF
+struct StructMeter
+{
+	float curMeterValue;
+	float newMeterValue;
+	uint8_t isCalculation;
+	float _chargingValue;
+	float _curTotalCharging;
+};
+struct MeterInformation
+{
+	struct StructMeter _meter[DC_CONNECTOR_COUNT];
+	uint8_t isWorking;
+};
+enum _DC_METER_TRANSACTION_ACTION
+{
+	_DC_METER_TRANSACTION_ACTION_NONE	= 0,
+	_DC_METER_TRANSACTION_ACTION_START,
+	_DC_METER_TRANSACTION_ACTION_STOP,
+};
+enum _OCMF_INFO_READY_FLAG
+{
+	_OCMF_INFO_READY_NO					= 0,
+	_OCMF_INFO_READY_YES,
+	_OCMF_INFO_READY_FAIL
+};
+enum _CHARGING_START_METHOD
+{
+    _CHARGING_START_RFID = 0,
+    _CHARGING_START_AUTOSTART,
+    _CHARGING_START_REMOTESTART,
+};
+
 //------------------------------------------------------------------------------
 //struct StructMeter {
 //    float curMeterValue;
@@ -407,8 +474,7 @@ typedef struct StGunInfo {
     int ConnectorID;
     char ReceiptInfo[255];
     int finalcost_flag;
-    time_t EVLoseTimer;
-    uint8_t EVLoseFlag;
+
     char ReservationID[32];
     uint8_t ReservationStatus;
     char UserPriceString[255];
@@ -417,10 +483,27 @@ typedef struct StGunInfo {
     char ChargeStartTime[32];
     char ChargeStopTime[32];
     char ChargeDuration[32];
-    uint8_t withChiller;      //是否有水冷機
-    uint8_t WaitForPlugit;    // 等待插槍FLAG
+
+    uint8_t SendOcmfDataReq;
+    char OcmfFileName[300];
+    double curMeterValue;
+    double _curTotalCharging;
+    struct {
+        uint8_t withChiller:1;      //是否有水冷機
+        uint8_t WaitForPlugit:1;    // 等待插槍FLAG
+        uint8_t isMeterStart:1;
+        uint8_t isMeterStop:1;
+    };
 } GunInfo;
 
+
+typedef struct StGunStatus {
+    time_t EVLoseTimer;
+        struct {
+        uint8_t EVLoseFlag:1;
+    };
+} GunStatus;
+
 typedef struct Psu_VersionInfo{
 	uint8_t n_PSU;
 	uint8_t DCVersion[32];
@@ -459,6 +542,12 @@ typedef struct stRecordTransactionInfo
     unsigned char res;
 }RecordTransactionInfo;
 
+typedef struct stTestFlag
+{
+    uint8_t ledflag;
+}TestFlag;
+
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -478,17 +567,84 @@ typedef struct StDcCommonInfo {
     uint8_t chillerCtrl;
     uint8_t debugflag;
     uint8_t LcmFwVersion;
-    int TZOffset;
-    uint8_t AuthroizeType; // 0: Central   1: eMAID    2: ISO14443 3: ISO15693 4: KeyCode  5: Local    6: MacAddress   7: NoAuthorization
-    char QRCodeString[255];
-    char DefaultPriceString[255];
-    PowerConsumptionValue pConsumption;
+    uint8_t _upgrade_lcm_flag;
+    uint8_t _upgrade_lcm_result;
+    uint8_t _upgrade_lcm_apk_flag;
+    // Power Cabinet Version
+    uint8_t CabinetModelName[32];
+    uint8_t CabinetBoolLoaderVersion[32];
+    uint8_t CabinetKernelVersion[32];
+    uint8_t CabinetRFSystemVersion[32];
+    uint8_t CabinetPrimaryVersion[32];
+    uint8_t CabinetIPAddr[32];
+    uint8_t CabinetRelay0Version[32];
+    uint8_t CabinetRelay1Version[32];
+    uint8_t CabinetFanVersion[32];
+    // PSU Version
+    uint8_t PSU_Number;
+    PsuVerInfo PsuVer[12];
+    int ConnectorId[2];
     int WeatherID;
     float Temperature;
     int Location;
+    char PresentTime[128];
+    TransInfo pCreditCard[2];
+    int runningcost[2];
+    float finalcost[2];
+    unsigned int finalcost_flag[2];
+    float ChargingRate;
+    int PreAuth_Config;
+    int PreAuth_Result;
+    int LineStatus[2];
+    int donate_flag[2];
+    unsigned int AuthPass_flag[2];
+    unsigned int PayPass_flag[2];
+    unsigned int PayFinish[2];
+    unsigned int StopCharge[2];
+    unsigned int GetCardNo[2];
+    unsigned int TradeCancel;
+    int reupload_deduct_status;		// 0:Not ReUpload 1:ReUpload 2:ReUpload finish
+    RecordTransactionInfo TransactionInfo[2];
+    int TZOffset;
+ 	uint8_t AuthroizeType; // 0: Central   1: eMAID    2: ISO14443 3: ISO15693 4: KeyCode  5: Local    6: MacAddress   7: NoAuthorization
+
+    time_t EVDisconnectTime[2];
+    int EVDisconnectFlag[2];
+    int isIntoCharge[2];
+    time_t RelayDisconnectTime;
+    time_t LedDisconnectTime;
+    time_t FanDisconnectTime;
+    int DemoCount;
+    char QRCodeString[255];
     GunInfo pGunInfo[2];
+    GunStatus pGunStatus[2];
+    char DefaultPriceString[255];
+    PowerConsumptionValue pConsumption;
+
     uint8_t showNetPackage;
     uint8_t showCanPackage;
+    char DebugVersion[32];
+    time_t FanOnTime;
+    uint8_t language;
+    int lcmtest;
+    uint8_t previousPage;
+    int SDUPATENUM;
+    int BlackLight;
+    time_t SleepTimer; // control by sleep mode
+    time_t lcmwatchdog; // Detect LCM alive or not
+    int8_t lcmmacAddr[32];
+    int8_t lcmcmd;
+    float TempVolt[4];
+    int8_t demo_flag;
+    int8_t isDark;
+    TestFlag pTest;
+    uint8_t _tiltSensorStep;
+    uint8_t LcmPage;
+    // Ocmf
+    uint8_t _hour_index;			//0 ~ 23
+    float energy_time_period[DC_CONNECTOR_COUNT][24];
+	// Ocmf Record resend
+	int ocmfTridRecord[DC_CONNECTOR_COUNT];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 190 - 1
EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.c

@@ -8,6 +8,7 @@
 #include "../Log/log.h"
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
+#include "../SelectGun/SelectGun.h"
 
 //------------------------------------------------------------------------------
 #define DB_FILE                                 "/Storage/ChargeLog/localCgargingRecord.db"
@@ -64,6 +65,15 @@ int DB_Open(void)
                          "connector TEXT, "
                          "val TEXT);";
 
+	char* createDcMeterSql="CREATE TABLE IF NOT EXISTS ocmf_record("
+							  "idx integer primary key AUTOINCREMENT, "
+							  "transactionId text, "
+			 	 	 	 	  "status INTEGER NOT NULL, "
+							  "connector INTEGER NOT NULL, "
+							  "publicKey text, "
+							  "ocmfInfo text"
+							  ");";
+
     if (sqlite3_open(DB_FILE, &localDb)) {
         result = FAIL;
         log_info( "Can't open database: %s", sqlite3_errmsg(localDb));
@@ -109,6 +119,15 @@ int DB_Open(void)
         }
         //-----
 
+		if (sqlite3_exec(localDb, createDcMeterSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			log_info( "Create OCMF record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			log_info( "Opened OCMF record table successfully\n");
+		}
         sqlite3_close(localDb);
     }
 
@@ -123,11 +142,12 @@ int DB_Insert_Record(int gunIndex)
     char insertSql[1024];
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
     struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+    SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
 
     sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
             "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
             pDcChargingInfo->ReservationId, //DS60-120 add
-            ShmOCPP16Data->StartTransaction[gunIndex].ResponseTransactionId,
+            ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId,
             pDcChargingInfo->StartMethod,
             pDcChargingInfo->StartUserId,
             pDcChargingInfo->StartDateTime,
@@ -436,3 +456,172 @@ int InsertEventRecord(uint8_t *statusCode)
 
     return result;
 }
+
+
+int DB_Insert_ocmf(uint8_t gun_index)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[2048];
+    SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+	memset(insertSql, 0, sizeof(insertSql));
+	sprintf(insertSql, "insert into ocmf_record (transactionId, status, connector) values('%d', 0, '%d');",
+					ShmSelectGunInfo->PricesInfo[gun_index].TransactionId,
+					gun_index);
+
+	if (sqlite3_open(DB_FILE, &localDb))
+	{
+		result = FAIL;
+		log_warn("Can't open database: %s\n", sqlite3_errmsg(localDb));
+		sqlite3_close(localDb);
+	}
+	else
+	{
+		if (sqlite3_exec(localDb, insertSql, 0, 0, & errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			log_warn("Insert ocmf error message : %s\n", errMsg);
+		}
+		else
+		{
+			log_info("Insert ocmf successfully");
+		}
+
+		sqlite3_close(localDb);
+	}
+
+	return result;
+}
+
+void DB_Update_ocmf(uint8_t gun_index)
+{
+	char* errMsg = NULL;
+	char insertSql[4096];
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+	memset(insertSql, 0, sizeof(insertSql));
+	sprintf(insertSql, "update ocmf_record set status=0, publicKey='%s', ocmfInfo='%s' where status=0 and transactionId=%d and connector=%d;",
+		pSysInfo->DcMeterStatusInfo[gun_index].publicKeyOcmf,
+		pSysInfo->DcMeterTransactionAction[gun_index].transactionOCMF,
+		ShmSelectGunInfo->PricesInfo[gun_index].TransactionId,
+		gun_index);
+	if (sqlite3_open(DB_FILE, &localDb))
+	{
+		log_warn("Can't open database: %s\n", sqlite3_errmsg(localDb));
+		sqlite3_close(localDb);
+	}
+	else
+	{
+		if (sqlite3_exec(localDb, insertSql, 0, 0, & errMsg) != SQLITE_OK)
+		{
+			log_warn("Update ocmf error message : %s", errMsg);
+		}
+		else
+		{
+			log_info("Update ocmf successfully ");
+		}
+		sqlite3_close(localDb);
+	}
+}
+
+void DB_Update_ocmf_Record(uint8_t gun_index, int _trid, bool isGet)
+{
+	char* errMsg = NULL;
+	char insertSql[4096];
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+	memset(insertSql, 0, sizeof(insertSql));
+	if (isGet)
+	{
+		sprintf(insertSql, "update ocmf_record set status=0, publicKey='%s', ocmfInfo='%s' where status=0 and transactionId=%d and connector=%d;",
+                pSysInfo->DcMeterStatusInfo[gun_index].publicKeyOcmf,
+				pSysInfo->DcMeterReadTransactionRecord[gun_index].transactionOCMF,
+				_trid,
+				gun_index);
+	}
+	else
+	{
+		sprintf(insertSql, "update ocmf_record set status=2 where status=0 and transactionId=%d and connector=%d;",
+				_trid,
+				gun_index);
+	}
+	if (sqlite3_open(DB_FILE, &localDb))
+	{
+		log_warn("Can't open database: %s\n", sqlite3_errmsg(localDb));
+		sqlite3_close(localDb);
+	}
+	else
+	{
+		if (sqlite3_exec(localDb, insertSql, 0, 0, & errMsg) != SQLITE_OK)
+		{
+			log_warn("Update ocmf error message : %s", errMsg);
+		}
+		else
+		{
+			log_info("Update ocmf_Record successfully ");
+		}
+		sqlite3_close(localDb);
+	}
+}
+
+int DB_Get_OcmfTrid(uint8_t gun_index)
+{
+	int result = 0;
+	char* errMsg = NULL;
+	char sqlStr[2048];
+	char **rs;
+	int rows, cols;
+
+	memset(sqlStr, 0, sizeof(sqlStr));
+	sprintf(sqlStr, "select * from ocmf_record where status=0 and connector=%d and transactionId!=0;", gun_index);
+
+	if (sqlite3_open(DB_FILE, &localDb))
+	{
+		log_warn("Can't open database: %s\r\n", sqlite3_errmsg(localDb));
+		sqlite3_close(localDb);
+	}
+	else
+	{
+		//log_info("Local config query database open successfully.\r\n");
+		sqlite3_get_table(localDb, sqlStr, &rs, &rows, &cols, &errMsg);
+		if (rows > 0)
+		{
+			for (int idxRow = 1; idxRow <= rows; idxRow++)
+			{
+				result = atoi(rs[(idxRow * cols) + 1]);
+				break;
+			}
+		}
+
+		sqlite3_free_table(rs);
+		sqlite3_close(localDb);
+	}
+
+	return result;
+}
+
+void DB_Upload_ocmf(uint8_t gun_index, int txid)
+{
+	char* errMsg = NULL;
+	char insertSql[4096];
+    struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+	memset(insertSql, 0, sizeof(insertSql));
+	sprintf(insertSql, "update ocmf_record set status=1 where transactionId=%d and connector=%d;",txid,gun_index);
+	if (sqlite3_open(DB_FILE, &localDb))
+	{
+		log_warn("Can't open database: %s\n", sqlite3_errmsg(localDb));
+		sqlite3_close(localDb);
+	}
+	else
+	{
+		if (sqlite3_exec(localDb, insertSql, 0, 0, & errMsg) != SQLITE_OK)
+		{
+			log_warn("Upload ocmf error message : %s", errMsg);
+		}
+		else
+		{
+			log_info("Upload ocmf successfully ");
+		}
+		sqlite3_close(localDb);
+	}
+}

+ 6 - 0
EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.h

@@ -13,4 +13,10 @@ int InsertEventRecord(uint8_t *statusCode);
 int DB_Get_PowerConsumption(uint8_t gunIndex);
 int DB_Insert_PowerConsumption(uint8_t gunIndex, float energy);
 int DB_Update_PowerConsumption(uint8_t gunIndex, float energy);
+// OCMF
+int DB_Insert_ocmf(uint8_t gun_index);
+void DB_Update_ocmf(uint8_t gun_index);
+void DB_Update_ocmf_Record(uint8_t gun_index, int _trid, bool isGet);
+int DB_Get_OcmfTrid(uint8_t gun_index);
+void DB_Upload_ocmf(uint8_t gun_index, int txid);
 #endif /* _DATA_BASE_H_ */

Файловите разлики са ограничени, защото са твърде много
+ 507 - 464
EVSE/Projects/DD360ComBox/Apps/Define/define.h


+ 4 - 4
EVSE/Projects/DD360ComBox/Apps/Log/log.h

@@ -2,11 +2,11 @@
 #define _LOG_H_
 
 //------------------------------------------------------------------------------
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
 
-#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args) //DS60-120 add
 //------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...);
 int StoreEventLogMsg(const char *fmt, ...);

+ 9 - 4
EVSE/Projects/DD360ComBox/Apps/Makefile

@@ -25,6 +25,9 @@ INC_FLAGS += -I $(TOP)/ModulePrimary
 INC_FLAGS += -I $(TOP)/ModuleLcmCtrl
 INC_FLAGS += -I $(TOP)/ModuleDoComm
 INC_FLAGS += -I $(TOP)/ModuleEventLog
+INC_FLAGS += -I ../../../Modularization/ocppfiles
+INC_FLAGS += -I ../../../GPL/mosquitto-2.0.13/release/usr/local/include
+
 
 DefineLib = $(TOP)/Define
 LogLib = $(TOP)/Log
@@ -41,7 +44,8 @@ DoCommLib = $(TOP)/ModuleDoComm
 EventLogLib = $(TOP)/ModuleEventLog
 SelectGunLib = $(TOP)/SelectGun
 ScriptLib = $(TOP)/Script
-
+Lib_MOSQUITTO = "-L../../../GPL/mosquitto-2.0.13/release/usr/local/lib" -lmosquitto
+Lib_JSONC = "-L../../../GPL/json-c-json-c-0.13.1-20180305/release/lib" -ljson-c
 
 #define library variable
 Internal485ProtocolLib = -L $(ModularizationPath)/Internal485Protocol -lInternal485Protocol
@@ -62,6 +66,7 @@ RatedCurrent_H = -include$(ModularizationPath)/Module_RatedCurrent.h
 
 InfypwrPsuComm_H = -include$(ModularizationPath)/Infypwr_PsuCommObj.h
 InfypwrPsuComm_A = $(ModularizationPath)/libInfypwr_PsuCommObj.a
+JSON_H = -include../../../GPL/json-c-json-c-0.13.1-20180305/release/include/json-c/json.h
 
 #common lib
 COMMON_OBJ_FILES = common.o \
@@ -81,7 +86,7 @@ MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 	$(CC) $(CFLAGS) -c $<
 
 #DoComm
-DOCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(DoCommLib)/DoComm.o
+DOCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(DoCommLib)/DoComm.o $(DataBaseLib)/DataBase.o
 DOCOMM_SRC_FILES = $(patsubst %.o, %.c, $(DOCOMM_OBJ_FILES))
 
 #internal comm lib
@@ -142,7 +147,7 @@ all: CopyFile apps
 apps: MainTask DoCommTask EvCommTask UpdateFWTask ChkSysTask \
 		EventLoggingTask InternalCommTask LcmControlTask \
 			PrimaryCommTask ReadCmdlineTask UnsafetyOutputTool \
-				FactoryConfigApp OtherTools CleanExec
+				FactoryConfigApp OtherTools CleanExec 
 
 MainTask:
 	$(CC) $(DEFINE) $(MAIN_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(ModuleUpgrade_H) $(RateCurrent_H) \
@@ -154,7 +159,7 @@ MainTask:
 	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
 
 DoCommTask:
-	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_DoComm
+	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(SQLite3_H) $(Lib_SQLite3) $(INC_FLAGS) -o Module_DoComm
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
 	#$(CC) -o Module_DoComm DoComm.o define.o

+ 13 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleChkSysTask/Module_ChkSysTask.c

@@ -78,6 +78,7 @@ unsigned char CheckSystemTask(unsigned char systemPage)
 	unsigned char count_doComm	    = GetProcessCount("Module_DoComm");
 	unsigned char count_produceComm	= GetProcessCount("Module_ProduceUtils");
 	unsigned char count_updateFW	= GetProcessCount("Module_UpdateFW");
+	unsigned char count_DcMeter  	= GetProcessCount("Module_DcMeter");
 
 	//if (systemPage != _LCM_FIX )
 	{
@@ -96,6 +97,8 @@ unsigned char CheckSystemTask(unsigned char systemPage)
 			system("killall Module_DoComm");
 			system("killall Module_ProduceUtils");
 			system("killall Module_UpdateFW");
+			if (pSysConfig->ModelName[3] == 'P')
+				system("killall Module_DcMeter");
             sleep(3);
             system("/root/main &");
             sleep(20);
@@ -156,6 +159,12 @@ unsigned char CheckSystemTask(unsigned char systemPage)
 				sleep(3);
 				system("/root/Module_UpdateFW &");
 			}
+			if (count_DcMeter < _SYSTEM_TASK_COUNT_DCMETER && pSysConfig->ModelName[3] == 'P' )
+			{
+				system("killall Module_DcMeter");
+				sleep(3);
+				system("/root/Module_DcMeter &");
+			}
 		}
 
 	}
@@ -180,7 +189,8 @@ unsigned char CheckSystemTask(unsigned char systemPage)
         result = _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS;
     else if (count_updateFW < _SYSTEM_TASK_COUNT_UPDATEFW)
         result = _SYSTEM_TASK_LOST_ITEM_UPDATEFW;
-
+    else if (count_DcMeter < _SYSTEM_TASK_COUNT_DCMETER && pSysConfig->ModelName[3] == 'P')
+        result = _SYSTEM_TASK_LOST_ITEM_DCMETER;
 
 	return result;
 }
@@ -214,6 +224,8 @@ void CheckSystemTaskAlive()
                log_error("System task lost (ProcductUtils Comm). ");
            else if (lostId == _SYSTEM_TASK_LOST_ITEM_UPDATEFW)
                log_error("System task lost (Update FW) ");
+           else if (lostId == _SYSTEM_TASK_LOST_ITEM_DCMETER)
+               log_error("System task lost (DcMeter) ");
            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = YES;
         }
     } else

+ 2 - 0
EVSE/Projects/DD360ComBox/Apps/ModuleChkSysTask/Module_ChkSysTask.h

@@ -45,6 +45,7 @@
 #define _SYSTEM_TASK_LOST_ITEM_DOCOMM       7
 #define _SYSTEM_TASK_LOST_ITEM_PRODUCTUTILS 8
 #define _SYSTEM_TASK_LOST_ITEM_UPDATEFW     9
+#define _SYSTEM_TASK_LOST_ITEM_DCMETER      10
 
 ///*
 #define _SYSTEM_TASK_COUNT_MAIN             5 
@@ -56,6 +57,7 @@
 #define _SYSTEM_TASK_COUNT_DOCOMM           1
 #define _SYSTEM_TASK_COUNT_PRODUCEUTILS     1
 #define _SYSTEM_TASK_COUNT_UPDATEFW         1
+#define _SYSTEM_TASK_COUNT_DCMETER          1
 //*/
 /*
 #define _SYSTEM_TASK_COUNT_MAIN             3 

+ 166 - 13
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c

@@ -62,6 +62,7 @@ static int TimeZoneOffset = 0;
 int RxLen;
 char Rxdata[1024];
 uint8_t _isplugin = 0;
+int gunstatus[2];
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -356,11 +357,15 @@ static void ClearAuthorizedFlag(void)
 
 static void ClearDetectPluginFlag(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount > 1 && gunIndex == RIGHT_GUN_NUM)
+        return;
     ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
 }
 
 static bool isDetectPlugin(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return false;
     if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
         return true;
     }
@@ -662,9 +667,8 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
         case MISC_CMD_DEFAULT_PRICES:
             prices = transPricesUnit((int)value);
             log_info("default prices = %.2f", prices);
-            //if (prices > 0)
-            //    ShmDcCommonData->ChargingRate = prices;
-            //pSysConfig->BillingData.isBilling = YES;
+            ShmDcCommonData->ChargingRate = prices;
+            pSysConfig->BillingData.isBilling = YES;
             for (j = 0; j < 24; j++) {
                 pSysConfig->BillingData.Fee[j] = prices;
             }
@@ -946,6 +950,12 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             gMoreInfoReq[plugNum].bits.ReceiptReq = YES;
             break;
+        case MISC_CMD_RFIDCARD_ENDIAN:
+            if (pSysConfig->RfidCardNumEndian != value) {
+                pSysConfig->RfidCardNumEndian = value;
+                log_info("Set RFID CARD %s endian", value ? "Big" : "Little");
+            }
+            break;
         default:
             clearMiscCommand();
             break;
@@ -1948,7 +1958,6 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
         strncpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
                 "",
                 sizeof(ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode));
-
         strncpy(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE);
     } else if ((pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EVSE) ||
                (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) ||
@@ -1958,9 +1967,28 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
         pConnState->State = CONN_ST_CHARGING;    //charging
     } else if (pDcChargingInfo->SystemStatus == S_TERMINATING ||
             pDcChargingInfo->SystemStatus == S_COMPLETE) {
+        if (pSysConfig->ModelName[3] == 'P') {
+            if (!ShmDcCommonData->pGunInfo[plugNum].isMeterStop) {
+                return FAIL;
+            }
+        } else {
+            if (pDcChargingInfo->RelayK1K2Status == YES) {
+                return FAIL;
+            }
+        }
         pConnState->State = CONN_ST_TERMINATING;    //terminating
+
     } else if ((pDcChargingInfo->SystemStatus == S_ALARM) ||
                (pDcChargingInfo->SystemStatus == S_FAULT)) {
+        if (pSysConfig->ModelName[3] == 'P') {
+            if (!ShmDcCommonData->pGunInfo[plugNum].isMeterStop && pDcChargingInfo->SystemStatus == S_ALARM) {
+                return FAIL;
+            }
+        } else {
+            if (pDcChargingInfo->RelayK1K2Status == YES && pDcChargingInfo->SystemStatus == S_ALARM) {
+                return FAIL;
+            }
+        }
         pConnState->State = CONN_ST_ALARM;
         strncpy((char *)pConnState->WarningCode,
                 (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
@@ -1975,7 +2003,7 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
             log_info("1 ID = %d, VendorErrorCode = %s",
                      plugNum,
                      (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode);
-                     */
+            */
         } else {
             if (strncmp(&vendorErrorCodeTmp[plugNum][0],
                         (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
@@ -1993,9 +2021,16 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
             }
         }
     }
+    if (gunstatus[plugNum] != pConnState->State) {
+        log_info("Gun%d Status[%d] to OCPP Backend",plugNum,pConnState->State);
+        gunstatus[plugNum] = pConnState->State;
+    }
+
 #ifdef DD360
-    memcpy((char*)&_consumption, (char*)&ShmDcCommonData->pGunInfo[plugNum].PowerConsumption, sizeof(float));
-    pConnState->consumption = ntohl(_consumption);
+
+        memcpy((char*)&_consumption, (char*)&ShmDcCommonData->pGunInfo[plugNum].PowerConsumption, sizeof(float));
+        pConnState->consumption = ntohl(_consumption);
+
 #endif
     ret = composeSocketData(fd,
                             id,
@@ -2006,6 +2041,92 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     return ret;
 }
 
+/**
+ *
+ * @param data
+ * @param length
+ * @return
+ */
+uint32_t crc32(uint8_t *data, uint32_t length)
+{
+	uint32_t crc=0xFFFFFFFF;
+
+	for(size_t i=0;i<length;i++)
+	{
+		char ch=data[i];
+		for(size_t j=0;j<8;j++)
+		{
+			uint32_t b=(ch^crc)&1;
+
+			crc>>=1;
+
+			if(b) crc=crc^0xEDB88320;
+
+			ch>>=1;
+		}
+	}
+
+	return ~crc;
+}
+
+/**
+ *
+ * @param filename
+ * @return
+ */
+uint32_t getFileCrc32(char *filename)
+{
+	uint32_t result = 0;
+
+	int fd = open(filename, O_RDONLY);
+    if(fd < 0)
+    {
+        log_error("Can not open file %s\n", filename);
+    }
+    else
+    {
+    	struct stat st;
+		stat(filename, &st);
+		uint8_t *data;
+		data = malloc(st.st_size);
+
+		if(read(fd,data,st.st_size) == st.st_size)
+		{
+			result = crc32(data, st.st_size);
+			close(fd);
+		} else {
+			log_error("Read file Error %d\n", st.st_size);
+		}
+
+		free(data);
+    }
+
+	return result;
+}
+static int wrtieOcmpInfo(int fd, uint8_t plugNum, uint8_t id)
+{
+    int ret = PASS;
+    uint8_t dataBuf[241];
+
+    OcmfInfoData* pOcmf = (OcmfInfoData*)dataBuf;
+    pOcmf->CRC = htonl(getFileCrc32(ShmDcCommonData->pGunInfo[plugNum].OcmfFileName));
+    if (pOcmf->CRC == 0) {
+        log_info("CRC is Zero! Not transmit to Cabinet");
+        return FAIL;
+    }
+    //memcpy((char*)pOcmf->TxId,pSysInfo->DcMeterReadTransactionRecord[plugNum].head.transactionId,sizeof(pSysInfo->DcMeterReadTransactionRecord[plugNum].head.transactionId));
+    sprintf((char*)pOcmf->TxId,"%d",ShmDcCommonData->ocmfTridRecord[plugNum]);
+
+    memcpy((char*)pOcmf->OcmfPublicKey, (char*)pSysInfo->DcMeterStatusInfo[plugNum].publicKeyOcmf,sizeof(pSysInfo->DcMeterStatusInfo[plugNum].publicKeyOcmf));
+    log_info("txid:[%s], crc:[%X], publicKey:[%s]",pOcmf->TxId,htonl(pOcmf->CRC),pSysInfo->DcMeterStatusInfo[plugNum].publicKeyOcmf);
+    ret = composeSocketData(fd,
+                        id,
+                        OP_WRITE_DATA,
+                        REG_OCMF_INFO,
+                        sizeof(dataBuf) - 1,
+                        &dataBuf[0]);
+    return ret;
+}
 static int writePlugInStatus(int fd, uint8_t plugNum, uint8_t id)
 {
     int ret = PASS;
@@ -2043,6 +2164,12 @@ static int writeChargingTarget(int fd, uint8_t plugNum, uint8_t id)
     uint8_t dataBuf[4] = {0};
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
+    if ((pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EV || pDcChargingInfo->SystemStatus >= S_TERMINATING) &&
+        pDcChargingInfo->SystemStatus != S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus != S_CCS_PRECHARGE_ST1) {
+        pDcChargingInfo->EvBatterytargetVoltage = 0;
+        pDcChargingInfo->EvBatterytargetCurrent = 0;
+    }
+
     ChargingVolt = pDcChargingInfo->EvBatterytargetVoltage;
     ChargingAmp = pDcChargingInfo->EvBatterytargetCurrent;
     ChargingVolt *= 10;
@@ -2452,6 +2579,25 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 writeConnectorState(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
+            curReg = REG_OCMF_INFO;
+            break;
+        case REG_OCMF_INFO:
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                if (ShmDcCommonData->pGunInfo[plugNum].SendOcmfDataReq) {
+                    if (wrtieOcmpInfo(fd,plugNum,gunID) == PASS) {
+                        DB_Upload_ocmf(plugNum,ShmDcCommonData->ocmfTridRecord[plugNum]);
+                        ShmDcCommonData->pGunInfo[plugNum].SendOcmfDataReq = FALSE;
+                        char cmd[500];
+                        sprintf(cmd,"rm -f %s",ShmDcCommonData->pGunInfo[plugNum].OcmfFileName);
+                        system(cmd);
+                        ShmDcCommonData->ocmfTridRecord[plugNum] = 0;
+                    } else {
+                        ShmDcCommonData->pGunInfo[plugNum].SendOcmfDataReq = FALSE;
+                    }
+                }
+                ftime(&gRegTimeUp[plugNum][curReg]);
+            }
             curReg = REG_DISPENSER_REQUEST;
             break;
         case REG_DISPENSER_REQUEST:
@@ -2708,16 +2854,16 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_MAINTAIN:
     case S_ALARM:
     case S_AUTHORIZING:
-        /*
+        
         if(pDcChargingInfo->SystemStatus == S_ALARM) {
             ftime(&AuthNowTime);
-            if (DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
-                DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) < 0
+            if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
                 ) {
-                readChargingTimeStamp(fd, gunID);
-                ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+                writePresentChargingInfo(fd, plugNum, gunID);
+                ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
             }
-        }*/
+        }
 
         checkAuthorProcess(fd, plugNum);
 
@@ -2926,6 +3072,13 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
+            DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
+            ) {
+            writePresentChargingInfo(fd, plugNum, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
+        }
         // 獲得Charging時間
         /*
         ftime(&AuthNowTime);

+ 12 - 0
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h

@@ -100,6 +100,7 @@
 #define REG_POWER_CONSUMPTION_INFO              0x24
 #define REG_READ_CHARGING_TIMESTAMP             0x25
 
+#define REG_OCMF_INFO                           0x29
 //------------------------------------------------------------------------------
 //--- dispenser result ---
 //------------------------------------------------------------------------------
@@ -133,6 +134,8 @@
 #define MISC_CMD_LED_INTENSITY                  (0x000E)
 #define MISC_CMD_AC_CONTACTOR                   (0x000F)
 #define MISC_CMD_TIME_OFFSET                    (0x0010)
+#define MISC_CMD_PARKING_PRICE                  (0x0011)
+#define MISC_CMD_RFIDCARD_ENDIAN                (0x0012)
 
 #define MISC_CMD_HARDWARE_REBOOT                (0x0101)
 #define MISC_CMD_SOFTWARE_RESTART               (0x0102)
@@ -148,6 +151,9 @@
 #define MISC_CMD_DEFAULT_PRICE_REQ              (0x010C)
 #define MISC_CMD_USER_PRICE_REQ                 (0x010D)
 #define MISC_CMD_RECEIPT_REQ                    (0x010E)
+#define MISC_CMD_CHARGING_BILL                  (0x010F)
+#define MISC_CMD_PARKING_PRICES                 (0x0110)
+
 
 #define ST_UPDATE_FIRMWARE                      (0x01)
 #define ST_NO_UPDATE_FIRMWARE                   (0x02)
@@ -240,6 +246,12 @@ typedef struct StDoCommGlobalVar {
     uint8_t Reserved[2];
 } DoCommGblData;
 
+typedef struct StOcmfInfoData {
+    uint8_t TxId[36];
+    unsigned int CRC;
+    uint8_t OcmfPublicKey[200];
+} OcmfInfoData;
+
 typedef struct StCommnadHead {
     uint8_t SeqNum;     //sequence number 0 ~ 255
     uint8_t ID;         //0: Reserved, 0x01 ~ 0xFE: connector ID, 0xFF: exists in register 1 and register 2

+ 2 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCCS.c

@@ -756,11 +756,12 @@ void ClearAbnormalStatus_CCS(uint8_t gun_index)
 
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
             if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                /*
                 log_info("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
                          index,
                          pDcChargingInfo->EvConnAlarmCode,
                          code);
-
+                */
                 if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
 
                     if (strncmp(code, "012219", 6) == EQUAL) { pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO; }

+ 2 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalCHA.c

@@ -200,11 +200,12 @@ void ClearAbnormalStatus_Chademo(uint8_t gun_index)
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
             if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                /*
                 log_info("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
                          index,
                          pDcChargingInfo->EvConnAlarmCode,
                          code);
-
+                */
                 if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
                     if (strncmp(code, "023700", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoEvCommFail = NO; }
                     if (strncmp(code, "023704", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ChademoBatteryMalfun = NO; }

+ 2 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalGBT.c

@@ -340,11 +340,12 @@ void ClearAbnormalStatus_GB(uint8_t gun_index)
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
             if (index != gun_index || pSysConfig->TotalConnectorCount == 1) {
+                /*
                 log_info("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n",
                          index,
                          pDcChargingInfo->EvConnAlarmCode,
                          code);
-
+                */
                 if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, code, 6) != EQUAL) {
                     if (strncmp(code, "023702", 6) == EQUAL) { pInfoCode->InfoEvents.bits.GbEvCommFail = NO; }
                     if (strncmp(code, "023900", 6) == EQUAL) { pInfoCode->InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = NO; }

+ 5 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/AbnormalState.c

@@ -37,7 +37,11 @@ bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode)
     if (strncmp((char *)pDcChargingInfo->EvConnAlarmCode, "", 6) != EQUAL) {
         return true;
     }
-
+    if (pDcChargingInfo->SystemStatus == S_TERMINATING || pDcChargingInfo->SystemStatus == S_COMPLETE ||
+        pDcChargingInfo->SystemStatus == S_ALARM) {
+            // 結束充電後不顯示小板錯誤Status Code
+            return true;
+    }
     memcpy(pDcChargingInfo->EvConnAlarmCode, string, 6);
     log_info("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s\n", pDcChargingInfo->EvConnAlarmCode);
 

+ 52 - 25
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -166,6 +166,7 @@ static void getChillerTemperature(ChillerTemp *chillerTemp)
     for (i = 0; i < 4; i++) {
         adcVoltage = 0.0;
         adcVoltage =  ReadAdcVolt(i);
+        ShmDcCommonData->TempVolt[i] = adcVoltage;
         if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
             pChillerTemp->Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
             //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
@@ -235,14 +236,18 @@ void CheckEvConnect(int gunIndex)
     struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     struct InfoCodeData* pInfoCode = (struct InfoCodeData*)GetShmInfoCodeData();
     struct ChargingInfoData* pDcChargingInfo_0 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
-    struct ChargingInfoData* pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(1);
+    struct ChargingInfoData* pDcChargingInfo_1 = NULL;
+    if (pSysConfig->TotalConnectorCount == 1)
+        pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
+    else
+        pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(1);
 
     if (pDcChargingInfo_0->Type == pDcChargingInfo_1->Type) {
         isSameType = TRUE;
-        isDisconnect = ShmDcCommonData->pGunInfo[0].EVLoseFlag | ShmDcCommonData->pGunInfo[1].EVLoseFlag;
+        isDisconnect = ShmDcCommonData->pGunStatus[0].EVLoseFlag | ShmDcCommonData->pGunStatus[1].EVLoseFlag;
         gunType = pDcChargingInfo_0->Type;
     } else {
-        isDisconnect = ShmDcCommonData->pGunInfo[gunIndex].EVLoseFlag;
+        isDisconnect = ShmDcCommonData->pGunStatus[gunIndex].EVLoseFlag;
         gunType = pDcChargingInfo->Type;
     }
 
@@ -299,7 +304,7 @@ void CANReceiver(int fd)
         uint8_t printConnTemp = NO;
         uint8_t chillerTemp[2] = {0, 0};
         uint8_t maxChillerTemp = 0;
-        uint8_t lastChillerTemp = 0;
+        uint8_t lastChillerTemp[2] = {0};
         uint8_t maxConnTemp = 0;
         uint8_t lastConnTemp[2] = {0, 0};
         struct can_frame frame;
@@ -309,6 +314,7 @@ void CANReceiver(int fd)
         int len = 0;
         char _info[1024];
         int i;
+        unsigned char GunStatus[2];
 
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -322,8 +328,8 @@ void CANReceiver(int fd)
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
         ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
 
-        ShmDcCommonData->pGunInfo[0].EVLoseTimer = time((time_t*)NULL);
-        ShmDcCommonData->pGunInfo[1].EVLoseTimer = time((time_t*)NULL);
+        ShmDcCommonData->pGunStatus[0].EVLoseTimer = time((time_t*)NULL);
+        ShmDcCommonData->pGunStatus[1].EVLoseTimer = time((time_t*)NULL);
 
         //log_info("Module_EvRXComm Child's PID is %d", getpid());
         CCS_PlugoutTimer[0] = time((time_t*)NULL);
@@ -335,23 +341,23 @@ void CANReceiver(int fd)
                 pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
                 // 檢查是否有收到EV小板訊號
                 if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
-                    if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 5) &&
-                        !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
+                    if ((time((time_t*)NULL) - ShmDcCommonData->pGunStatus[_index].EVLoseTimer > 10) &&
+                        !ShmDcCommonData->pGunStatus[_index].EVLoseFlag && pSysInfo->SelfTestSeq == _STEST_COMPLETE &&
                         pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
 
-                        ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
-                        ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
+                        ShmDcCommonData->pGunStatus[_index].EVLoseTimer = time((time_t*)NULL);
+                        ShmDcCommonData->pGunStatus[_index].EVLoseFlag = TRUE;
 
                         system("/sbin/ip link set can0 down");
                         sleep(1);
                         system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
                         system("/sbin/ip link set can0 up");
                     }
-                    CheckEvConnect(_index);
                 } else {
-                    ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
-                    ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
+                    ShmDcCommonData->pGunStatus[targetGun].EVLoseTimer = time((time_t*)NULL);
+                    ShmDcCommonData->pGunStatus[targetGun].EVLoseFlag = FALSE;
                 }
+                CheckEvConnect(_index);
             }
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -416,8 +422,8 @@ void CANReceiver(int fd)
                 continue;
             }
             // Reset Connect Timer
-            ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
-            ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
+            ShmDcCommonData->pGunStatus[targetGun].EVLoseTimer = time((time_t*)NULL);
+            ShmDcCommonData->pGunStatus[targetGun].EVLoseFlag = FALSE;
 
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
             gunTypeIndex = pDcChargingInfo->type_index;
@@ -515,8 +521,10 @@ void CANReceiver(int fd)
 
             case ACK_GET_OUTPUT_REQ:
                 //DS60-120 add
+
                 if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EV &&
-                        pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+                        pDcChargingInfo->SystemStatus <= S_TERMINATING) ||
+                        pDcChargingInfo->SystemStatus == S_ALARM ||
                         (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
                          pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
                    ) {
@@ -525,9 +533,18 @@ void CANReceiver(int fd)
                         pDcChargingInfo->EvBatteryStartSoc = frame.data[1];
                     }
 
-                    if (frame.data[1] > pDcChargingInfo->EvBatterySoc) {
+                    // 進入充電時重新更新電池電量
+                    if (GunStatus[targetGun] != pDcChargingInfo->SystemStatus && pDcChargingInfo->SystemStatus == S_CHARGING) {
+
+                        log_info("Reset Gun%d SoC:%d", targetGun, frame.data[1]);
+                        pDcChargingInfo->EvBatterySoc = frame.data[1];
+                        GunStatus[targetGun] = pDcChargingInfo->SystemStatus;
+                    }
+
+                    if (frame.data[1] > pDcChargingInfo->EvBatterySoc || pDcChargingInfo->SystemStatus == S_CHARGING) {
                         pDcChargingInfo->EvBatterySoc = frame.data[1];
-                        log_info("Gun%d SOC:%d", targetGun,pDcChargingInfo->EvBatterySoc);
+                        if (frame.data[1] > pDcChargingInfo->EvBatterySoc)
+                            log_info("Gun%d SOC:%d", targetGun,pDcChargingInfo->EvBatterySoc);
                     }
                 }
                 //pDcChargingInfo->EvBatterySoc = frame.data[1]; //DS60-120 remove
@@ -648,26 +665,36 @@ void CANReceiver(int fd)
                     memcpy((char *)ShmDcCommonData->SystemTemp, (char *)chiilerTemp.Temp, sizeof(ChillerTemp));
                     chillerTemp[0] = getMaxConnectTemp(chiilerTemp.Temp[0], chiilerTemp.Temp[1]);
                     chillerTemp[1] = getMaxConnectTemp(chiilerTemp.Temp[2], chiilerTemp.Temp[3]);
-
-                    maxChillerTemp = getMaxConnectTemp(chillerTemp[0], chillerTemp[1]);
-
+                    if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
+                        // 單Chiller
+                        maxChillerTemp = getMaxConnectTemp(chillerTemp[0], chillerTemp[1]);
+                    } else {
+                        // 雙Chiller
+                        if (gunTypeIndex == 0) {
+                            maxChillerTemp = chillerTemp[0];
+                        } else {
+                            maxChillerTemp = chillerTemp[1];
+                        }
+                    }
                     //if ((maxChillerTemp - 3) >= pDcChargingInfo->ChillerTemp) {
                     //    printChillerTemp = YES;
                     //}
-                    if(maxChillerTemp > (lastChillerTemp + 2) || maxChillerTemp < (lastChillerTemp - 2))
+                    if(maxChillerTemp > (lastChillerTemp[gunTypeIndex] + 2) || maxChillerTemp < (lastChillerTemp[gunTypeIndex] - 2))
                     {
-                        lastChillerTemp = maxChillerTemp;
+                        lastChillerTemp[gunTypeIndex] = maxChillerTemp;
                         printChillerTemp = YES;
                     }
 
                     pDcChargingInfo->ChillerTemp = maxChillerTemp;
                 }
-                if (ShmDcCommonData->ConnectorTemp[gunTypeIndex][0] != 0 && ShmDcCommonData->ConnectorTemp[gunTypeIndex][1] != 0) {
+                if (ShmDcCommonData->ConnectorTemp[gunTypeIndex][0] != 0 || ShmDcCommonData->ConnectorTemp[gunTypeIndex][1] != 0) {
                     maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
                     //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
                     //    printConnTemp = YES;
                     //}
-                    maxConnTemp = getAvageTemp(maxConnTemp, targetGun);
+                    if (maxConnTemp != UNDEFINED_TEMP)
+                        maxConnTemp = getAvageTemp(maxConnTemp, targetGun);
+                    
                     if (maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
                     {
                         lastConnTemp[targetGun] = maxConnTemp;

+ 168 - 5
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -37,6 +37,7 @@ static struct GBTData *ShmGBTData = NULL;
 static struct CcsData *ShmCcsData = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
 static SelectGunInfo *ShmSelectGunInfo = NULL;
+struct MeterInformation *ShmCsuMeterData = NULL;
 
 // 限制最大充電電壓,因應不同 type 槍線來限制
 // Chademo : 500V, 125A,
@@ -50,12 +51,13 @@ static float maxChargingVol[2] = {0, 0};       // 限制最大充電電壓,如
 // 限制最大充電電流與能量透過 Web
 static float maxChargingCur[2] = {0, 0};         // 限制最大充電電流,如依照模塊則填上 0
 static float maxChargingPow = 0;                   // 限制最大充電能量,如依照模塊則填上 0
-
+int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 static float LogInfo[2][10]; //DS60-120 add
 static int CanFd = -1;
 
 bool psuOutputReady[2] = {0, 0};
-
+uint8_t deratingIndex[2];
+bool ischillerHighTemp[2];
 //------------------------------------------------------------------------------
 extern void CANReceiver(int fd);
 extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
@@ -301,13 +303,40 @@ static void setCurrentOutput(void)
         }
     }
 }
+void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
+{
+    if (((chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
+        chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP) ||
+        (chargingData->ChillerTemp >= STAGE1_GUN_DERATING_TEMP &&
+            chargingData->ChillerTemp < STAGE2_GUN_DERATING_TEMP)) &&
+        chargingData->deratingByConnOtp.deratingIndex < 1)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 1;
+    } else if ((chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP ||
+        chargingData->ChillerTemp >= STAGE2_GUN_DERATING_TEMP) &&
+        chargingData->ConnectorTemp != UNDEFINED_TEMP &&
+        chargingData->ChillerTemp != UNDEFINED_TEMP &&
+        chargingData->deratingByConnOtp.deratingIndex < 2)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 2;
+    }
 
+    if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
+    } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        if (*cur > chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex])
+            *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex];
+    }
+}
 static void SetPresentChargingOutputCap(void)
 {
     float pow1 = 0, cur1 = 0;
     float pow2 = 0, cur2 = 0;
     struct ChargingInfoData *chargingData_1 = NULL;
     struct ChargingInfoData *chargingData_2 = NULL;
+    struct PrimaryMcuData* ShmPrimaryMcuData = (struct PrimaryMcuData*)GetShmPrimaryMcuData();
 
     if (pSysConfig->TotalConnectorCount == 1) {
         chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
@@ -346,6 +375,14 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_1->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_1, &pow1, &cur1);
+        if (deratingIndex[0] != chargingData_1->deratingByConnOtp.deratingIndex) {
+            log_info("Gun0 Derating Index Set %d", chargingData_1->deratingByConnOtp.deratingIndex);
+            deratingIndex[0] = chargingData_1->deratingByConnOtp.deratingIndex;
+        }
+    }
+
     pow2 = chargingData_2->AvailableChargingPower;
     cur2 = chargingData_2->AvailableChargingCurrent;
 
@@ -371,6 +408,44 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_2->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_2, &pow2, &cur2);
+        if (deratingIndex[1] != chargingData_2->deratingByConnOtp.deratingIndex) {
+            log_info("Gun1 Derating Index Set %d", chargingData_2->deratingByConnOtp.deratingIndex);
+            deratingIndex[1] = chargingData_2->deratingByConnOtp.deratingIndex;
+        }
+    }
+    // Chiller 錯誤或溫度降載
+    if (chargingData_1->ChillerTemp <= 70 && ShmDcCommonData->pGunInfo[0].withChiller && !ischillerHighTemp[0]) {
+        ischillerHighTemp[0] = TRUE;
+        if (cur1 > 2500) {
+            log_info("Gun0 chiller temperature(%d) too high set current less than 250A", chargingData_1->ChillerTemp);
+            cur1 = 2500;
+        }
+    } else if (chargingData_1->ChillerTemp > 75 && ischillerHighTemp[0]) {
+        cur1 = 2500;
+    }
+
+    if (chargingData_2->ChillerTemp <= 70 && ShmDcCommonData->pGunInfo[1].withChiller && !ischillerHighTemp[1]) {
+        ischillerHighTemp[1] = TRUE;
+        if (cur2 > 2500) {
+            log_info("Gun1 chiller temperature(%d) too high set current less than 250A", chargingData_2->ChillerTemp);
+            cur2 = 2500;
+        }
+    } else if (chargingData_2->ChillerTemp > 75 && ischillerHighTemp[1]) {
+        cur1 = 2500;
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+        if (cur1 > 2500) {
+            log_info("Gun0 chiller alarm set current less than 250A");
+            cur1 = 2500;
+        }
+        if (cur2 > 2500) {
+            log_info("Gun1 chiller alarm set current less than 250A");
+            cur2 = 2500;
+        }
+    }
     //DS60-120 add
     if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 ||
             LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
@@ -673,6 +748,83 @@ static int DiffTimeb(struct timeb ST, struct timeb ET)
     return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
 }
 
+void CalOutputPowerAndEnergy(int _index)
+{
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+    ShmCsuMeterData = (struct MeterInformation *)GetShmCsuMeterData();
+    
+    if (pSysConfig->ModelName[3] == 'P')
+	{
+		// DC Meter
+		if (ShmDcCommonData->pGunInfo[_index].curMeterValue == 0) {
+				ShmDcCommonData->pGunInfo[_index].curMeterValue = pSysInfo->DcMeterInfo[_index].totlizeImportEnergy;
+        } else
+		{
+			if (pSysInfo->DcMeterInfo[_index].totlizeImportEnergy >= ShmDcCommonData->pGunInfo[_index].curMeterValue)
+			{
+				ShmDcCommonData->pGunInfo[_index]._curTotalCharging += (pSysInfo->DcMeterInfo[_index].totlizeImportEnergy - ShmDcCommonData->pGunInfo[_index].curMeterValue);
+				float totalChargingValue = (float)ShmDcCommonData->pGunInfo[_index]._curTotalCharging;
+
+                ShmDcCommonData->pGunInfo[_index].curMeterValue = pSysInfo->DcMeterInfo[_index].totlizeImportEnergy;
+
+				if (totalChargingValue > pDcChargingInfo->PresentChargedEnergy)
+				{
+					ShmDcCommonData->energy_time_period[_index][ShmDcCommonData->_hour_index] += totalChargingValue - pDcChargingInfo->PresentChargedEnergy;
+					pDcChargingInfo->presentChargedEnergyPeriod[ShmDcCommonData->_hour_index] += totalChargingValue - pDcChargingInfo->PresentChargedEnergy;
+				}
+                
+                if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+				    pDcChargingInfo->PresentChargedEnergy = totalChargingValue;
+                    ShmDcCommonData->pGunInfo[_index].PowerConsumption += totalChargingValue;
+                } else {
+                    pDcChargingInfo->PresentChargedEnergy = (float ) pSysInfo->DcMeterTransactionResult[_index].energyImport;
+                    if (pSysInfo->DcMeterTransactionAction[_index].OcmfInfoReady) {
+                        ShmDcCommonData->pGunInfo[_index].PowerConsumption = (float ) pSysInfo->DcMeterTransactionResult[_index].energyImportTotalStop;
+                        ShmDcCommonData->pGunInfo[_index].isMeterStop = TRUE;
+                    }
+                }
+               //pDcChargingInfo->PresentChargedEnergy = totalChargingValue;
+				if (pSysConfig->BillingData.isBilling)
+				{
+					if(strcmp((char *)pSysConfig->OcppServerURL, "") == EQUAL ||
+						strcmp((char *)pSysConfig->ChargeBoxId, "") == EQUAL)
+						pDcChargingInfo->ChargingFee = totalChargingValue * pSysConfig->BillingData.Cur_fee;
+				}
+			}
+		}
+	}
+	else
+	{
+		if (chargingTime[_index] == 0 ||
+			chargingTime[_index] > pDcChargingInfo->PresentChargedDuration)
+		{
+			chargingTime[_index] = pDcChargingInfo->PresentChargedDuration;
+		}
+		else
+		{
+			int passTime = pDcChargingInfo->PresentChargedDuration - chargingTime[_index];
+
+			if (passTime > 0)
+			{
+				float changingPow = (pDcChargingInfo->PresentChargingPower) * passTime / 3600;
+				if (pSysConfig->BillingData.isBilling)
+				{
+					ShmDcCommonData->energy_time_period[_index][ShmDcCommonData->_hour_index] += changingPow;
+					pDcChargingInfo->presentChargedEnergyPeriod[ShmDcCommonData->_hour_index] += changingPow;
+					if(strcmp((char *)pSysConfig->OcppServerURL, "") == EQUAL ||
+						strcmp((char *)pSysConfig->ChargeBoxId, "") == EQUAL)
+					pDcChargingInfo->ChargingFee += changingPow * pSysConfig->BillingData.Cur_fee;
+				}
+
+				pDcChargingInfo->PowerConsumption += changingPow;
+                ShmDcCommonData->pGunInfo[_index].PowerConsumption += changingPow;
+				pDcChargingInfo->PresentChargedEnergy += changingPow;
+				chargingTime[_index] = pDcChargingInfo->PresentChargedDuration;
+			}
+		}
+	}
+}
+
 int main(int argc, char *argv[])
 {
     bool chkChademoPermission[2] = {false};
@@ -710,7 +862,7 @@ int main(int argc, char *argv[])
     ShmGBTData = (struct GBTData *)GetShmGBTData();
     ShmCcsData = (struct CcsData *)GetShmCcsData();
     ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-
+    ShmCsuMeterData = (struct MeterInformation *)GetShmCsuMeterData();
     CanFd = InitCanBus();
 
     FormatVoltageAndCurrent();
@@ -859,7 +1011,11 @@ int main(int argc, char *argv[])
                     //maxChargingPow = (pSysConfig->MaxChargingPower * 10);
                     //DS60-120 add
                     SendErrorCount[gunIndex] = 0;
-
+                    if (pSysConfig->ModelName[3] == 'P') {
+                        ShmCsuMeterData->_meter[gunIndex].curMeterValue = 0;
+                        ShmCsuMeterData->_meter[gunIndex]._chargingValue = 0;
+                        ShmCsuMeterData->_meter[gunIndex]._curTotalCharging = 0;
+                    }
                     //maxChargingPow = pSysConfig->MaxChargingPower * 10;
                     // ShmPsuData->SystemAvailablePower 已是 * 10
                     //maxChargingPow = ShmPsuData->SystemAvailablePower;
@@ -922,7 +1078,7 @@ int main(int argc, char *argv[])
 
                     pDcChargingInfo->RealMaxVoltage = maxVol;
 
-                    SetChargingPermission(gunIndex,
+                    SetChargingPermission(gunIndex, 
                                           START,
                                           pDcChargingInfo->AvailableChargingPower,
                                           maxCur,
@@ -1031,6 +1187,8 @@ int main(int argc, char *argv[])
                     ((float)((pDcChargingInfo->PresentChargingVoltage) *
                              (pDcChargingInfo->PresentChargingCurrent)) / 1000);
 
+                CalOutputPowerAndEnergy(gunIndex);
+                /*
                 //DS60-120 remove
                 if (chargingTime[gunIndex] == 0 ||
                         chargingTime[gunIndex] > pDcChargingInfo->PresentChargedDuration) {
@@ -1052,6 +1210,7 @@ int main(int argc, char *argv[])
                     }
                     
                 }
+                */
 
                 // 開始確認車端是否同意開始充電
                 GetOutputReq(gunIndex, pDcChargingInfo->Evboard_id);
@@ -1094,6 +1253,8 @@ int main(int argc, char *argv[])
 
             case S_ALARM:
             case S_TERMINATING:
+                CalOutputPowerAndEnergy(gunIndex);
+
                 // 設定當前輸出
                 setCurrentOutput();
                 SetPresentChargingOutputPower();
@@ -1146,6 +1307,8 @@ int main(int argc, char *argv[])
                 // 設定當前輸出
                 SetPresentChargingOutputPower();
 
+                CalOutputPowerAndEnergy(gunIndex);
+
                 if (priorityLow == 1) {
                     // 樁端輸出能力
                     maxVol = pDcChargingInfo->MaximumChargingVoltage;

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleEventLog/Module_EventLogging.c

@@ -52,7 +52,7 @@ static struct FaultCodeData *pFaultCode      = NULL;
 //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args) //DS60-120 add
 
 /*
 int StoreLogMsg(const char *fmt, ...)

+ 3 - 3
EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/Module_InternalComm.h

@@ -85,9 +85,9 @@
 #define AC_ROTARY_SWITCH_FAULT                  (131072)
 #define AC_RELAY_DRIVE_FAULT                    (262144)
 
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 

+ 62 - 10
EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c

@@ -1155,6 +1155,14 @@ void GetFwAndHwVersion_Relay(void)
         // SystemInfo
         strcpy((char *)pSysInfo->RelayModuleFwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Relay s1 = %s ", ver.Version_FW);
+
+        if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
+                pSysInfo->RelayModuleFwRev[0] != '\0') &&
+                (ShmRelayModuleData->SelfTest_Comp != YES)
+            ) {
+            //log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
+            ShmRelayModuleData->SelfTest_Comp = YES;
+        }
     }
 
     if (Query_HW_Ver(Uart5Fd, ADDR_RELAY, &ver) == PASS) {
@@ -1245,9 +1253,34 @@ static void GetFanSpeed(void)
 static void GetFanSpeedByFunction(void)
 {
     if (ShmDcCommonData->debugflag== YES) {
+        ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
         return;
     }
 
+    int gunIndex;
+    struct ChargingInfoData* pDcChargingInfo = NULL;
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
+        if (ShmDcCommonData->pGunInfo[gunIndex].withChiller) {
+            if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
+                (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                ShmDcCommonData->FanOnTime = time((time_t*)NULL);
+                if (ShmFanModuleData->SetFan1Speed == 0) {
+                    ShmFanModuleData->SetFan1Speed = 7000;
+                    log_info("Set Fan speed 7000");
+                }
+            }
+        }
+    }
+
+    if ((time((time_t*)NULL) - ShmDcCommonData->FanOnTime) >= 600 &&
+        ShmFanModuleData->SetFan1Speed == 7000) {
+        ShmFanModuleData->SetFan1Speed = 0;
+        log_info("Close fan");
+        ShmDcCommonData->FanOnTime = time((time_t*)NULL);
+    }
+
+    /*
     // 風控修改 :
     // ******************************************************* //
     //
@@ -1305,6 +1338,7 @@ static void GetFanSpeedByFunction(void)
     if (ShmFanModuleData->TestFanSpeed < 0) {
         ShmFanModuleData->TestFanSpeed = 0;
     }
+    */
 //
 //  printf("power = %f \n", power);
 //  printf("_maxPower = %d \n", _maxPower);
@@ -1371,6 +1405,13 @@ static void GetFwAndHwVersion_Fan(void)
         // SystemInfo
         strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
+        if ((strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
+                pSysInfo->FanModuleFwRev[0] != '\0') &&
+                (ShmFanModuleData->SelfTest_Comp != YES)
+            ) {
+            //log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
+            ShmFanModuleData->SelfTest_Comp = YES;
+        }
     }
 
     if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
@@ -1406,7 +1447,7 @@ static void fanBoardPorcess(void)
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
             //GetPsuTempForFanSpeed();
-            //GetFanSpeedByFunction();
+            GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
@@ -1486,7 +1527,7 @@ static void SetLedColor(void)
     //printf("chargingData_1->SystemStatus=%d\n",chargingData_1->SystemStatus);
     //printf("chargingData_2->SystemStatus=%d\n",chargingData_2->SystemStatus);
     //printf("pSysWarning->Level=%d\n",pSysWarning->Level);
-    if (pSysWarning->Level == 2) {
+    if (pSysWarning->Level == 2 || pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
         led_color.Connect_1_Green = COLOR_MIN_LV;
         led_color.Connect_1_Blue = COLOR_MIN_LV;
         led_color.Connect_1_Red = _colorBuf;
@@ -1530,7 +1571,9 @@ static void SetLedColor(void)
                 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_UPDATE ) {
+            } else if ( chargingData_1->SystemStatus == S_UPDATE ||
+                        chargingData_1->SystemStatus == S_FAULT ||
+                        chargingData_1->SystemStatus == S_MAINTAIN) {
                 led_color.Connect_1_Green = COLOR_MIN_LV;
                 led_color.Connect_1_Blue = COLOR_MIN_LV;
                 led_color.Connect_1_Red = _colorBuf;
@@ -1552,8 +1595,7 @@ static void SetLedColor(void)
         } else {
             //實際操作
             if (chargingData_1->SystemStatus == S_BOOTING ||
-                    chargingData_1->SystemStatus == S_IDLE ||
-                    chargingData_1->SystemStatus == S_MAINTAIN) {
+                    chargingData_1->SystemStatus == S_IDLE) {
 
                 if (chargingData_1->IsAvailable == NO) { //For Audi
                     led_color.Connect_1_Green = COLOR_MIN_LV;
@@ -1577,7 +1619,9 @@ static void SetLedColor(void)
                 led_color.Connect_1_Green = COLOR_MIN_LV;
                 led_color.Connect_1_Blue = _colorBuf;
                 led_color.Connect_1_Red = COLOR_MIN_LV;
-            }else if ( chargingData_1->SystemStatus == S_UPDATE ) {
+            }else if ( chargingData_1->SystemStatus == S_UPDATE ||
+                chargingData_1->SystemStatus == S_FAULT ||
+                    chargingData_1->SystemStatus == S_MAINTAIN) {
                 led_color.Connect_1_Green = COLOR_MIN_LV;
                 led_color.Connect_1_Blue = COLOR_MIN_LV;
                 led_color.Connect_1_Red = _colorBuf;
@@ -1591,11 +1635,9 @@ static void SetLedColor(void)
                 led_color.Connect_1_Red = COLOR_MIN_LV;
             }
 
-
             // --------------------------------------------------------------------------
             if (chargingData_2->SystemStatus == S_BOOTING ||
-                    chargingData_2->SystemStatus == S_IDLE ||
-                    chargingData_2->SystemStatus == S_MAINTAIN) {
+                    chargingData_2->SystemStatus == S_IDLE) {
                 if (chargingData_2->IsAvailable == NO) {
                     led_color.Connect_2_Green = COLOR_MIN_LV;
                     led_color.Connect_2_Blue = COLOR_MIN_LV;
@@ -1618,7 +1660,9 @@ static void SetLedColor(void)
                 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_2->SystemStatus == S_UPDATE ) {
+            }else if ( chargingData_2->SystemStatus == S_UPDATE ||
+                    chargingData_2->SystemStatus == S_FAULT ||
+                    chargingData_2->SystemStatus == S_MAINTAIN) {
                 led_color.Connect_2_Green = COLOR_MIN_LV;
                 led_color.Connect_2_Blue = COLOR_MIN_LV;
                 led_color.Connect_2_Red = _colorBuf;
@@ -1634,6 +1678,14 @@ static void SetLedColor(void)
 
         }
     }
+    if (ShmDcCommonData->pTest.ledflag) {
+        led_color.Connect_1_Red = pSysConfig->LedInfo.Red[0];
+        led_color.Connect_1_Green = pSysConfig->LedInfo.Green[0];
+        led_color.Connect_1_Blue = pSysConfig->LedInfo.Blue[0];
+        led_color.Connect_2_Red = pSysConfig->LedInfo.Red[0];
+        led_color.Connect_2_Green = pSysConfig->LedInfo.Green[0];
+        led_color.Connect_2_Blue = pSysConfig->LedInfo.Blue[0];
+    }
     if (_checkLedChanged > 0) {
         if (Config_Led_Color(Uart5Fd, ADDR_LED, &led_color) == PASS) {
             _checkLedChanged--;

+ 63 - 35
EVSE/Projects/DD360ComBox/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -933,20 +933,22 @@ void ChangeRemainTime(int sec)
 
 void ChangeChargingEnergyValue(float energy)
 {
-    uint8_t cmd[10];
-    uint8_t value[10];
+    uint8_t cmd[20];
+    uint8_t value[20];
 
     memset(cmd, 0x00, sizeof(cmd));
 
     sprintf((char*)value, "%.4f kWh", energy);
+    if (energy > 0.00005)
+        energy -= 0.00005;
     string2ByteArray(value, cmd);
     DisplayValueToLcm(__present_energy, cmd, sizeof(cmd));
 }
 
 void ChangeChargingPowerValue(float pow)
 {
-    uint8_t cmd[10];
-    uint8_t value[10];
+    uint8_t cmd[20];
+    uint8_t value[20];
 
     memset(cmd, 0x00, sizeof(cmd));
 
@@ -1040,8 +1042,8 @@ void DisplayMoneyRate(float money)
 
 void DisplayMoneyCur(uint8_t *cur)
 {
-    uint8_t cmd[10] = {0};
-    uint8_t buf[10] = {0};
+    uint8_t cmd[20] = {0};
+    uint8_t buf[20] = {0};
     uint8_t len = 0;
 
     *(cur + 3) = '\0';
@@ -1755,15 +1757,31 @@ void ProcessPageInfo()
     struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
     struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
 
+    bool isCharging = false;
+    for (uint8_t i = 0; i < _totalCount; i++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+        if (pDcChargingInfo->SystemStatus == S_IDLE) {
+            continue;
+        }
+
+        isCharging = true;
+        break;
+    }
+
     // 隨插即充 - 可省略該按鈕 //DS60-120 add
-    if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
+    //if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
         ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
-        if (_totalCount >= 2 && pSysInfo->IsAlternatvieConf == NO) {
+#if defined DD360Audi
+        if (_totalCount >= 2) {
+#else
+        if (_totalCount >= 2 && isCharging /*&& pSysInfo->IsAlternatvieConf == NO*/) {
+#endif
             ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
         } else {
             ChangeDisplay2Value(__sel_gun_btn, _disappear);
         }
-    }
+    //}
     showPhihongLogo(false);
     // Show Time
     ShowDateTime();
@@ -1779,6 +1797,7 @@ void ProcessPageInfo()
             ChangeDisplay2Value(__right_gun_map, _right_gun_enable_map);
         }
         ChangeDisplay2Value(__add_chk_btn, _select_gun_btn);
+        ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
         break;
 #endif //defined DD360Audi
 
@@ -1813,7 +1832,7 @@ void ProcessPageInfo()
         if (pSysConfig->isQRCode) {
             needReloadQr = false;
             ChangeQrCode_Idle((char*)ShmDcCommonData->QRCodeString);
-            /*
+            
             if (pSysConfig->QRCodeMadeMode == NO) {
                 //uint8_t len = strlen((char *)pSysConfig->SystemId);
                 ChangeQrCode_Idle((char *)pSysConfig->SystemId);
@@ -1822,7 +1841,7 @@ void ProcessPageInfo()
                 ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
             }
             //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
-            */
+            
         }
         //}
 
@@ -1838,11 +1857,15 @@ void ProcessPageInfo()
             isCharging = true;
             break;
         }
-        if (isCharging && pSysInfo->IsAlternatvieConf == NO) {
-            ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
-        } else {
-            ChangeDisplay2Value(__sel_gun_btn, _disappear);
-        }
+        //if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
+            if (isCharging && _totalCount >= 2/*&& pSysInfo->IsAlternatvieConf == NO*/) {
+                ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+            } else {
+                ChangeDisplay2Value(__sel_gun_btn, _disappear);
+            }
+        //} else {
+        //    ChangeDisplay2Value(__sel_gun_btn, _disappear);
+        //}
     }
     break;
     case _LCM_AUTHORIZING:
@@ -1868,23 +1891,21 @@ void ProcessPageInfo()
         if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
             // 新增隨插即充功能預設在等待插槍頁面在開啟
             ChangeDisplay2Value(__ret_home_btn, _disappear);
-            bool isCharging = false;
-            for (uint8_t i = 0; i < _totalCount; i++) {
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
-
-                if (pDcChargingInfo->SystemStatus == S_IDLE) {
-                    continue;
-                }
+        }
+        bool isCharging = false;
+        for (uint8_t i = 0; i < _totalCount; i++) {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
-                isCharging = true;
-                break;
+            if (pDcChargingInfo->SystemStatus == S_IDLE) {
+                continue;
             }
 
-            if (isCharging && pSysInfo->IsAlternatvieConf == NO) {
-                ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
-            } else {
-                ChangeDisplay2Value(__sel_gun_btn, _disappear);
-            }
+            isCharging = true;
+            break;
+        }
+
+        if (isCharging && _totalCount >= 2/*&& pSysInfo->IsAlternatvieConf == NO*/) {
+            ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
         } else {
             ChangeDisplay2Value(__sel_gun_btn, _disappear);
         }
@@ -1991,7 +2012,7 @@ void ProcessPageInfo()
             }
         }
 
-        ChangeDisplay2Value(__money_by_rate, _disappear);
+        //ChangeDisplay2Value(__money_by_rate, _disappear);
 
         gunTargetIndex = 0; //DS60-120 add
         for (uint8_t i = 0; i < _totalCount; i++) {
@@ -2085,7 +2106,7 @@ void ProcessPageInfo()
                     } else {
                         ChangeChargingPowerValue(0);
                     }
-
+                    
                     if (pDcChargingInfo->PresentChargedEnergy > 0 &&
                             pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
                         ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
@@ -2150,6 +2171,7 @@ void ProcessPageInfo()
                         }
                     }
                     /////////////////////// CTEP Add ///////////////////////
+#if defined DD360
                     if (strlen((char*)ShmDcCommonData->pGunInfo[i].ReceiptInfo) > 0) {
                         DisplayReceipt(ShmDcCommonData->pGunInfo[i].ReceiptInfo);
                         ChangeDisplay2Value(__receipt_backgroud, _receipt_bk);
@@ -2157,6 +2179,7 @@ void ProcessPageInfo()
                         DisplayReceipt("");
                         ChangeDisplay2Value(__receipt_backgroud, _disappear);
                     }
+#endif 
                     // EnergyCost
                     ChangeEnergyCostValue(ShmSelectGunInfo->PricesInfo[i].EnergyCost, _currentPage);
                     // Parking Fee
@@ -2240,7 +2263,7 @@ void ProcessPageInfo()
             break;
         }
         // For Network Disconnect
-        for (i = 0; i < pSysWarning->WarningCount; i++) {
+        for (int 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);
@@ -2277,10 +2300,15 @@ void ChangeDisplayMoneyInfo()
 #endif //defined DD360Audi
 
             pSysConfig->BillingData.Cur_fee = pSysConfig->BillingData.Fee[tmCSU->tm_hour];
+
+#if defined DD360Audi
+            if (tmCSU->tm_hour <= 23) {
+                DisplayMoneyRate(pSysConfig->BillingData.Cur_fee);
+            }
+#else
             ChangeDisplay2Value(__money_by_rate, _disappear);
             ShowAnimationPrice(ShmDcCommonData->DefaultPriceString);
-
-
+#endif
             if (pSysConfig->BillingData.Currency <= 53) {
                 DisplayMoneyCur((uint8_t *)GetCurrency(pSysConfig->BillingData.Currency));
             }

+ 204 - 261
EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -53,114 +53,14 @@ uint8_t EmgBtn_count = 0;
 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;
-}
-*/
-
+bool _isNeedChkTilt = FALSE;
+struct timespec _tilt_time;
+uint8_t tilt = NO;
+bool _chargeSwitch;
 //================================================
 // Function
 //================================================
-void GetFwAndHwVersion(int fd)
+bool GetFwAndHwVersion(int fd)
 {
     Ver ver = {0};
 
@@ -168,8 +68,9 @@ void GetFwAndHwVersion(int fd)
         //log_info("Primary FW Rev = %s ", ver.Version_FW);
         strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
         strcpy((char *) pSysInfo->CsuPrimFwRev, ver.Version_FW);
+        return TRUE;
     }
-
+    return FALSE;
     //if (Query_HW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS)
     //    ;//log_info("Primary HW Rev  = %s ", ver.Version_HW);
 }
@@ -186,6 +87,14 @@ void GetInputGpioStatus(int fd)
     }
 
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
+    //log_info("gpio_in.AC_Drop:%d", gpio_in.AC_Drop);
+    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) ||
+        (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
+    ) {
+        ShmPrimaryMcuData->InputDet.bits.Ac_Drop = gpio_in.AC_Drop; // Chiller Alarm ping
+    }
 #ifdef DD360ComBox
     EmgBtn_flag = 0;
 #else
@@ -224,7 +133,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 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) ||
@@ -233,8 +142,8 @@ void GetInputGpioStatus(int fd)
         pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
         pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
     } else {
-        pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
-        pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
+        //pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
+        //pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
     }
 
 #if defined DD360ComBox
@@ -286,56 +195,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)
@@ -345,17 +206,18 @@ static void checkChillerStatus(Gpio_out *gpio)
     struct ChargingInfoData *pDcChargingInfo = NULL;
     static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
     static ChillerInfo _chiller;
-    struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();;
+    struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();
+    DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     Gpio_out *pGpio = (Gpio_out *)gpio;
 
-    if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-            (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)) {
+    if ((strncmp((char*)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+        (strncmp((char*)&pSysConfig->ModelName[7], "F", 1) == 0)) {
         chillerCount++;
         ShmDcCommonData->pGunInfo[0].withChiller = TRUE;
     }
 
-    if ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)) {
+    if ((strncmp((char*)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+        (strncmp((char*)&pSysConfig->ModelName[9], "F", 1) == 0)) {
         chillerCount++;
         ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
     }
@@ -364,7 +226,7 @@ static void checkChillerStatus(Gpio_out *gpio)
         pGpio->AC_Connector = 0x00;
         return;
     }
-
+    // 設定chiller 開關
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
         if (!ShmDcCommonData->pGunInfo[gunIndex].withChiller)
             continue;
@@ -372,72 +234,52 @@ static void checkChillerStatus(Gpio_out *gpio)
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
         if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
-            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
-        {
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
             pChillerInfo->ChillerSwitch = YES;
             pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        }
-        else
-        {
-            if(pChillerInfo->ChillerSwitch == YES)
-            {
+        } else {
+            if(pChillerInfo->ChillerSwitch == YES) {
                 //10分鐘後停止
-                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600)
-                {
+                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
                     pChillerInfo->ChillerSwitch = NO;
-                    ShmFanModuleData->SetFan1Speed = 0;
-                }
-            }
-            else
-            {
-                pChillerInfo->ChillerSwitch = NO;
-            }
-        }
-#if 0
-        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
-            pChillerInfo->ChillerSwitch = YES;
-            pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        } else {
-            if (pChillerInfo->ChillerSwitch == YES) {
-                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) { //判斷如果還是大於100A不變動
-                    pChillerInfo->ChillerSwitch = YES;
-                    pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-                } else {
-                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) { //5分鐘後停止
-                        pChillerInfo->ChillerSwitch = NO;
-                    } else {
-                        pChillerInfo->ChillerSwitch = YES;
-                    }
+                    ShmDcCommonData->FanOnTime = time((time_t*)NULL);
                 }
             } else {
                 pChillerInfo->ChillerSwitch = NO;
+                ShmFanModuleData->SetFan1Speed = 0;
             }
         }
-#endif
+        // 檢查Chiller溫度點,若小於零下時開啟heater,大於10度時關閉heater
+        if (pDcChargingInfo->ChillerTemp < 70) {
+            pGpio->AC_Breaker = YES;
+        } else if(pDcChargingInfo->ChillerTemp > 75) {
+            pGpio->AC_Breaker = NO;
+        }
+        //log_info("Gun%d Set Heater %s", gunIndex, pGpio->AC_Breaker ? "ON" : "OFF");
     }
-
     uint8_t _chillerNeedOn = NO;
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
-        pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
-        if(pChillerInfo->ChillerSwitch == YES)
-        {
+        pChillerInfo = (ChillerInfo*)&fChillerInfo[gunIndex];
+        if (pChillerInfo->ChillerSwitch == YES) {
             _chillerNeedOn = YES;
-            if (chillerCount >= 2) {
-                ShmFanModuleData->SetFan1Speed = 7000;
-            }
+            ShmFanModuleData->SetFan1Speed = 7000;
         }
     }
-
+    /*
     if (ShmDcCommonData->debugflag == YES)
         _chillerNeedOn = ShmDcCommonData->chillerCtrl;
+    */
+    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+        _chillerNeedOn = NO;
+    }
 
-    if(_chiller.ChillerSwitch != _chillerNeedOn)
-    {
+    if(_chiller.ChillerSwitch != _chillerNeedOn) {
         log_info("Chiller Need Turn %s", _chillerNeedOn == YES ? "ON" : "OFF");
     }
     _chiller.ChillerSwitch = _chillerNeedOn;
     pGpio->AC_Connector = _chiller.ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
+
 }
 
 void SetOutputGpio(int fd, uint8_t outputValue)
@@ -463,15 +305,22 @@ void SetOutputGpio(int fd, uint8_t outputValue)
 
     gpio.Button_LED[0] = pLedConfig->LeftButtonLed;
     gpio.Button_LED[1] = pLedConfig->RightButtonLed;
-
+#if defined DD360ComBox
     gpio.System_LED[0] = pLedConfig->GreenLED;
     gpio.System_LED[1] = pLedConfig->YellowLED;
     gpio.System_LED[2] = pLedConfig->RedLED;
     gpio.System_LED[3] = 0x00;
-
+#else
+    if (_isNeedChkTilt) {
+        gpio.System_LED[0] = 0x00;
+        gpio.System_LED[1] = 0x00;
+        gpio.System_LED[2] = tilt;
+        gpio.System_LED[3] = tilt;
+    }
+#endif
     checkChillerStatus(&gpio);
 
-    gpio.AC_Breaker = 0x00;
+    //gpio.AC_Breaker = 0x01;
 
     Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
 }
@@ -554,56 +403,18 @@ int InitComPort()
     return fd;
 }
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+int GetTimeoutValue(struct timespec *startTime)
 {
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
+	struct timespec endTime;
 
-    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
 }
 
-//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);
-//    }
-//}
-
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
 static bool IsPrimaryProcessNeedPause(void)
 {
     bool _pause = false;
@@ -626,6 +437,128 @@ static bool IsPrimaryProcessNeedPause(void)
 
     return _pause;
 }
+bool CheckCustomer()
+{
+	bool result = false;
+	char _buf[3] = {0};
+
+	memcpy(_buf, &pSysConfig->ModelName[12], 2);
+	if (strcmp(_buf, "OL") == EQUAL)
+		result = true;
+	return result;
+}
+void TiltSensorSwitch(bool _switch)
+{
+	if (tilt != _switch)
+		tilt = _switch;
+
+}
+bool isChargingStatus(unsigned char status)
+{
+    if ((status >= S_REASSIGN_CHECK && status <= S_ALARM) ||
+        status == S_CCS_PRECHARGE_ST0 || status == S_CCS_PRECHARGE_ST1 ) {
+        return TRUE;
+    } else {
+        return FALSE;
+    }
+}
+void ChkTiltSensor(fd)
+{
+    struct ChargingInfoData *pDcChargingInfo = NULL;
+    bool isCharing = NO;
+    Gpio_in gpio_in = {0};
+
+    if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) != PASS) {
+        return;
+    }
+    for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
+    {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+        if (isChargingStatus(pDcChargingInfo->SystemStatus) || ShmPrimaryMcuData->SelfTest_Comp != PASS) {
+            isCharing = YES;
+        }
+    }
+
+	if (isCharing == YES)
+	{
+		if (_chargeSwitch == NO)
+		{
+			if (ShmDcCommonData->_tiltSensorStep == _TILT_SENSOR_STEP_NONE)
+			{
+				log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_ON ---- ");
+				ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_ON;
+				_chargeSwitch = YES;
+			}
+		}
+		else
+		{
+			switch (ShmDcCommonData->_tiltSensorStep)
+			{
+				case _TILT_SENSOR_STEP_PIN_ON:
+				{
+					TiltSensorSwitch(YES);
+					GetTimespecFunc(&_tilt_time);
+					log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_WAIT ---- ");
+					ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_WAIT;
+				}
+				break;
+				case _TILT_SENSOR_STEP_PIN_WAIT:
+				{
+					int _time = GetTimeoutValue(&_tilt_time);
+					if (_time < 0)
+						GetTimespecFunc(&_tilt_time);
+					else if (_time > 1)
+					{
+						if (gpio_in.Door_Open == NO)
+							pAlarmCode->AlarmEvents.bits.TiltSensorStestFail = YES;
+						else
+							pAlarmCode->AlarmEvents.bits.TiltSensorStestFail = NO;
+
+						if (_time > TILTSENSORDET)
+						{
+							GetTimespecFunc(&_tilt_time);
+							log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_OFF ---- ");
+                            log_info("---- Tilt Sensor : _TILT_SENSOR_TEST %s ---- ",
+                                pAlarmCode->AlarmEvents.bits.TiltSensorStestFail ? "FAIL" : "PASS");
+							ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_OFF;
+						}
+					}
+				}
+                break;
+				case _TILT_SENSOR_STEP_PIN_OFF:
+				{
+					TiltSensorSwitch(NO);
+					GetTimespecFunc(&_tilt_time);
+					log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_PIN_FINISH ---- ");
+					ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_PIN_FINISH;
+				}
+                break;
+				case _TILT_SENSOR_STEP_PIN_FINISH :
+				{
+					int _time = GetTimeoutValue(&_tilt_time);
+					if (_time < 0)
+						GetTimespecFunc(&_tilt_time);
+					else if (_time > TILTSENSORDET)
+					{
+						log_info("---- Tilt Sensor : _TILT_SENSOR_STEP_NONE ---- ");
+						ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_NONE;
+                        ShmPrimaryMcuData->SelfTest_Comp = PASS;
+					}
+				}
+                break;
+			}
+		}
+	}
+	else
+	{
+		TiltSensorSwitch(NO);
+		ShmDcCommonData->_tiltSensorStep = _TILT_SENSOR_STEP_NONE;
+		_chargeSwitch = NO;
+        //log_info("ShmPrimaryMcuData->SelfTest_Comp:%d",ShmPrimaryMcuData->SelfTest_Comp);
+	}
+    return;
+}
+
 
 int main(void)
 {
@@ -675,6 +608,9 @@ int main(void)
 
     //Initialization();
 
+    // 需要判斷這個的客戶碼 : OL
+	//_isNeedChkTilt = CheckCustomer();
+
     for (;;) {
         // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
         // 模組更新 FW 後,需重新做
@@ -685,16 +621,23 @@ int main(void)
         }
         if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
             //log_info("(407) Get Fw and Hw Ver. ");
-            GetFwAndHwVersion(Uart1Fd);
-            sleep(1);
-            ShmPrimaryMcuData->SelfTest_Comp = PASS;
+            if (GetFwAndHwVersion(Uart1Fd) != PASS ) {
+                sleep(1);
+                continue;
+            }
+            if (_isNeedChkTilt) {
+                ChkTiltSensor(Uart1Fd);
+            } else {
+                ShmPrimaryMcuData->SelfTest_Comp = PASS;
+            }
         } else {
+            if (_isNeedChkTilt) {
+                ChkTiltSensor(Uart1Fd);
+            }
             SetOutputGpio(Uart1Fd, ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
 
             GetInputGpioStatus(Uart1Fd);
         }
-
-
         usleep(50000);
     }
 

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -31,5 +31,5 @@ typedef struct StLedConfig {
 //------------------------------------------------------------------------------
 //int StoreLogMsg(const char *fmt, ...);
 #define SensorTrigCount 3
-
+#define TILTSENSORDET		2
 #endif /* _MODULE_PRIMARY_COMM_H_ */

+ 2 - 1
EVSE/Projects/DD360ComBox/Apps/ModulePrimary/PrimaryComm.c

@@ -117,6 +117,7 @@ int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
                 (rx[2] == tx[1]) &&
                 (rx[1] == tx[2]) &&
                 (rx[3] == tx[3])) {
+            //log_info("rx[6]:0x%x,rx[7]:0x%x", rx[6], rx[7]);
             Ret_Buf->AC_Connector       = (rx[6] >> 0) & 0x01;
             Ret_Buf->AC_MainBreaker     = (rx[6] >> 1) & 0x01;
             Ret_Buf->SPD                = (rx[6] >> 2) & 0x01;
@@ -124,7 +125,7 @@ int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
             Ret_Buf->GFD[0]             = (rx[6] >> 4) & 0x01;
             Ret_Buf->GFD[1]             = (rx[6] >> 5) & 0x01;
             Ret_Buf->AC_Drop            = (rx[6] >> 6) & 0x01;
-            Ret_Buf->Emergency_IO       = (rx[6] >> 7) & 0x01;
+            Ret_Buf->Emergency_IO       = (rx[6] >> 7) & 0x01; 
 
             Ret_Buf->Emergency_Btn      = (rx[7] >> 0) & 0x01;
             Ret_Buf->Button[0]          = (rx[7] >> 1) & 0x01;

+ 24 - 3
EVSE/Projects/DD360ComBox/Apps/ModuleUpdateFW/Module_UpdateFW.c

@@ -128,7 +128,8 @@ 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;
         }
@@ -185,6 +186,16 @@ static int InitCanBus(void)
     return fd;
 }
 
+unsigned long long getAvailableMemory()
+{
+    system("pkill ntpd");
+    sleep(1);
+    long pages = sysconf(_SC_AVPHYS_PAGES);
+    long page_size = sysconf(_SC_PAGE_SIZE);
+    log_info("Avaiable Memory size:%d MB",(pages*page_size/(1024*1024)));
+    return pages * page_size;
+}
+
 static int CheckUpdateProcess(void)
 {
     //bool isPass = true;
@@ -205,6 +216,13 @@ static int CheckUpdateProcess(void)
     DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     struct ChargingInfoData *pDcChargingInfo = NULL;
 
+
+    if (getAvailableMemory() < (200 * 1024 * 1024))
+    {
+        log_info("Available memory less than 200 MBytes, free cache first.\n");
+        system("echo 3 > /proc/sys/vm/drop_caches");
+    }
+
     pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     d = opendir("/mnt/");
     if (d) {
@@ -243,6 +261,8 @@ static int CheckUpdateProcess(void)
                         ((unsigned int)ptr[19]));
                 log_info("Typed...%x ", Type);
 
+                free(ptr);
+
                 switch (Type) {
                 case 0x10000001:
                 case 0x10000002:
@@ -396,12 +416,13 @@ static int CheckUpdateProcess(void)
                     //return isPass;
                     break;
                 }
+            } else {
+                free(ptr);
             }
             free(new_str);
-            free(ptr);
         }
     }
-    free(dir);
+    //free(dir);
     closedir(d);
 
     if (retFail != 0) {

BIN
EVSE/Projects/DD360ComBox/Apps/Module_ChkSysTask


BIN
EVSE/Projects/DD360ComBox/Apps/Module_DoComm


BIN
EVSE/Projects/DD360ComBox/Apps/Module_EvComm


BIN
EVSE/Projects/DD360ComBox/Apps/Module_EventLogging


BIN
EVSE/Projects/DD360ComBox/Apps/Module_InternalComm


BIN
EVSE/Projects/DD360ComBox/Apps/Module_UpdateFW


+ 326 - 32
EVSE/Projects/DD360ComBox/Apps/ReadCmdline.c

@@ -42,6 +42,8 @@
 #include "./Define/define.h"
 #include "./SelectGun/SelectGun.h"
 #include "Config.h"
+#include "./ModuleEvComm/Module_EvComm.h"
+#include "./CSU/main.h"
 
 //------------------------------------------------------------------------------
 #define CMD_KEY_WAIT                                (1)
@@ -342,6 +344,7 @@ void GetFwVerProc(void)
 
     printf("ModelName = %s\r\n", pSysConfig->ModelName);
     printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
+    printf("DC Main Debug Version = %s \n", ShmDcCommonData->DebugVersion);
     printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
     printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
     printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
@@ -704,6 +707,86 @@ static void setConfirmSelGun(uint8_t selGun)
     }
 }
 
+
+static float ReadAdcVolt(uint8_t AdcChannel)
+{
+    //AIN0=CCS GUN Temp 1
+    //AIN1=CCS GUN Temp 2
+    //AIN2=CCS_Proximity/2
+    //AIN3=pilot voltage
+    int fd = -1;
+    uint8_t str[64] = { 0 };
+    uint8_t AdcValue[8] = { '\0' };
+
+    if (AdcChannel > 7) {
+        return -1;
+    }
+
+    sprintf((char*)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel);
+    fd = open((char*)str, O_RDONLY);
+    read(fd, AdcValue, 4);
+
+    close(fd);
+
+    return (1.8 * atoi((char*)&AdcValue[0])) / 4095;
+    //return (1.8 * atoi((char *)&AdcValue)) / 4095;
+}
+
+static void getChillerTemperature(struct ChargingInfoData* chargingData)
+{
+    uint8_t i = 0;
+    float adcVoltage = 0.0;
+    ChillerTemp pChillerTemp;
+    uint8_t maxTemp;
+    for (i = 0; i < 4; i++) {
+        adcVoltage = 0.0;
+        adcVoltage = ReadAdcVolt(i);
+        ShmDcCommonData->TempVolt[i] = adcVoltage;
+        if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
+            pChillerTemp.Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
+            //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
+        } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) {
+            pChillerTemp.Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60;
+            //log_info("2 adcVoltage = %f", (adcVoltage - 0.9) * 500);
+        } else {
+            pChillerTemp.Temp[i] = UNDEFINED_TEMP;
+        }
+    }
+    maxTemp = pChillerTemp.Temp[0];
+    memcpy((char*)ShmDcCommonData->SystemTemp, (char*)pChillerTemp.Temp, sizeof(ChillerTemp));
+    for (i = 1; i < 4; i++) {
+        if (pChillerTemp.Temp[i] > pChillerTemp.Temp[i - 1] && pChillerTemp.Temp[i] != UNDEFINED_TEMP) {
+            maxTemp = pChillerTemp.Temp[i];
+        }
+    }
+    chargingData->ChillerTemp = maxTemp;
+}
+
+void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
+{
+    for(int i = 0 ; i < 4 ; i++) {
+        if (ShmDcCommonData->SystemTemp[i] >= STAGE1_GUN_DERATING_TEMP &&
+            ShmDcCommonData->SystemTemp[i] < STAGE2_GUN_DERATING_TEMP && 
+            chargingData->deratingByConnOtp.deratingIndex < 1) {
+            chargingData->deratingByConnOtp.deratingIndex = 1;
+        } else if (ShmDcCommonData->SystemTemp[i] >= STAGE2_GUN_DERATING_TEMP &&
+            ShmDcCommonData->SystemTemp[i] != UNDEFINED_TEMP &&
+            chargingData->deratingByConnOtp.deratingIndex < 2) {
+            chargingData->deratingByConnOtp.deratingIndex = 2;
+        }
+    }
+    if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
+    } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        if (*cur > (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10)) {
+            *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10;
+
+        }
+    }
+}
+
 void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 {
     int _GunIndex;
@@ -713,7 +796,11 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     int isContinue = 1;
     float _Voltage;
     float _Current;
+    float deratingPower;
+    float deratingCurrent;
+    int derating_index = 0;
     uint8_t PreviousSystemStatus[2] = {0xff};
+    int idx;
     char *usageMsg = "Usage:\n"
                      "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
                      "       chg    <voltage> <current>            ex: chg 500 100\n"
@@ -754,12 +841,16 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
         curGun = pSysInfo->CurGunSelected;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-
+        if (!pDcChargingInfo->IsAvailable) {
+            printf("Gun%d Not Available\n",curGun);
+            break;
+        }
         //fix gun 1
         switch (pDcChargingInfo->SystemStatus) {
         case S_IDLE:
             if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+                sleep(3);
 #if defined DD360Audi
                 setConfirmSelGun(curGun);
 #endif //defined DD360Audi
@@ -768,6 +859,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 pDcChargingInfo->ConnectorPlugIn = 1;
                 printf ("[UnconditionalCharge - S_IDLE]\n");
                 pDcChargingInfo->Type = 9;
+                sleep(1);
 
             }
             if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
@@ -781,7 +873,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARNIN]\n");
-
+                ShmFanModuleData->TestFanSpeed = 7000;
                 //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
                 printf ("wait find module\n");
 
@@ -840,7 +932,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
-
+                strcpy((char *)pSysConfig->UserId, "");
             }
             //printf ("tar vol = %d \n", _Voltage);
             //printf ("tar cur = %d \n", _Current);
@@ -920,6 +1012,60 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 //                      pDcChargingInfo->EvBatterytargetVoltage,
 //                      pDcChargingInfo->EvBatterytargetCurrent);
             //ev task do this
+            for (idx = 0; idx < pSysConfig->TotalConnectorCount; idx++) {
+                struct ChargingInfoData* pInfo = (struct ChargingInfoData*)GetDcChargingInfoData(idx);
+                if (!ShmDcCommonData->TestTemperature)
+                    getChillerTemperature(pInfo);
+                // 低溫保護
+                if ((strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "V", 1) == 0) ||
+                    (strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "F", 1) == 0)) {
+                    if ((ShmDcCommonData->SystemTemp[idx * 2] <= 70 ||
+                        ShmDcCommonData->SystemTemp[idx * 2 + 1] <= 70)) {
+                        if (pInfo->EvBatterytargetCurrent > 250) {
+                            pInfo->EvBatterytargetCurrent = 250;
+                            printf("Chiller%d temperature(%d %d) too low limit target Current under 250A\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
+                                ShmDcCommonData->SystemTemp[idx * 2 + 1]);
+                        }
+                    } else if ((ShmDcCommonData->SystemTemp[idx * 2] >= 80 ||
+                        ShmDcCommonData->SystemTemp[idx * 2 + 1] >= 80) && pInfo->EvBatterytargetCurrent != _Current) {
+                        pInfo->EvBatterytargetCurrent = _Current;
+                        printf("Chiller%d temperature(%d %d) recovery target Current set %.2fA\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
+                            ShmDcCommonData->SystemTemp[idx * 2 + 1], pInfo->EvBatterytargetCurrent);
+                    }
+                    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+                        if (pInfo->EvBatterytargetCurrent > 250) {
+                            pInfo->EvBatterytargetCurrent = 250;
+                            printf("Chiller alarm limit target Current under 250A\n");
+                        }
+                    }
+                }
+                // 高溫保護
+                if (pInfo->deratingByConnOtp.isNeedDerating) {
+                    deratingCurrent = pInfo->EvBatterytargetCurrent;
+                    deratingPower = pInfo->AvailableChargingPower;
+                    GetOtpPwrOrCurMethod(pInfo, &deratingPower, &deratingCurrent);
+                    if (derating_index != pDcChargingInfo->deratingByConnOtp.deratingIndex) {
+                        printf("Change Derating Index:%d\n", pInfo->deratingByConnOtp.deratingIndex);
+                        derating_index = pInfo->deratingByConnOtp.deratingIndex;
+                    }
+                    if (pInfo->EvBatterytargetCurrent != deratingCurrent ||
+                        pInfo->AvailableChargingPower != deratingPower) {
+                        pInfo->EvBatterytargetCurrent = deratingCurrent;
+                        pInfo->AvailableChargingPower = deratingPower;
+                        printf("Derating Current:%.3f Power:%.3f\n", pInfo->EvBatterytargetCurrent, pInfo->AvailableChargingPower);
+                    }
+                }
+
+
+            } // for
+
+            // 水冷槍低溫保護
+            if ((strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "V", 1) == 0) ||
+                (strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "F", 1) == 0)) {
+
+            }
+            
+
             pDcChargingInfo->PresentChargingPower =
                 ((float)((pDcChargingInfo->PresentChargingVoltage) *
                          (pDcChargingInfo->PresentChargingCurrent)) / 1000);
@@ -939,8 +1085,10 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 //無阻塞偵測 keybaord 結束
                 system(STTY_DEF TTY_PATH);
             }
-
+            sleep(1);
+            pDcChargingInfo->ConnectorPlugIn = 0;
             pDcChargingInfo->SystemStatus = S_COMPLETE;
+
             break;
 
         case S_COMPLETE:
@@ -955,13 +1103,14 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
                 if (PreviousSystemStatus[gunIndex] == 0xFF) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-                    pDcChargingInfo->SystemStatus = S_IDLE;
+                    pDcChargingInfo->IsAvailable ? (pDcChargingInfo->SystemStatus = S_IDLE) : (pDcChargingInfo->SystemStatus = S_MAINTAIN);
+                    
                 } else {
                     pSysInfo->CurGunSelected = gunIndex;
                 }
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-                if (pDcChargingInfo->SystemStatus == S_IDLE) {
+                if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_MAINTAIN) {
                     stopChg++;
                 }
             }
@@ -970,14 +1119,14 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             pDcChargingInfo->PresentChargingPower = 0;
 
             if (stopChg == pSysConfig->TotalConnectorCount) {
-                ShmDcCommonData->debugflag = NO;
                 system("/root/Module_EvComm &");
+                ShmFanModuleData->TestFanSpeed = 0;
+                ShmDcCommonData->debugflag = NO;
                 sleep(3);
 
                 for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
                     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-                    pDcChargingInfo->SystemStatus = S_IDLE;
+                    pDcChargingInfo->IsAvailable ? (pDcChargingInfo->SystemStatus = S_IDLE) : (pDcChargingInfo->SystemStatus = S_MAINTAIN);
                 }
                 return;
             }
@@ -1127,16 +1276,20 @@ static void resdGunAndChillerTemp(void)
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
-                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
+                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d(%.3f), %3d(%.3f), %3d(%.3f), %3d(%.3f)\r\n",
                              i,
                              pDcChargingInfo->ConnectorTemp,
                              pDcChargingInfo->ChillerTemp,
                              ShmDcCommonData->ConnectorTemp[i][0],
                              ShmDcCommonData->ConnectorTemp[i][1],
                              ShmDcCommonData->SystemTemp[0],
+                             ShmDcCommonData->TempVolt[0],
                              ShmDcCommonData->SystemTemp[1],
+                             ShmDcCommonData->TempVolt[1],
                              ShmDcCommonData->SystemTemp[2],
-                             ShmDcCommonData->SystemTemp[3]);
+                             ShmDcCommonData->TempVolt[2],
+                             ShmDcCommonData->SystemTemp[3],
+                             ShmDcCommonData->TempVolt[3]);
             }//for
             ftime(&showTime);
         }
@@ -1258,6 +1411,27 @@ void setSystemTime(char* date,char* time)
     system("hwclock -w -u");
     system("hwclock -s");
 }
+static uint8_t getMaxConnectTemp(uint8_t headTemp1, uint8_t headTemp2)
+{
+    uint8_t maxTemp = 0;
+
+    if (headTemp1 > TEMP_BOUNDARY &&
+            headTemp2 > TEMP_BOUNDARY) {
+        return UNDEFINED_TEMP;
+    }
+
+    if (headTemp1 <= TEMP_BOUNDARY) {
+        maxTemp = headTemp1;
+    }
+
+    if (headTemp2 <= TEMP_BOUNDARY) {
+        if (headTemp2 > maxTemp) {
+            maxTemp = headTemp2;
+        }
+    }
+    return maxTemp;
+}
+
 static void writeGunAndChillerTemp(void)
 {
     uint8_t _GunIndex = 0;
@@ -1298,31 +1472,59 @@ static void writeGunAndChillerTemp(void)
             continue;
         }
 
-        if (atoi(newString[2]) > 255 ||
+        if (strcmp(newString[0], "chiller") == 0) {
+            if (atoi(newString[2]) > 255 ||
+                    atoi(newString[2]) == -1 ||
+                    atoi(newString[3]) > 255 ||
+                    atoi(newString[3]) == -1 ||
+                    atoi(newString[4]) > 255 ||
+                    atoi(newString[4]) == -1 ||
+                    atoi(newString[5]) > 255 ||
+                    atoi(newString[5]) == -1) {
+                printf("temperature value overflow\r\n");
+                continue;
+            }
+        } else {
+            if (atoi(newString[2]) > 255 ||
                 atoi(newString[2]) == -1) {
-            printf("temperature value overflow\r\n");
-            continue;
+                    printf("temperature value overflow\r\n");
+                    continue;
+                }
         }
 
         _GunIndex = atoi((char *)newString[1]);
-
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
         if (_GunIndex >= pSysConfig->TotalConnectorCount) {
             printf("gun index over total connector\r\n");
             continue;
         }
 
         if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值
-            if (_GunIndex >= 1) {
-                _GunIndex = 0; //只會有一個水冷機
+            if (ShmDcCommonData->pGunInfo[_GunIndex].withChiller) {
+                ShmDcCommonData->SystemTemp[0] = atoi(newString[2]);
+                ShmDcCommonData->SystemTemp[1] = atoi(newString[3]);
+                ShmDcCommonData->SystemTemp[2] = atoi(newString[4]);
+                ShmDcCommonData->SystemTemp[3] = atoi(newString[5]);
+                for(int i = 0 ; i < pSysConfig->TotalConnectorCount ; i++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+                    if (!ShmDcCommonData->pGunInfo[i].withChiller)
+                        continue;
+                    if (i == LEFT_GUN_NUM) {
+                        pDcChargingInfo->ChillerTemp = getMaxConnectTemp(ShmDcCommonData->SystemTemp[0],ShmDcCommonData->SystemTemp[1]);
+                    } else {
+                        pDcChargingInfo->ChillerTemp = getMaxConnectTemp(ShmDcCommonData->SystemTemp[2],ShmDcCommonData->SystemTemp[3]);
+                    }
+                    printf("set %d chiller temperature = %d\r\n",
+                    i,
+                    pDcChargingInfo->ChillerTemp);
+                }
+                //memset((char*)ShmDcCommonData->SystemTemp, atoi(newString[2]), sizeof(ShmDcCommonData->SystemTemp));
+            
+            } else {
+                printf("This Gun without Chiller\r\n");
             }
 
-            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",
@@ -1333,15 +1535,95 @@ static void writeGunAndChillerTemp(void)
         usleep(sleepTime);
     }//while
 }
+
+void setledcolor(int on_off)
+{
+    if (on_off)
+        ShmDcCommonData->pTest.ledflag = TRUE;
+    else {
+        ShmDcCommonData->pTest.ledflag = FALSE;
+        return;
+    }
+
+    int isContinue = 1;
+    uint32_t sleepTime = 500000;
+    uint32_t color_value;
+    char* usageMsg = "Usage:\n"
+        "       r	0~100\n"
+        "       g	0~100\n"
+        "       b	0~100\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) {
+            ShmDcCommonData->pTest.ledflag = FALSE;
+            return;
+        }
+
+        if ((strcmp(newString[0], "r") != 0) &&
+            (strcmp(newString[1], "-1") == 0 ||
+                strcmp(newString[1], "") == 0)
+            ) {
+            printf("argc 1 is error parameter\r\n");
+            continue;
+        }
+        if ((strcmp(newString[0], "g") != 0) &&
+            (strcmp(newString[1], "-1") == 0 ||
+                strcmp(newString[1], "") == 0)
+            ) {
+            printf("argc 1 is error parameter\r\n");
+            continue;
+        }
+        if ((strcmp(newString[0], "b") != 0) &&
+            (strcmp(newString[1], "-1") == 0 ||
+                strcmp(newString[1], "") == 0)
+            ) {
+            printf("argc 1 is error parameter\r\n");
+            continue;
+        }
+        if (atoi(newString[1]) < 0 || atoi(newString[1]) > 100) {
+            printf("argc 1 is error parameter range is 0~100\r\n");
+            continue;
+        }
+        if (strcmp(newString[0], "r") == EQUAL &&
+            atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
+            pSysConfig->LedInfo.Red[0] = atoi(newString[1]);
+        } else {
+
+        }
+        if (strcmp(newString[0], "g") == EQUAL &&
+            atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
+            pSysConfig->LedInfo.Green[0] = atoi(newString[1]);
+        }
+        if (strcmp(newString[0], "b") == EQUAL &&
+            atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
+            pSysConfig->LedInfo.Blue[0] = atoi(newString[1]);
+        }
+        printf("Color set red[%d] green[%d] blue[%d]\n", pSysConfig->LedInfo.Red[0], pSysConfig->LedInfo.Green[0], pSysConfig->LedInfo.Blue[0]);
+
+        usleep(sleepTime);
+    }//while
+
+
+
+    ShmDcCommonData->pTest.ledflag = FALSE;
+}
+
 void ShowPowerConsumption(char* v1)
 {
     printf("Dispenser Gun0 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[0].PowerConsumption);
     printf("Dispenser Gun1 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[1].PowerConsumption);
 
-    printf("Power Consumption Gun1:%.4f, Gun2:%.4f, Gun3:%.4f, Gun4:%.4f", ShmDcCommonData->pConsumption.Gun1_Consumption,
-        ShmDcCommonData->pConsumption.Gun2_Consumption,
-        ShmDcCommonData->pConsumption.Gun3_Consumption,
-        ShmDcCommonData->pConsumption.Gun4_Consumption);
 }
 int main(void)
 {
@@ -1354,7 +1636,7 @@ int main(void)
                      "       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"
+                     "       ver| 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"
@@ -1367,10 +1649,10 @@ int main(void)
                      "       tempW                             : write connector header and Chiller temperature\r\n"
                      "       tempR                             : print connector header and chiller temperature\r\n"
                      "       OTP                               : Write OTP temperature\r\n"
-                     "       chiller                           : set chiller on/off\r\n"
                      "       netdump                           : show network package\r\n"
                      "       candump                           : show can package\r\n"
                      "       powerconsumption                  : Show Power Consumption\n"
+                     "       led                               : set led color\n"
                      "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
@@ -1442,7 +1724,7 @@ int main(void)
         } else if (strcmp(newString[0], "self") == 0) {
             // CSU 自我檢測狀態
             RunSelfProc(newString[1]);
-        } else if (strcmp(newString[0], "version") == 0 ||
+        } else if (strcmp(newString[0], "ver") == 0 ||
                    strcmp(newString[0], "v") == 0 ||
                    strcmp(newString[0], "-v") == 0) {
             //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
@@ -1541,8 +1823,8 @@ int main(void)
             resdGunAndChillerTemp();
         } else if (strcmp(newString[0], "OTP") == 0) { //測試槍頭和水冷機溫度
             writeOTPTemp();
-        } else if (strcmp(newString[0], "chiller") == 0) { //測試槍頭和水冷機溫度
-            writeChillerStatus(newString[1]);
+//        } else if (strcmp(newString[0], "chiller") == 0) { //測試槍頭和水冷機溫度
+//            writeChillerStatus(newString[1]);
         } else if (strcmp(newString[0], "netdump") == 0) { //印出網路封包
             showNetworkPage(newString[1]);
         } else if (strcmp(newString[0], "candump") == 0) { //印出網路封包
@@ -1551,6 +1833,18 @@ int main(void)
             setSystemTime(newString[1], newString[2]);
         } else if (strcmp(newString[0], "powerconsumption") == 0) { // Power Consumption
             ShowPowerConsumption(newString[1]);
+        } else if (strcmp(newString[0], "led") == 0) {              // LED
+            setledcolor(newString[1]);
+        } 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 if (strcmp(newString[0], "DcMeter") == 0) {
+
         } else {
             printf("%s\n", usageMsg);
         }

+ 2 - 0
EVSE/Projects/DD360ComBox/Apps/Script/init.sh

@@ -1,6 +1,7 @@
 chmod 777 Module_CSU
 chmod 777 Module_PrimaryComm
 chmod 777 Module_LcmControl
+chmod 777 Module_LcmWistronControl
 chmod 777 Module_InternalComm
 chmod 777 Module_EventLogging
 chmod 777 Module_EvComm
@@ -11,5 +12,6 @@ chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
 chmod 777 Module_DoComm
+chmod 777 Module_DcMeter
 chmod 777 SearchIP.sh
 chmod 777 FactoryConfig

+ 2 - 0
EVSE/Projects/DD360ComBox/Apps/Script/kill.sh

@@ -1,6 +1,7 @@
 pkill Module_CSU;
 pkill Module_PrimaryComm;
 pkill Module_LcmControl;
+pkill Module_LcmWistronControl;
 pkill Module_InternalComm;
 pkill Module_EventLogging;
 pkill Module_EvComm;
@@ -12,6 +13,7 @@ pkill Module_Wifi;
 pkill OcppBackend;
 pkill Module_ProduceUtils;
 pkill Module_DoComm;
+pkill Module_DcMeter;
 pkill main;
 
 /usr/bin/fuser -k /dev/watchdog

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

@@ -9,10 +9,6 @@ echo $SCRIPTPATH
 
 ProjectPath="/opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects"
 
-rm -rf $ProjectPath/DD360/Apps/;
-cp -r $ProjectPath/DD360Audi/Apps/ $ProjectPath/DD360/Apps;
-cp -r $ProjectPath/DD360Audi/ModelNameList.txt  $ProjectPath/DD360/ModelNameList.txt;
-
 rm -rf $ProjectPath/DD360ComBox/Apps/;
 cp -r $ProjectPath/DD360Audi/Apps/ $ProjectPath/DD360ComBox/Apps;
 cp -r $ProjectPath/DD360Audi/ModelNameList.txt $ProjectPath/DD360ComBox/ModelNameList.txt;

+ 36 - 5
EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c

@@ -42,6 +42,7 @@ static struct OCPP20Data* ShmOCPP20Data = NULL;
 
 static SelectGunInfo *ShmSelectGunInfo = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
+static struct MeterInformation *ShmCsuMeterData = NULL;
 
 static struct ChargingInfoData *DcChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {NULL};
 static struct ChargingInfoData *AcChargingData[AC_QUANTITY] = {NULL};
@@ -162,7 +163,6 @@ void *GetShmSysConfigData(void)
     if (ShmSysConfigAndInfo == NULL) {
         return NULL;
     }
-
     return &ShmSysConfigAndInfo->SysConfig;
 }
 
@@ -328,6 +328,15 @@ void *GetShmDcCommonData(void)
     return ShmDcCommonData;
 }
 
+void *GetShmCsuMeterData(void)
+{
+    if (ShmCsuMeterData == NULL) {
+        return NULL;
+    }
+
+    return ShmCsuMeterData;
+}
+
 //------------------------------------------------------------------------------
 static void initialGunIndexToUnUse(void)
 {
@@ -761,6 +770,24 @@ int InitSysConfigAndInfoShmMem(void)
     return PASS;
 }
 
+int InitShmCsuMeterShmMem(void)
+{
+    int MeterSMId = FAIL;
+
+    if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
+    {
+        printf("shmget ShmCsuMeterKey NG \n");
+        return 0;
+    }
+    else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        printf("shmat ShmCsuMeterData NG \n");
+        return 0;
+    }
+
+    return PASS;
+}
+
 void ClearAllShmMemParameter(void)
 {
     uint8_t i = 0;
@@ -893,7 +920,7 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
             {
                 gGunIndexInfo.AcIndex++;
                 gGunIndexInfo.AcGunIndex++;
-                pAcChargingInfo->IsAvailable = YES;
+                //pAcChargingInfo->IsAvailable = YES;
             }
         } else {
             result = false;
@@ -921,7 +948,7 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
             setAcGunTiggerStatus();
             //if( strcmp(whichtask,"CSU task") == EQUAL ) 
             {
-                pDcChargingInfo->IsAvailable = YES;
+                //pDcChargingInfo->IsAvailable = YES;
                 gGunIndexInfo.ChademoIndex++;
                 gGunIndexInfo.DcGunIndex++;
             }
@@ -954,7 +981,7 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
             pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
             //if( strcmp(whichtask,"CSU task") == EQUAL ) 
             {
-                pDcChargingInfo->IsAvailable = YES;
+                //pDcChargingInfo->IsAvailable = YES;
                 gGunIndexInfo.CcsIndex++;
                 gGunIndexInfo.DcGunIndex++;
             }
@@ -989,7 +1016,7 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
             setAcGunTiggerStatus();
             //if( strcmp(whichtask,"CSU task") == EQUAL ) 
             {
-                pDcChargingInfo->IsAvailable = YES;
+                //pDcChargingInfo->IsAvailable = YES;
                 gGunIndexInfo.GbIndex++;
                 gGunIndexInfo.DcGunIndex++;
             }
@@ -1162,6 +1189,10 @@ int CreateAllCsuShareMemory(void)
     if ((ret = InitCommonShmMem()) == FAIL) {
         return ret;
     }
+
+    if ((ret = InitShmCsuMeterShmMem()) == FAIL) {
+        return ret;
+    }
     //ClearAllShmMemParameter();
 
     //MappingChargingInfoData();

+ 1 - 1
EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.h

@@ -52,7 +52,7 @@ void *GetShmInfoCodeData(void);
 void *GetShmFaultCodeData(void);
 void *GetShmAlarmCodeData(void);
 void *GetShmStatusCodeData(void);
-
+void *GetShmCsuMeterData(void);
 void *GetShmPsuData(void);
 void *GetShmPrimaryMcuData(void);
 

BIN
EVSE/Projects/DD360ComBox/Apps/UnsafetyOutputTask


BIN
EVSE/Projects/DD360ComBox/Apps/main


+ 3 - 0
EVSE/Projects/DD360ComBox/Apps/timeout.h

@@ -54,6 +54,9 @@ enum Timeout_flag {
     Timeout_SelectGun              = 13,
     Timeout_WaitBalance            = 14,
     Timeout_EVCCID_Link            = 15,
+    Timeout_ReturnViewPage         = 16,
+    Timeout_helpPage               = 17,
+    Timeout_LanguagePage           = 18,
 };
 
 //------------------------------------------------------------------------------

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


BIN
EVSE/Projects/DD360ComBox/output/FactoryConfig


BIN
EVSE/Projects/DD360ComBox/output/Module_ChkSysTask


BIN
EVSE/Projects/DD360ComBox/output/Module_DoComm


BIN
EVSE/Projects/DD360ComBox/output/Module_EvComm


BIN
EVSE/Projects/DD360ComBox/output/Module_EventLogging


BIN
EVSE/Projects/DD360ComBox/output/Module_InternalComm


BIN
EVSE/Projects/DD360ComBox/output/Module_LcmControl


BIN
EVSE/Projects/DD360ComBox/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360ComBox/output/Module_UpdateFW


BIN
EVSE/Projects/DD360ComBox/output/ReadCmdline


BIN
EVSE/Projects/DD360ComBox/output/UnsafetyOutputTask


+ 2 - 0
EVSE/Projects/DD360ComBox/output/init.sh

@@ -1,6 +1,7 @@
 chmod 777 Module_CSU
 chmod 777 Module_PrimaryComm
 chmod 777 Module_LcmControl
+chmod 777 Module_LcmWistronControl
 chmod 777 Module_InternalComm
 chmod 777 Module_EventLogging
 chmod 777 Module_EvComm
@@ -11,5 +12,6 @@ chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
 chmod 777 Module_DoComm
+chmod 777 Module_DcMeter
 chmod 777 SearchIP.sh
 chmod 777 FactoryConfig

+ 2 - 0
EVSE/Projects/DD360ComBox/output/kill.sh

@@ -1,6 +1,7 @@
 pkill Module_CSU;
 pkill Module_PrimaryComm;
 pkill Module_LcmControl;
+pkill Module_LcmWistronControl;
 pkill Module_InternalComm;
 pkill Module_EventLogging;
 pkill Module_EvComm;
@@ -12,6 +13,7 @@ pkill Module_Wifi;
 pkill OcppBackend;
 pkill Module_ProduceUtils;
 pkill Module_DoComm;
+pkill Module_DcMeter;
 pkill main;
 
 /usr/bin/fuser -k /dev/watchdog

BIN
EVSE/Projects/DD360ComBox/output/main


Някои файлове не бяха показани, защото твърде много файлове са промени