12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "SpHelper.h"
- #include "CardReadAdapterFSM.h"
- #include "GetDevInfoHelper.h"
- #include "EventCode.h"
- #include "ModuleMix.h"
- #include <algorithm>
- #include <map>
- using namespace std;
- //CSimpleStringA<T> ambigulous
- #define _ATL_NO_AUTOMATIC_NAMESPACE
- //#include <atltime.h>
- class CCardReadAdapterEntity;
- void CCardReadAdapterFSM::s0_on_entry()
- {
- LOG_FUNCTION();
- CSystemStaticInfo sysInfo;
- m_csMachineType = m_csSite = m_terminalNo = "";
- GetEntityBase()->GetFunction()->GetSystemStaticInfo(sysInfo);
- m_csMachineType = sysInfo.strMachineType;
- m_csSite = sysInfo.strSite;
- m_terminalNo = sysInfo.strTerminalID;
- m_majorVerion = sysInfo.MachineVersion.GetMajor();
- m_minorVerion = sysInfo.MachineVersion.GetMinor();
- Dbg("machineType:%s,site:%s,terminalNo:%s,machineVersion:%d.%d", (const char*)m_csMachineType, (const char*)m_csSite, (const char*)m_terminalNo
- , m_majorVerion, m_minorVerion);
- m_eMachineType = MachineType_Unknown;
- if (_strnicmp((const char*)m_csMachineType, "RVC.Stand2S", strlen("RVC.Stand2S")) == 0)
- m_eMachineType = MachineType_RVC_Stand2S;
- else if (_strnicmp((const char*)m_csMachineType, "RVC.PAD", strlen("RVC.PAD")) == 0)
- m_eMachineType = MachineType_RVC_PAD;
- else if (_strnicmp((const char*)m_csMachineType, "RVC.Wall", strlen("RVC.Wall")) == 0)
- m_eMachineType = MachineType_RVC_Wall;
- // --Josephus at 8:17:02 201741
- else if (_strnicmp((const char*)m_csMachineType, "RPM.Stand1S", strlen("RPM.Stand1S")) == 0)
- m_eMachineType = MachineType_RPM_Stand1S;
- else if (_strnicmp((const char*)m_csMachineType, "RVC.CardStore", strlen("RVC.CardStore")) == 0)
- m_eMachineType = MachineType_RVC_CardStore;
- else if (_strnicmp((const char*)m_csMachineType, "RVC.CardPrinter", strlen("RVC.CardPrinter")) == 0)
- m_eMachineType = MachineType_RVC_CardPrinter;
- else if (_strnicmp((const char*)m_csMachineType, "RVC.Desk2S", strlen("RVC.Desk2S")) == 0)
- m_eMachineType = MachineType_RVC_DESK2S;
- else if (_strnicmp((const char*)m_csMachineType, "RVC.Desk1S", strlen("RVC.Desk1S")) == 0)
- m_eMachineType = MachineType_RVC_DESK1S;
- else if (_strnicmp((const char*)m_csMachineType, "RVC.IL", strlen("RVC.IL")) == 0)
- {
- m_bRVCIL = true;
- m_eMachineType = MachineType_RVC_IL;
- }
- FSMEvent *pEvt;
- pEvt = new FSMEvent(USER_EVT_INIT);
- PostEventFIFO(pEvt);
- }
- void CCardReadAdapterFSM::s0_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CCardReadAdapterFSM::s0_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- Dbg("s0 evt %d", pEvt->iEvt);
- switch (pEvt->iEvt)
- {
- case USER_EVT_INIT:
- {
- InitTask* task = new InitTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- pEvt->SetHandled();
- return 0;
- }
- break;
- default:
- break;
- }
- return 0;
- }
- //Initializing
- void CCardReadAdapterFSM::s1_on_entry()
- {
- LOG_FUNCTION();
- }
- void CCardReadAdapterFSM::s1_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CCardReadAdapterFSM::s1_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- Dbg("s1 evt %d", pEvt->iEvt);
- switch (pEvt->iEvt)
- {
- case USER_EVT_INIT_FINISHED:
- pEvt->SetHandled();
- return pEvt->param1;
- default:
- break;
- }
- return 0;
- }
- //Idle
- void CCardReadAdapterFSM::s2_on_entry()
- {
- LOG_FUNCTION();
- GetEntityBase()->GetFunction()->SetUserDefineState(USER_CARDISSUER_IDLE);
- Dbg("set reset times 0.");
- m_resetTimes = 0;
- m_testResult = Error_Succeed;
- m_bIssuingExit = false;
- m_bCancelAccept = false;
- m_lastS2Event = m_lastS2EvtParam1 = 0;
- //oiltmp 测试便携厂商发卡
- //m_pCardIssuer->SetIssuerCounter(0, 1);
- //m_pCardIssuer->MoveCard(CI_MOVECARD_FROM_HOPPER);
- //MagTracks magTracks;
- //magTracks.eRange = CI_TRACK_RANGE_2_3;
- //m_pCardIssuer->MagRead(magTracks);
- //Dbg("%s,%d,%d", magTracks.track[1].data, magTracks.track[1].dwSize, magTracks.track[1].eStatus);
- //m_pCardIssuer->MoveCard(CI_MOVECARD_FRONT_GATE);
- //ErrorCodeEnum err = m_pIDCard->SetCardInType(CARD_IN_TYPE_ALL);
- //Dbg("accept[%d]",err);
- //Sleep(WAIT_INTERVAL*10);
- //LPCardAccount* ppCardAccount;
- ////err = m_pIDCard->GetCardAccount(IDC_TRACK_1|IDC_TRACK_2|IDC_TRACK_3,&ppCardAccount);
- ////Dbg("read[%d]",err);
- ////Dbg("%d,%d,%d",ppCardAccount[0]->dataStatus,(ppCardAccount[1])->dataStatus,(ppCardAccount[2])->dataStatus);//,pCardAccount->data);
- ////Dbg("%d,%d,%d",ppCardAccount[0]->length,(ppCardAccount[1])->length,(ppCardAccount[2])->length);//,pCardAccount->data);
- ////Dbg("read data[%s][%s][%s]",(char*)(ppCardAccount[0]->data),(char*)(ppCardAccount[1]->data),(char*)(ppCardAccount[2]->data));
- //err = m_pIDCard->DectectCardType(m_cardType);
- //Dbg("detectcardtyp[%d][%d]",err,m_cardType);
- //err = m_pIDCard->ActiveCard();
- //Dbg("activecard[%d]",err);
- //vector<AIDData> vAIDs;
- //MessageBoxA(0,0,0,0);
- //if (m_cardType == CARDTYPE_CPU_T0 || m_cardType == CARDTYPE_CPU_T1)
- //{
- // BuildSupportedAppList(vAIDs);
- // Dbg("[%s]",testIC);
- // AppSelected(m_vADFRec.at(0).name,m_vADFRec.at(0).nameLen);
- //}
- }
- void CCardReadAdapterFSM::s2_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CCardReadAdapterFSM::s2_on_event(FSMEvent* pEvt)
- {
- Dbg("s2 evt(%d),param1:%d", pEvt->iEvt,pEvt->param1);
- m_lastS2Event = pEvt->iEvt;
- m_lastS2EvtParam1 = pEvt->param1;
- int ret = 0;
- switch (pEvt->iEvt)
- {
- case USER_EVT_READ:
- {
- //oilyang@20200426 according to MachineType ***AND MachineVersion*** to decide which Card-like entity to be called
- //RVC.Stand2S, RVC.PAD, RVC.IL, RPM.Stand1S, RVC.CardStore, RVC.Wall, RVC.Desk2S, RVC.Desk1S
- // ContactlessCard:
- // --RVC.Stand2S, RVC.Desk2S(all MachineVersion), RVC.Desk1S(all MachineVersion)
- // CardSwiper:
- // --except for RVC.Stand2S,RVC.CardStore,RVC.CardPrinter
- // --oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
- // Desk2S 2.1 have no CardSwiper,so no need call it
- // CardIssuer:
- // --no matter what MachineType is,just call it ,except for "RVC.Desk2S 2.0"
- // -- see the following "except for cross call" ,what the f**king line means?
- pEvt->SetHandled();
- CardReadEvent* cre = dynamic_cast<CardReadEvent*>(pEvt);
- bool bCardIssuer, bCardSwiper, bContactlessCard;
- bCardIssuer = bCardSwiper = bContactlessCard = false;
- if (m_eMachineType == MachineType_RVC_Stand2S || m_eMachineType == MachineType_RVC_DESK2S
- || m_eMachineType == MachineType_RVC_DESK1S)
- {
- ContactlessCardReadTask* cTask = new ContactlessCardReadTask(this);
- cTask->ctx = cre->ctx;
- if (IsTheEntity(cre->ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK())
- {
- bContactlessCard = true;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(cTask);
- Dbg("to ContactlessCard");
- }
- }
- //oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
- //Desk2S 2.1 have no CardSwiper,so no need call it
- if (!(m_eMachineType == MachineType_RVC_Stand2S
- || m_eMachineType == MachineType_RVC_CardStore
- || m_eMachineType == MachineType_RVC_CardPrinter
- || m_eMachineType == MachineType_RVC_DESK1S
- || (m_eMachineType == MachineType_RVC_DESK2S && m_majorVerion == 2 && m_minorVerion == 1)))
- {
- CardSwiperReadTask* sTask = new CardSwiperReadTask(this);
- sTask->ctx = cre->ctx;
- if (IsTheEntity(cre->ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
- {
- bCardSwiper = true;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(sTask);
- Dbg("to CardSwiper");
- }
- }
- //oilyang@20200426 暂时未发现这行代码的用处,可能简版?后来废弃。暂时保留,后续考虑去掉
- if ((cre->ctx->Req.reserved1.GetCount() == 0 || cre->ctx->Req.reserved1[0] != 1))//except for cross call
- {
- CardIssuerReadTask* iTask = new CardIssuerReadTask(this);
- iTask->ctx = cre->ctx;
- if (IsTheEntity(cre->ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
- {
- bCardIssuer = true;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(iTask);
- Dbg("to CardIssuer");
- }
- if (bCardIssuer || bCardSwiper || bContactlessCard)
- Dbg("bCardIssuer,bCardSwiper,bContactlessCard:%d,%d,%d", bCardIssuer, bCardSwiper, bContactlessCard);
- else
- {
- Dbg("can't find the right entity.");
- ret = 1;//no need to change to "Working" state
- cre->ctx->Answer(Error_Unexpect);
- }
- }
- }
- break;
- case USER_EVT_PREONLINE:
- {
- PreOnlineEvent* poe = dynamic_cast<PreOnlineEvent*>(pEvt);
- PreOnlineTask* task = new PreOnlineTask(this);
- task->ctx = poe->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- pEvt->SetHandled();
- return 0;
- }
- case USER_EVT_WRITE:
- {
- pEvt->SetHandled();
- CardWriteEvent* cwe = dynamic_cast<CardWriteEvent*>(pEvt);
- WriteTask* task = new WriteTask(this);
- task->ctx = cwe->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- return 0;
- }
- case USER_EVT_POSTONLINE:
- {
- PostOnlineEvent* poe = dynamic_cast<PostOnlineEvent*>(pEvt);
- PostOnlineTask* task = new PostOnlineTask(this);
- task->ctx = poe->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- pEvt->SetHandled();
- return 0;
- }
- case USER_EVT_EXIT:
- {
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- pEvt->SetHandled();
- DoExitTask* task = new DoExitTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_EJECT:
- {
- pEvt->SetHandled();
- CardEjectEvent* cee = dynamic_cast<CardEjectEvent*>(pEvt);
- EjectTask* task = new EjectTask(this);
- task->ctx = cee->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_SET_SOME_FLAG:
- {
- pEvt->SetHandled();
- SetSomeFlagEvent* ssfe = dynamic_cast<SetSomeFlagEvent*>(pEvt);
- SetSomeFlagTask* task = new SetSomeFlagTask(this);
- task->ctx = ssfe->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_GET_DEV_INFO:
- {
- pEvt->SetHandled();
- GetDevInfoEvent* gdie = dynamic_cast<GetDevInfoEvent*>(pEvt);
- GetDevInfoTask* task = new GetDevInfoTask(this);
- task->ctx = gdie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUERY_CARD_INFO:
- {
- pEvt->SetHandled();
- QueryCardInfoEvent* qcie = dynamic_cast<QueryCardInfoEvent*>(pEvt);
- QueryCardInfoTask* task = new QueryCardInfoTask(this);
- task->ctx = qcie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUIT:
- pEvt->SetHandled();
- break;
- case USER_EVT_ISSUE:
- {
- pEvt->SetHandled();
- CardIssueEvent* cee = dynamic_cast<CardIssueEvent*>(pEvt);
- IssueTask* task = new IssueTask(this);
- task->ctx = cee->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_CAPTURE:
- {
- pEvt->SetHandled();
- CardCaptureEvent* cee = dynamic_cast<CardCaptureEvent*>(pEvt);
- CaptureTask* task = new CaptureTask(this);
- task->ctx = cee->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_GET_MATERIAL:
- {
- pEvt->SetHandled();
- GetMaterialEvent *gme = dynamic_cast<GetMaterialEvent*>(pEvt);
- GetMaterialCountTask *task = new GetMaterialCountTask(this);
- task->ctx = gme->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- break;
- }
- case USER_EVT_SET_MATERIAL:
- {
- pEvt->SetHandled();
- SetMaterialEvent *sme = dynamic_cast<SetMaterialEvent*>(pEvt);
- SetMaterialCountTask *task = new SetMaterialCountTask(this);
- task->ctx = sme->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- break;
- }
- case USER_EVT_GET_SCI_INFO:
- {
- pEvt->SetHandled();
- GetSCIInfoEvent* gsie = dynamic_cast<GetSCIInfoEvent*>(pEvt);
- GetSCIInfoTask* task = new GetSCIInfoTask(this);
- task->ctx = gsie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_OPEN_SAFELOCK:
- {
- pEvt->SetHandled();
- OpenSafeLockEvent *osle = dynamic_cast<OpenSafeLockEvent*>(pEvt);
- OpenSafeLockTask* task = new OpenSafeLockTask(this);
- task->ctx = osle->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_MAGTRANS_INIT:
- {
- pEvt->SetHandled();
- MagTransferInitEvent* mtie = dynamic_cast<MagTransferInitEvent*>(pEvt);
- MagTransferInitTask* task = new MagTransferInitTask(this);
- task->ctx = mtie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUERY_CONN_INFO:
- {
- pEvt->SetHandled();
- QueryConnInfoEvent* qcie = dynamic_cast<QueryConnInfoEvent*>(pEvt);
- QueryConnInfoTask* task = new QueryConnInfoTask(this);
- task->ctx = qcie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_SAM_IC_COMMAND:
- {
- pEvt->SetHandled();
- SAMICCommandEvent* samice = dynamic_cast<SAMICCommandEvent*>(pEvt);
- SAMICCommandTask* task = new SAMICCommandTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUERY_PRINTER_STATUS:
- {
- pEvt->SetHandled();
- QueryPrinterStatusEvent* samice = dynamic_cast<QueryPrinterStatusEvent*>(pEvt);
- QueryPrinterStatusTask* task = new QueryPrinterStatusTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_PRINT:
- {
- pEvt->SetHandled();
- PrintEvent* samice = dynamic_cast<PrintEvent*>(pEvt);
- PrintTask* task = new PrintTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUERY_SCILIST:
- {
- pEvt->SetHandled();
- QuerySCIListEvent* samice = dynamic_cast<QuerySCIListEvent*>(pEvt);
- QuerySCIListTask* task = new QuerySCIListTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_BIND_SCI:
- {
- pEvt->SetHandled();
- BindSCIEvent* samice = dynamic_cast<BindSCIEvent*>(pEvt);
- BindSCITask* task = new BindSCITask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_PREONLINE_ON_STORE:
- {
- pEvt->SetHandled();
- PreOnlineOnStoreEvent* samice = dynamic_cast<PreOnlineOnStoreEvent*>(pEvt);
- PreOnlineOnStoreTask* task = new PreOnlineOnStoreTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_GET_ADD_CARD_INFO:
- {
- pEvt->SetHandled();
- GetAddCardInfoEvent* samice = dynamic_cast<GetAddCardInfoEvent*>(pEvt);
- GetAddCardInfoTask* task = new GetAddCardInfoTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_NOTIFY_PREONLINE:
- {
- pEvt->SetHandled();
- NotifyPreonlineEvent* samice = dynamic_cast<NotifyPreonlineEvent*>(pEvt);
- NotifyPreOnlineTask* task = new NotifyPreOnlineTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUERY_CARD_INFO_ON_STORE:
- {
- pEvt->SetHandled();
- QueryCardInfoOnStoreEvent* samice = dynamic_cast<QueryCardInfoOnStoreEvent*>(pEvt);
- QueryCardInfoOnStoreTask* task = new QueryCardInfoOnStoreTask(this);
- task->ctx = samice->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_CROSS_TERM_CALL:
- {
- pEvt->SetHandled();
- CrossTermCallEvent* ctce = dynamic_cast<CrossTermCallEvent*>(pEvt);
- CrossTermCallTask* task = new CrossTermCallTask(this);
- task->ctx = ctce->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_PRINT_CARD_IM:
- {
- pEvt->SetHandled();
- PrintCardImEvent* pcie = dynamic_cast<PrintCardImEvent*>(pEvt);
- PrintCardImTask* task = new PrintCardImTask(this);
- task->ctx = pcie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- default:
- break;
- }
- return ret;
- }
- //Working
- void CCardReadAdapterFSM::s3_on_entry()
- {
- LOG_FUNCTION();
- }
- void CCardReadAdapterFSM::s3_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CCardReadAdapterFSM::s3_on_event(FSMEvent* pEvt)
- {
- Dbg("s3 evt %d,%d", pEvt->iEvt,pEvt->param1);
- int ret = 0;
- switch (pEvt->iEvt)
- {
- case USER_EVT_READ_FINISHED:
- {
- pEvt->SetHandled();
- ret = pEvt->param1;
- //if (pEvt->param1 == 0)
- CardReadFinishedEvent* crfe = dynamic_cast<CardReadFinishedEvent*>(pEvt);
- {
- if (m_bCancelAccept)
- {
- Dbg("front cancel");
- crfe->ctx->Answer(Error_Cancel);
- ret = 0;
- }
- }
- if (pEvt->param1 == 7)//CardIssuer Timeout,need to cancel ContactlessCard insert
- {
- Dbg("CardIssuer Timeout,need to cancel ContactlessCard insert");
- if (IsContactlessCardSessionOK())
- m_pContactless->CancelInsert();
- crfe->ctx->Answer(Error_TimeOut);
- ret = 0;
- break;
- }
- else if (pEvt->param1 == 8)//ContactlessCard Timeout,need to cancel CardIssuer insert
- {
- Dbg("ContactlessCard Timeout,need to cancel CardIssuer insert");
- if (IsCardIssuerSessionOK())
- m_pCardIssuer->CancelInsert();
- if (IsCardSwiperSessionOK())
- m_pCardSwiper->CancelInsert();
- crfe->ctx->Answer(Error_TimeOut);
- ret = 0;
- break;
- }
- else if (pEvt->param1 == 9)//CardSwiper Timeout,need to cancel ContactlessCard insert
- {
- Dbg("ContactlessCard Timeout,need to cancel CardIssuer insert");
- if (IsContactlessCardSessionOK())
- m_pContactless->CancelInsert();
- crfe->ctx->Answer(Error_TimeOut);
- ret = 0;
- break;
- }
- if (m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
- {
- Dbg("as card in ContactlessCard,to cancel others");
- if (IsCardIssuerSessionOK())
- m_pCardIssuer->CancelInsert();
- if (IsCardSwiperSessionOK())
- m_pCardSwiper->CancelInsert();
- }
- else if (m_busCtx.eCardFromWhich == Card_In_CardIssuer)
- {
- Dbg("as card in CardIssuer,to cancel others");
- if (IsContactlessCardSessionOK())
- m_pContactless->CancelInsert();
- if (IsCardSwiperSessionOK())
- m_pCardSwiper->CancelInsert();
- }
- else if (m_busCtx.eCardFromWhich == Card_In_CardSwiper)
- {
- Dbg("as card in CardSwiper,to cancel others");
- if (IsCardIssuerSessionOK())
- m_pCardIssuer->CancelInsert();
- if (IsContactlessCardSessionOK())
- m_pContactless->CancelInsert();
- }
- return ret;
- }
- case USER_EVT_PREONLINE_FINISHED:
- pEvt->SetHandled();
- return 0;
- case USER_EVT_POSTONLINE_FINISHED:
- pEvt->SetHandled();
- return 0;
- case USER_EVT_READ_CANCEL:
- pEvt->SetHandled();
- m_bCancelAccept = true;
- CancelRead();
- break;
- case USER_EVT_READ_WAIT_MORE:
- {
- pEvt->SetHandled();
- ReadWaitMoreTask* task = new ReadWaitMoreTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_EXIT:
- {
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- pEvt->SetHandled();
- DoExitTask* task = new DoExitTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_WRITE_FINISHED:
- case USER_EVT_SET_SOME_FLAG_FINISHED:
- case USER_EVT_GET_DEV_INFO_FINISHED:
- case USER_EVT_QUERY_CARD_INFO_FINISHED:
- case USER_EVT_GET_MATERIAL_FINISHED:
- case USER_EVT_SET_MATERIAL_FINISHED:
- case USER_EVT_GET_SCI_INFO_FINISHED:
- case USER_EVT_OPEN_SAFELOCK_FINISHED:
- case USER_EVT_MAGTRANS_INIT_FINISHED:
- case USER_EVT_QUERY_CONN_INFO_FINISHED:
- case USER_EVT_QUIT:
- case USER_EVT_SAM_IC_COMMAND_FINISHED:
- case USER_EVT_QUERY_PRINTER_STATUS_FINISHED:
- case USER_EVT_PRINT_FINISHED:
- case USER_EVT_QUERY_SCILIST_FINISHED:
- case USER_EVT_BIND_SCI_FINISHED:
- case USER_EVT_PREONLINE_ON_STORE_FINISHED:
- case USER_EVT_GET_ADD_CARD_INFO_FINISHED:
- case USER_EVT_NOTIFY_PREONLINE_FINISHED:
- case USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED:
- case USER_EVT_CROSS_TERM_CALL_FINISHED:
- case USER_EVT_PRINT_CARD_IM_FINISHED:
- pEvt->SetHandled();
- break;
- default:
- break;
- }
- return ret;
- }
- //Failed
- void CCardReadAdapterFSM::s4_on_entry()
- {
- LOG_FUNCTION();
- m_lastS2Event = m_lastS2EvtParam1 = 0;
- GetEntityBase()->GetFunction()->SetUserDefineState(USER_CARDISSUER_HOLD);
- }
- void CCardReadAdapterFSM::s4_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CCardReadAdapterFSM::s4_on_event(FSMEvent* pEvt)
- {
- Dbg("s4 evt(%d)", pEvt->iEvt);
- switch (pEvt->iEvt)
- {
- case USER_EVT_EXIT:
- {
- pEvt->SetHandled();
- DoExitTask* task = new DoExitTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUIT:
- {
- pEvt->SetHandled();
- return 0;
- }
- case USER_EVT_SET_SOME_FLAG:
- {
- pEvt->SetHandled();
- SetSomeFlagEvent* ssfe = dynamic_cast<SetSomeFlagEvent*>(pEvt);
- SetSomeFlagTask* task = new SetSomeFlagTask(this);
- task->ctx = ssfe->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_GET_DEV_INFO:
- {
- pEvt->SetHandled();
- GetDevInfoEvent* gdie = dynamic_cast<GetDevInfoEvent*>(pEvt);
- GetDevInfoTask* task = new GetDevInfoTask(this);
- task->ctx = gdie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case USER_EVT_QUERY_CARD_INFO:
- {
- pEvt->SetHandled();
- QueryCardInfoEvent* qcie = dynamic_cast<QueryCardInfoEvent*>(pEvt);
- QueryCardInfoTask* task = new QueryCardInfoTask(this);
- task->ctx = qcie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- default:
- break;
- }
- return 0;
- }
- ErrorCodeEnum CCardReadAdapterFSM::OnInit()
- {
- LOG_FUNCTION();
- m_lastS2Event = m_lastS2EvtParam1 = 0;
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- return Error_Succeed;
- }
- ErrorCodeEnum CCardReadAdapterFSM::OnExit()
- {
- LOG_FUNCTION();
- FSMImpl<CCardReadAdapterFSM>::OnExit();
- return Error_Succeed;
- }
- int CCardReadAdapterFSM::Initial()
- {
- CheckSessionTask *pTask = new CheckSessionTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- ErrorCodeEnum eErr;
- eErr = GetEntityBase()->GetFunction()->SetSysVar("CardEntityState", "E");
- if (eErr != Error_Succeed)
- {
- Dbg("SetSysVar CardEntityState failed.%d",eErr);
- }
- return 0;//oiltmp no need to connect. let function "CheckAndReconnectSession" do
- }
- int CCardReadAdapterFSM::DoWork(int type)
- {
- switch (type)
- {
- case USER_EVT_READ:
- {
- }
- break;
- default:
- Dbg("unkown type:%d",type);
- break;
- }
- return 0;
- }
- int CCardReadAdapterFSM::CardIssuerRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (m_bCancelAccept || (m_busCtx.eCardFromWhich == Card_In_ContactlessCard || m_busCtx.eCardFromWhich == Card_In_CardSwiper))
- {
- char msg[128];
- memset(msg, 0, 128);
- sprintf(msg, "Maybe the thread pool is wrong.CardIssuerRead,bCancel:%d,cardpos:%d", m_bCancelAccept, m_busCtx.eCardFromWhich);
- LogWarn(Severity_Low, Error_NotInit, CardReadAdapter_UserErrorCode_MayBe_ThreadPool_Wrong, msg);
- return 3;
- }
- ErrorCodeEnum eErr = Error_Unexpect;
- if (IsTheEntity(ctx->Req.module,Module_CardIssuer) && IsCardIssuerSessionOK())
- {
- CardIssuerService_QueryCardInfo_Req qciReq;
- CardIssuerService_QueryCardInfo_Ans qciAns;
- bool bHasCard = false, bNeedPreOnline = false;
- DWORD dwUsrErrCode = 0;
- eErr = m_pCardIssuer->QueryCardInfo(qciReq, qciAns, 10000,dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- if (qciAns.position == 2)//有卡
- {
- Dbg("CardIssuer has card");
- bHasCard = true;
- bNeedPreOnline = true;//不知道卡片类型,默认
- m_busCtx.eCardFromWhich = Card_In_CardIssuer;
- if (IsContactlessCardSessionOK())
- m_pContactless->CancelInsert();
- }
- else
- {
- //oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
- //Desk2S 2.1 can insert into CardIssuer,so comment the following line
- //oilyang@20200426 if "RVC.Desk2S 2.1" ,call insert is forbidden
- //if (!(m_eMachineType == MachineType_RVC_DESK2S && m_majorVerion == 2 && m_minorVerion == 1))
- {
- CardIssuerService_Insert_Req req;
- CardIssuerService_Insert_Ans ans;
- req.aid = ctx->Req.aid;
- Dbg("to call cardissuer insert..");
- eErr = m_pCardIssuer->Insert(req, ans, 59000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- Dbg("Card insert into CardIssuer.");
- bHasCard = true;
- m_busCtx.eCardFromWhich = Card_In_CardIssuer;
- if (IsContactlessCardSessionOK())
- m_pContactless->CancelInsert();
- }
- else {
- Dbg("CardIssuer Insert return:%d", eErr);
- //oilyang@20200827 if time out, we must told front caller
- //AND set returned value of 0 to change FSM state
- if (eErr == Error_TimeOut)
- {
- return 7;
- }
- else
- return 1;//oilyang@20190709
- }
- }
- }
- if (bHasCard)
- {
- CardIssuerService_Read_Req reqR;
- CardIssuerService_Read_Ans ansR;
- reqR.aid = ctx->Req.aid;
- reqR.reserved1 = ctx->Req.lightPos;
- Dbg("to read ctx->Req.lightPos:%d", ctx->Req.lightPos);
- Sleep(100);//zjw@20190725 以防卡机状态还未跳转,这里就已经触发了Read操作
- eErr = m_pCardIssuer->Read(reqR, ansR, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.track1 = ansR.track1;
- ctx->Ans.track2 = ansR.track2;
- ctx->Ans.track3 = ansR.track3;
- ctx->Ans.ICType = ansR.ICType;
- ctx->Ans.ICCardNo = ansR.ICData;
- ctx->Ans.status = ansR.status;
- if (m_eMachineType == MachineType_RVC_Stand2S)
- ctx->Ans.cardPos = CardPos_CardIssuer_Stand2S;
- else
- ctx->Ans.cardPos = CardPos_CardIssuer_Split;
- ctx->Ans.t2Account = ansR.t2Account;
- ctx->Ans.t2Region = ansR.t2Region;
- ctx->Ans.t2CardSerial = ansR.t2CardSerial;
- ctx->Ans.t2CVC = ansR.t2CVC;
- ctx->Ans.t2ExpireDate = ansR.t2ExpireDate;
- if (ansR.ICType == 1 || ansR.ICType == 3)
- bNeedPreOnline = true;
- }
- }
- }
- else {
- Dbg("CardIssuer QueryCardInfo return:", eErr);
- return 1;//oilyang@20190709
- }
- if (bHasCard && bNeedPreOnline)
- {
- CardIssuerService_PreOnline_Req req;
- CardIssuerService_PreOnline_Ans ans;
- req.businessData = ctx->Req.businessData;
- BroadcastReadICing(0);
- Dbg("to preonline");
- eErr = m_pCardIssuer->PreOnline(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- ctx->Ans.status = 0;
- if (ctx->Ans.ICType == 1 || ctx->Ans.ICType == 3)
- {
- CardIssuerService_SetSomeFlag_Req ssfReq;
- CardIssuerService_SetSomeFlag_Ans ssfAns;
- ssfReq.IssueBusiness = 4;
- eErr = m_pCardIssuer->SetSomeFlag(ssfReq, ssfAns, 5000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- ctx->Ans.ICCardNo = ssfAns.reserved2[0];
- }
- }
- else
- {
- ctx->Ans.result = "";
- ctx->Ans.status = -1;
- }
-
-
- }
- if (bHasCard)
- {
- Dbg("%d", eErr);
- ctx->Answer(eErr, dwUsrErrCode);
- }
- return 0;
-
- }
- return 1;
- }
- int CCardReadAdapterFSM::ContactlessCardRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (m_bCancelAccept || (m_busCtx.eCardFromWhich == Card_In_CardIssuer || m_busCtx.eCardFromWhich == Card_In_CardSwiper))
- {
- char msg[128];
- memset(msg, 0, 128);
- sprintf(msg, "Maybe the thread pool is wrong.ContactlessCardRead,bCancel:%d,cardpos:%d", m_bCancelAccept, m_busCtx.eCardFromWhich);
- LogWarn(Severity_Low, Error_NotInit, CardReadAdapter_UserErrorCode_MayBe_ThreadPool_Wrong, msg);
- return 3;
- }
- ErrorCodeEnum eErr = Error_Unexpect;
- if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK())
- {
- bool bFindCard = false;
- //ContactlessCardService_QueryCardInfo_Req qciReq;
- //ContactlessCardService_QueryCardInfo_Ans qciAns;
- //eErr = m_pContactless->QueryCardInfo(qciReq, qciAns, 10000);
- //if (eErr == Error_Succeed)
- //{
- // if (qciAns.position == 4)//如果有卡,直接读卡
- // {
- // Dbg("find card on contactless card.");
- // m_busCtx.eCardFromWhich = Card_In_ContactlessCard;
- // m_pCardIssuer->CancelInsert();
- // bFindCard = true;
- // }
- // else
- // {
- ContactlessCardService_Insert_Req req;
- ContactlessCardService_Insert_Ans ans;
- req.aid = ctx->Req.aid;
- Dbg("to call contactless insert...");
- eErr = m_pContactless->Insert(req, ans, 56000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.track1 = ans.track1;
- ctx->Ans.track2 = ans.track2;
- ctx->Ans.track3 = ans.track3;
- ctx->Ans.ICType = ans.ICType;
- ctx->Ans.ICCardNo = ans.ICData;
- ctx->Ans.status = ans.status;
- ctx->Ans.cardPos = CardPos_ContactlessCard;
- ctx->Ans.t2Account = ans.t2Account;
- ctx->Ans.t2Region = ans.t2Region;
- ctx->Ans.t2CardSerial = ans.t2CardSerial;
- ctx->Ans.t2CVC = ans.t2CVC;
- ctx->Ans.t2ExpireDate = ans.t2ExpireDate;
- Dbg("Card in ContactlessCard.");
- m_busCtx.eCardFromWhich = Card_In_ContactlessCard;
- if (IsCardIssuerSessionOK())
- m_pCardIssuer->CancelInsert();
- if (ans.ICType == 4)
- {
- bFindCard = true;
- }
- }
- else if (eErr == Error_TimeOut)
- {
- Dbg("ContactlessCard timeout.");
- return 8;
- }
- else if (eErr == Error_Unexpect)
- {
- ctx->Answer(eErr);
- Dbg("read failed.");
- return 2;
- }
- // }
- //}
- if (bFindCard)
- {
- //oilyang@20210223 add,The Entity FSM is too late to change state ,as the call coming so fast
- Sleep(100);
- ContactlessCardService_PreOnline_Req req;
- ContactlessCardService_PreOnline_Ans ans;
- req.businessData = ctx->Req.businessData;
- BroadcastReadICing(0);
- eErr = m_pContactless->PreOnline(req, ans, 50000);
- Dbg("PreOnline result:%d", eErr);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- ctx->Ans.status = 0;
- }
- else
- {
- ctx->Ans.result = "";
- ctx->Ans.status = -1;
- }
- ctx->Answer(eErr);
- return 0;
- }
- //ctx->Answer(eErr);
- }
- return 1;
- }
- int CCardReadAdapterFSM::IssueCard(SpReqAnsContext<CardReadAdapterService_Issue_Req, CardReadAdapterService_Issue_Ans>::Pointer ctx)
- {
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_IssueEx_Req req;
- CardIssuerService_IssueEx_Ans ans;
- req.hopper = ctx->Req.hopper;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- DWORD dwUsrErrCode = 0;
- eErr = m_pCardIssuer->IssueEx(req, ans, 60000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- if (ans.reserved1.GetCount() > 0)
- ctx->Ans.reserved1.Copy(ans.reserved1);
- if (ans.reserved2.GetCount() > 0)
- ctx->Ans.reserved2.Copy(ans.reserved2);
- // --Josephus at 11:09:47 201747
- //oilyang@20180315 kaku
- //if(m_busCtx.eCardFromWhich == Card_In_No_Where)
- if (req.hopper == 99 || req.hopper == 98 || req.hopper == 89)
- {
- if (ans.reserved1[0] == 0 && ans.reserved1[1] == 0)
- m_busCtx.eCardFromWhich = Card_In_CardIssuer;
- }
- else if (req.hopper == 88 || req.hopper == 87)
- {
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- }
- else
- m_busCtx.eCardFromWhich = Card_In_CardIssuer;
- Dbg("req.hopper:%d Deem that CardIssuer has card after issuing succ. Set busCtx:findCard:%d,cardPos:%d"
- , req.hopper, ans.reserved1[0], ans.reserved1[1]);
- }
- ctx->Answer(eErr, dwUsrErrCode);
- return 0;
- }
- else
- {
- Dbg("issue card param error or connection is failed:(module)%d",ctx->Req.module);
- ctx->Answer(Error_Param);
- return 1;
- }
- }
- int CCardReadAdapterFSM::CardSwiperRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx,int &eRetErr)
- {
- if (m_bCancelAccept || (m_busCtx.eCardFromWhich == Card_In_CardIssuer || m_busCtx.eCardFromWhich == Card_In_ContactlessCard))
- {
- char msg[128];
- memset(msg, 0, 128);
- sprintf(msg, "Maybe the thread pool is wrong.CardSwiperRead,bCancel:%d,cardpos:%d", m_bCancelAccept, m_busCtx.eCardFromWhich);
- LogWarn(Severity_Low, Error_NotInit, CardReadAdapter_UserErrorCode_MayBe_ThreadPool_Wrong, msg);
- return 3;
- }
- ErrorCodeEnum eErr = Error_Unexpect;
- if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
- {
- CardSwiperService_Read_Req req;
- CardSwiperService_Read_Ans ans;
- req.aid = ctx->Req.aid;
- req.LightPos = 0;
- if (ctx->Req.lightPos == 0)
- req.LightPos = 7;
- if ((ctx->Req.lightPos&LightPos_CardSwiper_Mag) == LightPos_CardSwiper_Mag)
- req.LightPos += 1;
- if ((ctx->Req.lightPos&LightPos_CardSwiper_IC) == LightPos_CardSwiper_IC)
- req.LightPos += 2;
- if ((ctx->Req.lightPos&LightPos_CardSwiper_RFIC) == LightPos_CardSwiper_RFIC)
- req.LightPos += 4;
- Dbg("aid:%s,lightPos:%d",(const char*)req.aid,req.LightPos);
- eErr = m_pCardSwiper->Read(req, ans, 61000);
- Dbg("eErr:%d", eErr);
- eRetErr = eErr;
- if (eErr == Error_Succeed)
- {
- m_busCtx.eCardFromWhich = Card_In_CardSwiper;
- //oilyang@20180913 由于CardSwiper没有插卡过程,直接进行pboc流程,需要提前取消其他实体的输入
- if (IsCardIssuerSessionOK())
- m_pCardIssuer->CancelInsert();
- if (IsContactlessCardSessionOK())
- m_pContactless->CancelInsert();
- ctx->Ans.track1 = ans.track1;
- ctx->Ans.track2 = ans.track2;
- ctx->Ans.track3 = ans.track3;
- if (ans.ICType == 5)//oilyang@20170204 如果插错卡,反馈为未检测到(有效)卡
- ctx->Ans.ICType = 0;
- else if (ans.ICType == 6)//身份证
- ctx->Ans.ICType = 5;
- else
- ctx->Ans.ICType = ans.ICType;
- ctx->Ans.ICCardNo = ans.ICData;
- ctx->Ans.status = ans.status;
- if (ans.CardPos == 2 || ans.CardPos == 5)
- ctx->Ans.cardPos = CardPos_CardSwiper_IC_Insert;
- else if (ans.CardPos == 4 || ans.CardPos == 6)
- ctx->Ans.cardPos = CardPos_CardSwiper_RFIC;
- else
- ctx->Ans.cardPos = ans.CardPos;
- ctx->Ans.t2Account = ans.t2Account;
- ctx->Ans.t2Region = ans.t2Region;
- ctx->Ans.t2CardSerial = ans.t2CardSerial;
- ctx->Ans.t2CVC = ans.t2CVC;
- ctx->Ans.t2ExpireDate = ans.t2ExpireDate;
- Dbg("ICType:%d,%d,%s****%s", ctx->Ans.ICType, ans.ICType,(const char*)ctx->Ans.t2Account.SubString(0, 4), (const char*)ctx->Ans.t2Account.SubString(ctx->Ans.t2Account.GetLength() - 4, 4));
- if (ans.ICType == 3 || ans.ICType == 4)
- {
- CardSwiperService_PreOnline_Req req;
- CardSwiperService_PreOnline_Ans ans;
- req.businessData = ctx->Req.businessData;
- BroadcastReadICing(0);
- eErr = m_pCardSwiper->PreOnline(req, ans, 50000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- }
- else
- ctx->Ans.result = "";
- }
- }
- if (eErr == Error_TimeOut)
- {
- Dbg("CardSwiper timeout.");
- return 9;
- }
- else if (eErr == Error_InvalidState)
- {
- Dbg("CardSwiper in error state.");
- return 1;
- }
- else
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("can't find the corresponding Entity.req.Module:%d", ctx->Req.module);
- return 1;
- //ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- void CCardReadAdapterFSM::CancelRead()
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- if (IsCardIssuerSessionOK())
- {
- Dbg("CardIssuer read canceled by front user.");
- m_pCardIssuer->CancelInsert();
- }
- if (IsContactlessCardSessionOK())
- {
- Dbg("ContactlessCard read canceled by front user.");
- m_pContactless->CancelInsert();
- }
- if (IsCardSwiperSessionOK())
- {
- eErr = m_pCardSwiper->CancelInsert();
- Dbg("CardSwiper read canceled by front user.");
- }
- }
- void CCardReadAdapterFSM::ReadWaitMore()
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- if (IsCardIssuerSessionOK())
- {
- m_pCardIssuer->InsertWaitMore();
- }
- if (IsContactlessCardSessionOK())
- {
- m_pContactless->InsertWaitMore();
- }
- if (IsCardSwiperSessionOK())
- {
- m_pCardSwiper->InsertWaitMore();
- }
- }
- int CCardReadAdapterFSM::WriteTrack(SpReqAnsContext<CardReadAdapterService_WriteTrack_Req, CardReadAdapterService_WriteTrack_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- CardIssuerService_WriteTrack_Req req;
- CardIssuerService_WriteTrack_Ans ans;
- req.co = ctx->Req.co;
- req.mode = ctx->Req.mode;
- req.track1 = ctx->Req.track1;
- req.track2 = ctx->Req.track2;
- req.track3 = ctx->Req.track3;
- req.reserved = ctx->Req.reserved;
- ErrorCodeEnum eErr = Error_Unexpect;
- DWORD dwUsrErrCode = 0;
- eErr = m_pCardIssuer->WriteTrack(req, ans, 20000, dwUsrErrCode);
- if (eErr != Error_Succeed)
- {
- Dbg("WriteTrack failed.%d",eErr);
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else
- {
- ctx->Ans.result = ans.result;
- ctx->Ans.reserved1 = ans.reserved1;
- ctx->Ans.reserved2 = ans.reserved2;
- Dbg("Write tracks ok.");
- ctx->Answer(Error_Succeed);
- }
- }
- return 0;
- }
- int CCardReadAdapterFSM::PreOnline(SpReqAnsContext<CardReadAdapterService_PreOnline_Req, CardReadAdapterService_PreOnline_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum eErr = Error_Unexpect;
- DWORD dwUsrErrCode = 0;
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
- {
- CardIssuerService_PreOnline_Req req;
- CardIssuerService_PreOnline_Ans ans;
- req.businessData = ctx->Req.businessData;
- if (!ctx->Req.reserved2[0].IsNullOrEmpty())
- req.reserved1 = ctx->Req.reserved2[0];
- else
- req.reserved1 = "";
- if (!ctx->Req.reserved2[1].IsNullOrEmpty())
- req.reserved2 = ctx->Req.reserved2[1];
- else
- req.reserved2 = "";
- eErr = m_pCardIssuer->PreOnline(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
- {
- ContactlessCardService_PreOnline_Req req;
- ContactlessCardService_PreOnline_Ans ans;
- req.businessData = ctx->Req.businessData;
- //req.reserved1 = ctx->Req.reserved1;
- //req.reserved2 = ctx->Req.reserved2;
- eErr = m_pContactless->PreOnline(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
- {
- CardSwiperService_PreOnline_Req req;
- CardSwiperService_PreOnline_Ans ans;
- req.businessData = ctx->Req.businessData;
- //req.reserved1 = ctx->Req.reserved1;
- //req.reserved2 = ctx->Req.reserved2;
- eErr = m_pCardSwiper->PreOnline(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- return 0;
- }
- int CCardReadAdapterFSM::PostOnline(SpReqAnsContext<CardReadAdapterService_PostOnline_Req, CardReadAdapterService_PostOnline_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- Dbg("ctx->Req.module:%d,cardIn(Iss 1,RF 2):%d",ctx->Req.module, m_busCtx.eCardFromWhich);
- ErrorCodeEnum eErr = Error_Unexpect;
- DWORD dwUsrErrCode = 0;
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
- {
- CardIssuerService_PostOnline_Req req;
- CardIssuerService_PostOnline_Ans ans;
- req.data = ctx->Req.data;
- eErr = m_pCardIssuer->PostOnline(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
- {
- ContactlessCardService_PostOnline_Req req;
- ContactlessCardService_PostOnline_Ans ans;
- req.data = ctx->Req.data;
- eErr = m_pContactless->PostOnline(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
- {
- CardSwiperService_PostOnline_Req req;
- CardSwiperService_PostOnline_Ans ans;
- req.data = ctx->Req.data;
- eErr = m_pCardSwiper->PostOnline(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.result = ans.result;
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- return 0;
- }
- int CCardReadAdapterFSM::EjectCard(SpReqAnsContext<CardReadAdapterService_Eject_Req, CardReadAdapterService_Eject_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum eErr = Error_Unexpect;
- Dbg("before eject card,req.module %d,card in %d", ctx->Req.module,m_busCtx.eCardFromWhich);
- DWORD dwUsrErrCode = 0;
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
- {
- CardIssuerService_Eject_Req req;
- CardIssuerService_Eject_Ans ans;
- eErr = m_pCardIssuer->Eject(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- Dbg("CardIssuer EjectCard suc.");
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
- {
- ContactlessCardService_Eject_Req req;
- ContactlessCardService_Eject_Ans ans;
- eErr = m_pContactless->Eject(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- Dbg("ContactlessCard EjectCard suc.");
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
- {
- CardSwiperService_Eject_Req req;
- CardSwiperService_Eject_Ans ans;
- eErr = m_pCardSwiper->Eject(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- Dbg("CardSwiper EjectCard suc.");
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else
- {
- Dbg("nothing to do.");
- ctx->Answer(Error_NotExist);
- }
- return 0;
- }
- int CCardReadAdapterFSM::CaptureCard(SpReqAnsContext<CardReadAdapterService_Capture_Req, CardReadAdapterService_Capture_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum eErr = Error_Unexpect;
- DWORD dwUsrErrCode = 0;
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
- {
- CardIssuerService_Capture_Req req;
- CardIssuerService_Capture_Ans ans;
- eErr = m_pCardIssuer->Capture(req, ans, 15000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- Dbg("Capture card suc.");
- m_busCtx.eCardFromWhich = Card_In_No_Where;
- }
- ctx->Answer(eErr, dwUsrErrCode);
- }
- else
- {
- Dbg("Something wrong.the module(%d),cardinwhere(%d)", ctx->Req.module, m_busCtx.eCardFromWhich);
- ctx->Answer(eErr);
- }
- return 0;
- }
- int CCardReadAdapterFSM::QueryCardInfo(SpReqAnsContext<CardReadAdapterService_QueryCardInfo_Req, CardReadAdapterService_QueryCardInfo_Ans>::Pointer ctx)
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- DWORD dwUsrErrCode = 0;
- ctx->Ans.CardIssuerPos = ctx->Ans.ContactlessCardPos = ctx->Ans.CardSwiperPos = 0;
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
- {
- CardIssuerService_QueryCardInfo_Req req;
- CardIssuerService_QueryCardInfo_Ans ans;
- eErr = m_pCardIssuer->QueryCardInfo(req, ans, 10000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- switch (ans.position)
- {
- case 1:
- ctx->Ans.CardIssuerPos = -1;
- break;
- case 2:
- ctx->Ans.CardIssuerPos = 1;
- break;
- default:
- break;
- }
- }
- }
- if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
- {
- ContactlessCardService_QueryCardInfo_Req req;
- ContactlessCardService_QueryCardInfo_Ans ans;
- eErr = m_pContactless->QueryCardInfo(req, ans, 10000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- switch (ans.position)//oiltmp to add
- {
- case 2:
- break;
- case 3:
- break;
- case 4:
- ctx->Ans.ContactlessCardPos = 1;
- break;
- default:
- break;
- }
- }
- else
- ctx->Ans.ContactlessCardPos = -1;
- }
- if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
- {
- CardSwiperService_QueryCardInfo_Req req;
- CardSwiperService_QueryCardInfo_Ans ans;
- eErr = m_pCardSwiper->QueryCardInfo(req, ans, 10000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- switch (ans.position)
- {
- case 2:
- ctx->Ans.CardSwiperPos = 1;
- break;
- case 3:
- ctx->Ans.CardSwiperPos = 2;
- break;
- case 4:
- ctx->Ans.CardSwiperPos = 3;
- break;
- case 6:
- ctx->Ans.CardSwiperPos = 4;
- break;
- default:
- break;
- }
- }
- else
- ctx->Ans.CardSwiperPos = -1;
- }
- ctx->Answer(Error_Succeed);
- Dbg("%d,position(CI,CC,CS) %d,%d,%d", m_busCtx.eCardFromWhich, ctx->Ans.CardIssuerPos, ctx->Ans.ContactlessCardPos, ctx->Ans.CardSwiperPos);
- return 0;
- }
- void CCardReadAdapterFSM::CheckAndReconnectSession()
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- int cardIssuerCount = 0, contactlessCardCount = 0, cardSwiperCount = 0;
- while (1)
- {
- //the first time to connect or need to reconnect
- //CardIssuer
- if (!m_bRVCIL && (m_pCardIssuer == NULL || (m_pCardIssuer != NULL && m_pCardIssuer->QuerySessionClosed())))
- {
- if (m_pCardIssuer != NULL)
- {
- m_pCardIssuer->GetFunction()->CloseSession();
- m_pCardIssuer = NULL;
- }
- m_pCardIssuer = new CardIssuerService_ClientBase(GetEntityBase());
- if (m_pCardIssuer != NULL)
- {
- eErr = m_pCardIssuer->Connect();
- if (eErr != Error_Succeed)
- {
- if (cardIssuerCount%120 == 0)//about 10 minutes can't connect to entity
- Dbg("connect to entity CardIssuer failed.%d", eErr);
- cardIssuerCount++;
- m_pCardIssuer->SafeDelete();
- m_pCardIssuer = NULL;
- }
- else
- {
- cardIssuerCount = 0;
- Dbg("Connect to entity CardIssuer suc.");
- }
- }
- }
- //ContactlessCard
- if (!m_bRVCIL && (m_eMachineType != MachineType_RVC_PAD && m_eMachineType != MachineType_RVC_Wall && m_eMachineType != MachineType_RPM_Stand1S)
- && (m_pContactless == NULL || (m_pContactless != NULL && m_pContactless->QuerySessionClosed())))
- {
- if (m_pContactless != NULL)
- {
- m_pContactless->GetFunction()->CloseSession();
- m_pContactless = NULL;
- }
- m_pContactless = new ContactlessCardService_ClientBase(GetEntityBase());
- if (m_pContactless != NULL)
- {
- eErr = m_pContactless->Connect();
- if (eErr != Error_Succeed)
- {
- if (contactlessCardCount % 120 == 0)//about 10 minutes can't connect to entity
- Dbg("connect to entity ContactlessCard failed.%d", eErr);
- contactlessCardCount++;
- m_pContactless->SafeDelete();
- m_pContactless = NULL;
- }
- else
- {
- contactlessCardCount = 0;
- Dbg("Connect to entity ContactlessCard suc.");
- }
- }
- }
- //CardSwiper
- if (!m_bRVCIL && m_eMachineType != MachineType_RVC_Stand2S &&(m_pCardSwiper == NULL || (m_pCardSwiper != NULL && m_pCardSwiper->QuerySessionClosed())))
- {
- if (m_pCardSwiper != NULL)
- {
- m_pCardSwiper->GetFunction()->CloseSession();
- m_pCardSwiper = NULL;
- }
- m_pCardSwiper = new CardSwiperService_ClientBase(GetEntityBase());
- if (m_pCardSwiper != NULL)
- {
- eErr = m_pCardSwiper->Connect();
- if (eErr != Error_Succeed)
- {
- if (cardSwiperCount%120 == 0)//about 10 minutes can't connect to entity
- Dbg("connect to entity CardSwiper failed.%d", eErr);
- cardSwiperCount++;
- m_pCardSwiper->SafeDelete();
- m_pCardSwiper = NULL;
- }
- else
- {
- cardSwiperCount = 0;
- Dbg("Connect to entity CardSwiper suc.");
- //CUUID uuidCSMsg;
- //GetEntityBase()->GetFunction()->SubscribeBroadcast("CardSwiper", "", (IBroadcastListener*)m_pEty, uuidCSMsg);
- }
- }
- }
- Sleep(5000);
- }
- }
- bool CCardReadAdapterFSM::IsCardIssuerSessionOK()
- {
- if (m_pCardIssuer != NULL && !m_pCardIssuer->QuerySessionClosed())
- return true;
- return false;
- }
- bool CCardReadAdapterFSM::IsContactlessCardSessionOK()
- {
- if (m_pContactless != NULL && !m_pContactless->QuerySessionClosed())
- return true;
- return false;
- }
- bool CCardReadAdapterFSM::IsCardSwiperSessionOK()
- {
- if (m_pCardSwiper != NULL && !m_pCardSwiper->QuerySessionClosed())
- return true;
- return false;
- }
- bool CCardReadAdapterFSM::IsTheEntity(int module,ModuleType eModule)
- {
- if (module == 0)
- return true;
- //oilyang@20180409 add req.module==99
- else if (module == 99)
- {
- Dbg("req.module is 99,machineType is:%s",(const char*)m_csMachineType);
- //oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
- //Desk2S 2.1 can insert into CardIssuer
- //oilyang@20200612 if "RVC.Desk2S" ,no need to call CardIssuer(insert card)
- //from guodan 20180905
- //99:进卡读卡,功能集向除蓝牙发卡机之外的读卡实体发出进卡读卡指令。
-
- if (eModule == Module_CardIssuer)
- {
- if (m_eMachineType == MachineType_RVC_Stand2S
- || m_eMachineType == MachineType_RVC_CardStore
- || m_eMachineType == MachineType_RVC_CardPrinter
- || m_eMachineType == MachineType_RVC_DESK1S
- || m_eMachineType == MachineType_RVC_DESK2S && m_majorVerion == 2 && m_minorVerion == 1)
- return true;
- else
- return false;
- }
- else
- return true;
- }
- else if ((module&eModule) == eModule)
- return true;
- else
- return false;
- }
- int CCardReadAdapterFSM::SetSomeFlag(SpReqAnsContext<CardReadAdapterService_SetSomeFlag_Req, CardReadAdapterService_SetSomeFlag_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- CardIssuerService_SetSomeFlag_Req req;
- CardIssuerService_SetSomeFlag_Ans ans;
- req.IssueBusiness = ctx->Req.IssueBusiness;
- req.reserved1.Init(ctx->Req.reserved1.GetCount());
- for (int i = 0; i < ctx->Req.reserved1.GetCount(); ++i)
- {
- req.reserved1[i] = ctx->Req.reserved1[i];
- }
- ErrorCodeEnum eErr = m_pCardIssuer->SetSomeFlag(req, ans,10000);
- Dbg("CardIssuer SetSomeFlag ret:%d",eErr);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Answer(Error_Succeed);
- }
- else
- ctx->Answer(Error_Unexpect);
- }
- else
- {
- Dbg("SetSomeFlag can only apply to CardIssuer.Or CardIssuer connected failed.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::GetDevInfo(SpReqAnsContext<CardReadAdapterService_GetDevInfo_Req, CardReadAdapterService_GetDevInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- CSimpleStringA csCIType(""), csCIModel(""), csCIVersion(""), csCCType(""), csCCModel(""), csCCVersion(""), csCSType(""), csCSModel(""), csCSVersion("");
- int ciState, ccState, csState;
- bool bCI(false), bCC(false), bCS(false);
- ErrorCodeEnum eErr = Error_Unexpect;
- int count = 0;
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
- {
- CardIssuerService_GetDevInfo_Req req;
- CardIssuerService_GetDevInfo_Ans ans;
- eErr = m_pCardIssuer->GetDevInfo(req, ans, 10000);
- if (eErr == Error_Succeed)
- {
- bCI = true;
- count++;
- csCIType = ans.type;
- csCIModel = ans.model;
- csCIVersion = ans.version;
- ciState = ans.state;
- }
- }
- if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK())
- {
- ContactlessCardService_GetDevInfo_Req req;
- ContactlessCardService_GetDevInfo_Ans ans;
- eErr = m_pContactless->GetDevInfo(req, ans, 10000);
- if (eErr == Error_Succeed)
- {
- bCC = true;
- count++;
- csCCType = ans.type;
- csCCModel = ans.model;
- csCCVersion = ans.version;
- ccState = ans.state;
- }
- }
- if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
- {
- CardSwiperService_GetDevInfo_Req req;
- CardSwiperService_GetDevInfo_Ans ans;
- eErr = m_pCardSwiper->GetDevInfo(req, ans, 10000);
- if (eErr == Error_Succeed)
- {
- bCS = true;
- count++;
- csCSType = ans.type;
- csCSModel = ans.model;
- csCSVersion = ans.version;
- csState = ans.state;
- }
- }
- ctx->Ans.ModuleNum = count;
- ctx->Ans.ModuleSN.Init(count);
- ctx->Ans.type.Init(count);
- ctx->Ans.model.Init(count);
- ctx->Ans.version.Init(count);
- ctx->Ans.state.Init(count);
- int index = 0;
- Dbg("count:%d,index:%d,%d,%d,%d",count,index,bCI,bCC,bCS);
- if (bCI)
- {
- ctx->Ans.ModuleSN[index] = Module_CardIssuer;
- ctx->Ans.type[index] = csCIType;
- ctx->Ans.model[index] = csCIModel;
- ctx->Ans.version[index] = csCIVersion;
- ctx->Ans.state[index] = ciState;
- Dbg("CardIssuer,type:%s,model:%s,version:%s,state:%d", (const char*)csCIType, (const char*)csCIModel
- , (const char*)csCIVersion, ciState);
- index++;
- }
- if (bCC)
- {
- ctx->Ans.ModuleSN[index] = Module_ContactlessCard;
- ctx->Ans.type[index] = csCCType;
- ctx->Ans.model[index] = csCCModel;
- ctx->Ans.version[index] = csCCVersion;
- ctx->Ans.state[index] = ccState;
- Dbg("ContactlessCard,type:%s,model:%s,version:%s,state:%d", (const char*)csCCType, (const char*)csCCModel
- , (const char*)csCCVersion, ccState);
- index++;
- }
- if (bCS)
- {
- ctx->Ans.ModuleSN[index] = Module_CardSwiper;
- ctx->Ans.type[index] = csCSType;
- ctx->Ans.model[index] = csCSModel;
- ctx->Ans.version[index] = csCSVersion;
- ctx->Ans.state[index] = csState;
- Dbg("CardSwiper,type:%s,model:%s,version:%s,state:%d", (const char*)csCSType, (const char*)csCSModel
- , (const char*)csCSVersion, csState);
- index++;
- }
- ctx->Answer(Error_Succeed);
- return 0;
- }
- int CCardReadAdapterFSM::GetMaterialCount(SpReqAnsContext<CardReadAdapterService_GetMaterialCount_Req, CardReadAdapterService_GetMaterialCount_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- DWORD dwUsrErrCode = 0;
- if (IsCardIssuerSessionOK())
- {
- CardIssuerService_GetMaterialCountEx_Req req;
- CardIssuerService_GetMaterialCountEx_Ans ans;
- req.GetHopper.Copy(ctx->Req.GetHopper);
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- ErrorCodeEnum eErr = m_pCardIssuer->GetMaterialCountEx(req, ans, 10000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.captured = ans.captured;
- ctx->Ans.hasHopper.Copy(ans.hasHopper);
- ctx->Ans.CardBoxNo.Copy(ans.CardBoxNo);
- ctx->Ans.PsbCode.Copy(ans.PsbCode);
- ctx->Ans.PsbName.Copy(ans.PsbName);
- ctx->Ans.Maintainer.Copy(ans.Maintainer);
- ctx->Ans.CardInit.Copy(ans.CardInit);
- ctx->Ans.CardPercent.Copy(ans.CardPercent);
- ctx->Ans.remains.Copy(ans.remains);
- ctx->Ans.issued.Copy(ans.issued);
- ctx->Ans.mixed.Copy(ans.mixed);
- ctx->Ans.MaintainTime.Copy(ans.MaintainTime);
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Answer(Error_Succeed);
- }
- else
- ctx->Answer(Error_Unexpect, dwUsrErrCode);
- }
- else
- {
- Dbg("GetMaterialCountEx can only apply to CardIssuer.Or CardIssuer connected failed.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::SetMaterialCount(SpReqAnsContext<CardReadAdapterService_SetMaterialCount_Req, CardReadAdapterService_SetMaterialCount_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- DWORD dwUsrErrCode = 0;
- if (IsCardIssuerSessionOK())
- {
- CardIssuerService_SetMaterialCountEx_Req req;
- CardIssuerService_SetMaterialCountEx_Ans ans;
- req.SetCaptured = ctx->Req.SetCaptured;
- req.captured = ctx->Req.captured;
- req.SetHopper.Copy(ctx->Req.SetHopper);
- req.CardBoxNo.Copy(ctx->Req.CardBoxNo);
- req.PsbCode.Copy(ctx->Req.PsbCode);
- req.PsbName.Copy(ctx->Req.PsbName);
- req.Maintainer.Copy(ctx->Req.Maintainer);
- req.MaintainTime.Copy(ctx->Req.MaintainTime);
- req.CardInit.Copy(ctx->Req.CardInit);
- req.CardPercent.Copy(ctx->Req.CardPercent);
- req.remains.Copy(ctx->Req.remains);
- req.issued.Copy(ctx->Req.issued);
- req.mixed.Copy(ctx->Req.mixed);
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- ErrorCodeEnum eErr = m_pCardIssuer->SetMaterialCountEx(req, ans, 10000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Answer(Error_Succeed);
- }
- else
- ctx->Answer(Error_Unexpect, dwUsrErrCode);
- }
- else
- {
- Dbg("SetMaterialCountEx can only apply to CardIssuer.Or CardIssuer connected failed.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::GetSCIInfo(SpReqAnsContext<CardReadAdapterService_GetSCIInfo_Req, CardReadAdapterService_GetSCIInfo_Ans>::Pointer ctx)
- {
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_GetSCIInfo_Req req;
- CardIssuerService_GetSCIInfo_Ans ans;
- eErr = m_pCardIssuer->GetSCIInfo(req, ans, 15000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.connected = ans.connected;
- ctx->Ans.DevSN = ans.DevSN;
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardIssuer is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::OpenSafeLock(SpReqAnsContext<CardReadAdapterService_OpenSafeLock_Req, CardReadAdapterService_OpenSafeLock_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_OpenSafeLock_Req req;
- CardIssuerService_OpenSafeLock_Ans ans;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- eErr = m_pCardIssuer->OpenSafeLock(req, ans, 15000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardIssuer is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::MagTransferInit(SpReqAnsContext<CardReadAdapterService_MagTransferInit_Req, CardReadAdapterService_MagTransferInit_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardSwiperSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardSwiperService_MagTransferInit_Req req;
- CardSwiperService_MagTransferInit_Ans ans;
- req.data = ctx->Req.data;
- eErr = m_pCardSwiper->MagTransferInit(req, ans, 15000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.ex = ans.ex;
- ctx->Ans.result = ans.result;
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardSwiper is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::QueryConnInfo(SpReqAnsContext<CardReadAdapterService_QueryConnInfo_Req, CardReadAdapterService_QueryConnInfo_Ans>::Pointer ctx)
- {
- if (IsCardSwiperSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardSwiperService_QueryConnInfo_Req req;
- CardSwiperService_QueryConnInfo_Ans ans;
- eErr = m_pCardSwiper->QueryConnInfo(req, ans, 15000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.connect = ans.connect;
- ctx->Ans.reserved1 = ans.reserved1;
- ctx->Ans.reserved2 = ans.reserved2;
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardSwiper is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- void CCardReadAdapterFSM::DoExit()
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- if (IsCardIssuerSessionOK())
- {
- eErr = m_pCardIssuer->Exit();
- }
- if (IsContactlessCardSessionOK())
- {
- eErr = m_pContactless->Exit();
- }
- if (IsCardSwiperSessionOK())
- {
- eErr = m_pCardSwiper->Exit();
- }
- }
- void CCardReadAdapterFSM::BroadcastReadICing(int status)
- {
- ReadICing evt;
- evt.status = status;
- SpSendBroadcast(GetEntityBase()->GetFunction(), SP_MSG_OF(ReadICing), SP_MSG_SIG_OF(ReadICing), evt);
- }
- int CCardReadAdapterFSM::SAMICCommand(SpReqAnsContext<CardReadAdapterService_SAMICCommand_Req, CardReadAdapterService_SAMICCommand_Ans>::Pointer ctx)
- {
- if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_SAMICCommand_Req req;
- CardIssuerService_SAMICCommand_Ans ans;
- req.cmdType = ctx->Req.cmdType;
- req.param1.Copy(ctx->Req.param1);
- req.param2.Copy(ctx->Req.param2);
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- eErr = m_pCardIssuer->SAMICCommand(req, ans, 50000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.ret1.Copy(ans.ret1);
- ctx->Ans.ret2.Copy(ans.ret2);
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- }
- ctx->Answer(eErr);
- return 0;
- }
- else
- {
- Dbg("SAMICCommand param error or connection is failed:(module)%d", ctx->Req.module);
- ctx->Answer(Error_Param);
- return 1;
- }
- }
- int CCardReadAdapterFSM::QueryPrinterStatus(SpReqAnsContext<CardReadAdapterService_QueryPrinterStatus_Req, CardReadAdapterService_QueryPrinterStatus_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_QueryPrinterStatus_Req req;
- CardIssuerService_QueryPrinterStatus_Ans ans;
- req.param1.Copy(ctx->Req.param1);
- req.param2.Copy(ctx->Req.param2);
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- eErr = m_pCardIssuer->QueryPrinterStatus(req, ans, 20000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.ret1.Copy(ans.ret1);
- ctx->Ans.ret2.Copy(ans.ret2);
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- }
- ctx->Answer(eErr);
- return 0;
- }
- else
- {
- Dbg("CardIssuer session is not ok.");
- ctx->Answer(Error_Param);
- return 1;
- }
- }
- int CCardReadAdapterFSM::Print(SpReqAnsContext<CardReadAdapterService_Print_Req, CardReadAdapterService_Print_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_Print_Req req;
- CardIssuerService_Print_Ans ans;
- req.data1 = ctx->Req.data1;
- req.data2 = ctx->Req.data2;
- req.data3 = ctx->Req.data3;
- req.data4 = ctx->Req.data4;
- req.data5 = ctx->Req.data5;
- req.data6 = ctx->Req.data6;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- eErr = m_pCardIssuer->Print(req, ans, 50000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- }
- ctx->Answer(eErr);
- return 0;
- }
- else
- {
- Dbg("CardIssuer session is not ok.");
- ctx->Answer(Error_Param);
- return 1;
- }
- }
- int CCardReadAdapterFSM::QuerySCIList(SpReqAnsContext<CardReadAdapterService_QuerySCIList_Req, CardReadAdapterService_QuerySCIList_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- DWORD dwUsrErrCode = 0;
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_QuerySCIList_Req req;
- CardIssuerService_QuerySCIList_Ans ans;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- eErr = m_pCardIssuer->QuerySCIList(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.sciNo.Copy(ans.sciNo);
- ctx->Ans.arrMateriel.Copy(ans.arrMateriel);
- ctx->Ans.CardGroove.Copy(ans.CardGroove);
- ctx->Ans.CardBoxNo.Copy(ans.CardBoxNo);
- ctx->Ans.PsbCode.Copy(ans.PsbCode);
- ctx->Ans.PsbName.Copy(ans.PsbName);
- ctx->Ans.CardInit.Copy(ans.CardInit);
- ctx->Ans.CardRemains.Copy(ans.CardRemains);
- ctx->Ans.CardIssued.Copy(ans.CardIssued);
- ctx->Ans.CardMixed.Copy(ans.CardMixed);
- ctx->Ans.CardPercent.Copy(ans.CardPercent);
- ctx->Ans.Maintainer.Copy(ans.Maintainer);
- ctx->Ans.MaintainTime.Copy(ans.MaintainTime);
- ctx->Ans.UpdateTime.Copy(ans.UpdateTime);
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- }
- ctx->Answer(eErr, dwUsrErrCode);
- return 0;
- }
- else
- {
- Dbg("CardIssuer session is not ok.");
- ctx->Answer(Error_Param);
- return 1;
- }
- }
- int CCardReadAdapterFSM::BindSCI(SpReqAnsContext<CardReadAdapterService_BindSCI_Req, CardReadAdapterService_BindSCI_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- DWORD dwUsrErrCode = 0;
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_BindSCI_Req req;
- CardIssuerService_BindSCI_Ans ans;
- req.type = ctx->Req.type;
- req.sciNo = ctx->Req.sciNo;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- eErr = m_pCardIssuer->BindSCI(req, ans, 50000, dwUsrErrCode);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- }
- ctx->Answer(eErr, dwUsrErrCode);
- return 0;
- }
- else
- {
- Dbg("CardIssuer session is not ok.");
- ctx->Answer(Error_Param);
- return 1;
- }
- }
- int CCardReadAdapterFSM::PreOnlineOnStore(SpReqAnsContext<CardReadAdapterService_PreOnlineOnStore_Req, CardReadAdapterService_PreOnlineOnStore_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_PreOnlineOnStore_Req req;
- CardIssuerService_PreOnlineOnStore_Ans ans;
- req.account = ctx->Req.account;
- req.businessData = ctx->Req.businessData;
- req.slot = ctx->Req.slot;
- req.termNo = ctx->Req.termNo;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- req.reserved3.Copy(ctx->Req.reserved3);
- req.reserved4.Copy(ctx->Req.reserved4);
- eErr = m_pCardIssuer->PreOnlineOnStore(req, ans, 63000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.cardPos = ans.cardPos;
- ctx->Ans.findCard = ans.findCard;
- ctx->Ans.result = ans.result;
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Ans.reserved3.Copy(ans.reserved3);
- ctx->Ans.reserved4.Copy(ans.reserved4);
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardIssuer is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::NotifyPreonline(SpReqAnsContext<CardReadAdapterService_NotifyPreonline_Req, CardReadAdapterService_NotifyPreonline_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_NotifyPreonline_Req req;
- CardIssuerService_NotifyPreonline_Ans ans;
- req.account = ctx->Req.account;
- req.cardPos = ctx->Req.cardPos;
- req.data = ctx->Req.data;
- req.errCode = ctx->Req.errCode;
- req.findCard = ctx->Req.findCard;
- req.termNo = ctx->Req.termNo;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- req.reserved3.Copy(ctx->Req.reserved3);
- req.reserved4.Copy(ctx->Req.reserved4);
- eErr = m_pCardIssuer->NotifyPreonline(req, ans, 100000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Ans.reserved3.Copy(ans.reserved3);
- ctx->Ans.reserved4.Copy(ans.reserved4);
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardIssuer is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::QueryCardInfoOnStore(SpReqAnsContext<CardReadAdapterService_QueryCardInfoOnStore_Req, CardReadAdapterService_QueryCardInfoOnStore_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_QueryCardInfoOnStore_Req req;
- CardIssuerService_QueryCardInfoOnStore_Ans ans;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- req.reserved3.Copy(ctx->Req.reserved3);
- req.reserved4.Copy(ctx->Req.reserved4);
- eErr = m_pCardIssuer->QueryCardInfoOnStore(req, ans, INT_MAX / 2 - 5000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.cardPos = ans.cardPos;
- ctx->Ans.findCard = ans.findCard;
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Ans.reserved3.Copy(ans.reserved3);
- ctx->Ans.reserved4.Copy(ans.reserved4);
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardIssuer is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::GetAddCardInfo(SpReqAnsContext<CardReadAdapterService_GetAddCardInfo_Req, CardReadAdapterService_GetAddCardInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_GetAddCardInfo_Req req;
- CardIssuerService_GetAddCardInfo_Ans ans;
- req.isSync = ctx->Req.isSync;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- req.reserved3.Copy(ctx->Req.reserved3);
- req.reserved4.Copy(ctx->Req.reserved4);
- eErr = m_pCardIssuer->GetAddCardInfo(req, ans, 10000);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.account = ans.account;
- ctx->Ans.cardSerial = ans.cardSerial;
- ctx->Ans.count = ans.count;
- ctx->Ans.slot = ans.slot;
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Ans.reserved3.Copy(ans.reserved3);
- ctx->Ans.reserved4.Copy(ans.reserved4);
- }
- ctx->Answer(eErr);
- }
- else
- {
- Dbg("Entity CardIssuer is not ok.");
- ctx->Answer(Error_Unexpect);
- }
- return 0;
- }
- int CCardReadAdapterFSM::Test1(SpReqAnsContext<CardReadAdapterService_Test1_Req, CardReadAdapterService_Test1_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ctx->Answer(Error_Succeed);
- return 0;
- }
- int CCardReadAdapterFSM::Test2(SpReqAnsContext<CardReadAdapterService_Test2_Req, CardReadAdapterService_Test2_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ctx->Answer(Error_Succeed);
- return 0;
- }
- void CCardReadAdapterFSM::SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- //for simple
- pTransactionContext->SendAnswer(m_testResult);
- }
- int CCardReadAdapterFSM::CrossTermCall(SpReqAnsContext<CardReadAdapterService_CrossTermCall_Req, CardReadAdapterService_CrossTermCall_Ans>::Pointer cctx)
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- Dbg("CrossTermCall,type:%x", cctx->Req.type);
- switch (cctx->Req.type)
- {
- case CardReadAdapterService_Method_Read:
- {
- int retErr;
- DEFINE_PUPPET_CONTEXT_WITH_TYPE(CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans);
- if ((eErr = SpBlob2Object(cctx->Req.paramX, ctx->Req)) == Error_Succeed) {
- if (this->CardSwiperRead(ctx, retErr) != 0) {
- eErr = Error_Unexpect;
- }
- else {
- eErr = SpObject2Blob(ctx->Ans, cctx->Ans.retParamX);
- Dbg("after CardSwiperRead,eErr:%d,retErr:%x,paramX.len:%d", eErr, retErr, cctx->Ans.retParamX.m_iLength);
- }
- }
- cctx->Answer((ErrorCodeEnum)retErr);
- }
- break;
- case CardReadAdapterService_Method_CancelRead:
- m_bCancelAccept = true;
- CancelRead();
- break;
- case CardReadAdapterService_Method_ReadWaitMore:
- {
- ReadWaitMoreTask* task = new ReadWaitMoreTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- break;
- case CardReadAdapterService_Method_Exit:
- DoExit();
- break;
- default:
- break;
- }
- return 0;
- }
- void CCardReadAdapterFSM::CrossTermInvokeInfo(SpOnewayCallContext<CardReadAdapterService_CrossTermInvokeInfo_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- Dbg("entity sn:%x,type:%d,errcode:%x", ctx->Info.nEntityID, ctx->Info.type, ctx->Info.result);
- if (ctx->Info.paramX.m_iLength <= 1)
- {
- }
- ErrorCodeEnum eErr = Error_Succeed;
- CSmartPointer<ITransactionContext> pTransactionContext;
- switch (ctx->Info.type)
- {
- case CardReadAdapterService_Method_Read:
- {
- auto pt = static_cast<SpReqAnsContext<CardReadAdapterService_Read_Req,
- CardReadAdapterService_Read_Ans>*>(GetCtx(ctx->Info.type));
- SpReqAnsContext<CardReadAdapterService_Read_Req,
- CardReadAdapterService_Read_Ans>::Pointer xctx;
- xctx.Attach(pt);
- if (ctx->Info.paramX.m_iLength > 0)
- eErr = SpBlob2Object(ctx->Info.paramX, xctx->Ans);
- Dbg("eErr:%d,Y len:%d", eErr, ctx->Info.paramX.m_iLength);
- xctx->Answer((ErrorCodeEnum)ctx->Info.result);
- }
- break;
- default:
- break;
- }
- }
- int CCardReadAdapterFSM::LocalCallHeartBeat(int method, CBlob &bbSend,bool bTwoWay)
- {
- Dbg("method id(type):%d", method);
- HeartBeatService_ClientBase* pClient = new HeartBeatService_ClientBase(GetEntityBase());
- if (pClient == NULL)
- {
- Dbg("create HeartBeat client failed.GetLastError:%d", GetLastError());
- return -1;
- }
- ErrorCodeEnum eErr = Error_Unexpect;
- eErr = pClient->Connect();
- if (eErr != Error_Succeed)
- {
- Dbg("client connect to HeartBeat failed:%x", eErr);
- return -1;
- }
- HeartBeatService_CrossTermCall_Req req;
- HeartBeatService_CrossTermCall_Ans ans;
- req.nEntityID = 0x21b;
- req.isTwoWay = bTwoWay;
- req.fromTerminalNo = m_terminalNo;
- GetAttachedTerminal(req.toTerminalNo);
- //req.toTerminalNo = "7717715004";
- req.param1 = "";
- req.param2 = "";
- req.paramX = bbSend;
- req.type = method;
- eErr = pClient->CrossTermCall(req, ans, 20000);
- Dbg("CrossTermCall to HeartBeat from %s to %s, result:%x", (const char*)req.fromTerminalNo, (const char*)req.toTerminalNo, eErr);
- return 0;
- }
- bool CCardReadAdapterFSM::GetAttachedTerminal(CSimpleStringA &csTerm)
- {
- return GetEntityBase()->GetFunction()->GetSysVar("AttachedTerminal", csTerm);
- }
- void CCardReadAdapterFSM::CancelReadForEntity(ModuleType eModule)
- {
- LOG_FUNCTION();
- if (IsTheEntity(eModule, Module_CardIssuer) && IsCardIssuerSessionOK())
- {
- Dbg("Set cancel read by ContactlessCard flag of CardIssuer.");
- CardIssuerService_SetSomeFlag_Req req;
- CardIssuerService_SetSomeFlag_Ans ans;
- req.IssueBusiness = 3;
- m_pCardIssuer->SetSomeFlag(req,ans,5000);
- m_pCardIssuer->CancelInsert();
- }
- if (IsTheEntity(eModule, Module_ContactlessCard) && IsContactlessCardSessionOK())
- {
- Dbg("Cancel read by CardSwiper of ContactlessCard.");
- ContactlessCardService_CancelInsert_Info info;
- m_pContactless->CancelInsert();
- }
- }
- int CCardReadAdapterFSM::PrintCardIm(SpReqAnsContext<CardReadAdapterService_PrintCardImmediately_Req, CardReadAdapterService_PrintCardImmediately_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (IsCardIssuerSessionOK())
- {
- ErrorCodeEnum eErr = Error_Unexpect;
- CardIssuerService_PrintCardImmediately_Req req;
- CardIssuerService_PrintCardImmediately_Ans ans;
- req.formFile = ctx->Req.formFile;
- req.printData = ctx->Req.printData;
- req.reserved1.Copy(ctx->Req.reserved1);
- req.reserved2.Copy(ctx->Req.reserved2);
- req.reserved3.Copy(ctx->Req.reserved3);
- req.reserved4.Copy(ctx->Req.reserved4);
- int timeout = 60000;
- if (ctx->Req.reserved1.GetCount() > 0 && ctx->Req.reserved1[0] > 50000 && ctx->Req.reserved1[0] < 200000)
- timeout = ctx->Req.reserved1[0];
- Dbg("timeout:%d",timeout);
- eErr = m_pCardIssuer->PrintCardImmediately(req, ans, timeout);
- if (eErr == Error_Succeed)
- {
- ctx->Ans.ret = ans.ret;
- ctx->Ans.reserved1.Copy(ans.reserved1);
- ctx->Ans.reserved2.Copy(ans.reserved2);
- ctx->Ans.reserved3.Copy(ans.reserved3);
- ctx->Ans.reserved4.Copy(ans.reserved4);
- }
- ctx->Answer(eErr);
- return 0;
- }
- else
- {
- Dbg("CardIssuer session is not ok.");
- ctx->Answer(Error_Param);
- return 1;
- }
- }
|