mod_gpio.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #ifndef __MOD_GPIO_H
  2. #define __MOD_GPIO_H
  3. #include "modVer.h"
  4. #include "SpBase.h"
  5. #include "GpioClass.h"
  6. #include "Gpio_server_g.h"
  7. #include "EventCode.h"
  8. #include "Gpio_UserErrorCode.h"
  9. #include "DevFSMCommBase.hpp"
  10. #include "CommEntityUtil.hpp"
  11. using namespace std;
  12. using namespace Gpio;
  13. #define GpioService_LogCode_Detect_DoorOpen "QLR0402209A1"
  14. #define GpioService_LogCode_Detect_PhonePickup "QLR0402209A2"
  15. #define GpioService_LogCode_Detect_CardMouseJam "QLR0402209A3"
  16. #define GpioService_LogCode_Detect_DoorClose "QLR0402209A4"
  17. #define GpioService_LogCode_Detect_PhonePutDown "QLR0402209A5"
  18. enum OutputMode{
  19. OM_POSITIVE_LEVEL,
  20. OM_POSITIVE_FLICKER,
  21. OM_NEGATIVE_FLICKER
  22. };
  23. enum StopMode{
  24. SM_CALLTRIGGER,
  25. SM_TIMEOUT,
  26. SM_CYCLE
  27. };
  28. enum PinPort {
  29. VIBRATIONSENSOR, /**震动探测器*/
  30. OPENSENSOR, /*开机箱门感应器*/
  31. PICKUPSENSOR, /*话机感应器*/
  32. MOVESENSOR, /**人体探测感应器*/
  33. CARDGATESENSOR, /**发卡器卡嘴感应器*/
  34. };
  35. /*用于标识等挂机等状态,布尔型不能满足,需要有一个初始状态*/
  36. enum PinActiveStatus
  37. {
  38. UnknownStatus,
  39. InActive,
  40. Actived
  41. };
  42. struct OutDrivingInfo
  43. {
  44. ULONG Port;
  45. int OutputMode;
  46. int StopMode;
  47. int SetTime;
  48. int ResetTime;
  49. int TimeOut;
  50. };
  51. struct ReceivingInfo
  52. {
  53. ULONG Port;
  54. int ContinuousTriggerTime;
  55. };
  56. enum LightSeq {
  57. UNKNOWN_DEVICE,
  58. CARDREADER,
  59. CARDREADER_RED,
  60. IDCERTIFICATE,
  61. PINPAD,
  62. PINPADLIGHT,
  63. SHAKEDETECT,
  64. SWITCHINDUCTOR,
  65. PHONEPICKUP,
  66. MOVEDETECT,
  67. CARDGATEDETECT,
  68. HEADLIGHT,
  69. HEADLIGHT_RED,
  70. CONTACTLESSCARD,
  71. HEADLIGHT_ASSIST,
  72. HSPSCANNER,
  73. FINGERPRINT
  74. };
  75. /** 添加注释:对应规格说明书中的引脚信号,这里是从0开始,适应程序 [Gifur@202494]*/
  76. enum DevicePinSeq
  77. {
  78. PIN_CARD_READER_LIGHT = 0,
  79. PIN_USB_CONTROL_SWITCH, //已下线
  80. PIN_IDCERTIFICATE_LIGHT,
  81. PIN_PINPAD_LIGHT,
  82. PIN_HEAD_LIGHT,
  83. PIN_TROUBLE_LIGHT = 5,
  84. PIN_CARD_ISSUE_MAINTAIN_LIGHT,
  85. PIN_USB_CONTROL_LIGHT,//已下线
  86. PIN_CONTACELESS_LIGHT,
  87. PIN_RESERVED1, //RESERVED未使用,下同
  88. PIN_FINGERPRINT_LIGHT = 10,
  89. PIN_RESERVED2,
  90. PIN_HSPSCANNER_PREVIEW_LIGHT,
  91. PIN_RESERVED3,
  92. PIN_RESERVED4,
  93. PIN_RESERVED5 = 15,
  94. PIN_DETECT_SHAKE = 16,
  95. PIN_DETECT_OPENDOOR,
  96. PIN_DETECT_PHONE,
  97. PIN_DETECT_BODY,
  98. PIN_HSPSCANNER_LIGHT = 25
  99. };
  100. struct GpioService_Set_Info
  101. {
  102. int devseq;
  103. int mode;
  104. int close;
  105. };
  106. class CGpioEntity;
  107. class CGpioServiceSession : public GpioService_ServerSessionBase
  108. {
  109. public:
  110. CGpioServiceSession(CGpioEntity* pEntity):m_pEntity(pEntity){};
  111. virtual void Handle_GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
  112. GpioService_GetDevInfo_Ans>::Pointer ctx);
  113. virtual void Handle_Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx);
  114. private:
  115. CGpioEntity* m_pEntity;
  116. };
  117. struct SetContextInfo
  118. {
  119. ULONG timerID;
  120. ULONG pinSeq;
  121. int setTime;
  122. int resetTime;
  123. int timeout;
  124. };
  125. struct GetContextInfo
  126. {
  127. ULONG timerID;
  128. };
  129. class CGpioEntity : public CDevAdptEntityBase, public ILogListener, ISysVarListener
  130. {
  131. public:
  132. //0000 0000 0000 0010 0110 1111 1100 0000
  133. CGpioEntity():m_ePickUpFlag(UnknownStatus)
  134. ,m_bVibrationFlag(false),m_bOpenFlag(false),m_bMoveFlag(false),m_bCardGateFlag(false)
  135. , m_pLogListener(NULL), m_bHeadLightFlag(false), m_headlightDevPort(4), m_moveHoldTimes(0)
  136. , m_moveDisappearTimes(0),m_eMachineType(SP::Module::Comm::RVC_UNKNOWN)
  137. , m_bNewVersion(FALSE), m_bFuncVer2(FALSE)
  138. , m_bOpened(false), m_bOpening(true), m_btLastRevcInput(-1), m_iInWhatPage(PageType_Init)
  139. {
  140. memset(m_btOutputStatus,0,MAX_PORT_NUM*sizeof(BYTE));
  141. }
  142. virtual ~CGpioEntity(){}
  143. virtual const char* GetEntityName()const {return "Gpio";}
  144. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  145. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
  146. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  147. {
  148. pTransactionContext->SendAnswer(Error_Succeed);
  149. }
  150. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  151. {
  152. if(m_hDevHelper != nullptr) m_hDevHelper.TearDown();
  153. pTransactionContext->SendAnswer(Error_Succeed);
  154. }
  155. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * pszClass)
  156. {
  157. return new CGpioServiceSession(this);
  158. }
  159. void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
  160. virtual bool IsService()const { return true; }
  161. virtual bool IsMultiThread()const { return false; }
  162. virtual void OnSysVarEvent(const char* pszKey,
  163. const char* pszValue, const char* pszOldValue, const char* pszEntityName);
  164. void GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
  165. GpioService_GetDevInfo_Ans>::Pointer ctx);
  166. void Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx) {}
  167. //////////////////////////////////////////////////////////////////////////
  168. ErrorCodeEnum Initial();
  169. void OnPositiveFlickerSetTimerout(void *pData);
  170. void OnPositiveFlickerResetTimerout(void *pData);
  171. void OnEventDetect(void* pData);
  172. //开了一个监听线程,用于监听震动、开关门等事件
  173. void StartDetectWorkThread();
  174. void Set(GpioService_Set_Info info);
  175. void SetEx(GpioService_Set_Info info);
  176. bool SetOutDriving(GpioService_Set_Info req, OutDrivingInfo od, ULONG iIndex, ULONG devSeq);
  177. void WritePin(DWORD dwPinSeq,bool bHighLevel);
  178. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  179. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  180. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
  181. void ToLogRootINIInfo();
  182. void ToLogWarnInfoAboutTerm(const AdapterInfo& m_adapterInfo);
  183. void SetErrorAndLog(ErrorCodeEnum errCode, DWORD userCode, CSimpleStringA devApi, CSimpleStringA funPath, bool bInBusiness = false, int costTime = 0, CSimpleStringA logCode = "", CSimpleStringA context = "");
  184. public:
  185. CUUID m_uuidHealth, m_uuidCR, m_uuidIDC, m_uuidFP, m_uuidKB, m_uuidCA, m_uuidCC, m_uuidDD, m_uuidCS;
  186. CUUID m_uuidHSPscanner;
  187. private:
  188. bool DetectBit(ULONG data, int pos);
  189. bool IsInBusiness() const { return (m_iInWhatPage == PageType_Other); }
  190. void SetInWhatPage(int iPageType) { m_iInWhatPage = iPageType; }
  191. private:
  192. DevAdptLibHelper<GpioClass> m_hDevHelper;
  193. SP::Module::Comm::What m_eMachineType;
  194. BYTE m_btOutputStatus[MAX_PORT_NUM];
  195. BOOL m_bNewVersion;
  196. BOOL m_bFuncVer2;
  197. BYTE m_btLastRevcInput;
  198. bool m_bVibrationFlag,m_bOpenFlag,m_bMoveFlag,m_bCardGateFlag;
  199. PinActiveStatus m_ePickUpFlag;
  200. unsigned long m_PickUpTimeStamp;
  201. unsigned long m_PutDownTimeStamp;
  202. unsigned long m_DoorOpenTimeStamp;
  203. unsigned long m_DoorCloseTimeStamp;
  204. bool m_bHeadLightFlag;
  205. int m_headlightDevPort;
  206. unsigned long m_moveHoldTimes, m_moveDisappearTimes;
  207. ILogListener *m_pLogListener;
  208. AdapterInfo m_adapterInfo;
  209. bool m_bOpened;
  210. bool m_bOpening;
  211. int m_iInWhatPage/*在哪个页面,区分首页,用户桌面,其他页*/;
  212. };
  213. template<class T>
  214. class TimerOutHelper : public ITimerListener
  215. {
  216. public:
  217. typedef void (T::*FuncTimer)(void *pUserdata);
  218. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  219. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  220. virtual void OnTimeout(DWORD dwTimerID)
  221. {
  222. (m_pObject->*m_pTimer)(m_pUserData);
  223. if (m_bDeleteSelf)
  224. delete this;
  225. }
  226. private:
  227. void *m_pUserData;
  228. T *m_pObject;
  229. FuncTimer m_pTimer;
  230. bool m_bDeleteSelf;
  231. };
  232. #endif //__MOD_GPIO_H