Przeglądaj źródła

Merge branch 'master' of researchman/ya-serv into master

zzj 5 lat temu
rodzic
commit
9a2c874c9d
6 zmienionych plików z 97 dodań i 54 usunięć
  1. 3 3
      card_base.cpp
  2. 16 8
      his_location.cpp
  3. 2 1
      his_location.h
  4. 67 37
      message.cpp
  5. 6 2
      message.h
  6. 3 3
      net-service.cpp

+ 3 - 3
card_base.cpp

@@ -91,15 +91,15 @@ void card_location_base::do_status(int st)
 
 void card_location_base::make_his_location(uint64_t t,const point & pt,bool bclose /*= false*/)
 {
-	int area_id=0,mapid=0,site_id=0;
+	int area_id=0,map_id=0,site_id=0;
 	if(auto site_ptr=get_area_tool()->m_site)
 	{
 		area_id=site_ptr->m_area_id;
-		mapid=site_ptr->m_map_id;
+		map_id=site_ptr->m_map_id;
 		site_id=site_ptr->m_id;
 	}
 
-	m_his_location_card->push(t,pt,area_id,mapid,bclose);
+	m_his_location_card->push(t,pt,area_id,map_id,site_id,bclose);
 }
 
 void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )

+ 16 - 8
his_location.cpp

@@ -27,6 +27,7 @@ void location_card::init()
 {
     m_areaid=-1;
     m_mapid=-1;
+    m_siteid = -1;
     m_timestamp=0;
     m_p.set(0,0);
     std::queue<mini_data> tmp;
@@ -124,6 +125,8 @@ bool location_card::time_out(const point &p,uint64_t time)
         return true;
     return false;
 }
+
+//区域是否发生变化
 bool location_card::is_area_changed(int new_areaid)
 {
     bool flag =false;
@@ -134,6 +137,8 @@ bool location_card::is_area_changed(int new_areaid)
     }
     return flag;
 }
+
+//地图是否发生变化
 bool location_card::is_map_changed(int new_mapid)
 {
     bool flag =false;
@@ -144,7 +149,8 @@ bool location_card::is_map_changed(int new_mapid)
     }
     return flag;
 }
-void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,bool bclose/* = false*/)
+
+void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,int32_t siteid,bool bclose/* = false*/)
 {
     if (bclose) //卡移除后直接更新his_location
     {
@@ -152,10 +158,12 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
         init();
         return;
     }
-    if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0)
+    if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0 || m_siteid < 0)
     {
         set(p,timestamp);
-        m_areaid=areaid;m_mapid=mapid;
+        m_areaid = areaid;
+        m_mapid  = mapid;
+        m_siteid = siteid;
         m_d.emplace(p,timestamp);
         return ;
     }
@@ -197,7 +205,7 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
     if(is_area_changed(areaid))
         if(!flag)iflag=3;
     if(is_map_changed(mapid))
-        if(!flag)iflag=4;
+        if(!flag)iflag=4;  
     log_info("his_location cardid:%d:%d",m_cardid,iflag);
     if(iflag)
     {
@@ -213,9 +221,9 @@ void location_card::insert()
 {
     //std::string tabName=getTabName();
     char nsql[512]={0};
-    const char * sql = "replace into his_location (obj_id,card_type_id,ident,begin_time,map_id,area_id,begin_pt,direction)"
-                       "values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f);";
-    snprintf(nsql,512,sql,m_objid,m_type,m_cardid,tool_time::to_str(m_timestamp/1000).c_str(),m_mapid,m_areaid,m_p.x,m_p.y,m_arg);
+    const char * sql = "replace into his_location (obj_id,card_type_id,ident,begin_time,map_id,area_id,begin_pt,direction,reader_id)"
+                       "values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f,%d);";
+    snprintf(nsql,512,sql,m_objid,m_type,m_cardid,tool_time::to_str(m_timestamp/1000).c_str(),m_mapid,m_areaid,m_p.x,m_p.y,m_arg,m_siteid);
     log_info("his_location[%d,%lu]:%s",m_cardid,m_timestamp,nsql);
     sDBConnPool.PushAsync(nsql);
 }
@@ -226,7 +234,7 @@ void location_card::update(const point &p,uint64_t timestamp,int flag/*=0*/,int
     const char * sql = "update his_location set last_time='%s',speed=%.3f,direction=%f,location_flag=%d where obj_id=%d and begin_time='%s' and last_time is null;";
     double dist = m_p.dist(p);
     double t	= (timestamp - m_timestamp)/1000;
-    double avge_speed= dist/t;
+    double avge_speed = dist/t;
     if(std::isnan(avge_speed)|| std::isinf(avge_speed))avge_speed=0;
 
     log_info("his_location_time[%d]:%d[%lu,%lu,%lu]",m_cardid,flag,last_timestamp,timestamp,m_timestamp);

+ 2 - 1
his_location.h

@@ -16,6 +16,7 @@ struct location_card
 	double		m_arg;//运动方向角度值
 	int 		m_areaid;//区域
 	int 		m_mapid;//地图
+    int         m_siteid;   //分站
 	uint64_t	m_timestamp;//入库后的时间
 	point		m_p;//入库后的点
     int         m_direct_index;
@@ -55,7 +56,7 @@ struct location_card
     // 地图变化
 	bool is_map_changed(int new_mapid);
     // 计算当前点是否需要记录到DB中
-	void push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,bool bclose = false);
+	void push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,int32_t siteid,bool bclose = false);
 
 	void insert();
 

+ 67 - 37
message.cpp

@@ -5,8 +5,6 @@
 
 void message_locinfo::zero_this()
 {
-//	m_time_stamp=
-//	m_site_id=
 	m_site_time=
 	m_tof=
 	m_card_type=
@@ -19,13 +17,33 @@ void message_locinfo::zero_this()
 	m_ant_id=
 	m_sync_ct=
 	m_rssi=0;
+    m_distance = 0.0;
 }
 
-message_locinfo*message_locinfo::clone()
+task* message_locinfo::clone(message_locinfo* ml)
 {
-
-
-	return nullptr;
+    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)
@@ -78,11 +96,12 @@ void message_locinfo::load(zistream&is,bool tdoa)
 			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_753C(zistream&is)
+//优化协议数据解析
+std::vector<task*> message_locinfo::load_opt(zistream&is)
 {
 	std::vector<task*> rc;
-	task*t=task::alloc<message_locinfo>();
-
+	
+    task* t=task::alloc<message_locinfo>();
 	message_locinfo&m=t->body<message_locinfo>();
 	m.zero_this();
 
@@ -92,6 +111,7 @@ std::vector<task*> message_locinfo::load_753C(zistream&is)
 	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)
@@ -103,39 +123,49 @@ std::vector<task*> message_locinfo::load_753C(zistream&is)
 		m.m_rav=((b&0x80)?-1.:1.)*(b&0x7f)*3;
 	}
 
-	//加速度
+    //加速度
 	is>>b;
 	if(m.m_card_type==1 || m.m_card_type==4 || m.m_card_type==5)
 		m.m_acc=b;
 	else
 		m.m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;
-
-#if 0
-	//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_id:%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);
-#endif
-	rc.push_back(t);
-
-	return std::move(rc);
+   
+    //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()

+ 6 - 2
message.h

@@ -15,6 +15,7 @@ struct zistream;
 #define CHAR_ADHOC	0x803b							// 上传自组网数据
 #define CHAR_CTRL_READER_CMD 0x804c					// 向分站发送控制指令,控制分站向上位机发送数据
 #define CHAR_VIRTUAL_DATA_PUSH_CMD 0x699a			//虚拟数据推送
+#define CHAR_LOCATEDATA_TOF_OPTIMIZE 0x753d         // TOF优化协议
 
 //	分站传上来的卡定位数据,包括tof,tdoa
 struct message_locinfo:task
@@ -35,11 +36,14 @@ struct message_locinfo:task
 	uint16_t m_sync_ct;
 	int16_t  m_rssi;
 
+    //优化协议
+    float m_distance;
+
 	void zero_this();
     void load(zistream&is,bool tdoa);
     void set_rav(uint8_t rav){m_rav=rav;}
-    static std::vector<task*> load_753C(zistream&is);
-	static message_locinfo*clone();
+    static std::vector<task*> load_opt(zistream&is);
+    static task* clone(message_locinfo* ml);
 
 	int64_t long_id()const 
 	{

+ 3 - 3
net-service.cpp

@@ -123,7 +123,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					}
 				}
 				break;
-			case 0x753C://tof-优化,大小分站
+			case CHAR_LOCATEDATA_TOF_OPTIMIZE://tof-优化,大小分站
 				{
 					uint16_t site_id=-1;
 					uint16_t site_ct=-1;
@@ -188,8 +188,8 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					{
 						uint64_t tstamp = t -1000 + 50 + index* 45;
 						index++;
-
-						for(auto&tk:message_locinfo::load_753C(is))//未写完
+                        
+						for(auto & tk : message_locinfo::load_opt(is))
 						{
 							message_locinfo&m=tk->body<message_locinfo>();
 							m.m_site_id=site_id;