From 7316c326d0045cda017657bd72095ff84ba2960c Mon Sep 17 00:00:00 2001 From: JIe Date: Thu, 7 Nov 2024 17:35:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=B8=B2=E5=8F=A3=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=87=8D=E6=9E=84=20ComKit?= =?UTF-8?q?::Work=20=E6=96=B9=E6=B3=95=E4=BB=A5=E6=94=AF=E6=8C=81=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/ComKit.h | 2 +- include/ComWatch.h | 28 ++ include/serial.h | 518 +++++++++++++++++------------------ src/ComKit.cc | 37 +-- src/ComWatch.cc | 45 +++ src/main.cc | 20 ++ third/imgui/imgui_helper.cpp | 27 -- 7 files changed, 365 insertions(+), 312 deletions(-) create mode 100644 include/ComWatch.h create mode 100644 src/ComWatch.cc diff --git a/include/ComKit.h b/include/ComKit.h index 89349e9..b9cc552 100644 --- a/include/ComKit.h +++ b/include/ComKit.h @@ -38,7 +38,7 @@ class ComKit { static std::vector *GetAllComPortNames(); static void Start(std::string, std::string); static void End(); - static void Work(); + static void Work(const std::string& port_name); static bool ChangeComPortNumber(const std::string &oldPortName, const std::string &newPortName); static std::vector watchingComPort; diff --git a/include/ComWatch.h b/include/ComWatch.h new file mode 100644 index 0000000..134f1c3 --- /dev/null +++ b/include/ComWatch.h @@ -0,0 +1,28 @@ +#ifndef COMWATCH_H +#include "serial.h" +#include "spdlog/spdlog.h" +#include +#include +#include +#include + +enum class SIGNAL_TYPE{ + REMOVE_, + ADD_, +}; + +class SerialWatch { +private: + std::function callback; + std::jthread work_thread; + std::stop_source s; + std::mutex m; +public: + SerialWatch() = default; + ~SerialWatch(); + void set_callback(std::function func); + void work(); + +}; + +#endif // !COMWATCH_H \ No newline at end of file diff --git a/include/serial.h b/include/serial.h index 6ddc17f..c2a5dfc 100644 --- a/include/serial.h +++ b/include/serial.h @@ -22,300 +22,298 @@ namespace ranges = std::ranges; namespace views = std::views; namespace serial { - template struct _StrongType {}; +template struct _StrongType {}; - template struct _StrongType { - using Type = T; - }; +template struct _StrongType { + using Type = T; +}; - template struct _StrongType { - using Type = decltype(true ? std::declval() : std::declval()); - }; +template struct _StrongType { + using Type = decltype(true ? std::declval() : std::declval()); +}; - template struct _StrongType { - using Type = - typename _StrongType::Type>::Type; - }; +template struct _StrongType { + using Type = + typename _StrongType::Type>::Type; +}; - template - using _strongType_t = typename _StrongType::Type; +template +using _strongType_t = typename _StrongType::Type; - template struct _IsCastable {}; +template struct _IsCastable {}; - template struct _IsCastable { - static constexpr bool value = true; - using Type = T; - }; +template struct _IsCastable { + static constexpr bool value = true; + using Type = T; +}; - template struct _IsCastable { - using __TRUE = char; - using __FALSE = struct { - char _[2]; - }; - static consteval __TRUE __TEST(U); - static consteval __FALSE __TEST(...); - static constexpr bool value = - sizeof(__TEST(std::declval())) == sizeof(__TRUE); - using Type = std::conditional_t; - }; +template struct _IsCastable { + using __TRUE = char; + using __FALSE = struct { + char _[2]; + }; + static consteval __TRUE __TEST(U); + static consteval __FALSE __TEST(...); + static constexpr bool value = + sizeof(__TEST(std::declval())) == sizeof(__TRUE); + using Type = std::conditional_t; +}; - template struct _IsCastable { - static constexpr bool value = - _IsCastable::Type>::value; - using Type = - std::conditional_t::Type, void>; - }; +template struct _IsCastable { + static constexpr bool value = + _IsCastable::Type>::value; + using Type = + std::conditional_t::Type, void>; +}; - template - concept _SupportString = requires { - _IsCastable::value; - }; - template <_SupportString T> [[maybe_unused]] std::string _to_string(T&& str) { - if constexpr (std::is_same_v, std::string>) { - return str; - } - else if constexpr (std::is_same_v, std::string_view>) { - return std::move(std::string(str.data())); - } - else if constexpr (std::is_same_v, const char*>) { - return std::string(str); - } - } +template +concept _SupportString = requires { + _IsCastable::value; +}; +template <_SupportString T> [[maybe_unused]] std::string _to_string(T &&str) { + if constexpr (std::is_same_v, std::string>) { + return str; + } else if constexpr (std::is_same_v, std::string_view>) { + return std::move(std::string(str.data())); + } else if constexpr (std::is_same_v, const char *>) { + return std::string(str); + } +} - static std::vector GetUsbPorts() { +static std::vector GetUsbPorts() { #if defined(_WIN32) || defined(_WIN64) - std::vector portArray; - std::string comname; - std::string showname; - ranges::for_each(views::iota(1, 256), [&](int i) { - std::format_to(std::back_inserter(comname), "\\\\.\\COM{}", i); - std::format_to(std::back_inserter(showname), "COM{}", i); - const HANDLE m_handle = ::CreateFileA( - comname.c_str(), static_cast(GENERIC_WRITE) | GENERIC_READ, - 0U, nullptr, OPEN_EXISTING, 0U, nullptr); - if (m_handle != INVALID_HANDLE_VALUE) { - portArray.push_back(showname); - CloseHandle(m_handle); - } - comname.clear(); - showname.clear(); - }); - return portArray; + std::vector portArray; + std::string comname; + std::string showname; + ranges::for_each(views::iota(1, 256), [&](int i) { + std::format_to(std::back_inserter(comname), "\\\\.\\COM{}", i); + std::format_to(std::back_inserter(showname), "COM{}", i); + const HANDLE m_handle = ::CreateFileA( + comname.c_str(), static_cast(GENERIC_WRITE) | GENERIC_READ, + 0U, nullptr, OPEN_EXISTING, 0U, nullptr); + if (m_handle != INVALID_HANDLE_VALUE) { + portArray.emplace_back(showname); + CloseHandle(m_handle); + } else if(GetLastError() == ERROR_ACCESS_DENIED){ + portArray.emplace_back(showname); + } + comname.clear(); + showname.clear(); + }); + return portArray; #elif defined(__linux__) #endif - } +} - enum class [[maybe_unused]] SerialErrorCode { - SUCCESS, - TIMEOUT, - SETTIMEOUTERROR, - WRITEINGERROR, - READINGERROR, - }; +enum class [[maybe_unused]] SerialErrorCode { + SUCCESS, + TIMEOUT, + SETTIMEOUTERROR, + WRITEINGERROR, + READINGERROR, +}; - enum SerialDataBits { - DATABIT_5 = 0, - DATABIT_6, - DATABIT_7, - DATABIT_8, - DATABIT_16, - }; - enum SerialStopBits { - STOPBIT_1 = 0, - STOPBIT_1_5, - STOPBIT_2, - }; - enum SerialParity { - SERIAL_PARITY_NONE = 0, - SERIAL_PARITY_EVEN, - SERIAL_PARITY_ODD, - SERIAL_PARITY_MARK, - SERIAL_PARITY_SPACE, - }; +enum SerialDataBits { + DATABIT_5 = 0, + DATABIT_6, + DATABIT_7, + DATABIT_8, + DATABIT_16, +}; +enum SerialStopBits { + STOPBIT_1 = 0, + STOPBIT_1_5, + STOPBIT_2, +}; +enum SerialParity { + SERIAL_PARITY_NONE = 0, + SERIAL_PARITY_EVEN, + SERIAL_PARITY_ODD, + SERIAL_PARITY_MARK, + SERIAL_PARITY_SPACE, +}; - class Serial { - private: - serialib ser; - const char* endChar = "\r\n"; - std::function logCallBack; - bool removeEcho = true; // 剔除回显 +class Serial { + private: + serialib ser; + const char *endChar = "\r\n"; + std::function logCallBack; + bool removeEcho = true; // 剔除回显 - public: - Serial() = default; - ~Serial() { CloseDevice(); } - Serial(const Serial& other) = delete; - Serial(Serial&& other) = delete; - Serial& operator=(const Serial& other) = delete; - Serial& operator=(Serial&& other) = delete; + public: + Serial() = default; + ~Serial() { CloseDevice(); } + Serial(const Serial &other) = delete; + Serial(Serial &&other) = delete; + Serial &operator=(const Serial &other) = delete; + Serial &operator=(Serial &&other) = delete; - auto SetRemoveEcho(bool remove) { removeEcho = remove; } - auto SetDtr(bool flag) { return flag ? ser.setDTR() : ser.clearDTR(); } - auto SetRts(bool flag) { return flag ? ser.setRTS() : ser.clearRTS(); } + auto SetRemoveEcho(bool remove) { removeEcho = remove; } + auto SetDtr(bool flag) { return flag ? ser.setDTR() : ser.clearDTR(); } + auto SetRts(bool flag) { return flag ? ser.setRTS() : ser.clearRTS(); } - static std::string GetTimeNow() { - auto now = std::chrono::system_clock::now(); - auto now_c = std::chrono::system_clock::to_time_t(now); - char buffer[32]; - auto _ = ctime_s(buffer, 32, &now_c); - return buffer; - } + static std::string GetTimeNow() { + auto now = std::chrono::system_clock::now(); + auto now_c = std::chrono::system_clock::to_time_t(now); + char buffer[32]; + auto _ = ctime_s(buffer, 32, &now_c); + return buffer; + } - bool IsOpen() { return ser.isDeviceOpen(); } + bool IsOpen() { return ser.isDeviceOpen(); } - template <_SupportString T> - bool OpenDevice(T portName, unsigned int bauds = 115200, int delayTime = 0, - SerialDataBits dataBits = SerialDataBits::DATABIT_8, - SerialStopBits stopBits = SerialStopBits::STOPBIT_1, - SerialParity parity = SerialParity::SERIAL_PARITY_NONE) { + template <_SupportString T> + bool OpenDevice(T portName, unsigned int bauds = 115200, int delayTime = 0, + SerialDataBits dataBits = SerialDataBits::DATABIT_8, + SerialStopBits stopBits = SerialStopBits::STOPBIT_1, + SerialParity parity = SerialParity::SERIAL_PARITY_NONE) { #if defined(_WIN32) || defined(__WIN64) - std::string reallyPortName; - std::format_to(std::back_inserter(reallyPortName), "\\\\.\\{}", - portName); + std::string reallyPortName; + std::format_to(std::back_inserter(reallyPortName), "\\\\.\\{}", + portName); #elif defined(__linux__) - std::string reallyPortName = std::string(portName); + std::string reallyPortName = std::string(portName); #endif - std::this_thread::sleep_for(std::chrono::milliseconds(delayTime)); - if (ser.isDeviceOpen()) - ser.closeDevice(); + std::this_thread::sleep_for(std::chrono::milliseconds(delayTime)); + if (ser.isDeviceOpen()) + ser.closeDevice(); - int code = ser.openDevice(reallyPortName.c_str(), bauds, - static_cast<::SerialDataBits>(dataBits), - static_cast<::SerialParity>(parity), - static_cast<::SerialStopBits>(stopBits)); - if (code == 1) { - return true; - } - else { - return false; - } - } + int code = ser.openDevice(reallyPortName.c_str(), bauds, + static_cast<::SerialDataBits>(dataBits), + static_cast<::SerialParity>(parity), + static_cast<::SerialStopBits>(stopBits)); + if (code == 1) { + return true; + } else { + return false; + } + } - void Log(const std::string& log) const { - if (logCallBack) { - auto msg = GetTimeNow() + " " + log; - logCallBack(msg); - } - } + void Log(const std::string &log) const { + if (logCallBack) { + auto msg = GetTimeNow() + " " + log; + logCallBack(msg); + } + } - void - SetLogCallBack(const std::function& callBack) { - logCallBack = callBack; - } - void CloseDevice() { - if (!ser.isDeviceOpen()) - return; - ser.closeDevice(); - } + void + SetLogCallBack(const std::function &callBack) { + logCallBack = callBack; + } + void CloseDevice() { + if (!ser.isDeviceOpen()) + return; + ser.closeDevice(); + } - template <_SupportString T> - std::expected - DelayGetResponse(int delayTime, T command, int timeout = 50) { - std::this_thread::sleep_for(std::chrono::milliseconds(delayTime)); - return GetAtResponse(command, timeout); - } + template <_SupportString T> + std::expected + DelayGetResponse(int delayTime, T command, int timeout = 50) { + std::this_thread::sleep_for(std::chrono::milliseconds(delayTime)); + 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 + 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 <_SupportString T> - std::expected - GetAtResponse(T command, int timeout = 50) { - ser.flushReceiver(); - std::string reallyCommand = std::string(command) + endChar; - ser.writeString(reallyCommand.c_str()); - Log("Send: " + reallyCommand); - std::this_thread::sleep_for(10ms); - auto availableSize = ser.available(); - auto buffer = std::make_unique(availableSize + 1); - std::memset(buffer.get(), 0, availableSize); - auto size = ser.readBytes(buffer.get(), availableSize, timeout); + template <_SupportString T> + std::expected + GetAtResponse(T command, int timeout = 50) { + ser.flushReceiver(); + std::string reallyCommand = std::string(command) + endChar; + ser.writeString(reallyCommand.c_str()); + Log("Send: " + reallyCommand); + std::this_thread::sleep_for(10ms); + auto availableSize = ser.available(); + auto buffer = std::make_unique(availableSize + 1); + std::memset(buffer.get(), 0, availableSize); + auto size = ser.readBytes(buffer.get(), availableSize, timeout); - if (size > 0) { - buffer[size] = '\0'; - std::string response = std::string(buffer.get()); - Log("Receive: " + response); - if (removeEcho) - response.replace(0, reallyCommand.length(), ""); - return response; - } - return std::unexpected(SerialErrorCode::TIMEOUT); - } + if (size > 0) { + buffer[size] = '\0'; + std::string response = std::string(buffer.get()); + Log("Receive: " + response); + if (removeEcho) + response.replace(0, reallyCommand.length(), ""); + return response; + } + return std::unexpected(SerialErrorCode::TIMEOUT); + } - template <_SupportString T> - auto GetAtResponseRepeat(T command, int timeout = 200, int repeatTime = 1) - -> void { - for (int i = 0; i <= repeatTime; i++) { - auto _ = GetAtResponse(command, timeout); - } - } + template <_SupportString T> + auto GetAtResponseRepeat(T command, int timeout = 200, int repeatTime = 1) + -> void { + for (int i = 0; i <= repeatTime; i++) { + auto _ = GetAtResponse(command, timeout); + } + } - template - bool GetAtUntil(T command, Args... expect) { - auto endTime = std::chrono::system_clock::now() + - std::chrono::milliseconds(timeout); - ser.flushReceiver(); - std::string resp; - std::string reallyCommand = std::string(command) + endChar; - ser.writeString(reallyCommand.c_str()); - Log("Send : " + reallyCommand); - while (std::chrono::system_clock::now() < endTime) { - std::this_thread::sleep_for(10ms); - auto availableSize = ser.available(); - auto buffer = std::make_unique(availableSize + 1); - auto size = ser.readBytes(buffer.get(), availableSize, timeout); - buffer[size] = '\0'; - auto str = std::string(buffer.get()); - if (size > 0){ - Log("Receive: " + str); - resp += str; - } - if (((str.find(expect) != std::string::npos) && ...)) { - return true; - } - } - return false; - } + template + bool GetAtUntil(T command, Args... expect) { + auto endTime = std::chrono::system_clock::now() + + std::chrono::milliseconds(timeout); + ser.flushReceiver(); + std::string resp; + std::string reallyCommand = std::string(command) + endChar; + ser.writeString(reallyCommand.c_str()); + Log("Send : " + reallyCommand); + while (std::chrono::system_clock::now() < endTime) { + std::this_thread::sleep_for(10ms); + auto availableSize = ser.available(); + auto buffer = std::make_unique(availableSize + 1); + auto size = ser.readBytes(buffer.get(), availableSize, timeout); + buffer[size] = '\0'; + auto str = std::string(buffer.get()); + if (size > 0) { + Log("Receive: " + str); + resp += str; + } + if (((str.find(expect) != std::string::npos) && ...)) { + return true; + } + } + return false; + } - template - std::string GetAtUntilAndReturn(T command, Args... expect) - { - auto endTime = std::chrono::system_clock::now() + - std::chrono::milliseconds(timeout); - ser.flushReceiver(); - std::string resp = ""; - std::string reallyCommand = std::string(command) + endChar; - ser.writeString(reallyCommand.c_str()); - Log("Send : " + reallyCommand); - while (std::chrono::system_clock::now() < endTime) { - std::this_thread::sleep_for(10ms); - auto availableSize = ser.available(); - auto buffer = std::make_unique(availableSize + 1); - auto size = ser.readBytes(buffer.get(), availableSize, timeout); - buffer[size] = '\0'; - auto str = std::string(buffer.get()); - resp += str; - if (size > 0) - Log("Receive: " + str); - if (((resp.find(expect) != std::string::npos) && ...)) { - return resp; - } - } - return resp; - } - }; + template + std::string GetAtUntilAndReturn(T command, Args... expect) { + auto endTime = std::chrono::system_clock::now() + + std::chrono::milliseconds(timeout); + ser.flushReceiver(); + std::string resp = ""; + std::string reallyCommand = std::string(command) + endChar; + ser.writeString(reallyCommand.c_str()); + Log("Send : " + reallyCommand); + while (std::chrono::system_clock::now() < endTime) { + std::this_thread::sleep_for(10ms); + auto availableSize = ser.available(); + auto buffer = std::make_unique(availableSize + 1); + auto size = ser.readBytes(buffer.get(), availableSize, timeout); + buffer[size] = '\0'; + auto str = std::string(buffer.get()); + resp += str; + if (size > 0) + Log("Receive: " + str); + if (((resp.find(expect) != std::string::npos) && ...)) { + return resp; + } + } + return resp; + } +}; } // namespace serial #endif // SERIAL_H diff --git a/src/ComKit.cc b/src/ComKit.cc index 257f494..b0d425a 100644 --- a/src/ComKit.cc +++ b/src/ComKit.cc @@ -136,32 +136,21 @@ void ComKit::Start(std::string watchingPort, std::string input_commands) { commands = std::move(Split(input_commands)); isWorking = true; } -void ComKit::Work() { +void ComKit::Work(const std::string &port_name) { if (isWorking) { - std::thread([]() { - std::lock_guard lock(m); - auto currentPortStructures = GetAllComPortNames(); - std::vector currentPorts; - for (auto s : *currentPortStructures) { - currentPorts.emplace_back(s.comPortName); - } - for (auto &port : watchingComPort) { - if (std::find(currentPorts.begin(), currentPorts.end(), port) != - currentPorts.end()) { - spdlog::info( - std::format("Start Work With Port [{}]", port)); - device.OpenDevice(port); - for (auto &command : commands) { - spdlog::info(std::format("Send Command: {}", command)); - std::this_thread::sleep_for(50ms); - auto resp = device.GetAtUntilAndReturn(command, "OK"); - spdlog::info(std::format("resp: {}", resp)); - FlushLog(); - } - device.CloseDevice(); + if (ranges::find(watchingComPort, port_name) != watchingComPort.end()) + std::thread([&port_name]() { + spdlog::info(std::format("start working with [{}]", port_name)); + device.OpenDevice(port_name); + for (auto &command : commands) { + spdlog::info(std::format("Send Command: {}", command)); + std::this_thread::sleep_for(50ms); + auto resp = device.GetAtUntilAndReturn(command, "OK"); + spdlog::info(std::format("resp: {}", resp)); + FlushLog(); } - } - }).detach(); + device.CloseDevice(); + }).detach(); } } diff --git a/src/ComWatch.cc b/src/ComWatch.cc new file mode 100644 index 0000000..55399ac --- /dev/null +++ b/src/ComWatch.cc @@ -0,0 +1,45 @@ +#include "ComWatch.h" +#include +#include +#include +namespace ranges = std::ranges; +namespace views = std::ranges::views; +using namespace std::literals::chrono_literals; +SerialWatch::~SerialWatch() { + s.request_stop(); + if (work_thread.joinable()) { + work_thread.join(); + } +} + +void SerialWatch::set_callback( + std::function func) { + this->callback = func; +} + +void SerialWatch::work() { + this->work_thread = std::jthread( + [this](std::stop_token token) { + std::vector pre_ports; + while (!token.stop_requested()) { + auto curr_ports = serial::GetUsbPorts(); + for (auto &&port : pre_ports) { + if (ranges::find(curr_ports, port) == curr_ports.end()) { + std::lock_guard lock(m); + if (callback) + callback(port, SIGNAL_TYPE::REMOVE_); + } + } + for (auto &&port : curr_ports) { + if (ranges::find(pre_ports, port) == pre_ports.end()) { + std::lock_guard lock(m); + if (callback) + callback(port, SIGNAL_TYPE::ADD_); + } + } + pre_ports = std::move(curr_ports); + std::this_thread::sleep_for(500ms); + } + }, + s.get_token()); +} \ No newline at end of file diff --git a/src/main.cc b/src/main.cc index a5c1201..3d5f585 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,4 +1,5 @@ #include "ComKit.h" +#include "ComWatch.h" #include "imgui_helper.h" #include "imgui_stdlib.h" #include "spdlog/sinks/basic_file_sink.h" @@ -67,6 +68,25 @@ int main(int argc, char **) { filterComName = config.at("ComPorts").as_string(); inputCommands = config.at("Commands").as_string(); } + SerialWatch watcher; + watcher.set_callback([](const std::string &port_name, SIGNAL_TYPE type) { + switch (type) { + case SIGNAL_TYPE::REMOVE_: + spdlog::log(spdlog::level::debug, + std::format("port: [{}] removed", port_name)); + ComKit::FlushLog(); + ComKit::GetAllComPortNames(); + break; + case SIGNAL_TYPE::ADD_: + spdlog::log(spdlog::level::debug, + std::format("port: [{}] add", port_name)); + ComKit::FlushLog(); + ComKit::GetAllComPortNames(); + ComKit::Work(port_name); + break; + } + }); + watcher.work(); while (isRunning) helper.Render( [&]() { diff --git a/third/imgui/imgui_helper.cpp b/third/imgui/imgui_helper.cpp index 6e1b526..4287362 100644 --- a/third/imgui/imgui_helper.cpp +++ b/third/imgui/imgui_helper.cpp @@ -90,34 +90,7 @@ LRESULT ImGuiHelper::WndProc(HWND hWnd, UINT msg, WPARAM wParam, PDEV_BROADCAST_HDR pHdr = reinterpret_cast(lParam); switch (wParam) { case DBT_DEVICEARRIVAL: - if (pHdr->dbch_devicetype == DBT_DEVTYP_PORT) { - PDEV_BROADCAST_PORT pPort = - reinterpret_cast(pHdr); - spdlog::log(spdlog::level::debug, - std::format("port: [{}] add", pPort->dbcp_name)); - ComKit::FlushLog(); - ComKit::GetAllComPortNames(); - ComKit::Work(); - } else { - spdlog::log(spdlog::level::debug, - std::format("port: other device [{}] add", - pHdr->dbch_devicetype)); - } - break; case DBT_DEVICEREMOVECOMPLETE: - if (pHdr->dbch_devicetype == DBT_DEVTYP_PORT) { - PDEV_BROADCAST_PORT pPort = - reinterpret_cast(pHdr); - spdlog::log( - spdlog::level::debug, - std::format("port: [{}] removed", pPort->dbcp_name)); - ComKit::FlushLog(); - ComKit::GetAllComPortNames(); - } else { - spdlog::log(spdlog::level::debug, - std::format("port: other device [{}] add", - pHdr->dbch_devicetype)); - } break; } }