communication_message.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. };
  28. //通讯单元
  29. enum Communicator
  30. {
  31. eEmpty=0x0000, //空
  32. eMain=0x0001, //主流程
  33. eTerminor=0x0100, //终端
  34. eTable=0x0200, //数据表
  35. eMeasurer=0x0300, //测量单元
  36. eProcess=0x0400, //调度机构
  37. //...
  38. };
  39. public:
  40. Communication_message();
  41. Communication_message(std::string message_buf);
  42. Communication_message(char* p_buf, int size);
  43. Communication_message(const Communication_message& other)= default;
  44. Communication_message& operator =(const Communication_message& other)= default;
  45. ~Communication_message();
  46. public://API functions
  47. bool is_over_time();
  48. public://get or set member variable
  49. void reset(const message::Base_info& base_info, std::string receive_string);
  50. Message_type get_message_type();
  51. Communicator get_sender();
  52. Communicator get_receiver();
  53. std::string& get_message_buf();
  54. protected://member variable
  55. Message_type m_message_type; //消息类型
  56. std::chrono::system_clock::time_point m_receive_time; //接收消息的时间点
  57. std::chrono::milliseconds m_timeout_ms; //超时时间, 整个软件都统一为毫秒
  58. Communicator m_sender; //发送者
  59. Communicator m_receiver; //接受者
  60. std::string m_message_buf; //消息数据
  61. private:
  62. };
  63. #endif //NNXX_TESTS_COMMUNICATION_MESSAGE_H