Преглед на файлове

更正变量名称,Android改成Device,以便能正确阅读代码;

scbc.sat2 преди 5 години
родител
ревизия
a7c4462935
променени са 2 файла, в които са добавени 79 реда и са изтрити 71 реда
  1. 56 56
      SATService/SATService/SATDevices.cpp
  2. 23 15
      SATService/SATService/SATDevices.h

+ 56 - 56
SATService/SATService/SATDevices.cpp

@@ -4,7 +4,7 @@
 bool CSATDevices::s_bEnableAndroid = true;
 ULONGLONG CSATDevices::s_ulEraseDuration = 30000;
 ThreadSection CSATDevices::s_ThreadSection;
-std::vector<STAndroid> CSATDevices::s_vtAndroids;
+std::vector<STDevice> CSATDevices::s_vtDevices;
 
 void Split(vector<std::string>& vtLine, std::string strLines, const std::string strSplit)
 {
@@ -123,24 +123,24 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
 			continue;
 
 		// 刷新当前设备列表;
-		std::vector<STAndroid> vtAndroids;
+		std::vector<STDevice> vtDevices;
 		printf("GetCurrentDevices\n");
 		// 获取当前设备列表;
-		GetCurrentDevices(vtAndroids);
+		GetCurrentDevices(vtDevices);
 
 		// 遍历设备列表是否有下线设备;
-		std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
-		for ( ;it != s_vtAndroids.end(); ) {
+		std::vector<STDevice>::iterator it = s_vtDevices.begin();
+		for ( ;it != s_vtDevices.end(); ) {
 			if ( it->nType == Virtual ) {
 				it++;
 				continue;
 			}
 
-			if ( IsAndroidOffline(*it, vtAndroids) ) {
+			if ( IsAndroidOffline(*it, vtDevices) ) {
 				printf("IsAndroidOffline\n");
 				if ( GetTickCount64() - it->ulOfflineTime > s_ulEraseDuration ) {
 					// 移除设备(需要线程加锁);
-					it = s_vtAndroids.erase(it);
+					it = s_vtDevices.erase(it);
 				} else {
 					if ( it->nType == Reticle ) {
 						// 设备下线,尝试重新连接;
@@ -168,34 +168,34 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
 
 void CSATDevices::AddReticleDevices(std::string ip)
 {
-	STAndroid stAndroid;
-	stAndroid.nType = Reticle;
-	stAndroid.strName = ip;
-	stAndroid.ulOfflineTime = 0;
+	STDevice stDevice;
+	stDevice.nType = Reticle;
+	stDevice.strName = ip;
+	stDevice.ulOfflineTime = 0;
 
 	AutoThreadSection ats(&s_ThreadSection);
-	if (!IsDeviceExist(stAndroid))
-		s_vtAndroids.push_back(stAndroid);
+	if (!IsDeviceExist(stDevice))
+		s_vtDevices.push_back(stDevice);
 }
 
 void CSATDevices::AddVirtualDevices(std::string name)
 {
-	STAndroid stAndroid;
-	stAndroid.nType = Virtual;
-	stAndroid.strName = name;
-	stAndroid.ulOfflineTime = 0;
+	STDevice stDevice;
+	stDevice.nType = Virtual;
+	stDevice.strName = name;
+	stDevice.ulOfflineTime = 0;
 
 	AutoThreadSection ats(&s_ThreadSection);
-	if (!IsDeviceExist(stAndroid))
-		s_vtAndroids.push_back(stAndroid);
+	if (!IsDeviceExist(stDevice))
+		s_vtDevices.push_back(stDevice);
 }
 
-bool CSATDevices::IsDeviceExist(STAndroid &stAndroid)
+bool CSATDevices::IsDeviceExist(STDevice &stDevice)
 {
 	bool bExist = false;
-	std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
-	for(; it != s_vtAndroids.end(); it++ ) {
-		if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
+	std::vector<STDevice>::iterator it = s_vtDevices.begin();
+	for(; it != s_vtDevices.end(); it++ ) {
+		if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
 			bExist = true;
 			break;
 		}
@@ -204,40 +204,40 @@ bool CSATDevices::IsDeviceExist(STAndroid &stAndroid)
 	return bExist;
 }
 
-bool CSATDevices::IsAndroidOffline(STAndroid &stAndroid, std::vector<STAndroid> &vtAndroids )
+bool CSATDevices::IsAndroidOffline(STDevice &stDevice, std::vector<STDevice> &vtDevices )
 {
 	bool bOffline = true;
 	// 在当前设备列表查询;
-	std::vector<STAndroid>::iterator it = vtAndroids.begin();
-	for(; it != vtAndroids.end(); it++ ) {
-		if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
+	std::vector<STDevice>::iterator it = vtDevices.begin();
+	for(; it != vtDevices.end(); it++ ) {
+		if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
 			bOffline = false;
 			break;
 		}
 	}
 
 	if ( bOffline ) {
-		if ( stAndroid.ulOfflineTime == 0 ) {
+		if ( stDevice.ulOfflineTime == 0 ) {
 			// 首次检测到离线;
-			stAndroid.ulOfflineTime = GetTickCount64();
+			stDevice.ulOfflineTime = GetTickCount64();
 		}
 	} else {
 		// 若重新连接,重置离线时间;
-		if ( stAndroid.ulOfflineTime ) {
-			stAndroid.ulOfflineTime = 0;
+		if ( stDevice.ulOfflineTime ) {
+			stDevice.ulOfflineTime = 0;
 		}
 	}	
 
 	return bOffline;
 }
 
-bool CSATDevices::IsAndroidOffline(std::string strAndroidName, std::vector<STAndroid> &vtAndroids )
+bool CSATDevices::IsAndroidOffline(std::string strDeviceName, std::vector<STDevice> &vtDevices )
 {
 	bool bOffline = true;
 	// 在当前设备列表查询;
-	std::vector<STAndroid>::iterator it = vtAndroids.begin();
-	for(; it != vtAndroids.end(); it++ ) {
-		if ( _tcscmp(it->strName.c_str(), strAndroidName.c_str()) == 0 ) {
+	std::vector<STDevice>::iterator it = vtDevices.begin();
+	for(; it != vtDevices.end(); it++ ) {
+		if ( _tcscmp(it->strName.c_str(), strDeviceName.c_str()) == 0 ) {
 			bOffline = false;
 			break;
 		}
@@ -258,12 +258,12 @@ bool CSATDevices::IsAndroidOffline(std::string strAndroidName, std::vector<STAnd
 	return bOffline;
 }
 
-bool CSATDevices::IsNewAndroid(STAndroid &stAndroid)
+bool CSATDevices::IsNewAndroid(STDevice &stDevice)
 {
 	bool bNewAndroid = true;
-	std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
-	for(; it != s_vtAndroids.end(); it++ ) {
-		if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
+	std::vector<STDevice>::iterator it = s_vtDevices.begin();
+	for(; it != s_vtDevices.end(); it++ ) {
+		if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
 			bNewAndroid = false;
 			break;
 		}
@@ -272,23 +272,23 @@ bool CSATDevices::IsNewAndroid(STAndroid &stAndroid)
 	// 如果是新设备(一般是usb连接)
 	if ( bNewAndroid ) {
 		AutoThreadSection ats(&s_ThreadSection);
-		s_vtAndroids.push_back(stAndroid);
+		s_vtDevices.push_back(stDevice);
 	}
 
 	return bNewAndroid;
 }
 
-bool CSATDevices::IsNewUsbAndroid(STAndroid &stAndroid)
+bool CSATDevices::IsNewUsbAndroid(STDevice &stDevice)
 {
-	if ( stAndroid.nType != Usb )
+	if ( stDevice.nType != Usb )
 		return false;
 
 	bool bNewAndroid = true;
-	std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
-	for(; it != s_vtAndroids.end(); it++ ) {
+	std::vector<STDevice>::iterator it = s_vtDevices.begin();
+	for(; it != s_vtDevices.end(); it++ ) {
 		if ( it->nType != Usb )
 			continue;
-		if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
+		if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
 			bNewAndroid = false;
 			break;
 		}
@@ -297,13 +297,13 @@ bool CSATDevices::IsNewUsbAndroid(STAndroid &stAndroid)
 	// 如果是新设备(一般是usb连接)
 	if ( bNewAndroid ) {
 		AutoThreadSection ats(&s_ThreadSection);
-		s_vtAndroids.push_back(stAndroid);
+		s_vtDevices.push_back(stDevice);
 	}
 
 	return bNewAndroid;
 }
 
-void CSATDevices::GetCurrentDevices(std::vector<STAndroid> &vtAndroids)
+void CSATDevices::GetCurrentDevices(std::vector<STDevice> &vtDevices)
 {
 	std::string strLines = ExecuteCMD("adb devices");
 	std::vector<std::string> vtLine;
@@ -313,16 +313,16 @@ void CSATDevices::GetCurrentDevices(std::vector<STAndroid> &vtAndroids)
 	for ( std::vector<std::string>::iterator it = vtLine.begin(); it != vtLine.end(); it++ ) {
 		// 只获取在线设备,离线设备过滤;
 		if ( (npos = it->find("	device")) != std::string::npos ) {
-			STAndroid stAndroid;
+			STDevice stDevice;
 			if ( it->find(":5555") == std::string::npos )
-				stAndroid.nType = Usb;
+				stDevice.nType = Usb;
 			else
-				stAndroid.nType = Reticle;
-			stAndroid.ulOfflineTime = 0;
-			stAndroid.strName = it->substr(0, npos);
+				stDevice.nType = Reticle;
+			stDevice.ulOfflineTime = 0;
+			stDevice.strName = it->substr(0, npos);
 			// 新设备否(一般用于usb设备)
-			IsNewAndroid(stAndroid);
-			vtAndroids.push_back(stAndroid);
+			IsNewAndroid(stDevice);
+			vtDevices.push_back(stDevice);
 		}
 	}
 }
@@ -330,8 +330,8 @@ void CSATDevices::GetCurrentDevices(std::vector<STAndroid> &vtAndroids)
 void CSATDevices::ReConnectAllDevices()
 {
 	std::string str;
-	std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
-	for ( ;it != s_vtAndroids.end(); it++ ) {
+	std::vector<STDevice>::iterator it = s_vtDevices.begin();
+	for ( ;it != s_vtDevices.end(); it++ ) {
 		if ( it->nType == Reticle ) {
 			str = "adb connect ";
 			str.append(it->strName);

+ 23 - 15
SATService/SATService/SATDevices.h

@@ -11,18 +11,26 @@ enum DEVICE_TYPE{
 	Reticle
 };
 
-// 安卓设备adb连接:USB连接、网线连接;
-typedef struct __ANDROID__ 
+typedef struct __DEVICE__
 {
 	int 			nType;		// 0=虚拟, 1=usb, 2=网线;
 	std::string 	strName;	// 设备名称(IP:端口号);
-	/* 
-		离线时间,如果离线时间超过10分钟,删除该设备:
-		因为线程会一直尝试连接掉线设备,如果在指定时间内都未连接上,
-		认为设备被拨或IP变了, 只对网线连接Android有效;
-	*/
+	// 离线时刻:超过指定时长删除该设备,线程实时刷新离线时刻;
 	ULONGLONG		ulOfflineTime;
-}STAndroid, *pSTAndroid;
+}STDevice, *pSTDevice;
+
+// 安卓设备adb连接:USB连接、网线连接;
+typedef struct __DEVICE_INFO__ 
+{
+	STDevice		dev;
+	//////////////////////////////////////////////////////////////////////////
+	// 附加项;
+	int				nStatus;		// 设备状态:0表示空闲,1表示繁忙;
+	std::string		strSoftVersion;	// 软件版本;
+	std::string		strModel;		// 软件模型;
+	std::string		strHardVersion;	// 硬件版本;
+	std::string		strManu;		// 软件菜单;		
+}STDeviceInfo, *pSTDeviceInfo;
 
 class CSATDevices
 {
@@ -55,7 +63,7 @@ protected:
 	// 线程锁;
 	static ThreadSection s_ThreadSection;
 	// 安卓设备列表;
-	static std::vector<STAndroid> s_vtAndroids;	
+	static std::vector<STDevice> s_vtDevices;	
 
 	// 其他接口;
 public:
@@ -72,15 +80,15 @@ public:
 	static void AddReticleDevices(std::string ip);
 	static void AddVirtualDevices(std::string name);
 	// 设备是否存在;
-	static bool IsDeviceExist(STAndroid &stAndroid);
+	static bool IsDeviceExist(STDevice &stDevice);
 	// 设备是否下线;
-	static bool IsAndroidOffline(STAndroid &stAndroid, std::vector<STAndroid> &vtAndroids );
-	static bool IsAndroidOffline(std::string strAndroidName, std::vector<STAndroid> &vtAndroids );
+	static bool IsAndroidOffline(STDevice &stDevice, std::vector<STDevice> &vtDevices);
+	static bool IsAndroidOffline(std::string strDeviceName, std::vector<STDevice> &vtDevices );
 	// 是否新设备;
-	static bool IsNewAndroid(STAndroid &stAndroid);
-	static bool IsNewUsbAndroid(STAndroid &stAndroid);
+	static bool IsNewAndroid(STDevice &stDevice);
+	static bool IsNewUsbAndroid(STDevice &stDevice);
 	// 获取当前设备列表;
-	static void GetCurrentDevices(std::vector<STAndroid> &vtAndroids);
+	static void GetCurrentDevices(std::vector<STDevice> &vtDevices);
 	// 重连所有设备;
 	static void ReConnectAllDevices();