Browse Source

1、添加分站时间与服务器时间差异统计
2、添加输出人卡电池状态日志

zzj 6 years ago
parent
commit
36005d5df7
8 changed files with 60 additions and 17 deletions
  1. 2 0
      ant.cpp
  2. 47 8
      ant.h
  3. 2 2
      card.cpp
  4. 2 2
      card_message_handle.cpp
  5. 2 2
      db/db_card.cpp
  6. 3 1
      loc_message.h
  7. 1 1
      message.cpp
  8. 1 1
      net-service.cpp

+ 2 - 0
ant.cpp

@@ -21,6 +21,8 @@ site::site(int id)
 	,m_path_empty(true)
 {
 	m_time=time(0);
+	for(uint32_t i=0;i<m_timeoff_count.size();i++)
+		m_timeoff_count[i]=0;
 }
 
 const algo_config&site::config()const

+ 47 - 8
ant.h

@@ -8,6 +8,8 @@
 #include <array>
 #include <deque>
 #include <tuple>
+#include <time.h>
+#include <sstream>
 #include <memory>
 #include <memory.h>
 #include <algorithm>
@@ -123,18 +125,55 @@ struct site:point,std::enable_shared_from_this<site>
     bool m_power_ac_down=false;     //false=交流电供电状态
     bool m_path_empty;
 
+	std::array<int,32>	m_timeoff_count;
+
     site(int id=-1);
-	bool check_timestamp(const char*time)
+	bool check_timestamp(const char*tm_buf)
 	{
-		//秒、分、时、天、周、月、年, 脑残的设计
+		//秒、分、时、天、周、月、年
+
+		struct tm t={0};
 		
+
 		char buf[6];
-		buf[0]=time[6];
-		buf[1]=time[5];
-		buf[2]=time[3];
-		buf[3]=time[2];
-		buf[4]=time[1];
-		buf[5]=time[0];
+		buf[0]=tm_buf[6];
+		buf[1]=tm_buf[5];
+		buf[2]=tm_buf[3];
+		buf[3]=tm_buf[2];
+		buf[4]=tm_buf[1];
+		buf[5]=tm_buf[0];
+
+		t.tm_year=buf[0]+100;
+		t.tm_mon=buf[1]-1;
+		t.tm_mday=buf[2];
+		t.tm_hour=buf[3];
+		t.tm_min=buf[4];
+		t.tm_sec=buf[5];
+
+		time_t now=time(0);
+		time_t site_tm=mktime(&t);
+		int off=abs(now-site_tm);
+
+		if(off>0)
+		{
+			off=log(off)/log(2);
+		}
+
+		m_timeoff_count[off]++;
+
+		if(now % 300 ==0 )
+		{
+			std::ostringstream stm;
+			for(uint32_t i=0;i<m_timeoff_count.size();i++)
+			{
+				if(m_timeoff_count[i]==0)
+					continue;
+
+				stm<<"("<<i<<":"<<m_timeoff_count[i]<<"),";
+			}
+
+			log_info("site-time-stat:%s",stm.str().c_str());
+		}
 
 		if(memcmp(m_timestamp,buf,6)<=0)
 		{

+ 2 - 2
card.cpp

@@ -354,10 +354,10 @@ void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_
 		return;
 	}
 	double dist_tof=loc.m_tof*15.65*2.996*1e-4;
-	logn_info(3,"card_message:site=%d,ant=%d,type=%lu,card=%d,ct=%d,tof=%lld(%.2lfm),rav=%02X,acc=%02X,rssi=%d,stamp=%llu",
+	logn_info(3,"card_message:site=%d,ant=%d,type=%lu,card=%d,ct=%d,tof=%lld(%.2lfm),rav=%02X,acc=%02X,rssi=%d,bat=%02X,stamp=%llu",
 			loc.m_site_id,loc.m_ant_id,loc.m_card_type,loc.m_card_id,loc.m_card_ct,loc.m_tof,dist_tof,
 			(loc.m_card_type==1?loc.m_callinfo:loc.m_rav),
-			loc.m_acc,loc.m_rssi,loc.m_time_stamp);
+			loc.m_acc,loc.m_rssi,loc.m_batty_status,loc.m_time_stamp);
 
 	c->on_message(loop,loc,is_history);
 }

+ 2 - 2
card_message_handle.cpp

@@ -88,7 +88,7 @@ struct one_ct_message_handle
 			//这里构造loc_message 保存数据
 			m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
 						loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
-						loc.m_sync_ct,loc.m_rssi));
+						loc.m_sync_ct,loc.m_rssi,loc.m_batty_status));
 
 			//启动本CT的最小、最大两个定时器
 			m_min_timer.start(m_ac->min_wait_time);
@@ -98,7 +98,7 @@ struct one_ct_message_handle
 
 		m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
 					loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
-					loc.m_sync_ct,loc.m_rssi));
+					loc.m_sync_ct,loc.m_rssi,loc.m_batty_status));
 
 		if(m_min_timeout && (int)m_msg_list.size()>=m_ac->best_msg_cnt)
 		{

+ 2 - 2
db/db_card.cpp

@@ -90,7 +90,7 @@ namespace db_card
 
 			double over_speed= 0;
 			DBRes.GetField( "over_speed",over_speed, Error );
-            int type = tool_other::card_id_to_type(card_id);
+            uint32_t type = tool_other::card_id_to_type(card_id);
             if(type != card_type_id)
             {
                 log_error("init_vehicle_card error.Type is not matching..");
@@ -188,7 +188,7 @@ namespace db_card
 			int worktype_id;
 			DBRes.GetField( "worktype_id",worktype_id, Error );
 
-            int type = tool_other::card_id_to_type(card_id);
+            uint32_t type = tool_other::card_id_to_type(card_id);
             if(type != card_type_id)
             {
                 log_error("init_staffer_card error.Type is not matching..");

+ 3 - 1
loc_message.h

@@ -14,6 +14,7 @@ struct loc_message
     int16_t  m_acc;
     uint16_t m_sync_ct;
     uint16_t m_rssi;
+	uint16_t m_batstatus;
 
 	loc_message()
 	 :m_num_ticks(0)
@@ -26,7 +27,7 @@ struct loc_message
 
     loc_message(std::shared_ptr<site> s,uint64_t num_ticks,uint64_t timestamp,
                 uint32_t cardid,int32_t ct,int8_t type,int8_t antid,
-                int16_t rav,int16_t acc,uint16_t sync_ct,uint16_t rssi)
+                int16_t rav,int16_t acc,uint16_t sync_ct,uint16_t rssi,uint16_t batstatus)
         :m_sit(s)
         ,m_num_ticks(num_ticks)
         ,m_loc_time(timestamp)
@@ -38,6 +39,7 @@ struct loc_message
         ,m_acc(acc)
         ,m_sync_ct(sync_ct)
         ,m_rssi(rssi)
+		,m_batstatus(batstatus)
     {}
 };
 

+ 1 - 1
message.cpp

@@ -29,7 +29,7 @@ void message_locinfo::load(zistream&is,bool tdoa)
 	//卡类型、卡号、CT、电池状态
 	is>>b>>m_card_id>>m_card_ct>>m_batty_status;
 	m_card_type=b;
-	m_batty_status&=0xF;
+	m_batty_status&=0x3;
 
 	is>>b;
 	if(m_card_type==1)

+ 1 - 1
net-service.cpp

@@ -83,7 +83,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 						char timebuf[64]{0};
 						unsigned char*t=(unsigned char*)data+10;
 						sprintf(timebuf,"%d-%d %d:%d:%d",*(t+4)+1,*(t+3),*(t+2),*(t+1),*(t+0));
-						logn_info(1,"分站数据信息:%s net=%s,sid=%d,tm=%s,sct=%d",(power&1)==0?"true":"false",clt->name().c_str(),site_id,timebuf,((*t-2)<<8)|*(t-1));
+						logn_info(1,"分站数据信息:%s net=%s,sid=%d,tm=%s,sct=%d",(power&1)==0?"true":"false",clt->name().c_str(),site_id,timebuf,t[-2]*256+t[-1]);
 					}
 
 					site_ptr->set_client(clt);