|
@@ -14,7 +14,7 @@ Parkspace_allocation_communicator::~Parkspace_allocation_communicator()
|
|
|
|
|
|
//************************************* 公有函数 ****************************************
|
|
|
//外部调用发送分配车位结果
|
|
|
-Error_manager Parkspace_allocation_communicator::send_allocation_result(Communication_message *message)
|
|
|
+Error_manager Parkspace_allocation_communicator::send_response(Communication_message *message)
|
|
|
{
|
|
|
return encapsulate_msg(message);
|
|
|
}
|
|
@@ -55,18 +55,28 @@ Error_manager Parkspace_allocation_communicator::encapsulate_msg(Communication_m
|
|
|
{
|
|
|
return Error_manager(POINTER_IS_NULL, NEGLIGIBLE_ERROR, "Parkspace_allocation_communicator::message null pointer");
|
|
|
}
|
|
|
- //记录请求
|
|
|
- if (message->get_message_type() == Communication_message::eParkspace_allocation_response_msg)
|
|
|
+ //针对待发送的不同反馈消息,分别进行校核
|
|
|
+ switch(message->get_message_type())
|
|
|
{
|
|
|
- message::Parkspace_allocation_response_msg response;
|
|
|
- bool result = response.ParseFromString(message->get_message_buf());
|
|
|
- //可增加待发送分配车位反馈消息校核
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return Error_manager(PARKSPACE_ALLOCATOR_MSG_RESPONSE_TYPE_ERROR, NEGLIGIBLE_ERROR, "Parkspace_allocation_communicator::message response type error");
|
|
|
+ case Communication_message::eParkspace_allocation_response_msg:
|
|
|
+ {
|
|
|
+ message::Parkspace_allocation_response_msg response;
|
|
|
+ bool result = response.ParseFromString(message->get_message_buf());
|
|
|
+ //可增加待发送分配车位反馈消息校核
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case Communication_message::eParkspace_search_response_msg:
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case Communication_message::eParkspace_release_response_msg:
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return Error_manager(PARKSPACE_ALLOCATOR_MSG_RESPONSE_TYPE_ERROR, NEGLIGIBLE_ERROR, "Parkspace_allocation_communicator::message response type error");
|
|
|
}
|
|
|
+
|
|
|
//发送请求
|
|
|
return Communication_socket_base::encapsulate_msg(message);
|
|
|
}
|
|
@@ -84,44 +94,127 @@ Error_manager Parkspace_allocation_communicator::execute_msg(Communication_messa
|
|
|
{
|
|
|
message::Parkspace_allocation_request_msg request;
|
|
|
request.ParseFromString(p_msg->get_message_buf());
|
|
|
+ std::cout<<"allocation request, car license: "<<request.car_info().license()<<std::endl;
|
|
|
+
|
|
|
//根据请求的信息反馈分配的车位,并封装发送
|
|
|
- //此处跳过外部处理与调用的过程,直接在内部调用,发送分配结果用于测试
|
|
|
- Communication_message* response=new Communication_message();
|
|
|
+ //!!!!!此处跳过外部处理与调用的过程,直接在内部调用,发送分配结果用于测试,目前一直发布第一个车位
|
|
|
message::Parkspace_allocation_response_msg response_msg;
|
|
|
message::Base_info t_response_header;
|
|
|
message::Error_manager t_error;
|
|
|
+ message::Parkspace_info t_allocated_space;
|
|
|
t_response_header.set_msg_type(message::Message_type::eParkspace_allocation_response_msg);
|
|
|
t_response_header.set_timeout_ms(1000);
|
|
|
t_response_header.set_sender(message::Communicator::eParkspace_allocator);
|
|
|
t_response_header.set_receiver(message::Communicator::eMain);
|
|
|
- t_error.set_error_code(0);
|
|
|
- t_error.set_error_level(message::Error_level::NORMAL);
|
|
|
+ if(m_parkspace_status_msg.parkspace_info_size()>0)
|
|
|
+ {
|
|
|
+ t_error.set_error_code(0);
|
|
|
+ t_error.set_error_level(message::Error_level::NORMAL);
|
|
|
+ t_allocated_space.CopyFrom(m_parkspace_status_msg.parkspace_info(0));
|
|
|
+ } else{
|
|
|
+ t_error.set_error_code(1);
|
|
|
+ t_error.set_error_level(message::Error_level::MAJOR_ERROR);
|
|
|
+ }
|
|
|
response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
- response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
response_msg.set_command_id(request.command_id());
|
|
|
- response_msg.set_allocated_space_id(33);
|
|
|
+ response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
+ response_msg.mutable_allocated_space_info()->CopyFrom(t_allocated_space);
|
|
|
+ Communication_message* response=new Communication_message();
|
|
|
response->reset(t_response_header, response_msg.SerializeAsString());
|
|
|
- return send_allocation_result(response);
|
|
|
+ return send_response(response);
|
|
|
// return SUCCESS;
|
|
|
}
|
|
|
+ case Communication_message::eParkspace_search_request_msg:
|
|
|
+ {
|
|
|
+ message::Parkspace_search_request_msg request;
|
|
|
+ request.ParseFromString(p_msg->get_message_buf());
|
|
|
+ std::cout<<"search request, car license: "<<request.car_info().license()<<std::endl;
|
|
|
+
|
|
|
+ //根据车辆凭证信息查询车辆位置
|
|
|
+ //!!!!!此处跳过外部处理与调用的过程,直接在内部调用,发送分配结果用于测试,目前一直发布第一个车位
|
|
|
+ message::Parkspace_search_response_msg response_msg;
|
|
|
+ message::Base_info t_response_header;
|
|
|
+ message::Error_manager t_error;
|
|
|
+ message::Parkspace_info t_car_position;
|
|
|
+ t_response_header.set_msg_type(message::Message_type::eParkspace_search_response_msg);
|
|
|
+ t_response_header.set_timeout_ms(1000);
|
|
|
+ t_response_header.set_sender(message::Communicator::eParkspace_allocator);
|
|
|
+ t_response_header.set_receiver(message::Communicator::eMain);
|
|
|
+ if (m_parkspace_status_msg.parkspace_info_size() > 1)
|
|
|
+ {
|
|
|
+ t_error.set_error_code(0);
|
|
|
+ t_error.set_error_level(message::Error_level::NORMAL);
|
|
|
+ t_car_position.CopyFrom(m_parkspace_status_msg.parkspace_info(1));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ t_error.set_error_code(1);
|
|
|
+ t_error.set_error_level(message::Error_level::MAJOR_ERROR);
|
|
|
+ }
|
|
|
+ response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
+ response_msg.set_command_id(request.command_id());
|
|
|
+ response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
+ response_msg.mutable_car_position()->CopyFrom(t_car_position);
|
|
|
+ Communication_message* response=new Communication_message();
|
|
|
+ response->reset(t_response_header, response_msg.SerializeAsString());
|
|
|
+ return send_response(response);
|
|
|
+ }
|
|
|
+ case Communication_message::eParkspace_release_request_msg:
|
|
|
+ {
|
|
|
+ message::Parkspace_release_request_msg request;
|
|
|
+ request.ParseFromString(p_msg->get_message_buf());
|
|
|
+ std::cout<<"release request, parkspace id: "<<request.release_space_info().parkspace_id()<<std::endl;
|
|
|
+
|
|
|
+ //根据车位信息定位待释放车位位置,车辆凭证号用于校验
|
|
|
+ //!!!!!此处跳过外部处理与调用的过程,直接在内部调用,发送分配结果用于测试,目前一直发布第一个车位
|
|
|
+ message::Parkspace_release_response_msg response_msg;
|
|
|
+ message::Base_info t_response_header;
|
|
|
+ message::Error_manager t_error;
|
|
|
+ t_response_header.set_msg_type(message::Message_type::eParkspace_release_response_msg);
|
|
|
+ t_response_header.set_timeout_ms(1000);
|
|
|
+ t_response_header.set_sender(message::Communicator::eParkspace_allocator);
|
|
|
+ t_response_header.set_receiver(message::Communicator::eMain);
|
|
|
+ if (m_parkspace_status_msg.parkspace_info_size() > 0)
|
|
|
+ {
|
|
|
+ t_error.set_error_code(0);
|
|
|
+ t_error.set_error_level(message::Error_level::NORMAL);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ t_error.set_error_code(1);
|
|
|
+ t_error.set_error_level(message::Error_level::MAJOR_ERROR);
|
|
|
+ }
|
|
|
+ response_msg.mutable_base_info()->CopyFrom(t_response_header);
|
|
|
+ response_msg.set_command_id(request.command_id());
|
|
|
+ response_msg.mutable_error_manager()->CopyFrom(t_error);
|
|
|
+ response_msg.mutable_release_space_info()->CopyFrom(request.release_space_info());
|
|
|
+ Communication_message* response=new Communication_message();
|
|
|
+ response->reset(t_response_header, response_msg.SerializeAsString());
|
|
|
+ return send_response(response);
|
|
|
+ }
|
|
|
}
|
|
|
return Error_manager(PARKSPACE_ALLOCATOR_MSG_RESPONSE_TYPE_ERROR, NEGLIGIBLE_ERROR, "parkspace allocation wrong request type");
|
|
|
}
|
|
|
|
|
|
//检查消息是否应由本模块接收
|
|
|
+//本模块接收车位分配请求、车位查询请求与车位释放请求
|
|
|
Error_manager Parkspace_allocation_communicator::check_msg(Communication_message* p_msg)
|
|
|
{
|
|
|
//通过 p_msg->get_message_type() 和 p_msg->get_receiver() 判断这条消息是不是车位请求消息.
|
|
|
- if ( p_msg->get_message_type() == Communication_message::Message_type::eParkspace_allocation_request_msg
|
|
|
- && p_msg->get_receiver() == Communication_message::Communicator::eParkspace_allocator)
|
|
|
- {
|
|
|
- return Error_code::SUCCESS;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //认为接受人
|
|
|
- return Error_code::INVALID_MESSAGE;
|
|
|
- }
|
|
|
+ if(p_msg->get_receiver() == Communication_message::Communicator::eParkspace_allocator)
|
|
|
+ {
|
|
|
+ switch(p_msg->get_message_type())
|
|
|
+ {
|
|
|
+ case Communication_message::Message_type::eParkspace_allocation_request_msg:
|
|
|
+ return Error_code::SUCCESS;
|
|
|
+ case Communication_message::Message_type::eParkspace_search_request_msg:
|
|
|
+ return Error_code::SUCCESS;
|
|
|
+ case Communication_message::Message_type::eParkspace_release_request_msg:
|
|
|
+ return Error_code::SUCCESS;
|
|
|
+ default:
|
|
|
+ return Error_code::INVALID_MESSAGE;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Error_manager Parkspace_allocation_communicator::check_executer(Communication_message* p_msg)
|
|
@@ -147,7 +240,7 @@ Error_manager Parkspace_allocation_communicator::check_executer(Communication_me
|
|
|
|
|
|
if ( executer_is_ready )
|
|
|
{
|
|
|
- std::cout << "executer_is_ready , " << std::endl;
|
|
|
+ // std::cout << "executer_is_ready , " << std::endl;
|
|
|
return Error_code::SUCCESS;
|
|
|
}
|
|
|
else
|