项目命名修改, 添加按次数重复发送函数
This commit is contained in:
parent
478421ee07
commit
e0094441c2
@ -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)
|
||||
|
@ -3,12 +3,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <expected>
|
||||
#include <format>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <ranges>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
@ -62,7 +62,7 @@ class Serial {
|
||||
serialib ser;
|
||||
const char *endChar = "\r\n";
|
||||
std::function<void(const std::string &)> logCallBack;
|
||||
bool removeEcho = true;
|
||||
bool removeEcho = true; // 剔除回显
|
||||
|
||||
public:
|
||||
Serial() = default;
|
||||
@ -84,12 +84,6 @@ class Serial {
|
||||
|
||||
bool IsOpen() { return ser.isDeviceOpen(); }
|
||||
|
||||
template <SupportString T>
|
||||
bool OpenDeviceDelay(T portName, unsigned int baudRate, int delay) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(delay));
|
||||
return OpenDevice(portName, baudRate);
|
||||
}
|
||||
|
||||
template <SupportString T>
|
||||
bool OpenDevice(T portName, unsigned int bauds = 115200,
|
||||
int delayTime = 0) {
|
||||
@ -131,6 +125,22 @@ class Serial {
|
||||
return GetAtResponse(command, timeout);
|
||||
}
|
||||
|
||||
template <int repeatTime = 5, int delayTime = 200, int timeout = 200,
|
||||
SupportString T, SupportString... Args>
|
||||
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<timeout>(command, args...))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <SupportString T>
|
||||
std::expected<std::string, SerialErrorCode>
|
||||
GetAtResponse(T command, int timeout = 50) {
|
||||
|
Loading…
Reference in New Issue
Block a user