奥特QT DDS 插件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.7KB

  1. #pragma once
  2. #include <QObject>
  3. #include <QtPlugin>
  4. #include "interfaces/plugin_interface.hpp"
  5. #include <fastdds/dds/domain/DomainParticipant.hpp>
  6. #include <fastdds/dds/publisher/Publisher.hpp>
  7. #include <fastdds/dds/publisher/DataWriter.hpp>
  8. #include <fastdds/dds/subscriber/Subscriber.hpp>
  9. #include <fastdds/dds/subscriber/DataReader.hpp>
  10. #include <fastdds/dds/topic/Topic.hpp>
  11. #include "DDSSampleMachine.hpp"
  12. #include "DDSSampleMachinePubSubTypes.hpp"
  13. using namespace eprosima::fastdds::dds;
  14. using namespace SampleModule;
  15. // 导出宏定义
  16. #ifdef AQTSAMPLEMACHINEPLUG_LIBRARY
  17. #define AQTSAMPLEMACHINEPLUG_EXPORT Q_DECL_EXPORT
  18. #else
  19. #define AQTSAMPLEMACHINEPLUG_EXPORT Q_DECL_IMPORT
  20. #endif
  21. /**
  22. * @brief 采样机DDS插件类
  23. *
  24. * 实现采样机的DDS通信功能,包括:
  25. * - 采样机控制命令的发送
  26. * - 采样机状态的接收
  27. * - 数据点信息的管理
  28. */
  29. class AQTSAMPLEMACHINEPLUG_EXPORT AQTSampleMachinePlug : public QObject, public AuseftDDSPluginInterface, public DataReaderListener
  30. {
  31. Q_OBJECT
  32. Q_PLUGIN_METADATA(IID AuseftDDSPluginInterface_iid FILE "AQTSampleMachinePlug.json")
  33. Q_INTERFACES(AuseftDDSPluginInterface)
  34. public:
  35. /**
  36. * @brief 构造函数
  37. * @param parent 父对象指针
  38. */
  39. explicit AQTSampleMachinePlug(QObject *parent = nullptr);
  40. /**
  41. * @brief 析构函数
  42. * 负责清理DDS资源
  43. */
  44. ~AQTSampleMachinePlug();
  45. // 实现插件接口
  46. /**
  47. * @brief 初始化插件
  48. * @param domainId DDS域ID
  49. * @param domainName DDS域名称
  50. * @return 初始化是否成功
  51. */
  52. Q_INVOKABLE bool init(uint32_t domainId, const QString& domainName) override;
  53. /**
  54. * @brief 获取所有数据点信息
  55. * @return 数据点信息列表
  56. */
  57. Q_INVOKABLE QList<DataPointInfo> getDataPoints() override;
  58. /**
  59. * @brief 发布数据到DDS网络
  60. * @param dataList 要发布的数据列表
  61. * @return 发布是否成功
  62. */
  63. Q_INVOKABLE bool publishData(const QList<DataItem>& dataList) override;
  64. // 实现 DataReaderListener 接口
  65. void on_data_available(DataReader* reader) override;
  66. private:
  67. // DDS 实体
  68. DomainParticipant* participant_; ///< DDS参与者
  69. Publisher* publisher_; ///< DDS发布者
  70. Subscriber* subscriber_; ///< DDS订阅者
  71. Topic* commandTopic_; ///< 命令主题
  72. DataWriter* commandWriter_; ///< 命令写入器
  73. TypeSupport commandType_; ///< 命令类型支持
  74. Topic* statusTopic_; ///< 状态主题
  75. DataReader* statusReader_; ///< 状态读取器
  76. TypeSupport statusType_; ///< 状态类型支持
  77. Topic* configTopic_; ///< 配置主题
  78. DataWriter* configWriter_; ///< 配置写入器
  79. TypeSupport configType_; ///< 配置类型支持
  80. Topic* pointsTopic_; ///< 采样点主题
  81. DataWriter* pointsWriter_; ///< 采样点写入器
  82. DataReader* pointsReader_; ///< 采样点读取器
  83. TypeSupport pointsType_; ///< 采样点类型支持
  84. // 初始化辅助函数
  85. /**
  86. * @brief 初始化DDS实体
  87. * @return 初始化是否成功
  88. */
  89. bool initDDSEntities();
  90. /**
  91. * @brief 清理DDS实体
  92. */
  93. void cleanupDDSEntities();
  94. // 数据转换辅助函数
  95. SampleConfig dataItemsToConfig(const QList<DataItem>& items);
  96. SampleCommand dataItemsToCommand(const QList<DataItem>& items);
  97. SamplePoints dataItemsToPoints(const QList<DataItem>& items);
  98. QList<DataItem> infoToDataItems(const SampleMachineInfo& infos);
  99. };