rslidar_mqtt_async.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @project ALG_WHeelData
  3. * @brief 从mqtt服务器获取点云数据并进行处理,仅给外部一个获取数据的接口。
  4. * @author lz
  5. * @data 2023/4/21
  6. **/
  7. #pragma once
  8. #include "pahoc/mqtt_async.h"
  9. #include "message/unpacket.hpp"
  10. #include "defines.hpp"
  11. #include <vector>
  12. #include <memory>
  13. #include <typeinfo>
  14. // TODO: 完善功能
  15. class CloudDataMqttAsync : public MqttAsyncClient {
  16. public:
  17. CloudDataMqttAsync() = default;
  18. ~CloudDataMqttAsync() = default;
  19. static CloudDataMqttAsync *instance() {
  20. static CloudDataMqttAsync *p = nullptr;
  21. if (p == nullptr) {
  22. p = new CloudDataMqttAsync();
  23. p->init();
  24. }
  25. return p;
  26. }
  27. bool init();
  28. bool getCloudData(const std::string &topic, pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud);
  29. bool getCloudData(const std::string &topic, pcl::PointCloud<pcl::PointXYZI>::Ptr &cloud);
  30. bool getCloudData(const std::string &topic, pcl::PointCloud<pcl::PointRPRY>::Ptr &cloud);
  31. bool getCloudData(const std::string &topic, pcl::PointCloud<pcl::PointALL>::Ptr &cloud);
  32. private:
  33. static int CloudDataArrived(MqttAsyncClient *client, char *topicName, int topicLen, MQTTAsync_message *message);
  34. bool insertCloudData(std::string &topic, unsigned char *cloud_data, int size);
  35. private:
  36. const char *MQTT_CONFIG_PATH = ETC_PATH"/etc/icp_mqtt_async.json";
  37. CloudPointUnpacket *m_unpacket;
  38. pcl::PointCloud<pcl::PointXYZI>::Ptr m_clouds;
  39. std::mutex m_cloud_mutex;
  40. std::map<std::string, pcl::PointCloud<pcl::PointALL>::Ptr> m_full_clouds_map;
  41. std::map<std::string, std::chrono::steady_clock::time_point> m_cloud_time_stamp_map;
  42. };