Module_Systex.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /*
  2. * Module_RFID.c
  3. *
  4. * Created on: 2019-10-24
  5. * Update: 2020-10-19
  6. * Author: Eason Yang
  7. * Version: V0.03
  8. *
  9. * History
  10. * 1. Added : Reyax code.
  11. *
  12. *
  13. *
  14. *
  15. *
  16. */
  17. #include "Module_Systex.h"
  18. #define RequestLength 600
  19. #define ResponseLength 600
  20. //==================================
  21. // PRINT OUT LOG FORMAT
  22. //==================================
  23. #define SystemLogMessage
  24. #define DEBUG_INFO_1(format, args...) StoreLogMessage("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  25. #define DEBUG_WARN_1(format, args...) StoreLogMessage("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  26. #define DEBUG_ERROR_1(format, args...) StoreLogMessage("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  27. //==================================
  28. // HOST ID, offset = 0, length = 2 bytes ,
  29. //==================================
  30. unsigned char HOST_ID_CreditCard[] = {0x31, 0x30};//信用卡
  31. unsigned char HOST_ID_eTicket_Polling[] = {0x35, 0x30};//電子票證
  32. //==================================
  33. // Transaction Type, offset = 2, length = 2 bytes ,
  34. //==================================
  35. unsigned char TRANS_TYPE_Sale[] = {0x31, 0x31}; //消費交易 : 信用卡,票證,掃碼支付
  36. unsigned char TRANS_TYPE_Void[] = {0x30, 0x35};//取消交易 : 信用卡,
  37. unsigned char TRANS_TYPE_Refund[] = {0x31, 0x32};//退貨交易 : 信用卡,票證,掃碼支付
  38. unsigned char TRANS_TYPE_Pre_Auth[] = {0x31, 0x33}; //預授權交易 : 信用卡
  39. unsigned char TRANS_TYPE_Pre_Auth_Complete[] = {0x33, 0x31}; //預授權完成交易 : 信用卡
  40. unsigned char TRANS_TYPE_Pre_Auth_Cancel[] = {0x33, 0x32}; //取消預授權交易 : 信用卡
  41. unsigned char TRANS_TYPE_UnionSettlement[] = {0x35, 0x41}; //批次結帳請款
  42. //==================================
  43. // SystemLog message
  44. //==================================
  45. #ifdef SystemLogMessage
  46. int StoreLogMessage(const char *fmt, ...)
  47. {
  48. char Buf[4096 + 256];
  49. char buffer[4096];
  50. time_t CurrentTime;
  51. struct tm *tm;
  52. va_list args;
  53. va_start(args, fmt);
  54. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  55. va_end(args);
  56. memset(Buf, 0, sizeof(Buf));
  57. CurrentTime = time(NULL);
  58. tm = localtime(&CurrentTime);
  59. sprintf(Buf,
  60. "echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]RFID_SystemLog",
  61. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour,
  62. tm->tm_min, tm->tm_sec, buffer, tm->tm_year + 1900, tm->tm_mon + 1);
  63. system(Buf);
  64. #ifdef Debug
  65. printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year + 1900,
  66. tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
  67. buffer);
  68. #endif
  69. return rc;
  70. }
  71. #endif
  72. //==========================================
  73. // Module's command send/receive
  74. //==========================================
  75. int SendRequest(int uart, unsigned char* cmd, int length)
  76. {
  77. int len, TotalRtn=0, Rtn,i;
  78. unsigned int StartTime;
  79. unsigned char LRC=0;
  80. unsigned char SendBuffer[RequestLength+4], RecvBuf[8];
  81. len=length+3;
  82. memset(SendBuffer,0,RequestLength+4);
  83. SendBuffer[0]=0x02;
  84. memcpy(SendBuffer+1,cmd,length);
  85. SendBuffer[length+1]=0x03;
  86. for(i=1;i<=length+1;i++)
  87. {
  88. LRC^=SendBuffer[i];
  89. }
  90. SendBuffer[length+2]=LRC;
  91. //sleep(2); //required to make flush work, for some reason
  92. //for(int i=0;i<len;i++)
  93. //printf("%x\n",SendBuffer[i]);
  94. //printf("strlen(SendBuffer)=%d\n",strlen(SendBuffer));
  95. //printf("SendBuffer[0]=%x,SendBuffer[601]=%x,SendBuffer[602]=%x \n",SendBuffer[i],SendBuffer[601],SendBuffer[602]);
  96. //tcflush(uart,TCIOFLUSH);
  97. while(1)
  98. {
  99. Rtn=write(uart, SendBuffer+TotalRtn, len-TotalRtn);
  100. if(Rtn>0)
  101. {
  102. TotalRtn+=Rtn;
  103. if(TotalRtn>=len)
  104. {
  105. //printf("Rtn=%d,TotalRtn=%d\n",Rtn,TotalRtn);
  106. break;
  107. }
  108. }
  109. else
  110. {
  111. DEBUG_INFO_1("SendRequest: write fail (%d / %d)\n", TotalRtn,len);
  112. return -1;
  113. }
  114. }
  115. //usleep(100000);
  116. TotalRtn=0;
  117. memset(SendBuffer,0,RequestLength+4);
  118. StartTime = time(NULL);
  119. while(1)
  120. {
  121. Rtn=read(uart, SendBuffer+TotalRtn, 2-TotalRtn);
  122. if(Rtn>0)
  123. {
  124. TotalRtn+=Rtn;
  125. if(TotalRtn>=2)
  126. {
  127. if((SendBuffer[0]==0x06)&&(SendBuffer[1]==0x06))
  128. return TotalRtn;
  129. else
  130. {
  131. DEBUG_INFO_1("SendRequest: not recv ACKACK(%x, %x)\n", SendBuffer[0],SendBuffer[1]);
  132. return -1;
  133. }
  134. }
  135. }
  136. else
  137. {
  138. if((time(NULL)-StartTime)>3)
  139. {
  140. DEBUG_INFO_1("SendRequest: read fail (%d / 6)\n", TotalRtn);
  141. return -1;
  142. }
  143. }
  144. }
  145. }
  146. int RecvResponse(int uart, unsigned char* rx)
  147. {
  148. int len, TotalRtn=0, Rtn,i;
  149. unsigned int StartTime;
  150. unsigned char LRC=0, counter=0;
  151. unsigned char RecvBuffer[ResponseLength+4], tmpBuf[16];
  152. reRecv:
  153. len=ResponseLength+3;
  154. memset(RecvBuffer,0,ResponseLength+4);
  155. LRC=0;
  156. TotalRtn=0;
  157. StartTime = time(NULL);
  158. while(1)
  159. {
  160. Rtn=read(uart, RecvBuffer+TotalRtn, len-TotalRtn);
  161. if(Rtn>0)
  162. {
  163. TotalRtn+=Rtn;
  164. //for(int i=0;i<TotalRtn;i++)
  165. //printf("%x",RecvBuffer[i]);
  166. //printf("\n");
  167. if(TotalRtn>=len)
  168. {
  169. if((RecvBuffer[0]!=0x02)||(RecvBuffer[ResponseLength+1]!=0x03))
  170. {
  171. memset(tmpBuf,0,sizeof(tmpBuf));
  172. tmpBuf[0]=tmpBuf[1]=0x06;
  173. Rtn=write(uart, tmpBuf, 2);
  174. DEBUG_INFO_1("RecvResponse: Not Response format (STX=%c , ETX=%c)\n", RecvBuffer[0],RecvBuffer[ResponseLength+1]);
  175. return -1;
  176. }
  177. for(i=1;i<=ResponseLength+1;i++)
  178. {
  179. LRC^=RecvBuffer[i];
  180. }
  181. if(RecvBuffer[ResponseLength+2]!=LRC)
  182. {
  183. if(counter++<2)
  184. {
  185. memset(tmpBuf,0,sizeof(tmpBuf));
  186. tmpBuf[0]=tmpBuf[1]=0x15;
  187. Rtn=write(uart, tmpBuf, 2);
  188. goto reRecv;
  189. }
  190. else
  191. {
  192. memset(tmpBuf,0,sizeof(tmpBuf));
  193. tmpBuf[0]=tmpBuf[1]=0x06;
  194. Rtn=write(uart, tmpBuf, 2);
  195. DEBUG_INFO_1("RecvResponse: 2 times LRC Error (%d / %d)\n", LRC,RecvBuffer[ResponseLength+2]);
  196. return -1;
  197. }
  198. }
  199. memset(tmpBuf,0,sizeof(tmpBuf));
  200. memcpy(tmpBuf,RecvBuffer+1,8 );
  201. if((strstr(tmpBuf,"00000000")==NULL)&&(strstr(tmpBuf,"000000TD")==NULL))
  202. {
  203. memset(tmpBuf,0,sizeof(tmpBuf));
  204. tmpBuf[0]=tmpBuf[1]=0x06;
  205. Rtn=write(uart, tmpBuf, 2);
  206. DEBUG_INFO_1("RecvResponse: Response Code failed (%s)\n", tmpBuf);
  207. return -1;
  208. }
  209. memset(tmpBuf,0,sizeof(tmpBuf));
  210. tmpBuf[0]=tmpBuf[1]=0x06;
  211. Rtn=write(uart, tmpBuf, 2);
  212. memcpy(rx,RecvBuffer+1,ResponseLength);
  213. return ResponseLength;
  214. }
  215. }
  216. else
  217. {
  218. if((time(NULL)-StartTime)>40)//卡機30 seconds timeout
  219. {
  220. DEBUG_INFO_1("RecvResponse: read fail (%d / %d)\n", TotalRtn,len);
  221. return -1;
  222. }
  223. }
  224. }
  225. }
  226. //==========================================
  227. // CreditCardPreAuth
  228. // Input :
  229. // PreCost : 預扣金額*100, e.g., $1234 = 123400, $1234.56=123456
  230. // EVSEID: EVSE ID, max length is 18
  231. // Output :
  232. // ApprovalNo : EDC簽單調閱編號或授權碼[信用卡退貨交易, max length is 12
  233. // RRN : 信用卡交易序號, max length is 12
  234. // CardNum: 卡號,max length is 20
  235. // VemData : 無人自助設備交易資訊 交易別31/32 (預授權完成/預授權取消) 必要欄位 資訊來源為交易別13 (預授權)的回傳, max length is 64
  236. //==========================================
  237. int CreditCardPreAuth(int Fd, int PreCost,unsigned char *EVSEID, struct TransInfo *TransInfoReturn)
  238. {
  239. unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
  240. memset(Buffer,0x20,RequestLength);
  241. ptr=Buffer;
  242. strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
  243. ptr+=2;
  244. strncpy(ptr,TRANS_TYPE_Pre_Auth,2);//Transaction type
  245. ptr+=2;
  246. memset(tmpbuf,0,sizeof(tmpbuf));
  247. sprintf(tmpbuf,"%d", PreCost);
  248. if(strlen(tmpbuf)>12)
  249. {
  250. DEBUG_INFO_1("CreditCardPreAuth: Wrong PreCost (PreCost=%d)\n", PreCost);
  251. return -1;
  252. }
  253. memset(ptr,0x30,12);
  254. strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
  255. ptr+=12;//Trans Amount
  256. ptr+=12;//Approval No
  257. ptr+=20;//Card No
  258. strncpy(ptr,EVSEID, strlen(EVSEID));
  259. ptr+=18;//Store Id
  260. //ptr+=2;//Period
  261. if(SendRequest(Fd, Buffer, RequestLength)>0)
  262. {
  263. memset(Buffer,0,RequestLength);
  264. if(RecvResponse(Fd,Buffer)>0)
  265. {
  266. //for(int i=0;i<RequestLength;i++)
  267. //printf("%x, ",Buffer[i] );
  268. strncpy(TransInfoReturn->TransAmount,Buffer+44,12);
  269. strncpy(TransInfoReturn->TransDate,Buffer+56,6);
  270. strncpy(TransInfoReturn->TransTime,Buffer+62,6);
  271. strncpy(TransInfoReturn->StoreId,Buffer+97,18);
  272. strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
  273. strncpy(TransInfoReturn->RRN,Buffer+124,12);
  274. strncpy(TransInfoReturn->CardNo,Buffer+24,20);
  275. strncpy(TransInfoReturn->VemData,Buffer+246,64);
  276. return 1;
  277. }
  278. else
  279. {
  280. DEBUG_INFO_1("CreditCardPreAuth: RecvResponse failed\n");
  281. return -1;
  282. }
  283. }
  284. else
  285. {
  286. DEBUG_INFO_1("CreditCardPreAuth: SendRequest failed\n");
  287. return -1;
  288. }
  289. }
  290. //==========================================
  291. // CreditCardAuthComplete
  292. // Input :
  293. // PreCost : 扣金額*100, e.g., $1234 = 123400, $1234.56=123456
  294. // EVSEID: EVSE ID, max length is 18
  295. // VemData : the VEM data from CreditCardPreAuth, max length is 64
  296. // Output :
  297. //==========================================
  298. int CreditCardPreAuthComplete(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *VemData,struct TransInfo *TransInfoReturn)
  299. {
  300. unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
  301. memset(Buffer,0x20,RequestLength);
  302. ptr=Buffer;
  303. strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
  304. ptr+=2;
  305. strncpy(ptr,TRANS_TYPE_Pre_Auth_Complete,2);//Transaction type
  306. ptr+=2;
  307. memset(tmpbuf,0,sizeof(tmpbuf));
  308. sprintf(tmpbuf,"%d", PreCost);
  309. if(strlen(tmpbuf)>12)
  310. {
  311. DEBUG_INFO_1("CreditCardAuthComplete: Wrong PreCost (PreCost=%d)\n", PreCost);
  312. return -1;
  313. }
  314. memset(ptr,0x30,12);
  315. strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
  316. ptr+=12;//Trans Amount
  317. ptr+=12;//Approval No
  318. ptr+=20;//Card No
  319. strncpy(ptr,EVSEID, strlen(EVSEID));
  320. ptr+=18;//Store Id
  321. //ptr+=2;//Period
  322. strncpy(Buffer+500,VemData,64);
  323. if(SendRequest(Fd, Buffer, RequestLength)>0)
  324. {
  325. memset(Buffer,0,RequestLength);
  326. if(RecvResponse(Fd,Buffer)>0)
  327. {
  328. strncpy(TransInfoReturn->TransAmount,Buffer+44,12);
  329. strncpy(TransInfoReturn->TransDate,Buffer+56,6);
  330. strncpy(TransInfoReturn->TransTime,Buffer+62,6);
  331. strncpy(TransInfoReturn->StoreId,Buffer+97,18);
  332. strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
  333. strncpy(TransInfoReturn->RRN,Buffer+124,12);
  334. strncpy(TransInfoReturn->CardNo,Buffer+24,20);
  335. strncpy(TransInfoReturn->VemData,Buffer+246,64);
  336. return 1;
  337. }
  338. else
  339. {
  340. DEBUG_INFO_1("CreditCardAuthComplete: RecvResponse failed\n");
  341. return -1;
  342. }
  343. }
  344. else
  345. {
  346. DEBUG_INFO_1("CreditCardAuthComplete: SendRequest failed\n");
  347. return -1;
  348. }
  349. }
  350. //==========================================
  351. // CreditCardPreAuthCancel
  352. // Input :
  353. // PreCost : 預扣金額*100, e.g., $1234 = 123400, $1234.56=123456
  354. // EVSEID: EVSE ID, max length is 18
  355. // ApprovalNo: max length is 12
  356. // CardNum : max length is 20
  357. // Output :
  358. //==========================================
  359. int CreditCardPreAuthCancel(int Fd, int PreCost,unsigned char *EVSEID, unsigned char *ApprovalNo, unsigned char *CardNum,unsigned char *VemData)
  360. {
  361. unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
  362. memset(Buffer,0x20,RequestLength);
  363. ptr=Buffer;
  364. strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
  365. ptr+=2;
  366. strncpy(ptr,TRANS_TYPE_Pre_Auth_Cancel,2);//Transaction type
  367. ptr+=2;
  368. memset(tmpbuf,0,sizeof(tmpbuf));
  369. sprintf(tmpbuf,"%d", PreCost);
  370. if(strlen(tmpbuf)>12)
  371. {
  372. DEBUG_INFO_1("CreditCardPreAuthCancel: Wrong PreCost (PreCost=%d)\n", PreCost);
  373. return -1;
  374. }
  375. memset(ptr,0x30,12);
  376. strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
  377. ptr+=12;//Trans Amount
  378. strncpy(ptr,ApprovalNo, strlen(ApprovalNo));
  379. ptr+=12;//Approval No
  380. strncpy(ptr,CardNum, strlen(CardNum));
  381. ptr+=20;//Card No
  382. strncpy(ptr,EVSEID, strlen(EVSEID));
  383. ptr+=18;//Store Id
  384. //ptr+=2;//Period
  385. strncpy(Buffer+500,VemData,64);
  386. if(SendRequest(Fd, Buffer, RequestLength)>0)
  387. {
  388. memset(Buffer,0,RequestLength);
  389. if(RecvResponse(Fd,Buffer)>0)
  390. {
  391. return 1;
  392. }
  393. else
  394. {
  395. DEBUG_INFO_1("CreditCardPreAuthCancel: RecvResponse failed\n");
  396. return -1;
  397. }
  398. }
  399. else
  400. {
  401. DEBUG_INFO_1("CreditCardPreAuthCancel: SendRequest failed\n");
  402. return -1;
  403. }
  404. }
  405. //==========================================
  406. // CreditCardPreAuthCancel
  407. // Input :
  408. // PreCost : 預扣金額*100, e.g., $1234 = 123400, $1234.56=123456
  409. // EVSEID: EVSE ID, max length is 18
  410. // ApprovalNo: max length is 12
  411. // CardNum : max length is 20
  412. // Output :
  413. //==========================================
  414. int CreditCardUnionSettlement(int Fd,unsigned char *EVSEID,struct TransInfo *TransInfoReturn)
  415. {
  416. unsigned char Buffer[RequestLength], *ptr, tmpbuf[12];
  417. memset(Buffer,0x20,RequestLength);
  418. ptr=Buffer;
  419. strncpy(ptr,HOST_ID_CreditCard,2);//Host ID
  420. ptr+=2;
  421. strncpy(ptr,TRANS_TYPE_UnionSettlement,2);//Transaction type
  422. ptr+=2;
  423. /*memset(tmpbuf,0,sizeof(tmpbuf));
  424. sprintf(tmpbuf,"%d", PreCost);
  425. if(strlen(tmpbuf)>12)
  426. {
  427. DEBUG_INFO_1("CreditCardPreAuthCancel: Wrong PreCost (PreCost=%d)\n", PreCost);
  428. return -1;
  429. }
  430. memset(ptr,0x30,12);
  431. strncpy(ptr+12-(strlen(tmpbuf)+2),tmpbuf,strlen(tmpbuf));//Trans Amount
  432. */
  433. ptr+=12;//Trans Amount
  434. //strncpy(ptr,ApprovalNo, strlen(ApprovalNo));
  435. ptr+=12;//Approval No
  436. //strncpy(ptr,CardNum, strlen(CardNum));
  437. ptr+=20;//Card No
  438. strncpy(ptr,EVSEID, strlen(EVSEID));
  439. ptr+=18;//Store Id
  440. //ptr+=2;//Period
  441. if(SendRequest(Fd, Buffer, RequestLength)>0)
  442. {
  443. memset(Buffer,0,RequestLength);
  444. if(RecvResponse(Fd,Buffer)>0)
  445. {
  446. strncpy(TransInfoReturn->TransAmount,Buffer+44,12);
  447. strncpy(TransInfoReturn->TransDate,Buffer+56,6);
  448. strncpy(TransInfoReturn->TransTime,Buffer+62,6);
  449. strncpy(TransInfoReturn->StoreId,Buffer+97,18);
  450. strncpy(TransInfoReturn->ApprovalNo,Buffer+12,12);
  451. strncpy(TransInfoReturn->RRN,Buffer+124,12);
  452. strncpy(TransInfoReturn->CardNo,Buffer+24,20);
  453. strncpy(TransInfoReturn->VemData,Buffer+246,64);
  454. return 1;
  455. }
  456. else
  457. {
  458. DEBUG_INFO_1("CreditCardUnionSettlement: RecvResponse failed\n");
  459. return -1;
  460. }
  461. }
  462. else
  463. {
  464. DEBUG_INFO_1("CreditCardUnionSettlement: SendRequest failed\n");
  465. return -1;
  466. }
  467. }
  468. #if 0
  469. int InitComPort()
  470. {
  471. int fd;
  472. struct termios tios;
  473. fd = open("/dev/ttyS2", O_RDWR);
  474. if(fd<=0)
  475. {
  476. DEBUG_INFO_1("open /dev/ttyS2 NG\n");
  477. return -1;
  478. }
  479. ioctl (fd, TCGETS, &tios);
  480. tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
  481. tios.c_lflag = 0;
  482. tios.c_iflag = 0;
  483. tios.c_oflag = 0;
  484. tios.c_cc[VMIN]=0;
  485. tios.c_cc[VTIME]=(unsigned char)5; // timeout 500ms
  486. tios.c_lflag=0;
  487. tcflush(fd, TCIFLUSH);
  488. ioctl (fd, TCSETS, &tios);
  489. return fd;
  490. }
  491. int main(int argc, char *argv[])
  492. {
  493. int UartFd;
  494. struct TransInfo ReturnTransInfo;
  495. UartFd=InitComPort();
  496. if(UartFd<0)
  497. {
  498. printf("InitComPort NG\n");
  499. return;
  500. }
  501. //sleep(3);
  502. memset(&ReturnTransInfo,0,sizeof(struct TransInfo));
  503. printf("CreditCardPreAuth......\n");
  504. if(CreditCardPreAuth(UartFd, 1000,"TCC EVSE", &ReturnTransInfo)<=0)
  505. {
  506. printf("CreditCardPreAuth NG\n");
  507. return;
  508. }
  509. printf("ApprovalNo=%s\n",ReturnTransInfo.ApprovalNo);
  510. printf("RRN=%s\n",ReturnTransInfo.RRN);
  511. printf("CardNum=%s\n",ReturnTransInfo.CardNo);
  512. printf("VemData=%s\n",ReturnTransInfo.VemData);
  513. sleep(20);
  514. if(CreditCardPreAuthCancel(UartFd, 1000,"TCC EVSE", &ReturnTransInfo.ApprovalNo, &ReturnTransInfo.CardNo,&ReturnTransInfo.VemData)<=0)
  515. {
  516. printf("CreditCardPreAuthCancel NG\n");
  517. //return;
  518. }
  519. /*
  520. printf("CreditCardPreAuthComplete......\n");
  521. if(CreditCardPreAuthComplete(UartFd, 500,"TCC EVSE", &ReturnTransInfo.VemData, &ReturnTransInfo)<=0)
  522. {
  523. printf("CreditCardPreAuthComplete NG\n");
  524. return;
  525. }
  526. */
  527. sleep(15);
  528. if(CreditCardUnionSettlement(UartFd,"TCC EVSE",&ReturnTransInfo)<=0)
  529. {
  530. printf("CreditCardUnionSettlement NG\n");
  531. //return;
  532. }
  533. }
  534. #endif