1
0

message.cpp 4.8 KB

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