| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- #ifndef FINGERPRINT_FSM_H
- #define FINGERPRINT_FSM_H
- #include "DevFSMCommBase.hpp"
- #include "FingerPrintClass.h"
- #include "CardSwiper_client_g.h"
- #include <ctime>
- using namespace CardSwiper;
- #define FINGERPRINT_SCAN_TIMEOUT 15000 * 1000 //us
- #define FINGERPRINT_SCAN_INTERNAL 100 //ms
- #define FINGERPRINT_MATCH_TIMEOUT 15000 * 1000 //us
- #define MAX_FEATURE_LEN 1024
- struct ScanParam
- {
- CSimpleStringA m_DepPath;
- CSimpleStringA m_FullFilePath;
- CSimpleStringA m_BmpFileName;
- clock_t m_TimeStart;
- clock_t m_TimeEnd;
- DWORD 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_Quit;
- };
- enum EvtType
- {
- USER_EVT_TEST = EVT_USER + 1,
- USER_EVT_GET_DEVINFO,
- USER_EVT_SCAN,
- USER_EVT_SCAN_FINISHED,
- USER_EVT_MATCH,
- USER_EVT_MATCH_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;
- typedef ErrorCodeEnum (*lpCreateDevCom)(DeviceBaseClass *&baseObj);
- typedef ErrorCodeEnum (*lpReleaseDevCom)(DeviceBaseClass *&pBaseObj);
- class ScanEvent : public FSMEvent
- {
- public:
- ScanEvent() : FSMEvent(USER_EVT_SCAN){}
- virtual ~ScanEvent(){}
- SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if(ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- 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<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class MatchFinishedEvent : public FSMEvent
- {
- public:
- MatchFinishedEvent() : FSMEvent(USER_EVT_MATCH_FINISHED){}
- ~MatchFinishedEvent(){}
- SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- Dbg("Match finished unhandled.");
- }
- };
- class CancelMatchEvent : public FSMEvent
- {
- public:
- CancelMatchEvent() : FSMEvent(USER_EVT_CANCEL_MATCH){}
- virtual ~CancelMatchEvent(){}
- virtual void OnUnhandled()
- {
- LOG_TRACE("Cancel match not handled");
- }
- };
- class GetDevInfoEvent : public FSMEvent
- {
- public:
- GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){}
- virtual ~GetDevInfoEvent(){}
- SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if(ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class CFingerPrintFSM : public CCommDevFSM<CFingerPrintFSM, FingerPrintClass>
- {
- 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, 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(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_DevAdptLibHelper(NULL){};
- 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<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx);
- ErrorCodeEnum Match(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx);
- void DeleteBmp(int type);
- ErrorCodeEnum DeleteFileIfExisted(LPCTSTR fileName);
- bool IsFileExist(CSimpleString fileName);
- ErrorCodeEnum GetDevCatInfo(DevCategoryInfo& devInfo);
- ErrorCodeEnum GetDevState(int& state);
- ErrorCodeEnum CheckCardSwiperStatus();
- CSimpleString GenerateAlarmJson(CSimpleString entityName, int cost);
- void GetVendorLibName(CSmartPointer<IConfigInfo> spConfig, CSimpleString& dllName);
- ErrorCodeEnum GetMachineInfo(CSimpleString& machineVersion, CSimpleString& machineType);
- ErrorCodeEnum DoDevOpen(CSmartPointer<IConfigInfo> spConfig);
- ErrorCodeEnum DoGetDevInfo();
- ErrorCodeEnum QueryRootConfigObj(CSmartPointer<IConfigInfo> &spConfig);
- bool IsFWBDevice();
- ErrorCodeEnum InitParamBeforeScan(ScanParam *initParam, int scanTime);
- void ScanProcess(ScanParam* pScanParam, SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer &ctx);
- void ProcessAfterScan(ScanParam* pScanParam, SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer& ctx);
- void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
- private:
- DevAdptLibHelper<FingerPrintClass> *m_DevAdptLibHelper;
- ErrorCodeEnum m_testResult;
- DevCategoryInfo m_devCatInfo;
- DevStateEnum m_devState;
- CSimpleStringA m_BmpFileFullPath1;
- CSimpleStringA m_BmpFileFullPath2;
- CSimpleStringA m_BmpFileFullPath3;
- bool m_bCancelRegister;
- bool m_bCancelMatch;
- bool m_devInit;
- bool m_bExit;
- FingerPrintClass* m_pFingerPrint;
- };
- struct ScanTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::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 MatchTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::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
|