mod_gpio.cpp 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. #include "stdafx.h"
  2. #include "mod_gpio.h"
  3. const int MAX_GPIO_INIT_TRIES = 3;
  4. const int INPUT_PORT_2 = 2;
  5. const int MAX_MOVE_HOLD_TIMES = 5000;
  6. const int LOG_TIME_VALUE = 25;
  7. int positive_pulse_up_count = 0;
  8. int negative_pulse_down_count = 0;
  9. int positive_pulse_both_count = 0;
  10. int negative_pulse_both_count = 0;
  11. int positive_level_count = 0;
  12. int negative_level_count = 0;
  13. #define SETBIT(x,y) x|=(1<<(y))
  14. #define CLEARBIT(x,y) x&=((1<<(y))^0xffffff)
  15. using namespace SP::Module::Comm;
  16. bool DetectBit(ULONG data, int pos)
  17. {
  18. ULONG tmp = 0;
  19. SETBIT(tmp, pos);
  20. return data & tmp;
  21. }
  22. static const char* GetDriverPortString(int pin)
  23. {
  24. switch (pin) {
  25. case 1: return "【驱动】读卡发卡器提示灯";
  26. case 2: return "【驱动】前端USB通断控制";
  27. case 3: return "【驱动】身份证阅读器提示灯";
  28. case 4: return "【驱动】密码键盘提示灯";
  29. case 5: return "【驱动】脸部照明灯";
  30. case 6: return "【驱动】故障灯";
  31. case 7: return "【驱动】读卡发卡器维护提示灯";
  32. case 8: return "【驱动】前端USB口提示灯";
  33. case 9: return "【驱动】非接IC读卡器提示灯";
  34. case 10: return "";
  35. case 11: return "【驱动】指纹仪提示灯";
  36. case 12: return "【驱动】凭条打印提示灯";
  37. case 13: return "【驱动】高拍仪提示灯";
  38. case 14: return "";
  39. case 15: return "";
  40. case 16: return "";
  41. case 17: return "【接收】震动探测器";
  42. case 18: return "【接收】开机感应开关";
  43. case 19: return "【接收】话机提机感应开关";
  44. case 20: return "【接收】人体探测感应器";
  45. case 21: return "【接收】发卡器卡嘴覆盖探测器";
  46. //case 22: return "";
  47. //case 23: return "";
  48. //case 24: return "";
  49. //case 25: return "";
  50. case 26: return "【驱动】高拍仪提示灯";
  51. //case 27: return "";
  52. //case 28: return "";
  53. //case 29: return "";
  54. //case 30: return "";
  55. //case 31: return "";
  56. //case 32: return "";
  57. //case 33: return "";
  58. //case 34: return "";
  59. //case 35: return "";
  60. //case 36: return "";
  61. //case 37: return "";
  62. //case 38: return "";
  63. //case 39: return "";
  64. //case 40: return "";
  65. //case 41: return "";
  66. //case 42: return "";
  67. default:
  68. Dbg("Unkown pin sequence: %d", pin);
  69. return "";
  70. break;
  71. }
  72. }
  73. #define LIGHT_STRING_CONVERT(str) case str : return #str; break;
  74. static const char* GetLightSeqString(int seq)
  75. {
  76. switch (seq) {
  77. LIGHT_STRING_CONVERT(UNKNOWN_DEVICE)
  78. LIGHT_STRING_CONVERT(CARDREADER)
  79. LIGHT_STRING_CONVERT(CARDREADER_RED)
  80. LIGHT_STRING_CONVERT(PRINTER)
  81. LIGHT_STRING_CONVERT(IDCERTIFICATE)
  82. LIGHT_STRING_CONVERT(PINPAD)
  83. LIGHT_STRING_CONVERT(PINPADLIGHT)
  84. LIGHT_STRING_CONVERT(SHAKEDETECT)
  85. LIGHT_STRING_CONVERT(SWITCHINDUCTOR)
  86. LIGHT_STRING_CONVERT(PHONEPICKUP)
  87. LIGHT_STRING_CONVERT(MOVEDETECT)
  88. LIGHT_STRING_CONVERT(CARDGATEDETECT)
  89. LIGHT_STRING_CONVERT(HEADLIGHT)
  90. LIGHT_STRING_CONVERT(HEADLIGHT_RED)
  91. LIGHT_STRING_CONVERT(CONTACTLESSCARD)
  92. LIGHT_STRING_CONVERT(USBCONTROL)
  93. LIGHT_STRING_CONVERT(USBLIGHT)
  94. LIGHT_STRING_CONVERT(HEADLIGHT_ASSIST)
  95. LIGHT_STRING_CONVERT(HSPSCANNER)
  96. LIGHT_STRING_CONVERT(PRINTER_SEAL)
  97. LIGHT_STRING_CONVERT(FINGERPRINT)
  98. default:
  99. Dbg("Unkonwn LightSeq: %d", seq);
  100. return "UnConver One";
  101. break;
  102. }
  103. }
  104. #undef LIGHT_STRING_CONVERT
  105. void CGpioServiceSession::Handle_Set(SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx)
  106. {
  107. GpioService_Set_Info req = ctx->Info;
  108. Dbg("devseq=%d", req.devseq);
  109. Dbg("mode=%d", req.mode);
  110. Dbg("close=%d", req.close);
  111. m_pEntity->Set(req);
  112. }
  113. void CGpioServiceSession::Handle_GetStatus(SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx)
  114. {
  115. m_pEntity->GetStatus(ctx->Req.devseq, ctx);
  116. }
  117. void CGpioServiceSession::Handle_QueryCurrSet(SpReqAnsContext<GpioService_QueryCurrSet_Req, GpioService_QueryCurrSet_Ans>::Pointer ctx)
  118. {
  119. DevOutputInfo output;
  120. output = m_pEntity->GetCurrDevStatus();
  121. ctx->Ans.dir = output.dir;
  122. ctx->Ans.output = m_pEntity->GetOutputStatus(0);
  123. ctx->Answer(Error_Succeed);
  124. }
  125. bool isnostr(const char* str)
  126. {
  127. int len = strlen(str);
  128. if (len == 0)
  129. return true;
  130. for (int i = 0; i < len; ++i) {
  131. if (*(str + i) != ' ')
  132. return false;
  133. }
  134. return true;
  135. }
  136. ErrorCodeEnum CGpioEntity::Initial()
  137. {
  138. ErrorCodeEnum err;
  139. LOG_FUNCTION();
  140. ErrorCodeEnum eErrDev;
  141. CSimpleStringA dllName;
  142. eErrDev = ExtractVendorLibFullPath(dllName);
  143. if (eErrDev != Error_Succeed) {
  144. Dbg("load vendor dll or so(%s)(%s) failed.", dllName.GetData(), SpStrError(eErrDev));
  145. return Error_DevLoadFileFailed;
  146. }
  147. Dbg("library name: %s", dllName.GetData());
  148. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  149. CSmartPointer<IConfigInfo> spConfig;
  150. eErrDev = spEntityFunction->OpenConfig(Config_Root, spConfig);
  151. if (eErrDev != Error_Succeed) {
  152. Dbg("open cfg file failed!");
  153. return eErrDev;
  154. }
  155. CSimpleStringA devVendor, devVer, devBatch, dllSuffix;
  156. devVendor = devVer = devBatch = "";
  157. spConfig->ReadConfigValue("Device.Gpio", "Vendor", devVendor);
  158. spConfig->ReadConfigValue("Device.Gpio", "Version", devVer);
  159. spConfig->ReadConfigValue("Device.Gpio", "Batch", devBatch);
  160. #if defined(RVC_OS_WIN)
  161. Dbg("[%s],[%s],[%s]", devVendor.GetData(), devVer.GetData(), devBatch.GetData());
  162. if (!_stricmp(devVendor, "Hyosung") || !_stricmp(devVendor, "Keba") || !_stricmp(devVendor, "Kxd")) {
  163. if (devVer == "1" && devBatch == "1") {
  164. m_bNewVersion = FALSE;
  165. } else {
  166. m_bNewVersion = TRUE;
  167. }
  168. } else {
  169. m_bNewVersion = TRUE;
  170. }
  171. #else
  172. m_bNewVersion = TRUE;
  173. #endif
  174. eErrDev = m_hDevHelper.LoadUp(dllName);
  175. if (eErrDev != Error_Succeed) {
  176. Dbg("load up %s failed: %s", dllName.GetData(), SpStrError(eErrDev));
  177. return Error_DevLoadFileFailed;
  178. }
  179. int initTries = 0;
  180. do {
  181. Dbg("to open device.");
  182. int portNum, inOutDir, port, baudRate;
  183. err = spConfig->ReadConfigValueInt("Device.Gpio", "PortNum", portNum);
  184. if (err == Error_Succeed)
  185. m_dwPortNum = portNum;
  186. else
  187. return Error_IO;
  188. err = spConfig->ReadConfigValueInt("Device.Gpio", "InOutDir", inOutDir);
  189. if (err == Error_Succeed)
  190. m_dwInOutDir = inOutDir;
  191. else
  192. return Error_IO;
  193. spConfig->ReadConfigValueInt("Device.Gpio", "Port", port);
  194. spConfig->ReadConfigValueInt("Device.Gpio", "BaudRate", baudRate);
  195. Dbg("read cfg suc, port(%d), baudrate(%d).", port, baudRate);
  196. GpioInitParam initParam;
  197. if (!m_bNewVersion) {
  198. initParam.dwPortNum = 3;
  199. initParam.dir[0] = true;
  200. initParam.dir[1] = true;
  201. initParam.dir[2] = false;
  202. } else {
  203. initParam.dwPortNum = 4;
  204. initParam.dir[0] = true;
  205. initParam.dir[1] = true;
  206. initParam.dir[2] = false;
  207. initParam.dir[3] = true;
  208. Dbg("New available 4 port num");
  209. }
  210. initParam.dwPort = port;
  211. initParam.dwBaudRate = baudRate;
  212. err = m_hDevHelper->DevOpen(initParam);
  213. if (err == Error_Succeed) {
  214. initTries = 0;
  215. break;
  216. } else {
  217. Dbg("devopen failed(%d).", err);
  218. DevErrorInfo devErrInfo;
  219. m_hDevHelper->GetLastErr(devErrInfo);
  220. Dbg("err:[%s]", devErrInfo.szErrMsg);
  221. initTries++;
  222. continue;
  223. }
  224. } while (initTries < MAX_GPIO_INIT_TRIES);
  225. if (initTries != 0) {
  226. LOG_TRACE("open gpio failed.");
  227. err = Error_DevConnFailed;
  228. }
  229. err = m_hDevHelper->WritePort(0, 0x00);
  230. Dbg("write ports(%d)", err);
  231. err = m_hDevHelper->WritePort(1, 0x00);
  232. Dbg("write ports(%d)", err);
  233. if (m_bNewVersion) {
  234. err = m_hDevHelper->WritePort(3, 0x00);
  235. Dbg("write ports(%d)", err);
  236. }
  237. //oilyang@20170214
  238. eErrDev = Error_Unexpect;
  239. CSmartPointer<IConfigInfo> spConfigRun;
  240. eErrDev = spEntityFunction->OpenConfig(Config_Run, spConfigRun);
  241. if (eErrDev == Error_Succeed) {
  242. int iMoveHoldTimes = 0;
  243. spConfigRun->ReadConfigValueInt("Init", "MaxMoveHoldTimes", iMoveHoldTimes);
  244. if (iMoveHoldTimes == 0) {
  245. spConfigRun->WriteConfigValueInt("Init", "MaxMoveHoldTimes", MAX_MOVE_HOLD_TIMES);
  246. m_moveHoldTimes = MAX_MOVE_HOLD_TIMES;
  247. }
  248. } else {
  249. m_moveHoldTimes = MAX_MOVE_HOLD_TIMES;//oiltmp about 5000*300ms = 25 minutes
  250. }
  251. m_moveDisappearTimes = m_moveHoldTimes;
  252. m_eMachineType = SP::Module::Comm::GetTerminalMachineInfo(this).type;
  253. Dbg("machine type: %s", SP::Module::Comm::Type2Str(m_eMachineType));
  254. return err;
  255. }
  256. void CGpioEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  257. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  258. const CAutoArray<DWORD>& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage)
  259. {
  260. Dbg("usercode [%x]", dwUserCode);
  261. GpioService_Set_Info Req;
  262. Req.close = 0;
  263. switch (dwUserCode) {
  264. case LOG_EVT_CARDREADER_GREEN_ON:
  265. case LOG_EVT_CARDISSUER_GREEN_ON:
  266. Req.devseq = CARDREADER;
  267. Req.mode = 1;
  268. break;
  269. case LOG_EVT_CARDREADER_RED_ON:
  270. case LOG_EVT_CARDISSUER_RED_ON:
  271. Req.devseq = CARDREADER_RED;
  272. Req.mode = 1;
  273. break;
  274. case LOG_EVT_THERMAL_PRINTER_GREEN_ON:
  275. Req.devseq = PRINTER;
  276. Req.mode = 1;
  277. break;
  278. case LOG_EVT_IDCERTIFICATE_GREEN_ON:
  279. Req.devseq = IDCERTIFICATE;
  280. Req.mode = 1;
  281. break;
  282. case LOG_EVT_FINGERPRINT_GREEN_ON:
  283. Req.devseq = FINGERPRINT;
  284. Req.mode = 1;
  285. break;
  286. case LOG_EVT_PINPAD_GREEN_ON:
  287. Req.devseq = PINPAD;
  288. Req.mode = 1;
  289. break;
  290. case LOG_EVT_HEADLIGHT_GREEN_ON:
  291. m_bHeadLightFlag = true;
  292. Req.devseq = HEADLIGHT;
  293. Req.mode = 1;
  294. LOG_TRACE("machine light on");
  295. break;
  296. case LOG_EVT_HEADLIGHT_RED_ON:
  297. Req.devseq = HEADLIGHT_RED;
  298. Req.mode = 1;
  299. break;
  300. case LOG_EVT_CONTACTLESS_CARD_GREEN_ON:
  301. Req.devseq = CONTACTLESSCARD;
  302. Req.mode = 1;
  303. break;
  304. case LOG_EVT_USB_CONTROL_ON:
  305. Req.devseq = USBCONTROL;
  306. Req.mode = 1;
  307. break;
  308. case LOG_EVT_USB_LIGHT_ON:
  309. Req.devseq = USBLIGHT;
  310. Req.mode = 1;
  311. break;
  312. case LOG_EVT_IEBROWSER_LIGHT_ASSISTANT_ON:
  313. Req.devseq = HEADLIGHT_ASSIST;
  314. Req.mode = 1;
  315. break;
  316. case LOG_EVT_CARDREADER_GREEN_OFF:
  317. case LOG_EVT_CARDISSUER_GREEN_OFF:
  318. Req.devseq = CARDREADER;
  319. Req.mode = 1;
  320. Req.close = 1;
  321. break;
  322. case LOG_EVT_CARDREADER_RED_OFF:
  323. case LOG_EVT_CARDISSUER_RED_OFF:
  324. Req.devseq = CARDREADER_RED;
  325. Req.mode = 1;
  326. Req.close = 1;
  327. break;
  328. case LOG_EVT_THERMAL_PRINTER_GREEN_OFF:
  329. Req.devseq = PRINTER;
  330. Req.mode = 1;
  331. Req.close = 1;
  332. break;
  333. case LOG_EVT_IDCERTIFICATE_GREEN_OFF:
  334. Req.devseq = IDCERTIFICATE;
  335. Req.mode = 1;
  336. Req.close = 1;
  337. break;
  338. case LOG_EVT_FINGERPRINT_GREEN_OFF:
  339. Req.devseq = FINGERPRINT;
  340. Req.mode = 1;
  341. Req.close = 1;
  342. break;
  343. case LOG_EVT_PINPAD_GREEN_OFF:
  344. Req.devseq = PINPAD;
  345. Req.mode = 1;
  346. Req.close = 1;
  347. break;
  348. case LOG_EVT_HEADLIGHT_GREEN_OFF:
  349. m_bHeadLightFlag = false;
  350. Req.devseq = HEADLIGHT;
  351. Req.mode = 1;
  352. Req.close = 1;
  353. LOG_TRACE("machine light off");
  354. break;
  355. case LOG_EVT_HEADLIGHT_RED_OFF:
  356. Req.devseq = HEADLIGHT_RED;
  357. Req.mode = 1;
  358. Req.close = 1;
  359. break;
  360. case LOG_EVT_CONTACTLESS_CARD_GREEN_OFF:
  361. Req.devseq = CONTACTLESSCARD;
  362. Req.mode = 1;
  363. Req.close = 1;
  364. break;
  365. case LOG_EVT_USB_CONTROL_OFF:
  366. Req.devseq = USBCONTROL;
  367. Req.mode = 1;
  368. Req.close = 1;
  369. break;
  370. case LOG_EVT_USB_LIGHT_OFF:
  371. Req.devseq = USBLIGHT;
  372. Req.mode = 1;
  373. Req.close = 1;
  374. break;
  375. case LOG_EVT_IEBROWSER_LIGHT_ASSISTANT_OFF:
  376. Req.devseq = HEADLIGHT_ASSIST;
  377. Req.mode = 1;
  378. Req.close = 1;
  379. break;
  380. case LOG_EVT_HSPS_LIGHT_ON:
  381. Req.devseq = HSPSCANNER;
  382. Req.mode = 1;
  383. LOG_TRACE("hspscanner light on");
  384. break;
  385. case LOG_EVT_HSPS_LIGHT_OFF:
  386. Req.devseq = HSPSCANNER;
  387. Req.mode = 1;
  388. Req.close = 1;
  389. LOG_TRACE("hspscanner light off");
  390. break;
  391. case LOG_EVT_PRINTSEAL_LIGHT_GREEN_ON:
  392. Req.devseq = PRINTER_SEAL;
  393. Req.mode = PRINTER_LIGHT_GREEN;
  394. break;
  395. case LOG_EVT_PRINTSEAL_LIGHT_RED_ON:
  396. Req.devseq = PRINTER_SEAL;
  397. Req.mode = PRINTER_LIGHT_RED;
  398. break;
  399. case LOG_EVT_PRINTSEAL_LIGHT_OFF:
  400. Req.devseq = PRINTER_SEAL;
  401. Req.mode = PRINTER_LIGHT_OFF;
  402. Req.close = 1;
  403. break;
  404. case LOG_EVT_PRINTSEAL_PAPER_LIGHT_GREEN_ON:
  405. Req.devseq = PRINTER_SEAL;
  406. Req.mode = PAPER_LIGHT_GREEN;
  407. break;
  408. case LOG_EVT_PRINTSEAL_PAPER_LIGHT_RED_ON:
  409. Req.devseq = PRINTER_SEAL;
  410. Req.mode = PAPER_LIGHT_RED;
  411. break;
  412. case LOG_EVT_PRINTSEAL_PAPER_LIGHT_OFF:
  413. Req.devseq = PRINTER_SEAL;
  414. Req.mode = PAPER_LIGHT_OFF;
  415. Req.close = 1;
  416. break;
  417. default:
  418. Dbg("unkown event(%d)...", dwUserCode);
  419. return;
  420. }
  421. Dbg("devseq[%d],mode[%d]close[%d]", Req.devseq, Req.mode, Req.close);
  422. Set(Req);
  423. }
  424. void CGpioEntity::WritePin(DWORD dwPinSeq, bool bHighLevel)
  425. {
  426. ErrorCodeEnum result(Error_Succeed);
  427. LOG_TRACE("Write Pin %s with %s !", GetDriverPortString(dwPinSeq + 1), bHighLevel ? "[Active]" : "[Inactive]");
  428. if (dwPinSeq > 16) {
  429. if (!m_bNewVersion && dwPinSeq < 24) {
  430. return;
  431. }
  432. if (bHighLevel)
  433. SETBIT(m_btOutputStatus[3], dwPinSeq - 24);
  434. else
  435. CLEARBIT(m_btOutputStatus[3], dwPinSeq - 24);
  436. result = m_hDevHelper->WritePort(3, m_btOutputStatus[3]);
  437. Dbg("after write port3, %d returned %s", m_btOutputStatus[3], SpStrError(result));
  438. return;
  439. }
  440. if (dwPinSeq < 8) {
  441. if (bHighLevel)
  442. SETBIT(m_btOutputStatus[0], dwPinSeq);
  443. else
  444. CLEARBIT(m_btOutputStatus[0], dwPinSeq);
  445. result = m_hDevHelper->WritePort(0, m_btOutputStatus[0]);
  446. Dbg("after write port0,%d returned %s", m_btOutputStatus[0], SpStrError(result));
  447. } else {
  448. if (bHighLevel)
  449. SETBIT(m_btOutputStatus[1], dwPinSeq - 8);
  450. else
  451. CLEARBIT(m_btOutputStatus[1], dwPinSeq - 8);
  452. DWORD dwStart, dwEnd;
  453. dwStart = GetTickCount();
  454. result = m_hDevHelper->WritePort(1, m_btOutputStatus[1]);
  455. dwEnd = GetTickCount();
  456. if ((dwEnd - dwStart) > 3000)
  457. Dbg("writepin so long.than 3s(%d)", (dwEnd - dwStart));
  458. else
  459. Dbg("after write port1,%d returned %s", m_btOutputStatus[1], SpStrError(result));
  460. }
  461. }
  462. void CGpioEntity::Set(GpioService_Set_Info req)
  463. {
  464. CSimpleStringA activeModeSecName = "";
  465. int devicePort;
  466. BOOL bDone = FALSE;
  467. const int deviceSeq = req.devseq;
  468. LOG_TRACE("Set request %s arrived!", GetLightSeqString(deviceSeq));
  469. OutDrivingInfo odi;
  470. ErrorCodeEnum err;
  471. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  472. CSmartPointer<IConfigInfo> spConfig;
  473. err = spEntityFunction->OpenConfig(Config_Software, spConfig);
  474. if (err != Error_Succeed) {
  475. LOG_TRACE("open cfg file failed!");
  476. return;
  477. }
  478. switch (deviceSeq) {
  479. case CARDREADER:
  480. {
  481. err = spConfig->ReadConfigValue("InitDriver", "CardReader", activeModeSecName);
  482. if (err != Error_Succeed)
  483. goto Error;
  484. err = spConfig->ReadConfigValueInt("DriverPort", "CardReader", devicePort);
  485. if (err != Error_Succeed)
  486. goto Error;
  487. break;
  488. }
  489. case CARDREADER_RED:
  490. {
  491. err = spConfig->ReadConfigValue("InitDriver", "CardReaderRed", activeModeSecName);
  492. if (err != Error_Succeed)
  493. goto Error;
  494. err = spConfig->ReadConfigValueInt("DriverPort", "CardReaderRed", devicePort);
  495. if (err != Error_Succeed)
  496. goto Error;
  497. break;
  498. }
  499. case PRINTER:
  500. {
  501. spConfig->ReadConfigValue("InitDriver", "Printer", activeModeSecName);
  502. spConfig->ReadConfigValueInt("DriverPort", "Printer", devicePort);
  503. break;
  504. }
  505. case IDCERTIFICATE:
  506. {
  507. spConfig->ReadConfigValue("InitDriver", "IDCertificate", activeModeSecName);
  508. spConfig->ReadConfigValueInt("DriverPort", "IDCertificate", devicePort);
  509. break;
  510. }
  511. case FINGERPRINT:
  512. {
  513. spConfig->ReadConfigValue("InitDriver", "FingerPrint", activeModeSecName);
  514. spConfig->ReadConfigValueInt("DriverPort", "FingerPrint", devicePort);
  515. break;
  516. }
  517. case PINPAD:
  518. {
  519. spConfig->ReadConfigValue("InitDriver", "Pinpad", activeModeSecName);
  520. spConfig->ReadConfigValueInt("DriverPort", "Pinpad", devicePort);
  521. break;
  522. }
  523. case HEADLIGHT:
  524. {
  525. spConfig->ReadConfigValue("InitDriver", "HeadLight", activeModeSecName);
  526. spConfig->ReadConfigValueInt("DriverPort", "HeadLight", devicePort);
  527. m_headlightDevPort = devicePort;
  528. break;
  529. }
  530. case HEADLIGHT_RED:
  531. {
  532. spConfig->ReadConfigValue("InitDriver", "HeadLightRed", activeModeSecName);
  533. spConfig->ReadConfigValueInt("DriverPort", "HeadLightRed", devicePort);
  534. break;
  535. }
  536. case CONTACTLESSCARD:
  537. {
  538. spConfig->ReadConfigValue("InitDriver", "ContactlessCard", activeModeSecName);
  539. spConfig->ReadConfigValueInt("DriverPort", "ContactlessCard", devicePort);
  540. break;
  541. }
  542. case USBCONTROL:
  543. {
  544. spConfig->ReadConfigValue("InitDriver", "USBControl", activeModeSecName);
  545. spConfig->ReadConfigValueInt("DriverPort", "USBControl", devicePort);
  546. break;
  547. }
  548. case USBLIGHT:
  549. {
  550. spConfig->ReadConfigValue("InitDriver", "USBLight", activeModeSecName);
  551. spConfig->ReadConfigValueInt("DriverPort", "USBLight", devicePort);
  552. break;
  553. }
  554. case HEADLIGHT_ASSIST:
  555. {
  556. spConfig->ReadConfigValue("InitDriver", "HeadLightAssist", activeModeSecName);
  557. spConfig->ReadConfigValueInt("DriverPort", "HeadLightAssist", devicePort);
  558. break;
  559. }
  560. case HSPSCANNER:
  561. {
  562. spConfig->ReadConfigValue("InitDriver", "HSPScanner", activeModeSecName);
  563. spConfig->ReadConfigValueInt("DriverPort", "HSPScanner", devicePort);
  564. break;
  565. }
  566. case PRINTER_SEAL:
  567. {
  568. if (!m_bNewVersion) {
  569. bDone = TRUE;
  570. break;
  571. }
  572. //static int paperLighted = PRINTERSEAL_UNKNOWN;
  573. //static int printLighted = PRINTERSEAL_UNKNOWN;
  574. err = Error_Unexpect;
  575. switch (req.mode) {
  576. case PRINTER_LIGHT_GREEN:
  577. LOG_TRACE("printseal green light on");
  578. err = spConfig->ReadConfigValue("InitDriver", "PrintSeal", activeModeSecName);
  579. err = spConfig->ReadConfigValueInt("DriverPort", "PrintSeal", devicePort);
  580. break;
  581. case PRINTER_LIGHT_RED:
  582. LOG_TRACE("printseal red light on");
  583. err = spConfig->ReadConfigValue("InitDriver", "PrintSealRed", activeModeSecName);
  584. err = spConfig->ReadConfigValueInt("DriverPort", "PrintSealRed", devicePort);
  585. break;
  586. case PAPER_LIGHT_GREEN:
  587. LOG_TRACE("paper slot green light on");
  588. err = spConfig->ReadConfigValue("InitDriver", "PrintPaper", activeModeSecName);
  589. err = spConfig->ReadConfigValueInt("DriverPort", "PrintPaper", devicePort);
  590. break;
  591. case PAPER_LIGHT_RED:
  592. LOG_TRACE("paper slot red light on");
  593. err = spConfig->ReadConfigValue("InitDriver", "PrintPaperRed", activeModeSecName);
  594. err = spConfig->ReadConfigValueInt("DriverPort", "PrintPaperRed", devicePort);
  595. break;
  596. case PRINTER_LIGHT_OFF:
  597. LOG_TRACE("printerseal light off");
  598. err = Error_Pending;
  599. break;
  600. case PAPER_LIGHT_OFF:
  601. LOG_TRACE("paper slot light off");
  602. err = Error_Pending;
  603. break;
  604. default:
  605. err = Error_Param;
  606. break;
  607. }
  608. if (err == Error_Pending) {
  609. CSimpleStringA initDriver1 = "", initDriver2 = "";
  610. int devicePort1, devicePort2;
  611. if (req.mode == PRINTER_LIGHT_OFF) {
  612. err = spConfig->ReadConfigValueInt("DriverPort", "PrintSeal", devicePort1);
  613. err = spConfig->ReadConfigValueInt("DriverPort", "PrintSealRed", devicePort2);
  614. } else {
  615. err = spConfig->ReadConfigValueInt("DriverPort", "PrintPaper", devicePort1);
  616. err = spConfig->ReadConfigValueInt("DriverPort", "PrintPaperRed", devicePort2);
  617. }
  618. if (err != Error_Succeed) {
  619. Dbg("read cfg failed ~.");
  620. return;
  621. }
  622. memset(&odi, 0, sizeof(odi));
  623. SetOutDriving(req, odi, 0, devicePort1);
  624. SetOutDriving(req, odi, 0, devicePort2);
  625. bDone = TRUE;
  626. }
  627. break;
  628. }
  629. break;
  630. default:
  631. return;
  632. }
  633. Error:
  634. if (err != Error_Succeed)
  635. {
  636. Dbg("read cfg failed.");
  637. return;
  638. }
  639. if (bDone) {
  640. return;
  641. }
  642. GetOutDrivingModInfo(activeModeSecName, odi);
  643. SetOutDriving(req, odi, 0, devicePort);
  644. }
  645. void CGpioEntity::GetStatus(int deviceSeq, SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx)
  646. {
  647. Dbg("GetStatus devseq%d", deviceSeq);
  648. CSimpleStringA initDriver = "";
  649. int devicePort;
  650. ErrorCodeEnum Error;
  651. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  652. CSmartPointer<IConfigInfo> spConfig;
  653. Error = spEntityFunction->OpenConfig(Config_Software, spConfig);
  654. if (Error != Error_Succeed) {
  655. LOG_TRACE("open cfg file failed!");
  656. return;
  657. }
  658. {
  659. spConfig->ReadConfigValue("InitDriver", "PhoneLift", initDriver);
  660. spConfig->ReadConfigValueInt("DriverPort", "PhoneLift", devicePort);
  661. ReceivingInfo ri;
  662. GetReceivingModInfo(initDriver, ri);
  663. ri.Port = devicePort;
  664. GetReceiving(deviceSeq, ri, PICKUPSENSOR, ctx);
  665. }
  666. }
  667. void CGpioEntity::OnOutputPositiveLevelTimerout(void* pData)
  668. {
  669. SetContextInfo* pSCI = (SetContextInfo*)pData;
  670. GetFunction()->KillTimer(pSCI->timerID);
  671. ULONG devEnableStatus = GetDevEnableStatus();
  672. DevOutputInfo doi = GetCurrDevStatus();
  673. WritePin(pSCI->pinSeq, true);
  674. delete pSCI;
  675. SaveCurrDevStatus(doi);
  676. }
  677. void CGpioEntity::OnPositiveFlickerSetTimerout(void* pData)
  678. {
  679. SetContextInfo* pSCI = (SetContextInfo*)pData;
  680. GetFunction()->KillTimer(pSCI->timerID);
  681. ULONG devEnableStatus = GetDevEnableStatus();
  682. DevOutputInfo doi = GetCurrDevStatus();
  683. WritePin(pSCI->pinSeq, false);
  684. pSCI->timerID = pSCI->timerID;
  685. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerResetTimerout, pSCI, true);
  686. GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->resetTime);
  687. }
  688. void CGpioEntity::OnPositiveFlickerResetTimerout(void* pData)
  689. {
  690. SetContextInfo* pSCI = (SetContextInfo*)pData;
  691. GetFunction()->KillTimer(pSCI->timerID);
  692. ULONG devEnableStatus = GetDevEnableStatus();
  693. DevOutputInfo doi = GetCurrDevStatus();
  694. WritePin(pSCI->pinSeq, true);
  695. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSCI, true);
  696. GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->setTime);
  697. }
  698. bool CGpioEntity::SetOutDriving(GpioService_Set_Info req, OutDrivingInfo od, ULONG iIndex, ULONG pinSeq)
  699. {
  700. ULONG devEnableStatus = GetDevEnableStatus();
  701. DevOutputInfo doi = GetCurrDevStatus();
  702. if (req.close == 1) {
  703. GetFunction()->KillTimer(req.devseq);
  704. //oilyang add 20161222
  705. //如果关闭照明灯,以感知为准
  706. if (pinSeq == m_headlightDevPort)
  707. WritePin(pinSeq, m_bHeadLightFlag);
  708. else {
  709. if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
  710. Dbg("off hspsanner.");
  711. WritePin(PIN_HSPSCANNER_LIGHT, false);
  712. }
  713. WritePin(pinSeq, false);
  714. }
  715. return true;
  716. }
  717. switch (od.OutputMode) {
  718. case OM_POSITIVE_LEVEL:
  719. {
  720. switch (od.StopMode) {
  721. case SM_CALLTRIGGER:
  722. {
  723. LOG_TRACE("0.0 mode:output[%u], pinSeq=%u", doi.output, pinSeq);
  724. //if it is hspsanner
  725. if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
  726. Dbg("light hspsanner.");
  727. WritePin(PIN_HSPSCANNER_LIGHT, true);
  728. }
  729. WritePin(pinSeq, true);
  730. break;
  731. }
  732. case SM_TIMEOUT:
  733. {
  734. WritePin(pinSeq, true);
  735. SetContextInfo* pSci = new SetContextInfo();;
  736. pSci->ctx = NULL;
  737. pSci->timerID = req.devseq;
  738. pSci->timeout = od.TimeOut;
  739. pSci->index = iIndex;
  740. pSci->pinSeq = pinSeq;
  741. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnOutputPositiveLevelTimerout, pSci);
  742. GetFunction()->SetTimer(pSci->timerID, pListener, od.TimeOut);
  743. break;
  744. }
  745. case SM_CYCLE:
  746. break;
  747. default:
  748. break;
  749. }
  750. }
  751. break;
  752. case OM_POSITIVE_FLICKER:
  753. switch (od.StopMode) {
  754. case SM_CALLTRIGGER:
  755. break;
  756. case SM_TIMEOUT:
  757. break;
  758. case SM_CYCLE:
  759. {
  760. SetContextInfo* pSci = new SetContextInfo();
  761. pSci->ctx = NULL;
  762. pSci->index = iIndex;
  763. pSci->pinSeq = pinSeq;
  764. pSci->timerID = req.devseq;
  765. pSci->setTime = od.SetTime;
  766. pSci->resetTime = od.ResetTime;
  767. pSci->timeout = od.TimeOut;
  768. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSci, true);
  769. WritePin(pinSeq, true);
  770. GetFunction()->SetTimer(pSci->timerID, pListener, pSci->setTime);
  771. break;
  772. }
  773. default:
  774. break;
  775. }
  776. break;
  777. case OM_NEGATIVE_FLICKER:
  778. switch (od.StopMode) {
  779. case SM_CALLTRIGGER:
  780. break;
  781. case SM_TIMEOUT:
  782. break;
  783. case SM_CYCLE:
  784. break;
  785. default:
  786. break;
  787. }
  788. break;
  789. default:
  790. break;
  791. }
  792. return true;
  793. }
  794. void CGpioEntity::OnPositivePulseUpTimerout(void* pData)
  795. {
  796. GetContextInfo* pGCI = (GetContextInfo*)pData;
  797. BYTE btInput = 0;
  798. ErrorCodeEnum err;
  799. Dbg("port[%d]", INPUT_PORT_2);
  800. err = m_hDevHelper->ReadPort(INPUT_PORT_2, btInput);
  801. Dbg("read[%d]", btInput);
  802. //判断输入
  803. if (DetectBit(btInput, pGCI->index)) {
  804. if (pGCI->CttPhone == 0)//oiltest 20130709
  805. {
  806. ////触发
  807. pGCI->ctx->Ans.status = 1;
  808. pGCI->ctx->Answer(Error_Succeed);
  809. } else {
  810. pGCI->CttPhone--;//oiltest 20130709
  811. GetFunction()->ResetTimer(pGCI->timerID, 1000);
  812. }
  813. } else {
  814. pGCI->CttPhone = pGCI->InitCTT;//oiltest 20130709
  815. GetFunction()->ResetTimer(pGCI->timerID, 1);
  816. }
  817. }
  818. void CGpioEntity::OnNegativePulseUpTimerout(void* pData)
  819. {
  820. int count = 1;//from UserData
  821. ULONG input = 0;
  822. if (count == 1) {
  823. //oiltest GetInput(,&input);
  824. if (input == 0) {
  825. //返回给调用,发出触发日志
  826. } else {
  827. //不稳定,清空计数,重新来
  828. }
  829. } else {
  830. //oiltest GetInput(,&input);
  831. if (input == 0) {
  832. //计数减一,继续采样
  833. //ITimerListener *pListener = new TimerOutHelper<CGpioEntity>(this, CGpioEntity::OnPositivePulseUpTimerout, );
  834. //GetFunction()->SetTimer(,)
  835. } else {
  836. //不稳定,清空计数,重新来
  837. }
  838. }
  839. }
  840. void CGpioEntity::OnPositiveLevelTimerOut(void* pData)
  841. {
  842. GetContextInfo* pGci = (GetContextInfo*)pData;
  843. int count = pGci->InitCTT;
  844. int initCTT = pGci->InitCTT;
  845. int pos = pGci->Port;
  846. ULONG input = 0;
  847. bool bShakeOne, bMoveOne, bSwitchOne, bPhoneOne, bCardOne;
  848. bShakeOne = bMoveOne = bSwitchOne = bPhoneOne = bCardOne = false;
  849. BYTE btInput;
  850. ErrorCodeEnum err = m_hDevHelper->ReadPort(INPUT_PORT_2, btInput);
  851. if (err != Error_Succeed) {
  852. DevErrorInfo devErrInfo;
  853. ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
  854. ErrorCodeEnum erroCode = m_hDevHelper->GetLastErr(devErrInfo);
  855. Dbg("ReadPort failed: %s, ErrMsg[%s]", SpStrError(err), (LPCTSTR)devErrInfo.szErrMsg);
  856. return;
  857. }
  858. if (pGci->CttShake == 1) {
  859. do {
  860. bShakeOne = true;
  861. if (initCTT == 1) {
  862. if (DetectBit(btInput, VIBRATIONSENSOR)) {
  863. if (!m_bVibrationFlag && m_eMachineType == RVC_Stand2S) {
  864. LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, "机具震动 1");
  865. }
  866. m_bVibrationFlag = true;
  867. } else
  868. m_bVibrationFlag = false;
  869. break;
  870. }
  871. if (m_bVibrationRound) {
  872. if (DetectBit(btInput, VIBRATIONSENSOR)) {
  873. if (!m_bVibrationFlag) {
  874. if (m_eMachineType == RVC_Stand2S)
  875. LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, "机具震动 2");
  876. m_bVibrationFlag = true;
  877. m_bVibrationRound = false;
  878. }
  879. }
  880. } else {
  881. if (!DetectBit(btInput, VIBRATIONSENSOR)) {
  882. if (m_bVibrationFlag) {
  883. //LogEvent(Severity_Middle,LOG_EVT_VIBRATIONSENSOR,"震动");
  884. m_bVibrationFlag = false;
  885. m_bVibrationRound = true;
  886. }
  887. }
  888. }
  889. } while (0);
  890. pGci->CttShake = pGci->InitCTT;
  891. }
  892. if (pGci->CttSwitch == 1) {
  893. do {
  894. bSwitchOne = true;
  895. if (initCTT == 1) {
  896. if (DetectBit(btInput, OPENSENSOR)) {
  897. if (!m_bOpenFlag) {
  898. if (m_eMachineType == RVC_Stand2S)
  899. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, "机具门打开");
  900. }
  901. m_bOpenFlag = true;
  902. } else {
  903. if (m_bOpenFlag) {
  904. if (m_eMachineType == RVC_Stand2S)
  905. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, "机具门关闭");
  906. }
  907. m_bOpenFlag = false;
  908. }
  909. break;
  910. }
  911. if (m_bOpenRound) {
  912. if (DetectBit(btInput, OPENSENSOR)) {
  913. if (!m_bOpenFlag) {
  914. if (m_eMachineType == RVC_Stand2S)
  915. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, "机具门打开");
  916. m_bOpenFlag = true;
  917. m_bOpenRound = false;
  918. }
  919. }
  920. } else {
  921. if (!DetectBit(btInput, OPENSENSOR)) {
  922. if (m_bOpenFlag) {
  923. if (m_eMachineType == RVC_Stand2S)
  924. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, "机具门关闭");
  925. m_bOpenFlag = false;
  926. m_bOpenRound = true;
  927. }
  928. }
  929. }
  930. } while (0);
  931. pGci->CttSwitch = pGci->InitCTT;
  932. }
  933. if (pGci->CttPhone == 1) {
  934. do {
  935. bPhoneOne = true;
  936. if (initCTT == 1) {
  937. if (DetectBit(btInput, PICKUPSENSOR)) {
  938. if (!m_bPickUpFlag) {
  939. if (m_eMachineType == RVC_Stand2S)
  940. LogEvent(Severity_Middle, LOG_EVT_PICKUP, "话机提起");
  941. }
  942. m_bPickUpFlag = true;
  943. } else {
  944. if (m_bPickUpFlag) {
  945. if (m_eMachineType == RVC_Stand2S)
  946. LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "话机放下");
  947. }
  948. m_bPickUpFlag = false;
  949. }
  950. break;
  951. }
  952. if (m_bPickUpRound) {
  953. if (DetectBit(btInput, PICKUPSENSOR)) {
  954. if (!m_bPickUpFlag) {
  955. if (m_eMachineType == RVC_Stand2S)
  956. LogEvent(Severity_Middle, LOG_EVT_PICKUP, "话机提起");
  957. m_bPickUpFlag = true;
  958. m_bPickUpRound = false;
  959. }
  960. }
  961. } else {
  962. if (!DetectBit(btInput, PICKUPSENSOR)) {
  963. if (m_bPickUpFlag) {
  964. if (m_eMachineType == RVC_Stand2S)
  965. LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "话机放下");
  966. m_bPickUpFlag = false;
  967. m_bPickUpRound = true;
  968. }
  969. }
  970. }
  971. } while (0);
  972. pGci->CttPhone = pGci->InitCTT;
  973. }
  974. if (pGci->CttMove == 1) {
  975. do {
  976. bMoveOne = true;
  977. if (initCTT == 1) {
  978. if (DetectBit(btInput, MOVESENSOR)) {
  979. if (m_eMachineType == RVC_Stand2S)
  980. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, "移动 1");
  981. }
  982. break;
  983. }
  984. if (m_bMoveRound) {
  985. if (DetectBit(btInput, MOVESENSOR)) {
  986. m_moveHoldTimes++;
  987. m_moveDisappearTimes = 0;
  988. if (m_moveHoldTimes < MAX_MOVE_HOLD_TIMES) {
  989. if ((m_moveHoldTimes % LOG_TIME_VALUE) == 0) {
  990. if (m_eMachineType == RVC_Stand2S)
  991. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, "移动 2");
  992. }
  993. } else {
  994. if ((m_moveHoldTimes % MAX_MOVE_HOLD_TIMES) == 0) {
  995. if (m_eMachineType == RVC_Stand2S)
  996. LogWarn(Severity_Middle, Error_Unexpect, LOG_EVT_MOVEDETECT_ABNORMAL, "移动次数异常");
  997. }
  998. }
  999. m_bMoveRound = false;
  1000. }
  1001. } else {
  1002. if (!DetectBit(btInput, MOVESENSOR)) {
  1003. m_moveHoldTimes = 0;
  1004. m_moveDisappearTimes++;
  1005. if ((m_moveDisappearTimes % LOG_TIME_VALUE) == 0) {
  1006. if (m_eMachineType == RVC_Stand2S)
  1007. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_OFF, "移动消失");
  1008. }
  1009. m_bMoveRound = true;
  1010. }
  1011. }
  1012. } while (0);
  1013. pGci->CttMove = pGci->InitCTT;
  1014. }
  1015. if (pGci->CttCard == 1) {
  1016. do {
  1017. bCardOne = true;
  1018. //Dbg("oiltest %d",btInput);
  1019. if (initCTT == 1) {
  1020. if (DetectBit(btInput, CARDGATESENSOR)) {
  1021. if (!m_bCardGateFlag) {
  1022. if (m_eMachineType == RVC_Stand2S)
  1023. LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, "卡嘴 1");
  1024. }
  1025. m_bCardGateFlag = true;
  1026. } else
  1027. m_bCardGateFlag = false;
  1028. break;
  1029. }
  1030. if (m_bCardGateRound) {
  1031. if (DetectBit(btInput, CARDGATESENSOR)) {
  1032. if (!m_bCardGateFlag) {
  1033. if (m_eMachineType == RVC_Stand2S)
  1034. LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, "卡嘴 2");
  1035. m_bCardGateFlag = true;
  1036. m_bCardGateRound = false;
  1037. }
  1038. }
  1039. } else {
  1040. if (!DetectBit(btInput, CARDGATESENSOR)) {
  1041. if (m_bCardGateFlag) {
  1042. m_bCardGateFlag = false;
  1043. m_bCardGateRound = true;
  1044. }
  1045. }
  1046. }
  1047. } while (0);
  1048. pGci->CttCard = pGci->InitCTT;
  1049. }
  1050. if (pGci->CttShake > 1 && !bShakeOne) {
  1051. do {
  1052. if (m_bVibrationRound) {
  1053. if (DetectBit(btInput, VIBRATIONSENSOR))
  1054. pGci->CttShake--;
  1055. else {
  1056. m_bVibrationRound = false;
  1057. pGci->CttShake = pGci->InitCTT;
  1058. }
  1059. } else {
  1060. if (!DetectBit(btInput, VIBRATIONSENSOR))
  1061. pGci->CttShake--;
  1062. else {
  1063. m_bVibrationRound = true;
  1064. pGci->CttShake = pGci->InitCTT;
  1065. }
  1066. }
  1067. } while (0);
  1068. }
  1069. if (pGci->CttSwitch > 1 && !bSwitchOne) {
  1070. do {
  1071. if (m_bOpenRound) {
  1072. if (DetectBit(btInput, OPENSENSOR))
  1073. pGci->CttSwitch--;
  1074. else {
  1075. m_bOpenRound = false;
  1076. pGci->CttSwitch = pGci->InitCTT;
  1077. }
  1078. } else {
  1079. if (!DetectBit(btInput, OPENSENSOR))
  1080. pGci->CttSwitch--;
  1081. else {
  1082. m_bOpenRound = true;
  1083. pGci->CttSwitch = pGci->InitCTT;
  1084. }
  1085. }
  1086. } while (0);
  1087. }
  1088. if (pGci->CttPhone > 1 && !bPhoneOne) {
  1089. do {
  1090. if (m_bPickUpRound) {
  1091. if (DetectBit(btInput, PICKUPSENSOR)) {
  1092. pGci->CttPhone--;
  1093. } else {
  1094. m_bPickUpRound = false;
  1095. pGci->CttPhone = pGci->InitCTT;
  1096. }
  1097. } else {
  1098. if (!DetectBit(btInput, PICKUPSENSOR))
  1099. pGci->CttPhone--;
  1100. else {
  1101. m_bPickUpRound = true;
  1102. pGci->CttPhone = pGci->InitCTT;
  1103. }
  1104. }
  1105. } while (0);
  1106. }
  1107. if (pGci->CttMove > 1 && !bMoveOne) {
  1108. do {
  1109. if (m_bMoveRound) {
  1110. if (DetectBit(btInput, MOVESENSOR))
  1111. pGci->CttMove--;
  1112. else {
  1113. m_bMoveRound = false;
  1114. pGci->CttMove = pGci->InitCTT;
  1115. }
  1116. } else {
  1117. if (!DetectBit(btInput, MOVESENSOR))
  1118. pGci->CttMove--;
  1119. else {
  1120. m_bMoveRound = true;
  1121. pGci->CttMove = pGci->InitCTT;
  1122. }
  1123. }
  1124. } while (0);
  1125. }
  1126. if (pGci->CttCard > 1 && !bCardOne) {
  1127. do {
  1128. if (m_bCardGateRound) {
  1129. if (DetectBit(btInput, CARDGATESENSOR))
  1130. pGci->CttCard--;
  1131. else {
  1132. m_bCardGateRound = false;
  1133. pGci->CttCard = pGci->InitCTT;
  1134. }
  1135. } else {
  1136. if (!DetectBit(btInput, CARDGATESENSOR))
  1137. pGci->CttCard--;
  1138. else {
  1139. m_bCardGateRound = true;
  1140. pGci->CttCard = pGci->InitCTT;
  1141. }
  1142. }
  1143. } while (0);
  1144. }
  1145. GetFunction()->ResetTimer(pGci->timerID, 100);
  1146. }
  1147. void CGpioEntity::OnNegativeLevelTimerOut(void* pData)
  1148. {
  1149. int count = 1;//from UserData
  1150. ULONG input = 0;
  1151. if (count == 1) {
  1152. if (input == 0) {
  1153. //返回给调用
  1154. //取消定时器
  1155. } else {
  1156. //清零
  1157. }
  1158. } else {
  1159. if (input == 0) {
  1160. //返回给调用
  1161. //取消定时器
  1162. } else {
  1163. //清零
  1164. }
  1165. }
  1166. }
  1167. bool CGpioEntity::GetReceiving(int deviceSeq, ReceivingInfo ri, ULONG iIndex, SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx)
  1168. {
  1169. Dbg("inputmode[%d],port[%d],ctt[%d]", ri.InputMode, ri.Port, ri.ContinuousTriggerTime);
  1170. switch (ri.InputMode) {
  1171. case IM_POSITIVE_PULSE_UP:
  1172. {
  1173. GetContextInfo* pGci = new GetContextInfo();
  1174. pGci->timerID = ctx->Req.devseq;
  1175. pGci->ctx = ctx;
  1176. pGci->index = iIndex;
  1177. pGci->Port = ri.Port;
  1178. pGci->CttCard = ri.ContinuousTriggerTime;
  1179. pGci->CttMove = ri.ContinuousTriggerTime;
  1180. pGci->CttPhone = ri.ContinuousTriggerTime;
  1181. pGci->CttShake = ri.ContinuousTriggerTime;
  1182. pGci->CttSwitch = ri.ContinuousTriggerTime;
  1183. pGci->InitCTT = ri.ContinuousTriggerTime;
  1184. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositivePulseUpTimerout, pGci);
  1185. GetFunction()->SetTimer(pGci->timerID, pListener, 1);
  1186. break;
  1187. }
  1188. case IM_POSITIVE_LEVEL:
  1189. {
  1190. GetContextInfo* pGci = new GetContextInfo();
  1191. pGci->timerID = deviceSeq;
  1192. pGci->ctx = ctx;
  1193. pGci->index = iIndex;
  1194. pGci->Port = ri.Port;
  1195. //pGci->ContinuousTriggerTime = ri.ContinuousTriggerTime;//oiltest 20130709
  1196. pGci->CttCard = ri.ContinuousTriggerTime;
  1197. pGci->CttMove = ri.ContinuousTriggerTime;
  1198. pGci->CttPhone = ri.ContinuousTriggerTime;
  1199. pGci->CttShake = ri.ContinuousTriggerTime;
  1200. pGci->CttSwitch = ri.ContinuousTriggerTime;
  1201. pGci->InitCTT = ri.ContinuousTriggerTime;
  1202. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveLevelTimerOut, pGci);
  1203. GetFunction()->SetTimer(pGci->timerID, pListener, 100);
  1204. break;
  1205. }
  1206. case IM_NEGATIVE_LEVEL:
  1207. {
  1208. GetContextInfo* pGci = new GetContextInfo();
  1209. pGci->timerID = deviceSeq;
  1210. pGci->ctx = ctx;
  1211. pGci->index = iIndex;
  1212. pGci->Port = ri.Port;
  1213. //pGci->ContinuousTriggerTime = ri.ContinuousTriggerTime;//oiltest 20130709
  1214. pGci->InitCTT = ri.ContinuousTriggerTime;
  1215. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnNegativeLevelTimerOut, pGci);
  1216. GetFunction()->SetTimer(pGci->timerID, pListener, 1);
  1217. break;
  1218. }
  1219. default:
  1220. break;
  1221. }
  1222. return true;
  1223. }
  1224. void CGpioEntity::GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi)
  1225. {
  1226. ErrorCodeEnum Error;
  1227. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  1228. CSmartPointer<IConfigInfo> spConfig;
  1229. Error = spEntityFunction->OpenConfig(Config_Software, spConfig);
  1230. if (Error != Error_Succeed) {
  1231. LOG_TRACE("open cfg file failed!");
  1232. return;
  1233. }
  1234. spConfig->ReadConfigValueInt(modName, "OutputMode", odi.OutputMode);
  1235. spConfig->ReadConfigValueInt(modName, "StopMode", odi.StopMode);
  1236. spConfig->ReadConfigValueInt(modName, "SetTime", odi.SetTime);
  1237. spConfig->ReadConfigValueInt(modName, "ResetTime", odi.ResetTime);
  1238. spConfig->ReadConfigValueInt(modName, "Timeout", odi.TimeOut);
  1239. LOG_TRACE("outputmode.stopmode:[%d].[%d]", odi.OutputMode, odi.StopMode);
  1240. }
  1241. void CGpioEntity::GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri)
  1242. {
  1243. ErrorCodeEnum Error;
  1244. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  1245. CSmartPointer<IConfigInfo> spConfig;
  1246. Error = spEntityFunction->OpenConfig(Config_Software, spConfig);
  1247. if (Error != Error_Succeed) {
  1248. LOG_TRACE("open cfg file failed!");
  1249. return;
  1250. }
  1251. spConfig->ReadConfigValueInt(modName, "InputMode", ri.InputMode);
  1252. spConfig->ReadConfigValueInt(modName, "ContinuousTriggerTime", ri.ContinuousTriggerTime);
  1253. }
  1254. BYTE CGpioEntity::GetOutputStatus(int sn)
  1255. {
  1256. if (sn == 0)
  1257. return m_btOutputStatus[0];
  1258. else if (sn == 1)
  1259. return m_btOutputStatus[1];
  1260. else if (sn == 2)
  1261. return m_btOutputStatus[2];
  1262. else
  1263. return 0;
  1264. }
  1265. SP_BEGIN_ENTITY_MAP()
  1266. SP_ENTITY(CGpioEntity)
  1267. SP_END_ENTITY_MAP()