message.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <math.h>
  2. #include "zstream.h"
  3. #include "message.h"
  4. #include "log.h"
  5. void message_locinfo::zero_this()
  6. {
  7. memset(this,0,sizeof(*this));
  8. }
  9. void message_locinfo::load(zistream&is,bool tdoa)
  10. {
  11. zero_this();
  12. uint8_t b;
  13. uint32_t i;
  14. //卡类型、卡号、CT、电池状态
  15. is>>b>>m_card_id>>m_card_ct>>m_batty_status;
  16. m_card_type=b;
  17. m_batty_status&=0xF;
  18. //角度
  19. is>>b;
  20. if(m_card_type==1)
  21. {
  22. m_callinfo=b;
  23. }
  24. else
  25. {
  26. m_rav=((b&0x80)?-1.:1.)*(b&0x7f)*3;
  27. }
  28. //加速度
  29. is>>b;
  30. if(m_card_type==4 || m_card_type==5)
  31. m_acc=b;
  32. else
  33. m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*98;
  34. //TOF
  35. is>>b>>i;
  36. m_tof=b;
  37. m_tof=(m_tof<<32)|i;
  38. //天线号
  39. is>>m_ant_id;
  40. --m_ant_id;
  41. if(tdoa)
  42. {
  43. //同步序号,冲击响应丢弃
  44. is>>m_sync_ct>>skip(2);
  45. }
  46. //信号电平值
  47. uint16_t sp1=0,sp2=0;
  48. is>>sp1>>sp2;
  49. m_rssi=10*log10(1.*sp1*(1<<17)/pow(sp2-64.,2))-121.74;
  50. log_info("timestamp=%llu,type:%d,card_id:%d,ct:%d,status:%d,acc=%d,tof=%llu,ant_id:%d,spq=%d",m_time_stamp,m_card_type,m_card_id,m_card_ct,m_batty_status,m_acc,m_tof,m_ant_id,m_rssi);
  51. }
  52. void message_tdoasync::zero_this()
  53. {
  54. memset(this,0,sizeof(*this));
  55. }
  56. void message_tdoasync::load(zistream&is)
  57. {
  58. zero_this();
  59. uint8_t b;
  60. //本地分站ID和天线ID
  61. is>>m_local_site_id>>b; m_local_ant_id=b;
  62. //上级分站ID和天线ID
  63. is>>m_parent_site_id>>b; m_parent_ant_id=b;
  64. //根分站CT和本机级别
  65. is>>m_sync_ct>>m_local_level;
  66. uint32_t i;
  67. //本级发出的时间
  68. is>>b>>i;
  69. m_send_time=b;
  70. m_send_time=(m_send_time<<32)|i;
  71. //本级收到的时间
  72. is>>b>>i;
  73. m_recv_time=b;
  74. m_recv_time=(m_recv_time<<32)|i;
  75. }