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

2022-06-16 / Simon Xue

Action:
1. [Mod] Online Pay process.
2. [Fix] Online Pay and Offline Pay process. (Only keep Online Pay)
3. [Mod] Credit Card Preauth and PreAuthCancel process.
4. [Mod] Deduct database lineSn will store LineStatus.
5. [Add] Rededuct information from Cabinet. (DoComm register:0x26)

Files
As the following commit history files

Image Version:V2.12.XX.XXXX.XX
Simon Xue 2 жил өмнө
parent
commit
c602d174de
35 өөрчлөгдсөн 1530 нэмэгдсэн , 785 устгасан
  1. 1 1
      EVSE/Projects/DD360Tcci/Apps/CSU/Ethernet.c
  2. 5 5
      EVSE/Projects/DD360Tcci/Apps/CSU/OCPP.c
  3. 146 162
      EVSE/Projects/DD360Tcci/Apps/CSU/RFID.c
  4. 377 185
      EVSE/Projects/DD360Tcci/Apps/CSU/main.c
  5. 3 3
      EVSE/Projects/DD360Tcci/Apps/CSU/main.h
  6. 34 6
      EVSE/Projects/DD360Tcci/Apps/Config.h
  7. 173 9
      EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.c
  8. 6 1
      EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.h
  9. 2 2
      EVSE/Projects/DD360Tcci/Apps/Define/define.c
  10. 169 52
      EVSE/Projects/DD360Tcci/Apps/Define/define.h
  11. 3 3
      EVSE/Projects/DD360Tcci/Apps/ModuleChkSysTask/Module_ChkSysTask.c
  12. 202 123
      EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.c
  13. 25 4
      EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.h
  14. 53 53
      EVSE/Projects/DD360Tcci/Apps/ModuleEvComm/Module_EvRxComm.c
  15. 83 22
      EVSE/Projects/DD360Tcci/Apps/ModuleEvComm/Module_EvTxComm.c
  16. 32 62
      EVSE/Projects/DD360Tcci/Apps/ModuleInternalComm/RelayBoard.c
  17. 12 9
      EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Lcm_Update.c
  18. 143 70
      EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.c
  19. 1 0
      EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.h
  20. 26 13
      EVSE/Projects/DD360Tcci/Apps/ReadCmdline.c
  21. 3 0
      EVSE/Projects/DD360Tcci/Apps/SelectGun/SelectGun.h
  22. BIN
      EVSE/Projects/DD360Tcci/Images/ramdisk.gz
  23. BIN
      EVSE/Projects/DD360Tcci/output/FactoryConfig
  24. BIN
      EVSE/Projects/DD360Tcci/output/Module_ChkSysTask
  25. BIN
      EVSE/Projects/DD360Tcci/output/Module_DoComm
  26. BIN
      EVSE/Projects/DD360Tcci/output/Module_EvComm
  27. BIN
      EVSE/Projects/DD360Tcci/output/Module_EventLogging
  28. BIN
      EVSE/Projects/DD360Tcci/output/Module_InternalComm
  29. BIN
      EVSE/Projects/DD360Tcci/output/Module_LcmControl
  30. BIN
      EVSE/Projects/DD360Tcci/output/Module_PrimaryComm
  31. BIN
      EVSE/Projects/DD360Tcci/output/Module_UpdateFW
  32. BIN
      EVSE/Projects/DD360Tcci/output/ReadCmdline
  33. BIN
      EVSE/Projects/DD360Tcci/output/main
  34. BIN
      EVSE/rootfs/root/Module_PowerSharing
  35. 31 0
      build_rootfs_copy.sh

+ 1 - 1
EVSE/Projects/DD360Tcci/Apps/CSU/Ethernet.c

@@ -98,7 +98,7 @@ static int isReachableInternet(void)
         while (fgets(buf, sizeof(buf), fp) != NULL) {
             if (strstr(buf, "inet addr:") > 0) {
                 sscanf(buf, "%*s%s", tmp);
-                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
+                substr(tmp, tmp, strspn(tmp, "addr:"), strlen(tmp) - strspn(tmp, "addr:"));
 
                 if (strcmp(tmp, (char *)pSysConfig->Eth0Interface.EthIpAddress) != EQUAL) {
                     strcpy((char *) pSysConfig->Eth0Interface.EthIpAddress, tmp);

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

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

+ 146 - 162
EVSE/Projects/DD360Tcci/Apps/CSU/RFID.c

@@ -9,7 +9,7 @@
 #include "../ShareMemory/shmMem.h"
 #include "../SelectGun/SelectGun.h"
 #include "../DataBase/DataBase.h"
-
+#include <math.h>
 #include "main.h"
 #include "../timeout.h"
 static DcCommonInfo *ShmDcCommonData 			= NULL;
@@ -24,6 +24,15 @@ static char *rfidPortName = "/dev/ttyS2";
 static bool isCardScan = false;
 
 //------------------------------------------------------------------------------
+int checkRemoteStart(int gunIndex)
+{
+    if (ShmDcCommonData->is_RemoteStart[gunIndex] ||
+        ShmDcCommonData->TransactionInfo[gunIndex].LineStatus == _LINE_PAY_INVOICE ||
+        ShmDcCommonData->TransactionInfo[gunIndex].LineStatus == _LINE_PAY_DONATE) {
+        return TRUE;
+    }
+    return FALSE;
+}
 static bool canStartCharging(void)
 {
     uint8_t index = 0;
@@ -128,31 +137,20 @@ bool RfidStopCharging(void)
     }
     return false;
 }
-static void UserScanFunction(void)
+static void UserScanFunction(int gunIndex)
 {
-   // bool idleReq = false;
-    //uint8_t i = 0;
-    //uint8_t stopReq = NO_DEFINE;
-    //char value[32] = {0};
-    //static uint8_t _authorizeIndex = NO_DEFINE;
+
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     //struct ChargingInfoData *pAcChargingInfo =  (struct ChargingInfoData *)GetAcChargingInfoData(0);
     struct ChargingInfoData *pDcChargingInfo = NULL;
-    //GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
+    ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
 
     // 當前非驗證的狀態
     if (IsAuthorizingMode()) {
         isAutorCompleteHandle(/*&_authorizeIndex*/);
     }
 
-    //當前沒有選槍
-    /*
-    if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) {
-        strcpy((char *)pSysConfig->UserId, "");
-        return;
-    }*/
-
     // 先判斷現在是否可以提供刷卡
     // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
     // 2. 停止充電
@@ -161,88 +159,18 @@ static void UserScanFunction(void)
         strcpy((char *)pSysConfig->UserId, "");
         return;
     }
-    /*
-    for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
-
-        if (pDcChargingInfo->SystemStatus == S_CHARGING) {
-            stopReq = i;
-        }
-
-        if ((pDcChargingInfo->SystemStatus == S_AUTHORIZING &&
-                pDcChargingInfo->IsAvailable == YES) ||
-                (pGunIndexInfo->AcGunIndex > 0 &&
-                 pAcChargingInfo->SystemStatus == S_AUTHORIZING &&
-                 pAcChargingInfo->IsAvailable)
-           ) {
-            idleReq = true;
-        }
-    }
 
-    if (pGunIndexInfo->AcGunIndex > 0 &&
-            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-            pAcChargingInfo->SystemStatus == S_CHARGING) {
-        stopReq = DEFAULT_AC_INDEX;
-    }
-     */
     if (strlen((char *)pSysConfig->UserId) <= 0) {
         return;
     }
 
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-
-    // Stop Charging For AC
-    /*if (pGunIndexInfo->AcGunIndex > 0 &&
-            stopReq == DEFAULT_AC_INDEX &&
-            pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-        log_info("ac stop charging ");
-        log_info("index = %d, card number = %s, UserId = %s ",
-                 pSysInfo->CurGunSelectedByAc,
-                 pAcChargingInfo->StartUserId,
-                 pSysConfig->UserId);
-
-        memset(value, 0, sizeof(value));
-        memcpy(value,
-               (uint8_t *)pAcChargingInfo->StartUserId,
-               ARRAY_SIZE(pAcChargingInfo->StartUserId));
-        if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) {
-            AcChargingTerminalProcess();
-        }
-        strcpy((char *)pSysConfig->UserId, "");
-    } else if (stopReq < pSysConfig->TotalConnectorCount &&
-               pDcChargingInfo->SystemStatus == S_CHARGING &&
-               (pGunIndexInfo->AcGunIndex <= 0 ||
-                (pGunIndexInfo->AcGunIndex > 0 &&
-                 pSysInfo->CurGunSelectedByAc == NO_DEFINE))
-              ) {
-    	// Stop Charging
-        if (RfidStopCharging())
-            return;
-        if (pGunIndexInfo->AcGunIndex > 0 &&
-                pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) {
-            _authorizeIndex = pSysInfo->CurGunSelectedByAc;
-        } else {
-            _authorizeIndex = pSysInfo->CurGunSelected;
-        }
-
-        strcpy((char *)pSysConfig->UserId, "");
-        return;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-    } else if (idleReq) {
-        if (pSysConfig->TotalConnectorCount > 1 &&
-                stopReq != 255 &&
-                pSysInfo->IsAlternatvieConf == YES) {
-            idleReq = false;
-            strcpy((char *)pSysConfig->UserId, "");
-        } else if ((pGunIndexInfo->AcGunIndex > 0 &&
-                    pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-                   pDcChargingInfo->SystemStatus == S_AUTHORIZING) {*/
     if ( (pSysInfo->SystemPage == _PAGE_AUTHORIZE ||
-    		pSysInfo->SystemPage == _PAGE_SENSING) &&
-    		pDcChargingInfo->SystemStatus == S_IDLE) {
+    		pSysInfo->SystemPage == _PAGE_SENSING)) {
             log_info("// LCM => Authorizing");
-            confirmSelGun(pSysInfo->CurGunSelected);
-            setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
+            confirmSelGun(gunIndex);
+            setSelGunWaitToAuthor(gunIndex);
             StartSystemTimeoutDet(Timeout_Authorizing);
             AuthorizingStart();
 			pDcChargingInfo->SystemStatus = S_AUTHORIZING;
@@ -267,55 +195,69 @@ void SetIsCardScan(bool value)
 {
     isCardScan = value;
 }
-void AuthorizeToCharge()
+void AuthorizeToCharge(int gunIndex)
 {
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-   // SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-   // struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);;
-
+    struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+
+
+    if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
+        if (strcmp((char*)pSysConfig->UserId, (char*)ShmDcCommonData->pGunInfo[gunIndex].ReservationID) != EQUAL) {
+            log_info("LCM => Authorize fail");
+            ShmDcCommonData->TradeCancel = TRUE;
+            ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
+            ShmDcCommonData->PreAuth_Result = 0;
+            pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+            strcpy((char*)pSysConfig->UserId, "");
+            ClearAuthorizedFlag();
+            return;
+        }
+    }
     if(isAuthorizedComplete())
     {
         if (canStartCharging()) {
-
-            DetectPluginStart();
-            if (ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] == TRUE && 
+            DetectPluginStart(gunIndex);
+            if (ShmDcCommonData->AuthPass_flag[gunIndex] == TRUE &&
                 ShmDcCommonData->TradeCancel == FALSE) {
                 pSysInfo->SystemPage = _PAGE_PLUGIN;
             }
 
         } else {
+            struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
             log_info("LCM => Authorize fail");
             ShmDcCommonData->TradeCancel = TRUE;
             ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
             ShmDcCommonData->PreAuth_Result = 0;
-            pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+            if (!pDcChargingInfo->RemoteStartFlag || !pDcChargingInfo->isRemoteStart)
+                pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
             strcpy((char *)pSysConfig->UserId, "");
         }
         ClearAuthorizedFlag();
     }
 }
-void ScannerCardProcess(void)
+void ScannerCardProcess(int gunIndex)
 {
     //struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
     struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
     struct ChargingInfoData *pDcChargingInfo = NULL;
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
-    if (!isDetectPlugin() && (pSysInfo->SystemPage == _PAGE_SENSING ||
+    if (!isDetectPlugin(gunIndex) && (pSysInfo->SystemPage == _PAGE_SENSING ||
     		pSysInfo->SystemPage == _PAGE_AUTHORIZE ) &&
-    		pDcChargingInfo->SystemStatus == S_IDLE &&
+    		(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION )&&
             pSysWarning->Level != WARN_LV_ER ) {
-    	//setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
+    	//setSelGunWaitToAuthor(gunIndex);
         isCardScan = true;
         // 處理刷卡及驗證卡號的動作
-        UserScanFunction();
+        UserScanFunction(gunIndex);
     }
 
-    if (pDcChargingInfo->SystemStatus == S_AUTHORIZING && pSysInfo->SystemPage == _PAGE_SENSING ) {
-        AuthorizeToCharge();
+    if (pDcChargingInfo->SystemStatus == S_AUTHORIZING && pSysInfo->SystemPage == _PAGE_SENSING &&
+        !ShmDcCommonData->is_RemoteStart[gunIndex] ) {
+        AuthorizeToCharge(gunIndex);
     } else if (pSysInfo->SystemPage == _PAGE_AUTHORIZE_FAIL) {
         StartSystemTimeoutDet(Timeout_VerifyFail);
         isCardScan = false;
@@ -414,8 +356,10 @@ void ReDeductProcess(int fd)
     if (rededuct_num == 0) {
         //log_info("No Rededuct Information");
     } else {
+        ShmDcCommonData->CreditCardUpload = TRUE;
+        pSysInfo->SystemPage = _PAGE_PAYING;
         log_info("Rededuct Total Number:%d", rededuct_num);
-        for (j = 0; j < rededuct_num; j++) {
+        for (j = rededuct_num-1; j >= 0 ; j--) {
             sleep(10);
             /*
             if (pSysInfo->SystemPage != _PAGE_IDLE && !ShmDcCommonData->Exe_ReDeduct) {
@@ -425,7 +369,8 @@ void ReDeductProcess(int fd)
             */
             log_info("Start Rededuct item [%d]",j);
             if (deductInfo[j].isIntoCharge == FALSE ||
-                (deductInfo[j].Energy == 0 && deductInfo[j].Amount == 0)) {
+                (deductInfo[j].Energy == 0 && deductInfo[j].Amount == 0) ||
+                (deductInfo[j].LineStatus == _LINE_PAY_DONATE || deductInfo[j].LineStatus == _LINE_PAY_INVOICE)) {
                 // 未進入充電或度數等於零
                 result = CreditCardPreAuthCancel(fd, PREAUTHMONEY, &pSysConfig->ModelName[0],
                     &deductInfo[j].pCreditCard.ApprovalNo[0],
@@ -439,10 +384,8 @@ void ReDeductProcess(int fd)
             } else {
                 // 度數大於零
                 if (deductInfo[j].Amount == 0 && deductInfo[j].Energy > 0) {
-                    deductInfo[j].Amount = ceil(deductInfo[j].Energy * ShmDcCommonData->ChargingRate);
-                    if (deductInfo[j].Amount < 1)
-                        deductInfo[j].Amount = 1;
                     log_info("Error Close Charging recount amount:%.1f",deductInfo[j].Amount);
+                    continue;
                 }
                 result = CreditCardPreAuthComplete(fd, (int)deductInfo[j].Amount, &pSysConfig->ModelName[0],
                     &deductInfo[j].pCreditCard.VemData[0],
@@ -490,17 +433,30 @@ static int InitialRfidPort(void)
 
     return fd;
 }
+void RemoteStartCancelPreAuth(int sel_gun)
+{
+    log_info("Remote start need to cancel PreAuth");
+    memcpy(&ShmDcCommonData->RedeductBill, &ShmDcCommonData->TransactionInfo[sel_gun], sizeof(RecordTransactionInfo));
+    memset(&ShmDcCommonData->TransactionInfo[sel_gun], 0x00, sizeof(RecordTransactionInfo));
+    ShmDcCommonData->TransactionInfo[sel_gun].LineStatus = ShmDcCommonData->RedeductBill.LineStatus;
+    if (strcmp((char*)ShmDcCommonData->RedeductBill.pCreditCard.CardNo, "") != 0) {
+        log_info("Remote start get Wrong Authorize card:%s, vemData:%s",
+            ShmDcCommonData->RedeductBill.pCreditCard.CardNo,
+            ShmDcCommonData->RedeductBill.pCreditCard.VemData);
+        ShmDcCommonData->RedeductBill.DeductResult = _DEDUCT_PREAUTH;
+        ShmDcCommonData->RedeductBill.IsUpload = FALSE;
+        ShmDcCommonData->RedeductBill.ConnectorID = ShmDcCommonData->ConnectorID[sel_gun];
+        //InsertDeductInfo(sel_gun, &ShmDcCommonData->RedeductBill);
+    }
+}
 
 void CreateRfidFork(void)
 {
     pid_t rfidRecPid;
-    int rededuct_gunIndex[128];
-    RecordTransactionInfo deductInfo[128];
-    int rededuct_num = 0;
     int donate = 0;
     rfidRecPid = fork();
-    int j = 0;
     int sel_gun = 0;
+    int linestatus = 0;
     if (rfidRecPid == 0) {
         //char localTime[128] = {0};
         struct timeb SeqEndTime;
@@ -523,7 +479,7 @@ void CreateRfidFork(void)
         }
         int gunIndex;
         //int uploadIndex = 0;
-        int ReAuthComplete_Index = 0;
+        //int ReAuthComplete_Index = 0;
         //log_info("RFID fork Child's PID is %d", getpid());
         int result;
         int is_idle = TRUE;
@@ -544,38 +500,51 @@ void CreateRfidFork(void)
             is_idle = TRUE;
 			for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
 				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-				if (pDcChargingInfo->SystemStatus != S_IDLE && pDcChargingInfo->SystemStatus != S_FAULT) {
+
+
+                // 檢查電樁狀態是否為idle狀態
+				if (pDcChargingInfo->SystemStatus != S_IDLE ) {
 					is_idle = FALSE;
 				}
+                // 檢查使用者是否進行線上支付操作並且線下支付已完成
+                // 需進行取消預授權
+                if (checkRemoteStart(gunIndex) && ShmDcCommonData->AuthPass_flag[gunIndex] &&
+                    !ShmDcCommonData->PayPass_flag[gunIndex]) {
+                    RemoteStartCancelPreAuth(gunIndex);
+                    ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
+                }
+
                 if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && pDcChargingInfo->Replug_flag == TRUE) {
+                    // Remote Start of AutoStart ByPass Credit Card Reader
+                    if (ShmDcCommonData->DebugFlag == TRUE ||
+                        ShmDcCommonData->is_RemoteStart[gunIndex] == TRUE ||
+                        ShmDcCommonData->is_AutoStart[gunIndex] == TRUE) {
+                        pSysInfo->SystemPage = _PAGE_PLUGOUT;
+                        ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
+                        continue;
+                    }
                     ShmDcCommonData->StopCharge[gunIndex] = FALSE;
-                    log_info("Not Into Charging cancel Trade");
+                    log_info("Gun %d Not Into Charging cancel Trade",gunIndex);
                     StopGunInfoTimeoutDet(gunIndex);
                     ShmDcCommonData->TradeCancel = TRUE;
-                    pSysInfo->CurGunSelected = gunIndex;
                     pSysInfo->SystemPage = _PAGE_SENSING;
                     StartSystemTimeoutDet(Timeout_TradeCancel);
                     CreditCardCancelPreAuth(fd, gunIndex);
+                    pSysInfo->CurGunSelected = gunIndex;
                     pSysInfo->SystemPage = _PAGE_PLUGOUT;
                     StopSystemTimeoutDet();
                 } else {
-                    if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && ShmDcCommonData->finalcost_flag[gunIndex] &&
-                        (pSysInfo->SystemPage != _PAGE_AUTHORIZE && pSysInfo->SystemPage != _PAGE_SENSING)) {
+                    if (ShmDcCommonData->StopCharge[gunIndex] && ShmDcCommonData->finalcost_flag[gunIndex] &&
+                        ShmDcCommonData->PreAuth_Config != _CREDITCARD_CANCEL) {
                         ShmDcCommonData->StopCharge[gunIndex] = FALSE;
                         pSysInfo->CurGunSelected = gunIndex;
-                        if (pDcChargingInfo->Replug_flag == TRUE) {
-                            log_info("Not Into Charging cancel Trade");
-                            ShmDcCommonData->TradeCancel = TRUE;
-                            pSysInfo->SystemPage = _PAGE_SENSING;
-                            StartSystemTimeoutDet(Timeout_TradeCancel);
-                        } else
-                            pSysInfo->SystemPage = _PAGE_PAYING;
+                        pSysInfo->SystemPage = _PAGE_PAYING;
                         StopGunInfoTimeoutDet(gunIndex); //Timeout_FinalCost
 
                         // Remote Start of AutoStart ByPass Credit Card Reader
                         if (ShmDcCommonData->DebugFlag == TRUE ||
-                            ShmDcCommonData->is_RemoteStart[gunIndex] == TRUE ||
-                            ShmDcCommonData->is_AutoStart[gunIndex] == TRUE) {
+                            checkRemoteStart(gunIndex) ||
+                            ShmDcCommonData->is_AutoStart[gunIndex]) {
                             pSysInfo->SystemPage = _PAGE_COMPLETE;
                             ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
                             continue;
@@ -603,37 +572,47 @@ void CreateRfidFork(void)
             } else if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH /* && ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected]*/) {
                 sel_gun = pSysInfo->CurGunSelected;
                 donate = (int)ShmDcCommonData->TransactionInfo[sel_gun].IsDonateInvoice;
+                linestatus = (int)ShmDcCommonData->TransactionInfo[sel_gun].LineStatus;
                 memset(&ShmDcCommonData->TransactionInfo[sel_gun], 0x00, sizeof(RecordTransactionInfo));
                 ShmDcCommonData->TransactionInfo[sel_gun].IsDonateInvoice = (unsigned char)donate;
+                ShmDcCommonData->TransactionInfo[sel_gun].LineStatus = linestatus;
         		result = CreditCardPreAuth(fd, PREAUTHMONEY,&pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[sel_gun].pCreditCard);
-                if (!ShmDcCommonData->TradeCancel)
-                    StopSystemTimeoutDet();
-                if (ShmDcCommonData->TradeCancel == FALSE && result > 0) {
-                    pSysInfo->SystemPage = _PAGE_SENSING;
+
+                pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(sel_gun);
+                if (checkRemoteStart(sel_gun)) {
+                    RemoteStartCancelPreAuth(sel_gun);
+                } else {
+                    if (!ShmDcCommonData->TradeCancel)
+                        StopSystemTimeoutDet();
+                    if (ShmDcCommonData->TradeCancel == FALSE && result > 0) {
+                        pSysInfo->SystemPage = _PAGE_SENSING;
+                    }
+                    if (result > 0)
+                        sleep(3);
+
+                    ShmDcCommonData->PreAuth_Result = result;
+
+                    //result = 1;
+                    if (result > 0 && strcmp((char*)ShmDcCommonData->TransactionInfo[sel_gun].pCreditCard.CardNo, "") != 0) {
+
+                        ShmDcCommonData->AuthPass_flag[sel_gun] = TRUE;
+                        strncpy((char*)pSysConfig->UserId, (char*)ShmDcCommonData->TransactionInfo[sel_gun].pCreditCard.CardNo, 20);
+                        log_info("Authorize card:%s", pSysConfig->UserId);
+                        ShmDcCommonData->TransactionInfo[sel_gun].DeductResult = _DEDUCT_PREAUTH;
+                        ShmDcCommonData->TransactionInfo[sel_gun].IsUpload = FALSE;
+                        ShmDcCommonData->TransactionInfo[sel_gun].ConnectorID = ShmDcCommonData->ConnectorID[sel_gun];
+                        log_info("Line Status:%d", ShmDcCommonData->TransactionInfo[sel_gun].LineStatus);
+                        InsertDeductInfo(ShmDcCommonData->ConnectorID[sel_gun], &ShmDcCommonData->TransactionInfo[sel_gun]);
+                        log_info("PreAuth OK");
+                    } else if (result < 0) {
+                        if (ShmDcCommonData->TradeCancel == FALSE)
+                            pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+                        ShmDcCommonData->AuthPass_flag[sel_gun] = FALSE;
+                        memset(&ShmDcCommonData->TransactionInfo[sel_gun].pCreditCard, 0, sizeof(TransInfo));
+                        log_info("PreAuth Fail");
+                    }
+                    ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
                 }
-                sleep(3);
-
-                ShmDcCommonData->PreAuth_Result = result;
-				//result = 1;
-				if (result > 0 && strcmp(ShmDcCommonData->TransactionInfo[sel_gun].pCreditCard.CardNo,"") != 0 ) {
-
-					ShmDcCommonData->AuthPass_flag[sel_gun] = TRUE;
-                    strncpy((char*)pSysConfig->UserId, (char *)ShmDcCommonData->TransactionInfo[sel_gun].pCreditCard.CardNo, 20);
-                    log_info("Authorize card:%s", pSysConfig->UserId);
-                    ShmDcCommonData->TransactionInfo[sel_gun].DeductResult = _DEDUCT_PREAUTH;
-                    ShmDcCommonData->TransactionInfo[sel_gun].IsUpload = FALSE;
-                    ShmDcCommonData->TransactionInfo[sel_gun].ConnectorID = ShmDcCommonData->ConnectorID[sel_gun];
-                    InsertDeductInfo(ShmDcCommonData->ConnectorID[sel_gun], &ShmDcCommonData->TransactionInfo[sel_gun]);
-					log_info("PreAuth OK");
-				} else if (result < 0) {
-                    if (ShmDcCommonData->TradeCancel == FALSE)
-					    pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
-					ShmDcCommonData->AuthPass_flag[sel_gun] = FALSE;
-					memset(&ShmDcCommonData->TransactionInfo[sel_gun].pCreditCard, 0, sizeof(TransInfo));
-					log_info("PreAuth Fail");
-                    sleep(7);
-				}
-				ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
             }
 
             // 每30分鐘檢查補扣款
@@ -642,18 +621,20 @@ void CreateRfidFork(void)
             }
 
             if ((is_idle == TRUE &&
-                pSysInfo->SystemPage == _PAGE_IDLE &&
+                (pSysInfo->SystemPage == _PAGE_IDLE || pSysInfo->SystemPage == _PAGE_SELECT_GUN) &&
                 ShmDcCommonData->RoutineReduct == FALSE) || ShmDcCommonData->Exe_ReDeduct) {
-                ShmDcCommonData->CreditCardUpload = TRUE;
-                pSysInfo->SystemPage = _PAGE_PAYING;
+
                 ReDeductProcess(fd);
-                pSysInfo->SystemPage = _PAGE_IDLE;
+                if (ShmDcCommonData->TaiwanEast)
+                    pSysInfo->SystemPage = _PAGE_IDLE;
+                else
+                    pSysInfo->SystemPage = _PAGE_SELECT_GUN;
                 ShmDcCommonData->CreditCardUpload = FALSE;
                 ShmDcCommonData->Exe_ReDeduct = 0;
             }
 
             // 每日晚上11點30分結帳
-            if (is_idle == TRUE && pSysInfo->SystemPage == _PAGE_IDLE && 
+            if (is_idle == TRUE && (pSysInfo->SystemPage == _PAGE_IDLE || pSysInfo->SystemPage == _PAGE_SELECT_GUN) &&
                 ((tm->tm_hour == 15 && tm->tm_min > 30  && ShmDcCommonData->RoutineSettlement == FALSE) ||
                     ShmDcCommonData->UnionSettlement)) {
                 StopSystemTimeoutDet();
@@ -671,7 +652,10 @@ void CreateRfidFork(void)
                 else
                     log_info("CreditCardUnionSettlement FAIL");
                 sleep(90);
-                pSysInfo->SystemPage = _PAGE_IDLE;
+                if (ShmDcCommonData->TaiwanEast)
+                    pSysInfo->SystemPage = _PAGE_IDLE;
+                else
+                    pSysInfo->SystemPage = _PAGE_SELECT_GUN;
                 ShmDcCommonData->CreditCardUpload = FALSE;
             }
             if (tm->tm_hour == 16 && tm->tm_min == 0) {

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 377 - 185
EVSE/Projects/DD360Tcci/Apps/CSU/main.c


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

@@ -45,7 +45,7 @@
 #define TERMINATING_TIMEOUT                     (120)
 #define WHILE_LOOP_TIME                         (10000)
 #define PRECHARGING_TTIMEOUT                    (60)
-#define PLUGOUTGUN_TIMEOUT                      (30)
+#define PLUGOUTGUN_TIMEOUT                      (10)
 #define TCC_ADDLINE_TIMEOUT						(60)
 #define TCC_LINEREGISTER_TIMEOUT				(60)
 #define TCC_DONATECOMFIRM_TIMEOUT				(180)
@@ -74,7 +74,7 @@
 //} LedConfig;
 
 //------------------------------------------------------------------------------
-bool isDetectPlugin(void);
+bool isDetectPlugin(int gunIndex);
 void _DetectPlugInTimeout(uint8_t gunIndex);
 void _evccidlinktimeout(uint8_t gunIndex);
 void StartSystemTimeoutDet(uint8_t flag);
@@ -87,7 +87,7 @@ void AuthorizingStart(void);
 bool IsAuthorizingMode(void);
 bool isAuthorizedComplete(void);
 void ClearAuthorizedFlag(void);
-void ClearDetectPluginFlag(void);
+void ClearDetectPluginFlag(int gunIndex);
 
 void ChargingAlarmProcess(uint8_t gunIndex);
 void StopChargingProcessByString(uint8_t level);

+ 34 - 6
EVSE/Projects/DD360Tcci/Apps/Config.h

@@ -303,6 +303,21 @@ enum _CREDIT_DEDUCT_STATUS {
     _DEDUCT_COMPLETE_PASS = 1,
     _DEDUCT_CANCEL,
     _DEDUCT_PREAUTH,
+    _DEDUCT_REMOTESTART,
+};
+enum _LINE_STATUS {
+    _LINE_INIT = 0,
+    _LINE_SCAN_QR,
+    _LINE_ADD_FRIEND,
+    _LINE_CREDITCARD_INVOICE,
+    _LINE_CREDITCARD_DONATE,
+    _LINE_PAY_INVOICE = 7,
+    _LINE_PAY_DONATE,
+    _LINE_PAY_OPERATE,
+};
+enum _DERATING_TEMP {
+    _DERATING_80 = 140,
+    _DERATING_85 = 145,
 };
 //------------------------------------------------------------------------------
 //struct StructMeter {
@@ -429,7 +444,7 @@ typedef struct StGunInfo {
     char ChargeStopTime[32];
     char ChargeDuration[32];
     uint8_t withChiller;      //是否有水冷機
-    int EVStatus;          // ev小板狀態
+    uint8_t WaitForPlugit;    // 等待插槍FLAG
 } GunInfo;
 
 typedef struct Psu_VersionInfo{
@@ -471,8 +486,18 @@ typedef struct stRecordTransactionInfo
     float Energy;
     float prices;
     int RedeductTime;
+    int LineStatus;                        // Line State
 }RecordTransactionInfo;
 
+typedef struct stPriceBillInfo {
+    float TotalCost;
+    float Balance;
+    float Discount;
+    int TransactionId;
+    float EnergyCost;
+    float ParkingFee;
+    float RemainAmount;
+}PriceBillInfo;
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -506,8 +531,7 @@ typedef struct StDcCommonInfo {
     uint8_t PSU_Number;
     PsuVerInfo PsuVer[12];
 
-
-    int WeatherID;
+    int WeatherID; // 0:sun, 1:cloudy, 2:rain, 3:snow, 4:storm, 5:fog
     float Temperature;
     int Location;
     char PresentTime[128];
@@ -517,13 +541,16 @@ typedef struct StDcCommonInfo {
     float ChargingRate;
     int PreAuth_Config;
     int PreAuth_Result;
-    int LineStatus[2];
     unsigned int AuthPass_flag[2];
     unsigned int PayPass_flag[2];
     unsigned int StopCharge[2];
     unsigned int TradeCancel;
     int ConnectorID[2];
+
     RecordTransactionInfo TransactionInfo[2];
+    RecordTransactionInfo RedeductBill;
+    PriceBillInfo PriceBill;
+
     int UnionSettlement;
     int Exe_ReDeduct;
     unsigned int OperateIDLE[2];
@@ -531,7 +558,6 @@ typedef struct StDcCommonInfo {
     int RoutineSettlement;
     int RoutineReupload;
     int TZOffset;
-    int ClearServiceQR;
     int DebugFlag;
     int chillerCtrl;
     int is_RemoteStart[2];
@@ -547,7 +573,9 @@ typedef struct StDcCommonInfo {
     char DefaultPriceString[255];
     PowerConsumptionValue pConsumption;
     uint8_t CreditCardUpload;
-    uint8_t passbackend;
+    uint8_t tccdev;
+    uint8_t TaiwanEast;
+    uint8_t lcmtest;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 173 - 9
EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.c

@@ -12,11 +12,12 @@
 //------------------------------------------------------------------------------
 #define DB_FILE                                 "/Storage/ChargeLog/localCgargingRecord.db"
 #define DEDUCT_FILE                 			"/Storage/ChargeLog/CreditCardRecord.db"
-
+#define POWER_FILE                 			    "/Storage/ChargeLog/PowerConsumption.db"
 //------------------------------------------------------------------------------
 static sqlite3 *localDb;
 static sqlite3 *deductDb;
-
+static sqlite3* powerDb;
+static DcCommonInfo* ShmDcCommonData = NULL;
 //------------------------------------------------------------------------------
 //===============================================
 // SQLite3 related routine
@@ -101,6 +102,7 @@ int DB_Open(void)
         sqlite3_close(localDb);
     }
 
+    ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     return result;
 }
 
@@ -383,7 +385,7 @@ int DeductDB_Open(void)
 	}
 	else
 	{
-		log_info("Deduct database open successfully.");
+		//log_info("Deduct database open successfully.");
 		if (sqlite3_exec(deductDb, createDeductInfoSql, 0, 0, &errMsg) != SQLITE_OK)
 		{
 			result = FAIL;
@@ -428,11 +430,11 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
     strncpy(storeId, (char *)&deductInfo->pCreditCard.StoreId,18 );
     strncpy(RRN,(char *)&deductInfo->pCreditCard.RRN,12);
     strncpy(ROC,(char *)&deductInfo->pCreditCard.ROC,12);
-    CreditCardTimeSet(&_time, deductInfo);
+    CreditCardTimeSet(&_time[0], deductInfo);
     //sprintf(reportDate, "%s%s", deductInfo->pCreditCard.TransDate, deductInfo->pCreditCard.TransTime);
 
 	sprintf(sqlStr, "insert into report_credit_deduct(gun_index, reportDate, vemData, txId, creditNo, amount, storeId, approvalNo, RRN, ROC, isDonateInvoice, isDeductResult, isIntoCharge, isUpload, lineSn, Energy, RedeductTime) "
-				    "values('%d', '%s', '%s', '%d', '%s', '%.1f', '%s', '%s', '%s', '%s', '%d', '%d', '%d' , '%d', '%s', '%.4f', '%d');",
+				    "values('%d', '%s', '%s', '%d', '%s', '%.1f', '%s', '%s', '%s', '%s', '%d', '%d', '%d' , '%d', '%d', '%.4f', '%d');",
                     gunIndex,
                     _time,
 				    vemData,
@@ -447,7 +449,7 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
                     (int)deductInfo->DeductResult,
                     (int)deductInfo->isIntoCharge,
                     (int)deductInfo->IsUpload,
-                    lineSn,
+                    deductInfo->LineStatus,
                     deductInfo->Energy,
                     deductInfo->RedeductTime);
 
@@ -492,21 +494,22 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
 
 int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo)
 {
+
     int result = PASS;
     char *errMsg = NULL;
     char sqlStr[1024] = {0};
     char vemData[65] = {0};
-    char _time[20] = { 0 };
     memset(vemData, '\0', 65);
     strncpy(vemData, (char*)&deductInfo->pCreditCard.VemData,64);
 
-    sprintf(sqlStr, "update report_credit_deduct set isUpload = %d , isIntoCharge = %d, amount = %.1f, txId = %d, isDeductResult = %d, Energy = %.4f, RedeductTime = %d where vemData = '%s'; ",
+    sprintf(sqlStr, "update report_credit_deduct set isUpload = %d , isIntoCharge = %d, amount = %.1f, txId = %d, isDeductResult = %d, Energy = %.4f, lineSn = %d, RedeductTime = %d where vemData = '%s'; ",
                     (int)deductInfo->IsUpload,
                     (int)deductInfo->isIntoCharge,
                     deductInfo->Amount,
                     deductInfo->TransactionId,
                     (int)deductInfo->DeductResult,
                     deductInfo->Energy,
+                    deductInfo->LineStatus,
                     deductInfo->RedeductTime,
                     vemData);
 
@@ -537,6 +540,41 @@ int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo)
     return result;
 }
 
+int UpdateRedeuctBill(int Txid,float amount)
+{
+    int result = PASS;
+    char* errMsg = NULL;
+    char sqlStr[1024] = { 0 };
+
+    sprintf(sqlStr, "update report_credit_deduct set amount = %.1f where txId = '%d'; ",
+            amount,
+            Txid);
+
+    //log_info("%s",sqlStr);
+
+    if (sqlite3_open(DEDUCT_FILE, &deductDb))
+    {
+        result = FAIL;
+        log_info("Can't open deduct database: %s", sqlite3_errmsg(deductDb));
+        sqlite3_close(deductDb);
+    } else
+    {
+        //log_info( "Local event record database open successfully.");
+        if (sqlite3_exec(deductDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+        {
+            result = FAIL;
+            log_info("update deduct record error message: %s!", errMsg);
+        } else
+        {
+            //log_info( "update deduct record successfully");
+        }
+
+        sqlite3_close(deductDb);
+    }
+
+    return result;
+}
+
 int DB_GetDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo)
 {
     int result = PASS;
@@ -702,7 +740,7 @@ int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, Reco
                 deductInfo[idxRow - 1].DeductResult = atoi(rs[(idxRow * cols) + 12]);
                 deductInfo[idxRow - 1].isIntoCharge = atoi(rs[(idxRow * cols) + 13]);
                 deductInfo[idxRow - 1].IsUpload = atoi(rs[(idxRow * cols) + 14]);
-                // 15: LineSN
+                deductInfo[idxRow - 1].LineStatus = atoi(rs[(idxRow * cols) + 15]);
                 deductInfo[idxRow - 1].Energy = atof(rs[(idxRow * cols) + 16]);
                 deductInfo[idxRow - 1].RedeductTime = atoi(rs[(idxRow * cols) + 17]);
                 if(idxRow >= 128)
@@ -753,4 +791,130 @@ void ReDeductTest()
 			printf("Gun %d Rededuct CardNo: %s", gunList[i], deductInfo[i].pCreditCard.VemData);
 		}
 	}
+}
+
+int PowerDB_Open(void)
+{
+    int result = PASS;
+    char* errMsg = NULL;
+    char* createPowerConsumption = "CREATE TABLE IF NOT EXISTS power_consumption( "
+        "idx INTEGER PRIMARY KEY AUTOINCREMENT, "
+        "connector TEXT, "
+        "val TEXT);";
+
+    if (sqlite3_open(POWER_FILE, &powerDb))
+    {
+        result = FAIL;
+        log_info("Can't open deduct database: %s", sqlite3_errmsg(powerDb));
+        sqlite3_close(powerDb);
+    } else
+    {
+        if (sqlite3_exec(powerDb, 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");
+        }
+
+        sqlite3_close(powerDb);
+    }
+
+    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(POWER_FILE, &powerDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(powerDb));
+        sqlite3_close(powerDb);
+    } 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(powerDb, 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(powerDb);
+    }
+
+    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(POWER_FILE, &powerDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(powerDb));
+        sqlite3_close(powerDb);
+    } 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(powerDb, 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(powerDb);
+    }
+
+    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(POWER_FILE, &powerDb)) {
+        result = FAIL;
+        log_info("Can't open database: %s", sqlite3_errmsg(powerDb));
+        sqlite3_close(powerDb);
+    } else {
+        log_info("Local config query database open successfully.");
+        sqlite3_get_table(powerDb, 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(powerDb);
+    }
+
+    return result;
 }

+ 6 - 1
EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.h

@@ -13,13 +13,18 @@ int DB_Reboot_Record(void);
 int CreateEventRecord(void);
 int InsertEventRecord(uint8_t *statusCode);
 
+int PowerDB_Open(void);
+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);
+
 int DeductDB_Open(void);
 int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo);
 int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo);
 int DB_GetDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo);
 int DB_GetReDeductInfo(int *gunIndex, RecordTransactionInfo *deductInfo);
 int DB_GetReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo);
-
+int UpdateRedeuctBill(int Txid, float amount);
 int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo);
 int DB_GetMultiReDeductInfo(int *gunIndex, RecordTransactionInfo *deductInfo);
 int DB_GetMultiReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo);

+ 2 - 2
EVSE/Projects/DD360Tcci/Apps/Define/define.c

@@ -241,7 +241,7 @@ char AlarmStatusCode[160][6]=
 "012329",   // Psu Can Communication Fault
 "012330",   // Psu Dc to Dc OTP
 "012331",   // Psu Dc to Dc OVP
-"012332",   // reserved
+"012332",   // Chiller Tube OTP
 "012333",   // reserved
 "012334",   // reserved
 "012335",   // reserved
@@ -256,7 +256,7 @@ char AlarmStatusCode[160][6]=
 "012344",   // AC: Meter IC communication timeout
 "012345",   // AC: Pilot negative error
 "012346",   // Psu Communication error with CSU
-"012347",   // reserved
+"012347",   // AC: Local power sharing communication error (Slave disconnect from Master)
 "012348",   // reserved
 "012349",   // reserved
 "012350",   // reserved

+ 169 - 52
EVSE/Projects/DD360Tcci/Apps/Define/define.h

@@ -187,7 +187,8 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #define ShmOcpp20ModuleKey		1012
 #define ShmRelay2BdKey			1013
 #define ShmYesCustomKey         1014
-#define ShmOcppPHModuleKey		1015
+#define ShmOcppPHModuleKey      1015
+#define ShmSmartBoxKey          1016
 
 #define FaultCodeLength         5
 #define AlarmCodeLength         20
@@ -328,10 +329,11 @@ enum CoreProfile {
      MaintainServer,
      StatusNotificationPeriodically,
      StatusNotificationInterval,
-	 PreAuthAmount,
-	 isEnableLocalPowerSharing,
-	 PowerSharingServerIP,
-	 EVCCID_PREFIX,
+     PreAuthAmount,
+     isEnableLocalPowerSharing,
+     PowerSharingServerIP,
+     EVCCID_PREFIX,
+     OffLineMaxChargingPower,
      ConfigurationVersion,
 	 _CoreProfile_CNT
 };
@@ -345,10 +347,10 @@ enum OCPP_START_ID_TYPE {
     IdTokenType_Central=0,
     IdTokenType_eMAID,
     IdTokenType_ISO14443,
-	IdTokenType_ISO15693,
+    IdTokenType_ISO15693,
     IdTokenType_KeyCode,
     IdTokenType_Local,
-	IdTokenType_MacAddress,
+    IdTokenType_MacAddress,
     IdTokenType_NoAuthorization
 };
 /**************************************************************************************/
@@ -370,7 +372,9 @@ struct WifiConfigData
 {
 	unsigned char		WifiMode;					//0: disable, 1: Infrastructure client, 2: Infrastructure server, 3: Ad-Hoc
 	unsigned char		WifiSsid[256];				//default: Null
-	unsigned char		WifiPassword[256];			//default: Null
+    unsigned char       WifiPassword[224];          //default: Null
+    unsigned char       WifiBroadcastSsid;          //the SSID broadcast configuration, 0: hidden   1: broadcast
+    unsigned char       WifiTargetBssidMac[31];     //Target connect SSID MAC address, default: Null
 	int					WifiRssi;					//dbm
 	unsigned char		WifiDhcpServer;				//0: enable, 1: disable
 	unsigned char		WifiDhcpClient;				//0: enable, 1: disable
@@ -385,7 +389,8 @@ struct TeleConfigData
 {
 	unsigned char		TelcomModelName[64];		//default: Null
 	unsigned char		TelcomSoftwareVer[64];		//default: Null
-	unsigned char		TelcomApn[256];				//default: Null
+    unsigned char       TelcomApn[255];             //default: Null
+    unsigned char       TelcomNetworkType;          //0: Auto   1: CDMA  2: WCDMA  3: LTE  4: TD-SCDMA  5: UMTS  6: CDMA  7: HDR  8: CDMA/HDR
 	int					TelcomRssi;					//dbm
 	unsigned char		TelcomChapPapId[256];		//default: Null
 	unsigned char		TelcomChapPapPwd[256];		//default: Null
@@ -484,7 +489,8 @@ typedef union
         unsigned int InvalidIdStop:1;               // 0: no effect,    1: invalid stop when StopTransactionOnInvalidId is true
         unsigned int RemoteStop:1;                  // 0: no effect,    1: remote stop
         unsigned int UnlockStop:1;                  // 0: no effect,    1: unlock stop
-        unsigned int res:23;
+        unsigned int SessionTargetStop:1;           // 0: no effect,    1: session target stop
+        unsigned int res:22;
     }bits;
 }ChargingStop;
 
@@ -577,7 +583,7 @@ struct SysConfigData
 	struct LED				LedInfo;					// LED configuration info
 	unsigned char			ShowInformation;
 	unsigned char           isReqFirstUpgrade;          //EVSE is request first upgrade from PH server
-	unsigned char           isEnableLocalPowerSharing; //0: Disable power sharing  1: Master	2: Slave
+	unsigned char           isEnableLocalPowerSharing;  //0: Disable power sharing  1: Master   2: Slave
 	unsigned char           StopChargingByButton;       //0: Disable  1: Enable
     struct LCD_NOUSE        Legacy_LcdOveride;          // LCD override info (no use anymore)
     struct TTIA             TTIA_Info;                  // TTIA configuration struct
@@ -590,7 +596,17 @@ struct SysConfigData
     unsigned char           MaintainServerURL[512];             // ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
     unsigned char           MaintainServerSecurityProfile;      // Maintain server security profile 0~3
     unsigned char           MaintainServerSecurityPassword[41]; // Maintain server AuthorizationKey for security profile
-    unsigned char			PowerSharingServerIP[512];			// Local power sharing server ip address
+    unsigned char           PowerSharingServerIP[512];          // Local power sharing server ip address
+    unsigned int            PowerSharingCapacityPower;          // Local power sharing capacity power
+    unsigned char           MaxChargingSoc;                     //0: unlimit, 1 ~ 100 percent
+};
+
+struct DERATING_BY_OTP
+{
+    unsigned char isNeedDerating;
+    unsigned char deratingIndex;        // Current used power or current
+    double deratingTargetRate[5];       // Reduce the output energy rate
+    double deratingTargetCurrent[5];    // derating target current
 };
 
 struct ChargingInfoData
@@ -626,6 +642,7 @@ struct ChargingInfoData
 	int EvBatterySoc;				// 0~100%
 	unsigned char ConnectorPlugIn;			//0: unplug, 1: Plug-in
 	unsigned char GunLocked;				//0: unlocked 1: locked
+	unsigned char InProgress;               //0: real idle, 1: session(transaction) in progress
 	float PilotVoltage;
 	unsigned char PilotState;//1:state A, 2:State B1, 3:State B2, 4:State C, 5:State D, 6:State E, 7:State F, 8: Pilot error
 	unsigned char PilotDuty;					// 0~100%
@@ -695,6 +712,9 @@ struct ChargingInfoData
     unsigned char       CCSGunType;
     struct timeval      PreChargeTimer;
     unsigned char       _SaftyDetect;
+    unsigned char       _TotalPsuCount;                 // Psu count for connector
+    unsigned char       _TakePsuGpCount;                // Get the used psu group count
+    struct DERATING_BY_OTP deratingByConnOtp;
 };
 
 typedef struct
@@ -706,7 +726,7 @@ typedef struct
     unsigned char       AuthType;                       // 0: _AuthType_None,   1: _AuthType_RFID, 2: _AuthType_RemoteStart
     unsigned char       AuthResult;                     // 0: _AuthResult_None, 1: _AuthResult_Valid,   2: _AuthResult_Invalid
     unsigned char       AuthRequest;                    // 0: no request, 1: authorize request
-    unsigned char       res;
+    unsigned char       AuthIdType;
 }AuthorizingInfoData;
 
 typedef union
@@ -875,7 +895,10 @@ struct ConnectorInfoData
     float                   UserPrice;                      // connector user's user price, unit: 1 (dollar / kWh)
     float                   TotalCost;                      // connector user's total cost, unit: 1 dollar
     float                   AccountBalance;                 // connector user's account balance, unit: 1 dollar
-    float                   CostDiscount;                   // connector user's account balance, unit: 1 dollar
+    float                   CostDiscount;                   // connector user's Discount or couponPoint, unit: 1 point
+    float                   EnergyCost;                     // connector user's energy cost, unit: 1 dollar
+    float                   ParkingFee;                     // connector user's parking fee, unit: 1 dollar
+    float                   RemainAmount;                   // connector user's remain amount, unit: 1 dollar
 };
 
 typedef union
@@ -883,11 +906,7 @@ typedef union
     unsigned int SettingValue;
     struct
     {
-        unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
-        unsigned int FlashConfigChanged:1;      // 0: no effect, 1: flash config has changed
-        unsigned int EnableWriteFlash:1;        // 0: no effect, 1: enable to write flash after timeout
-        unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
-        unsigned int res:28;
+        unsigned int res:32;
     }bits;
 }CabinetSettingFlag;
 
@@ -901,6 +920,37 @@ typedef struct DC_METER_INFO
     unsigned char LinkStatus;                   // 0 = unknow ,1 = link , 2 miss link
 }DC_Meter_Info;
 
+typedef struct Bazel8Command
+{
+    unsigned char isReq:1;
+    unsigned char isRes:1;
+    unsigned char isWaitRes:1;
+    unsigned char isResultPass:1;
+} bazel8Command;
+
+typedef struct EventInfo
+{
+    int messageId;
+    char messageString[64];
+    unsigned char isGetOn:1;
+}eventInfo;
+
+typedef struct StartTxResp
+{
+    char statusCode[8];
+    char statusText[128];
+    char txnId[32];
+    unsigned char isGetOn:1;
+}startTxResp;
+
+struct BAZEL8
+{
+    eventInfo       event;
+    startTxResp     txResp;
+
+    bazel8Command   cmdPreAuth;
+};
+
 struct SysInfoData
 {
 	/**************System***************/
@@ -994,10 +1044,11 @@ struct SysInfoData
     unsigned char           AuthorizedStatus;           // cabinet authorized status
     CabinetSettingFlag      CabinetSetting;
     struct LocalSharingInfo localSharingInfo;           // Local power sharing info structure
-    DC_Meter_Info DcMeterInfo[4];
+    DC_Meter_Info           DcMeterInfo[4];
     unsigned char           OTPTemp;                    // OTP Temperature
     unsigned char           OTPTempR;                   // OTP Recovery Temperature
     struct LCD_OVERRIDE     LcdOveride;                 // LCD override info (no use anymore)
+    struct BAZEL8           bazel8;                     // Bazel8 payment used
 };
 
 struct SysConfigAndInfo
@@ -1251,18 +1302,18 @@ char AlarmStatusCode[160][6]=
 	"012261",	//GB groundfault detection timeout (GFD)
 	"012262",	//Circuit Short L1
 	"012263",	// PSU Duplicate ID
-	"012264", 	// PSU Output Short Circuit
+	"012264", 	// Psu Fault : Infy => Output Short Circuit,UU => Abnormal discharge circuit
 	"012265", 	// PSU Discharge Abnormal
 	"012266", 	// PSU Dc Side ShutDown
 	"012267", 	// PSU Failure Alarm
 	"012268", 	// PSU Protection Alarm
-	"012269", 	// PSU FanFailure Alarm
+	"012269", 	// Psu Fault : Infy => Fan Fault,UU => Fan Fault
 	"012270", 	// PSU Input UVP
 	"012271",	// PSU Input OVP
 	"012272", 	// PSU WalkIn State
-	"012273", 	// PSU Power Limited State
-	"012274", 	// PSU Id Repeat
-	"012275", 	// PSU Severe Uneven Current
+	"012273", 	// Psu Fault : Infy => Power Limited State,UU => Dc OVP and shutdown
+	"012274", 	// Psu Fault : Infy => Id Repeat,UU => Id Repeat
+	"012275", 	// Psu Fault : Infy => Severe Uneven Current,UU => Pfc internal unbalance
 	"012276", 	// PSU Three Phase Input Inadequate
 	"012277", 	// PSU Three Phase Onput Imbalance
 	"012278", 	// PSU Ffc Side ShutDown
@@ -1294,18 +1345,18 @@ char AlarmStatusCode[160][6]=
 	"012304",   // connection disconnected from power cabinet
 	"012305",   // Meter communication timeout
 	"012306",   // The dip switch of the PSU may be incorrect
-    "012307",   // Psu Fuse Burn-Out
-    "012308",   // Psu Pfc And Dcdc Communication Fault
-    "012309",   // Psu Bus Voltage Unbalance
-    "012310",   // Psu Bus Over Voltage
-    "012311",   // Psu Bus Voltage Abnormal
-    "012312",   // Psu Bus Under Voltage
-    "012313",   // Psu Input Phase Loss
-    "012314",   // Psu Fan Full Speed
-    "012315",   // Psu Temperature Power Limit
-    "012316",   // Psu Ac Power Limit
-    "012317",   // Psu Dcdc Eeprom Fault
-    "012318",   // Psu Pfc Eeprom Fault
+    "012307",   // Psu Fault : Infy => Fuse Burn-Out,UU => Pfc internal OVP
+    "012308",   // Psu Fault : Infy => Pfc And Dcdc Communication Fault,UU => Pfc And Dcdc Communication Fault
+    "012309",   // Psu Fault : Infy => Bus Voltage Unbalance,UU => Dc output voltage unbalance
+    "012310",   // Psu Fault : Infy => Bus Over Voltage,UU => Ac site OVP
+    "012311",   // Psu Fault : Infy => Bus Voltage Abnormal,UU => Ac site UVP
+    "012312",   // Psu Fault : Infy => Bus Under Voltage,UU => Pfc internal UVP
+    "012313",   // Psu Fault : Infy => Input Phase Loss,UU => Dc to Dc don’t work
+    "012314",   // Psu Fault : Infy => Fan Full Speed,UU => Fan don’t work
+    "012315",   // Psu Fault : Infy => Temperature Power Limit,UU => env OTP、Pfc OTP、output relay broken、Dc OTP
+    "012316",   // Psu Fault : Infy => Ac Power Limit,UU => Ac OVP and shutdown
+    "012317",   // Psu Fault : Infy => Dcdc Eeprom Fault,UU => Dc to Dc broken
+    "012318",   // Psu Fault : Infy => Pfc Eeprom Fault,UU => Pfc broken
     "012319",   // Psu Dcdc Over Voltage
     "012320",   // System CHAdeMO output UCP
     "012321",   // System CCS output UCP
@@ -1314,13 +1365,13 @@ char AlarmStatusCode[160][6]=
     "012324",   // Connector 1 detects abnormal voltage on the output line
     "012325",   // Connector 2 detects abnormal voltage on the output line
     "012326",   // System task is lost
-    "012327",   // DC input ovp
-    "012328",   // DC input uvp
-    "012329",   // Psu Can Communication Fault
-    "012330",   // Psu Dc to Dc OTP
-    "012331",   // Psu Dc to Dc OVP
-    "012332",   // reserved
-    "012333",   // reserved
+    "012327",   // System DC input ovp
+    "012328",   // System DC input uvp
+    "012329",   // Psu Fault : Infy => Psu Can Communication Fault,UU =>
+    "012330",   // Psu Fault : Infy => Psu Dc to Dc OTP,UU => env UTP
+    "012331",   // Psu Fault : Infy => Psu Dc to Dc OVP,UU => Dc output OVP
+    "012332",   // Chiller Tube OTP
+    "012333",   // Psu Fault : Infy => DC input ovp (Phase OVP),UU => Dc output UVP
     "012334",   // reserved
     "012335",   // reserved
     "012336",   // reserved
@@ -1334,7 +1385,7 @@ char AlarmStatusCode[160][6]=
     "012344",   // AC: Meter IC communication timeout
     "012345",   // AC: Pilot negative error
     "012346",   // Psu Communication error with CSU
-    "012347",   // reserved
+    "012347",   // AC: Local power sharing communication error (Slave disconnect from Master)
     "012348",   // reserved
     "012349",   // reserved
     "012350",   // reserved
@@ -1506,14 +1557,17 @@ struct AlarmCodeData
             unsigned char PsuCanCommFault:1;                        //bit 1
             unsigned char PsuDcDcOtp:1;                             //bit 2
             unsigned char PsuDcDcOvp:1;                             //bit 3
-            unsigned char :4;                                       //reserved bit 4 ~ bit 7
+            unsigned char ChillerTubeOTP : 1;                       //bit 4
+            unsigned char PsuPhaseOvp:1;                            //bit 5
+            unsigned char :2;                                       //reserved bit 6 ~ bit 7
             //AlarmVal[17]
             unsigned char :8;                                       //reserved bit 0 ~ bit 7
             //AlarmVal[18]
             unsigned char MeterIcCommTimeout:1;                     //bit 0
             unsigned char PilotNegativeError:1;                     //bit 1
             unsigned char PsuComminicationErrWithCSU:1;             //bit 2
-            unsigned char :5;                                       //reserved bit 3 ~ bit 7
+            unsigned char LocalPowerSharingCommunicationError:1;    //bit 3
+            unsigned char :4;                                       //reserved bit 4 ~ bit 7
             //AlarmVal[19]
             unsigned char :8;                                       //reserved bit 0 ~ bit 7
 		}bits;
@@ -1841,7 +1895,7 @@ char InfoStatusCode[384][6]=
     "023981",   // ERROR_CODE_CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT
     "023982",   // ERROR_CODE_CHADEMO_ADC_LESS_THAN_10V
     "023983",   // STOP by EV with unknow reason
-    "023984",   // Reserved
+    "023984",   // STOP by EVSE condition (Config or OCPP)
     "023985",   // Reserved
     "023986",   // Reserved
     "023987",   // Reserved
@@ -2188,7 +2242,8 @@ struct InfoCodeData
             unsigned char CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT:1; //bit 1
             unsigned char CHADEMO_ADC_LESS_THAN_10V:1;              //bit 2
             unsigned char Stop_by_EV_with_unknow_reason:1;          //bit 3
-            unsigned char :4;                                       //bit 4 ~ 7 reserved
+            unsigned char Stop_by_EVSE_condition:1;                 //bit 4
+            unsigned char :3;                                       //bit 5 ~ 7 reserved
 			//InfoVal[40]
 			unsigned char BackendDisconnectedViaEthernet:1;			//bit 0
 			unsigned char BackendDisconnectViaWiFi:1;				//bit 1
@@ -2265,6 +2320,8 @@ struct PsuModuleData
 	unsigned int 		AlarmCode;
 	unsigned int 		FaultCode;			//
 	unsigned int 		IAvailableCurrent;		            // unit: 0.1A
+    unsigned short  PresentMaxOutputVoltage;//abcd=abc.d volt
+    unsigned short  KwAvailablePower;       // unit: 0.1 kw
 };
 
 /*Following are the information for each PSU Group*/
@@ -2286,6 +2343,11 @@ struct PsuGroupData
     unsigned short          TempIAvailableCurrent;          // unit: 0.1A
     unsigned short          StableIAvailableCurrent;        // unit: 0.1A
     unsigned short          StableCurrentCounter;           // stable current counter
+    unsigned short          GroupMaxVoltage;                // unit: 0.1V
+    unsigned char           IsUsing;                        // 0 : none use
+    unsigned char           UsingTarget;                    // 0xFF : Check
+    unsigned char           PwSwitchStatus;
+    unsigned short          TotalRatingPower;               // unit: 1kW
 };
 
 /*Following is the information for system all PSU*/
@@ -2301,6 +2363,54 @@ struct PsuData
 	unsigned char           PsuStopChargeFlag;
 };
 
+struct SmartTimeChk
+{
+    struct timespec     FetchLoopTime;
+    unsigned char       IsFetchStart;
+
+    struct timespec     ReleaseLoopTime;
+    unsigned char       IsReleaseStart;
+};
+
+struct DynamicFetchCtrl
+{
+    unsigned char       ShareGroup;         // 255 : None
+    unsigned char       FetchLoopStep;      // 0 : None, 1 : Output Vol, 2 : RCB ON, 3 : Current sharing, 4 : Finish
+    unsigned short      ShareTargetCurrent; // 0.1A
+    unsigned char       TargetRelay;        // 255 : None
+};
+
+struct DynamicReleaseCtrl
+{
+    unsigned char       ReleaseGroup;       // 255 : None
+    unsigned char       ReleaseLoopStep;    // 0 : None, 1 : Limit Pwr, 2 : Pwr OFF, 3. RCB OFF, 4. Finish
+    float               CheckOutPwrIsStable;// 0.1kw
+    unsigned char       TargetRelay;        // 255 : None
+
+    float               LimitCurCap;        // Inform 0.1A
+    float               LimitPwrCap;        // Inform 0.1kw
+    float               LimitCur;           // Target 0.1A
+    float               LimitPwr;           // Target 0.1kw
+};
+
+struct ConnInfo
+{
+    unsigned char ConnectorStaus;
+    unsigned char NeedToFetch;
+};
+
+struct SmartBoxData
+{
+    struct ConnInfo     ConnectorStatus[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];     // Connector 1 / 2 Status : None, Wait, Using
+    struct ConnInfo     AnotherConnectorStatus[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    unsigned char       ConnectorUsingGroupCount[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; // Psu group for connector
+    struct SmartTimeChk SmartChk[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct DynamicFetchCtrl Dynamic4Fetch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    struct DynamicReleaseCtrl Dynamic4Release[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+    unsigned char       ParallelRelayStatus[3];
+    unsigned char       RcbParallelStatus[3];
+};
+
 /************************************************************************************/
 /**************************CHAdeMO protocol Share memory*********************/
 /**************************************************************************************/
@@ -4447,6 +4557,7 @@ struct Triggers
                                                     // be used to trigger a meter value when vehicle stops charging or when vehicle charges at a high power that requires a
                                                     // different tariff.
                                                     // It is recommended to implement a hysteresis around this value to avoid repetitive triggers when the power fluctuates around this level.
+    unsigned char atCPStatus[100];
 };
 
 struct StrcutRunningCost
@@ -4460,13 +4571,17 @@ struct StrcutRunningCost
     struct IdlePrice        idlePrice;              // (optional) Price components while not charging. Optional if no idle fee is charged.
     struct NextPeriod       nextPeriod;             // (optional) Pricing for next period
     struct Triggers         triggerMeterValue;      // (optional) Triggers to request a new meter value. Optional if no idle fee charged.
-    unsigned char           description[1024];       // Compatible California pricing V1.0
+    unsigned char           description[1024];      // Compatible California pricing V1.0
 };
 
 struct StrcutFinalCost
 {
     int             txId;
     unsigned char   description[1024];
+
+    float           cost;
+    unsigned char   priceText[1024];
+    unsigned char   qrCodeText[1024];
 };
 
 struct StructCost
@@ -4872,6 +4987,7 @@ enum OCPP20CtrlrVariable
 	ChargingStation_SystemUptimeSec,
 	ChargingStation_FreeVend,
 	ChargingStation_FreeVendIdtag,
+	ChargingStation_OffLineMaxChargingPower,
 	Connector_Available,
 	Connector_ConnectorType,
 	Connector_SupplyPhases,
@@ -5142,7 +5258,7 @@ struct ChargingScheduleType
 
 struct ChargingProfileType
 {
-	int id;											// Required. Id of ChargingProfile.
+	int id;											                // Required. Id of ChargingProfile.
 	unsigned short int stackLevel;									// Required. Value determining level in hierarchy stack of profiles. Higher values have precedence over lower values. Lowest level is 0.
 	unsigned char chargingProfilePurpose[36];						// Required. Defines the purpose of the schedule transferred by this profile
 	unsigned char chargingProfileKind[16];							// Required. Indicates the kind of schedule.
@@ -6006,7 +6122,8 @@ struct OCPP20Data
 			unsigned char SecurityEventNotificationConf :1;
 			unsigned char SignCertificateReq :1;
 			unsigned char SignCertificateConf :1;
-			unsigned char :2;
+            unsigned char NotifyCustomerInformationReq :1;  //bit 6
+            unsigned char NotifyCustomerInformationConf :1; //bit 7
 
 		} bits;
 	} SpMsg;

+ 3 - 3
EVSE/Projects/DD360Tcci/Apps/ModuleChkSysTask/Module_ChkSysTask.c

@@ -220,11 +220,11 @@ void CheckSystemTaskAlive()
 }
 
 
-void main(void)
+int main(void)
 {
     if (CreateAllCsuShareMemory() == FAIL) {
         log_error("create share memory error");
-        return ;
+        return FAIL;
     }
 
     pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
@@ -247,5 +247,5 @@ void main(void)
 		}
 		CheckSystemTaskAlive();
     }
-	return;
+	return FAIL;
 }

+ 202 - 123
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.c

@@ -59,7 +59,7 @@ static char ReservationIdTag[2][32];
 static int LineStatusCode[2] = {0};
 static unsigned int LedIntensity = 0;
 static int TimeZoneOffset = 0;
-
+uint8_t _isplugin[2] = { 0 };
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -176,7 +176,7 @@ int string2Date(char* input, uint8_t* output)
 }
 static void unixSocketSigPipeHandle(int sig)
 {
-    log_error("socket packet error %x", sig);
+    //log_error("socket packet error %x", sig);
 }
 
 static void InitSocketSigPipe(void)
@@ -316,17 +316,22 @@ static void ClearAuthorizedFlag(void)
     pSysInfo->AuthorizeFlag = NO;
 }
 
-static void ClearDetectPluginFlag(void)
+static void ClearDetectPluginFlag(int gunIndex)
 {
-    pSysInfo->WaitForPlugit = NO;
+    //pSysInfo->WaitForPlugit = NO;
+    ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
 }
 
-static bool isDetectPlugin(void)
+static bool isDetectPlugin(int gunIndex)
 {
+    if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
+        return true;
+    }
+    /*
     if (pSysInfo->WaitForPlugit == YES) {
         return YES;
     }
-
+    */
     return NO;
 }
 
@@ -367,29 +372,6 @@ static void destroySelectGun(uint8_t curGun)
     }
 }
 
-static int getConfirmSelectedGun(uint8_t curSel)
-{
-    if (((curSel == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
-            ((curSel == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
-        return PASS;
-    }
-
-    return FAIL;
-}
-
-static int getSelGunWaitToAuthor(uint8_t curGun)
-{
-    if (curGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
-        return FAIL;
-    }
-
-    if (curGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
-        return FAIL;
-    }
-
-    return PASS;
-}
-
 static void setConfirmSelGun(uint8_t selGun)
 {
     if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
@@ -489,7 +471,7 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
         string2Date((char*)data, (uint8_t*)_setTime);
         //printf("SystemId =  %s", pSysConfig->SystemId);
         if (!timecmp(localTime, _setTime)) {
-            log_info("Set Timer:%s", _setTime);
+            //log_info("Set Timer:%s", _setTime);
             sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
             system((char*)cmdBuf);
             system("hwclock -w -u");
@@ -654,13 +636,6 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-#if defined DD360Audi
-            if (getConfirmSelectedGun(plugNum) == FAIL) {
-                log_info("Remote start not select gun");
-                break;
-            }
-#endif //DD360Audi
-
             ShmSelectGunInfo->PricesInfo[plugNum].Balance = transPricesUnit((int)value);
             log_info("%d misc balance = %.2f", plugNum, ShmSelectGunInfo->PricesInfo[plugNum].Balance);
             clearMiscCommand();
@@ -728,45 +703,10 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             log_info("Remote start charging plugNum = %d", plugNum);
 
-#if defined DD360Audi
-            if (getSelGunWaitToAuthor(plugNum) == FAIL) {
-                log_error("Remote start gun already charging");
-                break;
-            }
-
-            if (pSysInfo->CurGunSelected != (plugNum)) {
-                if (plugNum == LEFT_GUN_NUM &&
-                        (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
-                         ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-                    ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
-                    strcpy((char *)pSysConfig->UserId, "");
-                    pSysInfo->WaitForPlugit = NO;
-                    sleep(1); //Jerry add
-                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
-                    pSysInfo->SystemTimeoutFlag = Timeout_None;
-                }
-
-                if (plugNum == RIGHT_GUN_NUM &&
-                        (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
-                         ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-                    ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-                    strcpy((char *)pSysConfig->UserId, "");
-                    pSysInfo->WaitForPlugit = NO;
-                    sleep(1); //Jerry add
-                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
-                    pSysInfo->SystemTimeoutFlag = Timeout_None;
-                }
-
-                pSysInfo->CurGunSelected = (plugNum);
-                pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-            }
-#else
             //pSysInfo->CurGunSelected = (plugNum);
             pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-#endif //DD360Audi
-            setConfirmSelGun(pSysInfo->CurGunSelected);
+
+            setConfirmSelGun(plugNum);
 
             ShmOCPP16Data->CsMsg.bits[plugNum].RemoteStartTransactionReq = YES;
             ShmSelectGunInfo->PricesInfo[plugNum].Balance = 0.00;
@@ -782,7 +722,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
 
             strcpy((char *)pSysConfig->UserId, "");
-            pSysInfo->WaitForPlugit = NO;
+            ClearDetectPluginFlag(plugNum);
             //pSysInfo->SystemPage = _LCM_SELECT_GUN;
             GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
             pSysInfo->SystemTimeoutFlag = Timeout_None;
@@ -799,10 +739,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            if (isDetectPlugin() == YES) {
-                ClearDetectPluginFlag();
+            if (isDetectPlugin(plugNum) == YES) {
+                ClearDetectPluginFlag(plugNum);
                 strcpy((char *)pSysConfig->UserId, "");
-                pSysInfo->WaitForPlugit = NO;
                 //pSysInfo->SystemPage = _LCM_SELECT_GUN;
                 GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                 pSysInfo->SystemTimeoutFlag = Timeout_None;
@@ -871,8 +810,12 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             break;
         case MISC_CMD_LINE_STATUS_REQ:
             LineStatusCode[plugNum] = value;
-            ShmDcCommonData->LineStatus[plugNum] = value;
+            ShmDcCommonData->TransactionInfo[plugNum].LineStatus = value;
             log_info("Gun %d Line Status Code: %d", plugNum, LineStatusCode[plugNum]);
+            if (ShmDcCommonData->TransactionInfo[plugNum].LineStatus != value &&
+                strcmp((char*)ShmDcCommonData->TransactionInfo[plugNum].pCreditCard.VemData, "") != 0) {
+                UpdateDeductInfoStatus(plugNum,&ShmDcCommonData->TransactionInfo[plugNum]);
+            }
             break;
         case MISC_CMD_LED_INTENSITY:
             LedIntensity = value;
@@ -889,6 +832,13 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             */
             break;
+        case MISC_CMD_CHARGING_BILL:
+            if (value != YES)
+            {
+                break;
+            }
+            gMoreInfoReq[plugNum].bits.ChargingBill = YES;
+            break;
         default:
             clearMiscCommand();
             break;
@@ -912,8 +862,29 @@ void AddDispenserReq(uint8_t* buff, MiscCommand* req)
 }
 
 
+static int chargingbillHandle(uint8_t* data, uint8_t gunIndex)
+{
 
+    ChargingBillInfo* pBillInfo = (ChargingBillInfo*)&data[0];
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
 
+    ShmDcCommonData->PriceBill.TotalCost = transPricesUnit(ntohl(pBillInfo->TotalCost));
+    ShmDcCommonData->PriceBill.Balance = transPricesUnit(ntohl(pBillInfo->Balance));
+    ShmDcCommonData->PriceBill.Discount = transPricesUnit(ntohl(pBillInfo->Discount));
+    ShmDcCommonData->PriceBill.TransactionId = ntohl(pBillInfo->Transaction);
+    ShmDcCommonData->PriceBill.EnergyCost = transPricesUnit(ntohl(pBillInfo->EnergyCost));
+    ShmDcCommonData->PriceBill.ParkingFee = transPricesUnit(ntohl(pBillInfo->ParkingFee));
+    pBillInfo->RemainAmount = ntohl(pBillInfo->RemainAmount);
+    memcpy((char*)&ShmDcCommonData->PriceBill.RemainAmount, (char*)&pBillInfo->RemainAmount, sizeof(uint32_t));
+    log_info("\t ******* TxId %d Charging Bill *******\n", ShmDcCommonData->PriceBill.TransactionId);
+    log_info("\t Total Cost = %.2f\n", ShmDcCommonData->PriceBill.TotalCost);
+    log_info("\t Discount = %.2f\n", ShmDcCommonData->PriceBill.Discount);
+    log_info("\t EnergyCost = %.2f\n", ShmDcCommonData->PriceBill.EnergyCost);
+    log_info("\t ParkingFee = %.2f\n", ShmDcCommonData->PriceBill.ParkingFee);
+    log_info("\t RemainAmount = %.2f\n", ShmDcCommonData->PriceBill.RemainAmount);
+    if (ShmDcCommonData->PriceBill.TransactionId != ShmDcCommonData->TransactionInfo[gunIndex].TransactionId)
+        UpdateRedeuctBill(ShmDcCommonData->PriceBill.TransactionId, ShmDcCommonData->PriceBill.TotalCost);
+}
 
 static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
 {
@@ -965,6 +936,10 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     ShmSelectGunInfo->PricesInfo[plugNum].Balance    = transPricesUnit(ntohl(pAccountInfo->Balance));
     ShmSelectGunInfo->PricesInfo[plugNum].Discount   = transPricesUnit(ntohl(pAccountInfo->Discount));
     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) ||
@@ -974,9 +949,13 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         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;
+
             UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
 
             log_info("id = %d, transaction id = %d, user prices = %.2f, Discount = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s",
@@ -988,6 +967,10 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
                 ShmSelectGunInfo->PricesInfo[plugNum].Balance,
                 (uint8_t*)GetCurrency(pSysConfig->BillingData.Currency)
             );
+            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);
         }
     }
 
@@ -1177,7 +1160,49 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
 
     return PASS;
 }
-
+void CheckTaiwanEastWest(int id)
+{
+    ShmDcCommonData->TaiwanEast = TRUE;
+    //西半部
+    if (id >= 100 && id <= 116) {//台北
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 200 && id <= 206) { //基隆
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 207 && id <= 253) { //新北
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 300 && id <= 315) { //新竹
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 320 && id <= 338) { //桃園
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 350 && id <= 369) { //苗栗
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 400 && id <= 439) { //台中
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 500 && id <= 530) { //彰化
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 600 && id <= 625) { //嘉義
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 630 && id <= 655) { //雲林
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 700 && id <= 745) { //台南
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 800 && id <= 852) { //高雄
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 900 && id <= 947) { //屏東
+        ShmDcCommonData->TaiwanEast = FALSE;
+    } else if (id >= 880 && id <= 885) { //澎湖
+        ShmDcCommonData->TaiwanEast = FALSE;
+    // 東半部
+    } else if (id >= 540 && id <= 558) { //南投
+        ShmDcCommonData->TaiwanEast = TRUE;
+    } else if (id >= 260 && id <= 272) { //宜蘭
+        ShmDcCommonData->TaiwanEast = TRUE;
+    } else if (id >= 950 && id <= 966) { //台東
+        ShmDcCommonData->TaiwanEast = TRUE;
+    } else if (id >= 970 && id <= 983) { //花蓮
+        ShmDcCommonData->TaiwanEast = TRUE;
+    }
+}
 static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_t reg)
 {
     int ret = PASS;
@@ -1329,6 +1354,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         }
         uint8_t reservationState = pCsuResult->Data.Data[0] == YES ? YES : NO;
         memset(&ReservationIdTag[plugNum][0], 0x00, 32);
+        ShmDcCommonData->pGunInfo[plugNum].ReservationStatus = reservationState;
         if(reservationState)
         {
             strcpy(&ReservationIdTag[plugNum][0], (char *)&pCsuResult->Data.Data[1]);
@@ -1339,6 +1365,9 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             if(reservationState)
             {
                 log_info("id = %d reservation idTag: %s", pCsuResult->Head.ID, (char *)&ReservationIdTag[plugNum][0]);
+                strcpy(&ShmDcCommonData->pGunInfo[plugNum].ReservationID[0], (char*)&pCsuResult->Data.Data[1]);
+            } else {
+                strcpy(&ShmDcCommonData->pGunInfo[plugNum].ReservationID[0], "");
             }
         }
         ReservationState[plugNum] = reservationState;
@@ -1382,6 +1411,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         ShmDcCommonData->Temperature = _stationInfo.Temperature;
         ShmDcCommonData->Location = atoi(_stationInfo.StationName);
 
+        CheckTaiwanEastWest(ShmDcCommonData->Location);
         log_info("Station Name: %s, ID: %d, Weather: %d, Temperature: %.1f",
                 _stationInfo.StationName,
                 _stationInfo.StationID,
@@ -1395,6 +1425,38 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         }
         break;
 
+    case REG_POWER_CONSUMPTION_INFO:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+
+        PowConsumValue* pValue = NULL;
+        pValue = (PowConsumValue*)&pCsuResult->Data.Data[0];
+
+        pValue->Gun1_Consumption = ntohl(pValue->Gun1_Consumption);
+        pValue->Gun2_Consumption = ntohl(pValue->Gun2_Consumption);
+        pValue->Gun3_Consumption = ntohl(pValue->Gun3_Consumption);
+        pValue->Gun4_Consumption = ntohl(pValue->Gun4_Consumption);
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun1_Consumption, (char*)&pValue->Gun1_Consumption, sizeof(uint32_t));
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun2_Consumption, (char*)&pValue->Gun2_Consumption, sizeof(uint32_t));
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun3_Consumption, (char*)&pValue->Gun3_Consumption, sizeof(uint32_t));
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun4_Consumption, (char*)&pValue->Gun4_Consumption, sizeof(uint32_t));
+
+        log_info("Gun1_Consumption:%f", ShmDcCommonData->pConsumption.Gun1_Consumption);
+        log_info("Gun2_Consumption:%f", ShmDcCommonData->pConsumption.Gun2_Consumption);
+        log_info("Gun3_Consumption:%f", ShmDcCommonData->pConsumption.Gun3_Consumption);
+        log_info("Gun4_Consumption:%f", ShmDcCommonData->pConsumption.Gun4_Consumption);
+
+
+        break;
+    case REG_READ_CHARGING_TIMESTAMP:
+        break;
+    case REG_CHARGING_BILL:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        chargingbillHandle(pCsuResult->Data.Data, plugNum);
+        break;
     default:
         break;
     }
@@ -1433,21 +1495,21 @@ static int composeSocketData(int fd,
 
     //send command packet
     if ((size = sendTcpSocket(fd, (uint8_t *)&csuCmdPkt, sendPktLen)) < 0) {
-        log_error("TCP socket send packet fail = %d", size);
+        log_error("TCP socket reg=0x%x send packet fail = %d",reg, size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result head
     if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
-        log_error("TCP socket RX head fail = %d", size);
+        log_error("TCP socket reg=0x%x RX head fail = %d",reg, size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
 
     //receive result raw data
     if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
-        log_error("TCP socket RX data fail = %d", size);
+        log_error("TCP socket reg=0x%x RX data fail = %d",reg, size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
     }
@@ -1525,6 +1587,22 @@ static int readRemoteStartNoIDState(int fd)
     return ret;
 }
 
+static int readChargingBill(int fd)
+{
+    int ret = PASS;
+
+    if ((ret = composeSocketData(fd,
+                                ID_REGISTER,
+                                OP_READ_DATA,
+                                REG_CHARGING_BILL,
+                                0,
+                                NULL)) == FAIL) {
+        return ret;
+    }
+
+    return ret;
+}
+
 static int readChargerStationInfo(int fd)
 {
     int ret = PASS;
@@ -1544,6 +1622,11 @@ static int readChargerStationInfo(int fd)
 static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactionInfo *transactionInfo)
 {
     int ret = PASS;
+    if (ShmDcCommonData->DebugFlag &&
+        strcmp((char*)transactionInfo->pCreditCard.VemData ,"") == EQUAL) {
+        return ret;
+    }
+
     uint8_t dataBuf[104] = {0};
     //int i;
 
@@ -1564,11 +1647,7 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     memcpy((char *)&dataBuf[10], transactionInfo->pCreditCard.ApprovalNo,9);
     memcpy((char *)&dataBuf[19], transactionInfo->pCreditCard.VemData, 64);
     memcpy((char*)&dataBuf[83], transactionInfo->pCreditCard.CardNo, 20);
-    /*
-    for(i=0;i<22;i++) {
-    	log_info("dataBuf[%d]:0x%x",i,dataBuf[i]);
-    }
-    */
+
     log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f Approva Num:'%s' VemData:'%s' CardNo:'%s'",
     		transactionInfo->ConnectorID,
             transactionInfo->TransactionId,
@@ -1592,11 +1671,14 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     return ret;
 }
 
-static int writeWaitPlugItState(int fd, uint8_t id)
+static int writeWaitPlugItState(int fd, uint8_t id,uint8_t gunIndex)
 {
     int ret = PASS;
-    uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
-
+    uint8_t data[2] = { ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit, 0};
+    if (_isplugin[gunIndex] != ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit) {
+        //log_info("Wait Gun%d for plug:%s", gunIndex, ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == 0 ? "disable" : "enable");
+        _isplugin[gunIndex] = ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit;
+    }
     //printf("WaitForPlugit = %d", pSysInfo->WaitForPlugit);
 
     if ((ret = composeSocketData(fd,
@@ -1760,7 +1842,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[16] = {'\0'};
+    uint32_t _consumption;
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
@@ -1769,6 +1852,7 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     pConnState->ConnectorTemp = pDcChargingInfo->ConnectorTemp;
     pConnState->ChillerTemp = pDcChargingInfo->ChillerTemp;
     pConnState->PlugIn = pDcChargingInfo->ConnectorPlugIn;
+    pConnState->ConnectMode = pDcChargingInfo->SystemStatus;
 
     if (pDcChargingInfo->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
@@ -1821,6 +1905,9 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
         }
     }
 
+    memcpy((char*)&_consumption, (char*)&ShmDcCommonData->pGunInfo[plugNum].PowerConsumption, sizeof(float));
+    pConnState->consumption = ntohl(_consumption);
+
     ret = composeSocketData(fd,
                             id,
                             OP_WRITE_DATA,
@@ -2173,29 +2260,6 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             curReg = REG_PLUG_IN_STATE;
             break;
 
-        //case REG_CHARGING_TARGET:
-        //    writeChargingTarget(fd, plugNum, gunID);
-        //    break;
-
-        //case REG_SOFTWARE_UPDATE:
-        //    if (ChargingData[plugNum]->SystemStatus == S_IDLE) {
-        //        if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > L OOP_RETRY_TIME||
-        //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0  * 1) {
-        //            readSoftwareUpdate(fd);
-        //            ftime(&gRegTimeUp[plugNum][curReg]);
-        //        }
-        //        while (pSysInfo->FirmwareUpdate == YES) {
-        //            ftime(&NowTime);
-        //            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowT ime) > LOOP_RETRY_TIME||
-        //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-        //                readSoftwareUpdate(fd);
-        //            }
-        //            usleep(128);
-        //        }
-        //    }
-        //    isContinue = 0;
-        //    break;
-
         case REG_PLUG_IN_STATE:
             if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
                     DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
@@ -2225,6 +2289,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                         gConnectorActReq[plugNum].Value = 0;
                         log_info("Gun %d CHARGING_CANCEL OK", plugNum);
                         ShmDcCommonData->OperateIDLE[plugNum] = 0;
+                        ShmDcCommonData->TransactionInfo[plugNum].LineStatus = _LINE_INIT;
                     }
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
@@ -2349,9 +2414,22 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
+            curReg = REG_CHARGING_BILL;
+            break;
+        case REG_CHARGING_BILL:
+            if (gMoreInfoReq[plugNum].bits.ChargingBill) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    if (readChargingBill(fd) == PASS)
+                    {
+                        log_info("Need to rededuct Bill");
+                        gMoreInfoReq[plugNum].bits.ChargingBill = false;
+                    }
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
             curReg = REG_REFUND_AMOUNT;
             break;
-
         case REG_REFUND_AMOUNT:
             curReg = REG_PREPAYMENT_INFO;
             break;
@@ -2442,8 +2520,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         ftime(&SeqEndTime);
         SeqEndTime.time = time(NULL);
         tm = localtime(&SeqEndTime.time);
-
-        if (pSysInfo->SystemPage == _PAGE_IDLE || pSysInfo->SystemPage == _PAGE_SELECT_GUN) {
+        
+        if ((pSysInfo->SystemPage == _PAGE_IDLE || pSysInfo->SystemPage == _PAGE_SELECT_GUN)) {
             ftime(&AuthNowTime);
             if (DiffTimeb(gRegTimeUp[plugNum][REG_DEDUCT_INFO], AuthNowTime) > LOOP_RETRY_TIME ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_DEDUCT_INFO], AuthNowTime) < 0
@@ -2452,9 +2530,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 if (reupload_num >= 1 && reuploadInfo[0].ConnectorID != 0) {
 
                     if (writeDeductInfo(fd, reuploadInfo[0].ConnectorID, reupload_gunIndex[0], &reuploadInfo[0]) == PASS) {
-                        log_info("Reupload Success");
                         reuploadInfo[0].IsUpload = YES;
-                        UpdateDeductInfoStatus(reupload_gunIndex[0], &reuploadInfo[0]);
+                        UpdateDeductInfoStatus(&reupload_gunIndex[0], &reuploadInfo[0]);
                     } else
                         log_info("Reupload fail");
 
@@ -2462,6 +2539,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 ftime(&gRegTimeUp[plugNum][REG_DEDUCT_INFO]);
             }
         }
+        
         /*
         if (pSysInfo->SystemPage == _PAGE_IDLE || pSysInfo->SystemPage == _PAGE_SELECT_GUN) {
             reupload_num = DB_GetMultiReUploadDeduct(&reupload_gunIndex[0], &reuploadInfo[0]);
@@ -2483,7 +2561,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
            ) {
-            writeWaitPlugItState(fd, gunID);
+            writeWaitPlugItState(fd, gunID, plugNum);
             ftime(&gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE]);
         }
         /*
@@ -2733,10 +2811,11 @@ static int networkCreatePorcess(void)
 
     return fd;
 }
+
 void CreditCardProcess(int fd,int plugNum,int gunID, RecordTransactionInfo *pInfo)
 {
-    if (pInfo->IsUpload == TRUE || (strcmp(pInfo->pCreditCard.VemData,"") == 0) ||
-        pSysInfo->SystemPage == _PAGE_SENSING)
+    if (pInfo->IsUpload == TRUE || (strcmp((char*)pInfo->pCreditCard.VemData,"") == 0) ||
+        pSysInfo->SystemPage == _PAGE_SENSING || ShmDcCommonData->is_RemoteStart[plugNum])
         return;
     if (ShmDcCommonData->TransactionInfo[plugNum].ConnectorID != 0) {
         if (writeDeductInfo(fd, gunID, plugNum, &ShmDcCommonData->TransactionInfo[plugNum]) == PASS) {

+ 25 - 4
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.h

@@ -93,7 +93,13 @@
 #define REG_CONNECTOR_QR_CODE                   0x1D
 #define REG_STATION_INFO                        0x1E
 #define REG_DEDUCT_INFO                         0x1F
-
+#define REG_READ_CABINET_SYSTEMID               0x20
+#define REG_READ_DEFAULT_PRICE                  0x21
+#define REG_READ_USER_PRICE                     0x22
+#define REG_RECEIPT_INFO                        0x23
+#define REG_POWER_CONSUMPTION_INFO              0x24
+#define REG_READ_CHARGING_TIMESTAMP             0x25
+#define REG_CHARGING_BILL                       0x26
 //------------------------------------------------------------------------------
 //--- dispenser result ---
 //------------------------------------------------------------------------------
@@ -142,6 +148,7 @@
 #define MISC_CMD_DEFAULT_PRICE_REQ              (0x010C)
 #define MISC_CMD_USER_PRICE_REQ                 (0x010D)
 #define MISC_CMD_RECEIPT_REQ                    (0x010E)
+#define MISC_CMD_CHARGING_BILL                  (0x010F)
 
 #define ST_UPDATE_FIRMWARE                      (0x01)
 #define ST_NO_UPDATE_FIRMWARE                   (0x02)
@@ -195,7 +202,8 @@ typedef union
         unsigned int RemoteStartNoID:1;             // 0: no effect,                1: need to request RemoteStartNoID
         unsigned int StationInfoReq:1;              // 0: no effect,                1: need to request StationInfo
         unsigned int FinalCostReq:1;                // 0: no effect,                1: need to request FinalCost
-        unsigned int res:28;
+        unsigned int ChargingBill:1;                // 0: no effect,                1: need to request ChargineBill
+        unsigned int res:27;
     }bits;
 } MoreInfoReq;
 
@@ -212,7 +220,8 @@ typedef struct StConnectorState {
     uint8_t ConnectorTemp;
     uint8_t ChillerTemp;
     uint8_t PlugIn;
-    uint8_t Reserved[2];
+    uint32_t consumption;
+    uint8_t ConnectMode;
 } ConnectorState;
 
 typedef struct StConnectorIDTable {
@@ -315,9 +324,21 @@ typedef struct StAccountInfo {
     int Balance;
     int Discount;
     int Transaction;
-    uint8_t Reserved[3];
+    int EnergyCost;
+    int ParkingFee;
+    uint32_t RemainAmount;
+    uint8_t Reserved[1];
 } AccountInfo;
 
+typedef struct StChargingBillInfo {
+    int TotalCost;
+    int Balance;
+    int Discount;
+    int Transaction;
+    int EnergyCost;
+    int ParkingFee;
+    uint32_t RemainAmount;
+} ChargingBillInfo;
 #pragma pack(pop)
 
 #endif /* _DO_COMM_H_ */

+ 53 - 53
EVSE/Projects/DD360Tcci/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -34,6 +34,8 @@ uint8_t TempArray_2[TempArraySize]={0};
 uint8_t ptemp_1 = 0;
 uint8_t ptemp_2 = 0;
 bool firstcircule = true;
+float EvTargetVolt[2] = { 0 };
+float EvTargetCur[2] = { 0 };
 
 //------------------------------------------------------------------------------
 extern bool AbnormalStopAnalysis(uint8_t gun_index, uint8_t *errCode);
@@ -80,10 +82,10 @@ static uint8_t getAvageTemp(uint8_t value,uint8_t gun)
     uint8_t ptr = 0;
     uint8_t *pArray; 
     if(gun == 0) { 
-        pArray = &TempArray_1;
+        pArray = &TempArray_1[0];
         ptr = ptemp_1;
     } else {
-        pArray = &TempArray_2;
+        pArray = &TempArray_2[0];
         ptr = ptemp_2;
     }
 
@@ -228,9 +230,9 @@ static void AddrAssignment(uint8_t *data)
 
 void CheckEvConnect(int gunIndex)
 {
-    int isSameType = FALSE;
     int isDisconnect = FALSE;
     int gunType = _Type_CCS_2;
+    int isSameType = FALSE;
     struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     struct InfoCodeData* pInfoCode = (struct InfoCodeData*)GetShmInfoCodeData();
     struct ChargingInfoData* pDcChargingInfo_0 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
@@ -303,9 +305,8 @@ void CANReceiver(int fd)
         uint8_t lastConnTemp[2] = {0, 0};
         struct can_frame frame;
         ChillerTemp chiilerTemp = {0};
-        time_t CCS_PlugoutTimer[2] = { 0 };
         struct ChargingInfoData *pDcChargingInfo = NULL;
-
+        time_t CCS_PlugoutTimer[2];
         pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
@@ -326,20 +327,25 @@ void CANReceiver(int fd)
             memset(&frame, 0, sizeof(struct can_frame));
 
             for (_index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
-                pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_index);
                 // 檢查是否有收到EV小板訊號
-                if ((time((time_t*)NULL) - ShmDcCommonData->EVDisconnectTime[_index]) > 3 &&
-                    !ShmDcCommonData->EVDisconnectFlag[_index] &&
-                    pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->DebugFlag) {
-                    ShmDcCommonData->EVDisconnectTime[_index] = time((time_t*)NULL);
-                    ShmDcCommonData->EVDisconnectFlag[_index] = TRUE;
-                    log_info("Not Get EV Board %d data in 3 sec.", _index);
-                    system("/sbin/ip link set can0 down");
-                    sleep(1);
-                    system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-                    system("/sbin/ip link set can0 up");
+                if (pSysInfo->SelfTestSeq == _STEST_COMPLETE) {
+                    if ((time((time_t*)NULL) - ShmDcCommonData->pGunInfo[_index].EVLoseTimer > 5) &&
+                        !ShmDcCommonData->pGunInfo[_index].EVLoseFlag &&
+                        pDcChargingInfo->SystemStatus != S_UPDATE && !ShmDcCommonData->DebugFlag) {
+
+                        ShmDcCommonData->pGunInfo[_index].EVLoseTimer = time((time_t*)NULL);
+                        ShmDcCommonData->pGunInfo[_index].EVLoseFlag = TRUE;
+
+                        system("/sbin/ip link set can0 down");
+                        sleep(1);
+                        system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+                        system("/sbin/ip link set can0 up");
+                    }
+                    CheckEvConnect(_index);
+                } else {
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseTimer = time((time_t*)NULL);
+                    ShmDcCommonData->pGunInfo[targetGun].EVLoseFlag = FALSE;
                 }
-                CheckEvConnect(_index);
             }
 
             nbytes = read(fd, &frame, sizeof(struct can_frame));
@@ -400,7 +406,6 @@ void CANReceiver(int fd)
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(targetGun);
             gunTypeIndex = pDcChargingInfo->type_index;
 
-
             switch (intCmd) {
             case NOTIFICATION_EV_STATUS:
                 if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) {
@@ -422,22 +427,16 @@ void CANReceiver(int fd)
                         pSysInfo->CurGunSelected = targetGun;
                     }
                 }
-                // CCS 小板確認拔除三秒
-                if (pDcChargingInfo->Type == _Type_CCS_2) {
-                    if (frame.data[0] == UNPLUG) {
-                        if ((time((time_t*)NULL) - CCS_PlugoutTimer[targetGun]) > 3) {
-                            if (pDcChargingInfo->ConnectorPlugIn != frame.data[0]) 
-                                log_info("CCS Conn %d, Unplug. ", targetGun);
-                        } else {
-                            frame.data[0] = PLUG;
-                        }
-                    } else {
-                        CCS_PlugoutTimer[targetGun] = time((time_t*)NULL);
-                        frame.data[0] = PLUG;
-                    }
-                }
-                pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+
                 pDcChargingInfo->PilotVoltage = frame.data[1];
+                // CCS 小板確認Pilot Voltage != 0
+                if (pDcChargingInfo->Type == _Type_CCS_2 && pDcChargingInfo->PilotVoltage != 0) {
+                    if (frame.data[0] == UNPLUG && pDcChargingInfo->ConnectorPlugIn != frame.data[0])
+                        log_info("Conn %d, Unplug. ", targetGun);
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                } else {
+                    pDcChargingInfo->ConnectorPlugIn = frame.data[0];
+                }
 
                 //log_info("index = %d, ConnectorPlugIn = %x, data[0] = %x ",
                 //         targetGun,
@@ -463,16 +462,6 @@ void CANReceiver(int fd)
                     if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
                         memcpy(ver, frame.data, frame.can_dlc); //DS60-120 add
 
-                        //for (uint8_t _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++) {//DS60-120 remove
-                        /*if (_vCount % 2 == 0 && _vCount != 0)
-                        {
-                            ver[_vCount + _vPoint] = 0x2E;
-                            _vPoint++;
-                        }*/
-
-                        //ver[_vCount + _vPoint] = frame.data[_vCount];
-                        //}
-
                         memcpy(&ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version, ver, ARRAY_SIZE(ver));
                         ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].SelfTest_Comp = PASS;
                         log_info("CCS FW = %s ", ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].version);
@@ -535,8 +524,9 @@ void CANReceiver(int fd)
                 //log_info("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];
                     }
 
@@ -545,8 +535,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];
                     }
 
@@ -556,10 +546,21 @@ void CANReceiver(int fd)
                     ShmGBTData->ev[gunTypeIndex].ChargingCurrentRequest = (pDcChargingInfo->EvBatterytargetCurrent * 10);
                 } else if (pDcChargingInfo->Type == _Type_CCS_2) {
                     if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
-                        ShmCcsData->V2GMessage_DIN70121[gunTypeIndex].PresentMsgFlowStatus = frame.data[0];
+                        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];
+                        }
                     }
                 }
-
+                if (pDcChargingInfo->EvBatterytargetVoltage > (EvTargetVolt[targetGun] + 3) ||
+                    pDcChargingInfo->EvBatterytargetVoltage < (EvTargetVolt[targetGun] - 3) ||
+                    pDcChargingInfo->EvBatterytargetCurrent > (EvTargetCur[targetGun] + 1) ||
+                    pDcChargingInfo->EvBatterytargetCurrent < (EvTargetCur[targetGun] - 1)) {
+                    log_info("Gun%d Battery TargetVoltage = %.1f , TargetCurrent = %.1f",
+                        targetGun,pDcChargingInfo->EvBatterytargetVoltage, pDcChargingInfo->EvBatterytargetCurrent);
+                    EvTargetVolt[targetGun] = pDcChargingInfo->EvBatterytargetVoltage;
+                    EvTargetCur[targetGun] = pDcChargingInfo->EvBatterytargetCurrent;
+                }
                 //log_info("EvBatterytargetVoltage = %f ", pDcChargingInfo->EvBatterytargetVoltage);
                 //log_info("EvBatterytargetCurrent = %f ", pDcChargingInfo->EvBatterytargetCurrent);
                 //log_info("BatteryVoltage = %d ",
@@ -637,12 +638,11 @@ void CANReceiver(int fd)
 
                     pDcChargingInfo->ChillerTemp = maxChillerTemp;
                 }
+                if (frame.data[1] != 0 || frame.data[2] != 0) {
+                    maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
 
-                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
-                //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
-                //    printConnTemp = YES;
-                //}
-                maxConnTemp = getAvageTemp(maxConnTemp,targetGun);
+                    maxConnTemp = getAvageTemp(maxConnTemp, targetGun);
+                }
                 if(maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
                 {
                     lastConnTemp[targetGun] = maxConnTemp;

+ 83 - 22
EVSE/Projects/DD360Tcci/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -324,7 +324,62 @@ static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
         *cur = pDcChargingInfo->ChargingProfileCurrent;
     }
 }
-
+void checkEachGunTypeOTP(int gunIndex, uint8_t Type, int derate_idx, struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
+    deratingByConnOtp->deratingIndex = derate_idx;
+    float pwr;
+    switch (Type) {
+        // Derate by power
+    case 'S':
+        if (pDcChargingInfo->RealMaxPower > deratingByConnOtp->deratingTargetRate[derate_idx]) {
+            pwr = pDcChargingInfo->EvBatterytargetCurrent * pDcChargingInfo->EvBatterytargetVoltage;
+
+            if (pwr > deratingByConnOtp->deratingTargetRate[derate_idx]) {
+                pDcChargingInfo->RealMaxPower *= deratingByConnOtp->deratingTargetRate[derate_idx];;
+            } else {
+                pDcChargingInfo->RealMaxPower = pwr;
+            }
+            log_info("Max Power derating to %.1f", pDcChargingInfo->RealMaxPower);
+        }
+        break;
+        // Derate by current
+    default:
+        if (pDcChargingInfo->RealMaxCurrent > deratingByConnOtp->deratingTargetCurrent[derate_idx]) {
+            if (pDcChargingInfo->EvBatterytargetCurrent > deratingByConnOtp->deratingTargetCurrent[derate_idx]) {
+                pDcChargingInfo->RealMaxCurrent = deratingByConnOtp->deratingTargetCurrent[derate_idx];
+            } else {
+                pDcChargingInfo->RealMaxCurrent = pDcChargingInfo->EvBatterytargetCurrent;
+            }
+            log_info("Max Current derating to %.1f", pDcChargingInfo->RealMaxCurrent);
+        }
+    }
+}
+static void CheckGunTypeOTP(void)
+{
+    uint8_t GunType = 0;
+    int derate_idx;
+    int i;
+
+    for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+        if (pSysConfig->TotalConnectorCount == 1) {
+            GunType = pSysConfig->ModelName[7];
+        } else if (pSysConfig->TotalConnectorCount == 2) {
+            GunType = (i == 0 ? pSysConfig->ModelName[7] : pSysConfig->ModelName[9]);
+        }
+        struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+        if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
+            if (pDcChargingInfo->ConnectorTemp >= _DERATING_85) {
+                derate_idx = 2;
+            } else if (pDcChargingInfo->ConnectorTemp >= _DERATING_80) {
+                derate_idx = 1;
+            } else {
+                derate_idx = 0;
+            }
+        }
+        checkEachGunTypeOTP(i, GunType, derate_idx, &pDcChargingInfo->deratingByConnOtp);
+    }
+}
 static void SetPresentChargingOutputCap(void)
 {
     float pow1 = 0, cur1 = 0;
@@ -339,21 +394,20 @@ static void SetPresentChargingOutputCap(void)
         chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
         chargingData_2 = (struct ChargingInfoData *)GetDcChargingInfoData(1);
     }
-
+/*
 #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     float vol = 0;
 #endif //!defined DD360Tcci && !defined DD360Audi
-
+*/
     pow1 = chargingData_1->AvailableChargingPower;
     cur1 = chargingData_1->AvailableChargingCurrent;
-
+/*
 #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     vol = chargingData_1->MaximumChargingVoltage;
     GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
     //GetMaxPowerMethod(chargingData_1->Index, &pow1);
 #endif //!defined DD360Tcci && !defined DD360Audi
-
-    //DS60-120 add
+*/
     if (pow1 <= 0) {
         cur1 = 0;
     } else {
@@ -371,14 +425,13 @@ static void SetPresentChargingOutputCap(void)
 
     pow2 = chargingData_2->AvailableChargingPower;
     cur2 = chargingData_2->AvailableChargingCurrent;
-
+    /*
 #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
     vol = chargingData_2->MaximumChargingVoltage;
     GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
     //GetMaxPowerMethod(chargingData_2->Index, &pow2);
 #endif //!defined DD360Tcci && !defined DD360Audi
-
-    //DS60-120 add
+*/
     if (pow2 <= 0) {
         cur2 = 0;
     } else {
@@ -413,18 +466,24 @@ static void SetPresentChargingOutputCap(void)
         LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;
         LogInfo[1][EV_LOG_OUTPUT_CAP_POW] = pow2;
         LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] = cur2;
-        chargingData_1->RealMaxCurrent = cur1;
-        chargingData_1->RealMaxPower = pow1;
+    }
 
-        if (pSysConfig->TotalConnectorCount == 2) {
-            chargingData_2->RealMaxCurrent = cur2;
-            chargingData_2->RealMaxPower = pow2;
-        }
+    chargingData_1->RealMaxCurrent = cur1;
+    chargingData_1->RealMaxPower = pow1;
+
+    if (pSysConfig->TotalConnectorCount == 2) {
+        chargingData_2->RealMaxCurrent = cur2;
+        chargingData_2->RealMaxPower = pow2;
     }
 
-    SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
-}
+    //CheckGunTypeOTP();
 
+    SetPresentOutputCapacity(chargingData_1->RealMaxPower,
+        chargingData_1->RealMaxCurrent,
+        chargingData_2->RealMaxPower,
+        chargingData_2->RealMaxCurrent);
+}
+/*
 static uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
 {
     PcPsuOutput *pPcPsuOutput = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[gunIndex];
@@ -438,12 +497,13 @@ static uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
 
     return NO;
 }
-
+*/
 /**
  * [SetPresentChargingOutputFromPcPsu 充電狀態讀取電源櫃PSU輸出電壓電流,縮小誤差值]
  * @Author   Jerry
  * @DateTime 2021-07-05
  */
+/*
 static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
 {
     float vol1 = 0, cur1 = 0;
@@ -498,7 +558,7 @@ static void SetPresentChargingOutputFromPcPsu(uint8_t gunCount)
 
     SetPresentOutputPower(vol1, cur1, vol2, cur2);
 }
-
+*/
 static void SetPresentChargingOutputPower(void)
 {
     float vol1 = 0, cur1 = 0;
@@ -569,7 +629,7 @@ static void SetPresentChargingOutputPower(void)
 
     SetPresentOutputPower(vol1, cur1, vol2, cur2);
 }
-
+/*
 static void checkConnectorOVPState(uint8_t gunIndex)
 {
     struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -612,7 +672,7 @@ static void checkConnectorOVPState(uint8_t gunIndex)
         gunTempAllowCount[gunIndex] = 0;
     }
 }
-
+*/
 static time_t GetRtcInfoForEpoch(void)
 {
     struct timeb csuTime;
@@ -1027,7 +1087,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) *
@@ -1048,6 +1108,7 @@ int main(int argc, char *argv[])
 
                         pDcChargingInfo->PresentChargedEnergy += changingPow;
                         pDcChargingInfo->PowerConsumption += changingPow;
+                        ShmDcCommonData->pGunInfo[gunIndex].PowerConsumption += changingPow;
                         chargingTime[gunIndex] = pDcChargingInfo->PresentChargedDuration;
                     }
                 }

+ 32 - 62
EVSE/Projects/DD360Tcci/Apps/ModuleInternalComm/RelayBoard.c

@@ -36,7 +36,8 @@ static uint16_t fanSpeedSmoothValue = 500;
 static Led_Color cur_led_color = {COLOR_MIN_LV};
 static Led_Color led_color;
 static struct timeval _led_priority_time;
-
+int ReservationLed;
+time_t ReservationFlashTimer;
 bool _show_GFD_Warming[2] = {TRUE};
 //static bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 //static struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
@@ -1493,54 +1494,11 @@ static void SetLedColor(void)
         led_color.Connect_2_Red = _colorBuf;
     } else {
         if (pSysInfo->IsAlternatvieConf) {
-            if ((chargingData_1->SystemStatus == S_BOOTING ||
-                    chargingData_1->SystemStatus == S_IDLE ||
-                    chargingData_1->SystemStatus == S_RESERVATION) &&
-                    (chargingData_2->SystemStatus == S_BOOTING ||
-                     chargingData_2->SystemStatus == S_IDLE ||
-                     chargingData_2->SystemStatus == S_RESERVATION)) {
-#if defined DD360Audi
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = _colorBuf;
-
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = _colorBuf;
-#else
-                led_color.Connect_1_Green = _colorBuf;
-                led_color.Connect_1_Blue = COLOR_MIN_LV;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-
-                led_color.Connect_2_Green = _colorBuf;
-                led_color.Connect_2_Blue = COLOR_MIN_LV;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-#endif
-            } else if ((chargingData_1->SystemStatus >= S_AUTHORIZING &&
-                        chargingData_1->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                        chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                       (chargingData_2->SystemStatus >= S_AUTHORIZING &&
-                        chargingData_2->SystemStatus <= S_COMPLETE) ||
-                       (chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-                        chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                led_color.Connect_1_Green = COLOR_MIN_LV;
-                led_color.Connect_1_Blue = _colorBuf;
-                led_color.Connect_1_Red = COLOR_MIN_LV;
-                led_color.Connect_2_Green = COLOR_MIN_LV;
-                led_color.Connect_2_Blue = _colorBuf;
-                led_color.Connect_2_Red = COLOR_MIN_LV;
-            } else if ( chargingData_1->SystemStatus == S_UPDATE ) {
-                led_color.Connect_1_Green = COLOR_MIN_LV;
-                led_color.Connect_1_Blue = COLOR_MIN_LV;
-                led_color.Connect_1_Red = _colorBuf;
-            }
 
         } else {
+            // 左邊燈條
             if (chargingData_1->SystemStatus == S_BOOTING ||
-                    chargingData_1->SystemStatus == S_IDLE ||
-                    chargingData_1->SystemStatus == S_RESERVATION) {
-
+                    chargingData_1->SystemStatus == S_IDLE ) {
                 if (chargingData_1->IsAvailable == NO) { //For Audi
                     led_color.Connect_1_Green = COLOR_MIN_LV;
                     led_color.Connect_1_Blue = COLOR_MIN_LV;
@@ -1563,18 +1521,24 @@ static void SetLedColor(void)
                 led_color.Connect_1_Green = COLOR_MIN_LV;
                 led_color.Connect_1_Blue = _colorBuf;
                 led_color.Connect_1_Red = COLOR_MIN_LV;
-            }else if ( chargingData_1->SystemStatus == S_UPDATE ||
+            } else if ( chargingData_1->SystemStatus == S_UPDATE ||
                     chargingData_1->SystemStatus == S_MAINTAIN ) {
                 led_color.Connect_1_Green = COLOR_MIN_LV;
                 led_color.Connect_1_Blue = COLOR_MIN_LV;
                 led_color.Connect_1_Red = _colorBuf;
+            } else if (chargingData_1->SystemStatus == S_RESERVATION) {
+                if (ReservationLed) {
+                    led_color.Connect_1_Green = COLOR_MIN_LV;
+                } else {
+                    led_color.Connect_1_Green = _colorBuf;
+                }
+                led_color.Connect_1_Blue = COLOR_MIN_LV;
+                led_color.Connect_1_Red = COLOR_MIN_LV;
             }
-
-
+            // 右邊燈條
             // --------------------------------------------------------------------------
             if (chargingData_2->SystemStatus == S_BOOTING ||
-                    chargingData_2->SystemStatus == S_IDLE ||
-                    chargingData_2->SystemStatus == S_RESERVATION ) {
+                    chargingData_2->SystemStatus == S_IDLE ) {
                 if (chargingData_2->IsAvailable == NO) {
                     led_color.Connect_2_Green = COLOR_MIN_LV;
                     led_color.Connect_2_Blue = COLOR_MIN_LV;
@@ -1602,6 +1566,14 @@ static void SetLedColor(void)
                 led_color.Connect_2_Green = COLOR_MIN_LV;
                 led_color.Connect_2_Blue = COLOR_MIN_LV;
                 led_color.Connect_2_Red = _colorBuf;
+            } else if (chargingData_2->SystemStatus == S_RESERVATION) {
+                if (ReservationLed) {
+                    led_color.Connect_2_Green = COLOR_MIN_LV;
+                } else {
+                    led_color.Connect_2_Green = _colorBuf;
+                }
+                led_color.Connect_2_Blue = COLOR_MIN_LV;
+                led_color.Connect_2_Red = COLOR_MIN_LV;
             }
 
         }
@@ -1659,16 +1631,14 @@ static void LEDBoardProcess(void)
         return;
     }
     pSysConfig->LedInfo.Intensity = LED_INTENSITY_BRIGHTEST;
-    if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000) {
-
-        //if (pSysConfig->TotalConnectorCount == 1) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo0);
-        //} else if (pSysConfig->TotalConnectorCount == 2) {
-        //    pDcChargingInfo0 = (struct ChargeingInfoData *)GetDcChargingInfoData(0);
-        //    pDcChargingInfo1 = (struct ChargeingInfoData *)GetDcChargingInfoData(1);
-        //    SetLedColor(pDcChargingInfo0, pDcChargingInfo1);
-        //}
+    if (GetTimeoutValue(_led_priority_time) / 1000 >= 500) {
+        if (time((time_t*)NULL) - ReservationFlashTimer >= 3) {
+            ReservationFlashTimer = time((time_t*)NULL);
+            if (ReservationLed)
+                ReservationLed = 0;
+            else
+                ReservationLed = 1;
+        }
         SetLedColor();
         gettimeofday(&_led_priority_time, NULL);
     }
@@ -1792,7 +1762,7 @@ void RelayBoardTask(int uartFD)
                              pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
                             (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
                              pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-                            pSysInfo->WaitForPlugit == YES ||
+                            ShmDcCommonData->pGunInfo[i].WaitForPlugit == YES ||
                             (pSysInfo->PageIndex >=  _PAGE_AUTHORIZE &&
                              pSysInfo->PageIndex <= _PAGE_PLUGIN)
                        ) {

+ 12 - 9
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Lcm_Update.c

@@ -29,6 +29,7 @@
 
 DcCommonInfo *ShmDcCommonData = NULL;
 int _port;
+
 void displayMessageDgus(uint8_t *data, uint16_t len, uint8_t isRX)
 {
     uint8_t output[8192];
@@ -151,6 +152,16 @@ int8_t lcdRegisterWrite(int32_t fd, uint8_t regType, uint16_t address, uint8_t *
 
     return result;
 }
+void ResetLCM()
+{
+    uint8_t cmd_reset[] = { 0x55, 0xaa, 0x5a, 0xa5 };
+    while (lcdRegisterWrite(_port, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) != PASS)
+    {
+        log_error("LCD reset fail.\n");
+        sleep(1);
+    }
+    sleep(1);
+}
 //=======================================
 // LCD upgrade
 //=======================================
@@ -392,15 +403,7 @@ uint8_t lcdUpgrade(char *forlder)
 
     return result;
 }
-void ResetLCM()
-{
-    uint8_t cmd_reset [] = { 0x55, 0xaa, 0x5a, 0xa5 };
-    while (lcdRegisterWrite ( _port, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE( cmd_reset ) ) != PASS)
-    {
-        log_error( "LCD reset fail.\n" );
-    }
-    sleep ( 1 );
-}
+
 void UpdateLcmFunction(DcCommonInfo *ShmDcCommonData,int _lcmport)
 {
     _port = _lcmport;

+ 143 - 70
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -344,7 +344,8 @@ void CheckReturnPress()
     }
     // Cancel Trade
 	if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING || 
-        (pDcChargingInfo->SystemStatus == S_IDLE && pSysInfo->SystemPage == _PAGE_AUTHORIZE)) {
+        ((pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION ) &&
+            pSysInfo->SystemPage == _PAGE_AUTHORIZE)) {
         log_info("Press Return button cancel PreAuth");
         ShmDcCommonData->TradeCancel = TRUE;
         pSysInfo->SystemPage = _PAGE_SENSING;
@@ -375,37 +376,14 @@ void CheckReturnPress()
 		strcpy((char *)pSysConfig->UserId, "");
 		return;
 	}
-    // Authorize Page Cancel Trade
-    /*
-    if (pDcChargingInfo->SystemStatus == S_IDLE && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
-        ShmDcCommonData->TradeCancel = TRUE;
-        pSysInfo->SystemPage = _PAGE_SENSING;
-        StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
-        StartSystemTimeoutDet(Timeout_TradeCancel);
-        if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH) {
-            for (i = 0; i <= 30; i++) {
-                if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
-                    break;
-                sleep(1);
-            }
-            ShmDcCommonData->PreAuth_Result = 0;
-        }
-        if (strcmp(ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.VemData, "") != 0) {
-            ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
-            ShmDcCommonData->PreAuth_Result = 0;
-            for (i = 0; i <= 30; i++) {
-                if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
-                    break;
-                sleep(1);
-            }
-        }
-        pSysInfo->SystemPage = _PAGE_SELECT_PAY;
-        return;
-    }*/
+
 	if ( pSysInfo->SystemPage == _PAGE_EXIT ) {
         StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
 		pDcChargingInfo->SystemStatus = S_IDLE;
-		pSysInfo->SystemPage = _PAGE_IDLE;
+        if (ShmDcCommonData->TaiwanEast)
+            pSysInfo->SystemPage = _PAGE_IDLE;
+        else
+            pSysInfo->SystemPage = _PAGE_SELECT_GUN;
 		return;
 	}
 
@@ -425,21 +403,17 @@ void CheckStopPress()
 }
 void CheckStopConfirmPress()
 {
-
 	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
 	pDcChargingInfo->SystemStatus = S_TERMINATING;
 	pSysInfo->SystemPage = _PAGE_PAYING;
 	is_stop = FALSE;
 	//ShmDcCommonData->StopCharge[pSysInfo->CurGunSelected] = TRUE;
-    if (ShmDcCommonData->is_AutoStart[pSysInfo->CurGunSelected] == TRUE) {
+    if (ShmDcCommonData->is_AutoStart[pSysInfo->CurGunSelected] ||
+        ShmDcCommonData->is_RemoteStart[pSysInfo->CurGunSelected]) {
         pSysInfo->SystemPage = _PAGE_COMPLETE;
         return;
     }
 	StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_FinalCost);
-	/*
-	ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
-	ShmDcCommonData->PreAuth_Result = 0;
-	*/
 
 }
 void CheckStopCancelPress()
@@ -450,6 +424,11 @@ void CheckStopCancelPress()
 }
 void CheckConfirmGun(uint8_t gunIndex)
 {
+    pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
+    if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
+        log_info("Reservation can't select");
+        return;
+    }
 	pSysInfo->CurGunSelected = gunIndex;
 	pSysInfo->SystemPage = _PAGE_BILL;
 }
@@ -472,11 +451,17 @@ void CheckDonateNo()
 }
 void CheckPayCreditCard()
 {
-    ShmDcCommonData->LineStatus[pSysInfo->CurGunSelected] = 0;
+    //ShmDcCommonData->LineStatus[pSysInfo->CurGunSelected] = 0;
+    // 使用者進入線上支付,禁止使用者使用刷卡機
+    if (ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].LineStatus == _LINE_PAY_OPERATE) {
+        log_info("Some one operate LINE PAY");
+        return;
+    }
     ShmDcCommonData->TradeCancel = FALSE;
    	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
 
-	if (pDcChargingInfo->SystemStatus == S_IDLE && pSysInfo->SystemPage == _PAGE_SELECT_PAY &&
+	if ((pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION ) &&
+        pSysInfo->SystemPage == _PAGE_SELECT_PAY &&
         ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE) {
         ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
         ShmDcCommonData->PreAuth_Result = 0;
@@ -505,13 +490,18 @@ void CheckTouchPress(short id)
         _btn_press_count = 0;
         switch (id) {
         case _Touch_Show_Left:
-        	if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
+        	if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_SENSING) {
         		log_info("Authorize Process can't select gun");
         		return;
         	}
             // Show log
         	if(pSysInfo->CurGunSelected != LEFT_GUN_NUM) {
         		pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
+                if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
+                    pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+                    log_info("Can't select Reservation Gun");
+                    break;
+                }
         		pSysInfo->CurGunSelected = LEFT_GUN_NUM;
                 if(pDcChargingInfo->SystemStatus == S_IDLE) {
                 	pSysInfo->SystemPage = _PAGE_SELECT_GUN;
@@ -523,17 +513,23 @@ void CheckTouchPress(short id)
         	if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
         			pSysInfo->SystemPage == _PAGE_PAYFAIL) {
 				StopSystemTimeoutDet();
-				StartSystemTimeoutDet(Timeout_ReturnViewPage);
+                if (ShmDcCommonData->TaiwanEast)
+                    StartSystemTimeoutDet(Timeout_ReturnViewPage);
         	}
             break;
         case _Touch_Show_Right:
-        	if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
+        	if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_SENSING) {
         		log_info("Authorize Process can't select gun");
         		return;
         	}
 			// Show log
 			if(pSysInfo->CurGunSelected != RIGHT_GUN_NUM) {
 				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
+                if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
+                    pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+                    log_info("Can't select Reservation Gun");
+                    break;
+                }
 				pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
 	            if(pDcChargingInfo->SystemStatus == S_IDLE) {
 	            	pSysInfo->SystemPage = _PAGE_SELECT_GUN;
@@ -545,7 +541,8 @@ void CheckTouchPress(short id)
         	if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
         			pSysInfo->SystemPage == _PAGE_PAYFAIL) {
 				StopSystemTimeoutDet();
-				StartSystemTimeoutDet(Timeout_ReturnViewPage);
+                if (ShmDcCommonData->TaiwanEast)
+                    StartSystemTimeoutDet(Timeout_ReturnViewPage);
         	}
             break;
         case _Touch_Return:
@@ -669,7 +666,7 @@ void GetHrFormTimeString(char* time,char* hr)
     for(int i = 0 ; i < 2 ; i++) {
         hr[i] = time[i+11];
     }
-    if( atoi(hr) == NULL ) {
+    if( atoi(hr) < 0 || atoi(hr) > 24) {
         strcmp(hr,"");
     }
 }
@@ -679,7 +676,7 @@ void GetMinFormTimeString(char* time,char* min)
     for(int i = 0 ; i < 2 ; i++) {
         min[i] = time[i+14];
     }
-    if( atoi(min) == NULL || atoi(min) > 60) {
+    if( atoi(min) < 0 || atoi(min) > 60) {
         strcmp(min,"");
     }
 }
@@ -804,12 +801,13 @@ void ChangeCurPage()
         case _PAGE_COMPLETE:
             break;
         case _PAGE_MAINTAIN:
-            ShmDcCommonData->ClearServiceQR = FALSE;
             break;
         }
         _currentPage = pSysInfo->PageIndex;
+        /*
         if (pSysInfo->PageIndex != _PAGE_IDLE)
             log_info("Gun[%d] Chagne LCM Page:%d",pSysInfo->CurGunSelected, pSysInfo->PageIndex);
+        */    
         ChangeToOtherPage(pSysInfo->PageIndex);
     }
 }
@@ -891,10 +889,12 @@ void ChangeQrCode_Idle(char *input)
 {
     char cmd[256];
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-    // https://nhoatcc.lineapid.tw/web/tologin?sn=ABC123&cid=2
+    int len = 0;
     memset(cmd,0,256);
-    int len = sprintf(cmd,"https://nhoatcc.lineapid.tw/web/tologin?sn=%s&cid=%d",input,ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
-    //int len = sprintf(cmd, "https://nhoatcctest.lineapid.tw/web/tologin?sn=%s&cid=%d", input, ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
+    if (!ShmDcCommonData->tccdev)
+        len = sprintf(cmd, "https://nhoatcc.lineapid.tw/web/tologin?sn=%s&cid=%d", input, ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
+    else
+        len = sprintf(cmd, "https://nhoatcctest.lineapid.tw/web/tologin?sn=%s&cid=%d", input, ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
     //log_info("QR Code:URL:%s",cmd);
     if (pSysInfo->SystemPage == _PAGE_BILL)
     	DisplayValueToLcm(_QRCode_AddLine, cmd, len+1);
@@ -909,7 +909,7 @@ void ChangeQrCode_Error()
 {
     char cmd[200];
     memset(cmd, 0, 200);
-    int len = sprintf(cmd, "https://line.me/R/ti/p/@217tcevc");
+    sprintf(cmd, "https://line.me/R/ti/p/@217tcevc");
 
     //log_info("QR Code:URL:%s",cmd);
 
@@ -941,7 +941,7 @@ void ShowSelectGun()
 {
 	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
     if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
-        pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
+        pDcChargingInfo->SystemStatus <= S_ALARM) ||
         pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
         pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
 		if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
@@ -970,7 +970,7 @@ void ShowSelectGun()
 	}
 	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
     if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
-        pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
+        pDcChargingInfo->SystemStatus <= S_ALARM) ||
         pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
         pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
 		if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
@@ -1086,7 +1086,6 @@ void ChangeBattMapAndValue(int soc)
 			_battery_display_ani= FALSE ;
 		_battery_display_count = 0;
 	}
-
 	if (pSysInfo->SystemPage == _PAGE_CHARGING) {
 		if (i>=36)
 			ChangeDisplay2Value(_Icon_ChargeCircle,_TCC_Charging_Circle0+36);
@@ -1100,7 +1099,7 @@ void ChangeBattMapAndValue(int soc)
 	} else if (pSysInfo->SystemPage == _PAGE_COMPLETE)
 		ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
 	else
-		ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
+		ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_FAILCircle0 +i);
 
     memset(cmd, 0x00, sizeof(cmd));
     memset(value, 0x00, sizeof(value));
@@ -1226,14 +1225,16 @@ int old_money = 0;
 int ClearQR_flag[2];
 void ProcessPageInfo()
 {
+    if (ShmDcCommonData->CreditCardUpload) {
+        pSysInfo->SystemPage = _PAGE_PAYING;
+    }
     // Show Gun Working and Type
-
     if (pSysInfo->SystemPage == _PAGE_IDLE) {
     	changeWeatherValue(ShmDcCommonData->WeatherID);
     	changeWeekValue(0);
     	changeDegreeValue((int)ShmDcCommonData->Temperature);
     	changeDateValue(&ShmDcCommonData->PresentTime[0]);
-    	changeLocationValue(ShmDcCommonData->Location);
+    	changeLocationValue(1001);
     	return;
     }
     if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
@@ -1263,13 +1264,6 @@ void ProcessPageInfo()
             ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
         }
         ChangeQrCode_Error();
-        /*
-        if (ShmDcCommonData->ClearServiceQR == FALSE) {
-            ShmDcCommonData->ClearServiceQR = TRUE;
-            ClearQrCode_Error();
-            ChangeQrCode_Error();
-        }
-        */
     	return;
     }
     showGunWorkingType();
@@ -1357,7 +1351,8 @@ void ProcessPageInfo()
                 	ChangeTimeValue(0);
                 }
                 ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
-                StartSystemTimeoutDet(Timeout_ReturnViewPage);
+                if (ShmDcCommonData->TaiwanEast)
+                    StartSystemTimeoutDet(Timeout_ReturnViewPage);
                 break;
             case _PAGE_COMPLETE:
             case _PAGE_PAYFAIL:
@@ -1618,6 +1613,80 @@ static int InitialRfidPort(void)
     return fd;
 }
 */
+void DemoFunction(int index)
+{
+    int i;
+    showGunWorkingType();
+    switch (index) {
+    case 1:   // _PAGE_IDLE
+        /*
+        for (i = 0; i <= 100; i++) {
+            changeWeatherValue(i / 20);
+            ChangeDisplay2Value(_Icon_Week, i / 15);
+            changeDegreeValue(i);
+            sprintf(text, "20%02d/%02d/%02d %02d:%02d:%02d", i, i, i, i, i, i);
+            DisplayValueToLcm(_String_Date, (uint8_t*)text, 30);
+            usleep(100000);
+        }
+        */
+        break;
+    case 3:
+        ChangeQrCode_Idle((char*)pSysConfig->SystemId);
+        sleep(3);
+        break;
+    case 4:  //_PAGE_ADD_FRIEND
+        for (i = 0; i <= 10; i++) {
+            ChangeDisplay2Value(_Icon_ScanCntDownTen, (short)_TCC_CntDownNumber0 + i);
+            ChangeDisplay2Value(_Icon_ScanCntDownDigits, (short)_TCC_CntDownNumber0 + i);
+            usleep(100000);
+        }
+        break;
+    case 7:  //_PAGE_AUTHORIZE
+        for (i = 0; i < 10; i++) {
+            ChangeChargingRateValue(i+i*10);
+            ChangeDisplay2Value(_Icon_AuthCntDownTen, (short)_TCC_CntDownNumber0 + i);
+            ChangeDisplay2Value(_Icon_AuthCntDownDigits, (short)_TCC_CntDownNumber0 + i);
+            usleep(100000);
+        }
+        break;
+    case 8:  //_PAGE_SENSING
+        for (i = 0; i < 10; i++) {
+            ChangeDisplay2Value(_Icon_CancelCntDownTen, (short)(_TCC_CancelNum_0 + i));
+            ChangeDisplay2Value(_Icon_CancelCntDownDigits, (short)(_TCC_CancelNum_0 + i));
+            usleep(100000);
+        }
+        break;
+    case 10:  //_PAGE_PRECHARGE
+        for (i = 1; i <= 24; i++) {
+            ChangeDisplay2Value(_Icon_Precharge, i);
+            usleep(100000);
+        }
+        break;
+    case 11:  //_PAGE_CHARGING
+        for (i = 0; i <= 100; i++) {
+            ChangeChargingPowerValue(i);
+            ChangeChargingEnergyValue(i);
+            ChangeChargingFeeValue(i);
+            ChangeTimeValue(i);
+            ChangeBattMapAndValue(i);
+            usleep(100000);
+        }
+        break;
+    case 13:  //_PAGE_PAYING
+        break;
+    case 14:  //_PAGE_COMPLETE
+    case 20:  //_PAGE_PAYFAIL
+        for (i = 0; i <= 100; i++) {
+            ChangeChargingEnergyValue(i);
+            ChangeChargingFeeValue(i);
+            ChangeCarBonValue(i*2);
+            ChangeBattMapAndValue(i);
+            usleep(100000);
+        }
+        break;
+    }
+    sleep(1);
+}
 int main(void)
 {
     bool defaulttext = false;
@@ -1650,9 +1719,7 @@ int main(void)
     //ChangeToOtherPage(_LCM_COMPLETE);
     DefautLayOut();
     //return 0;
-    //uint8_t index = 1;
-
-	int result = 0;
+    uint8_t index = 1;
 
     ShmDcCommonData->PSU_Number = 12;
     /*
@@ -1669,11 +1736,10 @@ int main(void)
             sleep(1);
 
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
-            ShmDcCommonData->ClearServiceQR = FALSE;
         } else {
             UpdateLcmFunction(ShmDcCommonData,_port);
 
-            ///*
+            /*
             // Warning 處理
             if (curWarningCount != pSysWarning->WarningCount) {
                 changeWarningPriority = 0;
@@ -1690,6 +1756,7 @@ int main(void)
 
                 ChangeWarningFunc();
             }
+            */
             ///*
             // Show Default Text
             if (!defaulttext) {
@@ -1697,10 +1764,14 @@ int main(void)
                 ShowDispenserVersionDefautlText();
                 defaulttext = true;
             }
+            
             ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
 
             // 頁面資訊處理
-            ProcessPageInfo();
+            if (!ShmDcCommonData->lcmtest)
+                ProcessPageInfo();
+            else
+                pSysInfo->SystemPage = index;
 
             // 換頁處理
             //GetCurrentPage(); //DS60-120 add
@@ -1719,11 +1790,13 @@ int main(void)
 
             ChangeCurPage();
             changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
-
+            if (ShmDcCommonData->lcmtest) {
+                DemoFunction(index);
+                index >= 20 ? index = 1 : index++;
+            }
             usleep(10000); //*/
 
             /*
-            ProcessPageInfo();
             GetCurrentPage();
             ChangeCurPage();
             usleep(10000);

+ 1 - 0
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -356,6 +356,7 @@ enum _TCC_ICON_LIST_ {
 	_TCC_PlugOutFrame,
 	_TCC_ErrorFrame,
 	_TCC_Warming,
+	_TCC_FAILCircle0,
 	_TCC_ShowLeftGunCharging_CCS1 = 292,
 	_TCC_ShowLeftGunCharging_CCS2,
 	_TCC_ShowLeftGunCharging_CHAdeMo,

+ 26 - 13
EVSE/Projects/DD360Tcci/Apps/ReadCmdline.c

@@ -526,13 +526,22 @@ void writeChillerStatus(char* v1)
     else
         printf("Please open Debug mode\n");
 }
-void writePassBackend()
+void writeTccdev()
 {
-    ShmDcCommonData->passbackend = !ShmDcCommonData->passbackend;
-    if (ShmDcCommonData->passbackend)
-        printf("Pass Backend on\n");
+    ShmDcCommonData->tccdev = !ShmDcCommonData->tccdev;
+    if (ShmDcCommonData->tccdev)
+        printf("TCC DEV on\n");
     else
-        printf("Pass Backend off\n");
+        printf("TC DEV off\n");
+
+}
+void showlcmtest()
+{
+    ShmDcCommonData->lcmtest = !ShmDcCommonData->lcmtest;
+    if (ShmDcCommonData->lcmtest)
+        printf("LCM Test on\n");
+    else
+        printf("LCM Test off\n");
 
 }
 void SetFanSpeed(char *v1)
@@ -764,9 +773,9 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         case S_IDLE:
             if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
+                sleep(3);
                 setConfirmSelGun(curGun);
-
+                ShmDcCommonData->TradeCancel = FALSE;
                 pSysInfo->SystemPage = _PAGE_SENSING;
                 strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
                 pDcChargingInfo->ConnectorPlugIn = 1;
@@ -948,14 +957,16 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
             pDcChargingInfo->SystemStatus = S_COMPLETE;
             break;
-
         case S_COMPLETE:
             if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
 
                 printf ("[UnconditionalCharge - S_COMPLETE]\n");
+                pDcChargingInfo->TimeoutFlag = 0;
+                pSysInfo->PageIndex = _PAGE_COMPLETE;
+                ShmDcCommonData->StopCharge[gunIndex] = FALSE;
             }
-
+            pSysInfo->SystemTimeoutFlag = 0;
             PreviousSystemStatus[curGun] = 0xFF;
             stopChg = 0;
             for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
@@ -1134,7 +1145,7 @@ static void resdGunAndChillerTemp(void)
 
                 pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
 
-                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
+                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d, SysTemp = %3d, %3d, %3d, %3d\r\n",
                              i,
                              pDcChargingInfo->ConnectorTemp,
                              pDcChargingInfo->ChillerTemp,
@@ -1282,7 +1293,7 @@ int main(void)
                      "       rededuct                          : Credit Card rededuct\n"
                      "       preauth                           : Credit Card PreAuth\n"
                      "       preauthcancel                     : Credit Card PreAuth Cancel\n"
-                     "       passbackend                       : Pass Backend disconnect\n"
+                     "       tccdev                            : print TCC dev QR Code\n"
                      "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
@@ -1467,8 +1478,10 @@ int main(void)
             ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
         } else if (strcmp(newString[0], "chiller") == 0) { //測試槍頭和水冷機溫度
             writeChillerStatus(newString[1]);
-        } else if (strcmp(newString[0], "passbackend") == 0) { //Pass Backend disconnect
-            writePassBackend();
+        } else if (strcmp(newString[0], "tccdev") == 0) { //Open TCC DEV
+            writeTccdev();
+        } else if (strcmp(newString[0], "lcmtest") == 0) { 
+            showlcmtest();
         } else {
             printf("%s\n", usageMsg);
         }

+ 3 - 0
EVSE/Projects/DD360Tcci/Apps/SelectGun/SelectGun.h

@@ -62,6 +62,9 @@ typedef struct StPricesInfo {
     //float DefaultPrices;        //unit = 0.01 dollar, value / 100
     float Discount;
     int TransactionId;
+    float EnergyCost;
+    float ParkingFee;
+    float RemainAmount;
 } PricesInfo;
 
 //typedef struct StOperativeInfo {

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


BIN
EVSE/Projects/DD360Tcci/output/FactoryConfig


BIN
EVSE/Projects/DD360Tcci/output/Module_ChkSysTask


BIN
EVSE/Projects/DD360Tcci/output/Module_DoComm


BIN
EVSE/Projects/DD360Tcci/output/Module_EvComm


BIN
EVSE/Projects/DD360Tcci/output/Module_EventLogging


BIN
EVSE/Projects/DD360Tcci/output/Module_InternalComm


BIN
EVSE/Projects/DD360Tcci/output/Module_LcmControl


BIN
EVSE/Projects/DD360Tcci/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Tcci/output/Module_UpdateFW


BIN
EVSE/Projects/DD360Tcci/output/ReadCmdline


BIN
EVSE/Projects/DD360Tcci/output/main


BIN
EVSE/rootfs/root/Module_PowerSharing


+ 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 cp -r /mnt/d/Phihong/Project/DD360Tcci/Apps/* $ProjectPath/DD360Tcci/Apps/
+#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 DD360Tcci-rootfs
+cp $ProjectPath/DD360Tcci/Images/* /mnt/d/Image/DD360Tcc/
+#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/
+

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно