mod_gpio.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 "DevFSMCommBase.hpp"
  10. #include "CommEntityUtil.hpp"
  11. using namespace Gpio;
  12. const int GPIO_INIT_COUNT = 3;
  13. typedef ErrorCodeEnum (*lpCreateDevCom)(DeviceBaseClass *&baseObj);
  14. typedef ErrorCodeEnum (*lpReleaseDevCom)(DeviceBaseClass *&pBaseObj);
  15. enum OutputMode{
  16. OM_POSITIVE_LEVEL,
  17. OM_NEGATIVE_LEVEL,
  18. OM_POSITIVE_FLICKER,
  19. OM_NEGATIVE_FLICKER
  20. };
  21. enum StopMode{
  22. SM_CALLTRIGGER,
  23. SM_TIMEOUT,
  24. SM_CYCLE
  25. };
  26. enum InputMode{
  27. IM_POSITIVE_PULSE_UP,
  28. IM_NEGATIVE_PULSE_DOWN,
  29. IM_POSITIVE_PULSE_BOTH,
  30. IM_NEGATIVE_PULSE_BOTH,
  31. IM_POSITIVE_LEVEL,
  32. IM_NEGATIVE_LEVEL
  33. };
  34. enum PinPort{
  35. VIBRATIONSENSOR,
  36. OPENSENSOR,
  37. PICKUPSENSOR,
  38. MOVESENSOR,
  39. CARDGATESENSOR,
  40. };
  41. struct OutDrivingInfo
  42. {
  43. ULONG Port;
  44. int OutputMode;
  45. int StopMode;
  46. int SetTime;
  47. int ResetTime;
  48. int TimeOut;
  49. };
  50. struct ReceivingInfo
  51. {
  52. ULONG Port;
  53. int InputMode;
  54. int ContinuousTriggerTime;
  55. };
  56. enum PrintSealType{
  57. PRINTERSEAL_UNKNOWN = 0,
  58. PRINTER_LIGHT_GREEN,
  59. PRINTER_LIGHT_RED,
  60. PRINTER_LIGHT_OFF,
  61. PAPER_LIGHT_GREEN,
  62. PAPER_LIGHT_RED,
  63. PAPER_LIGHT_OFF
  64. };
  65. enum DevicePinSeq
  66. {
  67. PIN_CARD_READER_LIGHT,
  68. PIN_USB_CONTROL_SWITCH,
  69. PIN_IDCERTIFICATE_LIGHT,
  70. PIN_PINPAD_LIGHT,
  71. PIN_HEAD_LIGHT,
  72. PIN_TROUBLE_LIGHT,
  73. PIN_CARD_ISSUE_MAINTAIN_LIGHT,
  74. PIN_USB_CONTROL_LIGHT,
  75. PIN_CONTACELESS_LIGHT,
  76. PIN_QR_LIGHT,
  77. PIN_FINGERPRINT_LIGHT,
  78. PIN_THERMPRINT_LIGHT,
  79. PIN_HSPSCANNER_PREVIEW_LIGHT,
  80. PIN_PRINTERSEAL_GREEN_LIGHT,
  81. PIN_PAPER_SLOT_GREEN_LIGHT,
  82. PIN_PAPER_SHORTAGE_RED_LIGHT,
  83. PIN_PRINTERSEAL_RED_LIGHT = 24,
  84. PIN_HSPSCANNER_LIGHT
  85. };
  86. class CGpioEntity;
  87. class CGpioServiceSession : public GpioService_ServerSessionBase
  88. {
  89. public:
  90. CGpioServiceSession(CGpioEntity* pEntity):m_pEntity(pEntity){};
  91. virtual void Handle_Set(SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx);
  92. virtual void Handle_GetStatus(SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx);
  93. virtual void Handle_QueryCurrSet(SpReqAnsContext<GpioService_QueryCurrSet_Req, GpioService_QueryCurrSet_Ans>::Pointer ctx);
  94. private:
  95. CGpioEntity* m_pEntity;
  96. };
  97. struct DevOutputInfo
  98. {
  99. ULONG dir;
  100. ULONG output;
  101. };
  102. struct SetContextInfo
  103. {
  104. SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx;
  105. ULONG timerID;
  106. BYTE index;
  107. ULONG pinSeq;
  108. int setTime;
  109. int resetTime;
  110. int timeout;
  111. };
  112. struct GetContextInfo
  113. {
  114. int Port;
  115. SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx;
  116. ULONG timerID;
  117. ULONG index;
  118. int CttPhone,CttMove,CttShake,CttSwitch,CttCard;
  119. int InitCTT;//ContinuousTriggerTime get from configure file
  120. };
  121. class CGpioEntity : public CDevAdptEntityBase, public ILogListener
  122. {
  123. public:
  124. //0000 0000 0000 0010 0110 1111 1100 0000
  125. CGpioEntity():m_devEnableStatus(0x1f),m_bPickUpRound(false),m_bVibrationRound(false)
  126. ,m_bOpenRound(false),m_bMoveRound(false),m_bCardGateRound(false),m_bPickUpFlag(false)
  127. ,m_bVibrationFlag(false),m_bOpenFlag(false),m_bMoveFlag(false),m_bCardGateFlag(false)
  128. , m_pLogListener(NULL), m_bHeadLightFlag(false), m_headlightDevPort(0), m_moveHoldTimes(0)
  129. , m_moveDisappearTimes(0),m_eMachineType(SP::Module::Comm::RVC_UNKNOWN)
  130. , m_bNewVersion(FALSE)
  131. {
  132. m_timerID = 1;
  133. currDevStatus.dir = 0x3eFC0;
  134. // 11 1110 1111 1100 0000
  135. //currDevStatus.dir = 0x7ffb0;
  136. memset(m_btOutputStatus,0,MAX_PORT_NUM);
  137. currDevStatus.output = 0x0;
  138. // currDir = 0x2007ffff;
  139. //m_pPIUT = new PositivePulseUpTimer();
  140. }
  141. #ifdef RVC_OS_LINUX
  142. unsigned long GetTickCount()
  143. {
  144. struct timespec ts;
  145. clock_gettime(CLOCK_MONOTONIC, &ts);
  146. return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
  147. }
  148. #endif
  149. virtual ~CGpioEntity()
  150. {
  151. LOG_FUNCTION();
  152. }
  153. virtual const char* GetEntityName()const {return "Gpio";}
  154. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  155. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  156. {
  157. LOG_FUNCTION();
  158. InitializeVendorLogSwitch();
  159. ErrorCodeEnum err = Initial();
  160. if (err == Error_Succeed)
  161. {
  162. LOG_TRACE("Gpio open succeeded.");
  163. GetStatus(PHONEPICKUP,NULL);
  164. Dbg("subscribelog...");
  165. GetFunction()->SubscribeLog(m_uuidHealth,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"HealthManager");
  166. GetFunction()->SubscribeLog(m_uuidPtr,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"Printer");
  167. GetFunction()->SubscribeLog(m_uuidIDC,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"IDCertificate");
  168. GetFunction()->SubscribeLog(m_uuidFP, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "FingerPrint");
  169. GetFunction()->SubscribeLog(m_uuidKB,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"PinPad");
  170. GetFunction()->SubscribeLog(m_uuidCR,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"CardIssuer");
  171. GetFunction()->SubscribeLog(m_uuidCA,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"CustomerAware");
  172. GetFunction()->SubscribeLog(m_uuidCC,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"ContactlessCard");
  173. GetFunction()->SubscribeLog(m_uuidDD,this,Log_Event,Severity_Middle,Error_IgnoreAll,-1,"DeviceControl");
  174. GetFunction()->SubscribeLog(m_uuidCS, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "CardSwiper");
  175. GetFunction()->SubscribeLog(m_uuidIE, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "IEBrowser");
  176. GetFunction()->SubscribeLog(m_uuidHSPscanner, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "HSPScanner");
  177. GetFunction()->SubscribeLog(m_uuidPrinter, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "ThermalPrint");
  178. GetFunction()->SubscribeLog(m_uuidPrintSeal, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "PrintSeal");
  179. Dbg("subscribelog ok...");
  180. pTransactionContext->SendAnswer(Error_Succeed);
  181. }
  182. else
  183. {
  184. Dbg("gpio open failed(%s).",SpStrError(err));
  185. pTransactionContext->SendAnswer(Error_Unexpect);
  186. }
  187. }
  188. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  189. {
  190. LogEvent(Severity_Middle, LOG_EVT_PICKUP, "pick up");
  191. Dbg("logevent pick up");
  192. CSimpleStringA initDriver = "";
  193. int driverPort;
  194. ErrorCodeEnum Error;
  195. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  196. CSmartPointer<IConfigInfo> spConfig;
  197. Error = spEntityFunction->OpenConfig(Config_Software, spConfig);
  198. spConfig->ReadConfigValue("InitDriver","CardReader",initDriver);
  199. spConfig->ReadConfigValueInt("DriverPort","CardReader",driverPort);
  200. OutDrivingInfo odi;
  201. GetOutDrivingModInfo(initDriver,odi);
  202. bool bSetFlag = true;
  203. Dbg("read port[%u]",(ULONG)driverPort);
  204. pTransactionContext->SendAnswer(Error_Succeed);
  205. }
  206. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  207. {
  208. LOG_FUNCTION();
  209. m_hDevHelper.TearDown();
  210. pTransactionContext->SendAnswer(Error_Succeed);
  211. }
  212. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * pszClass)
  213. {
  214. return new CGpioServiceSession(this);
  215. }
  216. bool SetOutDriving(GpioService_Set_Info req,OutDrivingInfo od, ULONG iIndex,ULONG devSeq);
  217. bool GetReceiving(int deviceSeq,ReceivingInfo ri, ULONG iIndex, SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx);
  218. DevOutputInfo GetCurrDevStatus()const {return currDevStatus;}
  219. void SaveCurrDevStatus(DevOutputInfo devOutputInfo) {currDevStatus = devOutputInfo;}
  220. ULONG GetDevEnableStatus(){return m_devEnableStatus;}
  221. void SetDevEnableStatus(ULONG devEnableStatus){m_devEnableStatus = devEnableStatus;}
  222. ULONG GetNewTimerID(){return m_timerID++;}
  223. BYTE GetOutputStatus(int sn=0);
  224. virtual bool IsService()const{return true;}
  225. virtual bool IsMultiThread()const{return false;}
  226. ErrorCodeEnum Initial();
  227. void OnOutputPositiveLevelTimerout(void *pData);
  228. void OnPositiveFlickerSetTimerout(void *pData);
  229. void OnPositiveFlickerResetTimerout(void *pData);
  230. void OnPositivePulseUpTimerout(void* pData);
  231. void OnNegativePulseUpTimerout(void* pData);
  232. void OnPositiveLevelTimerOut(void* pData);
  233. void OnNegativeLevelTimerOut(void* pData);
  234. void GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi);
  235. void GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri);
  236. void GetStatus(int deviceSeq,SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx);
  237. void Set(GpioService_Set_Info info);
  238. void WritePin(DWORD dwPinSeq,bool bHighLevel);
  239. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  240. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  241. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage);
  242. private:
  243. HMODULE m_hVerdorDll;
  244. lpCreateDevCom CreateDevComponent;
  245. lpReleaseDevCom ReleaseDevComponent;
  246. DevAdptLibHelper<GpioClass> m_hDevHelper;
  247. SP::Module::Comm::What m_eMachineType;
  248. BYTE m_btOutputStatus[MAX_PORT_NUM];
  249. DWORD m_dwPortNum,m_dwInOutDir;
  250. BOOL m_bNewVersion;
  251. CUUID m_uuidHealth,m_uuidPtr,m_uuidCR,m_uuidIDC,m_uuidFP,m_uuidKB,m_uuidCA,m_uuidCC,m_uuidDD,m_uuidCS,m_uuidIE,m_uuidPrinter;
  252. CUUID m_uuidHSPscanner;
  253. CUUID m_uuidPrintSeal;
  254. DevOutputInfo currDevStatus;
  255. ULONG m_devEnableStatus;
  256. ULONG m_timerID;
  257. bool m_bPickUpRound,m_bVibrationRound,m_bOpenRound,m_bMoveRound,m_bCardGateRound;
  258. bool m_bPickUpFlag,m_bVibrationFlag,m_bOpenFlag,m_bMoveFlag,m_bCardGateFlag;
  259. bool m_bHeadLightFlag;
  260. int m_headlightDevPort, m_moveHoldTimes, m_moveDisappearTimes;
  261. ILogListener *m_pLogListener;
  262. CSimpleStringA m_csMachineType;
  263. };
  264. template<class T>
  265. class TimerOutHelper : public ITimerListener
  266. {
  267. public:
  268. typedef void (T::*FuncTimer)(void *pUserdata);
  269. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  270. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  271. virtual void OnTimeout(DWORD dwTimerID)
  272. {
  273. (m_pObject->*m_pTimer)(m_pUserData);
  274. if (m_bDeleteSelf)
  275. delete this;
  276. }
  277. private:
  278. void *m_pUserData;
  279. T *m_pObject;
  280. FuncTimer m_pTimer;
  281. bool m_bDeleteSelf;
  282. };
  283. #endif //__MOD_GPIO_H