FingerPrintFSM.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. #ifndef FINGERPRINT_FSM_H
  2. #define FINGERPRINT_FSM_H
  3. #include "SpFSM.h"
  4. #include "DevFSMCommBase.hpp"
  5. #include "FingerPrintClass.h"
  6. #include "FingerPrint_UserErrorCode.h"
  7. #include "CommEntityUtil.hpp"
  8. using namespace std;
  9. enum EvtType
  10. {
  11. USER_EVT_TEST = EVT_USER + 1,
  12. USER_EVT_INIT,
  13. USER_EVT_INIT_FINISHED,
  14. USER_EVT_GET_DEVINFO,
  15. USER_EVT_SCAN,
  16. USER_EVT_SCAN_FINISHED,
  17. USER_EVT_SCANEX,
  18. USER_EVT_SCANEX_FINISHED,
  19. USER_EVT_MATCH,
  20. USER_EVT_MATCH_FINISHED,
  21. USER_EVT_GETFINGER,
  22. USER_EVT_GETFINGER_FINISHED,
  23. USER_EVT_GENERATE_TEMPLATE,
  24. USER_EVT_GENERATE_TEMPLATE_FINISHED,
  25. USER_EVT_MATCH_FINGERPRINT,
  26. USER_EVT_MATCH_FINGERPRINT_FINISHED,
  27. USER_EVT_CANCEL_SCAN,
  28. USER_EVT_CANCEL_MATCH,
  29. USER_EVT_CANCEL_SCAN_FINISHED,
  30. USER_EVT_QUIT,
  31. USER_EVT_ERROR,
  32. USER_EVT_EXIT,
  33. USER_EVT_FWB_OPEN_SUC,
  34. USER_EVT_FWB_OPEN_SUC_FINISHED,
  35. };
  36. enum BmpType
  37. {
  38. BmpImage = 1,
  39. TestImage
  40. };
  41. #include "FingerPrint_server_g.h"
  42. #include "FingerPrintClass.h"
  43. using namespace FingerPrint;
  44. class ScanEvent : public FSMEvent
  45. {
  46. public:
  47. ScanEvent() : FSMEvent(USER_EVT_SCAN){}
  48. virtual ~ScanEvent(){}
  49. SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx;
  50. virtual void OnUnhandled()
  51. {
  52. if (ctx != NULL) {
  53. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ScanEvent unhandled.");
  54. ctx->Answer(Error_InvalidState);
  55. }
  56. }
  57. };
  58. class ScanExEvent : public FSMEvent
  59. {
  60. public:
  61. ScanExEvent() : FSMEvent(USER_EVT_SCANEX) {}
  62. virtual ~ScanExEvent() {}
  63. SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx;
  64. virtual void OnUnhandled()
  65. {
  66. if (ctx != NULL)
  67. {
  68. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ScanEx unhandled");
  69. ctx->Answer(Error_InvalidState);
  70. }
  71. }
  72. };
  73. class GetFingerEvent : public FSMEvent
  74. {
  75. public:
  76. GetFingerEvent() : FSMEvent(USER_EVT_GETFINGER) {}
  77. virtual ~GetFingerEvent() {}
  78. SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
  79. virtual void OnUnhandled()
  80. {
  81. if (ctx != NULL)
  82. {
  83. ctx->Answer(Error_InvalidState);
  84. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetFinger unhandled");
  85. }
  86. }
  87. };
  88. class GenerateTemplateEvent : public FSMEvent
  89. {
  90. public:
  91. GenerateTemplateEvent() : FSMEvent(USER_EVT_GENERATE_TEMPLATE) {}
  92. virtual ~GenerateTemplateEvent() {}
  93. SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx;
  94. virtual void OnUnhandled()
  95. {
  96. if (ctx != NULL)
  97. {
  98. ctx->Answer(Error_InvalidState);
  99. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GenerateTemplate unhandled.");
  100. }
  101. }
  102. };
  103. class CancelRegisterEvent : public FSMEvent
  104. {
  105. public:
  106. CancelRegisterEvent() : FSMEvent(USER_EVT_CANCEL_SCAN){}
  107. virtual ~CancelRegisterEvent(){}
  108. virtual void OnUnhandled()
  109. {
  110. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Cancel scan not handled");
  111. }
  112. };
  113. class MatchEvent : public FSMEvent
  114. {
  115. public:
  116. MatchEvent() : FSMEvent(USER_EVT_MATCH){}
  117. virtual ~MatchEvent(){}
  118. SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
  119. virtual void OnUnhandled()
  120. {
  121. if (ctx != NULL)
  122. {
  123. ctx->Answer(Error_InvalidState);
  124. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Match unhandled.");
  125. }
  126. }
  127. };
  128. class MatchFinishedEvent : public FSMEvent
  129. {
  130. public:
  131. MatchFinishedEvent() : FSMEvent(USER_EVT_MATCH_FINISHED){}
  132. ~MatchFinishedEvent(){}
  133. SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
  134. virtual void OnUnhandled()
  135. {
  136. if (ctx != NULL)
  137. {
  138. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Match finished unhandled.");
  139. }
  140. }
  141. };
  142. class GetFingerFinishedEvent : public FSMEvent
  143. {
  144. public:
  145. GetFingerFinishedEvent() : FSMEvent(USER_EVT_GETFINGER_FINISHED) {}
  146. ~GetFingerFinishedEvent() {}
  147. SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
  148. virtual void OnUnhandled()
  149. {
  150. if (ctx != NULL)
  151. {
  152. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetFingerFinished unhandled.");
  153. }
  154. }
  155. };
  156. class CancelMatchEvent : public FSMEvent
  157. {
  158. public:
  159. CancelMatchEvent() : FSMEvent(USER_EVT_CANCEL_MATCH){}
  160. virtual ~CancelMatchEvent(){}
  161. virtual void OnUnhandled()
  162. {
  163. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Cancel match not handled");
  164. }
  165. };
  166. class GetDevInfoEvent : public FSMEvent
  167. {
  168. public:
  169. GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){}
  170. virtual ~GetDevInfoEvent(){}
  171. SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx;
  172. virtual void OnUnhandled()
  173. {
  174. if(ctx != NULL)
  175. ctx->Answer(Error_InvalidState);
  176. }
  177. };
  178. class CFingerPrintFSM : public CCommDevFSM<CFingerPrintFSM, FingerPrintClass>
  179. {
  180. public:
  181. enum {s0, s1, s2, s3, s4};
  182. BEGIN_FSM_STATE(CFingerPrintFSM)
  183. FSM_STATE_ENTRY(s0, "Normal", s0_on_entry,s0_on_exit,s0_on_event)
  184. FSM_STATE_ENTRY(s1, "Scan", s1_on_entry,s1_on_exit,s1_on_event)
  185. FSM_STATE_ENTRY(s2, "Fail", s2_on_entry,s2_on_exit,s2_on_event)
  186. FSM_STATE_ENTRY(s3, "Match", s3_on_entry,s3_on_exit,s3_on_event)//废弃的状态
  187. FSM_STATE_ENTRY(s4, "Init", s4_on_entry,s4_on_exit,s4_on_event)
  188. END_FSM_STATE()
  189. BEGIN_FSM_RULE(CFingerPrintFSM, s4)
  190. FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  191. FSM_RULE_ENTRY(s0, s1, USER_EVT_SCAN, 0)
  192. FSM_RULE_ENTRY(s0, s1, USER_EVT_SCANEX, 0)
  193. FSM_RULE_ENTRY(s0, s1, USER_EVT_GETFINGER, 0)
  194. FSM_RULE_ENTRY(s0, s1, USER_EVT_GENERATE_TEMPLATE, 0)
  195. FSM_RULE_ENTRY(s0, s1, USER_EVT_SCANEX, 0)
  196. FSM_RULE_ENTRY(s0, s2, USER_EVT_ERROR, 0)
  197. FSM_RULE_ENTRY(s0, s3, USER_EVT_MATCH, 0)
  198. FSM_RULE_ENTRY(s0, s4, USER_EVT_FWB_OPEN_SUC_FINISHED, 0)
  199. FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  200. FSM_RULE_ENTRY(s1, s0, USER_EVT_SCAN_FINISHED, 0)
  201. FSM_RULE_ENTRY(s1, s2, USER_EVT_SCAN_FINISHED, 2)
  202. FSM_RULE_ENTRY(s1, s0, USER_EVT_SCANEX_FINISHED, 0)
  203. FSM_RULE_ENTRY(s1, s2, USER_EVT_SCANEX_FINISHED, 2)
  204. FSM_RULE_ENTRY(s1, s0, USER_EVT_GETFINGER_FINISHED, 0)
  205. FSM_RULE_ENTRY(s1, s2, USER_EVT_GETFINGER_FINISHED, 2)
  206. FSM_RULE_ENTRY(s1, s0, USER_EVT_GENERATE_TEMPLATE_FINISHED, 0)
  207. FSM_RULE_ENTRY(s1, s2, USER_EVT_GENERATE_TEMPLATE_FINISHED, 2)
  208. FSM_RULE_ENTRY(s2, s4, USER_EVT_FWB_OPEN_SUC_FINISHED, 0)
  209. FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  210. FSM_RULE_ENTRY(s3, s0, USER_EVT_MATCH_FINISHED, 0)
  211. FSM_RULE_ENTRY(s3, s2, USER_EVT_MATCH_FINISHED, 2)
  212. FSM_RULE_ENTRY(s4, s0, USER_EVT_INIT_FINISHED, 0)
  213. FSM_RULE_ENTRY(s4, s2, USER_EVT_INIT_FINISHED, 2)
  214. END_FSM_RULE()
  215. CFingerPrintFSM():m_bCancelRegister(false), m_bCancelMatch(false), m_bExit(false),
  216. m_testResult(Error_Succeed),m_csMachineType(""), m_terminalNo(""), m_machineVersion("")
  217. {
  218. HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x204);
  219. }
  220. virtual ErrorCodeEnum OnInit();
  221. virtual ErrorCodeEnum OnExit();
  222. void s0_on_entry();
  223. void s0_on_exit();
  224. unsigned int s0_on_event(FSMEvent* e);
  225. void s4_on_entry();
  226. void s4_on_exit();
  227. unsigned int s4_on_event(FSMEvent* e);
  228. void s1_on_entry();
  229. void s1_on_exit();
  230. unsigned int s1_on_event(FSMEvent* e);
  231. void s2_on_entry();
  232. void s2_on_exit();
  233. unsigned int s2_on_event(FSMEvent* e);
  234. void s3_on_entry();
  235. void s3_on_exit();
  236. unsigned int s3_on_event(FSMEvent* e);
  237. int GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx);
  238. int GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx);
  239. void DeleteBmp(int type);
  240. ErrorCodeEnum DeleteFileIfExisted(const char* fileName);
  241. ErrorCodeEnum GetDevCatInfo(DevCategoryInfo& devInfo);
  242. ErrorCodeEnum GetDevState(int &state);
  243. int Initial();
  244. bool GetDevInitFlag() { return m_bOpened; }
  245. bool GetDevInitingFlag() { return m_bOpening; }
  246. DevStateEnum GetDevState(){
  247. return m_devState;
  248. }
  249. void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  250. private:
  251. ErrorCodeEnum m_testResult;
  252. DevCategoryInfo m_devCatInfo;
  253. DevStateEnum m_devState;
  254. bool m_bCancelRegister;
  255. bool m_bCancelMatch;
  256. bool m_bExit;
  257. CSimpleStringA m_csMachineType, m_terminalNo, m_machineVersion;
  258. };
  259. //废弃
  260. struct ScanTask : public ITaskSp
  261. {
  262. CFingerPrintFSM* fsm;
  263. SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx;
  264. ScanTask(CFingerPrintFSM* f) : fsm(f){}
  265. void Process()
  266. {
  267. //LOG_FUNCTION();
  268. //FSMEvent* e = new FSMEvent(USER_EVT_SCAN_FINISHED);
  269. //e->param1 = fsm->GetImageAndFeature(ctx);
  270. //fsm->PostEventFIFO(e);
  271. }
  272. };
  273. //废弃
  274. struct ScanExTask : public ITaskSp
  275. {
  276. CFingerPrintFSM* fsm;
  277. SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx;
  278. ScanExTask(CFingerPrintFSM* f) : fsm(f) {}
  279. void Process()
  280. {
  281. //LOG_FUNCTION();
  282. //FSMEvent* e = new FSMEvent(USER_EVT_SCANEX_FINISHED);
  283. //e->param1 = fsm->GetImageAndFeatureEx(ctx);
  284. //fsm->PostEventFIFO(e);
  285. }
  286. };
  287. //有用
  288. struct GetFingerTask : public ITaskSp
  289. {
  290. CFingerPrintFSM* fsm;
  291. SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
  292. GetFingerTask(CFingerPrintFSM* f) : fsm(f) {}
  293. void Process()
  294. {
  295. LOG_FUNCTION();
  296. FSMEvent* e = new FSMEvent(USER_EVT_GETFINGER_FINISHED);
  297. e->param1 = fsm->GetFingerPrint(ctx);
  298. fsm->PostEventFIFO(e);
  299. }
  300. };
  301. //有用
  302. struct GenerateTemplateTask : public ITaskSp
  303. {
  304. CFingerPrintFSM* fsm;
  305. SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx;
  306. GenerateTemplateTask(CFingerPrintFSM* f) : fsm(f) {}
  307. void Process()
  308. {
  309. LOG_FUNCTION();
  310. FSMEvent* e = new FSMEvent(USER_EVT_GENERATE_TEMPLATE_FINISHED);
  311. e->param1 = fsm->GenerateTemplate(ctx);
  312. fsm->PostEventFIFO(e);
  313. }
  314. };
  315. //废弃
  316. struct MatchTask : public ITaskSp
  317. {
  318. CFingerPrintFSM* fsm;
  319. SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
  320. MatchTask(CFingerPrintFSM* f) : fsm(f){}
  321. void Process()
  322. {
  323. //LOG_FUNCTION();
  324. //MatchFinishedEvent* e = new MatchFinishedEvent();
  325. //e->param1 = fsm->Match(ctx);
  326. //e->ctx = ctx;
  327. //fsm->PostEventFIFO(e);
  328. }
  329. };
  330. //有用
  331. struct InitTask : public ITaskSp
  332. {
  333. CFingerPrintFSM* fsm;
  334. InitTask(CFingerPrintFSM* f) : fsm(f) {}
  335. void Process()
  336. {
  337. FSMEvent* e = new FSMEvent(USER_EVT_INIT_FINISHED);
  338. fsm->m_bOpening = true;
  339. e->param1 = fsm->Initial();
  340. fsm->m_bOpening = false;
  341. fsm->PostEventFIFO(e);
  342. }
  343. };
  344. #endif