Browse Source

添加分站类型区域和普通区域的框架类

zzj 6 years ago
parent
commit
f02b7af8b7
8 changed files with 221 additions and 7 deletions
  1. 1 1
      ant.h
  2. 45 0
      area.cpp
  3. 160 0
      area.h
  4. 12 4
      card.cpp
  5. 1 1
      message.h
  6. 1 1
      site_area_hover.cpp
  7. 0 0
      site_area.h
  8. 1 0
      znet.cpp

+ 1 - 1
ant.h

@@ -261,7 +261,7 @@ struct loc_message
 {
 	site     m_sit;
 	uint64_t m_num_ticks; //tof时间片m_tof或tdoa相对root时间
-	uint64_t  m_loc_time;
+	uint64_t m_loc_time;
 	uint32_t m_card_id;
 	int32_t	 m_card_ct;
 	int8_t   m_card_type;

+ 45 - 0
area.cpp

@@ -0,0 +1,45 @@
+#include <memory>
+#include <write-copy.h>
+
+#include <area.h>
+
+template<> std::shared_ptr<area_list> 
+single_base<area_list, int, std::shared_ptr<area>>::m_instance=std::make_shared<area_list>();
+
+struct area_impl
+{
+	area_impl()
+	{
+	}
+
+	void on_hover(int card_id,const point&pt)
+	{
+	
+	}
+
+	void on_enter(int card_id,std::shared_ptr<area_hover>&c,double speed)
+	{
+	
+	}
+
+	void on_leave(int card_id,std::shared_ptr<area_hover>&c,double speed)
+	{
+	
+	
+	}
+};
+
+area_list::area_list()
+{
+}
+
+std::vector<std::shared_ptr<area>> area_list::get_area(const point&pt)
+{
+	std::vector<std::shared_ptr<area>> ret;
+	//需要添加根据点查找区域的算法
+
+
+
+	return std::move(ret);
+}
+

+ 160 - 0
area.h

@@ -0,0 +1,160 @@
+#ifndef _AREA_HPP_
+#define _AREA_HPP_
+
+#include <atomic>
+#include <algorithm>
+#include <iterator>
+#include <point.h>
+
+#include <write-copy.h>
+
+struct area_hover;
+struct point;
+struct area
+{
+	area()
+	{
+	}
+
+	virtual void on_hover(int card_id,std::shared_ptr<area_hover>&c,double speed)=0;
+	virtual void on_enter(int card_id,std::shared_ptr<area_hover>&c,double speed)=0;
+	virtual void on_leave(int card_id,std::shared_ptr<area_hover>&c,double speed)=0;
+
+	int id()const
+	{
+		return m_id;
+	}
+
+	std::atomic<int> m_card_count;
+
+	int    m_id;
+	double m_limit_speed;
+
+//	std::string m_name;
+//	int m_limit_time_second;
+//	int m_limit_person_count;
+//	int m_area_type;
+
+	std::vector<point> m_bound;
+};
+
+struct area_list:single_base<area_list,int,std::shared_ptr<area>>
+{
+	area_list();
+
+	std::vector<std::shared_ptr<area>> get_area(const point&pt);
+	static void init_from_db()
+	{
+	}
+};
+
+struct area_hover
+{
+	std::shared_ptr<area>  m_area;
+	time_t m_enter_time,m_last_time;
+	point  m_enter_point,m_last_point;
+	int    m_num_speeding;
+
+	area_hover(std::shared_ptr<area>&area,const point&pt,double speed)
+		:m_area(area)
+	{
+		m_enter_time=m_last_time=time(0);
+		m_enter_point=m_last_point=pt;
+		m_num_speeding=0;
+		if(speed>m_area->m_limit_speed)
+			m_num_speeding++;
+	}
+
+	int id()const
+	{
+		return m_area->id();
+	}
+
+	bool operator == (const area_hover&o)const
+	{
+		return m_area->id()==o.m_area->id();
+	}
+
+	bool operator < (const area_hover&o)const
+	{
+		return m_area->id()<o.m_area->id();
+	}
+};
+
+struct area_tool
+{
+	std::vector<std::shared_ptr<area_hover>> m_clist;
+	void on_point(int card_id,const point&pt,double speed)
+	{
+		std::vector<std::shared_ptr<area>> areas=area_list::instance()->get_area(pt);//找出所有的区域
+		std::sort(areas.begin(),areas.end(),[](std::shared_ptr<area>&l,std::shared_ptr<area>&r){
+			return l->id()<r->id();
+		});
+
+		auto c1=m_clist.begin(),ce=m_clist.end();
+		auto a1=areas.begin() ,ae=areas.end();
+
+		std::vector<std::shared_ptr<area_hover>> nlist;
+
+		while (c1!=ce && a1!=ae)
+		{
+			if ((*c1)->id()<(*a1)->id()) 
+			{ 
+				do_leave_biz(card_id,*c1,speed);
+				++c1;
+			}
+			else if ((*a1)->id()<(*c1)->id()) 
+			{
+				nlist.push_back(std::make_shared<area_hover>(*a1,pt,speed));
+				do_enter_biz(card_id,nlist.back(),speed);
+				++a1;
+			}
+			else 
+			{ 
+				nlist.push_back(*c1);
+				do_hover_biz(card_id,nlist.back(),speed);
+				++c1,++a1;
+			}
+		}
+
+		while(c1!=ce)
+		{
+			do_leave_biz(card_id,*c1,speed);
+			++c1;
+		}
+
+		while(a1!=ae)
+		{
+			nlist.push_back(std::make_shared<area_hover>(*a1,pt,speed));
+			do_enter_biz(card_id,nlist.back(),speed);
+			++a1;
+		}
+
+		m_clist=std::move(nlist);
+	}
+
+
+	//检测是否超时
+	void on_timer(int card_id)
+	{
+	
+	}
+
+	void do_hover_biz(int card_id,std::shared_ptr<area_hover>&a,double speed)
+	{
+		a->m_area->on_hover(card_id,a,speed);
+	}
+
+	void do_enter_biz(int card_id,std::shared_ptr<area_hover> a,double speed)
+	{
+		a->m_area->on_enter(card_id,a,speed);
+	}
+
+	void do_leave_biz(int card_id,std::shared_ptr<area_hover> a,double speed)
+	{
+		a->m_area->on_leave(card_id,a,speed);
+	}
+};
+
+#endif
+

+ 12 - 4
card.cpp

@@ -6,6 +6,9 @@
 #include "select_tool.h"
 #include "loc_tool.h"
 
+#include <area.h>
+#include <site_area.h>
+
 #include <card.h>
 
 enum STA_TYPE
@@ -170,7 +173,13 @@ struct card_message_handle
 	}
 };
 
-struct person:card_location_base
+struct card_area
+{
+	std::shared_ptr<site_area_hover> m_site_area;
+	std::shared_ptr<area_tool> m_area_tool;
+};
+
+struct person:card_location_base,card_area
 {
 	person(std::string type)
         :card_location_base(type)
@@ -182,9 +191,8 @@ struct person:card_location_base
 	{
 		m_message_handle->on_message(loop,loc,is_history);
 	}
-
 };
-struct car:card_location_base
+struct car:card_location_base,card_area
 {
     car(std::string type)
         :card_location_base(type)
@@ -201,7 +209,6 @@ loc_tool_main one_ct_message_handle::m_loc_tool;
 
 struct card_list_impl:card_list
 {
-
 	std::vector<card_location_base*> m_list;
 
 	card_list_impl()
@@ -242,3 +249,4 @@ struct card_list_impl:card_list
 
 template<> std::shared_ptr<card_list> 
 single_base<card_list, int, std::shared_ptr<card_location_base>>::m_instance=std::make_shared<card_list_impl>();
+

+ 1 - 1
message.h

@@ -16,7 +16,7 @@ struct message_locinfo
 	uint32_t m_card_id;
 	uint64_t m_tof;
 	uint16_t m_card_ct;
-	uint16_t m_batty_status;
+	uint8_t  m_batty_status;
 	uint8_t  m_callinfo;//0x80-呼救,0x01-一般呼叫,0x02-紧急呼叫
 	uint8_t  m_rav;
 	uint8_t  m_acc;

+ 1 - 1
site_area_hover.cpp

@@ -1,5 +1,5 @@
 
-#include "site_area_hover.h"
+#include "site_area.h"
 
 //每张卡包含这样一个对象,保存最后一个分站区域
 //1、记录卡进出分站的时间,地点

site_area_hover.h → site_area.h


+ 1 - 0
znet.cpp

@@ -461,6 +461,7 @@ struct main_loop:io_context
 		int fd=zio::listen_on(port);
 		if(fd<0)
 		{
+			log_errno("try listen_on %d",port);
 			return -1;
 		}