// // Created by zx on 2020/8/28. // #include "message_communicator.h" #include "measure_excutor.h" #include "exception_solver.h" #include "dispatch_excutor.h" #include "parkspace_excutor.h" #include "command_accepter.h" Message_communicator::Message_communicator() { } Message_communicator::~Message_communicator() { } /* * 发送消息 */ Error_manager Message_communicator::send_msg(Communication_message* p_msg) { return Communication_socket_base::encapsulate_msg(p_msg); } //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载 Error_manager Message_communicator::encapsulate_send_data() { return Error_code::SUCCESS; } /* * 检测消息是否合法 */ Error_manager Message_communicator::check_msg(Communication_message* p_msg) { if ( (p_msg->get_receiver() == Communication_message::Communicator::eMain) && (p_msg->get_message_type() == Communication_message::Message_type::eDispatch_response_msg ||p_msg->get_message_type() == Communication_message::Message_type::eDispatch_status_msg ||p_msg->get_message_type() == Communication_message::Message_type::eStore_command_request_msg ||p_msg->get_message_type() == Communication_message::Message_type::ePickup_command_request_msg ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_allocation_response_msg ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_search_response_msg ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_release_response_msg ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_confirm_alloc_response_msg ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_allocation_status_msg ||p_msg->get_message_type() == Communication_message::Message_type::eLocate_response_msg ||p_msg->get_message_type() == Communication_message::Message_type::eLocate_status_msg ||p_msg->get_message_type() == Communication_message::Message_type::eProcess_manual_operation_msg ||p_msg->get_message_type() == Communication_message::Message_type::eEntrance_manual_operation_msg)) { return Error_code::SUCCESS; } return Error_code::INVALID_MESSAGE; } //检查消息是否可以被处理, 需要重载 Error_manager Message_communicator::check_executer(Communication_message* p_msg) { return SUCCESS; } /* * 处理接收到的消息 */ Error_manager Message_communicator::execute_msg(Communication_message* p_msg) { /* * 接收终端指令, 生成流程 */ Error_manager code; switch(p_msg->get_message_type()) { //终端消息 case Communication_message::eStore_command_request_msg: { Command_accepter::get_instance_pointer()->consume_msg(p_msg); break; } case Communication_message::ePickup_command_request_msg: { Command_accepter::get_instance_pointer()->consume_msg(p_msg); break; } ///搬运结果反馈消息 case Communication_message::eDispatch_response_msg: { Dispatch_excutor::get_instance_pointer()->consume_msg(p_msg); break; } case Communication_message::eDispatch_status_msg: { Dispatch_excutor::get_instance_pointer()->consume_msg(p_msg); break; } ///// 车位分配模块的消息 case Communication_message::eParkspace_allocation_response_msg: { Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg); break; } case Communication_message::eParkspace_search_response_msg: { Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg); break; } case Communication_message::eParkspace_release_response_msg: { Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg); break; } case Communication_message::eParkspace_confirm_alloc_response_msg: { Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg); break; } case Communication_message::eParkspace_allocation_status_msg: { Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg); break; } ///测量结果反馈消息 case Communication_message::eLocate_response_msg: { Measure_excutor::get_instance_pointer()->consume_msg(p_msg); break; } //测量系统状态 case Communication_message::eLocate_status_msg: { Measure_excutor::get_instance_pointer()->consume_msg(p_msg); break; } //异常处理,手动操作 case Communication_message::eProcess_manual_operation_msg: { Exception_solver::get_instance_pointer()->consume_msg(p_msg); break; } case Communication_message::eEntrance_manual_operation_msg: { Exception_solver::get_instance_pointer()->consume_msg(p_msg); break; } default:break; } return SUCCESS; }