message.cpp 3.3 KB

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