Browse Source

1、修正g_szIPAddress为g_strIPAddress;
2、设备管理函数:add、del、sync、isexist;

scbc.sat2 5 years ago
parent
commit
972aa99400

+ 3 - 3
SATService/SATService/Global.cpp

@@ -44,7 +44,7 @@ namespace GLOBAL
 	TCHAR g_szDBPassWord[MAX_PATH];				// 数据库登录密码;
 	TCHAR g_szDBName[MAX_PATH];					// 数据库名称;	
 
-	std::string g_szIPAddress;
+	std::string g_strIPAddress;
 
 	//////////////////////////////////////////////////////////////////////////
 	std::string g_strMacs;
@@ -1208,7 +1208,7 @@ namespace GLOBAL
 				IP_ADDR_STRING*pIpAddrString = &(pIpAdapterInfo->IpAddressList);
 				if ( pIpAdapterInfo->Type == nType )
 				{
-					g_szIPAddress = pIpAddrString->IpAddress.String;
+					g_strIPAddress = pIpAddrString->IpAddress.String;
 					break;
 				}
 #if 0
@@ -1244,7 +1244,7 @@ namespace GLOBAL
 			delete pIpAdapterInfo;
 		}
 
-		return g_szIPAddress;
+		return g_strIPAddress;
 	}
 
 	INT GetMacAddress()

+ 1 - 1
SATService/SATService/Global.h

@@ -86,7 +86,7 @@ namespace GLOBAL
 	extern TCHAR g_szFna[_MAX_FNAME];
 	extern TCHAR g_szExt[_MAX_EXT];
 
-	extern std::string g_szIPAddress;
+	extern std::string g_strIPAddress;
 
 	//////////////////////////////////////////////////////////////////////////
 	// Íø¿¨ÀàÐÍ;

+ 12 - 0
SATService/SATService/SATDevices.cpp

@@ -349,6 +349,18 @@ void CSATDevices::ReConnectAllDevices()
 	}
 }
 
+void CSATDevices::SetDeviceUsageStatus(std::string strDevName, SATDEV::DEVICE_USAGE_STATUS status)
+{
+	AutoThreadSection ats(&s_ThreadSection);
+	std::vector<SATDEV::STDevice>::iterator it = s_vtDevices.begin();
+	for ( ;it != s_vtDevices.end(); it++ ) {
+		if ( _tcsicmp(it->strName.c_str(), strDevName.c_str() ) == 0) {
+			it->nUsageState = status;
+			break;
+		}
+	}
+}
+
 int CSATDevices::AttachDeviceName2Buffer(SATPROTO::Device (&pbuff)[30])
 {
 	int count = 0;

+ 2 - 0
SATService/SATService/SATDevices.h

@@ -108,6 +108,8 @@ public:
 	static void GetCurrentDevices(std::vector<SATDEV::STDevice> &vtDevices);
 	// 重连所有设备;
 	static void ReConnectAllDevices();
+	// 设置设备使用状态;
+	static void SetDeviceUsageStatus(std::string strDevName, SATDEV::DEVICE_USAGE_STATUS status);
 
 	// 附加设备名到缓存中;
 	static int AttachDeviceName2Buffer(SATPROTO::Device (&pbuff)[30]);

+ 75 - 9
SATService/SATService/SATExecutor.cpp

@@ -113,9 +113,78 @@ SATHTTP::STCase* CSATExecutor::ExecuteFreeCaseScript(SATHTTP::STTask* pTask)
 	return pCase;
 }
 
-void CSATExecutor::AddDevices(SATDEV::STDevice &stDevice)
+void CSATExecutor::AddDevices(const SATDEV::STDevice &stDevice)
 {
-	
+	if ( IsDeviceExist(stDevice.strName) )
+		return;
+
+	SATHTTP::STDevice http_dev;
+	// 设备使用状态;
+	if ( stDevice.nStatus == SATDEV::Idle )
+		http_dev.strStatus = "0";
+	else if ( stDevice.nStatus == SATDEV::InUse )
+		http_dev.strStatus = "1";
+	// 设备序列号;
+	http_dev.strDeviceSerial = stDevice.strName;
+	// 余下变量固定值;
+	http_dev.strComments = "";
+	http_dev.strCPU = "";
+	http_dev.strDeviceMac = "";
+	http_dev.strElectric = "";
+	http_dev.strHardwareVersion = "SAT-HV";
+	http_dev.strLastJob = "";
+	http_dev.strLastJobFinishTime = "";
+	http_dev.strLastJobStartTime = "";
+	http_dev.strLastTimeBreak = "";
+	http_dev.strLastTimeConnected = "";
+	http_dev.strManu = "";
+	http_dev.strMemory = "";
+	http_dev.strModel = "SATModel";
+	http_dev.strPhoneNumber = "";
+	http_dev.strSoftwareVersion = "0123456789";
+
+	m_vtDevice.push_back(http_dev);
+}
+
+void CSATExecutor::DelDevices(const SATDEV::STDevice &stDevice)
+{
+	std::vector<SATHTTP::STDevice>::iterator it = m_vtDevice.begin();
+	for ( ; it != m_vtDevice.end(); it++ ) {
+		if ( _tcsicmp(it->strDeviceSerial.c_str(), stDevice.strName.c_str()) == 0 ) {
+			m_vtDevice.erase(it);
+			break;
+		}
+	}
+}
+
+void CSATExecutor::SynchDeviceStatus(std::string strDevName, SATDEV::DEVICE_USAGE_STATUS status)
+{
+	std::vector<SATHTTP::STDevice>::iterator it = m_vtDevice.begin();
+	for ( ; it != m_vtDevice.end(); it++ ) {
+		if ( _tcsicmp(it->strDeviceSerial.c_str(), strDevName.c_str()) == 0 ) {
+			if ( status == SATDEV::Idle )
+				it->strStatus = "0";
+			else if ( status == SATDEV::InUse )
+				it->strStatus = "1";
+			break;
+		}
+	}
+
+	CSATDevices::SetDeviceUsageStatus(strDevName, status);
+}
+
+bool CSATExecutor::IsDeviceExist(std::string strDevName)
+{
+	bool bExist = false;
+	std::vector<SATHTTP::STDevice>::iterator it = m_vtDevice.begin();
+	for ( ; it != m_vtDevice.end(); it++ ) {
+		if ( _tcsicmp(it->strDeviceSerial.c_str(), strDevName.c_str()) == 0 ) {
+			bExist = true;
+			break;
+		}
+	}
+
+	return bExist;
 }
 
 bool CSATExecutor::Login(std::string user, std::string password, std::string actuator, bool bLogin /*= true*/)
@@ -127,7 +196,7 @@ bool CSATExecutor::Login(std::string user, std::string password, std::string act
 	m_stLoginReq.strPassword = password;
 	m_stLoginReq.strStatus = bLogin ? "0" : "1";   // 0表示登录;
 	m_stLoginReq.strDeleteStatus = "";
-	m_stLoginReq.strIP = GLOBAL::g_szIPAddress;
+	m_stLoginReq.strIP = GLOBAL::g_strIPAddress;
 	m_stLoginReq.strStorage = "";
 	if ( bLogin ) {
 		m_stLoginReq.strDisconnectTime = "";
@@ -192,14 +261,11 @@ bool CSATExecutor::UpdateDevice()
 	
 	stUpdateDeviceReq.strStatus = "0";
 	stUpdateDeviceReq.strUserName = m_stLoginReq.strUserName;		
-	stUpdateDeviceReq.strIP = "10.118.158.175";
+	stUpdateDeviceReq.strIP = GLOBAL::g_strIPAddress;
 	stUpdateDeviceReq.strStorage = "228092536KB";
 	stUpdateDeviceReq.strRunnerName = "SAT-Admin";
-	//stUpdateDeviceReq.strMAC = "40:16:7e:23:10:53";
-	if ( GLOBAL::g_vtMac.size() )
-		stUpdateDeviceReq.strMAC = GLOBAL::g_vtMac[0].szMacAddress; // 取第一个MAC地址;
-	else
-		stUpdateDeviceReq.strMAC = "";
+	// 这里使用PC物理地址;
+	stUpdateDeviceReq.strMAC = GLOBAL::g_strMacs;
 	stUpdateDeviceReq.strReportType = "1";
 	stUpdateDeviceReq.strStartTime = "2019-12-16 19:15:30";
 	stUpdateDeviceReq.strMemory = "8938544KB";

+ 6 - 4
SATService/SATService/SATExecutor.h

@@ -69,11 +69,13 @@ protected:
 	// 执行空闲新用例;
 	SATHTTP::STCase* ExecuteFreeCaseScript(SATHTTP::STTask* pTask);
 	// 添加设备;
-	void AddDevices(SATDEV::STDevice &stDevice);
+	void AddDevices(const SATDEV::STDevice &stDevice);
 	// 删除设备;
-	void DelDevices(SATDEV::STDevice &stDevice);
-	// 同步设备;
-	void SynchDevices(SATDEV::STDevice &stDevice);
+	void DelDevices(const SATDEV::STDevice &stDevice);
+	// 同步设备状态;
+	void SynchDeviceStatus(std::string strDevName, SATDEV::DEVICE_USAGE_STATUS status);
+	// 设备是否存在;
+	bool IsDeviceExist(std::string strDevName);
 
 
 public: