123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //
- // Created by huli on 2020/6/28.
- //
- #include "system_communicator.h"
- #include "command_manager.h"
- System_communicator::System_communicator()
- {
- }
- System_communicator::~System_communicator()
- {
- }
- //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
- Error_manager System_communicator::encapsulate_send_data()
- {
- return Error_code::SUCCESS;
- }
- Error_manager System_communicator::send_entrance_statu(message::Entrance_statu_msg& msg)
- {
- Communication_message message;
- message.reset(msg.base_info(),msg.SerializeAsString());
- return encapsulate_msg(&message);
- }
- /*
- * 发送消息函数
- */
- Error_manager System_communicator::encapsulate_msg(Communication_message* message)
- {
- return Communication_socket_base::encapsulate_msg(message);
- }
- /*
- * 检测消息是否合法
- */
- Error_manager System_communicator::check_msg(Communication_message* p_msg)
- {
- return SUCCESS;
- }
- //检查消息是否可以被处理, 需要重载
- Error_manager System_communicator::check_executer(Communication_message* p_msg)
- {
- return SUCCESS;
- }
- /*
- * 处理接收到的消息
- */
- Error_manager System_communicator::execute_msg(Communication_message* p_msg)
- {
- /*
- * 接收终端指令, 生成流程
- */
- switch(p_msg->get_message_type())
- {
- case Communication_message::eStore_command_request_msg:
- {
- if(Command_manager::get_instance_pointer()!= nullptr)
- {
- message::Store_command_request_msg request;
- if(request.ParseFromString(p_msg->get_message_buf())==false)
- {
- //严重错误
- return Error_manager(INVALID_MESSAGE,MAJOR_ERROR,"停车请求消息解析失败");
- }
- message::Store_command_response_msg response;
- Command_manager::get_instance_pointer()->execute_store_command(request,response);
- Communication_message send_response;
- send_response.reset(response.base_info(),response.SerializeAsString());
- //发送反馈
- encapsulate_msg(&send_response);
- }
- break;
- }
- case Communication_message::ePickup_command_request_msg:
- {
- if(Command_manager::get_instance_pointer()!= nullptr)
- {
- message::Pickup_command_request_msg request;
- if(request.ParseFromString(p_msg->get_message_buf())==false)
- {
- //严重错误
- return Error_manager(INVALID_MESSAGE,MAJOR_ERROR,"取车请求消息解析失败");
- }
- message::Pickup_command_response_msg response;
- //调用请求回调,无需判断返回值,错误信息保存在response中
- Command_manager::get_instance_pointer()->execute_pickup_command(request,response);
- Communication_message send_response;
- send_response.reset(response.base_info(),response.SerializeAsString());
- //发送反馈
- encapsulate_msg(&send_response);
- }
- break;
- }
- default:break;
- }
- return SUCCESS;
- }
|