message.cpp 4.6 KB

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