#include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include #include #include "../Config.h" #include "../Log/log.h" #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 SelectGunInfo *ShmSelectGunInfo = NULL; static struct SysInfoData *pSysInfo = NULL; #define PREAUTHMONEY 888 bool isDeductDb_ready; static RecordTransactionInfo LocalTransactionInfo; //------------------------------------------------------------------------------ static char *rfidPortName = "/dev/ttyS2"; static bool isCardScan = false; //------------------------------------------------------------------------------ static bool canStartCharging(void) { uint8_t index = 0; char buf2[16] = ""; memset(buf2, 0, ARRAY_SIZE(buf2)); struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data(); for (index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) { sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]); } sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); // 因為無法得知實際的長度,所以只能用搜尋的方式 if (strcmp(buf2, "Accepted") == EQUAL) { return true; } return false; } bool isAutorCompleteHandle(/*uint8_t *authorizeIndex*/) { // uint8_t i = 0; struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); //struct ChargingInfoData *pDcChargingInfo = NULL; //struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); // 透過後臺停止充電的判斷 if (isAuthorizedComplete()) { // 判斷後台回覆狀態 if (canStartCharging() == false) { strcpy((char *)pSysConfig->UserId, ""); ClearAuthorizedFlag(); } return true; } return false; /* if (*(authorizeIndex) != NO_DEFINE) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(*(authorizeIndex)); if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST && strcmp((char *)pDcChargingInfo->StartUserId, "") != EQUAL) { // 先找 AC if (*(authorizeIndex) == DEFAULT_AC_INDEX) { AcChargingTerminalProcess(); } else { ChargingTerminalProcess(*(authorizeIndex)); } } strcpy((char *)pSysConfig->UserId, ""); *(authorizeIndex) = NO_DEFINE; } ClearAuthorizedFlag(); } else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) { // 白名單驗證 for (i = 0; i < 10; i++) { if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) { continue; } if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) { ChargingTerminalProcess(*(authorizeIndex)); strcpy((char *)pSysConfig->UserId, ""); ClearAuthorizedFlag(); break; } } }*/ } bool RfidStopCharging(void) { //當前沒有選槍 struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL ) { strcpy((char *)pSysConfig->UserId, ""); return false; } struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected); if (pDcChargingInfo->isRemoteStart) { } else { if (strcmp((char *)pSysConfig->UserId, (char *)pDcChargingInfo->StartUserId) == EQUAL) { ChargingTerminalProcess(pSysInfo->CurGunSelected); strcpy((char *)pSysConfig->UserId, ""); log_info("index = %d, card number = %s, UserId = %s ", pSysInfo->CurGunSelected, pDcChargingInfo->StartUserId, pSysConfig->UserId); return true; } else { strcpy((char *)pSysConfig->UserId, ""); return false; } } return false; } 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; struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); //struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0); struct ChargingInfoData *pDcChargingInfo = NULL; //GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo(); // 當前非驗證的狀態 if (IsAuthorizingMode()) { isAutorCompleteHandle(/*&_authorizeIndex*/); } //當前沒有選槍 /* if (getConfirmSelectedGun(pSysInfo->CurGunSelected) == FAIL) { strcpy((char *)pSysConfig->UserId, ""); return; }*/ // 先判斷現在是否可以提供刷卡 // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能 // 2. 停止充電 //if (pSysInfo->PageIndex == _LCM_ERROR) { if (pSysInfo->SystemPage == _PAGE_MAINTAIN) { strcpy((char *)pSysConfig->UserId, ""); return; } /* for (i = 0; i < pSysConfig->TotalConnectorCount; i++) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i); if (pDcChargingInfo->SystemStatus == S_CHARGING) { stopReq = i; } if ((pDcChargingInfo->SystemStatus == S_AUTHORIZING && pDcChargingInfo->IsAvailable == YES) || (pGunIndexInfo->AcGunIndex > 0 && pAcChargingInfo->SystemStatus == S_AUTHORIZING && pAcChargingInfo->IsAvailable) ) { idleReq = true; } } if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX && pAcChargingInfo->SystemStatus == S_CHARGING) { stopReq = DEFAULT_AC_INDEX; } */ if (strlen((char *)pSysConfig->UserId) <= 0) { return; } pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected); // Stop Charging For AC /*if (pGunIndexInfo->AcGunIndex > 0 && stopReq == DEFAULT_AC_INDEX && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) { log_info("ac stop charging "); log_info("index = %d, card number = %s, UserId = %s ", pSysInfo->CurGunSelectedByAc, pAcChargingInfo->StartUserId, pSysConfig->UserId); memset(value, 0, sizeof(value)); memcpy(value, (uint8_t *)pAcChargingInfo->StartUserId, ARRAY_SIZE(pAcChargingInfo->StartUserId)); if (strcmp((char *)pSysConfig->UserId, value) == EQUAL) { AcChargingTerminalProcess(); } strcpy((char *)pSysConfig->UserId, ""); } else if (stopReq < pSysConfig->TotalConnectorCount && pDcChargingInfo->SystemStatus == S_CHARGING && (pGunIndexInfo->AcGunIndex <= 0 || (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == NO_DEFINE)) ) { // Stop Charging if (RfidStopCharging()) return; if (pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) { _authorizeIndex = pSysInfo->CurGunSelectedByAc; } else { _authorizeIndex = pSysInfo->CurGunSelected; } strcpy((char *)pSysConfig->UserId, ""); return; } else if (idleReq) { if (pSysConfig->TotalConnectorCount > 1 && stopReq != 255 && pSysInfo->IsAlternatvieConf == YES) { idleReq = false; strcpy((char *)pSysConfig->UserId, ""); } else if ((pGunIndexInfo->AcGunIndex > 0 && pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX) || pDcChargingInfo->SystemStatus == S_AUTHORIZING) {*/ if ( (pSysInfo->SystemPage == _PAGE_AUTHORIZE || pSysInfo->SystemPage == _PAGE_SENSING) && pDcChargingInfo->SystemStatus == S_IDLE) { log_info("// LCM => Authorizing"); confirmSelGun(pSysInfo->CurGunSelected); setSelGunWaitToAuthor(pSysInfo->CurGunSelected); StartSystemTimeoutDet(Timeout_Authorizing); AuthorizingStart(); pDcChargingInfo->SystemStatus = S_AUTHORIZING; // LCM => Authorizing //pSysInfo->SystemPage = _PAGE_AUTHORIZE; // 進入確認卡號狀態 } else { //strcpy((char *)pSysConfig->UserId, ""); } return; } bool GetIsCardScan(void) { return isCardScan; } void SetIsCardScan(bool value) { isCardScan = value; } void AuthorizeToCharge() { struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); // SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); // struct ChargingInfoData *pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);; ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData(); if(isAuthorizedComplete()) { if (canStartCharging()) { DetectPluginStart(); if (ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] == TRUE && ShmDcCommonData->TradeCancel == FALSE) { pSysInfo->SystemPage = _PAGE_PLUGIN; } } else { log_info("LCM => Authorize fail"); pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL; strcpy((char *)pSysConfig->UserId, ""); } ClearAuthorizedFlag(); } } void ScannerCardProcess(void) { //struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo(); struct ChargingInfoData *pDcChargingInfo = NULL; pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected); if (!isDetectPlugin() && (pSysInfo->SystemPage == _PAGE_SENSING || pSysInfo->SystemPage == _PAGE_AUTHORIZE ) && pDcChargingInfo->SystemStatus == S_IDLE && pSysWarning->Level != WARN_LV_ER /*&& pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE*/) { //setSelGunWaitToAuthor(pSysInfo->CurGunSelected); isCardScan = true; // 處理刷卡及驗證卡號的動作 UserScanFunction(); } if (pDcChargingInfo->SystemStatus == S_AUTHORIZING && pSysInfo->SystemPage == _PAGE_SENSING ) { AuthorizeToCharge(); } else if (pSysInfo->SystemPage == _PAGE_AUTHORIZE_FAIL) { StartSystemTimeoutDet(Timeout_VerifyFail); isCardScan = false; } else { isCardScan = false; } } void WritePayResult(int result ,uint8_t gunIndex) { 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, ShmDcCommonData->TransactionInfo[gunIndex].DeductResult, ShmDcCommonData->TransactionInfo[gunIndex].IsDonateInvoice, ShmDcCommonData->TransactionInfo[gunIndex].Amount); } void storePayResult(uint8_t gunIndex) { memset(&LocalTransactionInfo, 0, sizeof(RecordTransactionInfo)); 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->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->TransactionInfo[gunIndex].Amount, &pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard.VemData[0], &ShmDcCommonData->TransactionInfo[gunIndex].pCreditCard); sleep(10); 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); } 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]); memset(&ShmDcCommonData->TransactionInfo[gunIndex], 0x00, sizeof(RecordTransactionInfo)); 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 Total Number:%d", rededuct_num); for (j = 0; j < rededuct_num; j++) { if (pSysInfo->SystemPage != _PAGE_IDLE && !ShmDcCommonData->Exe_ReDeduct) { ShmDcCommonData->RoutineReduct = FALSE; break; } log_info("Start Rededuct item [%d]",j); if (deductInfo[j].isIntoCharge == FALSE || (deductInfo[j].Energy == 0 && deductInfo[j].Amount == 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; log_info("Backgroud PreAuthComplete OK"); } else if (result < 0) { deductInfo[j].DeductResult = _DEDUCT_COMPLETE_FAIL; 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; deductInfo[j].RedeductTime++; UpdateDeductInfoStatus(rededuct_gunIndex[j], &deductInfo[j]); } } ShmDcCommonData->RoutineReduct = TRUE; } static int InitialRfidPort(void) { int fd = open(rfidPortName, O_RDWR); struct termios tios; struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData(); if (fd != FAIL) { ioctl (fd, TCGETS, &tios); tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD; tios.c_lflag = 0; tios.c_iflag = 0; tios.c_oflag = 0; tios.c_cc[VMIN] = 0; tios.c_cc[VTIME] = (uint8_t) 1; tios.c_lflag = 0; tcflush(fd, TCIFLUSH); ioctl(fd, TCSETS, &tios); } if (fd < 0) { pAlarmCode->AlarmEvents.bits.RfidModuleCommFail = 1; } return fd; } void CreateRfidFork(void) { pid_t rfidRecPid; int rededuct_gunIndex[128]; RecordTransactionInfo deductInfo[128]; int rededuct_num = 0; int donate = 0; rfidRecPid = fork(); int j = 0; if (rfidRecPid == 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; 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 ReAuthComplete_Index = 0; //log_info("RFID fork Child's PID is %d", getpid()); int result; int is_idle = TRUE; while (isContinue) { result = 0; usleep(500000); ftime(&SeqEndTime); SeqEndTime.time = time(NULL); tm = localtime(&SeqEndTime.time); 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; } is_idle = TRUE; for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) { pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex); if (pDcChargingInfo->SystemStatus != S_IDLE) { is_idle = FALSE; } if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && pDcChargingInfo->Replug_flag == TRUE) { ShmDcCommonData->StopCharge[gunIndex] = FALSE; log_info("Not Into Charging cancel Trade"); StopGunInfoTimeoutDet(gunIndex); ShmDcCommonData->TradeCancel = TRUE; pSysInfo->SystemPage = _PAGE_SENSING; StartSystemTimeoutDet(Timeout_TradeCancel); CreditCardCancelPreAuth(fd, gunIndex); pSysInfo->SystemPage = _PAGE_PLUGOUT; StopSystemTimeoutDet(); } else { if (ShmDcCommonData->StopCharge[gunIndex] == TRUE && ShmDcCommonData->finalcost_flag[gunIndex]) { ShmDcCommonData->StopCharge[gunIndex] = FALSE; if (pDcChargingInfo->Replug_flag == TRUE) { log_info("Not Into Charging cancel Trade"); ShmDcCommonData->TradeCancel = TRUE; pSysInfo->SystemPage = _PAGE_SENSING; StartSystemTimeoutDet(Timeout_TradeCancel); } else pSysInfo->SystemPage = _PAGE_PAYING; StopGunInfoTimeoutDet(gunIndex); //Timeout_FinalCost // Remote Start of AutoStart ByPass Credit Card Reader if (ShmDcCommonData->DebugFlag == TRUE || ShmDcCommonData->is_RemoteStart[gunIndex] == TRUE || ShmDcCommonData->is_AutoStart[gunIndex] == TRUE) { pSysInfo->SystemPage = _PAGE_COMPLETE; ShmDcCommonData->PayPass_flag[gunIndex] = TRUE; continue; } // 實際扣款 if (ShmDcCommonData->TransactionInfo[gunIndex].Amount < 1) { log_info("Final Cost less 1 , Cancel Trade!!"); if (CreditCardCancelPreAuth(fd, gunIndex) > 0) { pSysInfo->SystemPage = _PAGE_COMPLETE; ShmDcCommonData->PayPass_flag[gunIndex] = TRUE; } else { pSysInfo->SystemPage = _PAGE_PAYFAIL; ShmDcCommonData->PayPass_flag[gunIndex] = FALSE; } } else { PreAuthCompleteToCardReader(fd, gunIndex); } } } } // for // 取消預授權 if(ShmDcCommonData->PreAuth_Config == _CREDITCARD_CANCEL) { CreditCardCancelPreAuth(fd,pSysInfo->CurGunSelected); // 預授權 } else if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH /* && ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected]*/) { donate = (int)ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice; memset(&ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected], 0x00, sizeof(RecordTransactionInfo)); ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = (unsigned char)donate; result = CreditCardPreAuth(fd, PREAUTHMONEY,&pSysConfig->ModelName[0], &ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard); if (!ShmDcCommonData->TradeCancel) StopSystemTimeoutDet(); if (ShmDcCommonData->TradeCancel == FALSE && result > 0) { pSysInfo->SystemPage = _PAGE_SENSING; } sleep(10); ShmDcCommonData->PreAuth_Result = result; //result = 1; if (result > 0 && strcmp(ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.CardNo,"") != 0 ) { ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = TRUE; strncpy((char*)pSysConfig->UserId, (char *)ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.CardNo, 20); log_info("Authorize card:%s", pSysConfig->UserId); ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].DeductResult = _DEDUCT_PREAUTH; ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsUpload = FALSE; InsertDeductInfo(ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected], &ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected]); log_info("PreAuth OK"); } else if (result < 0) { if (ShmDcCommonData->TradeCancel == FALSE) pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL; ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = FALSE; memset(&ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard, 0, sizeof(TransInfo)); log_info("PreAuth Fail"); } 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) { ReDeductProcess(fd); ShmDcCommonData->Exe_ReDeduct = 0; } // 每日晚上11點30分結帳 if (is_idle == TRUE && pSysInfo->SystemPage == _PAGE_IDLE && ((tm->tm_hour == 15 && tm->tm_min > 30 && ShmDcCommonData->RoutineSettlement == FALSE) || ShmDcCommonData->UnionSettlement)) { StopSystemTimeoutDet(); if (ShmDcCommonData->UnionSettlement) ShmDcCommonData->UnionSettlement = 0; else ShmDcCommonData->RoutineSettlement = TRUE; pSysInfo->SystemPage = _PAGE_MAINTAIN; result = CreditCardUnionSettlement(fd, &pSysConfig->ModelName[0], &LocalTransactionInfo.pCreditCard); if (result > 0) { log_info("CreditCardUnionSettlement OK"); } else log_info("CreditCardUnionSettlement FAIL"); sleep(90); pSysInfo->SystemPage = _PAGE_IDLE; } if (tm->tm_hour == 16 && tm->tm_min == 0) { ShmDcCommonData->RoutineSettlement = FALSE; ShmDcCommonData->RoutineReduct = FALSE; } /* // 刷卡判斷 if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING || !pSysConfig->isRFID) { continue; } if (getRequestCardSN(fd, 0, &rfid) == false) { continue; } //log_info("Get Card..-%s- ", pSysConfig->UserId); if (strlen((char *)pSysConfig->UserId) != 0) { continue; } if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) { switch (rfid.snType) { case RFID_SN_TYPE_6BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]); break; case RFID_SN_TYPE_7BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]); break; case RFID_SN_TYPE_10BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7], rfid.currentCard[8], rfid.currentCard[9]); break; case RFID_SN_TYPE_4BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]); break; } } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) { switch (rfid.snType) { case RFID_SN_TYPE_6BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]); break; case RFID_SN_TYPE_7BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]); break; case RFID_SN_TYPE_10BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[9], rfid.currentCard[8], rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]); break; case RFID_SN_TYPE_4BYTE: sprintf((char *) pSysConfig->UserId, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]); break; } } log_info("card number = %s", pSysConfig->UserId); */ } } }