瀏覽代碼

2022-05-12 / Simon Xue

Action:
1. [Fix] GBT 012221 OVP bug.
2. [Add] Chiller Tube OVP.
3. [Add] Print EV Board status in log.
4. [Add] PowerConsumption function.
5. [Add] Right Gun with chiller.
6. [Add] Remain Amount.

Files
As the following commit history files.

Image Version:V1.21.XX.XXXX.XX
Simon Xue 2 年之前
父節點
當前提交
d936f4c937
共有 62 個文件被更改,包括 1792 次插入1107 次删除
  1. 111 227
      EVSE/Projects/DD360/Apps/CSU/main.c
  2. 19 4
      EVSE/Projects/DD360/Apps/Config.h
  3. 113 1
      EVSE/Projects/DD360/Apps/DataBase/DataBase.c
  4. 3 1
      EVSE/Projects/DD360/Apps/DataBase/DataBase.h
  5. 159 64
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  6. 5 2
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  7. 14 2
      EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.c
  8. 36 19
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  9. 5 3
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  10. 24 24
      EVSE/Projects/DD360/Apps/ModuleInternalComm/FanBoard.c
  11. 13 6
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  12. 13 6
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c
  13. 6 2
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c
  14. 50 1
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  15. 1 0
      EVSE/Projects/DD360/Apps/SelectGun/SelectGun.h
  16. 15 7
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c
  17. 二進制
      EVSE/Projects/DD360/Images/ramdisk.gz
  18. 二進制
      EVSE/Projects/DD360/output/DoComm
  19. 二進制
      EVSE/Projects/DD360/output/FactoryConfig
  20. 二進制
      EVSE/Projects/DD360/output/Module_ChkSysTask
  21. 二進制
      EVSE/Projects/DD360/output/Module_DoComm
  22. 二進制
      EVSE/Projects/DD360/output/Module_EvComm
  23. 二進制
      EVSE/Projects/DD360/output/Module_EventLogging
  24. 二進制
      EVSE/Projects/DD360/output/Module_InternalComm
  25. 二進制
      EVSE/Projects/DD360/output/Module_LcmControl
  26. 二進制
      EVSE/Projects/DD360/output/Module_PrimaryComm
  27. 二進制
      EVSE/Projects/DD360/output/Module_UpdateFW
  28. 二進制
      EVSE/Projects/DD360/output/ReadCmdline
  29. 二進制
      EVSE/Projects/DD360/output/main
  30. 111 227
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  31. 19 4
      EVSE/Projects/DD360Audi/Apps/Config.h
  32. 113 1
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c
  33. 3 1
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.h
  34. 159 64
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  35. 5 2
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  36. 14 2
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.c
  37. 36 19
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  38. 5 3
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  39. 24 24
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/FanBoard.c
  40. 13 6
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  41. 13 6
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c
  42. 6 2
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c
  43. 50 1
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  44. 1 0
      EVSE/Projects/DD360Audi/Apps/SelectGun/SelectGun.h
  45. 15 7
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c
  46. 111 227
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  47. 19 4
      EVSE/Projects/DD360ComBox/Apps/Config.h
  48. 113 1
      EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.c
  49. 3 1
      EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.h
  50. 159 64
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c
  51. 5 2
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h
  52. 14 2
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Ev_Comm.c
  53. 36 19
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c
  54. 5 3
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c
  55. 24 24
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/FanBoard.c
  56. 13 6
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c
  57. 13 6
      EVSE/Projects/DD360ComBox/Apps/ModuleLcmCtrl/Module_LcmControl.c
  58. 6 2
      EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.c
  59. 50 1
      EVSE/Projects/DD360ComBox/Apps/ReadCmdline.c
  60. 1 0
      EVSE/Projects/DD360ComBox/Apps/SelectGun/SelectGun.h
  61. 15 7
      EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c
  62. 31 0
      build_rootfs_copy.sh

+ 111 - 227
EVSE/Projects/DD360/Apps/CSU/main.c

@@ -84,7 +84,7 @@ uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
 char *fwVersion = "V1.21.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "v1.21.0";
+char* DebugVersion = "v1.21.5";
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -404,52 +404,105 @@ static void checkGunOTPState(uint8_t gunIndex)
     //log_info("OTP:%d OTPR%d",pSysInfo->OTPTemp,pSysInfo->OTPTempR);
     //水冷機溫度檢測
     if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
-        if (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP) {
-            if (pDcChargingInfo->ChillerTemp >= pSysInfo->OTPTemp ) {
-                if (((gunIndex == 0) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                         ||
-                    ((gunIndex == 1) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-                   ) {
-                    RecordAlarmCode(gunIndex, "012323");
+        if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
+            // 單水冷機
+            // Chiller OTP
+            if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
-                }
-                else
-                {
+                    RecordAlarmCode(gunIndex, "012323");
+                } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
                 }
-            } else if (pDcChargingInfo->ChillerTemp != 0 &&
-                       pDcChargingInfo->ChillerTemp < pSysInfo->OTPTempR) {
-                //ResetChargerAlarmCode(gunIndex, "012323");
-                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
-        } else {
-            // 沒接上 Sensor or 異常
-            //RecordAlarmCode(gunIndex, "011038");
-            //ResetChargerAlarmCode(gunIndex, "012323");
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
-            if (((gunIndex == 0) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                     ||
-                ((gunIndex == 1) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-               ) {
+            // Chiller Tube OTP
+            if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
-            }
-            else
-            {
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                    RecordAlarmCode(gunIndex, "012332");
+                } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[3] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                }
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
+        } else {
+            // 雙水冷機
+            if (gunIndex == LEFT_GUN_NUM) {
+                if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+                    } else if (ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            } else {
+                if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+
+                    } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            }
         }
 
-        if(pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES)
-        {
+        if (pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES) {
             RecordAlarmCode(gunIndex, "011037");
         }
     }
@@ -1554,11 +1607,7 @@ uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
     uint8_t result = 0x00;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-        result = ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;
-    }
-
-    return result;
+    return ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;;
 }
 
 bool isEvStopCharging_ccs(uint8_t gunIndex)
@@ -1658,7 +1707,7 @@ void _DetectPlugInTimeout(void)
 	//pSysInfo->SystemPage = _LCM_COMPLETE;
 	setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
 #elif DD360 || DD360Combox
- 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
+ 	setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
 #endif
     systemPageRestoreInit();
 }
@@ -4128,9 +4177,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
     case _Type_Chademo:
         // 檢查樁端的 GFD 結果
         if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_chademo(gunIndex) > 6 &&
-                isPrechargeStatus_chademo(gunIndex) < 8
-           ) {
+                isPrechargeStatus_chademo(gunIndex) >= 6) {
             // 當前操作的槍號,進入 Charging
             setChargerMode(gunIndex, MODE_CHARGING);
         }
@@ -4177,8 +4224,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
     case _Type_GB:
         // 檢查樁端的 GFD 結果
         //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
-        if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_gb(gunIndex) > 6) {
+        if (sysStatus == S_PREPARING_FOR_EVSE && isPrechargeStatus_gb(gunIndex) >= 6) {
             setChargerMode(gunIndex, MODE_CHARGING);
         }
 
@@ -4472,6 +4518,9 @@ int main(void)
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
 
             pDcChargingInfo->IsAvailable = DB_Get_Operactive(_index);
+            if (!DB_Get_PowerConsumption(_index)) {
+                DB_Insert_PowerConsumption(_index, 0);
+            }
         }
         DB_Reboot_Record();
     }
@@ -4502,6 +4551,9 @@ int main(void)
 
     pSysInfo->OTPTemp = GUN_OTP_VALUE;
     pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
+
+    time_t ShowEVStatusTimer[2] = { 0 };
+
     for (;;) {
 
         CheckOcppStatus();
@@ -4600,9 +4652,6 @@ int main(void)
                 CheckSmartChargeProfile(gunIndex);
             }
 
-            //log_info("index = %d, ErrorCode = %s",
-            //         gunIndex,
-            //         ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode);
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
             case S_RESERVATION:
@@ -4625,6 +4674,7 @@ int main(void)
                     //Jerry add
                     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
                     memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
+                    DB_Get_PowerConsumption(gunIndex);
                     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
                     destroySelGun(gunIndex);
                     ResetDetAlarmStatus(gunIndex); //recovery OVP status code
@@ -4882,7 +4932,7 @@ int main(void)
 
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 5000000) {
+                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 1000000) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 
@@ -4953,52 +5003,7 @@ int main(void)
                 }
 
                 checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gunIndex) > 5 &&
-                            isPrechargeStatus_chademo(gunIndex) < 8) {
-                        // 當前操作的槍號,進入 Charging
-                        setChargerMode(gunIndex, MODE_CHARGING);
-                    }
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    // 檢查樁端的 GFD 結果
-                    //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
-                    if (isPrechargeStatus_gb(gunIndex) > 9) {
-                        setChargerMode(gunIndex, MODE_CHARGING);
-                    }
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    // 檢查樁端的 GFD 結果
-                    if ((pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
-                            pDcChargingInfo->GroundFaultStatus == GFD_WARNING)) {
-                        setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP0);
-                    }
 
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
-                }
-#endif //0
                 checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
 
                 // LCM => Pre-charging
@@ -5025,64 +5030,12 @@ int main(void)
                 pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
 
                 checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    }
-                    //else if (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //            pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //            pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012289");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    }
-                    //else if (isPrechargeStatus_gb(gunIndex) == 10 &&
-                    //           (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //             pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //            (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //             pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL))
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012290");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    }
-                    //else if (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //            pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //            pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012288");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
+
+                if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime) >= 5) {
+                    ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
+                    if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
+                        DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
                 }
-#endif //0
 
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
@@ -5144,82 +5097,13 @@ int main(void)
 
                     //log_info ("terminating......................... %x ", gunIndex);
                     StopGunInfoTimeoutDet(gunIndex);
+                    ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
+                    if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
+                        DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
                 }
 
                 //checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
 
-                    //if (isEvStopCharging_chademo(gunIndex) == YES ||
-                    //        isPrechargeStatus_chademo(gunIndex) <= 0) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    //log_info("************ GB lock Status = %d, status = %d ",
-                    //         isEvStopCharging_gb(gunIndex),
-                    //         isPrechargeStatus_gb(gunIndex));
-
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-
-                    //if (isEvStopCharging_gb(gunIndex) == YES ||
-                    //        isPrechargeStatus_gb(gunIndex) <= 0) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
-
-                    //if (isEvStopCharging_ccs(gunIndex) == YES &&
-                    //        (isPrechargeStatus_ccs(gunIndex) >= 53 ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 0  ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 13 ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 14)) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                }
-#endif //0
                 if (pDcChargingInfo->SystemStatus == S_ALARM) {
                     if (pDcChargingInfo->ConnectorPlugIn == NO &&
                             GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 10000000) {

+ 19 - 4
EVSE/Projects/DD360/Apps/Config.h

@@ -135,11 +135,17 @@ enum _GUN_TYPE {
     _Type_GB,
     _Type_AC,
 };
-
+enum _CCS_GUN_TYPE {
+    _TYPE_CCS_NONE  = 0,
+    _TYPE_CCS1_Natural,
+    _TYPE_CCS1_Liquid,
+    _TYPE_CCS2_Natural,
+    _TYPE_CCS2_Liquid,
+};
 enum _LCM_INDEX {
-    _LCM_INIT          = 0x00,
-    _LCM_IDLE          = 0x01,
-    _LCM_AUTHORIZING   = 0x02,
+    _LCM_INIT = 0x00,
+    _LCM_IDLE = 0x01,
+    _LCM_AUTHORIZING = 0x02,
     _LCM_AUTHORIZ_COMP = 0x03,
     _LCM_AUTHORIZ_FAIL = 0x04,
     _LCM_WAIT_FOR_PLUG = 0x05,
@@ -406,6 +412,12 @@ typedef struct StGunInfo {
     char ReservationID[32];
     uint8_t ReservationStatus;
     char UserPriceString[255];
+    float PowerConsumption;
+    time_t RecordEnergyTime;
+    char ChargeStartTime[32];
+    char ChargeStopTime[32];
+    char ChargeDuration[32];
+    uint8_t withChiller;      //是否有水冷機
 } GunInfo;
 
 typedef struct Psu_VersionInfo{
@@ -445,6 +457,7 @@ typedef struct stRecordTransactionInfo
     unsigned char IsUpload; // 0: not upload, 1: uploaded
     unsigned char res;
 }RecordTransactionInfo;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -473,6 +486,8 @@ typedef struct StDcCommonInfo {
     float Temperature;
     int Location;
     GunInfo pGunInfo[2];
+    uint8_t showNetPackage;
+    uint8_t showCanPackage;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 113 - 1
EVSE/Projects/DD360/Apps/DataBase/DataBase.c

@@ -14,7 +14,7 @@
 
 //------------------------------------------------------------------------------
 static sqlite3 *localDb;
-
+static DcCommonInfo* ShmDcCommonData = NULL;
 //------------------------------------------------------------------------------
 //===============================================
 // SQLite3 related routine
@@ -59,6 +59,11 @@ int DB_Open(void)
                             "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
                             "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
 
+    char *createPowerConsumption = "CREATE TABLE IF NOT EXISTS power_consumption( "
+                         "idx INTEGER PRIMARY KEY AUTOINCREMENT, "
+                         "connector TEXT, "
+                         "val TEXT);";
+
     if (sqlite3_open(DB_FILE, &localDb)) {
         result = FAIL;
         log_info( "Can't open database: %s", sqlite3_errmsg(localDb));
@@ -88,6 +93,14 @@ int DB_Open(void)
             log_info( "Opened local record table successfully");
         }
 
+        //DS60-120
+        if (sqlite3_exec(localDb, createPowerConsumption, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("Create power consumption record table error message: %s", errMsg);
+        } else {
+            log_info("Opened power consumption record table successfully");
+        }
+
         if (sqlite3_exec(localDb, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
             log_info( "Create reboot record table error message: %s", errMsg);
@@ -99,6 +112,7 @@ int DB_Open(void)
         sqlite3_close(localDb);
     }
 
+    ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     return result;
 }
 
@@ -222,6 +236,104 @@ int DB_Get_Operactive(uint8_t gunIndex)
     return result;
 }
 
+int DB_Insert_PowerConsumption(uint8_t gunIndex, float energy)
+{
+    uint8_t result = false;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    srand(time(NULL));
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        //log_info("Local charging record database open successfully (%f).", energy);
+        sprintf(sqlStr,"insert into power_consumption (connector, val) values (%d, %f);",
+            gunIndex,
+            energy); //DS60-120 add
+        //log_info("sqlStr= %s", sqlStr);
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("Insert power consumption error message: %s", errMsg);
+        } else {
+            log_info("Insert connector-%d config item PowerComsumption to %f", gunIndex, energy);
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int DB_Update_PowerConsumption(uint8_t gunIndex, float energy)
+{
+    uint8_t result = false;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    srand(time(NULL));
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        //log_info("Local charging record database open successfully.");
+        sprintf(sqlStr,"update power_consumption set val = %f where connector = %d; ",
+                        energy,
+                        gunIndex); //DS60-120 add
+        //log_info("sqlStr= %s", sqlStr);
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("update config error message: %s", errMsg);
+        } else {
+            //log_info("update connector-%d config item PowerComsumption to %f", gunIndex, energy);
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int DB_Get_PowerConsumption(uint8_t gunIndex)
+{
+    uint8_t result = true;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    char** rs;
+    int  rows, cols;
+
+    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gunIndex);
+    sprintf(sqlStr, "select * from power_consumption where connector=%d;", gunIndex); //DS60-120 add
+    //DEBUG_INFO("sqlStr= %s", sqlStr);
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info("Local config query database open successfully.");
+        sqlite3_get_table(localDb, sqlStr, &rs, &rows, &cols, &errMsg);
+        if (rows > 0) {
+            for (int idxRow = 1; idxRow <= rows; idxRow++) {
+                ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = atof(rs[(idxRow * cols) + 2]);
+                log_info("Query connector-%d PowerConsumption: %s", gunIndex, rs[(idxRow * cols) + 2]);
+                
+            }
+        } else {
+            log_info("Query connector-%d fail, set default value to operactive.", gunIndex);
+            result = false;
+        }
+
+        sqlite3_free_table(rs);
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+
 int DB_Reboot_Record(void)
 {
     int result = PASS;

+ 3 - 1
EVSE/Projects/DD360/Apps/DataBase/DataBase.h

@@ -10,5 +10,7 @@ int DB_Reboot_Record(void);
 //for Module_EventLog
 int CreateEventRecord(void);
 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);
 #endif /* _DATA_BASE_H_ */

+ 159 - 64
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -27,6 +27,7 @@
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
 #include "../timeout.h"
+#include "../DataBase/DataBase.h"
 #include "DoComm.h"
 
 //------------------------------------------------------------------------------
@@ -58,7 +59,9 @@ static char ReservationIdTag[2][32];
 static int LineStatusCode[2] = {0};
 static unsigned int LedIntensity = 0;
 static int TimeZoneOffset = 0;
-
+int RxLen;
+char Rxdata[1024];
+uint8_t _isplugin = 0;
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -200,6 +203,23 @@ static void setTcpStatus(uint8_t setValue)
 static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
 {
     int size = -1;
+    int i;
+    char _info[1024];
+    int len = 0;
+
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        len = 0;
+        len += sprintf(&_info[len], "Net Tx[%d]:", dataLen);
+        for (i = 0; i < dataLen; i++) {
+            if (i == 0)
+                len += sprintf(&_info[len], "[%X]\t", data[i]);
+            else
+                len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s", _info);
+    }
 
     size = send(fd, data, dataLen , 0);
     if ((size < 0) || (errno == EAGAIN)) {
@@ -211,15 +231,34 @@ static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
     return size;
 }
 
-static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
+static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen,uint8_t ishead)
 {
     int size = -1;
+    int i;
     uint8_t *pdata = (uint8_t *)data;
 
     size = recv(fd, pdata, dataLen, MSG_WAITALL);
     if ((errno == EAGAIN) || (size < 0)) {
         log_error("Receive Socket Size = %d, EAGAIN error %d:%s", size, errno, strerror(errno));
     }
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        if (ishead) {
+            RxLen = 0;
+            RxLen += sprintf(&Rxdata[RxLen], "Net Rx[%d]:", size);
+        }
+        for (i = 0; i < dataLen; i++) {
+            if (ishead && i == 0)
+                RxLen += sprintf(&Rxdata[RxLen], "[%X]\t", data[i]);
+            else
+                RxLen += sprintf(&Rxdata[RxLen], "%X ", data[i]);
+        }
+        if (!ishead) {
+            RxLen += sprintf(&Rxdata[RxLen], "\n");
+            printf("%s", Rxdata);
+            strcpy(Rxdata,"");
+        }
+    }
 
     return size;
 }
@@ -925,10 +964,6 @@ void AddDispenserReq(uint8_t* buff, MiscCommand* req)
     buff[5] = req->Value[3];
 }
 
-
-
-
-
 static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
 {
     uint8_t addr = 0;
@@ -981,19 +1016,23 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     ShmSelectGunInfo->PricesInfo[plugNum].TransactionId = ntohl(pAccountInfo->Transaction);
     ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost = transPricesUnit(ntohl(pAccountInfo->EnergyCost));
     ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee = transPricesUnit(ntohl(pAccountInfo->ParkingFee));
+    pAccountInfo->RemainAmount = ntohl(pAccountInfo->RemainAmount);
+    memcpy((char*)&ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount, (char*)&pAccountInfo->RemainAmount, sizeof(uint32_t));
 
     if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
             (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance) ||
 			(pricesInfo[plugNum].Discount != ShmSelectGunInfo->PricesInfo[plugNum].Discount) ||
 			(pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId) ||
             (pricesInfo[plugNum].EnergyCost != ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost) ||
-            (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee)) {
+            (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee) || 
+            (pricesInfo[plugNum].RemainAmount != ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount)) {
         pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
         pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
         pricesInfo[plugNum].Discount = ShmSelectGunInfo->PricesInfo[plugNum].Discount;
         pricesInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
         pricesInfo[plugNum].ParkingFee = ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee;
         pricesInfo[plugNum].EnergyCost = ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost;
+        pricesInfo[plugNum].RemainAmount = ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount;
         if (ShmSelectGunInfo->PricesInfo[plugNum].TransactionId != 0) {
 
             //ShmDcCommonData->TransactionInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
@@ -1010,6 +1049,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
             log_info("Total Cost:%.2f", pDcChargingInfo->ChargingFee);
             log_info("Parking Fee:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee);
             log_info("Energy Cost:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost);
+            log_info("Remain Amount:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount);
         }
     }
 
@@ -1462,6 +1502,22 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             log_info("Gun%d Receipt:%s", plugNum, ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo);
         }
         break;
+    case REG_READ_CHARGING_TIMESTAMP:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        if (rawDataLen <= 2) {
+            log_info("No Charging timestamp");
+            break;
+        }
+
+        strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStartTime, (char*)&pCsuResult->Data.Data[0]);
+        int timelen = strlen((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStartTime);
+        if (timelen != 0) {
+            timelen = strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStopTime, (char*)&pCsuResult->Data.Data[timelen+1]);
+        }
+        break;
+        
     case REG_POWER_CONSUMPTION_INFO:
         if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
             return COMMAND_RESULT_NG;
@@ -1486,6 +1542,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         
         
         break;
+        
     default:
         break;
     }
@@ -1530,14 +1587,14 @@ static int composeSocketData(int fd,
     }
 
     //receive result head
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head), 1)) < 0) {
         log_error("TCP socket RX head fail = %d", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result raw data
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen, 0)) < 0) {
         log_error("TCP socket RX data fail = %d", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
@@ -1679,11 +1736,29 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     return ret;
 }
 */
+
+static int readChargingTimeStamp(int fd, uint8_t id)
+{
+    int ret = PASS;
+    if ((ret = composeSocketData(fd,
+                                 id,
+                                 OP_READ_DATA,
+                                 REG_READ_CHARGING_TIMESTAMP,
+                                 0,
+                                 NULL)) == FAIL) {
+        return ret;
+    }
+
+    return ret;
+}
 static int writeWaitPlugItState(int fd, uint8_t id)
 {
     int ret = PASS;
     uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-
+    if (_isplugin != pSysInfo->WaitForPlugit) {
+        log_info("Wait for plug:%s", pSysInfo->WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin = pSysInfo->WaitForPlugit;
+    }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
     if ((ret = composeSocketData(fd,
@@ -1852,7 +1927,8 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[10] = {'\0'};
+    uint8_t dataBuf[15] = {'\0'};
+    uint32_t _consumption;
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
@@ -1912,7 +1988,10 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
             }
         }
     }
-
+#ifdef DD360
+    memcpy((char*)&_consumption, (char*)&ShmDcCommonData->pGunInfo[plugNum].PowerConsumption, sizeof(float));
+    pConnState->consumption = ntohl(_consumption);
+#endif
     ret = composeSocketData(fd,
                             id,
                             OP_WRITE_DATA,
@@ -2319,7 +2398,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         case REG_CHARGING_CAP:
             if(gMoreInfoReq[plugNum].bits.FinalCostReq)
             {
-                if (readChargingCapability(fd, gunID) == PASS) {
+                if (readChargingCapability(fd, gunID) == PASS && readChargingTimeStamp(fd, gunID) == PASS) {
 					gMoreInfoReq[plugNum].bits.FinalCostReq = false;
 					pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 					//ShmDcCommonData->TransactionInfo[plugNum].Amount = pDcChargingInfo->ChargingFee;
@@ -2399,7 +2478,11 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_READ_CABINET_SYSTEMID;
+#ifdef DD360Audi
+        curReg = REG_POWER_CONSUMPTION_INFO;
+#else
+        curReg = REG_READ_CABINET_SYSTEMID;
+#endif
             break;
         //case REG_USER_ID:
         //    writeUserID(fd, gunID, uint8_t *pUserID);
@@ -2441,53 +2524,14 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             }
             break;
 
-        //case REG_PRESENT_CHARGING_INFO:
-        //    break;
-
-
-
-        //case REG_WAIT_PLUG_IT_STATE:
-        //    if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME / 10)) {
-        //        writeWaitPlugItState(fd, gunID);
-        //        ftime(&gRegTimeUp[plugNum][curReg]);
-        //    }
-        //    isContinue = 0;
-        //    break;
-
-        //case REG_CABINET_DCM_VERSION:
-        //    break;
-
-        //case REG_CABINET_OTHER_VERSION:
-        //    break;
-
-        //case REG_TOTAL_PSU_QUANTITY:
-        //    break;
-
-        //case REG_PSU_VERSION:
-        //    break;
-
-
-        //case REG_DISPENSER_REQUEST:
-        //    break;
-
-
         case REG_READ_CABINET_SYSTEMID:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 readSystemID(fd);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
-            curReg = REG_POWER_CONSUMPTION_INFO;
-            break;
-
-        case REG_POWER_CONSUMPTION_INFO:
-            if (pSysConfig->ShowInformation || ShmDcCommonData->debugflag) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-                    readConsumptionInfo(fd);
-                    ftime(&gRegTimeUp[plugNum][curReg]);
-                }
-            }
+            curReg = REG_RESERVATION_IDTAG;
+            /*
             //check misc command from power cabinet
             if (gDoCommGblData.MiscCmd != 0) {
                 if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
@@ -2499,8 +2543,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             } else {
                 isContinue = 0;
             }
+            */
             break;
-
         case REG_RESERVATION_IDTAG:
             if (gMoreInfoReq[plugNum].bits.ReservationReq)
             {
@@ -2513,8 +2557,30 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_REMOTE_START_NO_ID;
+            curReg = REG_POWER_CONSUMPTION_INFO;
             break;
+        case REG_POWER_CONSUMPTION_INFO:
+            if (pSysConfig->ShowInformation || ShmDcCommonData->debugflag) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    readConsumptionInfo(fd);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            //check misc command from power cabinet
+            if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
+                }
+                curReg = gDoCommGblData.MiscCmd;
+            } else if (gMoreInfoReq[plugNum].Value != 0) {
+                curReg = REG_REMOTE_START_NO_ID;
+            } else {
+                isContinue = 0;
+            }
+            break;
+            
+
         case REG_REMOTE_START_NO_ID:
             if (gMoreInfoReq[plugNum].bits.RemoteStartNoID)
             {
@@ -2637,6 +2703,17 @@ 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
+                ) {
+                readChargingTimeStamp(fd, gunID);
+                ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+            }
+        }*/
+
         checkAuthorProcess(fd, plugNum);
 
         //authorization complete, write wait plug it state
@@ -2805,10 +2882,12 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
            ) {
             if (readChargePermission(fd, gunID) == 0) {
-                log_info("Stop charging by power cabinet's permission = %d, %d",
-                         plugNum,
-                         REG_CHARGING_PERMISSION);
-                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                if (pDcChargingInfo->StopChargeFlag != POWER_CABINET_STOP_CHARGING) {
+                    log_info("Stop charging by power cabinet's permission = %d, %d",
+                        plugNum,
+                        REG_CHARGING_PERMISSION);
+                    pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                }
                 //printf("%d StopChargeFlag = %d\n", plugNum, pDcChargingInfo->StopChargeFlag);
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
@@ -2823,8 +2902,15 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
 
+        // 獲得Charging時間
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) > (LOOP_RETRY_TIME*5) ||
+            DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) < 0
+            ) {
+            readChargingTimeStamp(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+        }
         break;
-
     case S_COMPLETE:
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2835,7 +2921,16 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
-
+        // 獲得Charging時間
+        /*
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
+            DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) < 0
+            ) {
+            readChargingTimeStamp(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+        }
+        */
         break;
 
     default:

+ 5 - 2
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h

@@ -16,7 +16,7 @@
 #define TFTP_PULL_CMD                           "tftp"
 #define SIGTERM_MSG                             "SegmentFault.~~~~\n"
 
-#define MAX_REGISTER_NUM                        40
+#define MAX_REGISTER_NUM                        50
 
 #define CHECK_NETWORK_FAIL_COUNT                10//10
 #define CONNECT_SERVER_FAIL_COUNT               3//5
@@ -98,6 +98,7 @@
 #define REG_READ_USER_PRICE                     0x22
 #define REG_RECEIPT_INFO                        0x23
 #define REG_POWER_CONSUMPTION_INFO              0x24
+#define REG_READ_CHARGING_TIMESTAMP             0x25
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -220,7 +221,8 @@ typedef struct StConnectorState {
     uint8_t ConnectorTemp;
     uint8_t ChillerTemp;
     uint8_t PlugIn;
-    uint8_t Reserved[2];
+    uint32_t consumption;
+    uint8_t Reserved[1];
 } ConnectorState;
 
 typedef struct StConnectorIDTable {
@@ -325,6 +327,7 @@ typedef struct StAccountInfo {
     int Transaction;
     int EnergyCost;
     int ParkingFee;
+    uint32_t RemainAmount;
     uint8_t Reserved[1];
 } AccountInfo;
 

+ 14 - 2
EVSE/Projects/DD360/Apps/ModuleEvComm/Ev_Comm.c

@@ -13,7 +13,7 @@
 
 #include "Ev_Comm.h"
 #include "Module_EvComm.h"
-
+#include "../Config.h"
 //------------------------------------------------------------------------------
 int PackageIdCmd(int cmd)
 {
@@ -22,14 +22,26 @@ int PackageIdCmd(int cmd)
 
 void SendCmdToEvboard(int cmd, uint8_t *data, uint8_t dataLen)
 {
+    DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     int fd = GetCanFd();
     struct can_frame frame;
-
+    int i;
+    int len = 0;
+    char _info[1024];
     frame.can_id = cmd;
     frame.can_dlc = dataLen;
     memcpy(frame.data, data, sizeof(frame.data));
 
     write(fd, &frame, sizeof(struct can_frame));
+
+    if (ShmDcCommonData->showCanPackage) {
+        len += sprintf(&_info[len], "CAN Dispenser => EV Tx:\t[0x%X] ", cmd);
+        for (i = 0; i < dataLen; i++) {
+            len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s",_info);
+    }
 }
 
 //------------------------------------------------------------------------------

+ 36 - 19
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -305,6 +305,9 @@ void CANReceiver(int fd)
         ChillerTemp chiilerTemp = {0};
         time_t CCS_PlugoutTimer[2] = { 0 };
         struct ChargingInfoData *pDcChargingInfo = NULL;
+        int len = 0;
+        char _info[1024];
+        int i;
 
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -332,7 +335,7 @@ void CANReceiver(int fd)
                 // 檢查是否有收到EV小板訊號
                 if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 3) &&
                     !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
-                    pDcChargingInfo->SystemStatus != S_UPDATE) {
+                    pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
 
                     ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
                     ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
@@ -364,6 +367,16 @@ void CANReceiver(int fd)
             intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
 
             recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
+            
+            if (ShmDcCommonData->showCanPackage) {
+                len = 0;
+                len += sprintf(&_info[len], "CAN Dispenser <= EV Rx:\t[0x%X] ", frame.can_id);
+                for (i = 0; i < nbytes; i++) {
+                    len += sprintf(&_info[len], "%X ", frame.data[i]);
+                }
+                len += sprintf(&_info[len], "\n");
+                printf("%s", _info);
+            }
 
             for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {                    // 假設有找到回應的 Index
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
@@ -538,8 +551,8 @@ void CANReceiver(int fd)
                 //printf("RemainChargingDuration = %d",  pDcChargingInfo->RemainChargingDuration);
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
-                    //if (ShmCHAdeMOData->ev[gunTypeIndex].EvDetection != frame.data[0])
-                    {
+                    if (ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
+                        log_info("Gun%d CHAdeMO board status = %d ", targetGun, ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus);
                         ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
 
@@ -548,8 +561,8 @@ void CANReceiver(int fd)
                     ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
                     ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
                 } else if (pDcChargingInfo->Type == _Type_GB) {
-                    //if (ShmGBTData->ev[gunTypeIndex].EvDetection != frame.data[0])
-                    {
+                    if (ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
+                        log_info("Gun%d GB Board status = %d ", targetGun, ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
                         ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
 
@@ -558,7 +571,8 @@ void CANReceiver(int fd)
                     ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
                     ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
                 } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                    if (ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus != frame.data[0] && frame.data[0] != 0xFF) {
+                        log_info("Gun%d CCS board status = %d ", targetGun, ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus);
                         ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
                 }
@@ -641,20 +655,23 @@ void CANReceiver(int fd)
 
                     pDcChargingInfo->ChillerTemp = maxChillerTemp;
                 }
+                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 > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
+                    {
+                        lastConnTemp[targetGun] = maxConnTemp;
+                        printConnTemp = YES;
+                    }
 
-                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
-                //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
-                //    printConnTemp = YES;
-                //}
-                maxConnTemp = getAvageTemp(maxConnTemp,targetGun);
-                if(maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
-                {
-                    lastConnTemp[targetGun] = maxConnTemp;
-                    printConnTemp = YES;
+                    pDcChargingInfo->ConnectorTemp = maxConnTemp;
+                } else {
+                    //log_info("Connector%d Tmep is zero:[%d,%d]", gunTypeIndex, ShmDcCommonData->ConnectorTemp[gunTypeIndex][0],
+                    //    ShmDcCommonData->ConnectorTemp[gunTypeIndex][1]);
                 }
-
-                pDcChargingInfo->ConnectorTemp = maxConnTemp;
-
                 //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
                 if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
                         (printConnTemp == YES) ||
@@ -667,7 +684,7 @@ void CANReceiver(int fd)
                     ShmDcCommonData->SystemModeChange[targetGun] = NO;
                     log_info("Conn %d max temp = %d, chiller = [%d %d], chiller2 = [%d %d]",
                              targetGun,
-                             maxConnTemp,
+                             pDcChargingInfo->ConnectorTemp,
                              chiilerTemp.Temp[0],
                              chiilerTemp.Temp[1],
                              chiilerTemp.Temp[2],

+ 5 - 3
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -1028,7 +1028,7 @@ int main(int argc, char *argv[])
                 //if (waitPsuVolwithRealyVol(gunIndex) == NO) {
                 //    continue;
                 //}
-
+                GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id); //DS60-120 add
                 // 計算 Power
                 pDcChargingInfo->PresentChargingPower =
                     ((float)((pDcChargingInfo->PresentChargingVoltage) *
@@ -1040,7 +1040,7 @@ int main(int argc, char *argv[])
                     chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
                 } else {
                     int passTime = pDcChargingInfo->PresentChargedDuration - chargingTime[gunIndex];
-                    /*
+                    
                     if (passTime > 0) {
                         float changingPow = (pDcChargingInfo->PresentChargingPower) * passTime / 3600;
                         if (pSysConfig->BillingData.isBilling) {
@@ -1048,10 +1048,12 @@ int main(int argc, char *argv[])
                         }
 
                         pDcChargingInfo->PresentChargedEnergy += changingPow;
+
+                        ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption += changingPow;
                         pDcChargingInfo->PowerConsumption += changingPow;
                         chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
                     }
-                    */
+                    
                 }
 
                 // 開始確認車端是否同意開始充電

+ 24 - 24
EVSE/Projects/DD360/Apps/ModuleInternalComm/FanBoard.c

@@ -20,6 +20,7 @@ static struct SysInfoData *pSysInfo = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct FanModuleData *ShmFanModuleData = NULL;
 static struct PsuData *ShmPsuData = NULL;
+static DcCommonInfo* ShmDcCommonData = NULL;
 
 static int Uart5Fd = 0;
 static struct timeval gFanBoardRunTimer;
@@ -149,8 +150,8 @@ static void GetFanSpeedByFunction(void)
 static void SetRtcData_Fan(void)
 {
     struct timeb csuTime;
-    struct tm *tmCSU;
-    Rtc rtc = {0};
+    struct tm* tmCSU;
+    Rtc rtc = { 0 };
 
     ftime(&csuTime);
     tmCSU = localtime(&csuTime.time);
@@ -186,30 +187,42 @@ static void SetRtcData_Fan(void)
 static void SetModelName_Fan(void)
 {
     if (Config_Model_Name(Uart5Fd, ADDR_FAN, pSysConfig->ModelName) == PASS) {
-        return;
-    } else
-        log_info("******** Set Model name FAIL = %s ************", pSysConfig->ModelName);
+        log_info("Set Model name PASS = %s ", pSysConfig->ModelName);
+    }
 }
 
 static void GetFwAndHwVersion_Fan(void)
 {
-    Ver ver = {0};
+    Ver ver = { 0 };
 
     if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // FanModuleData
-        strcpy((char *)ShmFanModuleData->version, ver.Version_FW);
+        strcpy((char*)ShmFanModuleData->version, ver.Version_FW);
         // SystemInfo
-        strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
+        strcpy((char*)pSysInfo->FanModuleFwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
     }
 
     if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // SystemInfo
-        strcpy((char *)pSysInfo->FanModuleHwRev, ver.Version_FW);
+        strcpy((char*)pSysInfo->FanModuleHwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s2 = %s ", ver.Version_HW);
     }
 }
 
+static void fanBoardSelfTest(void)
+{
+    if (ShmFanModuleData->SelfTest_Comp == YES) {
+        return;
+    }
+
+    GetFwAndHwVersion_Fan();
+    SetModelName_Fan();
+    SetRtcData_Fan();
+    sleep(1);
+    gettimeofday(&gFanBoardRunTimer, NULL);
+}
+
 static void fanBoardPorcess(void)
 {
     if (ShmFanModuleData->SelfTest_Comp == NO) {
@@ -217,8 +230,8 @@ static void fanBoardPorcess(void)
     }
 
     if (ShmFanModuleData->SelfTest_Comp == YES ||
-            strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
-            pSysInfo->FanModuleFwRev[0] != '\0') {
+        strlen((char*)pSysInfo->FanModuleFwRev) != 0 ||
+        pSysInfo->FanModuleFwRev[0] != '\0') {
         ShmFanModuleData->SelfTest_Comp = YES;
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
@@ -239,19 +252,6 @@ static void fanBoardPorcess(void)
     }
 }
 
-static void fanBoardSelfTest(void)
-{
-    if (ShmFanModuleData->SelfTest_Comp == YES) {
-        return;
-    }
-
-    GetFwAndHwVersion_Fan();
-    SetModelName_Fan();
-    SetRtcData_Fan();
-    sleep(1);
-    gettimeofday(&gFanBoardRunTimer, NULL);
-}
-
 void FanBoardTask(int uartFD)
 {
 #if defined NO_FAN_BOARD || defined DD360ComBox

+ 13 - 6
EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c

@@ -25,7 +25,7 @@ static DcCommonInfo *ShmDcCommonData = NULL;
 static struct WARNING_CODE_INFO *pSysWarning = NULL;
 static struct LedModuleData *ShmLedModuleData = NULL;
 static struct FanModuleData *ShmFanModuleData = NULL;
-
+static struct GBTData* ShmGBTData = NULL;
 static Relay outputRelay = {0};
 static Relay regRelay = {0};
 static int Uart5Fd = 0;
@@ -362,10 +362,17 @@ static void GetGfdAdc(void)
 void CheckOutputPowerOverCarReq(uint8_t index)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
-
+    ShmGBTData = (struct GBTData*)GetShmGBTData();
     float fireV = pDcChargingInfo->FireChargingVoltage;
     float carV = pDcChargingInfo->EvBatteryMaxVoltage * 10;
-
+    /*
+    log_info("PresentChargingVoltage:%f, FireChargingVoltage:%f ", pDcChargingInfo->PresentChargingVoltage * 10, pDcChargingInfo->FireChargingVoltage);
+    log_info("fireV:%f, carV:%f, _isOvpChkTimeFlag:%d", fireV, carV, _isOvpChkTimeFlag[index]);
+    log_info("EvBatterytargetVoltage:%f", pDcChargingInfo->EvBatterytargetVoltage);
+    if (pDcChargingInfo->Type == _Type_GB) {
+        log_info("GB EV Board Status:%d", ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
+    }
+    */
     if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
             (pDcChargingInfo->Type == _Type_Chademo ||
              pDcChargingInfo->Type == _Type_CCS_2 ||
@@ -1399,16 +1406,16 @@ static void fanBoardPorcess(void)
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
             //GetPsuTempForFanSpeed();
-            GetFanSpeedByFunction();
+            //GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
-
+            /*
             ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-
+            */
             //log_info("set fan = %d ", ShmFanModuleData->SetFan1Speed);
             SetFanModuleSpeed();
         }

+ 13 - 6
EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -1458,7 +1458,7 @@ void DisplayInfoConsumption(bool isShow)
         uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
-        strcpy((char*)value, "CSPT >");
+        strcpy((char*)value, "PWCT >");
         DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
         memset(value, 0x00, sizeof(value));
         data = ShmDcCommonData->pConsumption.Gun1_Consumption +
@@ -1742,8 +1742,7 @@ void ShowAnimationPrice(char* pString)
     memset(cmd, 0x00, sizeof(cmd));
     string2ByteArray((uint8_t*)pString,cmd);
     int len = strlen(pString);
-    if (len <= 0)
-        return;
+
     if (strcmp((char*)old_string, pString) != EQUAL) {
         strcpy((char*)old_string, pString);
         DisplayFeeValueToLcm(__Animation_Price, cmd, sizeof(cmd));
@@ -2064,8 +2063,11 @@ void ProcessPageInfo()
                     ChangeParkingFeeValue(ShmSelectGunInfo->PricesInfo[i].ParkingFee, _currentPage);
                     // Total Cost
                     ChangeTotalCostValue(pDcChargingInfo->ChargingFee, _currentPage);
-
-                    ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    if (pSysConfig->BillingData.isBilling) {
+                        ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    } else {
+                        ShowAnimationPrice("");
+                    }
                 }
             } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
@@ -2107,7 +2109,11 @@ void ProcessPageInfo()
                         ChangeTotalCostValue(pDcChargingInfo->ChargingFee, _currentPage);
                     }
 
-                    ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    if (pSysConfig->BillingData.isBilling) {
+                        ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    } else {
+                        ShowAnimationPrice("");
+                    }
                 }
             } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
@@ -2285,6 +2291,7 @@ void ChangeDisplayMoneyInfo()
         ChangeDisplay2Value(__money_rate_map, _disappear);
         ChangeDisplay2Value(__money_by_rate, _disappear);
         ChangeDisplay2Value(__money_rate, _disappear);
+        ShowAnimationPrice("");
     }
 }
 

+ 6 - 2
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -351,11 +351,13 @@ static void checkChillerStatus(Gpio_out *gpio)
     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)) {
         chillerCount++;
+        ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
     }
 
     if (chillerCount == 0) {
@@ -363,7 +365,9 @@ static void checkChillerStatus(Gpio_out *gpio)
         return;
     }
 
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        if (!ShmDcCommonData->pGunInfo[gunIndex].withChiller)
+            continue;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
@@ -413,7 +417,7 @@ static void checkChillerStatus(Gpio_out *gpio)
     }
 
     uint8_t _chillerNeedOn = NO;
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++)
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
         if(pChillerInfo->ChillerSwitch == YES)

+ 50 - 1
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -1229,6 +1229,35 @@ void writeChillerStatus(char *v1)
     } else
         printf("Please open Debug mode\n");
 }
+
+void showNetworkPage(char* v1)
+{
+    ShmDcCommonData->showNetPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showNetPackage)
+        printf("Show Network Package on\n");
+    else
+        printf("Show Network Package off\n");
+}
+
+void showCANBUSPage(char* v1)
+{
+    ShmDcCommonData->showCanPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showCanPackage)
+        printf("Show CAN Bus Package on\n");
+    else
+        printf("Show CAN Bus Package off\n");
+}
+void setSystemTime(char* date,char* time)
+{
+    char _setTime[30];
+    char cmdBuf[50];
+    sprintf(_setTime, "%s %s", date, time);
+    printf("Set Timer:%s", _setTime);
+    sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
+    system((char*)cmdBuf);
+    system("hwclock -w -u");
+    system("hwclock -s");
+}
 static void writeGunAndChillerTemp(void)
 {
     uint8_t _GunIndex = 0;
@@ -1304,7 +1333,16 @@ static void writeGunAndChillerTemp(void)
         usleep(sleepTime);
     }//while
 }
+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)
 {
     uint8_t _GunIndex = 0;
@@ -1329,7 +1367,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"
+                     "       chiller                           : set chiller on/off\r\n"
+                     "       netdump                           : show network package\r\n"
+                     "       candump                           : show can package\r\n"
+                     "       powerconsumption                  : Show Power Consumption\n"
                      "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
@@ -1502,6 +1543,14 @@ int main(void)
             writeOTPTemp();
         } 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) { //印出網路封包
+            showCANBUSPage(newString[1]);
+        } else if (strcmp(newString[0], "time") == 0) {  //設定系統時間
+            setSystemTime(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "powerconsumption") == 0) { // Power Consumption
+            ShowPowerConsumption(newString[1]);
         } else {
             printf("%s\n", usageMsg);
         }

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

@@ -65,6 +65,7 @@ typedef struct StPricesInfo {
     int TransactionId;
     float EnergyCost;
     float ParkingFee;
+    float RemainAmount;
 } PricesInfo;
 
 //typedef struct StOperativeInfo {

+ 15 - 7
EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c

@@ -930,16 +930,15 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
         }
         break;
 
+    case 'V': // Liquid CCS1 combo
+    case 'F': // Liquid CCS2 combo
     case 'T': // Rema CCS1
     case 'D': // Rema CCS2
     case 'U': // CCS1 combo
     case 'E': // CCS2 combo
-    case 'V': // Liquid CCS1 combo
-    case 'F': // Liquid CCS2 combo
     case 'M': // 80A CCS2
     case 'N': // 80A CCS1
-    case 'P': // Phoenix CCS2 500A 水冷
-    case 'R': // Phoenix CCS1 500A 水冷
+    case 'P': // 急電弓
         if (CCS_QUANTITY > gGunIndexInfo.CcsIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[gGunIndexInfo.CcsIndex];
 
@@ -959,16 +958,25 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
                 gGunIndexInfo.CcsIndex++;
                 gGunIndexInfo.DcGunIndex++;
             }
-            if(typeValue == 'P')
-            {
+            if(typeValue == 'P') {
                 pDcChargingInfo->PantographFlag = YES;
-            }
+            } else if (typeValue == 'V') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Liquid;
+            } else if (typeValue == 'F') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Liquid;
+            } else if (typeValue == 'T' || typeValue == 'U' || typeValue == 'N') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Natural;
+            } else if (typeValue == 'D' || typeValue == 'E' || typeValue == 'M') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Natural;
+            } else
+                pDcChargingInfo->CCSGunType = _TYPE_CCS_NONE;
         } else {
             result = false;
         }
         break;
 
     case 'G':  // GBT DC
+    case 'B': // GBT YG PT100
         if (GB_QUANTITY > gGunIndexInfo.GbIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex];
 

二進制
EVSE/Projects/DD360/Images/ramdisk.gz


二進制
EVSE/Projects/DD360/output/DoComm


二進制
EVSE/Projects/DD360/output/FactoryConfig


二進制
EVSE/Projects/DD360/output/Module_ChkSysTask


二進制
EVSE/Projects/DD360/output/Module_DoComm


二進制
EVSE/Projects/DD360/output/Module_EvComm


二進制
EVSE/Projects/DD360/output/Module_EventLogging


二進制
EVSE/Projects/DD360/output/Module_InternalComm


二進制
EVSE/Projects/DD360/output/Module_LcmControl


二進制
EVSE/Projects/DD360/output/Module_PrimaryComm


二進制
EVSE/Projects/DD360/output/Module_UpdateFW


二進制
EVSE/Projects/DD360/output/ReadCmdline


二進制
EVSE/Projects/DD360/output/main


+ 111 - 227
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -84,7 +84,7 @@ uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
 char *fwVersion = "V1.21.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "v1.21.0";
+char* DebugVersion = "v1.21.5";
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -404,52 +404,105 @@ static void checkGunOTPState(uint8_t gunIndex)
     //log_info("OTP:%d OTPR%d",pSysInfo->OTPTemp,pSysInfo->OTPTempR);
     //水冷機溫度檢測
     if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
-        if (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP) {
-            if (pDcChargingInfo->ChillerTemp >= pSysInfo->OTPTemp ) {
-                if (((gunIndex == 0) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                         ||
-                    ((gunIndex == 1) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-                   ) {
-                    RecordAlarmCode(gunIndex, "012323");
+        if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
+            // 單水冷機
+            // Chiller OTP
+            if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
-                }
-                else
-                {
+                    RecordAlarmCode(gunIndex, "012323");
+                } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
                 }
-            } else if (pDcChargingInfo->ChillerTemp != 0 &&
-                       pDcChargingInfo->ChillerTemp < pSysInfo->OTPTempR) {
-                //ResetChargerAlarmCode(gunIndex, "012323");
-                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
-        } else {
-            // 沒接上 Sensor or 異常
-            //RecordAlarmCode(gunIndex, "011038");
-            //ResetChargerAlarmCode(gunIndex, "012323");
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
-            if (((gunIndex == 0) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                     ||
-                ((gunIndex == 1) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-               ) {
+            // Chiller Tube OTP
+            if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
-            }
-            else
-            {
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                    RecordAlarmCode(gunIndex, "012332");
+                } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[3] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                }
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
+        } else {
+            // 雙水冷機
+            if (gunIndex == LEFT_GUN_NUM) {
+                if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+                    } else if (ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            } else {
+                if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+
+                    } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            }
         }
 
-        if(pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES)
-        {
+        if (pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES) {
             RecordAlarmCode(gunIndex, "011037");
         }
     }
@@ -1554,11 +1607,7 @@ uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
     uint8_t result = 0x00;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-        result = ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;
-    }
-
-    return result;
+    return ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;;
 }
 
 bool isEvStopCharging_ccs(uint8_t gunIndex)
@@ -1658,7 +1707,7 @@ void _DetectPlugInTimeout(void)
 	//pSysInfo->SystemPage = _LCM_COMPLETE;
 	setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
 #elif DD360 || DD360Combox
- 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
+ 	setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
 #endif
     systemPageRestoreInit();
 }
@@ -4128,9 +4177,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
     case _Type_Chademo:
         // 檢查樁端的 GFD 結果
         if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_chademo(gunIndex) > 6 &&
-                isPrechargeStatus_chademo(gunIndex) < 8
-           ) {
+                isPrechargeStatus_chademo(gunIndex) >= 6) {
             // 當前操作的槍號,進入 Charging
             setChargerMode(gunIndex, MODE_CHARGING);
         }
@@ -4177,8 +4224,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
     case _Type_GB:
         // 檢查樁端的 GFD 結果
         //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
-        if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_gb(gunIndex) > 6) {
+        if (sysStatus == S_PREPARING_FOR_EVSE && isPrechargeStatus_gb(gunIndex) >= 6) {
             setChargerMode(gunIndex, MODE_CHARGING);
         }
 
@@ -4472,6 +4518,9 @@ int main(void)
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
 
             pDcChargingInfo->IsAvailable = DB_Get_Operactive(_index);
+            if (!DB_Get_PowerConsumption(_index)) {
+                DB_Insert_PowerConsumption(_index, 0);
+            }
         }
         DB_Reboot_Record();
     }
@@ -4502,6 +4551,9 @@ int main(void)
 
     pSysInfo->OTPTemp = GUN_OTP_VALUE;
     pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
+
+    time_t ShowEVStatusTimer[2] = { 0 };
+
     for (;;) {
 
         CheckOcppStatus();
@@ -4600,9 +4652,6 @@ int main(void)
                 CheckSmartChargeProfile(gunIndex);
             }
 
-            //log_info("index = %d, ErrorCode = %s",
-            //         gunIndex,
-            //         ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode);
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
             case S_RESERVATION:
@@ -4625,6 +4674,7 @@ int main(void)
                     //Jerry add
                     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
                     memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
+                    DB_Get_PowerConsumption(gunIndex);
                     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
                     destroySelGun(gunIndex);
                     ResetDetAlarmStatus(gunIndex); //recovery OVP status code
@@ -4882,7 +4932,7 @@ int main(void)
 
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 5000000) {
+                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 1000000) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 
@@ -4953,52 +5003,7 @@ int main(void)
                 }
 
                 checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gunIndex) > 5 &&
-                            isPrechargeStatus_chademo(gunIndex) < 8) {
-                        // 當前操作的槍號,進入 Charging
-                        setChargerMode(gunIndex, MODE_CHARGING);
-                    }
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    // 檢查樁端的 GFD 結果
-                    //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
-                    if (isPrechargeStatus_gb(gunIndex) > 9) {
-                        setChargerMode(gunIndex, MODE_CHARGING);
-                    }
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    // 檢查樁端的 GFD 結果
-                    if ((pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
-                            pDcChargingInfo->GroundFaultStatus == GFD_WARNING)) {
-                        setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP0);
-                    }
 
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
-                }
-#endif //0
                 checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
 
                 // LCM => Pre-charging
@@ -5025,64 +5030,12 @@ int main(void)
                 pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
 
                 checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    }
-                    //else if (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //            pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //            pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012289");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    }
-                    //else if (isPrechargeStatus_gb(gunIndex) == 10 &&
-                    //           (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //             pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //            (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //             pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL))
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012290");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    }
-                    //else if (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //            pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //            pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012288");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
+
+                if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime) >= 5) {
+                    ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
+                    if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
+                        DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
                 }
-#endif //0
 
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
@@ -5144,82 +5097,13 @@ int main(void)
 
                     //log_info ("terminating......................... %x ", gunIndex);
                     StopGunInfoTimeoutDet(gunIndex);
+                    ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
+                    if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
+                        DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
                 }
 
                 //checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
 
-                    //if (isEvStopCharging_chademo(gunIndex) == YES ||
-                    //        isPrechargeStatus_chademo(gunIndex) <= 0) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    //log_info("************ GB lock Status = %d, status = %d ",
-                    //         isEvStopCharging_gb(gunIndex),
-                    //         isPrechargeStatus_gb(gunIndex));
-
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-
-                    //if (isEvStopCharging_gb(gunIndex) == YES ||
-                    //        isPrechargeStatus_gb(gunIndex) <= 0) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
-
-                    //if (isEvStopCharging_ccs(gunIndex) == YES &&
-                    //        (isPrechargeStatus_ccs(gunIndex) >= 53 ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 0  ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 13 ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 14)) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                }
-#endif //0
                 if (pDcChargingInfo->SystemStatus == S_ALARM) {
                     if (pDcChargingInfo->ConnectorPlugIn == NO &&
                             GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 10000000) {

+ 19 - 4
EVSE/Projects/DD360Audi/Apps/Config.h

@@ -135,11 +135,17 @@ enum _GUN_TYPE {
     _Type_GB,
     _Type_AC,
 };
-
+enum _CCS_GUN_TYPE {
+    _TYPE_CCS_NONE  = 0,
+    _TYPE_CCS1_Natural,
+    _TYPE_CCS1_Liquid,
+    _TYPE_CCS2_Natural,
+    _TYPE_CCS2_Liquid,
+};
 enum _LCM_INDEX {
-    _LCM_INIT          = 0x00,
-    _LCM_IDLE          = 0x01,
-    _LCM_AUTHORIZING   = 0x02,
+    _LCM_INIT = 0x00,
+    _LCM_IDLE = 0x01,
+    _LCM_AUTHORIZING = 0x02,
     _LCM_AUTHORIZ_COMP = 0x03,
     _LCM_AUTHORIZ_FAIL = 0x04,
     _LCM_WAIT_FOR_PLUG = 0x05,
@@ -406,6 +412,12 @@ typedef struct StGunInfo {
     char ReservationID[32];
     uint8_t ReservationStatus;
     char UserPriceString[255];
+    float PowerConsumption;
+    time_t RecordEnergyTime;
+    char ChargeStartTime[32];
+    char ChargeStopTime[32];
+    char ChargeDuration[32];
+    uint8_t withChiller;      //是否有水冷機
 } GunInfo;
 
 typedef struct Psu_VersionInfo{
@@ -445,6 +457,7 @@ typedef struct stRecordTransactionInfo
     unsigned char IsUpload; // 0: not upload, 1: uploaded
     unsigned char res;
 }RecordTransactionInfo;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -473,6 +486,8 @@ typedef struct StDcCommonInfo {
     float Temperature;
     int Location;
     GunInfo pGunInfo[2];
+    uint8_t showNetPackage;
+    uint8_t showCanPackage;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 113 - 1
EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c

@@ -14,7 +14,7 @@
 
 //------------------------------------------------------------------------------
 static sqlite3 *localDb;
-
+static DcCommonInfo* ShmDcCommonData = NULL;
 //------------------------------------------------------------------------------
 //===============================================
 // SQLite3 related routine
@@ -59,6 +59,11 @@ int DB_Open(void)
                             "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
                             "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
 
+    char *createPowerConsumption = "CREATE TABLE IF NOT EXISTS power_consumption( "
+                         "idx INTEGER PRIMARY KEY AUTOINCREMENT, "
+                         "connector TEXT, "
+                         "val TEXT);";
+
     if (sqlite3_open(DB_FILE, &localDb)) {
         result = FAIL;
         log_info( "Can't open database: %s", sqlite3_errmsg(localDb));
@@ -88,6 +93,14 @@ int DB_Open(void)
             log_info( "Opened local record table successfully");
         }
 
+        //DS60-120
+        if (sqlite3_exec(localDb, createPowerConsumption, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("Create power consumption record table error message: %s", errMsg);
+        } else {
+            log_info("Opened power consumption record table successfully");
+        }
+
         if (sqlite3_exec(localDb, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
             log_info( "Create reboot record table error message: %s", errMsg);
@@ -99,6 +112,7 @@ int DB_Open(void)
         sqlite3_close(localDb);
     }
 
+    ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     return result;
 }
 
@@ -222,6 +236,104 @@ int DB_Get_Operactive(uint8_t gunIndex)
     return result;
 }
 
+int DB_Insert_PowerConsumption(uint8_t gunIndex, float energy)
+{
+    uint8_t result = false;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    srand(time(NULL));
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        //log_info("Local charging record database open successfully (%f).", energy);
+        sprintf(sqlStr,"insert into power_consumption (connector, val) values (%d, %f);",
+            gunIndex,
+            energy); //DS60-120 add
+        //log_info("sqlStr= %s", sqlStr);
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("Insert power consumption error message: %s", errMsg);
+        } else {
+            log_info("Insert connector-%d config item PowerComsumption to %f", gunIndex, energy);
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int DB_Update_PowerConsumption(uint8_t gunIndex, float energy)
+{
+    uint8_t result = false;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    srand(time(NULL));
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        //log_info("Local charging record database open successfully.");
+        sprintf(sqlStr,"update power_consumption set val = %f where connector = %d; ",
+                        energy,
+                        gunIndex); //DS60-120 add
+        //log_info("sqlStr= %s", sqlStr);
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("update config error message: %s", errMsg);
+        } else {
+            //log_info("update connector-%d config item PowerComsumption to %f", gunIndex, energy);
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int DB_Get_PowerConsumption(uint8_t gunIndex)
+{
+    uint8_t result = true;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    char** rs;
+    int  rows, cols;
+
+    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gunIndex);
+    sprintf(sqlStr, "select * from power_consumption where connector=%d;", gunIndex); //DS60-120 add
+    //DEBUG_INFO("sqlStr= %s", sqlStr);
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info("Local config query database open successfully.");
+        sqlite3_get_table(localDb, sqlStr, &rs, &rows, &cols, &errMsg);
+        if (rows > 0) {
+            for (int idxRow = 1; idxRow <= rows; idxRow++) {
+                ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = atof(rs[(idxRow * cols) + 2]);
+                log_info("Query connector-%d PowerConsumption: %s", gunIndex, rs[(idxRow * cols) + 2]);
+                
+            }
+        } else {
+            log_info("Query connector-%d fail, set default value to operactive.", gunIndex);
+            result = false;
+        }
+
+        sqlite3_free_table(rs);
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+
 int DB_Reboot_Record(void)
 {
     int result = PASS;

+ 3 - 1
EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.h

@@ -10,5 +10,7 @@ int DB_Reboot_Record(void);
 //for Module_EventLog
 int CreateEventRecord(void);
 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);
 #endif /* _DATA_BASE_H_ */

+ 159 - 64
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -27,6 +27,7 @@
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
 #include "../timeout.h"
+#include "../DataBase/DataBase.h"
 #include "DoComm.h"
 
 //------------------------------------------------------------------------------
@@ -58,7 +59,9 @@ static char ReservationIdTag[2][32];
 static int LineStatusCode[2] = {0};
 static unsigned int LedIntensity = 0;
 static int TimeZoneOffset = 0;
-
+int RxLen;
+char Rxdata[1024];
+uint8_t _isplugin = 0;
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -200,6 +203,23 @@ static void setTcpStatus(uint8_t setValue)
 static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
 {
     int size = -1;
+    int i;
+    char _info[1024];
+    int len = 0;
+
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        len = 0;
+        len += sprintf(&_info[len], "Net Tx[%d]:", dataLen);
+        for (i = 0; i < dataLen; i++) {
+            if (i == 0)
+                len += sprintf(&_info[len], "[%X]\t", data[i]);
+            else
+                len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s", _info);
+    }
 
     size = send(fd, data, dataLen , 0);
     if ((size < 0) || (errno == EAGAIN)) {
@@ -211,15 +231,34 @@ static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
     return size;
 }
 
-static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
+static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen,uint8_t ishead)
 {
     int size = -1;
+    int i;
     uint8_t *pdata = (uint8_t *)data;
 
     size = recv(fd, pdata, dataLen, MSG_WAITALL);
     if ((errno == EAGAIN) || (size < 0)) {
         log_error("Receive Socket Size = %d, EAGAIN error %d:%s", size, errno, strerror(errno));
     }
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        if (ishead) {
+            RxLen = 0;
+            RxLen += sprintf(&Rxdata[RxLen], "Net Rx[%d]:", size);
+        }
+        for (i = 0; i < dataLen; i++) {
+            if (ishead && i == 0)
+                RxLen += sprintf(&Rxdata[RxLen], "[%X]\t", data[i]);
+            else
+                RxLen += sprintf(&Rxdata[RxLen], "%X ", data[i]);
+        }
+        if (!ishead) {
+            RxLen += sprintf(&Rxdata[RxLen], "\n");
+            printf("%s", Rxdata);
+            strcpy(Rxdata,"");
+        }
+    }
 
     return size;
 }
@@ -925,10 +964,6 @@ void AddDispenserReq(uint8_t* buff, MiscCommand* req)
     buff[5] = req->Value[3];
 }
 
-
-
-
-
 static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
 {
     uint8_t addr = 0;
@@ -981,19 +1016,23 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     ShmSelectGunInfo->PricesInfo[plugNum].TransactionId = ntohl(pAccountInfo->Transaction);
     ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost = transPricesUnit(ntohl(pAccountInfo->EnergyCost));
     ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee = transPricesUnit(ntohl(pAccountInfo->ParkingFee));
+    pAccountInfo->RemainAmount = ntohl(pAccountInfo->RemainAmount);
+    memcpy((char*)&ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount, (char*)&pAccountInfo->RemainAmount, sizeof(uint32_t));
 
     if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
             (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance) ||
 			(pricesInfo[plugNum].Discount != ShmSelectGunInfo->PricesInfo[plugNum].Discount) ||
 			(pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId) ||
             (pricesInfo[plugNum].EnergyCost != ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost) ||
-            (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee)) {
+            (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee) || 
+            (pricesInfo[plugNum].RemainAmount != ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount)) {
         pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
         pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
         pricesInfo[plugNum].Discount = ShmSelectGunInfo->PricesInfo[plugNum].Discount;
         pricesInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
         pricesInfo[plugNum].ParkingFee = ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee;
         pricesInfo[plugNum].EnergyCost = ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost;
+        pricesInfo[plugNum].RemainAmount = ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount;
         if (ShmSelectGunInfo->PricesInfo[plugNum].TransactionId != 0) {
 
             //ShmDcCommonData->TransactionInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
@@ -1010,6 +1049,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
             log_info("Total Cost:%.2f", pDcChargingInfo->ChargingFee);
             log_info("Parking Fee:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee);
             log_info("Energy Cost:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost);
+            log_info("Remain Amount:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount);
         }
     }
 
@@ -1462,6 +1502,22 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             log_info("Gun%d Receipt:%s", plugNum, ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo);
         }
         break;
+    case REG_READ_CHARGING_TIMESTAMP:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        if (rawDataLen <= 2) {
+            log_info("No Charging timestamp");
+            break;
+        }
+
+        strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStartTime, (char*)&pCsuResult->Data.Data[0]);
+        int timelen = strlen((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStartTime);
+        if (timelen != 0) {
+            timelen = strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStopTime, (char*)&pCsuResult->Data.Data[timelen+1]);
+        }
+        break;
+        
     case REG_POWER_CONSUMPTION_INFO:
         if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
             return COMMAND_RESULT_NG;
@@ -1486,6 +1542,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         
         
         break;
+        
     default:
         break;
     }
@@ -1530,14 +1587,14 @@ static int composeSocketData(int fd,
     }
 
     //receive result head
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head), 1)) < 0) {
         log_error("TCP socket RX head fail = %d", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result raw data
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen, 0)) < 0) {
         log_error("TCP socket RX data fail = %d", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
@@ -1679,11 +1736,29 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     return ret;
 }
 */
+
+static int readChargingTimeStamp(int fd, uint8_t id)
+{
+    int ret = PASS;
+    if ((ret = composeSocketData(fd,
+                                 id,
+                                 OP_READ_DATA,
+                                 REG_READ_CHARGING_TIMESTAMP,
+                                 0,
+                                 NULL)) == FAIL) {
+        return ret;
+    }
+
+    return ret;
+}
 static int writeWaitPlugItState(int fd, uint8_t id)
 {
     int ret = PASS;
     uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-
+    if (_isplugin != pSysInfo->WaitForPlugit) {
+        log_info("Wait for plug:%s", pSysInfo->WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin = pSysInfo->WaitForPlugit;
+    }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
     if ((ret = composeSocketData(fd,
@@ -1852,7 +1927,8 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[10] = {'\0'};
+    uint8_t dataBuf[15] = {'\0'};
+    uint32_t _consumption;
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
@@ -1912,7 +1988,10 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
             }
         }
     }
-
+#ifdef DD360
+    memcpy((char*)&_consumption, (char*)&ShmDcCommonData->pGunInfo[plugNum].PowerConsumption, sizeof(float));
+    pConnState->consumption = ntohl(_consumption);
+#endif
     ret = composeSocketData(fd,
                             id,
                             OP_WRITE_DATA,
@@ -2319,7 +2398,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         case REG_CHARGING_CAP:
             if(gMoreInfoReq[plugNum].bits.FinalCostReq)
             {
-                if (readChargingCapability(fd, gunID) == PASS) {
+                if (readChargingCapability(fd, gunID) == PASS && readChargingTimeStamp(fd, gunID) == PASS) {
 					gMoreInfoReq[plugNum].bits.FinalCostReq = false;
 					pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 					//ShmDcCommonData->TransactionInfo[plugNum].Amount = pDcChargingInfo->ChargingFee;
@@ -2399,7 +2478,11 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_READ_CABINET_SYSTEMID;
+#ifdef DD360Audi
+        curReg = REG_POWER_CONSUMPTION_INFO;
+#else
+        curReg = REG_READ_CABINET_SYSTEMID;
+#endif
             break;
         //case REG_USER_ID:
         //    writeUserID(fd, gunID, uint8_t *pUserID);
@@ -2441,53 +2524,14 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             }
             break;
 
-        //case REG_PRESENT_CHARGING_INFO:
-        //    break;
-
-
-
-        //case REG_WAIT_PLUG_IT_STATE:
-        //    if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME / 10)) {
-        //        writeWaitPlugItState(fd, gunID);
-        //        ftime(&gRegTimeUp[plugNum][curReg]);
-        //    }
-        //    isContinue = 0;
-        //    break;
-
-        //case REG_CABINET_DCM_VERSION:
-        //    break;
-
-        //case REG_CABINET_OTHER_VERSION:
-        //    break;
-
-        //case REG_TOTAL_PSU_QUANTITY:
-        //    break;
-
-        //case REG_PSU_VERSION:
-        //    break;
-
-
-        //case REG_DISPENSER_REQUEST:
-        //    break;
-
-
         case REG_READ_CABINET_SYSTEMID:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 readSystemID(fd);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
-            curReg = REG_POWER_CONSUMPTION_INFO;
-            break;
-
-        case REG_POWER_CONSUMPTION_INFO:
-            if (pSysConfig->ShowInformation || ShmDcCommonData->debugflag) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-                    readConsumptionInfo(fd);
-                    ftime(&gRegTimeUp[plugNum][curReg]);
-                }
-            }
+            curReg = REG_RESERVATION_IDTAG;
+            /*
             //check misc command from power cabinet
             if (gDoCommGblData.MiscCmd != 0) {
                 if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
@@ -2499,8 +2543,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             } else {
                 isContinue = 0;
             }
+            */
             break;
-
         case REG_RESERVATION_IDTAG:
             if (gMoreInfoReq[plugNum].bits.ReservationReq)
             {
@@ -2513,8 +2557,30 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_REMOTE_START_NO_ID;
+            curReg = REG_POWER_CONSUMPTION_INFO;
             break;
+        case REG_POWER_CONSUMPTION_INFO:
+            if (pSysConfig->ShowInformation || ShmDcCommonData->debugflag) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    readConsumptionInfo(fd);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            //check misc command from power cabinet
+            if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
+                }
+                curReg = gDoCommGblData.MiscCmd;
+            } else if (gMoreInfoReq[plugNum].Value != 0) {
+                curReg = REG_REMOTE_START_NO_ID;
+            } else {
+                isContinue = 0;
+            }
+            break;
+            
+
         case REG_REMOTE_START_NO_ID:
             if (gMoreInfoReq[plugNum].bits.RemoteStartNoID)
             {
@@ -2637,6 +2703,17 @@ 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
+                ) {
+                readChargingTimeStamp(fd, gunID);
+                ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+            }
+        }*/
+
         checkAuthorProcess(fd, plugNum);
 
         //authorization complete, write wait plug it state
@@ -2805,10 +2882,12 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
            ) {
             if (readChargePermission(fd, gunID) == 0) {
-                log_info("Stop charging by power cabinet's permission = %d, %d",
-                         plugNum,
-                         REG_CHARGING_PERMISSION);
-                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                if (pDcChargingInfo->StopChargeFlag != POWER_CABINET_STOP_CHARGING) {
+                    log_info("Stop charging by power cabinet's permission = %d, %d",
+                        plugNum,
+                        REG_CHARGING_PERMISSION);
+                    pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                }
                 //printf("%d StopChargeFlag = %d\n", plugNum, pDcChargingInfo->StopChargeFlag);
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
@@ -2823,8 +2902,15 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
 
+        // 獲得Charging時間
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) > (LOOP_RETRY_TIME*5) ||
+            DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) < 0
+            ) {
+            readChargingTimeStamp(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+        }
         break;
-
     case S_COMPLETE:
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2835,7 +2921,16 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
-
+        // 獲得Charging時間
+        /*
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
+            DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) < 0
+            ) {
+            readChargingTimeStamp(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+        }
+        */
         break;
 
     default:

+ 5 - 2
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h

@@ -16,7 +16,7 @@
 #define TFTP_PULL_CMD                           "tftp"
 #define SIGTERM_MSG                             "SegmentFault.~~~~\n"
 
-#define MAX_REGISTER_NUM                        40
+#define MAX_REGISTER_NUM                        50
 
 #define CHECK_NETWORK_FAIL_COUNT                10//10
 #define CONNECT_SERVER_FAIL_COUNT               3//5
@@ -98,6 +98,7 @@
 #define REG_READ_USER_PRICE                     0x22
 #define REG_RECEIPT_INFO                        0x23
 #define REG_POWER_CONSUMPTION_INFO              0x24
+#define REG_READ_CHARGING_TIMESTAMP             0x25
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -220,7 +221,8 @@ typedef struct StConnectorState {
     uint8_t ConnectorTemp;
     uint8_t ChillerTemp;
     uint8_t PlugIn;
-    uint8_t Reserved[2];
+    uint32_t consumption;
+    uint8_t Reserved[1];
 } ConnectorState;
 
 typedef struct StConnectorIDTable {
@@ -325,6 +327,7 @@ typedef struct StAccountInfo {
     int Transaction;
     int EnergyCost;
     int ParkingFee;
+    uint32_t RemainAmount;
     uint8_t Reserved[1];
 } AccountInfo;
 

+ 14 - 2
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Ev_Comm.c

@@ -13,7 +13,7 @@
 
 #include "Ev_Comm.h"
 #include "Module_EvComm.h"
-
+#include "../Config.h"
 //------------------------------------------------------------------------------
 int PackageIdCmd(int cmd)
 {
@@ -22,14 +22,26 @@ int PackageIdCmd(int cmd)
 
 void SendCmdToEvboard(int cmd, uint8_t *data, uint8_t dataLen)
 {
+    DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     int fd = GetCanFd();
     struct can_frame frame;
-
+    int i;
+    int len = 0;
+    char _info[1024];
     frame.can_id = cmd;
     frame.can_dlc = dataLen;
     memcpy(frame.data, data, sizeof(frame.data));
 
     write(fd, &frame, sizeof(struct can_frame));
+
+    if (ShmDcCommonData->showCanPackage) {
+        len += sprintf(&_info[len], "CAN Dispenser => EV Tx:\t[0x%X] ", cmd);
+        for (i = 0; i < dataLen; i++) {
+            len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s",_info);
+    }
 }
 
 //------------------------------------------------------------------------------

+ 36 - 19
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -305,6 +305,9 @@ void CANReceiver(int fd)
         ChillerTemp chiilerTemp = {0};
         time_t CCS_PlugoutTimer[2] = { 0 };
         struct ChargingInfoData *pDcChargingInfo = NULL;
+        int len = 0;
+        char _info[1024];
+        int i;
 
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -332,7 +335,7 @@ void CANReceiver(int fd)
                 // 檢查是否有收到EV小板訊號
                 if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 3) &&
                     !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
-                    pDcChargingInfo->SystemStatus != S_UPDATE) {
+                    pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
 
                     ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
                     ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
@@ -364,6 +367,16 @@ void CANReceiver(int fd)
             intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
 
             recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
+            
+            if (ShmDcCommonData->showCanPackage) {
+                len = 0;
+                len += sprintf(&_info[len], "CAN Dispenser <= EV Rx:\t[0x%X] ", frame.can_id);
+                for (i = 0; i < nbytes; i++) {
+                    len += sprintf(&_info[len], "%X ", frame.data[i]);
+                }
+                len += sprintf(&_info[len], "\n");
+                printf("%s", _info);
+            }
 
             for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {                    // 假設有找到回應的 Index
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
@@ -538,8 +551,8 @@ void CANReceiver(int fd)
                 //printf("RemainChargingDuration = %d",  pDcChargingInfo->RemainChargingDuration);
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
-                    //if (ShmCHAdeMOData->ev[gunTypeIndex].EvDetection != frame.data[0])
-                    {
+                    if (ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
+                        log_info("Gun%d CHAdeMO board status = %d ", targetGun, ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus);
                         ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
 
@@ -548,8 +561,8 @@ void CANReceiver(int fd)
                     ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
                     ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
                 } else if (pDcChargingInfo->Type == _Type_GB) {
-                    //if (ShmGBTData->ev[gunTypeIndex].EvDetection != frame.data[0])
-                    {
+                    if (ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
+                        log_info("Gun%d GB Board status = %d ", targetGun, ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
                         ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
 
@@ -558,7 +571,8 @@ void CANReceiver(int fd)
                     ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
                     ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
                 } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                    if (ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus != frame.data[0] && frame.data[0] != 0xFF) {
+                        log_info("Gun%d CCS board status = %d ", targetGun, ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus);
                         ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
                 }
@@ -641,20 +655,23 @@ void CANReceiver(int fd)
 
                     pDcChargingInfo->ChillerTemp = maxChillerTemp;
                 }
+                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 > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
+                    {
+                        lastConnTemp[targetGun] = maxConnTemp;
+                        printConnTemp = YES;
+                    }
 
-                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
-                //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
-                //    printConnTemp = YES;
-                //}
-                maxConnTemp = getAvageTemp(maxConnTemp,targetGun);
-                if(maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
-                {
-                    lastConnTemp[targetGun] = maxConnTemp;
-                    printConnTemp = YES;
+                    pDcChargingInfo->ConnectorTemp = maxConnTemp;
+                } else {
+                    //log_info("Connector%d Tmep is zero:[%d,%d]", gunTypeIndex, ShmDcCommonData->ConnectorTemp[gunTypeIndex][0],
+                    //    ShmDcCommonData->ConnectorTemp[gunTypeIndex][1]);
                 }
-
-                pDcChargingInfo->ConnectorTemp = maxConnTemp;
-
                 //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
                 if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
                         (printConnTemp == YES) ||
@@ -667,7 +684,7 @@ void CANReceiver(int fd)
                     ShmDcCommonData->SystemModeChange[targetGun] = NO;
                     log_info("Conn %d max temp = %d, chiller = [%d %d], chiller2 = [%d %d]",
                              targetGun,
-                             maxConnTemp,
+                             pDcChargingInfo->ConnectorTemp,
                              chiilerTemp.Temp[0],
                              chiilerTemp.Temp[1],
                              chiilerTemp.Temp[2],

+ 5 - 3
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -1028,7 +1028,7 @@ int main(int argc, char *argv[])
                 //if (waitPsuVolwithRealyVol(gunIndex) == NO) {
                 //    continue;
                 //}
-
+                GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id); //DS60-120 add
                 // 計算 Power
                 pDcChargingInfo->PresentChargingPower =
                     ((float)((pDcChargingInfo->PresentChargingVoltage) *
@@ -1040,7 +1040,7 @@ int main(int argc, char *argv[])
                     chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
                 } else {
                     int passTime = pDcChargingInfo->PresentChargedDuration - chargingTime[gunIndex];
-                    /*
+                    
                     if (passTime > 0) {
                         float changingPow = (pDcChargingInfo->PresentChargingPower) * passTime / 3600;
                         if (pSysConfig->BillingData.isBilling) {
@@ -1048,10 +1048,12 @@ int main(int argc, char *argv[])
                         }
 
                         pDcChargingInfo->PresentChargedEnergy += changingPow;
+
+                        ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption += changingPow;
                         pDcChargingInfo->PowerConsumption += changingPow;
                         chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
                     }
-                    */
+                    
                 }
 
                 // 開始確認車端是否同意開始充電

+ 24 - 24
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/FanBoard.c

@@ -20,6 +20,7 @@ static struct SysInfoData *pSysInfo = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct FanModuleData *ShmFanModuleData = NULL;
 static struct PsuData *ShmPsuData = NULL;
+static DcCommonInfo* ShmDcCommonData = NULL;
 
 static int Uart5Fd = 0;
 static struct timeval gFanBoardRunTimer;
@@ -149,8 +150,8 @@ static void GetFanSpeedByFunction(void)
 static void SetRtcData_Fan(void)
 {
     struct timeb csuTime;
-    struct tm *tmCSU;
-    Rtc rtc = {0};
+    struct tm* tmCSU;
+    Rtc rtc = { 0 };
 
     ftime(&csuTime);
     tmCSU = localtime(&csuTime.time);
@@ -186,30 +187,42 @@ static void SetRtcData_Fan(void)
 static void SetModelName_Fan(void)
 {
     if (Config_Model_Name(Uart5Fd, ADDR_FAN, pSysConfig->ModelName) == PASS) {
-        return;
-    } else
-        log_info("******** Set Model name FAIL = %s ************", pSysConfig->ModelName);
+        log_info("Set Model name PASS = %s ", pSysConfig->ModelName);
+    }
 }
 
 static void GetFwAndHwVersion_Fan(void)
 {
-    Ver ver = {0};
+    Ver ver = { 0 };
 
     if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // FanModuleData
-        strcpy((char *)ShmFanModuleData->version, ver.Version_FW);
+        strcpy((char*)ShmFanModuleData->version, ver.Version_FW);
         // SystemInfo
-        strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
+        strcpy((char*)pSysInfo->FanModuleFwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
     }
 
     if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // SystemInfo
-        strcpy((char *)pSysInfo->FanModuleHwRev, ver.Version_FW);
+        strcpy((char*)pSysInfo->FanModuleHwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s2 = %s ", ver.Version_HW);
     }
 }
 
+static void fanBoardSelfTest(void)
+{
+    if (ShmFanModuleData->SelfTest_Comp == YES) {
+        return;
+    }
+
+    GetFwAndHwVersion_Fan();
+    SetModelName_Fan();
+    SetRtcData_Fan();
+    sleep(1);
+    gettimeofday(&gFanBoardRunTimer, NULL);
+}
+
 static void fanBoardPorcess(void)
 {
     if (ShmFanModuleData->SelfTest_Comp == NO) {
@@ -217,8 +230,8 @@ static void fanBoardPorcess(void)
     }
 
     if (ShmFanModuleData->SelfTest_Comp == YES ||
-            strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
-            pSysInfo->FanModuleFwRev[0] != '\0') {
+        strlen((char*)pSysInfo->FanModuleFwRev) != 0 ||
+        pSysInfo->FanModuleFwRev[0] != '\0') {
         ShmFanModuleData->SelfTest_Comp = YES;
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
@@ -239,19 +252,6 @@ static void fanBoardPorcess(void)
     }
 }
 
-static void fanBoardSelfTest(void)
-{
-    if (ShmFanModuleData->SelfTest_Comp == YES) {
-        return;
-    }
-
-    GetFwAndHwVersion_Fan();
-    SetModelName_Fan();
-    SetRtcData_Fan();
-    sleep(1);
-    gettimeofday(&gFanBoardRunTimer, NULL);
-}
-
 void FanBoardTask(int uartFD)
 {
 #if defined NO_FAN_BOARD || defined DD360ComBox

+ 13 - 6
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c

@@ -25,7 +25,7 @@ static DcCommonInfo *ShmDcCommonData = NULL;
 static struct WARNING_CODE_INFO *pSysWarning = NULL;
 static struct LedModuleData *ShmLedModuleData = NULL;
 static struct FanModuleData *ShmFanModuleData = NULL;
-
+static struct GBTData* ShmGBTData = NULL;
 static Relay outputRelay = {0};
 static Relay regRelay = {0};
 static int Uart5Fd = 0;
@@ -362,10 +362,17 @@ static void GetGfdAdc(void)
 void CheckOutputPowerOverCarReq(uint8_t index)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
-
+    ShmGBTData = (struct GBTData*)GetShmGBTData();
     float fireV = pDcChargingInfo->FireChargingVoltage;
     float carV = pDcChargingInfo->EvBatteryMaxVoltage * 10;
-
+    /*
+    log_info("PresentChargingVoltage:%f, FireChargingVoltage:%f ", pDcChargingInfo->PresentChargingVoltage * 10, pDcChargingInfo->FireChargingVoltage);
+    log_info("fireV:%f, carV:%f, _isOvpChkTimeFlag:%d", fireV, carV, _isOvpChkTimeFlag[index]);
+    log_info("EvBatterytargetVoltage:%f", pDcChargingInfo->EvBatterytargetVoltage);
+    if (pDcChargingInfo->Type == _Type_GB) {
+        log_info("GB EV Board Status:%d", ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
+    }
+    */
     if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
             (pDcChargingInfo->Type == _Type_Chademo ||
              pDcChargingInfo->Type == _Type_CCS_2 ||
@@ -1399,16 +1406,16 @@ static void fanBoardPorcess(void)
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
             //GetPsuTempForFanSpeed();
-            GetFanSpeedByFunction();
+            //GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
-
+            /*
             ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-
+            */
             //log_info("set fan = %d ", ShmFanModuleData->SetFan1Speed);
             SetFanModuleSpeed();
         }

+ 13 - 6
EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -1458,7 +1458,7 @@ void DisplayInfoConsumption(bool isShow)
         uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
-        strcpy((char*)value, "CSPT >");
+        strcpy((char*)value, "PWCT >");
         DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
         memset(value, 0x00, sizeof(value));
         data = ShmDcCommonData->pConsumption.Gun1_Consumption +
@@ -1742,8 +1742,7 @@ void ShowAnimationPrice(char* pString)
     memset(cmd, 0x00, sizeof(cmd));
     string2ByteArray((uint8_t*)pString,cmd);
     int len = strlen(pString);
-    if (len <= 0)
-        return;
+
     if (strcmp((char*)old_string, pString) != EQUAL) {
         strcpy((char*)old_string, pString);
         DisplayFeeValueToLcm(__Animation_Price, cmd, sizeof(cmd));
@@ -2064,8 +2063,11 @@ void ProcessPageInfo()
                     ChangeParkingFeeValue(ShmSelectGunInfo->PricesInfo[i].ParkingFee, _currentPage);
                     // Total Cost
                     ChangeTotalCostValue(pDcChargingInfo->ChargingFee, _currentPage);
-
-                    ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    if (pSysConfig->BillingData.isBilling) {
+                        ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    } else {
+                        ShowAnimationPrice("");
+                    }
                 }
             } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
@@ -2107,7 +2109,11 @@ void ProcessPageInfo()
                         ChangeTotalCostValue(pDcChargingInfo->ChargingFee, _currentPage);
                     }
 
-                    ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    if (pSysConfig->BillingData.isBilling) {
+                        ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    } else {
+                        ShowAnimationPrice("");
+                    }
                 }
             } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
@@ -2285,6 +2291,7 @@ void ChangeDisplayMoneyInfo()
         ChangeDisplay2Value(__money_rate_map, _disappear);
         ChangeDisplay2Value(__money_by_rate, _disappear);
         ChangeDisplay2Value(__money_rate, _disappear);
+        ShowAnimationPrice("");
     }
 }
 

+ 6 - 2
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -351,11 +351,13 @@ static void checkChillerStatus(Gpio_out *gpio)
     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)) {
         chillerCount++;
+        ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
     }
 
     if (chillerCount == 0) {
@@ -363,7 +365,9 @@ static void checkChillerStatus(Gpio_out *gpio)
         return;
     }
 
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        if (!ShmDcCommonData->pGunInfo[gunIndex].withChiller)
+            continue;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
@@ -413,7 +417,7 @@ static void checkChillerStatus(Gpio_out *gpio)
     }
 
     uint8_t _chillerNeedOn = NO;
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++)
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
         if(pChillerInfo->ChillerSwitch == YES)

+ 50 - 1
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -1229,6 +1229,35 @@ void writeChillerStatus(char *v1)
     } else
         printf("Please open Debug mode\n");
 }
+
+void showNetworkPage(char* v1)
+{
+    ShmDcCommonData->showNetPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showNetPackage)
+        printf("Show Network Package on\n");
+    else
+        printf("Show Network Package off\n");
+}
+
+void showCANBUSPage(char* v1)
+{
+    ShmDcCommonData->showCanPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showCanPackage)
+        printf("Show CAN Bus Package on\n");
+    else
+        printf("Show CAN Bus Package off\n");
+}
+void setSystemTime(char* date,char* time)
+{
+    char _setTime[30];
+    char cmdBuf[50];
+    sprintf(_setTime, "%s %s", date, time);
+    printf("Set Timer:%s", _setTime);
+    sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
+    system((char*)cmdBuf);
+    system("hwclock -w -u");
+    system("hwclock -s");
+}
 static void writeGunAndChillerTemp(void)
 {
     uint8_t _GunIndex = 0;
@@ -1304,7 +1333,16 @@ static void writeGunAndChillerTemp(void)
         usleep(sleepTime);
     }//while
 }
+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)
 {
     uint8_t _GunIndex = 0;
@@ -1329,7 +1367,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"
+                     "       chiller                           : set chiller on/off\r\n"
+                     "       netdump                           : show network package\r\n"
+                     "       candump                           : show can package\r\n"
+                     "       powerconsumption                  : Show Power Consumption\n"
                      "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
@@ -1502,6 +1543,14 @@ int main(void)
             writeOTPTemp();
         } 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) { //印出網路封包
+            showCANBUSPage(newString[1]);
+        } else if (strcmp(newString[0], "time") == 0) {  //設定系統時間
+            setSystemTime(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "powerconsumption") == 0) { // Power Consumption
+            ShowPowerConsumption(newString[1]);
         } else {
             printf("%s\n", usageMsg);
         }

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

@@ -65,6 +65,7 @@ typedef struct StPricesInfo {
     int TransactionId;
     float EnergyCost;
     float ParkingFee;
+    float RemainAmount;
 } PricesInfo;
 
 //typedef struct StOperativeInfo {

+ 15 - 7
EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c

@@ -930,16 +930,15 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
         }
         break;
 
+    case 'V': // Liquid CCS1 combo
+    case 'F': // Liquid CCS2 combo
     case 'T': // Rema CCS1
     case 'D': // Rema CCS2
     case 'U': // CCS1 combo
     case 'E': // CCS2 combo
-    case 'V': // Liquid CCS1 combo
-    case 'F': // Liquid CCS2 combo
     case 'M': // 80A CCS2
     case 'N': // 80A CCS1
-    case 'P': // Phoenix CCS2 500A 水冷
-    case 'R': // Phoenix CCS1 500A 水冷
+    case 'P': // 急電弓
         if (CCS_QUANTITY > gGunIndexInfo.CcsIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[gGunIndexInfo.CcsIndex];
 
@@ -959,16 +958,25 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
                 gGunIndexInfo.CcsIndex++;
                 gGunIndexInfo.DcGunIndex++;
             }
-            if(typeValue == 'P')
-            {
+            if(typeValue == 'P') {
                 pDcChargingInfo->PantographFlag = YES;
-            }
+            } else if (typeValue == 'V') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Liquid;
+            } else if (typeValue == 'F') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Liquid;
+            } else if (typeValue == 'T' || typeValue == 'U' || typeValue == 'N') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Natural;
+            } else if (typeValue == 'D' || typeValue == 'E' || typeValue == 'M') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Natural;
+            } else
+                pDcChargingInfo->CCSGunType = _TYPE_CCS_NONE;
         } else {
             result = false;
         }
         break;
 
     case 'G':  // GBT DC
+    case 'B': // GBT YG PT100
         if (GB_QUANTITY > gGunIndexInfo.GbIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex];
 

+ 111 - 227
EVSE/Projects/DD360ComBox/Apps/CSU/main.c

@@ -84,7 +84,7 @@ uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
 char *fwVersion = "V1.21.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "v1.21.0";
+char* DebugVersion = "v1.21.5";
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -404,52 +404,105 @@ static void checkGunOTPState(uint8_t gunIndex)
     //log_info("OTP:%d OTPR%d",pSysInfo->OTPTemp,pSysInfo->OTPTempR);
     //水冷機溫度檢測
     if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
-        if (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP) {
-            if (pDcChargingInfo->ChillerTemp >= pSysInfo->OTPTemp ) {
-                if (((gunIndex == 0) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                         ||
-                    ((gunIndex == 1) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-                   ) {
-                    RecordAlarmCode(gunIndex, "012323");
+        if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
+            // 單水冷機
+            // Chiller OTP
+            if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
-                }
-                else
-                {
+                    RecordAlarmCode(gunIndex, "012323");
+                } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
                 }
-            } else if (pDcChargingInfo->ChillerTemp != 0 &&
-                       pDcChargingInfo->ChillerTemp < pSysInfo->OTPTempR) {
-                //ResetChargerAlarmCode(gunIndex, "012323");
-                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
-        } else {
-            // 沒接上 Sensor or 異常
-            //RecordAlarmCode(gunIndex, "011038");
-            //ResetChargerAlarmCode(gunIndex, "012323");
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
-            if (((gunIndex == 0) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                     ||
-                ((gunIndex == 1) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-               ) {
+            // Chiller Tube OTP
+            if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
-            }
-            else
-            {
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                    RecordAlarmCode(gunIndex, "012332");
+                } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[3] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                }
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
+        } else {
+            // 雙水冷機
+            if (gunIndex == LEFT_GUN_NUM) {
+                if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+                    } else if (ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            } else {
+                if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+
+                    } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            }
         }
 
-        if(pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES)
-        {
+        if (pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES) {
             RecordAlarmCode(gunIndex, "011037");
         }
     }
@@ -1554,11 +1607,7 @@ uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
     uint8_t result = 0x00;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-        result = ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;
-    }
-
-    return result;
+    return ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;;
 }
 
 bool isEvStopCharging_ccs(uint8_t gunIndex)
@@ -1658,7 +1707,7 @@ void _DetectPlugInTimeout(void)
 	//pSysInfo->SystemPage = _LCM_COMPLETE;
 	setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
 #elif DD360 || DD360Combox
- 	setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
+ 	setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
 #endif
     systemPageRestoreInit();
 }
@@ -4128,9 +4177,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
     case _Type_Chademo:
         // 檢查樁端的 GFD 結果
         if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_chademo(gunIndex) > 6 &&
-                isPrechargeStatus_chademo(gunIndex) < 8
-           ) {
+                isPrechargeStatus_chademo(gunIndex) >= 6) {
             // 當前操作的槍號,進入 Charging
             setChargerMode(gunIndex, MODE_CHARGING);
         }
@@ -4177,8 +4224,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
     case _Type_GB:
         // 檢查樁端的 GFD 結果
         //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
-        if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_gb(gunIndex) > 6) {
+        if (sysStatus == S_PREPARING_FOR_EVSE && isPrechargeStatus_gb(gunIndex) >= 6) {
             setChargerMode(gunIndex, MODE_CHARGING);
         }
 
@@ -4472,6 +4518,9 @@ int main(void)
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
 
             pDcChargingInfo->IsAvailable = DB_Get_Operactive(_index);
+            if (!DB_Get_PowerConsumption(_index)) {
+                DB_Insert_PowerConsumption(_index, 0);
+            }
         }
         DB_Reboot_Record();
     }
@@ -4502,6 +4551,9 @@ int main(void)
 
     pSysInfo->OTPTemp = GUN_OTP_VALUE;
     pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
+
+    time_t ShowEVStatusTimer[2] = { 0 };
+
     for (;;) {
 
         CheckOcppStatus();
@@ -4600,9 +4652,6 @@ int main(void)
                 CheckSmartChargeProfile(gunIndex);
             }
 
-            //log_info("index = %d, ErrorCode = %s",
-            //         gunIndex,
-            //         ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode);
             switch (pDcChargingInfo->SystemStatus) {
             case S_IDLE:
             case S_RESERVATION:
@@ -4625,6 +4674,7 @@ int main(void)
                     //Jerry add
                     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
                     memset(&ShmDcCommonData->pGunInfo[gunIndex], 0, sizeof(GunInfo));
+                    DB_Get_PowerConsumption(gunIndex);
                     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
                     destroySelGun(gunIndex);
                     ResetDetAlarmStatus(gunIndex); //recovery OVP status code
@@ -4882,7 +4932,7 @@ int main(void)
 
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 5000000) {
+                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 1000000) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 
@@ -4953,52 +5003,7 @@ int main(void)
                 }
 
                 checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gunIndex) > 5 &&
-                            isPrechargeStatus_chademo(gunIndex) < 8) {
-                        // 當前操作的槍號,進入 Charging
-                        setChargerMode(gunIndex, MODE_CHARGING);
-                    }
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    // 檢查樁端的 GFD 結果
-                    //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
-                    if (isPrechargeStatus_gb(gunIndex) > 9) {
-                        setChargerMode(gunIndex, MODE_CHARGING);
-                    }
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    // 檢查樁端的 GFD 結果
-                    if ((pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
-                            pDcChargingInfo->GroundFaultStatus == GFD_WARNING)) {
-                        setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP0);
-                    }
 
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
-                }
-#endif //0
                 checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
 
                 // LCM => Pre-charging
@@ -5025,64 +5030,12 @@ int main(void)
                 pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
 
                 checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    }
-                    //else if (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //            pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //            pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012289");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    }
-                    //else if (isPrechargeStatus_gb(gunIndex) == 10 &&
-                    //           (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //             pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //            (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //             pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL))
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012290");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    }
-                    //else if (((pDcChargingInfo->EvBatterytargetVoltage * 10) > 0 &&
-                    //            pDcChargingInfo->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-                    //           (pDcChargingInfo->PresentChargedDuration >= 10 &&
-                    //            pDcChargingInfo->PresentChargingVoltage < SYSTEM_MIN_VOL)
-                    //          ) {
-                    //    // UVP
-                    //    RecordAlarmCode(gunIndex, "012288");
-                    //    ChargingTerminalProcess(gunIndex);
-                    //}
-                    else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
+
+                if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime) >= 5) {
+                    ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
+                    if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
+                        DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
                 }
-#endif //0
 
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
@@ -5144,82 +5097,13 @@ int main(void)
 
                     //log_info ("terminating......................... %x ", gunIndex);
                     StopGunInfoTimeoutDet(gunIndex);
+                    ShmDcCommonData->pGunInfo[gunIndex].RecordEnergyTime = time((time_t*)NULL);
+                    if (ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption != 0)
+                        DB_Update_PowerConsumption(gunIndex, ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption);
                 }
 
                 //checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
-#if 0
-                if (pDcChargingInfo->Type == _Type_Chademo) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //        strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012234");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012296");
-                    }
 
-                    //if (isEvStopCharging_chademo(gunIndex) == YES ||
-                    //        isPrechargeStatus_chademo(gunIndex) <= 0) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                } else if (pDcChargingInfo->Type == _Type_GB) {
-                    //log_info("************ GB lock Status = %d, status = %d ",
-                    //         isEvStopCharging_gb(gunIndex),
-                    //         isPrechargeStatus_gb(gunIndex));
-
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012236");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012298");
-                    }
-
-                    //if (isEvStopCharging_gb(gunIndex) == YES ||
-                    //        isPrechargeStatus_gb(gunIndex) <= 0) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    //if (isEvStopCharging_chademo(gunIndex) == YES) {
-                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
-                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
-                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");*/
-                    //    /*--- 20200908, vern, disable it for DD360 ---*/
-                    //}
-
-                    if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
-                        // GFD 錯誤停止
-                        RecordAlarmCode(gunIndex, "012235");
-                    } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
-                        // GFD 警告
-                        RecordAlarmCode(gunIndex, "012297");
-                    }
-
-                    //if (isEvStopCharging_ccs(gunIndex) == YES &&
-                    //        (isPrechargeStatus_ccs(gunIndex) >= 53 ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 0  ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 13 ||
-                    //         isPrechargeStatus_ccs(gunIndex) == 14)) {
-                    //    setChargerMode(gunIndex, MODE_COMPLETE);
-                    //}
-                }
-#endif //0
                 if (pDcChargingInfo->SystemStatus == S_ALARM) {
                     if (pDcChargingInfo->ConnectorPlugIn == NO &&
                             GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 10000000) {

+ 19 - 4
EVSE/Projects/DD360ComBox/Apps/Config.h

@@ -135,11 +135,17 @@ enum _GUN_TYPE {
     _Type_GB,
     _Type_AC,
 };
-
+enum _CCS_GUN_TYPE {
+    _TYPE_CCS_NONE  = 0,
+    _TYPE_CCS1_Natural,
+    _TYPE_CCS1_Liquid,
+    _TYPE_CCS2_Natural,
+    _TYPE_CCS2_Liquid,
+};
 enum _LCM_INDEX {
-    _LCM_INIT          = 0x00,
-    _LCM_IDLE          = 0x01,
-    _LCM_AUTHORIZING   = 0x02,
+    _LCM_INIT = 0x00,
+    _LCM_IDLE = 0x01,
+    _LCM_AUTHORIZING = 0x02,
     _LCM_AUTHORIZ_COMP = 0x03,
     _LCM_AUTHORIZ_FAIL = 0x04,
     _LCM_WAIT_FOR_PLUG = 0x05,
@@ -406,6 +412,12 @@ typedef struct StGunInfo {
     char ReservationID[32];
     uint8_t ReservationStatus;
     char UserPriceString[255];
+    float PowerConsumption;
+    time_t RecordEnergyTime;
+    char ChargeStartTime[32];
+    char ChargeStopTime[32];
+    char ChargeDuration[32];
+    uint8_t withChiller;      //是否有水冷機
 } GunInfo;
 
 typedef struct Psu_VersionInfo{
@@ -445,6 +457,7 @@ typedef struct stRecordTransactionInfo
     unsigned char IsUpload; // 0: not upload, 1: uploaded
     unsigned char res;
 }RecordTransactionInfo;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -473,6 +486,8 @@ typedef struct StDcCommonInfo {
     float Temperature;
     int Location;
     GunInfo pGunInfo[2];
+    uint8_t showNetPackage;
+    uint8_t showCanPackage;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

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

@@ -14,7 +14,7 @@
 
 //------------------------------------------------------------------------------
 static sqlite3 *localDb;
-
+static DcCommonInfo* ShmDcCommonData = NULL;
 //------------------------------------------------------------------------------
 //===============================================
 // SQLite3 related routine
@@ -59,6 +59,11 @@ int DB_Open(void)
                             "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
                             "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
 
+    char *createPowerConsumption = "CREATE TABLE IF NOT EXISTS power_consumption( "
+                         "idx INTEGER PRIMARY KEY AUTOINCREMENT, "
+                         "connector TEXT, "
+                         "val TEXT);";
+
     if (sqlite3_open(DB_FILE, &localDb)) {
         result = FAIL;
         log_info( "Can't open database: %s", sqlite3_errmsg(localDb));
@@ -88,6 +93,14 @@ int DB_Open(void)
             log_info( "Opened local record table successfully");
         }
 
+        //DS60-120
+        if (sqlite3_exec(localDb, createPowerConsumption, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("Create power consumption record table error message: %s", errMsg);
+        } else {
+            log_info("Opened power consumption record table successfully");
+        }
+
         if (sqlite3_exec(localDb, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
             result = FAIL;
             log_info( "Create reboot record table error message: %s", errMsg);
@@ -99,6 +112,7 @@ int DB_Open(void)
         sqlite3_close(localDb);
     }
 
+    ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     return result;
 }
 
@@ -222,6 +236,104 @@ int DB_Get_Operactive(uint8_t gunIndex)
     return result;
 }
 
+int DB_Insert_PowerConsumption(uint8_t gunIndex, float energy)
+{
+    uint8_t result = false;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    srand(time(NULL));
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        //log_info("Local charging record database open successfully (%f).", energy);
+        sprintf(sqlStr,"insert into power_consumption (connector, val) values (%d, %f);",
+            gunIndex,
+            energy); //DS60-120 add
+        //log_info("sqlStr= %s", sqlStr);
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("Insert power consumption error message: %s", errMsg);
+        } else {
+            log_info("Insert connector-%d config item PowerComsumption to %f", gunIndex, energy);
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int DB_Update_PowerConsumption(uint8_t gunIndex, float energy)
+{
+    uint8_t result = false;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    srand(time(NULL));
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        //log_info("Local charging record database open successfully.");
+        sprintf(sqlStr,"update power_consumption set val = %f where connector = %d; ",
+                        energy,
+                        gunIndex); //DS60-120 add
+        //log_info("sqlStr= %s", sqlStr);
+        if (sqlite3_exec(localDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
+            result = FAIL;
+            log_info("update config error message: %s", errMsg);
+        } else {
+            //log_info("update connector-%d config item PowerComsumption to %f", gunIndex, energy);
+        }
+
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+int DB_Get_PowerConsumption(uint8_t gunIndex)
+{
+    uint8_t result = true;
+    char* errMsg = NULL;
+    char sqlStr[1024];
+    char** rs;
+    int  rows, cols;
+
+    //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gunIndex);
+    sprintf(sqlStr, "select * from power_consumption where connector=%d;", gunIndex); //DS60-120 add
+    //DEBUG_INFO("sqlStr= %s", sqlStr);
+
+    if (sqlite3_open(DB_FILE, &localDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(localDb));
+        sqlite3_close(localDb);
+    } else {
+        log_info("Local config query database open successfully.");
+        sqlite3_get_table(localDb, sqlStr, &rs, &rows, &cols, &errMsg);
+        if (rows > 0) {
+            for (int idxRow = 1; idxRow <= rows; idxRow++) {
+                ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption = atof(rs[(idxRow * cols) + 2]);
+                log_info("Query connector-%d PowerConsumption: %s", gunIndex, rs[(idxRow * cols) + 2]);
+                
+            }
+        } else {
+            log_info("Query connector-%d fail, set default value to operactive.", gunIndex);
+            result = false;
+        }
+
+        sqlite3_free_table(rs);
+        sqlite3_close(localDb);
+    }
+
+    return result;
+}
+
+
 int DB_Reboot_Record(void)
 {
     int result = PASS;

+ 3 - 1
EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.h

@@ -10,5 +10,7 @@ int DB_Reboot_Record(void);
 //for Module_EventLog
 int CreateEventRecord(void);
 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);
 #endif /* _DATA_BASE_H_ */

+ 159 - 64
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c

@@ -27,6 +27,7 @@
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
 #include "../timeout.h"
+#include "../DataBase/DataBase.h"
 #include "DoComm.h"
 
 //------------------------------------------------------------------------------
@@ -58,7 +59,9 @@ static char ReservationIdTag[2][32];
 static int LineStatusCode[2] = {0};
 static unsigned int LedIntensity = 0;
 static int TimeZoneOffset = 0;
-
+int RxLen;
+char Rxdata[1024];
+uint8_t _isplugin = 0;
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -200,6 +203,23 @@ static void setTcpStatus(uint8_t setValue)
 static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
 {
     int size = -1;
+    int i;
+    char _info[1024];
+    int len = 0;
+
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        len = 0;
+        len += sprintf(&_info[len], "Net Tx[%d]:", dataLen);
+        for (i = 0; i < dataLen; i++) {
+            if (i == 0)
+                len += sprintf(&_info[len], "[%X]\t", data[i]);
+            else
+                len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s", _info);
+    }
 
     size = send(fd, data, dataLen , 0);
     if ((size < 0) || (errno == EAGAIN)) {
@@ -211,15 +231,34 @@ static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
     return size;
 }
 
-static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
+static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen,uint8_t ishead)
 {
     int size = -1;
+    int i;
     uint8_t *pdata = (uint8_t *)data;
 
     size = recv(fd, pdata, dataLen, MSG_WAITALL);
     if ((errno == EAGAIN) || (size < 0)) {
         log_error("Receive Socket Size = %d, EAGAIN error %d:%s", size, errno, strerror(errno));
     }
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        if (ishead) {
+            RxLen = 0;
+            RxLen += sprintf(&Rxdata[RxLen], "Net Rx[%d]:", size);
+        }
+        for (i = 0; i < dataLen; i++) {
+            if (ishead && i == 0)
+                RxLen += sprintf(&Rxdata[RxLen], "[%X]\t", data[i]);
+            else
+                RxLen += sprintf(&Rxdata[RxLen], "%X ", data[i]);
+        }
+        if (!ishead) {
+            RxLen += sprintf(&Rxdata[RxLen], "\n");
+            printf("%s", Rxdata);
+            strcpy(Rxdata,"");
+        }
+    }
 
     return size;
 }
@@ -925,10 +964,6 @@ void AddDispenserReq(uint8_t* buff, MiscCommand* req)
     buff[5] = req->Value[3];
 }
 
-
-
-
-
 static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
 {
     uint8_t addr = 0;
@@ -981,19 +1016,23 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     ShmSelectGunInfo->PricesInfo[plugNum].TransactionId = ntohl(pAccountInfo->Transaction);
     ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost = transPricesUnit(ntohl(pAccountInfo->EnergyCost));
     ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee = transPricesUnit(ntohl(pAccountInfo->ParkingFee));
+    pAccountInfo->RemainAmount = ntohl(pAccountInfo->RemainAmount);
+    memcpy((char*)&ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount, (char*)&pAccountInfo->RemainAmount, sizeof(uint32_t));
 
     if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
             (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance) ||
 			(pricesInfo[plugNum].Discount != ShmSelectGunInfo->PricesInfo[plugNum].Discount) ||
 			(pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId) ||
             (pricesInfo[plugNum].EnergyCost != ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost) ||
-            (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee)) {
+            (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee) || 
+            (pricesInfo[plugNum].RemainAmount != ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount)) {
         pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
         pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
         pricesInfo[plugNum].Discount = ShmSelectGunInfo->PricesInfo[plugNum].Discount;
         pricesInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
         pricesInfo[plugNum].ParkingFee = ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee;
         pricesInfo[plugNum].EnergyCost = ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost;
+        pricesInfo[plugNum].RemainAmount = ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount;
         if (ShmSelectGunInfo->PricesInfo[plugNum].TransactionId != 0) {
 
             //ShmDcCommonData->TransactionInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
@@ -1010,6 +1049,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
             log_info("Total Cost:%.2f", pDcChargingInfo->ChargingFee);
             log_info("Parking Fee:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee);
             log_info("Energy Cost:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost);
+            log_info("Remain Amount:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].RemainAmount);
         }
     }
 
@@ -1462,6 +1502,22 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             log_info("Gun%d Receipt:%s", plugNum, ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo);
         }
         break;
+    case REG_READ_CHARGING_TIMESTAMP:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        if (rawDataLen <= 2) {
+            log_info("No Charging timestamp");
+            break;
+        }
+
+        strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStartTime, (char*)&pCsuResult->Data.Data[0]);
+        int timelen = strlen((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStartTime);
+        if (timelen != 0) {
+            timelen = strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ChargeStopTime, (char*)&pCsuResult->Data.Data[timelen+1]);
+        }
+        break;
+        
     case REG_POWER_CONSUMPTION_INFO:
         if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
             return COMMAND_RESULT_NG;
@@ -1486,6 +1542,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         
         
         break;
+        
     default:
         break;
     }
@@ -1530,14 +1587,14 @@ static int composeSocketData(int fd,
     }
 
     //receive result head
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head), 1)) < 0) {
         log_error("TCP socket RX head fail = %d", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result raw data
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen, 0)) < 0) {
         log_error("TCP socket RX data fail = %d", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
@@ -1679,11 +1736,29 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     return ret;
 }
 */
+
+static int readChargingTimeStamp(int fd, uint8_t id)
+{
+    int ret = PASS;
+    if ((ret = composeSocketData(fd,
+                                 id,
+                                 OP_READ_DATA,
+                                 REG_READ_CHARGING_TIMESTAMP,
+                                 0,
+                                 NULL)) == FAIL) {
+        return ret;
+    }
+
+    return ret;
+}
 static int writeWaitPlugItState(int fd, uint8_t id)
 {
     int ret = PASS;
     uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-
+    if (_isplugin != pSysInfo->WaitForPlugit) {
+        log_info("Wait for plug:%s", pSysInfo->WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin = pSysInfo->WaitForPlugit;
+    }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
     if ((ret = composeSocketData(fd,
@@ -1852,7 +1927,8 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 {
-    uint8_t dataBuf[10] = {'\0'};
+    uint8_t dataBuf[15] = {'\0'};
+    uint32_t _consumption;
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
@@ -1912,7 +1988,10 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
             }
         }
     }
-
+#ifdef DD360
+    memcpy((char*)&_consumption, (char*)&ShmDcCommonData->pGunInfo[plugNum].PowerConsumption, sizeof(float));
+    pConnState->consumption = ntohl(_consumption);
+#endif
     ret = composeSocketData(fd,
                             id,
                             OP_WRITE_DATA,
@@ -2319,7 +2398,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         case REG_CHARGING_CAP:
             if(gMoreInfoReq[plugNum].bits.FinalCostReq)
             {
-                if (readChargingCapability(fd, gunID) == PASS) {
+                if (readChargingCapability(fd, gunID) == PASS && readChargingTimeStamp(fd, gunID) == PASS) {
 					gMoreInfoReq[plugNum].bits.FinalCostReq = false;
 					pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 					//ShmDcCommonData->TransactionInfo[plugNum].Amount = pDcChargingInfo->ChargingFee;
@@ -2399,7 +2478,11 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_READ_CABINET_SYSTEMID;
+#ifdef DD360Audi
+        curReg = REG_POWER_CONSUMPTION_INFO;
+#else
+        curReg = REG_READ_CABINET_SYSTEMID;
+#endif
             break;
         //case REG_USER_ID:
         //    writeUserID(fd, gunID, uint8_t *pUserID);
@@ -2441,53 +2524,14 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             }
             break;
 
-        //case REG_PRESENT_CHARGING_INFO:
-        //    break;
-
-
-
-        //case REG_WAIT_PLUG_IT_STATE:
-        //    if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME / 10)) {
-        //        writeWaitPlugItState(fd, gunID);
-        //        ftime(&gRegTimeUp[plugNum][curReg]);
-        //    }
-        //    isContinue = 0;
-        //    break;
-
-        //case REG_CABINET_DCM_VERSION:
-        //    break;
-
-        //case REG_CABINET_OTHER_VERSION:
-        //    break;
-
-        //case REG_TOTAL_PSU_QUANTITY:
-        //    break;
-
-        //case REG_PSU_VERSION:
-        //    break;
-
-
-        //case REG_DISPENSER_REQUEST:
-        //    break;
-
-
         case REG_READ_CABINET_SYSTEMID:
-            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
                 readSystemID(fd);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
-            curReg = REG_POWER_CONSUMPTION_INFO;
-            break;
-
-        case REG_POWER_CONSUMPTION_INFO:
-            if (pSysConfig->ShowInformation || ShmDcCommonData->debugflag) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-                    readConsumptionInfo(fd);
-                    ftime(&gRegTimeUp[plugNum][curReg]);
-                }
-            }
+            curReg = REG_RESERVATION_IDTAG;
+            /*
             //check misc command from power cabinet
             if (gDoCommGblData.MiscCmd != 0) {
                 if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
@@ -2499,8 +2543,8 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             } else {
                 isContinue = 0;
             }
+            */
             break;
-
         case REG_RESERVATION_IDTAG:
             if (gMoreInfoReq[plugNum].bits.ReservationReq)
             {
@@ -2513,8 +2557,30 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_REMOTE_START_NO_ID;
+            curReg = REG_POWER_CONSUMPTION_INFO;
             break;
+        case REG_POWER_CONSUMPTION_INFO:
+            if (pSysConfig->ShowInformation || ShmDcCommonData->debugflag) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    readConsumptionInfo(fd);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            //check misc command from power cabinet
+            if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
+                }
+                curReg = gDoCommGblData.MiscCmd;
+            } else if (gMoreInfoReq[plugNum].Value != 0) {
+                curReg = REG_REMOTE_START_NO_ID;
+            } else {
+                isContinue = 0;
+            }
+            break;
+            
+
         case REG_REMOTE_START_NO_ID:
             if (gMoreInfoReq[plugNum].bits.RemoteStartNoID)
             {
@@ -2637,6 +2703,17 @@ 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
+                ) {
+                readChargingTimeStamp(fd, gunID);
+                ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+            }
+        }*/
+
         checkAuthorProcess(fd, plugNum);
 
         //authorization complete, write wait plug it state
@@ -2805,10 +2882,12 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) < 0
            ) {
             if (readChargePermission(fd, gunID) == 0) {
-                log_info("Stop charging by power cabinet's permission = %d, %d",
-                         plugNum,
-                         REG_CHARGING_PERMISSION);
-                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                if (pDcChargingInfo->StopChargeFlag != POWER_CABINET_STOP_CHARGING) {
+                    log_info("Stop charging by power cabinet's permission = %d, %d",
+                        plugNum,
+                        REG_CHARGING_PERMISSION);
+                    pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                }
                 //printf("%d StopChargeFlag = %d\n", plugNum, pDcChargingInfo->StopChargeFlag);
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
@@ -2823,8 +2902,15 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
 
+        // 獲得Charging時間
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) > (LOOP_RETRY_TIME*5) ||
+            DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) < 0
+            ) {
+            readChargingTimeStamp(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+        }
         break;
-
     case S_COMPLETE:
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2835,7 +2921,16 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
-
+        // 獲得Charging時間
+        /*
+        ftime(&AuthNowTime);
+        if (DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
+            DiffTimeb(gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP], AuthNowTime) < 0
+            ) {
+            readChargingTimeStamp(fd, gunID);
+            ftime(&gRegTimeUp[plugNum][REG_READ_CHARGING_TIMESTAMP]);
+        }
+        */
         break;
 
     default:

+ 5 - 2
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h

@@ -16,7 +16,7 @@
 #define TFTP_PULL_CMD                           "tftp"
 #define SIGTERM_MSG                             "SegmentFault.~~~~\n"
 
-#define MAX_REGISTER_NUM                        40
+#define MAX_REGISTER_NUM                        50
 
 #define CHECK_NETWORK_FAIL_COUNT                10//10
 #define CONNECT_SERVER_FAIL_COUNT               3//5
@@ -98,6 +98,7 @@
 #define REG_READ_USER_PRICE                     0x22
 #define REG_RECEIPT_INFO                        0x23
 #define REG_POWER_CONSUMPTION_INFO              0x24
+#define REG_READ_CHARGING_TIMESTAMP             0x25
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -220,7 +221,8 @@ typedef struct StConnectorState {
     uint8_t ConnectorTemp;
     uint8_t ChillerTemp;
     uint8_t PlugIn;
-    uint8_t Reserved[2];
+    uint32_t consumption;
+    uint8_t Reserved[1];
 } ConnectorState;
 
 typedef struct StConnectorIDTable {
@@ -325,6 +327,7 @@ typedef struct StAccountInfo {
     int Transaction;
     int EnergyCost;
     int ParkingFee;
+    uint32_t RemainAmount;
     uint8_t Reserved[1];
 } AccountInfo;
 

+ 14 - 2
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Ev_Comm.c

@@ -13,7 +13,7 @@
 
 #include "Ev_Comm.h"
 #include "Module_EvComm.h"
-
+#include "../Config.h"
 //------------------------------------------------------------------------------
 int PackageIdCmd(int cmd)
 {
@@ -22,14 +22,26 @@ int PackageIdCmd(int cmd)
 
 void SendCmdToEvboard(int cmd, uint8_t *data, uint8_t dataLen)
 {
+    DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     int fd = GetCanFd();
     struct can_frame frame;
-
+    int i;
+    int len = 0;
+    char _info[1024];
     frame.can_id = cmd;
     frame.can_dlc = dataLen;
     memcpy(frame.data, data, sizeof(frame.data));
 
     write(fd, &frame, sizeof(struct can_frame));
+
+    if (ShmDcCommonData->showCanPackage) {
+        len += sprintf(&_info[len], "CAN Dispenser => EV Tx:\t[0x%X] ", cmd);
+        for (i = 0; i < dataLen; i++) {
+            len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s",_info);
+    }
 }
 
 //------------------------------------------------------------------------------

+ 36 - 19
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -305,6 +305,9 @@ void CANReceiver(int fd)
         ChillerTemp chiilerTemp = {0};
         time_t CCS_PlugoutTimer[2] = { 0 };
         struct ChargingInfoData *pDcChargingInfo = NULL;
+        int len = 0;
+        char _info[1024];
+        int i;
 
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -332,7 +335,7 @@ void CANReceiver(int fd)
                 // 檢查是否有收到EV小板訊號
                 if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 3) &&
                     !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
-                    pDcChargingInfo->SystemStatus != S_UPDATE) {
+                    pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->debugflag) {
 
                     ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
                     ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
@@ -364,6 +367,16 @@ void CANReceiver(int fd)
             intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
 
             recvID = ((uint8_t) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
+            
+            if (ShmDcCommonData->showCanPackage) {
+                len = 0;
+                len += sprintf(&_info[len], "CAN Dispenser <= EV Rx:\t[0x%X] ", frame.can_id);
+                for (i = 0; i < nbytes; i++) {
+                    len += sprintf(&_info[len], "%X ", frame.data[i]);
+                }
+                len += sprintf(&_info[len], "\n");
+                printf("%s", _info);
+            }
 
             for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {                    // 假設有找到回應的 Index
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
@@ -538,8 +551,8 @@ void CANReceiver(int fd)
                 //printf("RemainChargingDuration = %d",  pDcChargingInfo->RemainChargingDuration);
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
-                    //if (ShmCHAdeMOData->ev[gunTypeIndex].EvDetection != frame.data[0])
-                    {
+                    if (ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
+                        log_info("Gun%d CHAdeMO board status = %d ", targetGun, ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus);
                         ShmCHAdeMOData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
 
@@ -548,8 +561,8 @@ void CANReceiver(int fd)
                     ShmCHAdeMOData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
                     ShmCHAdeMOData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
                 } else if (pDcChargingInfo->Type == _Type_GB) {
-                    //if (ShmGBTData->ev[gunTypeIndex].EvDetection != frame.data[0])
-                    {
+                    if (ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus != frame.data[0]) {
+                        log_info("Gun%d GB Board status = %d ", targetGun, ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
                         ShmGBTData->ev[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
 
@@ -558,7 +571,8 @@ void CANReceiver(int fd)
                     ShmGBTData->ev[gunTypeIndex].TargetBatteryVoltage = (pDcChargingInfo->EvBatterytargetVoltage * 10);
                     ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
                 } else if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
+                    if (ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus != frame.data[0] && frame.data[0] != 0xFF) {
+                        log_info("Gun%d CCS board status = %d ", targetGun, ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus);
                         ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
                     }
                 }
@@ -641,20 +655,23 @@ void CANReceiver(int fd)
 
                     pDcChargingInfo->ChillerTemp = maxChillerTemp;
                 }
+                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 > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
+                    {
+                        lastConnTemp[targetGun] = maxConnTemp;
+                        printConnTemp = YES;
+                    }
 
-                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
-                //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
-                //    printConnTemp = YES;
-                //}
-                maxConnTemp = getAvageTemp(maxConnTemp,targetGun);
-                if(maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
-                {
-                    lastConnTemp[targetGun] = maxConnTemp;
-                    printConnTemp = YES;
+                    pDcChargingInfo->ConnectorTemp = maxConnTemp;
+                } else {
+                    //log_info("Connector%d Tmep is zero:[%d,%d]", gunTypeIndex, ShmDcCommonData->ConnectorTemp[gunTypeIndex][0],
+                    //    ShmDcCommonData->ConnectorTemp[gunTypeIndex][1]);
                 }
-
-                pDcChargingInfo->ConnectorTemp = maxConnTemp;
-
                 //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
                 if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
                         (printConnTemp == YES) ||
@@ -667,7 +684,7 @@ void CANReceiver(int fd)
                     ShmDcCommonData->SystemModeChange[targetGun] = NO;
                     log_info("Conn %d max temp = %d, chiller = [%d %d], chiller2 = [%d %d]",
                              targetGun,
-                             maxConnTemp,
+                             pDcChargingInfo->ConnectorTemp,
                              chiilerTemp.Temp[0],
                              chiilerTemp.Temp[1],
                              chiilerTemp.Temp[2],

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

@@ -1028,7 +1028,7 @@ int main(int argc, char *argv[])
                 //if (waitPsuVolwithRealyVol(gunIndex) == NO) {
                 //    continue;
                 //}
-
+                GetEvBatteryInfo(gunIndex, pDcChargingInfo->Evboard_id); //DS60-120 add
                 // 計算 Power
                 pDcChargingInfo->PresentChargingPower =
                     ((float)((pDcChargingInfo->PresentChargingVoltage) *
@@ -1040,7 +1040,7 @@ int main(int argc, char *argv[])
                     chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
                 } else {
                     int passTime = pDcChargingInfo->PresentChargedDuration - chargingTime[gunIndex];
-                    /*
+                    
                     if (passTime > 0) {
                         float changingPow = (pDcChargingInfo->PresentChargingPower) * passTime / 3600;
                         if (pSysConfig->BillingData.isBilling) {
@@ -1048,10 +1048,12 @@ int main(int argc, char *argv[])
                         }
 
                         pDcChargingInfo->PresentChargedEnergy += changingPow;
+
+                        ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption += changingPow;
                         pDcChargingInfo->PowerConsumption += changingPow;
                         chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
                     }
-                    */
+                    
                 }
 
                 // 開始確認車端是否同意開始充電

+ 24 - 24
EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/FanBoard.c

@@ -20,6 +20,7 @@ static struct SysInfoData *pSysInfo = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct FanModuleData *ShmFanModuleData = NULL;
 static struct PsuData *ShmPsuData = NULL;
+static DcCommonInfo* ShmDcCommonData = NULL;
 
 static int Uart5Fd = 0;
 static struct timeval gFanBoardRunTimer;
@@ -149,8 +150,8 @@ static void GetFanSpeedByFunction(void)
 static void SetRtcData_Fan(void)
 {
     struct timeb csuTime;
-    struct tm *tmCSU;
-    Rtc rtc = {0};
+    struct tm* tmCSU;
+    Rtc rtc = { 0 };
 
     ftime(&csuTime);
     tmCSU = localtime(&csuTime.time);
@@ -186,30 +187,42 @@ static void SetRtcData_Fan(void)
 static void SetModelName_Fan(void)
 {
     if (Config_Model_Name(Uart5Fd, ADDR_FAN, pSysConfig->ModelName) == PASS) {
-        return;
-    } else
-        log_info("******** Set Model name FAIL = %s ************", pSysConfig->ModelName);
+        log_info("Set Model name PASS = %s ", pSysConfig->ModelName);
+    }
 }
 
 static void GetFwAndHwVersion_Fan(void)
 {
-    Ver ver = {0};
+    Ver ver = { 0 };
 
     if (Query_FW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // FanModuleData
-        strcpy((char *)ShmFanModuleData->version, ver.Version_FW);
+        strcpy((char*)ShmFanModuleData->version, ver.Version_FW);
         // SystemInfo
-        strcpy((char *)pSysInfo->FanModuleFwRev, ver.Version_FW);
+        strcpy((char*)pSysInfo->FanModuleFwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s1 = %s ", ver.Version_FW);
     }
 
     if (Query_HW_Ver(Uart5Fd, ADDR_FAN, &ver) == PASS) {
         // SystemInfo
-        strcpy((char *)pSysInfo->FanModuleHwRev, ver.Version_FW);
+        strcpy((char*)pSysInfo->FanModuleHwRev, ver.Version_FW);
         //log_info("GetFwAndHwVersion_Fan s2 = %s ", ver.Version_HW);
     }
 }
 
+static void fanBoardSelfTest(void)
+{
+    if (ShmFanModuleData->SelfTest_Comp == YES) {
+        return;
+    }
+
+    GetFwAndHwVersion_Fan();
+    SetModelName_Fan();
+    SetRtcData_Fan();
+    sleep(1);
+    gettimeofday(&gFanBoardRunTimer, NULL);
+}
+
 static void fanBoardPorcess(void)
 {
     if (ShmFanModuleData->SelfTest_Comp == NO) {
@@ -217,8 +230,8 @@ static void fanBoardPorcess(void)
     }
 
     if (ShmFanModuleData->SelfTest_Comp == YES ||
-            strlen((char *)pSysInfo->FanModuleFwRev) != 0 ||
-            pSysInfo->FanModuleFwRev[0] != '\0') {
+        strlen((char*)pSysInfo->FanModuleFwRev) != 0 ||
+        pSysInfo->FanModuleFwRev[0] != '\0') {
         ShmFanModuleData->SelfTest_Comp = YES;
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
@@ -239,19 +252,6 @@ static void fanBoardPorcess(void)
     }
 }
 
-static void fanBoardSelfTest(void)
-{
-    if (ShmFanModuleData->SelfTest_Comp == YES) {
-        return;
-    }
-
-    GetFwAndHwVersion_Fan();
-    SetModelName_Fan();
-    SetRtcData_Fan();
-    sleep(1);
-    gettimeofday(&gFanBoardRunTimer, NULL);
-}
-
 void FanBoardTask(int uartFD)
 {
 #if defined NO_FAN_BOARD || defined DD360ComBox

+ 13 - 6
EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c

@@ -25,7 +25,7 @@ static DcCommonInfo *ShmDcCommonData = NULL;
 static struct WARNING_CODE_INFO *pSysWarning = NULL;
 static struct LedModuleData *ShmLedModuleData = NULL;
 static struct FanModuleData *ShmFanModuleData = NULL;
-
+static struct GBTData* ShmGBTData = NULL;
 static Relay outputRelay = {0};
 static Relay regRelay = {0};
 static int Uart5Fd = 0;
@@ -362,10 +362,17 @@ static void GetGfdAdc(void)
 void CheckOutputPowerOverCarReq(uint8_t index)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
-
+    ShmGBTData = (struct GBTData*)GetShmGBTData();
     float fireV = pDcChargingInfo->FireChargingVoltage;
     float carV = pDcChargingInfo->EvBatteryMaxVoltage * 10;
-
+    /*
+    log_info("PresentChargingVoltage:%f, FireChargingVoltage:%f ", pDcChargingInfo->PresentChargingVoltage * 10, pDcChargingInfo->FireChargingVoltage);
+    log_info("fireV:%f, carV:%f, _isOvpChkTimeFlag:%d", fireV, carV, _isOvpChkTimeFlag[index]);
+    log_info("EvBatterytargetVoltage:%f", pDcChargingInfo->EvBatterytargetVoltage);
+    if (pDcChargingInfo->Type == _Type_GB) {
+        log_info("GB EV Board Status:%d", ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus);
+    }
+    */
     if ((pDcChargingInfo->EvBatterytargetVoltage * 10) > 1500 &&
             (pDcChargingInfo->Type == _Type_Chademo ||
              pDcChargingInfo->Type == _Type_CCS_2 ||
@@ -1399,16 +1406,16 @@ static void fanBoardPorcess(void)
 
         if (GetTimeoutValue(gFanBoardRunTimer) / 1000 >= 1000) {
             //GetPsuTempForFanSpeed();
-            GetFanSpeedByFunction();
+            //GetFanSpeedByFunction();
             GetFanSpeed();
             pSysInfo->SystemFanRotaSpeed = _setFanSpeed;
             gettimeofday(&gFanBoardRunTimer, NULL);
-
+            /*
             ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
             ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-
+            */
             //log_info("set fan = %d ", ShmFanModuleData->SetFan1Speed);
             SetFanModuleSpeed();
         }

+ 13 - 6
EVSE/Projects/DD360ComBox/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -1458,7 +1458,7 @@ void DisplayInfoConsumption(bool isShow)
         uint8_t value[20];
 
         memset(value, 0x00, sizeof(value));
-        strcpy((char*)value, "CSPT >");
+        strcpy((char*)value, "PWCT >");
         DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
         memset(value, 0x00, sizeof(value));
         data = ShmDcCommonData->pConsumption.Gun1_Consumption +
@@ -1742,8 +1742,7 @@ void ShowAnimationPrice(char* pString)
     memset(cmd, 0x00, sizeof(cmd));
     string2ByteArray((uint8_t*)pString,cmd);
     int len = strlen(pString);
-    if (len <= 0)
-        return;
+
     if (strcmp((char*)old_string, pString) != EQUAL) {
         strcpy((char*)old_string, pString);
         DisplayFeeValueToLcm(__Animation_Price, cmd, sizeof(cmd));
@@ -2064,8 +2063,11 @@ void ProcessPageInfo()
                     ChangeParkingFeeValue(ShmSelectGunInfo->PricesInfo[i].ParkingFee, _currentPage);
                     // Total Cost
                     ChangeTotalCostValue(pDcChargingInfo->ChargingFee, _currentPage);
-
-                    ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    if (pSysConfig->BillingData.isBilling) {
+                        ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    } else {
+                        ShowAnimationPrice("");
+                    }
                 }
             } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
@@ -2107,7 +2109,11 @@ void ProcessPageInfo()
                         ChangeTotalCostValue(pDcChargingInfo->ChargingFee, _currentPage);
                     }
 
-                    ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    if (pSysConfig->BillingData.isBilling) {
+                        ShowAnimationPrice(ShmDcCommonData->pGunInfo[i].UserPriceString);
+                    } else {
+                        ShowAnimationPrice("");
+                    }
                 }
             } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
                 if (pSysInfo->CurGunSelected == i) {
@@ -2285,6 +2291,7 @@ void ChangeDisplayMoneyInfo()
         ChangeDisplay2Value(__money_rate_map, _disappear);
         ChangeDisplay2Value(__money_by_rate, _disappear);
         ChangeDisplay2Value(__money_rate, _disappear);
+        ShowAnimationPrice("");
     }
 }
 

+ 6 - 2
EVSE/Projects/DD360ComBox/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -351,11 +351,13 @@ static void checkChillerStatus(Gpio_out *gpio)
     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)) {
         chillerCount++;
+        ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
     }
 
     if (chillerCount == 0) {
@@ -363,7 +365,9 @@ static void checkChillerStatus(Gpio_out *gpio)
         return;
     }
 
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        if (!ShmDcCommonData->pGunInfo[gunIndex].withChiller)
+            continue;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
@@ -413,7 +417,7 @@ static void checkChillerStatus(Gpio_out *gpio)
     }
 
     uint8_t _chillerNeedOn = NO;
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++)
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
         if(pChillerInfo->ChillerSwitch == YES)

+ 50 - 1
EVSE/Projects/DD360ComBox/Apps/ReadCmdline.c

@@ -1229,6 +1229,35 @@ void writeChillerStatus(char *v1)
     } else
         printf("Please open Debug mode\n");
 }
+
+void showNetworkPage(char* v1)
+{
+    ShmDcCommonData->showNetPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showNetPackage)
+        printf("Show Network Package on\n");
+    else
+        printf("Show Network Package off\n");
+}
+
+void showCANBUSPage(char* v1)
+{
+    ShmDcCommonData->showCanPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showCanPackage)
+        printf("Show CAN Bus Package on\n");
+    else
+        printf("Show CAN Bus Package off\n");
+}
+void setSystemTime(char* date,char* time)
+{
+    char _setTime[30];
+    char cmdBuf[50];
+    sprintf(_setTime, "%s %s", date, time);
+    printf("Set Timer:%s", _setTime);
+    sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
+    system((char*)cmdBuf);
+    system("hwclock -w -u");
+    system("hwclock -s");
+}
 static void writeGunAndChillerTemp(void)
 {
     uint8_t _GunIndex = 0;
@@ -1304,7 +1333,16 @@ static void writeGunAndChillerTemp(void)
         usleep(sleepTime);
     }//while
 }
+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)
 {
     uint8_t _GunIndex = 0;
@@ -1329,7 +1367,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"
+                     "       chiller                           : set chiller on/off\r\n"
+                     "       netdump                           : show network package\r\n"
+                     "       candump                           : show can package\r\n"
+                     "       powerconsumption                  : Show Power Consumption\n"
                      "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
@@ -1502,6 +1543,14 @@ int main(void)
             writeOTPTemp();
         } 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) { //印出網路封包
+            showCANBUSPage(newString[1]);
+        } else if (strcmp(newString[0], "time") == 0) {  //設定系統時間
+            setSystemTime(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "powerconsumption") == 0) { // Power Consumption
+            ShowPowerConsumption(newString[1]);
         } else {
             printf("%s\n", usageMsg);
         }

+ 1 - 0
EVSE/Projects/DD360ComBox/Apps/SelectGun/SelectGun.h

@@ -65,6 +65,7 @@ typedef struct StPricesInfo {
     int TransactionId;
     float EnergyCost;
     float ParkingFee;
+    float RemainAmount;
 } PricesInfo;
 
 //typedef struct StOperativeInfo {

+ 15 - 7
EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c

@@ -930,16 +930,15 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
         }
         break;
 
+    case 'V': // Liquid CCS1 combo
+    case 'F': // Liquid CCS2 combo
     case 'T': // Rema CCS1
     case 'D': // Rema CCS2
     case 'U': // CCS1 combo
     case 'E': // CCS2 combo
-    case 'V': // Liquid CCS1 combo
-    case 'F': // Liquid CCS2 combo
     case 'M': // 80A CCS2
     case 'N': // 80A CCS1
-    case 'P': // Phoenix CCS2 500A 水冷
-    case 'R': // Phoenix CCS1 500A 水冷
+    case 'P': // 急電弓
         if (CCS_QUANTITY > gGunIndexInfo.CcsIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[gGunIndexInfo.CcsIndex];
 
@@ -959,16 +958,25 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichta
                 gGunIndexInfo.CcsIndex++;
                 gGunIndexInfo.DcGunIndex++;
             }
-            if(typeValue == 'P')
-            {
+            if(typeValue == 'P') {
                 pDcChargingInfo->PantographFlag = YES;
-            }
+            } else if (typeValue == 'V') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Liquid;
+            } else if (typeValue == 'F') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Liquid;
+            } else if (typeValue == 'T' || typeValue == 'U' || typeValue == 'N') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS1_Natural;
+            } else if (typeValue == 'D' || typeValue == 'E' || typeValue == 'M') {
+                pDcChargingInfo->CCSGunType = _TYPE_CCS2_Natural;
+            } else
+                pDcChargingInfo->CCSGunType = _TYPE_CCS_NONE;
         } else {
             result = false;
         }
         break;
 
     case 'G':  // GBT DC
+    case 'B': // GBT YG PT100
         if (GB_QUANTITY > gGunIndexInfo.GbIndex) {
             pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex];
 

+ 31 - 0
build_rootfs_copy.sh

@@ -0,0 +1,31 @@
+#!/bin/bash
+# Absolute path to this script, e.g. /home/user/bin/foo.sh
+SCRIPT=$(readlink -f "$0")
+
+# Absolute path this script is in, thus /home/user/bin
+SCRIPTPATH=$(dirname "$SCRIPT")
+echo $SCRIPTPATH
+
+ProjectPath="/opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects"
+
+
+sudo rm /dev/ram*
+sleep 3
+sudo cp -r /mnt/d/Phihong/Project/DD360Audi/Apps/* $ProjectPath/DD360Audi/Apps/
+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;
+
+#sudo make DD360Audi-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360Audi/Images/* /mnt/e/Image/DD360Audi/
+sudo make DD360-rootfs
+cp $ProjectPath/DD360/Images/* /mnt/d/Image/DD360/
+#sudo make DD360ComBox-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360ComBox/Images/* /mnt/e/Image/DD360ComBox/
+#sudo make DD360UCar-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360UCar/Images/* /mnt/d/Image/DD360UCar/
+