123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- #include <math.h>
- #include "zstream.h"
- #include "message.h"
- #include "log.h"
- #include "common_tool.h"
- #include "card.h"
- void message_locinfo::zero_this()
- {
- m_site_time=
- m_tof=
- m_card_type=
- m_card_id=
- m_card_ct=
- m_batty_status=
- m_callinfo=
- m_rav=
- m_acc=
- m_ant_id=
- m_sync_ct=
- m_rssi=0;
- m_distance = 0.0;
- }
- task* message_locinfo::clone(message_locinfo* ml)
- {
- log_info("clone: enter");
- task* t = task::alloc<message_locinfo>();
- message_locinfo& m = t->body<message_locinfo>();
- m.zero_this();
-
- log_info("clone: begin copy");
- m.m_time_stamp = ml->m_time_stamp;
- m.m_site_time = ml->m_site_time;
- m.m_tof = ml->m_tof;
- m.m_site_id = ml->m_site_id;
- m.m_card_type = ml->m_card_type;
- m.m_card_id = ml->m_card_id;
- m.m_card_ct = ml->m_card_ct;
- m.m_batty_status = ml->m_batty_status;
- m.m_callinfo = ml->m_callinfo;
- m.m_rav = ml->m_rav;
- m.m_acc = ml->m_acc;
- m.m_ant_id = ml->m_ant_id;
- m.m_sync_ct = ml->m_sync_ct;
- m.m_rssi = ml->m_rssi;
- log_info("clone: end copy");
- return std::move(t);
- }
- void message_locinfo::load(zistream&is,bool tdoa)
- {
- zero_this();
- uint8_t b;
- uint32_t i;
- //卡类型、卡号、CT、电池状态
- is>>b>>m_card_id>>m_card_ct>>m_batty_status;
- m_card_id &= 0xFFFF; //卡号不会大于65535,分站上传数据的bug
- m_card_type=b;
- m_batty_status&=0x3;
- is>>b;
- if(m_card_type==1)
- {
- m_callinfo=b;
- }
- else
- {
- m_rav=((b&0x80)?-1.:1.)*(b&0x7f)*3;
- }
- //加速度
- is>>b;
- const auto &c=card_list::instance()->get(tool_other::type_id_to_u64(m_card_type,m_card_id));
- if(m_card_type == 1 ||(c && tool_other::is_coal_or_driving(m_card_type,c->get_vehicle_type_id())))
- m_acc=b;
- else
- m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;
- //TOF
- is>>b>>i;
- m_tof=b;
- m_tof=(m_tof<<32)|i;
- //天线号
- is>>m_ant_id;
- --m_ant_id;
- if(tdoa)
- {
- //同步序号,冲击响应丢弃
- is>>m_sync_ct>>skip(2);
- }
- //信号电平值
- uint16_t sp1=0,sp2=0;
- is>>sp1>>sp2;
- m_rssi=10*log10(1.*sp1*(1<<17)/pow(sp2-64.,2))-121.74;
- log_info("timestamp=%llu,type=%d,card=%d,site=%d,ct=%d,status=%d,acc=%d,tof=%llu,ant_id=%d,spq=%d",
- 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);
- }
- //优化协议数据解析
- std::vector<task*> message_locinfo::load_opt(zistream&is)
- {
- std::vector<task*> rc;
-
- task* t=task::alloc<message_locinfo>();
- message_locinfo&m=t->body<message_locinfo>();
- m.zero_this();
- uint8_t b;
- uint16_t card_id;
- //卡类型、卡号、CT、电池状态
- is>>b>>card_id>>m.m_card_ct;
- m.m_card_type=b&0xF;
- m.m_batty_status=b>>4;
- m.m_card_id = card_id;
- is>>b;
- if(m.m_card_type==1)
- {
- m.m_callinfo=b;
- }
- else
- {
- m.m_rav=((b&0x80)?-1.:1.)*(b&0x7f)*3;
- }
- //加速度
- is>>b;
- auto c=card_list::instance()->get(tool_other::type_id_to_u64(m.m_card_type,m.m_card_id));
- if(m.m_card_type == 1 ||(c && tool_other::is_coal_or_driving(m.m_card_type,c->get_vehicle_type_id())))
- m.m_acc=b;
- else
- m.m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;
-
- //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);
-
- //天线
- is>>b;
- m.m_ant_id = b-1;
- //分站RSSI
- int8_t val;
- is>>val;
- m.m_rssi = val;
- //天线1距离
- uint16_t d;
- is>>d;
- m.m_distance = d*0.02;
- //log_info("load_opt: ant1 ant_id:%d, rssi: %d, d: %.2f",m.m_ant_id,m.m_rssi,m.m_distance);
- task* t2 = message_locinfo::clone(&m);
- message_locinfo& m2 = t2->body<message_locinfo>();
- m2.m_ant_id = m.m_ant_id==0?1:0;
- //分站RSSI
- is>>val;
- m2.m_rssi = val;
- //天线2距离
- is>>d;
- m2.m_distance = d*0.02;
-
- //log_info("load_opt: ant2 ant_id:%d, rssi: %d, d: %.2f",m2.m_ant_id,m2.m_rssi,m2.m_distance);
- 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);
- rc.push_back(t);
- rc.push_back(t2);
-
- return std::move(rc);
- }
- void message_tdoasync::zero_this()
- {
- m_local_site_id=
- m_parent_site_id=
- m_local_ant_id=
- m_parent_ant_id=
- m_sync_ct=
- m_local_level=
- m_recv_time=
- m_send_time=0;
- }
- void message_tdoasync::load(zistream&is)
- {
- zero_this();
- uint8_t b;
- //本地分站ID和天线ID
- is>>m_local_site_id>>b; m_local_ant_id=b;
- //上级分站ID和天线ID
- is>>m_parent_site_id>>b; m_parent_ant_id=b;
- //根分站CT和本机级别
- is>>m_sync_ct>>m_local_level;
- uint32_t i;
- //本级发出的时间
- is>>b>>i;
- m_send_time=b;
- m_send_time=(m_send_time<<32)|i;
- //本级收到的时间
- is>>b>>i;
- m_recv_time=b;
- m_recv_time=(m_recv_time<<32)|i;
- }
|