|
@@ -1,8 +1,8 @@
|
|
|
#include "StdAfx.h"
|
|
|
#include "SATDevices.h"
|
|
|
|
|
|
-bool CSATDevices::s_bEnableAndroid = false;
|
|
|
-ULONGLONG CSATDevices::s_ulEraseDuration = 300000;
|
|
|
+bool CSATDevices::s_bEnableAndroid = true;
|
|
|
+ULONGLONG CSATDevices::s_ulEraseDuration = 30000;
|
|
|
ThreadSection CSATDevices::s_ThreadSection;
|
|
|
std::vector<STAndroid> CSATDevices::s_vtAndroids;
|
|
|
|
|
@@ -124,23 +124,30 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
|
|
|
|
|
|
// 刷新当前设备列表;
|
|
|
std::vector<STAndroid> vtAndroids;
|
|
|
+ printf("GetCurrentDevices\n");
|
|
|
// 获取当前设备列表;
|
|
|
GetCurrentDevices(vtAndroids);
|
|
|
|
|
|
// 遍历设备列表是否有下线设备;
|
|
|
std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
|
|
|
for ( ;it != s_vtAndroids.end(); ) {
|
|
|
+ if ( it->nType == Virtual ) {
|
|
|
+ it++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
if ( IsAndroidOffline(*it, vtAndroids) ) {
|
|
|
+ printf("IsAndroidOffline\n");
|
|
|
if ( GetTickCount64() - it->ulOfflineTime > s_ulEraseDuration ) {
|
|
|
// 移除设备(需要线程加锁);
|
|
|
it = s_vtAndroids.erase(it);
|
|
|
} else {
|
|
|
- if ( it->nType == 1 ) {
|
|
|
+ if ( it->nType == Reticle ) {
|
|
|
// 设备下线,尝试重新连接;
|
|
|
std::string str = "adb connect ";
|
|
|
str.append(it->strName);
|
|
|
WinExec(str.c_str(), SW_HIDE);
|
|
|
- } else {
|
|
|
+ } else if ( it->nType == Usb ) {
|
|
|
// 如果是usb的话,可能要kill-server,再全部重连接;
|
|
|
WinExec("adb kill-server", SW_HIDE);
|
|
|
// 重连所有;
|
|
@@ -150,9 +157,12 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
|
|
|
it++;
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ it++;
|
|
|
}
|
|
|
- } while (WaitForSingleObject(that->m_hEvent, 200) == WAIT_TIMEOUT);
|
|
|
+ } while (WaitForSingleObject(that->m_hEvent, 1000) == WAIT_TIMEOUT);
|
|
|
|
|
|
+ printf("end thread\n");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -207,16 +217,16 @@ bool CSATDevices::IsAndroidOffline(STAndroid &stAndroid, std::vector<STAndroid>
|
|
|
}
|
|
|
|
|
|
if ( bOffline ) {
|
|
|
- if ( it->ulOfflineTime == 0 ) {
|
|
|
+ if ( stAndroid.ulOfflineTime == 0 ) {
|
|
|
// 首次检测到离线;
|
|
|
- it->ulOfflineTime = GetTickCount64();
|
|
|
+ stAndroid.ulOfflineTime = GetTickCount64();
|
|
|
}
|
|
|
} else {
|
|
|
// 若重新连接,重置离线时间;
|
|
|
- if ( it->ulOfflineTime ) {
|
|
|
- it->ulOfflineTime = 0;
|
|
|
+ if ( stAndroid.ulOfflineTime ) {
|
|
|
+ stAndroid.ulOfflineTime = 0;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
return bOffline;
|
|
|
}
|
|
@@ -262,8 +272,32 @@ bool CSATDevices::IsNewAndroid(STAndroid &stAndroid)
|
|
|
// 如果是新设备(一般是usb连接)
|
|
|
if ( bNewAndroid ) {
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
- if (!IsDeviceExist(stAndroid))
|
|
|
- s_vtAndroids.push_back(stAndroid);
|
|
|
+ s_vtAndroids.push_back(stAndroid);
|
|
|
+ }
|
|
|
+
|
|
|
+ return bNewAndroid;
|
|
|
+}
|
|
|
+
|
|
|
+bool CSATDevices::IsNewUsbAndroid(STAndroid &stAndroid)
|
|
|
+{
|
|
|
+ if ( stAndroid.nType != Usb )
|
|
|
+ return false;
|
|
|
+
|
|
|
+ bool bNewAndroid = true;
|
|
|
+ std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
|
|
|
+ for(; it != s_vtAndroids.end(); it++ ) {
|
|
|
+ if ( it->nType != Usb )
|
|
|
+ continue;
|
|
|
+ if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
|
|
|
+ bNewAndroid = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是新设备(一般是usb连接)
|
|
|
+ if ( bNewAndroid ) {
|
|
|
+ AutoThreadSection ats(&s_ThreadSection);
|
|
|
+ s_vtAndroids.push_back(stAndroid);
|
|
|
}
|
|
|
|
|
|
return bNewAndroid;
|
|
@@ -278,17 +312,17 @@ void CSATDevices::GetCurrentDevices(std::vector<STAndroid> &vtAndroids)
|
|
|
// 需要在此处过滤掉offline的usb设备,不要加入vt中;
|
|
|
for ( std::vector<std::string>::iterator it = vtLine.begin(); it != vtLine.end(); it++ ) {
|
|
|
// 只获取在线设备,离线设备过滤;
|
|
|
- if ( (npos = it->find("devices")) != std::string::npos ) {
|
|
|
+ if ( (npos = it->find(" device")) != std::string::npos ) {
|
|
|
STAndroid stAndroid;
|
|
|
if ( it->find(":5555") == std::string::npos )
|
|
|
- stAndroid.nType = 0;
|
|
|
+ stAndroid.nType = Usb;
|
|
|
else
|
|
|
- stAndroid.nType = 1;
|
|
|
+ stAndroid.nType = Reticle;
|
|
|
stAndroid.ulOfflineTime = 0;
|
|
|
stAndroid.strName = it->substr(0, npos);
|
|
|
// 新设备否(一般用于usb设备)
|
|
|
- if ( !IsNewAndroid(stAndroid) )
|
|
|
- vtAndroids.push_back(stAndroid);
|
|
|
+ IsNewAndroid(stAndroid);
|
|
|
+ vtAndroids.push_back(stAndroid);
|
|
|
}
|
|
|
}
|
|
|
}
|