sat23 4 жил өмнө
parent
commit
820a6ef4c5

+ 5 - 5
SerialWatch/SerialWatch/SerialWatch.cpp

@@ -39,7 +39,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 			// 开始监听;
 			StartMonitor();
 
-			//RTK_USBUpgrade(0x1B); // ESC键升级;
+			RTK_USBUpgrade(0x1B); // ESC键升级;
 			//RTK_USBUpgrade(0x09); // TAB键升级;
 
 			//Sleep(30000);
@@ -131,9 +131,9 @@ SERIALWATCH_API bool RTK_USBUpgrade(BYTE byKey)
 				DWORD dwTickCount = GetTickCount();
 				while ( TRUE ) {
 					// 连续发送150次按键;
-					SendCommand((LPCTSTR)&byKey, 150, 0);
+					SendCommand((LPCTSTR)&byKey, 10, 0);
 					if ( byKey == 0x1B ){ // ESC键;
-						if ( WatchWord(_T("Realtek>"), 150) ) {
+						if ( WatchWord(_T("Realtek>"), 120) ) {
 #ifdef _DEBUG
 							printf("找到关键字\n");
 #endif
@@ -143,7 +143,7 @@ SERIALWATCH_API bool RTK_USBUpgrade(BYTE byKey)
 							break;
 						}
 					} else if (byKey == 0x09) { // TAB键;
-						if ( WatchWord(_T("loader start!"), 150) ) {
+						if ( WatchWord(_T("loader start!"), 120) ) {
 #ifdef _DEBUG
 							printf("找到关键字\n");
 #endif
@@ -153,7 +153,7 @@ SERIALWATCH_API bool RTK_USBUpgrade(BYTE byKey)
 					}
 
 					// 超过1分钟,退出;
-					if ( GetTickCount() - dwTickCount > 60000 )
+					if ( GetTickCount() - dwTickCount > 15000 )
 						break;
 				}
 			}				

+ 14 - 4
SerialWatch/SerialWatch/SynSerial.cpp

@@ -454,18 +454,28 @@ DWORD CSynSerial::ThreadWatch(LPVOID lpVoid)
 		memset(szValue, 0, 1024);
 		if ( (dwRealRead = pthat->ReadComm((BYTE*)szValue, 1024)) > 0) {
 			AutoThreadSection aSection(&s_csClearBuffer);
+
+#ifdef _DEBUG
 			OutputDebugString(_T("内容:"));
 			OutputDebugString(szValue);
 			OutputDebugString(_T("\n"));
+#endif
 
 #if 1
-			pthat->SwapBuffers(szValue, dwRealRead);			
+			if ( pthat->m_strbuffer.length() > BUFFER_LEN * 10 ) {
+				int nIndex = 0;
+				pthat->m_strbuffer = pthat->m_strbuffer.substr(BUFFER_LEN * 9);
+				if ( (nIndex = pthat->m_strbuffer.find_first_of('\r')) != std::string::npos )
+					pthat->m_strbuffer = pthat->m_strbuffer.substr(nIndex+1);
+			}
+
+			pthat->m_strbuffer.append(szValue, dwRealRead);		
 #else // 这里如果不及时清除,内存越来越大;
 			pthat->m_strbuffer.append(szValue, dwRealRead);
 #endif
 		}
 
-	} while ( WaitForSingleObject(pthat->m_hEvent, 50) == WAIT_TIMEOUT );
+	} while ( WaitForSingleObject(pthat->m_hEvent, 30) == WAIT_TIMEOUT );
 
 #ifdef _DEBUG
 	printf("线程结束\n");
@@ -477,13 +487,13 @@ DWORD CSynSerial::ThreadWatch(LPVOID lpVoid)
 bool CSynSerial::FindWord(std::string strWord, int nWatchTime )
 {
 	bool found = false;
-	int nSize = nWatchTime/50;
+	int nSize = nWatchTime/30;
 	for ( int i = 0; i < nSize; i++ ) {
 		if ( m_strbuffer.find(strWord) != std::string::npos ) {
 			found = true;
 			break;
 		}
-		Sleep(10);
+		Sleep(30);
 	}
 
 	return found;