Browse Source

修复设备重连问题;

scbc.sat2 5 years ago
parent
commit
5415415465
1 changed files with 17 additions and 2 deletions
  1. 17 2
      SATService/SATService/SATDevices.cpp

+ 17 - 2
SATService/SATService/SATDevices.cpp

@@ -160,6 +160,7 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
 				if ( GetTickCount64() - it->ulOfflineTime > GLOBAL::g_stSATConfig.dwAdbTimeout ) {
 				if ( GetTickCount64() - it->ulOfflineTime > GLOBAL::g_stSATConfig.dwAdbTimeout ) {
 					// 移除设备(需要线程加锁);
 					// 移除设备(需要线程加锁);
 					it = s_vtDevices.erase(it);
 					it = s_vtDevices.erase(it);
+					GLOBAL::WriteTextLog("移除设备->设备类型:%d, 设备名称:%s, 状态:%d", it->nType, it->strName.c_str(), it->nStatus);
 				} else {
 				} else {
 					if ( it->nType == SATDEV::Reticle ) {
 					if ( it->nType == SATDEV::Reticle ) {
 						if ( it->nStatus == SATDEV::Offline ) {
 						if ( it->nStatus == SATDEV::Offline ) {
@@ -167,12 +168,14 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
 							std::string str = "adb reconnect offline";
 							std::string str = "adb reconnect offline";
 							WinExec(str.c_str(), SW_HIDE);
 							WinExec(str.c_str(), SW_HIDE);
 							// 重连后,break此次循环;
 							// 重连后,break此次循环;
+							GLOBAL::WriteTextLog("offline重连->设备类型:%d, 设备名称:%s, 状态:%d, 命名:%s", it->nType, it->strName.c_str(), it->nStatus, str.c_str());
 							break;
 							break;
 						} 
 						} 
 						else if ( it->nStatus == SATDEV::Dropline ) {
 						else if ( it->nStatus == SATDEV::Dropline ) {
 							std::string str = "adb connect ";
 							std::string str = "adb connect ";
 							str.append(it->strName);
 							str.append(it->strName);
 							WinExec(str.c_str(), SW_HIDE);
 							WinExec(str.c_str(), SW_HIDE);
+							GLOBAL::WriteTextLog("dropline重连->设备类型:%d, 设备名称:%s, 状态:%d, 命名:%s", it->nType, it->strName.c_str(), it->nStatus, str.c_str());
 						}
 						}
 					} else if ( it->nType == SATDEV::Usb ) {
 					} else if ( it->nType == SATDEV::Usb ) {
 #if 0
 #if 0
@@ -180,11 +183,13 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
 						std::string str = "adb reconnect offline";
 						std::string str = "adb reconnect offline";
 						WinExec(str.c_str(), SW_HIDE);
 						WinExec(str.c_str(), SW_HIDE);
 #else
 #else
+						std::string str = "adb kill-server";
 						// 如果是usb的话,可能要kill-server,再全部重连接;
 						// 如果是usb的话,可能要kill-server,再全部重连接;
-						WinExec("adb kill-server", SW_HIDE);
+						WinExec(str.c_str(), SW_HIDE);
 						// 重连所有;
 						// 重连所有;
 						ReConnectAllDevices();
 						ReConnectAllDevices();
 						// 重连后,break此次循环;
 						// 重连后,break此次循环;
+						GLOBAL::WriteTextLog("usb重连->设备类型:%d, 设备名称:%s, 状态:%d, 命名:%s", it->nType, it->strName.c_str(), it->nStatus, str.c_str());
 #endif
 #endif
 						break;
 						break;
 					}
 					}
@@ -270,11 +275,14 @@ bool CSATDevices::IsDeviceExist(SATDEV::STDevice &stDevice)
 
 
 bool CSATDevices::IsDevicesOffline(SATDEV::STDevice &stDevice, std::vector<SATDEV::STDevice> &vtDevices )
 bool CSATDevices::IsDevicesOffline(SATDEV::STDevice &stDevice, std::vector<SATDEV::STDevice> &vtDevices )
 {
 {
+	bool bFound = false;
 	bool bOffline = true;
 	bool bOffline = true;
 	// 在当前设备列表查询;
 	// 在当前设备列表查询;
 	std::vector<SATDEV::STDevice>::iterator it = vtDevices.begin();
 	std::vector<SATDEV::STDevice>::iterator it = vtDevices.begin();
 	for(; it != vtDevices.end(); it++ ) {
 	for(; it != vtDevices.end(); it++ ) {
 		if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
 		if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
+			// 找到设备;
+			bFound = true;
 			// 同步状态;
 			// 同步状态;
 			stDevice.nStatus = it->nStatus;
 			stDevice.nStatus = it->nStatus;
 			// 设备是否offline或dropline;
 			// 设备是否offline或dropline;
@@ -291,11 +299,18 @@ bool CSATDevices::IsDevicesOffline(SATDEV::STDevice &stDevice, std::vector<SATDE
 				stDevice.nStatus = SATDEV::Dropline;
 				stDevice.nStatus = SATDEV::Dropline;
 			stDevice.ulOfflineTime = GetTickCount64();
 			stDevice.ulOfflineTime = GetTickCount64();
 		}
 		}
+
+		// 如果没找到设备,彻底离线;
+		if ( !bFound )
+			stDevice.nStatus = SATDEV::Dropline;
+
+		GLOBAL::WriteTextLog("离线->设备类型:%d, 设备名称:%s, 状态:%d", stDevice.nType, stDevice.strName.c_str(), stDevice.nStatus);
 	} else {
 	} else {
 		// 若重新连接,重置离线时间;
 		// 若重新连接,重置离线时间;
 		if ( stDevice.ulOfflineTime ) {
 		if ( stDevice.ulOfflineTime ) {
 			stDevice.nStatus = SATDEV::Online;
 			stDevice.nStatus = SATDEV::Online;
 			stDevice.ulOfflineTime = 0;
 			stDevice.ulOfflineTime = 0;
+			GLOBAL::WriteTextLog("重连成功->设备类型:%d, 设备名称:%s, 状态:%d", stDevice.nType, stDevice.strName.c_str(), stDevice.nStatus);
 		}
 		}
 	}	
 	}	
 
 
@@ -341,7 +356,7 @@ void CSATDevices::GetCurrentDevices(std::vector<SATDEV::STDevice> &vtDevices)
 		if ( it->find(":5555") != std::string::npos )
 		if ( it->find(":5555") != std::string::npos )
 			stDevice.nType = SATDEV::Reticle;
 			stDevice.nType = SATDEV::Reticle;
 		else if ( it->find(":5555") == std::string::npos )
 		else if ( it->find(":5555") == std::string::npos )
-			stDevice.nType = SATDEV::Reticle;
+			stDevice.nType = SATDEV::Usb;
 		stDevice.ulOfflineTime = 0;
 		stDevice.ulOfflineTime = 0;
 		// 设备状态;
 		// 设备状态;
 		if ( (npos = it->find("	device")) != std::string::npos )
 		if ( (npos = it->find("	device")) != std::string::npos )