command_accepter.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Created by huli on 2020/6/28.
  3. //
  4. #include "command_accepter.h"
  5. #include "command_manager.h"
  6. Command_accepter::Command_accepter()
  7. {
  8. }
  9. Command_accepter::~Command_accepter()
  10. {
  11. }
  12. //发送停车流程进度
  13. Error_manager Command_accepter::post_process_statu(message::Storing_process_statu_msg& msg)
  14. {
  15. Communication_message message;
  16. message.reset(msg.base_info(),msg.SerializeAsString());
  17. return Message_communicator::get_instance_pointer()->send_msg(&message);
  18. }
  19. //发送取车流程进度
  20. Error_manager Command_accepter::post_process_statu(message::Picking_process_statu_msg& msg)
  21. {
  22. Communication_message message;
  23. message.reset(msg.base_info(),msg.SerializeAsString());
  24. return Message_communicator::get_instance_pointer()->send_msg(&message);
  25. }
  26. //发送中控状态消息
  27. Error_manager Command_accepter::post_central_statu(message::Central_controller_statu_msg& msg)
  28. {
  29. Communication_message message;
  30. message.reset(msg.base_info(),msg.SerializeAsString());
  31. return Message_communicator::get_instance_pointer()->send_msg(&message);
  32. }
  33. /*
  34. * 处理接收到的消息
  35. */
  36. Error_manager Command_accepter::consume_msg(Communication_message* p_msg)
  37. {
  38. /*
  39. * 接收终端指令, 生成流程
  40. */
  41. Error_manager code;
  42. switch(p_msg->get_message_type())
  43. {
  44. case Communication_message::eStore_command_request_msg:
  45. {
  46. if(Command_manager::get_instance_pointer()!= nullptr)
  47. {
  48. message::Store_command_request_msg request;
  49. if(request.ParseFromString(p_msg->get_message_buf())==false)
  50. {
  51. //严重错误
  52. return Error_manager(INVALID_MESSAGE,MAJOR_ERROR,"停车请求消息解析失败");
  53. }
  54. code=Command_manager::get_instance_pointer()->execute_store_command(request);
  55. LOG_IF(ERROR,code!=SUCCESS)<<code.get_error_description();
  56. }
  57. break;
  58. }
  59. case Communication_message::ePickup_command_request_msg:
  60. {
  61. if(Command_manager::get_instance_pointer()!= nullptr)
  62. {
  63. message::Pickup_command_request_msg request;
  64. if(request.ParseFromString(p_msg->get_message_buf())==false)
  65. {
  66. //严重错误
  67. return Error_manager(INVALID_MESSAGE,MAJOR_ERROR,"取车请求消息解析失败");
  68. }
  69. message::Pickup_command_response_msg response;
  70. //调用请求回调,无需判断返回值,错误信息保存在response中
  71. code=Command_manager::get_instance_pointer()->execute_pickup_command(request);
  72. LOG_IF(ERROR,code!=SUCCESS)<<code.get_error_description();
  73. }
  74. break;
  75. }
  76. default:break;
  77. }
  78. return SUCCESS;
  79. }