#ifndef FINGERPRINT_FSM_H #define FINGERPRINT_FSM_H #include "CommEntityUtil.hpp" #include "DevFSMCommBase.hpp" #include "DeviceBaseHelper.h" #include "FingerPrintClass.h" #include "CardSwiper_client_g.h" #include "fileutil.h" #include using namespace CardSwiper; struct ScanParam { CSimpleStringA m_DepPath; CSimpleStringA m_FullFilePath; CSimpleStringA m_BmpFileName; ULLINT m_TimeStart; ULLINT m_TimeEnd; ULLINT m_TimeLeft; LPBYTE m_Feature; LPBYTE m_Template; int m_FeatureLen; bool m_ScanSuc; bool m_GetTemplateSuc; bool m_NotFindImage; bool m_FeatureIsNull; bool m_bLenIsNotRight; bool m_bGetFingerPrintSuc; bool m_Quit; }; enum OperateType { RegisterType = 1, MatchType }; enum EvtType { USER_EVT_TEST = EVT_USER + 1, USER_EVT_GET_DEVINFO, USER_EVT_SCAN, USER_EVT_SCAN_FINISHED, USER_EVT_SCANEX, USER_EVT_SCANEX_FINISHED, USER_EVT_MATCH, USER_EVT_MATCH_FINISHED, USER_EVT_GETFINGER, USER_EVT_GETFINGER_FINISHED, USER_EVT_GENERATE_TEMPLATE, USER_EVT_GENERATE_TEMPLATE_FINISHED, USER_EVT_CANCEL_SCAN, USER_EVT_CANCEL_MATCH, USER_EVT_CANCEL_SCAN_FINISHED, USER_EVT_QUIT, USER_EVT_ERROR, USER_EVT_EXIT }; enum BmpType { BmpImage = 1, TestImage }; #include "FingerPrint_server_g.h" #include "FingerPrintClass.h" using namespace FingerPrint; class ScanEvent : public FSMEvent { public: ScanEvent() : FSMEvent(USER_EVT_SCAN){} virtual ~ScanEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { Dbg("ScanEvent unhandled."); ctx->Answer(Error_InvalidState); } } }; class ScanExEvent : public FSMEvent { public: ScanExEvent() : FSMEvent(USER_EVT_SCANEX) {} virtual ~ScanExEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { Dbg("ScanEx unhandled"); ctx->Answer(Error_InvalidState); } } }; class GetFingerEvent : public FSMEvent { public: GetFingerEvent() : FSMEvent(USER_EVT_GETFINGER) {} virtual ~GetFingerEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { ctx->Answer(Error_InvalidState); Dbg("GetFinger unhandled"); } } }; class GenerateTemplateEvent : public FSMEvent { public: GenerateTemplateEvent() : FSMEvent(USER_EVT_GENERATE_TEMPLATE) {} virtual ~GenerateTemplateEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { ctx->Answer(Error_InvalidState); Dbg("GenerateTemplate unhandled."); } } }; class CancelRegisterEvent : public FSMEvent { public: CancelRegisterEvent() : FSMEvent(USER_EVT_CANCEL_SCAN){} virtual ~CancelRegisterEvent(){} virtual void OnUnhandled() { LOG_TRACE("Cancel scan not handled"); } }; class MatchEvent : public FSMEvent { public: MatchEvent() : FSMEvent(USER_EVT_MATCH){} virtual ~MatchEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { ctx->Answer(Error_InvalidState); Dbg("match unhandled."); } } }; class MatchFinishedEvent : public FSMEvent { public: MatchFinishedEvent() : FSMEvent(USER_EVT_MATCH_FINISHED){} ~MatchFinishedEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { Dbg("Match finished unhandled."); } }; class GetFingerFinishedEvent : public FSMEvent { public: GetFingerFinishedEvent() : FSMEvent(USER_EVT_GETFINGER_FINISHED) {} ~GetFingerFinishedEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) Dbg("GetFingerFinished unhandled."); } }; class CancelMatchEvent : public FSMEvent { public: CancelMatchEvent() : FSMEvent(USER_EVT_CANCEL_MATCH){} virtual ~CancelMatchEvent(){} virtual void OnUnhandled() { Dbg("Cancel match not handled"); } }; class GetDevInfoEvent : public FSMEvent { public: GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){} virtual ~GetDevInfoEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if(ctx != NULL) ctx->Answer(Error_InvalidState); } }; class CFingerPrintFSM : public CCommDevFSM { public: enum {s0, s1, s2, s3, s4}; BEGIN_FSM_STATE(CFingerPrintFSM) FSM_STATE_ENTRY(s0, "Normal", s0_on_entry,s0_on_exit,s0_on_event) FSM_STATE_ENTRY(s1, "Scan", s1_on_entry,s1_on_exit,s1_on_event) FSM_STATE_ENTRY(s2, "Fail", s2_on_entry,s2_on_exit,s2_on_event) FSM_STATE_ENTRY(s3, "Match", s3_on_entry,s3_on_exit,s3_on_event) END_FSM_STATE() BEGIN_FSM_RULE(CFingerPrintFSM, s0) FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s0, s1, USER_EVT_SCAN, 0) FSM_RULE_ENTRY(s0, s1, USER_EVT_SCANEX, 0) FSM_RULE_ENTRY(s0, s1, USER_EVT_GETFINGER, 0) FSM_RULE_ENTRY(s0, s1, USER_EVT_GENERATE_TEMPLATE, 0) FSM_RULE_ENTRY(s0, s2, USER_EVT_ERROR, 0) FSM_RULE_ENTRY(s0, s3, USER_EVT_MATCH, 0) FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s1, s0, USER_EVT_SCAN_FINISHED, 0) FSM_RULE_ENTRY(s1, s2, USER_EVT_SCAN_FINISHED, 2) FSM_RULE_ENTRY(s1, s0, USER_EVT_SCANEX_FINISHED, 0) FSM_RULE_ENTRY(s1, s2, USER_EVT_SCANEX_FINISHED, 2) FSM_RULE_ENTRY(s1, s0, USER_EVT_GETFINGER_FINISHED, 0) FSM_RULE_ENTRY(s1, s2, USER_EVT_GETFINGER_FINISHED, 2) FSM_RULE_ENTRY(s1, s0, USER_EVT_GENERATE_TEMPLATE_FINISHED, 0) FSM_RULE_ENTRY(s1, s2, USER_EVT_GENERATE_TEMPLATE_FINISHED, 2) FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s3, s0, USER_EVT_MATCH_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_MATCH_FINISHED, 2) END_FSM_RULE() CFingerPrintFSM():m_devInit(false), m_bCancelRegister(false), m_bCancelMatch(false), m_bExit(false), m_testResult(Error_Succeed), m_csDevSN("") { HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x204); m_FirstStart = TRUE; ZeroMemory(&m_adapterInfo, sizeof(m_adapterInfo)); }; virtual ErrorCodeEnum OnInit(); virtual ErrorCodeEnum OnExit(); void s0_on_entry(); void s0_on_exit(); unsigned int s0_on_event(FSMEvent* e); void s1_on_entry(); void s1_on_exit(); unsigned int s1_on_event(FSMEvent* e); void s2_on_entry(); void s2_on_exit(); unsigned int s2_on_event(FSMEvent* e); void s3_on_entry(); void s3_on_exit(); unsigned int s3_on_event(FSMEvent* e); int GetImageAndFeature(SpReqAnsContext::Pointer ctx); int GetImageAndFeatureEx(SpReqAnsContext::Pointer ctx); int GetFingerPrint(SpReqAnsContext::Pointer ctx); int GenerateTemplate(SpReqAnsContext::Pointer ctx); ErrorCodeEnum Match(SpReqAnsContext::Pointer ctx); void DeleteBmp(int type); ErrorCodeEnum DeleteFileIfExisted(const char* fileName); ErrorCodeEnum GetDevCatInfo(DevCategoryInfo& devInfo); ErrorCodeEnum GetDevState(int& state); ErrorCodeEnum CheckCardSwiperStatus(); CSimpleString GenerateAlarmJson(CSimpleString entityName, int cost); ErrorCodeEnum DoDevOpen(CSmartPointer spConfig); ErrorCodeEnum DoGetDevInfo(); ErrorCodeEnum QueryRootConfigObj(CSmartPointer &spConfig); bool IsFWBDevice(CSimpleString& vendorName); ErrorCodeEnum InitCommParam(ScanParam* initParam, int type, int scanTime, int templateNum = -1); ErrorCodeEnum InitParamBeforeScan(ScanParam *initParam, int scanTime); void ScanProcess(ScanParam* pScanParam, SpReqAnsContext::Pointer &ctx); void ScanProcessEx(ScanParam* pScanParam, SpReqAnsContext::Pointer& ctx); void ProcessAfterScan(ScanParam* pScanParam, SpReqAnsContext::Pointer& ctx); void ProcessAfterScanEx(ScanParam* pScanParam, SpReqAnsContext::Pointer& ctx); void CollectProcess(ScanParam* pScanParam, SpReqAnsContext::Pointer& ctx); void ProcessAfterCollect(ScanParam* pScanParam, SpReqAnsContext::Pointer& ctx); ErrorCodeEnum InitParamBeforeMatch(ScanParam* initParam, int templateNum); void ScanBeforeMatch(ScanParam* initParam); ErrorCodeEnum MatchProcess(ScanParam* initParam, SpReqAnsContext::Pointer& ctx); ErrorCodeEnum ExtractVendorLib(CSimpleStringA& strLibFullPath); void SelfTest(EntityTestEnum eTestType,CSmartPointer pTransactionContext); private: ErrorCodeEnum m_testResult; DevCategoryInfo m_devCatInfo; DevStateEnum m_devState; CSimpleStringA m_BmpFileFullPath1; CSimpleStringA m_BmpFileFullPath2; CSimpleStringA m_BmpFileFullPath3; CSimpleStringA m_csDevSN; bool m_bCancelRegister; bool m_bCancelMatch; bool m_devInit; bool m_bExit; ErrorPackage m_errPkg; AdapterInfo m_adapterInfo; }; struct ScanTask : public ITaskSp { CFingerPrintFSM* fsm; SpReqAnsContext::Pointer ctx; ScanTask(CFingerPrintFSM* f) : fsm(f){} void Process() { LOG_FUNCTION(); FSMEvent* e = new FSMEvent(USER_EVT_SCAN_FINISHED); e->param1 = fsm->GetImageAndFeature(ctx); fsm->PostEventFIFO(e); } }; struct ScanExTask : public ITaskSp { CFingerPrintFSM* fsm; SpReqAnsContext::Pointer ctx; ScanExTask(CFingerPrintFSM* f) : fsm(f) {} void Process() { LOG_FUNCTION(); FSMEvent* e = new FSMEvent(USER_EVT_SCANEX_FINISHED); e->param1 = fsm->GetImageAndFeatureEx(ctx); fsm->PostEventFIFO(e); } }; struct GetFingerTask : public ITaskSp { CFingerPrintFSM* fsm; SpReqAnsContext::Pointer ctx; GetFingerTask(CFingerPrintFSM* f) : fsm(f) {} void Process() { LOG_FUNCTION(); FSMEvent* e = new FSMEvent(USER_EVT_GETFINGER_FINISHED); e->param1 = fsm->GetFingerPrint(ctx); fsm->PostEventFIFO(e); } }; struct GenerateTemplateTask : public ITaskSp { CFingerPrintFSM* fsm; SpReqAnsContext::Pointer ctx; GenerateTemplateTask(CFingerPrintFSM* f) : fsm(f) {} void Process() { LOG_FUNCTION(); FSMEvent* e = new FSMEvent(USER_EVT_GENERATE_TEMPLATE_FINISHED); e->param1 = fsm->GenerateTemplate(ctx); fsm->PostEventFIFO(e); } }; struct MatchTask : public ITaskSp { CFingerPrintFSM* fsm; SpReqAnsContext::Pointer ctx; MatchTask(CFingerPrintFSM* f) : fsm(f){} void Process() { LOG_FUNCTION(); MatchFinishedEvent* e = new MatchFinishedEvent(); e->param1 = fsm->Match(ctx); e->ctx = ctx; fsm->PostEventFIFO(e); } }; #endif