| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570 |
- #include "stdafx.h"
- #include "mod_gpio.h"
- #include "publicFunExport.h"
- const int MAX_GPIO_INIT_TRIES = 3;
- const int INPUT_PORT_2 = 2;
- const int MAX_MOVE_HOLD_TIMES = 5000;
- const int LOG_TIME_VALUE = 25;
- int positive_pulse_up_count = 0;
- int negative_pulse_down_count = 0;
- int positive_pulse_both_count = 0;
- int negative_pulse_both_count = 0;
- int positive_level_count = 0;
- int negative_level_count = 0;
- #define SETBIT(x,y) x|=(1<<(y))
- #define CLEARBIT(x,y) x&=((1<<(y))^0xffffff)
- using namespace SP::Module::Comm;
- static const char* GetDriverPortStringZhCN(int pin)
- {
- switch (pin) {
- case 1: return "【驱动】读卡发卡器提示灯";
- case 2: return "【驱动】前端USB通断控制";
- case 3: return "【驱动】身份证阅读器提示灯";
- case 4: return "【驱动】密码键盘提示灯";
- case 5: return "【驱动】脸部照明灯";
- case 6: return "【驱动】故障灯";
- case 7: return "【驱动】读卡发卡器维护提示灯";
- case 8: return "【驱动】前端USB口提示灯";
- case 9: return "【驱动】非接IC读卡器提示灯";
- case 10: return "";
- case 11: return "【驱动】指纹仪提示灯";
- case 12: return "【驱动】凭条打印提示灯";
- case 13: return "【驱动】高拍仪提示灯";
- case 14: return "";
- case 15: return "";
- case 16: return "";
- case 17: return "【接收】震动探测器";
- case 18: return "【接收】机具门感应开关";
- case 19: return "【接收】话机提机感应开关";
- case 20: return "【接收】人体探测感应器";
- case 21: return "【接收】发卡器卡嘴覆盖探测器";
- //case 22: return "";
- //case 23: return "";
- //case 24: return "";
- //case 25: return "";
- case 26: return "【驱动】高拍仪提示灯";
- //case 27: return "";
- //case 28: return "";
- //case 29: return "";
- //case 30: return "";
- //case 31: return "";
- //case 32: return "";
- //case 33: return "";
- //case 34: return "";
- //case 35: return "";
- //case 36: return "";
- //case 37: return "";
- //case 38: return "";
- //case 39: return "";
- //case 40: return "";
- //case 41: return "";
- //case 42: return "";
- default:
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unkown pin sequence: %d", pin);
- return "";
- break;
- }
- }
- static const char* GetDriverPortString(int pin)
- {
- switch (pin) {
- case 1: return "[Driver] CarIssuer Tip Light";
- case 2: return "[Driver] USB Switch";
- case 3: return "[Driver] IDCer Tip Light";
- case 4: return "[Driver] PinPad Tip Light";
- case 5: return "[Driver] Face Light";
- case 6: return "[Driver] Maintain Light";
- case 7: return "[Driver] CardIssuser Mouse Maintain Light";
- case 8: return "[Driver] USB Tip Light";
- case 9: return "[Driver] RF Tip Light";
- case 10: return "";
- case 11: return "[Driver] FingerPrint Tip Light";
- case 12: return "[Driver] Printer Tip Light";
- case 13: return "[Driver] HSPSCanner Tip Light";
- case 14: return "";
- case 15: return "";
- case 16: return "";
- case 17: return "[Receiver] Shake Detecter";
- case 18: return "[Receiver] Door Detecter";
- case 19: return "[Receiver] Phone Detecter";
- case 20: return "[Receiver] Body Detecter";
- case 21: return "[Receiver] CardIssuer Mouse Detecter";
- //case 22: return "";
- //case 23: return "";
- //case 24: return "";
- //case 25: return "";
- case 26: return "[Driver] HSPSCanner Tip Light";
- //case 27: return "";
- //case 28: return "";
- //case 29: return "";
- //case 30: return "";
- //case 31: return "";
- //case 32: return "";
- //case 33: return "";
- //case 34: return "";
- //case 35: return "";
- //case 36: return "";
- //case 37: return "";
- //case 38: return "";
- //case 39: return "";
- //case 40: return "";
- //case 41: return "";
- //case 42: return "";
- default:
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unkown pin sequence: %d", pin);
- return "";
- break;
- }
- }
- #define LIGHT_STRING_CONVERT(str) case str : return #str; break;
- static const char* GetLightSeqString(int seq)
- {
- switch (seq) {
- LIGHT_STRING_CONVERT(UNKNOWN_DEVICE)
- LIGHT_STRING_CONVERT(CARDREADER)
- LIGHT_STRING_CONVERT(CARDREADER_RED)
- LIGHT_STRING_CONVERT(IDCERTIFICATE)
- LIGHT_STRING_CONVERT(PINPAD)
- LIGHT_STRING_CONVERT(SHAKEDETECT)
- LIGHT_STRING_CONVERT(SWITCHINDUCTOR)
- LIGHT_STRING_CONVERT(PHONEPICKUP)
- LIGHT_STRING_CONVERT(MOVEDETECT)
- LIGHT_STRING_CONVERT(CARDGATEDETECT)
- LIGHT_STRING_CONVERT(HEADLIGHT)
- LIGHT_STRING_CONVERT(HEADLIGHT_RED)
- LIGHT_STRING_CONVERT(CONTACTLESSCARD)
- LIGHT_STRING_CONVERT(HEADLIGHT_ASSIST)
- LIGHT_STRING_CONVERT(HSPSCANNER)
- LIGHT_STRING_CONVERT(FINGERPRINT)
- default:
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unkonwn LightSeq: %d", seq);
- return "UnConver One";
- break;
- }
- }
- #undef LIGHT_STRING_CONVERT
- void CGpioServiceSession::Handle_GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req,
- GpioService_GetDevInfo_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- m_pEntity->GetDevInfo(ctx);
- }
- void CGpioServiceSession::Handle_Exit(SpOnewayCallContext<GpioService_Exit_Info>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- m_pEntity->Exit(ctx);
- }
- bool isnostr(const char* str)
- {
- int len = strlen(str);
- if (len == 0)
- return true;
- for (int i = 0; i < len; ++i) {
- if (*(str + i) != ' ')
- return false;
- }
- return true;
- }
- /** 因为GPIO没有状态机的概念,所以抛送信息的代码单独实现,没有跟其他硬件类似使用基类中的公有函数 [Gifur@2023810]*/
- void CGpioEntity::ToLogRootINIInfo()
- {
- CSmartPointer<IConfigInfo> spConfigRoot;
- GetFunction()->OpenConfig(Config_Root, spConfigRoot);
- CSimpleStringA entityName(GetEntityName());
- CSimpleStringA sectionName = CSimpleStringA::Format("Device.%s", entityName.GetData());
- CSimpleStringA csVendor(true), csVersion(true), csBatch(true), csPort(true), csBaudrate(true);
- spConfigRoot->ReadConfigValue(sectionName.GetData(), "Vendor", csVendor);
- spConfigRoot->ReadConfigValue(sectionName.GetData(), "Version", csVersion);
- spConfigRoot->ReadConfigValue(sectionName.GetData(), "Batch", csBatch);
- spConfigRoot->ReadConfigValue(sectionName.GetData(), "Port", csPort);
- spConfigRoot->ReadConfigValue(sectionName.GetData(), "Baudrate", csBaudrate);
- std::map<std::string, std::string> rootInfo;
- CSimpleStringA csPortNum(true), csCheckData(true), csKeySN(true);
- rootInfo["Vendor"] = csVendor;
- rootInfo["Version"] = csVersion;
- rootInfo["Batch"] = csBatch;
- rootInfo["Port"] = csPort;
- rootInfo["Baudrate"] = csBaudrate;
- spConfigRoot->ReadConfigValue(sectionName.GetData(), "PortNum", csPortNum);
- rootInfo["PortNum"] = csPortNum;
- std::pair<bool, std::string> strResult;
- strResult = generateJsonStr(rootInfo);
- if (!entityName.IsNullOrEmpty()) {
- LogWarn(Severity_Low, Error_Debug, GPIO_UserErrorCode_Real_Root_Config, strResult.second.c_str());
- } else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Entity Name is empty, please check!!!");
- }
- return;
- }
- struct GpioInitTask : public ITaskSp {
- CGpioEntity* m_entity;
- CSmartPointer<ITransactionContext> m_pTransactionContext;
- GpioInitTask(CGpioEntity* entity, CSmartPointer<ITransactionContext> pTransactionContext) :m_entity(entity), m_pTransactionContext(pTransactionContext) {}
- void Process()
- {
- m_entity->InitializeVendorLogSwitch();
- ErrorCodeEnum err = m_entity->Initial();
- if (err == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Gpio open succeeded.");
- //oiltest 20130118 for audiodg handle
- m_entity->GetStatus(PHONEPICKUP);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribelog...");
- //oiltmp the subscribelog should distinct machine type?
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidHealth, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "HealthManager");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidIDC, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "IDCertificate");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidFP, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "FingerPrint");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidKB, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "PinPad");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidCR, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "CardIssuerStand");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidCA, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "CustomerAware");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidCC, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "ContactlessCard");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidDD, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "DeviceControl");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidCS, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "CardIssuerStore");
- m_entity->GetFunction()->SubscribeLog(m_entity->m_uuidHSPscanner, m_entity, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "HSPScanner");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sub ok...");
- m_pTransactionContext->SendAnswer(Error_Succeed);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("send Error_Succeed ok...");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("gpio open failed(%d).", err);
- m_pTransactionContext->SendAnswer(Error_Succeed);
- }
- }
- };
- void CGpioEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- GpioInitTask* initTask = new GpioInitTask(this, pTransactionContext);
- GetFunction()->PostThreadPoolTask(initTask);
- }
- void CGpioEntity::ToLogWarnInfoAboutTerm(const AdapterInfo& m_adapterInfo)
- {
- LOG_FUNCTION();
- CSmartPointer<IConfigInfo> spConfigRoot;
- GetFunction()->OpenConfig(Config_Root, spConfigRoot);
- CSimpleStringA csEnvCamera(""), csOptCamera, csOSVerion, csWarnMsg("");
- //calculate file hash value
- std::map<std::string, std::string> termInfo;
- char* strFileHash = new char[128];
- ZeroMemory(strFileHash, 128);
- BYTE fileHash[32];
- SM3File(const_cast<char*>(m_adapterInfo.adapterFileName.GetData()), fileHash);
- SP::Module::Util::HexBuf2StrBuf(fileHash, &strFileHash, 32);
- //calculate file size
- #if defined(RVC_OS_LINUX)
- struct stat statbuf;
- ZeroMemory(&statbuf, sizeof(statbuf));
- stat(m_adapterInfo.adapterFilePath.GetData(), &statbuf);
- int fileSize = statbuf.st_size;
- #else
- int fileSize = 0;
- HANDLE hFile;
- hFile = CreateFile(m_adapterInfo.adapterFilePath.GetData(), 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hFile != INVALID_HANDLE_VALUE) {
- fileSize = GetFileSize(hFile, NULL);
- CloseHandle(hFile);
- }
- #endif //RVC_OS_LINUX
- termInfo["VendorDllName"] = m_adapterInfo.adapterFileName;
- termInfo["VendorDllFileHash"] = strFileHash;
- ZeroMemory(strFileHash, 128);
- termInfo["VendorDllFileSize"] = _itoa(fileSize, strFileHash, 10);
- termInfo["szModel"] = m_adapterInfo.devCatInfo.szModel;
- termInfo["szType"] = m_adapterInfo.devCatInfo.szType;
- termInfo["Port"] = m_port;
- termInfo["PortNum"] = m_portNum;
- termInfo["Baudrate"] = m_Baudrate;
- if (strFileHash != nullptr) {
- delete[] strFileHash;
- strFileHash = nullptr;
- }
- std::pair<bool, std::string> strResult;
- strResult = generateJsonStr(termInfo);
- LogWarn(Severity_Low, Error_Unexpect, GPIO_UserErrorCode_LogInfoAboutTerm, strResult.second.c_str());
- return;
- }
- bool CGpioEntity::DetectBit(ULONG data, int pos)
- {
- if (!m_bFuncVer2) {
- ULONG tmp = 0;
- SETBIT(tmp, pos);
- return (data & tmp);
- }
- else {
- #if defined(RVC_OS_LINUX)
- if (m_hDevHelper != nullptr) {
- DWORD dwReq = (GPIO_DEV_SN_SENSOR_SHAKE << pos);
- return (data & dwReq);
- }
- #endif //RVC_OS_LINUX
- }
- return 0;
- }
- ErrorCodeEnum CGpioEntity::Initial()
- {
- ErrorCodeEnum err;
- LOG_FUNCTION();
- ErrorCodeEnum eErrDev;
- CSimpleStringA dllName;
- eErrDev = ExtractVendorLibFullPath(dllName);
- if (eErrDev != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("load vendor dll or so(%s)(%s) failed.", dllName.GetData(), SpStrError(eErrDev));
- m_bOpening = false;
- return Error_DevLoadFileFailed;
- }
- LogWarn(Severity_Low, Error_Unexpect, GPIO_UserErrorCode_RootInfo, dllName.GetData());
- CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- eErrDev = spEntityFunction->OpenConfig(Config_Root, spConfig);
- if (eErrDev != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open cfg file failed %s", SpStrError(eErrDev));
- m_bOpening = false;
- return eErrDev;
- }
- CSimpleStringA devVendor, devVer, devBatch, dllSuffix;
- devVendor = devVer = devBatch = "";
- spConfig->ReadConfigValue("Device.Gpio", "Vendor", devVendor);
- spConfig->ReadConfigValue("Device.Gpio", "Version", devVer);
- spConfig->ReadConfigValue("Device.Gpio", "Batch", devBatch);
- #if defined(RVC_OS_WIN)
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%s],[%s],[%s]", devVendor.GetData(), devVer.GetData(), devBatch.GetData());
- if (!_stricmp(devVendor, "Hyosung") || !_stricmp(devVendor, "Keba") || !_stricmp(devVendor, "Kxd")) {
- if (devVer == "1" && devBatch == "1") {
- m_bNewVersion = FALSE;
- } else {
- m_bNewVersion = TRUE;
- }
- } else {
- m_bNewVersion = TRUE;
- }
- #else
- m_bNewVersion = TRUE;
- #endif
- eErrDev = m_hDevHelper.LoadUp(dllName);
- if (eErrDev != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("load up %s failed: %s", dllName.GetData(), SpStrError(eErrDev));
- m_bOpening = false;
- return Error_DevLoadFileFailed;
- }
- m_adapterInfo.adapterFilePath = dllName;
- int initTries = 0;
- do {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to open device.");
- int portNum, port, baudRate;
- err = spConfig->ReadConfigValueInt("Device.Gpio", "PortNum", portNum);
- if (err == Error_Succeed)
- m_dwPortNum = portNum;
- else {
- m_bOpening = false;
- return Error_IO;
- }
- spConfig->ReadConfigValueInt("Device.Gpio", "Port", port);
- spConfig->ReadConfigValueInt("Device.Gpio", "BaudRate", baudRate);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read cfg suc, port(%d), baudrate(%d).", port, baudRate);
- m_port = CSimpleStringA::Format("%d", port);
- m_Baudrate = CSimpleStringA::Format("%d", baudRate);
- m_portNum = CSimpleStringA::Format("%d", portNum);
- GpioInitParam initParam;
- if (!m_bNewVersion) {
- initParam.dwPortNum = 3;
- initParam.dir[0] = true;
- initParam.dir[1] = true;
- initParam.dir[2] = false;
- } else {
- initParam.dwPortNum = 4;
- initParam.dir[0] = true;
- initParam.dir[1] = true;
- initParam.dir[2] = false;
- initParam.dir[3] = true;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("New available 4 port num");
- }
- CSimpleStringA errMsg("");
- initParam.dwPort = port;
- initParam.dwBaudRate = baudRate;
- err = m_hDevHelper->DevOpen(initParam);
- if (err == Error_Succeed) {
- ToLogRootINIInfo();
- ZeroMemory(m_devCatInfo.szModel, sizeof(m_devCatInfo.szModel));
- ZeroMemory(m_devCatInfo.szType, sizeof(m_devCatInfo.szType));
- ZeroMemory(m_devCatInfo.szVendor, sizeof(m_devCatInfo.szVendor));
- err = m_hDevHelper->GetDevCategory(m_devCatInfo);
- if (err == Error_Succeed) {
- m_adapterInfo.FulfillCategoryInfo(m_devCatInfo);
- #if defined(RVC_OS_LINUX)
- CSimpleStringA strType(m_devCatInfo.szType);
- if (strType.IndexOf("FUNCVER=2.0") != -1) {
- m_bFuncVer2 = TRUE;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Detect new interface version: %s", strType.GetData());
- }
- #endif //RVC_OS_LINUX
- ToLogWarnInfoAboutTerm(m_adapterInfo);
- } else {
- DevErrorInfo devErrInfo;
- ZeroMemory(&devErrInfo, sizeof(devErrInfo));
- m_hDevHelper->GetLastErr(devErrInfo);
- errMsg = CSimpleStringA::Format("GetDevCategory failed:%s(s)", SpStrError(err), devErrInfo.szErrMsg);
- LogWarn(Severity_Middle, Error_Unexpect, GPIO_UserErrorCode_GetDevCategory_Failed, errMsg.GetData());
- }
- initTries = 0;
- m_bOpened = true;
- break;
- } else {
- DevErrorInfo devErrInfo;
- ZeroMemory(&devErrInfo, sizeof(devErrInfo));
- m_hDevHelper->GetLastErr(devErrInfo);
- errMsg = CSimpleStringA::Format("DevOpen failed:%s(%s)", SpStrError(err), devErrInfo.szErrMsg);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2901")(errMsg.GetData());
- LogWarn(Severity_Middle, Error_Unexpect, GPIO_UserErrorCode_DevOpen_Failed, errMsg.GetData());
- Sleep(300);
- initTries++;
- continue;
- }
- } while (initTries < MAX_GPIO_INIT_TRIES);
- m_bOpening = false;
- if (!m_bOpened) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open gpio failed.");
- err = Error_DevConnFailed;
- }
- else {
- if (!m_bFuncVer2) {
- eErrDev = m_hDevHelper->WritePort(0, 0x00);
- if (eErrDev != Error_Succeed)
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("write ports(0) returned: %s)", SpStrError(eErrDev));
- eErrDev = m_hDevHelper->WritePort(1, 0x00);
- if (eErrDev != Error_Succeed)
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("write ports(1) returned: %s)", SpStrError(eErrDev));
- if (m_bNewVersion) {
- eErrDev = m_hDevHelper->WritePort(3, 0x00);
- if (eErrDev != Error_Succeed)
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("write ports(3) returned: %s)", SpStrError(eErrDev));
- }
- }
- else {
- #if defined(RVC_OS_LINUX)
- eErrDev = m_hDevHelper->SetStatus(GPIO_DEV_SN_LIGHT_SENSOR_ALL, GPIO_DEV_LIGHT_MODE_RESET);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("write resetone returned: %s)", SpStrError(eErrDev));
- #endif //RVC_OS_LINUX
- }
- }
-
- //oilyang@20170214
- eErrDev = Error_Unexpect;
- CSmartPointer<IConfigInfo> spConfigRun;
- eErrDev = spEntityFunction->OpenConfig(Config_Run, spConfigRun);
- if (eErrDev == Error_Succeed) {
- int iMoveHoldTimes = 0;
- spConfigRun->ReadConfigValueInt("Init", "MaxMoveHoldTimes", iMoveHoldTimes);
- if (iMoveHoldTimes == 0) {
- spConfigRun->WriteConfigValueInt("Init", "MaxMoveHoldTimes", MAX_MOVE_HOLD_TIMES);
- m_moveHoldTimes = MAX_MOVE_HOLD_TIMES;
- }
- } else {
- m_moveHoldTimes = MAX_MOVE_HOLD_TIMES;//oiltmp about 5000*300ms = 25 minutes
- }
- m_moveDisappearTimes = m_moveHoldTimes;
- m_eMachineType = SP::Module::Comm::GetTerminalMachineInfo(this).type;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("machine type: %s", SP::Module::Comm::Type2Str(m_eMachineType));
- return err;
- }
- void CGpioEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD>& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("usercode [%x]", dwUserCode);
- GpioService_Set_Info Req;
- Req.close = 0;
- switch (dwUserCode) {
- case LOG_EVT_CARDISSUER_GREEN_ON:
- case LOG_EVT_CARDISSUER_STORE_GREEN_ON:
- Req.devseq = CARDREADER;
- Req.mode = 1;
- break;
- case LOG_EVT_CARDISSUER_RED_ON:
- Req.devseq = CARDREADER_RED;
- Req.mode = 1;
- break;
- case LOG_EVT_IDCERTIFICATE_GREEN_ON:
- Req.devseq = IDCERTIFICATE;
- Req.mode = 1;
- break;
- case LOG_EVT_FINGERPRINT_GREEN_ON:
- Req.devseq = FINGERPRINT;
- Req.mode = 1;
- break;
- case LOG_EVT_PINPAD_GREEN_ON:
- Req.devseq = PINPAD;
- Req.mode = 1;
- break;
- case LOG_EVT_HEADLIGHT_GREEN_ON:
- m_bHeadLightFlag = true;
- Req.devseq = HEADLIGHT;
- Req.mode = 0;
- LOG_TRACE("machine light on");
- break;
- case LOG_EVT_HEADLIGHT_RED_ON:
- Req.devseq = HEADLIGHT_RED;
- Req.mode = 1;
- break;
- case LOG_EVT_CONTACTLESS_CARD_GREEN_ON:
- Req.devseq = CONTACTLESSCARD;
- Req.mode = 1;
- break;
- case LOG_EVT_IEBROWSER_LIGHT_ASSISTANT_ON:
- Req.devseq = HEADLIGHT_ASSIST;
- Req.mode = 1;
- break;
- case LOG_EVT_CARDISSUER_GREEN_OFF:
- case LOG_EVT_CARDISSUER_STORE_GREEN_OFF:
- Req.devseq = CARDREADER;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_CARDISSUER_RED_OFF:
- Req.devseq = CARDREADER_RED;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_IDCERTIFICATE_GREEN_OFF:
- Req.devseq = IDCERTIFICATE;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_FINGERPRINT_GREEN_OFF:
- Req.devseq = FINGERPRINT;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_PINPAD_GREEN_OFF:
- Req.devseq = PINPAD;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_HEADLIGHT_GREEN_OFF:
- m_bHeadLightFlag = false;
- Req.devseq = HEADLIGHT;
- Req.mode = 1;
- Req.close = 1;
- LOG_TRACE("machine light off");
- break;
- case LOG_EVT_HEADLIGHT_RED_OFF:
- Req.devseq = HEADLIGHT_RED;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_CONTACTLESS_CARD_GREEN_OFF:
- Req.devseq = CONTACTLESSCARD;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_IEBROWSER_LIGHT_ASSISTANT_OFF:
- Req.devseq = HEADLIGHT_ASSIST;
- Req.mode = 1;
- Req.close = 1;
- break;
- case LOG_EVT_HSPS_LIGHT_ON:
- Req.devseq = HSPSCANNER;
- Req.mode = 1;
- LOG_TRACE("hspscanner light on");
- break;
- case LOG_EVT_HSPS_LIGHT_OFF:
- Req.devseq = HSPSCANNER;
- Req.mode = 1;
- Req.close = 1;
- LOG_TRACE("hspscanner light off");
- break;
- default:
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("unkown event: 0x%X", dwUserCode);
- return;
- }
- if (m_bOpened) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("devseq[%d],mode[%d]close[%d]", Req.devseq, Req.mode, Req.close);
- m_bFuncVer2 ? SetEx(Req) : Set(Req);
- }
- else {
- 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);
- }
- }
- void CGpioEntity::WritePin(DWORD dwPinSeq, bool bHighLevel)
- {
- ErrorCodeEnum result(Error_Succeed);
- LOG_TRACE("Write Pin %s with %s !", GetDriverPortString(dwPinSeq + 1), bHighLevel ? "[Active]" : "[Inactive]");
- if (dwPinSeq > 16) {
- if (!m_bNewVersion && dwPinSeq < 24) {
- return;
- }
- if (bHighLevel)
- SETBIT(m_btOutputStatus[3], dwPinSeq - 24);
- else
- CLEARBIT(m_btOutputStatus[3], dwPinSeq - 24);
- result = m_hDevHelper->WritePort(3, m_btOutputStatus[3]);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after write port3, %d returned %s", m_btOutputStatus[3], SpStrError(result));
- return;
- }
- if (dwPinSeq < 8) {
- if (bHighLevel)
- SETBIT(m_btOutputStatus[0], dwPinSeq);
- else
- CLEARBIT(m_btOutputStatus[0], dwPinSeq);
- result = m_hDevHelper->WritePort(0, m_btOutputStatus[0]);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after write port0,%d returned %s", m_btOutputStatus[0], SpStrError(result));
- } else {
- if (bHighLevel)
- SETBIT(m_btOutputStatus[1], dwPinSeq - 8);
- else
- CLEARBIT(m_btOutputStatus[1], dwPinSeq - 8);
- DWORD dwStart, dwEnd;
- dwStart = GetTickCount();
- result = m_hDevHelper->WritePort(1, m_btOutputStatus[1]);
- dwEnd = GetTickCount();
- if ((dwEnd - dwStart) > 3000)
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("writepin so long.than 3s(%d)", (dwEnd - dwStart));
- else
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after write port1,%d returned %s", m_btOutputStatus[1], SpStrError(result));
- }
- }
- void CGpioEntity::SetEx(GpioService_Set_Info req)
- {
- #if defined(RVC_OS_LINUX)
- int devicePort;
- LOG_TRACE("SetEx request %s arrived!", GetLightSeqString(req.devseq));
- switch (req.devseq) {
- case CARDREADER:
- {
- devicePort = GPIO_DEV_SN_LIGHT_CARDISSUER;
- break;
- }
- case CARDREADER_RED:
- {
- devicePort = GPIO_DEV_SN_LIGHT_CARDISSUER_MAINTAIN;
- break;
- }
- case IDCERTIFICATE:
- {
- devicePort = GPIO_DEV_SN_LIGHT_IDCERTIFICATE;
- break;
- }
- case FINGERPRINT:
- {
- devicePort = GPIO_DEV_SN_LIGHT_FINGERPRINT;
- break;
- }
- case PINPAD:
- {
- devicePort = GPIO_DEV_SN_LIGHT_PINPAD;
- break;
- }
- case HEADLIGHT:
- {
- devicePort = GPIO_DEV_SN_LIGHT_FACE;
- break;
- }
- case HEADLIGHT_RED:
- {
- devicePort = 6/*GPIO_DEV_SN_LIGHT_MACHINE_FAULT*/;
- break;
- }
- case CONTACTLESSCARD:
- {
- devicePort = GPIO_DEV_SN_LIGHT_CONTACTLESSCARD;
- break;
- }
- case HEADLIGHT_ASSIST:
- {
- devicePort = GPIO_DEV_SN_LIGHT_FACE;
- break;
- }
- break;
- default:
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("unsupport device seq: %d", req.devseq);
- return;
- }
- if (m_hDevHelper != nullptr) {
- DWORD dwReq = devicePort;
- DWORD dwMode = 0;
- if (!req.close) {
- dwMode |= GPIO_DEV_LIGHT_MODE_COLOR_NORMAL;
- if (!!req.mode) {
- dwMode |= GPIO_DEV_LIGHT_MODE_LIGHT_FLICKER;
- } else {
- dwMode |= GPIO_DEV_LIGHT_MODE_LIGHT_SUSTAIN;
- }
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to set SetStatus...%d, 0x%X", dwReq, dwMode);
- const ErrorCodeEnum ec = m_hDevHelper->SetStatus(dwReq, dwMode);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SetStatus returned %s", SpStrError(ec));
- if (ec != Error_Succeed) {
- DevErrorInfo devErrInfo;
- ZeroMemory(&devErrInfo, sizeof(devErrInfo));
- m_hDevHelper->GetLastErr(devErrInfo);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("SetStatus failed:%s(%s)", SpStrError(ec), devErrInfo.szErrMsg);
- }
- } else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("dev helper object is invalid pointer!");
- }
- #endif //RVC_OS_LINUX
- }
- void CGpioEntity::Set(GpioService_Set_Info req)
- {
- CSimpleStringA activeModeSecName = "";
- int devicePort;
- const int deviceSeq = req.devseq;
- LOG_TRACE("Set request %s arrived!", GetLightSeqString(deviceSeq));
- switch (deviceSeq) {
- case CARDREADER:
- {
- activeModeSecName = "CardReaderNormal";
- devicePort = 0;
- break;
- }
- case CARDREADER_RED:
- {
- activeModeSecName = "RedLightNormal";
- devicePort = 6;
- break;
- }
- case IDCERTIFICATE:
- {
- activeModeSecName = "IDCertificateNormal";
- devicePort = 2;
- break;
- }
- case FINGERPRINT:
- {
- activeModeSecName = "FingerPrintNormal";
- devicePort = 10;
- break;
- }
- case PINPAD:
- {
- activeModeSecName = "CardReaderNormal";
- devicePort = 3;
- break;
- }
- case HEADLIGHT:
- {
- activeModeSecName = "LightNormal";
- devicePort = 4;
- m_headlightDevPort = devicePort;
- break;
- }
- case HEADLIGHT_RED:
- {
- activeModeSecName = "RedLightNormal";
- devicePort = 5;
- break;
- }
- case CONTACTLESSCARD:
- {
- activeModeSecName = "CardReaderNormal";
- devicePort = 8;
- break;
- }
- case HEADLIGHT_ASSIST:
- {
- activeModeSecName = "AssistNormal";
- devicePort = 4;
- break;
- }
- case HSPSCANNER:
- {
- activeModeSecName = "LightNormal";
- devicePort = 12;
- break;
- }
- break;
- default:
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("unsupport device seq: %d", deviceSeq);
- return;
- }
- OutDrivingInfo odi;
- GetOutDrivingModInfo(activeModeSecName, odi);
- SetOutDriving(req, odi, 0, devicePort);
- }
- //仅仅获取挂机的状态,但远远没有这么简单,这点只调用了一次,开了一个监听线程,用于监听震动、开关门等事件
- void CGpioEntity::GetStatus(int deviceSeq)
- {
- /** 注意设备序号是实体内定义的逻辑,不是设备端口号,用作于计时器的ID去了*/
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetStatus with devseq %d", deviceSeq);
- if (deviceSeq == PHONEPICKUP) {
- CSimpleStringA initDriver = "";
- int devicePort;
- /** 获取指定的模式,以便后续获取输入模式和持续触发模式,见 GetReceivingModInfo*/
- initDriver = "PhoneNormal";
- /** 获取硬件规格里对应的序号,其实是固定死的*/
- devicePort = 18;
- ReceivingInfo ri;
- GetReceivingModInfo(initDriver, ri);
- ri.Port = devicePort;
- GetReceiving(deviceSeq, ri, PICKUPSENSOR);
- }
- }
- void CGpioEntity::OnOutputPositiveLevelTimerout(void* pData)
- {
- SetContextInfo* pSCI = (SetContextInfo*)pData;
- GetFunction()->KillTimer(pSCI->timerID);
- DevOutputInfo doi = GetCurrDevStatus();
- WritePin(pSCI->pinSeq, true);
- delete pSCI;
- SaveCurrDevStatus(doi);
- }
- void CGpioEntity::OnPositiveFlickerSetTimerout(void* pData)
- {
- SetContextInfo* pSCI = (SetContextInfo*)pData;
- GetFunction()->KillTimer(pSCI->timerID);
- DevOutputInfo doi = GetCurrDevStatus();
- WritePin(pSCI->pinSeq, false);
- pSCI->timerID = pSCI->timerID;
- ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerResetTimerout, pSCI, true);
- GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->resetTime);
- }
- void CGpioEntity::OnPositiveFlickerResetTimerout(void* pData)
- {
- SetContextInfo* pSCI = (SetContextInfo*)pData;
- GetFunction()->KillTimer(pSCI->timerID);
- DevOutputInfo doi = GetCurrDevStatus();
- WritePin(pSCI->pinSeq, true);
- ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSCI, true);
- GetFunction()->SetTimer(pSCI->timerID, pListener, pSCI->setTime);
- }
- void CGpioEntity::OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- if (!m_bOpened && m_hDevHelper) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("let selftest to restart it!");
- pTransactionContext->SendAnswer(Error_InvalidState);
- return;
- }
- else if(!m_bOpened) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("process failed before DevOpen, do not try to restart");
- pTransactionContext->SendAnswer(Error_Succeed);
- return;
- }
- pTransactionContext->SendAnswer(Error_Succeed);
- return;
- }
- void CGpioEntity::GetDevInfo(SpReqAnsContext<GpioService_GetDevInfo_Req, GpioService_GetDevInfo_Ans>::Pointer ctx)
- {
- if (m_bOpening) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(GpioService_LogCode_GetDevInfo).setAPI(__FUNCTION__)("device is opening");
- ctx->Answer(Error_NotInit);
- return;
- }
- if (!m_bOpened) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(GpioService_LogCode_GetDevInfo).setResultCode("RTA2901").setAPI(__FUNCTION__)("GPIO未打开");
- ctx->Answer(Error_DevNotAvailable, GPIO_UserErrorCode_DevOpen_Failed);
- }
- else {
- DevCategoryInfo info = { 0 };
- const ULONGLONG ullStart = SP::Module::Comm::RVCGetTickCount();
- ErrorCodeEnum erroCode = m_hDevHelper->GetDevCategory(info);
- const ULONGLONG ullEnd = SP::Module::Comm::RVCGetTickCount();
- ctx->Ans.state = (int)erroCode;
- if (erroCode == Error_Succeed) {
- ctx->Ans.model = info.szModel;
- ctx->Ans.type = info.szType;
- ctx->Ans.version = CSimpleStringA::Format("%d.%d.%d.%d",
- info.version.wMajor, info.version.wMinor, info.version.wRevision, info.version.wBuild);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(GpioService_LogCode_GetDevInfo)
- .setAPI("DevAdapter::GetDevCategory").setCostTime(ullEnd - ullStart)("model: %s, state:%d, type:%s, version:%s"
- , ctx->Ans.model.GetData(), ctx->Ans.state, ctx->Ans.type.GetData(), ctx->Ans.version.GetData());
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(GpioService_LogCode_GetDevInfo).setAPI("DevAdapter::GetDevCategory")
- .setCostTime(ullEnd - ullStart).setResultCode("RTA2904")("GetDevInfo failed: %s", SpStrError(erroCode));
- }
- ctx->Answer(Error_Succeed);
- }
- }
- //老接口,用于控制灯
- bool CGpioEntity::SetOutDriving(GpioService_Set_Info req, OutDrivingInfo od, ULONG iIndex, ULONG pinSeq)
- {
- DevOutputInfo doi = GetCurrDevStatus();
- if (req.close == 1) {
- GetFunction()->KillTimer(req.devseq);
- //oilyang add 20161222
- //如果关闭照明灯,以感知为准
- if (pinSeq == m_headlightDevPort)
- WritePin(pinSeq, m_bHeadLightFlag); //这个值有待商榷
- else {
- if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("off hspsanner.");
- WritePin(PIN_HSPSCANNER_LIGHT, false);
- }
- WritePin(pinSeq, false);
- }
- return true;
- }
- switch (od.OutputMode) {
- case OM_POSITIVE_LEVEL:
- {
- switch (od.StopMode) {
- case SM_CALLTRIGGER:
- {
- LOG_TRACE("0.0 mode:output[%u], pinSeq=%u", doi.output, pinSeq);
- //if it is hspsanner
- if (pinSeq == PIN_HSPSCANNER_PREVIEW_LIGHT) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("light hspsanner.");
- WritePin(PIN_HSPSCANNER_LIGHT, true);
- }
- WritePin(pinSeq, true);
- break;
- }
- case SM_TIMEOUT:
- {
- WritePin(pinSeq, true);
- SetContextInfo* pSci = new SetContextInfo();;
- pSci->timerID = req.devseq;
- pSci->timeout = od.TimeOut;
- pSci->index = iIndex;
- pSci->pinSeq = pinSeq;
- ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnOutputPositiveLevelTimerout, pSci);
- GetFunction()->SetTimer(pSci->timerID, pListener, od.TimeOut);
- break;
- }
- case SM_CYCLE:
- break;
- default:
- break;
- }
- }
- break;
- case OM_POSITIVE_FLICKER:
- switch (od.StopMode) {
- case SM_CALLTRIGGER:
- break;
- case SM_TIMEOUT:
- break;
- case SM_CYCLE:
- {
- SetContextInfo* pSci = new SetContextInfo();
- pSci->index = iIndex;
- pSci->pinSeq = pinSeq;
- pSci->timerID = req.devseq;
- pSci->setTime = od.SetTime;
- pSci->resetTime = od.ResetTime;
- pSci->timeout = od.TimeOut;
- ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveFlickerSetTimerout, pSci, true);
- WritePin(pinSeq, true);
- GetFunction()->SetTimer(pSci->timerID, pListener, pSci->setTime);
- break;
- }
- default:
- break;
- }
- break;
- case OM_NEGATIVE_FLICKER:
- switch (od.StopMode) {
- case SM_CALLTRIGGER:
- break;
- case SM_TIMEOUT:
- break;
- case SM_CYCLE:
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- return true;
- }
- /** 太复杂了,先掺在一起再改动吧 [Gifur@2023921]*/
- void CGpioEntity::OnPositiveLevelTimerOut(void* pData)
- {
- GetContextInfo* pGci = (GetContextInfo*)pData;
- const int initCtt = pGci->InitCTT;
- const int pos = pGci->Port;
-
- ULONG input = 0;
- BYTE btInput;
- bool bShakeOne, bMoveOne, bSwitchOne, bPhoneOne, bCardOne;
- bShakeOne = bMoveOne = bSwitchOne = bPhoneOne = bCardOne = false;
- ErrorCodeEnum err(Error_Succeed);
- if (!m_bFuncVer2) {
- err = m_hDevHelper->ReadPort(INPUT_PORT_2, btInput);
- } else {
- #if defined(RVC_OS_LINUX)
- DWORD dwReq(GPIO_DEV_SN_LIGHT_SENSOR_ALL);
- DWORD dwMode = 0;
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to DetectStatus 0x%X...", dwReq);
- err = m_hDevHelper->DetectStatus(dwReq, dwMode);
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DetectStatus return %s, 0x%X", SpStrError(err), dwMode);
- btInput = dwMode;
- #else
- err = Error_NotSupport;
- #endif //RVC_OS_LINUX
- }
- if (err != Error_Succeed) {
- DevErrorInfo devErrInfo;
- ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
- ErrorCodeEnum erroCode = m_hDevHelper->GetLastErr(devErrInfo);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s failed: %s, ErrMsg[%s]", m_bFuncVer2 ? "DetectStatus": "ReadPort", SpStrError(err), (LPCTSTR)devErrInfo.szErrMsg);
- return;
- }
- /** 震动感应 */
- if (pGci->CttShake == 1) {
-
- bShakeOne = true;
- do {
- /** 待商榷,这里永远不可能为1 [Gifur@2023921]*/
- if (initCtt == 1) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("test initCtt == 1");
- if (DetectBit(btInput, VIBRATIONSENSOR)) {
- if (!m_bVibrationFlag && IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(17), __LINE__));
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s [Active]", GetDriverPortString(17));
- }
- m_bVibrationFlag = true;
- } else
- m_bVibrationFlag = false;
- break;
- }
- if (m_bVibrationRound) {
- if (DetectBit(btInput, VIBRATIONSENSOR) && !m_bVibrationFlag) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_VIBRATIONSENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(17), __LINE__));
- }
- m_bVibrationFlag = true;
- m_bVibrationRound = false;
- }
- } else if (!DetectBit(btInput, VIBRATIONSENSOR) && m_bVibrationFlag) {
- m_bVibrationFlag = false;
- m_bVibrationRound = true;
- }
- } while (0);
- pGci->CttShake = pGci->InitCTT;
- }
- /** 机箱门开关检测*/
- if (pGci->CttSwitch == 1) {
- bSwitchOne = true;
- do {
- if (initCtt == 1) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("test initCtt == 1");
- if (DetectBit(btInput, OPENSENSOR)) {
- if (!m_bOpenFlag) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(18), __LINE__));
- }
- m_bOpenFlag = true;
- }
- } else if (m_bOpenFlag) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(18), __LINE__));
- }
- m_bOpenFlag = false;
- }
- break;
- }
- if (m_bOpenRound) {
- if (DetectBit(btInput, OPENSENSOR) && !m_bOpenFlag) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(18), __LINE__));
- }
- m_bOpenFlag = true;
- m_bOpenRound = false;
- }
- } else if (!DetectBit(btInput, OPENSENSOR) && m_bOpenFlag) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_OPENSENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(18), __LINE__));
- }
- m_bOpenFlag = false;
- m_bOpenRound = true;
- }
- } while (0);
- pGci->CttSwitch = pGci->InitCTT;
- }
- /**话机检测*/
- if (pGci->CttPhone == 1) {
- bPhoneOne = true;
- do {
- if (initCtt == 1) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("test initCtt == 1");
- if (m_ePickUpFlag == UnknownStatus) {
- if (DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = Actived;
- else if (!DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = InActive;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set initial value: %d", (int)m_ePickUpFlag);
- } else {
- if (DetectBit(btInput, PICKUPSENSOR)) {
- if (m_ePickUpFlag == InActive) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_PICKUP, "Life the Phone up");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("话机提起");
- }
- m_ePickUpFlag = Actived;
- }
- } else if (m_ePickUpFlag == Actived) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "Put the Phone down");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("话机放下");
- }
- m_ePickUpFlag = InActive;
- }
- }
- break;
- }
- if (m_bPickUpRound) {
- if (DetectBit(btInput, PICKUPSENSOR)) {
- if (m_ePickUpFlag == InActive) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_PICKUP, "Life the Phone up");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("话机提起");
- }
- m_ePickUpFlag = Actived;
- m_bPickUpRound = false;
- } else if (m_ePickUpFlag == UnknownStatus) {
- m_ePickUpFlag = Actived;
- }
- }
- } else if (!DetectBit(btInput, PICKUPSENSOR)) {
- if (m_ePickUpFlag == Actived) {
- if (IfHaveMoveDetect()) {
- LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "Put the Phone down");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("话机放下");
- }
- m_ePickUpFlag = InActive;
- m_bPickUpRound = true;
- } else if (m_ePickUpFlag == UnknownStatus) {
- m_ePickUpFlag = InActive;
- }
- }
- } while (0);
- pGci->CttPhone = pGci->InitCTT;
- }
- /*物体靠近感知检测*/
- if (pGci->CttMove == 1) {
- bMoveOne = true;
- do {
- if (initCtt == 1) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("test initCtt == 1");
- if (DetectBit(btInput, MOVESENSOR)) {
- if (IfHaveMoveDetect())
- LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(20), __LINE__));
- }
- break;
- }
- if (m_bMoveRound) {
- if (DetectBit(btInput, MOVESENSOR)) {
- m_moveDisappearTimes = 0;
- if (m_moveHoldTimes < MAX_MOVE_HOLD_TIMES) { // 100ms * 5000
- if ((m_moveHoldTimes % LOG_TIME_VALUE) == 0) { //100ms * 25 = 2.5s 但因为厂家接口调用,不进来计数,需要800ms+
- if (IfHaveMoveDetect())
- LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_ON, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(20), __LINE__));
- }
- } else if ((m_moveHoldTimes % MAX_MOVE_HOLD_TIMES) == 0) { //难道8分钟一直有人就异常?还有一个 Round 标识
- if (IfHaveMoveDetect()) {
- SYSTEMTIME localTime;
- GetLocalTime(&localTime);
- if (localTime.wHour > 8 && localTime.wHour < 18)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2902")("Move detect is abnormal(Work time).");
- LogWarn(Severity_High, Error_Unexpect, LOG_EVT_MOVEDETECT_ABNORMAL_WORKTIME, "Move detect is abnormal(Work time).");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2903")("Move detect is abnormal(off work).");
- LogWarn(Severity_High, Error_Unexpect, LOG_EVT_MOVEDETECT_ABNORMAL_OFFWORK, "Move detect is abnormal(off work).");
- }
-
- }
- }
- m_moveHoldTimes++;
- m_bMoveRound = false;
- }
- } else if (!DetectBit(btInput, MOVESENSOR)) {
- m_moveHoldTimes = 0;
- if ((m_moveDisappearTimes % LOG_TIME_VALUE) == 0) {
- if (IfHaveMoveDetect())
- LogEvent(Severity_Middle, LOG_EVT_MOVESENSOR_OFF, CSimpleStringA::Format("%s [InActive] line: %d", GetDriverPortString(20), __LINE__));
- }
- m_moveDisappearTimes++;
- m_bMoveRound = true;
- }
- } while (0);
- pGci->CttMove = pGci->InitCTT;
- }
- /*卡嘴异物检测*/
- if (pGci->CttCard == 1) {
- bCardOne = true;
- do {
-
- if (initCtt == 1) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("test initCtt == 1");
- if (DetectBit(btInput, CARDGATESENSOR)) {
- if (!m_bCardGateFlag) {
- if (IfHaveMoveDetect())
- LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(21), __LINE__));
- m_bCardGateFlag = true;
- }
- } else
- m_bCardGateFlag = false;
- break;
- }
- if (m_bCardGateRound) {
- if (DetectBit(btInput, CARDGATESENSOR) && !m_bCardGateFlag) {
- if (IfHaveMoveDetect())
- LogEvent(Severity_Middle, LOG_EVT_CARDGATESENSOR, CSimpleStringA::Format("%s [Active] line: %d", GetDriverPortString(21), __LINE__));
- m_bCardGateFlag = true;
- m_bCardGateRound = false;
- }
- } else if (!DetectBit(btInput, CARDGATESENSOR) && m_bCardGateFlag) {
- m_bCardGateFlag = false;
- m_bCardGateRound = true;
- }
- } while (0);
- pGci->CttCard = pGci->InitCTT;
- }
- /////////////////////////////////////////////////////////////////////////////////////
- if (pGci->CttShake > 1 && !bShakeOne) {
- do {
- if (m_bVibrationRound) {
- if (DetectBit(btInput, VIBRATIONSENSOR))
- pGci->CttShake--;
- else {
- m_bVibrationRound = false;
- pGci->CttShake = pGci->InitCTT;
- }
- } else {
- if (!DetectBit(btInput, VIBRATIONSENSOR))
- pGci->CttShake--;
- else {
- m_bVibrationRound = true;
- pGci->CttShake = pGci->InitCTT;
- }
- }
- } while (0);
- }
- if (pGci->CttSwitch > 1 && !bSwitchOne) {
- do {
- if (m_bOpenRound) {
- if (DetectBit(btInput, OPENSENSOR))
- pGci->CttSwitch--;
- else {
- m_bOpenRound = false;
- pGci->CttSwitch = pGci->InitCTT;
- }
- } else {
- if (!DetectBit(btInput, OPENSENSOR))
- pGci->CttSwitch--;
- else {
- m_bOpenRound = true;
- pGci->CttSwitch = pGci->InitCTT;
- }
- }
- } while (0);
- }
- if (pGci->CttPhone > 1 && !bPhoneOne) {
- do {
- if (m_ePickUpFlag == UnknownStatus) {
- if (DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = Actived;
- else if (!DetectBit(btInput, PICKUPSENSOR)) m_ePickUpFlag = InActive;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Set initial value: %d", (int)m_ePickUpFlag);
- break;
- }
- if (m_bPickUpRound) { /** 该参数的作用貌似是用于记录当前是否是提机的累计次数中,状态切换时会重置次数 [Gifur@2022527]*/
- if (DetectBit(btInput, PICKUPSENSOR)) {
- pGci->CttPhone--;
- } else {
- m_bPickUpRound = false;
- pGci->CttPhone = pGci->InitCTT;
- }
- } else {
- if (!DetectBit(btInput, PICKUPSENSOR))
- pGci->CttPhone--;
- else {
- m_bPickUpRound = true;
- pGci->CttPhone = pGci->InitCTT;
- }
- }
- } while (0);
- }
- if (pGci->CttMove > 1 && !bMoveOne) {
- do {
- if (m_bMoveRound) {
- if (DetectBit(btInput, MOVESENSOR))
- pGci->CttMove--;
- else {
- m_bMoveRound = false;
- pGci->CttMove = pGci->InitCTT;
- }
- } else {
- if (!DetectBit(btInput, MOVESENSOR))
- pGci->CttMove--;
- else {
- m_bMoveRound = true;
- pGci->CttMove = pGci->InitCTT;
- }
- }
- } while (0);
- }
- if (pGci->CttCard > 1 && !bCardOne) {
- do {
- if (m_bCardGateRound) {
- if (DetectBit(btInput, CARDGATESENSOR))
- pGci->CttCard--;
- else {
- m_bCardGateRound = false;
- pGci->CttCard = pGci->InitCTT;
- }
- } else {
- if (!DetectBit(btInput, CARDGATESENSOR))
- pGci->CttCard--;
- else {
- m_bCardGateRound = true;
- pGci->CttCard = pGci->InitCTT;
- }
- }
- } while (0);
- }
- GetFunction()->ResetTimer(pGci->timerID, 100);
- }
- bool CGpioEntity::GetReceiving(int deviceSeq, ReceivingInfo ri, ULONG iIndex)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("inputmode[%d],port[%d],ctt[%d]", ri.InputMode, ri.Port, ri.ContinuousTriggerTime);
- switch (ri.InputMode)
- {
- case IM_POSITIVE_LEVEL:
- { /** 目前只是使用了这一个 [Gifur@2023921]*/
- GetContextInfo* pGci = new GetContextInfo();
- pGci->timerID = deviceSeq;
- pGci->index = iIndex;
- pGci->Port = ri.Port;
- pGci->CttCard = ri.ContinuousTriggerTime;
- pGci->CttMove = ri.ContinuousTriggerTime;
- pGci->CttPhone = ri.ContinuousTriggerTime;
- pGci->CttShake = ri.ContinuousTriggerTime;
- pGci->CttSwitch = ri.ContinuousTriggerTime;
- pGci->InitCTT = ri.ContinuousTriggerTime;
- ITimerListener* pListener = new TimerOutHelper<CGpioEntity>(this, &CGpioEntity::OnPositiveLevelTimerOut, pGci);
- GetFunction()->SetTimer(pGci->timerID, pListener, 100);
- break;
- }
- default:
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("not support: %d", ri.InputMode);
- break;
- }
- return true;
- }
- /** 旧接口,从配置中获取闪烁的属性 [Gifur@2023921]*/
- void CGpioEntity::GetOutDrivingModInfo(CSimpleStringA modName, OutDrivingInfo& odi)
- {
- if (modName.Compare("IDCertificateNormal") == 0) {
- odi.OutputMode = OM_POSITIVE_FLICKER;
- odi.StopMode = SM_CYCLE;
- odi.SetTime = 150;
- odi.ResetTime = 150;
- odi.TimeOut = 5000;
- } else if (modName.Compare("FingerPrintNormal") == 0) {
- odi.OutputMode = OM_POSITIVE_FLICKER;
- odi.StopMode = SM_CYCLE;
- odi.SetTime = 150;
- odi.ResetTime = 150;
- odi.TimeOut = 5000;
- } else if (modName.Compare("CardReaderNormal") == 0) {
- odi.OutputMode = OM_POSITIVE_FLICKER;
- odi.StopMode = SM_CYCLE;
- odi.SetTime = 200;
- odi.ResetTime = 200;
- odi.TimeOut = 5000;
- } else if (modName.Compare("AssistNormal") == 0) {
- odi.OutputMode = OM_POSITIVE_FLICKER;
- odi.StopMode = SM_CYCLE;
- odi.SetTime = 1000;
- odi.ResetTime = 500;
- odi.TimeOut = 5000;
- } else if (modName.Compare("LightNormal") == 0) {
- odi.OutputMode = OM_POSITIVE_LEVEL;
- odi.StopMode = SM_CALLTRIGGER;
- odi.SetTime = 1000;
- odi.ResetTime = 1000;
- odi.TimeOut = 5000;
- } else if (modName.Compare("RedLightNormal") == 0) {
- odi.OutputMode = OM_POSITIVE_LEVEL;
- odi.StopMode = SM_CALLTRIGGER;
- odi.SetTime = 200;
- odi.ResetTime = 200;
- odi.TimeOut = 3000;
- } else {
- odi.OutputMode = OM_POSITIVE_LEVEL;
- odi.StopMode = SM_CALLTRIGGER;
- odi.SetTime = 200;
- odi.ResetTime = 200;
- odi.TimeOut = 5000;
- }
- LOG_TRACE("outputmode.stopmode:[%d].[%d]", odi.OutputMode, odi.StopMode);
- }
- /*从配置文件中获取配置*/
- void CGpioEntity::GetReceivingModInfo(CSimpleStringA modName, ReceivingInfo& ri)
- {
- if (modName.Compare("PhoneNormal") == 0) {
- ri.ContinuousTriggerTime = 2;
- } else if (modName.Compare("GpioNormal") == 0) {
- ri.ContinuousTriggerTime = 10;
- } else if (modName.Compare("CardGateNormal") == 0) {
- ri.ContinuousTriggerTime = 10;
- } else if (modName.Compare("ShakeNormal") == 0) {
- ri.ContinuousTriggerTime = 4;
- } else {
- ri.ContinuousTriggerTime = 10;
- }
- ri.InputMode = IM_POSITIVE_LEVEL;
- }
- BYTE CGpioEntity::GetOutputStatus(int sn)
- {
- if (sn == 0)
- return m_btOutputStatus[0];
- else if (sn == 1)
- return m_btOutputStatus[1];
- else if (sn == 2)
- return m_btOutputStatus[2];
- else
- return 0;
- }
- bool CGpioEntity::IfHaveMoveDetect()
- {
- if (m_eMachineType == RVC_Stand2S || m_eMachineType == RVC_Stand1SPlus ||m_eMachineType == RVC_CardPrinter)
- return true;
- else
- return false;
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CGpioEntity)
- SP_END_ENTITY_MAP()
|