mod_gpio.cpp 55 KB

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