communication_message.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Created by huli on 2020/6/29.
  3. //
  4. #ifndef NNXX_TESTS_COMMUNICATION_MESSAGE_H
  5. #define NNXX_TESTS_COMMUNICATION_MESSAGE_H
  6. #include "../error_code/error_code.h"
  7. #include <time.h>
  8. #include <sys/time.h>
  9. #include <chrono>
  10. //#include <iosfwd>
  11. #include <string>
  12. #include "../message/message_base.pb.h"
  13. class Communication_message
  14. {
  15. public:
  16. //消息类型定义,每个在网络上传输的消息必须含有这个属性
  17. enum Message_type
  18. {
  19. eBase_msg = 0x00,
  20. eCommand_msg = 0x01, //指令消息
  21. eLocate_status_msg = 0x11, //定位模块状态消息
  22. eLocate_request_msg = 0x12, //定位请求消息
  23. eLocate_response_msg = 0x13, //定位反馈消息
  24. eHarware_statu_msg = 0x21, //调度模块硬件状态消息
  25. eExecute_request_msg = 0x22, //请求调度消息
  26. eExecute_response_msg = 0x23, //调度结果反馈消息
  27. eParkspace_allocation_status_msg = 0x31, //车位分配模块状态消息,包括车位信息
  28. eParkspace_allocation_request_msg = 0x32, //请求分配车位消息
  29. eParkspace_allocation_response_msg = 0x33, //分配车位结果反馈消息
  30. eParkspace_search_request_msg = 0x34, //查询车位请求消息
  31. eParkspace_search_response_msg = 0x35, //查询车位反馈消息
  32. eParkspace_release_request_msg = 0x36, //释放车位请求消息
  33. eParkspace_release_response_msg = 0x37, //释放车位反馈消息
  34. eParkspace_force_update_request_msg = 0x38, //手动修改车位消息
  35. eParkspace_force_update_response_msg = 0x39,//手动修改车位反馈消息
  36. };
  37. //通讯单元
  38. enum Communicator
  39. {
  40. eEmpty=0x0000, //空
  41. eMain=0x0001, //主流程
  42. eTerminor=0x0100, //终端
  43. eParkspace_allocator=0x0200, //数据表
  44. eMeasurer=0x0300, //测量单元
  45. eProcess=0x0400, //调度机构
  46. //...
  47. };
  48. public:
  49. Communication_message();
  50. Communication_message(std::string message_buf);
  51. Communication_message(char* p_buf, int size);
  52. Communication_message(const Communication_message& other)= default;
  53. Communication_message& operator =(const Communication_message& other)= default;
  54. ~Communication_message();
  55. public://API functions
  56. bool is_over_time();
  57. public://get or set member variable
  58. void reset(const message::Base_info& base_info, std::string receive_string);
  59. Message_type get_message_type();
  60. Communicator get_sender();
  61. Communicator get_receiver();
  62. std::string& get_message_buf();
  63. protected://member variable
  64. Message_type m_message_type; //消息类型
  65. std::chrono::system_clock::time_point m_receive_time; //接收消息的时间点
  66. std::chrono::milliseconds m_timeout_ms; //超时时间, 整个软件都统一为毫秒
  67. Communicator m_sender; //发送者
  68. Communicator m_receiver; //接受者
  69. std::string m_message_buf; //消息数据
  70. private:
  71. };
  72. #endif //NNXX_TESTS_COMMUNICATION_MESSAGE_H