CardReadAdapterFSM.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. #ifndef __CARDREAD_ADAPTER_FSM_H
  2. #define __CARDREAD_ADAPTER_FSM_H
  3. #pragma once
  4. #include "SpFSM.h"
  5. #include "CardReadAdapter_server_g.h"
  6. #include "CardIssuerClass.h"
  7. #include "CardAssist.h"
  8. #include "ICDataElement.h"
  9. using namespace CardReadAdapter;
  10. #include "CardIssuer_client_g.h"
  11. #include "ContactlessCard_client_g.h"
  12. #include "CardSwiper_client_g.h"
  13. #include "CardIssuer_msg_g.h"
  14. #include "CardSwiper_msg_g.h"
  15. #include "ContactlessCard_msg_g.h"
  16. #include "CardReadAdapter_msg_g.h"
  17. #include "HeartBeat_client_g.h"
  18. #include "DeviceCrossHelper.h"
  19. #include <map>
  20. using namespace std;
  21. using namespace HeartBeat;
  22. using namespace CardIssuer;
  23. using namespace ContactlessCard;
  24. using namespace CardSwiper;
  25. struct CtxInfo
  26. {
  27. int dataSize;
  28. LPVOID pCtx;
  29. };
  30. enum EvtType
  31. {
  32. USER_EVT_TEST = EVT_USER + 1,
  33. USER_EVT_QUIT,
  34. USER_EVT_INIT,
  35. USER_EVT_INIT_FINISHED,
  36. // USER_EVT_CARD_ACCEPT,
  37. // USER_EVT_CARD_ACCEPT_FINISHED,
  38. USER_EVT_READ,
  39. USER_EVT_READ_FINISHED,
  40. USER_EVT_READ_CANCEL,
  41. USER_EVT_READ_WAIT_MORE,
  42. USER_EVT_PREONLINE,
  43. USER_EVT_POSTONLINE,
  44. USER_EVT_PREONLINE_FINISHED,
  45. USER_EVT_POSTONLINE_FINISHED,
  46. USER_EVT_EJECT,
  47. USER_EVT_EJECT_FINISHED,
  48. USER_EVT_ISSUE,
  49. USER_EVT_ISSUE_FINISHED,
  50. USER_EVT_CAPTURE,
  51. USER_EVT_WAITFINISHED,
  52. USER_EVT_CAPTUREFINISHED,
  53. USER_EVT_WAITFETCHINGTIMEOUT,
  54. USER_EVT_RESET,
  55. USER_EVT_RESETFINISHED,
  56. USER_EVT_EXIT,
  57. USER_EVT_WRITE,
  58. USER_EVT_WRITE_FINISHED,
  59. USER_EVT_SET_SOME_FLAG,
  60. USER_EVT_SET_SOME_FLAG_FINISHED,
  61. USER_EVT_GET_DEV_INFO,
  62. USER_EVT_GET_DEV_INFO_FINISHED,
  63. USER_EVT_QUERY_CARD_INFO,
  64. USER_EVT_QUERY_CARD_INFO_FINISHED,
  65. USER_EVT_GET_MATERIAL,
  66. USER_EVT_GET_MATERIAL_FINISHED,
  67. USER_EVT_SET_MATERIAL,
  68. USER_EVT_SET_MATERIAL_FINISHED,
  69. USER_EVT_GET_SCI_INFO,
  70. USER_EVT_GET_SCI_INFO_FINISHED,
  71. USER_EVT_OPEN_SAFELOCK,
  72. USER_EVT_OPEN_SAFELOCK_FINISHED,
  73. USER_EVT_MAGTRANS_INIT,
  74. USER_EVT_MAGTRANS_INIT_FINISHED,
  75. USER_EVT_QUERY_CONN_INFO,
  76. USER_EVT_QUERY_CONN_INFO_FINISHED,
  77. USER_EVT_SAM_IC_COMMAND,
  78. USER_EVT_SAM_IC_COMMAND_FINISHED,
  79. USER_EVT_PREONLINE_ON_STORE,
  80. USER_EVT_PREONLINE_ON_STORE_FINISHED,
  81. USER_EVT_GET_ADD_CARD_INFO,
  82. USER_EVT_GET_ADD_CARD_INFO_FINISHED,
  83. USER_EVT_NOTIFY_PREONLINE,
  84. USER_EVT_NOTIFY_PREONLINE_FINISHED,
  85. USER_EVT_QUERY_CARD_INFO_ON_STORE,
  86. USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED,
  87. USER_EVT_QUERY_PRINTER_STATUS,
  88. USER_EVT_QUERY_PRINTER_STATUS_FINISHED,
  89. USER_EVT_PRINT,
  90. USER_EVT_PRINT_FINISHED,
  91. USER_EVT_QUERY_SCILIST,
  92. USER_EVT_QUERY_SCILIST_FINISHED,
  93. USER_EVT_BIND_SCI,
  94. USER_EVT_BIND_SCI_FINISHED,
  95. USER_EVT_CROSS_TERM_CALL,
  96. USER_EVT_CROSS_TERM_CALL_FINISHED,
  97. USER_EVT_TEST1,
  98. USER_EVT_TEST1_FINISHED,
  99. USER_EVT_TEST2,
  100. USER_EVT_TEST2_FINISHED,
  101. };
  102. enum CardFromWhichEntity//卡片信息从哪个实体返回
  103. {
  104. Card_In_No_Where,
  105. Card_In_CardIssuer,
  106. Card_In_ContactlessCard,
  107. Card_In_CardSwiper,
  108. };
  109. struct BusinessContext
  110. {
  111. CardFromWhichEntity eCardFromWhich;
  112. };
  113. enum MachineType
  114. {
  115. MachineType_Unknown = 0,
  116. MachineType_RVC_Stand2S,
  117. MachineType_RVC_PAD,
  118. MachineType_RVC_Wall,
  119. MachineType_RPM_Stand1S,
  120. MachineType_RVC_CardStore,
  121. MachineType_RVC_DESK2S,
  122. MachineType_RVC_DESK1S,
  123. MachineType_RVC_IL,
  124. };
  125. enum ModuleType//从哪个实体读卡
  126. {
  127. Module_Any = 0,
  128. Module_CardIssuer = 1,
  129. Module_ContactlessCard = 2,
  130. Module_CardSwiper = 4,
  131. };
  132. enum CardPosType
  133. {
  134. CardPos_No_Card = 0,//0:检查超时,未发现设备有卡。
  135. CardPos_CardSwiper_Mag_Swipe,//1:CardSwiper刷卡
  136. CardPos_CardSwiper_IC_Insert,//2:CardSwiper插IC卡槽
  137. CardPos_CardSwiper_RFIC,//3 : CardSwiper非接卡
  138. CardPos_CardIssuer_Stand2S,//4:卡片在大机卡机里面
  139. CardPos_ContactlessCard,//5:卡片在大机非接上面
  140. CardPos_CardIssuer_Split,//6:卡片在便携发卡机里面
  141. //CardPos_No_Card = 0,//0:检查超时,未发现设备有卡。
  142. //CardPos_CardSwiper_Mag_OK,//1:CardSwiper刷卡且有磁道数据(至少有二磁道数据)
  143. //CardPos_CardSwiper_IC,//2:CardSwiper插IC卡
  144. //CardPos_CardSwiper_Mag_No_Track2,//3:CardSwiper刷卡,但二磁道数据缺失
  145. //CardPos_CardSwiper_RFIC,//4 : CardSwiper非接卡
  146. //CardPos_CardSwiper_Invalid,//5:CardSwiper插入接触卡, 卡面插反或无效卡
  147. //CardPos_CardSwiper_ID,//6:CardSwiper非接IC位发现身份证
  148. //CardPos_CardIssuer_Stand2S,//7:卡片在大机卡机里面
  149. //CardPos_ContactlessCard_OK,//8:卡片在大机非接上面
  150. //CardPos_ContactlessCard_ID,//9:在大机非接位发现身份证
  151. //CardPos_CardIssuer_Split,//10:卡片在便携发卡机里面
  152. };
  153. enum LightPos
  154. {
  155. LightPos_ALL = 0,
  156. LightPos_CardIssuer = 1,
  157. LightPos_ContactlessCard = 2,
  158. LightPos_CardSwiper_Mag = 4,
  159. LightPos_CardSwiper_IC = 8,
  160. LightPos_CardSwiper_RFIC = 16,
  161. LightPos_CardIssuer_Only_Mag = 32,
  162. };
  163. class CCardReadAdapterEntity;
  164. class CCardReadAdapterFSM;
  165. const int ONE_K = 1024;
  166. class CardIssueEvent : public FSMEvent
  167. {
  168. public:
  169. CardIssueEvent() : FSMEvent(USER_EVT_ISSUE){}
  170. ~CardIssueEvent(){}
  171. SpReqAnsContext<CardReadAdapterService_Issue_Req, CardReadAdapterService_Issue_Ans>::Pointer ctx;
  172. virtual void OnUnhandled()
  173. {
  174. if (ctx != NULL)
  175. {
  176. Dbg("card issue unhandled");
  177. ctx->Answer(Error_InvalidState);
  178. }
  179. }
  180. };
  181. //class CardAcceptEvent : public FSMEvent
  182. //{
  183. //public:
  184. // CardAcceptEvent() : FSMEvent(USER_EVT_CARD_ACCEPT){}
  185. // ~CardAcceptEvent(){}
  186. // SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx;
  187. // virtual void OnUnhandled()
  188. // {
  189. // if (ctx != NULL)
  190. // {
  191. // Dbg("card accept unhandled");
  192. // ctx->Answer(Error_InvalidState);
  193. // }
  194. // }
  195. //protected:
  196. //private:
  197. //};
  198. //class CardAcceptFinishedEvent : public FSMEvent
  199. //{
  200. //public:
  201. // CardAcceptFinishedEvent() : FSMEvent(USER_EVT_CARD_ACCEPT_FINISHED){}
  202. // ~CardAcceptFinishedEvent(){}
  203. // SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx;
  204. // virtual void OnUnhandled()
  205. // {
  206. // if (ctx != NULL)
  207. // {
  208. // Dbg("card accept finished unhandled");
  209. // ctx->Answer(Error_InvalidState);
  210. // }
  211. // }
  212. //protected:
  213. //private:
  214. //};
  215. class CancelReadEvent : public FSMEvent
  216. {
  217. public:
  218. CancelReadEvent() : FSMEvent(USER_EVT_READ_CANCEL){}
  219. ~CancelReadEvent(){}
  220. virtual void OnUnhandled()
  221. {
  222. Dbg("card cancel accept unhandled");
  223. }
  224. };
  225. class ReadWaitMoreEvent : public FSMEvent
  226. {
  227. public:
  228. ReadWaitMoreEvent() : FSMEvent(USER_EVT_READ_WAIT_MORE){}
  229. ~ReadWaitMoreEvent(){}
  230. virtual void OnUnhandled()
  231. {
  232. Dbg("ReadWaitMore unhandled");
  233. }
  234. };
  235. class CardReadEvent : public FSMEvent
  236. {
  237. public:
  238. CardReadEvent() : FSMEvent(USER_EVT_READ){}
  239. ~CardReadEvent(){}
  240. SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx;
  241. virtual void OnUnhandled()
  242. {
  243. if (ctx != NULL)
  244. {
  245. Dbg("card read unhandled");
  246. ctx->Answer(Error_InvalidState);
  247. }
  248. }
  249. protected:
  250. private:
  251. };
  252. class CardReadFinishedEvent : public FSMEvent
  253. {
  254. public:
  255. CardReadFinishedEvent() : FSMEvent(USER_EVT_READ_FINISHED){}
  256. ~CardReadFinishedEvent(){}
  257. SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx;
  258. virtual void OnUnhandled()
  259. {
  260. if (ctx != NULL)
  261. {
  262. Dbg("card read unhandled(new)");
  263. ctx->Answer(Error_InvalidState);
  264. }
  265. }
  266. protected:
  267. private:
  268. };
  269. class ResetDeviceEvent : public FSMEvent
  270. {
  271. public:
  272. ResetDeviceEvent() : FSMEvent(USER_EVT_RESET){}
  273. ~ResetDeviceEvent(){}
  274. protected:
  275. private:
  276. };
  277. class ResetFinishedEvent : public FSMEvent
  278. {
  279. public:
  280. ResetFinishedEvent() : FSMEvent(USER_EVT_RESETFINISHED){}
  281. ~ResetFinishedEvent(){}
  282. protected:
  283. private:
  284. };
  285. class PreOnlineEvent : public FSMEvent
  286. {
  287. public:
  288. PreOnlineEvent() : FSMEvent(USER_EVT_PREONLINE){}
  289. ~PreOnlineEvent(){}
  290. SpReqAnsContext<CardReadAdapterService_PreOnline_Req, CardReadAdapterService_PreOnline_Ans>::Pointer ctx;
  291. virtual void OnUnhandled()
  292. {
  293. if (ctx != NULL)
  294. ctx->Answer(Error_InvalidState);
  295. }
  296. protected:
  297. private:
  298. };
  299. class PostOnlineEvent : public FSMEvent
  300. {
  301. public:
  302. PostOnlineEvent() : FSMEvent(USER_EVT_POSTONLINE){}
  303. ~PostOnlineEvent(){}
  304. SpReqAnsContext<CardReadAdapterService_PostOnline_Req, CardReadAdapterService_PostOnline_Ans>::Pointer ctx;
  305. virtual void OnUnhandled()
  306. {
  307. if (ctx != NULL)
  308. ctx->Answer(Error_InvalidState);
  309. }
  310. protected:
  311. private:
  312. };
  313. class CardCaptureEvent : public FSMEvent
  314. {
  315. public:
  316. CardCaptureEvent() : FSMEvent(USER_EVT_CAPTURE){}
  317. ~CardCaptureEvent(){}
  318. SpReqAnsContext<CardReadAdapterService_Capture_Req, CardReadAdapterService_Capture_Ans>::Pointer ctx;
  319. virtual void OnUnhandled()
  320. {
  321. if (ctx != NULL)
  322. ctx->Answer(Error_InvalidState);
  323. }
  324. protected:
  325. private:
  326. };
  327. class CardEjectEvent : public FSMEvent
  328. {
  329. public:
  330. CardEjectEvent() : FSMEvent(USER_EVT_EJECT){}
  331. ~CardEjectEvent(){}
  332. SpReqAnsContext<CardReadAdapterService_Eject_Req, CardReadAdapterService_Eject_Ans>::Pointer ctx;
  333. virtual void OnUnhandled()
  334. {
  335. if (ctx != NULL)
  336. ctx->Answer(Error_InvalidState);
  337. }
  338. protected:
  339. private:
  340. };
  341. class CardWriteEvent : public FSMEvent
  342. {
  343. public:
  344. CardWriteEvent() : FSMEvent(USER_EVT_WRITE){}
  345. ~CardWriteEvent(){}
  346. SpReqAnsContext<CardReadAdapterService_WriteTrack_Req, CardReadAdapterService_WriteTrack_Ans>::Pointer ctx;
  347. virtual void OnUnhandled()
  348. {
  349. if (ctx != NULL)
  350. {
  351. Dbg("card read unhandled");
  352. ctx->Answer(Error_InvalidState);
  353. }
  354. }
  355. protected:
  356. private:
  357. };
  358. class CardWriteFinishedEvent : public FSMEvent
  359. {
  360. public:
  361. CardWriteFinishedEvent() : FSMEvent(USER_EVT_WRITE_FINISHED){}
  362. ~CardWriteFinishedEvent(){}
  363. SpReqAnsContext<CardReadAdapterService_WriteTrack_Req, CardReadAdapterService_WriteTrack_Ans>::Pointer ctx;
  364. virtual void OnUnhandled()
  365. {
  366. if (ctx != NULL)
  367. {
  368. Dbg("card read unhandled(new)");
  369. ctx->Answer(Error_InvalidState);
  370. }
  371. }
  372. };
  373. class SetSomeFlagEvent : public FSMEvent
  374. {
  375. public:
  376. SetSomeFlagEvent() : FSMEvent(USER_EVT_SET_SOME_FLAG){}
  377. ~SetSomeFlagEvent(){}
  378. SpReqAnsContext<CardReadAdapterService_SetSomeFlag_Req, CardReadAdapterService_SetSomeFlag_Ans>::Pointer ctx;
  379. virtual void OnUnhandled()
  380. {
  381. if (ctx != NULL)
  382. {
  383. Dbg("SetSomeFlag unhandled");
  384. ctx->Answer(Error_InvalidState);
  385. }
  386. }
  387. };
  388. class QueryCardInfoEvent : public FSMEvent
  389. {
  390. public:
  391. QueryCardInfoEvent() : FSMEvent(USER_EVT_QUERY_CARD_INFO){}
  392. ~QueryCardInfoEvent(){}
  393. SpReqAnsContext<CardReadAdapterService_QueryCardInfo_Req, CardReadAdapterService_QueryCardInfo_Ans>::Pointer ctx;
  394. virtual void OnUnhandled()
  395. {
  396. if (ctx != NULL)
  397. {
  398. Dbg("QueryCardInfo unhandled");
  399. ctx->Answer(Error_InvalidState);
  400. }
  401. }
  402. };
  403. class GetMaterialEvent : public FSMEvent
  404. {
  405. public:
  406. GetMaterialEvent() : FSMEvent(USER_EVT_GET_MATERIAL){}
  407. ~GetMaterialEvent(){}
  408. SpReqAnsContext<CardReadAdapterService_GetMaterialCount_Req, CardReadAdapterService_GetMaterialCount_Ans>::Pointer ctx;
  409. virtual void OnUnhandled()
  410. {
  411. if (ctx != NULL)
  412. ctx->Answer(Error_InvalidState);
  413. }
  414. protected:
  415. private:
  416. };
  417. class SetMaterialEvent : public FSMEvent
  418. {
  419. public:
  420. SetMaterialEvent() : FSMEvent(USER_EVT_SET_MATERIAL){}
  421. ~SetMaterialEvent(){}
  422. SpReqAnsContext<CardReadAdapterService_SetMaterialCount_Req, CardReadAdapterService_SetMaterialCount_Ans>::Pointer ctx;
  423. virtual void OnUnhandled()
  424. {
  425. if (ctx != NULL)
  426. ctx->Answer(Error_InvalidState);
  427. }
  428. protected:
  429. private:
  430. };
  431. class GetSCIInfoEvent : public FSMEvent
  432. {
  433. public:
  434. GetSCIInfoEvent() : FSMEvent(USER_EVT_GET_SCI_INFO){}
  435. ~GetSCIInfoEvent(){}
  436. SpReqAnsContext<CardReadAdapterService_GetSCIInfo_Req, CardReadAdapterService_GetSCIInfo_Ans>::Pointer ctx;
  437. virtual void OnUnhandled()
  438. {
  439. if (ctx != NULL)
  440. ctx->Answer(Error_InvalidState);
  441. }
  442. protected:
  443. private:
  444. };
  445. class OpenSafeLockEvent : public FSMEvent
  446. {
  447. public:
  448. OpenSafeLockEvent() : FSMEvent(USER_EVT_OPEN_SAFELOCK){}
  449. ~OpenSafeLockEvent(){}
  450. SpReqAnsContext<CardReadAdapterService_OpenSafeLock_Req, CardReadAdapterService_OpenSafeLock_Ans>::Pointer ctx;
  451. virtual void OnUnhandled()
  452. {
  453. if (ctx != NULL)
  454. ctx->Answer(Error_InvalidState);
  455. }
  456. protected:
  457. private:
  458. };
  459. class MagTransferInitEvent : public FSMEvent
  460. {
  461. public:
  462. MagTransferInitEvent() : FSMEvent(USER_EVT_MAGTRANS_INIT){}
  463. ~MagTransferInitEvent(){}
  464. SpReqAnsContext<CardReadAdapterService_MagTransferInit_Req, CardReadAdapterService_MagTransferInit_Ans>::Pointer ctx;
  465. virtual void OnUnhandled()
  466. {
  467. if (ctx != NULL)
  468. ctx->Answer(Error_InvalidState);
  469. }
  470. protected:
  471. private:
  472. };
  473. class QueryConnInfoEvent : public FSMEvent
  474. {
  475. public:
  476. QueryConnInfoEvent() : FSMEvent(USER_EVT_QUERY_CONN_INFO){}
  477. ~QueryConnInfoEvent(){}
  478. SpReqAnsContext<CardReadAdapterService_QueryConnInfo_Req, CardReadAdapterService_QueryConnInfo_Ans>::Pointer ctx;
  479. virtual void OnUnhandled()
  480. {
  481. if (ctx != NULL)
  482. ctx->Answer(Error_InvalidState);
  483. }
  484. protected:
  485. private:
  486. };
  487. class SAMICCommandEvent : public FSMEvent
  488. {
  489. public:
  490. SAMICCommandEvent() : FSMEvent(USER_EVT_SAM_IC_COMMAND){}
  491. ~SAMICCommandEvent(){}
  492. SpReqAnsContext<CardReadAdapterService_SAMICCommand_Req, CardReadAdapterService_SAMICCommand_Ans>::Pointer ctx;
  493. virtual void OnUnhandled()
  494. {
  495. if (ctx != NULL)
  496. ctx->Answer(Error_InvalidState);
  497. }
  498. };
  499. class QueryPrinterStatusEvent : public FSMEvent
  500. {
  501. public:
  502. QueryPrinterStatusEvent() : FSMEvent(USER_EVT_QUERY_PRINTER_STATUS){}
  503. ~QueryPrinterStatusEvent(){}
  504. SpReqAnsContext<CardReadAdapterService_QueryPrinterStatus_Req, CardReadAdapterService_QueryPrinterStatus_Ans>::Pointer ctx;
  505. virtual void OnUnhandled()
  506. {
  507. if (ctx != NULL)
  508. ctx->Answer(Error_InvalidState);
  509. }
  510. };
  511. class PrintEvent : public FSMEvent
  512. {
  513. public:
  514. PrintEvent() : FSMEvent(USER_EVT_PRINT){}
  515. ~PrintEvent(){}
  516. SpReqAnsContext<CardReadAdapterService_Print_Req, CardReadAdapterService_Print_Ans>::Pointer ctx;
  517. virtual void OnUnhandled()
  518. {
  519. if (ctx != NULL)
  520. ctx->Answer(Error_InvalidState);
  521. }
  522. };
  523. class QuerySCIListEvent : public FSMEvent
  524. {
  525. public:
  526. QuerySCIListEvent() : FSMEvent(USER_EVT_QUERY_SCILIST){}
  527. ~QuerySCIListEvent(){}
  528. SpReqAnsContext<CardReadAdapterService_QuerySCIList_Req, CardReadAdapterService_QuerySCIList_Ans>::Pointer ctx;
  529. virtual void OnUnhandled()
  530. {
  531. if (ctx != NULL)
  532. ctx->Answer(Error_InvalidState);
  533. }
  534. };
  535. class BindSCIEvent : public FSMEvent
  536. {
  537. public:
  538. BindSCIEvent() : FSMEvent(USER_EVT_BIND_SCI){}
  539. ~BindSCIEvent(){}
  540. SpReqAnsContext<CardReadAdapterService_BindSCI_Req, CardReadAdapterService_BindSCI_Ans>::Pointer ctx;
  541. virtual void OnUnhandled()
  542. {
  543. if (ctx != NULL)
  544. ctx->Answer(Error_InvalidState);
  545. }
  546. };
  547. class PreOnlineOnStoreEvent : public FSMEvent
  548. {
  549. public:
  550. PreOnlineOnStoreEvent() : FSMEvent(USER_EVT_PREONLINE_ON_STORE){}
  551. ~PreOnlineOnStoreEvent(){}
  552. SpReqAnsContext<CardReadAdapterService_PreOnlineOnStore_Req, CardReadAdapterService_PreOnlineOnStore_Ans>::Pointer ctx;
  553. virtual void OnUnhandled()
  554. {
  555. if (ctx != NULL)
  556. ctx->Answer(Error_InvalidState);
  557. }
  558. };
  559. class PreOnlineOnStoreFinishedEvent : public FSMEvent
  560. {
  561. public:
  562. PreOnlineOnStoreFinishedEvent() : FSMEvent(USER_EVT_PREONLINE_ON_STORE_FINISHED){}
  563. ~PreOnlineOnStoreFinishedEvent(){}
  564. SpReqAnsContext<CardReadAdapterService_PreOnlineOnStore_Req, CardReadAdapterService_PreOnlineOnStore_Ans>::Pointer ctx;
  565. virtual void OnUnhandled()
  566. {
  567. if (ctx != NULL)
  568. ctx->Answer(Error_InvalidState);
  569. }
  570. };
  571. class NotifyPreonlineEvent : public FSMEvent
  572. {
  573. public:
  574. NotifyPreonlineEvent() : FSMEvent(USER_EVT_NOTIFY_PREONLINE){}
  575. ~NotifyPreonlineEvent(){}
  576. SpReqAnsContext<CardReadAdapterService_NotifyPreonline_Req, CardReadAdapterService_NotifyPreonline_Ans>::Pointer ctx;
  577. virtual void OnUnhandled()
  578. {
  579. if (ctx != NULL)
  580. ctx->Answer(Error_InvalidState);
  581. }
  582. };
  583. class NotifyPreonlineFinishedEvent : public FSMEvent
  584. {
  585. public:
  586. NotifyPreonlineFinishedEvent() : FSMEvent(USER_EVT_NOTIFY_PREONLINE_FINISHED){}
  587. ~NotifyPreonlineFinishedEvent(){}
  588. SpReqAnsContext<CardReadAdapterService_NotifyPreonline_Req, CardReadAdapterService_NotifyPreonline_Ans>::Pointer ctx;
  589. virtual void OnUnhandled()
  590. {
  591. if (ctx != NULL)
  592. ctx->Answer(Error_InvalidState);
  593. }
  594. };
  595. class QueryCardInfoOnStoreEvent : public FSMEvent
  596. {
  597. public:
  598. QueryCardInfoOnStoreEvent() : FSMEvent(USER_EVT_QUERY_CARD_INFO_ON_STORE){}
  599. ~QueryCardInfoOnStoreEvent(){}
  600. SpReqAnsContext<CardReadAdapterService_QueryCardInfoOnStore_Req, CardReadAdapterService_QueryCardInfoOnStore_Ans>::Pointer ctx;
  601. virtual void OnUnhandled()
  602. {
  603. if (ctx != NULL)
  604. ctx->Answer(Error_InvalidState);
  605. }
  606. };
  607. class QueryCardInfoOnStoreFinishedEvent : public FSMEvent
  608. {
  609. public:
  610. QueryCardInfoOnStoreFinishedEvent() : FSMEvent(USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED){}
  611. ~QueryCardInfoOnStoreFinishedEvent(){}
  612. SpReqAnsContext<CardReadAdapterService_QueryCardInfoOnStore_Req, CardReadAdapterService_QueryCardInfoOnStore_Ans>::Pointer ctx;
  613. virtual void OnUnhandled()
  614. {
  615. if (ctx != NULL)
  616. ctx->Answer(Error_InvalidState);
  617. }
  618. };
  619. class GetAddCardInfoEvent : public FSMEvent
  620. {
  621. public:
  622. GetAddCardInfoEvent() : FSMEvent(USER_EVT_GET_ADD_CARD_INFO){}
  623. ~GetAddCardInfoEvent(){}
  624. SpReqAnsContext<CardReadAdapterService_GetAddCardInfo_Req, CardReadAdapterService_GetAddCardInfo_Ans>::Pointer ctx;
  625. virtual void OnUnhandled()
  626. {
  627. if (ctx != NULL)
  628. ctx->Answer(Error_InvalidState);
  629. }
  630. };
  631. class GetAddCardInfoFinishedEvent : public FSMEvent
  632. {
  633. public:
  634. GetAddCardInfoFinishedEvent() : FSMEvent(USER_EVT_GET_ADD_CARD_INFO_FINISHED){}
  635. ~GetAddCardInfoFinishedEvent(){}
  636. SpReqAnsContext<CardReadAdapterService_GetAddCardInfo_Req, CardReadAdapterService_GetAddCardInfo_Ans>::Pointer ctx;
  637. virtual void OnUnhandled()
  638. {
  639. if (ctx != NULL)
  640. ctx->Answer(Error_InvalidState);
  641. }
  642. };
  643. class CrossTermCallEvent : public FSMEvent
  644. {
  645. public:
  646. CrossTermCallEvent() : FSMEvent(USER_EVT_CROSS_TERM_CALL){}
  647. ~CrossTermCallEvent(){}
  648. SpReqAnsContext<CardReadAdapterService_CrossTermCall_Req, CardReadAdapterService_CrossTermCall_Ans>::Pointer ctx;
  649. virtual void OnUnhandled()
  650. {
  651. if (ctx != NULL)
  652. ctx->Answer(Error_InvalidState);
  653. }
  654. };
  655. class GetDevInfoEvent : public FSMEvent
  656. {
  657. public:
  658. GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEV_INFO){}
  659. ~GetDevInfoEvent(){}
  660. SpReqAnsContext<CardReadAdapterService_GetDevInfo_Req, CardReadAdapterService_GetDevInfo_Ans>::Pointer ctx;
  661. virtual void OnUnhandled()
  662. {
  663. if (ctx != NULL)
  664. {
  665. Dbg("GetDevInfo unhandled");
  666. ctx->Answer(Error_InvalidState);
  667. }
  668. }
  669. };
  670. class CCardReadAdapterFSM : public FSMImpl<CCardReadAdapterFSM>
  671. {
  672. public:
  673. enum { s0, s1, s2, s3, s4};
  674. BEGIN_FSM_STATE(CCardReadAdapterFSM)
  675. FSM_STATE_ENTRY(s0, "Init", s0_on_entry, s0_on_exit, s0_on_event)
  676. FSM_STATE_ENTRY(s1, "Initializing", s1_on_entry, s1_on_exit, s1_on_event)
  677. FSM_STATE_ENTRY(s2, "Idle", s2_on_entry, s2_on_exit, s2_on_event)
  678. FSM_STATE_ENTRY(s3, "Working", s3_on_entry, s3_on_exit, s3_on_event)
  679. FSM_STATE_ENTRY(s4, "Failed", s4_on_entry, s4_on_exit, s4_on_event)
  680. END_FSM_STATE()
  681. BEGIN_FSM_RULE(CCardReadAdapterFSM, s0)
  682. FSM_RULE_ENTRY(s0, s2, USER_EVT_TEST, 0)//oiltest
  683. FSM_RULE_ENTRY(s0, s1, USER_EVT_INIT, 0)
  684. FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  685. FSM_RULE_ENTRY(s1, s2, USER_EVT_INIT_FINISHED, 0)
  686. FSM_RULE_ENTRY(s1, s4, USER_EVT_INIT_FINISHED, 1)
  687. FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  688. FSM_RULE_ENTRY(s2, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  689. FSM_RULE_ENTRY(s2, s3, USER_EVT_READ, 0)
  690. FSM_RULE_ENTRY(s2, s3, USER_EVT_PREONLINE, 0)
  691. FSM_RULE_ENTRY(s2, s3, USER_EVT_POSTONLINE, 0)
  692. FSM_RULE_ENTRY(s2, s3, USER_EVT_EJECT, 0)
  693. FSM_RULE_ENTRY(s2, s3, USER_EVT_SET_SOME_FLAG, 0)
  694. FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_DEV_INFO, 0)
  695. FSM_RULE_ENTRY(s2, s3, USER_EVT_QUERY_CARD_INFO, 0)
  696. FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_MATERIAL, 0)
  697. FSM_RULE_ENTRY(s2, s3, USER_EVT_SET_MATERIAL, 0)
  698. FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_SCI_INFO, 0)
  699. FSM_RULE_ENTRY(s2, s3, USER_EVT_OPEN_SAFELOCK, 0)
  700. FSM_RULE_ENTRY(s2, s3, USER_EVT_MAGTRANS_INIT, 0)
  701. FSM_RULE_ENTRY(s2, s3, USER_EVT_QUERY_CONN_INFO, 0)
  702. FSM_RULE_ENTRY(s2, s3, USER_EVT_SAM_IC_COMMAND, 0)
  703. FSM_RULE_ENTRY(s2, s3, USER_EVT_PREONLINE_ON_STORE, 0)
  704. FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_ADD_CARD_INFO, 0)
  705. FSM_RULE_ENTRY(s3, s2, USER_EVT_EXIT, 0)
  706. FSM_RULE_ENTRY(s3, s2, USER_EVT_READ_FINISHED, 0)
  707. FSM_RULE_ENTRY(s3, s2, USER_EVT_PREONLINE_FINISHED, 0)
  708. FSM_RULE_ENTRY(s3, s2, USER_EVT_POSTONLINE_FINISHED, 0)
  709. FSM_RULE_ENTRY(s3, s2, USER_EVT_EJECT_FINISHED, 0)
  710. FSM_RULE_ENTRY(s3, s2, USER_EVT_WRITE_FINISHED,0)
  711. FSM_RULE_ENTRY(s3, s2, USER_EVT_SET_SOME_FLAG_FINISHED,0)
  712. FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_DEV_INFO_FINISHED,0)
  713. FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_CARD_INFO_FINISHED,0)
  714. FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_MATERIAL_FINISHED,0)
  715. FSM_RULE_ENTRY(s3, s2, USER_EVT_SET_MATERIAL_FINISHED,0)
  716. FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_SCI_INFO_FINISHED,0)
  717. FSM_RULE_ENTRY(s3, s2, USER_EVT_OPEN_SAFELOCK_FINISHED,0)
  718. FSM_RULE_ENTRY(s3, s2, USER_EVT_MAGTRANS_INIT_FINISHED,0)
  719. FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_CONN_INFO_FINISHED,0)
  720. FSM_RULE_ENTRY(s3, s2, USER_EVT_SAM_IC_COMMAND_FINISHED, 0)
  721. FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_PRINTER_STATUS_FINISHED, 0)
  722. FSM_RULE_ENTRY(s3, s2, USER_EVT_PRINT_FINISHED, 0)
  723. FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_SCILIST_FINISHED, 0)
  724. FSM_RULE_ENTRY(s3, s2, USER_EVT_BIND_SCI_FINISHED, 0)
  725. FSM_RULE_ENTRY(s3, s2, USER_EVT_PREONLINE_ON_STORE_FINISHED, 0)
  726. FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_ADD_CARD_INFO_FINISHED, 0)
  727. FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  728. FSM_RULE_ENTRY(s4, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  729. END_FSM_RULE()
  730. CCardReadAdapterFSM() : m_pCardIssuer(NULL), m_pContactless(NULL), m_pCardSwiper(NULL), m_bRVCIL(false){}
  731. ~CCardReadAdapterFSM(){}
  732. virtual ErrorCodeEnum OnInit();
  733. virtual ErrorCodeEnum OnExit();
  734. //unsigned int sReady_on_event(FSMEvent* event)
  735. //{
  736. // if (event->iEvt == USER_EVT_READ) {
  737. // // new read task
  738. //
  739. // event->SetHandled();
  740. // return 0;
  741. // }
  742. //}
  743. void s0_on_entry();
  744. void s0_on_exit();
  745. unsigned int s0_on_event(FSMEvent* event);
  746. void s1_on_entry();
  747. void s1_on_exit();
  748. unsigned int s1_on_event(FSMEvent* event);
  749. void s2_on_entry();
  750. void s2_on_exit();
  751. unsigned int s2_on_event(FSMEvent* event);
  752. void s3_on_entry();
  753. void s3_on_exit();
  754. unsigned int s3_on_event(FSMEvent* event);
  755. void s4_on_entry();
  756. void s4_on_exit();
  757. unsigned int s4_on_event(FSMEvent* event);
  758. void TransEntity(CCardReadAdapterEntity* pEty){ m_pEty = pEty; }
  759. int Initial();
  760. int DoWork(int type);
  761. int CardIssuerRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx);
  762. int ContactlessCardRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx);
  763. int CardSwiperRead(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx,int &eRetErr);
  764. int IssueCard(SpReqAnsContext<CardReadAdapterService_Issue_Req, CardReadAdapterService_Issue_Ans>::Pointer ctx);
  765. void CancelRead();
  766. void ReadWaitMore();
  767. int WriteTrack(SpReqAnsContext<CardReadAdapterService_WriteTrack_Req, CardReadAdapterService_WriteTrack_Ans>::Pointer ctx);
  768. int PreOnline(SpReqAnsContext<CardReadAdapterService_PreOnline_Req, CardReadAdapterService_PreOnline_Ans>::Pointer ctx);
  769. int PostOnline(SpReqAnsContext<CardReadAdapterService_PostOnline_Req, CardReadAdapterService_PostOnline_Ans>::Pointer ctx);
  770. int EjectCard(SpReqAnsContext<CardReadAdapterService_Eject_Req, CardReadAdapterService_Eject_Ans>::Pointer ctx);
  771. int CaptureCard(SpReqAnsContext<CardReadAdapterService_Capture_Req, CardReadAdapterService_Capture_Ans>::Pointer ctx);
  772. int QueryCardInfo(SpReqAnsContext<CardReadAdapterService_QueryCardInfo_Req, CardReadAdapterService_QueryCardInfo_Ans>::Pointer ctx);
  773. void CheckAndReconnectSession();
  774. int SetSomeFlag(SpReqAnsContext<CardReadAdapterService_SetSomeFlag_Req, CardReadAdapterService_SetSomeFlag_Ans>::Pointer ctx);
  775. void DoExit();
  776. int GetMaterialCount(SpReqAnsContext<CardReadAdapterService_GetMaterialCount_Req, CardReadAdapterService_GetMaterialCount_Ans>::Pointer ctx);
  777. int SetMaterialCount(SpReqAnsContext<CardReadAdapterService_SetMaterialCount_Req, CardReadAdapterService_SetMaterialCount_Ans>::Pointer ctx);
  778. int GetSCIInfo(SpReqAnsContext<CardReadAdapterService_GetSCIInfo_Req, CardReadAdapterService_GetSCIInfo_Ans>::Pointer ctx);
  779. int OpenSafeLock(SpReqAnsContext<CardReadAdapterService_OpenSafeLock_Req, CardReadAdapterService_OpenSafeLock_Ans>::Pointer ctx);
  780. int MagTransferInit(SpReqAnsContext<CardReadAdapterService_MagTransferInit_Req, CardReadAdapterService_MagTransferInit_Ans>::Pointer ctx);
  781. int QueryConnInfo(SpReqAnsContext<CardReadAdapterService_QueryConnInfo_Req, CardReadAdapterService_QueryConnInfo_Ans>::Pointer ctx);
  782. int GetDevInfo(SpReqAnsContext<CardReadAdapterService_GetDevInfo_Req, CardReadAdapterService_GetDevInfo_Ans>::Pointer ctx);
  783. void BroadcastReadICing(int status);
  784. int SAMICCommand(SpReqAnsContext<CardReadAdapterService_SAMICCommand_Req, CardReadAdapterService_SAMICCommand_Ans>::Pointer ctx);
  785. int QueryPrinterStatus(SpReqAnsContext<CardReadAdapterService_QueryPrinterStatus_Req, CardReadAdapterService_QueryPrinterStatus_Ans>::Pointer ctx);
  786. int Print(SpReqAnsContext<CardReadAdapterService_Print_Req, CardReadAdapterService_Print_Ans>::Pointer ctx);
  787. int QuerySCIList(SpReqAnsContext<CardReadAdapterService_QuerySCIList_Req, CardReadAdapterService_QuerySCIList_Ans>::Pointer ctx);
  788. int BindSCI(SpReqAnsContext<CardReadAdapterService_BindSCI_Req, CardReadAdapterService_BindSCI_Ans>::Pointer ctx);
  789. int PreOnlineOnStore(SpReqAnsContext<CardReadAdapterService_PreOnlineOnStore_Req, CardReadAdapterService_PreOnlineOnStore_Ans>::Pointer ctx);
  790. int NotifyPreonline(SpReqAnsContext<CardReadAdapterService_NotifyPreonline_Req, CardReadAdapterService_NotifyPreonline_Ans>::Pointer ctx);
  791. int QueryCardInfoOnStore(SpReqAnsContext<CardReadAdapterService_QueryCardInfoOnStore_Req, CardReadAdapterService_QueryCardInfoOnStore_Ans>::Pointer ctx);
  792. int GetAddCardInfo(SpReqAnsContext<CardReadAdapterService_GetAddCardInfo_Req, CardReadAdapterService_GetAddCardInfo_Ans>::Pointer ctx);
  793. int Test1(SpReqAnsContext<CardReadAdapterService_Test1_Req, CardReadAdapterService_Test1_Ans>::Pointer ctx);
  794. int Test2(SpReqAnsContext<CardReadAdapterService_Test2_Req, CardReadAdapterService_Test2_Ans>::Pointer ctx);
  795. void SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
  796. void SetReadCtx(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx) { m_readCtx = ctx; }
  797. bool IsRVCIL() { /*return (m_eMachineType == MachineType_RVC_IL);*/return false;}//oilyang@20190123 方案改了,这里暂时不需要了
  798. template <class TReq, class TAns>
  799. void SaveCtx(int methodID, CSmartPointer<SpReqAnsContext<TReq, TAns> > ctx)
  800. {
  801. m_mapCtx[methodID].pCtx = static_cast<void*>(ctx.GetRawPointer());
  802. }
  803. LPVOID GetCtx(int methodID)
  804. {
  805. if (m_mapCtx.find(methodID) != m_mapCtx.end())
  806. return m_mapCtx[methodID].pCtx;
  807. else
  808. return NULL;
  809. }
  810. int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay=false);
  811. bool GetAttachedTerminal(CSimpleStringA &csTerm);
  812. int CrossTermCall(SpReqAnsContext<CardReadAdapterService_CrossTermCall_Req, CardReadAdapterService_CrossTermCall_Ans>::Pointer ctx);
  813. void CrossTermInvokeInfo(SpOnewayCallContext<CardReadAdapterService_CrossTermInvokeInfo_Info>::Pointer ctx);
  814. void CancelReadForEntity(ModuleType eModule);
  815. protected:
  816. //LPIDCCARDDATA* lppCardData;
  817. int m_iInsertTries;
  818. int m_resetTries;
  819. int m_ejectTries;
  820. private:
  821. CCardReadAdapterEntity *m_pEty;
  822. CardIssuerService_ClientBase *m_pCardIssuer;
  823. ContactlessCardService_ClientBase *m_pContactless;
  824. CardSwiperService_ClientBase *m_pCardSwiper;
  825. BusinessContext m_busCtx;
  826. SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer m_readCtx;
  827. //m_machineType:1:RVC.Stand2S;2:RVC.PAD
  828. //int m_machineType;
  829. //m_CardInWhere:0:no card in any machine; 1:CardIssuer; 2:ContactlessCard; 3:CardSwiper;
  830. int m_CardInWhere;
  831. //m_lastModule:0~7
  832. //0:all; 1:CardIssuer; 2:ContactlessCard; 4:CardSwiper
  833. int m_lastModule;
  834. //m_eMachineType: 0:unkown; 1:RVC.Stand2S; 2:RVC.PAD; 3:RVC.Wall; 4:RPM.Stand1S
  835. MachineType m_eMachineType;
  836. WORD m_majorVerion,m_minorVerion;
  837. ///
  838. int m_resetTimes;
  839. HMODULE m_hVerdorDll;
  840. //GUIConsoleService_ClientBase *m_pGUIConsoleClient;
  841. bool m_devInit, m_bCancelAccept, m_bWaitingAccept, m_bWaitAccepteMore, m_bSM
  842. , m_bOnlineOnly, m_bCDA, m_bIssuingExit, m_bCardIssued, m_bCaptureCfgFlag, m_bHasHopper[3], m_bBTConncting
  843. ,m_bRVCIL;
  844. ErrorCodeEnum m_testResult;
  845. //m_CardInit,m_CardRemains,m_CardIssued,m_CardMixed,m_CardPercent
  846. int m_CardCaptured, m_issueStatusFromFile, m_issueStatus, m_port, m_baudRate, m_currentHopper, m_scanSlot;
  847. CSimpleStringA m_CardBoxNoEx[3], m_PsbCodeEx[3], m_PsbNameEx[3], m_MaintainerEx[3], m_csMaintainTimeEx[3];
  848. int m_CardInitEx[3], m_CardPercentEx[3], m_remainsEx[3], m_issuedEx[3], m_mixedEx[3], m_hopperNum;
  849. DWORD m_MaintainTimeEx[3];
  850. BYTE m_connectType, m_r1[128], m_r2[128], m_r3[128], m_priKey[ONE_K / 2], m_devPubKey[ONE_K / 2], m_bdk[64], m_ksn[64];
  851. DevStateEnum m_eDevState;
  852. CCardProcess *m_pCardProcess;
  853. char *m_pDataToARQC;
  854. long xxTest;
  855. CSimpleStringA m_currCardNo, m_captureReason, m_csMachineType, m_csSite, m_csDevSN, m_terminalNo, m_devSN;
  856. char m_AuthCode[2];
  857. bool m_bBTConnected;
  858. map<int, CtxInfo> m_mapCtx;
  859. bool IsCardIssuerSessionOK();
  860. bool IsContactlessCardSessionOK();
  861. bool IsCardSwiperSessionOK();
  862. bool IsTheEntity(int module,ModuleType eModule);
  863. };
  864. struct InitTask : public ITaskSp
  865. {
  866. CCardReadAdapterFSM* fsm;
  867. InitTask(CCardReadAdapterFSM* f) : fsm(f) {}
  868. void Process()
  869. {
  870. FSMEvent *e = new FSMEvent(USER_EVT_INIT_FINISHED);
  871. e->param1 = fsm->Initial();
  872. fsm->PostEventFIFO(e);
  873. }
  874. };
  875. struct CardIssuerReadTask : public ITaskSp
  876. {
  877. CCardReadAdapterFSM* fsm;
  878. SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx;
  879. CardIssuerReadTask(CCardReadAdapterFSM* f) : fsm(f) {}
  880. void Process()
  881. {
  882. CardReadFinishedEvent *e = new CardReadFinishedEvent();
  883. e->ctx = ctx;
  884. e->param1 = fsm->CardIssuerRead(ctx);
  885. fsm->PostEventFIFO(e);
  886. }
  887. };
  888. struct ContactlessCardReadTask : public ITaskSp
  889. {
  890. CCardReadAdapterFSM* fsm;
  891. SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx;
  892. ContactlessCardReadTask(CCardReadAdapterFSM* f) : fsm(f) {}
  893. void Process()
  894. {
  895. CardReadFinishedEvent *e = new CardReadFinishedEvent();
  896. e->ctx = ctx;
  897. e->param1 = fsm->ContactlessCardRead(ctx);
  898. fsm->PostEventFIFO(e);
  899. }
  900. };
  901. struct CardSwiperReadTask : public ITaskSp
  902. {
  903. CCardReadAdapterFSM* fsm;
  904. SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx;
  905. CardSwiperReadTask(CCardReadAdapterFSM* f) : fsm(f) {}
  906. int x;
  907. void Process()
  908. {
  909. CardReadFinishedEvent *e = new CardReadFinishedEvent();
  910. e->ctx = ctx;
  911. e->param1 = fsm->CardSwiperRead(ctx,x);
  912. fsm->PostEventFIFO(e);
  913. }
  914. };
  915. struct WriteTask : public ITaskSp
  916. {
  917. CCardReadAdapterFSM* fsm;
  918. SpReqAnsContext<CardReadAdapterService_WriteTrack_Req, CardReadAdapterService_WriteTrack_Ans>::Pointer ctx;
  919. WriteTask(CCardReadAdapterFSM* f) : fsm(f) {}
  920. void Process()
  921. {
  922. CardWriteFinishedEvent *e = new CardWriteFinishedEvent();
  923. e->ctx = ctx;
  924. e->param1 = fsm->WriteTrack(ctx);
  925. fsm->PostEventFIFO(e);
  926. }
  927. };
  928. struct DoWorkTask : public ITaskSp
  929. {
  930. CCardReadAdapterFSM* fsm;
  931. int type;
  932. DoWorkTask(CCardReadAdapterFSM* f) : fsm(f) {}
  933. void Process()
  934. {
  935. //FSMEvent *e = new FSMEvent(USER_EVT_DO_WORK_FINISHED);
  936. //e->param1 = fsm->DoWork(type);
  937. //fsm->PostEventFIFO(e);
  938. }
  939. };
  940. struct TestCancelReadTask : public ITaskSp
  941. {
  942. CCardReadAdapterFSM* fsm;
  943. int type;
  944. TestCancelReadTask(CCardReadAdapterFSM* f) : fsm(f) {}
  945. void Process()
  946. {
  947. Sleep(10000);
  948. fsm->CancelRead();
  949. }
  950. };
  951. struct ReadWaitMoreTask : public ITaskSp
  952. {
  953. CCardReadAdapterFSM* fsm;
  954. int type;
  955. ReadWaitMoreTask(CCardReadAdapterFSM* f) : fsm(f) {}
  956. void Process()
  957. {
  958. fsm->ReadWaitMore();
  959. }
  960. };
  961. struct PreOnlineTask : public ITaskSp
  962. {
  963. SpReqAnsContext<CardReadAdapterService_PreOnline_Req, CardReadAdapterService_PreOnline_Ans>::Pointer ctx;
  964. CCardReadAdapterFSM* fsm;
  965. PreOnlineTask(CCardReadAdapterFSM* f) : fsm(f) {}
  966. void Process()
  967. {
  968. FSMEvent *e = new FSMEvent(USER_EVT_PREONLINE_FINISHED);
  969. e->param1 = fsm->PreOnline(ctx);
  970. fsm->PostEventFIFO(e);
  971. }
  972. };
  973. struct PostOnlineTask : public ITaskSp
  974. {
  975. SpReqAnsContext<CardReadAdapterService_PostOnline_Req, CardReadAdapterService_PostOnline_Ans>::Pointer ctx;
  976. CCardReadAdapterFSM* fsm;
  977. PostOnlineTask(CCardReadAdapterFSM* f) : fsm(f) {}
  978. void Process()
  979. {
  980. FSMEvent *e = new FSMEvent(USER_EVT_POSTONLINE_FINISHED);
  981. e->param1 = fsm->PostOnline(ctx);
  982. fsm->PostEventFIFO(e);
  983. }
  984. };
  985. struct IssueTask : public ITaskSp
  986. {
  987. SpReqAnsContext<CardReadAdapterService_Issue_Req, CardReadAdapterService_Issue_Ans>::Pointer ctx;
  988. CCardReadAdapterFSM* fsm;
  989. IssueTask(CCardReadAdapterFSM* f) : fsm(f) {}
  990. void Process()
  991. {
  992. FSMEvent *e = new FSMEvent(USER_EVT_ISSUE_FINISHED);
  993. e->param1 = fsm->IssueCard(ctx);
  994. fsm->PostEventFIFO(e);
  995. }
  996. };
  997. struct EjectTask : public ITaskSp
  998. {
  999. SpReqAnsContext<CardReadAdapterService_Eject_Req, CardReadAdapterService_Eject_Ans>::Pointer ctx;
  1000. CCardReadAdapterFSM* fsm;
  1001. EjectTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1002. void Process()
  1003. {
  1004. FSMEvent *e = new FSMEvent(USER_EVT_EJECT_FINISHED);
  1005. e->param1 = fsm->EjectCard(ctx);
  1006. fsm->PostEventFIFO(e);
  1007. }
  1008. };
  1009. struct CaptureTask : public ITaskSp
  1010. {
  1011. SpReqAnsContext<CardReadAdapterService_Capture_Req, CardReadAdapterService_Capture_Ans>::Pointer ctx;
  1012. CCardReadAdapterFSM* fsm;
  1013. CaptureTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1014. void Process()
  1015. {
  1016. FSMEvent *e = new FSMEvent(USER_EVT_CAPTUREFINISHED);
  1017. e->param1 = fsm->CaptureCard(ctx);
  1018. fsm->PostEventFIFO(e);
  1019. }
  1020. };
  1021. struct CheckSessionTask : public ITaskSp
  1022. {
  1023. CCardReadAdapterFSM* fsm;
  1024. CheckSessionTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1025. void Process()
  1026. {
  1027. fsm->CheckAndReconnectSession();
  1028. }
  1029. };
  1030. struct SetSomeFlagTask : public ITaskSp
  1031. {
  1032. CCardReadAdapterFSM* fsm;
  1033. SpReqAnsContext<CardReadAdapterService_SetSomeFlag_Req, CardReadAdapterService_SetSomeFlag_Ans>::Pointer ctx;
  1034. SetSomeFlagTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1035. void Process()
  1036. {
  1037. FSMEvent *e = new FSMEvent(USER_EVT_SET_SOME_FLAG_FINISHED);
  1038. e->param1 = fsm->SetSomeFlag(ctx);
  1039. fsm->PostEventFIFO(e);
  1040. }
  1041. };
  1042. struct GetDevInfoTask : public ITaskSp
  1043. {
  1044. CCardReadAdapterFSM* fsm;
  1045. SpReqAnsContext<CardReadAdapterService_GetDevInfo_Req, CardReadAdapterService_GetDevInfo_Ans>::Pointer ctx;
  1046. GetDevInfoTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1047. void Process()
  1048. {
  1049. FSMEvent *e = new FSMEvent(USER_EVT_GET_DEV_INFO_FINISHED);
  1050. e->param1 = fsm->GetDevInfo(ctx);
  1051. fsm->PostEventFIFO(e);
  1052. }
  1053. };
  1054. struct QueryCardInfoTask : public ITaskSp
  1055. {
  1056. CCardReadAdapterFSM* fsm;
  1057. SpReqAnsContext<CardReadAdapterService_QueryCardInfo_Req, CardReadAdapterService_QueryCardInfo_Ans>::Pointer ctx;
  1058. QueryCardInfoTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1059. void Process()
  1060. {
  1061. FSMEvent *e = new FSMEvent(USER_EVT_QUERY_CARD_INFO_FINISHED);
  1062. e->param1 = fsm->QueryCardInfo(ctx);
  1063. fsm->PostEventFIFO(e);
  1064. }
  1065. };
  1066. struct GetMaterialCountTask : public ITaskSp
  1067. {
  1068. CCardReadAdapterFSM* fsm;
  1069. SpReqAnsContext<CardReadAdapterService_GetMaterialCount_Req, CardReadAdapterService_GetMaterialCount_Ans>::Pointer ctx;
  1070. GetMaterialCountTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1071. void Process()
  1072. {
  1073. FSMEvent *e = new FSMEvent(USER_EVT_GET_MATERIAL_FINISHED);
  1074. e->param1 = fsm->GetMaterialCount(ctx);
  1075. fsm->PostEventFIFO(e);
  1076. }
  1077. };
  1078. struct SetMaterialCountTask : public ITaskSp
  1079. {
  1080. CCardReadAdapterFSM* fsm;
  1081. SpReqAnsContext<CardReadAdapterService_SetMaterialCount_Req, CardReadAdapterService_SetMaterialCount_Ans>::Pointer ctx;
  1082. SetMaterialCountTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1083. void Process()
  1084. {
  1085. FSMEvent *e = new FSMEvent(USER_EVT_SET_MATERIAL_FINISHED);
  1086. e->param1 = fsm->SetMaterialCount(ctx);
  1087. fsm->PostEventFIFO(e);
  1088. }
  1089. };
  1090. struct GetSCIInfoTask : public ITaskSp
  1091. {
  1092. CCardReadAdapterFSM* fsm;
  1093. SpReqAnsContext<CardReadAdapterService_GetSCIInfo_Req, CardReadAdapterService_GetSCIInfo_Ans>::Pointer ctx;
  1094. GetSCIInfoTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1095. void Process()
  1096. {
  1097. FSMEvent *e = new FSMEvent(USER_EVT_GET_SCI_INFO_FINISHED);
  1098. e->param1 = fsm->GetSCIInfo(ctx);
  1099. fsm->PostEventFIFO(e);
  1100. }
  1101. };
  1102. struct OpenSafeLockTask : public ITaskSp
  1103. {
  1104. CCardReadAdapterFSM* fsm;
  1105. SpReqAnsContext<CardReadAdapterService_OpenSafeLock_Req, CardReadAdapterService_OpenSafeLock_Ans>::Pointer ctx;
  1106. OpenSafeLockTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1107. void Process()
  1108. {
  1109. FSMEvent *e = new FSMEvent(USER_EVT_OPEN_SAFELOCK_FINISHED);
  1110. e->param1 = fsm->OpenSafeLock(ctx);
  1111. fsm->PostEventFIFO(e);
  1112. }
  1113. };
  1114. struct MagTransferInitTask : public ITaskSp
  1115. {
  1116. CCardReadAdapterFSM* fsm;
  1117. SpReqAnsContext<CardReadAdapterService_MagTransferInit_Req, CardReadAdapterService_MagTransferInit_Ans>::Pointer ctx;
  1118. MagTransferInitTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1119. void Process()
  1120. {
  1121. FSMEvent *e = new FSMEvent(USER_EVT_MAGTRANS_INIT_FINISHED);
  1122. e->param1 = fsm->MagTransferInit(ctx);
  1123. fsm->PostEventFIFO(e);
  1124. }
  1125. };
  1126. struct QueryConnInfoTask : public ITaskSp
  1127. {
  1128. CCardReadAdapterFSM* fsm;
  1129. SpReqAnsContext<CardReadAdapterService_QueryConnInfo_Req, CardReadAdapterService_QueryConnInfo_Ans>::Pointer ctx;
  1130. QueryConnInfoTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1131. void Process()
  1132. {
  1133. FSMEvent *e = new FSMEvent(USER_EVT_QUERY_CONN_INFO_FINISHED);
  1134. e->param1 = fsm->QueryConnInfo(ctx);
  1135. fsm->PostEventFIFO(e);
  1136. }
  1137. };
  1138. struct DoExitTask : public ITaskSp
  1139. {
  1140. CCardReadAdapterFSM* fsm;
  1141. DoExitTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1142. void Process()
  1143. {
  1144. fsm->DoExit();
  1145. }
  1146. };
  1147. struct SAMICCommandTask : public ITaskSp
  1148. {
  1149. CCardReadAdapterFSM* fsm;
  1150. SpReqAnsContext<CardReadAdapterService_SAMICCommand_Req, CardReadAdapterService_SAMICCommand_Ans>::Pointer ctx;
  1151. SAMICCommandTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1152. void Process()
  1153. {
  1154. FSMEvent *e = new FSMEvent(USER_EVT_SAM_IC_COMMAND_FINISHED);
  1155. e->param1 = fsm->SAMICCommand(ctx);
  1156. fsm->PostEventFIFO(e);
  1157. }
  1158. };
  1159. struct QueryPrinterStatusTask : public ITaskSp
  1160. {
  1161. CCardReadAdapterFSM* fsm;
  1162. SpReqAnsContext<CardReadAdapterService_QueryPrinterStatus_Req, CardReadAdapterService_QueryPrinterStatus_Ans>::Pointer ctx;
  1163. QueryPrinterStatusTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1164. void Process()
  1165. {
  1166. FSMEvent *e = new FSMEvent(USER_EVT_QUERY_PRINTER_STATUS_FINISHED);
  1167. e->param1 = fsm->QueryPrinterStatus(ctx);
  1168. fsm->PostEventFIFO(e);
  1169. }
  1170. };
  1171. struct PrintTask : public ITaskSp
  1172. {
  1173. CCardReadAdapterFSM* fsm;
  1174. SpReqAnsContext<CardReadAdapterService_Print_Req, CardReadAdapterService_Print_Ans>::Pointer ctx;
  1175. PrintTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1176. void Process()
  1177. {
  1178. FSMEvent *e = new FSMEvent(USER_EVT_PRINT_FINISHED);
  1179. e->param1 = fsm->Print(ctx);
  1180. fsm->PostEventFIFO(e);
  1181. }
  1182. };
  1183. struct QuerySCIListTask : public ITaskSp
  1184. {
  1185. CCardReadAdapterFSM* fsm;
  1186. SpReqAnsContext<CardReadAdapterService_QuerySCIList_Req, CardReadAdapterService_QuerySCIList_Ans>::Pointer ctx;
  1187. QuerySCIListTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1188. void Process()
  1189. {
  1190. FSMEvent *e = new FSMEvent(USER_EVT_QUERY_SCILIST_FINISHED);
  1191. e->param1 = fsm->QuerySCIList(ctx);
  1192. fsm->PostEventFIFO(e);
  1193. }
  1194. };
  1195. struct BindSCITask : public ITaskSp
  1196. {
  1197. CCardReadAdapterFSM* fsm;
  1198. SpReqAnsContext<CardReadAdapterService_BindSCI_Req, CardReadAdapterService_BindSCI_Ans>::Pointer ctx;
  1199. BindSCITask(CCardReadAdapterFSM* f) : fsm(f) {}
  1200. void Process()
  1201. {
  1202. FSMEvent *e = new FSMEvent(USER_EVT_BIND_SCI_FINISHED);
  1203. e->param1 = fsm->BindSCI(ctx);
  1204. fsm->PostEventFIFO(e);
  1205. }
  1206. };
  1207. struct PreOnlineOnStoreTask : public ITaskSp
  1208. {
  1209. CCardReadAdapterFSM* fsm;
  1210. SpReqAnsContext<CardReadAdapterService_PreOnlineOnStore_Req, CardReadAdapterService_PreOnlineOnStore_Ans>::Pointer ctx;
  1211. PreOnlineOnStoreTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1212. void Process()
  1213. {
  1214. FSMEvent *e = new FSMEvent(USER_EVT_PREONLINE_ON_STORE_FINISHED);
  1215. e->param1 = fsm->PreOnlineOnStore(ctx);
  1216. fsm->PostEventFIFO(e);
  1217. }
  1218. };
  1219. struct GetAddCardInfoTask : public ITaskSp
  1220. {
  1221. CCardReadAdapterFSM* fsm;
  1222. SpReqAnsContext<CardReadAdapterService_GetAddCardInfo_Req, CardReadAdapterService_GetAddCardInfo_Ans>::Pointer ctx;
  1223. GetAddCardInfoTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1224. void Process()
  1225. {
  1226. FSMEvent *e = new FSMEvent(USER_EVT_GET_ADD_CARD_INFO_FINISHED);
  1227. e->param1 = fsm->GetAddCardInfo(ctx);
  1228. fsm->PostEventFIFO(e);
  1229. }
  1230. };
  1231. struct NotifyPreOnlineTask : public ITaskSp
  1232. {
  1233. CCardReadAdapterFSM* fsm;
  1234. SpReqAnsContext<CardReadAdapterService_NotifyPreonline_Req, CardReadAdapterService_NotifyPreonline_Ans>::Pointer ctx;
  1235. NotifyPreOnlineTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1236. void Process()
  1237. {
  1238. FSMEvent *e = new FSMEvent(USER_EVT_NOTIFY_PREONLINE_FINISHED);
  1239. e->param1 = fsm->NotifyPreonline(ctx);
  1240. fsm->PostEventFIFO(e);
  1241. }
  1242. };
  1243. struct QueryCardInfoOnStoreTask : public ITaskSp
  1244. {
  1245. CCardReadAdapterFSM* fsm;
  1246. SpReqAnsContext<CardReadAdapterService_QueryCardInfoOnStore_Req, CardReadAdapterService_QueryCardInfoOnStore_Ans>::Pointer ctx;
  1247. QueryCardInfoOnStoreTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1248. void Process()
  1249. {
  1250. FSMEvent *e = new FSMEvent(USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED);
  1251. e->param1 = fsm->QueryCardInfoOnStore(ctx);
  1252. fsm->PostEventFIFO(e);
  1253. }
  1254. };
  1255. struct CrossTermCallTask : public ITaskSp
  1256. {
  1257. CCardReadAdapterFSM* fsm;
  1258. SpReqAnsContext<CardReadAdapterService_CrossTermCall_Req, CardReadAdapterService_CrossTermCall_Ans>::Pointer ctx;
  1259. CrossTermCallTask(CCardReadAdapterFSM* f) : fsm(f) {}
  1260. void Process()
  1261. {
  1262. FSMEvent *e = new FSMEvent(USER_EVT_CROSS_TERM_CALL_FINISHED);
  1263. e->param1 = fsm->CrossTermCall(ctx);
  1264. fsm->PostEventFIFO(e);
  1265. }
  1266. };
  1267. struct Test1Task : public ITaskSp
  1268. {
  1269. CCardReadAdapterFSM* fsm;
  1270. SpReqAnsContext<CardReadAdapterService_Test1_Req, CardReadAdapterService_Test1_Ans>::Pointer ctx;
  1271. Test1Task(CCardReadAdapterFSM* f) : fsm(f) {}
  1272. void Process()
  1273. {
  1274. FSMEvent *e = new FSMEvent(USER_EVT_TEST1_FINISHED);
  1275. e->param1 = fsm->Test1(ctx);
  1276. fsm->PostEventFIFO(e);
  1277. }
  1278. };
  1279. struct Test2Task : public ITaskSp
  1280. {
  1281. CCardReadAdapterFSM* fsm;
  1282. SpReqAnsContext<CardReadAdapterService_Test2_Req, CardReadAdapterService_Test2_Ans>::Pointer ctx;
  1283. Test2Task(CCardReadAdapterFSM* f) : fsm(f) {}
  1284. void Process()
  1285. {
  1286. FSMEvent *e = new FSMEvent(USER_EVT_TEST1_FINISHED);
  1287. e->param1 = fsm->Test2(ctx);
  1288. fsm->PostEventFIFO(e);
  1289. }
  1290. };
  1291. #endif //__CARDREAD_ADAPTER_FSM_H