message_communicator.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // Created by zx on 2020/8/28.
  3. //
  4. #include "message_communicator.h"
  5. #include "measure_excutor.h"
  6. #include "exception_solver.h"
  7. #include "dispatch_excutor.h"
  8. #include "parkspace_excutor.h"
  9. #include "command_accepter.h"
  10. Message_communicator::Message_communicator()
  11. {
  12. }
  13. Message_communicator::~Message_communicator()
  14. {
  15. }
  16. /*
  17. * 发送消息
  18. */
  19. Error_manager Message_communicator::send_msg(Communication_message* p_msg)
  20. {
  21. return Communication_socket_base::encapsulate_msg(p_msg);
  22. }
  23. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  24. Error_manager Message_communicator::encapsulate_send_data()
  25. {
  26. return Error_code::SUCCESS;
  27. }
  28. /*
  29. * 检测消息是否合法
  30. */
  31. Error_manager Message_communicator::check_msg(Communication_message* p_msg)
  32. {
  33. if ( (p_msg->get_receiver() == Communication_message::Communicator::eMain) &&
  34. (p_msg->get_message_type() == Communication_message::Message_type::eDispatch_response_msg
  35. ||p_msg->get_message_type() == Communication_message::Message_type::eDispatch_status_msg
  36. ||p_msg->get_message_type() == Communication_message::Message_type::eStore_command_request_msg
  37. ||p_msg->get_message_type() == Communication_message::Message_type::ePickup_command_request_msg
  38. ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_allocation_response_msg
  39. ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_search_response_msg
  40. ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_release_response_msg
  41. ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_confirm_alloc_response_msg
  42. ||p_msg->get_message_type() == Communication_message::Message_type::eParkspace_allocation_status_msg
  43. ||p_msg->get_message_type() == Communication_message::Message_type::eLocate_response_msg
  44. ||p_msg->get_message_type() == Communication_message::Message_type::eLocate_status_msg
  45. ||p_msg->get_message_type() == Communication_message::Message_type::eProcess_manual_operation_msg
  46. ||p_msg->get_message_type() == Communication_message::Message_type::eEntrance_manual_operation_msg))
  47. {
  48. return Error_code::SUCCESS;
  49. }
  50. return Error_code::INVALID_MESSAGE;
  51. }
  52. //检查消息是否可以被处理, 需要重载
  53. Error_manager Message_communicator::check_executer(Communication_message* p_msg)
  54. {
  55. return SUCCESS;
  56. }
  57. /*
  58. * 处理接收到的消息
  59. */
  60. Error_manager Message_communicator::execute_msg(Communication_message* p_msg)
  61. {
  62. /*
  63. * 接收终端指令, 生成流程
  64. */
  65. Error_manager code;
  66. switch(p_msg->get_message_type())
  67. {
  68. //终端消息
  69. case Communication_message::eStore_command_request_msg:
  70. {
  71. Command_accepter::get_instance_pointer()->consume_msg(p_msg);
  72. break;
  73. }
  74. case Communication_message::ePickup_command_request_msg:
  75. {
  76. Command_accepter::get_instance_pointer()->consume_msg(p_msg);
  77. break;
  78. }
  79. ///搬运结果反馈消息
  80. case Communication_message::eDispatch_response_msg:
  81. {
  82. Dispatch_excutor::get_instance_pointer()->consume_msg(p_msg);
  83. break;
  84. }
  85. case Communication_message::eDispatch_status_msg:
  86. {
  87. Dispatch_excutor::get_instance_pointer()->consume_msg(p_msg);
  88. break;
  89. }
  90. ///// 车位分配模块的消息
  91. case Communication_message::eParkspace_allocation_response_msg:
  92. {
  93. Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg);
  94. break;
  95. }
  96. case Communication_message::eParkspace_search_response_msg:
  97. {
  98. Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg);
  99. break;
  100. }
  101. case Communication_message::eParkspace_release_response_msg:
  102. {
  103. Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg);
  104. break;
  105. }
  106. case Communication_message::eParkspace_confirm_alloc_response_msg:
  107. {
  108. Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg);
  109. break;
  110. }
  111. case Communication_message::eParkspace_allocation_status_msg:
  112. {
  113. Parkspace_excutor::get_instance_pointer()->consume_msg(p_msg);
  114. break;
  115. }
  116. ///测量结果反馈消息
  117. case Communication_message::eLocate_response_msg:
  118. {
  119. Measure_excutor::get_instance_pointer()->consume_msg(p_msg);
  120. break;
  121. }
  122. //测量系统状态
  123. case Communication_message::eLocate_status_msg:
  124. {
  125. Measure_excutor::get_instance_pointer()->consume_msg(p_msg);
  126. break;
  127. }
  128. //异常处理,手动操作
  129. case Communication_message::eProcess_manual_operation_msg:
  130. {
  131. Exception_solver::get_instance_pointer()->consume_msg(p_msg);
  132. break;
  133. }
  134. case Communication_message::eEntrance_manual_operation_msg:
  135. {
  136. Exception_solver::get_instance_pointer()->consume_msg(p_msg);
  137. break;
  138. }
  139. default:break;
  140. }
  141. return SUCCESS;
  142. }