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

2022-03-16 / Simon Xue

Action:
1. [bug] Swift card and press return button will enter authorize mode.
2. [Modify] Not into charge and occure error flow.
3. [Modify] DataBase item add more credit card information.
4. [Add] Update preauthcancel to backend.
5. [Modify] Print more debug information.
6. [Modify] PreAuth money change to 888.
7. [Modify] Reupload Credit card information timing.

Files
As the following commit history files

Image Version: v2.08.XX.XXXX.XX
Simon Xue 3 жил өмнө
parent
commit
902e2cbc3d

+ 71 - 52
EVSE/Projects/DD360Tcci/Apps/CSU/RFID.c

@@ -15,7 +15,7 @@
 static DcCommonInfo *ShmDcCommonData 			= NULL;
 static SelectGunInfo *ShmSelectGunInfo          = NULL;
 static struct SysInfoData *pSysInfo 			= NULL;
-#define PREAUTHMONEY	1000
+#define PREAUTHMONEY	888
 bool isDeductDb_ready;
 static RecordTransactionInfo LocalTransactionInfo;
 //------------------------------------------------------------------------------
@@ -393,11 +393,7 @@ int CreditCardCancelPreAuth(int fd, uint8_t gunIndex)
     }
     ShmDcCommonData->TransactionInfo[gunIndex].IsUpload = FALSE;
     UpdateDeductInfoStatus(gunIndex, &ShmDcCommonData->TransactionInfo[gunIndex]);
-
-    if (ShmDcCommonData->PreAuth_Result >= 0) {
-        memset(&ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard, 0, sizeof(TransInfo));
-    }
-
+    memset(&ShmDcCommonData->TransactionInfo[gunIndex], 0x00, sizeof(RecordTransactionInfo));
     ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
     return ShmDcCommonData->PreAuth_Result;
 }
@@ -415,12 +411,13 @@ void ReDeductProcess(int fd)
     if (rededuct_num == 0)
         log_info("No Rededuct Information");
     else {
-        log_info("Rededuct Number:%d", rededuct_num);
+        log_info("Rededuct Total Number:%d", rededuct_num);
         for (j = 0; j < rededuct_num; j++) {
             if (pSysInfo->SystemPage != _PAGE_IDLE && !ShmDcCommonData->Exe_ReDeduct) {
                 ShmDcCommonData->RoutineReduct = FALSE;
                 break;
             }
+            log_info("Start Rededuct item [%d]",j);
             if (deductInfo[j].isIntoCharge == FALSE || deductInfo[j].Energy == 0) {
                 // 未進入充電或度數等於零
                 result = CreditCardPreAuthCancel(fd, PREAUTHMONEY, &pSysConfig->ModelName[0],
@@ -446,11 +443,9 @@ void ReDeductProcess(int fd)
                 sleep(10);
                 if (result > 0) {
                     deductInfo[j].DeductResult = _DEDUCT_COMPLETE_PASS;
-                    deductInfo[j].IsUpload = NO;
                     log_info("Backgroud PreAuthComplete OK");
                 } else if (result < 0) {
                     deductInfo[j].DeductResult = _DEDUCT_COMPLETE_FAIL;
-                    deductInfo[j].IsUpload = NO;
                     log_info("Backgroud ID:%d Amount:%d VemData:%s PreAuthComplete fail",
                         deductInfo[j].TransactionId,
                         (int)deductInfo[j].Amount,
@@ -458,6 +453,7 @@ void ReDeductProcess(int fd)
                 }
             }
             deductInfo[j].IsUpload = FALSE;
+            deductInfo[j].RedeductTime++;
             UpdateDeductInfoStatus(rededuct_gunIndex[j], &deductInfo[j]);
         }
     }
@@ -495,7 +491,7 @@ void CreateRfidFork(void)
     int rededuct_gunIndex[128];
     RecordTransactionInfo deductInfo[128];
     int rededuct_num = 0;
-
+    int donate = 0;
     rfidRecPid = fork();
     int j = 0;
     if (rfidRecPid == 0) {
@@ -538,71 +534,84 @@ void CreateRfidFork(void)
                 ShmDcCommonData->PreAuth_Result = 0;
             }
 
-            if (ShmDcCommonData->UnionSettlement) {
-                ShmDcCommonData->UnionSettlement = 0;
-                result = CreditCardUnionSettlement(fd, &pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[0].pCreditCard);
-                if (result > 0) {
-                    log_info("CreditCardUnionSettlement OK");
-                }
-                else
-                    log_info("CreditCardUnionSettlement FAIL");
-            }
             is_idle = TRUE;
 			for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
 				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 				if (pDcChargingInfo->SystemStatus != S_IDLE) {
 					is_idle = FALSE;
 				}
-				if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && ShmDcCommonData->finalcost_flag[gunIndex]) {
+                if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && pDcChargingInfo->Replug_flag == TRUE) {
                     ShmDcCommonData->StopCharge[gunIndex] = FALSE;
-                    ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
-                    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) {
-                        pSysInfo->SystemPage = _PAGE_COMPLETE;
-                        ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
-                        continue;
-                    }
-                    // 實際扣款
-					if (ShmDcCommonData->TransactionInfo[gunIndex].Amount == 0) {
-                        log_info("Final Cost less 1 , Cancel Trade!!");
-                        if (CreditCardCancelPreAuth(fd, gunIndex) > 0) {
+                    log_info("Not Into Charging cancel Trade");
+                    StopGunInfoTimeoutDet(gunIndex);
+                    ShmDcCommonData->TradeCancel = TRUE;
+                    pSysInfo->SystemPage = _PAGE_SENSING;
+                    StartSystemTimeoutDet(Timeout_TradeCancel);
+                    CreditCardCancelPreAuth(fd, gunIndex);
+                    pSysInfo->SystemPage = _PAGE_PLUGOUT;
+                    StopSystemTimeoutDet();
+                } else {
+                    if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && ShmDcCommonData->finalcost_flag[gunIndex]) {
+                        ShmDcCommonData->StopCharge[gunIndex] = FALSE;
+                        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;
+                        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) {
                             pSysInfo->SystemPage = _PAGE_COMPLETE;
                             ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
+                            continue;
                         }
-                        else {
-                            pSysInfo->SystemPage = _PAGE_PAYFAIL;
-                            ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
+                        // 實際扣款
+                        if (ShmDcCommonData->TransactionInfo[gunIndex].Amount < 1) {
+                            log_info("Final Cost less 1 , Cancel Trade!!");
+                            if (CreditCardCancelPreAuth(fd, gunIndex) > 0) {
+                                pSysInfo->SystemPage = _PAGE_COMPLETE;
+                                ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
+                            } else {
+                                pSysInfo->SystemPage = _PAGE_PAYFAIL;
+                                ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
+                            }
+                        } else {
+                            PreAuthCompleteToCardReader(fd, gunIndex);
                         }
-					} else {                        		
-						PreAuthCompleteToCardReader(fd,gunIndex);
-					}
-				}
+                    }
+                }
 			} // for
             // 取消預授權
             if(ShmDcCommonData->PreAuth_Config == _CREDITCARD_CANCEL) {
                 CreditCardCancelPreAuth(fd,pSysInfo->CurGunSelected);
             // 預授權
-            } else if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH /* && ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected]*/) {                
+            } else if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH /* && ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected]*/) {
+                donate = (int)ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice;
+                memset(&ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected], 0x00, sizeof(RecordTransactionInfo));
+                ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = (unsigned char)donate;
         		result = CreditCardPreAuth(fd, PREAUTHMONEY,&pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard);
+                if (!ShmDcCommonData->TradeCancel)
+                    StopSystemTimeoutDet();
                 if (ShmDcCommonData->TradeCancel == FALSE && result > 0) {
                     pSysInfo->SystemPage = _PAGE_SENSING;
-                    sleep(10);
                 }
-                StopSystemTimeoutDet();
+                sleep(10);
+
                 ShmDcCommonData->PreAuth_Result = result;
 				//result = 1;
-				if (result > 0) {
+				if (result > 0 && strcmp(ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.CardNo,"") != 0 ) {
+
 					ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = TRUE;
                     strncpy((char*)pSysConfig->UserId, (char *)ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.CardNo, 20);
                     log_info("Authorize card:%s", pSysConfig->UserId);
                     ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].DeductResult = _DEDUCT_PREAUTH;
                     ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsUpload = FALSE;
-                    InsertDeductInfo(pSysInfo->CurGunSelected,&ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected]);
+                    InsertDeductInfo(ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected], &ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected]);
 					log_info("PreAuth OK");
 				} else if (result < 0) {
                     if (ShmDcCommonData->TradeCancel == FALSE)
@@ -621,16 +630,26 @@ void CreateRfidFork(void)
                 ReDeductProcess(fd);
                 ShmDcCommonData->Exe_ReDeduct = 0;
             }
+
             // 每日晚上11點30分結帳
-            if (is_idle == TRUE && tm->tm_hour == 15 && tm->tm_min > 30  &&
-                ShmDcCommonData->RoutineSettlement == FALSE) {
-                ShmDcCommonData->RoutineSettlement = TRUE;
-                result = CreditCardUnionSettlement(fd, &pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[0].pCreditCard);
+            if (is_idle == TRUE && pSysInfo->SystemPage == _PAGE_IDLE && 
+                ((tm->tm_hour == 15 && tm->tm_min > 30  && ShmDcCommonData->RoutineSettlement == FALSE) ||
+                    ShmDcCommonData->UnionSettlement)) {
+                StopSystemTimeoutDet();
+                if (ShmDcCommonData->UnionSettlement)
+                    ShmDcCommonData->UnionSettlement = 0;
+                else
+                    ShmDcCommonData->RoutineSettlement = TRUE;
+                pSysInfo->SystemPage = _PAGE_MAINTAIN;
+                 
+                result = CreditCardUnionSettlement(fd, &pSysConfig->ModelName[0], &LocalTransactionInfo.pCreditCard);
                 if (result > 0) {
                     log_info("CreditCardUnionSettlement OK");
                 }
                 else
                     log_info("CreditCardUnionSettlement FAIL");
+                sleep(90);
+                pSysInfo->SystemPage = _PAGE_IDLE;
             }
             if (tm->tm_hour == 16 && tm->tm_min == 0) {
                 ShmDcCommonData->RoutineSettlement = FALSE;

+ 129 - 65
EVSE/Projects/DD360Tcci/Apps/CSU/main.c

@@ -82,7 +82,7 @@ uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
 char *fwVersion = "V2.08.00.0000.00"; // Phihong version
-char* DebugVersion = "v2.08.00";      // Software debug version
+char* DebugVersion = "v2.08.03";      // Software debug version
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -1492,18 +1492,32 @@ void _SelfTestTimeout(void)
 
 void _AuthorizedTimeout(void)
 {
+    int i;
     //if (IsAuthorizingMode()) {
         log_info("*********** _AuthorizedTimeout *********** ");
         StopSystemTimeoutDet();
         //isCardScan = false;
         SetIsCardScan(false);
 
-        pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+        //StopSystemTimeoutDet();
+        StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
+        ShmDcCommonData->TradeCancel = TRUE;
         ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
         ShmDcCommonData->PreAuth_Result = 0;
-        //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
-        strcpy((char *)pSysConfig->UserId, "");
+        pSysInfo->SystemPage = _PAGE_SENSING;
+        StartSystemTimeoutDet(Timeout_TradeCancel);
+        for (i = 0; i <= 30; i++) {
+            if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
+                break;
+            sleep(1);
+        }
+        ShmDcCommonData->PreAuth_Result = 0;
+
+        StopSystemTimeoutDet();
+        ClearDetectPluginFlag();
+        strcpy((char*)pSysConfig->UserId, "");
         ClearAuthorizedFlag();
+        setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
      //   StartSystemTimeoutDet(Timeout_ReturnViewPage);
     //}
 }
@@ -1515,11 +1529,13 @@ void _DetectPlugInTimeout(uint8_t gunIndex)
     strcpy((char *)pSysConfig->UserId, "");
     //StopSystemTimeoutDet();
     StopGunInfoTimeoutDet(gunIndex);
-
+    ShmDcCommonData->TradeCancel = TRUE;
 	ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
 	ShmDcCommonData->PreAuth_Result = 0;
+    pSysInfo->SystemPage = _PAGE_SENSING;
+    StartSystemTimeoutDet(Timeout_TradeCancel);
 	for(i=0;i<=30;i++) {
-		if(ShmDcCommonData->PreAuth_Result == _CREDITCARD_IDLE)
+		if(ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
 			break;
 		sleep(1);
 	}
@@ -1527,6 +1543,7 @@ void _DetectPlugInTimeout(uint8_t gunIndex)
 
     if (pSysInfo->CurGunSelected == gunIndex)
     	pSysInfo->SystemPage = _PAGE_IDLE;
+    StopSystemTimeoutDet();
     ClearDetectPluginFlag();
     strcpy((char *)pSysConfig->UserId, "");
 	setChargerMode(gunIndex, S_IDLE);
@@ -1753,16 +1770,16 @@ void ReleaseAlarmCode(uint8_t gunIndex)
 void ChargingTerminalProcess(uint8_t gunIndex)
 {
     pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
-    if (pDcChargingInfo->SystemStatus == S_CHARGING)
-        ShmDcCommonData->StopCharge[gunIndex] = TRUE;
+    //if (pDcChargingInfo->SystemStatus == S_CHARGING)
+    ShmDcCommonData->StopCharge[gunIndex] = TRUE;
     setChargerMode(gunIndex, MODE_TERMINATING);
 }
 
 void ChargingAlarmProcess(uint8_t gunIndex)
 {
     pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
-    if (pDcChargingInfo->SystemStatus == S_CHARGING)
-        ShmDcCommonData->StopCharge[gunIndex] = TRUE;
+    //if (pDcChargingInfo->SystemStatus == S_CHARGING)
+    ShmDcCommonData->StopCharge[gunIndex] = TRUE;
     UpdateErrorCodeToOcpp(gunIndex);
     setChargerMode(gunIndex, MODE_ALARM);
 }
@@ -2510,12 +2527,13 @@ void CreateTimeoutFork(void)
             	break;
             case Timeout_Authorizing:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
-                    //log_error("Authorizing Timeout");
+                    log_error("Authorizing Timeout");
                     _AuthorizedTimeout();
                     if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
                         ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
                         pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
                         log_error("Author timeout restart DoComm");
+                        system("killall Module_DoComm");
                     }
                 }
                 break;
@@ -2534,6 +2552,7 @@ void CreateTimeoutFork(void)
             case Timeout_VerifyFail:
 
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                    log_info("Timeout_VerifyFail");
                     /*if (pSysInfo->SystemPage ==_LCM_START_AUTHORIZE_FAIL ) {
                         StopSystemTimeoutDet();
                         _AutoReturnTimeout();
@@ -2579,6 +2598,7 @@ void CreateTimeoutFork(void)
 
             case Timeout_AuthorizingForStop:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
+                    log_info("Timeout_AuthorizingForStop");
                     strcpy((char *)pSysConfig->UserId, "");
                     ClearAuthorizedFlag();
                     StopSystemTimeoutDet();
@@ -2587,6 +2607,7 @@ void CreateTimeoutFork(void)
                 break;
             case Timeout_ScanCard:
 				if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_SCANCARD_TIMEOUT) {
+                    log_info("Timeout_ScanCard");
 					strcpy((char *)pSysConfig->UserId, "");
 					ClearAuthorizedFlag();
 					StopSystemTimeoutDet();
@@ -2606,6 +2627,7 @@ void CreateTimeoutFork(void)
                 break;
             case Timeout_AddLine:
             	if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_ADDLINE_TIMEOUT) {
+                    log_info("Timeout_AddLine");
             		StopSystemTimeoutDet();
             		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
                     ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
@@ -2614,12 +2636,14 @@ void CreateTimeoutFork(void)
 
             case Timeout_DonateComfirm:
             	if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_DONATECOMFIRM_TIMEOUT) {
+                    log_info("Timeout_DonateComfirm");
             		StopSystemTimeoutDet();
             		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
             	}
             	break;
             case Timeout_SelectPayMode:
             	if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_SELECTPAY_TIMEOUT) {
+                    log_info("Timeout_SelectPayMode");
             		StopSystemTimeoutDet();
             		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
                     ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
@@ -2627,6 +2651,7 @@ void CreateTimeoutFork(void)
             	break;
             case Timeout_TradeCancel:
                 if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_TRADECANCEL_TIMEOUT) {
+                    log_info("Timeout_TradeCancel");
                     StopSystemTimeoutDet();
                     pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
                     setChargerMode(pSysInfo->CurGunSelected, MODE_IDLE);
@@ -2703,6 +2728,7 @@ void CreateTimeoutFork(void)
                     break;
                 case Timeout_PlugOutGun:
                     if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= PLUGOUTGUN_TIMEOUT) {
+                        log_info("Gun[%d] Timeout_PlugOutGun",gunIndex);
                         setChargerMode(gunIndex, MODE_IDLE);
                         destroySelGun(gunIndex); //Jerry add
                         StopGunInfoTimeoutDet(gunIndex);
@@ -2711,6 +2737,7 @@ void CreateTimeoutFork(void)
                     break;
                 case Timeout_FinalCost:
                 	if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_FINALCOST_TIMEOUT) {
+                        log_info("Gun[%d] Timeout_FinalCost",gunIndex);
                 		StopGunInfoTimeoutDet(gunIndex);
                 		if (ShmDcCommonData->finalcost_flag[gunIndex] == FALSE) {
                 			ShmDcCommonData->TransactionInfo[gunIndex].Amount = pDcChargingInfo->PresentChargedEnergy * ShmDcCommonData->ChargingRate;
@@ -2720,12 +2747,22 @@ void CreateTimeoutFork(void)
                 	break;
                 case Timeout_LineReigster:
                 	if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_LINEREGISTER_TIMEOUT) {
+                        log_info("Gun[%d] Timeout_LineReigster",gunIndex);
                 		StopGunInfoTimeoutDet(gunIndex);
                 		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
                 		ShmDcCommonData->TransactionInfo[gunIndex].IsDonateInvoice = FALSE;
                         ShmDcCommonData->OperateIDLE[gunIndex] = 1;
                 	}
                 	break;
+                case Timeout_ExitPage:
+                    if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_EXITPAGE_TIMEOUT) {
+                        log_info("Gun[%d] Timeout_ExitPage", gunIndex);
+                        StopGunInfoTimeoutDet(gunIndex);
+                        ShmDcCommonData->is_exit[gunIndex] = TRUE;
+                        pSysInfo->SystemPage = _PAGE_EXIT;
+                        StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
+                    }
+                    break;
                     /*
                 case Timeout_SelectGun: //Jerry add 
                     if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
@@ -3889,6 +3926,8 @@ void ResetIdleData(uint8_t gunIndex)
     ShmDcCommonData->OperateIDLE[gunIndex] = 1;
     ShmDcCommonData->is_RemoteStart[gunIndex] = FALSE;
     ShmDcCommonData->is_AutoStart[gunIndex] = FALSE;
+    ShmDcCommonData->is_exit[gunIndex] = FALSE;
+    ShmDcCommonData->StopCharge[gunIndex] = FALSE;
 
     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
     destroySelGun(gunIndex);
@@ -4010,7 +4049,7 @@ int main(void)
     log_info(" ********************************************************");
     log_info(" ******************  Project:DD360Tcc   *****************");
     log_info(" ********************************************************");
-    int is_plugout[2];
+
     if (!InitialSystemDefaultConfig()) {
         log_error("InitialSystemDefaultConfig NG ");
         //StopProcessingLoop();
@@ -4181,7 +4220,6 @@ int main(void)
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_IDLE(%x) ============================= ", gunIndex);
                     ResetIdleData(gunIndex);
-                    is_plugout[gunIndex] = FALSE;
                 }
                 isChargingAverageState();
                 // For RemoteStart Using
@@ -4195,7 +4233,8 @@ int main(void)
                 autoStartCharging(gunIndex);
                 cancelcount = 0;
                 // 讀卡邏輯
-                ScannerCardProcess();
+                if (!ShmDcCommonData->TradeCancel)
+                    ScannerCardProcess();
                 if (pSysInfo->SystemPage == _PAGE_SELECT_GUN) {
                 	ShmDcCommonData->LineStatus[gunIndex] = 0;
                 	StopGunInfoTimeoutDet(gunIndex);
@@ -4488,7 +4527,7 @@ CheckStatus:
                 // 切換 D+ Relay to Precharge Relay
                 if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
                     pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
-                    pSysInfo->CurGunSelected = gunIndex;
+                   // pSysInfo->CurGunSelected = gunIndex;
                     setChargerMode(gunIndex, MODE_CHARGING);
                 }
                 if (pSysInfo->CurGunSelected == gunIndex) {
@@ -4505,7 +4544,6 @@ CheckStatus:
                     ChangeStartOrStopDateTime(YES, gunIndex);
                     pDcChargingInfo->Replug_flag = FALSE;
                     ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
-                    ShmDcCommonData->StopCharge[gunIndex] = FALSE;
                     ShmDcCommonData->TransactionInfo[gunIndex].isIntoCharge = TRUE;
                     ShmDcCommonData->RecordEnergyTime[gunIndex] = time((time_t*)NULL);
                     UpdateDeductInfoStatus(gunIndex, &ShmDcCommonData->TransactionInfo[gunIndex]);
@@ -4549,8 +4587,15 @@ CheckStatus:
                     StopGunInfoTimeoutDet(gunIndex);
                     StartGunInfoTimeoutDet(gunIndex, Timeout_FinalCost);
                     StartSystemTimeoutDet(Timeout_Terminating);
-                    pSysInfo->CurGunSelected = gunIndex;
-                    pSysInfo->SystemPage = _PAGE_PAYING;
+                    //pSysInfo->CurGunSelected = gunIndex;
+                    /*
+                    if (pDcChargingInfo->Replug_flag == TRUE) {
+                        ShmDcCommonData->TradeCancel = TRUE;
+                        StartSystemTimeoutDet(Timeout_TradeCancel);
+                        ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
+                        ShmDcCommonData->PreAuth_Result = 0;
+                        pSysInfo->SystemPage = _PAGE_SENSING;
+                    }*/
                 }
                 // For Precharging timeout
 
@@ -4578,12 +4623,16 @@ CheckStatus:
                 if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
 					break;
                 }
-                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING &&
-                    ShmDcCommonData->finalcost_flag[gunIndex]) {
-                	if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
-                		pSysInfo->SystemPage = _PAGE_COMPLETE;
-                	else
-                		pSysInfo->SystemPage = _PAGE_PAYFAIL;
+                if (pSysInfo->CurGunSelected == gunIndex && 
+                    pSysInfo->SystemPage != _PAGE_PAYING && pSysInfo->SystemPage != _PAGE_SENSING) {
+                    if (pDcChargingInfo->Replug_flag == TRUE)
+                        pSysInfo->SystemPage = _PAGE_PLUGOUT;
+                    else {
+                        if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
+                            pSysInfo->SystemPage = _PAGE_COMPLETE;
+                        else
+                            pSysInfo->SystemPage = _PAGE_PAYFAIL;
+                    }
                 }
                 break;
 
@@ -4594,35 +4643,43 @@ CheckStatus:
                         OcppStopTransation(gunIndex);
                     }
                     TheEndCharging(gunIndex);
-                    StopSystemTimeoutDet();
+                    if (pDcChargingInfo->Replug_flag != TRUE && pSysInfo->SystemPage != _PAGE_PLUGOUT)
+                        StopSystemTimeoutDet();
                     if (ShmDcCommonData->is_AutoStart[gunIndex] == TRUE && pSysInfo->CurGunSelected == gunIndex)
                         pSysInfo->SystemPage = _PAGE_COMPLETE;
                 }
-
+                /*
+                if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_CANCEL &&
+                    ShmDcCommonData->PreAuth_Result != 0 && cancelcount < 30) {
+                    sleep(1);
+                    cancelcount++;
+                    log_info("Cancel Not Complete yet");
+                    break;
+                }
+                */
                 //if (pSysInfo->SystemPage == _LCM_ERROR) {
                 if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
                     break;
                 }
-                if (pSysInfo->CurGunSelected == gunIndex && is_plugout[gunIndex] == TRUE) {
-                    StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
+                if (pSysInfo->CurGunSelected == gunIndex && ShmDcCommonData->is_exit[gunIndex]) {
                 	pSysInfo->SystemPage = _PAGE_EXIT;
                 	break;
                 }
-                if (pSysInfo->CurGunSelected == gunIndex &&  pDcChargingInfo->ConnectorPlugIn == NO) {
-                	is_plugout[gunIndex] = TRUE;
-                    StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
-                    if (pSysInfo->CurGunSelected == gunIndex) {
-                        sleep(10);
-                    	pSysInfo->SystemPage = _PAGE_EXIT;
-                    	break;
-                    }
+                if (pSysInfo->CurGunSelected == gunIndex &&  pDcChargingInfo->ConnectorPlugIn == NO &&
+                    (pSysInfo->SystemPage != _PAGE_PAYING || pSysInfo->SystemPage != _PAGE_SENSING)) {
+                    StartGunInfoTimeoutDet(gunIndex, Timeout_ExitPage);
                 }
 
-                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING ) {
-                	if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
-						pSysInfo->SystemPage = _PAGE_COMPLETE;
-					else
-						pSysInfo->SystemPage = _PAGE_PAYFAIL;
+                if (pSysInfo->CurGunSelected == gunIndex && 
+                    pSysInfo->SystemPage != _PAGE_PAYING && pSysInfo->SystemPage != _PAGE_SENSING) {
+                    if (pDcChargingInfo->Replug_flag == TRUE)
+                        pSysInfo->SystemPage = _PAGE_PLUGOUT;
+                    else {
+                        if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
+                            pSysInfo->SystemPage = _PAGE_COMPLETE;
+                        else
+                            pSysInfo->SystemPage = _PAGE_PAYFAIL;
+                    }
                 }
 
                 break;
@@ -4639,17 +4696,23 @@ CheckStatus:
                     }
                     TheEndCharging(gunIndex);
                     StopGunInfoTimeoutDet(gunIndex);
-                    StartGunInfoTimeoutDet(gunIndex, Timeout_FinalCost);
+                    
                     if (pDcChargingInfo->Replug_flag == TRUE) {
+                        /*
+                        ShmDcCommonData->TradeCancel = TRUE;
+                        StartSystemTimeoutDet(Timeout_TradeCancel);
                 		ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
                 		ShmDcCommonData->PreAuth_Result = 0;
-                        pSysInfo->SystemPage = _PAGE_PLUGOUT;
+                        pSysInfo->SystemPage = _PAGE_SENSING;
+                        */
                     } else {
+                        StartGunInfoTimeoutDet(gunIndex, Timeout_FinalCost);
 						if(ShmDcCommonData->finalcost_flag[gunIndex] == FALSE) {
 							pSysInfo->SystemPage = _PAGE_PAYING;
 						}
                     }
                 }
+                /*
                 if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_CANCEL && 
                     ShmDcCommonData->PreAuth_Result != 0 && cancelcount < 30) {
                     sleep(1);
@@ -4657,30 +4720,21 @@ CheckStatus:
                     //log_info("Cancel Not Complete yet");
                     break;
                 }
+                */
                 if (pSysWarning->Level == WARN_LV_ER) {
 					pSysInfo->SystemPage = _PAGE_MAINTAIN;
 
 					continue;
 				}
-                if (pSysInfo->CurGunSelected == gunIndex && is_plugout[gunIndex] == TRUE) {
-                    StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
-                	pSysInfo->SystemPage = _PAGE_EXIT;
-                	break;
+                if (pSysInfo->CurGunSelected == gunIndex && ShmDcCommonData->is_exit[gunIndex]) {
+                    pSysInfo->SystemPage = _PAGE_EXIT;
+                    break;
                 }
 
-                if (pSysInfo->CurGunSelected == gunIndex && pDcChargingInfo->ConnectorPlugIn == NO) {
-                	is_plugout[gunIndex] = TRUE;
-					if (pDcChargingInfo->Replug_flag == TRUE) {
-						pSysInfo->SystemPage = _PAGE_SELECT_GUN;
-						pDcChargingInfo->SystemStatus = S_IDLE;
-					} else {
-						StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
-						pSysInfo->SystemPage = _PAGE_EXIT;
-					}
-					break;
-				}
-                //if (pSysInfo->SystemPage == _PAGE_PAYING)
-                //	break;
+                if (pSysInfo->CurGunSelected == gunIndex && pDcChargingInfo->ConnectorPlugIn == NO &&
+                    (pSysInfo->SystemPage != _PAGE_PAYING || pSysInfo->SystemPage != _PAGE_SENSING)) {
+                    StartGunInfoTimeoutDet(gunIndex, Timeout_ExitPage);
+                }
 
                 if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING ) {
                 	if (pDcChargingInfo->Replug_flag == TRUE)
@@ -4700,11 +4754,10 @@ CheckStatus:
                         pSysInfo->SystemPage = _PAGE_MAINTAIN;
                         continue;
                     }
-
-                    if (pSysInfo->CurGunSelected == gunIndex) {
-                    	pSysInfo->SystemPage = _PAGE_MAINTAIN;
+                    if (ShmDcCommonData->RoutineSettlement == TRUE) {
+                        pSysInfo->SystemPage = _PAGE_MAINTAIN;
+                        continue;
                     }
-
                     if (pDcChargingInfo->IsAvailable == NO )
                         break;
 
@@ -4726,7 +4779,18 @@ CheckStatus:
                     if (pSysInfo->SelfTestSeq == _STEST_FAIL)
                         StopProcessingLoop();
                 }
-
+                /*
+                if (pDcChargingInfo->IsAvailable == TRUE) {
+                    log_info("Gun[%d] set Available",gunIndex);
+                    setChargerMode(gunIndex, MODE_IDLE);
+                    break;
+                }
+                */
+                if (pSysInfo->CurGunSelected == gunIndex) {
+                    StopSystemTimeoutDet();
+                    StopGunInfoTimeoutDet(gunIndex);
+                    pSysInfo->SystemPage = _PAGE_MAINTAIN;
+                }
 
                 break;
             case S_UPDATE:

+ 1 - 0
EVSE/Projects/DD360Tcci/Apps/CSU/main.h

@@ -53,6 +53,7 @@
 #define TCC_FINALCOST_TIMEOUT					(30)
 #define TCC_SCANCARD_TIMEOUT					(30)
 #define TCC_TRADECANCEL_TIMEOUT                 (60)
+#define TCC_EXITPAGE_TIMEOUT                    (10)
 
 //#define log_info(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)

+ 4 - 1
EVSE/Projects/DD360Tcci/Apps/Config.h

@@ -426,6 +426,7 @@ typedef struct stTransInfo
 
 typedef struct stRecordTransactionInfo
 {
+    int ConnectorID;
 	int TransactionId;
     float Amount;
     char DeductResult;                     // 0: Fail, 1: Pass , -1: Cancel , 99:Rededuct fail
@@ -436,6 +437,7 @@ typedef struct stRecordTransactionInfo
     TransInfo pCreditCard;
     float Energy;
     float prices;
+    int RedeductTime;
 }RecordTransactionInfo;
 
 typedef struct StDcCommonInfo {
@@ -483,11 +485,11 @@ typedef struct StDcCommonInfo {
     int PreAuth_Config;
     int PreAuth_Result;
     int LineStatus[2];
-    int ConnectorID[2];
     unsigned int AuthPass_flag[2];
     unsigned int PayPass_flag[2];
     unsigned int StopCharge[2];
     unsigned int TradeCancel;
+    int ConnectorID[2];
     RecordTransactionInfo TransactionInfo[2];
     int UnionSettlement;
     int Exe_ReDeduct;
@@ -502,6 +504,7 @@ typedef struct StDcCommonInfo {
     int is_RemoteStart[2];
     int is_AutoStart[2];
     time_t RecordEnergyTime[2];
+    int is_exit[2];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 18 - 13
EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.c

@@ -11,7 +11,7 @@
 
 //------------------------------------------------------------------------------
 #define DB_FILE                                 "/Storage/ChargeLog/localCgargingRecord.db"
-#define DEDUCT_FILE                 			"/Storage/ChargeLog/localDeductRecord.db"
+#define DEDUCT_FILE                 			"/Storage/ChargeLog/CreditCardRecord.db"
 
 //------------------------------------------------------------------------------
 static sqlite3 *localDb;
@@ -370,8 +370,9 @@ int DeductDB_Open(void)
                               "isDeductResult text, "
                               "isIntoCharge text, "
                               "isUpload text, "
-                              "lineSn text"
-                              "Energy text"
+                              "lineSn text, "
+                              "Energy text, "
+                              "RedeductTime "
 						  	  ");";
 
 	if(sqlite3_open(DEDUCT_FILE, &deductDb))
@@ -430,9 +431,9 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
     CreditCardTimeSet(&_time, 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) "
-				    "values('%d', '%s', '%s', '%d', '%s', '%.1f', '%s', '%s', '%s', '%s', '%d', '%d', '%d' , '%d', '%s' ,'%.1f');",
-				    gunIndex,
+	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');",
+                    gunIndex,
                     _time,
 				    vemData,
                     deductInfo->TransactionId,
@@ -446,9 +447,11 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
                     (int)deductInfo->DeductResult,
                     (int)deductInfo->isIntoCharge,
                     (int)deductInfo->IsUpload,
-                    lineSn);
+                    lineSn,
+                    deductInfo->Energy,
+                    deductInfo->RedeductTime);
 
-    
+    //log_info("%s",sqlStr);
 
     if (sqlite3_open(DEDUCT_FILE, &deductDb))
     {
@@ -497,16 +500,17 @@ int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo)
     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 = %.1f where vemData = '%s'; ",
+    sprintf(sqlStr, "update report_credit_deduct set isUpload = %d , isIntoCharge = %d, amount = %.1f, txId = %d, isDeductResult = %d, Energy = %.4f, RedeductTime = %d where vemData = '%s'; ",
                     (int)deductInfo->IsUpload,
                     (int)deductInfo->isIntoCharge,
                     deductInfo->Amount,
                     deductInfo->TransactionId,
                     (int)deductInfo->DeductResult,
                     deductInfo->Energy,
+                    deductInfo->RedeductTime,
                     vemData);
 
-    log_info("%s",sqlStr);
+    //log_info("%s",sqlStr);
 
     if (sqlite3_open(DEDUCT_FILE, &deductDb))
     {
@@ -659,7 +663,7 @@ int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, Reco
     }
     else if(deductResult >= 0 && uploadState < 0)
     {
-        sprintf(sqlStr, "select * from report_credit_deduct where isDeductResult = 0 OR isDeductResult = 3;");
+        sprintf(sqlStr, "select * from report_credit_deduct where isDeductResult IN (0,3) AND RedeductTime < 3;");
     }
     else if(deductResult < 0 && uploadState >= 0)
     {
@@ -683,7 +687,8 @@ int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, Reco
         {
             for (int idxRow = 1; idxRow <= rows; idxRow++)
             {
-                gunIndex[idxRow - 1] = atoi(rs[(idxRow * cols) + 1]);
+                //gunIndex[idxRow - 1] = atoi(rs[(idxRow * cols) + 1]);
+                deductInfo[idxRow - 1].ConnectorID = atoi(rs[(idxRow * cols) + 1]);
                // GetDeductTime(rs[(idxRow * cols) + 1], deductInfo);
                 memcpy((char*)&deductInfo[idxRow - 1].pCreditCard.VemData, rs[(idxRow * cols) + 3],64);
                 deductInfo[idxRow - 1].TransactionId = atoi(rs[(idxRow * cols) + 4]);
@@ -697,7 +702,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]);
-
+                deductInfo[idxRow - 1].RedeductTime = atoi(rs[(idxRow * cols) + 15]);
                 if(idxRow >= 128)
                 {
                 	rows = 128;

+ 50 - 61
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.c

@@ -634,6 +634,10 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
         case MISC_CMD_BACKEND_STATUS :
             ShmSelectGunInfo->EthDevStatus.Backend = value;
+            if (ShmSelectGunInfo->EthDevStatus.Backend == 0 ||
+                ShmSelectGunInfo->EthDevStatus.Backend == 2) {
+                log_info("!!!!!!!!!!!!!! Backend Disconnect !!!!!!!!!!!!!!");
+            }
             break;
 
         case MISC_CMD_ETHERNET_STATUS :
@@ -936,7 +940,7 @@ 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;
-        if (ShmSelectGunInfo->PricesInfo[plugNum].TransactionId > 0) {
+        if (ShmSelectGunInfo->PricesInfo[plugNum].TransactionId != 0) {
 
             ShmDcCommonData->TransactionInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
             UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
@@ -1171,7 +1175,6 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
                  pCsuResult->Data.Data[1]);
         ShmDcCommonData->ConnectorID[0] = pCsuResult->Data.Data[0];
         ShmDcCommonData->ConnectorID[1] = pCsuResult->Data.Data[1];
-
         break;
 
     case REG_POWER_CABINET_STATUS:
@@ -1506,7 +1509,7 @@ static int readChargerStationInfo(int fd)
 static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactionInfo *transactionInfo)
 {
     int ret = PASS;
-    uint8_t dataBuf[86] = {0};
+    uint8_t dataBuf[104] = {0};
     //int i;
 
     memset((char *)dataBuf, 0x00, sizeof(dataBuf));
@@ -1525,26 +1528,28 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     dataBuf[9] = (amount & 0xFF);
     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'",
-    		gunIndex,
+    log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f Approva Num:'%s' VemData:'%s' CardNo:'%s'",
+    		transactionInfo->ConnectorID,
             transactionInfo->TransactionId,
             transactionInfo->DeductResult,
             transactionInfo->IsDonateInvoice,
             transactionInfo->Amount,
             transactionInfo->pCreditCard.ApprovalNo,
-            transactionInfo->pCreditCard.VemData);
+            transactionInfo->pCreditCard.VemData,
+            transactionInfo->pCreditCard.CardNo);
     // copy deduct result to dataBuf here
 
     if ((ret = composeSocketData(fd,
                                  id,
                                  OP_WRITE_DATA,
                                  REG_DEDUCT_INFO,
-                                 86,
+                                 104,
                                  &dataBuf[0])) == FAIL) {
         return ret;
     }
@@ -2367,7 +2372,6 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 //
 //    return NO;
 //}
-
 static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8_t gunID)
 {
     uint8_t i = 0;
@@ -2379,6 +2383,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     int reupload_num = 0;
     struct timeb SeqEndTime;
     struct tm* tm;
+
     switch (pDcChargingInfo->SystemStatus) {
     case S_IDLE:
     case S_RESERVATION:
@@ -2397,34 +2402,44 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (ShmSelectGunInfo->PricesInfo[plugNum].Balance == FAIL_BALANCE_PRICES) {
             break;
         }
-        /*
+
         ftime(&SeqEndTime);
         SeqEndTime.time = time(NULL);
         tm = localtime(&SeqEndTime.time);
-        
-        if (tm->tm_min % 2 == 0 && pSysInfo->SystemPage == _PAGE_IDLE) {
 
+        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
+                ) {
+                reupload_num = DB_GetMultiReUploadDeduct(&reupload_gunIndex[0], &reuploadInfo[0]);
+                if (reupload_num >= 1) {
+
+                    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]);
+                    } else
+                        log_info("Reupload fail");
+
+                }
+                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]);
-            //log_info("ReUpload number:%d", reupload_num);
+            log_info("ReUpload number:%d", reupload_num);
+
             for (j = 0; j < reupload_num; j++) {
-                log_info("Card No:%s", reuploadInfo[j].pCreditCard.CardNo);
-                if (writeDeductInfo(fd, 0xff, reupload_gunIndex[j], &reuploadInfo[j]) == PASS) {
+                log_info("Connector ID:%d Card No:%s", reuploadInfo[j].ConnectorID, reuploadInfo[j].pCreditCard.CardNo);
+
+                if (writeDeductInfo(fd, reuploadInfo[j].ConnectorID, reupload_gunIndex[j], &reuploadInfo[j]) == PASS) {
                     log_info("Reupload Success");
                     reuploadInfo[j].IsUpload = YES;
                     UpdateDeductInfoStatus(reupload_gunIndex[j], &reuploadInfo[j]);
                 } else
-                    log_info("writeDeductInfo fail");
-            }
-
-        }
-        */
-        /*
-        if (ShmDcCommonData->reupload_deduct_status == 1) {
-            log_info("Reupload Deduct");
-        	if (writeDeductInfo(fd, 0xff,plugNum, &ShmDcCommonData->UploadRedectInfo) == PASS) {
-        		ShmDcCommonData->UploadRedectInfo.IsUpload = YES;
-            } else {
-                log_info("Reupload Deduct Failure!");
+                    log_info("Reupload fail");
             }
         }*/
 
@@ -2453,23 +2468,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
-        /*
-        if(!DeductResultReq[plugNum] && pDcChargingInfo->SystemStatus == S_ALARM &&
-        		ShmDcCommonData->PayFinish[plugNum] == TRUE)
-        {
-            DeductResultReq[plugNum] = YES;
-            log_info("Write Gun %d Deduct Result", plugNum);
-            if (writeDeductInfo(fd, gunID, plugNum, &ShmDcCommonData->TransactionInfo[plugNum]) == PASS) {                
-                ShmDcCommonData->finalcost_flag[plugNum] = FALSE;
-                ShmDcCommonData->PayFinish[plugNum] = FALSE;
-                ShmDcCommonData->TransactionInfo[plugNum].IsUpload = YES;
-                UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
-                log_info("writeDeductInfo finish");
-            } else {
-                log_info("Write Deduct fail");
-            }
-        }
-        */
+
         break;
 
     case S_PREPARNING: //get permission
@@ -2635,23 +2634,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 				writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
-        /*
-        if(!DeductResultReq[plugNum] &&
-				ShmDcCommonData->PayFinish[plugNum] == TRUE)
-        {
-            DeductResultReq[plugNum] = YES;
-            log_info("Write Gun %d Deduct Result", plugNum);
-            if (writeDeductInfo(fd, gunID, plugNum, &ShmDcCommonData->TransactionInfo[plugNum]) == PASS) {
-                ShmDcCommonData->finalcost_flag[plugNum] = FALSE;
-                ShmDcCommonData->PayFinish[plugNum] = FALSE;
-                ShmDcCommonData->TransactionInfo[plugNum].IsUpload = YES;
-                UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
-                log_info("writeDeductInfo finish");
-            }
-            else {
-                log_info("Write Deduct fail");
-            }
-        }*/
+
         break;
 
     default:
@@ -2716,12 +2699,18 @@ static int networkCreatePorcess(void)
 }
 void CreditCardProcess(int fd,int plugNum,int gunID, RecordTransactionInfo *pInfo)
 {
-    if (pInfo->IsUpload == TRUE)
+    if (pInfo->IsUpload == TRUE || (strcmp(pInfo->pCreditCard.VemData,"") == 0) ||
+        pSysInfo->SystemPage == _PAGE_SENSING)
         return;
 
     if (writeDeductInfo(fd, gunID, plugNum, &ShmDcCommonData->TransactionInfo[plugNum]) == PASS) {
         ShmDcCommonData->TransactionInfo[plugNum].IsUpload = YES;
         UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
+
+        if (ShmDcCommonData->TransactionInfo[plugNum].DeductResult == _DEDUCT_CANCEL) {
+            memset(&ShmDcCommonData->TransactionInfo[plugNum].pCreditCard, 0x00, sizeof(TransInfo));
+        }
+
         log_info("writeDeductInfo finish");
     } else {
         log_info("Write Deduct fail");

+ 1 - 1
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.h

@@ -16,7 +16,7 @@
 #define TFTP_PULL_CMD                           "tftp"
 #define SIGTERM_MSG                             "SegmentFault.~~~~\n"
 
-#define MAX_REGISTER_NUM                        30
+#define MAX_REGISTER_NUM                        40
 
 #define CHECK_NETWORK_FAIL_COUNT                10//10
 #define CONNECT_SERVER_FAIL_COUNT               3//5

+ 53 - 48
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -342,41 +342,46 @@ void CheckReturnPress()
             ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
         log_info("Operate return to IDLE");
     }
-	if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
+    // Cancel Trade
+	if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING || 
+        (pDcChargingInfo->SystemStatus == S_IDLE && pSysInfo->SystemPage == _PAGE_AUTHORIZE)) {
+        log_info("Press Return button cancel PreAuth");
         ShmDcCommonData->TradeCancel = TRUE;
-        /*
-		if (pSysInfo->SystemPage == _PAGE_AUTHORIZE ) {
-			pSysInfo->SystemPage = _PAGE_SELECT_PAY;
-		} else if (pSysInfo->SystemPage == _PAGE_PLUGIN)
-            pSysInfo->SystemPage = _PAGE_SELECT_GUN;
-            */
+        pSysInfo->SystemPage = _PAGE_SENSING;
+        StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
+        StartSystemTimeoutDet(Timeout_TradeCancel);
         for (i = 0; i <= 30; i++) {
             if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
                 break;
             sleep(1);
         }
-        pSysInfo->SystemPage = _PAGE_SENSING;
-        StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
-        StartSystemTimeoutDet(Timeout_TradeCancel);
+
         ShmDcCommonData->PreAuth_Result = 0;
-        log_info("Press Return button cancel PreAuth");
-		ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
-		ShmDcCommonData->PreAuth_Result = 0;
-		for(i=0;i<=30;i++) {
-			if(ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
-				break;
-			sleep(1);
-		}
-		ShmDcCommonData->PreAuth_Result = 0;
+        ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = FALSE;
+        
+        log_info("Sensing Card vemdata:'%s need to cancel", ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.VemData);
+        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);
+            }
+            ShmDcCommonData->PreAuth_Result = 0;
+        }
         StopSystemTimeoutDet();
         pSysInfo->SystemPage = _PAGE_SELECT_GUN;
         pDcChargingInfo->SystemStatus = S_IDLE;
 		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++) {
@@ -385,19 +390,19 @@ void CheckReturnPress()
                 sleep(1);
             }
             ShmDcCommonData->PreAuth_Result = 0;
-            if (ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] == TRUE) {
-                ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
-                ShmDcCommonData->PreAuth_Result = 0;
-                for (i = 0; i <= 30; i++) {
-                    if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
-                        break;
-                    sleep(1);
-                }
+        }
+        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;
         }
+        pSysInfo->SystemPage = _PAGE_SELECT_PAY;
         return;
-    }
+    }*/
 	if ( pSysInfo->SystemPage == _PAGE_EXIT ) {
         StopSystemTimeoutDet();
 		pDcChargingInfo->SystemStatus = S_IDLE;
@@ -471,16 +476,11 @@ void CheckPayCreditCard()
     ShmDcCommonData->LineStatus[pSysInfo->CurGunSelected] = 0;
     ShmDcCommonData->TradeCancel = FALSE;
    	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-	if (pDcChargingInfo->SystemStatus == S_IDLE) {
-		//confirmSelGun(pSysInfo->CurGunSelected);
+	if (pDcChargingInfo->SystemStatus == S_IDLE && pSysInfo->SystemPage == _PAGE_SELECT_PAY &&
+        ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE) {
         ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
         ShmDcCommonData->PreAuth_Result = 0;
-		//setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
 		pSysInfo->SystemPage = _PAGE_AUTHORIZE;
-		//pDcChargingInfo->SystemStatus = S_AUTHORIZING;
-
-		//
-		//AuthorizingStart();
 	}
 }
 void CheckPayIcash()
@@ -493,7 +493,6 @@ void CheckPayLinePay()
 }
 void CheckTouchPress(short id)
 {
-
     GetDeviceInfoStatus(id,1);
     if (_btn_press >= 1 && _btn_press_id == id ) {
     	_btn_press_count++;
@@ -807,7 +806,8 @@ void ChangeCurPage()
             break;
         }
         _currentPage = pSysInfo->PageIndex;
-        //log_info("Chagne Page:%d",pSysInfo->PageIndex);
+        if (pSysInfo->PageIndex != _PAGE_IDLE)
+            log_info("Gun[%d] Chagne LCM Page:%d",pSysInfo->CurGunSelected, pSysInfo->PageIndex);
         ChangeToOtherPage(pSysInfo->PageIndex);
     }
 }
@@ -938,7 +938,10 @@ void ChangeRemainTime(int sec)
 void ShowSelectGun()
 {
 	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
-	if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+    if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
+        pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+        pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
+        pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
 		if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
 				pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
 			ChangeDisplay2Value(_Icon_Select_Left,_TCC_ShowLeftGunCharging_CCS1);
@@ -964,7 +967,10 @@ void ShowSelectGun()
 		}
 	}
 	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
-	if (pDcChargingInfo->SystemStatus == S_CHARGING) {
+    if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
+        pDcChargingInfo->SystemStatus <= S_CHARGING) ||
+        pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
+        pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
 		if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
 				pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
 			ChangeDisplay2Value(_Icon_Select_Right,_TCC_ShowRightGunCharging_CCS1);
@@ -1038,8 +1044,7 @@ void ChangeCarBonValue(float data)
     memset(cmd, 0x00, sizeof(cmd));
     _carbon = data * 0.577;
     //log_info("Carbon:%d",(int)_carbon);
-    if (data > 0 && _carbon < 1)
-        _carbon = 1;
+
 	sprintf((char *) value, "%d", (int)_carbon);
     string2ByteArray(value, cmd);
     DisplayValueToLcm(_String_Carbon, cmd, sizeof(cmd));
@@ -1380,11 +1385,8 @@ void ProcessPageInfo()
                 } else {
                     ChangeChargingEnergyValue(0);
                 }
-                if ( ShmDcCommonData->TransactionInfo[i].Amount > 0 && ShmDcCommonData->finalcost_flag[i] == TRUE) {
-                	StopGunInfoTimeoutDet(i);
-					ChangeChargingFeeValue(ShmDcCommonData->TransactionInfo[i].Amount);
-					//ShmDcCommonData->finalcost_flag[i] = FALSE;
-                }
+
+				ChangeChargingFeeValue(ShmDcCommonData->TransactionInfo[i].Amount);
                 ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);
                 ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
                 //StartSystemTimeoutDet(Timeout_ReturnViewPage);
@@ -1405,8 +1407,11 @@ void ProcessPageInfo()
                 }*/
             	break;
             case _PAGE_PAYING:
-
+                ChangeDisplay2Value(_Icon_Ani_Dot, 1);
             	break;
+            case _PAGE_EXIT:
+                
+                break;
                 /*
             case _PAGE_MAINTAIN:
                 ChangeQrCode_Error();

BIN
EVSE/Projects/DD360Tcci/Apps/UnsafetyOutputTask


+ 1 - 0
EVSE/Projects/DD360Tcci/Apps/timeout.h

@@ -60,6 +60,7 @@ enum Timeout_flag {
 	Timeout_SelectPayMode		   = 23,
 	Timeout_FinalCost			   = 24,
 	Timeout_ScanCard			   = 25,
+    Timeout_ExitPage               = 26,
     Timeout_TradeCancel            = 28,
 };
 

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