mod_gpio.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  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(0) returned: %d)", err);
  231. err = m_hDevHelper->WritePort(1, 0x00);
  232. Dbg("write ports(1) returned: %d", err);
  233. if (m_bNewVersion) {
  234. err = m_hDevHelper->WritePort(3, 0x00);
  235. Dbg("write ports(3) returned: %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: 0x%X", 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. /** 注意设备序号是实体内定义的逻辑,不是设备端口号*/
  648. Dbg("GetStatus with devseq %d", deviceSeq);
  649. CSimpleStringA initDriver = "";
  650. int devicePort;
  651. ErrorCodeEnum Error;
  652. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  653. CSmartPointer<IConfigInfo> spConfig;
  654. Error = spEntityFunction->OpenConfig(Config_Software, spConfig);
  655. if (Error != Error_Succeed) {
  656. LOG_TRACE("open cfg file failed!");
  657. return;
  658. }
  659. /** 获取指定的模式,以便后续获取输入模式和持续触发模式,见 GetReceivingModInfo*/
  660. spConfig->ReadConfigValue("InitDriver", "PhoneLift", initDriver);
  661. /** 获取硬件规格里对应的序号,其实是固定死的*/
  662. spConfig->ReadConfigValueInt("DriverPort", "PhoneLift", devicePort);
  663. ReceivingInfo ri;
  664. GetReceivingModInfo(initDriver, ri);
  665. ri.Port = devicePort;
  666. GetReceiving(deviceSeq, ri, PICKUPSENSOR, ctx);
  667. }
  668. void CGpioEntity::OnOutputPositiveLevelTimerout(void* pData)
  669. {
  670. SetContextInfo* pSCI = (SetContextInfo*)pData;
  671. GetFunction()->KillTimer(pSCI->timerID);
  672. ULONG devEnableStatus = GetDevEnableStatus();
  673. DevOutputInfo doi = GetCurrDevStatus();
  674. WritePin(pSCI->pinSeq, true);
  675. delete pSCI;
  676. SaveCurrDevStatus(doi);
  677. }
  678. void CGpioEntity::OnPositiveFlickerSetTimerout(void* pData)
  679. {
  680. SetContextInfo* pSCI = (SetContextInfo*)pData;
  681. GetFunction()->KillTimer(pSCI->timerID);
  682. ULONG devEnableStatus = GetDevEnableStatus();
  683. DevOutputInfo doi = GetCurrDevStatus();
  684. WritePin(pSCI->pinSeq, false);
  685. pSCI->timerID = pSCI->timerID;
  686. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerResetTimerout, pSCI, true);
  687. GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->resetTime);
  688. }
  689. void CGpioEntity::OnPositiveFlickerResetTimerout(void* pData)
  690. {
  691. SetContextInfo* pSCI = (SetContextInfo*)pData;
  692. GetFunction()->KillTimer(pSCI->timerID);
  693. ULONG devEnableStatus = GetDevEnableStatus();
  694. DevOutputInfo doi = GetCurrDevStatus();
  695. WritePin(pSCI->pinSeq, true);
  696. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSCI, true);
  697. GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->setTime);
  698. }
  699. bool CGpioEntity::SetOutDriving(GpioService_Set_Info req, OutDrivingInfo od, ULONG iIndex, ULONG pinSeq)
  700. {
  701. ULONG devEnableStatus = GetDevEnableStatus();
  702. DevOutputInfo doi = GetCurrDevStatus();
  703. if (req.close == 1) {
  704. GetFunction()->KillTimer(req.devseq);
  705. //oilyang add 20161222
  706. //如果关闭照明灯,以感知为准
  707. if (pinSeq == m_headlightDevPort)
  708. WritePin(pinSeq, m_bHeadLightFlag);
  709. else {
  710. if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
  711. Dbg("off hspsanner.");
  712. WritePin(PIN_HSPSCANNER_LIGHT, false);
  713. }
  714. WritePin(pinSeq, false);
  715. }
  716. return true;
  717. }
  718. switch (od.OutputMode) {
  719. case OM_POSITIVE_LEVEL:
  720. {
  721. switch (od.StopMode) {
  722. case SM_CALLTRIGGER:
  723. {
  724. LOG_TRACE("0.0 mode:output[%u], pinSeq=%u", doi.output, pinSeq);
  725. //if it is hspsanner
  726. if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
  727. Dbg("light hspsanner.");
  728. WritePin(PIN_HSPSCANNER_LIGHT, true);
  729. }
  730. WritePin(pinSeq, true);
  731. break;
  732. }
  733. case SM_TIMEOUT:
  734. {
  735. WritePin(pinSeq, true);
  736. SetContextInfo* pSci = new SetContextInfo();;
  737. pSci->ctx = NULL;
  738. pSci->timerID = req.devseq;
  739. pSci->timeout = od.TimeOut;
  740. pSci->index = iIndex;
  741. pSci->pinSeq = pinSeq;
  742. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnOutputPositiveLevelTimerout, pSci);
  743. GetFunction()->SetTimer(pSci->timerID, pListener, od.TimeOut);
  744. break;
  745. }
  746. case SM_CYCLE:
  747. break;
  748. default:
  749. break;
  750. }
  751. }
  752. break;
  753. case OM_POSITIVE_FLICKER:
  754. switch (od.StopMode) {
  755. case SM_CALLTRIGGER:
  756. break;
  757. case SM_TIMEOUT:
  758. break;
  759. case SM_CYCLE:
  760. {
  761. SetContextInfo* pSci = new SetContextInfo();
  762. pSci->ctx = NULL;
  763. pSci->index = iIndex;
  764. pSci->pinSeq = pinSeq;
  765. pSci->timerID = req.devseq;
  766. pSci->setTime = od.SetTime;
  767. pSci->resetTime = od.ResetTime;
  768. pSci->timeout = od.TimeOut;
  769. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSci, true);
  770. WritePin(pinSeq, true);
  771. GetFunction()->SetTimer(pSci->timerID, pListener, pSci->setTime);
  772. break;
  773. }
  774. default:
  775. break;
  776. }
  777. break;
  778. case OM_NEGATIVE_FLICKER:
  779. switch (od.StopMode) {
  780. case SM_CALLTRIGGER:
  781. break;
  782. case SM_TIMEOUT:
  783. break;
  784. case SM_CYCLE:
  785. break;
  786. default:
  787. break;
  788. }
  789. break;
  790. default:
  791. break;
  792. }
  793. return true;
  794. }
  795. void CGpioEntity::OnPositivePulseUpTimerout(void* pData)
  796. {
  797. GetContextInfo* pGCI = (GetContextInfo*)pData;
  798. BYTE btInput = 0;
  799. ErrorCodeEnum err;
  800. Dbg("port[%d]", INPUT_PORT_2);
  801. err = m_hDevHelper->ReadPort(INPUT_PORT_2, btInput);
  802. Dbg("read[%d]", btInput);
  803. //判断输入
  804. if (DetectBit(btInput, pGCI->index)) {
  805. if (pGCI->CttPhone == 0)//oiltest 20130709
  806. {
  807. ////触发
  808. pGCI->ctx->Ans.status = 1;
  809. pGCI->ctx->Answer(Error_Succeed);
  810. } else {
  811. pGCI->CttPhone--;//oiltest 20130709
  812. GetFunction()->ResetTimer(pGCI->timerID, 1000);
  813. }
  814. } else {
  815. pGCI->CttPhone = pGCI->InitCTT;//oiltest 20130709
  816. GetFunction()->ResetTimer(pGCI->timerID, 1);
  817. }
  818. }
  819. void CGpioEntity::OnNegativePulseUpTimerout(void* pData)
  820. {
  821. int count = 1;//from UserData
  822. ULONG input = 0;
  823. if (count == 1) {
  824. //oiltest GetInput(,&input);
  825. if (input == 0) {
  826. //返回给调用,发出触发日志
  827. } else {
  828. //不稳定,清空计数,重新来
  829. }
  830. } else {
  831. //oiltest GetInput(,&input);
  832. if (input == 0) {
  833. //计数减一,继续采样
  834. //ITimerListener *pListener = new TimerOutHelper<CGpioEntity>(this, CGpioEntity::OnPositivePulseUpTimerout, );
  835. //GetFunction()->SetTimer(,)
  836. } else {
  837. //不稳定,清空计数,重新来
  838. }
  839. }
  840. }
  841. void CGpioEntity::OnPositiveLevelTimerOut(void* pData)
  842. {
  843. GetContextInfo* pGci = (GetContextInfo*)pData;
  844. const int count = pGci->InitCTT;
  845. const int initCtt = pGci->InitCTT;
  846. const int pos = pGci->Port;
  847. ULONG input = 0;
  848. BYTE btInput;
  849. bool bShakeOne, bMoveOne, bSwitchOne, bPhoneOne, bCardOne;
  850. bShakeOne = bMoveOne = bSwitchOne = bPhoneOne = bCardOne = false;
  851. ErrorCodeEnum err = m_hDevHelper->ReadPort(INPUT_PORT_2, btInput);
  852. if (err != Error_Succeed) {
  853. DevErrorInfo devErrInfo;
  854. ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
  855. ErrorCodeEnum erroCode = m_hDevHelper->GetLastErr(devErrInfo);
  856. Dbg("ReadPort failed: %s, ErrMsg[%s]", SpStrError(err), (LPCTSTR)devErrInfo.szErrMsg);
  857. return;
  858. }
  859. /** 震动感应 */
  860. if (pGci->CttShake == 1) {
  861. bShakeOne = true;
  862. do {
  863. if (initCtt == 1) {
  864. if (DetectBit(btInput, VIBRATIONSENSOR)) {
  865. if (!m_bVibrationFlag && m_eMachineType == RVC_Stand2S) {
  866. LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(17), __LINE__));
  867. }
  868. m_bVibrationFlag = true;
  869. } else
  870. m_bVibrationFlag = false;
  871. break;
  872. }
  873. if (m_bVibrationRound) {
  874. if (DetectBit(btInput, VIBRATIONSENSOR) && !m_bVibrationFlag) {
  875. if (m_eMachineType == RVC_Stand2S)
  876. LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(17), __LINE__));
  877. m_bVibrationFlag = true;
  878. m_bVibrationRound = false;
  879. }
  880. } else if (!DetectBit(btInput, VIBRATIONSENSOR) && m_bVibrationFlag) {
  881. m_bVibrationFlag = false;
  882. m_bVibrationRound = true;
  883. }
  884. } while (0);
  885. pGci->CttShake = pGci->InitCTT;
  886. }
  887. /** 机箱门开关检测*/
  888. if (pGci->CttSwitch == 1) {
  889. bSwitchOne = true;
  890. do {
  891. if (initCtt == 1) {
  892. if (DetectBit(btInput, OPENSENSOR)) {
  893. if (!m_bOpenFlag) {
  894. if (m_eMachineType == RVC_Stand2S)
  895. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(18), __LINE__));
  896. m_bOpenFlag = true;
  897. }
  898. } else if (m_bOpenFlag) {
  899. if (m_eMachineType == RVC_Stand2S)
  900. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(18), __LINE__));
  901. m_bOpenFlag = false;
  902. }
  903. break;
  904. }
  905. if (m_bOpenRound) {
  906. if (DetectBit(btInput, OPENSENSOR) && !m_bOpenFlag) {
  907. if (m_eMachineType == RVC_Stand2S)
  908. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(18), __LINE__));
  909. m_bOpenFlag = true;
  910. m_bOpenRound = false;
  911. }
  912. } else if (!DetectBit(btInput, OPENSENSOR) && m_bOpenFlag) {
  913. if (m_eMachineType == RVC_Stand2S)
  914. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(18), __LINE__));
  915. m_bOpenFlag = false;
  916. m_bOpenRound = true;
  917. }
  918. } while (0);
  919. pGci->CttSwitch = pGci->InitCTT;
  920. }
  921. /**话机检测*/
  922. if (pGci->CttPhone == 1) {
  923. bPhoneOne = true;
  924. do {
  925. if (initCtt == 1) {
  926. if (DetectBit(btInput, PICKUPSENSOR)) {
  927. if (!m_bPickUpFlag) {
  928. if (m_eMachineType == RVC_Stand2S)
  929. LogEvent(Severity_Middle, LOG_EVT_PICKUP, "话机提起");
  930. m_bPickUpFlag = true;
  931. }
  932. } else if (m_bPickUpFlag) {
  933. if (m_eMachineType == RVC_Stand2S)
  934. LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "话机放下");
  935. m_bPickUpFlag = false;
  936. }
  937. break;
  938. }
  939. if (m_bPickUpRound) {
  940. if (DetectBit(btInput, PICKUPSENSOR) && !m_bPickUpFlag) {
  941. if (m_eMachineType == RVC_Stand2S)
  942. LogEvent(Severity_Middle, LOG_EVT_PICKUP, "话机提起");
  943. m_bPickUpFlag = true;
  944. m_bPickUpRound = false;
  945. }
  946. } else if (!DetectBit(btInput, PICKUPSENSOR)) {
  947. if (m_bPickUpFlag) {
  948. if (m_eMachineType == RVC_Stand2S)
  949. LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "话机放下");
  950. m_bPickUpFlag = false;
  951. m_bPickUpRound = true;
  952. }
  953. }
  954. } while (0);
  955. pGci->CttPhone = pGci->InitCTT;
  956. }
  957. /*物体靠近感知检测*/
  958. if (pGci->CttMove == 1) {
  959. bMoveOne = true;
  960. do {
  961. if (initCtt == 1) {
  962. if (DetectBit(btInput, MOVESENSOR)) {
  963. if (m_eMachineType == RVC_Stand2S)
  964. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(20), __LINE__));
  965. }
  966. break;
  967. }
  968. if (m_bMoveRound) {
  969. if (DetectBit(btInput, MOVESENSOR)) {
  970. m_moveDisappearTimes = 0;
  971. if (m_moveHoldTimes < MAX_MOVE_HOLD_TIMES) { // 100ms * 5000
  972. if ((m_moveHoldTimes % LOG_TIME_VALUE) == 0) { //100ms * 25 = 2.5s 但因为厂家接口调用,不进来计数,需要800ms+
  973. if (m_eMachineType == RVC_Stand2S)
  974. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(20), __LINE__));
  975. }
  976. } else if ((m_moveHoldTimes % MAX_MOVE_HOLD_TIMES) == 0) { //难道8分钟一直有人就异常?还有一个 Round 标识
  977. if (m_eMachineType == RVC_Stand2S)
  978. LogWarn(Severity_Middle, Error_Unexpect, LOG_EVT_MOVEDETECT_ABNORMAL, "移动次数异常");
  979. }
  980. m_moveHoldTimes++;
  981. m_bMoveRound = false;
  982. }
  983. } else if (!DetectBit(btInput, MOVESENSOR)) {
  984. m_moveHoldTimes = 0;
  985. if ((m_moveDisappearTimes % LOG_TIME_VALUE) == 0) {
  986. if (m_eMachineType == RVC_Stand2S)
  987. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(20), __LINE__));
  988. }
  989. m_moveDisappearTimes++;
  990. m_bMoveRound = true;
  991. }
  992. } while (0);
  993. pGci->CttMove = pGci->InitCTT;
  994. }
  995. /*卡嘴异物检测*/
  996. if (pGci->CttCard == 1) {
  997. bCardOne = true;
  998. do {
  999. if (initCtt == 1) {
  1000. if (DetectBit(btInput, CARDGATESENSOR)) {
  1001. if (!m_bCardGateFlag) {
  1002. if (m_eMachineType == RVC_Stand2S)
  1003. LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(21), __LINE__));
  1004. m_bCardGateFlag = true;
  1005. }
  1006. } else
  1007. m_bCardGateFlag = false;
  1008. break;
  1009. }
  1010. if (m_bCardGateRound) {
  1011. if (DetectBit(btInput, CARDGATESENSOR) && !m_bCardGateFlag) {
  1012. if (m_eMachineType == RVC_Stand2S)
  1013. LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(21), __LINE__));
  1014. m_bCardGateFlag = true;
  1015. m_bCardGateRound = false;
  1016. }
  1017. } else if (!DetectBit(btInput, CARDGATESENSOR) && m_bCardGateFlag) {
  1018. m_bCardGateFlag = false;
  1019. m_bCardGateRound = true;
  1020. }
  1021. } while (0);
  1022. pGci->CttCard = pGci->InitCTT;
  1023. }
  1024. /////////////////////////////////////////////////////////////////////////////////////
  1025. if (pGci->CttShake > 1 && !bShakeOne) {
  1026. do {
  1027. if (m_bVibrationRound) {
  1028. if (DetectBit(btInput, VIBRATIONSENSOR))
  1029. pGci->CttShake--;
  1030. else {
  1031. m_bVibrationRound = false;
  1032. pGci->CttShake = pGci->InitCTT;
  1033. }
  1034. } else {
  1035. if (!DetectBit(btInput, VIBRATIONSENSOR))
  1036. pGci->CttShake--;
  1037. else {
  1038. m_bVibrationRound = true;
  1039. pGci->CttShake = pGci->InitCTT;
  1040. }
  1041. }
  1042. } while (0);
  1043. }
  1044. if (pGci->CttSwitch > 1 && !bSwitchOne) {
  1045. do {
  1046. if (m_bOpenRound) {
  1047. if (DetectBit(btInput, OPENSENSOR))
  1048. pGci->CttSwitch--;
  1049. else {
  1050. m_bOpenRound = false;
  1051. pGci->CttSwitch = pGci->InitCTT;
  1052. }
  1053. } else {
  1054. if (!DetectBit(btInput, OPENSENSOR))
  1055. pGci->CttSwitch--;
  1056. else {
  1057. m_bOpenRound = true;
  1058. pGci->CttSwitch = pGci->InitCTT;
  1059. }
  1060. }
  1061. } while (0);
  1062. }
  1063. if (pGci->CttPhone > 1 && !bPhoneOne) {
  1064. do {
  1065. if (m_bPickUpRound) {
  1066. if (DetectBit(btInput, PICKUPSENSOR)) {
  1067. pGci->CttPhone--;
  1068. } else {
  1069. m_bPickUpRound = false;
  1070. pGci->CttPhone = pGci->InitCTT;
  1071. }
  1072. } else {
  1073. if (!DetectBit(btInput, PICKUPSENSOR))
  1074. pGci->CttPhone--;
  1075. else {
  1076. m_bPickUpRound = true;
  1077. pGci->CttPhone = pGci->InitCTT;
  1078. }
  1079. }
  1080. } while (0);
  1081. }
  1082. if (pGci->CttMove > 1 && !bMoveOne) {
  1083. do {
  1084. //Dbg("before ccMove: %d, ccInit: %d, moveRound: %d, %d, disppear: %d, holder: %d",
  1085. // pGci->CttMove, pGci->InitCTT, m_bMoveRound, DetectBit(btInput, MOVESENSOR), m_moveDisappearTimes, m_moveHoldTimes);
  1086. if (m_bMoveRound) {
  1087. if (DetectBit(btInput, MOVESENSOR))
  1088. pGci->CttMove--;
  1089. else {
  1090. m_bMoveRound = false;
  1091. pGci->CttMove = pGci->InitCTT;
  1092. }
  1093. } else {
  1094. if (!DetectBit(btInput, MOVESENSOR))
  1095. pGci->CttMove--;
  1096. else {
  1097. m_bMoveRound = true;
  1098. pGci->CttMove = pGci->InitCTT;
  1099. }
  1100. }
  1101. //Dbg("after ccMove: %d, ccInit: %d, moveRound: %d, %d, disppear: %d, holder: %d",
  1102. // pGci->CttMove, pGci->InitCTT, m_bMoveRound, DetectBit(btInput, MOVESENSOR), m_moveDisappearTimes, m_moveHoldTimes);
  1103. } while (0);
  1104. } else {
  1105. //Dbg("===== ccMove: %d, moveOne: %d, moveRound: %d, %d, disppear: %d, holder: %d",
  1106. // pGci->CttMove, bMoveOne, m_bMoveRound, DetectBit(btInput, MOVESENSOR), m_moveDisappearTimes, m_moveHoldTimes);
  1107. }
  1108. if (pGci->CttCard > 1 && !bCardOne) {
  1109. do {
  1110. if (m_bCardGateRound) {
  1111. if (DetectBit(btInput, CARDGATESENSOR))
  1112. pGci->CttCard--;
  1113. else {
  1114. m_bCardGateRound = false;
  1115. pGci->CttCard = pGci->InitCTT;
  1116. }
  1117. } else {
  1118. if (!DetectBit(btInput, CARDGATESENSOR))
  1119. pGci->CttCard--;
  1120. else {
  1121. m_bCardGateRound = true;
  1122. pGci->CttCard = pGci->InitCTT;
  1123. }
  1124. }
  1125. } while (0);
  1126. }
  1127. GetFunction()->ResetTimer(pGci->timerID, 100);
  1128. }
  1129. void CGpioEntity::OnNegativeLevelTimerOut(void* pData)
  1130. {
  1131. int count = 1;//from UserData
  1132. ULONG input = 0;
  1133. if (count == 1) {
  1134. if (input == 0) {
  1135. //返回给调用
  1136. //取消定时器
  1137. } else {
  1138. //清零
  1139. }
  1140. } else {
  1141. if (input == 0) {
  1142. //返回给调用
  1143. //取消定时器
  1144. } else {
  1145. //清零
  1146. }
  1147. }
  1148. }
  1149. bool CGpioEntity::GetReceiving(int deviceSeq, ReceivingInfo ri, ULONG iIndex,
  1150. SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx)
  1151. {
  1152. Dbg("inputmode[%d],port[%d],ctt[%d]", ri.InputMode, ri.Port, ri.ContinuousTriggerTime);
  1153. switch (ri.InputMode)
  1154. {
  1155. case IM_POSITIVE_PULSE_UP:
  1156. {
  1157. GetContextInfo* pGci = new GetContextInfo();
  1158. pGci->timerID = ctx->Req.devseq;
  1159. pGci->ctx = ctx;
  1160. pGci->index = iIndex;
  1161. pGci->Port = ri.Port;
  1162. pGci->CttCard = ri.ContinuousTriggerTime;
  1163. pGci->CttMove = ri.ContinuousTriggerTime;
  1164. pGci->CttPhone = ri.ContinuousTriggerTime;
  1165. pGci->CttShake = ri.ContinuousTriggerTime;
  1166. pGci->CttSwitch = ri.ContinuousTriggerTime;
  1167. pGci->InitCTT = ri.ContinuousTriggerTime;
  1168. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositivePulseUpTimerout, pGci);
  1169. GetFunction()->SetTimer(pGci->timerID, pListener, 1);
  1170. break;
  1171. }
  1172. case IM_POSITIVE_LEVEL:
  1173. {
  1174. GetContextInfo* pGci = new GetContextInfo();
  1175. pGci->timerID = deviceSeq;
  1176. pGci->ctx = ctx;
  1177. pGci->index = iIndex;
  1178. pGci->Port = ri.Port;
  1179. //pGci->ContinuousTriggerTime = ri.ContinuousTriggerTime;//oiltest 20130709
  1180. pGci->CttCard = ri.ContinuousTriggerTime;
  1181. pGci->CttMove = ri.ContinuousTriggerTime;
  1182. pGci->CttPhone = ri.ContinuousTriggerTime;
  1183. pGci->CttShake = ri.ContinuousTriggerTime;
  1184. pGci->CttSwitch = ri.ContinuousTriggerTime;
  1185. pGci->InitCTT = ri.ContinuousTriggerTime;
  1186. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveLevelTimerOut, pGci);
  1187. GetFunction()->SetTimer(pGci->timerID, pListener, 100);
  1188. break;
  1189. }
  1190. case IM_NEGATIVE_LEVEL:
  1191. {
  1192. GetContextInfo* pGci = new GetContextInfo();
  1193. pGci->timerID = deviceSeq;
  1194. pGci->ctx = ctx;
  1195. pGci->index = iIndex;
  1196. pGci->Port = ri.Port;
  1197. //pGci->ContinuousTriggerTime = ri.ContinuousTriggerTime;//oiltest 20130709
  1198. pGci->InitCTT = ri.ContinuousTriggerTime;
  1199. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnNegativeLevelTimerOut, pGci);
  1200. GetFunction()->SetTimer(pGci->timerID, pListener, 1);
  1201. break;
  1202. }
  1203. default:
  1204. break;
  1205. }
  1206. return true;
  1207. }
  1208. void CGpioEntity::GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi)
  1209. {
  1210. ErrorCodeEnum Error;
  1211. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  1212. CSmartPointer<IConfigInfo> spConfig;
  1213. Error = spEntityFunction->OpenConfig(Config_Software, spConfig);
  1214. if (Error != Error_Succeed) {
  1215. Dbg("open cfg file failed!");
  1216. return;
  1217. }
  1218. spConfig->ReadConfigValueInt(modName, "OutputMode", odi.OutputMode);
  1219. spConfig->ReadConfigValueInt(modName, "StopMode", odi.StopMode);
  1220. spConfig->ReadConfigValueInt(modName, "SetTime", odi.SetTime);
  1221. spConfig->ReadConfigValueInt(modName, "ResetTime", odi.ResetTime);
  1222. spConfig->ReadConfigValueInt(modName, "Timeout", odi.TimeOut);
  1223. LOG_TRACE("outputmode.stopmode:[%d].[%d]", odi.OutputMode, odi.StopMode);
  1224. }
  1225. /*从配置文件中获取配置*/
  1226. void CGpioEntity::GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri)
  1227. {
  1228. ErrorCodeEnum Error;
  1229. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  1230. CSmartPointer<IConfigInfo> spConfig;
  1231. Error = spEntityFunction->OpenConfig(Config_Software, spConfig);
  1232. if (Error != Error_Succeed) {
  1233. LOG_TRACE("open cfg file failed!");
  1234. return;
  1235. }
  1236. spConfig->ReadConfigValueInt(modName, "InputMode", ri.InputMode);
  1237. spConfig->ReadConfigValueInt(modName, "ContinuousTriggerTime", ri.ContinuousTriggerTime);
  1238. }
  1239. BYTE CGpioEntity::GetOutputStatus(int sn)
  1240. {
  1241. if (sn == 0)
  1242. return m_btOutputStatus[0];
  1243. else if (sn == 1)
  1244. return m_btOutputStatus[1];
  1245. else if (sn == 2)
  1246. return m_btOutputStatus[2];
  1247. else
  1248. return 0;
  1249. }
  1250. SP_BEGIN_ENTITY_MAP()
  1251. SP_ENTITY(CGpioEntity)
  1252. SP_END_ENTITY_MAP()