mod_gpio.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 "GetDevInfoHelper.h"
  9. #include "Gpio_UserErrorCode.h"
  10. #include "DevFSMCommBase.hpp"
  11. #include "CommEntityUtil.hpp"
  12. using namespace std;
  13. using namespace Gpio;
  14. const int GPIO_INIT_COUNT = 3;
  15. typedef ErrorCodeEnum (*lpCreateDevCom)(DeviceBaseClass *&baseObj);
  16. typedef ErrorCodeEnum (*lpReleaseDevCom)(DeviceBaseClass *&pBaseObj);
  17. enum OutputMode{
  18. OM_POSITIVE_LEVEL,
  19. OM_NEGATIVE_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 InputMode{
  29. IM_POSITIVE_PULSE_UP,
  30. IM_NEGATIVE_PULSE_DOWN,
  31. IM_POSITIVE_PULSE_BOTH,
  32. IM_NEGATIVE_PULSE_BOTH,
  33. IM_POSITIVE_LEVEL,
  34. IM_NEGATIVE_LEVEL
  35. };
  36. enum PinPort{
  37. VIBRATIONSENSOR, /**震动探测器*/
  38. OPENSENSOR, /*开机箱门感应器*/
  39. PICKUPSENSOR, /*话机感应器*/
  40. MOVESENSOR, /**人体探测感应器*/
  41. CARDGATESENSOR, /**发卡器卡嘴感应器*/
  42. };
  43. /*用于标识等挂机等状态,布尔型不能满足,需要有一个初始状态*/
  44. enum PinActiveStatus
  45. {
  46. UnknownStatus,
  47. InActive,
  48. Actived
  49. };
  50. struct OutDrivingInfo
  51. {
  52. ULONG Port;
  53. int OutputMode;
  54. int StopMode;
  55. int SetTime;
  56. int ResetTime;
  57. int TimeOut;
  58. };
  59. struct ReceivingInfo
  60. {
  61. ULONG Port;
  62. int InputMode;
  63. int ContinuousTriggerTime;
  64. };
  65. /** 添加注释:对应规格说明书中的引脚信号 [Gifur@202494]*/
  66. enum DevicePinSeq
  67. {
  68. PIN_CARD_READER_LIGHT,
  69. PIN_USB_CONTROL_SWITCH, //已下线
  70. PIN_IDCERTIFICATE_LIGHT,
  71. PIN_PINPAD_LIGHT,
  72. PIN_HEAD_LIGHT,
  73. PIN_TROUBLE_LIGHT,
  74. PIN_CARD_ISSUE_MAINTAIN_LIGHT,
  75. PIN_USB_CONTROL_LIGHT,//已下线
  76. PIN_CONTACELESS_LIGHT,
  77. PIN_RESERVED1, //RESERVED未使用,下同
  78. PIN_FINGERPRINT_LIGHT,
  79. PIN_RESERVED2,
  80. PIN_HSPSCANNER_PREVIEW_LIGHT,
  81. PIN_RESERVED3,
  82. PIN_RESERVED4,
  83. PIN_RESERVED5,
  84. PIN_HSPSCANNER_LIGHT = 25
  85. };
  86. //TODO: 临时 [Gifur@202494]
  87. struct GpioService_Set_Info
  88. {
  89. int devseq;
  90. int mode;
  91. int close;
  92. };
  93. class CGpioEntity;
  94. class CGpioServiceSession : public GpioService_ServerSessionBase
  95. {
  96. public:
  97. CGpioServiceSession(CGpioEntity* pEntity):m_pEntity(pEntity){};
  98. virtual void Handle_GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
  99. GpioService_GetDevInfo_Ans>::Pointer ctx);
  100. virtual void Handle_Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx);
  101. private:
  102. CGpioEntity* m_pEntity;
  103. };
  104. struct DevOutputInfo
  105. {
  106. ULONG dir;
  107. ULONG output;
  108. };
  109. struct SetContextInfo
  110. {
  111. ULONG timerID;
  112. BYTE index;
  113. ULONG pinSeq;
  114. int setTime;
  115. int resetTime;
  116. int timeout;
  117. };
  118. struct GetContextInfo
  119. {
  120. int Port;
  121. ULONG timerID;
  122. ULONG index;
  123. int CttPhone,CttMove,CttShake,CttSwitch,CttCard;
  124. //ContinuousTriggerTime get from configure file
  125. int InitCTT;
  126. };
  127. class CGpioEntity : public CDevAdptEntityBase, public ILogListener
  128. {
  129. public:
  130. //0000 0000 0000 0010 0110 1111 1100 0000
  131. CGpioEntity():m_devEnableStatus(0x1f),m_bPickUpRound(false),m_bVibrationRound(false)
  132. ,m_bOpenRound(false),m_bMoveRound(false),m_bCardGateRound(false), m_ePickUpFlag(UnknownStatus)
  133. ,m_bVibrationFlag(false),m_bOpenFlag(false),m_bMoveFlag(false),m_bCardGateFlag(false)
  134. , m_pLogListener(NULL), m_bHeadLightFlag(false), m_headlightDevPort(0), m_moveHoldTimes(0)
  135. , m_moveDisappearTimes(0),m_eMachineType(SP::Module::Comm::RVC_UNKNOWN)
  136. , m_bNewVersion(FALSE), m_bFuncVer2(FALSE), m_FirstStart(true)
  137. , m_csDevNo(true), m_port(true), m_portNum(true), m_Baudrate(true), m_bOpened(false), m_bOpening(true)
  138. {
  139. m_timerID = 1;
  140. currDevStatus.dir = 0x3eFC0;
  141. // 11 1110 1111 1100 0000
  142. //currDevStatus.dir = 0x7ffb0;
  143. memset(m_btOutputStatus,0,MAX_PORT_NUM);
  144. currDevStatus.output = 0x0;
  145. // currDir = 0x2007ffff;
  146. //m_pPIUT = new PositivePulseUpTimer();
  147. HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x209);
  148. }
  149. virtual ~CGpioEntity(){}
  150. virtual const char* GetEntityName()const {return "Gpio";}
  151. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  152. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
  153. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  154. {
  155. CSimpleStringA initDriver = "";
  156. int driverPort;
  157. initDriver = "CardReaderNormal";
  158. driverPort = 0;
  159. OutDrivingInfo odi;
  160. GetOutDrivingModInfo(initDriver,odi);
  161. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read port[%u]",(ULONG)driverPort);
  162. pTransactionContext->SendAnswer(Error_Succeed);
  163. }
  164. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  165. {
  166. LOG_FUNCTION();
  167. if(m_hDevHelper != nullptr) m_hDevHelper.TearDown();
  168. pTransactionContext->SendAnswer(Error_Succeed);
  169. }
  170. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * pszClass)
  171. {
  172. return new CGpioServiceSession(this);
  173. }
  174. bool SetOutDriving(GpioService_Set_Info req, OutDrivingInfo od, ULONG iIndex, ULONG devSeq);
  175. void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
  176. void Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx) {}
  177. void GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
  178. GpioService_GetDevInfo_Ans>::Pointer ctx);
  179. bool GetReceiving(int deviceSeq,ReceivingInfo ri, ULONG iIndex);
  180. DevOutputInfo GetCurrDevStatus()const {return currDevStatus;}
  181. void SaveCurrDevStatus(DevOutputInfo devOutputInfo) {currDevStatus = devOutputInfo;}
  182. ULONG GetDevEnableStatus(){return m_devEnableStatus;}
  183. void SetDevEnableStatus(ULONG devEnableStatus){m_devEnableStatus = devEnableStatus;}
  184. ULONG GetNewTimerID(){return m_timerID++;}
  185. BYTE GetOutputStatus(int sn=0);
  186. virtual bool IsService()const{return true;}
  187. virtual bool IsMultiThread()const{return false;}
  188. ErrorCodeEnum Initial();
  189. void OnOutputPositiveLevelTimerout(void *pData);
  190. void OnPositiveFlickerSetTimerout(void *pData);
  191. void OnPositiveFlickerResetTimerout(void *pData);
  192. void OnPositiveLevelTimerOut(void* pData);
  193. void GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi);
  194. void GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri);
  195. void GetStatus(int deviceSeq);
  196. void Set(GpioService_Set_Info info);
  197. void SetEx(GpioService_Set_Info info);
  198. void WritePin(DWORD dwPinSeq,bool bHighLevel);
  199. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  200. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  201. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
  202. void ToLogRootINIInfo();
  203. void ToLogWarnInfoAboutTerm(const AdapterInfo& m_adapterInfo);
  204. bool DetectBit(ULONG data, int pos);
  205. public:
  206. CUUID m_uuidHealth, m_uuidPtr, m_uuidCR, m_uuidIDC, m_uuidFP, m_uuidKB, m_uuidCA, m_uuidCC, m_uuidDD, m_uuidCS, m_uuidIE;
  207. CUUID m_uuidHSPscanner;
  208. private:
  209. DevAdptLibHelper<GpioClass> m_hDevHelper;
  210. SP::Module::Comm::What m_eMachineType;
  211. BYTE m_btOutputStatus[MAX_PORT_NUM];
  212. DWORD m_dwPortNum,m_dwInOutDir;
  213. BOOL m_bNewVersion;
  214. BOOL m_bFuncVer2;
  215. DevOutputInfo currDevStatus;
  216. DevCategoryInfo m_devCatInfo;
  217. ULONG m_devEnableStatus;
  218. ULONG m_timerID;
  219. bool m_bPickUpRound,m_bVibrationRound,m_bOpenRound,m_bMoveRound,m_bCardGateRound;
  220. bool m_bVibrationFlag,m_bOpenFlag,m_bMoveFlag,m_bCardGateFlag;
  221. PinActiveStatus m_ePickUpFlag;
  222. bool m_bHeadLightFlag;
  223. int m_headlightDevPort, m_moveHoldTimes, m_moveDisappearTimes;
  224. ILogListener *m_pLogListener;
  225. CSimpleStringA m_csMachineType, m_csAlarmMsg;
  226. DevEntityErrorCode m_entCode;
  227. bool IfHaveMoveDetect();
  228. ErrorPackage m_errPkg;
  229. AdapterInfo m_adapterInfo;
  230. CSimpleStringA m_csDevNo;
  231. CSimpleStringA m_port;
  232. CSimpleStringA m_portNum;
  233. CSimpleStringA m_Baudrate;
  234. bool m_FirstStart;
  235. bool m_bOpened;
  236. bool m_bOpening;
  237. };
  238. template<class T>
  239. class TimerOutHelper : public ITimerListener
  240. {
  241. public:
  242. typedef void (T::*FuncTimer)(void *pUserdata);
  243. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  244. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  245. virtual void OnTimeout(DWORD dwTimerID)
  246. {
  247. (m_pObject->*m_pTimer)(m_pUserData);
  248. if (m_bDeleteSelf)
  249. delete this;
  250. }
  251. private:
  252. void *m_pUserData;
  253. T *m_pObject;
  254. FuncTimer m_pTimer;
  255. bool m_bDeleteSelf;
  256. };
  257. #endif //__MOD_GPIO_H