فهرست منبع

2022-02-23 / Simon Xue

Action
1. [fix] Show date and week by time zone.
2. [Add] Disable press button
3. [Improve] Rededuct time change on UTC 15:00~15:30
4. [Improve] Settlement time change on UTC 15:30~16:00
5. [Improve] Search Rededuct function improve.
6. [Improve] Search Reupload function improve.

Files
As the following commit history files

Image Version: V2.05.XX.XXXX.XX
Simon Xue 3 سال پیش
والد
کامیت
d6659993fc

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

@@ -188,6 +188,7 @@ void ChkPrimaryStatus(void)
         pSysConfig->ShowInformation = NO;
     if (pSysConfig->ShowInformation)
         return;
+    return;
     // Press Left Button
     if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush ) {
     	if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_PLUGIN) {

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

@@ -351,8 +351,14 @@ void storePayResult(uint8_t gunIndex)
 void PreAuthCompleteToCardReader(int fd,uint8_t gunIndex)
 {
 	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;
+    }
     storePayResult(gunIndex);
-	result = CreditCardPreAuthComplete(fd,(int)ShmDcCommonData->finalcost[pSysInfo->CurGunSelected], "TCC Test",
+
+	result = CreditCardPreAuthComplete(fd,(int)ShmDcCommonData->finalcost[gunIndex], "TCC Test",
 											&ShmDcCommonData->pCreditCard[gunIndex].VemData[0],
 											&ShmDcCommonData->pCreditCard[gunIndex]);
 
@@ -425,8 +431,12 @@ int CreditCardCancelPreAuth(int fd,uint8_t gunIndex)
 void CreateRfidFork(void)
 {
     pid_t rfidRecPid;
+    int rededuct_gunIndex[128];
+    RecordTransactionInfo deductInfo[128];
+    int rededuct_num = 0;
 
     rfidRecPid = fork();
+    int j = 0;
     if (rfidRecPid == 0) {
         char localTime[128] = {0};
         struct timeb SeqEndTime;
@@ -441,7 +451,6 @@ void CreateRfidFork(void)
         ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
         ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
         struct ChargingInfoData *pDcChargingInfo = NULL;
-        ShmDcCommonData->reupload_deduct_status = 0;
         int gunIndex;
         int uploadIndex = 0;
         int ReAuthComplete_Index = 0;
@@ -462,75 +471,16 @@ void CreateRfidFork(void)
             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");
-				} else
-					log_info("CreditCardUnionSettlement FAIL");
-			}
-
-			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 (is_idle == TRUE && tm->tm_min % 15 == 0 &&
-                pSysInfo->SystemPage == _PAGE_IDLE && ShmDcCommonData->reupload_deduct_status == 0) {
-                sleep(1);
-                if (DB_GetReDeductInfo(&ReAuthComplete_Index, &ShmDcCommonData->ReAuthComplete) == PASS) {
-
-                    result = CreditCardPreAuthComplete(fd, (int)ShmDcCommonData->ReAuthComplete.Amount, "TCC Test",
-                        &ShmDcCommonData->ReAuthComplete.VemData[0],
-                        &ShmDcCommonData->pCreditCard[0]);
-                    sleep(10);
-                    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");
-                }
-            }
 
-            // Scan Card to get card number
-            /*
-            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) {
-            		//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...");
-            	}
+            if (ShmDcCommonData->UnionSettlement) {
+                ShmDcCommonData->UnionSettlement = 0;
+                result = CreditCardUnionSettlement(fd, "TCC Test", &ShmDcCommonData->pCreditCard[0]);
+                if (result > 0) {
+                    log_info("CreditCardUnionSettlement OK");
+                }
+                else
+                    log_info("CreditCardUnionSettlement FAIL");
             }
-            */
             is_idle = FALSE;
 			for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
 				pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
@@ -541,7 +491,7 @@ void CreateRfidFork(void)
                     ShmDcCommonData->StopCharge[gunIndex] = FALSE;
                     pSysInfo->SystemPage = _PAGE_PAYING;
                     StopGunInfoTimeoutDet(gunIndex); //Timeout_FinalCost
-					if (ShmDcCommonData->finalcost[gunIndex] < 1) {
+					if (ShmDcCommonData->finalcost[gunIndex] == 0) {
                         log_info("Final Cost less 1 , Cancel Trade!!");
                         if (CreditCardCancelPreAuth(fd, gunIndex) > 0) {
                             pSysInfo->SystemPage = _PAGE_COMPLETE;
@@ -585,6 +535,57 @@ void CreateRfidFork(void)
 				}
 				ShmDcCommonData->PreAuth_Config = _CREDITCARD_IDLE;
             }
+
+            // 每日晚上11點進行補扣款
+            if ((is_idle == TRUE && (tm->tm_hour == 15 && tm->tm_min < 30) &&
+                pSysInfo->SystemPage == _PAGE_IDLE &&
+                ShmDcCommonData->RoutineReduct == FALSE) || ShmDcCommonData->Exe_ReDeduct) {
+                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 &&
+                ShmDcCommonData->RoutineSettlement == FALSE) {
+                ShmDcCommonData->RoutineSettlement = TRUE;
+                result = CreditCardUnionSettlement(fd, "TCC Test", &ShmDcCommonData->pCreditCard[0]);
+                if (result > 0) {
+                    log_info("CreditCardUnionSettlement OK");
+                }
+                else
+                    log_info("CreditCardUnionSettlement FAIL");
+            }
+            if (tm->tm_hour == 16 && tm->tm_min == 0) {
+                ShmDcCommonData->RoutineSettlement = FALSE;
+                ShmDcCommonData->RoutineReduct = FALSE;
+            }
             /*
             // 刷卡判斷
             if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||

+ 10 - 4
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.04.00.0000.00"; // Phihong version
-char* DebugVersion = "v2.04.01";      // Software debug version
+char *fwVersion = "V2.05.00.0000.00"; // Phihong version
+char* DebugVersion = "v2.05.01";      // Software debug version
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -2593,6 +2593,7 @@ void CreateTimeoutFork(void)
                     pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
                     pDcChargingInfo->SystemStatus = S_IDLE;
 					pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
+                    ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
 				}
 				break;
             case Timeout_Terminating:
@@ -2607,6 +2608,7 @@ void CreateTimeoutFork(void)
             	if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_ADDLINE_TIMEOUT) {
             		StopSystemTimeoutDet();
             		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+                    ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
             	}
             	break;
 
@@ -2620,6 +2622,7 @@ void CreateTimeoutFork(void)
             	if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_SELECTPAY_TIMEOUT) {
             		StopSystemTimeoutDet();
             		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+                    ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
             	}
             	break;
             case Timeout_TradeCancel:
@@ -2628,6 +2631,7 @@ void CreateTimeoutFork(void)
                     pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
                     setChargerMode(pSysInfo->CurGunSelected, MODE_IDLE);
                     pSysInfo->SystemPage = _PAGE_SELECT_GUN;
+                    ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
                 }
                 break;
             }
@@ -2717,8 +2721,9 @@ void CreateTimeoutFork(void)
                 case Timeout_LineReigster:
                 	if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_LINEREGISTER_TIMEOUT) {
                 		StopGunInfoTimeoutDet(gunIndex);
-                		pSysInfo->SystemPage = _PAGE_SELECT_PAY;
+                		pSysInfo->SystemPage = _PAGE_SELECT_GUN;
                 		ShmDcCommonData->donate_flag[gunIndex] = FALSE;
+                        ShmDcCommonData->OperateIDLE[gunIndex] = 1;
                 	}
                 	break;
                     /*
@@ -3872,6 +3877,7 @@ void ResetIdleData(uint8_t gunIndex)
     ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
     ShmDcCommonData->GetCardNo[gunIndex] = FALSE;
     ShmDcCommonData->LineStatus[gunIndex] = 0;
+    ShmDcCommonData->OperateIDLE[gunIndex] = 1;
 
     ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
     destroySelGun(gunIndex);
@@ -4187,7 +4193,7 @@ int main(void)
 
                 	if(pSysInfo->SystemPage ==_PAGE_BILL) {
                 		StartSystemTimeoutDet(Timeout_AddLine);
-                        if (/*ShmDcCommonData->LineStatus[gunIndex] == 1 || */ShmDcCommonData->LineStatus[gunIndex] == 2) {
+                        if (ShmDcCommonData->LineStatus[gunIndex] == 1 || ShmDcCommonData->LineStatus[gunIndex] == 2) {
                             pSysInfo->SystemPage = _PAGE_ADD_FRIEND;
                             log_info("Change to Add Line Friend Page");
                         }

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

@@ -485,10 +485,16 @@ typedef struct StDcCommonInfo {
     unsigned int StopCharge[2];
     unsigned int GetCardNo[2];
     unsigned int TradeCancel;
-    int reupload_deduct_status;		// 0:Not ReUpload 1:ReUpload 2:ReUpload finish
     RecordTransactionInfo TransactionInfo[2];
     RecordTransactionInfo UploadRedectInfo;
     RecordTransactionInfo ReAuthComplete;
+    int UnionSettlement;
+    int Exe_ReDeduct;
+    unsigned int OperateIDLE[2];
+    int RoutineReduct;
+    int RoutineSettlement;
+    int RoutineReupload;
+    int TZOffset;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

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

@@ -419,6 +419,18 @@ int InsertDeductInfo(int gunIndex, RecordTransactionInfo *deductInfo)
             //log_info( "Insert local event record successfully");
         }
 
+
+        sprintf(sqlStr, "delete from deduct_record where idx < (select idx from deduct_record order by idx desc limit 1)-10000;");
+        if (sqlite3_exec(deductDb, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+        {
+            result = FAIL;
+            log_info("delete deduct record error message: %s", errMsg);
+        }
+        else
+        {
+            //log_info("delete local charging record successfully");
+        }
+
         sqlite3_close(deductDb);
     }
 
@@ -557,3 +569,102 @@ int DB_GetReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo)
     return result;
 }
 
+// return quantity of DeductInfo
+int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo)
+{
+    char *errMsg = NULL;
+    char sqlStr[1024];
+    char **rs;
+    int rows = 0, cols = 0;
+
+    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))
+    {
+        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[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]);
+
+                if(idxRow >= 128)
+                {
+                	rows = 128;
+                	break;
+                }
+            }
+        }
+
+        sqlite3_free_table(rs);
+        sqlite3_close(deductDb);
+    }
+
+    return rows;
+}
+
+int DB_GetMultiReDeductInfo(int *gunIndex, RecordTransactionInfo *deductInfo)
+{
+    int quantity = 0;
+
+    quantity = DB_GetMultiDeductInfo(0, -1, gunIndex, deductInfo);
+
+    return quantity;
+}
+
+int DB_GetMultiReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo)
+{
+	int quantity = 0;
+
+	quantity = DB_GetMultiDeductInfo(-1, 0, gunIndex, deductInfo);
+
+    return quantity;
+}
+
+void ReDeductTest()
+{
+	int quantity = 0;
+	int gunList[128];
+	RecordTransactionInfo deductInfo[128];
+
+	quantity = DB_GetMultiReDeductInfo(gunList, deductInfo);
+
+	if(quantity > 0)
+	{
+		for(int i = 0; i < quantity; i++)
+		{
+			printf("Gun %d Rededuct CardNo: %s", gunList[i], deductInfo[i].CardNo);
+		}
+	}
+}
+
+

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

@@ -20,4 +20,8 @@ int DB_GetDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTra
 int DB_GetReDeductInfo(int *gunIndex, RecordTransactionInfo *deductInfo);
 int DB_GetReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo);
 
+int DB_GetMultiDeductInfo(int deductResult, int uploadState, int *gunIndex, RecordTransactionInfo *deductInfo);
+int DB_GetMultiReDeductInfo(int *gunIndex, RecordTransactionInfo *deductInfo);
+int DB_GetMultiReUploadDeduct(int *gunIndex, RecordTransactionInfo *deductInfo);
+
 #endif /* _DATA_BASE_H_ */

+ 2 - 2
EVSE/Projects/DD360Tcci/Apps/Makefile

@@ -82,7 +82,7 @@ MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 	$(CC) $(CFLAGS) -c $<
 
 #DoComm
-DOCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(DoCommLib)/DoComm.o
+DOCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(DoCommLib)/DoComm.o $(DataBaseLib)/DataBase.o 
 DOCOMM_SRC_FILES = $(patsubst %.o, %.c, $(DOCOMM_OBJ_FILES))
 
 #internal comm lib
@@ -164,7 +164,7 @@ MainTask:
 	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent) $(Lib_Module_Systex)
 
 DoCommTask:
-	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_DoComm
+	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_DoComm
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
 	#$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
 	#$(CC) -o Module_DoComm DoComm.o define.o

+ 35 - 9
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.c

@@ -843,10 +843,13 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
         case MISC_CMD_TIME_OFFSET:
             TimeZoneOffset = value;
             log_info("Time Zone Offset: %d", TimeZoneOffset);
+            ShmDcCommonData->TZOffset = TimeZoneOffset;
+            /*
             if (TimeZoneOffset == 480) {
                 system("export TZ=CST-8");
                 log_info("Set Time Zone CST 8");
             }
+            */
             break;
         default:
             clearMiscCommand();
@@ -2155,7 +2158,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 writeConnectorState(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
-            curReg = REG_QRCODE_URL_INFO;
+            curReg = REG_DISPENSER_REQUEST;
             break;
 
         //case REG_USER_ID:
@@ -2257,28 +2260,28 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_DISPENSER_REQUEST;
+            curReg = REG_REMOTE_START_NO_ID;
             break;
 
         //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");
+                            log_info("Gun %d CHARGING_CANCEL OK",plugNum);
+                            ShmDcCommonData->OperateIDLE[plugNum] = 0;
                         }
                         ftime(&gRegTimeUp[plugNum][curReg]);
                     }
                 }
-                curReg = REG_REMOTE_START_NO_ID;
+                curReg = REG_QRCODE_URL_INFO;
                 break;
         case REG_REMOTE_START_NO_ID:
             if(gMoreInfoReq[plugNum].bits.RemoteStartNoID)
@@ -2355,9 +2358,14 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8_t gunID)
 {
     uint8_t i = 0;
+    int j;
     struct timeb AuthNowTime = {0};
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
-
+    int reupload_gunIndex[128];
+    RecordTransactionInfo reuploadInfo[128];
+    int reupload_num = 0;
+    struct timeb SeqEndTime;
+    struct tm* tm;
     switch (pDcChargingInfo->SystemStatus) {
     case S_IDLE:
     case S_RESERVATION:
@@ -2374,17 +2382,35 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (ShmSelectGunInfo->PricesInfo[plugNum].Balance == FAIL_BALANCE_PRICES) {
             break;
         }
+        ftime(&SeqEndTime);
+        SeqEndTime.time = time(NULL);
+        tm = localtime(&SeqEndTime.time);
+
+        if (tm->tm_min % 2 == 0 && pSysInfo->SystemPage == _PAGE_IDLE) {
+
+            reupload_num = DB_GetMultiReUploadDeduct(&reupload_gunIndex, &reuploadInfo);
+            //log_info("ReUpload number:%d", reupload_num);
+            for (j = 0; j < reupload_num; j++) {
+                log_info("Card No:%s", reuploadInfo[j].CardNo);
+                if (writeDeductInfo(fd, 0xff, reupload_gunIndex[j], &reuploadInfo[j]) == PASS) {
+                    log_info("Reupload Success");
+                    reuploadInfo[j].IsUpload = YES;
+                    UpdateDeductInfoStatus(reupload_gunIndex[j], &reuploadInfo[j]);
+                } else
+                    log_info("writeDeductInfo fail");
+            }
 
+        }
 
+        /*
         if (ShmDcCommonData->reupload_deduct_status == 1) {
             log_info("Reupload Deduct");
         	if (writeDeductInfo(fd, 0xff,plugNum, &ShmDcCommonData->UploadRedectInfo) == PASS) {
         		ShmDcCommonData->UploadRedectInfo.IsUpload = YES;
-        		ShmDcCommonData->reupload_deduct_status = 2;
             } else {
                 log_info("Reupload Deduct Failure!");
             }
-        }
+        }*/
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10) ||

+ 24 - 5
EVSE/Projects/DD360Tcci/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -225,7 +225,10 @@ void CheckReturnPress()
 	int i;
 	pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
 	//pDcChargingInfo->SystemStatus = S_IDLE;
-	
+    if (pSysInfo->SystemPage >= _PAGE_BILL && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
+        ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
+        log_info("Operate return to IDLE");
+    }
 	if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
         ShmDcCommonData->TradeCancel = TRUE;
         /*
@@ -287,7 +290,7 @@ void CheckReturnPress()
 		pSysInfo->SystemPage = _PAGE_IDLE;
 		return;
 	}
-	
+
     if (pSysInfo->SystemPage == _PAGE_AUTHORIZE)
         pSysInfo->SystemPage = _PAGE_SELECT_PAY;
     else
@@ -879,6 +882,7 @@ void ChangeQrCode_Idle(char *input)
     // https://nhoatcc.lineapid.tw/web/tologin?sn=ABC123&cid=2
     memset(cmd,0,256);
     int len = sprintf(cmd,"https://nhoatcc.lineapid.tw/web/tologin?sn=%s&cid=%d",input,ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
+    //int len = sprintf(cmd, "https://nhoatcctest.lineapid.tw/web/tologin?sn=%s&cid=%d", input, ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
     //log_info("QR Code:URL:%s",cmd);
     if (pSysInfo->SystemPage == _PAGE_BILL)
     	DisplayValueToLcm(_QRCode_AddLine, cmd, len+1);
@@ -1119,9 +1123,13 @@ void changeWeatherValue(int _weather)
 }
 void changeWeekValue(int _week)
 {
-	time_t t = time(NULL);
-	struct tm *now = localtime(&t);
-	_week = now->tm_wday;
+    time_t timep;
+    struct tm* tm;
+    time(&timep);
+    timep += (ShmDcCommonData->TZOffset * 60);
+
+    tm = localtime(&timep);
+	_week = tm->tm_wday;
 	if (_week == 0 )
 		_week = 7;
 	ChangeDisplay2Value(_Icon_Week,_week);
@@ -1135,6 +1143,17 @@ void changeDegreeValue(int _degree)
 }
 void changeDateValue(char* _date)
 {
+    time_t timep;
+    struct tm* tm;
+    time(&timep);
+    timep += (ShmDcCommonData->TZOffset * 60);
+
+    tm = localtime(&timep);
+
+    sprintf(_date, "%04d/%02d/%02d",
+        tm->tm_year + 1900,
+        tm->tm_mon + 1,
+        tm->tm_mday);
     char value[16];
     memset(value, 0x00, sizeof(value));
     sprintf((char *)value,"%s",_date);

+ 10 - 3
EVSE/Projects/DD360Tcci/Apps/ReadCmdline.c

@@ -535,6 +535,7 @@ void SetDebugMode(char *v1)
     int mode = atoi(v1);
 
     pSysConfig->SwitchDebugFlag = mode;
+    printf("Debug Flag:%d\n", pSysConfig->SwitchDebugFlag);
 }
 
 void SetGFDMode(char *v1)
@@ -1241,6 +1242,8 @@ int main(void)
                      "       tempR                             : print connector header and chiller temperature\r\n"
     			     "       btnl                              : press left button\n"
     			  	 "       btnr                              : press right button\n"
+                     "       settlement                        : Credit Card UnionSettlement\n"
+                     "       rededuct                          : Credit Card rededuct\n"
                      "\r\n";
 
     if (CreateAllCsuShareMemory() == FAIL) {
@@ -1413,9 +1416,13 @@ int main(void)
         	sleep(1);
         	ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_RELEASE;
         } else if (strcmp(newString[0], "btnr") == 0) {
-        	ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_PRESS;
-        	sleep(1);
-        	ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_RELEASE;
+            ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_PRESS;
+            sleep(1);
+            ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_RELEASE;
+        } else if (strcmp(newString[0], "settlement") == 0) {
+            ShmDcCommonData->UnionSettlement = 1;
+        } else if(strcmp(newString[0], "rededuct") == 0) {
+            ShmDcCommonData->Exe_ReDeduct = 1;
         } else {
             printf("%s\n", usageMsg);
         }

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