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

2022-03-08 / Simon Xue

Action
1. Remote start function working.
2. AutoStartCharging function working.
3. Add reportDate StoreID RRN ROC isIntoCharge Emergy LineSn[not use] in DataBase and communication with Cabient.
4. Modify isDeductResult variance. 0: PreCompleteFail 1:PreCompletePass
2:PreAuthCancel 3:PreAuth

Files
As the follow commit history files

Image Version: V2.08.XX.XXXX.XX
Simon Xue 3 жил өмнө
parent
commit
d426f6958c

+ 6 - 2
EVSE/Projects/DD360Tcci/Apps/CSU/Module_Systex.h

@@ -53,7 +53,8 @@ struct TransInfo
 {
 	unsigned char TransDate[6];	//交易日期
 	unsigned char TransTime[6];	//交易時間
-	unsigned char ApprovalNo[12];		//EDC簽單調閱編號或授權碼[信用卡退貨交易] (左靠右補空白)
+	unsigned char ROC[12];		//EDC簽單調閱編號 (左靠右補空白)
+	unsigned char ApprovalNo[9];		//授權碼[信用卡退貨交易] (左靠右補空白)
 	unsigned char StoreId[18];		//櫃號,機號,發票號碼(左靠右補空白)
 	unsigned char RRN[12];		//信用卡交易序號
 	unsigned char CardNo[20];		//卡號(左靠右補空白),卡號部份隱藏
@@ -61,7 +62,10 @@ struct TransInfo
 	unsigned char VemData[64];		//無人自助設備交易資訊 交易別31/32 (預授權完成/預授權取消) 必要欄位 資訊來源為交易別13 (預授權)的回傳
 };
 
+int CreditCardSearch(int Fd,unsigned char *EVSEID, struct TransInfo *TransInfoReturn);
 int CreditCardPreAuth(int Fd, int PreCost,unsigned char *EVSEID, struct TransInfo *TransInfoReturn);
 int CreditCardPreAuthComplete(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *VemData,struct TransInfo *TransInfoReturn);
-int CreditCardPreAuthCancel(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *ApprovalNo, unsigned char *CardNum);
+int CreditCardPreAuthCancel(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *ApprovalNo, unsigned char *CardNum,unsigned char *VemData);
+int CreditCardUnionSettlement(int Fd,unsigned char *EVSEID,struct TransInfo *TransInfoReturn);
+
 #endif

+ 157 - 113
EVSE/Projects/DD360Tcci/Apps/CSU/RFID.c

@@ -81,7 +81,7 @@ bool isAutorCompleteHandle(/*uint8_t *authorizeIndex*/)
 
         ClearAuthorizedFlag();
 
-    } /*else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
+    } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
         // 白名單驗證
         for (i = 0; i < 10; i++) {
             if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
@@ -130,16 +130,16 @@ bool RfidStopCharging(void)
 }
 static void UserScanFunction(void)
 {
-    bool idleReq = false;
-    uint8_t i = 0;
-    uint8_t stopReq = NO_DEFINE;
-    char value[32] = {0};
-    static uint8_t _authorizeIndex = NO_DEFINE;
+   // bool idleReq = false;
+    //uint8_t i = 0;
+    //uint8_t stopReq = NO_DEFINE;
+    //char value[32] = {0};
+    //static uint8_t _authorizeIndex = NO_DEFINE;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-    struct ChargingInfoData *pAcChargingInfo =  (struct ChargingInfoData *)GetAcChargingInfoData(0);
+    //struct ChargingInfoData *pAcChargingInfo =  (struct ChargingInfoData *)GetAcChargingInfoData(0);
     struct ChargingInfoData *pDcChargingInfo = NULL;
-    GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
+    //GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
     // 當前非驗證的狀態
     if (IsAuthorizingMode()) {
@@ -271,9 +271,9 @@ void AuthorizeToCharge()
 {
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-    SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-    struct ChargingInfoData *pDcChargingInfo = NULL;
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+   // SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+   // struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);;
+
     ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     if(isAuthorizedComplete())
     {
@@ -295,7 +295,7 @@ void AuthorizeToCharge()
 }
 void ScannerCardProcess(void)
 {
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    //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;
@@ -324,13 +324,11 @@ void ScannerCardProcess(void)
 
 void WritePayResult(int result ,uint8_t gunIndex)
 {
-	ShmDcCommonData->TransactionInfo[gunIndex].Amount = LocalTransactionInfo.Amount;
-	memcpy(ShmDcCommonData->TransactionInfo[gunIndex].ApprovalNo , LocalTransactionInfo.ApprovalNo,9);
-	memcpy(ShmDcCommonData->TransactionInfo[gunIndex].CardNo , LocalTransactionInfo.CardNo,20);
-	ShmDcCommonData->TransactionInfo[gunIndex].DeductResult = result;
-	ShmDcCommonData->TransactionInfo[gunIndex].IsDonateInvoice = LocalTransactionInfo.IsDonateInvoice;
-	ShmDcCommonData->TransactionInfo[gunIndex].TransactionId = LocalTransactionInfo.TransactionId;
-	memcpy(ShmDcCommonData->TransactionInfo[gunIndex].VemData, LocalTransactionInfo.VemData,64);
+    memcpy(&ShmDcCommonData->TransactionInfo[gunIndex], &LocalTransactionInfo, sizeof(RecordTransactionInfo));
+    if (result == TRUE)
+        ShmDcCommonData->TransactionInfo[gunIndex].DeductResult = _DEDUCT_COMPLETE_PASS;
+    else
+        ShmDcCommonData->TransactionInfo[gunIndex].DeductResult = _DEDUCT_COMPLETE_FAIL;
 
     log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f",
         gunIndex, ShmDcCommonData->TransactionInfo[gunIndex].TransactionId,
@@ -341,44 +339,129 @@ void WritePayResult(int result ,uint8_t gunIndex)
 void storePayResult(uint8_t gunIndex)
 {
     memset(&LocalTransactionInfo, 0, sizeof(RecordTransactionInfo));
-    LocalTransactionInfo.Amount = ShmDcCommonData->finalcost[gunIndex];
-    memcpy(LocalTransactionInfo.ApprovalNo, ShmDcCommonData->pCreditCard[gunIndex].ApprovalNo, 9);
-    memcpy(LocalTransactionInfo.CardNo, ShmDcCommonData->pCreditCard[gunIndex].CardNo, 20);
-    LocalTransactionInfo.IsDonateInvoice = ShmDcCommonData->donate_flag[gunIndex];
-    LocalTransactionInfo.TransactionId = ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId;
-    memcpy(LocalTransactionInfo.VemData, ShmDcCommonData->pCreditCard[gunIndex].VemData, 64);
+    memcpy(&LocalTransactionInfo, &ShmDcCommonData->TransactionInfo[gunIndex] ,sizeof(RecordTransactionInfo));
+    //LocalTransactionInfo.Amount = ShmDcCommonData->finalcost[gunIndex];
 }
 void PreAuthCompleteToCardReader(int fd,uint8_t gunIndex)
 {
+    struct SysConfigData* pSysConfig = (struct SysConfigData*)GetShmSysConfigData();
 	int result = 0;
 
-    if (ShmDcCommonData->finalcost[gunIndex] > 0 && ShmDcCommonData->finalcost[gunIndex] < 1) {
-        log_info("final cost less 1 : %f", ShmDcCommonData->finalcost[gunIndex]);
-        ShmDcCommonData->finalcost[gunIndex] = 1;
+    if (ShmDcCommonData->TransactionInfo[gunIndex].Amount > 0 && ShmDcCommonData->TransactionInfo[gunIndex].Amount < 1) {
+        log_info("final cost less 1 : %f", ShmDcCommonData->TransactionInfo[gunIndex].Amount);
+        ShmDcCommonData->TransactionInfo[gunIndex].Amount = 1;
     }
     storePayResult(gunIndex);
 
-	result = CreditCardPreAuthComplete(fd,(int)ShmDcCommonData->finalcost[gunIndex], "TCC Test",
-											&ShmDcCommonData->pCreditCard[gunIndex].VemData[0],
-											&ShmDcCommonData->pCreditCard[gunIndex]);
-
-	//result = 1;
+	result = CreditCardPreAuthComplete(fd,(int)ShmDcCommonData->TransactionInfo[gunIndex].Amount, &pSysConfig->ModelName[0],
+											&ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard.VemData[0],
+											&ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard);
     sleep(10);
-    ShmDcCommonData->PayFinish[gunIndex] = TRUE;
 	if (result > 0 ) {
 		log_info("Credit Card Spend Money:%.1f", LocalTransactionInfo.Amount);
 		pSysInfo->SystemPage = _PAGE_COMPLETE;
+        LocalTransactionInfo.DeductResult = _DEDUCT_COMPLETE_PASS;
 		WritePayResult(TRUE,gunIndex);
         ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
 	} else {
 		log_info("PAYING FAIL");
 		ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
 		pSysInfo->SystemPage = _PAGE_PAYFAIL;
+        LocalTransactionInfo.DeductResult = _DEDUCT_COMPLETE_FAIL;
 		WritePayResult(FALSE,gunIndex);
 	}
-	if (isDeductDb_ready == TRUE) {
-		InsertDeductInfo(gunIndex,&ShmDcCommonData->TransactionInfo[gunIndex]);
-	}
+    ShmDcCommonData->TransactionInfo[gunIndex].IsUpload = FALSE;
+    UpdateDeductInfoStatus(gunIndex, &ShmDcCommonData->TransactionInfo[gunIndex]);
+
+}
+int CreditCardCancelPreAuth(int fd, uint8_t gunIndex)
+{
+    struct SysConfigData* pSysConfig = (struct SysConfigData*)GetShmSysConfigData();
+    ShmDcCommonData->PreAuth_Result = CreditCardPreAuthCancel(fd, PREAUTHMONEY, &pSysConfig->ModelName[0],
+        &ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard.ApprovalNo[0],
+        &ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard.CardNo[0],
+        &ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard.VemData[0]);
+    sleep(10);
+    if (ShmDcCommonData->PreAuth_Result >= 0) {
+        strcpy((char*)pSysConfig->UserId, "");
+        //ShmDcCommonData->PayFinish[gunIndex] = TRUE;
+        log_info("Card Reader PreAuth Cancel Success");
+        ShmDcCommonData->TransactionInfo[gunIndex].DeductResult = _DEDUCT_CANCEL;
+    } else if (ShmDcCommonData->PreAuth_Result < 0) {
+        log_info("Card Reader PreAuth Cancel Failure");
+        ShmDcCommonData->TransactionInfo[gunIndex].DeductResult = _DEDUCT_PREAUTH;
+    }
+    ShmDcCommonData->TransactionInfo[gunIndex].IsUpload = FALSE;
+    UpdateDeductInfoStatus(gunIndex, &ShmDcCommonData->TransactionInfo[gunIndex]);
+
+    if (ShmDcCommonData->PreAuth_Result >= 0) {
+        memset(&ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard, 0, sizeof(TransInfo));
+    }
+
+    ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
+    return ShmDcCommonData->PreAuth_Result;
+}
+
+void ReDeductProcess(int fd)
+{
+    struct SysConfigData* pSysConfig = (struct SysConfigData*)GetShmSysConfigData();
+    int j;
+    int result;
+    int rededuct_gunIndex[128];
+    RecordTransactionInfo deductInfo[128];
+    int rededuct_num = 0;
+    rededuct_num = DB_GetMultiReDeductInfo(&rededuct_gunIndex[0], &deductInfo[0]);
+
+    if (rededuct_num == 0)
+        log_info("No Rededuct Information");
+    else {
+        log_info("Rededuct Number:%d", rededuct_num);
+        for (j = 0; j < rededuct_num; j++) {
+            if (pSysInfo->SystemPage != _PAGE_IDLE && !ShmDcCommonData->Exe_ReDeduct) {
+                ShmDcCommonData->RoutineReduct = FALSE;
+                break;
+            }
+            if (deductInfo[j].isIntoCharge == FALSE || deductInfo[j].Energy == 0) {
+                // 未進入充電或度數等於零
+                result = CreditCardPreAuthCancel(fd, PREAUTHMONEY, &pSysConfig->ModelName[0],
+                    &deductInfo[j].pCreditCard.ApprovalNo[0],
+                    &deductInfo[j].pCreditCard.CardNo[0],
+                    &deductInfo[j].pCreditCard.VemData[0]);
+                sleep(10);
+                if (result > 0) {
+                    deductInfo[j].DeductResult = _DEDUCT_CANCEL;
+                    log_info("Backgroud PreAuthCancel OK");
+                }
+            } else {
+                // 度數大於零
+                if (deductInfo[j].Amount == 0 && deductInfo[j].Energy > 0) {
+                    deductInfo[j].Amount = 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);
+                }
+                result = CreditCardPreAuthComplete(fd, (int)deductInfo[j].Amount, &pSysConfig->ModelName[0],
+                    &deductInfo[j].pCreditCard.VemData[0],
+                    &ShmDcCommonData->TransactionInfo[0].pCreditCard);
+                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,
+                        deductInfo[j].pCreditCard.VemData);
+                }
+            }
+            deductInfo[j].IsUpload = FALSE;
+            UpdateDeductInfoStatus(rededuct_gunIndex[j], &deductInfo[j]);
+        }
+    }
+    ShmDcCommonData->RoutineReduct = TRUE;
 }
 static int InitialRfidPort(void)
 {
@@ -405,29 +488,7 @@ static int InitialRfidPort(void)
 
     return fd;
 }
-int CreditCardCancelPreAuth(int fd,uint8_t gunIndex)
-{
-
-    struct SysConfigData* pSysConfig = (struct SysConfigData*)GetShmSysConfigData();
-    ShmDcCommonData->PreAuth_Result = CreditCardPreAuthCancel(fd, PREAUTHMONEY, "TCC Test",
-        &ShmDcCommonData->pCreditCard[gunIndex].ApprovalNo[0],
-        &ShmDcCommonData->pCreditCard[gunIndex].CardNo[0],
-        &ShmDcCommonData->pCreditCard[gunIndex].VemData[0]);
-    sleep(10);
-    ShmDcCommonData->PayFinish[gunIndex] = TRUE;
-    if (ShmDcCommonData->PreAuth_Result >= 0) {
-        strcpy((char*)pSysConfig->UserId, "");
-        //ShmDcCommonData->PayFinish[gunIndex] = TRUE;
-        log_info("Card Reader PreAuth Cancel Success");
-        memset(&ShmDcCommonData->pCreditCard[gunIndex], 0, sizeof(TransInfo));
 
-    }
-    else if (ShmDcCommonData->PreAuth_Result < 0) {
-        log_info("Card Reader PreAuth Cancel Failure");
-    }
-    ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
-    return ShmDcCommonData->PreAuth_Result;
-}
 void CreateRfidFork(void)
 {
     pid_t rfidRecPid;
@@ -438,30 +499,28 @@ void CreateRfidFork(void)
     rfidRecPid = fork();
     int j = 0;
     if (rfidRecPid == 0) {
-        char localTime[128] = {0};
+        //char localTime[128] = {0};
         struct timeb SeqEndTime;
         struct tm *tm;
         pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         int fd = -1;
         int isContinue = 1;
-        RFID rfid = {0};
-        RecordTransactionInfo deduct;
+        //RFID rfid = {0};
+        //RecordTransactionInfo deduct;
         fd = InitialRfidPort();
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
         ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
         struct ChargingInfoData *pDcChargingInfo = NULL;
+        if (DeductDB_Open() != PASS) {
+            isDeductDb_ready = false;
+        } else {
+            isDeductDb_ready = true;
+            //InsertDeductInfo(0, &ShmDcCommonData->TransactionInfo);
+        }
         int gunIndex;
-        int uploadIndex = 0;
+        //int uploadIndex = 0;
         int ReAuthComplete_Index = 0;
-        if(DeductDB_Open() != PASS)
-        {
-        	isDeductDb_ready = false;
-        }
-        else
-        {
-        	isDeductDb_ready = true;
-        }
         //log_info("RFID fork Child's PID is %d", getpid());
         int result;
         int is_idle = TRUE;
@@ -472,15 +531,16 @@ void CreateRfidFork(void)
             SeqEndTime.time = time(NULL);
             tm = localtime(&SeqEndTime.time);
 
-            if (ShmDcCommonData->DebugFlag == TRUE) {
+            if (ShmDcCommonData->DebugFlag == TRUE ||
+                ShmDcCommonData->is_RemoteStart[pSysInfo->CurGunSelected] == TRUE ||
+                ShmDcCommonData->is_AutoStart[pSysInfo->CurGunSelected] == TRUE) {
                 ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
                 ShmDcCommonData->PreAuth_Result = 0;
-                continue;
             }
 
             if (ShmDcCommonData->UnionSettlement) {
                 ShmDcCommonData->UnionSettlement = 0;
-                result = CreditCardUnionSettlement(fd, "TCC Test", &ShmDcCommonData->pCreditCard[0]);
+                result = CreditCardUnionSettlement(fd, &pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[0].pCreditCard);
                 if (result > 0) {
                     log_info("CreditCardUnionSettlement OK");
                 }
@@ -495,9 +555,20 @@ void CreateRfidFork(void)
 				}
 				if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && ShmDcCommonData->finalcost_flag[gunIndex]) {
                     ShmDcCommonData->StopCharge[gunIndex] = FALSE;
+                    ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
                     pSysInfo->SystemPage = _PAGE_PAYING;
                     StopGunInfoTimeoutDet(gunIndex); //Timeout_FinalCost
-					if (ShmDcCommonData->finalcost[gunIndex] == 0) {
+
+                    // 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) {
                             pSysInfo->SystemPage = _PAGE_COMPLETE;
@@ -512,31 +583,32 @@ void CreateRfidFork(void)
 					}
 				}
 			} // for
-
+            // 取消預授權
             if(ShmDcCommonData->PreAuth_Config == _CREDITCARD_CANCEL) {
                 CreditCardCancelPreAuth(fd,pSysInfo->CurGunSelected);
+            // 預授權
             } else if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH /* && ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected]*/) {                
-        		result = CreditCardPreAuth(fd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
+        		result = CreditCardPreAuth(fd, PREAUTHMONEY,&pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard);
                 if (ShmDcCommonData->TradeCancel == FALSE && result > 0) {
                     pSysInfo->SystemPage = _PAGE_SENSING;
                     sleep(10);
                 }
                 StopSystemTimeoutDet();
-                
                 ShmDcCommonData->PreAuth_Result = result;
 				//result = 1;
 				if (result > 0) {
 					ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = TRUE;
-                    strncpy((char*)pSysConfig->UserId, ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo, 20);
+                    strncpy((char*)pSysConfig->UserId, (char *)ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.CardNo, 20);
                     log_info("Authorize card:%s", pSysConfig->UserId);
-                    ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected] = TRUE;
+                    ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].DeductResult = _DEDUCT_PREAUTH;
+                    ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsUpload = FALSE;
+                    InsertDeductInfo(pSysInfo->CurGunSelected,&ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected]);
 					log_info("PreAuth OK");
 				} else if (result < 0) {
-				    struct ChargingInfoData *pDcChargingInfo = NULL;
                     if (ShmDcCommonData->TradeCancel == FALSE)
 					    pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
 					ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = FALSE;
-					memset(&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected], 0, sizeof(TransInfo));
+					memset(&ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard, 0, sizeof(TransInfo));
 					log_info("PreAuth Fail");
 				}
 				ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
@@ -546,42 +618,14 @@ void CreateRfidFork(void)
             if ((is_idle == TRUE && (tm->tm_hour == 15 && tm->tm_min < 30) &&
                 pSysInfo->SystemPage == _PAGE_IDLE &&
                 ShmDcCommonData->RoutineReduct == FALSE) || ShmDcCommonData->Exe_ReDeduct) {
+                ReDeductProcess(fd);
                 ShmDcCommonData->Exe_ReDeduct = 0;
-                rededuct_num = DB_GetMultiReDeductInfo(&rededuct_gunIndex, &deductInfo);
-                ShmDcCommonData->RoutineReduct = TRUE;
-                if (rededuct_num == 0)
-                    log_info("No Rededuct Information");
-                else {
-                    for (j = 0; j < rededuct_num; j++) {
-                        if (pSysInfo->SystemPage != _PAGE_IDLE) {
-                            ShmDcCommonData->RoutineReduct = FALSE;
-                            break;
-                        }
-                        result = CreditCardPreAuthComplete(fd, (int)deductInfo[j].Amount, "TCC Test",
-                            &deductInfo[j].VemData[0],
-                            &ShmDcCommonData->pCreditCard[0]);
-                        sleep(10);
-                        if (result > 0) {
-                            deductInfo[j].DeductResult = YES;
-                            deductInfo[j].IsUpload = NO;
-                            UpdateDeductInfoStatus(&ReAuthComplete_Index, &deductInfo[j]);
-                            log_info("Backgroud PreAuthComplete OK");
-                        }
-                        else if (result < 0) {
-                            log_info("Backgroud ID:%d Amount:%d VemData:%s PreAuthComplete fail",
-                                deductInfo[j].TransactionId,
-                                (int)deductInfo[j].Amount,
-                                deductInfo[j].VemData);
-                        }
-
-                    }
-                }
             }
             // 每日晚上11點30分結帳
-            if (is_idle == TRUE && tm->tm_hour == 15 && tm->tm_min > 30 && tm->tm_sec == 0 &&
+            if (is_idle == TRUE && tm->tm_hour == 15 && tm->tm_min > 30  &&
                 ShmDcCommonData->RoutineSettlement == FALSE) {
                 ShmDcCommonData->RoutineSettlement = TRUE;
-                result = CreditCardUnionSettlement(fd, "TCC Test", &ShmDcCommonData->pCreditCard[0]);
+                result = CreditCardUnionSettlement(fd, &pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[0].pCreditCard);
                 if (result > 0) {
                     log_info("CreditCardUnionSettlement OK");
                 }

+ 35 - 19
EVSE/Projects/DD360Tcci/Apps/CSU/main.c

@@ -81,8 +81,8 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V2.07.00.0000.00"; // Phihong version
-char* DebugVersion = "v2.07.00";      // Software debug version
+char *fwVersion = "V2.08.00.0000.00"; // Phihong version
+char* DebugVersion = "v2.08.00";      // Software debug version
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -1519,7 +1519,7 @@ void _DetectPlugInTimeout(uint8_t gunIndex)
 	ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
 	ShmDcCommonData->PreAuth_Result = 0;
 	for(i=0;i<=30;i++) {
-		if(ShmDcCommonData->PreAuth_Result != 0)
+		if(ShmDcCommonData->PreAuth_Result == _CREDITCARD_IDLE)
 			break;
 		sleep(1);
 	}
@@ -2713,7 +2713,7 @@ void CreateTimeoutFork(void)
                 	if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_FINALCOST_TIMEOUT) {
                 		StopGunInfoTimeoutDet(gunIndex);
                 		if (ShmDcCommonData->finalcost_flag[gunIndex] == FALSE) {
-                			ShmDcCommonData->finalcost[gunIndex] = pDcChargingInfo->PresentChargedEnergy * ShmDcCommonData->ChargingRate;
+                			ShmDcCommonData->TransactionInfo[gunIndex].Amount = pDcChargingInfo->PresentChargedEnergy * ShmDcCommonData->ChargingRate;
                 			ShmDcCommonData->finalcost_flag[gunIndex] = TRUE;
                 		}
                 	}
@@ -2722,7 +2722,7 @@ void CreateTimeoutFork(void)
                 	if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_LINEREGISTER_TIMEOUT) {
                 		StopGunInfoTimeoutDet(gunIndex);
                 		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
-                		ShmDcCommonData->donate_flag[gunIndex] = FALSE;
+                		ShmDcCommonData->TransactionInfo[gunIndex].IsDonateInvoice = FALSE;
                         ShmDcCommonData->OperateIDLE[gunIndex] = 1;
                 	}
                 	break;
@@ -2968,6 +2968,7 @@ void OcppRemoteStartChk()
             		pDcChargingInfo->SystemStatus == S_AUTHORIZING ||
                     pDcChargingInfo->SystemStatus == S_RESERVATION) {
                 pDcChargingInfo->RemoteStartFlag = YES;
+                ShmDcCommonData->is_RemoteStart[dcIndex] = TRUE;
                 pSysInfo->OrderCharging = YES;
                 //pDcChargingInfo->SystemStatus = S_AUTHORIZING;
                 //pSysInfo->OrderCharging = gunIndex;
@@ -3463,13 +3464,13 @@ void ResetDetAlarmStatus(uint8_t gun)
         }
     }
 }
-#if 0
+
 static void autoStartCharging(uint8_t gunIndex)
 {
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
     if ( (pSysInfo->SystemPage >= _PAGE_AUTHORIZE && pSysInfo->SystemPage <= _PAGE_SENSING) ||
-        pDcChargingInfo->isEVCCIDVerify && strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL) {
+        (pDcChargingInfo->isEVCCIDVerify && strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL)) {
             return;
     }
 
@@ -3505,13 +3506,15 @@ static void autoStartCharging(uint8_t gunIndex)
             strcpy((char *)&pSysConfig->UserId, "AutoStartCharging");
             ChangeGunSelectByIndex(gunIndex);
             confirmSelGun(gunIndex);
-            pSysInfo->SystemPage = _LCM_START_AUTHORIZING;
-            setChargerMode(gunIndex, MODE_AUTHORIZING);
+            ShmDcCommonData->is_AutoStart[gunIndex] = TRUE;
+            pSysInfo->SystemPage = _PAGE_SENSING;
+            ShmDcCommonData->AuthPass_flag[gunIndex] = TRUE;
+            //setChargerMode(gunIndex, MODE_AUTHORIZING);
             log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
         }
     }
 }
-#endif
+
 static bool PrecheckIsPass(uint8_t gunIndex)
 {
     bool result = true;
@@ -3549,6 +3552,7 @@ static void ReviewCriticalAlarm(void)
             pSysWarning->Level = WARN_LV_NL;
             return;
         }
+
         pSysWarning->Level = WARN_LV_ER;
     } else {
         pSysWarning->Level = WARN_LV_NL;
@@ -3877,15 +3881,14 @@ void ResetIdleData(uint8_t gunIndex)
     ClearDetectPluginFlag();
     //Jerry add
     memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
-    memset(&ShmDcCommonData->pCreditCard[gunIndex], 0, sizeof(TransInfo));
     memset(&ShmDcCommonData->TransactionInfo[gunIndex], 0, sizeof(RecordTransactionInfo));
     ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
-    ShmDcCommonData->finalcost[gunIndex] = 0;
     ShmDcCommonData->AuthPass_flag[gunIndex] = FALSE;
     ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
-    ShmDcCommonData->GetCardNo[gunIndex] = FALSE;
     ShmDcCommonData->LineStatus[gunIndex] = 0;
     ShmDcCommonData->OperateIDLE[gunIndex] = 1;
+    ShmDcCommonData->is_RemoteStart[gunIndex] = FALSE;
+    ShmDcCommonData->is_AutoStart[gunIndex] = FALSE;
 
     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
     destroySelGun(gunIndex);
@@ -4088,7 +4091,7 @@ int main(void)
     //AdjustChargerCurrent();
     gettimeofday(&_cmdMainPriority_time, NULL);
 
-    GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
+   // GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
 
     CheckTaskAlive();
 
@@ -4189,6 +4192,7 @@ int main(void)
 					setChargerMode(gunIndex, MODE_AUTHORIZING);
 					break;
                 }
+                autoStartCharging(gunIndex);
                 cancelcount = 0;
                 // 讀卡邏輯
                 ScannerCardProcess();
@@ -4211,13 +4215,13 @@ int main(void)
                 		if (ShmDcCommonData->LineStatus[gunIndex] == 3)  {
                             StopGunInfoTimeoutDet(gunIndex);
                 			pSysInfo->SystemPage =_PAGE_SELECT_PAY;
-                			ShmDcCommonData->donate_flag[gunIndex] = FALSE;
+                			ShmDcCommonData->TransactionInfo[gunIndex].IsDonateInvoice = FALSE;
                             log_info("Change to Select Pay Page");
                 		}
 						if (ShmDcCommonData->LineStatus[gunIndex] == 4 ) {
                             StopGunInfoTimeoutDet(gunIndex);
                 			pSysInfo->SystemPage =_PAGE_SELECT_PAY;
-                			ShmDcCommonData->donate_flag[gunIndex] = TRUE;
+                			ShmDcCommonData->TransactionInfo[gunIndex].IsDonateInvoice = TRUE;
                             log_info("Change to Select Pay Page");
                 		}
                 	}
@@ -4275,7 +4279,7 @@ CheckStatus:
                 }
 				ScannerCardProcess();
                 // 隨插即充
-                //autoStartCharging(gunIndex);
+
                 if (pSysInfo->SystemPage == _PAGE_PLUGIN && ShmDcCommonData->TradeCancel == FALSE) {
                 	pDcChargingInfo->Replug_flag = TRUE;
                 	StopSystemTimeoutDet();
@@ -4292,6 +4296,7 @@ CheckStatus:
                             log_info("-------- S_AUTHORIZING Remote Start(%d) --------", gunIndex);
                             pDcChargingInfo->RemoteStartFlag = NO;
                             pDcChargingInfo->isRemoteStart = YES; //DS60-120
+                            
                             ChangeGunSelectByIndex(gunIndex);
                             //AddPlugInTimes(gunIndex);
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
@@ -4501,6 +4506,9 @@ CheckStatus:
                     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]);
                 }
 
                 if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
@@ -4508,6 +4516,13 @@ CheckStatus:
                 }
                 ftime(&endChargingTime[gunIndex]);
                 pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
+                ShmDcCommonData->TransactionInfo[gunIndex].Energy = pDcChargingInfo->PresentChargedEnergy;
+
+                // 每秒紀錄使用電量到資料庫內
+                if ((time((time_t*)NULL) - ShmDcCommonData->RecordEnergyTime[gunIndex]) >= 1) {
+                    ShmDcCommonData->RecordEnergyTime[gunIndex] = time((time_t*)NULL);
+                    UpdateDeductInfoStatus(gunIndex, &ShmDcCommonData->TransactionInfo[gunIndex]);
+                }
 
                 checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
 
@@ -4577,10 +4592,11 @@ CheckStatus:
                     log_info ("============================= S_COMPLETE(%x) ============================= ", gunIndex);
                     if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
                         OcppStopTransation(gunIndex);
-
                     }
                     TheEndCharging(gunIndex);
                     StopSystemTimeoutDet();
+                    if (ShmDcCommonData->is_AutoStart[gunIndex] == TRUE && pSysInfo->CurGunSelected == gunIndex)
+                        pSysInfo->SystemPage = _PAGE_COMPLETE;
                 }
 
                 //if (pSysInfo->SystemPage == _LCM_ERROR) {
@@ -4592,7 +4608,7 @@ CheckStatus:
                 	pSysInfo->SystemPage = _PAGE_EXIT;
                 	break;
                 }
-                if (pSysInfo->CurGunSelected == gunIndex &&     pDcChargingInfo->ConnectorPlugIn == NO) {
+                if (pSysInfo->CurGunSelected == gunIndex &&  pDcChargingInfo->ConnectorPlugIn == NO) {
                 	is_plugout[gunIndex] = TRUE;
                     StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
                     if (pSysInfo->CurGunSelected == gunIndex) {

+ 19 - 15
EVSE/Projects/DD360Tcci/Apps/Config.h

@@ -9,7 +9,7 @@
 
 //------------------------------------------------------------------------------
 #include <stdint.h>
-
+#include <time.h>
 //------------------------------------------------------------------------------
 //Dispenser simulation ev signal
 //------------------------------------------------------------------------------
@@ -298,6 +298,12 @@ enum _CREDITCARD_STATUS {
 	_CREDITCARD_SETTLEMENT,
 	_CREDITCARD_START,
 };
+enum _CREDIT_DEDUCT_STATUS {
+    _DEDUCT_COMPLETE_FAIL = 0,
+    _DEDUCT_COMPLETE_PASS = 1,
+    _DEDUCT_CANCEL,
+    _DEDUCT_PREAUTH,
+};
 //------------------------------------------------------------------------------
 //struct StructMeter {
 //    float curMeterValue;
@@ -421,14 +427,15 @@ typedef struct stTransInfo
 typedef struct stRecordTransactionInfo
 {
 	int TransactionId;
-    unsigned char DeductResult;                     // 0: Fail, 1: Pass
-    unsigned char IsDonateInvoice;                  // 0: Do not donate, 1: Donate
-    unsigned char ApprovalNo[9];
-    unsigned char CardNo[20];		//卡號(左靠右補空白),卡號部份隱藏
-    unsigned char VemData[64];
     float Amount;
-    unsigned char IsUpload; // 0: not upload, 1: uploaded
-    unsigned char res;
+    char DeductResult;                     // 0: Fail, 1: Pass , -1: Cancel , 99:Rededuct fail
+    unsigned char IsDonateInvoice;         // 0: Do not donate, 1: Donate
+    unsigned char LineSn[20];
+    unsigned char isIntoCharge;
+    unsigned char IsUpload;                // 0: not upload, 1: uploaded
+    TransInfo pCreditCard;
+    float Energy;
+    float prices;
 }RecordTransactionInfo;
 
 typedef struct StDcCommonInfo {
@@ -469,25 +476,19 @@ typedef struct StDcCommonInfo {
     float Temperature;
     int Location;
     char PresentTime[128];
-    TransInfo pCreditCard[2];
+    //TransInfo pCreditCard[2];
     int runningcost[2];
-    float finalcost[2];
     unsigned int finalcost_flag[2];
     float ChargingRate;
     int PreAuth_Config;
     int PreAuth_Result;
     int LineStatus[2];
-    int donate_flag[2];
     int ConnectorID[2];
     unsigned int AuthPass_flag[2];
     unsigned int PayPass_flag[2];
-    unsigned int PayFinish[2];
     unsigned int StopCharge[2];
-    unsigned int GetCardNo[2];
     unsigned int TradeCancel;
     RecordTransactionInfo TransactionInfo[2];
-    RecordTransactionInfo UploadRedectInfo;
-    RecordTransactionInfo ReAuthComplete;
     int UnionSettlement;
     int Exe_ReDeduct;
     unsigned int OperateIDLE[2];
@@ -498,6 +499,9 @@ typedef struct StDcCommonInfo {
     int ClearServiceQR;
     int DebugFlag;
     int chillerCtrl;
+    int is_RemoteStart[2];
+    int is_AutoStart[2];
+    time_t RecordEnergyTime[2];
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 141 - 62
EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.c

@@ -326,23 +326,52 @@ int InsertEventRecord(uint8_t *statusCode)
 
     return result;
 }
-
+void CreditCardTimeSet(char *_time, RecordTransactionInfo* deductInfo)
+{
+    _time[0] = '2';
+    _time[1] = '0';
+    _time[2] = (char)deductInfo->pCreditCard.TransDate[0];
+    _time[3] = (char)deductInfo->pCreditCard.TransDate[1];
+    _time[4] = '-';
+    _time[5] = (char)deductInfo->pCreditCard.TransDate[2];
+    _time[6] = (char)deductInfo->pCreditCard.TransDate[3];
+    _time[7] = '-';
+    _time[8] = (char)deductInfo->pCreditCard.TransDate[4];
+    _time[9] = (char)deductInfo->pCreditCard.TransDate[5];
+    _time[10] = ' ';
+    _time[11] = (char)deductInfo->pCreditCard.TransTime[0];
+    _time[12] = (char)deductInfo->pCreditCard.TransTime[1];
+    _time[13] = ':';
+    _time[14] = (char)deductInfo->pCreditCard.TransTime[2];
+    _time[15] = (char)deductInfo->pCreditCard.TransTime[3];
+    _time[16] = ':';
+    _time[17] = (char)deductInfo->pCreditCard.TransTime[4];
+    _time[18] = (char)deductInfo->pCreditCard.TransTime[5];
+    _time[19] = '\0';
+}
 
 int DeductDB_Open(void)
 {
 	int result = PASS;
 	char* errMsg = NULL;
-	char* createDeductInfoSql="CREATE TABLE IF NOT EXISTS deduct_record("
+	char* createDeductInfoSql="CREATE TABLE IF NOT EXISTS report_credit_deduct("
 					      	  "idx integer primary key AUTOINCREMENT, "
-							  "gunIndex text, "
-						  	  "transactionId text, "
-						  	  "deductResult text, "
-						  	  "isDonate text, "
-						  	  "approvalNo text, "
-						  	  "cardNo text,"
-						  	  "vemData text, "
-						  	  "amount text, "
-						  	  "isUpload text"
+							  "gun_index text, "
+                              "reportDate text, "
+                              "vemData text, "
+                              "txId text, "
+                              "creditNo text, "
+                              "amount text, "
+                              "storeId text, "
+                              "approvalNo text, "
+                              "RRN text, "
+                              "ROC text, "
+                              "isDonateInvoice text, "
+                              "isDeductResult text, "
+                              "isIntoCharge text, "
+                              "isUpload text, "
+                              "lineSn text"
+                              "Energy text"
 						  	  ");";
 
 	if(sqlite3_open(DEDUCT_FILE, &deductDb))
@@ -354,7 +383,6 @@ int DeductDB_Open(void)
 	else
 	{
 		log_info("Deduct database open successfully.");
-
 		if (sqlite3_exec(deductDb, createDeductInfoSql, 0, 0, &errMsg) != SQLITE_OK)
 		{
 			result = FAIL;
@@ -364,7 +392,7 @@ int DeductDB_Open(void)
 		{
 			log_info("Opened deduct info table successfully");
 		}
-
+       
 		sqlite3_close(deductDb);
 	}
 
@@ -379,26 +407,48 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
     char approNo[13];
     char carNo[21];
     char vemData[65];
-
-    memset(approNo, 0x00, sizeof(approNo));
-    memset(carNo, 0x00, sizeof(carNo));
-    memset(vemData, 0x00, sizeof(vemData));
-
-    memcpy(approNo, (char *)&deductInfo->ApprovalNo, sizeof(deductInfo->ApprovalNo));
-    memcpy(carNo, (char *)&deductInfo->CardNo, sizeof(deductInfo->CardNo));
-    memcpy(vemData, (char *)&deductInfo->VemData, sizeof(deductInfo->VemData));
-
-	sprintf(sqlStr, "insert into deduct_record(gunIndex, transactionId, deductResult, isDonate, approvalNo, cardNo, vemData, amount, isUpload) "
-				    "values('%d', '%d', '%d', '%d', '%s', '%s', '%s', '%f', '%d');",
+    char storeId[18];
+    char RRN[12];
+    char ROC[12];
+    char lineSn[20];
+    char _time[20];
+
+    memset(approNo, '\0', sizeof(approNo));
+    memset(carNo, '\0', sizeof(carNo));
+    memset(vemData, '\0', sizeof(vemData));
+    memset(storeId, '\0', sizeof(storeId));
+    memset(RRN, '\0', sizeof(RRN));
+    memset(ROC, '\0', sizeof(ROC));
+    memset(lineSn, '\0', sizeof(lineSn));
+
+    strncpy(approNo, (char *)&deductInfo->pCreditCard.ApprovalNo,9);
+    strncpy(carNo, (char *)&deductInfo->pCreditCard.CardNo,20);
+    strncpy(vemData, (char *)&deductInfo->pCreditCard.VemData,64);
+    strncpy(storeId, (char *)&deductInfo->pCreditCard.StoreId,18 );
+    strncpy(RRN,(char *)&deductInfo->pCreditCard.RRN,12);
+    strncpy(ROC,(char *)&deductInfo->pCreditCard.ROC,12);
+    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,
-				    deductInfo->TransactionId,
-				    deductInfo->DeductResult,
-				    deductInfo->IsDonateInvoice,
-					approNo,
-					carNo,
-					vemData,
-				    deductInfo->Amount,
-				    deductInfo->IsUpload);
+                    _time,
+				    vemData,
+                    deductInfo->TransactionId,
+                    carNo,
+                    deductInfo->Amount,
+					storeId,
+                    approNo,
+				    RRN,
+				    ROC,
+                    (int)deductInfo->IsDonateInvoice,
+                    (int)deductInfo->DeductResult,
+                    (int)deductInfo->isIntoCharge,
+                    (int)deductInfo->IsUpload,
+                    lineSn);
+
+    
 
     if (sqlite3_open(DEDUCT_FILE, &deductDb))
     {
@@ -420,7 +470,7 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
         }
 
 
-        sprintf(sqlStr, "delete from deduct_record where idx < (select idx from deduct_record order by idx desc limit 1)-10000;");
+        sprintf(sqlStr, "delete from report_credit_deduct where idx < (select idx from report_credit_deduct order by idx desc limit 1)-10000;");
         if (sqlite3_exec(deductDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
         {
             result = FAIL;
@@ -442,11 +492,21 @@ int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo)
     int result = PASS;
     char *errMsg = NULL;
     char sqlStr[1024] = {0};
-
-    sprintf(sqlStr, "update deduct_record set deductResult = %d, isUpload = %d where transactionId = %d;",
-                    deductInfo->DeductResult,
-                    deductInfo->IsUpload,
-                    deductInfo->TransactionId);
+    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 = %.1f where vemData = '%s'; ",
+                    (int)deductInfo->IsUpload,
+                    (int)deductInfo->isIntoCharge,
+                    deductInfo->Amount,
+                    deductInfo->TransactionId,
+                    (int)deductInfo->DeductResult,
+                    deductInfo->Energy,
+                    vemData);
+
+    log_info("%s",sqlStr);
 
     if (sqlite3_open(DEDUCT_FILE, &deductDb))
     {
@@ -460,7 +520,7 @@ int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo)
         if (sqlite3_exec(deductDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
         {
             result = FAIL;
-            log_info( "update deduct record error message: %s", errMsg);
+            log_info( "update deduct record error message: %s!", errMsg);
         }
         else
         {
@@ -483,19 +543,19 @@ int DB_GetDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTra
 
     if(deductResult >= 0 && uploadState >= 0)
     {
-        sprintf(sqlStr, "select * from deduct_record where deductResult = %d and isUpload = %d;", deductResult > 0 ? 1 : 0, uploadState > 0 ? 1 : 0);
+        sprintf(sqlStr, "select * from report_credit_deduct where isDeductResult = %d and isUpload = %d;", deductResult > 0 ? 1 : 0, uploadState > 0 ? 1 : 0);
     }
     else if(deductResult >= 0 && uploadState < 0)
     {
-        sprintf(sqlStr, "select * from deduct_record where deductResult = %d;", deductResult > 0 ? 1 : 0);
+        sprintf(sqlStr, "select * from report_credit_deduct where isDeductResult = 0 OR isDeductResult = 3;");
     }
     else if(deductResult < 0 && uploadState >= 0)
     {
-        sprintf(sqlStr, "select * from deduct_record where isUpload = %d;", uploadState > 0 ? 1 : 0);
+        sprintf(sqlStr, "select * from report_credit_deduct where isUpload = %d;", uploadState > 0 ? 1 : 0);
     }
     else
     {
-        sprintf(sqlStr, "select * from deduct_record;");
+        sprintf(sqlStr, "select * from report_credit_deduct;");
     }
 
     if (sqlite3_open(DEDUCT_FILE, &deductDb))
@@ -516,9 +576,9 @@ int DB_GetDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTra
                 deductInfo->TransactionId = atoi(rs[(idxRow * cols) + 2]);
                 deductInfo->DeductResult = atoi(rs[(idxRow * cols) + 3]);
                 deductInfo->IsDonateInvoice = atoi(rs[(idxRow * cols) + 4]);
-                strcpy((char *)&deductInfo->ApprovalNo, rs[(idxRow * cols) + 5]);
-                strcpy((char *)&deductInfo->CardNo, rs[(idxRow * cols) + 6]);
-                strcpy((char *)&deductInfo->VemData, rs[(idxRow * cols) + 7]);
+                strcpy((char *)&deductInfo->pCreditCard.ApprovalNo, rs[(idxRow * cols) + 5]);
+                strcpy((char *)&deductInfo->pCreditCard.CardNo, rs[(idxRow * cols) + 6]);
+                strcpy((char *)&deductInfo->pCreditCard.VemData, rs[(idxRow * cols) + 7]);
                 deductInfo->Amount = atoi(rs[(idxRow * cols) + 8]);
                 deductInfo->IsUpload = atoi(rs[(idxRow * cols) + 9]);
                 break;
@@ -568,7 +628,23 @@ int DB_GetReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo)
 
     return result;
 }
+void GetDeductTime(char* _time,RecordTransactionInfo* deductInfo)
+{
+    deductInfo->pCreditCard.TransDate[0] = (unsigned char)_time[2];
+    deductInfo->pCreditCard.TransDate[1] = (unsigned char)_time[3];
+    deductInfo->pCreditCard.TransDate[2] = (unsigned char)_time[5];
+    deductInfo->pCreditCard.TransDate[3] = (unsigned char)_time[6];
+    deductInfo->pCreditCard.TransDate[4] = (unsigned char)_time[8];
+    deductInfo->pCreditCard.TransDate[5] = (unsigned char)_time[9];
+
+    deductInfo->pCreditCard.TransTime[0] = (unsigned char)_time[11];
+    deductInfo->pCreditCard.TransTime[1] = (unsigned char)_time[12];
+    deductInfo->pCreditCard.TransTime[2] = (unsigned char)_time[14];
+    deductInfo->pCreditCard.TransTime[3] = (unsigned char)_time[15];
+    deductInfo->pCreditCard.TransTime[4] = (unsigned char)_time[17];
+    deductInfo->pCreditCard.TransTime[5] = (unsigned char)_time[18];
 
+}
 // return quantity of DeductInfo
 int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo)
 {
@@ -579,19 +655,19 @@ int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, Reco
 
     if(deductResult >= 0 && uploadState >= 0)
     {
-        sprintf(sqlStr, "select * from deduct_record where deductResult = %d and isUpload = %d;", deductResult > 0 ? 1 : 0, uploadState > 0 ? 1 : 0);
+        sprintf(sqlStr, "select * from report_credit_deduct where isDeductResult = %d and isUpload = %d;", deductResult > 0 ? 1 : 0, uploadState > 0 ? 1 : 0);
     }
     else if(deductResult >= 0 && uploadState < 0)
     {
-        sprintf(sqlStr, "select * from deduct_record where deductResult = %d;", deductResult > 0 ? 1 : 0);
+        sprintf(sqlStr, "select * from report_credit_deduct where isDeductResult = 0 OR isDeductResult = 3;");
     }
     else if(deductResult < 0 && uploadState >= 0)
     {
-        sprintf(sqlStr, "select * from deduct_record where isUpload = %d;", uploadState > 0 ? 1 : 0);
+        sprintf(sqlStr, "select * from report_credit_deduct where isUpload = %d;", uploadState > 0 ? 1 : 0);
     }
     else
     {
-        sprintf(sqlStr, "select * from deduct_record;");
+        sprintf(sqlStr, "select * from report_credit_deduct;");
     }
 
     if (sqlite3_open(DEDUCT_FILE, &deductDb))
@@ -608,14 +684,19 @@ 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]);
-                deductInfo[idxRow - 1].TransactionId = atoi(rs[(idxRow * cols) + 2]);
-                deductInfo[idxRow - 1].DeductResult = atoi(rs[(idxRow * cols) + 3]);
-                deductInfo[idxRow - 1].IsDonateInvoice = atoi(rs[(idxRow * cols) + 4]);
-                strcpy((char *)&deductInfo[idxRow - 1].ApprovalNo, rs[(idxRow * cols) + 5]);
-                strcpy((char *)&deductInfo[idxRow - 1].CardNo, rs[(idxRow * cols) + 6]);
-                strcpy((char *)&deductInfo[idxRow - 1].VemData, rs[(idxRow * cols) + 7]);
-                deductInfo[idxRow - 1].Amount = atoi(rs[(idxRow * cols) + 8]);
-                deductInfo[idxRow - 1].IsUpload = atoi(rs[(idxRow * cols) + 9]);
+               // 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]);
+                memcpy((char*)&deductInfo[idxRow - 1].pCreditCard.CardNo, rs[(idxRow * cols) + 5],20);
+                deductInfo[idxRow - 1].Amount = atoi(rs[(idxRow * cols) + 6]);
+                memcpy((char*)&deductInfo[idxRow - 1].pCreditCard.StoreId, rs[(idxRow * cols) + 7],18);
+                memcpy((char*)&deductInfo[idxRow - 1].pCreditCard.ApprovalNo, rs[(idxRow * cols) + 8],9);
+                memcpy((char*)&deductInfo[idxRow - 1].pCreditCard.RRN, rs[(idxRow * cols) + 9],12);
+                memcpy((char*)&deductInfo[idxRow - 1].pCreditCard.ROC, rs[(idxRow * cols) + 10],12);
+                deductInfo[idxRow - 1].IsDonateInvoice = atoi(rs[(idxRow * cols) + 11]);
+                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]);
 
                 if(idxRow >= 128)
                 {
@@ -662,9 +743,7 @@ void ReDeductTest()
 	{
 		for(int i = 0; i < quantity; i++)
 		{
-			printf("Gun %d Rededuct CardNo: %s", gunList[i], deductInfo[i].CardNo);
+			printf("Gun %d Rededuct CardNo: %s", gunList[i], deductInfo[i].pCreditCard.VemData);
 		}
 	}
-}
-
-
+}

+ 1 - 0
EVSE/Projects/DD360Tcci/Apps/ModuleChkSysTask/Module_ChkSysTask.c

@@ -247,4 +247,5 @@ void main(void)
 		}
 		CheckSystemTaskAlive();
     }
+	return;
 }

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

@@ -55,7 +55,7 @@ char old_Hexdump[10240];
 static uint8_t RemoteStartNoIDState = NO;
 static uint8_t ReservationState[2] = {0};
 static char ReservationIdTag[2][32];
-static uint8_t DeductResultReq[2] = {0};
+//static uint8_t DeductResultReq[2] = {0};
 static int LineStatusCode[2] = {0};
 static unsigned int LedIntensity = 0;
 static int TimeZoneOffset = 0;
@@ -936,16 +936,21 @@ 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) {
 
-        log_info("id = %d, transaction id = %d, user prices = %.2f, Discount = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s",
-                 plugNum,
-				 ShmSelectGunInfo->PricesInfo[plugNum].TransactionId,
-                 ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
-				 ShmSelectGunInfo->PricesInfo[plugNum].Discount,
-                 pDcChargingInfo->ChargingFee,
-                 ShmSelectGunInfo->PricesInfo[plugNum].Balance,
-                 (uint8_t *)GetCurrency(pSysConfig->BillingData.Currency)
-                );
+            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",
+                plugNum,
+                ShmSelectGunInfo->PricesInfo[plugNum].TransactionId,
+                ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
+                ShmSelectGunInfo->PricesInfo[plugNum].Discount,
+                pDcChargingInfo->ChargingFee,
+                ShmSelectGunInfo->PricesInfo[plugNum].Balance,
+                (uint8_t*)GetCurrency(pSysConfig->BillingData.Currency)
+            );
+        }
     }
 
     return PASS;
@@ -1501,8 +1506,8 @@ static int readChargerStationInfo(int fd)
 static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactionInfo *transactionInfo)
 {
     int ret = PASS;
-    uint8_t dataBuf[22] = {0};
-    int i;
+    uint8_t dataBuf[86] = {0};
+    //int i;
 
     memset((char *)dataBuf, 0x00, sizeof(dataBuf));
     dataBuf[0] = transactionInfo->DeductResult;
@@ -1518,21 +1523,28 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     dataBuf[7] = (amount >> 16) & 0xFF;
     dataBuf[8] = (amount >> 8) & 0xFF;
     dataBuf[9] = (amount & 0xFF);
-    memcpy((char *)&dataBuf[10], transactionInfo->ApprovalNo,9);
+    memcpy((char *)&dataBuf[10], transactionInfo->pCreditCard.ApprovalNo,9);
+    memcpy((char *)&dataBuf[19], transactionInfo->pCreditCard.VemData, 64);
     /*
     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",
-    		gunIndex,transactionInfo->TransactionId,transactionInfo->DeductResult,transactionInfo->IsDonateInvoice,transactionInfo->Amount);
+    log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f Approva Num:'%s' VemData:'%s'",
+    		gunIndex,
+            transactionInfo->TransactionId,
+            transactionInfo->DeductResult,
+            transactionInfo->IsDonateInvoice,
+            transactionInfo->Amount,
+            transactionInfo->pCreditCard.ApprovalNo,
+            transactionInfo->pCreditCard.VemData);
     // copy deduct result to dataBuf here
 
     if ((ret = composeSocketData(fd,
                                  id,
                                  OP_WRITE_DATA,
                                  REG_DEDUCT_INFO,
-                                 22,
+                                 86,
                                  &dataBuf[0])) == FAIL) {
         return ret;
     }
@@ -2112,7 +2124,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 if (readChargingCapability(fd, gunID) == PASS) {
 					gMoreInfoReq[plugNum].bits.FinalCostReq = false;
 					pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
-					ShmDcCommonData->finalcost[plugNum] = pDcChargingInfo->ChargingFee;
+					ShmDcCommonData->TransactionInfo[plugNum].Amount = pDcChargingInfo->ChargingFee;
 					ShmDcCommonData->finalcost_flag[plugNum] = TRUE;
 					log_info("Gun %d get final cost %f", plugNum, pDcChargingInfo->ChargingFee);
                 }
@@ -2160,7 +2172,47 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             }
             curReg = REG_DISPENSER_REQUEST;
             break;
+        case REG_DISPENSER_REQUEST:
+            gConnectorActReq[plugNum].bits.ChargingCancel = ShmDcCommonData->OperateIDLE[plugNum];
+            if (gConnectorActReq[plugNum].Value != 0)
+            {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+
+                    if (writeDispenserRequest(fd, gunID, plugNum) == PASS)
+                    {
+                        gConnectorActReq[plugNum].Value = 0;
+                        log_info("Gun %d CHARGING_CANCEL OK", plugNum);
+                        ShmDcCommonData->OperateIDLE[plugNum] = 0;
+                    }
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            curReg = REG_QRCODE_URL_INFO;
+            break;
+        case REG_QRCODE_URL_INFO:
+            if (gunID == 1) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
+                    ) {
+                    readQRcodeURLAndSystemDate(fd);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
 
+            //check misc command from power cabinet
+            if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
+                }
+                curReg = gDoCommGblData.MiscCmd;
+            } else if (gMoreInfoReq[plugNum].Value != 0) {
+                curReg = REG_RESERVATION_IDTAG;
+            } else {
+                isContinue = 0;
+            }
+            //curReg = REG_SOFTWARE_UPDATE;
+            break;
         //case REG_USER_ID:
         //    writeUserID(fd, gunID, uint8_t *pUserID);
         //    break;
@@ -2204,29 +2256,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //case REG_PRESENT_CHARGING_INFO:
         //    break;
 
-        case REG_QRCODE_URL_INFO:
-            if (gunID == 1) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
-                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
-                   ) {
-                    readQRcodeURLAndSystemDate(fd);
-                    ftime(&gRegTimeUp[plugNum][curReg]);
-                }
-            }
 
-            //check misc command from power cabinet
-            if (gDoCommGblData.MiscCmd != 0) {
-                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
-                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
-                }
-                curReg = gDoCommGblData.MiscCmd;
-            } else if (gMoreInfoReq[plugNum].Value != 0) {
-                curReg = REG_RESERVATION_IDTAG;
-            } else {
-                isContinue = 0;
-            }
-            //curReg = REG_SOFTWARE_UPDATE;
-            break;
 
         //case REG_WAIT_PLUG_IT_STATE:
         //    if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME / 10)) {
@@ -2265,24 +2295,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
         //case REG_DISPENSER_REQUEST:
         //    break;
-            case REG_DISPENSER_REQUEST:
-                gConnectorActReq[plugNum].bits.ChargingCancel = ShmDcCommonData->OperateIDLE[plugNum];
-                if (gConnectorActReq[plugNum].Value != 0)
-                {
-                    if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
 
-                        if (writeDispenserRequest(fd, gunID, plugNum) == PASS)
-                        {
-                            gConnectorActReq[plugNum].Value = 0;
-                            log_info("Gun %d CHARGING_CANCEL OK",plugNum);
-                            ShmDcCommonData->OperateIDLE[plugNum] = 0;
-                        }
-                        ftime(&gRegTimeUp[plugNum][curReg]);
-                    }
-                }
-                curReg = REG_QRCODE_URL_INFO;
-                break;
         case REG_REMOTE_START_NO_ID:
             if(gMoreInfoReq[plugNum].bits.RemoteStartNoID)
             {
@@ -2372,26 +2385,29 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_MAINTAIN:
     case S_ALARM:
     case S_AUTHORIZING:
+        /*
         if(pDcChargingInfo->SystemStatus != S_ALARM)
         {
             DeductResultReq[plugNum] = NO;
         }
+        */
         checkAuthorProcess(fd, plugNum);
 
         //authorization complete, write wait plug it state
         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) {
 
-            reupload_num = DB_GetMultiReUploadDeduct(&reupload_gunIndex, &reuploadInfo);
+            reupload_num = DB_GetMultiReUploadDeduct(&reupload_gunIndex[0], &reuploadInfo[0]);
             //log_info("ReUpload number:%d", reupload_num);
             for (j = 0; j < reupload_num; j++) {
-                log_info("Card No:%s", reuploadInfo[j].CardNo);
+                log_info("Card No:%s", reuploadInfo[j].pCreditCard.CardNo);
                 if (writeDeductInfo(fd, 0xff, reupload_gunIndex[j], &reuploadInfo[j]) == PASS) {
                     log_info("Reupload Success");
                     reuploadInfo[j].IsUpload = YES;
@@ -2401,7 +2417,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             }
 
         }
-
+        */
         /*
         if (ShmDcCommonData->reupload_deduct_status == 1) {
             log_info("Reupload Deduct");
@@ -2437,6 +2453,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)
         {
@@ -2452,6 +2469,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 log_info("Write Deduct fail");
             }
         }
+        */
         break;
 
     case S_PREPARNING: //get permission
@@ -2617,6 +2635,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)
         {
@@ -2632,7 +2651,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             else {
                 log_info("Write Deduct fail");
             }
-        }
+        }*/
         break;
 
     default:
@@ -2695,7 +2714,19 @@ static int networkCreatePorcess(void)
 
     return fd;
 }
+void CreditCardProcess(int fd,int plugNum,int gunID, RecordTransactionInfo *pInfo)
+{
+    if (pInfo->IsUpload == TRUE)
+        return;
 
+    if (writeDeductInfo(fd, gunID, plugNum, &ShmDcCommonData->TransactionInfo[plugNum]) == PASS) {
+        ShmDcCommonData->TransactionInfo[plugNum].IsUpload = YES;
+        UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
+        log_info("writeDeductInfo finish");
+    } else {
+        log_info("Write Deduct fail");
+    }
+}
 int main(int argc, char *argv[])
 {
     uint8_t plugNum = 0, gunID = 0;
@@ -2759,6 +2790,8 @@ int main(int argc, char *argv[])
                 gunID = gDoCommGblData.ConnectorID[plugNum];
                 systemStatusProcess(fd, totalConnCount, plugNum, gunID);
 
+                CreditCardProcess(fd, plugNum,gunID, &ShmDcCommonData->TransactionInfo[plugNum]);
+
                 initDone = messageTrigger(fd,
                                           plugNum,
                                           gunID,

+ 128 - 122
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -166,6 +166,92 @@ void confirmSelGun(uint8_t selGun)
     //StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
     //StartSystemTimeoutDet(Timeout_ReturnViewPage);
 }
+
+void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
+{
+    int len = write(_port, cmd, cmdLen);
+    if (len < sizeof(cmd)) {
+        log_error("Write cmd to LCM Failure. ");
+    }
+}
+void ReadMsgFromLcm(uint8_t* msg, uint8_t readLen)
+{
+    read(_port, msg, readLen);
+
+    //  5a : CMD_TITLE_1
+    //  a5 : CMD_TITLE_2
+    //  5
+    //  81 : CMD_WRITE
+    //  3  : CMD_REGISTER
+    //  2  : Data length
+    //  0  : High byte
+    //  1  : Low byte
+
+    //  printf("-------------------------------------------- \n");
+    //  printf("msg = %x \n", *msg);            // A5
+    //  printf("msg = %x \n", *(msg + 1));      // 5A
+    //  printf("msg = %x \n", *(msg + 2));      // Len : [3] ~ [6] + Data Len
+    //  printf("msg = %x \n", *(msg + 3));      // cmd : 0x83
+    //  printf("msg = %x \n", *(msg + 4));      // addr : H
+    //  printf("msg = %x \n", *(msg + 5));      // addr : L
+    //  printf("msg = %x \n", *(msg + 6));      // Data Len
+    //
+    //  printf("msg = %x \n", *(msg + 7));
+    //  printf("msg = %x \n", *(msg + 8));
+    //  printf("msg = %x \n", *(msg + 9));
+    //  printf("msg = %x \n", *(msg + 10));
+    //  printf("msg = %x \n", *(msg + 11));
+    //  printf("msg = %x \n", *(msg + 12));
+    //  printf("msg = %x \n", *(msg + 13));
+    //  printf("msg = %x \n", *(msg + 14));
+        /*
+        for(uint8_t i = 0 ; i<readLen+3; i++) {
+            log_info("Read data[%d]:0x%x",i,msg[i]);
+        }*/
+
+    if (*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
+    {
+        if (*(msg + 3) == CMD_WRITE)
+        {
+            switch (*(msg + 4))
+            {
+            case CMD_REGISTER:
+            {
+                // 頁面
+                if (strcmp((char*)pSysInfo->LcmHwRev, "") != EQUAL)
+                    strcpy((char*)pSysInfo->LcmHwRev, moduleName);
+
+                _currentPage = *(msg + 7);
+                log_info("Current Page:%d", _currentPage);
+                //                  if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
+                //                      printf("_currentPage = %d \n", _currentPage);
+            }
+            break;
+            }
+        } else if (*(msg + 3) == CMD_MULTI_READ)
+        {
+            short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
+            if (strcmp((char*)pSysInfo->LcmHwRev, "") != EQUAL)
+                strcpy((char*)pSysInfo->LcmHwRev, moduleName);
+            if (key == 0x0014)
+                _currentPage = *(msg + 8);
+            if (key >= _Touch_IDLE && key <= _Touch_Pay_LinePay) {
+
+                _btn_press_id = key;
+                _btn_press = *(msg + 8);
+            }
+            //          switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
+            //          {
+            //              case BUTTON_GUN_INDEX:
+            //              {
+            //                  // 當前選的槍號
+            //                  _curGunIndex = (*(msg + 8));
+            //              }
+            //              break;
+            //          }
+        }
+    }
+}
 void GetDeviceInfoStatus(short address, uint8_t len)
 {
     uint8_t cmd[8];
@@ -185,14 +271,40 @@ void GetDeviceInfoStatus(short address, uint8_t len)
     usleep(1000);
     ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
 }
-void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
+
+void DisplayValueToLcm(short address, uint8_t* data, uint8_t len)
 {
-    int len = write(_port, cmd, cmdLen);
-    if (len < sizeof(cmd)) {
-        log_error("Write cmd to LCM Failure. ");
+
+    uint8_t cmd[256];
+    memset(cmd, 0x00, sizeof(cmd));
+    uint8_t msg[9];
+    memset(msg, 0x00, sizeof(msg));
+
+    cmd[0] = CMD_TITLE_1;
+    cmd[1] = CMD_TITLE_2;
+    cmd[2] = 0x03 + len;
+    cmd[3] = CMD_MULTI_WRITE;
+    cmd[4] = address >> 8;
+    cmd[5] = address & 0x00FF;
+
+    for (uint8_t count = 0; count < len; count++)
+    {
+        cmd[6 + count] = *(data + count);
     }
+
+    WriteCmdToLcm(cmd, cmd[2] + 3);
+    usleep(10000);
+    ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
 }
 
+void ChangeDisplay2Value(short address, short value)
+{
+    uint8_t data[2];
+    data[0] = value >> 8;
+    data[1] = value & 0x00FF;
+    //log_info("Addr:0x%x, value:%d",address,value);
+    DisplayValueToLcm(address, data, sizeof(data));
+}
 void TradeRunning(uint8_t _run)
 {
     if (_run == TRUE) {
@@ -257,6 +369,7 @@ void CheckReturnPress()
 		}
 		ShmDcCommonData->PreAuth_Result = 0;
         StopSystemTimeoutDet();
+        pSysInfo->SystemPage = _PAGE_SELECT_GUN;
         pDcChargingInfo->SystemStatus = S_IDLE;
 		strcpy((char *)pSysConfig->UserId, "");
 		return;
@@ -267,7 +380,7 @@ void CheckReturnPress()
         StartSystemTimeoutDet(Timeout_TradeCancel);
         if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH) {
             for (i = 0; i <= 30; i++) {
-                if (ShmDcCommonData->PreAuth_Result != 0)
+                if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
                     break;
                 sleep(1);
             }
@@ -308,12 +421,16 @@ void CheckStopPress()
 }
 void CheckStopConfirmPress()
 {
-	int result;
+
 	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) {
+        pSysInfo->SystemPage = _PAGE_COMPLETE;
+        return;
+    }
 	StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_FinalCost);
 	/*
 	ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
@@ -342,12 +459,12 @@ void CheckDonateBill(uint8_t gunIndex)
 void CheckDonateYes()
 {
 	pSysInfo->SystemPage = _PAGE_SELECT_PAY;
-	ShmDcCommonData->donate_flag[pSysInfo->CurGunSelected] = TRUE;
+	ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = TRUE;
 }
 void CheckDonateNo()
 {
 	pSysInfo->SystemPage = _PAGE_BILL;
-	ShmDcCommonData->donate_flag[pSysInfo->CurGunSelected] = FALSE;
+    ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = FALSE;
 }
 void CheckPayCreditCard()
 {
@@ -481,7 +598,6 @@ void CheckTouchPress(short id)
 
 void CheckLCMPressed()
 {
-	int i;
     pid_t Pid = fork();
     if ( Pid == 0 ) {
         while (1) {
@@ -545,85 +661,7 @@ void CheckLCMPressed()
     log_info("Create LCM fork:%d",Pid);
 }
 
-void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
-{
-    read(_port, msg, readLen);
-
-//  5a : CMD_TITLE_1
-//  a5 : CMD_TITLE_2
-//  5
-//  81 : CMD_WRITE
-//  3  : CMD_REGISTER
-//  2  : Data length
-//  0  : High byte
-//  1  : Low byte
-
-//  printf("-------------------------------------------- \n");
-//  printf("msg = %x \n", *msg);            // A5
-//  printf("msg = %x \n", *(msg + 1));      // 5A
-//  printf("msg = %x \n", *(msg + 2));      // Len : [3] ~ [6] + Data Len
-//  printf("msg = %x \n", *(msg + 3));      // cmd : 0x83
-//  printf("msg = %x \n", *(msg + 4));      // addr : H
-//  printf("msg = %x \n", *(msg + 5));      // addr : L
-//  printf("msg = %x \n", *(msg + 6));      // Data Len
-//
-//  printf("msg = %x \n", *(msg + 7));
-//  printf("msg = %x \n", *(msg + 8));
-//  printf("msg = %x \n", *(msg + 9));
-//  printf("msg = %x \n", *(msg + 10));
-//  printf("msg = %x \n", *(msg + 11));
-//  printf("msg = %x \n", *(msg + 12));
-//  printf("msg = %x \n", *(msg + 13));
-//  printf("msg = %x \n", *(msg + 14));
-    /*
-    for(uint8_t i = 0 ; i<readLen+3; i++) {
-        log_info("Read data[%d]:0x%x",i,msg[i]);
-    }*/
 
-    if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
-    {
-        if(*(msg + 3) == CMD_WRITE)
-        {
-            switch (*(msg + 4))
-            {
-                case CMD_REGISTER:
-                {
-                    // 頁面
-                    if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
-                        strcpy((char *)pSysInfo->LcmHwRev, moduleName);
-
-                    _currentPage = *(msg + 7);
-                    log_info("Current Page:%d",_currentPage);
-//                  if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
-//                      printf("_currentPage = %d \n", _currentPage);
-                }
-                break;
-            }
-        }
-        else if (*(msg + 3) == CMD_MULTI_READ)
-        {
-            short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
-            if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
-                strcpy((char *)pSysInfo->LcmHwRev, moduleName);
-            if (key == 0x0014)
-                _currentPage = *(msg + 8);
-            if ( key >= _Touch_IDLE && key <=_Touch_Pay_LinePay ) {
-
-                _btn_press_id = key;
-                _btn_press = *(msg + 8);
-            }
-//          switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
-//          {
-//              case BUTTON_GUN_INDEX:
-//              {
-//                  // 當前選的槍號
-//                  _curGunIndex = (*(msg + 8));
-//              }
-//              break;
-//          }
-        }
-    }
-}
 void GetHrFormTimeString(char* time,char* hr)
 {
     //char tm[] = "2021-12-06 17:29:08:084";
@@ -718,39 +756,7 @@ void GetCurrentPage()
 }
 
 
-void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
-{
-
-    uint8_t cmd[256];
-    memset(cmd, 0x00, sizeof(cmd));
-    uint8_t msg[9];
-    memset(msg, 0x00, sizeof(msg));
-
-    cmd[0] = CMD_TITLE_1;
-    cmd[1] = CMD_TITLE_2;
-    cmd[2] = 0x03 + len;
-    cmd[3] = CMD_MULTI_WRITE;
-    cmd[4] = address >> 8;
-    cmd[5] = address & 0x00FF;
-
-    for(uint8_t count = 0; count < len; count++)
-    {
-        cmd[6 + count] = *(data + count);
-    }
-
-    WriteCmdToLcm(cmd, cmd[2] + 3);
-    usleep(10000);
-    ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
-}
 
-void ChangeDisplay2Value(short address, short value)
-{
-    uint8_t data[2];
-    data[0] = value >> 8;
-    data[1] = value & 0x00FF;
-    //log_info("Addr:0x%x, value:%d",address,value);
-    DisplayValueToLcm(address, data, sizeof(data));
-}
 
 //================================================
 // Warning process
@@ -1272,7 +1278,7 @@ void ProcessPageInfo()
                 StopSystemTimeoutDet();
             	break;
             case _PAGE_SELECT_PAY:
-            	if (ShmDcCommonData->donate_flag[i] == TRUE) {
+            	if (ShmDcCommonData->TransactionInfo[i].IsDonateInvoice == TRUE) {
             		ChangeDisplay2Value(_Icon_WordAddFriend,_ICON_Empty);
             	} else
             		ChangeDisplay2Value(_Icon_WordAddFriend,_TCC_SelectPayMode);
@@ -1374,9 +1380,9 @@ void ProcessPageInfo()
                 } else {
                     ChangeChargingEnergyValue(0);
                 }
-                if ( ShmDcCommonData->finalcost[i] > 0 && ShmDcCommonData->finalcost_flag[i] == TRUE) {
+                if ( ShmDcCommonData->TransactionInfo[i].Amount > 0 && ShmDcCommonData->finalcost_flag[i] == TRUE) {
                 	StopGunInfoTimeoutDet(i);
-					ChangeChargingFeeValue(ShmDcCommonData->finalcost[i]);
+					ChangeChargingFeeValue(ShmDcCommonData->TransactionInfo[i].Amount);
 					//ShmDcCommonData->finalcost_flag[i] = FALSE;
                 }
                 ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);

+ 8 - 2
EVSE/Projects/DD360Tcci/Apps/ReadCmdline.c

@@ -739,7 +739,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     //kill ev task
     system("killall Module_EvComm");
 
-    printf("Warming!!!!\n Please pay attention chiller on or off !!!!\n");
+    printf("Warming!!!!\nPlease pay attention chiller on or off !!!!\n");
     
 
     pSysInfo->CurGunSelected = _GunIndex;
@@ -1065,7 +1065,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         }
 
         usleep(100000);
-    }
+    }// while
 }
 
 int printTimeMsg(const char *fmt, ...)
@@ -1269,6 +1269,8 @@ int main(void)
                      "       chiller                           : set chiller on/off\n"
                      "       settlement                        : Credit Card UnionSettlement\n"
                      "       rededuct                          : Credit Card rededuct\n"
+                     "       preauth                           : Credit Card PreAuth\n"
+                     "       preauthcancel                     : Credit Card PreAuth Cancel\n"
                      "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
@@ -1451,6 +1453,10 @@ int main(void)
             ShmDcCommonData->UnionSettlement = 1;
         } else if(strcmp(newString[0], "rededuct") == 0) {
             ShmDcCommonData->Exe_ReDeduct = 1;
+        } else if (strcmp(newString[0], "preauth") == 0) {
+            ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
+        } else if (strcmp(newString[0], "preauthcancel") == 0) {
+            ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
         } else if (strcmp(newString[0], "chiller") == 0) { //測試槍頭和水冷機溫度
             writeChillerStatus(newString[1]);
         } else {

BIN
EVSE/Projects/DD360Tcci/Apps/UnsafetyOutputTask


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


+ 15 - 0
build_rootfs_copy.sh

@@ -0,0 +1,15 @@
+#!/bin/bash
+sudo rm /dev/ram*
+sleep 3
+rm /mnt/e/Temp/IMAGE/*
+#sudo make DD360Audi-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360Audi/Images/* /mnt/e/Image/DD360Audi/
+#sudo make DD360-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360/Images/* /mnt/e/Image/DD360/
+#sudo make DD360ComBox-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360ComBox/Images/* /mnt/e/Image/DD360ComBox/
+#sudo make DD360UCar-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360UCar/Images/* /mnt/d/Image/DD360UCar/
+sudo make DD360Tcci-rootfs
+cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360Tcci/Images/* /mnt/d/Image/DD360Tcc/
+