奥特QT DDS 插件库
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

127 lignes
4.0KB

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