优化Until逻辑
This commit is contained in:
		@@ -268,6 +268,7 @@ namespace serial {
 | 
				
			|||||||
			auto endTime = std::chrono::system_clock::now() +
 | 
								auto endTime = std::chrono::system_clock::now() +
 | 
				
			||||||
				std::chrono::milliseconds(timeout);
 | 
									std::chrono::milliseconds(timeout);
 | 
				
			||||||
			ser.flushReceiver();
 | 
								ser.flushReceiver();
 | 
				
			||||||
 | 
								std::string resp;
 | 
				
			||||||
			std::string reallyCommand = std::string(command) + endChar;
 | 
								std::string reallyCommand = std::string(command) + endChar;
 | 
				
			||||||
			ser.writeString(reallyCommand.c_str());
 | 
								ser.writeString(reallyCommand.c_str());
 | 
				
			||||||
			Log("Send : " + reallyCommand);
 | 
								Log("Send : " + reallyCommand);
 | 
				
			||||||
@@ -278,8 +279,10 @@ namespace serial {
 | 
				
			|||||||
				auto size = ser.readBytes(buffer.get(), availableSize, timeout);
 | 
									auto size = ser.readBytes(buffer.get(), availableSize, timeout);
 | 
				
			||||||
				buffer[size] = '\0';
 | 
									buffer[size] = '\0';
 | 
				
			||||||
				auto str = std::string(buffer.get());
 | 
									auto str = std::string(buffer.get());
 | 
				
			||||||
				if (size > 0)
 | 
									if (size > 0){
 | 
				
			||||||
					Log("Receive: " + str);
 | 
										Log("Receive: " + str);
 | 
				
			||||||
 | 
										resp += str;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				if (((str.find(expect) != std::string::npos) && ...)) {
 | 
									if (((str.find(expect) != std::string::npos) && ...)) {
 | 
				
			||||||
					return true;
 | 
										return true;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -307,7 +310,7 @@ namespace serial {
 | 
				
			|||||||
				resp += str;
 | 
									resp += str;
 | 
				
			||||||
				if (size > 0)
 | 
									if (size > 0)
 | 
				
			||||||
					Log("Receive: " + str);
 | 
										Log("Receive: " + str);
 | 
				
			||||||
				if (((str.find(expect) != std::string::npos) && ...)) {
 | 
									if (((resp.find(expect) != std::string::npos) && ...)) {
 | 
				
			||||||
					return resp;
 | 
										return resp;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user