实现串口监控功能,重构 ComKit::Work 方法以支持指定端口

This commit is contained in:
JIe
2024-11-07 17:35:02 +08:00
parent cea5209222
commit 7316c326d0
7 changed files with 365 additions and 312 deletions

28
include/ComWatch.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef COMWATCH_H
#include "serial.h"
#include "spdlog/spdlog.h"
#include <functional>
#include <string>
#include <mutex>
#include <thread>
enum class SIGNAL_TYPE{
REMOVE_,
ADD_,
};
class SerialWatch {
private:
std::function<void(const std::string&, SIGNAL_TYPE type)> callback;
std::jthread work_thread;
std::stop_source s;
std::mutex m;
public:
SerialWatch() = default;
~SerialWatch();
void set_callback(std::function<void(const std::string&, SIGNAL_TYPE type)> func);
void work();
};
#endif // !COMWATCH_H