Эх сурвалжийг харах

!10502 指纹仪异常信息优化分支归并到解耦分支
Merge pull request !10502 from 80174520/feature_fingerPrint_log_1011

刘文涛80174520 11 сар өмнө
parent
commit
207bc0d9e3

+ 83 - 4
DevAdapter/simulator/FingerPrint.1.1/FingerPrint_impl.cpp

@@ -104,10 +104,15 @@ FingerPrintImpl::~FingerPrintImpl()
 
 ErrorCodeEnum FingerPrintImpl::GetDevCategory(DevCategoryInfo& devCategory)
 {
-	strcpy(devCategory.szModel, "szModel");
-	strcpy(devCategory.szType, "szType");
-	strcpy(devCategory.szVendor, "szVendor=cmbszSimulator");
-	return Error_Succeed;
+	if (GetDevCategoryHttp(devCategory)) {
+		strcpy(devCategory.szModel, "CM=2.0#CID=00000000");
+		strcpy(devCategory.szType, "PVER=ACT#MID=ACT-F5-5540-0SH");
+		strcpy(devCategory.szVendor, "cmbszSimulator");
+		return Error_Succeed;
+	}
+	else {
+		return Error_Exception;
+	}
 }
 
 ErrorCodeEnum FingerPrintImpl::Reset()
@@ -330,6 +335,80 @@ bool FingerPrintImpl::Image2TemplateHttp(LPBYTE lpbTemplate, int& iLength)
 	}
 }
 
+bool FingerPrintImpl::GetDevCategoryHttp(DevCategoryInfo& devCategory)
+{
+	LOG4VTM(INFO, "GetDevCategoryHttp");
+	return commonSimpleHttp("GetDevCategory");
+}
+
+bool FingerPrintImpl::commonSimpleHttp(string adapterInterName)
+{
+	CommonReq cReq;
+	CommonRet cRet;
+	IHttpFunc* client;
+	client = create_http(HttpsLogCallBack);
+
+	Json::Value rootReq;
+	Json::FastWriter writer;
+
+	rootReq["ip"] = GetLocalIP();
+	rootReq["entityName"] = "FingerPrint";
+	rootReq["adapterInterName"] = adapterInterName;//适配器接口名
+	string strErrPrefix = adapterInterName + "http";
+	cReq.m_url = getUrl();
+	cReq.m_timeOut = 30;
+	string jsonReq = writer.write(rootReq);
+	cReq.m_reqStr = jsonReq;//请求参数
+
+	bool ret = client->Post(cReq, cRet);
+	if (ret) {
+		Json::Reader reader;
+		Json::Value rootRet;
+		if (!reader.parse(cRet.m_retStr, rootRet, false))
+		{
+			LOG4VTM(INFO, strErrPrefix << " parse resp is fail,url=" << cReq.m_url.c_str());
+			return false;//失败
+		}
+		bool isSucc = rootRet["success"].asBool();
+		if (isSucc) {
+			//解析数据
+			if (rootRet.isMember("data")) {
+				bool isResult = rootRet["data"]["result"].asBool();
+				if (isResult) {
+					return true;
+				}
+				else {
+					return false;
+				}
+			}
+			else {
+				LOG4VTM(INFO, strErrPrefix << " return [data] is null");
+				return false;
+			}
+		}
+		else {
+			LOG4VTM(INFO, strErrPrefix << " [success] is false,");
+			return false;
+		}
+	}
+	else {
+		LOG4VTM(INFO, strErrPrefix << " req fail,err=%s" << cRet.m_errMsg.c_str());
+		return false;
+	}
+}
+
+string FingerPrintImpl::getUrl()
+{
+	string urlStr = iniRead.ReadString("server", "url", "");
+	if (urlStr.empty()) {
+		LOG4VTM(INFO, "url is empty, use default url");
+		return "http://localhost:8080/avs/imitate/simulateDataN";
+	}
+	else {
+		return urlStr;
+	}
+}
+
 #ifdef NEWER_COMPILER_WORKAROUNDS
 
 DEVICEBASE_API ErrorCodeEnum  GetDevAdapterVersion(DevSoftVersion& retVesion)

+ 19 - 0
DevAdapter/simulator/FingerPrint.1.1/FingerPrint_impl.h

@@ -8,6 +8,21 @@
 #include "../../DeviceSimulator.h"
 #include "json/json.h"
 
+typedef struct CommonReq : CHTTPReq {
+	string m_reqStr;
+	string ToJson() {
+		return m_reqStr;
+	}
+} CommonReq;
+
+typedef struct CommonRet : CHTTPRet {
+	string m_retStr;
+	bool Parse(string strData) {
+		m_retStr = strData;
+		return true;
+	}
+} CommonRet;
+
 typedef struct Image2FeatureReq : CHTTPReq {
 	string m_reqStr;
 	string ToJson() {
@@ -76,6 +91,10 @@ public:
 
 	bool Image2TemplateHttp(LPBYTE lpbTemplate, int& iLength);
 
+	bool GetDevCategoryHttp(DevCategoryInfo& devCategory);
+
+	bool commonSimpleHttp(string adapterInterName);
+	string getUrl();
 	string depCfgPath;
 	iniReader iniRead;
 };