1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245 |
- #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.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;
- //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)", pEvt->iEvt);
- 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
- // --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_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.");
- 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:
- {
- 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;
- 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;
- }
- 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:
- {
- 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:
- pEvt->SetHandled();
- break;
- default:
- break;
- }
- return ret;
- }
- //Failed
- void CCardReadAdapterFSM::s4_on_entry()
- {
- LOG_FUNCTION();
- 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_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();
- 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();
- 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;
- }
- }
- // }
- //}
- if (bFindCard)
- {
- 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)
- {
- 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_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->SafeDelete();
- 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->SafeDelete();
- 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->SafeDelete();
- 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_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.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 = 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 = 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 = 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);
- }
- if (IsTheEntity(eModule, Module_ContactlessCard) && IsContactlessCardSessionOK())
- {
- Dbg("Cancel read by CardSwiper of ContactlessCard.");
- ContactlessCardService_CancelInsert_Info info;
- m_pContactless->CancelInsert();
- }
- }
|