system_executor.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // Created by huli on 2020/7/2.
  3. //
  4. #ifndef NNXX_TESTS_SYSTEM_EXECUTOR_H
  5. #define NNXX_TESTS_SYSTEM_EXECUTOR_H
  6. #include "../tool/thread_pool.h"
  7. #include "../tool/singleton.h"
  8. #include "../tool/pathcreator.h"
  9. #include "../error_code/error_code.h"
  10. #include "../communication/communication_message.h"
  11. #include "../tool/common_data.h"
  12. #include "../tool/measure_filter.h"
  13. #include "../message/measure_message.pb.h"
  14. #include "../message/message.pb.h"
  15. #include "../system/system_communication.h"
  16. #include "../system/system_communication_mq.h"
  17. #include "../wanji_lidar/wanji_manager.h"
  18. #include "../velodyne_lidar/velodyne_manager.h"
  19. #define DISP_TERM_ID -1
  20. // 0wj 1velo 2both
  21. #define WJ_VELO 2
  22. class System_executor:public Singleton<System_executor>
  23. {
  24. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  25. friend class Singleton<System_executor>;
  26. public:
  27. //系统执行者的状态
  28. enum System_executor_status
  29. {//default SYSTEM_EXECUTOR_UNKNOW = 0
  30. SYSTEM_EXECUTOR_UNKNOW = 0, //
  31. SYSTEM_EXECUTOR_READY = 1, //
  32. SYSTEM_EXECUTOR_FAULT = 10, //
  33. };
  34. private:
  35. // 父类的构造函数必须保护,子类的构造函数必须私有。
  36. System_executor();
  37. public:
  38. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  39. System_executor(const System_executor& other) = delete;
  40. System_executor& operator =(const System_executor& other) = delete;
  41. ~System_executor();
  42. public://API functions
  43. //初始化
  44. Error_manager system_executor_init(int threads_size, int terminal_id);
  45. //反初始化
  46. Error_manager system_executor_uninit();
  47. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  48. Error_manager check_msg(Communication_message* p_msg);
  49. //检查执行者的状态, 判断能否处理这条消息,
  50. Error_manager check_executer(Communication_message* p_msg);
  51. //处理消息的执行函数
  52. Error_manager execute_msg(Communication_message* p_msg);
  53. //检查状态
  54. Error_manager check_status();
  55. //定时发送状态信息
  56. Error_manager encapsulate_send_status();
  57. //定时发送mq状态信息
  58. Error_manager encapsulate_send_mq_status();
  59. //判断是否为待机,如果已经准备好,则可以执行任务。
  60. bool is_ready();
  61. int transMeasureStatus(const int &statu);
  62. // 更新消息中关于定位结果与超界信息的内容
  63. bool update_measure_info(message::Ground_status_msg &msg, Common_data::Car_wheel_information &measure_info, int cloud_size);
  64. // 更新消息中关于终端的定位结果与超界信息的内容
  65. bool update_terminal_measure_info(message::Ground_status_msg &msg, Common_data::Car_wheel_information &measure_info, int cloud_size);
  66. public://get or set member variable
  67. System_executor_status get_system_executor_status();
  68. int get_terminal_id();
  69. public:
  70. //注注注注注意了, 线程池的函数独立运行,
  71. //传递参数, 不能使用即将销毁的内存
  72. //雷达感测定位 的处理函数
  73. //input::command_id, 消息指令id, 由主控制系统生成的唯一码
  74. //input::command_id, 终端id, 对应具体的某个车位
  75. //return::void, 没有返回, 执行结果直接生成一条答复消息, 然后通过通信返回
  76. void execute_for_measure(std::string command_info, int terminal_id,std::chrono::system_clock::time_point receive_time);
  77. protected://member variable
  78. System_executor_status m_system_executor_status; //系统执行者的状态
  79. Thread_pool m_thread_pool; //执行多任务的线程池
  80. int m_terminal_id; //终端id
  81. private:
  82. };
  83. #endif //NNXX_TESTS_SYSTEM_EXECUTOR_H