card_base.h 8.1 KB

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