Terminal_communication.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // Created by zx on 2020/7/13.
  3. //
  4. #ifndef NNXX_TESTS_TERMINAL_COMMUNICATION_H
  5. #define NNXX_TESTS_TERMINAL_COMMUNICATION_H
  6. #include <process_message.pb.h>
  7. #include "../tool/singleton.h"
  8. #include "../communication/communication_socket_base.h"
  9. #include "terminal_message.pb.h"
  10. #include "parkspace_allocation_message.pb.h"
  11. #include "message_compare.h"
  12. class Terminal_communication :public Singleton<Terminal_communication>, public Communication_socket_base{
  13. friend class Singleton<Terminal_communication>;
  14. private:
  15. // 父类的构造函数必须保护,子类的构造函数必须私有。
  16. Terminal_communication();
  17. public:
  18. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  19. Terminal_communication(const Terminal_communication& other) = delete;
  20. Terminal_communication& operator =(const Terminal_communication& other) = delete;
  21. ~Terminal_communication();
  22. /*
  23. * 设置终端id
  24. */
  25. Error_manager set_terminal_id(int id);
  26. /*
  27. * 发送停车指令请求
  28. */
  29. Error_manager store_request(message::Store_command_request_msg& request,message::Store_command_response_msg& response);
  30. /*
  31. * 发送取车指令请求
  32. */
  33. Error_manager pickup_request(message::Pickup_command_request_msg& request,message::Pickup_command_response_msg& response);
  34. /*
  35. * 检查入口完成状态
  36. */
  37. Error_manager check_store_entrance_statu(int terminal_id,message::Entrance_statu& statu);
  38. /*
  39. * 检查出口完成状态
  40. */
  41. Error_manager check_pickup_entrance_statu(int terminal_id,message::Entrance_statu& statu);
  42. protected:
  43. //重载函数
  44. virtual Error_manager encapsulate_msg(Communication_message* message);
  45. virtual Error_manager execute_msg(Communication_message* p_msg);
  46. /*
  47. * 检测消息是否可被处理
  48. */
  49. virtual Error_manager check_msg(Communication_message* p_msg);
  50. /*
  51. * 心跳发送函数,重载
  52. */
  53. virtual Error_manager encapsulate_send_data();
  54. //检查消息是否可以被解析, 需要重载
  55. virtual Error_manager check_executer(Communication_message* p_msg);
  56. private:
  57. message::Store_command_response_msg m_store_response_msg;
  58. message::Pickup_command_response_msg m_pickup_response_msg;
  59. int m_terminal_id;
  60. std::mutex m_statu_lock;
  61. message::Entrance_statu_msg m_entrance_status;
  62. };
  63. #endif //NNXX_TESTS_TERMINAL_COMMUNICATION_H