#include #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) { task* t = task::alloc(); message_locinfo& m = t->body(); m.zero_this(); 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; 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; if(m_card_id & 0xFFFF0000) log_warn("card_id=%#X,CT=%d,大于0xFFFF.",m_card_id,m_card_ct); m_card_id &= 0xFFFF; //卡号不会大于65535,分站上传数据的bug m_card_type=b; //m_batty_status&=0x03; 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,bat=%#X,acc=%.2f,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 message_locinfo::load_opt(zistream&is) { std::vector rc; task* t=task::alloc(); message_locinfo&m=t->body(); 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; //天线 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; task* t2 = message_locinfo::clone(&m); message_locinfo& m2 = t2->body(); 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: 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_num= m_local_level= m_recv_time= m_root_site_id = m_root_ant_id = 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_num>>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; logn_info(4, "local_id: %d, upper_id: %d, sync_num: %d, level: %d, send: %llu, recv: %llu", m_local_site_id, m_parent_site_id, m_sync_num, m_local_level, m_send_time, m_recv_time ); } void message_tdoa_locinfo::zero_this() { m_site_msg.clear(); m_card_msg.clear(); } void message_tdoa_locinfo::load(zistream& is, uint16_t& cmd) { zero_this(); uint8_t b; uint32_t i; //卡类型、卡号、CT、电池状态 is>>b>>m_card_msg.m_id>>m_card_msg.m_time_stamp>>m_card_msg.m_battery_status; if(m_card_msg.m_id & 0xFFFF0000) log_warn("card_id=%#X,CT=%d,大于0xFFFF.",m_card_msg.m_id,m_card_msg.m_time_stamp); m_card_msg.m_id &= 0xFFFF; //卡号不会大于65535,分站上传数据的bug m_card_msg.m_type = b; is>>b; if(m_card_msg.m_type == 1) { m_card_msg.m_call_info = b; } else { m_card_msg.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_msg.m_type, m_card_msg.m_id)); if(m_card_msg.m_type == 1 ||(c && tool_other::is_coal_or_driving(m_card_msg.m_type, c->get_vehicle_type_id()))) m_card_msg.m_acc = b; else m_card_msg.m_acc = ((b&0x80)?-1.:1.)*(b&0x7f)*0.01; //定位时间戳 is>>b>>i; m_card_msg.m_loc_stamp = b; m_card_msg.m_loc_stamp = (m_card_msg.m_loc_stamp<<32)|i; //天线号 is>>m_card_msg.m_ant_id; --m_card_msg.m_ant_id; //序列号 is>>m_card_msg.m_sync_num; //脉冲信道响应值 is>>m_card_msg.m_rssi; if(CHAR_LOCATEDATA_TDOA_EXTEND == cmd || CHAR_LOCATEDATA_TDOA_EXTEND_INS == cmd){ //信号电平值 uint16_t sp1 = 0, sp2 = 0; is>>sp1>>sp2; m_card_msg.m_rssi = 10*log10(1.*sp1*(1<<17)/pow(sp2-64.,2))-121.74; m_card_msg.m_strength = sp1; m_card_msg.m_rxpacc = sp2; } if(CHAR_LOCATEDATA_TDOA_EXTEND_INS == cmd){ is>>m_card_msg.m_acc_data[0] >>m_card_msg.m_acc_data[1] >>m_card_msg.m_acc_data[2] >>m_card_msg.m_rav_data[0] >>m_card_msg.m_rav_data[1] >>m_card_msg.m_rav_data[2] >>m_card_msg.m_walk_steps >>m_card_msg.m_jump_counts >>m_card_msg.m_hang_time >>m_card_msg.m_hang_height; } log_info("[tdoa] type=%d, card=%d, site=%d, ct=%d, bat=%#X, acc=%d, fly_time=%llu, ant_id=%d, spq=%d", m_card_msg.m_type, m_card_msg.m_id, m_site_msg.m_site_id, m_card_msg.m_time_stamp, m_card_msg.m_battery_status, m_card_msg.m_acc, m_card_msg.m_loc_stamp, m_card_msg.m_ant_id, m_card_msg.m_rssi ); } void message_pdoa_locinfo::zero_this() { m_time_stamp = m_site_time = m_tof = m_site_id = m_card_type = m_card_id = m_card_ct = m_batty_status = m_callinfo = m_acc = m_ant_id = m_rssi = 0; m_rav = 0; m_poa[0] = m_poa[1] = m_poa[2] = 0.0; } void message_pdoa_locinfo::load(zistream& is) { zero_this(); uint8_t b; // 1字节,低4位为卡类型 is>>b; m_card_type = b&0x0F; //m_batty_status = (b>>4)&0xFF; // 电量,1字节 is>>b; m_batty_status = b; //2字节卡号,2字节卡的ct号 uint16_t id; is>>id>>m_card_ct; m_card_id = id; /*if(m_card_ct % 5 == 4){ m_batty_status = (m_batty_status>>4)&0xFF; }*/ //角速度值:人卡车卡表示含义不同 is>>b; if(m_card_type == 1){ // 1表示呼救 m_callinfo = ((b&0x80) >> 7); m_rav = m_callinfo; }else{ m_rav = ((b&0x80)?-1.:1.)*(b&0x7F)*3; } //加速度 is>>b; if(m_card_type == 1 || m_card_type == 4 || m_card_type == 5){ m_acc = b; }else{ m_acc = ((b&0x80)?-1.:1.)*(b&0x7F)*0.01; } //信号电平值,tof测距结果 int8_t rssi = 0; uint32_t tof = 0; uint8_t high_tof = 0; is>>rssi>>high_tof>>tof; m_rssi = rssi; m_tof = high_tof; m_tof = (m_tof<<32) | tof; is>>m_ant_id; --m_ant_id; uint16_t _poa = 0; for(int i = 0; i < 3; ++i){ is>>_poa; m_poa[i] = (float)((((short)_poa)*1.0)/1000.0); } if(tof > 0){ logn_info(3,"[pdoa] card_type=%d, card_id=%d, ct=%d, status=%d, call_type=%d, rav=%d, acc=.2f, tof=%llu, ant_id=%d, rssi=%d, poa1=%.2f, poa2=%.2f, poa3=%.2f", m_card_type, m_card_id, m_card_ct, m_batty_status, m_callinfo, m_rav, m_acc, m_tof, m_ant_id, m_rssi, m_poa[0], m_poa[1], m_poa[2]); } }