123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775 |
- #ifndef __CARD_SWIPER_FSM_H
- #define __CARD_SWIPER_FSM_H
- #pragma once
- #include "stdafx.h"
- #include "SpFSM.h"
- #include "EventCode.h"
- #include "CardSwiper_UserErrorCode.h"
- #include "CardSwiper_server_g.h"
- #include "CardSwiper_msg_g.h"
- #include "CardSwiperClass.h"
- #include "DevFSMCommBase.hpp"
- #include "CardAssist.h"
- #include "ICDataElement.h"
- #include "json/json.h"
- #include "AccessAuthorization_client_g.h"
- #include "PinPad_client_g.h"
- #include "HealthManager_client_g.h"
- #include "HealthManager_def_g.h"
- #include "SelfChecker_client_g.h"
- #include "SelfChecker_def_g.h"
- using namespace SelfChecker;
- using namespace HealthManager;
- using namespace PinPad;
- using namespace CardSwiper;
- using namespace AccessAuthorization;
- const int ONE_K = 1024;
- enum EvtType
- {
- USER_EVT_TEST = EVT_USER+1,
- USER_EVT_QUIT,
- USER_EVT_INIT,
- USER_EVT_INITFINISHED,
- USER_EVT_ACCEPT,
- USER_EVT_ACCEPT_CANCEL,
- USER_EVT_ACCEPTFINISHED,
- USER_EVT_ISSUE,
- USER_EVT_ISSUE_FINISHED,
- USER_EVT_READ,
- USER_EVT_EJECT,
- USER_EVT_CAPTURE,
- USER_EVT_READFINISHED,
- USER_EVT_EJECTFINISHED,
- USER_EVT_WAITFINISHED,
- USER_EVT_CAPTUREFINISHED,
- USER_EVT_WAITFETCHINGTIMEOUT,
- USER_EVT_PREONLINE,
- USER_EVT_POSTONLINE,
- USER_EVT_PREONLINEFINISHED,
- USER_EVT_POSTONLINEFINISHED,
- USER_EVT_EXIT,
- USER_EVT_CANCELINSERT,
- USER_EVT_QUERY_CARD_INFO,
- USER_EVT_QUERY_CARD_INFO_FINISHED,
- USER_EVT_MAGDATA_TRANSFER_INIT_V2,
- USER_EVT_MAGDATA_TRANSFER_INIT_V2_FINISHED,
- USER_EVT_DEV_DISCONNECTED,
- USER_EVT_DEV_CONNECTED,
- USER_EVT_ENCRYPTED_CHANNEL,
- USER_EVT_QUERY_FWB_LIST,
- USER_EVT_QUERY_FWB_LIST_FINISHED,
- USER_EVT_BIND_FWB,
- USER_EVT_BIND_FWB_FINISHED,
- USER_EVT_NO_BIND_FWB,
- };
- struct FWBRecord
- {
- CSimpleStringA name;
- CSimpleStringA remoteMac;
- };
- class SelfChekerClient:public SelfCheckerService_ClientBase
- {
- public:
- SelfChekerClient(CEntityBase* pEntity);
- };
- class HealthMngClient : public HealthManagerService_ClientBase
- {
- public:
- HealthMngClient(CEntityBase* pEntity);
- };
- typedef int(*lpCMBdecodeMag2)(char* Mag2Data, char * data);
- typedef int(*lpCMBdecodeEx)( char* MagData, char * type, char * data);
- typedef ErrorCodeEnum (*lpCreateDevCom)(DeviceBaseClass *&baseObj);
- typedef ErrorCodeEnum (*lpReleaseDevCom)(DeviceBaseClass *&pBaseObj);
- class CCardSwiperEntity;
- class CCardSwiperFSM;
- struct Track2Data
- {
- int status;
- CSimpleStringA t2Account;
- CSimpleStringA t2Region;
- CSimpleStringA t2CardSerial;
- CSimpleStringA t2CVC;
- CSimpleStringA t2ExpireDate;
- };
- class CardReadEvent : public FSMEvent
- {
- public:
- CardReadEvent() : FSMEvent(USER_EVT_READ){}
- ~CardReadEvent(){}
- SpReqAnsContext<CardSwiperService_Read_Req,CardSwiperService_Read_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWarn("card read unhandled");
- ctx->Answer(Error_InvalidState);
- }
- }
- protected:
- private:
- };
- class CardReadFinishedEvent : public FSMEvent
- {
- public:
- CardReadFinishedEvent() : FSMEvent(USER_EVT_READFINISHED){}
- ~CardReadFinishedEvent(){}
- SpReqAnsContext<CardSwiperService_Read_Req,CardSwiperService_Read_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWarn("card read unhandled");
- //ctx->Answer(Error_InvalidState);
- }
- }
- protected:
- private:
- };
- class PreOnlineEvent : public FSMEvent
- {
- public:
- PreOnlineEvent() : FSMEvent(USER_EVT_PREONLINE){}
- ~PreOnlineEvent(){}
- SpReqAnsContext<CardSwiperService_PreOnline_Req,CardSwiperService_PreOnline_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- protected:
- private:
- };
- class PostOnlineEvent : public FSMEvent
- {
- public:
- PostOnlineEvent() : FSMEvent(USER_EVT_POSTONLINE){}
- ~PostOnlineEvent(){}
- SpReqAnsContext<CardSwiperService_PostOnline_Req,CardSwiperService_PostOnline_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- protected:
- private:
- };
- class QueryCardInfoEvent : public FSMEvent
- {
- public:
- QueryCardInfoEvent() : FSMEvent(USER_EVT_QUERY_CARD_INFO){}
- ~QueryCardInfoEvent(){}
- SpReqAnsContext<CardSwiperService_QueryCardInfo_Req,CardSwiperService_QueryCardInfo_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- protected:
- private:
- };
- class QueryFWBListEvent : public FSMEvent
- {
- public:
- QueryFWBListEvent() : FSMEvent(USER_EVT_QUERY_FWB_LIST) {}
- ~QueryFWBListEvent() {}
- SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWarn("query fwb list unhandled");
- ctx->Answer(Error_InvalidState);
- }
- }
- };
- class BindFWBEvent : public FSMEvent
- {
- public:
- BindFWBEvent() : FSMEvent(USER_EVT_BIND_FWB) {}
- ~BindFWBEvent() {}
- SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWarn("bind fwb unhandled");
- ctx->Answer(Error_InvalidState);
- }
- }
- };
- class CCardSwiperFSM : public CCommDevFSM<CCardSwiperFSM, CardSwiperClass>, public IFSMStateHooker
- {
- public:
- enum {s0,s1,s2,s3,s4,s5,s6,s7,s8};
- BEGIN_FSM_STATE(CCardSwiperFSM)
- FSM_STATE_ENTRY(s0,"Init",s0_on_entry,s0_on_exit,s0_on_event)
- FSM_STATE_ENTRY(s1,"Initializing",s1_on_entry,s1_on_exit,s1_on_event)
- FSM_STATE_ENTRY(s2,"Idle",s2_on_entry,s2_on_exit,s2_on_event)
- FSM_STATE_ENTRY(s3,"Reading",s3_on_entry,s3_on_exit,s3_on_event)
- FSM_STATE_ENTRY(s4,"Hold",s4_on_entry,s4_on_exit,s4_on_event)
- FSM_STATE_ENTRY(s5,"Failed",s5_on_entry,s5_on_exit,s5_on_event)
- FSM_STATE_ENTRY(s6,"WaitingFetch",s6_on_entry,s6_on_exit,s6_on_event)
- FSM_STATE_ENTRY(s7,"DeviceOff",s7_on_entry,s7_on_exit,s7_on_event)
- FSM_STATE_ENTRY(s8, "FWB", s8_on_entry, s8_on_exit, s8_on_event)
- END_FSM_STATE()
- BEGIN_FSM_RULE(CCardSwiperFSM,s0)
- FSM_RULE_ENTRY(s0,s1,USER_EVT_INIT,0)
- FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s1,s2,USER_EVT_INITFINISHED,0)
- FSM_RULE_ENTRY(s1, s5, USER_EVT_INITFINISHED, 5)
- // --Josephus at 11:25:31 2016126
- FSM_RULE_ENTRY(s1,s7,USER_EVT_INITFINISHED,1)
- FSM_RULE_ENTRY(s1,s1, USER_EVT_INITFINISHED , 2)
- FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s4, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s2,s3,USER_EVT_READ,0)
- FSM_RULE_ENTRY(s2,s6,USER_EVT_EJECT,0)
- FSM_RULE_ENTRY(s2, s8, USER_EVT_QUERY_FWB_LIST, 0)
- FSM_RULE_ENTRY(s2, s8, USER_EVT_BIND_FWB, 0)
- // --Josephus at 11:27:29 2016126
- FSM_RULE_ENTRY(s2, s7, USER_EVT_DEV_DISCONNECTED, 0)
- FSM_RULE_ENTRY(s3,s2,USER_EVT_READFINISHED,0)
- FSM_RULE_ENTRY(s3,s5,USER_EVT_READFINISHED,1)
- FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s3,s2,USER_EVT_EXIT,0)
- FSM_RULE_ENTRY(s5, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s5, s0, USER_EVT_INIT, 0)
- FSM_RULE_ENTRY(s5, s7, USER_EVT_DEV_DISCONNECTED, 0)
- FSM_RULE_ENTRY(s6,s2,USER_EVT_EJECTFINISHED,0)
- FSM_RULE_ENTRY(s6,s2,USER_EVT_EJECTFINISHED,1)
- FSM_RULE_ENTRY(s6,s2,USER_EVT_EJECTFINISHED,2)
- FSM_RULE_ENTRY(s7, s5, USER_EVT_DEV_CONNECTED, 0)
- FSM_RULE_ENTRY(s7, s0, USER_EVT_BIND_FWB_FINISHED, 0)
- FSM_RULE_ENTRY(s7, s2, USER_EVT_BIND_FWB_FINISHED, 2)
- FSM_RULE_ENTRY(s7, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s7, s0, USER_EVT_INIT, 0)
- FSM_RULE_ENTRY(s8, s2, USER_EVT_QUERY_FWB_LIST_FINISHED, 2)
- FSM_RULE_ENTRY(s8, s0, USER_EVT_BIND_FWB_FINISHED, 0)
- FSM_RULE_ENTRY(s8, s2, USER_EVT_BIND_FWB_FINISHED, 2)
- END_FSM_RULE()
- CCardSwiperFSM() : m_bCancelAccept(false),m_bWaitingAccept(false),
- m_bWaitAccepteMore(false),m_bExit(false),m_resetTimes(0),m_testResult(Error_Succeed), m_pSelfcheckClient(NULL)
- ,m_bCDA(false),m_pDataToARQC(NULL),m_bCancelRead(false)
- , m_bReading(false), m_bNeedInitCh(true), m_connStatus(0), m_connChecking(false), m_periodResetCount(0)
- ,m_dwPeriodResetTime(0), m_bCancelQueryConn(true), m_nLastSentMsg(-1), m_nReadFailCnt(0), m_nAAStatus(-1)
- , m_bResetInsertMore(false), m_csDevNo(""), m_bDoingBindFWB(false), m_bCallingDevOpenEx(false),m_bBTScan(false)
- , m_bInMainPage(false), m_batteryLeft(999), m_bFWBOpenSucEver(false), m_isFWB(false), m_timesToTryOpen(3)
- {
- HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x202);
- m_aidList.Init(3);
- m_aidList[0] = "A000000333";
- m_aidList[1] = "A0000000108888";
- m_aidList[2] = "A000000790";
- }
- ~CCardSwiperFSM(){}
- virtual ErrorCodeEnum OnInit();
- virtual ErrorCodeEnum OnExit();
- void s0_on_entry();
- void s0_on_exit();
- unsigned int s0_on_event(FSMEvent* event);
- void s1_on_entry();
- void s1_on_exit();
- unsigned int s1_on_event(FSMEvent* event);
- void s2_on_entry();
- void s2_on_exit();
- unsigned int s2_on_event(FSMEvent* event);
- void s3_on_entry();
- void s3_on_exit();
- unsigned int s3_on_event(FSMEvent* event);
- void s4_on_entry();
- void s4_on_exit();
- unsigned int s4_on_event(FSMEvent* event);
- void s5_on_entry();
- void s5_on_exit();
- unsigned int s5_on_event(FSMEvent* event);
- void s6_on_entry();
- void s6_on_exit();
- unsigned int s6_on_event(FSMEvent* event);
- void s7_on_entry();
- void s7_on_exit();
- unsigned int s7_on_event(FSMEvent* event);
- void s8_on_entry();
- void s8_on_exit();
- unsigned int s8_on_event(FSMEvent* event);
- ErrorCodeEnum Load(CSimpleStringA csDevSN="");
- int Initial(CSimpleStringA csDevSN="",bool bInitChannel = true);
- bool GetDevStatus();
- int UnAcceptCard();
- int WaitFetchingCard();
- /*
- -1: !Error_succeed
- 3: CancelRead
- 1: device failed
- 4: timeout
- 5: unknown or ID card. returned directly
- 6: rebuild channel.
- \*/
- int ReadCard(SpReqAnsContext<CardSwiperService_Read_Req,CardSwiperService_Read_Ans>::Pointer ctx);
- int PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req,CardSwiperService_PreOnline_Ans>::Pointer ctx);
- int PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req,CardSwiperService_PostOnline_Ans>::Pointer ctx);
- int QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req,CardSwiperService_QueryCardInfo_Ans>::Pointer ctx);
- int Eject();
- int InternalAcceptCard();
- //oiltmp 测试南天新加密通道
- int TransInitEx(bool bPassvie = false);
- int QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx,int fsmState);
- int BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx, int fsmState);
- void SetExitFlag(bool bFlag=true){m_bExit = bFlag;}
- //LPIDCCARDDATA* GetIDCData(){return lppCardData;}
- void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
- int QueryConnInfo(int nFlag = 0);
- int QueryConnStatus(){ return m_connStatus; }
- DevStateEnum GetDevState(){ return m_eDevState;}
- bool GetDevInitFlag() { return m_bOpened; }
- void SetMainPageFlag(bool bValue)
- {
- DbgInfo(CSimpleStringA::Format("SetMainPageFlag:%d", bValue));
- m_bInMainPage = bValue;
- }
- int DoAbortRead();
- int SplitDevModelInfo();
- char *m_pubKey;//oiltest
- bool IsReading()
- {
- return m_bReading;
- }
- bool IsNeedInitChannel()
- {
- return m_bNeedInitCh;
- }
- void ShowFatalrForConnect(LPCTSTR szMessage, BOOL bFatal = TRUE)
- {
- static int nDisConnectTimes = 0;
- if(bFatal)
- {
- nDisConnectTimes++;
- //GetEntityBase()->GetFunction()->ShowFatalError(szMessage);
- }
- else if(nDisConnectTimes != 0)
- {
- nDisConnectTimes = 0;
- //GetEntityBase()->GetFunction()->ShowFatalError(szMessage);
- }
- return;
- }
- void ShowFatalrForTransferChannel(int nChannelType, BOOL bFatal = TRUE)
- {
- static int nFailBuiltTimes = 0;
- CSimpleStringA csMessage;
- if(bFatal)
- {
- csMessage = CSimpleStringA::Format("CardSwiper加密传输通道V%d建立失败!", nChannelType);
- if(nFailBuiltTimes == 0)
- {
- //GetEntityBase()->GetFunction()->ShowFatalError((LPCTSTR)csMessage);
- //LogWarn(Severity_Middle, Error_NotInit,
- // nChannelType == 1 ? LOG_ERR_CARDSWIPER_BUILT_CHANNELV1_FAILED: LOG_ERR_CARDSWIPER_BUILT_CHANNELV2_FAILED,
- // (LPCTSTR)csMessage);
- }
- else
- {
- //LogWarn(Severity_Middle, Error_NotInit,
- // nChannelType == 1 ? LOG_ERR_CARDSWIPER_BUILT_CHANNELV1_FAILED: LOG_ERR_CARDSWIPER_BUILT_CHANNELV2_FAILED,
- // (LPCTSTR)csMessage);
- }
- //oilyang@20201015 no need to LogWarn repeatablility,as other LogWarn have contain the error.
- //only log the message
- LogWarn(Severity_Middle, Error_Unexpect, CardSwiper_UserErrorCode_Build_Channel_Failed, csMessage.GetData());
- nFailBuiltTimes++;
-
- }
- else if(nFailBuiltTimes != 0)
- {
- csMessage = CSimpleStringA::Format("CardSwiper加密传输通道V%d建立成功!", nChannelType);
- nFailBuiltTimes = 0;
- //GetEntityBase()->GetFunction()->ShowFatalError((LPCTSTR)csMessage);
- }
- return;
- }
- //The list of value of nInforType:
- //0: device is disconnected.
- //1: device is connected and available.
- //2: device is recovering.
- //3: device is unavailable and tell AM to remove the device off pad and connect it again.
- //4: device is not ready, need to wait a moment.
- //5: the ReadCardType of Swiping Magnetic stripe card is unavailable (Built Transfer encrypted channel failed).
- //6: The PinPad is unavailable.
- //7: The entity is going to die, the business have better do nothing.
- //8: device is still unavailalble after removing and connecting action.
- //9: device is busing reading card.
- //10:clear all the notify components.
- void SendDevStatusMsg(int nInforType, bool bForce = false)
- {
- if(m_nLastSentMsg == nInforType && !bForce)
- {
- DbgInfo(CSimpleStringA::Format("Stop from sending msg %d.", nInforType));
- return;
- }
- if(nInforType == 10 && (m_nLastSentMsg == 2 || m_nLastSentMsg == 0))
- {
- DbgInfo(CSimpleStringA::Format("Needless to clear Lst: %d.", m_nLastSentMsg));
- return;
- }
- switch (nInforType)
- {
- case 0:
- DbgInfo(" device is disconnected.");
- break;
- case 1:
- DbgInfo(" device is connected and available.");
- break;
- case 2:
- DbgInfo(" device is recovering.");
- break;
- case 3:
- DbgInfo(" device is unavailable and tell AM to remove the device off pad and connect it.");
- break;
- case 4:
- DbgInfo(" device is not ready, need to wait a moment.");
- break;
- case 5:
- DbgInfo(" the ReadCardType of Swiping Magnetic stripe card is unavailable (Built Transfer encrypted channel failed).");
- break;
- case 6:
- DbgInfo(" The PinPad is unavailable.");
- break;
- case 7:
- DbgInfo("The entity is going to die, the business have better do nothing.");
- break;
- case 8:
- DbgInfo(" device is still unavailalble after removing and connecting action.");
- break;
- case 9:
- DbgInfo("device is busing reading card.");
- nInforType = 1;
- DbgInfo("change Msg from 9 to 1 !!!");
- break;
- case 10:
- DbgInfo("clear all the notify components.");
- nInforType = 1;
- DbgInfo("change Msg from 10 to 1 !!!");
- break;
- default:
- DbgInfo(CSimpleStringA::Format(" Unknown information type %d.", nInforType));
- break;
- }
- m_nLastSentMsg = nInforType;
- //if(nInforType == 0 || nInforType == 1)
- {
- DbgInfo(CSimpleStringA::Format("Really send msg %d.", nInforType));
- ConnectStatus evt;
- evt.status = nInforType;
- SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(ConnectStatus),
- SP_MSG_SIG_OF(ConnectStatus), evt);
- }
- }
- void OnStateTrans(int iSrcState, int iDstState)
- {
- DbgInfo(CSimpleStringA::Format("m_nLstState = %d, StateName = %s", iSrcState, GetStateName(iSrcState)));
- }
- int GetAccessAuthState();
- //-1:初始状态 0: 准入成功, 1: 准入失败, 2: 未准入
- void SetAAState(int val);
- //-1:初始状态 0: 准入成功, 1: 准入失败, 2: 未准入
- int GetAAState()
- {
- //oilyang@20220916 加密通道独立的,不要和准入形成依赖 默认返回0,后续再梳理清理本实体(南天、其他不需要的逻辑)
- return 0;
- if(m_nAAStatus == -1)
- {
- SetAAState(GetAccessAuthState());
- }
- return m_nAAStatus;
- }
- bool IsCryptMachinaType()
- {
- //oilyang@20200615 "Desk2S 1.0" should contain the encrypted Channel
- if (_strnicmp(m_rvcsysInfo.strMachineType.GetData(), "RVC.PAD", strlen("RVC.PAD")) == 0
- || (_strnicmp(m_rvcsysInfo.strMachineType.GetData(), "RVC.Desk2S", strlen("RVC.Desk2S")) == 0
- && m_rvcsysInfo.MachineVersion.GetMajor() == 1 && m_rvcsysInfo.MachineVersion.GetMinor() == 0))
- return true;
- else
- return false;
- }
- void SetAcceptWaitMore(bool bValue);
- bool GetAcceptWaitMore() { return m_bWaitAccepteMore; };
- void InsertWaitMore();
- int FWBBluetoothScanTask();
- int nameToBthAddr(bool isSearchNearBy);//oiltest
- void StartEntity(const char* pEntityName, bool bFWBOpenSucEver=false);
- void TodoReConn();
- protected:
- //LPIDCCARDDATA* lppCardData;
- int m_iInsertTries;
- int m_ejectTries;
- private:
- //m_periodResetCount:一定时间内重置计数
- int m_resetTimes,m_testThreadCount,m_connStatus,m_periodResetCount;
- //m_dwPeriodResetTime:一定时间内第一次重启时间
- DWORD m_dwPeriodResetTime,m_batteryLeft;
- HMODULE m_hVerdorDll;
- // GUIConsoleService_ClientBase *m_pGUIConsoleClient;
- lpCreateDevCom CreateDevComponent;
- lpReleaseDevCom ReleaseDevComponent;
- lpCMBdecodeMag2 cmdDecodeMag2;
- lpCMBdecodeEx cmdDecodeEx;
- bool m_devInit,m_bCancelAccept,m_bWaitingAccept,m_bWaitAccepteMore,m_bExit,m_bCancelRead
- , m_bCDA, m_bReading,m_bNeedInitCh,m_connChecking,m_bResetInsertMore
- , m_bDoingBindFWB, m_bCallingDevOpenEx, m_bBTScan, m_bInMainPage,m_bFWBOpenSucEver;
-
- ErrorCodeEnum m_testResult;
- CAutoArray<CSimpleStringA> m_aidList;
- SelfChekerClient*m_pSelfcheckClient;
- bool m_bCancelQueryConn;
- int m_nLastSentMsg, m_timesToTryOpen;
- int m_nReadFailCnt;
- int m_nAAStatus;
- CardSwiperStatus devStatus;
- DevStateEnum m_eDevState;
- CCardProcess *m_pCardProcess;
- CardReadType m_eReadType;
- char *m_pDataToARQC;
- long xxTest;
- CSimpleStringA m_csCM,m_csPM,m_csDevNo;
- bool m_isFWB;
- int m_version,m_batch;
- int m_nSplitRes;
- char m_AuthCode[2];
- BYTE m_r1[ONE_K / 8], m_r2[ONE_K / 8], m_r3[ONE_K / 8], m_priKey[ONE_K / 2], m_devPubKey[ONE_K / 2];
- vector<FWBRecord> m_vFWBRecords;
- int SplitTrack2(CSimpleStringA pTrack2,Track2Data &decodeData);
- int ProcessEnChannel(bool bIgnore = false);
- int IsValidFWBName(const char* pName, int len);
- ErrorCodeEnum AfterBindUpdateFWBNameToRunCfg(const char* name, bool bBind);
- void AddToFWBRecords(const char* name, const char* remoteMac, bool bFirst);
- void ClearFWBRecords();
- int ScanNearbyBTDevice();
- void ClearHandleOjbects();
- CSimpleStringA TransferAboutVendorShortName(CSimpleStringA name);
- DevCategoryInfo m_devCat;
- CSimpleStringA m_csAlarmMsg;
- CSystemStaticInfo m_rvcsysInfo;
- };
- struct InitTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- InitTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent *e = new FSMEvent(USER_EVT_INITFINISHED);
- e->param1 = fsm->Initial();
- fsm->PostEventFIFO(e);
- }
- };
- struct ReadTask : public ITaskSp
- {
- SpReqAnsContext<CardSwiperService_Read_Req,CardSwiperService_Read_Ans>::Pointer ctx;
- CCardSwiperFSM* fsm;
- ReadTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- fsm->SetExitFlag(false);
- //int tmpChannelTest = fsm->IsNeedInitChannel()? 1 : 0;
- CardReadFinishedEvent *e = new CardReadFinishedEvent();
- e->ctx = ctx;
- e->param1 = fsm->ReadCard(ctx);
- //e->param2 = tmpChannelTest;
- fsm->PostEventFIFO(e);
- }
- };
- struct CancelReadTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- CancelReadTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- int nRes = fsm->DoAbortRead();
- if(nRes != -1)
- {
- int checkTimes = 0;
- int checkMaxTimes = 5;
- for(; checkTimes < checkMaxTimes; ++checkTimes)
- {
- if(!fsm->IsReading()) break;
- Sleep(1000);
- }
- if(checkTimes >= checkMaxTimes)
- {
- LogWarn(Severity_Middle, Error_Unexpect,
- CardSwiper_UserErrorCode_Wait_Too_Much_Time_After_AbortRead,"Wait too much time after AbortRead op.");
- }
- }
- }
- };
- struct ExitTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- ExitTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- fsm->DoAbortRead();
- }
- };
- struct PreOnlineTask : public ITaskSp
- {
- SpReqAnsContext<CardSwiperService_PreOnline_Req,CardSwiperService_PreOnline_Ans>::Pointer ctx;
- CCardSwiperFSM* fsm;
- PreOnlineTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent *e = new FSMEvent(USER_EVT_PREONLINEFINISHED);
- e->param1 = fsm->PreOnline(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct PostOnlineTask : public ITaskSp
- {
- SpReqAnsContext<CardSwiperService_PostOnline_Req,CardSwiperService_PostOnline_Ans>::Pointer ctx;
- CCardSwiperFSM* fsm;
- PostOnlineTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent *e = new FSMEvent(USER_EVT_POSTONLINEFINISHED);
- e->param1 = fsm->PostOnline(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct EjectTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- EjectTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent *pEvt = new FSMEvent(USER_EVT_EJECTFINISHED);
- pEvt->param1 = fsm->Eject();
- fsm->PostEventFIFO(pEvt);
- }
- };
- struct QueryCardInfoTask : public ITaskSp
- {
- SpReqAnsContext<CardSwiperService_QueryCardInfo_Req,CardSwiperService_QueryCardInfo_Ans>::Pointer ctx;
- CCardSwiperFSM* fsm;
- QueryCardInfoTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent *e = new FSMEvent(USER_EVT_QUERY_CARD_INFO_FINISHED);
- e->param1 = fsm->QueryCardInfo(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct MagTransInitV2Task : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- MagTransInitV2Task(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent *e = new FSMEvent(USER_EVT_MAGDATA_TRANSFER_INIT_V2_FINISHED);
- e->param1 = fsm->TransInitEx(true);
- fsm->PostEventFIFO(e);
- }
- };
- struct QueryConnectTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- int nReserved;
- QueryConnectTask(CCardSwiperFSM* f) : fsm(f), nReserved(0) {}
- void Process()
- {
- DbgInfo("Start listerning devcic connect status.");
- fsm->QueryConnInfo(nReserved);
- }
- };
- struct InsertWaitMoreTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- InsertWaitMoreTask(CCardSwiperFSM* f) : fsm(f){}
- void Process()
- {
- fsm->InsertWaitMore();
- }
- };
- struct QueryFWBListTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx;
- int fsmState;
- QueryFWBListTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent* e = new FSMEvent(USER_EVT_QUERY_FWB_LIST_FINISHED);
- e->param1 = fsm->QueryFWBList(ctx, fsmState);
- fsm->PostEventFIFO(e);
- }
- };
- struct BindFWBTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx;
- int fsmState;
- BindFWBTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent* e = new FSMEvent(USER_EVT_BIND_FWB_FINISHED);
- e->param1 = fsm->BindFWB(ctx, fsmState);
- fsm->PostEventFIFO(e);
- }
- };
- struct FWBBluetoothScanTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- FWBBluetoothScanTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- fsm->FWBBluetoothScanTask();
- }
- };
- struct ReConnTask : public ITaskSp
- {
- CCardSwiperFSM* fsm;
- ReConnTask(CCardSwiperFSM* f) : fsm(f) {}
- void Process()
- {
- fsm->TodoReConn();
- }
- };
- #endif //__CARD_SWIPER_FSM_H
|