CardReadAdapterFSM.cpp 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "SpHelper.h"
  4. #include "CardReadAdapterFSM.h"
  5. #include "GetDevInfoHelper.h"
  6. #include "EventCode.h"
  7. #include "ModuleMix.h"
  8. #include <algorithm>
  9. #include <map>
  10. using namespace std;
  11. //CSimpleStringA<T> ambigulous
  12. #define _ATL_NO_AUTOMATIC_NAMESPACE
  13. //#include <atltime.h>
  14. class CCardReadAdapterEntity;
  15. void CCardReadAdapterFSM::s0_on_entry()
  16. {
  17. LOG_FUNCTION();
  18. CSystemStaticInfo sysInfo;
  19. m_csMachineType = m_csSite = m_terminalNo = "";
  20. GetEntityBase()->GetFunction()->GetSystemStaticInfo(sysInfo);
  21. m_csMachineType = sysInfo.strMachineType;
  22. m_csSite = sysInfo.strSite;
  23. m_terminalNo = sysInfo.strTerminalID;
  24. m_majorVerion = sysInfo.MachineVersion.GetMajor();
  25. m_minorVerion = sysInfo.MachineVersion.GetMinor();
  26. Dbg("machineType:%s,site:%s,terminalNo:%s,machineVersion:%d.%d", (const char*)m_csMachineType, (const char*)m_csSite, (const char*)m_terminalNo
  27. , m_majorVerion, m_minorVerion);
  28. m_eMachineType = MachineType_Unknown;
  29. if (_strnicmp((const char*)m_csMachineType, "RVC.Stand2S", strlen("RVC.Stand2S")) == 0)
  30. m_eMachineType = MachineType_RVC_Stand2S;
  31. else if (_strnicmp((const char*)m_csMachineType, "RVC.PAD", strlen("RVC.PAD")) == 0)
  32. m_eMachineType = MachineType_RVC_PAD;
  33. else if (_strnicmp((const char*)m_csMachineType, "RVC.Wall", strlen("RVC.Wall")) == 0)
  34. m_eMachineType = MachineType_RVC_Wall;
  35. // --Josephus at 8:17:02 201741
  36. else if (_strnicmp((const char*)m_csMachineType, "RPM.Stand1S", strlen("RPM.Stand1S")) == 0)
  37. m_eMachineType = MachineType_RPM_Stand1S;
  38. else if (_strnicmp((const char*)m_csMachineType, "RVC.CardStore", strlen("RVC.CardStore")) == 0)
  39. m_eMachineType = MachineType_RVC_CardStore;
  40. else if (_strnicmp((const char*)m_csMachineType, "RVC.Desk2S", strlen("RVC.Desk2S")) == 0)
  41. m_eMachineType = MachineType_RVC_DESK2S;
  42. else if (_strnicmp((const char*)m_csMachineType, "RVC.Desk1S", strlen("RVC.Desk1S")) == 0)
  43. m_eMachineType = MachineType_RVC_DESK1S;
  44. else if (_strnicmp((const char*)m_csMachineType, "RVC.IL", strlen("RVC.IL")) == 0)
  45. {
  46. m_bRVCIL = true;
  47. m_eMachineType = MachineType_RVC_IL;
  48. }
  49. FSMEvent *pEvt;
  50. pEvt = new FSMEvent(USER_EVT_INIT);
  51. PostEventFIFO(pEvt);
  52. }
  53. void CCardReadAdapterFSM::s0_on_exit()
  54. {
  55. LOG_FUNCTION();
  56. }
  57. unsigned int CCardReadAdapterFSM::s0_on_event(FSMEvent* pEvt)
  58. {
  59. LOG_FUNCTION();
  60. Dbg("s0 evt %d", pEvt->iEvt);
  61. switch (pEvt->iEvt)
  62. {
  63. case USER_EVT_INIT:
  64. {
  65. InitTask* task = new InitTask(this);
  66. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  67. pEvt->SetHandled();
  68. return 0;
  69. }
  70. break;
  71. default:
  72. break;
  73. }
  74. return 0;
  75. }
  76. //Initializing
  77. void CCardReadAdapterFSM::s1_on_entry()
  78. {
  79. LOG_FUNCTION();
  80. }
  81. void CCardReadAdapterFSM::s1_on_exit()
  82. {
  83. LOG_FUNCTION();
  84. }
  85. unsigned int CCardReadAdapterFSM::s1_on_event(FSMEvent* pEvt)
  86. {
  87. LOG_FUNCTION();
  88. Dbg("s1 evt %d", pEvt->iEvt);
  89. switch (pEvt->iEvt)
  90. {
  91. case USER_EVT_INIT_FINISHED:
  92. pEvt->SetHandled();
  93. return pEvt->param1;
  94. default:
  95. break;
  96. }
  97. return 0;
  98. }
  99. //Idle
  100. void CCardReadAdapterFSM::s2_on_entry()
  101. {
  102. LOG_FUNCTION();
  103. GetEntityBase()->GetFunction()->SetUserDefineState(USER_CARDISSUER_IDLE);
  104. Dbg("set reset times 0.");
  105. m_resetTimes = 0;
  106. m_testResult = Error_Succeed;
  107. m_bIssuingExit = false;
  108. m_bCancelAccept = false;
  109. //oiltmp 测试便携厂商发卡
  110. //m_pCardIssuer->SetIssuerCounter(0, 1);
  111. //m_pCardIssuer->MoveCard(CI_MOVECARD_FROM_HOPPER);
  112. //MagTracks magTracks;
  113. //magTracks.eRange = CI_TRACK_RANGE_2_3;
  114. //m_pCardIssuer->MagRead(magTracks);
  115. //Dbg("%s,%d,%d", magTracks.track[1].data, magTracks.track[1].dwSize, magTracks.track[1].eStatus);
  116. //m_pCardIssuer->MoveCard(CI_MOVECARD_FRONT_GATE);
  117. //ErrorCodeEnum err = m_pIDCard->SetCardInType(CARD_IN_TYPE_ALL);
  118. //Dbg("accept[%d]",err);
  119. //Sleep(WAIT_INTERVAL*10);
  120. //LPCardAccount* ppCardAccount;
  121. ////err = m_pIDCard->GetCardAccount(IDC_TRACK_1|IDC_TRACK_2|IDC_TRACK_3,&ppCardAccount);
  122. ////Dbg("read[%d]",err);
  123. ////Dbg("%d,%d,%d",ppCardAccount[0]->dataStatus,(ppCardAccount[1])->dataStatus,(ppCardAccount[2])->dataStatus);//,pCardAccount->data);
  124. ////Dbg("%d,%d,%d",ppCardAccount[0]->length,(ppCardAccount[1])->length,(ppCardAccount[2])->length);//,pCardAccount->data);
  125. ////Dbg("read data[%s][%s][%s]",(char*)(ppCardAccount[0]->data),(char*)(ppCardAccount[1]->data),(char*)(ppCardAccount[2]->data));
  126. //err = m_pIDCard->DectectCardType(m_cardType);
  127. //Dbg("detectcardtyp[%d][%d]",err,m_cardType);
  128. //err = m_pIDCard->ActiveCard();
  129. //Dbg("activecard[%d]",err);
  130. //vector<AIDData> vAIDs;
  131. //MessageBoxA(0,0,0,0);
  132. //if (m_cardType == CARDTYPE_CPU_T0 || m_cardType == CARDTYPE_CPU_T1)
  133. //{
  134. // BuildSupportedAppList(vAIDs);
  135. // Dbg("[%s]",testIC);
  136. // AppSelected(m_vADFRec.at(0).name,m_vADFRec.at(0).nameLen);
  137. //}
  138. }
  139. void CCardReadAdapterFSM::s2_on_exit()
  140. {
  141. LOG_FUNCTION();
  142. }
  143. unsigned int CCardReadAdapterFSM::s2_on_event(FSMEvent* pEvt)
  144. {
  145. Dbg("s2 evt(%d)", pEvt->iEvt);
  146. int ret = 0;
  147. switch (pEvt->iEvt)
  148. {
  149. case USER_EVT_READ:
  150. {
  151. //oilyang@20200426 according to MachineType ***AND MachineVersion*** to decide which Card-like entity to be called
  152. //RVC.Stand2S, RVC.PAD, RVC.IL, RPM.Stand1S, RVC.CardStore, RVC.Wall, RVC.Desk2S, RVC.Desk1S
  153. // ContactlessCard:
  154. // --RVC.Stand2S, RVC.Desk2S(all MachineVersion), RVC.Desk1S(all MachineVersion)
  155. // CardSwiper:
  156. // --except for RVC.Stand2S,RVC.CardStore
  157. // --oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
  158. // Desk2S 2.1 have no CardSwiper,so no need call it
  159. // CardIssuer:
  160. // --no matter what MachineType is,just call it ,except for "RVC.Desk2S 2.0"
  161. // -- see the following "except for cross call" ,what the f**king line means?
  162. pEvt->SetHandled();
  163. CardReadEvent* cre = dynamic_cast<CardReadEvent*>(pEvt);
  164. bool bCardIssuer, bCardSwiper, bContactlessCard;
  165. bCardIssuer = bCardSwiper = bContactlessCard = false;
  166. if (m_eMachineType == MachineType_RVC_Stand2S || m_eMachineType == MachineType_RVC_DESK2S
  167. || m_eMachineType == MachineType_RVC_DESK1S)
  168. {
  169. ContactlessCardReadTask* cTask = new ContactlessCardReadTask(this);
  170. cTask->ctx = cre->ctx;
  171. if (IsTheEntity(cre->ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK())
  172. {
  173. bContactlessCard = true;
  174. GetEntityBase()->GetFunction()->PostThreadPoolTask(cTask);
  175. Dbg("to ContactlessCard");
  176. }
  177. }
  178. //oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
  179. //Desk2S 2.1 have no CardSwiper,so no need call it
  180. if (!(m_eMachineType == MachineType_RVC_Stand2S
  181. || m_eMachineType == MachineType_RVC_CardStore
  182. || m_eMachineType == MachineType_RVC_DESK1S
  183. || (m_eMachineType == MachineType_RVC_DESK2S && m_majorVerion == 2 && m_minorVerion == 1)))
  184. {
  185. CardSwiperReadTask* sTask = new CardSwiperReadTask(this);
  186. sTask->ctx = cre->ctx;
  187. if (IsTheEntity(cre->ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
  188. {
  189. bCardSwiper = true;
  190. GetEntityBase()->GetFunction()->PostThreadPoolTask(sTask);
  191. Dbg("to CardSwiper");
  192. }
  193. }
  194. //oilyang@20200426 暂时未发现这行代码的用处,可能简版?后来废弃。暂时保留,后续考虑去掉
  195. if ((cre->ctx->Req.reserved1.GetCount() == 0 || cre->ctx->Req.reserved1[0] != 1))//except for cross call
  196. {
  197. CardIssuerReadTask* iTask = new CardIssuerReadTask(this);
  198. iTask->ctx = cre->ctx;
  199. if (IsTheEntity(cre->ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
  200. {
  201. bCardIssuer = true;
  202. GetEntityBase()->GetFunction()->PostThreadPoolTask(iTask);
  203. Dbg("to CardIssuer");
  204. }
  205. if (bCardIssuer || bCardSwiper || bContactlessCard)
  206. Dbg("bCardIssuer,bCardSwiper,bContactlessCard:%d,%d,%d", bCardIssuer, bCardSwiper, bContactlessCard);
  207. else
  208. {
  209. Dbg("can't find the right entity.");
  210. cre->ctx->Answer(Error_Unexpect);
  211. }
  212. }
  213. }
  214. break;
  215. case USER_EVT_PREONLINE:
  216. {
  217. PreOnlineEvent* poe = dynamic_cast<PreOnlineEvent*>(pEvt);
  218. PreOnlineTask* task = new PreOnlineTask(this);
  219. task->ctx = poe->ctx;
  220. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  221. pEvt->SetHandled();
  222. return 0;
  223. }
  224. case USER_EVT_WRITE:
  225. {
  226. pEvt->SetHandled();
  227. CardWriteEvent* cwe = dynamic_cast<CardWriteEvent*>(pEvt);
  228. WriteTask* task = new WriteTask(this);
  229. task->ctx = cwe->ctx;
  230. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  231. return 0;
  232. }
  233. case USER_EVT_POSTONLINE:
  234. {
  235. PostOnlineEvent* poe = dynamic_cast<PostOnlineEvent*>(pEvt);
  236. PostOnlineTask* task = new PostOnlineTask(this);
  237. task->ctx = poe->ctx;
  238. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  239. pEvt->SetHandled();
  240. return 0;
  241. }
  242. case USER_EVT_EXIT:
  243. {
  244. pEvt->SetHandled();
  245. DoExitTask* task = new DoExitTask(this);
  246. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  247. }
  248. break;
  249. case USER_EVT_EJECT:
  250. {
  251. pEvt->SetHandled();
  252. CardEjectEvent* cee = dynamic_cast<CardEjectEvent*>(pEvt);
  253. EjectTask* task = new EjectTask(this);
  254. task->ctx = cee->ctx;
  255. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  256. }
  257. break;
  258. case USER_EVT_SET_SOME_FLAG:
  259. {
  260. pEvt->SetHandled();
  261. SetSomeFlagEvent* ssfe = dynamic_cast<SetSomeFlagEvent*>(pEvt);
  262. SetSomeFlagTask* task = new SetSomeFlagTask(this);
  263. task->ctx = ssfe->ctx;
  264. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  265. }
  266. break;
  267. case USER_EVT_GET_DEV_INFO:
  268. {
  269. pEvt->SetHandled();
  270. GetDevInfoEvent* gdie = dynamic_cast<GetDevInfoEvent*>(pEvt);
  271. GetDevInfoTask* task = new GetDevInfoTask(this);
  272. task->ctx = gdie->ctx;
  273. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  274. }
  275. break;
  276. case USER_EVT_QUERY_CARD_INFO:
  277. {
  278. pEvt->SetHandled();
  279. QueryCardInfoEvent* qcie = dynamic_cast<QueryCardInfoEvent*>(pEvt);
  280. QueryCardInfoTask* task = new QueryCardInfoTask(this);
  281. task->ctx = qcie->ctx;
  282. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  283. }
  284. break;
  285. case USER_EVT_QUIT:
  286. pEvt->SetHandled();
  287. break;
  288. case USER_EVT_ISSUE:
  289. {
  290. pEvt->SetHandled();
  291. CardIssueEvent* cee = dynamic_cast<CardIssueEvent*>(pEvt);
  292. IssueTask* task = new IssueTask(this);
  293. task->ctx = cee->ctx;
  294. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  295. }
  296. break;
  297. case USER_EVT_CAPTURE:
  298. {
  299. pEvt->SetHandled();
  300. CardCaptureEvent* cee = dynamic_cast<CardCaptureEvent*>(pEvt);
  301. CaptureTask* task = new CaptureTask(this);
  302. task->ctx = cee->ctx;
  303. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  304. }
  305. break;
  306. case USER_EVT_GET_MATERIAL:
  307. {
  308. pEvt->SetHandled();
  309. GetMaterialEvent *gme = dynamic_cast<GetMaterialEvent*>(pEvt);
  310. GetMaterialCountTask *task = new GetMaterialCountTask(this);
  311. task->ctx = gme->ctx;
  312. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  313. break;
  314. }
  315. case USER_EVT_SET_MATERIAL:
  316. {
  317. pEvt->SetHandled();
  318. SetMaterialEvent *sme = dynamic_cast<SetMaterialEvent*>(pEvt);
  319. SetMaterialCountTask *task = new SetMaterialCountTask(this);
  320. task->ctx = sme->ctx;
  321. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  322. break;
  323. }
  324. case USER_EVT_GET_SCI_INFO:
  325. {
  326. pEvt->SetHandled();
  327. GetSCIInfoEvent* gsie = dynamic_cast<GetSCIInfoEvent*>(pEvt);
  328. GetSCIInfoTask* task = new GetSCIInfoTask(this);
  329. task->ctx = gsie->ctx;
  330. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  331. }
  332. break;
  333. case USER_EVT_OPEN_SAFELOCK:
  334. {
  335. pEvt->SetHandled();
  336. OpenSafeLockEvent *osle = dynamic_cast<OpenSafeLockEvent*>(pEvt);
  337. OpenSafeLockTask* task = new OpenSafeLockTask(this);
  338. task->ctx = osle->ctx;
  339. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  340. }
  341. break;
  342. case USER_EVT_MAGTRANS_INIT:
  343. {
  344. pEvt->SetHandled();
  345. MagTransferInitEvent* mtie = dynamic_cast<MagTransferInitEvent*>(pEvt);
  346. MagTransferInitTask* task = new MagTransferInitTask(this);
  347. task->ctx = mtie->ctx;
  348. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  349. }
  350. break;
  351. case USER_EVT_QUERY_CONN_INFO:
  352. {
  353. pEvt->SetHandled();
  354. QueryConnInfoEvent* qcie = dynamic_cast<QueryConnInfoEvent*>(pEvt);
  355. QueryConnInfoTask* task = new QueryConnInfoTask(this);
  356. task->ctx = qcie->ctx;
  357. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  358. }
  359. break;
  360. case USER_EVT_SAM_IC_COMMAND:
  361. {
  362. pEvt->SetHandled();
  363. SAMICCommandEvent* samice = dynamic_cast<SAMICCommandEvent*>(pEvt);
  364. SAMICCommandTask* task = new SAMICCommandTask(this);
  365. task->ctx = samice->ctx;
  366. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  367. }
  368. break;
  369. case USER_EVT_QUERY_PRINTER_STATUS:
  370. {
  371. pEvt->SetHandled();
  372. QueryPrinterStatusEvent* samice = dynamic_cast<QueryPrinterStatusEvent*>(pEvt);
  373. QueryPrinterStatusTask* task = new QueryPrinterStatusTask(this);
  374. task->ctx = samice->ctx;
  375. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  376. }
  377. break;
  378. case USER_EVT_PRINT:
  379. {
  380. pEvt->SetHandled();
  381. PrintEvent* samice = dynamic_cast<PrintEvent*>(pEvt);
  382. PrintTask* task = new PrintTask(this);
  383. task->ctx = samice->ctx;
  384. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  385. }
  386. break;
  387. case USER_EVT_QUERY_SCILIST:
  388. {
  389. pEvt->SetHandled();
  390. QuerySCIListEvent* samice = dynamic_cast<QuerySCIListEvent*>(pEvt);
  391. QuerySCIListTask* task = new QuerySCIListTask(this);
  392. task->ctx = samice->ctx;
  393. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  394. }
  395. break;
  396. case USER_EVT_BIND_SCI:
  397. {
  398. pEvt->SetHandled();
  399. BindSCIEvent* samice = dynamic_cast<BindSCIEvent*>(pEvt);
  400. BindSCITask* task = new BindSCITask(this);
  401. task->ctx = samice->ctx;
  402. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  403. }
  404. break;
  405. case USER_EVT_PREONLINE_ON_STORE:
  406. {
  407. pEvt->SetHandled();
  408. PreOnlineOnStoreEvent* samice = dynamic_cast<PreOnlineOnStoreEvent*>(pEvt);
  409. PreOnlineOnStoreTask* task = new PreOnlineOnStoreTask(this);
  410. task->ctx = samice->ctx;
  411. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  412. }
  413. break;
  414. case USER_EVT_GET_ADD_CARD_INFO:
  415. {
  416. pEvt->SetHandled();
  417. GetAddCardInfoEvent* samice = dynamic_cast<GetAddCardInfoEvent*>(pEvt);
  418. GetAddCardInfoTask* task = new GetAddCardInfoTask(this);
  419. task->ctx = samice->ctx;
  420. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  421. }
  422. break;
  423. case USER_EVT_NOTIFY_PREONLINE:
  424. {
  425. pEvt->SetHandled();
  426. NotifyPreonlineEvent* samice = dynamic_cast<NotifyPreonlineEvent*>(pEvt);
  427. NotifyPreOnlineTask* task = new NotifyPreOnlineTask(this);
  428. task->ctx = samice->ctx;
  429. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  430. }
  431. break;
  432. case USER_EVT_QUERY_CARD_INFO_ON_STORE:
  433. {
  434. pEvt->SetHandled();
  435. QueryCardInfoOnStoreEvent* samice = dynamic_cast<QueryCardInfoOnStoreEvent*>(pEvt);
  436. QueryCardInfoOnStoreTask* task = new QueryCardInfoOnStoreTask(this);
  437. task->ctx = samice->ctx;
  438. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  439. }
  440. break;
  441. case USER_EVT_CROSS_TERM_CALL:
  442. {
  443. pEvt->SetHandled();
  444. CrossTermCallEvent* ctce = dynamic_cast<CrossTermCallEvent*>(pEvt);
  445. CrossTermCallTask* task = new CrossTermCallTask(this);
  446. task->ctx = ctce->ctx;
  447. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  448. }
  449. break;
  450. default:
  451. break;
  452. }
  453. return ret;
  454. }
  455. //Working
  456. void CCardReadAdapterFSM::s3_on_entry()
  457. {
  458. LOG_FUNCTION();
  459. }
  460. void CCardReadAdapterFSM::s3_on_exit()
  461. {
  462. LOG_FUNCTION();
  463. }
  464. unsigned int CCardReadAdapterFSM::s3_on_event(FSMEvent* pEvt)
  465. {
  466. Dbg("s3 evt %d,%d", pEvt->iEvt,pEvt->param1);
  467. int ret = 0;
  468. switch (pEvt->iEvt)
  469. {
  470. case USER_EVT_READ_FINISHED:
  471. {
  472. pEvt->SetHandled();
  473. ret = pEvt->param1;
  474. //if (pEvt->param1 == 0)
  475. CardReadFinishedEvent* crfe = dynamic_cast<CardReadFinishedEvent*>(pEvt);
  476. {
  477. if (m_bCancelAccept)
  478. {
  479. Dbg("front cancel");
  480. crfe->ctx->Answer(Error_Cancel);
  481. ret = 0;
  482. }
  483. }
  484. if (pEvt->param1 == 7)//CardIssuer Timeout,need to cancel ContactlessCard insert
  485. {
  486. Dbg("CardIssuer Timeout,need to cancel ContactlessCard insert");
  487. if (IsContactlessCardSessionOK())
  488. m_pContactless->CancelInsert();
  489. crfe->ctx->Answer(Error_TimeOut);
  490. ret = 0;
  491. }
  492. if (m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
  493. {
  494. Dbg("as card in ContactlessCard,to cancel others");
  495. if (IsCardIssuerSessionOK())
  496. m_pCardIssuer->CancelInsert();
  497. if (IsCardSwiperSessionOK())
  498. m_pCardSwiper->CancelInsert();
  499. }
  500. else if (m_busCtx.eCardFromWhich == Card_In_CardIssuer)
  501. {
  502. Dbg("as card in CardIssuer,to cancel others");
  503. if (IsContactlessCardSessionOK())
  504. m_pContactless->CancelInsert();
  505. if (IsCardSwiperSessionOK())
  506. m_pCardSwiper->CancelInsert();
  507. }
  508. else if (m_busCtx.eCardFromWhich == Card_In_CardSwiper)
  509. {
  510. Dbg("as card in CardSwiper,to cancel others");
  511. if (IsCardIssuerSessionOK())
  512. m_pCardIssuer->CancelInsert();
  513. if (IsContactlessCardSessionOK())
  514. m_pContactless->CancelInsert();
  515. }
  516. return ret;
  517. }
  518. case USER_EVT_PREONLINE_FINISHED:
  519. pEvt->SetHandled();
  520. return 0;
  521. case USER_EVT_POSTONLINE_FINISHED:
  522. pEvt->SetHandled();
  523. return 0;
  524. case USER_EVT_READ_CANCEL:
  525. pEvt->SetHandled();
  526. m_bCancelAccept = true;
  527. CancelRead();
  528. break;
  529. case USER_EVT_READ_WAIT_MORE:
  530. {
  531. pEvt->SetHandled();
  532. ReadWaitMoreTask* task = new ReadWaitMoreTask(this);
  533. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  534. }
  535. break;
  536. case USER_EVT_EXIT:
  537. {
  538. pEvt->SetHandled();
  539. DoExitTask* task = new DoExitTask(this);
  540. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  541. }
  542. break;
  543. case USER_EVT_WRITE_FINISHED:
  544. case USER_EVT_SET_SOME_FLAG_FINISHED:
  545. case USER_EVT_GET_DEV_INFO_FINISHED:
  546. case USER_EVT_QUERY_CARD_INFO_FINISHED:
  547. case USER_EVT_GET_MATERIAL_FINISHED:
  548. case USER_EVT_SET_MATERIAL_FINISHED:
  549. case USER_EVT_GET_SCI_INFO_FINISHED:
  550. case USER_EVT_OPEN_SAFELOCK_FINISHED:
  551. case USER_EVT_MAGTRANS_INIT_FINISHED:
  552. case USER_EVT_QUERY_CONN_INFO_FINISHED:
  553. case USER_EVT_QUIT:
  554. case USER_EVT_SAM_IC_COMMAND_FINISHED:
  555. case USER_EVT_QUERY_PRINTER_STATUS_FINISHED:
  556. case USER_EVT_PRINT_FINISHED:
  557. case USER_EVT_QUERY_SCILIST_FINISHED:
  558. case USER_EVT_BIND_SCI_FINISHED:
  559. case USER_EVT_PREONLINE_ON_STORE_FINISHED:
  560. case USER_EVT_GET_ADD_CARD_INFO_FINISHED:
  561. case USER_EVT_NOTIFY_PREONLINE_FINISHED:
  562. case USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED:
  563. case USER_EVT_CROSS_TERM_CALL_FINISHED:
  564. pEvt->SetHandled();
  565. break;
  566. default:
  567. break;
  568. }
  569. return ret;
  570. }
  571. //Failed
  572. void CCardReadAdapterFSM::s4_on_entry()
  573. {
  574. LOG_FUNCTION();
  575. GetEntityBase()->GetFunction()->SetUserDefineState(USER_CARDISSUER_HOLD);
  576. }
  577. void CCardReadAdapterFSM::s4_on_exit()
  578. {
  579. LOG_FUNCTION();
  580. }
  581. unsigned int CCardReadAdapterFSM::s4_on_event(FSMEvent* pEvt)
  582. {
  583. Dbg("s4 evt(%d)", pEvt->iEvt);
  584. switch (pEvt->iEvt)
  585. {
  586. case USER_EVT_EXIT:
  587. {
  588. pEvt->SetHandled();
  589. DoExitTask* task = new DoExitTask(this);
  590. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  591. }
  592. break;
  593. case USER_EVT_QUIT:
  594. {
  595. pEvt->SetHandled();
  596. return 0;
  597. }
  598. case USER_EVT_SET_SOME_FLAG:
  599. {
  600. pEvt->SetHandled();
  601. SetSomeFlagEvent* ssfe = dynamic_cast<SetSomeFlagEvent*>(pEvt);
  602. SetSomeFlagTask* task = new SetSomeFlagTask(this);
  603. task->ctx = ssfe->ctx;
  604. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  605. }
  606. break;
  607. case USER_EVT_GET_DEV_INFO:
  608. {
  609. pEvt->SetHandled();
  610. GetDevInfoEvent* gdie = dynamic_cast<GetDevInfoEvent*>(pEvt);
  611. GetDevInfoTask* task = new GetDevInfoTask(this);
  612. task->ctx = gdie->ctx;
  613. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  614. }
  615. break;
  616. case USER_EVT_QUERY_CARD_INFO:
  617. {
  618. pEvt->SetHandled();
  619. QueryCardInfoEvent* qcie = dynamic_cast<QueryCardInfoEvent*>(pEvt);
  620. QueryCardInfoTask* task = new QueryCardInfoTask(this);
  621. task->ctx = qcie->ctx;
  622. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  623. }
  624. break;
  625. default:
  626. break;
  627. }
  628. return 0;
  629. }
  630. ErrorCodeEnum CCardReadAdapterFSM::OnInit()
  631. {
  632. LOG_FUNCTION();
  633. m_busCtx.eCardFromWhich = Card_In_No_Where;
  634. return Error_Succeed;
  635. }
  636. ErrorCodeEnum CCardReadAdapterFSM::OnExit()
  637. {
  638. LOG_FUNCTION();
  639. FSMImpl<CCardReadAdapterFSM>::OnExit();
  640. return Error_Succeed;
  641. }
  642. int CCardReadAdapterFSM::Initial()
  643. {
  644. CheckSessionTask *pTask = new CheckSessionTask(this);
  645. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  646. ErrorCodeEnum eErr;
  647. eErr = GetEntityBase()->GetFunction()->SetSysVar("CardEntityState", "E");
  648. if (eErr != Error_Succeed)
  649. {
  650. Dbg("SetSysVar CardEntityState failed.%d",eErr);
  651. }
  652. return 0;//oiltmp no need to connect. let function "CheckAndReconnectSession" do
  653. }
  654. int CCardReadAdapterFSM::DoWork(int type)
  655. {
  656. switch (type)
  657. {
  658. case USER_EVT_READ:
  659. {
  660. }
  661. break;
  662. default:
  663. Dbg("unkown type:%d",type);
  664. break;
  665. }
  666. return 0;
  667. }
  668. int CCardReadAdapterFSM::CardIssuerRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx)
  669. {
  670. LOG_FUNCTION();
  671. ErrorCodeEnum eErr = Error_Unexpect;
  672. if (IsTheEntity(ctx->Req.module,Module_CardIssuer) && IsCardIssuerSessionOK())
  673. {
  674. CardIssuerService_QueryCardInfo_Req qciReq;
  675. CardIssuerService_QueryCardInfo_Ans qciAns;
  676. bool bHasCard = false, bNeedPreOnline = false;
  677. DWORD dwUsrErrCode = 0;
  678. eErr = m_pCardIssuer->QueryCardInfo(qciReq, qciAns, 10000,dwUsrErrCode);
  679. if (eErr == Error_Succeed)
  680. {
  681. if (qciAns.position == 2)//有卡
  682. {
  683. Dbg("CardIssuer has card");
  684. bHasCard = true;
  685. bNeedPreOnline = true;//不知道卡片类型,默认
  686. m_busCtx.eCardFromWhich = Card_In_CardIssuer;
  687. if (IsContactlessCardSessionOK())
  688. m_pContactless->CancelInsert();
  689. }
  690. else
  691. {
  692. //oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
  693. //Desk2S 2.1 can insert into CardIssuer,so comment the following line
  694. //oilyang@20200426 if "RVC.Desk2S 2.1" ,call insert is forbidden
  695. //if (!(m_eMachineType == MachineType_RVC_DESK2S && m_majorVerion == 2 && m_minorVerion == 1))
  696. {
  697. CardIssuerService_Insert_Req req;
  698. CardIssuerService_Insert_Ans ans;
  699. req.aid = ctx->Req.aid;
  700. Dbg("to call cardissuer insert..");
  701. eErr = m_pCardIssuer->Insert(req, ans, 59000, dwUsrErrCode);
  702. if (eErr == Error_Succeed)
  703. {
  704. Dbg("Card insert into CardIssuer.");
  705. bHasCard = true;
  706. m_busCtx.eCardFromWhich = Card_In_CardIssuer;
  707. if (IsContactlessCardSessionOK())
  708. m_pContactless->CancelInsert();
  709. }
  710. else {
  711. Dbg("CardIssuer Insert return:%d", eErr);
  712. //oilyang@20200827 if time out, we must told front caller
  713. //AND set returned value of 0 to change FSM state
  714. if (eErr == Error_TimeOut)
  715. {
  716. return 7;
  717. }
  718. else
  719. return 1;//oilyang@20190709
  720. }
  721. }
  722. }
  723. if (bHasCard)
  724. {
  725. CardIssuerService_Read_Req reqR;
  726. CardIssuerService_Read_Ans ansR;
  727. reqR.aid = ctx->Req.aid;
  728. reqR.reserved1 = ctx->Req.lightPos;
  729. Dbg("to read ctx->Req.lightPos:%d", ctx->Req.lightPos);
  730. Sleep(100);//zjw@20190725 以防卡机状态还未跳转,这里就已经触发了Read操作
  731. eErr = m_pCardIssuer->Read(reqR, ansR, 50000, dwUsrErrCode);
  732. if (eErr == Error_Succeed)
  733. {
  734. ctx->Ans.track1 = ansR.track1;
  735. ctx->Ans.track2 = ansR.track2;
  736. ctx->Ans.track3 = ansR.track3;
  737. ctx->Ans.ICType = ansR.ICType;
  738. ctx->Ans.ICCardNo = ansR.ICData;
  739. ctx->Ans.status = ansR.status;
  740. if (m_eMachineType == MachineType_RVC_Stand2S)
  741. ctx->Ans.cardPos = CardPos_CardIssuer_Stand2S;
  742. else
  743. ctx->Ans.cardPos = CardPos_CardIssuer_Split;
  744. ctx->Ans.t2Account = ansR.t2Account;
  745. ctx->Ans.t2Region = ansR.t2Region;
  746. ctx->Ans.t2CardSerial = ansR.t2CardSerial;
  747. ctx->Ans.t2CVC = ansR.t2CVC;
  748. ctx->Ans.t2ExpireDate = ansR.t2ExpireDate;
  749. if (ansR.ICType == 1 || ansR.ICType == 3)
  750. bNeedPreOnline = true;
  751. }
  752. }
  753. }
  754. else {
  755. Dbg("CardIssuer QueryCardInfo return:", eErr);
  756. return 1;//oilyang@20190709
  757. }
  758. if (bHasCard && bNeedPreOnline)
  759. {
  760. CardIssuerService_PreOnline_Req req;
  761. CardIssuerService_PreOnline_Ans ans;
  762. req.businessData = ctx->Req.businessData;
  763. BroadcastReadICing(0);
  764. Dbg("to preonline");
  765. eErr = m_pCardIssuer->PreOnline(req, ans, 50000, dwUsrErrCode);
  766. if (eErr == Error_Succeed)
  767. {
  768. ctx->Ans.result = ans.result;
  769. ctx->Ans.status = 0;
  770. if (ctx->Ans.ICType == 1 || ctx->Ans.ICType == 3)
  771. {
  772. CardIssuerService_SetSomeFlag_Req ssfReq;
  773. CardIssuerService_SetSomeFlag_Ans ssfAns;
  774. ssfReq.IssueBusiness = 4;
  775. eErr = m_pCardIssuer->SetSomeFlag(ssfReq, ssfAns, 5000, dwUsrErrCode);
  776. if (eErr == Error_Succeed)
  777. ctx->Ans.ICCardNo = ssfAns.reserved2[0];
  778. }
  779. }
  780. else
  781. {
  782. ctx->Ans.result = "";
  783. ctx->Ans.status = -1;
  784. }
  785. }
  786. if (bHasCard)
  787. {
  788. Dbg("%d", eErr);
  789. ctx->Answer(eErr, dwUsrErrCode);
  790. }
  791. return 0;
  792. }
  793. return 1;
  794. }
  795. int CCardReadAdapterFSM::ContactlessCardRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx)
  796. {
  797. LOG_FUNCTION();
  798. ErrorCodeEnum eErr = Error_Unexpect;
  799. if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK())
  800. {
  801. bool bFindCard = false;
  802. //ContactlessCardService_QueryCardInfo_Req qciReq;
  803. //ContactlessCardService_QueryCardInfo_Ans qciAns;
  804. //eErr = m_pContactless->QueryCardInfo(qciReq, qciAns, 10000);
  805. //if (eErr == Error_Succeed)
  806. //{
  807. // if (qciAns.position == 4)//如果有卡,直接读卡
  808. // {
  809. // Dbg("find card on contactless card.");
  810. // m_busCtx.eCardFromWhich = Card_In_ContactlessCard;
  811. // m_pCardIssuer->CancelInsert();
  812. // bFindCard = true;
  813. // }
  814. // else
  815. // {
  816. ContactlessCardService_Insert_Req req;
  817. ContactlessCardService_Insert_Ans ans;
  818. req.aid = ctx->Req.aid;
  819. Dbg("to call contactless insert...");
  820. eErr = m_pContactless->Insert(req, ans, 56000);
  821. if (eErr == Error_Succeed)
  822. {
  823. ctx->Ans.track1 = ans.track1;
  824. ctx->Ans.track2 = ans.track2;
  825. ctx->Ans.track3 = ans.track3;
  826. ctx->Ans.ICType = ans.ICType;
  827. ctx->Ans.ICCardNo = ans.ICData;
  828. ctx->Ans.status = ans.status;
  829. ctx->Ans.cardPos = CardPos_ContactlessCard;
  830. ctx->Ans.t2Account = ans.t2Account;
  831. ctx->Ans.t2Region = ans.t2Region;
  832. ctx->Ans.t2CardSerial = ans.t2CardSerial;
  833. ctx->Ans.t2CVC = ans.t2CVC;
  834. ctx->Ans.t2ExpireDate = ans.t2ExpireDate;
  835. Dbg("Card in ContactlessCard.");
  836. m_busCtx.eCardFromWhich = Card_In_ContactlessCard;
  837. if (IsCardIssuerSessionOK())
  838. m_pCardIssuer->CancelInsert();
  839. if (ans.ICType == 4)
  840. {
  841. bFindCard = true;
  842. }
  843. }
  844. // }
  845. //}
  846. if (bFindCard)
  847. {
  848. ContactlessCardService_PreOnline_Req req;
  849. ContactlessCardService_PreOnline_Ans ans;
  850. req.businessData = ctx->Req.businessData;
  851. BroadcastReadICing(0);
  852. eErr = m_pContactless->PreOnline(req, ans, 50000);
  853. Dbg("PreOnline result:%d", eErr);
  854. if (eErr == Error_Succeed)
  855. {
  856. ctx->Ans.result = ans.result;
  857. ctx->Ans.status = 0;
  858. }
  859. else
  860. {
  861. ctx->Ans.result = "";
  862. ctx->Ans.status = -1;
  863. }
  864. ctx->Answer(eErr);
  865. return 0;
  866. }
  867. //ctx->Answer(eErr);
  868. }
  869. return 1;
  870. }
  871. int CCardReadAdapterFSM::IssueCard(SpReqAnsContext<CardReadAdapterService_Issue_Req, CardReadAdapterService_Issue_Ans>::Pointer ctx)
  872. {
  873. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
  874. {
  875. ErrorCodeEnum eErr = Error_Unexpect;
  876. CardIssuerService_IssueEx_Req req;
  877. CardIssuerService_IssueEx_Ans ans;
  878. req.hopper = ctx->Req.hopper;
  879. req.reserved1.Copy(ctx->Req.reserved1);
  880. req.reserved2.Copy(ctx->Req.reserved2);
  881. DWORD dwUsrErrCode = 0;
  882. eErr = m_pCardIssuer->IssueEx(req, ans, 60000, dwUsrErrCode);
  883. if (eErr == Error_Succeed)
  884. {
  885. if (ans.reserved1.GetCount() > 0)
  886. ctx->Ans.reserved1.Copy(ans.reserved1);
  887. if (ans.reserved2.GetCount() > 0)
  888. ctx->Ans.reserved2.Copy(ans.reserved2);
  889. // --Josephus at 11:09:47 201747
  890. //oilyang@20180315 kaku
  891. //if(m_busCtx.eCardFromWhich == Card_In_No_Where)
  892. if (req.hopper == 99 || req.hopper == 98 || req.hopper == 89)
  893. {
  894. if (ans.reserved1[0] == 0 && ans.reserved1[1] == 0)
  895. m_busCtx.eCardFromWhich = Card_In_CardIssuer;
  896. }
  897. else if (req.hopper == 88 || req.hopper == 87)
  898. {
  899. m_busCtx.eCardFromWhich = Card_In_No_Where;
  900. }
  901. else
  902. m_busCtx.eCardFromWhich = Card_In_CardIssuer;
  903. Dbg("req.hopper:%d Deem that CardIssuer has card after issuing succ. Set busCtx:findCard:%d,cardPos:%d"
  904. , req.hopper, ans.reserved1[0], ans.reserved1[1]);
  905. }
  906. ctx->Answer(eErr, dwUsrErrCode);
  907. return 0;
  908. }
  909. else
  910. {
  911. Dbg("issue card param error or connection is failed:(module)%d",ctx->Req.module);
  912. ctx->Answer(Error_Param);
  913. return 1;
  914. }
  915. }
  916. int CCardReadAdapterFSM::CardSwiperRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx,int &eRetErr)
  917. {
  918. ErrorCodeEnum eErr = Error_Unexpect;
  919. if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
  920. {
  921. CardSwiperService_Read_Req req;
  922. CardSwiperService_Read_Ans ans;
  923. req.aid = ctx->Req.aid;
  924. req.LightPos = 0;
  925. if (ctx->Req.lightPos == 0)
  926. req.LightPos = 7;
  927. if ((ctx->Req.lightPos&LightPos_CardSwiper_Mag) == LightPos_CardSwiper_Mag)
  928. req.LightPos += 1;
  929. if ((ctx->Req.lightPos&LightPos_CardSwiper_IC) == LightPos_CardSwiper_IC)
  930. req.LightPos += 2;
  931. if ((ctx->Req.lightPos&LightPos_CardSwiper_RFIC) == LightPos_CardSwiper_RFIC)
  932. req.LightPos += 4;
  933. Dbg("aid:%s,lightPos:%d",(const char*)req.aid,req.LightPos);
  934. eErr = m_pCardSwiper->Read(req, ans, 61000);
  935. Dbg("eErr:%d", eErr);
  936. eRetErr = eErr;
  937. if (eErr == Error_Succeed)
  938. {
  939. m_busCtx.eCardFromWhich = Card_In_CardSwiper;
  940. //oilyang@20180913 由于CardSwiper没有插卡过程,直接进行pboc流程,需要提前取消其他实体的输入
  941. if (IsCardIssuerSessionOK())
  942. m_pCardIssuer->CancelInsert();
  943. if (IsContactlessCardSessionOK())
  944. m_pContactless->CancelInsert();
  945. ctx->Ans.track1 = ans.track1;
  946. ctx->Ans.track2 = ans.track2;
  947. ctx->Ans.track3 = ans.track3;
  948. if (ans.ICType == 5)//oilyang@20170204 如果插错卡,反馈为未检测到(有效)卡
  949. ctx->Ans.ICType = 0;
  950. else if (ans.ICType == 6)//身份证
  951. ctx->Ans.ICType = 5;
  952. else
  953. ctx->Ans.ICType = ans.ICType;
  954. ctx->Ans.ICCardNo = ans.ICData;
  955. ctx->Ans.status = ans.status;
  956. if (ans.CardPos == 2 || ans.CardPos == 5)
  957. ctx->Ans.cardPos = CardPos_CardSwiper_IC_Insert;
  958. else if (ans.CardPos == 4 || ans.CardPos == 6)
  959. ctx->Ans.cardPos = CardPos_CardSwiper_RFIC;
  960. else
  961. ctx->Ans.cardPos = ans.CardPos;
  962. ctx->Ans.t2Account = ans.t2Account;
  963. ctx->Ans.t2Region = ans.t2Region;
  964. ctx->Ans.t2CardSerial = ans.t2CardSerial;
  965. ctx->Ans.t2CVC = ans.t2CVC;
  966. ctx->Ans.t2ExpireDate = ans.t2ExpireDate;
  967. 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));
  968. if (ans.ICType == 3 || ans.ICType == 4)
  969. {
  970. CardSwiperService_PreOnline_Req req;
  971. CardSwiperService_PreOnline_Ans ans;
  972. req.businessData = ctx->Req.businessData;
  973. BroadcastReadICing(0);
  974. eErr = m_pCardSwiper->PreOnline(req, ans, 50000);
  975. if (eErr == Error_Succeed)
  976. {
  977. ctx->Ans.result = ans.result;
  978. }
  979. else
  980. ctx->Ans.result = "";
  981. }
  982. }
  983. if (eErr == Error_InvalidState)
  984. {
  985. Dbg("CardSwiper in error state.");
  986. return 1;
  987. }
  988. else
  989. ctx->Answer(eErr);
  990. }
  991. else
  992. {
  993. Dbg("can't find the corresponding Entity.req.Module:%d", ctx->Req.module);
  994. return 1;
  995. //ctx->Answer(Error_Unexpect);
  996. }
  997. return 0;
  998. }
  999. void CCardReadAdapterFSM::CancelRead()
  1000. {
  1001. ErrorCodeEnum eErr = Error_Unexpect;
  1002. if (IsCardIssuerSessionOK())
  1003. {
  1004. Dbg("CardIssuer read canceled by front user.");
  1005. m_pCardIssuer->CancelInsert();
  1006. }
  1007. if (IsContactlessCardSessionOK())
  1008. {
  1009. Dbg("ContactlessCard read canceled by front user.");
  1010. m_pContactless->CancelInsert();
  1011. }
  1012. if (IsCardSwiperSessionOK())
  1013. {
  1014. eErr = m_pCardSwiper->CancelInsert();
  1015. Dbg("CardSwiper read canceled by front user.");
  1016. }
  1017. }
  1018. void CCardReadAdapterFSM::ReadWaitMore()
  1019. {
  1020. ErrorCodeEnum eErr = Error_Unexpect;
  1021. if (IsCardIssuerSessionOK())
  1022. {
  1023. m_pCardIssuer->InsertWaitMore();
  1024. }
  1025. if (IsContactlessCardSessionOK())
  1026. {
  1027. m_pContactless->InsertWaitMore();
  1028. }
  1029. if (IsCardSwiperSessionOK())
  1030. {
  1031. m_pCardSwiper->InsertWaitMore();
  1032. }
  1033. }
  1034. int CCardReadAdapterFSM::WriteTrack(SpReqAnsContext<CardReadAdapterService_WriteTrack_Req, CardReadAdapterService_WriteTrack_Ans>::Pointer ctx)
  1035. {
  1036. LOG_FUNCTION();
  1037. if (IsCardIssuerSessionOK())
  1038. {
  1039. CardIssuerService_WriteTrack_Req req;
  1040. CardIssuerService_WriteTrack_Ans ans;
  1041. req.co = ctx->Req.co;
  1042. req.mode = ctx->Req.mode;
  1043. req.track1 = ctx->Req.track1;
  1044. req.track2 = ctx->Req.track2;
  1045. req.track3 = ctx->Req.track3;
  1046. req.reserved = ctx->Req.reserved;
  1047. ErrorCodeEnum eErr = Error_Unexpect;
  1048. DWORD dwUsrErrCode = 0;
  1049. eErr = m_pCardIssuer->WriteTrack(req, ans, 20000, dwUsrErrCode);
  1050. if (eErr != Error_Succeed)
  1051. {
  1052. Dbg("WriteTrack failed.%d",eErr);
  1053. ctx->Answer(eErr, dwUsrErrCode);
  1054. }
  1055. else
  1056. {
  1057. ctx->Ans.result = ans.result;
  1058. ctx->Ans.reserved1 = ans.reserved1;
  1059. ctx->Ans.reserved2 = ans.reserved2;
  1060. Dbg("Write tracks ok.");
  1061. ctx->Answer(Error_Succeed);
  1062. }
  1063. }
  1064. return 0;
  1065. }
  1066. int CCardReadAdapterFSM::PreOnline(SpReqAnsContext<CardReadAdapterService_PreOnline_Req, CardReadAdapterService_PreOnline_Ans>::Pointer ctx)
  1067. {
  1068. LOG_FUNCTION();
  1069. ErrorCodeEnum eErr = Error_Unexpect;
  1070. DWORD dwUsrErrCode = 0;
  1071. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
  1072. {
  1073. CardIssuerService_PreOnline_Req req;
  1074. CardIssuerService_PreOnline_Ans ans;
  1075. req.businessData = ctx->Req.businessData;
  1076. if (!ctx->Req.reserved2[0].IsNullOrEmpty())
  1077. req.reserved1 = ctx->Req.reserved2[0];
  1078. else
  1079. req.reserved1 = "";
  1080. if (!ctx->Req.reserved2[1].IsNullOrEmpty())
  1081. req.reserved2 = ctx->Req.reserved2[1];
  1082. else
  1083. req.reserved2 = "";
  1084. eErr = m_pCardIssuer->PreOnline(req, ans, 50000, dwUsrErrCode);
  1085. if (eErr == Error_Succeed)
  1086. {
  1087. ctx->Ans.result = ans.result;
  1088. }
  1089. ctx->Answer(eErr, dwUsrErrCode);
  1090. }
  1091. else if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
  1092. {
  1093. ContactlessCardService_PreOnline_Req req;
  1094. ContactlessCardService_PreOnline_Ans ans;
  1095. req.businessData = ctx->Req.businessData;
  1096. //req.reserved1 = ctx->Req.reserved1;
  1097. //req.reserved2 = ctx->Req.reserved2;
  1098. eErr = m_pContactless->PreOnline(req, ans, 50000, dwUsrErrCode);
  1099. if (eErr == Error_Succeed)
  1100. {
  1101. ctx->Ans.result = ans.result;
  1102. }
  1103. ctx->Answer(eErr, dwUsrErrCode);
  1104. }
  1105. else if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
  1106. {
  1107. CardSwiperService_PreOnline_Req req;
  1108. CardSwiperService_PreOnline_Ans ans;
  1109. req.businessData = ctx->Req.businessData;
  1110. //req.reserved1 = ctx->Req.reserved1;
  1111. //req.reserved2 = ctx->Req.reserved2;
  1112. eErr = m_pCardSwiper->PreOnline(req, ans, 50000, dwUsrErrCode);
  1113. if (eErr == Error_Succeed)
  1114. {
  1115. ctx->Ans.result = ans.result;
  1116. }
  1117. ctx->Answer(eErr, dwUsrErrCode);
  1118. }
  1119. return 0;
  1120. }
  1121. int CCardReadAdapterFSM::PostOnline(SpReqAnsContext<CardReadAdapterService_PostOnline_Req, CardReadAdapterService_PostOnline_Ans>::Pointer ctx)
  1122. {
  1123. LOG_FUNCTION();
  1124. Dbg("ctx->Req.module:%d,cardIn(Iss 1,RF 2):%d",ctx->Req.module, m_busCtx.eCardFromWhich);
  1125. ErrorCodeEnum eErr = Error_Unexpect;
  1126. DWORD dwUsrErrCode = 0;
  1127. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
  1128. {
  1129. CardIssuerService_PostOnline_Req req;
  1130. CardIssuerService_PostOnline_Ans ans;
  1131. req.data = ctx->Req.data;
  1132. eErr = m_pCardIssuer->PostOnline(req, ans, 50000, dwUsrErrCode);
  1133. if (eErr == Error_Succeed)
  1134. {
  1135. ctx->Ans.result = ans.result;
  1136. }
  1137. ctx->Answer(eErr, dwUsrErrCode);
  1138. }
  1139. else if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
  1140. {
  1141. ContactlessCardService_PostOnline_Req req;
  1142. ContactlessCardService_PostOnline_Ans ans;
  1143. req.data = ctx->Req.data;
  1144. eErr = m_pContactless->PostOnline(req, ans, 50000, dwUsrErrCode);
  1145. if (eErr == Error_Succeed)
  1146. {
  1147. ctx->Ans.result = ans.result;
  1148. }
  1149. ctx->Answer(eErr, dwUsrErrCode);
  1150. }
  1151. else if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
  1152. {
  1153. CardSwiperService_PostOnline_Req req;
  1154. CardSwiperService_PostOnline_Ans ans;
  1155. req.data = ctx->Req.data;
  1156. eErr = m_pCardSwiper->PostOnline(req, ans, 50000, dwUsrErrCode);
  1157. if (eErr == Error_Succeed)
  1158. {
  1159. ctx->Ans.result = ans.result;
  1160. }
  1161. ctx->Answer(eErr, dwUsrErrCode);
  1162. }
  1163. return 0;
  1164. }
  1165. int CCardReadAdapterFSM::EjectCard(SpReqAnsContext<CardReadAdapterService_Eject_Req, CardReadAdapterService_Eject_Ans>::Pointer ctx)
  1166. {
  1167. LOG_FUNCTION();
  1168. ErrorCodeEnum eErr = Error_Unexpect;
  1169. Dbg("before eject card,req.module %d,card in %d", ctx->Req.module,m_busCtx.eCardFromWhich);
  1170. DWORD dwUsrErrCode = 0;
  1171. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
  1172. {
  1173. CardIssuerService_Eject_Req req;
  1174. CardIssuerService_Eject_Ans ans;
  1175. eErr = m_pCardIssuer->Eject(req, ans, 50000, dwUsrErrCode);
  1176. if (eErr == Error_Succeed)
  1177. {
  1178. m_busCtx.eCardFromWhich = Card_In_No_Where;
  1179. Dbg("CardIssuer EjectCard suc.");
  1180. }
  1181. ctx->Answer(eErr, dwUsrErrCode);
  1182. }
  1183. else if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
  1184. {
  1185. ContactlessCardService_Eject_Req req;
  1186. ContactlessCardService_Eject_Ans ans;
  1187. eErr = m_pContactless->Eject(req, ans, 50000, dwUsrErrCode);
  1188. if (eErr == Error_Succeed)
  1189. {
  1190. m_busCtx.eCardFromWhich = Card_In_No_Where;
  1191. Dbg("ContactlessCard EjectCard suc.");
  1192. }
  1193. ctx->Answer(eErr, dwUsrErrCode);
  1194. }
  1195. else if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
  1196. {
  1197. CardSwiperService_Eject_Req req;
  1198. CardSwiperService_Eject_Ans ans;
  1199. eErr = m_pCardSwiper->Eject(req, ans, 50000, dwUsrErrCode);
  1200. if (eErr == Error_Succeed)
  1201. {
  1202. m_busCtx.eCardFromWhich = Card_In_No_Where;
  1203. Dbg("CardSwiper EjectCard suc.");
  1204. }
  1205. ctx->Answer(eErr, dwUsrErrCode);
  1206. }
  1207. else
  1208. {
  1209. Dbg("nothing to do.");
  1210. ctx->Answer(Error_NotExist);
  1211. }
  1212. return 0;
  1213. }
  1214. int CCardReadAdapterFSM::CaptureCard(SpReqAnsContext<CardReadAdapterService_Capture_Req, CardReadAdapterService_Capture_Ans>::Pointer ctx)
  1215. {
  1216. LOG_FUNCTION();
  1217. ErrorCodeEnum eErr = Error_Unexpect;
  1218. DWORD dwUsrErrCode = 0;
  1219. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
  1220. {
  1221. CardIssuerService_Capture_Req req;
  1222. CardIssuerService_Capture_Ans ans;
  1223. eErr = m_pCardIssuer->Capture(req, ans, 15000, dwUsrErrCode);
  1224. if (eErr == Error_Succeed)
  1225. {
  1226. Dbg("Capture card suc.");
  1227. m_busCtx.eCardFromWhich = Card_In_No_Where;
  1228. }
  1229. ctx->Answer(eErr, dwUsrErrCode);
  1230. }
  1231. else
  1232. {
  1233. Dbg("Something wrong.the module(%d),cardinwhere(%d)", ctx->Req.module, m_busCtx.eCardFromWhich);
  1234. ctx->Answer(eErr);
  1235. }
  1236. return 0;
  1237. }
  1238. int CCardReadAdapterFSM::QueryCardInfo(SpReqAnsContext<CardReadAdapterService_QueryCardInfo_Req, CardReadAdapterService_QueryCardInfo_Ans>::Pointer ctx)
  1239. {
  1240. ErrorCodeEnum eErr = Error_Unexpect;
  1241. DWORD dwUsrErrCode = 0;
  1242. ctx->Ans.CardIssuerPos = ctx->Ans.ContactlessCardPos = ctx->Ans.CardSwiperPos = 0;
  1243. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK() && m_busCtx.eCardFromWhich == Card_In_CardIssuer)
  1244. {
  1245. CardIssuerService_QueryCardInfo_Req req;
  1246. CardIssuerService_QueryCardInfo_Ans ans;
  1247. eErr = m_pCardIssuer->QueryCardInfo(req, ans, 10000, dwUsrErrCode);
  1248. if (eErr == Error_Succeed)
  1249. {
  1250. switch (ans.position)
  1251. {
  1252. case 1:
  1253. ctx->Ans.CardIssuerPos = -1;
  1254. break;
  1255. case 2:
  1256. ctx->Ans.CardIssuerPos = 1;
  1257. break;
  1258. default:
  1259. break;
  1260. }
  1261. }
  1262. }
  1263. if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK() && m_busCtx.eCardFromWhich == Card_In_ContactlessCard)
  1264. {
  1265. ContactlessCardService_QueryCardInfo_Req req;
  1266. ContactlessCardService_QueryCardInfo_Ans ans;
  1267. eErr = m_pContactless->QueryCardInfo(req, ans, 10000, dwUsrErrCode);
  1268. if (eErr == Error_Succeed)
  1269. {
  1270. switch (ans.position)//oiltmp to add
  1271. {
  1272. case 2:
  1273. break;
  1274. case 3:
  1275. break;
  1276. case 4:
  1277. ctx->Ans.ContactlessCardPos = 1;
  1278. break;
  1279. default:
  1280. break;
  1281. }
  1282. }
  1283. else
  1284. ctx->Ans.ContactlessCardPos = -1;
  1285. }
  1286. if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
  1287. {
  1288. CardSwiperService_QueryCardInfo_Req req;
  1289. CardSwiperService_QueryCardInfo_Ans ans;
  1290. eErr = m_pCardSwiper->QueryCardInfo(req, ans, 10000, dwUsrErrCode);
  1291. if (eErr == Error_Succeed)
  1292. {
  1293. switch (ans.position)
  1294. {
  1295. case 2:
  1296. ctx->Ans.CardSwiperPos = 1;
  1297. break;
  1298. case 3:
  1299. ctx->Ans.CardSwiperPos = 2;
  1300. break;
  1301. case 4:
  1302. ctx->Ans.CardSwiperPos = 3;
  1303. break;
  1304. case 6:
  1305. ctx->Ans.CardSwiperPos = 4;
  1306. break;
  1307. default:
  1308. break;
  1309. }
  1310. }
  1311. else
  1312. ctx->Ans.CardSwiperPos = -1;
  1313. }
  1314. ctx->Answer(Error_Succeed);
  1315. Dbg("%d,position(CI,CC,CS) %d,%d,%d", m_busCtx.eCardFromWhich, ctx->Ans.CardIssuerPos, ctx->Ans.ContactlessCardPos, ctx->Ans.CardSwiperPos);
  1316. return 0;
  1317. }
  1318. void CCardReadAdapterFSM::CheckAndReconnectSession()
  1319. {
  1320. ErrorCodeEnum eErr = Error_Unexpect;
  1321. int cardIssuerCount = 0, contactlessCardCount = 0, cardSwiperCount = 0;
  1322. while (1)
  1323. {
  1324. //the first time to connect or need to reconnect
  1325. //CardIssuer
  1326. if (!m_bRVCIL && (m_pCardIssuer == NULL || (m_pCardIssuer != NULL && m_pCardIssuer->QuerySessionClosed())))
  1327. {
  1328. if (m_pCardIssuer != NULL)
  1329. {
  1330. //m_pCardIssuer->SafeDelete();
  1331. m_pCardIssuer = NULL;
  1332. }
  1333. m_pCardIssuer = new CardIssuerService_ClientBase(GetEntityBase());
  1334. if (m_pCardIssuer != NULL)
  1335. {
  1336. eErr = m_pCardIssuer->Connect();
  1337. if (eErr != Error_Succeed)
  1338. {
  1339. if (cardIssuerCount%120 == 0)//about 10 minutes can't connect to entity
  1340. Dbg("connect to entity CardIssuer failed.%d", eErr);
  1341. cardIssuerCount++;
  1342. //m_pCardIssuer->SafeDelete();
  1343. m_pCardIssuer = NULL;
  1344. }
  1345. else
  1346. {
  1347. cardIssuerCount = 0;
  1348. Dbg("Connect to entity CardIssuer suc.");
  1349. }
  1350. }
  1351. }
  1352. //ContactlessCard
  1353. if (!m_bRVCIL && (m_eMachineType != MachineType_RVC_PAD && m_eMachineType != MachineType_RVC_Wall && m_eMachineType != MachineType_RPM_Stand1S)
  1354. && (m_pContactless == NULL || (m_pContactless != NULL && m_pContactless->QuerySessionClosed())))
  1355. {
  1356. if (m_pContactless != NULL)
  1357. {
  1358. //m_pContactless->SafeDelete();
  1359. m_pContactless = NULL;
  1360. }
  1361. m_pContactless = new ContactlessCardService_ClientBase(GetEntityBase());
  1362. if (m_pContactless != NULL)
  1363. {
  1364. eErr = m_pContactless->Connect();
  1365. if (eErr != Error_Succeed)
  1366. {
  1367. if (contactlessCardCount % 120 == 0)//about 10 minutes can't connect to entity
  1368. Dbg("connect to entity ContactlessCard failed.%d", eErr);
  1369. contactlessCardCount++;
  1370. //m_pContactless->SafeDelete();
  1371. m_pContactless = NULL;
  1372. }
  1373. else
  1374. {
  1375. contactlessCardCount = 0;
  1376. Dbg("Connect to entity ContactlessCard suc.");
  1377. }
  1378. }
  1379. }
  1380. //CardSwiper
  1381. if (!m_bRVCIL && m_eMachineType != MachineType_RVC_Stand2S &&(m_pCardSwiper == NULL || (m_pCardSwiper != NULL && m_pCardSwiper->QuerySessionClosed())))
  1382. {
  1383. if (m_pCardSwiper != NULL)
  1384. {
  1385. //m_pCardSwiper->SafeDelete();
  1386. m_pCardSwiper = NULL;
  1387. }
  1388. m_pCardSwiper = new CardSwiperService_ClientBase(GetEntityBase());
  1389. if (m_pCardSwiper != NULL)
  1390. {
  1391. eErr = m_pCardSwiper->Connect();
  1392. if (eErr != Error_Succeed)
  1393. {
  1394. if (cardSwiperCount%120 == 0)//about 10 minutes can't connect to entity
  1395. Dbg("connect to entity CardSwiper failed.%d", eErr);
  1396. cardSwiperCount++;
  1397. //m_pCardSwiper->SafeDelete();
  1398. m_pCardSwiper = NULL;
  1399. }
  1400. else
  1401. {
  1402. cardSwiperCount = 0;
  1403. Dbg("Connect to entity CardSwiper suc.");
  1404. //CUUID uuidCSMsg;
  1405. //GetEntityBase()->GetFunction()->SubscribeBroadcast("CardSwiper", "", (IBroadcastListener*)m_pEty, uuidCSMsg);
  1406. }
  1407. }
  1408. }
  1409. Sleep(5000);
  1410. }
  1411. }
  1412. bool CCardReadAdapterFSM::IsCardIssuerSessionOK()
  1413. {
  1414. if (m_pCardIssuer != NULL && !m_pCardIssuer->QuerySessionClosed())
  1415. return true;
  1416. return false;
  1417. }
  1418. bool CCardReadAdapterFSM::IsContactlessCardSessionOK()
  1419. {
  1420. if (m_pContactless != NULL && !m_pContactless->QuerySessionClosed())
  1421. return true;
  1422. return false;
  1423. }
  1424. bool CCardReadAdapterFSM::IsCardSwiperSessionOK()
  1425. {
  1426. if (m_pCardSwiper != NULL && !m_pCardSwiper->QuerySessionClosed())
  1427. return true;
  1428. return false;
  1429. }
  1430. bool CCardReadAdapterFSM::IsTheEntity(int module,ModuleType eModule)
  1431. {
  1432. if (module == 0)
  1433. return true;
  1434. //oilyang@20180409 add req.module==99
  1435. else if (module == 99)
  1436. {
  1437. Dbg("req.module is 99,machineType is:%s",(const char*)m_csMachineType);
  1438. //oilyang@20200730 according to meeting with Ratail/Test/Hangzhou
  1439. //Desk2S 2.1 can insert into CardIssuer
  1440. //oilyang@20200612 if "RVC.Desk2S" ,no need to call CardIssuer(insert card)
  1441. //from guodan 20180905
  1442. //99:进卡读卡,功能集向除蓝牙发卡机之外的读卡实体发出进卡读卡指令。
  1443. if (eModule == Module_CardIssuer)
  1444. {
  1445. if (m_eMachineType == MachineType_RVC_Stand2S
  1446. || m_eMachineType == MachineType_RVC_CardStore
  1447. || m_eMachineType == MachineType_RVC_DESK1S
  1448. || m_eMachineType == MachineType_RVC_DESK2S && m_majorVerion == 2 && m_minorVerion == 1)
  1449. return true;
  1450. else
  1451. return false;
  1452. }
  1453. else
  1454. return true;
  1455. }
  1456. else if ((module&eModule) == eModule)
  1457. return true;
  1458. else
  1459. return false;
  1460. }
  1461. int CCardReadAdapterFSM::SetSomeFlag(SpReqAnsContext<CardReadAdapterService_SetSomeFlag_Req, CardReadAdapterService_SetSomeFlag_Ans>::Pointer ctx)
  1462. {
  1463. LOG_FUNCTION();
  1464. if (IsCardIssuerSessionOK())
  1465. {
  1466. CardIssuerService_SetSomeFlag_Req req;
  1467. CardIssuerService_SetSomeFlag_Ans ans;
  1468. req.IssueBusiness = ctx->Req.IssueBusiness;
  1469. req.reserved1.Init(ctx->Req.reserved1.GetCount());
  1470. for (int i = 0; i < ctx->Req.reserved1.GetCount(); ++i)
  1471. {
  1472. req.reserved1[i] = ctx->Req.reserved1[i];
  1473. }
  1474. ErrorCodeEnum eErr = m_pCardIssuer->SetSomeFlag(req, ans,10000);
  1475. Dbg("CardIssuer SetSomeFlag ret:%d",eErr);
  1476. if (eErr == Error_Succeed)
  1477. {
  1478. ctx->Ans.reserved1.Copy(ans.reserved1);
  1479. ctx->Ans.reserved2.Copy(ans.reserved2);
  1480. ctx->Answer(Error_Succeed);
  1481. }
  1482. else
  1483. ctx->Answer(Error_Unexpect);
  1484. }
  1485. else
  1486. {
  1487. Dbg("SetSomeFlag can only apply to CardIssuer.Or CardIssuer connected failed.");
  1488. ctx->Answer(Error_Unexpect);
  1489. }
  1490. return 0;
  1491. }
  1492. int CCardReadAdapterFSM::GetDevInfo(SpReqAnsContext<CardReadAdapterService_GetDevInfo_Req, CardReadAdapterService_GetDevInfo_Ans>::Pointer ctx)
  1493. {
  1494. LOG_FUNCTION();
  1495. CSimpleStringA csCIType(""), csCIModel(""), csCIVersion(""), csCCType(""), csCCModel(""), csCCVersion(""), csCSType(""), csCSModel(""), csCSVersion("");
  1496. int ciState, ccState, csState;
  1497. bool bCI(false), bCC(false), bCS(false);
  1498. ErrorCodeEnum eErr = Error_Unexpect;
  1499. int count = 0;
  1500. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
  1501. {
  1502. CardIssuerService_GetDevInfo_Req req;
  1503. CardIssuerService_GetDevInfo_Ans ans;
  1504. eErr = m_pCardIssuer->GetDevInfo(req, ans, 10000);
  1505. if (eErr == Error_Succeed)
  1506. {
  1507. bCI = true;
  1508. count++;
  1509. csCIType = ans.type;
  1510. csCIModel = ans.model;
  1511. csCIVersion = ans.version;
  1512. ciState = ans.state;
  1513. }
  1514. }
  1515. if (IsTheEntity(ctx->Req.module, Module_ContactlessCard) && IsContactlessCardSessionOK())
  1516. {
  1517. ContactlessCardService_GetDevInfo_Req req;
  1518. ContactlessCardService_GetDevInfo_Ans ans;
  1519. eErr = m_pContactless->GetDevInfo(req, ans, 10000);
  1520. if (eErr == Error_Succeed)
  1521. {
  1522. bCC = true;
  1523. count++;
  1524. csCCType = ans.type;
  1525. csCCModel = ans.model;
  1526. csCCVersion = ans.version;
  1527. ccState = ans.state;
  1528. }
  1529. }
  1530. if (IsTheEntity(ctx->Req.module, Module_CardSwiper) && IsCardSwiperSessionOK())
  1531. {
  1532. CardSwiperService_GetDevInfo_Req req;
  1533. CardSwiperService_GetDevInfo_Ans ans;
  1534. eErr = m_pCardSwiper->GetDevInfo(req, ans, 10000);
  1535. if (eErr == Error_Succeed)
  1536. {
  1537. bCS = true;
  1538. count++;
  1539. csCSType = ans.type;
  1540. csCSModel = ans.model;
  1541. csCSVersion = ans.version;
  1542. csState = ans.state;
  1543. }
  1544. }
  1545. ctx->Ans.ModuleNum = count;
  1546. ctx->Ans.type.Init(count);
  1547. ctx->Ans.model.Init(count);
  1548. ctx->Ans.version.Init(count);
  1549. ctx->Ans.state.Init(count);
  1550. int index = 0;
  1551. Dbg("count:%d,index:%d,%d,%d,%d",count,index,bCI,bCC,bCS);
  1552. if (bCI)
  1553. {
  1554. ctx->Ans.ModuleSN = Module_CardIssuer;
  1555. ctx->Ans.type[index] = csCIType;
  1556. ctx->Ans.model[index] = csCIModel;
  1557. ctx->Ans.version[index] = csCIVersion;
  1558. ctx->Ans.state[index] = ciState;
  1559. Dbg("CardIssuer,type:%s,model:%s,version:%s,state:%d", (const char*)csCIType, (const char*)csCIModel
  1560. , (const char*)csCIVersion, ciState);
  1561. index++;
  1562. }
  1563. if (bCC)
  1564. {
  1565. ctx->Ans.ModuleSN = Module_ContactlessCard;
  1566. ctx->Ans.type[index] = csCCType;
  1567. ctx->Ans.model[index] = csCCModel;
  1568. ctx->Ans.version[index] = csCCVersion;
  1569. ctx->Ans.state[index] = ccState;
  1570. Dbg("ContactlessCard,type:%s,model:%s,version:%s,state:%d", (const char*)csCCType, (const char*)csCCModel
  1571. , (const char*)csCCVersion, ccState);
  1572. index++;
  1573. }
  1574. if (bCS)
  1575. {
  1576. ctx->Ans.ModuleSN = Module_CardSwiper;
  1577. ctx->Ans.type[index] = csCSType;
  1578. ctx->Ans.model[index] = csCSModel;
  1579. ctx->Ans.version[index] = csCSVersion;
  1580. ctx->Ans.state[index] = csState;
  1581. Dbg("CardSwiper,type:%s,model:%s,version:%s,state:%d", (const char*)csCSType, (const char*)csCSModel
  1582. , (const char*)csCSVersion, csState);
  1583. index++;
  1584. }
  1585. ctx->Answer(Error_Succeed);
  1586. return 0;
  1587. }
  1588. int CCardReadAdapterFSM::GetMaterialCount(SpReqAnsContext<CardReadAdapterService_GetMaterialCount_Req, CardReadAdapterService_GetMaterialCount_Ans>::Pointer ctx)
  1589. {
  1590. LOG_FUNCTION();
  1591. DWORD dwUsrErrCode = 0;
  1592. if (IsCardIssuerSessionOK())
  1593. {
  1594. CardIssuerService_GetMaterialCountEx_Req req;
  1595. CardIssuerService_GetMaterialCountEx_Ans ans;
  1596. req.GetHopper.Copy(ctx->Req.GetHopper);
  1597. req.reserved1.Copy(ctx->Req.reserved1);
  1598. req.reserved2.Copy(ctx->Req.reserved2);
  1599. ErrorCodeEnum eErr = m_pCardIssuer->GetMaterialCountEx(req, ans, 10000, dwUsrErrCode);
  1600. if (eErr == Error_Succeed)
  1601. {
  1602. ctx->Ans.captured = ans.captured;
  1603. ctx->Ans.hasHopper.Copy(ans.hasHopper);
  1604. ctx->Ans.CardBoxNo.Copy(ans.CardBoxNo);
  1605. ctx->Ans.PsbCode.Copy(ans.PsbCode);
  1606. ctx->Ans.PsbName.Copy(ans.PsbName);
  1607. ctx->Ans.Maintainer.Copy(ans.Maintainer);
  1608. ctx->Ans.CardInit.Copy(ans.CardInit);
  1609. ctx->Ans.CardPercent.Copy(ans.CardPercent);
  1610. ctx->Ans.remains.Copy(ans.remains);
  1611. ctx->Ans.issued.Copy(ans.issued);
  1612. ctx->Ans.mixed.Copy(ans.mixed);
  1613. ctx->Ans.MaintainTime.Copy(ans.MaintainTime);
  1614. ctx->Ans.reserved1.Copy(ans.reserved1);
  1615. ctx->Ans.reserved2.Copy(ans.reserved2);
  1616. ctx->Answer(Error_Succeed);
  1617. }
  1618. else
  1619. ctx->Answer(Error_Unexpect, dwUsrErrCode);
  1620. }
  1621. else
  1622. {
  1623. Dbg("GetMaterialCountEx can only apply to CardIssuer.Or CardIssuer connected failed.");
  1624. ctx->Answer(Error_Unexpect);
  1625. }
  1626. return 0;
  1627. }
  1628. int CCardReadAdapterFSM::SetMaterialCount(SpReqAnsContext<CardReadAdapterService_SetMaterialCount_Req, CardReadAdapterService_SetMaterialCount_Ans>::Pointer ctx)
  1629. {
  1630. LOG_FUNCTION();
  1631. DWORD dwUsrErrCode = 0;
  1632. if (IsCardIssuerSessionOK())
  1633. {
  1634. CardIssuerService_SetMaterialCountEx_Req req;
  1635. CardIssuerService_SetMaterialCountEx_Ans ans;
  1636. req.SetCaptured = ctx->Req.SetCaptured;
  1637. req.captured = ctx->Req.captured;
  1638. req.SetHopper.Copy(ctx->Req.SetHopper);
  1639. req.CardBoxNo.Copy(ctx->Req.CardBoxNo);
  1640. req.PsbCode.Copy(ctx->Req.PsbCode);
  1641. req.PsbName.Copy(ctx->Req.PsbName);
  1642. req.Maintainer.Copy(ctx->Req.Maintainer);
  1643. req.MaintainTime.Copy(ctx->Req.MaintainTime);
  1644. req.CardInit.Copy(ctx->Req.CardInit);
  1645. req.CardPercent.Copy(ctx->Req.CardPercent);
  1646. req.remains.Copy(ctx->Req.remains);
  1647. req.issued.Copy(ctx->Req.issued);
  1648. req.mixed.Copy(ctx->Req.mixed);
  1649. req.reserved1.Copy(ctx->Req.reserved1);
  1650. req.reserved2.Copy(ctx->Req.reserved2);
  1651. ErrorCodeEnum eErr = m_pCardIssuer->SetMaterialCountEx(req, ans, 10000, dwUsrErrCode);
  1652. if (eErr == Error_Succeed)
  1653. {
  1654. ctx->Ans.reserved1.Copy(ans.reserved1);
  1655. ctx->Ans.reserved2.Copy(ans.reserved2);
  1656. ctx->Answer(Error_Succeed);
  1657. }
  1658. else
  1659. ctx->Answer(Error_Unexpect, dwUsrErrCode);
  1660. }
  1661. else
  1662. {
  1663. Dbg("SetMaterialCountEx can only apply to CardIssuer.Or CardIssuer connected failed.");
  1664. ctx->Answer(Error_Unexpect);
  1665. }
  1666. return 0;
  1667. }
  1668. int CCardReadAdapterFSM::GetSCIInfo(SpReqAnsContext<CardReadAdapterService_GetSCIInfo_Req, CardReadAdapterService_GetSCIInfo_Ans>::Pointer ctx)
  1669. {
  1670. if (IsCardIssuerSessionOK())
  1671. {
  1672. ErrorCodeEnum eErr = Error_Unexpect;
  1673. CardIssuerService_GetSCIInfo_Req req;
  1674. CardIssuerService_GetSCIInfo_Ans ans;
  1675. eErr = m_pCardIssuer->GetSCIInfo(req, ans, 15000);
  1676. if (eErr == Error_Succeed)
  1677. {
  1678. ctx->Ans.connected = ans.connected;
  1679. ctx->Ans.DevSN = ans.DevSN;
  1680. ctx->Ans.reserved1.Copy(ans.reserved1);
  1681. ctx->Ans.reserved2.Copy(ans.reserved2);
  1682. }
  1683. ctx->Answer(eErr);
  1684. }
  1685. else
  1686. {
  1687. Dbg("Entity CardIssuer is not ok.");
  1688. ctx->Answer(Error_Unexpect);
  1689. }
  1690. return 0;
  1691. }
  1692. int CCardReadAdapterFSM::OpenSafeLock(SpReqAnsContext<CardReadAdapterService_OpenSafeLock_Req, CardReadAdapterService_OpenSafeLock_Ans>::Pointer ctx)
  1693. {
  1694. LOG_FUNCTION();
  1695. if (IsCardIssuerSessionOK())
  1696. {
  1697. ErrorCodeEnum eErr = Error_Unexpect;
  1698. CardIssuerService_OpenSafeLock_Req req;
  1699. CardIssuerService_OpenSafeLock_Ans ans;
  1700. req.reserved1.Copy(ctx->Req.reserved1);
  1701. req.reserved2.Copy(ctx->Req.reserved2);
  1702. eErr = m_pCardIssuer->OpenSafeLock(req, ans, 15000);
  1703. if (eErr == Error_Succeed)
  1704. {
  1705. ctx->Ans.reserved1.Copy(ans.reserved1);
  1706. ctx->Ans.reserved2.Copy(ans.reserved2);
  1707. }
  1708. ctx->Answer(eErr);
  1709. }
  1710. else
  1711. {
  1712. Dbg("Entity CardIssuer is not ok.");
  1713. ctx->Answer(Error_Unexpect);
  1714. }
  1715. return 0;
  1716. }
  1717. int CCardReadAdapterFSM::MagTransferInit(SpReqAnsContext<CardReadAdapterService_MagTransferInit_Req, CardReadAdapterService_MagTransferInit_Ans>::Pointer ctx)
  1718. {
  1719. LOG_FUNCTION();
  1720. if (IsCardSwiperSessionOK())
  1721. {
  1722. ErrorCodeEnum eErr = Error_Unexpect;
  1723. CardSwiperService_MagTransferInit_Req req;
  1724. CardSwiperService_MagTransferInit_Ans ans;
  1725. req.data = ctx->Req.data;
  1726. eErr = m_pCardSwiper->MagTransferInit(req, ans, 15000);
  1727. if (eErr == Error_Succeed)
  1728. {
  1729. ctx->Ans.ex = ans.ex;
  1730. ctx->Ans.result = ans.result;
  1731. }
  1732. ctx->Answer(eErr);
  1733. }
  1734. else
  1735. {
  1736. Dbg("Entity CardSwiper is not ok.");
  1737. ctx->Answer(Error_Unexpect);
  1738. }
  1739. return 0;
  1740. }
  1741. int CCardReadAdapterFSM::QueryConnInfo(SpReqAnsContext<CardReadAdapterService_QueryConnInfo_Req, CardReadAdapterService_QueryConnInfo_Ans>::Pointer ctx)
  1742. {
  1743. if (IsCardSwiperSessionOK())
  1744. {
  1745. ErrorCodeEnum eErr = Error_Unexpect;
  1746. CardSwiperService_QueryConnInfo_Req req;
  1747. CardSwiperService_QueryConnInfo_Ans ans;
  1748. eErr = m_pCardSwiper->QueryConnInfo(req, ans, 15000);
  1749. if (eErr == Error_Succeed)
  1750. {
  1751. ctx->Ans.connect = ans.connect;
  1752. ctx->Ans.reserved1 = ans.reserved1;
  1753. ctx->Ans.reserved2 = ans.reserved2;
  1754. }
  1755. ctx->Answer(eErr);
  1756. }
  1757. else
  1758. {
  1759. Dbg("Entity CardSwiper is not ok.");
  1760. ctx->Answer(Error_Unexpect);
  1761. }
  1762. return 0;
  1763. }
  1764. void CCardReadAdapterFSM::DoExit()
  1765. {
  1766. ErrorCodeEnum eErr = Error_Unexpect;
  1767. if (IsCardIssuerSessionOK())
  1768. {
  1769. eErr = m_pCardIssuer->Exit();
  1770. }
  1771. if (IsContactlessCardSessionOK())
  1772. {
  1773. eErr = m_pContactless->Exit();
  1774. }
  1775. if (IsCardSwiperSessionOK())
  1776. {
  1777. eErr = m_pCardSwiper->Exit();
  1778. }
  1779. }
  1780. void CCardReadAdapterFSM::BroadcastReadICing(int status)
  1781. {
  1782. ReadICing evt;
  1783. evt.status = status;
  1784. SpSendBroadcast(GetEntityBase()->GetFunction(), SP_MSG_OF(ReadICing), SP_MSG_SIG_OF(ReadICing), evt);
  1785. }
  1786. int CCardReadAdapterFSM::SAMICCommand(SpReqAnsContext<CardReadAdapterService_SAMICCommand_Req, CardReadAdapterService_SAMICCommand_Ans>::Pointer ctx)
  1787. {
  1788. if (IsTheEntity(ctx->Req.module, Module_CardIssuer) && IsCardIssuerSessionOK())
  1789. {
  1790. ErrorCodeEnum eErr = Error_Unexpect;
  1791. CardIssuerService_SAMICCommand_Req req;
  1792. CardIssuerService_SAMICCommand_Ans ans;
  1793. req.cmdType = ctx->Req.cmdType;
  1794. req.param1.Copy(ctx->Req.param1);
  1795. req.param2.Copy(ctx->Req.param2);
  1796. req.reserved1.Copy(ctx->Req.reserved1);
  1797. req.reserved2.Copy(ctx->Req.reserved2);
  1798. eErr = m_pCardIssuer->SAMICCommand(req, ans, 50000);
  1799. if (eErr == Error_Succeed)
  1800. {
  1801. ctx->Ans.ret1.Copy(ans.ret1);
  1802. ctx->Ans.ret2.Copy(ans.ret2);
  1803. ctx->Ans.reserved1.Copy(ans.reserved1);
  1804. ctx->Ans.reserved2.Copy(ans.reserved2);
  1805. }
  1806. ctx->Answer(eErr);
  1807. return 0;
  1808. }
  1809. else
  1810. {
  1811. Dbg("SAMICCommand param error or connection is failed:(module)%d", ctx->Req.module);
  1812. ctx->Answer(Error_Param);
  1813. return 1;
  1814. }
  1815. }
  1816. int CCardReadAdapterFSM::QueryPrinterStatus(SpReqAnsContext<CardReadAdapterService_QueryPrinterStatus_Req, CardReadAdapterService_QueryPrinterStatus_Ans>::Pointer ctx)
  1817. {
  1818. LOG_FUNCTION();
  1819. if (IsCardIssuerSessionOK())
  1820. {
  1821. ErrorCodeEnum eErr = Error_Unexpect;
  1822. CardIssuerService_QueryPrinterStatus_Req req;
  1823. CardIssuerService_QueryPrinterStatus_Ans ans;
  1824. req.param1.Copy(ctx->Req.param1);
  1825. req.param2.Copy(ctx->Req.param2);
  1826. req.reserved1.Copy(ctx->Req.reserved1);
  1827. req.reserved2.Copy(ctx->Req.reserved2);
  1828. eErr = m_pCardIssuer->QueryPrinterStatus(req, ans, 20000);
  1829. if (eErr == Error_Succeed)
  1830. {
  1831. ctx->Ans.ret1.Copy(ans.ret1);
  1832. ctx->Ans.ret2.Copy(ans.ret2);
  1833. ctx->Ans.reserved1.Copy(ans.reserved1);
  1834. ctx->Ans.reserved2.Copy(ans.reserved2);
  1835. }
  1836. ctx->Answer(eErr);
  1837. return 0;
  1838. }
  1839. else
  1840. {
  1841. Dbg("CardIssuer session is not ok.");
  1842. ctx->Answer(Error_Param);
  1843. return 1;
  1844. }
  1845. }
  1846. int CCardReadAdapterFSM::Print(SpReqAnsContext<CardReadAdapterService_Print_Req, CardReadAdapterService_Print_Ans>::Pointer ctx)
  1847. {
  1848. LOG_FUNCTION();
  1849. if (IsCardIssuerSessionOK())
  1850. {
  1851. ErrorCodeEnum eErr = Error_Unexpect;
  1852. CardIssuerService_Print_Req req;
  1853. CardIssuerService_Print_Ans ans;
  1854. req.data1 = ctx->Req.data1;
  1855. req.data2 = ctx->Req.data2;
  1856. req.data3 = ctx->Req.data3;
  1857. req.data4 = ctx->Req.data4;
  1858. req.data5 = ctx->Req.data5;
  1859. req.data6 = ctx->Req.data6;
  1860. req.reserved1.Copy(ctx->Req.reserved1);
  1861. req.reserved2.Copy(ctx->Req.reserved2);
  1862. eErr = m_pCardIssuer->Print(req, ans, 50000);
  1863. if (eErr == Error_Succeed)
  1864. {
  1865. ctx->Ans.reserved1.Copy(ans.reserved1);
  1866. ctx->Ans.reserved2.Copy(ans.reserved2);
  1867. }
  1868. ctx->Answer(eErr);
  1869. return 0;
  1870. }
  1871. else
  1872. {
  1873. Dbg("CardIssuer session is not ok.");
  1874. ctx->Answer(Error_Param);
  1875. return 1;
  1876. }
  1877. }
  1878. int CCardReadAdapterFSM::QuerySCIList(SpReqAnsContext<CardReadAdapterService_QuerySCIList_Req, CardReadAdapterService_QuerySCIList_Ans>::Pointer ctx)
  1879. {
  1880. LOG_FUNCTION();
  1881. DWORD dwUsrErrCode = 0;
  1882. if (IsCardIssuerSessionOK())
  1883. {
  1884. ErrorCodeEnum eErr = Error_Unexpect;
  1885. CardIssuerService_QuerySCIList_Req req;
  1886. CardIssuerService_QuerySCIList_Ans ans;
  1887. req.reserved1.Copy(ctx->Req.reserved1);
  1888. req.reserved2.Copy(ctx->Req.reserved2);
  1889. eErr = m_pCardIssuer->QuerySCIList(req, ans, 50000, dwUsrErrCode);
  1890. if (eErr == Error_Succeed)
  1891. {
  1892. ctx->Ans.sciNo.Copy(ans.sciNo);
  1893. ctx->Ans.arrMateriel.Copy(ans.arrMateriel);
  1894. ctx->Ans.CardGroove.Copy(ans.CardGroove);
  1895. ctx->Ans.CardBoxNo.Copy(ans.CardBoxNo);
  1896. ctx->Ans.PsbCode.Copy(ans.PsbCode);
  1897. ctx->Ans.PsbName.Copy(ans.PsbName);
  1898. ctx->Ans.CardInit.Copy(ans.CardInit);
  1899. ctx->Ans.CardRemains.Copy(ans.CardRemains);
  1900. ctx->Ans.CardIssued.Copy(ans.CardIssued);
  1901. ctx->Ans.CardMixed.Copy(ans.CardMixed);
  1902. ctx->Ans.CardPercent.Copy(ans.CardPercent);
  1903. ctx->Ans.Maintainer.Copy(ans.Maintainer);
  1904. ctx->Ans.MaintainTime.Copy(ans.MaintainTime);
  1905. ctx->Ans.UpdateTime.Copy(ans.UpdateTime);
  1906. ctx->Ans.reserved1.Copy(ans.reserved1);
  1907. ctx->Ans.reserved2.Copy(ans.reserved2);
  1908. }
  1909. ctx->Answer(eErr, dwUsrErrCode);
  1910. return 0;
  1911. }
  1912. else
  1913. {
  1914. Dbg("CardIssuer session is not ok.");
  1915. ctx->Answer(Error_Param);
  1916. return 1;
  1917. }
  1918. }
  1919. int CCardReadAdapterFSM::BindSCI(SpReqAnsContext<CardReadAdapterService_BindSCI_Req, CardReadAdapterService_BindSCI_Ans>::Pointer ctx)
  1920. {
  1921. LOG_FUNCTION();
  1922. DWORD dwUsrErrCode = 0;
  1923. if (IsCardIssuerSessionOK())
  1924. {
  1925. ErrorCodeEnum eErr = Error_Unexpect;
  1926. CardIssuerService_BindSCI_Req req;
  1927. CardIssuerService_BindSCI_Ans ans;
  1928. req.type = ctx->Req.type;
  1929. req.sciNo = ctx->Req.sciNo;
  1930. req.reserved1.Copy(ctx->Req.reserved1);
  1931. req.reserved2.Copy(ctx->Req.reserved2);
  1932. eErr = m_pCardIssuer->BindSCI(req, ans, 50000, dwUsrErrCode);
  1933. if (eErr == Error_Succeed)
  1934. {
  1935. ctx->Ans.reserved1.Copy(ans.reserved1);
  1936. ctx->Ans.reserved2.Copy(ans.reserved2);
  1937. }
  1938. ctx->Answer(eErr, dwUsrErrCode);
  1939. return 0;
  1940. }
  1941. else
  1942. {
  1943. Dbg("CardIssuer session is not ok.");
  1944. ctx->Answer(Error_Param);
  1945. return 1;
  1946. }
  1947. }
  1948. int CCardReadAdapterFSM::PreOnlineOnStore(SpReqAnsContext<CardReadAdapterService_PreOnlineOnStore_Req, CardReadAdapterService_PreOnlineOnStore_Ans>::Pointer ctx)
  1949. {
  1950. LOG_FUNCTION();
  1951. if (IsCardIssuerSessionOK())
  1952. {
  1953. ErrorCodeEnum eErr = Error_Unexpect;
  1954. CardIssuerService_PreOnlineOnStore_Req req;
  1955. CardIssuerService_PreOnlineOnStore_Ans ans;
  1956. req.account = ctx->Req.account;
  1957. req.businessData = ctx->Req.businessData;
  1958. req.slot = ctx->Req.slot;
  1959. req.termNo = ctx->Req.termNo;
  1960. req.reserved1.Copy(ctx->Req.reserved1);
  1961. req.reserved2.Copy(ctx->Req.reserved2);
  1962. req.reserved3.Copy(ctx->Req.reserved3);
  1963. req.reserved4.Copy(ctx->Req.reserved4);
  1964. eErr = m_pCardIssuer->PreOnlineOnStore(req, ans, 63000);
  1965. if (eErr == Error_Succeed)
  1966. {
  1967. ctx->Ans.cardPos = ans.cardPos;
  1968. ctx->Ans.findCard = ans.findCard;
  1969. ctx->Ans.result = ans.result;
  1970. ctx->Ans.reserved1.Copy(ans.reserved1);
  1971. ctx->Ans.reserved2.Copy(ans.reserved2);
  1972. ctx->Ans.reserved3.Copy(ans.reserved3);
  1973. ctx->Ans.reserved4.Copy(ans.reserved4);
  1974. }
  1975. ctx->Answer(eErr);
  1976. }
  1977. else
  1978. {
  1979. Dbg("Entity CardIssuer is not ok.");
  1980. ctx->Answer(Error_Unexpect);
  1981. }
  1982. return 0;
  1983. }
  1984. int CCardReadAdapterFSM::NotifyPreonline(SpReqAnsContext<CardReadAdapterService_NotifyPreonline_Req, CardReadAdapterService_NotifyPreonline_Ans>::Pointer ctx)
  1985. {
  1986. LOG_FUNCTION();
  1987. if (IsCardIssuerSessionOK())
  1988. {
  1989. ErrorCodeEnum eErr = Error_Unexpect;
  1990. CardIssuerService_NotifyPreonline_Req req;
  1991. CardIssuerService_NotifyPreonline_Ans ans;
  1992. req.account = ctx->Req.account;
  1993. req.cardPos = ctx->Req.cardPos;
  1994. req.data = ctx->Req.data;
  1995. req.errCode = ctx->Req.errCode;
  1996. req.findCard = ctx->Req.findCard;
  1997. req.termNo = ctx->Req.termNo;
  1998. req.reserved1.Copy(ctx->Req.reserved1);
  1999. req.reserved2.Copy(ctx->Req.reserved2);
  2000. req.reserved3.Copy(ctx->Req.reserved3);
  2001. req.reserved4.Copy(ctx->Req.reserved4);
  2002. eErr = m_pCardIssuer->NotifyPreonline(req, ans, 100000);
  2003. if (eErr == Error_Succeed)
  2004. {
  2005. ctx->Ans.reserved1.Copy(ans.reserved1);
  2006. ctx->Ans.reserved2.Copy(ans.reserved2);
  2007. ctx->Ans.reserved3.Copy(ans.reserved3);
  2008. ctx->Ans.reserved4.Copy(ans.reserved4);
  2009. }
  2010. ctx->Answer(eErr);
  2011. }
  2012. else
  2013. {
  2014. Dbg("Entity CardIssuer is not ok.");
  2015. ctx->Answer(Error_Unexpect);
  2016. }
  2017. return 0;
  2018. }
  2019. int CCardReadAdapterFSM::QueryCardInfoOnStore(SpReqAnsContext<CardReadAdapterService_QueryCardInfoOnStore_Req, CardReadAdapterService_QueryCardInfoOnStore_Ans>::Pointer ctx)
  2020. {
  2021. LOG_FUNCTION();
  2022. if (IsCardIssuerSessionOK())
  2023. {
  2024. ErrorCodeEnum eErr = Error_Unexpect;
  2025. CardIssuerService_QueryCardInfoOnStore_Req req;
  2026. CardIssuerService_QueryCardInfoOnStore_Ans ans;
  2027. req.reserved1.Copy(ctx->Req.reserved1);
  2028. req.reserved2.Copy(ctx->Req.reserved2);
  2029. req.reserved3.Copy(ctx->Req.reserved3);
  2030. req.reserved4.Copy(ctx->Req.reserved4);
  2031. eErr = m_pCardIssuer->QueryCardInfoOnStore(req, ans, INT_MAX / 2 - 5000);
  2032. if (eErr == Error_Succeed)
  2033. {
  2034. ctx->Ans.cardPos = ans.cardPos;
  2035. ctx->Ans.findCard = ans.findCard;
  2036. ctx->Ans.reserved1.Copy(ans.reserved1);
  2037. ctx->Ans.reserved2.Copy(ans.reserved2);
  2038. ctx->Ans.reserved3.Copy(ans.reserved3);
  2039. ctx->Ans.reserved4.Copy(ans.reserved4);
  2040. }
  2041. ctx->Answer(eErr);
  2042. }
  2043. else
  2044. {
  2045. Dbg("Entity CardIssuer is not ok.");
  2046. ctx->Answer(Error_Unexpect);
  2047. }
  2048. return 0;
  2049. }
  2050. int CCardReadAdapterFSM::GetAddCardInfo(SpReqAnsContext<CardReadAdapterService_GetAddCardInfo_Req, CardReadAdapterService_GetAddCardInfo_Ans>::Pointer ctx)
  2051. {
  2052. LOG_FUNCTION();
  2053. if (IsCardIssuerSessionOK())
  2054. {
  2055. ErrorCodeEnum eErr = Error_Unexpect;
  2056. CardIssuerService_GetAddCardInfo_Req req;
  2057. CardIssuerService_GetAddCardInfo_Ans ans;
  2058. req.isSync = ctx->Req.isSync;
  2059. req.reserved1.Copy(ctx->Req.reserved1);
  2060. req.reserved2.Copy(ctx->Req.reserved2);
  2061. req.reserved3.Copy(ctx->Req.reserved3);
  2062. req.reserved4.Copy(ctx->Req.reserved4);
  2063. eErr = m_pCardIssuer->GetAddCardInfo(req, ans, 10000);
  2064. if (eErr == Error_Succeed)
  2065. {
  2066. ctx->Ans.account = ans.account;
  2067. ctx->Ans.cardSerial = ans.cardSerial;
  2068. ctx->Ans.count = ans.count;
  2069. ctx->Ans.slot = ans.slot;
  2070. ctx->Ans.reserved1.Copy(ans.reserved1);
  2071. ctx->Ans.reserved2.Copy(ans.reserved2);
  2072. ctx->Ans.reserved3.Copy(ans.reserved3);
  2073. ctx->Ans.reserved4.Copy(ans.reserved4);
  2074. }
  2075. ctx->Answer(eErr);
  2076. }
  2077. else
  2078. {
  2079. Dbg("Entity CardIssuer is not ok.");
  2080. ctx->Answer(Error_Unexpect);
  2081. }
  2082. return 0;
  2083. }
  2084. int CCardReadAdapterFSM::Test1(SpReqAnsContext<CardReadAdapterService_Test1_Req, CardReadAdapterService_Test1_Ans>::Pointer ctx)
  2085. {
  2086. LOG_FUNCTION();
  2087. ctx->Answer(Error_Succeed);
  2088. return 0;
  2089. }
  2090. int CCardReadAdapterFSM::Test2(SpReqAnsContext<CardReadAdapterService_Test2_Req, CardReadAdapterService_Test2_Ans>::Pointer ctx)
  2091. {
  2092. LOG_FUNCTION();
  2093. ctx->Answer(Error_Succeed);
  2094. return 0;
  2095. }
  2096. void CCardReadAdapterFSM::SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  2097. {
  2098. //for simple
  2099. pTransactionContext->SendAnswer(m_testResult);
  2100. }
  2101. int CCardReadAdapterFSM::CrossTermCall(SpReqAnsContext<CardReadAdapterService_CrossTermCall_Req, CardReadAdapterService_CrossTermCall_Ans>::Pointer cctx)
  2102. {
  2103. ErrorCodeEnum eErr = Error_Unexpect;
  2104. Dbg("CrossTermCall,type:%x", cctx->Req.type);
  2105. switch (cctx->Req.type)
  2106. {
  2107. case CardReadAdapterService_Method_Read:
  2108. {
  2109. int retErr;
  2110. DEFINE_PUPPET_CONTEXT_WITH_TYPE(CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans);
  2111. if ((eErr = SpBlob2Object(cctx->Req.paramX, ctx->Req)) == Error_Succeed) {
  2112. if (this->CardSwiperRead(ctx, retErr) != 0) {
  2113. eErr = Error_Unexpect;
  2114. }
  2115. else {
  2116. eErr = SpObject2Blob(ctx->Ans, cctx->Ans.retParamX);
  2117. Dbg("after CardSwiperRead,eErr:%d,retErr:%x,paramX.len:%d", eErr, retErr, cctx->Ans.retParamX.m_iLength);
  2118. }
  2119. }
  2120. cctx->Answer((ErrorCodeEnum)retErr);
  2121. }
  2122. break;
  2123. case CardReadAdapterService_Method_CancelRead:
  2124. m_bCancelAccept = true;
  2125. CancelRead();
  2126. break;
  2127. case CardReadAdapterService_Method_ReadWaitMore:
  2128. {
  2129. ReadWaitMoreTask* task = new ReadWaitMoreTask(this);
  2130. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  2131. }
  2132. break;
  2133. case CardReadAdapterService_Method_Exit:
  2134. DoExit();
  2135. break;
  2136. default:
  2137. break;
  2138. }
  2139. return 0;
  2140. }
  2141. void CCardReadAdapterFSM::CrossTermInvokeInfo(SpOnewayCallContext<CardReadAdapterService_CrossTermInvokeInfo_Info>::Pointer ctx)
  2142. {
  2143. LOG_FUNCTION();
  2144. Dbg("entity sn:%x,type:%d,errcode:%x", ctx->Info.nEntityID, ctx->Info.type, ctx->Info.result);
  2145. if (ctx->Info.paramX.m_iLength <= 1)
  2146. {
  2147. }
  2148. ErrorCodeEnum eErr = Error_Succeed;
  2149. CSmartPointer<ITransactionContext> pTransactionContext;
  2150. switch (ctx->Info.type)
  2151. {
  2152. case CardReadAdapterService_Method_Read:
  2153. {
  2154. auto pt = static_cast<SpReqAnsContext<CardReadAdapterService_Read_Req,
  2155. CardReadAdapterService_Read_Ans>*>(GetCtx(ctx->Info.type));
  2156. SpReqAnsContext<CardReadAdapterService_Read_Req,
  2157. CardReadAdapterService_Read_Ans>::Pointer xctx;
  2158. xctx.Attach(pt);
  2159. if (ctx->Info.paramX.m_iLength > 0)
  2160. eErr = SpBlob2Object(ctx->Info.paramX, xctx->Ans);
  2161. Dbg("eErr:%d,Y len:%d", eErr, ctx->Info.paramX.m_iLength);
  2162. xctx->Answer((ErrorCodeEnum)ctx->Info.result);
  2163. }
  2164. break;
  2165. default:
  2166. break;
  2167. }
  2168. }
  2169. int CCardReadAdapterFSM::LocalCallHeartBeat(int method, CBlob &bbSend,bool bTwoWay)
  2170. {
  2171. Dbg("method id(type):%d", method);
  2172. HeartBeatService_ClientBase* pClient = new HeartBeatService_ClientBase(GetEntityBase());
  2173. if (pClient == NULL)
  2174. {
  2175. Dbg("create HeartBeat client failed.GetLastError:%d", GetLastError());
  2176. return -1;
  2177. }
  2178. ErrorCodeEnum eErr = Error_Unexpect;
  2179. eErr = pClient->Connect();
  2180. if (eErr != Error_Succeed)
  2181. {
  2182. Dbg("client connect to HeartBeat failed:%x", eErr);
  2183. return -1;
  2184. }
  2185. HeartBeatService_CrossTermCall_Req req;
  2186. HeartBeatService_CrossTermCall_Ans ans;
  2187. req.nEntityID = 0x21b;
  2188. req.isTwoWay = bTwoWay;
  2189. req.fromTerminalNo = m_terminalNo;
  2190. GetAttachedTerminal(req.toTerminalNo);
  2191. //req.toTerminalNo = "7717715004";
  2192. req.param1 = "";
  2193. req.param2 = "";
  2194. req.paramX = bbSend;
  2195. req.type = method;
  2196. eErr = pClient->CrossTermCall(req, ans, 20000);
  2197. Dbg("CrossTermCall to HeartBeat from %s to %s, result:%x", (const char*)req.fromTerminalNo, (const char*)req.toTerminalNo, eErr);
  2198. return 0;
  2199. }
  2200. bool CCardReadAdapterFSM::GetAttachedTerminal(CSimpleStringA &csTerm)
  2201. {
  2202. return GetEntityBase()->GetFunction()->GetSysVar("AttachedTerminal", csTerm);
  2203. }
  2204. void CCardReadAdapterFSM::CancelReadForEntity(ModuleType eModule)
  2205. {
  2206. LOG_FUNCTION();
  2207. if (IsTheEntity(eModule, Module_CardIssuer) && IsCardIssuerSessionOK())
  2208. {
  2209. Dbg("Set cancel read by ContactlessCard flag of CardIssuer.");
  2210. CardIssuerService_SetSomeFlag_Req req;
  2211. CardIssuerService_SetSomeFlag_Ans ans;
  2212. req.IssueBusiness = 3;
  2213. m_pCardIssuer->SetSomeFlag(req,ans,5000);
  2214. }
  2215. if (IsTheEntity(eModule, Module_ContactlessCard) && IsContactlessCardSessionOK())
  2216. {
  2217. Dbg("Cancel read by CardSwiper of ContactlessCard.");
  2218. ContactlessCardService_CancelInsert_Info info;
  2219. m_pContactless->CancelInsert();
  2220. }
  2221. }