1
0
فهرست منبع

日志输出相关的修改

zzj 6 سال پیش
والد
کامیت
cf902282e0
6فایلهای تغییر یافته به همراه66 افزوده شده و 38 حذف شده
  1. 4 0
      card_base.cpp
  2. 3 28
      client.cpp
  3. 4 3
      message.cpp
  4. 50 4
      message_file.cpp
  5. 4 2
      message_file.h
  6. 1 1
      net-service.cpp

+ 4 - 0
card_base.cpp

@@ -50,6 +50,10 @@ void card_location_base::on_location(const std::vector<point>&vp,const std::vect
 		log_info("useful:card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%f,y:%f acc:%.2f",m_id,m_ct,m_time,x,y,acc);
 		do_business(lm.front().m_sit, pt, acc);
 	}
+	else
+	{
+		log_warn("坐标不可用:card_id:%d,ct:%d,x:%f,y:%f",m_id,m_ct,pt.x,pt.y);
+	}
 }
 
 void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)

+ 3 - 28
client.cpp

@@ -3,44 +3,19 @@
 #include "log.h"
 #include "message_file.h"
 
-time_t site_timestamp(const char*time)
-{
-	//秒、分、时、天、周、月、年, 脑残的设计
-
-	struct tm t={0};
-
-	t.tm_sec=time[0];
-	t.tm_min=time[1];
-	t.tm_hour=time[2];
-	t.tm_mday=time[3];
-	t.tm_mon=time[5]-1;
-	t.tm_year=time[6]+100;
-
-	return mktime(&t);
-}
 
 int main()
 {
+	message_file  mf(stdin);
+
 	unsigned char b[2048];
 	char m[2048];
-	message_file mf(stdin);
 	uint64_t time=0;
 	int len;
 
 	while((len=mf.get_line(&time,(char*)b,sizeof(b),m))>0)
 	{
-		if(!((b[2]==0x84) && (b[3]==0x3b)))
-			continue;
-
-		int diff=abs(time/1000-site_timestamp((const char*)&b[10]));
-		if(diff>300)
-		{
-			printf("%d:%s\n",diff,m);
-		}
-		else
-		{
-//			printf ("%d\n",diff);
-		}
+		mf.put_line(stdout,time,(char*)b,len);
 	}
 
 	return 0;

+ 4 - 3
message.cpp

@@ -5,8 +5,8 @@
 
 void message_locinfo::zero_this()
 {
-	m_time_stamp=
-	m_site_id=
+//	m_time_stamp=
+//	m_site_id=
 	m_site_time=
 
 	m_card_type=
@@ -68,7 +68,8 @@ void message_locinfo::load(zistream&is,bool tdoa)
 	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);
+	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);
 }
 
 void message_tdoasync::zero_this()

+ 50 - 4
message_file.cpp

@@ -6,8 +6,9 @@
 #include <memory.h>
 #include <time.h>
 #include <stdint.h>
-#include "message_file.h"
 
+#include "message_file.h"
+#include "zstream.h"
 namespace
 {
 char decode[256];
@@ -100,19 +101,24 @@ inline const char* now(char*date_str,uint64_t time)
 	return date_str;
 }
 
-int message_file::put_line(uint64_t time,char*buf,int buflen)
+int message_file::put_line(FILE*fp,uint64_t time,char*buf,int buflen)
 {
 	char b[8192];
 
-	printf("[%s]\n",now(b,time));
+	fprintf(fp,"[%s]\n",now(b,time));
 	int n=0,t;
 	for(int i=0;i<buflen;i++)
 	{
 		t=(int)(unsigned char)buf[i];
 		n+=sprintf(&b[n],"%s ",encode[t]);
+
+		if((i+1)%32 == 0)
+		{
+			n+=sprintf(&b[n],"\n");
+		}
 	}
 
-	printf("%s\n",b);
+	fprintf(fp,"%s\n",b);
 
 	return 0;
 }
@@ -175,3 +181,43 @@ int message_file::get_line(uint64_t*time,char*buf,int buflen,char*m)
 	return o-buf;
 }
 
+int message_file::get_card_message(uint32_t card_id,char*b)
+{
+	int len;
+	char buf[2048];
+	uint64_t time=0;
+
+	int ppos=0;
+	while((len=get_line(&time,buf,sizeof(buf)))>0)
+	{
+		zistream is(buf,len-2);
+		uint16_t cmd;
+		is>>skip(2)>>cmd;
+
+		if(cmd!=0x843b && cmd!=0x753b)
+			continue;
+
+		is>>skip(16);
+
+		while(!is.eof())
+		{
+			uint32_t cid;
+			uint32_t gpos=is.pos();
+			is>>skip(1)>>cid;
+
+			if(cid!=card_id) continue;
+
+			if(ppos==0) memcpy(b,buf,ppos=20); 
+			memcpy(&b[ppos],&buf[gpos],20);
+			ppos+=20;
+		}
+
+		if(ppos==0)  continue;
+
+		ppos+=2;
+	}
+
+	return -1;
+}
+
+

+ 4 - 2
message_file.h

@@ -8,7 +8,7 @@ struct message_file
 private:
 	bool  m_owner;
 	FILE* m_file;
-	char  m_last_line[256];
+	char  m_last_line[1024];
 	message_file(const message_file&);
 public:
 
@@ -19,7 +19,9 @@ public:
 	
 	int get_line(uint64_t*time,char*buf,int buflen,char*msg);
 	int get_line(uint64_t*time,char*buf,int buflen);
-	int put_line(uint64_t time,char*buf,int buflen);
+	int put_line(FILE*fp,uint64_t time,char*buf,int buflen);
+	int get_card_message(uint32_t card_id,char*b);
+
 };
 
 #endif

+ 1 - 1
net-service.cpp

@@ -96,9 +96,9 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 						index++;
 						task*t=task::alloc<message_locinfo>();
 						message_locinfo&m=t->body<message_locinfo>();
-						m.load(is,false);
 						m.m_site_id=site_id;
 						m.m_time_stamp=tstamp;
+						m.load(is,false);
 						//t_site->m_site_data = 0;
 
 						t->m_cmd_code=cmd;