int main(int argc, char **argv) { address_tuple_t tuple; char *server = NULL; char *port = NULL; char *keyfile = NULL; char *pidfile = NULL; char *logfile = NULL; char *progname; char c; char buf[BUFSIZ]; extern char build_info[]; pideid = NULL; progname = argv[0]; while ((c = getopt(argc, argv, "s:p:e:l:dk:i:Vu:N:")) != -1) { switch (c) { case 'd': debug++; break; case 's': server = optarg; break; case 'p': port = optarg; break; case 'e': pideid = optarg; break; case 'i': pidfile = optarg; break; case 'l': logfile = optarg; break; case 'k': keyfile = optarg; break; case 'u': swapper = optarg; break; case 'N': nodelocal_dir = optarg; break; case 'V': fprintf(stderr, "%s\n", build_info); exit(0); break; default: usage(progname); } } if (!pideid) usage(progname); if (debug) loginit(0, 0); else { if (logfile) loginit(0, logfile); else loginit(1, "linktest"); /* See below for daemonization */ } /* * Convert server/port to elvin thing. * * XXX This elvin string stuff should be moved down a layer. */ if (server) { snprintf(buf, sizeof(buf), "elvin://%s%s%s", server, (port ? ":" : ""), (port ? port : "")); server = buf; } /* * Construct an address tuple for subscribing to events for * this node. */ tuple = address_tuple_alloc(); if (tuple == NULL) { fatal("could not allocate an address tuple"); } /* * Ask for just the events we care about. */ tuple->expt = pideid; tuple->objtype = TBDB_OBJECTTYPE_LINKTEST; tuple->eventtype = TBDB_EVENTTYPE_START "," TBDB_EVENTTYPE_KILL; /* * Register with the event system. */ handle = event_register_withkeyfile(server, 0, keyfile); if (handle == NULL) { fatal("could not register with event system"); } /* * Subscribe to the event we specified above. */ if (! event_subscribe(handle, callback, tuple, NULL)) { fatal("could not subscribe to event"); } tuple->objtype = TBDB_OBJECTTYPE_TIME; tuple->objname = ADDRESSTUPLE_ANY; tuple->eventtype = TBDB_EVENTTYPE_START; /* * Subscribe to the TIME start event we specified above. */ if (! event_subscribe(handle, start_callback, tuple, NULL)) { fatal("could not subscribe to event"); } /* * Do this now, once we have had a chance to fail on the above * event system calls. */ if (!debug) daemon(0, 1); /* * Write out a pidfile if root (after we daemonize). */ if (!getuid()) { FILE *fp; if (pidfile) strcpy(buf, pidfile); else sprintf(buf, "%s/linktest.pid", _PATH_VARRUN); fp = fopen(buf, "w"); if (fp != NULL) { fprintf(fp, "%d\n", getpid()); (void) fclose(fp); } } /* * Initialize variables used to control child execution */ locked = FALSE; if(signal(SIGCHLD,sigchld_handler) == SIG_ERR) { fatal("could not install child handler"); } /* * Begin the event loop, waiting to receive event notifications: */ event_main(handle); /* * Unregister with the event system: */ if (event_unregister(handle) == 0) { fatal("could not unregister with event system"); } return 0; }
int ProcEcrEvent(void)//EPS should change here { int ii=0, iLen=0,DataLen=0; uchar sCurTime[7];//2014-11-4 uchar ucRet, szBuff[ECR_BUFFER_LEN],ucLRC; ST_EVENT_MSG stEvent; uchar sDataOut[100]; int nDataOutLen; memset(szBuff,0,sizeof(szBuff)); iLen = EcrRecvDataOnly(szBuff, sizeof(szBuff), 0); if (iLen<1 || iLen>sizeof(szBuff)) { return -1; } DelayMs(100);//2014-5-15 0.1s //PubDebugOutput("msg1",szBuff,iLen,DEVICE_PRN,HEX_MODE); // find first quote in data for (ii=0; ii<iLen; ii++) { if (szBuff[ii]=='\"') { break; } if (szBuff[ii]==0x02)//eps jardine 4mat { break; } } if (ii>=iLen) { return -1; } // continue receive from first quote if (ii!=0) { memmove(szBuff, szBuff+ii, iLen-ii); iLen = iLen-ii; } ii = EcrRecvDataOnly(szBuff+iLen, (ushort)(sizeof(szBuff)-iLen), 0); iLen += ii; if(0x02==szBuff[0]) //EPS jardine { DataLen = PubBcd2Long(szBuff+1,2,NULL); if (szBuff[0]!=0x02|| szBuff[iLen-2]!=0x03) { PortSend(glSysParam.stECR.ucPort, NAK); return -3; } //*** Check LRC *** ucLRC = szBuff[iLen-1]; for (ii = 1; ii <= DataLen+3 ; ii++) { ucLRC ^= szBuff[ii]; } if (ucLRC != 0) { PortSend(glSysParam.stECR.ucPort, NAK); return -3; } //OK PortSend(glSysParam.stECR.ucPort, ACK); // PubDebugOutput("msg",szBuff+3,DataLen,DEVICE_SCR,ASC_MODE); PackEcrMsgToEPS(&stEvent, EDC_ECR_MSG, szBuff+3,DataLen); AppDoEvent(glSysParam.astSubApp[APP_EPS].ucAppNo, &stEvent); EpsUpdateReverseState(stEvent.MagMsg.track1[0]);//2014-7-10 update EPS state } else { // ensure start/end format if ((strstr(szBuff, "\"<START>\"")==NULL) || (strstr(szBuff, "\"<END>\"")==NULL)) { return -3; } ucRet = EcrSendData_Sub((uchar *)STR_ECR_ACK, (ushort)strlen(STR_ECR_ACK), FALSE); /* PubDebugOutput("Here","02",2,DEVICE_PRN,ASC_MODE);//testttttt*/ //Beep(); Beef(6, 80);//2014-5-12 use Beef instead of beep ? /* PubDebugOutput("Here","03",2,DEVICE_PRN,ASC_MODE);//testttttt*/ if (strstr(szBuff,(uchar *)STR_ECR_ACK)!=NULL)//STR_ECR_ACK will send to eventmain which will cause excption { return 0; } // TODO : add processing here if (strstr(szBuff, "\"FUNC=CUP\"")!=NULL) { //2014-5-14 enhancement for ECR & Modem connection #ifdef _S60_ ClssClose(); //2014-5-16 enhance #endif #ifdef AMT_PROC_DEBUG//2014-11-4 record amt before send if(GetEcrAmtElement(szBuff)==0) { //time GetTime(sCurTime); sprintf((char *)glEcrAMT.glEcrAmtLog[glEcrAmtCnt].szTime, "%02X%02X%02X",sCurTime[3], sCurTime[4], sCurTime[5]); //txntype glEcrAMT.glEcrAmtLog[glEcrAmtCnt].szTranType = 1; ////2014-11-4 ttt //ScrCls(); //ScrPrint(0,0,0, "1_time: %s",glEcrAMT.glEcrAmtLog[glEcrAmtCnt].szTime); //ScrPrint(0,2,0, "1_type: %d",glEcrAMT.glEcrAmtLog[glEcrAmtCnt].szTranType); //ScrPrint(0,4,0, "1_amt : %s",glEcrAMT.glEcrAmtLog[glEcrAmtCnt].szEcrAmt); //getkey(); if(glEcrAmtCnt++ > 99) { glEcrAmtCnt = 0; } } #endif //11 Apr 2012 - build23: add CUP interface // TODO : Call CUP // CUP use EDC_ECR_MSG too PackEcrMsgToEvent(&stEvent, EDC_ECR_MSG, szBuff); //EDC_ECR_MSG, CUP_ECR_MSG share the same value 1231 //Gillian 20161129 if (glSysParam.stEdcInfo.ucClssFlag == 1)//send cmd to change R50 application to CUP { //2014-5-13 enhance tt ClssOpen(); //2014-5-16 enhance WaveProcOtherProtocol("\xE5", 1, sDataOut, &nDataOutLen); //2014-5-13 enhance tt ClssClose(); //2014-5-16 enhance } AppDoEvent(glSysParam.astSubApp[APP_CUP].ucAppNo, &stEvent); //2014-5-14 enhancement for ECR & Modem connection #ifdef _S60_ if (glSysParam.stEdcInfo.ucClssFlag==1)//2014-5-16 enhance { ClssOpen(); //2014-5-16 enhance } #endif } else if (strstr(szBuff, "\"FUNC=EPS\"")!=NULL) { // TODO : Call EPS } else { // Call EDC PackEcrMsgToEvent(&stEvent, EDC_ECR_MSG, szBuff); event_main(&stEvent); //AppDoEvent(glSysParam.astSubApp[APP_EDC].ucAppNo, &stEvent); } } EcrPortReset(); return 0; }
int main(void) { uchar bUpdateUI, bGallery = FALSE; int iRet; ST_EVENT_MSG stEventMsg; int iGallery_Image_Num = 0; uchar szGallery_Image_Num[5]= {0}; #ifdef APP_DEBUG ST_KEY_INFO stTmp_Key; ST_KCV_INFO stTmp_Kcv; #endif OsLogSetTag(APP_NAME); OsRegGetValue("ro.fac.mach", gl_szTerminalType); // Application initialization memset(&stEventMsg, 0, sizeof(stEventMsg)); stEventMsg.MsgType = USER_MSG; iRet = event_main(&stEventMsg); if (iRet == ERR_EXIT_APP) { // CommOnHook(TRUE); return 0; } ////////////////////////////////////////////////////////////////////////// //temp #ifdef APP_DEBUG OsPedEraseKeys(); stTmp_Key.ucSrcKeyType = PED_TMK; stTmp_Key.ucSrcKeyIdx = 0; stTmp_Key.ucDstKeyType = PED_TMK; stTmp_Key.ucDstKeyIdx = MASTER_KEY_ID; memcpy(stTmp_Key.aucDstKeyValue, "\xAB\xCD\xEF\x01\x23\x45\x67\x89"\ "\xAB\xCD\xEF\x01\x23\x45\x67\x89", 16); stTmp_Key.iDstKeyLen = 16; stTmp_Kcv.iCheckMode =0; PedWriteKey(&stTmp_Key, &stTmp_Kcv); stTmp_Key.ucSrcKeyType = PED_TMK; stTmp_Key.ucSrcKeyIdx = MASTER_KEY_ID; stTmp_Key.ucDstKeyType = PED_TPK; stTmp_Key.ucDstKeyIdx = DEF_PIN_KEY_ID; memcpy(stTmp_Key.aucDstKeyValue, "\xAB\xCD\xEF\x01\x23\x45\x67\x89"\ "\xAB\xCD\xEF\x01\x23\x45\x67\x89", 16); stTmp_Key.iDstKeyLen = 16; stTmp_Kcv.iCheckMode =0; PedWriteKey(&stTmp_Key, &stTmp_Kcv); stTmp_Key.ucSrcKeyType = PED_TMK; stTmp_Key.ucSrcKeyIdx = MASTER_KEY_ID; stTmp_Key.ucDstKeyType = PED_TDK; stTmp_Key.ucDstKeyIdx = DEF_DATA_KEY_ID; memcpy(stTmp_Key.aucDstKeyValue, "\x12\x12\x12\x12\x12\x12\x12\x12"\ "\x12\x12\x12\x12\x12\x12\x12\x12", 16); stTmp_Key.iDstKeyLen = 16; stTmp_Kcv.iCheckMode =0; PedWriteKey(&stTmp_Key, &stTmp_Kcv); #endif ////////////////////////////////////////////////////////////////////////// // Main loop bUpdateUI = TRUE; if(0 == GetEnv("PIC_NO", szGallery_Image_Num)) { iGallery_Image_Num = atoi(szGallery_Image_Num); } else { iGallery_Image_Num = 0; } //RunApp(1); test while( 1 ) { // Setup idle timer if (bUpdateUI) { SetIdleTimer(); } ShowIdleMainUI(&bUpdateUI, bGallery, iGallery_Image_Num); // bUpdateUI value may change // When magstripe card swiped if( MagSwiped()==0 ) { memset(&stEventMsg, 0, sizeof(ST_EVENT_MSG)); stEventMsg.MsgType = MAGCARD_MSG; stEventMsg.MagMsg.RetCode = MagRead(stEventMsg.MagMsg.track1, stEventMsg.MagMsg.track2, stEventMsg.MagMsg.track3); iRet = event_main(&stEventMsg); if (iRet==ERR_EXIT_APP) { // CommOnHook(TRUE); return 0; } bUpdateUI = TRUE; bGallery = FALSE; CommOnHook(FALSE); continue; } // When chip card inserted if( ChkIfEmvEnable() && IccDetect(ICC_USER)==0 ) { memset(&stEventMsg, 0, sizeof(ST_EVENT_MSG)); stEventMsg.MsgType = ICCARD_MSG; iRet = event_main(&stEventMsg); if (iRet==ERR_EXIT_APP) { // CommOnHook(TRUE); return 0; } bUpdateUI = TRUE; bGallery = FALSE; CommOnHook(FALSE); continue; } // If any key is pressed if( 0==kbhit() ) { memset(&stEventMsg, 0, sizeof(ST_EVENT_MSG)); stEventMsg.MsgType = KEYBOARD_MSG; stEventMsg.KeyValue = getkey(); // Add by lirz v1.02.0000 // If key enter,it repaint the main UI(mainly logo) again and again,do not do this if(KEYENTER == stEventMsg.KeyValue) { //RunApp(1); test continue; } iRet = event_main(&stEventMsg); if (iRet==ERR_EXIT_APP) { SetCurrTitle(_T("Exit")); // CommOnHook(TRUE); if(PasswordBank() == 0) { return 0; } } bUpdateUI = TRUE; bGallery = FALSE; CommOnHook(FALSE); continue; } // bug 803 change the sequence of 2 ChkIdleTimer if (ChkIdleTimer(glSysParam.stEdcInfo.ucIdleMinute * 60 /2)) { bGallery = TRUE; } // One of idle-processing if (ChkIdleTimer(glSysParam.stEdcInfo.ucIdleMinute * 60)) { if(0 == MainIdleProc()) { bUpdateUI = TRUE; bGallery = FALSE; } continue; } // TODO:add your event-handlers here... } // end of while( 1 return 0; }