|
@@ -7,6 +7,8 @@
|
|
|
#include "../laser/laser_manager.h"
|
|
|
#include "../locate/locate_manager.h"
|
|
|
#include "../system/system_communication.h"
|
|
|
+#include "../message/dispatch_message.pb.h"
|
|
|
+#include "../dispatch/dispatch_manager.h"
|
|
|
|
|
|
System_executor::System_executor()
|
|
|
{
|
|
@@ -97,7 +99,60 @@ Error_manager System_executor::check_executer(Communication_message* p_msg)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- LOG(INFO) << " System_executor::check_executer second PARSE_ERROR "<< this;
|
|
|
+ LOG(INFO) << " System_executor::check_executer Second analysis ERROR "<< this;
|
|
|
+ return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
|
|
|
+ " message::Measure_request_msg ParseFromString error ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case Communication_message::Message_type::eDispatch_request_msg:
|
|
|
+ {
|
|
|
+ Error_manager t_dispatch_result = Dispatch_manager::get_instance_references().check_status();
|
|
|
+ Error_manager t_executor_result = System_executor::get_instance_references().check_status();
|
|
|
+ if (t_dispatch_result == SUCCESS
|
|
|
+ && t_executor_result == SUCCESS)
|
|
|
+ {
|
|
|
+ return Error_code::SUCCESS;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //整合所有的错误码
|
|
|
+ t_error.compare_and_cover_error(t_dispatch_result);
|
|
|
+ t_error.compare_and_cover_error(t_executor_result);
|
|
|
+ if (t_error.get_error_level() == NEGLIGIBLE_ERROR)//一级故障,轻微故障,
|
|
|
+ {
|
|
|
+ std::cout << "executer_is_busy , " << std::endl;
|
|
|
+ //返回繁忙之后, 通信模块1秒后再次调用check
|
|
|
+ return Error_code::COMMUNICATION_EXCUTER_IS_BUSY;
|
|
|
+ }
|
|
|
+ else//返回二级故障,可以封装一条答复信息, 返回错误码
|
|
|
+ {
|
|
|
+ message::Dispatch_response_msg t_dispatch_request_msg;
|
|
|
+ //针对消息类型, 对消息进行二次解析
|
|
|
+ if (t_dispatch_request_msg.ParseFromString(p_msg->get_message_buf()))
|
|
|
+ {
|
|
|
+ //创建一条答复消息
|
|
|
+ message::Dispatch_response_msg t_dispatch_response_msg;
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_timeout_ms(5000);
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch);
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
|
|
|
+
|
|
|
+ t_dispatch_response_msg.set_command_id(t_dispatch_request_msg.command_id());
|
|
|
+ t_dispatch_response_msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
|
|
|
+ t_dispatch_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
|
|
|
+ t_dispatch_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
|
|
|
+
|
|
|
+ string t_msg = t_dispatch_response_msg.SerializeAsString();
|
|
|
+ System_communication::get_instance_references().encapsulate_msg(t_msg);
|
|
|
+ LOG(INFO) << " System_executor::check_executer executer status error "<< this;
|
|
|
+ return t_error;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LOG(INFO) << " System_executor::check_executer Second analysis ERROR "<< this;
|
|
|
return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
|
|
|
" message::Measure_request_msg ParseFromString error ");
|
|
|
}
|
|
@@ -125,22 +180,61 @@ Error_manager System_executor::execute_msg(Communication_message* p_msg)
|
|
|
}
|
|
|
switch ( p_msg->get_message_type() )
|
|
|
{
|
|
|
- case Communication_message::eLocate_request_msg:
|
|
|
+ case Communication_message::Message_type::eLocate_request_msg:
|
|
|
+ {
|
|
|
message::Measure_request_msg t_measure_request_msg;
|
|
|
//针对消息类型, 对消息进行二次解析
|
|
|
- if( t_measure_request_msg.ParseFromString(p_msg->get_message_buf()) )
|
|
|
+ if (t_measure_request_msg.ParseFromString(p_msg->get_message_buf()))
|
|
|
{
|
|
|
//往线程池添加执行任务, 之后会唤醒一个线程去执行他.
|
|
|
m_thread_pool.enqueue(&System_executor::execute_for_measure, this,
|
|
|
- t_measure_request_msg.command_id(), t_measure_request_msg.terminal_id());
|
|
|
+ t_measure_request_msg.command_id(), t_measure_request_msg.terminal_id());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
|
|
|
- " message::Measure_request_msg ParseFromString error ");
|
|
|
+ return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
|
|
|
+ " message::Measure_request_msg ParseFromString error ");
|
|
|
}
|
|
|
break;
|
|
|
+ }
|
|
|
+ case Communication_message::Message_type::eDispatch_request_msg:
|
|
|
+ {
|
|
|
+ message::Dispatch_request_msg t_dispatch_request_msg;
|
|
|
+ //针对消息类型, 对消息进行二次解析
|
|
|
+ if (t_dispatch_request_msg.ParseFromString(p_msg->get_message_buf()))
|
|
|
+ {
|
|
|
+ Locate_information t_locate_information;
|
|
|
|
|
|
+ if ( t_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR
|
|
|
+ && t_dispatch_request_msg.has_locate_information())
|
|
|
+ {
|
|
|
+ t_locate_information.locate_x = t_dispatch_request_msg.locate_information().locate_x();
|
|
|
+ t_locate_information.locate_y = t_dispatch_request_msg.locate_information().locate_y();
|
|
|
+ t_locate_information.locate_angle = t_dispatch_request_msg.locate_information().locate_angle();
|
|
|
+ t_locate_information.locate_length = t_dispatch_request_msg.locate_information().locate_length();
|
|
|
+ t_locate_information.locate_width = t_dispatch_request_msg.locate_information().locate_width();
|
|
|
+ t_locate_information.locate_height = t_dispatch_request_msg.locate_information().locate_height();
|
|
|
+ t_locate_information.locate_wheel_base = t_dispatch_request_msg.locate_information().locate_wheel_base();
|
|
|
+ t_locate_information.locate_wheel_width = t_dispatch_request_msg.locate_information().locate_wheel_width();
|
|
|
+ t_locate_information.locate_correct = t_dispatch_request_msg.locate_information().locate_correct();
|
|
|
+ }
|
|
|
+ //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
|
|
|
+ m_thread_pool.enqueue(&System_executor::execute_for_dispatch, this,
|
|
|
+ t_dispatch_request_msg.command_id(),
|
|
|
+ (Dispatch_manager::Dispatch_motion_direction)t_dispatch_request_msg.dispatch_motion_direction(),
|
|
|
+ t_dispatch_request_msg.terminal_id(),
|
|
|
+ t_dispatch_request_msg.parkspace_id(),
|
|
|
+ &t_locate_information );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
|
|
|
+ " message::Dispatch_request_msg ParseFromString error ");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -169,6 +263,26 @@ Error_manager System_executor::check_status()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//定时发送状态信息
|
|
|
+Error_manager System_executor::encapsulate_send_status()
|
|
|
+{
|
|
|
+ Error_manager t_error;
|
|
|
+ //创建一条状态消息
|
|
|
+ message::Dispatch_status_msg t_dispatch_status_msg;
|
|
|
+ t_dispatch_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_status_msg);
|
|
|
+ t_dispatch_status_msg.mutable_base_info()->set_timeout_ms(5000);
|
|
|
+ t_dispatch_status_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch);
|
|
|
+ t_dispatch_status_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
|
|
|
+
|
|
|
+ Dispatch_manager::Dispatch_manager_status t_dispatch_manager_status = Dispatch_manager::get_instance_references().get_dispatch_manager_status();
|
|
|
+ t_dispatch_status_msg.set_dispatch_manager_status((message::Dispatch_manager_status)t_dispatch_manager_status);
|
|
|
+
|
|
|
+ string t_msg = t_dispatch_status_msg.SerializeAsString();
|
|
|
+ System_communication::get_instance_references().encapsulate_msg(t_msg);
|
|
|
+
|
|
|
+ return Error_code::SUCCESS;
|
|
|
+}
|
|
|
+
|
|
|
//判断是否为待机,如果已经准备好,则可以执行任务。
|
|
|
bool System_executor::is_ready()
|
|
|
{
|
|
@@ -226,5 +340,43 @@ void System_executor::execute_for_measure(int command_id, int terminal_id)
|
|
|
|
|
|
string t_msg = t_measure_response_msg.SerializeAsString();
|
|
|
System_communication::get_instance_references().encapsulate_msg(t_msg);
|
|
|
+ LOG(INFO) << " System_executor::execute_for_measure end "<< this;
|
|
|
+
|
|
|
return ;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//调度模块的处理函数
|
|
|
+void System_executor::execute_for_dispatch(int command_id, Dispatch_manager::Dispatch_motion_direction dispatch_motion_direction,
|
|
|
+ int terminal_id, int parkspace_id, Locate_information * p_locate_information)
|
|
|
+{
|
|
|
+ Error_manager t_error;
|
|
|
+
|
|
|
+ LOG(INFO) << " System_executor::execute_for_dispatch run "<< this;
|
|
|
+ //这里要处理.......以后再写
|
|
|
+
|
|
|
+ t_error = Dispatch_manager::get_instance_references().execute_task(dispatch_motion_direction);
|
|
|
+
|
|
|
+ //创建一条答复消息
|
|
|
+ message::Dispatch_response_msg t_dispatch_response_msg;
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_timeout_ms(5000);
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch);
|
|
|
+ t_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
|
|
|
+
|
|
|
+ t_dispatch_response_msg.set_command_id(command_id);
|
|
|
+ t_dispatch_response_msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
|
|
|
+ t_dispatch_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
|
|
|
+ t_dispatch_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description(), t_error.get_description_length());
|
|
|
+
|
|
|
+ string t_msg = t_dispatch_response_msg.SerializeAsString();
|
|
|
+ System_communication::get_instance_references().encapsulate_msg(t_msg);
|
|
|
+
|
|
|
+ std::cout << "huli test dispatch_motion_direction = " << dispatch_motion_direction << std::endl;
|
|
|
+ std::cout << "huli test error = " << t_error << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ LOG(INFO) << " System_executor::execute_for_dispatch end "<< this;
|
|
|
+ return ;
|
|
|
+
|
|
|
}
|