Browse Source

#IQRV #comment 优化Gpio握手和监听时间的逻辑

80374374 8 months ago
parent
commit
73b94e246d

+ 3 - 17
Module/include/DevFSMCommBase.hpp

@@ -381,14 +381,13 @@ public:
 	CSimpleStringA strPort;
 	CSimpleStringA strBaudrate;
 	CSimpleStringA strPortNum;
-	CSimpleStringA strInOutDir;
 	CSimpleStringA strCheckdata;
 	CSimpleStringA strKeysn;
 	CSimpleStringA strPureAdapterName;
 
 	AdaptorInfo() :strVendor(true), strVersion(true), strBatch(true)
 		, strPort(true), strBaudrate(true)
-		, strPortNum(true), strInOutDir(true)
+		, strPortNum(true)
 		, strCheckdata(true), strKeysn(true), strPureAdapterName(true)
 	{
 	}
@@ -436,14 +435,6 @@ public:
 		}
 		return result;
 	}
-	int GetInOutDirInt() const
-	{
-		int result = 0;
-		if (!strInOutDir.IsNullOrEmpty()) {
-			result = atoi(strInOutDir.GetData());
-		}
-		return result;
-	}
 };
 
 struct AdapterInfo : public AdaptorInfo
@@ -745,9 +736,7 @@ public:
 		CSimpleStringA csPortNum(true), csCheckData(true), csKeySN(true), csInOutDir(true);
 		if (!entityName.Compare("Gpio")) {
 			spConfigRoot->ReadConfigValue(sectionName.GetData(), "PortNum", csPortNum);
-			spConfigRoot->ReadConfigValue(sectionName.GetData(), "InOutDir", csInOutDir);
 			m_adapterInfo.strPortNum = csPortNum;
-			m_adapterInfo.strInOutDir = csInOutDir;
 		} else if (!entityName.Compare("PinPad")) {
 			spConfigRoot->ReadConfigValue(sectionName.GetData(), "Checkdata", csCheckData);
 			spConfigRoot->ReadConfigValue(sectionName.GetData(), "Keysn", csKeySN);
@@ -790,10 +779,10 @@ public:
 	{
 		CSimpleStringA result(true);
 		if (0 == devDeviceName.Compare("Gpio", true)) {
-			result = CSimpleStringA::Format("{\"Vendor\":\"%s\", \"Version\":\"%s\", \"Batch\":\"%s\", \"Port\":\"%s\", \"Baudrate\":\"%s\", \"PortNum\":\"%s\", \"InOutDir\":\"%s\"}",
+			result = CSimpleStringA::Format("{\"Vendor\":\"%s\", \"Version\":\"%s\", \"Batch\":\"%s\", \"Port\":\"%s\", \"Baudrate\":\"%s\", \"PortNum\":\"%s\"}",
 				LPCSTRSmartPrintString(adaptorInfo.strVendor), LPCSTRSmartPrintString(adaptorInfo.strVersion),
 				LPCSTRSmartPrintString(adaptorInfo.strBatch), LPCSTRSmartPrintString(adaptorInfo.strPort), LPCSTRSmartPrintString(adaptorInfo.strBaudrate),
-				LPCSTRSmartPrintString(adaptorInfo.strPortNum), LPCSTRSmartPrintString(adaptorInfo.strInOutDir));
+				LPCSTRSmartPrintString(adaptorInfo.strPortNum));
 		} else if (0 == devDeviceName.Compare("PinPad", true)) {
 			result = CSimpleStringA::Format("{\"Vendor\":\"%s\", \"Version\":\"%s\", \"Batch\":\"%s\", \"Port\":\"%s\", \"Baudrate\":\"%s\", \"Checkdata\":\"%s\", \"Keysn\":\"%s\"}",
 				LPCSTRSmartPrintString(adaptorInfo.strVendor), LPCSTRSmartPrintString(adaptorInfo.strVersion),
@@ -824,7 +813,6 @@ public:
         }
 	}
 
-	/** GPIO不调用此接口 [Gifur@20221025]*/
 	void ToLogRootINIInfo()
 	{
 		CSimpleStringA entityName(this->GetEntityBase()->GetEntityName());
@@ -838,7 +826,6 @@ public:
 
 		if (!entityName.Compare("Gpio")) {
 			rootInfo["PortNum"] = m_adapterInfo.strPortNum.GetData();
-			rootInfo["InOutDir"] = m_adapterInfo.strInOutDir.GetData();
 		} else if (!entityName.Compare("PinPad")) {
 			rootInfo["Checkdata"] = m_adapterInfo.strCheckdata.GetData();
 			rootInfo["Keysn"] = m_adapterInfo.strKeysn.GetData();
@@ -917,7 +904,6 @@ public:
 		CSimpleStringA entityName(this->GetEntityBase()->GetEntityName());
 		if (!entityName.Compare("Gpio")) {
 			termInfo["PortNum"] = m_adapterInfo.strPortNum.GetData();
-			termInfo["InOutDir"] = m_adapterInfo.strInOutDir.GetData();
 		}
 		else if (!entityName.Compare("PinPad")) {
 			termInfo["CheckData"] = m_adapterInfo.strCheckdata.GetData();

+ 19 - 10
Module/mod_gpio/GpioFSM.cpp

@@ -248,7 +248,7 @@ CSimpleStringA CombineJsonContext(const char* szMessage)
 
 CGPIOFSM::CGPIOFSM(void) :m_bVibrationFlag(false), m_bOpenFlag(false), m_bMoveFlag(false), m_bCardGateFlag(false)
 	, m_bHeadLightFlag(false), m_headlightDevPort(4), m_moveHoldTimes(0)
-	, m_moveDisappearTimes(0), m_eMachineType(SP::Module::Comm::RVC_UNKNOWN)
+	, m_moveDisappearTimes(0)
 	, m_bNewVersion(FALSE), m_bFuncVer2(FALSE), m_btLastRevcInput(-1)
 {
 	memset(m_btOutputStatus, 0, MAX_PORT_NUM * sizeof(BYTE));
@@ -261,12 +261,13 @@ ErrorCodeEnum CGPIOFSM::OnInit()
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Source Code complied at: %s %s", __DATE__, __TIME__);
 	auto pEntity = GET_DEV_ENTITY_BASE_POINTER();
 	pEntity->InitializeVendorLogSwitch();
-
+	SetDevInitingFlag(true);
+	SetDevInitFlag(false);
 	CSimpleStringA strNoUse(true);
 	erroCode = pEntity->ExtractVendorLibFullPath(strNoUse);
 	if (erroCode != Error_Succeed) {
 		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("load vendor dll or so(%s) failed, ec=%s", strNoUse.GetData(), SpStrError(erroCode));
-		m_bOpening = false;
+		SetDevInitingFlag(false);
 		return Error_DevLoadFileFailed;
 	}
 
@@ -274,6 +275,7 @@ ErrorCodeEnum CGPIOFSM::OnInit()
 	LogWarn(Severity_Low, Error_Unexpect, GPIO_UserErrorCode_RootInfo, (LPCTSTR)m_adapterInfo.adapterFilePath);
 	erroCode = LoadUpAdapterLibrary();
 	if (erroCode != Error_Succeed) {
+		SetDevInitingFlag(false);
 		return erroCode;
 	}
 
@@ -301,7 +303,7 @@ ErrorCodeEnum CGPIOFSM::OnInit()
 		ULONGLONG ullEnd = SP::Module::Comm::RVCGetTickCount();
 		if (err == Error_Succeed) {
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::DevOpen").setCostTime(ullEnd - ullStart)("open device succ");
-			ToLogRootINIInfo(); //WARN:这里是重新读一遍原生的root配置信息
+			ToLogRootINIInfo();
 			DevCategoryInfo devCatInfo;
 			ZeroMemory(devCatInfo.szModel, sizeof(devCatInfo.szModel));
 			ZeroMemory(devCatInfo.szType, sizeof(devCatInfo.szType));
@@ -323,7 +325,7 @@ ErrorCodeEnum CGPIOFSM::OnInit()
 			else {
 				SetErrorAndLog(err, GPIO_UserErrorCode_GetDevCategory_Failed, "DevAdapter::GetDevCategory", "FulfillAdapterDevCategory", false, ullEnd - ullStart);
 			}
-			m_bOpened = true;
+			SetDevInitFlag(true);
 			break;
 		}
 		else {
@@ -334,8 +336,7 @@ ErrorCodeEnum CGPIOFSM::OnInit()
 		}
 	} while (initTries < MAX_GPIO_INIT_TRIES);
 
-	m_bOpening = false;
-	if (!m_bOpened) {
+	if (!GetDevInitFlag()) {
 		err = Error_DevConnFailed;
 	}
 	else {
@@ -367,15 +368,20 @@ ErrorCodeEnum CGPIOFSM::OnInit()
 				SetErrorAndLog(eErrDev, GPIO_UserErrorCode_SetStatus_Failed, "DevAdapter::SetStatus", __FUNCTION__, false, ullEnd - ullStart, "", CombineJsonContext("SetStatus after DevOpen"));
 #endif //RVC_OS_LINUX
 		}
+		SetDevState(DEVICE_STATUS_NORMAL);
 	}
-	m_eMachineType = SP::Module::Comm::GetTerminalMachineInfo(GetEntityBase()).type;
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("machine type: %s", SP::Module::Comm::Type2Str(m_eMachineType));
+	SetDevInitingFlag(false);
 	m_moveHoldTimes = MAX_MOVE_HOLD_TIMES;//oiltmp about 5000*300ms = 25 minutes
 	m_moveDisappearTimes = m_moveHoldTimes;
 	return err;
 
 }
 
+void CGPIOFSM::AfterInit()
+{
+	StartDetectWorkThread();
+}
+
 void CGPIOFSM::SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
 {
 	OnHardwareShakeHand(pTransactionContext);
@@ -915,11 +921,13 @@ void CGPIOFSM::OnEventDetect(void* pData)
 			m_PickUpTimeStamp = SP::Module::Comm::RVCGetTickCount();
 			LogEvent(Severity_Middle, LOG_EVT_PICKUP, "Life the Phone up");
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(GpioService_LogCode_Detect_PhonePickup)("[GPIO] 话机提起");
+			LogWarn(Severity_Low, Error_Debug, GPIO_UserErrorCode_Phone_HandUp, "话机提起");
 		}
 		else if (m_ePickUpFlag == UnknownStatus) {
 			m_ePickUpFlag = Actived;
 			m_PickUpTimeStamp = SP::Module::Comm::RVCGetTickCount();
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(GpioService_LogCode_Detect_PhonePickup)("[GPIO] 话机提起(启动时)");
+			LogWarn(Severity_Low, Error_Debug, GPIO_UserErrorCode_Phone_HandUp_AtBegin, "话机提起(启动时)");
 		}
 	}
 	else if (!DetectBit(btInput, PICKUPSENSOR)) {
@@ -927,7 +935,8 @@ void CGPIOFSM::OnEventDetect(void* pData)
 			m_ePickUpFlag = InActive;
 			m_PutDownTimeStamp = SP::Module::Comm::RVCGetTickCount();
 			LogEvent(Severity_Middle, LOG_EVT_ONHOOK, "Put the Phone down");
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(GpioService_LogCode_Detect_PhonePutDown).setCostTime(m_PutDownTimeStamp - m_PickUpTimeStamp)("话机放下");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(GpioService_LogCode_Detect_PhonePutDown).setCostTime(m_PutDownTimeStamp - m_PickUpTimeStamp)("[GPIO] 话机放下");
+			LogWarn(Severity_Low, Error_Debug, GPIO_UserErrorCode_Phone_PutDown, "话机放下");
 		}
 		else if (m_ePickUpFlag == UnknownStatus) {
 			m_ePickUpFlag = InActive;

+ 1 - 2
Module/mod_gpio/GpioFSM.h

@@ -135,6 +135,7 @@ public:
 		LOG_FUNCTION();
 		return Error_Succeed;
 	}
+	void AfterInit();
 
 	void SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
 
@@ -176,8 +177,6 @@ private:
 	bool DetectBit(ULONG data, int pos);
 
 private:
-	SP::Module::Comm::What m_eMachineType;
-
 	BYTE m_btOutputStatus[MAX_PORT_NUM];
 
 	BOOL m_bNewVersion;

+ 5 - 0
Module/mod_gpio/Gpio_UserErrorCode.h

@@ -15,4 +15,9 @@
 #define GPIO_UserErrorCode_ReadPort_Failed	0x20900208
 #define GPIO_UserErrorCode_DetectStatus_Failed	0x20900209
 
+#define GPIO_UserErrorCode_Phone_HandUp	0x2090020A
+#define GPIO_UserErrorCode_Phone_HandUp_AtBegin	0x2090020B
+#define GPIO_UserErrorCode_Phone_PutDown 0x2090020C
+
+
 #endif //_CONTACTLESSCARD_USER_ERRORCODE_H

+ 1 - 0
Module/mod_gpio/mod_gpio.cpp

@@ -35,6 +35,7 @@ void CGpioEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<I
 		GetFunction()->SubscribeLog(m_uuidCS, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "CardIssuerStore");
 		GetFunction()->SubscribeLog(m_uuidHSPscanner, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "HSPScanner");
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sub ok...");
+		m_fsm.AfterInit();
 	}
 	else
 	{