diff --git a/CMakeLists.txt b/CMakeLists.txt index 195c52d..445f825 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.26) -set(PROJECT_N demo) +set(PROJECT_N serialt) project(${PROJECT_N} VERSION 1.0) set(CMAKE_CXX_STANDARD 23) diff --git a/include/serial.h b/include/serial.h index b4e2abe..3e34f07 100644 --- a/include/serial.h +++ b/include/serial.h @@ -3,12 +3,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -62,7 +62,7 @@ class Serial { serialib ser; const char *endChar = "\r\n"; std::function logCallBack; - bool removeEcho = true; + bool removeEcho = true; // 剔除回显 public: Serial() = default; @@ -84,12 +84,6 @@ class Serial { bool IsOpen() { return ser.isDeviceOpen(); } - template - bool OpenDeviceDelay(T portName, unsigned int baudRate, int delay) { - std::this_thread::sleep_for(std::chrono::seconds(delay)); - return OpenDevice(portName, baudRate); - } - template bool OpenDevice(T portName, unsigned int bauds = 115200, int delayTime = 0) { @@ -131,6 +125,22 @@ class Serial { return GetAtResponse(command, timeout); } + template + bool GetAtUntilRepeat(T command, Args... args) { + std::stringstream ss; + int i = 0; + while (i++ < repeatTime) { + ss.str(""); + ss << "Count: " << i << "\n"; + Log(ss.str()); + std::this_thread::sleep_for(std::chrono::milliseconds(delayTime)); + if (GetAtUntil(command, args...)) + return true; + } + return false; + } + template std::expected GetAtResponse(T command, int timeout = 50) {