1
0

message.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #include <math.h>
  2. #include "zstream.h"
  3. #include "message.h"
  4. #include "log.h"
  5. void message_locinfo::zero_this()
  6. {
  7. m_site_time=
  8. m_tof=
  9. m_card_type=
  10. m_card_id=
  11. m_card_ct=
  12. m_batty_status=
  13. m_callinfo=
  14. m_rav=
  15. m_acc=
  16. m_ant_id=
  17. m_sync_ct=
  18. m_rssi=0;
  19. m_distance = 0.0;
  20. }
  21. task* message_locinfo::clone(message_locinfo* ml)
  22. {
  23. log_info("clone: enter");
  24. task* t = task::alloc<message_locinfo>();
  25. message_locinfo& m = t->body<message_locinfo>();
  26. m.zero_this();
  27. log_info("clone: begin copy");
  28. m.m_time_stamp = ml->m_time_stamp;
  29. m.m_site_time = ml->m_site_time;
  30. m.m_tof = ml->m_tof;
  31. m.m_site_id = ml->m_site_id;
  32. m.m_card_type = ml->m_card_type;
  33. m.m_card_id = ml->m_card_id;
  34. m.m_card_ct = ml->m_card_ct;
  35. m.m_batty_status = ml->m_batty_status;
  36. m.m_callinfo = ml->m_callinfo;
  37. m.m_rav = ml->m_rav;
  38. m.m_acc = ml->m_acc;
  39. m.m_ant_id = ml->m_ant_id;
  40. m.m_sync_ct = ml->m_sync_ct;
  41. m.m_rssi = ml->m_rssi;
  42. log_info("clone: end copy");
  43. return std::move(t);
  44. }
  45. void message_locinfo::load(zistream&is,bool tdoa)
  46. {
  47. zero_this();
  48. uint8_t b;
  49. uint32_t i;
  50. //卡类型、卡号、CT、电池状态
  51. is>>b>>m_card_id>>m_card_ct>>m_batty_status;
  52. m_card_type=b;
  53. m_batty_status&=0x3;
  54. is>>b;
  55. if(m_card_type==1)
  56. {
  57. m_callinfo=b;
  58. }
  59. else
  60. {
  61. m_rav=((b&0x80)?-1.:1.)*(b&0x7f)*3;
  62. }
  63. //加速度
  64. is>>b;
  65. if(m_card_type == 1 || m_card_type==4 || m_card_type==5)
  66. m_acc=b;
  67. else
  68. m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;
  69. //TOF
  70. is>>b>>i;
  71. m_tof=b;
  72. m_tof=(m_tof<<32)|i;
  73. //天线号
  74. is>>m_ant_id;
  75. --m_ant_id;
  76. if(tdoa)
  77. {
  78. //同步序号,冲击响应丢弃
  79. is>>m_sync_ct>>skip(2);
  80. }
  81. //信号电平值
  82. uint16_t sp1=0,sp2=0;
  83. is>>sp1>>sp2;
  84. m_rssi=10*log10(1.*sp1*(1<<17)/pow(sp2-64.,2))-121.74;
  85. log_info("timestamp=%llu,type:%d,card_id:%d,site:%d,ct:%d,status:%d,acc=%d,tof=%llu,ant_id:%d,spq=%d",
  86. m_time_stamp,m_card_type,m_card_id,m_site_id,m_card_ct,m_batty_status,m_acc,m_tof,m_ant_id,m_rssi);
  87. }
  88. //优化协议数据解析
  89. std::vector<task*> message_locinfo::load_opt(zistream&is)
  90. {
  91. std::vector<task*> rc;
  92. task* t=task::alloc<message_locinfo>();
  93. message_locinfo&m=t->body<message_locinfo>();
  94. m.zero_this();
  95. uint8_t b;
  96. uint16_t card_id;
  97. //卡类型、卡号、CT、电池状态
  98. is>>b>>card_id>>m.m_card_ct;
  99. m.m_card_type=b&0xF;
  100. m.m_batty_status=b>>4;
  101. m.m_card_id = card_id;
  102. is>>b;
  103. if(m.m_card_type==1)
  104. {
  105. m.m_callinfo=b;
  106. }
  107. else
  108. {
  109. m.m_rav=((b&0x80)?-1.:1.)*(b&0x7f)*3;
  110. }
  111. //加速度
  112. is>>b;
  113. if(m.m_card_type==1 || m.m_card_type==4 || m.m_card_type==5)
  114. m.m_acc=b;
  115. else
  116. m.m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;
  117. //log_info("load_opt: card_type: %d,card_id: %d,ct:%d, callinfo:%d, rav:%d,acc:%.2f",m.m_card_type,m.m_card_id,m.m_card_ct,m.m_callinfo,m.m_rav,m.m_acc);
  118. //天线
  119. is>>b;
  120. m.m_ant_id = b-1;
  121. //分站RSSI
  122. int8_t val;
  123. is>>val;
  124. m.m_rssi = val;
  125. //天线1距离
  126. uint16_t d;
  127. is>>d;
  128. m.m_distance = d*0.02;
  129. //log_info("load_opt: ant1 ant_id:%d, rssi: %d, d: %.2f",m.m_ant_id,m.m_rssi,m.m_distance);
  130. task* t2 = message_locinfo::clone(&m);
  131. message_locinfo& m2 = t2->body<message_locinfo>();
  132. m2.m_ant_id = m.m_ant_id==0?1:0;
  133. //分站RSSI
  134. is>>val;
  135. m2.m_rssi = val;
  136. //天线2距离
  137. is>>d;
  138. m2.m_distance = d*0.02;
  139. //log_info("load_opt: ant2 ant_id:%d, rssi: %d, d: %.2f",m2.m_ant_id,m2.m_rssi,m2.m_distance);
  140. log_info("load_opt: type=%d, card_id=%d,ct=%d, callinfo=%d, rav=%d, acc=%d, ant1=%d, tof1=%.2f, spq1=%d, ant2=%d, tof2=%.2f, sqp2=%d",m.m_card_type,m.m_card_id,m.m_card_ct,m.m_callinfo,m.m_rav,m.m_acc,m.m_ant_id,m.m_distance,m.m_rssi,m2.m_ant_id,m2.m_distance,m2.m_rssi);
  141. rc.push_back(t);
  142. rc.push_back(t2);
  143. return std::move(rc);
  144. }
  145. void message_tdoasync::zero_this()
  146. {
  147. m_local_site_id=
  148. m_parent_site_id=
  149. m_local_ant_id=
  150. m_parent_ant_id=
  151. m_sync_ct=
  152. m_local_level=
  153. m_recv_time=
  154. m_send_time=0;
  155. }
  156. void message_tdoasync::load(zistream&is)
  157. {
  158. zero_this();
  159. uint8_t b;
  160. //本地分站ID和天线ID
  161. is>>m_local_site_id>>b; m_local_ant_id=b;
  162. //上级分站ID和天线ID
  163. is>>m_parent_site_id>>b; m_parent_ant_id=b;
  164. //根分站CT和本机级别
  165. is>>m_sync_ct>>m_local_level;
  166. uint32_t i;
  167. //本级发出的时间
  168. is>>b>>i;
  169. m_send_time=b;
  170. m_send_time=(m_send_time<<32)|i;
  171. //本级收到的时间
  172. is>>b>>i;
  173. m_recv_time=b;
  174. m_recv_time=(m_recv_time<<32)|i;
  175. }