mod_gpio.cpp 49 KB

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