bonus-edge-proxy/src/modbus/modbus_rtu_poller_service.h

76 lines
2.4 KiB
C
Raw Normal View History

2025-10-14 16:06:43 +08:00
// 文件名: src/modbus/modbus_rtu_poller_service.h
#ifndef MODBUS_RTU_POLLER_SERVICE_H
#define MODBUS_RTU_POLLER_SERVICE_H
#include "protocol/iprotocol_adapter.h"
#include "modbus_rtu_client.h"
#include "modbus_common.h" // 包含 ModbusRtuDeviceConfig 和 DataPointConfig 定义
#include <thread>
#include <atomic>
#include <string>
/**
* @brief Modbus RTU
* * 线Modbus RTU设备
* IO操作与主程序的异步事件循环隔离开来
* 线
*/
class ModbusRtuPollerService {
public:
/**
* @brief
* @param config
* @param report_cb
*/
ModbusRtuPollerService(ModbusRtuDeviceConfig config, ReportDataCallback report_cb);
/**
* @brief
* * 线
*/
~ModbusRtuPollerService();
// 禁止拷贝和赋值,因为该类管理着一个线程资源
ModbusRtuPollerService(const ModbusRtuPollerService&) = delete;
ModbusRtuPollerService& operator=(const ModbusRtuPollerService&) = delete;
/**
* @brief
* * 线 run()
*/
void start();
/**
* @brief
* * 线退
*/
void stop();
// --- <<< 新增方法 >>> ---
/**
* @brief (const-ref to avoid copy)
*/
const ModbusRtuDeviceConfig& get_config() const;
/**
* @brief
*/
bool is_running() const;
// --- <<< END >>> ---
2025-10-14 16:06:43 +08:00
private:
/**
* @brief 线
* * 线
*
*/
void run();
ModbusRtuDeviceConfig m_config;
ReportDataCallback m_report_callback;
ModbusRTUClient m_client;
std::thread m_thread;
std::atomic<bool> m_stop_flag{false};
};
#endif // MODBUS_RTU_POLLER_SERVICE_H