loc_common.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef algo_loc_common_h
  2. #define algo_loc_common_h
  3. #include <unordered_map>
  4. #include <deque>
  5. #include "point.h"
  6. /*
  7. * 基站id和基站坐标
  8. *
  9. * */
  10. struct site_point: point
  11. {
  12. unsigned int m_site_id; //分站号
  13. site_point():point(0.0,0.0), m_site_id(0)
  14. {}
  15. site_point(const point& p):point(p), m_site_id(0)
  16. {}
  17. site_point& operator=(const point& rhs)
  18. {
  19. this->x = rhs.x;
  20. this->y = rhs.y;
  21. this->z = rhs.z;
  22. return *this;
  23. }
  24. };
  25. /*
  26. * 基站构成的三角形
  27. * */
  28. struct triangle{
  29. std::vector<site_point> m_vertex; //三角形三个顶点
  30. triangle()
  31. {
  32. m_vertex.clear();
  33. std::vector<site_point>().swap(m_vertex);
  34. }
  35. /*
  36. * 求点P到三角形质心的距离
  37. *
  38. * */
  39. double get_distance(const point& p)
  40. {
  41. if(m_vertex.size() < 3 || m_vertex.size() > 3){
  42. return 0.0;
  43. }
  44. // 中心点坐标
  45. point _cp;
  46. for(auto it = m_vertex.cbegin(); it != m_vertex.cend(); ++it)
  47. {
  48. _cp.x += (*it).x;
  49. _cp.y += (*it).y;
  50. }
  51. _cp.x /= 3;
  52. _cp.y /= 3;
  53. return sqrt((p.x - _cp.x)*(p.x - _cp.x) + (p.y - _cp.y)*(p.y - _cp.y));
  54. }
  55. };
  56. struct algo_solution{
  57. std::shared_ptr<point> m_pos;
  58. std::shared_ptr<triangle> m_triangle;
  59. algo_solution(): m_pos(nullptr), m_triangle(nullptr)
  60. {}
  61. };
  62. struct pdoa_data{
  63. int site_id; // 分站号
  64. float distance; // 距离
  65. float pdoa; // pdoa值
  66. uint64_t loc_time; // 定位时间戳(毫秒级)
  67. pdoa_data(): site_id(0), distance(0.0), pdoa(0.0), loc_time(0)
  68. {}
  69. pdoa_data operator=(const pdoa_data& pd)
  70. {
  71. this->site_id = pd.site_id;
  72. this->distance = pd.distance;
  73. this->pdoa = pd.pdoa;
  74. this->loc_time = pd.loc_time;
  75. return *this;
  76. }
  77. };
  78. // 数据队列定义
  79. using msg_map = std::unordered_map<std::string, std::shared_ptr<loc_message>>;
  80. struct message_item{
  81. uint16_t m_card_stamp; // 卡的ct号
  82. msg_map m_msg_map;
  83. message_item(): m_card_stamp(0)
  84. {}
  85. };
  86. using msg_deque = std::deque<message_item>;
  87. const double EPS = 0.00001;
  88. const double SAFE = 3.0;
  89. #endif