mod_gpio.cpp 54 KB

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