123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- #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<GpioService_Set_Info>::Pointer ctx);
- virtual void Handle_GetStatus(SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx);
- virtual void Handle_QueryCurrSet(SpReqAnsContext<GpioService_QueryCurrSet_Req, GpioService_QueryCurrSet_Ans>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
- GpioService_GetDevInfo_Ans>::Pointer ctx);
- virtual void Handle_Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx);
- private:
- CGpioEntity* m_pEntity;
- };
- struct DevOutputInfo
- {
- ULONG dir;
- ULONG output;
- };
- struct SetContextInfo
- {
- SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx;
- ULONG timerID;
- BYTE index;
- ULONG pinSeq;
- int setTime;
- int resetTime;
- int timeout;
- };
- struct GetContextInfo
- {
- int Port;
- SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::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_bOpened(false), m_bOpening(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<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
-
- virtual void OnPrePause(CSmartPointer<ITransactionContext> 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<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- m_hDevHelper.TearDown();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * pszClass)
- {
- return new CGpioServiceSession(this);
- }
- void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
- void Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx) {}
- void GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
- GpioService_GetDevInfo_Ans>::Pointer ctx);
- 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<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::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<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD> &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<GpioClass> 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;
- bool m_bOpened;
- bool m_bOpening;
- };
- template<class T>
- 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
|