module_screen.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * @file
  3. * module_screen.h
  4. *
  5. * @brief
  6. * 大屏业务
  7. * @version
  8. * V1.0
  9. * @author
  10. * zhuyf
  11. * @date
  12. * 2021/05/18
  13. * @note
  14. *
  15. * @warning
  16. * @bug
  17. * @copyright
  18. * */
  19. #ifndef module_screen_hpp
  20. #define module_screen_hpp
  21. #include <map>
  22. #include <mutex>
  23. #include <thread>
  24. #include <memory>
  25. #include "module_singleton_base.h"
  26. #include "websocket/ws_common.h"
  27. struct mine_person{
  28. uint32_t m_id; // card id
  29. int m_battery; // value
  30. uint64_t m_recv_time; //
  31. mine_person()
  32. : m_id(0)
  33. , m_battery(0)
  34. , m_recv_time(0)
  35. {}
  36. mine_person(uint32_t id, int battery)
  37. : m_id(id)
  38. , m_battery(battery)
  39. , m_recv_time(time(NULL))
  40. {}
  41. };
  42. class module_screen: public singleton_base<module_screen>
  43. {
  44. private:
  45. friend class singleton_base<module_screen>;
  46. module_screen(){}
  47. public:
  48. void do_write(const std::map<uint64_t, sys::_CARD_POS_> card_pos_list);
  49. void do_wellhead();
  50. void put(const mine_person& p)
  51. {
  52. std::lock_guard<std::mutex> lg(m_mtx);
  53. auto it = m_card_list.find(p.m_id);
  54. if(it == m_card_list.end()){
  55. m_card_list.insert(std::make_pair(p.m_id, p));
  56. }else{
  57. m_card_list[p.m_id].m_recv_time = time(NULL);
  58. m_card_list[p.m_id].m_battery = p.m_battery;
  59. }
  60. }
  61. void start();
  62. void run();
  63. void stop()
  64. {
  65. m_exited = true;
  66. }
  67. private:
  68. std::unique_ptr<std::thread> m_thread;
  69. std::mutex m_mtx;
  70. std::map<uint64_t, mine_person> m_card_list;
  71. bool m_exited = false;
  72. };
  73. #endif