|
- #pragma once
-
- #include <QObject>
- #include <QtPlugin>
- #include "interfaces/plugin_interface.hpp"
- #include <fastdds/dds/domain/DomainParticipant.hpp>
- #include <fastdds/dds/publisher/Publisher.hpp>
- #include <fastdds/dds/publisher/DataWriter.hpp>
- #include <fastdds/dds/subscriber/Subscriber.hpp>
- #include <fastdds/dds/subscriber/DataReader.hpp>
- #include <fastdds/dds/topic/Topic.hpp>
- #include "DDSSampleMachine.hpp"
- #include "DDSSampleMachinePubSubTypes.hpp"
-
- using namespace eprosima::fastdds::dds;
- using namespace SampleModule;
-
- // 导出宏定义
- #ifdef AQTSAMPLEMACHINEPLUG_LIBRARY
- #define AQTSAMPLEMACHINEPLUG_EXPORT Q_DECL_EXPORT
- #else
- #define AQTSAMPLEMACHINEPLUG_EXPORT Q_DECL_IMPORT
- #endif
-
- /**
- * @brief 采样机DDS插件类
- *
- * 实现采样机的DDS通信功能,包括:
- * - 采样机控制命令的发送
- * - 采样机状态的接收
- * - 数据点信息的管理
- */
- class AQTSAMPLEMACHINEPLUG_EXPORT AQTSampleMachinePlug : public QObject, public AuseftDDSPluginInterface, public DataReaderListener
- {
- Q_OBJECT
- Q_PLUGIN_METADATA(IID AuseftDDSPluginInterface_iid FILE "AQTSampleMachinePlug.json")
- Q_INTERFACES(AuseftDDSPluginInterface)
-
- public:
- /**
- * @brief 构造函数
- * @param parent 父对象指针
- */
- explicit AQTSampleMachinePlug(QObject *parent = nullptr);
-
- /**
- * @brief 析构函数
- * 负责清理DDS资源
- */
- ~AQTSampleMachinePlug();
-
- // 实现插件接口
- /**
- * @brief 初始化插件
- * @param domainId DDS域ID
- * @param domainName DDS域名称
- * @return 初始化是否成功
- */
- Q_INVOKABLE bool init(uint32_t domainId, const QString& domainName) override;
-
- /**
- * @brief 获取所有数据点信息
- * @return 数据点信息列表
- */
- Q_INVOKABLE QList<DataPointInfo> getDataPoints() override;
-
- /**
- * @brief 发布数据到DDS网络
- * @param dataList 要发布的数据列表
- * @return 发布是否成功
- */
- Q_INVOKABLE bool publishData(const QList<DataItem>& dataList) override;
-
-
- // 实现 DataReaderListener 接口
- void on_data_available(DataReader* reader) override;
-
-
- private:
- // DDS 实体
- DomainParticipant* participant_; ///< DDS参与者
- Publisher* publisher_; ///< DDS发布者
- Subscriber* subscriber_; ///< DDS订阅者
-
- Topic* commandTopic_; ///< 命令主题
- DataWriter* commandWriter_; ///< 命令写入器
- TypeSupport commandType_; ///< 命令类型支持
-
- Topic* statusTopic_; ///< 状态主题
- DataReader* statusReader_; ///< 状态读取器
- TypeSupport statusType_; ///< 状态类型支持
-
- Topic* configTopic_; ///< 配置主题
- DataWriter* configWriter_; ///< 配置写入器
- TypeSupport configType_; ///< 配置类型支持
-
- Topic* pointsTopic_; ///< 采样点主题
- DataWriter* pointsWriter_; ///< 采样点写入器
- DataReader* pointsReader_; ///< 采样点读取器
- TypeSupport pointsType_; ///< 采样点类型支持
-
- // 初始化辅助函数
- /**
- * @brief 初始化DDS实体
- * @return 初始化是否成功
- */
- bool initDDSEntities();
-
- /**
- * @brief 清理DDS实体
- */
- void cleanupDDSEntities();
-
- // 数据转换辅助函数
-
- SampleConfig dataItemsToConfig(const QList<DataItem>& items);
- SampleCommand dataItemsToCommand(const QList<DataItem>& items);
- SamplePoints dataItemsToPoints(const QList<DataItem>& items);
- QList<DataItem> infoToDataItems(const SampleMachineInfo& infos);
- };
|