Browse Source

Merge remote-tracking branch 'origin/DD360Tcci'

Folus 3 years ago
parent
commit
95abb4b725

+ 7 - 4
EVSE/Modularization/Module_Systex.c

@@ -39,7 +39,7 @@ unsigned char HOST_ID_eTicket_Polling[] = {0x35, 0x30};//
 // Transaction Type, offset = 2, length = 2 bytes , 
 //==================================
 //-------------尋卡---------------
-unsigned char TRANS_TYPE_Search[] = {0x30, 0x30};	//讀取卡片卡號 or 條碼資料
+unsigned char TRANS_TYPE_Search[] = {0x37, 0x32};	//讀取卡片卡號 or 條碼資料
 //--------------信用卡一般消費---------------
 unsigned char TRANS_TYPE_Sale[] = {0x31, 0x31};	//消費交易 : 信用卡,票證,掃碼支付
 unsigned char TRANS_TYPE_Void[] = {0x30, 0x35};//取消交易 : 信用卡,
@@ -353,7 +353,8 @@ int CreditCardPreAuth(int Fd, int PreCost,unsigned char *EVSEID, struct TransInf
 			strncpy(TransInfoReturn->TransDate,Buffer+56,6);	
 			strncpy(TransInfoReturn->TransTime,Buffer+62,6);	
 			strncpy(TransInfoReturn->StoreId,Buffer+97,18);
-			strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
+			strncpy(TransInfoReturn->ROC,Buffer+12,12);
+			strncpy(TransInfoReturn->ApprovalNo,Buffer+115,9);
 			strncpy(TransInfoReturn->RRN,Buffer+124,12);
 			strncpy(TransInfoReturn->CardNo,Buffer+24,20);
 			strncpy(TransInfoReturn->VemData,Buffer+246,64);
@@ -415,7 +416,8 @@ int CreditCardPreAuthComplete(int Fd, int PreCost,unsigned char *EVSEID, unsigne
 			strncpy(TransInfoReturn->TransDate,Buffer+56,6);	
 			strncpy(TransInfoReturn->TransTime,Buffer+62,6);	
 			strncpy(TransInfoReturn->StoreId,Buffer+97,18);
-			strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
+			strncpy(TransInfoReturn->ROC,Buffer+12,12);
+			strncpy(TransInfoReturn->ApprovalNo,Buffer+115,9);
 			strncpy(TransInfoReturn->RRN,Buffer+124,12);
 			strncpy(TransInfoReturn->CardNo,Buffer+24,20);
 			strncpy(TransInfoReturn->VemData,Buffer+246,64);
@@ -534,7 +536,8 @@ int CreditCardUnionSettlement(int Fd,unsigned char *EVSEID, struct TransInfo *Tr
 			strncpy(TransInfoReturn->TransDate,Buffer+56,6);	
 			strncpy(TransInfoReturn->TransTime,Buffer+62,6);	
 			strncpy(TransInfoReturn->StoreId,Buffer+97,18);
-			strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
+			strncpy(TransInfoReturn->ROC,Buffer+12,12);
+			strncpy(TransInfoReturn->ApprovalNo,Buffer+115,9);
 			strncpy(TransInfoReturn->RRN,Buffer+124,12);
 			strncpy(TransInfoReturn->CardNo,Buffer+24,20);
 			strncpy(TransInfoReturn->VemData,Buffer+246,64);

+ 2 - 1
EVSE/Modularization/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];		//卡號(左靠右補空白),卡號部份隱藏

+ 20 - 1
EVSE/Projects/DD360Tcci/Apps/CSU/Primary.c

@@ -24,14 +24,29 @@ void ChangeLCM(uint8_t page)
 // ***********************************
 // Enter LCM Page
 // ***********************************
-
 void CheckLeftButton()
 {
     pSysInfo->CurGunSelected = LEFT_GUN_NUM;
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    if(pSysInfo->SystemPage == _PAGE_SELECT_GUN) {
+    	pSysInfo->SystemPage = _PAGE_BILL;
+    	return;
+    }
+    if(pDcChargingInfo->SystemStatus == S_IDLE) {
+    	pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+    }
 }
 void CheckRightButton()
 {
     pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
+    struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    if(pSysInfo->SystemPage == _PAGE_SELECT_GUN) {
+    	pSysInfo->SystemPage = _PAGE_BILL;
+    	return;
+    }
+    if(pDcChargingInfo->SystemStatus == S_IDLE) {
+		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+	}
 }
 void CheckPrimaryWarm(void)
 {
@@ -175,6 +190,10 @@ void ChkPrimaryStatus(void)
         return;
     // Press Left Button
     if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush ) {
+    	if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
+    		log_info("Authorize Process can't select gun");
+    		return;
+    	}
         leftBtnPush = true;
         CheckLeftButton();
         log_info("left btn down...............................%x %x %x",

+ 132 - 48
EVSE/Projects/DD360Tcci/Apps/CSU/RFID.c

@@ -8,13 +8,15 @@
 #include "../Define/define.h"
 #include "../ShareMemory/shmMem.h"
 #include "../SelectGun/SelectGun.h"
+#include "../DataBase/DataBase.h"
 
 #include "main.h"
 #include "../timeout.h"
-static DcCommonInfo *ShmDcCommonData = NULL;
-static struct SysInfoData *pSysInfo = NULL;
-#define PREAUTHMONEY 2
-
+static DcCommonInfo *ShmDcCommonData 			= NULL;
+static SelectGunInfo *ShmSelectGunInfo          = NULL;
+static struct SysInfoData *pSysInfo 			= NULL;
+#define PREAUTHMONEY	1
+bool isDeductDb_ready;
 //------------------------------------------------------------------------------
 static char *rfidPortName = "/dev/ttyS2";
 
@@ -272,6 +274,7 @@ void AuthorizeToCharge()
     SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
     struct ChargingInfoData *pDcChargingInfo = NULL;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
     if(isAuthorizedComplete())
     {
        // StopSystemTimeoutDet();
@@ -285,6 +288,8 @@ void AuthorizeToCharge()
                 //pSysInfo->SystemPage = _PAGE_PLUGIN;
                 //log_info("Wait Gun(%d) plugin",pSysInfo->CurGunSelected);
                 DetectPluginStart();
+                if (ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] == TRUE)
+                	pSysInfo->SystemPage = _PAGE_PLUGIN;
                 //log_info("Gun(%d) Balance: %f",pSysInfo->CurGunSelected,
                 //        ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
             } else {
@@ -304,7 +309,8 @@ void ScannerCardProcess(void)
     struct ChargingInfoData *pDcChargingInfo = NULL;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
 
-    if (!isDetectPlugin() && pSysInfo->SystemPage == _PAGE_SENSING &&
+    if (!isDetectPlugin() && (pSysInfo->SystemPage == _PAGE_SENSING ||
+    		pSysInfo->SystemPage == _PAGE_AUTHORIZE ) &&
     		pDcChargingInfo->SystemStatus == S_IDLE &&
             pSysWarning->Level != WARN_LV_ER /*&&
             pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) {
@@ -326,7 +332,17 @@ void ScannerCardProcess(void)
     }
 }
 
+void WritePayResult(int result ,uint8_t gunIndex)
+{
+	ShmDcCommonData->TransactionInfo[gunIndex].Amount = ShmDcCommonData->finalcost[gunIndex];
+	memcpy(ShmDcCommonData->TransactionInfo[gunIndex].ApprovalNo , ShmDcCommonData->pCreditCard[gunIndex].ApprovalNo,9);
+	memcpy(ShmDcCommonData->TransactionInfo[gunIndex].CardNo , ShmDcCommonData->pCreditCard[gunIndex].CardNo,20);
+	ShmDcCommonData->TransactionInfo[gunIndex].DeductResult = result;
+	ShmDcCommonData->TransactionInfo[gunIndex].IsDonateInvoice = ShmDcCommonData->donate_flag[gunIndex];
+	ShmDcCommonData->TransactionInfo[gunIndex].TransactionId = ShmSelectGunInfo->PricesInfo[gunIndex].TransactionId;
+	memcpy(&ShmDcCommonData->TransactionInfo[gunIndex].VemData,&ShmDcCommonData->pCreditCard[gunIndex].VemData,64);
 
+}
 static int InitialRfidPort(void)
 {
     int fd = open(rfidPortName, O_RDWR);
@@ -366,79 +382,128 @@ void CreateRfidFork(void)
         int fd = -1;
         int isContinue = 1;
         RFID rfid = {0};
+        RecordTransactionInfo deduct;
         fd = InitialRfidPort();
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
-
+        ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+        struct ChargingInfoData *pDcChargingInfo = NULL;
+        ShmDcCommonData->reupload_deduct_status = 0;
+        int gunIndex;
+        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 = FALSE;
         while (isContinue) {
         	result = 0;
             usleep(500000);
             ftime(&SeqEndTime);
             SeqEndTime.time = time(NULL);
             tm = localtime(&SeqEndTime.time);
-
+            // 每日結帳
             if (tm->tm_hour == 23 && tm->tm_min == 00 && tm->tm_sec == 0) {
 				result = CreditCardUnionSettlement(fd,"TCC Test",&ShmDcCommonData->pCreditCard[0]);
 				if (result > 0) {
 					log_info("CreditCardUnionSettlement OK");
-					log_info("Get Money:%s",ShmDcCommonData->pCreditCard[0].TransAmount);
 				} else
 					log_info("CreditCardUnionSettlement FAIL");
 			}
 
-            if (pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
-            	//result = CreditCardSearch(fd,"TCC Test",&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
-            	result = 1;
+			if (tm->tm_min%2 == 0 && pSysInfo->SystemPage == _PAGE_IDLE) {
+				if(ShmDcCommonData->reupload_deduct_status == 0) {
+					// 嘗試傳送未上傳成功到後台ID
+					if (DB_GetReUploadDeduct(&uploadIndex,&ShmDcCommonData->UploadRedectInfo) == PASS) {
+						ShmDcCommonData->reupload_deduct_status = 1;
+						//log_info("deduct uploading");
+					} else {
+						//log_info("no deduct upload");
+					}
+				} else if (ShmDcCommonData->reupload_deduct_status == 2) {
+					UpdateDeductInfoStatus(&uploadIndex,&ShmDcCommonData->UploadRedectInfo);
+					ShmDcCommonData->reupload_deduct_status = 0;
+				}
+			}
+
+            if (pSysInfo->SystemPage == _PAGE_AUTHORIZE && ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected] == FALSE) {
+            	result = CreditCardSearch(fd,"TCC Test",&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
+            	//result = 1;
             	StartSystemTimeoutDet(Timeout_ScanCard);
             	if (result > 0) {
-            		pSysInfo->SystemPage = _PAGE_SENSING;
-            		strcpy((char *)pSysConfig->UserId,"AutoStartCharging");
-            		//strncpy((char *)pSysConfig->UserId,ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo,20);
+            		//strcpy((char *)pSysConfig->UserId,"AutoStartCharging");
+            		strncpy((char *)pSysConfig->UserId,ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo,20);
+            		log_info("Authorize card:%s",pSysConfig->UserId);
+            		StopSystemTimeoutDet();
+            		ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected] = TRUE;
+
             	} else if (result < 0) {
             		//pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
             		log_info("No Card Scanning...");
             	}
-            } else if (pSysInfo->SystemPage == _PAGE_SENSING) {
-            	result = CreditCardPreAuth(fd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
-            	//result = 1;
-            	if (result > 0) {
-            		ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = TRUE;
-					pSysInfo->SystemPage = _PAGE_PLUGIN;
-					//strncpy((char *)pSysConfig->UserId,ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo,20);
-
-				} else if (result < 0) {
-					pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
-					ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = FALSE;
-					memset(&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected], 0, sizeof(TransInfo));
+            }
+            is_idle = FALSE;
+			for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+				if (pDcChargingInfo->SystemStatus == S_IDLE) {
+					is_idle = TRUE;
 				}
-            } else if (pSysInfo->SystemPage == _PAGE_PAYING) {
-            	result = CreditCardPreAuthComplete(fd, 1/*ShmDcCommonData->finalcost[pSysInfo->CurGunSelected]*/ ,"TCC Test",
-            	            	            			&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].VemData[0],
-            	            							&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
-            	//result = 1;
-            	if (result > 0 ) {
-					log_info("Credit Card Spend Money:%d",ShmDcCommonData->finalcost[pSysInfo->CurGunSelected]);
-					ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] = TRUE;
-					pSysInfo->SystemPage = _PAGE_COMPLETE;
-					/*
-					result = CreditCardUnionSettlement(fd,"TCC Test",&ShmDcCommonData->pCreditCard[0]);
-					if (result > 0) {
-						log_info("CreditCardUnionSettlement OK");
-						log_info("Get Money:%s",ShmDcCommonData->pCreditCard[0].TransAmount);
-					} else
-						log_info("CreditCardUnionSettlement FAIL");
-						*/
 
-				} else {
-					log_info("PAYING FAIL");
-					ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] = FALSE;
-					pSysInfo->SystemPage = _PAGE_PAYFAIL;
+				if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && ShmDcCommonData->finalcost_flag[gunIndex]) {
+					ShmDcCommonData->StopCharge[gunIndex] = FALSE;
+					StopGunInfoTimeoutDet(gunIndex); //Timeout_FinalCost
+					result = CreditCardPreAuthComplete(fd,1 /*(int)ShmDcCommonData->finalcost[pSysInfo->CurGunSelected]*/ ,"TCC Test",
+															&ShmDcCommonData->pCreditCard[gunIndex].VemData[0],
+															&ShmDcCommonData->pCreditCard[gunIndex]);
+					//result = 1;
+					if (result > 0 ) {
+						log_info("Credit Card Spend Money:%.1f",ShmDcCommonData->finalcost[gunIndex]);
+						pSysInfo->SystemPage = _PAGE_COMPLETE;
+						WritePayResult(TRUE,gunIndex);
+						ShmDcCommonData->PayPass_flag[gunIndex] = TRUE;
+
+					} else {
+						log_info("PAYING FAIL");
+						ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
+						pSysInfo->SystemPage = _PAGE_PAYFAIL;
+						WritePayResult(FALSE,gunIndex);
+					}
+					if (isDeductDb_ready == TRUE) {
+						InsertDeductInfo(gunIndex,&ShmDcCommonData->TransactionInfo[gunIndex]);
+					}
+					ShmDcCommonData->PayFinish[gunIndex] = TRUE;
 				}
 
-            }
+			} // for
+			if (is_idle == TRUE && tm->tm_min%2 == 0 &&
+					pSysInfo->SystemPage == _PAGE_IDLE && ShmDcCommonData->reupload_deduct_status == 0) {
+				if (DB_GetReDeductInfo(&ReAuthComplete_Index,&ShmDcCommonData->ReAuthComplete) == PASS ) {
 
+					result = CreditCardPreAuthComplete(fd,(int)ShmDcCommonData->ReAuthComplete.Amount ,"TCC Test",
+															&ShmDcCommonData->ReAuthComplete.VemData[0],
+															&ShmDcCommonData->pCreditCard[0]);
+					if (result > 0) {
+						ShmDcCommonData->ReAuthComplete.DeductResult = YES;
+						ShmDcCommonData->ReAuthComplete.IsUpload = NO;
+						UpdateDeductInfoStatus(&ReAuthComplete_Index,&ShmDcCommonData->ReAuthComplete);
+						log_info("PreAuthComplete OK");
+					} else if ( result < 0) {
+						log_info("Backgroud ID:%d Amount:%d VemData:%s PreAuthComplete fail",
+								ShmDcCommonData->ReAuthComplete.TransactionId,
+								(int)ShmDcCommonData->ReAuthComplete.Amount,
+								ShmDcCommonData->ReAuthComplete.VemData);
+					}
+				} else {
+					log_info("DB_GetReDeductInfo Fail");
+				}
+			}
             if(ShmDcCommonData->PreAuth_Config == _CREDITCARD_CANCEL) {
             	ShmDcCommonData->PreAuth_Result = CreditCardPreAuthCancel(fd,PREAUTHMONEY,"TCC Test",
 					&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].ApprovalNo[0],
@@ -454,6 +519,25 @@ void CreateRfidFork(void)
 
 				}
 				ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
+            } else if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH) {
+        		result = CreditCardPreAuth(fd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
+				//result = 1;
+				if (result > 0) {
+					ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = TRUE;
+					//pSysInfo->SystemPage = _PAGE_PLUGIN;
+					//strncpy((char *)pSysConfig->UserId,ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo,20);
+					log_info("PreAuth OK");
+				} else if (result < 0) {
+				    struct ChargingInfoData *pDcChargingInfo = NULL;
+				    //pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
+					pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+					//pDcChargingInfo->SystemStatus = S_IDLE;
+					ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = FALSE;
+					memset(&ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected], 0, sizeof(TransInfo));
+					log_info("PreAuth Fail");
+					ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
+				}
+				ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
             }
             /*
             // 刷卡判斷

+ 46 - 21
EVSE/Projects/DD360Tcci/Apps/CSU/main.c

@@ -3511,7 +3511,9 @@ static void ReviewCriticalAlarm(void)
             ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP == YES ||
             ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP == YES ||
             ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP == YES ||
-            ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure == YES
+            ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure == YES ||
+			ShmSelectGunInfo->EthDevStatus.Backend == 0 ||
+			ShmSelectGunInfo->EthDevStatus.Backend == 2
        ) {
         pSysWarning->Level = WARN_LV_ER;
     } else {
@@ -3694,9 +3696,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
     case _Type_Chademo:
         // 檢查樁端的 GFD 結果
         if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_chademo(gunIndex) > 6 &&
-                isPrechargeStatus_chademo(gunIndex) < 8
-           ) {
+                isPrechargeStatus_chademo(gunIndex) >= 6 ) {
             // 當前操作的槍號,進入 Charging
             setChargerMode(gunIndex, MODE_CHARGING);
         }
@@ -3723,7 +3723,7 @@ static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sys
         // 檢查樁端的 GFD 結果
         //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
         if (sysStatus == S_PREPARING_FOR_EVSE &&
-                isPrechargeStatus_gb(gunIndex) > 6) {
+                isPrechargeStatus_gb(gunIndex) >= 6) {
             setChargerMode(gunIndex, MODE_CHARGING);
         }
 
@@ -3844,10 +3844,12 @@ void ResetIdleData(uint8_t gunIndex)
     //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[pSysInfo->CurGunSelected] = FALSE;
-    ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] = FALSE;
+    ShmDcCommonData->AuthPass_flag[gunIndex] = FALSE;
+    ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
+    ShmDcCommonData->GetCardNo[gunIndex] = FALSE;
 
     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
     destroySelGun(gunIndex);
@@ -3857,7 +3859,7 @@ void ResetIdleData(uint8_t gunIndex)
     }
     //strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
     ReleaseAlarmCode(gunIndex);
-    if (pSysInfo->SystemPage != _PAGE_SELECT_GUN)
+    if (pSysInfo->SystemPage != _PAGE_SELECT_GUN && pSysInfo->SystemPage != _PAGE_SELECT_PAY)
     	pSysInfo->SystemPage = _PAGE_IDLE;
 }
 void CheckErrorCode(uint8_t gunIndex)
@@ -3968,6 +3970,7 @@ int main(void)
     log_info(" ********************************************************");
     log_info(" ******************  Project:DD360Tcci  *****************");
     log_info(" ********************************************************");
+    int is_plugout[2];
     if (!InitialSystemDefaultConfig()) {
         log_error("InitialSystemDefaultConfig NG ");
         //StopProcessingLoop();
@@ -4138,6 +4141,7 @@ int main(void)
                 if (isModeChange(gunIndex)) {
                     log_info("============================= S_IDLE(%x) ============================= ", gunIndex);
                     ResetIdleData(gunIndex);
+                    is_plugout[gunIndex] = FALSE;
                 }
                 isChargingAverageState();
                 // For RemoteStart Using
@@ -4153,17 +4157,27 @@ int main(void)
                 ScannerCardProcess();
                 if (pSysInfo->SystemPage == _PAGE_SELECT_GUN) {
                 	ShmDcCommonData->LineStatus[gunIndex] = 0;
+                	StopGunInfoTimeoutDet(gunIndex);
                 	StartSystemTimeoutDet(Timeout_ReturnViewPage);
 				}
                 if (pSysInfo->CurGunSelected == gunIndex){
+
                 	if(pSysInfo->SystemPage ==_PAGE_BILL) {
                 		StartSystemTimeoutDet(Timeout_AddLine);
                 		if (ShmDcCommonData->LineStatus[gunIndex] == 1 || ShmDcCommonData->LineStatus[gunIndex] == 2 )
                 			pSysInfo->SystemPage =_PAGE_ADD_FRIEND;
                 	} else if(pSysInfo->SystemPage ==_PAGE_ADD_FRIEND) {
+                		StopSystemTimeoutDet();
                 		StartGunInfoTimeoutDet(gunIndex, Timeout_LineReigster);
-                		if (ShmDcCommonData->LineStatus[gunIndex] == 3 || ShmDcCommonData->LineStatus[gunIndex] == 4 )
+                		if (ShmDcCommonData->LineStatus[gunIndex] == 3)  {
+                			pSysInfo->SystemPage =_PAGE_SELECT_PAY;
+                			ShmDcCommonData->donate_flag[gunIndex] = FALSE;
+                		}
+						if (ShmDcCommonData->LineStatus[gunIndex] == 4 ) {
                 			pSysInfo->SystemPage =_PAGE_SELECT_PAY;
+                			ShmDcCommonData->donate_flag[gunIndex] = TRUE;
+
+                		}
                 	}
                 }
                 goto CheckStatus;
@@ -4269,7 +4283,8 @@ CheckStatus:
                     }
 
                     if (!GetIsCardScan() && pSysInfo->CurGunSelected == gunIndex &&
-                    		pSysInfo->SystemPage != _PAGE_AUTHORIZE_FAIL) {
+                    		pSysInfo->SystemPage != _PAGE_AUTHORIZE_FAIL &&
+                    		pSysInfo->SystemPage != _PAGE_SENSING) {
                         pSysInfo->SystemPage = _PAGE_PLUGIN;
                     }
                 }
@@ -4443,6 +4458,7 @@ CheckStatus:
                     ChangeStartOrStopDateTime(YES, gunIndex);
                     pDcChargingInfo->Replug_flag = FALSE;
                     ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
+                    ShmDcCommonData->StopCharge[gunIndex] = FALSE;
                 }
 
                 if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
@@ -4461,7 +4477,8 @@ CheckStatus:
                 		pSysInfo->SystemPage == _PAGE_STOP_CONFIRM_RIGHT)
                 	break;
                 // LCM => Charging
-                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_IDLE) {
+                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_IDLE &&
+                		pSysInfo->SystemPage != _PAGE_SELECT_GUN) {
                     pSysInfo->SystemPage = _PAGE_CHARGING;
                 }
                 break;
@@ -4525,8 +4542,12 @@ CheckStatus:
                 if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
                     break;
                 }
-
-                if (pDcChargingInfo->ConnectorPlugIn == NO ) {
+                if (pSysInfo->CurGunSelected == gunIndex && is_plugout[gunIndex] == TRUE) {
+                	pSysInfo->SystemPage = _PAGE_EXIT;
+                	break;
+                }
+                if (pDcChargingInfo->ConnectorPlugIn == NO) {
+                	is_plugout[gunIndex] = TRUE;
                     StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
                     if (pSysInfo->CurGunSelected == gunIndex) {
                     	pSysInfo->SystemPage = _PAGE_EXIT;
@@ -4534,8 +4555,7 @@ CheckStatus:
                     }
                 }
 
-                if (pSysInfo->CurGunSelected == gunIndex &&
-                		pSysInfo->SystemPage != _PAGE_PAYING) {
+                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING) {
                 	if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
 						pSysInfo->SystemPage = _PAGE_COMPLETE;
 					else
@@ -4560,9 +4580,10 @@ CheckStatus:
                 		ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
                 		ShmDcCommonData->PreAuth_Result = 0;
                     } else {
-						if(ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == FALSE) {
+						if(ShmDcCommonData->PayFinish[gunIndex] == FALSE) {
 							pSysInfo->SystemPage = _PAGE_PAYING;
 						}
+						ShmDcCommonData->StopCharge[gunIndex] = TRUE;
                     }
                 }
 
@@ -4571,7 +4592,12 @@ CheckStatus:
 
 					continue;
 				}
-                if (pDcChargingInfo->ConnectorPlugIn == NO ) {
+                if (pSysInfo->CurGunSelected == gunIndex && is_plugout[gunIndex] == TRUE) {
+                	pSysInfo->SystemPage = _PAGE_EXIT;
+                	break;
+                }
+                if (pDcChargingInfo->ConnectorPlugIn == NO) {
+                	is_plugout[gunIndex] = TRUE;
 					if (pDcChargingInfo->Replug_flag == TRUE) {
 						pSysInfo->SystemPage = _PAGE_SELECT_GUN;
 						pDcChargingInfo->SystemStatus = S_IDLE;
@@ -4582,11 +4608,10 @@ CheckStatus:
 					}
 					break;
 				}
-                if (pSysInfo->SystemPage == _PAGE_PAYING)
-                	break;
+                //if (pSysInfo->SystemPage == _PAGE_PAYING)
+                //	break;
 
-                if (pSysInfo->CurGunSelected == gunIndex &&
-                		pSysInfo->SystemPage != _PAGE_PAYING) {
+                if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING) {
                 	if (pDcChargingInfo->Replug_flag == TRUE)
                 		pSysInfo->SystemPage = _PAGE_PLUGOUT;
                 	else {

+ 23 - 2
EVSE/Projects/DD360Tcci/Apps/Config.h

@@ -409,7 +409,8 @@ typedef struct stTransInfo
 {
 	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];		//卡號(左靠右補空白),卡號部份隱藏
@@ -417,6 +418,19 @@ typedef struct stTransInfo
 	unsigned char VemData[64];		//無人自助設備交易資訊 交易別31/32 (預授權完成/預授權取消) 必要欄位 資訊來源為交易別13 (預授權)的回傳
 }TransInfo;
 
+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;
+}RecordTransactionInfo;
+
 typedef struct StDcCommonInfo {
     uint8_t RebootCount;
     uint8_t CcsVersion;
@@ -457,7 +471,7 @@ typedef struct StDcCommonInfo {
     char PresentTime[128];
     TransInfo pCreditCard[2];
     int runningcost[2];
-    int finalcost[2];
+    float finalcost[2];
     unsigned int finalcost_flag[2];
     float ChargingRate;
     int PreAuth_Config;
@@ -467,6 +481,13 @@ typedef struct StDcCommonInfo {
     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];
+    int reupload_deduct_status;		// 0:Not ReUpload 1:ReUpload 2:ReUpload finish
+    RecordTransactionInfo TransactionInfo[2];
+    RecordTransactionInfo UploadRedectInfo;
+    RecordTransactionInfo ReAuthComplete;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 233 - 0
EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.c

@@ -11,9 +11,11 @@
 
 //------------------------------------------------------------------------------
 #define DB_FILE                                 "/Storage/ChargeLog/localCgargingRecord.db"
+#define DEDUCT_FILE                 			"/Storage/ChargeLog/localDeductRecord.db"
 
 //------------------------------------------------------------------------------
 static sqlite3 *localDb;
+static sqlite3 *deductDb;
 
 //------------------------------------------------------------------------------
 //===============================================
@@ -324,3 +326,234 @@ int InsertEventRecord(uint8_t *statusCode)
 
     return result;
 }
+
+
+int DeductDB_Open(void)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char* createDeductInfoSql="CREATE TABLE IF NOT EXISTS deduct_record("
+					      	  "idx integer primary key AUTOINCREMENT, "
+							  "gunIndex text, "
+						  	  "transactionId text, "
+						  	  "deductResult text, "
+						  	  "isDonate text, "
+						  	  "approvalNo text, "
+						  	  "cardNo text,"
+						  	  "vemData text, "
+						  	  "amount text, "
+						  	  "isUpload text"
+						  	  ");";
+
+	if(sqlite3_open(DEDUCT_FILE, &deductDb))
+	{
+		result = FAIL;
+		log_info("Can't open deduct database: %s", sqlite3_errmsg(deductDb));
+		sqlite3_close(deductDb);
+	}
+	else
+	{
+		log_info("Deduct database open successfully.");
+
+		if (sqlite3_exec(deductDb, createDeductInfoSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			log_info("Create deduct info table error message: %s", errMsg);
+		}
+		else
+		{
+			log_info("Opened deduct info table successfully");
+		}
+
+		sqlite3_close(deductDb);
+	}
+
+	return result;
+}
+
+int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char sqlStr[1024] = {0};
+    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');",
+				    gunIndex,
+				    deductInfo->TransactionId,
+				    deductInfo->DeductResult,
+				    deductInfo->IsDonateInvoice,
+					approNo,
+					carNo,
+					vemData,
+				    deductInfo->Amount,
+				    deductInfo->IsUpload);
+
+    if (sqlite3_open(DEDUCT_FILE, &deductDb))
+    {
+        result = FAIL;
+        log_info( "Can't open deduct database: %s", sqlite3_errmsg(deductDb));
+        sqlite3_close(deductDb);
+    }
+    else
+    {
+        //log_info( "Local event record database open successfully.");
+        if (sqlite3_exec(deductDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+        {
+            result = FAIL;
+            log_info( "Insert deduct record error message: %s", errMsg);
+        }
+        else
+        {
+            //log_info( "Insert local event record successfully");
+        }
+
+        sqlite3_close(deductDb);
+    }
+
+    return result;
+}
+
+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);
+
+    if (sqlite3_open(DEDUCT_FILE, &deductDb))
+    {
+        result = FAIL;
+        log_info( "Can't open deduct database: %s", sqlite3_errmsg(deductDb));
+        sqlite3_close(deductDb);
+    }
+    else
+    {
+        //log_info( "Local event record database open successfully.");
+        if (sqlite3_exec(deductDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+        {
+            result = FAIL;
+            log_info( "update deduct record error message: %s", errMsg);
+        }
+        else
+        {
+            //log_info( "update deduct record successfully");
+        }
+
+        sqlite3_close(deductDb);
+    }
+
+    return result;
+}
+
+int DB_GetDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo)
+{
+    int result = PASS;
+    char *errMsg = NULL;
+    char sqlStr[1024];
+    char **rs;
+    int rows, cols;
+
+    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);
+    }
+    else if(deductResult >= 0 && uploadState < 0)
+    {
+        sprintf(sqlStr, "select * from deduct_record where deductResult = %d;", deductResult > 0 ? 1 : 0);
+    }
+    else if(deductResult < 0 && uploadState >= 0)
+    {
+        sprintf(sqlStr, "select * from deduct_record where isUpload = %d;", uploadState > 0 ? 1 : 0);
+    }
+    else
+    {
+        sprintf(sqlStr, "select * from deduct_record;");
+    }
+
+    if (sqlite3_open(DEDUCT_FILE, &deductDb))
+    {
+        result = FAIL;
+        log_info("Can't open deduct database: %s", sqlite3_errmsg(deductDb));
+        sqlite3_close(deductDb);
+    }
+    else
+    {
+        sqlite3_get_table(deductDb, sqlStr, &rs, &rows, &cols, &errMsg);
+
+        if (rows > 0)
+        {
+            for (int idxRow = 1; idxRow <= rows; idxRow++)
+            {
+                *gunIndex = atoi(rs[(idxRow * cols) + 1]);
+                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]);
+                deductInfo->Amount = atoi(rs[(idxRow * cols) + 8]);
+                deductInfo->IsUpload = atoi(rs[(idxRow * cols) + 9]);
+                break;
+            }
+        }
+        else
+        {
+            result = FAIL;
+        }
+        sqlite3_free_table(rs);
+        sqlite3_close(deductDb);
+    }
+
+    return result;
+}
+
+int DB_GetReDeductInfo(int *gunIndex, RecordTransactionInfo *deductInfo)
+{
+    int result = PASS;
+
+    if(DB_GetDeductInfo(0, -1, gunIndex, deductInfo) == PASS)
+    {
+        //log_info("GetReDeductInfo OK");
+    }
+    else
+    {
+        result = FAIL;
+        //log_info("GetReDeductInfo NG");
+    }
+
+    return result;
+}
+
+int DB_GetReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo)
+{
+    int result = PASS;
+
+    if(DB_GetDeductInfo(-1, 0, gunIndex, deductInfo) == PASS)
+    {
+        //log_info("GetReUploadDeduct OK");
+    }
+    else
+    {
+        result = FAIL;
+        //log_info("GetReUploadDeduct NG");
+    }
+
+    return result;
+}
+

+ 9 - 0
EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.h

@@ -1,6 +1,8 @@
 #ifndef _DATA_BASE_H_
 #define _DATA_BASE_H_
 
+#include "../Config.h"
+
 int DB_Open(void);
 int DB_Insert_Record(int gunIndex);
 int DB_Update_Operactive(uint8_t gunIndex, uint8_t IsAvailable);
@@ -11,4 +13,11 @@ int DB_Reboot_Record(void);
 int CreateEventRecord(void);
 int InsertEventRecord(uint8_t *statusCode);
 
+int DeductDB_Open(void);
+int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo);
+int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo);
+int DB_GetDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo);
+int DB_GetReDeductInfo(int *gunIndex, RecordTransactionInfo *deductInfo);
+int DB_GetReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo);
+
 #endif /* _DATA_BASE_H_ */

+ 76 - 31
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.c

@@ -27,6 +27,7 @@
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
 #include "../timeout.h"
+#include "../DataBase/DataBase.h"
 #include "DoComm.h"
 
 //------------------------------------------------------------------------------
@@ -891,15 +892,23 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     ShmSelectGunInfo->PricesInfo[plugNum].UserPrices = transPricesUnit(ntohl(pAccountInfo->UserPrices));
     pDcChargingInfo->ChargingFee                     = transPricesUnit(ntohl(pAccountInfo->TotalCost));
     ShmSelectGunInfo->PricesInfo[plugNum].Balance    = transPricesUnit(ntohl(pAccountInfo->Balance));
+    ShmSelectGunInfo->PricesInfo[plugNum].Discount   = transPricesUnit(ntohl(pAccountInfo->Discount));
+    ShmSelectGunInfo->PricesInfo[plugNum].TransactionId = ntohl(pAccountInfo->Transaction);
 
     if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
-            (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance)) {
+            (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance) ||
+			(pricesInfo[plugNum].Discount != ShmSelectGunInfo->PricesInfo[plugNum].Discount) ||
+			(pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId)) {
         pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
         pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
+        pricesInfo[plugNum].Discount = ShmSelectGunInfo->PricesInfo[plugNum].Discount;
+        pricesInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
 
-        log_info("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s",
+        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)
@@ -1305,6 +1314,9 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         break;
 
     case REG_DEDUCT_INFO:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
         break;
 
     default:
@@ -1426,30 +1438,41 @@ static int readChargerStationInfo(int fd)
     return ret;
 }
 
-static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex)
+static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactionInfo *transactionInfo)
 {
     int ret = PASS;
-    uint8_t dataBuf[6] = {0};
-    DeductInfoVar DeductInfo;
-
-    DeductInfo.Amount = ShmDcCommonData->finalcost[gunIndex];
-    DeductInfo.DeductResult = ShmDcCommonData->PayPass_flag[gunIndex];
-    DeductInfo.IsDonateInvoice = ShmDcCommonData->donate_flag[gunIndex];
-
-    dataBuf[0] = DeductInfo.DeductResult;
-    dataBuf[1] = DeductInfo.IsDonateInvoice;
-    dataBuf[2] = (DeductInfo.Amount >> 24) & 0xFF;
-    dataBuf[3] = (DeductInfo.Amount >> 16) & 0xFF;
-    dataBuf[4] = (DeductInfo.Amount >> 8) & 0xFF;
-    dataBuf[5] = (DeductInfo.Amount & 0xFF);
-
+    uint8_t dataBuf[22] = {0};
+    int i;
+
+    memset((char *)dataBuf, 0x00, sizeof(dataBuf));
+    dataBuf[0] = transactionInfo->DeductResult;
+    dataBuf[1] = transactionInfo->IsDonateInvoice;
+    dataBuf[2] = (transactionInfo->TransactionId >> 24) & 0xFF;
+    dataBuf[3] = (transactionInfo->TransactionId >> 16) & 0xFF;
+    dataBuf[4] = (transactionInfo->TransactionId >> 8) & 0xFF;
+    dataBuf[5] = (transactionInfo->TransactionId & 0xFF);
+
+    int amount = (int)(transactionInfo->Amount * 100);
+
+    dataBuf[6] = (amount >> 24) & 0xFF;
+    dataBuf[7] = (amount >> 16) & 0xFF;
+    dataBuf[8] = (amount >> 8) & 0xFF;
+    dataBuf[9] = (amount & 0xFF);
+    memcpy((char *)&dataBuf[10], transactionInfo->ApprovalNo,9);
+    /*
+    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);
     // copy deduct result to dataBuf here
 
     if ((ret = composeSocketData(fd,
                                  id,
                                  OP_WRITE_DATA,
                                  REG_DEDUCT_INFO,
-                                 6,
+                                 22,
                                  &dataBuf[0])) == FAIL) {
         return ret;
     }
@@ -1935,7 +1958,7 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
         ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
     }
 #else
-    gunID = ID_REGISTER;
+    gunID = gDoCommGblData.ConnectorID[plugNum];;
 
     ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0; //非Audi 不需要等待主櫃回報餘額
 #endif // DD360Audi
@@ -2026,12 +2049,13 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         case REG_CHARGING_CAP:
             if(gMoreInfoReq[plugNum].bits.FinalCostReq)
             {
-                readChargingCapability(fd, gunID);
-                gMoreInfoReq[plugNum].bits.FinalCostReq = false;
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
-                ShmDcCommonData->finalcost[plugNum] = (int)pDcChargingInfo->ChargingFee;
-                ShmDcCommonData->finalcost_flag[plugNum] = TRUE;
-                log_info("Gun %d get final cost", plugNum);
+                if (readChargingCapability(fd, gunID) == PASS) {
+					gMoreInfoReq[plugNum].bits.FinalCostReq = false;
+					pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+					ShmDcCommonData->finalcost[plugNum] = pDcChargingInfo->ChargingFee;
+					ShmDcCommonData->finalcost_flag[plugNum] = TRUE;
+					log_info("Gun %d get final cost", plugNum);
+                }
             }
             curReg = REG_PLUG_IN_STATE;
             break;
@@ -2277,6 +2301,14 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             break;
         }
 
+
+        if (ShmDcCommonData->reupload_deduct_status == 1) {
+        	if (writeDeductInfo(fd, 0xff,plugNum, &ShmDcCommonData->UploadRedectInfo) == PASS) {
+        		ShmDcCommonData->UploadRedectInfo.IsUpload = YES;
+        		ShmDcCommonData->reupload_deduct_status = 2;
+        	}
+        }
+
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) < 0
@@ -2303,12 +2335,14 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         if(!DeductResultReq[plugNum] && pDcChargingInfo->SystemStatus == S_ALARM &&
-        		ShmDcCommonData->finalcost_flag[plugNum] == TRUE)
+        		ShmDcCommonData->PayFinish[plugNum] == TRUE)
         {
             DeductResultReq[plugNum] = YES;
             log_info("Write Gun %d Deduct Result", plugNum);
-            writeDeductInfo(fd, gunID,plugNum);
+            writeDeductInfo(fd, gunID,plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
             ShmDcCommonData->finalcost_flag[plugNum] = FALSE;
+            ShmDcCommonData->PayFinish[plugNum] = FALSE;
+            log_info("writeDeductInfo finish");
         }
         break;
 
@@ -2462,6 +2496,17 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             writePresentChargingInfo(fd, plugNum, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
+        if(!DeductResultReq[plugNum] &&
+				pDcChargingInfo->SystemStatus == S_TERMINATING &&
+				ShmDcCommonData->PayFinish[plugNum] == TRUE)
+		{
+			DeductResultReq[plugNum] = YES;
+			log_info("Write Gun %d Deduct Result", plugNum);
+			writeDeductInfo(fd, gunID,plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
+			ShmDcCommonData->finalcost_flag[plugNum] = FALSE;
+			ShmDcCommonData->PayFinish[plugNum] = FALSE;
+			log_info("writeDeductInfo finish");
+		}
         break;
 
     case S_COMPLETE:
@@ -2475,14 +2520,14 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         if(!DeductResultReq[plugNum] &&
-        		(pDcChargingInfo->SystemStatus == S_COMPLETE ||
-					pDcChargingInfo->SystemStatus == S_TERMINATING) &&
-        		ShmDcCommonData->finalcost_flag[plugNum] == TRUE)
+				ShmDcCommonData->PayFinish[plugNum] == TRUE)
         {
             DeductResultReq[plugNum] = YES;
             log_info("Write Gun %d Deduct Result", plugNum);
-            writeDeductInfo(fd, gunID,plugNum);
+            writeDeductInfo(fd, gunID,plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
             ShmDcCommonData->finalcost_flag[plugNum] = FALSE;
+            ShmDcCommonData->PayFinish[plugNum] = FALSE;
+            log_info("writeDeductInfo finish");
         }
         break;
 

+ 7 - 0
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.h

@@ -141,6 +141,9 @@
 #define ST_NO_UPDATE_FIRMWARE                   (0x02)
 
 #define LCM_PAGE_REMOTE_START_NO_ID             (0x0001)
+
+#define UPLOAD_DEDUCT_DB						(0x5656)
+
 //#define LCM_PAGE_JOIN_LINE                      (0x0002)
 //#define LCM_PAGE_PAYMENT_SWITCH                 (0x0003)
 
@@ -151,7 +154,9 @@
 typedef struct StDeductInfoVar {
     unsigned char DeductResult;                     // 0: Fail, 1: Pass
     unsigned char IsDonateInvoice;                  // 0: Do not donate, 1: Donate
+    int TransactionId;								// transaction id
     int Amount;                                     // unit = 0.01 dollar
+    char ApprovalNumber[12];						// approval number
 } DeductInfoVar;
 
 /*
@@ -294,6 +299,8 @@ typedef struct StAccountInfo {
     int UserPrices;
     int TotalCost;
     int Balance;
+    int Discount;
+    int Transaction;
     uint8_t Reserved[3];
 } AccountInfo;
 

+ 72 - 45
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -20,6 +20,7 @@
 #include "../timeout.h"
 
 #define uSEC_VAL                                (1000000)
+
 //------------------------------------------------------------------------------
 //struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 //struct StatusCodeData           *ShmStatusCodeData;
@@ -204,6 +205,10 @@ void CheckReturnPress()
 	//pDcChargingInfo->SystemStatus = S_IDLE;
 	StopSystemTimeoutDet();
 	if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
+		if (pSysInfo->SystemPage == _PAGE_AUTHORIZE || pSysInfo->SystemPage == _PAGE_PLUGIN ) {
+			pSysInfo->SystemPage = _PAGE_SELECT_PAY;
+		}
+		pDcChargingInfo->SystemStatus = S_IDLE;
 		ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
 		ShmDcCommonData->PreAuth_Result = 0;
 		for(i=0;i<=30;i++) {
@@ -212,7 +217,7 @@ void CheckReturnPress()
 			sleep(1);
 		}
 		ShmDcCommonData->PreAuth_Result = 0;
-		pDcChargingInfo->SystemStatus = S_IDLE;
+
 		strcpy((char *)pSysConfig->UserId, "");
 		return;
 	}
@@ -239,6 +244,7 @@ void CheckStopConfirmPress()
 	pDcChargingInfo->SystemStatus = S_TERMINATING;
 	pSysInfo->SystemPage = _PAGE_PAYING;
 	is_stop = FALSE;
+	ShmDcCommonData->StopCharge[pSysInfo->CurGunSelected] = TRUE;
 	StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_FinalCost);
 	/*
 	ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
@@ -322,18 +328,18 @@ void CheckTouchPress(short id)
 				log_info("LCM left Gun down...............................%x %x %x",
 						pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
 			}
-        	/*
-        	if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE) {
+
+        	if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
+        			pSysInfo->SystemPage == _PAGE_PAYFAIL) {
 				StopSystemTimeoutDet();
 				StartSystemTimeoutDet(Timeout_ReturnViewPage);
-        	}*/
+        	}
             break;
         case _Touch_Show_Right:
-        	if (pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
-				log_info("Authorize Page can't select gun");
-				return;
-			}
-
+        	if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
+        		log_info("Authorize Process can't select gun");
+        		return;
+        	}
 			// Show log
 			if(pSysInfo->CurGunSelected != RIGHT_GUN_NUM) {
 				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
@@ -344,14 +350,17 @@ void CheckTouchPress(short id)
 				log_info("LCM Right Gun down...............................%x %x %x",
 						pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
 			}
-			/*
-        	if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE) {
+
+        	if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
+        			pSysInfo->SystemPage == _PAGE_PAYFAIL) {
 				StopSystemTimeoutDet();
 				StartSystemTimeoutDet(Timeout_ReturnViewPage);
         	}
-        	*/
+
             break;
         case _Touch_Return:
+        	if (pSysInfo->SystemPage == _PAGE_AUTHORIZE)
+        		pSysInfo->SystemPage = _PAGE_SELECT_PAY;
         	CheckReturnPress();
         	break;
         case _Touch_IDLE:
@@ -465,6 +474,7 @@ void CheckLCMPressed()
     } // if pid
     log_info("Create LCM fork:%d",Pid);
 }
+
 void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
 {
     read(_port, msg, readLen);
@@ -691,7 +701,7 @@ void string2ByteArray(uint8_t *input, uint8_t *output)
 
 void RefreshProgressAnimation()
 {
-	_everyPageRollChange >= 20 ? _everyPageRollChange = 0 : _everyPageRollChange++;
+	_everyPageRollChange >= 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
 }
 
 //================================================
@@ -830,6 +840,35 @@ void ChangeRemainTime(int sec)
     DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
 }
 */
+void ShowSelectGun()
+{
+	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
+	if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
+			pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
+		ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS1);
+
+	} else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
+			pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
+		ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS2);
+
+	} else if (pDcChargingInfo->Type == _Type_Chademo) {
+		ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CHAdeMo);
+
+	}
+	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
+	if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
+			pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
+		ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS1);
+
+	} else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
+			pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
+		ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS2);
+
+	} else if (pDcChargingInfo->Type == _Type_Chademo) {
+		ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CHAdeMo);
+
+	}
+}
 void ChangeChargingPowerValue(float pow)
 {
     uint8_t cmd[10];
@@ -861,7 +900,9 @@ void ChangeCarBonValue(float data)
     float _carbon = 0;
     memset(cmd, 0x00, sizeof(cmd));
     _carbon = (data*9)/10*2.36 - data*0.637;
-    sprintf((char *) value, "%d", (int)_carbon);
+    //log_info("Carbon:%d",(int)_carbon);
+
+	sprintf((char *) value, "%d", (int)_carbon);
     string2ByteArray(value, cmd);
     DisplayValueToLcm(_String_Carbon, cmd, sizeof(cmd));
 }
@@ -881,8 +922,10 @@ void ChangeChargingEnergyValue(float energy)
     	ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0+100);
     else
     	ChangeDisplay2Value(_Icon_ChargeBar,(int)energy+_TCC_Charging_Bar0);
-
-    sprintf((char *) value, "%.1f", energy);
+    if (energy < 10)
+    	sprintf((char *) value, "%.1f", energy);
+    else
+    	sprintf((char *) value, "%d", (int)energy);
     string2ByteArray(value, cmd);
     DisplayValueToLcm(_Strting_Energy, cmd, sizeof(cmd));
 }
@@ -1047,13 +1090,14 @@ void ProcessPageInfo()
 
             	break;
             case _PAGE_SELECT_PAY:
-            	if (ShmDcCommonData->donate_flag == TRUE) {
+            	if (ShmDcCommonData->donate_flag[i] == TRUE) {
             		ChangeDisplay2Value(_Icon_WordAddFriend,_ICON_Empty);
             	} else
             		ChangeDisplay2Value(_Icon_WordAddFriend,_TCC_SelectPayMode);
             	StartSystemTimeoutDet(Timeout_SelectPayMode);
             	break;
             case _PAGE_SELECT_GUN:
+            	ShowSelectGun();
             	ClearQR_flag[i] = FALSE;
 				break;
             case _PAGE_BILL:
@@ -1073,6 +1117,13 @@ void ProcessPageInfo()
 				}*/
             	//ChangeDisplay2Value(_Icon_Precharge,0);
             	//ChangeDisplay2Value(_Icon_Precharge,1);
+            	if (ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected] == TRUE &&
+            			ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] != TRUE) {
+            		ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
+            		ShmDcCommonData->PreAuth_Result = 0;
+            		sleep(3);
+            		pSysInfo->SystemPage = _PAGE_SENSING;
+            	}
             	_Text_Running_Count = 1;
                 break;
             case _PAGE_PLUGIN:
@@ -1115,7 +1166,7 @@ void ProcessPageInfo()
                 	ChangeTimeValue(0);
                 }
                 ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
-                //StartSystemTimeoutDet(Timeout_ReturnViewPage);
+                StartSystemTimeoutDet(Timeout_ReturnViewPage);
                 break;
             case _PAGE_COMPLETE:
             case _PAGE_PAYFAIL:
@@ -1129,7 +1180,7 @@ void ProcessPageInfo()
                 if ( ShmDcCommonData->finalcost[i] >= 0 && ShmDcCommonData->finalcost_flag[i] == TRUE) {
                 	StopGunInfoTimeoutDet(i);
 					ChangeChargingFeeValue(ShmDcCommonData->finalcost[i]);
-					ShmDcCommonData->finalcost_flag[i] = FALSE;
+					//ShmDcCommonData->finalcost_flag[i] = FALSE;
                 }
                 ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);
                 ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
@@ -1332,6 +1383,7 @@ void InformationShow()
     }
 }
 */
+
 void DefautLayOut()
 {
 	int i;
@@ -1344,32 +1396,7 @@ void DefautLayOut()
 	ChangeDisplay2Value(_Icon_CardPay,0);
 	ChangeDisplay2Value(0x5000,1);
 
-	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
-	if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
-			pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
-		ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS1);
-
-	} else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
-			pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
-		ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS2);
-
-	} else if (pDcChargingInfo->Type == _Type_Chademo) {
-		ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CHAdeMo);
-
-	}
-	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
-	if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
-			pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
-		ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS1);
-
-	} else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
-			pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
-		ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS2);
-
-	} else if (pDcChargingInfo->Type == _Type_Chademo) {
-		ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CHAdeMo);
-
-	}
+	ShowSelectGun();
 }
 /*
 static int InitialRfidPort(void)

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

@@ -60,6 +60,8 @@ typedef struct StPricesInfo {
     //float TotalCost;            //unit = 0.01 dollar, value / 100
     float Balance;              //unit = 0.01 dollar, value / 100
     //float DefaultPrices;        //unit = 0.01 dollar, value / 100
+    float Discount;
+    int TransactionId;
     uint8_t Reserved[4];
 } PricesInfo;
 

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


BIN
EVSE/Projects/DD360Tcci/output/FactoryConfig


BIN
EVSE/Projects/DD360Tcci/output/Module_ChkSysTask


BIN
EVSE/Projects/DD360Tcci/output/Module_DoComm


BIN
EVSE/Projects/DD360Tcci/output/Module_EvComm


BIN
EVSE/Projects/DD360Tcci/output/Module_EventLogging


BIN
EVSE/Projects/DD360Tcci/output/Module_InternalComm


BIN
EVSE/Projects/DD360Tcci/output/Module_LcmControl


BIN
EVSE/Projects/DD360Tcci/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Tcci/output/Module_UpdateFW


BIN
EVSE/Projects/DD360Tcci/output/ReadCmdline


BIN
EVSE/Projects/DD360Tcci/output/main


BIN
EVSE/Projects/DD360Tcci/output/simulation