123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- /*
- * @Author: yct 18202736439@163.com
- * @Date: 2022-09-30 18:11:59
- * @LastEditors: yct 18202736439@163.com
- * @LastEditTime: 2023-01-17 15:41:04
- * @FilePath: /puai_wj_2021/system/system_communication mq.cpp
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- //
- // Created by huli on 2020/6/28.
- //
- #include "system_communication_mq.h"
- #include "../system/system_executor.h"
- System_communication_mq::System_communication_mq()
- {
- //1~6
- for (int j = 1; j < 7; ++j)
- {
- dispatch_region_info t_dispatch_region_info;
- t_dispatch_region_info.set_terminal_id(j);
- t_dispatch_region_info.set_turnplate_angle_min(0);
- t_dispatch_region_info.set_turnplate_angle_max(0);
- dispatch_region_info_map[j] = t_dispatch_region_info;
- }
- }
- System_communication_mq::~System_communication_mq()
- {
- }
- //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
- Error_manager System_communication_mq::check_msg(Rabbitmq_message* p_msg)
- {
- return SUCCESS;
- }
- //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
- Error_manager System_communication_mq::check_executer(Rabbitmq_message* p_msg)
- {
- return SUCCESS;
- }
- //处理消息, 需要子类重载
- Error_manager System_communication_mq::execute_msg(Rabbitmq_message* p_msg)
- {
- // return SUCCESS;
- return execute_dispatch_status_msg(p_msg);
- }
- //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
- Error_manager System_communication_mq::auto_encapsulate_status()
- {
- // return SUCCESS;
- return System_executor::get_instance_references().encapsulate_send_mq_status();
- }
- Error_manager System_communication_mq::execute_dispatch_status_msg(Rabbitmq_message* p_msg)
- {
- std::unique_lock<std::mutex> t_lock(m_lock);
- if ( p_msg->m_routing_key == "dispatch_1_statu_port" ||
- p_msg->m_routing_key == "dispatch_2_statu_port" ||
- p_msg->m_routing_key == "dispatch_3_statu_port" )
- {
- dispatch_node_statu t_dispatch_node_statu;
- if(google::protobuf::TextFormat::ParseFromString(p_msg->m_message_buf, &t_dispatch_node_statu))
- {
- // std::cout<< "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << t_dispatch_node_statu.DebugString() << std::endl;
- // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << t_dispatch_node_statu.DebugString() << this;
- for (int j = 0; j < t_dispatch_node_statu.dispatch_region_info_vector_size() ; ++j)
- {
- int t_terminal = t_dispatch_node_statu.dispatch_region_info_vector(j).terminal_id();
- dispatch_region_info_map[t_terminal] = t_dispatch_node_statu.dispatch_region_info_vector(j);
- // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx t_terminal = " << t_terminal << " ";
- // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << dispatch_region_info_map[t_terminal].terminal_id() << " ";
- // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << dispatch_region_info_map[t_terminal].turnplate_angle_min()<< " ";
- // LOG(INFO) << "hulixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << dispatch_region_info_map[t_terminal].turnplate_angle_max()<< " ";
- }
- }
- }
- //终端点击存车时, 发送存车表单给检查节点, 这里顺便发送给感测节点.
- if( p_msg->m_routing_key == "user_command_port" )
- {
- park_table t_park_table_msg; //存车表单
- LOG(INFO) << " huli test::t_string p_msg->m_message_buf = "<< p_msg->m_message_buf << " --- " << this;
- if(google::protobuf::TextFormat::ParseFromString(p_msg->m_message_buf, &t_park_table_msg))
- {
- std::string t_string = t_park_table_msg.DebugString();
- LOG(INFO) << " huli test::t_string = t_park_table_msg "<< t_string << " --- " ;
- // 给唐有成, 这里面有terminal_id(范围1-6), 可以触发感测节点保存事件.
- // added by yct for region cloud saving function
- // vlp16 region
- std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
- int region_index = 0;
- for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
- {
- // get clouds from corresponding region
- if(t_park_table_msg.terminal_id()-1 == iter->second->get_terminal_id())
- {
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_total_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_filtered_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
- iter->second->get_region_cloud(t_total_cloud, Ground_region::Region_cloud_type::total);
- iter->second->get_region_cloud(t_filtered_cloud, Ground_region::Region_cloud_type::filtered);
- PathCreator pc;
- pc.Mkdir("./data/");
- if(pc.CreateDatePath(pc.GetCurPath()+"/"+std::to_string(t_park_table_msg.terminal_id())+"/", true))
- {
- save_cloud_txt(t_total_cloud, pc.GetCurPath()+"total.txt");
- save_cloud_txt(t_filtered_cloud, pc.GetCurPath()+"filtered.txt");
- LOG(INFO) <<"total and filtered cloud in region "<<t_park_table_msg.terminal_id()<<"(1-6) has been saved in "<<pc.GetCurPath();
- }
- }
- }
- }
- //指令信息必须手动ack, 这样才能清除服务器的指令,
- //(状态消息临时队列接受后自动清除, 指令消息永久队列接收后手动清除)
- ack_msg(p_msg);
- }
- return SUCCESS;
- }
|