message.cpp 3.0 KB

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