system_communication.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // Created by huli on 2020/6/28.
  3. //
  4. #include "system_communication.h"
  5. //#include "../laser/laser_manager.h"
  6. //#include "../locate/locate_manager.h"
  7. #include "../system/system_executor.h"
  8. System_communication::System_communication()
  9. {
  10. }
  11. System_communication::~System_communication()
  12. {
  13. }
  14. //初始化 通信 模块。如下三选一
  15. Error_manager System_communication::communication_init()
  16. {
  17. return Communication_socket_base::communication_init();
  18. }
  19. //初始化 通信 模块。如下三选一
  20. Error_manager System_communication::communication_init(int dispatch_id)
  21. {
  22. switch ( dispatch_id )
  23. {
  24. case 0:
  25. {
  26. return Communication_socket_base::communication_init_from_protobuf(COMMUNICATION_PARAMETER_PATH_A);
  27. break;
  28. }
  29. case 1:
  30. {
  31. return Communication_socket_base::communication_init_from_protobuf(COMMUNICATION_PARAMETER_PATH_B);
  32. break;
  33. }
  34. case 2:
  35. {
  36. return Communication_socket_base::communication_init_from_protobuf(COMMUNICATION_PARAMETER_PATH_C);
  37. break;
  38. }
  39. default:
  40. {
  41. return Error_manager(Error_code::COMMUNICATION_READ_PROTOBUF_ERROR, Error_level::MINOR_ERROR,
  42. " System_communication::communication_init dispatch_id error ");
  43. break;
  44. }
  45. }
  46. return Error_code::SUCCESS;
  47. }
  48. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  49. Error_manager System_communication::check_msg(Communication_message* p_msg)
  50. {
  51. return System_executor::get_instance_references().check_msg(p_msg);
  52. }
  53. //检查执行者的状态, 判断能否处理这条消息, 需要子类重载
  54. Error_manager System_communication::check_executer(Communication_message* p_msg)
  55. {
  56. //检查对应模块的状态, 判断是否可以处理这条消息
  57. //同时也要判断是否超时, 超时返回 COMMUNICATION_ANALYSIS_TIME_OUT
  58. //如果处理器正在忙别的, 那么返回 COMMUNICATION_EXCUTER_IS_BUSY
  59. // std::cout << "Communication_socket_base::check_msg p_buf = " << p_msg->get_message_buf() << std::endl;
  60. // std::cout << "Communication_socket_base::check_msg size = " << p_msg->get_message_buf().size() << std::endl;
  61. Error_manager t_error;
  62. if ( p_msg->is_over_time() )
  63. {
  64. std::cout << "COMMUNICATION_ANALYSIS_TIME_OUT , " << std::endl;
  65. //超时:接收方不做处理,发送方会进行超时处理
  66. return Error_code::COMMUNICATION_ANALYSIS_TIME_OUT;
  67. }
  68. else
  69. {
  70. return System_executor::get_instance_references().check_executer(p_msg);
  71. }
  72. return Error_code::SUCCESS;
  73. }
  74. //处理消息, 需要子类重载
  75. Error_manager System_communication::execute_msg(Communication_message* p_msg)
  76. {
  77. return System_executor::get_instance_references().execute_msg(p_msg);
  78. }
  79. //定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
  80. Error_manager System_communication::encapsulate_send_data()
  81. {
  82. Error_manager t_error;
  83. return System_executor::get_instance_references().encapsulate_send_dispatch_manager_status();
  84. return Error_code::SUCCESS;
  85. }