message.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. };
  77. /*
  78. * tdoa协议之分站数据
  79. * */
  80. struct message_site{
  81. uint16_t m_time_stamp; // 分站时间戳
  82. time_t m_site_time; // 分站时间
  83. uint32_t m_site_id; // 分站号
  84. uint8_t m_status; // 状态
  85. uint8_t m_reverse; // 保留
  86. uint8_t m_power_status; // 电源状态
  87. message_site():m_time_stamp(0), m_site_time(0), m_site_id(0), m_status(0), m_reverse(0), m_power_status(0)
  88. {}
  89. void clear()
  90. {
  91. m_time_stamp = m_site_time = m_site_id = m_status = m_reverse = m_power_status = 0;
  92. }
  93. };
  94. /*
  95. * tdoa协议之卡数据,支持以下三种数据协议:
  96. * 1.tdoa实时定位数据协议;
  97. * 2.扩展tdoa实时定位数据协议;
  98. * 3.扩展tdoa实时定位数据协议(带惯导数据);
  99. * */
  100. struct message_tdoa_card{
  101. uint8_t m_type; // 卡类型
  102. uint32_t m_id; // 卡id
  103. uint16_t m_time_stamp; // 卡报文时间戳
  104. uint8_t m_battery_status; // 电池状态
  105. uint8_t m_call_info; // 0x80-呼救,0x01-一般呼叫,0x02-紧急呼叫
  106. int8_t m_rav; // 角速度
  107. uint8_t m_acc; // 加速度
  108. uint64_t m_loc_stamp; // 定位时间戳
  109. uint8_t m_ant_id; // 天线号
  110. uint16_t m_sync_num; // 同步序列号
  111. int16_t m_rssi; // 脉冲信道响应值
  112. int16_t m_strength; // 信号强度
  113. int16_t m_rxpacc; // 接收信号功率
  114. // 以下参数用于tdoa带惯导数据输出
  115. int16_t m_acc_data[3]; // 加速度三轴数据,0-x,1-y,2-z
  116. int16_t m_rav_data[3]; // 角速度三轴数据,0-x,1-y,2-z
  117. uint8_t m_walk_steps; // 行进步数
  118. uint8_t m_jump_counts; // 跳跃次数
  119. uint8_t m_hang_time; // 滞空时间
  120. uint8_t m_hang_height; // 滞空高度
  121. 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)
  122. {
  123. m_acc_data[0] = m_acc_data[1] = m_acc_data[2] = 0;
  124. m_rav_data[0] = m_rav_data[1] = m_rav_data[2] = 0;
  125. }
  126. int64_t get_long_id()const
  127. {
  128. return (((int64_t)m_type) << 32) | m_id;
  129. }
  130. void clear()
  131. {
  132. m_type = m_id = m_time_stamp = m_battery_status =
  133. m_call_info = m_rav = m_acc = m_loc_stamp = m_ant_id =
  134. m_sync_num = m_rssi = m_strength = m_rxpacc = m_walk_steps =
  135. m_jump_counts = m_hang_time = m_hang_height = 0;
  136. }
  137. };
  138. /*
  139. * tdoa消息虚基类,主要定义子类重载的方法
  140. *
  141. * */
  142. struct message_loc{
  143. virtual void zero_this() = 0;
  144. virtual void load(zistream& is, uint16_t& cmd) = 0;
  145. virtual int64_t long_id()const = 0;
  146. };
  147. struct message_tdoa_locinfo:task{
  148. message_site m_site_msg;
  149. message_tdoa_card m_card_msg;
  150. uint64_t m_interpolation;
  151. uint8_t m_loc_type;
  152. uint8_t m_loc_dimension;
  153. virtual void zero_this();
  154. virtual void load(zistream& is, uint16_t& cmd);
  155. virtual int64_t long_id()const
  156. {
  157. return m_card_msg.get_long_id();
  158. }
  159. };
  160. // 分站传上来的卡定位数据,包括tof,tdoa
  161. struct message_locinfo:task
  162. {
  163. uint64_t m_time_stamp; // 分站时间戳
  164. time_t m_site_time; // 分站时间
  165. uint64_t m_tof; // 卡tof值
  166. uint32_t m_site_id; // 分站号
  167. uint32_t m_card_type; // 卡类型
  168. uint32_t m_card_id; // 卡id
  169. uint16_t m_card_ct; // 卡报文时间戳
  170. uint8_t m_batty_status; // 电池状态
  171. uint8_t m_callinfo; // 0x80-呼救,0x01-一般呼叫,0x02-紧急呼叫
  172. int8_t m_rav; // 角速度
  173. uint8_t m_acc; // 加速度
  174. uint8_t m_ant_id; // 天线号
  175. uint16_t m_sync_ct; // 同步序列号,对于pdoa应用,用来保存是否使用原始定位算法参数
  176. int16_t m_rssi; // 信号功率强度
  177. //优化协议
  178. float m_distance;
  179. uint8_t m_loc_type; // 数据类型,tof,tdoa,pdoa
  180. void zero_this();
  181. void load(zistream&is,bool tdoa);
  182. void set_rav(uint8_t rav){m_rav=rav;}
  183. static std::vector<task*> load_opt(zistream&is);
  184. static task* clone(message_locinfo* ml);
  185. int64_t long_id()const
  186. {
  187. return (((int64_t)m_card_type)<<32)|m_card_id;
  188. }
  189. };
  190. //tdoa分站同步数据
  191. struct message_tdoasync:task
  192. {
  193. uint32_t m_local_site_id; // 本地分站号
  194. uint32_t m_parent_site_id; // 上一级分站号
  195. uint16_t m_local_ant_id; // 分站分站天线号
  196. uint16_t m_parent_ant_id; // 上一级分站天线号
  197. uint16_t m_sync_num; // 同步序列号
  198. uint16_t m_local_level; // 分站本地层级
  199. uint64_t m_recv_time; // 接收时间
  200. uint64_t m_send_time; // 发送时间
  201. uint64_t m_root_site_id; // 本次同步root节点分站号
  202. uint16_t m_root_ant_id; // 本次同步root节点天线号
  203. void zero_this();
  204. void load(zistream&is);
  205. };
  206. // pdoa分站数据
  207. struct message_pdoa_locinfo: public message_locinfo{
  208. uint8_t m_loc_type;
  209. uint8_t m_loc_dimension;
  210. float m_poa[3];
  211. void zero_this();
  212. void load(zistream& is);
  213. };
  214. struct message_ins_locinfo: public message_locinfo{
  215. ins_data m_ins_data;
  216. uint8_t m_biz_type;
  217. void zero_this();
  218. void load(zistream& is);
  219. };
  220. struct message_light: task{
  221. uint32_t m_light_id;
  222. uint8_t m_type;
  223. uint16_t m_stamp;
  224. uint64_t m_recv_time;
  225. uint8_t m_status;
  226. message_light(): m_light_id(0), m_type(0), m_stamp(0), m_recv_time(0), m_status(0)
  227. {}
  228. message_light(const uint32_t& lid, const uint16_t& type, const uint8_t& stamp, const uint64_t& rtime): m_status(0)
  229. {}
  230. };
  231. #endif