#ifndef __CARDREAD_ADAPTER_FSM_H #define __CARDREAD_ADAPTER_FSM_H #pragma once #include "SpFSM.h" #include "CardReadAdapter_server_g.h" #include "CommEntityUtil.hpp" #include "CardIssuerClass.h" //#include "CardAssist.h" #include "CardIssuerStand_UserErrorCode.h" #include "CardIssuerStore_UserErrorCode.h" //#include "ICDataElement.h" using namespace CardReadAdapter; #include "CardIssuerStand_client_g.h" #include "CardIssuerStore_client_g.h" #include "ContactlessCard_client_g.h" #include "CardIssuerStand_msg_g.h" #include "CardIssuerStore_msg_g.h" #include "ContactlessCard_msg_g.h" #include "CardReadAdapter_msg_g.h" #include "HeartBeat_client_g.h" #include "CardReadAdapter_UserErrorCode.h" #include using namespace std; using namespace HeartBeat; using namespace CardIssuerStand; using namespace CardIssuerStore; using namespace ContactlessCard; enum EvtType { USER_EVT_TEST = EVT_USER + 1, USER_EVT_QUIT, USER_EVT_INIT, USER_EVT_INIT_FINISHED, // USER_EVT_CARD_ACCEPT, // USER_EVT_CARD_ACCEPT_FINISHED, USER_EVT_READ, USER_EVT_READ_FINISHED, USER_EVT_READ_CANCEL, USER_EVT_READ_WAIT_MORE, USER_EVT_PREONLINE, USER_EVT_POSTONLINE, USER_EVT_PREONLINE_FINISHED, USER_EVT_POSTONLINE_FINISHED, USER_EVT_EJECT, USER_EVT_EJECT_FINISHED, USER_EVT_ISSUE, USER_EVT_ISSUE_FINISHED, USER_EVT_CAPTURE, USER_EVT_WAITFINISHED, USER_EVT_CAPTUREFINISHED, USER_EVT_WAITFETCHINGTIMEOUT, USER_EVT_RESET, USER_EVT_RESETFINISHED, USER_EVT_EXIT, USER_EVT_WRITE, USER_EVT_WRITE_FINISHED, USER_EVT_SET_SOME_FLAG, USER_EVT_SET_SOME_FLAG_FINISHED, USER_EVT_GET_DEV_INFO, USER_EVT_GET_DEV_INFO_FINISHED, USER_EVT_QUERY_CARD_INFO, USER_EVT_QUERY_CARD_INFO_FINISHED, USER_EVT_GET_MATERIAL, USER_EVT_GET_MATERIAL_FINISHED, USER_EVT_SET_MATERIAL, USER_EVT_SET_MATERIAL_FINISHED, USER_EVT_GET_SCI_INFO, USER_EVT_GET_SCI_INFO_FINISHED, USER_EVT_OPEN_SAFELOCK, USER_EVT_OPEN_SAFELOCK_FINISHED, USER_EVT_MAGTRANS_INIT, USER_EVT_MAGTRANS_INIT_FINISHED, USER_EVT_QUERY_CONN_INFO, USER_EVT_QUERY_CONN_INFO_FINISHED, USER_EVT_SAM_IC_COMMAND, USER_EVT_SAM_IC_COMMAND_FINISHED, USER_EVT_PREONLINE_ON_STORE, USER_EVT_PREONLINE_ON_STORE_FINISHED, USER_EVT_GET_ADD_CARD_INFO, USER_EVT_GET_ADD_CARD_INFO_FINISHED, USER_EVT_NOTIFY_PREONLINE, USER_EVT_NOTIFY_PREONLINE_FINISHED, USER_EVT_QUERY_CARD_INFO_ON_STORE, USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED, USER_EVT_QUERY_PRINTER_STATUS, USER_EVT_QUERY_PRINTER_STATUS_FINISHED, USER_EVT_PRINT, USER_EVT_PRINT_FINISHED, USER_EVT_QUERY_SCILIST, USER_EVT_QUERY_SCILIST_FINISHED, USER_EVT_BIND_SCI, USER_EVT_BIND_SCI_FINISHED, USER_EVT_CROSS_TERM_CALL, USER_EVT_CROSS_TERM_CALL_FINISHED, USER_EVT_TEST1, USER_EVT_TEST1_FINISHED, USER_EVT_TEST2, USER_EVT_TEST2_FINISHED, USER_EVT_PRINT_CARD_IM, USER_EVT_PRINT_CARD_IM_FINISHED, USER_EVT_QUERY_CI_STATUS, USER_EVT_QUERY_CI_STATUS_FINISHED, }; enum CardFromWhichEntity//卡片信息从哪个实体返回 { Card_In_No_Where, Card_In_CardIssuer, Card_In_ContactlessCard }; enum CardProcStage//stage of card process { Card_ProcStage_Idle, Card_ProcStage_WaitForCard, Card_ProcStage_Read, Card_ProcStage_Eject, Card_ProcStage_Capture, }; struct BusinessContext { CardFromWhichEntity eCardFromWhich; CardProcStage eCardProcStage; }; enum ModuleType//从哪个实体读卡 { Module_Any = 0, Module_CardIssuer = 1, Module_ContactlessCard = 2, Module_CardSwiper = 4, }; enum CardPosType { CardPos_No_Card = 0,//0:检查超时,未发现设备有卡。 CardPos_CardSwiper_Mag_Swipe,//1:CardSwiper刷卡 CardPos_CardSwiper_IC_Insert,//2:CardSwiper插IC卡槽 CardPos_CardSwiper_RFIC,//3 : CardSwiper非接卡 CardPos_CardIssuer_Stand2S,//4:卡片在大机卡机里面 CardPos_ContactlessCard,//5:卡片在大机非接上面 CardPos_CardIssuer_Split//6:卡片在便携发卡机里面 }; enum LightPos { LightPos_ALL = 0, LightPos_CardIssuer = 1, LightPos_ContactlessCard = 2, LightPos_CardSwiper_Mag = 4, LightPos_CardSwiper_IC = 8, LightPos_CardSwiper_RFIC = 16, LightPos_CardIssuer_Only_Mag = 32, }; class CCardReadAdapterEntity; class CCardReadAdapterFSM; const int ONE_K = 1024; class CardIssueEvent : public FSMEvent { public: CardIssueEvent() : FSMEvent(USER_EVT_ISSUE){} ~CardIssueEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("card issue unhandled"); ctx->Answer(Error_InvalidState); } } }; class CancelReadEvent : public FSMEvent { public: CancelReadEvent() : FSMEvent(USER_EVT_READ_CANCEL){} ~CancelReadEvent(){} virtual void OnUnhandled() { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("card cancel accept unhandled"); } }; class ReadWaitMoreEvent : public FSMEvent { public: ReadWaitMoreEvent() : FSMEvent(USER_EVT_READ_WAIT_MORE){} ~ReadWaitMoreEvent(){} virtual void OnUnhandled() { } }; class CardReadEvent : public FSMEvent { public: CardReadEvent() : FSMEvent(USER_EVT_READ){} ~CardReadEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("card read unhandled"); ctx->Answer(Error_InvalidState); } } protected: private: }; class CardReadFinishedEvent : public FSMEvent { public: CardReadFinishedEvent() : FSMEvent(USER_EVT_READ_FINISHED){} ~CardReadFinishedEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("card read unhandled(new)"); } } protected: private: }; class ResetDeviceEvent : public FSMEvent { public: ResetDeviceEvent() : FSMEvent(USER_EVT_RESET){} ~ResetDeviceEvent(){} protected: private: }; class ResetFinishedEvent : public FSMEvent { public: ResetFinishedEvent() : FSMEvent(USER_EVT_RESETFINISHED){} ~ResetFinishedEvent(){} protected: private: }; class PreOnlineEvent : public FSMEvent { public: PreOnlineEvent() : FSMEvent(USER_EVT_PREONLINE){} ~PreOnlineEvent(){} SpReqAnsContext::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::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class CardCaptureEvent : public FSMEvent { public: CardCaptureEvent() : FSMEvent(USER_EVT_CAPTURE){} ~CardCaptureEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class CardEjectEvent : public FSMEvent { public: CardEjectEvent() : FSMEvent(USER_EVT_EJECT){} ~CardEjectEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class CardWriteEvent : public FSMEvent { public: CardWriteEvent() : FSMEvent(USER_EVT_WRITE){} ~CardWriteEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("card write unhandled"); ctx->Answer(Error_InvalidState); } } protected: private: }; class CardWriteFinishedEvent : public FSMEvent { public: CardWriteFinishedEvent() : FSMEvent(USER_EVT_WRITE_FINISHED){} ~CardWriteFinishedEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("card write unhandled(new)"); } } }; class SetSomeFlagEvent : public FSMEvent { public: SetSomeFlagEvent() : FSMEvent(USER_EVT_SET_SOME_FLAG){} ~SetSomeFlagEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("SetSomeFlag unhandled"); ctx->Answer(Error_InvalidState); } } }; class QueryCardInfoEvent : public FSMEvent { public: QueryCardInfoEvent() : FSMEvent(USER_EVT_QUERY_CARD_INFO){} ~QueryCardInfoEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("QueryCardInfo unhandled"); ctx->Answer(Error_InvalidState); } } }; class GetMaterialEvent : public FSMEvent { public: GetMaterialEvent() : FSMEvent(USER_EVT_GET_MATERIAL){} ~GetMaterialEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class SetMaterialEvent : public FSMEvent { public: SetMaterialEvent() : FSMEvent(USER_EVT_SET_MATERIAL){} ~SetMaterialEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class GetSCIInfoEvent : public FSMEvent { public: GetSCIInfoEvent() : FSMEvent(USER_EVT_GET_SCI_INFO){} ~GetSCIInfoEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class OpenSafeLockEvent : public FSMEvent { public: OpenSafeLockEvent() : FSMEvent(USER_EVT_OPEN_SAFELOCK){} ~OpenSafeLockEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class MagTransferInitEvent : public FSMEvent { public: MagTransferInitEvent() : FSMEvent(USER_EVT_MAGTRANS_INIT){} ~MagTransferInitEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class QueryConnInfoEvent : public FSMEvent { public: QueryConnInfoEvent() : FSMEvent(USER_EVT_QUERY_CONN_INFO){} ~QueryConnInfoEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } protected: private: }; class SAMICCommandEvent : public FSMEvent { public: SAMICCommandEvent() : FSMEvent(USER_EVT_SAM_IC_COMMAND){} ~SAMICCommandEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class QueryPrinterStatusEvent : public FSMEvent { public: QueryPrinterStatusEvent() : FSMEvent(USER_EVT_QUERY_PRINTER_STATUS){} ~QueryPrinterStatusEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class PrintEvent : public FSMEvent { public: PrintEvent() : FSMEvent(USER_EVT_PRINT){} ~PrintEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class QuerySCIListEvent : public FSMEvent { public: QuerySCIListEvent() : FSMEvent(USER_EVT_QUERY_SCILIST){} ~QuerySCIListEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class BindSCIEvent : public FSMEvent { public: BindSCIEvent() : FSMEvent(USER_EVT_BIND_SCI){} ~BindSCIEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class PreOnlineOnStoreEvent : public FSMEvent { public: PreOnlineOnStoreEvent() : FSMEvent(USER_EVT_PREONLINE_ON_STORE){} ~PreOnlineOnStoreEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class PreOnlineOnStoreFinishedEvent : public FSMEvent { public: PreOnlineOnStoreFinishedEvent() : FSMEvent(USER_EVT_PREONLINE_ON_STORE_FINISHED){} ~PreOnlineOnStoreFinishedEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class NotifyPreonlineEvent : public FSMEvent { public: NotifyPreonlineEvent() : FSMEvent(USER_EVT_NOTIFY_PREONLINE){} ~NotifyPreonlineEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class NotifyPreonlineFinishedEvent : public FSMEvent { public: NotifyPreonlineFinishedEvent() : FSMEvent(USER_EVT_NOTIFY_PREONLINE_FINISHED){} ~NotifyPreonlineFinishedEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class QueryCardInfoOnStoreEvent : public FSMEvent { public: QueryCardInfoOnStoreEvent() : FSMEvent(USER_EVT_QUERY_CARD_INFO_ON_STORE){} ~QueryCardInfoOnStoreEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class QueryCardInfoOnStoreFinishedEvent : public FSMEvent { public: QueryCardInfoOnStoreFinishedEvent() : FSMEvent(USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED){} ~QueryCardInfoOnStoreFinishedEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class GetAddCardInfoEvent : public FSMEvent { public: GetAddCardInfoEvent() : FSMEvent(USER_EVT_GET_ADD_CARD_INFO){} ~GetAddCardInfoEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class GetAddCardInfoFinishedEvent : public FSMEvent { public: GetAddCardInfoFinishedEvent() : FSMEvent(USER_EVT_GET_ADD_CARD_INFO_FINISHED){} ~GetAddCardInfoFinishedEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class CrossTermCallEvent : public FSMEvent { public: CrossTermCallEvent() : FSMEvent(USER_EVT_CROSS_TERM_CALL){} ~CrossTermCallEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class PrintCardImEvent : public FSMEvent { public: PrintCardImEvent() : FSMEvent(USER_EVT_PRINT_CARD_IM) {} ~PrintCardImEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class PrintCardImFinishedEvent : public FSMEvent { public: PrintCardImFinishedEvent() : FSMEvent(USER_EVT_PRINT_CARD_IM_FINISHED) {} ~PrintCardImFinishedEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class QueryCIStatusEvent : public FSMEvent { public: QueryCIStatusEvent() : FSMEvent(USER_EVT_QUERY_CI_STATUS) {} ~QueryCIStatusEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class QueryCIStatusFinishedEvent : public FSMEvent { public: QueryCIStatusFinishedEvent() : FSMEvent(USER_EVT_QUERY_CI_STATUS_FINISHED) {} ~QueryCIStatusFinishedEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class GetDevInfoEvent : public FSMEvent { public: GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEV_INFO){} ~GetDevInfoEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) { DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetDevInfo unhandled"); ctx->Answer(Error_InvalidState); } } }; class CCardReadAdapterFSM : public FSMImpl { public: enum { s0, s1, s2, s3, s4}; BEGIN_FSM_STATE(CCardReadAdapterFSM) 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, "Working", s3_on_entry, s3_on_exit, s3_on_event) FSM_STATE_ENTRY(s4, "Failed", s4_on_entry, s4_on_exit, s4_on_event) END_FSM_STATE() BEGIN_FSM_RULE(CCardReadAdapterFSM, s0) FSM_RULE_ENTRY(s0, s2, USER_EVT_TEST, 0)//oiltest 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_INIT_FINISHED, 0) FSM_RULE_ENTRY(s1, s4, USER_EVT_INIT_FINISHED, 1) FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s2, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_READ, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_PREONLINE, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_POSTONLINE, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_EJECT, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_SET_SOME_FLAG, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_DEV_INFO, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_QUERY_CARD_INFO, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_MATERIAL, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_SET_MATERIAL, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_SCI_INFO, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_OPEN_SAFELOCK, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_MAGTRANS_INIT, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_QUERY_CONN_INFO, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_SAM_IC_COMMAND, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_PREONLINE_ON_STORE, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_GET_ADD_CARD_INFO, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_PRINT_CARD_IM, 0) FSM_RULE_ENTRY(s2, s3, USER_EVT_QUERY_CI_STATUS, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_EXIT, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_READ_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_READ_FINISHED, 2) FSM_RULE_ENTRY(s3, s2, USER_EVT_PREONLINE_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_POSTONLINE_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_EJECT_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_WRITE_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_SET_SOME_FLAG_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_DEV_INFO_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_CARD_INFO_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_MATERIAL_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_SET_MATERIAL_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_SCI_INFO_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_OPEN_SAFELOCK_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_MAGTRANS_INIT_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_CONN_INFO_FINISHED,0) FSM_RULE_ENTRY(s3, s2, USER_EVT_SAM_IC_COMMAND_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_PRINTER_STATUS_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_PRINT_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_SCILIST_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_BIND_SCI_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_PREONLINE_ON_STORE_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_GET_ADD_CARD_INFO_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_PRINT_CARD_IM_FINISHED, 0) FSM_RULE_ENTRY(s3, s2, USER_EVT_QUERY_CI_STATUS_FINISHED, 0) FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s4, FSM_STATE_EXIT, USER_EVT_QUIT, 0) END_FSM_RULE() CCardReadAdapterFSM() : m_pCardIssuer(NULL), m_pCardIssuerStore(NULL), m_pContactless(NULL), m_pHBClient(NULL){} ~CCardReadAdapterFSM(){} 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 TransEntity(CCardReadAdapterEntity* pEty){ m_pEty = pEty; } int Initial(); int DoWork(int type); int CardIssuerRead(SpReqAnsContext::Pointer ctx); int ContactlessCardRead(SpReqAnsContext::Pointer ctx); int IssueCard(SpReqAnsContext::Pointer ctx); void CancelRead(); void ReadWaitMore(); int WriteTrack(SpReqAnsContext::Pointer ctx); int PreOnline(SpReqAnsContext::Pointer ctx); int PostOnline(SpReqAnsContext::Pointer ctx); int EjectCard(SpReqAnsContext::Pointer ctx); int CaptureCard(SpReqAnsContext::Pointer ctx); int QueryCardInfo(SpReqAnsContext::Pointer ctx); void CheckAndReconnectSession(); int SetSomeFlag(SpReqAnsContext::Pointer ctx); void DoExit(); int GetMaterialCount(SpReqAnsContext::Pointer ctx); int SetMaterialCount(SpReqAnsContext::Pointer ctx); int OpenSafeLock(SpReqAnsContext::Pointer ctx); int MagTransferInit(SpReqAnsContext::Pointer ctx); int QueryConnInfo(SpReqAnsContext::Pointer ctx); int GetDevInfo(SpReqAnsContext::Pointer ctx); void BroadcastReadICing(int status); int SAMICCommand(SpReqAnsContext::Pointer ctx); int QueryPrinterStatus(SpReqAnsContext::Pointer ctx); int Print(SpReqAnsContext::Pointer ctx); int QuerySCIList(SpReqAnsContext::Pointer ctx); int BindSCI(SpReqAnsContext::Pointer ctx); int PreOnlineOnStore(SpReqAnsContext::Pointer ctx); int NotifyPreonline(SpReqAnsContext::Pointer ctx); int QueryCardInfoOnStore(SpReqAnsContext::Pointer ctx); int GetAddCardInfo(SpReqAnsContext::Pointer ctx); int Test1(SpReqAnsContext::Pointer ctx); int Test2(SpReqAnsContext::Pointer ctx); void SelfTest(EntityTestEnum eTestType, CSmartPointer pTransactionContext); void SetReadCtx(SpReqAnsContext::Pointer ctx) { m_readCtx = ctx; } bool GetAttachedTerminal(CSimpleStringA &csTerm); int CrossTermCall(SpReqAnsContext::Pointer ctx); void CrossTermInvokeInfo(SpOnewayCallContext::Pointer ctx); void CancelReadForEntity(ModuleType eModule); int PrintCardIm(SpReqAnsContext::Pointer ctx); void QueryCurrFSMAndLastS2EventInfo(int &currFSM, int& event, int& param1) { currFSM = GetCurrState()->id; event = m_lastS2Event; param1 = m_lastS2EvtParam1; } MachineTypeEnum GetMachineType() {return m_eMachineType;} int QueryCIStatus(SpReqAnsContext::Pointer ctx); void WaitCardActive(); protected: //LPIDCCARDDATA* lppCardData; int m_iInsertTries; int m_resetTries; int m_ejectTries; private: CCardReadAdapterEntity *m_pEty; CardIssuerStandService_ClientBase *m_pCardIssuer; CardIssuerStoreService_ClientBase* m_pCardIssuerStore; ContactlessCardService_ClientBase *m_pContactless; HeartBeatService_ClientBase* m_pHBClient; BusinessContext m_busCtx; SpReqAnsContext::Pointer m_readCtx; //m_lastModule:0~7 //0:all; 1:CardIssuerStand or CardIssuerStore; 2:ContactlessCard int m_lastModule,m_lastS2Event, m_lastS2EvtParam1; MachineTypeEnum m_eMachineType; /// int m_resetTimes; bool m_devInit, m_bCancelAccept, m_bWaitingAccept, m_bWaitAccepteMore , m_bCDA, m_bIssuingExit, m_bCardIssued, m_bCaptureCfgFlag, m_bHasHopper[3] , m_bCardActiveNotify; ErrorCodeEnum m_testResult; //m_CardInit,m_CardRemains,m_CardIssued,m_CardMixed,m_CardPercent char *m_pDataToARQC; long xxTest; CSimpleStringA m_currCardNo, m_captureReason, m_csMachineType, m_terminalNo; char m_AuthCode[2]; SpReqAnsContext::Pointer m_crossCtx; ULONGLONG m_ullCrossStart; bool IsCardIssuerSessionOK(); bool IsContactlessCardSessionOK(); bool IsTheEntity(int module,ModuleType eModule); bool CheckHBSessionOrToConnect(); //oilyang@20230614 跨及时因为卡片的实际交易发生在卡库,需要在发起端对返回的UserErrorCode做二次映射,方便客户理解提示信息 DWORD MapErrorCodeWhileCallStore(DWORD eErrCode) { //eErrCode defined on CardIssuer_UserErrorCode.h switch (eErrCode) { case 0x20300240: case 0x22000240: return 0x203002E0; case 0x20300242: case 0x22000242: return 0x203002E1; case 0x20300243: case 0x22000243: case 0x203002a1: case 0x220002a1: return 0x203002E2; case 0x20300244: case 0x22000244: return 0x203002E3; case 0x20300246: case 0x22000246: return 0x203002E4; case 0x2030000D: case 0x2200000D: return 0x203002E5; default: return eErrCode; } } bool IsCardIssuerStore() { if (m_eMachineType == RVC_CardStore || m_eMachineType == RVC_CardPrinter) { return true; } else { return false; } } }; struct InitTask : public ITaskSp { CCardReadAdapterFSM* fsm; InitTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_INIT_FINISHED); e->param1 = fsm->Initial(); fsm->PostEventFIFO(e); } }; struct CardIssuerReadTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; CardIssuerReadTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { CardReadFinishedEvent *e = new CardReadFinishedEvent(); e->ctx = ctx; e->param1 = fsm->CardIssuerRead(ctx); fsm->PostEventFIFO(e); } }; struct ContactlessCardReadTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; ContactlessCardReadTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { CardReadFinishedEvent *e = new CardReadFinishedEvent(); e->ctx = ctx; e->param1 = fsm->ContactlessCardRead(ctx); fsm->PostEventFIFO(e); } }; struct WriteTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; WriteTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { CardWriteFinishedEvent *e = new CardWriteFinishedEvent(); e->ctx = ctx; e->param1 = fsm->WriteTrack(ctx); fsm->PostEventFIFO(e); } }; struct DoWorkTask : public ITaskSp { CCardReadAdapterFSM* fsm; int type; DoWorkTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { //FSMEvent *e = new FSMEvent(USER_EVT_DO_WORK_FINISHED); //e->param1 = fsm->DoWork(type); //fsm->PostEventFIFO(e); } }; struct TestCancelReadTask : public ITaskSp { CCardReadAdapterFSM* fsm; int type; TestCancelReadTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { Sleep(10000); fsm->CancelRead(); } }; struct ReadWaitMoreTask : public ITaskSp { CCardReadAdapterFSM* fsm; int type; ReadWaitMoreTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { fsm->ReadWaitMore(); } }; struct PreOnlineTask : public ITaskSp { SpReqAnsContext::Pointer ctx; CCardReadAdapterFSM* fsm; PreOnlineTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_PREONLINE_FINISHED); e->param1 = fsm->PreOnline(ctx); fsm->PostEventFIFO(e); } }; struct PostOnlineTask : public ITaskSp { SpReqAnsContext::Pointer ctx; CCardReadAdapterFSM* fsm; PostOnlineTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_POSTONLINE_FINISHED); e->param1 = fsm->PostOnline(ctx); fsm->PostEventFIFO(e); } }; struct IssueTask : public ITaskSp { SpReqAnsContext::Pointer ctx; CCardReadAdapterFSM* fsm; IssueTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_ISSUE_FINISHED); e->param1 = fsm->IssueCard(ctx); fsm->PostEventFIFO(e); } }; struct EjectTask : public ITaskSp { SpReqAnsContext::Pointer ctx; CCardReadAdapterFSM* fsm; EjectTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_EJECT_FINISHED); e->param1 = fsm->EjectCard(ctx); fsm->PostEventFIFO(e); } }; struct CaptureTask : public ITaskSp { SpReqAnsContext::Pointer ctx; CCardReadAdapterFSM* fsm; CaptureTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_CAPTUREFINISHED); e->param1 = fsm->CaptureCard(ctx); fsm->PostEventFIFO(e); } }; struct CheckSessionTask : public ITaskSp { CCardReadAdapterFSM* fsm; CheckSessionTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { fsm->CheckAndReconnectSession(); } }; struct SetSomeFlagTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; SetSomeFlagTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_SET_SOME_FLAG_FINISHED); e->param1 = fsm->SetSomeFlag(ctx); fsm->PostEventFIFO(e); } }; struct GetDevInfoTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; GetDevInfoTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_GET_DEV_INFO_FINISHED); e->param1 = fsm->GetDevInfo(ctx); fsm->PostEventFIFO(e); } }; struct QueryCardInfoTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; QueryCardInfoTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_QUERY_CARD_INFO_FINISHED); e->param1 = fsm->QueryCardInfo(ctx); fsm->PostEventFIFO(e); } }; struct GetMaterialCountTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; GetMaterialCountTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_GET_MATERIAL_FINISHED); e->param1 = fsm->GetMaterialCount(ctx); fsm->PostEventFIFO(e); } }; struct SetMaterialCountTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; SetMaterialCountTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_SET_MATERIAL_FINISHED); e->param1 = fsm->SetMaterialCount(ctx); fsm->PostEventFIFO(e); } }; struct OpenSafeLockTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; OpenSafeLockTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_OPEN_SAFELOCK_FINISHED); e->param1 = fsm->OpenSafeLock(ctx); fsm->PostEventFIFO(e); } }; struct MagTransferInitTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; MagTransferInitTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_MAGTRANS_INIT_FINISHED); e->param1 = fsm->MagTransferInit(ctx); fsm->PostEventFIFO(e); } }; struct QueryConnInfoTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; QueryConnInfoTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_QUERY_CONN_INFO_FINISHED); e->param1 = fsm->QueryConnInfo(ctx); fsm->PostEventFIFO(e); } }; struct DoExitTask : public ITaskSp { CCardReadAdapterFSM* fsm; DoExitTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { fsm->DoExit(); } }; struct SAMICCommandTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; SAMICCommandTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_SAM_IC_COMMAND_FINISHED); e->param1 = fsm->SAMICCommand(ctx); fsm->PostEventFIFO(e); } }; struct QueryPrinterStatusTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; QueryPrinterStatusTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_QUERY_PRINTER_STATUS_FINISHED); e->param1 = fsm->QueryPrinterStatus(ctx); fsm->PostEventFIFO(e); } }; struct PrintTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; PrintTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_PRINT_FINISHED); e->param1 = fsm->Print(ctx); fsm->PostEventFIFO(e); } }; struct QuerySCIListTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; QuerySCIListTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_QUERY_SCILIST_FINISHED); e->param1 = fsm->QuerySCIList(ctx); fsm->PostEventFIFO(e); } }; struct BindSCITask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; BindSCITask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_BIND_SCI_FINISHED); e->param1 = fsm->BindSCI(ctx); fsm->PostEventFIFO(e); } }; struct PreOnlineOnStoreTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; PreOnlineOnStoreTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { fsm->PreOnlineOnStore(ctx); } }; struct GetAddCardInfoTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; GetAddCardInfoTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_GET_ADD_CARD_INFO_FINISHED); e->param1 = fsm->GetAddCardInfo(ctx); fsm->PostEventFIFO(e); } }; struct NotifyPreOnlineTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; NotifyPreOnlineTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent* e = new FSMEvent(USER_EVT_PREONLINE_ON_STORE_FINISHED); e->param1 = fsm->NotifyPreonline(ctx); fsm->PostEventFIFO(e); } }; struct QueryCardInfoOnStoreTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; QueryCardInfoOnStoreTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_QUERY_CARD_INFO_ON_STORE_FINISHED); e->param1 = fsm->QueryCardInfoOnStore(ctx); fsm->PostEventFIFO(e); } }; struct CrossTermCallTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; CrossTermCallTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_CROSS_TERM_CALL_FINISHED); e->param1 = fsm->CrossTermCall(ctx); fsm->PostEventFIFO(e); } }; struct PrintCardImTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; PrintCardImTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent* e = new FSMEvent(USER_EVT_PRINT_CARD_IM_FINISHED); e->param1 = fsm->PrintCardIm(ctx); fsm->PostEventFIFO(e); } }; struct QueryCIStatusTask : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; QueryCIStatusTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent* e = new FSMEvent(USER_EVT_QUERY_CI_STATUS_FINISHED); e->param1 = fsm->QueryCIStatus(ctx); fsm->PostEventFIFO(e); } }; struct Test1Task : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; Test1Task(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_TEST1_FINISHED); e->param1 = fsm->Test1(ctx); fsm->PostEventFIFO(e); } }; struct Test2Task : public ITaskSp { CCardReadAdapterFSM* fsm; SpReqAnsContext::Pointer ctx; Test2Task(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_TEST1_FINISHED); e->param1 = fsm->Test2(ctx); fsm->PostEventFIFO(e); } }; struct WaitCardActiveTask : public ITaskSp { CCardReadAdapterFSM* fsm; WaitCardActiveTask(CCardReadAdapterFSM* f) : fsm(f) {} void Process() { fsm->WaitCardActive(); } }; #endif //__CARDREAD_ADAPTER_FSM_H