mod_gpio.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  1. #include "stdafx.h"
  2. #include "mod_gpio.h"
  3. #include "publicFunExport.h"
  4. const int MAX_GPIO_INIT_TRIES = 3;
  5. const int INPUT_PORT_2 = 2;
  6. const int MAX_MOVE_HOLD_TIMES = 5000;
  7. const int LOG_TIME_VALUE = 25;
  8. int positive_pulse_up_count = 0;
  9. int negative_pulse_down_count = 0;
  10. int positive_pulse_both_count = 0;
  11. int negative_pulse_both_count = 0;
  12. int positive_level_count = 0;
  13. int negative_level_count = 0;
  14. #define SETBIT(x,y) x|=(1<<(y))
  15. #define CLEARBIT(x,y) x&=((1<<(y))^0xffffff)
  16. using namespace SP::Module::Comm;
  17. static const char* GetDriverPortString(int pin)
  18. {
  19. switch (pin) {
  20. case 1: return "【驱动】读卡发卡器提示灯";
  21. case 2: return "【驱动】前端USB通断控制";
  22. case 3: return "【驱动】身份证阅读器提示灯";
  23. case 4: return "【驱动】密码键盘提示灯";
  24. case 5: return "【驱动】脸部照明灯";
  25. case 6: return "【驱动】故障灯";
  26. case 7: return "【驱动】读卡发卡器维护提示灯";
  27. case 8: return "【驱动】前端USB口提示灯";
  28. case 9: return "【驱动】非接IC读卡器提示灯";
  29. case 10: return "";
  30. case 11: return "【驱动】指纹仪提示灯";
  31. case 12: return "【驱动】凭条打印提示灯";
  32. case 13: return "【驱动】高拍仪提示灯";
  33. case 14: return "";
  34. case 15: return "";
  35. case 16: return "";
  36. case 17: return "【接收】震动探测器";
  37. case 18: return "【接收】机具门感应开关";
  38. case 19: return "【接收】话机提机感应开关";
  39. case 20: return "【接收】人体探测感应器";
  40. case 21: return "【接收】发卡器卡嘴覆盖探测器";
  41. //case 22: return "";
  42. //case 23: return "";
  43. //case 24: return "";
  44. //case 25: return "";
  45. case 26: return "【驱动】高拍仪提示灯";
  46. //case 27: return "";
  47. //case 28: return "";
  48. //case 29: return "";
  49. //case 30: return "";
  50. //case 31: return "";
  51. //case 32: return "";
  52. //case 33: return "";
  53. //case 34: return "";
  54. //case 35: return "";
  55. //case 36: return "";
  56. //case 37: return "";
  57. //case 38: return "";
  58. //case 39: return "";
  59. //case 40: return "";
  60. //case 41: return "";
  61. //case 42: return "";
  62. default:
  63. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unkown pin sequence: %d", pin);
  64. return "";
  65. break;
  66. }
  67. }
  68. #define LIGHT_STRING_CONVERT(str) case str : return #str; break;
  69. static const char* GetLightSeqString(int seq)
  70. {
  71. switch (seq) {
  72. LIGHT_STRING_CONVERT(UNKNOWN_DEVICE)
  73. LIGHT_STRING_CONVERT(CARDREADER)
  74. LIGHT_STRING_CONVERT(CARDREADER_RED)
  75. LIGHT_STRING_CONVERT(IDCERTIFICATE)
  76. LIGHT_STRING_CONVERT(PINPAD)
  77. LIGHT_STRING_CONVERT(SHAKEDETECT)
  78. LIGHT_STRING_CONVERT(SWITCHINDUCTOR)
  79. LIGHT_STRING_CONVERT(PHONEPICKUP)
  80. LIGHT_STRING_CONVERT(MOVEDETECT)
  81. LIGHT_STRING_CONVERT(CARDGATEDETECT)
  82. LIGHT_STRING_CONVERT(HEADLIGHT)
  83. LIGHT_STRING_CONVERT(HEADLIGHT_RED)
  84. LIGHT_STRING_CONVERT(CONTACTLESSCARD)
  85. LIGHT_STRING_CONVERT(HEADLIGHT_ASSIST)
  86. LIGHT_STRING_CONVERT(HSPSCANNER)
  87. LIGHT_STRING_CONVERT(FINGERPRINT)
  88. default:
  89. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unkonwn LightSeq: %d", seq);
  90. return "UnConver One";
  91. break;
  92. }
  93. }
  94. #undef LIGHT_STRING_CONVERT
  95. void CGpioServiceSession::Handle_Set(SpOnewayCallContext<GpioService_Set_Info>::Pointer ctx)
  96. {
  97. }
  98. void CGpioServiceSession::Handle_GetStatus(SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx)
  99. {
  100. ctx->Answer(Error_NotSupport);
  101. }
  102. void CGpioServiceSession::Handle_QueryCurrSet(SpReqAnsContext<GpioService_QueryCurrSet_Req, GpioService_QueryCurrSet_Ans>::Pointer ctx)
  103. {
  104. ctx->Answer(Error_NotSupport);
  105. }
  106. bool isnostr(const char* str)
  107. {
  108. int len = strlen(str);
  109. if (len == 0)
  110. return true;
  111. for (int i = 0; i < len; ++i) {
  112. if (*(str + i) != ' ')
  113. return false;
  114. }
  115. return true;
  116. }
  117. /** 因为GPIO没有状态机的概念,所以抛送信息的代码单独实现,没有跟其他硬件类似使用基类中的公有函数 [Gifur@2023810]*/
  118. void CGpioEntity::ToLogRootINIInfo()
  119. {
  120. CSmartPointer<IConfigInfo> spConfigRoot;
  121. GetFunction()->OpenConfig(Config_Root, spConfigRoot);
  122. CSimpleStringA entityName(GetEntityName());
  123. CSimpleStringA sectionName = CSimpleStringA::Format("Device.%s", entityName.GetData());
  124. CSimpleStringA csVendor(true), csVersion(true), csBatch(true), csPort(true), csBaudrate(true);
  125. spConfigRoot->ReadConfigValue(sectionName.GetData(), "Vendor", csVendor);
  126. spConfigRoot->ReadConfigValue(sectionName.GetData(), "Version", csVersion);
  127. spConfigRoot->ReadConfigValue(sectionName.GetData(), "Batch", csBatch);
  128. spConfigRoot->ReadConfigValue(sectionName.GetData(), "Port", csPort);
  129. spConfigRoot->ReadConfigValue(sectionName.GetData(), "Baudrate", csBaudrate);
  130. std::map<std::string, std::string> rootInfo;
  131. CSimpleStringA csPortNum(true), csCheckData(true), csKeySN(true), csInOutDir(true);
  132. rootInfo["Vendor"] = csVendor;
  133. rootInfo["Version"] = csVersion;
  134. rootInfo["Batch"] = csBatch;
  135. rootInfo["Port"] = csPort;
  136. rootInfo["Baudrate"] = csBaudrate;
  137. spConfigRoot->ReadConfigValue(sectionName.GetData(), "PortNum", csPortNum);
  138. spConfigRoot->ReadConfigValue(sectionName.GetData(), "InOutDir", csInOutDir);
  139. rootInfo["PortNum"] = csPortNum;
  140. rootInfo["InOutDir"] = csInOutDir;
  141. std::pair<bool, std::string> strResult;
  142. strResult = generateJsonStr(rootInfo);
  143. strResult.second.c_str();
  144. if (!entityName.IsNullOrEmpty()) {
  145. LogWarn(Severity_Low, Error_Debug, GPIO_UserErrorCode_Real_Root_Config, strResult.second.c_str());
  146. } else {
  147. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Entity Name is empty, please check!!!");
  148. }
  149. return;
  150. }
  151. void CGpioEntity::ToLogWarnInfoAboutTerm(const AdapterInfo& m_adapterInfo)
  152. {
  153. LOG_FUNCTION();
  154. CSmartPointer<IConfigInfo> spConfigRoot;
  155. GetFunction()->OpenConfig(Config_Root, spConfigRoot);
  156. CSimpleStringA csEnvCamera(""), csOptCamera, csOSVerion, csWarnMsg("");
  157. //calculate file hash value
  158. std::map<std::string, std::string> termInfo;
  159. char* strFileHash = new char[128];
  160. ZeroMemory(strFileHash, 128);
  161. BYTE fileHash[32];
  162. SM3File(const_cast<char*>(m_adapterInfo.adapterFileName.GetData()), fileHash);
  163. SP::Module::Util::HexBuf2StrBuf(fileHash, &strFileHash, 32);
  164. //calculate file size
  165. struct stat statbuf;
  166. ZeroMemory(&statbuf, sizeof(statbuf));
  167. stat(m_adapterInfo.adapterFileName.GetData(), &statbuf);
  168. int fileSize = statbuf.st_size;
  169. termInfo["VendorDllName"] = m_adapterInfo.adapterFileName;
  170. termInfo["VendorDllFileHash"] = strFileHash;
  171. ZeroMemory(strFileHash, 128);
  172. termInfo["VendorDllFileSize"] = _itoa(fileSize, strFileHash, 10);
  173. termInfo["szModel"] = m_adapterInfo.devCatInfo.szModel;
  174. termInfo["szType"] = m_adapterInfo.devCatInfo.szType;
  175. termInfo["Port"] = m_port;
  176. termInfo["PortNum"] = m_portNum;
  177. termInfo["Baudrate"] = m_Baudrate;
  178. termInfo["InOutDir"] = m_InOutDir;
  179. if (strFileHash != nullptr) {
  180. delete[] strFileHash;
  181. strFileHash = nullptr;
  182. }
  183. std::pair<bool, std::string> strResult;
  184. strResult = generateJsonStr(termInfo);
  185. LogWarn(Severity_Low, Error_Unexpect, GPIO_UserErrorCode_LogInfoAboutTerm, strResult.second.c_str());
  186. return;
  187. }
  188. bool CGpioEntity::DetectBit(ULONG data, int pos)
  189. {
  190. if (!m_bFuncVer2) {
  191. ULONG tmp = 0;
  192. SETBIT(tmp, pos);
  193. return data & tmp;
  194. } else {
  195. if (m_hDevHelper != nullptr) {
  196. DWORD dwReq = (GPIO_DEV_SN_SENSOR_SHAKE << pos);
  197. return (data & dwReq);
  198. }
  199. }
  200. }
  201. ErrorCodeEnum CGpioEntity::Initial()
  202. {
  203. ErrorCodeEnum err;
  204. LOG_FUNCTION();
  205. ErrorCodeEnum eErrDev;
  206. CSimpleStringA dllName;
  207. eErrDev = ExtractVendorLibFullPath(dllName);
  208. if (eErrDev != Error_Succeed) {
  209. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("load vendor dll or so(%s)(%s) failed.", dllName.GetData(), SpStrError(eErrDev));
  210. return Error_DevLoadFileFailed;
  211. }
  212. LogWarn(Severity_Low, Error_Unexpect, GPIO_UserErrorCode_RootInfo, dllName.GetData());
  213. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  214. CSmartPointer<IConfigInfo> spConfig;
  215. eErrDev = spEntityFunction->OpenConfig(Config_Root, spConfig);
  216. if (eErrDev != Error_Succeed) {
  217. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open cfg file failed %s", SpStrError(eErrDev));
  218. return eErrDev;
  219. }
  220. CSimpleStringA devVendor, devVer, devBatch, dllSuffix;
  221. devVendor = devVer = devBatch = "";
  222. spConfig->ReadConfigValue("Device.Gpio", "Vendor", devVendor);
  223. spConfig->ReadConfigValue("Device.Gpio", "Version", devVer);
  224. spConfig->ReadConfigValue("Device.Gpio", "Batch", devBatch);
  225. #if defined(RVC_OS_WIN)
  226. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%s],[%s],[%s]", devVendor.GetData(), devVer.GetData(), devBatch.GetData());
  227. if (!_stricmp(devVendor, "Hyosung") || !_stricmp(devVendor, "Keba") || !_stricmp(devVendor, "Kxd")) {
  228. if (devVer == "1" && devBatch == "1") {
  229. m_bNewVersion = FALSE;
  230. } else {
  231. m_bNewVersion = TRUE;
  232. }
  233. } else {
  234. m_bNewVersion = TRUE;
  235. }
  236. #else
  237. m_bNewVersion = TRUE;
  238. #endif
  239. eErrDev = m_hDevHelper.LoadUp(dllName);
  240. if (eErrDev != Error_Succeed) {
  241. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("load up %s failed: %s", dllName.GetData(), SpStrError(eErrDev));
  242. return Error_DevLoadFileFailed;
  243. }
  244. m_adapterInfo.adapterFileName = dllName;
  245. int initTries = 0;
  246. do {
  247. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to open device.");
  248. int portNum, inOutDir, port, baudRate;
  249. err = spConfig->ReadConfigValueInt("Device.Gpio", "PortNum", portNum);
  250. if (err == Error_Succeed)
  251. m_dwPortNum = portNum;
  252. else
  253. return Error_IO;
  254. err = spConfig->ReadConfigValueInt("Device.Gpio", "InOutDir", inOutDir);
  255. if (err == Error_Succeed)
  256. m_dwInOutDir = inOutDir;
  257. else
  258. return Error_IO;
  259. spConfig->ReadConfigValueInt("Device.Gpio", "Port", port);
  260. spConfig->ReadConfigValueInt("Device.Gpio", "BaudRate", baudRate);
  261. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read cfg suc, port(%d), baudrate(%d).", port, baudRate);
  262. m_port = CSimpleStringA::Format("%d", port);
  263. m_Baudrate = CSimpleStringA::Format("%d", baudRate);
  264. m_portNum = CSimpleStringA::Format("%d", portNum);
  265. m_InOutDir = CSimpleStringA::Format("%d", inOutDir);
  266. GpioInitParam initParam;
  267. if (!m_bNewVersion) {
  268. initParam.dwPortNum = 3;
  269. initParam.dir[0] = true;
  270. initParam.dir[1] = true;
  271. initParam.dir[2] = false;
  272. } else {
  273. initParam.dwPortNum = 4;
  274. initParam.dir[0] = true;
  275. initParam.dir[1] = true;
  276. initParam.dir[2] = false;
  277. initParam.dir[3] = true;
  278. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("New available 4 port num");
  279. }
  280. CSimpleStringA errMsg("");
  281. initParam.dwPort = port;
  282. initParam.dwBaudRate = baudRate;
  283. err = m_hDevHelper->DevOpen(initParam);
  284. if (err == Error_Succeed) {
  285. ZeroMemory(m_devCatInfo.szModel, sizeof(m_devCatInfo.szModel));
  286. ZeroMemory(m_devCatInfo.szType, sizeof(m_devCatInfo.szType));
  287. ZeroMemory(m_devCatInfo.szVendor, sizeof(m_devCatInfo.szVendor));
  288. err = m_hDevHelper->GetDevCategory(m_devCatInfo);
  289. if (err == Error_Succeed) {
  290. m_adapterInfo.FulfillCategoryInfo(m_devCatInfo);
  291. CSimpleStringA strType(m_devCatInfo.szType);
  292. if (strType.IndexOf("FUNCVER=2.0") != -1) {
  293. m_bFuncVer2 = TRUE;
  294. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Detect new interface version: %s", strType.GetData());
  295. }
  296. } else {
  297. DevErrorInfo devErrInfo;
  298. ZeroMemory(&devErrInfo, sizeof(devErrInfo));
  299. m_hDevHelper->GetLastErr(devErrInfo);
  300. errMsg = CSimpleStringA::Format("GetDevCategory failed:%s(s)", SpStrError(err), devErrInfo.szErrMsg);
  301. LogWarn(Severity_Middle, Error_Unexpect, GPIO_UserErrorCode_GetDevCategory_Failed, errMsg.GetData());
  302. }
  303. initTries = 0;
  304. break;
  305. } else {
  306. DevErrorInfo devErrInfo;
  307. ZeroMemory(&devErrInfo, sizeof(devErrInfo));
  308. m_hDevHelper->GetLastErr(devErrInfo);
  309. errMsg = CSimpleStringA::Format("DevOpen failed:%s(%s)", SpStrError(err), devErrInfo.szErrMsg);
  310. LogWarn(Severity_Middle, Error_Unexpect, GPIO_UserErrorCode_DevOpen_Failed, errMsg.GetData());
  311. Sleep(300);
  312. initTries++;
  313. continue;
  314. }
  315. } while (initTries < MAX_GPIO_INIT_TRIES);
  316. if (initTries != 0) {
  317. LOG_TRACE("open gpio failed.");
  318. err = Error_DevConnFailed;
  319. }
  320. if (!m_bFuncVer2) {
  321. err = m_hDevHelper->WritePort(0, 0x00);
  322. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write ports(0) returned: %s)", SpStrError(err));
  323. err = m_hDevHelper->WritePort(1, 0x00);
  324. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write ports(1) returned: %s)", SpStrError(err));
  325. if (m_bNewVersion) {
  326. err = m_hDevHelper->WritePort(3, 0x00);
  327. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write ports(3) returned: %s)", SpStrError(err));
  328. }
  329. } else {
  330. err = m_hDevHelper->SetStatus(GPIO_DEV_SN_LIGHT_SENSOR_ALL, GPIO_DEV_LIGHT_MODE_RESET);
  331. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write resetone returned: %s)", SpStrError(err));
  332. }
  333. //oilyang@20170214
  334. eErrDev = Error_Unexpect;
  335. CSmartPointer<IConfigInfo> spConfigRun;
  336. eErrDev = spEntityFunction->OpenConfig(Config_Run, spConfigRun);
  337. if (eErrDev == Error_Succeed) {
  338. int iMoveHoldTimes = 0;
  339. spConfigRun->ReadConfigValueInt("Init", "MaxMoveHoldTimes", iMoveHoldTimes);
  340. if (iMoveHoldTimes == 0) {
  341. spConfigRun->WriteConfigValueInt("Init", "MaxMoveHoldTimes", MAX_MOVE_HOLD_TIMES);
  342. m_moveHoldTimes = MAX_MOVE_HOLD_TIMES;
  343. }
  344. } else {
  345. m_moveHoldTimes = MAX_MOVE_HOLD_TIMES;//oiltmp about 5000*300ms = 25 minutes
  346. }
  347. m_moveDisappearTimes = m_moveHoldTimes;
  348. m_eMachineType = SP::Module::Comm::GetTerminalMachineInfo(this).type;
  349. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("machine type: %s", SP::Module::Comm::Type2Str(m_eMachineType));
  350. if (m_FirstStart) {
  351. m_FirstStart = FALSE;
  352. ToLogRootINIInfo();
  353. ToLogWarnInfoAboutTerm(m_adapterInfo);
  354. }
  355. return err;
  356. }
  357. void CGpioEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  358. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  359. const CAutoArray<DWORD>& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo)
  360. {
  361. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("usercode [%x]", dwUserCode);
  362. GpioService_Set_Info Req;
  363. Req.close = 0;
  364. switch (dwUserCode) {
  365. case LOG_EVT_CARDREADER_GREEN_ON:
  366. case LOG_EVT_CARDISSUER_GREEN_ON:
  367. Req.devseq = CARDREADER;
  368. Req.mode = 1;
  369. break;
  370. case LOG_EVT_CARDREADER_RED_ON:
  371. case LOG_EVT_CARDISSUER_RED_ON:
  372. Req.devseq = CARDREADER_RED;
  373. Req.mode = 1;
  374. break;
  375. case LOG_EVT_IDCERTIFICATE_GREEN_ON:
  376. Req.devseq = IDCERTIFICATE;
  377. Req.mode = 1;
  378. break;
  379. case LOG_EVT_FINGERPRINT_GREEN_ON:
  380. Req.devseq = FINGERPRINT;
  381. Req.mode = 1;
  382. break;
  383. case LOG_EVT_PINPAD_GREEN_ON:
  384. Req.devseq = PINPAD;
  385. Req.mode = 1;
  386. break;
  387. case LOG_EVT_HEADLIGHT_GREEN_ON:
  388. m_bHeadLightFlag = true;
  389. Req.devseq = HEADLIGHT;
  390. Req.mode = 1;
  391. LOG_TRACE("machine light on");
  392. break;
  393. case LOG_EVT_HEADLIGHT_RED_ON:
  394. Req.devseq = HEADLIGHT_RED;
  395. Req.mode = 1;
  396. break;
  397. case LOG_EVT_CONTACTLESS_CARD_GREEN_ON:
  398. Req.devseq = CONTACTLESSCARD;
  399. Req.mode = 1;
  400. break;
  401. case LOG_EVT_IEBROWSER_LIGHT_ASSISTANT_ON:
  402. Req.devseq = HEADLIGHT_ASSIST;
  403. Req.mode = 1;
  404. break;
  405. case LOG_EVT_CARDREADER_GREEN_OFF:
  406. case LOG_EVT_CARDISSUER_GREEN_OFF:
  407. Req.devseq = CARDREADER;
  408. Req.mode = 1;
  409. Req.close = 1;
  410. break;
  411. case LOG_EVT_CARDREADER_RED_OFF:
  412. case LOG_EVT_CARDISSUER_RED_OFF:
  413. Req.devseq = CARDREADER_RED;
  414. Req.mode = 1;
  415. Req.close = 1;
  416. break;
  417. case LOG_EVT_IDCERTIFICATE_GREEN_OFF:
  418. Req.devseq = IDCERTIFICATE;
  419. Req.mode = 1;
  420. Req.close = 1;
  421. break;
  422. case LOG_EVT_FINGERPRINT_GREEN_OFF:
  423. Req.devseq = FINGERPRINT;
  424. Req.mode = 1;
  425. Req.close = 1;
  426. break;
  427. case LOG_EVT_PINPAD_GREEN_OFF:
  428. Req.devseq = PINPAD;
  429. Req.mode = 1;
  430. Req.close = 1;
  431. break;
  432. case LOG_EVT_HEADLIGHT_GREEN_OFF:
  433. m_bHeadLightFlag = false;
  434. Req.devseq = HEADLIGHT;
  435. Req.mode = 1;
  436. Req.close = 1;
  437. LOG_TRACE("machine light off");
  438. break;
  439. case LOG_EVT_HEADLIGHT_RED_OFF:
  440. Req.devseq = HEADLIGHT_RED;
  441. Req.mode = 1;
  442. Req.close = 1;
  443. break;
  444. case LOG_EVT_CONTACTLESS_CARD_GREEN_OFF:
  445. Req.devseq = CONTACTLESSCARD;
  446. Req.mode = 1;
  447. Req.close = 1;
  448. break;
  449. case LOG_EVT_IEBROWSER_LIGHT_ASSISTANT_OFF:
  450. Req.devseq = HEADLIGHT_ASSIST;
  451. Req.mode = 1;
  452. Req.close = 1;
  453. break;
  454. case LOG_EVT_HSPS_LIGHT_ON:
  455. Req.devseq = HSPSCANNER;
  456. Req.mode = 1;
  457. LOG_TRACE("hspscanner light on");
  458. break;
  459. case LOG_EVT_HSPS_LIGHT_OFF:
  460. Req.devseq = HSPSCANNER;
  461. Req.mode = 1;
  462. Req.close = 1;
  463. LOG_TRACE("hspscanner light off");
  464. break;
  465. default:
  466. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("unkown event: 0x%X", dwUserCode);
  467. return;
  468. }
  469. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("devseq[%d],mode[%d]close[%d]", Req.devseq, Req.mode, Req.close);
  470. m_bFuncVer2 ? SetEx(Req) : Set(Req);
  471. }
  472. void CGpioEntity::WritePin(DWORD dwPinSeq, bool bHighLevel)
  473. {
  474. ErrorCodeEnum result(Error_Succeed);
  475. LOG_TRACE("Write Pin %s with %s !", GetDriverPortString(dwPinSeq + 1), bHighLevel ? "[Active]" : "[Inactive]");
  476. if (dwPinSeq > 16) {
  477. if (!m_bNewVersion && dwPinSeq < 24) {
  478. return;
  479. }
  480. if (bHighLevel)
  481. SETBIT(m_btOutputStatus[3], dwPinSeq - 24);
  482. else
  483. CLEARBIT(m_btOutputStatus[3], dwPinSeq - 24);
  484. result = m_hDevHelper->WritePort(3, m_btOutputStatus[3]);
  485. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after write port3, %d returned %s", m_btOutputStatus[3], SpStrError(result));
  486. return;
  487. }
  488. if (dwPinSeq < 8) {
  489. if (bHighLevel)
  490. SETBIT(m_btOutputStatus[0], dwPinSeq);
  491. else
  492. CLEARBIT(m_btOutputStatus[0], dwPinSeq);
  493. result = m_hDevHelper->WritePort(0, m_btOutputStatus[0]);
  494. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after write port0,%d returned %s", m_btOutputStatus[0], SpStrError(result));
  495. } else {
  496. if (bHighLevel)
  497. SETBIT(m_btOutputStatus[1], dwPinSeq - 8);
  498. else
  499. CLEARBIT(m_btOutputStatus[1], dwPinSeq - 8);
  500. DWORD dwStart, dwEnd;
  501. dwStart = GetTickCount();
  502. result = m_hDevHelper->WritePort(1, m_btOutputStatus[1]);
  503. dwEnd = GetTickCount();
  504. if ((dwEnd - dwStart) > 3000)
  505. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("writepin so long.than 3s(%d)", (dwEnd - dwStart));
  506. else
  507. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after write port1,%d returned %s", m_btOutputStatus[1], SpStrError(result));
  508. }
  509. }
  510. void CGpioEntity::SetEx(GpioService_Set_Info req)
  511. {
  512. int devicePort;
  513. LOG_TRACE("SetEx request %s arrived!", GetLightSeqString(req.devseq));
  514. switch (req.devseq) {
  515. case CARDREADER:
  516. {
  517. devicePort = GPIO_DEV_SN_LIGHT_CARDISSUER;
  518. break;
  519. }
  520. case CARDREADER_RED:
  521. {
  522. devicePort = GPIO_DEV_SN_LIGHT_CARDISSUER_MAINTAIN;
  523. break;
  524. }
  525. case IDCERTIFICATE:
  526. {
  527. devicePort = GPIO_DEV_SN_LIGHT_IDCERTIFICATE;
  528. break;
  529. }
  530. case FINGERPRINT:
  531. {
  532. devicePort = GPIO_DEV_SN_LIGHT_FINGERPRINT;
  533. break;
  534. }
  535. case PINPAD:
  536. {
  537. devicePort = GPIO_DEV_SN_LIGHT_PINPAD;
  538. break;
  539. }
  540. case HEADLIGHT:
  541. {
  542. devicePort = GPIO_DEV_SN_LIGHT_FACE;
  543. break;
  544. }
  545. case HEADLIGHT_RED:
  546. {
  547. devicePort = 6/*GPIO_DEV_SN_LIGHT_MACHINE_FAULT*/;
  548. break;
  549. }
  550. case CONTACTLESSCARD:
  551. {
  552. devicePort = GPIO_DEV_SN_LIGHT_CONTACTLESSCARD;
  553. break;
  554. }
  555. case HEADLIGHT_ASSIST:
  556. {
  557. devicePort = GPIO_DEV_SN_LIGHT_FACE;
  558. break;
  559. }
  560. break;
  561. default:
  562. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("unsupport device seq: %d", req.devseq);
  563. return;
  564. }
  565. if (m_hDevHelper != nullptr) {
  566. DWORD dwReq = devicePort;
  567. DWORD dwMode = 0;
  568. if (!req.close) {
  569. dwMode |= GPIO_DEV_LIGHT_MODE_COLOR_NORMAL;
  570. dwMode |= GPIO_DEV_LIGHT_MODE_LIGHT_FLICKER;
  571. }
  572. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to set SetStatus...%d, 0x%X", dwReq, dwMode);
  573. const ErrorCodeEnum ec = m_hDevHelper->SetStatus(dwReq, dwMode);
  574. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SetStatus returned %s", SpStrError(ec));
  575. if (ec != Error_Succeed) {
  576. DevErrorInfo devErrInfo;
  577. ZeroMemory(&devErrInfo, sizeof(devErrInfo));
  578. m_hDevHelper->GetLastErr(devErrInfo);
  579. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("SetStatus failed:%s(%s)", SpStrError(ec), devErrInfo.szErrMsg);
  580. }
  581. } else {
  582. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("dev helper object is invalid pointer!");
  583. }
  584. }
  585. void CGpioEntity::Set(GpioService_Set_Info req)
  586. {
  587. CSimpleStringA activeModeSecName = "";
  588. int devicePort;
  589. const int deviceSeq = req.devseq;
  590. LOG_TRACE("Set request %s arrived!", GetLightSeqString(deviceSeq));
  591. switch (deviceSeq) {
  592. case CARDREADER:
  593. {
  594. activeModeSecName = "CardReaderNormal";
  595. devicePort = 0;
  596. break;
  597. }
  598. case CARDREADER_RED:
  599. {
  600. activeModeSecName = "RedLightNormal";
  601. devicePort = 6;
  602. break;
  603. }
  604. case IDCERTIFICATE:
  605. {
  606. activeModeSecName = "IDCertificateNormal";
  607. devicePort = 2;
  608. break;
  609. }
  610. case FINGERPRINT:
  611. {
  612. activeModeSecName = "FingerPrintNormal";
  613. devicePort = 10;
  614. break;
  615. }
  616. case PINPAD:
  617. {
  618. activeModeSecName = "CardReaderNormal";
  619. devicePort = 3;
  620. break;
  621. }
  622. case HEADLIGHT:
  623. {
  624. activeModeSecName = "LightNormal";
  625. devicePort = 4;
  626. m_headlightDevPort = devicePort;
  627. break;
  628. }
  629. case HEADLIGHT_RED:
  630. {
  631. activeModeSecName = "RedLightNormal";
  632. devicePort = 5;
  633. break;
  634. }
  635. case CONTACTLESSCARD:
  636. {
  637. activeModeSecName = "CardReaderNormal";
  638. devicePort = 8;
  639. break;
  640. }
  641. case HEADLIGHT_ASSIST:
  642. {
  643. activeModeSecName = "AssistNormal";
  644. devicePort = 4;
  645. break;
  646. }
  647. case HSPSCANNER:
  648. {
  649. activeModeSecName = "LightNormal";
  650. devicePort = 12;
  651. break;
  652. }
  653. break;
  654. default:
  655. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("unsupport device seq: %d", deviceSeq);
  656. return;
  657. }
  658. OutDrivingInfo odi;
  659. GetOutDrivingModInfo(activeModeSecName, odi);
  660. SetOutDriving(req, odi, 0, devicePort);
  661. }
  662. //仅仅获取挂机的状态,但远远没有这么简单,这点只调用了一次,开了一个监听线程,用于监听震动、开关门等事件
  663. void CGpioEntity::GetStatus(int deviceSeq, SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx)
  664. {
  665. /** 注意设备序号是实体内定义的逻辑,不是设备端口号,用作于计时器的ID去了*/
  666. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetStatus with devseq %d", deviceSeq);
  667. if (deviceSeq == PHONEPICKUP) {
  668. if (!m_bFuncVer2) {
  669. CSimpleStringA initDriver = "";
  670. int devicePort;
  671. /** 获取指定的模式,以便后续获取输入模式和持续触发模式,见 GetReceivingModInfo*/
  672. initDriver = "PhoneNormal";
  673. /** 获取硬件规格里对应的序号,其实是固定死的*/
  674. devicePort = 18;
  675. ReceivingInfo ri;
  676. GetReceivingModInfo(initDriver, ri);
  677. ri.Port = devicePort;
  678. GetReceiving(deviceSeq, ri, PICKUPSENSOR);
  679. }
  680. }
  681. }
  682. void CGpioEntity::OnOutputPositiveLevelTimerout(void* pData)
  683. {
  684. SetContextInfo* pSCI = (SetContextInfo*)pData;
  685. GetFunction()->KillTimer(pSCI->timerID);
  686. DevOutputInfo doi = GetCurrDevStatus();
  687. WritePin(pSCI->pinSeq, true);
  688. delete pSCI;
  689. SaveCurrDevStatus(doi);
  690. }
  691. void CGpioEntity::OnPositiveFlickerSetTimerout(void* pData)
  692. {
  693. SetContextInfo* pSCI = (SetContextInfo*)pData;
  694. GetFunction()->KillTimer(pSCI->timerID);
  695. DevOutputInfo doi = GetCurrDevStatus();
  696. WritePin(pSCI->pinSeq, false);
  697. pSCI->timerID = pSCI->timerID;
  698. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerResetTimerout, pSCI, true);
  699. GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->resetTime);
  700. }
  701. void CGpioEntity::OnPositiveFlickerResetTimerout(void* pData)
  702. {
  703. SetContextInfo* pSCI = (SetContextInfo*)pData;
  704. GetFunction()->KillTimer(pSCI->timerID);
  705. DevOutputInfo doi = GetCurrDevStatus();
  706. WritePin(pSCI->pinSeq, true);
  707. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSCI, true);
  708. GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->setTime);
  709. }
  710. //老接口,用于控制灯
  711. bool CGpioEntity::SetOutDriving(GpioService_Set_Info req, OutDrivingInfo od, ULONG iIndex, ULONG pinSeq)
  712. {
  713. DevOutputInfo doi = GetCurrDevStatus();
  714. if (req.close == 1) {
  715. GetFunction()->KillTimer(req.devseq);
  716. //oilyang add 20161222
  717. //如果关闭照明灯,以感知为准
  718. if (pinSeq == m_headlightDevPort)
  719. WritePin(pinSeq, m_bHeadLightFlag); //这个值有待商榷
  720. else {
  721. if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
  722. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("off hspsanner.");
  723. WritePin(PIN_HSPSCANNER_LIGHT, false);
  724. }
  725. WritePin(pinSeq, false);
  726. }
  727. return true;
  728. }
  729. switch (od.OutputMode) {
  730. case OM_POSITIVE_LEVEL:
  731. {
  732. switch (od.StopMode) {
  733. case SM_CALLTRIGGER:
  734. {
  735. LOG_TRACE("0.0 mode:output[%u], pinSeq=%u", doi.output, pinSeq);
  736. //if it is hspsanner
  737. if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
  738. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("light hspsanner.");
  739. WritePin(PIN_HSPSCANNER_LIGHT, true);
  740. }
  741. WritePin(pinSeq, true);
  742. break;
  743. }
  744. case SM_TIMEOUT:
  745. {
  746. WritePin(pinSeq, true);
  747. SetContextInfo* pSci = new SetContextInfo();;
  748. pSci->ctx = NULL;
  749. pSci->timerID = req.devseq;
  750. pSci->timeout = od.TimeOut;
  751. pSci->index = iIndex;
  752. pSci->pinSeq = pinSeq;
  753. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnOutputPositiveLevelTimerout, pSci);
  754. GetFunction()->SetTimer(pSci->timerID, pListener, od.TimeOut);
  755. break;
  756. }
  757. case SM_CYCLE:
  758. break;
  759. default:
  760. break;
  761. }
  762. }
  763. break;
  764. case OM_POSITIVE_FLICKER:
  765. switch (od.StopMode) {
  766. case SM_CALLTRIGGER:
  767. break;
  768. case SM_TIMEOUT:
  769. break;
  770. case SM_CYCLE:
  771. {
  772. SetContextInfo* pSci = new SetContextInfo();
  773. pSci->ctx = NULL;
  774. pSci->index = iIndex;
  775. pSci->pinSeq = pinSeq;
  776. pSci->timerID = req.devseq;
  777. pSci->setTime = od.SetTime;
  778. pSci->resetTime = od.ResetTime;
  779. pSci->timeout = od.TimeOut;
  780. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSci, true);
  781. WritePin(pinSeq, true);
  782. GetFunction()->SetTimer(pSci->timerID, pListener, pSci->setTime);
  783. break;
  784. }
  785. default:
  786. break;
  787. }
  788. break;
  789. case OM_NEGATIVE_FLICKER:
  790. switch (od.StopMode) {
  791. case SM_CALLTRIGGER:
  792. break;
  793. case SM_TIMEOUT:
  794. break;
  795. case SM_CYCLE:
  796. break;
  797. default:
  798. break;
  799. }
  800. break;
  801. default:
  802. break;
  803. }
  804. return true;
  805. }
  806. /** 太复杂了,先掺在一起再改动吧 [Gifur@2023921]*/
  807. void CGpioEntity::OnPositiveLevelTimerOut(void* pData)
  808. {
  809. GetContextInfo* pGci = (GetContextInfo*)pData;
  810. const int initCtt = pGci->InitCTT;
  811. const int pos = pGci->Port;
  812. ULONG input = 0;
  813. BYTE btInput;
  814. bool bShakeOne, bMoveOne, bSwitchOne, bPhoneOne, bCardOne;
  815. bShakeOne = bMoveOne = bSwitchOne = bPhoneOne = bCardOne = false;
  816. ErrorCodeEnum err(Error_Succeed);
  817. if (!m_bFuncVer2) {
  818. err = m_hDevHelper->ReadPort(INPUT_PORT_2, btInput);
  819. } else {
  820. DWORD dwReq(GPIO_DEV_SN_LIGHT_SENSOR_ALL);
  821. DWORD dwMode = 0;
  822. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to DetectStatus 0x%X...", dwReq);
  823. err = m_hDevHelper->DetectStatus(dwReq, dwMode);
  824. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DetectStatus return %s, 0x%X", SpStrError(err), dwMode);
  825. btInput = dwMode;
  826. }
  827. if (err != Error_Succeed) {
  828. DevErrorInfo devErrInfo;
  829. ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
  830. ErrorCodeEnum erroCode = m_hDevHelper->GetLastErr(devErrInfo);
  831. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s failed: %s, ErrMsg[%s]", m_bFuncVer2 ? "DetectStatus": "ReadPort", SpStrError(err), (LPCTSTR)devErrInfo.szErrMsg);
  832. return;
  833. }
  834. /** 震动感应 */
  835. if (pGci->CttShake == 1) {
  836. bShakeOne = true;
  837. do {
  838. /** 待商榷,这里永远不可能为1 [Gifur@2023921]*/
  839. if (initCtt == 1) {
  840. if (DetectBit(btInput, VIBRATIONSENSOR)) {
  841. if (!m_bVibrationFlag && (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)) {
  842. LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(17), __LINE__));
  843. }
  844. m_bVibrationFlag = true;
  845. } else
  846. m_bVibrationFlag = false;
  847. break;
  848. }
  849. if (m_bVibrationRound) {
  850. if (DetectBit(btInput, VIBRATIONSENSOR) && !m_bVibrationFlag) {
  851. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  852. LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(17), __LINE__));
  853. m_bVibrationFlag = true;
  854. m_bVibrationRound = false;
  855. }
  856. } else if (!DetectBit(btInput, VIBRATIONSENSOR) && m_bVibrationFlag) {
  857. m_bVibrationFlag = false;
  858. m_bVibrationRound = true;
  859. }
  860. } while (0);
  861. pGci->CttShake = pGci->InitCTT;
  862. }
  863. /** 机箱门开关检测*/
  864. if (pGci->CttSwitch == 1) {
  865. bSwitchOne = true;
  866. do {
  867. if (initCtt == 1) {
  868. if (DetectBit(btInput, OPENSENSOR)) {
  869. if (!m_bOpenFlag) {
  870. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  871. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(18), __LINE__));
  872. m_bOpenFlag = true;
  873. }
  874. } else if (m_bOpenFlag) {
  875. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  876. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(18), __LINE__));
  877. m_bOpenFlag = false;
  878. }
  879. break;
  880. }
  881. if (m_bOpenRound) {
  882. if (DetectBit(btInput, OPENSENSOR) && !m_bOpenFlag) {
  883. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  884. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(18), __LINE__));
  885. m_bOpenFlag = true;
  886. m_bOpenRound = false;
  887. }
  888. } else if (!DetectBit(btInput, OPENSENSOR) && m_bOpenFlag) {
  889. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  890. LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(18), __LINE__));
  891. m_bOpenFlag = false;
  892. m_bOpenRound = true;
  893. }
  894. } while (0);
  895. pGci->CttSwitch = pGci->InitCTT;
  896. }
  897. /**话机检测*/
  898. if (pGci->CttPhone == 1) {
  899. bPhoneOne = true;
  900. do {
  901. if (initCtt == 1) {
  902. if (m_ePickUpFlag == Unknown) {
  903. if (DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = Actived;
  904. else if (!DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = InActive;
  905. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set initial value: %d", (int)m_ePickUpFlag);
  906. } else {
  907. if (DetectBit(btInput, PICKUPSENSOR)) {
  908. if (m_ePickUpFlag == InActive) {
  909. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  910. LogEvent(Severity_Middle, LOG_EVT_PICKUP, "话机提起");
  911. m_ePickUpFlag = Actived;
  912. }
  913. } else if (m_ePickUpFlag == Actived) {
  914. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  915. LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "话机放下");
  916. m_ePickUpFlag = InActive;
  917. }
  918. }
  919. break;
  920. }
  921. if (m_bPickUpRound) {
  922. if (DetectBit(btInput, PICKUPSENSOR)) {
  923. if (m_ePickUpFlag == InActive) {
  924. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  925. LogEvent(Severity_Middle, LOG_EVT_PICKUP, "话机提起");
  926. m_ePickUpFlag = Actived;
  927. m_bPickUpRound = false;
  928. } else if (m_ePickUpFlag == Unknown) {
  929. m_ePickUpFlag = Actived;
  930. }
  931. }
  932. } else if (!DetectBit(btInput, PICKUPSENSOR)) {
  933. if (m_ePickUpFlag == Actived) {
  934. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  935. LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "话机放下");
  936. m_ePickUpFlag = InActive;
  937. m_bPickUpRound = true;
  938. } else if (m_ePickUpFlag == Unknown) {
  939. m_ePickUpFlag = InActive;
  940. }
  941. }
  942. } while (0);
  943. pGci->CttPhone = pGci->InitCTT;
  944. }
  945. /*物体靠近感知检测*/
  946. if (pGci->CttMove == 1) {
  947. bMoveOne = true;
  948. do {
  949. if (initCtt == 1) {
  950. if (DetectBit(btInput, MOVESENSOR)) {
  951. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  952. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(20), __LINE__));
  953. }
  954. break;
  955. }
  956. if (m_bMoveRound) {
  957. if (DetectBit(btInput, MOVESENSOR)) {
  958. m_moveDisappearTimes = 0;
  959. if (m_moveHoldTimes < MAX_MOVE_HOLD_TIMES) { // 100ms * 5000
  960. if ((m_moveHoldTimes % LOG_TIME_VALUE) == 0) { //100ms * 25 = 2.5s 但因为厂家接口调用,不进来计数,需要800ms+
  961. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  962. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(20), __LINE__));
  963. }
  964. } else if ((m_moveHoldTimes % MAX_MOVE_HOLD_TIMES) == 0) { //难道8分钟一直有人就异常?还有一个 Round 标识
  965. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  966. LogWarn(Severity_Middle, Error_Unexpect, LOG_EVT_MOVEDETECT_ABNORMAL, "移动次数异常");
  967. }
  968. m_moveHoldTimes++;
  969. m_bMoveRound = false;
  970. }
  971. } else if (!DetectBit(btInput, MOVESENSOR)) {
  972. m_moveHoldTimes = 0;
  973. if ((m_moveDisappearTimes % LOG_TIME_VALUE) == 0) {
  974. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  975. LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(20), __LINE__));
  976. }
  977. m_moveDisappearTimes++;
  978. m_bMoveRound = true;
  979. }
  980. } while (0);
  981. pGci->CttMove = pGci->InitCTT;
  982. }
  983. /*卡嘴异物检测*/
  984. if (pGci->CttCard == 1) {
  985. bCardOne = true;
  986. do {
  987. if (initCtt == 1) {
  988. if (DetectBit(btInput, CARDGATESENSOR)) {
  989. if (!m_bCardGateFlag) {
  990. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  991. LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(21), __LINE__));
  992. m_bCardGateFlag = true;
  993. }
  994. } else
  995. m_bCardGateFlag = false;
  996. break;
  997. }
  998. if (m_bCardGateRound) {
  999. if (DetectBit(btInput, CARDGATESENSOR) && !m_bCardGateFlag) {
  1000. if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus)
  1001. LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(21), __LINE__));
  1002. m_bCardGateFlag = true;
  1003. m_bCardGateRound = false;
  1004. }
  1005. } else if (!DetectBit(btInput, CARDGATESENSOR) && m_bCardGateFlag) {
  1006. m_bCardGateFlag = false;
  1007. m_bCardGateRound = true;
  1008. }
  1009. } while (0);
  1010. pGci->CttCard = pGci->InitCTT;
  1011. }
  1012. /////////////////////////////////////////////////////////////////////////////////////
  1013. if (pGci->CttShake > 1 && !bShakeOne) {
  1014. do {
  1015. if (m_bVibrationRound) {
  1016. if (DetectBit(btInput, VIBRATIONSENSOR))
  1017. pGci->CttShake--;
  1018. else {
  1019. m_bVibrationRound = false;
  1020. pGci->CttShake = pGci->InitCTT;
  1021. }
  1022. } else {
  1023. if (!DetectBit(btInput, VIBRATIONSENSOR))
  1024. pGci->CttShake--;
  1025. else {
  1026. m_bVibrationRound = true;
  1027. pGci->CttShake = pGci->InitCTT;
  1028. }
  1029. }
  1030. } while (0);
  1031. }
  1032. if (pGci->CttSwitch > 1 && !bSwitchOne) {
  1033. do {
  1034. if (m_bOpenRound) {
  1035. if (DetectBit(btInput, OPENSENSOR))
  1036. pGci->CttSwitch--;
  1037. else {
  1038. m_bOpenRound = false;
  1039. pGci->CttSwitch = pGci->InitCTT;
  1040. }
  1041. } else {
  1042. if (!DetectBit(btInput, OPENSENSOR))
  1043. pGci->CttSwitch--;
  1044. else {
  1045. m_bOpenRound = true;
  1046. pGci->CttSwitch = pGci->InitCTT;
  1047. }
  1048. }
  1049. } while (0);
  1050. }
  1051. if (pGci->CttPhone > 1 && !bPhoneOne) {
  1052. do {
  1053. if (m_ePickUpFlag == Unknown) {
  1054. if (DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = Actived;
  1055. else if (!DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = InActive;
  1056. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set initial value: %d", (int)m_ePickUpFlag);
  1057. break;
  1058. }
  1059. if (m_bPickUpRound) { /** 该参数的作用貌似是用于记录当前是否是提机的累计次数中,状态切换时会重置次数 [Gifur@2022527]*/
  1060. if (DetectBit(btInput, PICKUPSENSOR)) {
  1061. pGci->CttPhone--;
  1062. } else {
  1063. m_bPickUpRound = false;
  1064. pGci->CttPhone = pGci->InitCTT;
  1065. }
  1066. } else {
  1067. if (!DetectBit(btInput, PICKUPSENSOR))
  1068. pGci->CttPhone--;
  1069. else {
  1070. m_bPickUpRound = true;
  1071. pGci->CttPhone = pGci->InitCTT;
  1072. }
  1073. }
  1074. } while (0);
  1075. }
  1076. if (pGci->CttMove > 1 && !bMoveOne) {
  1077. do {
  1078. if (m_bMoveRound) {
  1079. if (DetectBit(btInput, MOVESENSOR))
  1080. pGci->CttMove--;
  1081. else {
  1082. m_bMoveRound = false;
  1083. pGci->CttMove = pGci->InitCTT;
  1084. }
  1085. } else {
  1086. if (!DetectBit(btInput, MOVESENSOR))
  1087. pGci->CttMove--;
  1088. else {
  1089. m_bMoveRound = true;
  1090. pGci->CttMove = pGci->InitCTT;
  1091. }
  1092. }
  1093. } while (0);
  1094. }
  1095. if (pGci->CttCard > 1 && !bCardOne) {
  1096. do {
  1097. if (m_bCardGateRound) {
  1098. if (DetectBit(btInput, CARDGATESENSOR))
  1099. pGci->CttCard--;
  1100. else {
  1101. m_bCardGateRound = false;
  1102. pGci->CttCard = pGci->InitCTT;
  1103. }
  1104. } else {
  1105. if (!DetectBit(btInput, CARDGATESENSOR))
  1106. pGci->CttCard--;
  1107. else {
  1108. m_bCardGateRound = true;
  1109. pGci->CttCard = pGci->InitCTT;
  1110. }
  1111. }
  1112. } while (0);
  1113. }
  1114. GetFunction()->ResetTimer(pGci->timerID, 100);
  1115. }
  1116. bool CGpioEntity::GetReceiving(int deviceSeq, ReceivingInfo ri, ULONG iIndex)
  1117. {
  1118. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("inputmode[%d],port[%d],ctt[%d]", ri.InputMode, ri.Port, ri.ContinuousTriggerTime);
  1119. switch (ri.InputMode)
  1120. {
  1121. case IM_POSITIVE_LEVEL:
  1122. { /** 目前只是使用了这一个 [Gifur@2023921]*/
  1123. GetContextInfo* pGci = new GetContextInfo();
  1124. pGci->timerID = deviceSeq;
  1125. pGci->index = iIndex;
  1126. pGci->Port = ri.Port;
  1127. pGci->CttCard = ri.ContinuousTriggerTime;
  1128. pGci->CttMove = ri.ContinuousTriggerTime;
  1129. pGci->CttPhone = ri.ContinuousTriggerTime;
  1130. pGci->CttShake = ri.ContinuousTriggerTime;
  1131. pGci->CttSwitch = ri.ContinuousTriggerTime;
  1132. pGci->InitCTT = ri.ContinuousTriggerTime;
  1133. ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveLevelTimerOut, pGci);
  1134. GetFunction()->SetTimer(pGci->timerID, pListener, 100);
  1135. break;
  1136. }
  1137. default:
  1138. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("not support: %d", ri.InputMode);
  1139. break;
  1140. }
  1141. return true;
  1142. }
  1143. /** 旧接口,从配置中获取闪烁的属性 [Gifur@2023921]*/
  1144. void CGpioEntity::GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi)
  1145. {
  1146. if (modName.Compare("IDCertificateNormal") == 0) {
  1147. odi.OutputMode = OM_POSITIVE_FLICKER;
  1148. odi.StopMode = SM_CYCLE;
  1149. odi.SetTime = 150;
  1150. odi.ResetTime = 150;
  1151. odi.TimeOut = 5000;
  1152. } else if (modName.Compare("FingerPrintNormal") == 0) {
  1153. odi.OutputMode = OM_POSITIVE_FLICKER;
  1154. odi.StopMode = SM_CYCLE;
  1155. odi.SetTime = 150;
  1156. odi.ResetTime = 150;
  1157. odi.TimeOut = 5000;
  1158. } else if (modName.Compare("CardReaderNormal") == 0) {
  1159. odi.OutputMode = OM_POSITIVE_FLICKER;
  1160. odi.StopMode = SM_CYCLE;
  1161. odi.SetTime = 200;
  1162. odi.ResetTime = 200;
  1163. odi.TimeOut = 5000;
  1164. } else if (modName.Compare("AssistNormal") == 0) {
  1165. odi.OutputMode = OM_POSITIVE_FLICKER;
  1166. odi.StopMode = SM_CYCLE;
  1167. odi.SetTime = 1000;
  1168. odi.ResetTime = 500;
  1169. odi.TimeOut = 5000;
  1170. } else if (modName.Compare("LightNormal") == 0) {
  1171. odi.OutputMode = OM_POSITIVE_LEVEL;
  1172. odi.StopMode = SM_CALLTRIGGER;
  1173. odi.SetTime = 1000;
  1174. odi.ResetTime = 1000;
  1175. odi.TimeOut = 5000;
  1176. } else if (modName.Compare("RedLightNormal") == 0) {
  1177. odi.OutputMode = OM_POSITIVE_LEVEL;
  1178. odi.StopMode = SM_CALLTRIGGER;
  1179. odi.SetTime = 200;
  1180. odi.ResetTime = 200;
  1181. odi.TimeOut = 3000;
  1182. } else {
  1183. odi.OutputMode = OM_POSITIVE_LEVEL;
  1184. odi.StopMode = SM_CALLTRIGGER;
  1185. odi.SetTime = 200;
  1186. odi.ResetTime = 200;
  1187. odi.TimeOut = 5000;
  1188. }
  1189. LOG_TRACE("outputmode.stopmode:[%d].[%d]", odi.OutputMode, odi.StopMode);
  1190. }
  1191. /*从配置文件中获取配置*/
  1192. void CGpioEntity::GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri)
  1193. {
  1194. if (modName.Compare("PhoneNormal") == 0) {
  1195. ri.ContinuousTriggerTime = 2;
  1196. } else if (modName.Compare("GpioNormal") == 0) {
  1197. ri.ContinuousTriggerTime = 10;
  1198. } else if (modName.Compare("CardGateNormal") == 0) {
  1199. ri.ContinuousTriggerTime = 10;
  1200. } else if (modName.Compare("ShakeNormal") == 0) {
  1201. ri.ContinuousTriggerTime = 4;
  1202. } else {
  1203. ri.ContinuousTriggerTime = 10;
  1204. }
  1205. ri.InputMode = IM_POSITIVE_LEVEL;
  1206. }
  1207. BYTE CGpioEntity::GetOutputStatus(int sn)
  1208. {
  1209. if (sn == 0)
  1210. return m_btOutputStatus[0];
  1211. else if (sn == 1)
  1212. return m_btOutputStatus[1];
  1213. else if (sn == 2)
  1214. return m_btOutputStatus[2];
  1215. else
  1216. return 0;
  1217. }
  1218. SP_BEGIN_ENTITY_MAP()
  1219. SP_ENTITY(CGpioEntity)
  1220. SP_END_ENTITY_MAP()