system_communication mq.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * @Author: yct 18202736439@163.com
  3. * @Date: 2022-09-30 18:11:59
  4. * @LastEditors: yct 18202736439@163.com
  5. * @LastEditTime: 2023-01-17 15:41:04
  6. * @FilePath: /puai_wj_2021/system/system_communication mq.cpp
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. //
  10. // Created by huli on 2020/6/28.
  11. //
  12. #include "system_communication_mq.h"
  13. #include "../system/system_executor.h"
  14. System_communication_mq::System_communication_mq()
  15. {
  16. //1~6
  17. for (int j = 1; j < 7; ++j)
  18. {
  19. dispatch_region_info t_dispatch_region_info;
  20. t_dispatch_region_info.set_terminal_id(j);
  21. t_dispatch_region_info.set_turnplate_angle_min(0);
  22. t_dispatch_region_info.set_turnplate_angle_max(0);
  23. dispatch_region_info_map[j] = t_dispatch_region_info;
  24. }
  25. }
  26. System_communication_mq::~System_communication_mq()
  27. {
  28. }
  29. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  30. Error_manager System_communication_mq::check_msg(Rabbitmq_message* p_msg)
  31. {
  32. return SUCCESS;
  33. }
  34. //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
  35. Error_manager System_communication_mq::check_executer(Rabbitmq_message* p_msg)
  36. {
  37. return SUCCESS;
  38. }
  39. //处理消息, 需要子类重载
  40. Error_manager System_communication_mq::execute_msg(Rabbitmq_message* p_msg)
  41. {
  42. // return SUCCESS;
  43. return execute_dispatch_status_msg(p_msg);
  44. }
  45. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  46. Error_manager System_communication_mq::auto_encapsulate_status()
  47. {
  48. // return SUCCESS;
  49. return System_executor::get_instance_references().encapsulate_send_mq_status();
  50. }
  51. Error_manager System_communication_mq::execute_dispatch_status_msg(Rabbitmq_message* p_msg)
  52. {
  53. std::unique_lock<std::mutex> t_lock(m_lock);
  54. if ( p_msg->m_routing_key == "dispatch_1_statu_port" ||
  55. p_msg->m_routing_key == "dispatch_2_statu_port" ||
  56. p_msg->m_routing_key == "dispatch_3_statu_port" )
  57. {
  58. dispatch_node_statu t_dispatch_node_statu;
  59. if(google::protobuf::TextFormat::ParseFromString(p_msg->m_message_buf, &t_dispatch_node_statu))
  60. {
  61. // std::cout<< "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << t_dispatch_node_statu.DebugString() << std::endl;
  62. // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << t_dispatch_node_statu.DebugString() << this;
  63. for (int j = 0; j < t_dispatch_node_statu.dispatch_region_info_vector_size() ; ++j)
  64. {
  65. int t_terminal = t_dispatch_node_statu.dispatch_region_info_vector(j).terminal_id();
  66. dispatch_region_info_map[t_terminal] = t_dispatch_node_statu.dispatch_region_info_vector(j);
  67. // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx t_terminal = " << t_terminal << " ";
  68. // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << dispatch_region_info_map[t_terminal].terminal_id() << " ";
  69. // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << dispatch_region_info_map[t_terminal].turnplate_angle_min()<< " ";
  70. // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << dispatch_region_info_map[t_terminal].turnplate_angle_max()<< " ";
  71. }
  72. }
  73. }
  74. //终端点击存车时, 发送存车表单给检查节点, 这里顺便发送给感测节点.
  75. if( p_msg->m_routing_key == "user_command_port" )
  76. {
  77. park_table t_park_table_msg; //存车表单
  78. LOG(INFO) << " huli test::t_string p_msg->m_message_buf = "<< p_msg->m_message_buf << " --- " << this;
  79. if(google::protobuf::TextFormat::ParseFromString(p_msg->m_message_buf, &t_park_table_msg))
  80. {
  81. std::string t_string = t_park_table_msg.DebugString();
  82. LOG(INFO) << " huli test::t_string = t_park_table_msg "<< t_string << " --- " ;
  83. // 给唐有成, 这里面有terminal_id(范围1-6), 可以触发感测节点保存事件.
  84. // added by yct for region cloud saving function
  85. // vlp16 region
  86. std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
  87. int region_index = 0;
  88. for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
  89. {
  90. // get clouds from corresponding region
  91. if(t_park_table_msg.terminal_id()-1 == iter->second->get_terminal_id())
  92. {
  93. pcl::PointCloud<pcl::PointXYZ>::Ptr t_total_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  94. pcl::PointCloud<pcl::PointXYZ>::Ptr t_filtered_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  95. iter->second->get_region_cloud(t_total_cloud, Ground_region::Region_cloud_type::total);
  96. iter->second->get_region_cloud(t_filtered_cloud, Ground_region::Region_cloud_type::filtered);
  97. PathCreator pc;
  98. pc.Mkdir("./data/");
  99. if(pc.CreateDatePath(pc.GetCurPath()+"/"+std::to_string(t_park_table_msg.terminal_id())+"/", true))
  100. {
  101. save_cloud_txt(t_total_cloud, pc.GetCurPath()+"total.txt");
  102. save_cloud_txt(t_filtered_cloud, pc.GetCurPath()+"filtered.txt");
  103. LOG(INFO) <<"total and filtered cloud in region "<<t_park_table_msg.terminal_id()<<"(1-6) has been saved in "<<pc.GetCurPath();
  104. }
  105. }
  106. }
  107. }
  108. //指令信息必须手动ack, 这样才能清除服务器的指令,
  109. //(状态消息临时队列接受后自动清除, 指令消息永久队列接收后手动清除)
  110. ack_msg(p_msg);
  111. }
  112. return SUCCESS;
  113. }