Browse Source

add const && 调整card message ant area类字节序

lixioayao 6 years ago
parent
commit
1fcd33530e
11 changed files with 62 additions and 63 deletions
  1. 7 8
      ant.h
  2. 7 7
      area.cpp
  3. 9 10
      area.h
  4. 16 14
      card_base.h
  5. 2 2
      card_person.cpp
  6. 1 2
      message.cpp
  7. 2 2
      message.h
  8. 5 5
      net-service.cpp
  9. 2 2
      net-service.h
  10. 5 5
      znet.cpp
  11. 6 6
      znet.h

+ 7 - 8
ant.h

@@ -92,8 +92,6 @@ struct site:point,std::enable_shared_from_this<site>
     double  m_scale = 2.0;  // 地图比例尺
     point    m_position;
     mutable double m_height=1.5;
-    int m_id;
-    bool m_path_empty;
     std::array<ant,2> m_ant;
     mutable double m_ant_dist=0;
     mutable double m_ant_dist_sum_new=0;
@@ -106,25 +104,26 @@ struct site:point,std::enable_shared_from_this<site>
     int m_device_type_id=0;
     /// 指定分站定位类型:一维定位,二维定位,三维定位
     int m_dimension=0;
+
     std::shared_ptr<client> m_clt=nullptr;
     std::shared_ptr<area> m_area=nullptr;
 
-
 	time_t m_time;
     time_t m_rec_time;              // 接收数据的时间
     time_t m_lost_time;		        // 丢失时间
     time_t m_last_send_time;	    // 最后向前端发送时间
+	char m_timestamp[8]={0};
+
+    int m_id{-1};
+    int  m_tick_count;			    // 分站发生消息的计数器
 
     unsigned char m_reader_dir;		// 分站方向,对于大小分站适用
     unsigned char m_relay_counts;		// 大小分站经过中继数
-    int  m_tick_count;			    // 分站发生消息的计数器
     bool m_power_check_enable=false;//该分站是否启用交流掉电检测功能(告警功能)
     bool m_power_ac_down=false;     //false=交流电供电状态
+    bool m_path_empty;
 
     site(int id=-1);
-
-
-	char m_timestamp[8]={0};
 	bool check_timestamp(const char*time)
 	{
 		//秒、分、时、天、周、月、年, 脑残的设计
@@ -152,7 +151,7 @@ struct site:point,std::enable_shared_from_this<site>
     {
         return m_id;
 	}
-    void set_client(std::shared_ptr<client>& clt)
+    void set_client(const std::shared_ptr<client>& clt)
     {
 		if(m_clt != clt)
 			m_clt = clt;

+ 7 - 7
area.cpp

@@ -71,20 +71,20 @@ area::area(int id,int limit_count_person, int limit_time_person,double scale,int
      ,m_biz_type(b_type)
      ,m_limit_person_min(limit_time_person)
      ,m_limit_person_count(limit_count_person)
-     ,m_scale(scale)
+	 ,m_event_person_count(false)
+	 ,m_event_person_show_count(false)
+	 ,m_event_vehicle_count(false)
+	 ,m_event_vehicle_show_count(false)
      ,m_mapid(mapid)
+     ,m_scale(scale)
      ,m_person_count(0)
      ,m_vehicle_count(0)
      ,m_person_show_count(0)
      ,m_vehicle_show_count(0)
+	 ,m_frozen_count(0)
+     ,m_is_work_area(0)
     {
 		m_area_business_list=area_business::get_instance_list(m_biz_type,id);
-		m_event_person_count = false;
-		m_event_vehicle_count = false;
-		m_event_person_show_count = false;
-		m_event_vehicle_show_count = false;
-
-		m_frozen_count.store(0);
     }
 void area::clear()
 {

+ 9 - 10
area.h

@@ -61,8 +61,6 @@ struct area
         m_limit_vehicle_min=limit_time_vehicle;
     }
 public:
-	std::vector<area_business*> m_area_business_list;
-	std::atomic<int> m_frozen_count;
 
 	void set_business_list(std::vector<area_business*>&&business_list)
 	{
@@ -87,7 +85,6 @@ public:
 	void change_business(uint32_t new_bits);
     void clear();
 public:
-    std::vector<point> m_bound;
 	//数据库唯一ID
     int    m_id;
 
@@ -110,15 +107,15 @@ public:
     //是否人卡超员已有告警
     bool m_event_person_count;
     bool m_event_person_show_count;
+    //是否人卡超员已有告警
+    bool m_event_vehicle_count;
+    bool m_event_vehicle_show_count;
 
 	//人卡超时及超员数量(阀值)
     int m_limit_vehicle_min;
     int m_limit_vehicle_count;
-    //是否人卡超员已有告警
-    bool m_event_vehicle_count;
-    bool m_event_vehicle_show_count;
-    double m_scale;
     int32_t m_mapid;
+    double m_scale;
 
     ///区域人卡数
     std::atomic<int> m_person_count;
@@ -129,12 +126,14 @@ public:
     ///区域显示车卡数
     std::atomic<int> m_vehicle_show_count;
 
-
-    //区域速度门限
-    std::map<int,double> m_speed;
+	std::atomic<int> m_frozen_count;
 
     //是否是工作区域(0:不是、1:是)
     int m_is_work_area=0;
+    //区域速度门限
+    std::map<int,double> m_speed;
+    std::vector<point> m_bound;
+	std::vector<area_business*> m_area_business_list;
 };
 
 struct area_list:single_base<area_list,int,std::shared_ptr<area>>

+ 16 - 14
card_base.h

@@ -31,33 +31,35 @@ namespace YA{struct _CARD_POS_;}
 struct card:point
 {
 	card(uint32_t id,uint16_t dis,uint64_t type,int32_t deptid,int32_t level_id,uint32_t cid)
-		:m_id(id)
-		,m_cid(cid)
-		,m_type(type)
-		,m_display(dis)
-		,m_speed(0)
-		,m_stat(0)
-		,m_ct(0)
+		:m_type(type)
 		,m_time(0)
+		,m_id(id)
+		,m_cid(cid)
 		,m_deptid(deptid)
 		,m_level_id(level_id)
+		,m_stat(0)
 		,m_biz_stat(0)
+		,m_display(dis)
+		,m_ct(0)
+        ,m_acc(0)
+		,m_speed(0)
 	{}
 	uint64_t type_(){return m_type;}
 	uint64_t time_(){return m_time;}
-	uint32_t m_id;				//卡号
-	uint32_t m_cid;				//标识id 人staff_id 车 vehicle_id
+
 	uint64_t m_type;			//类型
-	uint16_t m_display;			//1显示0不显示,往前端推送
-	double   m_speed;			//速度
-	int		 m_stat;			//运动静止状态
-	uint16_t m_ct;				//ct
     uint64_t m_time;			//时间戳 ms
+	uint32_t m_id;				//卡号
+	uint32_t m_cid;				//标识id 人staff_id 车 vehicle_id
 	int32_t  m_deptid;			//部门编号
 	int32_t  m_level_id;		//部门级别
+	int		 m_stat;			//运动静止状态
 	int		 m_biz_stat;
+	uint16_t m_display;			//1显示0不显示,往前端推送
+	uint16_t m_ct;				//ct
     ///人卡(加速度状态),其值就是0和1,掘进机和采煤机,其值就是0~255,车辆,其值就需要乘以0.01,用于表示加速度值
-    double m_acc =0;
+    double   m_acc;
+	double   m_speed;			//速度
 };
 
 struct card_location_base:card,std::enable_shared_from_this<card_location_base>

+ 2 - 2
card_person.cpp

@@ -155,8 +155,8 @@ void person::on_timer()
 //进入盲区超过2h的卡
 void person::print_card_detained()
 {
-    static point p(4677,-193.7);
-    static double limit_dist=45.0;
+    const static point p(4677,-193.7);
+    const static double limit_dist=45.0;
     int h=tool_time::get_hour();
     uint64_t _now=tool_time::now_to_ms();
     uint64_t work_time=m_mine_tool->get_work_time();

+ 1 - 2
message.cpp

@@ -8,10 +8,9 @@ void message_locinfo::zero_this()
 //	m_time_stamp=
 //	m_site_id=
 	m_site_time=
-
+	m_tof=
 	m_card_type=
 	m_card_id=
-	m_tof=
 	m_card_ct=
 	m_batty_status=
 	m_callinfo=

+ 2 - 2
message.h

@@ -19,12 +19,12 @@ struct zistream;
 struct message_locinfo:task
 {
 	uint64_t m_time_stamp;
-	uint32_t m_site_id;
 	time_t   m_site_time;
+	uint64_t m_tof;
+	uint32_t m_site_id;
 
 	uint32_t m_card_type;
 	uint32_t m_card_id;
-	uint64_t m_tof;
 	uint16_t m_card_ct;
 	uint8_t  m_batty_status;
 	uint8_t  m_callinfo;//0x80-呼救,0x01-一般呼叫,0x02-紧急呼叫

+ 5 - 5
net-service.cpp

@@ -45,11 +45,11 @@ void net_service::on_timer()
 	card_list::instance()->accept(clv);
 	mine_business::inst()->run_business();
 }
-void net_service::on_connect(std::shared_ptr<client> clt)
+void net_service::on_connect(const std::shared_ptr<client>& clt)
 {
      
 }
-void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t len)
+void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,size_t len)
 {
 	bool message_handled=true;
 	try
@@ -62,8 +62,8 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 			case CHAR_LOCATEDATA_TOF_EXTEND://tof-扩展
             case CHAR_LOCATEDATASMALL_TOF_EXTEND:
 				{
-					uint32_t site_id;
-					uint8_t  power;
+					uint32_t site_id=-1;
+					uint8_t  power=-1;
 
 					is>>site_id>>skip(11)>>power;
 					auto site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
@@ -80,7 +80,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 					}
 
 					{
-						char timebuf[64];
+						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));

+ 2 - 2
net-service.h

@@ -14,9 +14,9 @@ struct net_service:service_callback
 
 	net_service();
 	~net_service();
-	void on_message(std::shared_ptr<client> clt,const char*data,size_t len);
+	void on_message(const std::shared_ptr<client> &clt,const char*data,size_t len);
 	void on_timer();
-    void on_connect(std::shared_ptr<client> clt);
+    void on_connect(const std::shared_ptr<client> &clt);
 };
 
 #endif

+ 5 - 5
znet.cpp

@@ -65,7 +65,7 @@ public:
 	{
 		m_serv.on_timer();	
 	}
-	void on_connect(std::shared_ptr<client> clt)
+	void on_connect(const std::shared_ptr<client> &clt)
 	{
 		if(clt->handle()>=(int)m_thread_clts.size())
 		{
@@ -76,23 +76,23 @@ public:
 		m_serv.on_connect(clt);
 	}
 
-	void on_close(std::shared_ptr<client> clt)
+	void on_close(const std::shared_ptr<client> &clt)
 	{
 		m_serv.on_close(clt);
 		m_thread_clts[clt->handle()].reset();
 	}
 
-	void on_send_timeout(std::shared_ptr<client> clt)
+	void on_send_timeout(const std::shared_ptr<client> &clt)
 	{
 		m_serv.on_send_timeout(clt);
 	}
 
-	void on_recv_timeout(std::shared_ptr<client> clt)
+	void on_recv_timeout(const std::shared_ptr<client> &clt)
 	{
 		m_serv.on_recv_timeout(clt);
 	}
 
-	void on_message(std::shared_ptr<client> clt,const char*data,size_t len)
+	void on_message(const std::shared_ptr<client>& clt,const char*data,size_t len)
 	{
 		m_serv.on_message(clt,data,len);
 	}

+ 6 - 6
znet.h

@@ -54,32 +54,32 @@ struct service_callback:service_handle
 		m_handle->boardcast(msg);
 	}
 
-	virtual void on_connect(std::shared_ptr<client> clt)
+	virtual void on_connect(const std::shared_ptr<client>& clt)
 	{
 		log_info("client(%s) connected",clt->name().c_str());
 	}
 
-	virtual void on_close(std::shared_ptr<client> clt)
+	virtual void on_close(const std::shared_ptr<client> &clt)
 	{
 		log_info("client(%s) closed",clt->name().c_str());
 	}
 
-	virtual void on_error(std::shared_ptr<client> clt,const char*error)
+	virtual void on_error(const std::shared_ptr<client> &clt,const char*error)
 	{
 		log_info("client(%s) error with:%s",clt->name().c_str(),error);
 	}
 
-	virtual void on_send_timeout(std::shared_ptr<client> clt)
+	virtual void on_send_timeout(const std::shared_ptr<client> &clt)
 	{
 		log_info("client(%s) send time out",clt->name().c_str());
 	}
 
-	virtual void on_recv_timeout(std::shared_ptr<client> clt)
+	virtual void on_recv_timeout(const std::shared_ptr<client> &clt)
 	{
 		log_info("client(%s) recv time out",clt->name().c_str());
 	}
 
-	virtual void on_message(std::shared_ptr<client> clt,const char*data,size_t len)=0;
+	virtual void on_message(const std::shared_ptr<client>& clt,const char*data,size_t len)=0;
 	virtual void on_timer()=0;
 
 	virtual ~service_callback(){}