message.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #ifndef __MESSAGE_HPP__
  2. #define __MESSAGE_HPP__
  3. #include <stdint.h>
  4. #include <time.h>
  5. #include "worker.h"
  6. #include "protocol.h"
  7. #include <cmath>
  8. struct zistream;
  9. // 惯导数据,含加速度和角速度
  10. struct ins_data{
  11. double m_acc;
  12. double m_ang;
  13. // 0,1,2分别对应加速度的X轴,Y轴,Z轴
  14. std::array<uint16_t, 3> m_acc_data;
  15. std::array<uint16_t, 3> m_ang_data;
  16. ins_data()
  17. : m_acc(0)
  18. , m_ang(0)
  19. {
  20. m_acc_data.fill(0);
  21. m_ang_data.fill(0);
  22. }
  23. double get_acc()
  24. {
  25. return (m_acc = sqrt(pow(get_acc(0), 2) + pow(get_acc(1), 2) + pow(get_acc(2), 2)));
  26. }
  27. double get_acc(int i)
  28. {
  29. return calc_acc(m_acc_data[i]);
  30. }
  31. double get_gyro()
  32. {
  33. return (m_ang = sqrt(pow(get_gyro(0), 2) + pow(get_gyro(1), 2) + pow(get_gyro(2), 2)));
  34. }
  35. double get_gyro(int i)
  36. {
  37. return calc_gyro(m_ang_data[i]);
  38. }
  39. double calc_acc(const uint16_t val)
  40. {
  41. int acc_fs = 16;
  42. double ret = 0.0;
  43. uint8_t H = 0, L = 0;
  44. H = val >> 8;
  45. L = val & 0xFF;
  46. if(H > 0x80){
  47. H = ~H;
  48. L = (~L) + 0x01;
  49. ret = (-(((H << 8) | L) * 0.061 * (acc_fs / 2) / 1000));
  50. }else{
  51. ret = ((((H << 8) | L) * 0.061 * (acc_fs / 2) / 1000));
  52. }
  53. return ret;
  54. }
  55. double calc_gyro(const uint16_t val)
  56. {
  57. double ret = 0.0;
  58. uint8_t H = 0, L = 0;
  59. H = val >> 8;
  60. L = val & 0xFF;
  61. if(H > 0X80){
  62. H = ~H;
  63. L = (~L) + 0X01;
  64. ret = (-(((H << 8) | L) / 1000.0));
  65. }else{
  66. ret = ((((H << 8) | L) / 1000.0));
  67. }
  68. return ret;
  69. }
  70. void reset()
  71. {
  72. m_acc = m_ang = 0;
  73. m_acc_data.fill(0);
  74. m_ang_data.fill(0);
  75. }
  76. ins_data& operator=(const ins_data& lhs)
  77. {
  78. this->m_acc = lhs.m_acc;
  79. this->m_ang = lhs.m_ang;
  80. for(size_t i = 0; i < lhs.m_acc_data.size(); ++i){
  81. this->m_acc_data[i] = lhs.m_acc_data[i];
  82. }
  83. for(size_t i = 0; i < lhs.m_ang_data.size(); ++i){
  84. this->m_ang_data[i] = lhs.m_ang_data[i];
  85. }
  86. return *this;
  87. }
  88. };
  89. /*
  90. * tdoa协议之分站数据
  91. * */
  92. struct message_site{
  93. uint16_t m_time_stamp; // 分站时间戳
  94. time_t m_site_time; // 分站时间
  95. uint32_t m_site_id; // 分站号
  96. uint8_t m_status; // 状态
  97. uint8_t m_reverse; // 保留
  98. uint8_t m_power_status; // 电源状态
  99. message_site():m_time_stamp(0), m_site_time(0), m_site_id(0), m_status(0), m_reverse(0), m_power_status(0)
  100. {}
  101. void clear()
  102. {
  103. m_time_stamp = m_site_time = m_site_id = m_status = m_reverse = m_power_status = 0;
  104. }
  105. };
  106. /*
  107. * tdoa协议之卡数据,支持以下三种数据协议:
  108. * 1.tdoa实时定位数据协议;
  109. * 2.扩展tdoa实时定位数据协议;
  110. * 3.扩展tdoa实时定位数据协议(带惯导数据);
  111. * */
  112. struct message_tdoa_card{
  113. uint8_t m_type; // 卡类型
  114. uint32_t m_id; // 卡id
  115. uint16_t m_time_stamp; // 卡报文时间戳
  116. uint8_t m_battery_status; // 电池状态
  117. uint8_t m_call_info; // 0x80-呼救,0x01-一般呼叫,0x02-紧急呼叫
  118. int8_t m_rav; // 角速度
  119. uint8_t m_acc; // 加速度
  120. uint64_t m_loc_stamp; // 定位时间戳
  121. uint8_t m_ant_id; // 天线号
  122. uint16_t m_sync_num; // 同步序列号
  123. int16_t m_rssi; // 脉冲信道响应值
  124. int16_t m_strength; // 信号强度
  125. int16_t m_rxpacc; // 接收信号功率
  126. // 以下参数用于tdoa带惯导数据输出
  127. int16_t m_acc_data[3]; // 加速度三轴数据,0-x,1-y,2-z
  128. int16_t m_rav_data[3]; // 角速度三轴数据,0-x,1-y,2-z
  129. uint8_t m_walk_steps; // 行进步数
  130. uint8_t m_jump_counts; // 跳跃次数
  131. uint8_t m_hang_time; // 滞空时间
  132. uint8_t m_hang_height; // 滞空高度
  133. message_tdoa_card():m_type(0), m_id(0), m_time_stamp(0), m_battery_status(0), m_call_info(0), m_rav(0), m_acc(0), m_loc_stamp(0), m_ant_id(0), m_sync_num(0), m_rssi(0), m_strength(0), m_rxpacc(0), m_walk_steps(0), m_jump_counts(0), m_hang_time(0), m_hang_height(0)
  134. {
  135. m_acc_data[0] = m_acc_data[1] = m_acc_data[2] = 0;
  136. m_rav_data[0] = m_rav_data[1] = m_rav_data[2] = 0;
  137. }
  138. int64_t get_long_id()const
  139. {
  140. return (((int64_t)m_type) << 32) | m_id;
  141. }
  142. void clear()
  143. {
  144. m_type = m_id = m_time_stamp = m_battery_status =
  145. m_call_info = m_rav = m_acc = m_loc_stamp = m_ant_id =
  146. m_sync_num = m_rssi = m_strength = m_rxpacc = m_walk_steps =
  147. m_jump_counts = m_hang_time = m_hang_height = 0;
  148. }
  149. };
  150. /*
  151. * tdoa消息虚基类,主要定义子类重载的方法
  152. *
  153. * */
  154. struct message_loc{
  155. virtual void zero_this() = 0;
  156. virtual void load(zistream& is, uint16_t& cmd) = 0;
  157. virtual int64_t long_id()const = 0;
  158. };
  159. struct message_tdoa_locinfo:task{
  160. message_site m_site_msg;
  161. message_tdoa_card m_card_msg;
  162. uint64_t m_interpolation;
  163. uint8_t m_loc_type;
  164. uint8_t m_loc_dimension;
  165. virtual void zero_this();
  166. virtual void load(zistream& is, uint16_t& cmd);
  167. virtual int64_t long_id()const
  168. {
  169. return m_card_msg.get_long_id();
  170. }
  171. };
  172. // 分站传上来的卡定位数据,包括tof,tdoa
  173. struct message_locinfo:task
  174. {
  175. uint64_t m_time_stamp; // 分站时间戳
  176. time_t m_site_time; // 分站时间
  177. uint64_t m_tof; // 卡tof值
  178. uint32_t m_site_id; // 分站号
  179. uint32_t m_card_type; // 卡类型
  180. uint32_t m_card_id; // 卡id
  181. uint16_t m_card_ct; // 卡报文时间戳
  182. uint8_t m_batty_status; // 电池状态
  183. uint8_t m_callinfo; // 0x80-呼救,0x01-一般呼叫,0x02-紧急呼叫
  184. int8_t m_rav; // 角速度
  185. uint8_t m_acc; // 加速度
  186. uint8_t m_ant_id; // 天线号
  187. uint16_t m_sync_ct; // 同步序列号,对于pdoa应用,用来保存是否使用原始定位算法参数
  188. int16_t m_rssi; // 信号功率强度
  189. //优化协议
  190. float m_distance;
  191. uint8_t m_loc_type; // 数据类型,tof,tdoa,pdoa
  192. void zero_this();
  193. void load(zistream&is,bool tdoa);
  194. void set_rav(uint8_t rav){m_rav=rav;}
  195. static std::vector<task*> load_opt(zistream&is);
  196. static task* clone(message_locinfo* ml);
  197. int64_t long_id()const
  198. {
  199. return (((int64_t)m_card_type)<<32)|m_card_id;
  200. }
  201. };
  202. //tdoa分站同步数据
  203. struct message_tdoasync:task
  204. {
  205. uint32_t m_local_site_id; // 本地分站号
  206. uint32_t m_parent_site_id; // 上一级分站号
  207. uint16_t m_local_ant_id; // 分站分站天线号
  208. uint16_t m_parent_ant_id; // 上一级分站天线号
  209. uint16_t m_sync_num; // 同步序列号
  210. uint16_t m_local_level; // 分站本地层级
  211. uint64_t m_recv_time; // 接收时间
  212. uint64_t m_send_time; // 发送时间
  213. uint64_t m_root_site_id; // 本次同步root节点分站号
  214. uint16_t m_root_ant_id; // 本次同步root节点天线号
  215. void zero_this();
  216. void load(zistream&is);
  217. };
  218. // pdoa分站数据
  219. struct message_pdoa_locinfo: public message_locinfo{
  220. uint8_t m_loc_type;
  221. uint8_t m_loc_dimension;
  222. float m_poa[3];
  223. void zero_this();
  224. void load(zistream& is);
  225. };
  226. struct message_ins_locinfo: public message_locinfo{
  227. ins_data m_ins_data;
  228. uint8_t m_biz_type;
  229. void zero_this();
  230. void load(zistream& is);
  231. };
  232. struct message_lora_locinfo : public message_locinfo {
  233. ins_data m_ins_data;
  234. uint8_t m_biz_type;
  235. void zero_this();
  236. void load(zistream& is);
  237. };
  238. struct message_light: task{
  239. uint32_t m_light_id;
  240. uint8_t m_type;
  241. uint16_t m_stamp;
  242. uint64_t m_recv_time;
  243. uint8_t m_status;
  244. message_light(): m_light_id(0), m_type(0), m_stamp(0), m_recv_time(0), m_status(0)
  245. {}
  246. message_light(const uint32_t& lid, const uint16_t& type, const uint8_t& stamp, const uint64_t& rtime): m_status(0)
  247. {}
  248. };
  249. #endif