mod_gpio.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. virtual void Handle_GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
  104. GpioService_GetDevInfo_Ans>::Pointer ctx);
  105. virtual void Handle_Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx);
  106. private:
  107. CGpioEntity* m_pEntity;
  108. };
  109. struct DevOutputInfo
  110. {
  111. ULONG dir;
  112. ULONG output;
  113. };
  114. struct SetContextInfo
  115. {
  116. SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx;
  117. ULONG timerID;
  118. BYTE index;
  119. ULONG pinSeq;
  120. int setTime;
  121. int resetTime;
  122. int timeout;
  123. };
  124. struct GetContextInfo
  125. {
  126. int Port;
  127. SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx;
  128. ULONG timerID;
  129. ULONG index;
  130. int CttPhone,CttMove,CttShake,CttSwitch,CttCard;
  131. //ContinuousTriggerTime get from configure file
  132. int InitCTT;
  133. };
  134. class CGpioEntity : public CDevAdptEntityBase, public ILogListener
  135. {
  136. public:
  137. //0000 0000 0000 0010 0110 1111 1100 0000
  138. CGpioEntity():m_devEnableStatus(0x1f),m_bPickUpRound(false),m_bVibrationRound(false)
  139. ,m_bOpenRound(false),m_bMoveRound(false),m_bCardGateRound(false), m_ePickUpFlag(UnknownStatus)
  140. ,m_bVibrationFlag(false),m_bOpenFlag(false),m_bMoveFlag(false),m_bCardGateFlag(false)
  141. , m_pLogListener(NULL), m_bHeadLightFlag(false), m_headlightDevPort(0), m_moveHoldTimes(0)
  142. , m_moveDisappearTimes(0),m_eMachineType(SP::Module::Comm::RVC_UNKNOWN)
  143. , m_bNewVersion(FALSE), m_bFuncVer2(FALSE), m_FirstStart(true)
  144. , m_csDevNo(true), m_port(true), m_portNum(true), m_Baudrate(true), m_bOpened(false), m_bOpening(true)
  145. {
  146. m_timerID = 1;
  147. currDevStatus.dir = 0x3eFC0;
  148. // 11 1110 1111 1100 0000
  149. //currDevStatus.dir = 0x7ffb0;
  150. memset(m_btOutputStatus,0,MAX_PORT_NUM);
  151. currDevStatus.output = 0x0;
  152. // currDir = 0x2007ffff;
  153. //m_pPIUT = new PositivePulseUpTimer();
  154. HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x209);
  155. }
  156. virtual ~CGpioEntity(){}
  157. virtual const char* GetEntityName()const {return "Gpio";}
  158. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  159. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
  160. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  161. {
  162. CSimpleStringA initDriver = "";
  163. int driverPort;
  164. initDriver = "CardReaderNormal";
  165. driverPort = 0;
  166. OutDrivingInfo odi;
  167. GetOutDrivingModInfo(initDriver,odi);
  168. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read port[%u]",(ULONG)driverPort);
  169. pTransactionContext->SendAnswer(Error_Succeed);
  170. }
  171. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  172. {
  173. LOG_FUNCTION();
  174. m_hDevHelper.TearDown();
  175. pTransactionContext->SendAnswer(Error_Succeed);
  176. }
  177. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * pszClass)
  178. {
  179. return new CGpioServiceSession(this);
  180. }
  181. void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
  182. void Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx) {}
  183. void GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
  184. GpioService_GetDevInfo_Ans>::Pointer ctx);
  185. bool SetOutDriving(GpioService_Set_Info req,OutDrivingInfo od, ULONG iIndex,ULONG devSeq);
  186. bool GetReceiving(int deviceSeq,ReceivingInfo ri, ULONG iIndex);
  187. DevOutputInfo GetCurrDevStatus()const {return currDevStatus;}
  188. void SaveCurrDevStatus(DevOutputInfo devOutputInfo) {currDevStatus = devOutputInfo;}
  189. ULONG GetDevEnableStatus(){return m_devEnableStatus;}
  190. void SetDevEnableStatus(ULONG devEnableStatus){m_devEnableStatus = devEnableStatus;}
  191. ULONG GetNewTimerID(){return m_timerID++;}
  192. BYTE GetOutputStatus(int sn=0);
  193. virtual bool IsService()const{return true;}
  194. virtual bool IsMultiThread()const{return false;}
  195. ErrorCodeEnum Initial();
  196. void OnOutputPositiveLevelTimerout(void *pData);
  197. void OnPositiveFlickerSetTimerout(void *pData);
  198. void OnPositiveFlickerResetTimerout(void *pData);
  199. void OnPositiveLevelTimerOut(void* pData);
  200. void GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi);
  201. void GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri);
  202. void GetStatus(int deviceSeq,SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx);
  203. void Set(GpioService_Set_Info info);
  204. void SetEx(GpioService_Set_Info info);
  205. void WritePin(DWORD dwPinSeq,bool bHighLevel);
  206. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  207. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  208. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
  209. void ToLogRootINIInfo();
  210. void ToLogWarnInfoAboutTerm(const AdapterInfo& m_adapterInfo);
  211. bool DetectBit(ULONG data, int pos);
  212. public:
  213. CUUID m_uuidHealth, m_uuidPtr, m_uuidCR, m_uuidIDC, m_uuidFP, m_uuidKB, m_uuidCA, m_uuidCC, m_uuidDD, m_uuidCS, m_uuidIE;
  214. CUUID m_uuidHSPscanner;
  215. private:
  216. DevAdptLibHelper<GpioClass> m_hDevHelper;
  217. SP::Module::Comm::What m_eMachineType;
  218. BYTE m_btOutputStatus[MAX_PORT_NUM];
  219. DWORD m_dwPortNum,m_dwInOutDir;
  220. BOOL m_bNewVersion;
  221. BOOL m_bFuncVer2;
  222. DevOutputInfo currDevStatus;
  223. DevCategoryInfo m_devCatInfo;
  224. ULONG m_devEnableStatus;
  225. ULONG m_timerID;
  226. bool m_bPickUpRound,m_bVibrationRound,m_bOpenRound,m_bMoveRound,m_bCardGateRound;
  227. bool m_bVibrationFlag,m_bOpenFlag,m_bMoveFlag,m_bCardGateFlag;
  228. PinActiveStatus m_ePickUpFlag;
  229. bool m_bHeadLightFlag;
  230. int m_headlightDevPort, m_moveHoldTimes, m_moveDisappearTimes;
  231. ILogListener *m_pLogListener;
  232. CSimpleStringA m_csMachineType, m_csAlarmMsg;
  233. DevEntityErrorCode m_entCode;
  234. bool IfHaveMoveDetect();
  235. ErrorPackage m_errPkg;
  236. AdapterInfo m_adapterInfo;
  237. CSimpleStringA m_csDevNo;
  238. CSimpleStringA m_port;
  239. CSimpleStringA m_portNum;
  240. CSimpleStringA m_Baudrate;
  241. bool m_FirstStart;
  242. bool m_bOpened;
  243. bool m_bOpening;
  244. };
  245. template<class T>
  246. class TimerOutHelper : public ITimerListener
  247. {
  248. public:
  249. typedef void (T::*FuncTimer)(void *pUserdata);
  250. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  251. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  252. virtual void OnTimeout(DWORD dwTimerID)
  253. {
  254. (m_pObject->*m_pTimer)(m_pUserData);
  255. if (m_bDeleteSelf)
  256. delete this;
  257. }
  258. private:
  259. void *m_pUserData;
  260. T *m_pObject;
  261. FuncTimer m_pTimer;
  262. bool m_bDeleteSelf;
  263. };
  264. #endif //__MOD_GPIO_H