card_base.h 6.9 KB

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