card.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef _CARD_HPP_
  2. #define _CARD_HPP_
  3. #include <message.h>
  4. #include <ev++.h>
  5. #include "point.h"
  6. #include "ant.h"
  7. #include "write-copy.h"
  8. #include "websocket/ws_common.h"
  9. #include "common.h"
  10. #include "area.h"
  11. #include "mine.h"
  12. #include "site_area.h"
  13. #define CARD_LOST_TIME_OUT (30*1000)
  14. struct task;
  15. template<typename T> struct zloop;
  16. struct select_tool;
  17. struct smooth_tool;
  18. struct monkey_person;
  19. struct card_message_handle;
  20. struct card:point
  21. {
  22. card(uint32_t id,uint16_t dis,int16_t type,int32_t deptid)
  23. :m_id(id)
  24. ,m_type(type)
  25. ,m_display(dis)
  26. ,m_speed(0)
  27. ,m_is_attendance(0)
  28. ,m_stat(0)
  29. ,m_ct(0)
  30. ,m_time(0)
  31. ,m_deptid(deptid)
  32. {}
  33. uint32_t m_id; //卡号
  34. int16_t m_type; //类型
  35. uint16_t m_display; //1显示0不显示,往前端推送
  36. double m_speed; //速度
  37. int m_is_attendance; //井上井下状态 0初始状态 1 井上 2 井下
  38. int m_stat; //运动静止状态
  39. uint16_t m_ct; //ct
  40. uint64_t m_time; //时间戳
  41. int32_t m_deptid; //部门编号
  42. };
  43. struct card_location_base:card
  44. {
  45. std::unique_ptr<select_tool> m_sel_tool;
  46. std::unique_ptr<smooth_tool> m_smo_tool;
  47. card_message_handle *m_message_handle=nullptr;
  48. ev::dynamic_loop * m_loop = nullptr;
  49. ev::timer m_timer;
  50. card_location_base()=default;
  51. card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t );
  52. virtual void do_business(const point &pt)=0;
  53. virtual void set(ev::dynamic_loop * loop)=0;
  54. virtual void site_hover(int sid)=0;
  55. virtual std::shared_ptr<area_hover> get_area_hover()=0;
  56. virtual std::shared_ptr<mine_tool> get_mine_tool()=0;
  57. virtual std::shared_ptr<site_area_hover> get_site_area()=0;
  58. virtual void clear();
  59. virtual void reset(std::shared_ptr<monkey_person> mp){}
  60. void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history);
  61. void on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm );
  62. void do_status(STATUS_CARD st);
  63. void upt_card_pos(YA::_CARD_POS_ &,const point &pt);
  64. int get_stat();
  65. bool is_person() const
  66. {
  67. return CT_PERSON == m_type;
  68. }
  69. bool is_vehicle() const
  70. {
  71. return CT_VEHICLE == m_type;
  72. }
  73. virtual ~card_location_base();
  74. };
  75. struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_base>>
  76. {
  77. void init_staffer();
  78. void init_vehicle();
  79. uint64_t getId(uint32_t cardid,uint64_t);
  80. void on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history);
  81. void init_card_from_db();
  82. /// (类型<<32)|卡号
  83. static uint64_t to_id64(int32_t type, uint32_t id)
  84. {
  85. return (static_cast<uint64_t>(type)<<32)|id;
  86. }
  87. static std::string to_id64_str(int32_t type, uint32_t id)
  88. {
  89. char sql[15] = {'\0'};
  90. sprintf(sql, "%03d%010d", type, id);
  91. return std::string(sql);
  92. }
  93. ~card_list(){}
  94. };
  95. #endif