Explorar el Código

查询设备接口变更;

scbc.sat2 hace 5 años
padre
commit
b126debf71

+ 7 - 3
SATService/SATService/SATDevices.cpp

@@ -160,7 +160,7 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
 			else
 				it++;
 		}
-	} while (WaitForSingleObject(that->m_hEvent, 1000) == WAIT_TIMEOUT);
+	} while (WaitForSingleObject(that->m_hEvent, 2500) == WAIT_TIMEOUT);
 
 	printf("end thread\n");
 	return 0;
@@ -192,6 +192,7 @@ void CSATDevices::AddReticleDevices(std::string ip)
 	stDevice.nType = Reticle;
 	stDevice.strName = ip;
 	stDevice.ulOfflineTime = 0;
+	stDevice.nStatus = 0;
 
 	AutoThreadSection ats(&s_ThreadSection);
 	if (!IsDeviceExist(stDevice))
@@ -204,6 +205,7 @@ void CSATDevices::AddVirtualDevices(std::string name)
 	stDevice.nType = Virtual;
 	stDevice.strName = name;
 	stDevice.ulOfflineTime = 0;
+	stDevice.nStatus = 0;
 
 	AutoThreadSection ats(&s_ThreadSection);
 	if (!IsDeviceExist(stDevice))
@@ -360,14 +362,16 @@ void CSATDevices::ReConnectAllDevices()
 	}
 }
 
-int CSATDevices::AttachDeviceName2Buffer(char (&pbuff)[30][MAX_PATH])
+int CSATDevices::AttachDeviceName2Buffer(SATProtocol::Device (&pbuff)[30])
 {
 	int count = 0;
 	if ( pbuff ) {
 		std::string str;
 		std::vector<STDevice>::iterator it = s_vtDevices.begin();
 		for ( ;it != s_vtDevices.end(); it++ ) {
-			memcpy_s(pbuff[count++], MAX_PATH, it->strName.c_str(), it->strName.size());
+			pbuff[count].nType = it->nType;
+			pbuff[count].nStatus = it->nStatus;
+			memcpy_s(pbuff[count++].szName, MAX_PATH, it->strName.c_str(), it->strName.size());
 			// ³¬¹ý30Í˳ö;
 			if ( count == 30)
 				break;

+ 3 - 1
SATService/SATService/SATDevices.h

@@ -4,6 +4,7 @@
 #pragma once
 
 #include "CritSection.h"
+#include "SATProtocol.h"
 
 enum DEVICE_TYPE{
 	Virtual,
@@ -17,6 +18,7 @@ typedef struct __DEVICE__
 	std::string 	strName;	// 设备名称(IP:端口号);
 	// 离线时刻:超过指定时长删除该设备,线程实时刷新离线时刻;
 	ULONGLONG		ulOfflineTime;
+	int				nStatus;		// 设备状态:0表示空闲,1表示繁忙;
 }STDevice, *pSTDevice;
 
 // 安卓设备adb连接:USB连接、网线连接;
@@ -95,7 +97,7 @@ public:
 	static void ReConnectAllDevices();
 
 	// 附加设备名到缓存中;
-	static int AttachDeviceName2Buffer(char (&pbuff)[30][MAX_PATH]);
+	static int AttachDeviceName2Buffer(SATProtocol::Device (&pbuff)[30]);
 
 };
 

+ 7 - 1
SATService/SATService/SATProtocol.h

@@ -51,12 +51,18 @@ namespace SATProtocol{
 		char		szMessage[MAX_PATH];
 	}LoginResp, *pLoginResp;
 
+	typedef struct __DEVICE__ {
+		int 			nType;				// 0=虚拟, 1=usb, 2=网线;
+		char		 	szName[MAX_PATH];	// 设备名称(IP:端口号);
+		int				nStatus;			// 设备状态:0表示空闲,1表示繁忙;
+	}Device, *pDevice;
+
 	// 查询设备返回;
 	typedef struct __QUERY_DEVICES_RESP__ {
 		// 设备数量;
 		int			nSize;
 		// 最多只能返回30个设备;
-		char		szDevs[30][MAX_PATH];
+		Device		ssDevs[30];
 	}DeviceResp, *pDeviceResp;
 
 #pragma pack(pop)

+ 3 - 2
SATService/SATService/SATTCPServer.cpp

@@ -336,6 +336,7 @@ bool CSATTCPServer::_InitializeListenSocket(unsigned int port)
 	// 绑定地址和端口
 	if (SOCKET_ERROR == ::bind(m_pListenContext->m_Socket, (struct sockaddr *) &ServerAddress, sizeof(ServerAddress))) 
 	{
+		TRACE("bind() 失败.\n");
 		this->_ShowMessage(_T("bind()函数执行错误! 错误代码: %d/n"), WSAGetLastError());  
 		return false;
 	}
@@ -961,9 +962,9 @@ void CSATTCPServer::_TaskProcess(PER_IO_CONTEXT* pIoContext, SATProtocol::Packag
 					pSendPak->header.len = len;
 					// 转换pak->buf为结构体;
 					SATProtocol::DeviceResp *pDevResp = (SATProtocol::DeviceResp*)(pbuff+sizeof(SATProtocol::DataHeader));
-					memset(pDevResp->szDevs, 0, 30*MAX_PATH);
+					memset(pDevResp->ssDevs, 0, 30*sizeof(SATProtocol::Device));
 					// 获取设备列表;
-					pDevResp->nSize = CSATDevices::AttachDeviceName2Buffer(pDevResp->szDevs);
+					pDevResp->nSize = CSATDevices::AttachDeviceName2Buffer(pDevResp->ssDevs);
 
 					// 返回给客户端;
 					send(pIoContext->m_sockAccept, (const char*)pbuff, len, 0);