diff --git a/include/serial.h b/include/serial.h index 1745e57..364389a 100644 --- a/include/serial.h +++ b/include/serial.h @@ -292,6 +292,27 @@ namespace serial { return false; } + template + bool ReadUntil(Args... args){ + auto end_time = std::chrono::system_clock::now() + 1s; + std::string resp; + while(std::chrono::system_clock::now() < end_time){ + std::this_thread::sleep_for(10ms); + auto available_size = ser.available(); + auto buffer = std::unique_ptr{available_size + 1}; + auto read_size = ser.readBytes(buffer.get(), available_size, timeout); + buffer[read_size] = '\0'; + auto str = std::string(buffer.get()); + resp += str; + if(read_size > 0){ + Log("Read: " + str); + } + if(((resp.find(args) != std::string::npos) && ...)){ + return true; + } + } + } + template std::string GetAtUntilAndReturn(T command, Args... expect) {