card_base.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef _CARD_BASE_HPP_
  2. #define _CARD_BASE_HPP_
  3. #include <vector>
  4. #include <map>
  5. #include <memory>
  6. #include <atomic>
  7. #include "point.h"
  8. #include "common.h"
  9. #include <boost/circular_buffer.hpp>
  10. #include "websocket/ws_common.h"
  11. struct task;
  12. template<typename T> struct zloop;
  13. struct select_tool;
  14. struct smooth_tool;
  15. struct monkey_person;
  16. struct card_message_handle;
  17. struct card_location_base;
  18. struct message_locinfo;
  19. struct loc_message;
  20. struct mine_tool;
  21. struct location_card;
  22. struct card_pos;
  23. struct area_hover;
  24. struct site_area_hover;
  25. struct site;
  26. struct area_tool;
  27. struct message_tdoa_locinfo;
  28. struct message_pdoa_locinfo;
  29. struct message_ins_locinfo;
  30. namespace sys{
  31. struct _CARD_POS_;
  32. }
  33. struct card:point
  34. {
  35. card(uint32_t id,uint16_t dis,uint64_t type,int32_t deptid,int32_t level_id,uint32_t cid)
  36. :m_type(type)
  37. ,m_time(0)
  38. ,m_id(id)
  39. ,m_cid(cid)
  40. ,m_deptid(deptid)
  41. ,m_level_id(level_id)
  42. ,m_stat(0)
  43. ,m_biz_stat(0)
  44. ,m_pwr_stat(0)
  45. ,m_display(dis)
  46. ,m_ct(0)
  47. ,m_freq_id(0)
  48. ,m_freq(0.0)
  49. ,m_acc(0)
  50. ,m_speed(0)
  51. ,m_v_point(0, 0, 0)
  52. {}
  53. uint64_t type_(){return m_type;}
  54. uint64_t time_(){return m_time;}
  55. uint64_t m_type; //类型
  56. uint64_t m_time; //时间戳 ms
  57. uint32_t m_id; //卡号
  58. uint32_t m_cid; //标识id 人staff_id 车 vehicle_id
  59. int32_t m_deptid; //部门编号
  60. int32_t m_level_id; //职务级别
  61. int m_stat; //运动静止状态
  62. int m_biz_stat;
  63. int m_pwr_stat; //电量状态
  64. int m_battery_value = 10; //电量值
  65. uint16_t m_display; //1显示0不显示,往前端推送
  66. uint16_t m_ct; //ct
  67. uint8_t m_freq_id; // 频率索引
  68. double m_freq; // 频率值
  69. ///人卡(加速度状态),其值就是0和1,掘进机和采煤机,其值就是0~255,车辆,其值就需要乘以0.01,用于表示加速度值
  70. double m_acc;
  71. double m_speed; //速度
  72. double m_last_x = 0.0;
  73. double m_last_y = 0.0;
  74. point m_v_point; //车辆定位系统的定位结果
  75. bool m_isVehicleMap = false;
  76. };
  77. struct card_location_base:card,std::enable_shared_from_this<card_location_base>
  78. {
  79. uint64_t m_timeval=0;
  80. uint16_t m_display_old{0}; //1显示0不显示,往前端推送
  81. void update_display()
  82. {
  83. m_display_old = m_display;
  84. }
  85. bool eq_display()
  86. {
  87. return m_display_old == m_display;
  88. }
  89. std::uint8_t m_event[CARD_EVENT_COUNT_MAX]{0};
  90. std::unique_ptr<select_tool> m_sel_tool;
  91. std::unique_ptr<smooth_tool> m_smo_tool;
  92. std::unique_ptr<card_message_handle> m_message_handle;
  93. std::unique_ptr<location_card> m_his_location_card;
  94. std::atomic<int> m_upmine_flag{0};
  95. time_t m_help_last_time = 0; // 呼救持续时间
  96. int m_help_bit = 0;
  97. // 基站对应的数据信息:距离+时间戳
  98. struct sinfo{
  99. int sct;
  100. double sdist;
  101. double angle;
  102. double pdoa;
  103. sinfo()
  104. : sct(0)
  105. , sdist(0.0)
  106. , angle(0.0)
  107. , pdoa(0.0)
  108. {}
  109. };
  110. std::map<int, sinfo> last_site_info;
  111. std::map<int, sinfo> d3_last_site_info; // 3维上一次基站数据
  112. //pdoa
  113. int m_last_ct = -1;
  114. float m_last_dist = 0.0;
  115. uint16_t m_last_site_id = 0; // 卡上一次定位的分站id
  116. uint64_t m_last_recv_time = 0; // 卡上一次接收时间
  117. int m_last_site_dir = -1; // 卡上一次定位的分站天线1朝向
  118. bool m_last_over_site = false; // 卡是否过分站
  119. int m_cache_nums = 0; // 过分站后缓存的数据个数
  120. int m_buff_size = 0;
  121. float m_pdoa_diff = 100.0; // pdoa分站当前上传相位差
  122. float m_last_pdoa_diff = 100.0; // pdoa 分站上一帧数据的相位差
  123. boost::circular_buffer<float> m_cb_pdoa; // the list of current pdoa's different of phase;
  124. boost::circular_buffer<float> m_cb_tof; // the list of tof that is pdoa history value
  125. boost::circular_buffer<point> m_cb_point;
  126. point m_last_point;
  127. int m_cur_site_counts = 0; // 当前基站缓存数据总数
  128. std::vector<float> m_vtp_dist; // 相同分站存储距离数据
  129. bool m_over_site = false; // 过分站状态
  130. //int m_last_down_stream_idx = 0;
  131. boost::circular_buffer<int> m_cb_stream_idx; // 分站下行方向的索引号
  132. bool m_enable_anti_collision = false;
  133. int m_call_level = 0;
  134. std::map<int, std::vector<message_ins_locinfo>> m_msg_list;
  135. card_location_base()=default;
  136. card_location_base(const std::string&type,uint32_t id,uint16_t dis,int16_t t,int32_t,int32_t,uint32_t );
  137. void inc_upmine_flag(int flag){m_upmine_flag=flag;}
  138. int upmine_flag(){return m_upmine_flag.load();}
  139. virtual void do_business(const std::shared_ptr<site>&site,const point &pt)=0;
  140. virtual void on_timer()=0;
  141. virtual std::shared_ptr<mine_tool> get_mine_tool()=0;
  142. virtual void clear();
  143. virtual void reset(std::shared_ptr<monkey_person> mp){}
  144. virtual int get_vehicle_type_id(){return 0;}
  145. virtual void set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)=0;
  146. virtual int get_area(){return -1;}
  147. virtual std::shared_ptr<area_tool> get_area_tool()=0;
  148. virtual int get_vehicle_category_id(){return -1;}
  149. virtual int get_workline(){return -1;}
  150. virtual void get_card(bool f)=0;
  151. virtual void site_hover(int sid){}
  152. virtual void handle_message(uint16_t ct,uint8_t& value){}
  153. void make_his_location(uint64_t t,const point & pt,bool bclose = false);
  154. void make_his_location_cell_card_tdoa(uint64_t t, const sys::tdoa_2d_data& tdoa2d);
  155. void on_message(zloop<task*>* loop, message_locinfo&loc, bool is_history);
  156. void on_message(zloop<task*>* loop, message_tdoa_locinfo& loc, bool is_history);
  157. void on_message(zloop<task*>* loop, message_pdoa_locinfo& loc, bool is_history);
  158. void on_message(zloop<task*>* loop, message_ins_locinfo& loc, bool is_history);
  159. void on_location(const std::vector<point>&vp, const std::vector<loc_message> &lm);
  160. void do_status(int st);
  161. void upt_card_pos(sys::_CARD_POS_&cp, point &pt);
  162. void del_card_pos();
  163. int get_stat();
  164. void put_traffic_light(card_pos& cp);
  165. void set_event_flag(EVENT_TYPE et,std::uint8_t f=1){m_event[et]=f;}
  166. bool get_event_flag(EVENT_TYPE et){return m_event[et];}
  167. void do_site_coverage(message_pdoa_locinfo& loc);
  168. void do_card_locate_event(const message_pdoa_locinfo& loc);
  169. void do_site_locate_event(const message_pdoa_locinfo& loc);
  170. bool is_person() const;
  171. bool is_vehicle() const;
  172. void set_base_data(uint32_t cid,uint16_t type,uint32_t deptid,int32_t level_id);
  173. virtual ~card_location_base();
  174. static std::shared_ptr<card_location_base> make_person(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  175. int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string & sname,const std::string & dname,int worktype_id);
  176. static std::shared_ptr<card_location_base> make_car(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t,
  177. int32_t deptid, int32_t categoryid, int type_id,int32_t level_id,uint32_t cid);
  178. void set_freq_id(const uint8_t& val)
  179. {
  180. m_freq_id = val;
  181. }
  182. };
  183. #endif