mod_gpio.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. enum PrintSealType{
  66. PRINTERSEAL_UNKNOWN = 0,
  67. PRINTER_LIGHT_GREEN,
  68. PRINTER_LIGHT_RED,
  69. PRINTER_LIGHT_OFF,
  70. PAPER_LIGHT_GREEN,
  71. PAPER_LIGHT_RED,
  72. PAPER_LIGHT_OFF
  73. };
  74. enum DevicePinSeq
  75. {
  76. PIN_CARD_READER_LIGHT,
  77. PIN_USB_CONTROL_SWITCH,
  78. PIN_IDCERTIFICATE_LIGHT,
  79. PIN_PINPAD_LIGHT,
  80. PIN_HEAD_LIGHT,
  81. PIN_TROUBLE_LIGHT,
  82. PIN_CARD_ISSUE_MAINTAIN_LIGHT,
  83. PIN_USB_CONTROL_LIGHT,
  84. PIN_CONTACELESS_LIGHT,
  85. PIN_QR_LIGHT,
  86. PIN_FINGERPRINT_LIGHT,
  87. PIN_THERMPRINT_LIGHT,
  88. PIN_HSPSCANNER_PREVIEW_LIGHT,
  89. PIN_PRINTERSEAL_GREEN_LIGHT,
  90. PIN_PAPER_SLOT_GREEN_LIGHT,
  91. PIN_PAPER_SHORTAGE_RED_LIGHT,
  92. PIN_PRINTERSEAL_RED_LIGHT = 24,
  93. PIN_HSPSCANNER_LIGHT
  94. };
  95. class CGpioEntity;
  96. class CGpioServiceSession : public GpioService_ServerSessionBase
  97. {
  98. public:
  99. CGpioServiceSession(CGpioEntity* pEntity):m_pEntity(pEntity){};
  100. virtual void Handle_Set(SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx);
  101. virtual void Handle_GetStatus(SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx);
  102. virtual void Handle_QueryCurrSet(SpReqAnsContext<GpioService_QueryCurrSet_Req, GpioService_QueryCurrSet_Ans>::Pointer ctx);
  103. private:
  104. CGpioEntity* m_pEntity;
  105. };
  106. struct DevOutputInfo
  107. {
  108. ULONG dir;
  109. ULONG output;
  110. };
  111. struct SetContextInfo
  112. {
  113. SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx;
  114. ULONG timerID;
  115. BYTE index;
  116. ULONG pinSeq;
  117. int setTime;
  118. int resetTime;
  119. int timeout;
  120. };
  121. struct GetContextInfo
  122. {
  123. int Port;
  124. SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx;
  125. ULONG timerID;
  126. ULONG index;
  127. int CttPhone,CttMove,CttShake,CttSwitch,CttCard;
  128. //ContinuousTriggerTime get from configure file
  129. int InitCTT;
  130. };
  131. class CGpioEntity : public CDevAdptEntityBase, public ILogListener
  132. {
  133. public:
  134. //0000 0000 0000 0010 0110 1111 1100 0000
  135. CGpioEntity():m_devEnableStatus(0x1f),m_bPickUpRound(false),m_bVibrationRound(false)
  136. ,m_bOpenRound(false),m_bMoveRound(false),m_bCardGateRound(false), m_ePickUpFlag(UnknownStatus)
  137. ,m_bVibrationFlag(false),m_bOpenFlag(false),m_bMoveFlag(false),m_bCardGateFlag(false)
  138. , m_pLogListener(NULL), m_bHeadLightFlag(false), m_headlightDevPort(0), m_moveHoldTimes(0)
  139. , m_moveDisappearTimes(0),m_eMachineType(SP::Module::Comm::RVC_UNKNOWN)
  140. , m_bNewVersion(FALSE), m_bFuncVer2(FALSE), m_FirstStart(true)
  141. , m_csDevNo(true), m_port(true), m_portNum(true), m_Baudrate(true)
  142. {
  143. m_timerID = 1;
  144. currDevStatus.dir = 0x3eFC0;
  145. // 11 1110 1111 1100 0000
  146. //currDevStatus.dir = 0x7ffb0;
  147. memset(m_btOutputStatus,0,MAX_PORT_NUM);
  148. currDevStatus.output = 0x0;
  149. // currDir = 0x2007ffff;
  150. //m_pPIUT = new PositivePulseUpTimer();
  151. HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x209);
  152. }
  153. virtual ~CGpioEntity(){}
  154. virtual const char* GetEntityName()const {return "Gpio";}
  155. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  156. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
  157. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  158. {
  159. CSimpleStringA initDriver = "";
  160. int driverPort;
  161. initDriver = "CardReaderNormal";
  162. driverPort = 0;
  163. OutDrivingInfo odi;
  164. GetOutDrivingModInfo(initDriver,odi);
  165. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read port[%u]",(ULONG)driverPort);
  166. pTransactionContext->SendAnswer(Error_Succeed);
  167. }
  168. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  169. {
  170. LOG_FUNCTION();
  171. m_hDevHelper.TearDown();
  172. pTransactionContext->SendAnswer(Error_Succeed);
  173. }
  174. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * pszClass)
  175. {
  176. return new CGpioServiceSession(this);
  177. }
  178. bool SetOutDriving(GpioService_Set_Info req,OutDrivingInfo od, ULONG iIndex,ULONG devSeq);
  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,SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx);
  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. };
  236. template<class T>
  237. class TimerOutHelper : public ITimerListener
  238. {
  239. public:
  240. typedef void (T::*FuncTimer)(void *pUserdata);
  241. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  242. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  243. virtual void OnTimeout(DWORD dwTimerID)
  244. {
  245. (m_pObject->*m_pTimer)(m_pUserData);
  246. if (m_bDeleteSelf)
  247. delete this;
  248. }
  249. private:
  250. void *m_pUserData;
  251. T *m_pObject;
  252. FuncTimer m_pTimer;
  253. bool m_bDeleteSelf;
  254. };
  255. #endif //__MOD_GPIO_H