#ifndef __MOD_GPIO_H #define __MOD_GPIO_H #include "modVer.h" #include "SpBase.h" #include "GpioClass.h" #include "Gpio_server_g.h" #include "EventCode.h" #include "GetDevInfoHelper.h" #include "Gpio_UserErrorCode.h" #include "DevFSMCommBase.hpp" #include "CommEntityUtil.hpp" using namespace std; using namespace Gpio; const int GPIO_INIT_COUNT = 3; typedef ErrorCodeEnum (*lpCreateDevCom)(DeviceBaseClass *&baseObj); typedef ErrorCodeEnum (*lpReleaseDevCom)(DeviceBaseClass *&pBaseObj); enum OutputMode{ OM_POSITIVE_LEVEL, OM_NEGATIVE_LEVEL, OM_POSITIVE_FLICKER, OM_NEGATIVE_FLICKER }; enum StopMode{ SM_CALLTRIGGER, SM_TIMEOUT, SM_CYCLE }; enum InputMode{ IM_POSITIVE_PULSE_UP, IM_NEGATIVE_PULSE_DOWN, IM_POSITIVE_PULSE_BOTH, IM_NEGATIVE_PULSE_BOTH, IM_POSITIVE_LEVEL, IM_NEGATIVE_LEVEL }; enum PinPort{ VIBRATIONSENSOR, /**震动探测器*/ OPENSENSOR, /*开机箱门感应器*/ PICKUPSENSOR, /*话机感应器*/ MOVESENSOR, /**人体探测感应器*/ CARDGATESENSOR, /**发卡器卡嘴感应器*/ }; /*用于标识等挂机等状态,布尔型不能满足,需要有一个初始状态*/ enum PinActiveStatus { UnknownStatus, InActive, Actived }; struct OutDrivingInfo { ULONG Port; int OutputMode; int StopMode; int SetTime; int ResetTime; int TimeOut; }; struct ReceivingInfo { ULONG Port; int InputMode; int ContinuousTriggerTime; }; enum PrintSealType{ PRINTERSEAL_UNKNOWN = 0, PRINTER_LIGHT_GREEN, PRINTER_LIGHT_RED, PRINTER_LIGHT_OFF, PAPER_LIGHT_GREEN, PAPER_LIGHT_RED, PAPER_LIGHT_OFF }; enum DevicePinSeq { PIN_CARD_READER_LIGHT, PIN_USB_CONTROL_SWITCH, PIN_IDCERTIFICATE_LIGHT, PIN_PINPAD_LIGHT, PIN_HEAD_LIGHT, PIN_TROUBLE_LIGHT, PIN_CARD_ISSUE_MAINTAIN_LIGHT, PIN_USB_CONTROL_LIGHT, PIN_CONTACELESS_LIGHT, PIN_QR_LIGHT, PIN_FINGERPRINT_LIGHT, PIN_THERMPRINT_LIGHT, PIN_HSPSCANNER_PREVIEW_LIGHT, PIN_PRINTERSEAL_GREEN_LIGHT, PIN_PAPER_SLOT_GREEN_LIGHT, PIN_PAPER_SHORTAGE_RED_LIGHT, PIN_PRINTERSEAL_RED_LIGHT = 24, PIN_HSPSCANNER_LIGHT }; class CGpioEntity; class CGpioServiceSession : public GpioService_ServerSessionBase { public: CGpioServiceSession(CGpioEntity* pEntity):m_pEntity(pEntity){}; virtual void Handle_Set(SpOnewayCallContext::Pointer ctx); virtual void Handle_GetStatus(SpReqAnsContext::Pointer ctx); virtual void Handle_QueryCurrSet(SpReqAnsContext::Pointer ctx); private: CGpioEntity* m_pEntity; }; struct DevOutputInfo { ULONG dir; ULONG output; }; struct SetContextInfo { SpOnewayCallContext::Pointer ctx; ULONG timerID; BYTE index; ULONG pinSeq; int setTime; int resetTime; int timeout; }; struct GetContextInfo { int Port; SpReqAnsContext::Pointer ctx; ULONG timerID; ULONG index; int CttPhone,CttMove,CttShake,CttSwitch,CttCard; //ContinuousTriggerTime get from configure file int InitCTT; }; class CGpioEntity : public CDevAdptEntityBase, public ILogListener { public: //0000 0000 0000 0010 0110 1111 1100 0000 CGpioEntity():m_devEnableStatus(0x1f),m_bPickUpRound(false),m_bVibrationRound(false) ,m_bOpenRound(false),m_bMoveRound(false),m_bCardGateRound(false), m_ePickUpFlag(UnknownStatus) ,m_bVibrationFlag(false),m_bOpenFlag(false),m_bMoveFlag(false),m_bCardGateFlag(false) , m_pLogListener(NULL), m_bHeadLightFlag(false), m_headlightDevPort(0), m_moveHoldTimes(0) , m_moveDisappearTimes(0),m_eMachineType(SP::Module::Comm::RVC_UNKNOWN) , m_bNewVersion(FALSE), m_bFuncVer2(FALSE), m_FirstStart(true) , m_csDevNo(true), m_port(true), m_portNum(true), m_Baudrate(true) { m_timerID = 1; currDevStatus.dir = 0x3eFC0; // 11 1110 1111 1100 0000 //currDevStatus.dir = 0x7ffb0; memset(m_btOutputStatus,0,MAX_PORT_NUM); currDevStatus.output = 0x0; // currDir = 0x2007ffff; //m_pPIUT = new PositivePulseUpTimer(); HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x209); } virtual ~CGpioEntity(){} virtual const char* GetEntityName()const {return "Gpio";} const char* GetEntityVersion() const { return MODULE_VERSION_FULL; } virtual void OnPreStart(CAutoArray strArgs, CSmartPointer pTransactionContext); virtual void OnPrePause(CSmartPointer pTransactionContext) { CSimpleStringA initDriver = ""; int driverPort; initDriver = "CardReaderNormal"; driverPort = 0; OutDrivingInfo odi; GetOutDrivingModInfo(initDriver,odi); DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read port[%u]",(ULONG)driverPort); pTransactionContext->SendAnswer(Error_Succeed); } virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer pTransactionContext) { LOG_FUNCTION(); m_hDevHelper.TearDown(); pTransactionContext->SendAnswer(Error_Succeed); } virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * pszClass) { return new CGpioServiceSession(this); } bool SetOutDriving(GpioService_Set_Info req,OutDrivingInfo od, ULONG iIndex,ULONG devSeq); bool GetReceiving(int deviceSeq,ReceivingInfo ri, ULONG iIndex); DevOutputInfo GetCurrDevStatus()const {return currDevStatus;} void SaveCurrDevStatus(DevOutputInfo devOutputInfo) {currDevStatus = devOutputInfo;} ULONG GetDevEnableStatus(){return m_devEnableStatus;} void SetDevEnableStatus(ULONG devEnableStatus){m_devEnableStatus = devEnableStatus;} ULONG GetNewTimerID(){return m_timerID++;} BYTE GetOutputStatus(int sn=0); virtual bool IsService()const{return true;} virtual bool IsMultiThread()const{return false;} ErrorCodeEnum Initial(); void OnOutputPositiveLevelTimerout(void *pData); void OnPositiveFlickerSetTimerout(void *pData); void OnPositiveFlickerResetTimerout(void *pData); void OnPositiveLevelTimerOut(void* pData); void GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi); void GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri); void GetStatus(int deviceSeq,SpReqAnsContext::Pointer ctx); void Set(GpioService_Set_Info info); void SetEx(GpioService_Set_Info info); void WritePin(DWORD dwPinSeq,bool bHighLevel); virtual void OnLog(const CAutoArray &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel, const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, const CAutoArray &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo); void ToLogRootINIInfo(); void ToLogWarnInfoAboutTerm(const AdapterInfo& m_adapterInfo); bool DetectBit(ULONG data, int pos); public: CUUID m_uuidHealth, m_uuidPtr, m_uuidCR, m_uuidIDC, m_uuidFP, m_uuidKB, m_uuidCA, m_uuidCC, m_uuidDD, m_uuidCS, m_uuidIE; CUUID m_uuidHSPscanner; private: DevAdptLibHelper m_hDevHelper; SP::Module::Comm::What m_eMachineType; BYTE m_btOutputStatus[MAX_PORT_NUM]; DWORD m_dwPortNum,m_dwInOutDir; BOOL m_bNewVersion; BOOL m_bFuncVer2; DevOutputInfo currDevStatus; DevCategoryInfo m_devCatInfo; ULONG m_devEnableStatus; ULONG m_timerID; bool m_bPickUpRound,m_bVibrationRound,m_bOpenRound,m_bMoveRound,m_bCardGateRound; bool m_bVibrationFlag,m_bOpenFlag,m_bMoveFlag,m_bCardGateFlag; PinActiveStatus m_ePickUpFlag; bool m_bHeadLightFlag; int m_headlightDevPort, m_moveHoldTimes, m_moveDisappearTimes; ILogListener *m_pLogListener; CSimpleStringA m_csMachineType, m_csAlarmMsg; DevEntityErrorCode m_entCode; bool IfHaveMoveDetect(); ErrorPackage m_errPkg; AdapterInfo m_adapterInfo; CSimpleStringA m_csDevNo; CSimpleStringA m_port; CSimpleStringA m_portNum; CSimpleStringA m_Baudrate; bool m_FirstStart; }; template class TimerOutHelper : public ITimerListener { public: typedef void (T::*FuncTimer)(void *pUserdata); TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false) : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {} virtual void OnTimeout(DWORD dwTimerID) { (m_pObject->*m_pTimer)(m_pUserData); if (m_bDeleteSelf) delete this; } private: void *m_pUserData; T *m_pObject; FuncTimer m_pTimer; bool m_bDeleteSelf; }; #endif //__MOD_GPIO_H