system_communication_mq.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. dispatch_plc_passway_status t_dispatch_region_info;
  17. t_dispatch_region_info.set_turnplate_angle_min(-5);
  18. t_dispatch_region_info.set_turnplate_angle_max(5);
  19. dispatch_region_info_map.insert(std::pair<int, dispatch_plc_passway_status>(3117, t_dispatch_region_info));
  20. dispatch_region_info_map.insert(std::pair<int, dispatch_plc_passway_status>(3118, t_dispatch_region_info));
  21. dispatch_region_info_map.insert(std::pair<int, dispatch_plc_passway_status>(3219, t_dispatch_region_info));
  22. }
  23. System_communication_mq::~System_communication_mq()
  24. {
  25. }
  26. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  27. Error_manager System_communication_mq::check_msg(Rabbitmq_message* p_msg)
  28. {
  29. return SUCCESS;
  30. }
  31. //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
  32. Error_manager System_communication_mq::check_executer(Rabbitmq_message* p_msg)
  33. {
  34. return SUCCESS;
  35. }
  36. //处理消息, 需要子类重载
  37. Error_manager System_communication_mq::execute_msg(Rabbitmq_message* p_msg)
  38. {
  39. // return SUCCESS;
  40. return execute_dispatch_status_msg(p_msg);
  41. }
  42. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  43. Error_manager System_communication_mq::auto_encapsulate_status()
  44. {
  45. // return SUCCESS;
  46. return System_executor::get_instance_references().encapsulate_send_mq_status();
  47. }
  48. Error_manager System_communication_mq::execute_dispatch_status_msg(Rabbitmq_message* p_msg)
  49. {
  50. std::unique_lock<std::mutex> t_lock(m_lock);
  51. if (p_msg->m_routing_key.find("dispatch_") != std::string::npos &&
  52. p_msg->m_routing_key.find("_statu_port") != std::string::npos)
  53. {
  54. dispatch_node_statu t_dispatch_node_statu;
  55. if(google::protobuf::TextFormat::ParseFromString(p_msg->m_message_buf, &t_dispatch_node_statu))
  56. {
  57. int t_terminal = t_dispatch_node_statu.unit_id();
  58. if (t_terminal == 31) {
  59. dispatch_region_info_map[3117] = t_dispatch_node_statu.dispatch_plc_passway_status_vector(0);
  60. dispatch_region_info_map[3118] = t_dispatch_node_statu.dispatch_plc_passway_status_vector(1);
  61. }
  62. if (t_terminal == 32) {
  63. dispatch_region_info_map[3219] = t_dispatch_node_statu.dispatch_plc_passway_status_vector(0);
  64. }
  65. }
  66. }
  67. //终端点击存车时, 发送存车表单给检查节点, 这里顺便发送给感测节点.
  68. if (p_msg->m_routing_key == "user_park_command_request_port")
  69. {
  70. park_table t_park_table_msg; //存车表单
  71. LOG(INFO) << "Receive p_msg " << " --- " << this;
  72. if(google::protobuf::TextFormat::ParseFromString(p_msg->m_message_buf, &t_park_table_msg))
  73. {
  74. std::string t_string = t_park_table_msg.DebugString();
  75. LOG(INFO) << "ParseFromString success, it's id: "<< t_park_table_msg.terminal_id() << " --- " ;
  76. // 给唐有成, 这里面有terminal_id(范围1-6), 可以触发感测节点保存事件.
  77. // added by yct for region cloud saving function
  78. // vlp16 region
  79. std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
  80. int region_index = 0;
  81. for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
  82. {
  83. // get clouds from corresponding region
  84. if(t_park_table_msg.terminal_id() == iter->second->get_terminal_id())
  85. {
  86. pcl::PointCloud<pcl::PointXYZ>::Ptr t_total_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  87. pcl::PointCloud<pcl::PointXYZ>::Ptr t_trans_total_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  88. pcl::PointCloud<pcl::PointXYZ>::Ptr t_filtered_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  89. pcl::PointCloud<pcl::PointXYZ>::Ptr t_failture_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  90. iter->second->get_region_cloud(t_total_cloud, Ground_region::Region_cloud_type::total);
  91. iter->second->get_region_cloud(t_trans_total_cloud, Ground_region::Region_cloud_type::trans);
  92. iter->second->get_region_cloud(t_filtered_cloud, Ground_region::Region_cloud_type::filtered);
  93. iter->second->get_region_cloud(t_failture_cloud, Ground_region::Region_cloud_type::failure);
  94. PathCreator pc;
  95. pc.Mkdir(ETC_PATH"/etc/data/");
  96. if(pc.CreateDatePath(pc.GetCurPath()+"/"+std::to_string(t_park_table_msg.terminal_id())+"/", true))
  97. {
  98. save_cloud_txt(t_total_cloud, pc.GetCurPath()+"total.txt");
  99. save_cloud_txt(t_trans_total_cloud, pc.GetCurPath()+"t_trans_total_cloud.txt");
  100. save_cloud_txt(t_filtered_cloud, pc.GetCurPath()+"filtered.txt");
  101. if (!t_failture_cloud->empty()) {
  102. save_cloud_txt(t_failture_cloud, pc.GetCurPath()+"failture.txt");
  103. }
  104. LOG(INFO) <<"total and filtered cloud in region "<<t_park_table_msg.terminal_id()<<"(1-6) has been saved in "<<pc.GetCurPath();
  105. }
  106. }
  107. }
  108. }
  109. // 指令信息必须手动ack, 这样才能清除服务器的指令,
  110. // (状态消息临时队列接受后自动清除, 指令消息永久队列接收后手动清除)
  111. // ack_msg(p_msg);
  112. }
  113. return SUCCESS;
  114. }