dispatch_singlechip.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // Created by huli on 2021/11/18.
  3. //
  4. #ifndef NNXX_TESTS_DISPATCH_SINGLECHIP_H
  5. #define NNXX_TESTS_DISPATCH_SINGLECHIP_H
  6. #include "../error_code/error_code.h"
  7. #include <glog/logging.h>
  8. #include <thread>
  9. #include <mutex>
  10. #include "../tool/thread_condition.h"
  11. #include "../tool/common_data.h"
  12. #include "../tool/time_tool.h"
  13. #include "../task/task_base.h"
  14. #include "../message/dispatch_message.pb.h"
  15. #include "../message/singlechip_msg.pb.h"
  16. #include "../dispatch/dispatch_communication.h"
  17. //调度单片机通信
  18. class Dispatch_singlechip
  19. {
  20. public:
  21. //调度plc状态
  22. enum Dispatch_singlechip_status
  23. {
  24. DISPATCH_SINGLECHIP_UNKNOW = 0, //未知
  25. DISPATCH_SINGLECHIP_READY = 1, //准备,待机
  26. DISPATCH_SINGLECHIP_FAULT = 10, //故障
  27. DISPATCH_SINGLECHIP_DISCONNECT = 11, //断连
  28. };
  29. public:
  30. Dispatch_singlechip();
  31. Dispatch_singlechip(const Dispatch_singlechip& other)= default;
  32. Dispatch_singlechip& operator =(const Dispatch_singlechip& other)= default;
  33. ~Dispatch_singlechip();
  34. public://API functions
  35. //调度单片机 初始化
  36. Error_manager dispatch_singlechip_init(int plc_id, int singlechip_id, int singlechip_direction);
  37. //调度单片机 反初始化
  38. Error_manager dispatch_singlechip_uninit();
  39. //调度单片机 执行状态消息
  40. Error_manager execute_for_singlechip_data_msg(message::Singlechip_data &singlechip_data_msg, bool validity);
  41. //判断出口是否空闲
  42. bool is_outlet_ready();
  43. public://get or set member variable
  44. Dispatch_singlechip_status get_dispatch_singlechip_status();
  45. protected://member functions
  46. //执行外界任务的执行函数
  47. void execute_thread_fun();
  48. protected://member variable
  49. std::atomic<Dispatch_singlechip_status> m_dispatch_singlechip_status;//调度单片机的状态
  50. int m_plc_id; //设备id, 索引, 就是楚天车库的单元号.
  51. int m_singlechip_id; //单片机id
  52. int m_singlechip_direction; //单片机方向, 1是入口, 2是出口
  53. std::mutex m_lock; //锁
  54. //任务执行线程
  55. std::thread* mp_execute_thread; //执行的线程指针,内存由本类管理
  56. Thread_condition m_execute_condition; //执行的条件变量
  57. //数据缓存
  58. message::Singlechip_data m_singlechip_data_msg; //单片机消息
  59. bool m_validity; //有效性
  60. std::chrono::system_clock::time_point m_singlechip_data_msg_updata_time; //状态更新时间点
  61. std::atomic<bool> m_singlechip_data_msg_updata_flag;
  62. private:
  63. };
  64. #endif //NNXX_TESTS_DISPATCH_SINGLECHIP_H