Procházet zdrojové kódy

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

liheting před 6 roky
rodič
revize
7e1bc71c0f

+ 4 - 4
Makefile.am

@@ -9,17 +9,17 @@ SRC_MODULE_SERVICE= module_service/area_business_car_attendance.cpp module_servi
 					module_service/area_business_person_attendance.cpp module_service/area_business_person_dwell_checker.cpp \
 					module_service/area_business_post_area.cpp module_service/area_business_speed_checker.cpp \
 					module_service/module_meta_date_changed.cpp module_service/module_web.cpp \
-					module_service/module_call.cpp module_service/module_call_help.cpp module_service/module_mgr.cpp module_service/module_other_alarm.cpp
+					module_service/module_call.cpp module_service/module_call_help.cpp module_service/module_mgr.cpp \
+					module_service/module_other_alarm.cpp module_service/area_business_work_rate.cpp
 
 
 SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_area.cpp card_base.cpp card_car.cpp \
     	  card.cpp card_message_handle.cpp cardMgr.cpp card_path.cpp card_person.cpp crc.cpp geo_hash.cpp \
 		  landmark.cpp line_fit.cpp loc_point.cpp loc_tool.cpp message.cpp message_file.cpp mine.cpp \
 		  net-service.cpp point.cpp select_tool.cpp site_area.cpp special_area.cpp tdoa_sync.cpp visit.cpp \
-		  web-client.cpp worker.cpp  znet.cpp ya_setting.cpp area_business.cpp event.cpp 
-SRC_MAIN_EVENT= mine_module/MineCardManager.cpp
+		  web-client.cpp worker.cpp event.cpp znet.cpp ya_setting.cpp area_business.cpp
 
-AM_SOURCES=$(SRC_MODULE_SERVICE) $(SRC_MONKEYCAR) $(SRC_MAIN) $(SRC_MAIN_EVENT)
+AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN) $(SRC_MAIN_EVENT)
 
 AM_CPPFLAGS=-Wall -pthread -m64 -g -std=c++11  -I${prefix}/include -I/usr/local/mysql/include -Iwebsocket -Iwebsocket/sio -I./db -I../dist/include -I../rapidjson/include -Imodule_service
 

+ 7 - 20
ant.cpp

@@ -4,6 +4,7 @@
 #include "ant.h"
 #include "db_api/CDBSingletonDefine.h"
 #include "event.h"
+#include "tool_time.h"
 template<> std::shared_ptr<sit_list> 
 single_base<sit_list, int, std::shared_ptr<site>>::m_instance=std::make_shared<sit_list>();
 int site::index()const
@@ -330,35 +331,21 @@ void sit_list::read_sit_list(int id)
     }
 }
 
-
 /*
-
    处理分站供电状态,交流供电时,ac_down=false,直流供电时,ac_down=true
 
    目前只有大分站实现了这个功能,并且井下安装时是否接入了该电信号也不确定
    ,所以需要有张表定义某个ID是否需要告警
-
  */
 void site::on_power_status(bool ac_down)//电源状态
 {
-	if(!m_power_check_enable)
-		return;
-	
-	if(ac_down == m_power_ac_down)
-		return;
-	m_power_ac_down=ac_down;
-	if(m_power_ac_down)
+	if(!m_power_check_enable || ac_down == m_power_ac_down)
 	{
-		//掉电告警
-	
-	
-	}
-	else
-	{
-		//撤销警告
-	
-	
-	}
+        return;
+    }
+    m_power_ac_down=ac_down;
+    event_tool::instance()->handle_event(OT_DEVICE_READER,ET_READER_POWER_BY_BATTERY,id(),tool_time::now_to_seconds(),ac_down,m_power_ac_down);
+    log_info("[event warning: reader power supply by battery] reader_id: Power %d->%d.",id(),!m_power_ac_down,m_power_ac_down);
 }
 
 #if 0

+ 0 - 206
ant.cppbak

@@ -1,206 +0,0 @@
-
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include "ant.h"
-
-int site::index()const
-{
-	return m_algo+(m_num_dims<<1);
-}
-
-sit_list*sit_list::instance()
-{
-	static sit_list _impl;
-	//_impl.load_from_db();
-	return &_impl;
-}
-site::site(int id)
-	:m_algo(0)
-	,m_num_dims(0)
-    ,m_id(id)
-    ,m_path_empty(true)
-{
-
-}
-const algo_config&site::config()const
-{
-	return g_config[index()];
-}
-
-const site& sit_list::operator[](int id) const
-{
-    return m_list[id];
-} 
-static int str_split(char*s,char**rc)
-{
-	char**o=rc;
-
-	for(;*s;)
-	{
-		*o=strtok_r(s,",",&s);
-		o++;
-	}
-
-	return o-rc;
-}
-
-//1, 101, 1, '101-1', 4727, 75, 0, 0, '2017-08-29 10:21:14'
-void sit_list::read_sit_list(const char*fname)
-{
-	FILE*fp=fopen(fname,"r");
-	char buf[512];
-	int t,id;
-	char* s[20];
-	while(fgets(buf,sizeof(buf),fp))
-	{
-		t=str_split(buf,&s[0]);
-		if(t<8)
-			continue;
-
-		id=atoi(s[1]);
-		if(id>(int)m_list.size())
-			continue;
-
-		int antid=atoi(s[2])-1;
-		if(antid>=2)
-			continue;
-
-		m_list[id].m_id=id;
-		m_list[id].m_ant[antid].set(atof(s[4]),-atof(s[5]));
-	}
-
-	for(auto&sit:m_list)
-	{
-		if(sit.m_id==-1)
-			continue;
-
-		if(sit.m_ant[0]==sit.m_ant[1])
-		{
-			printf("%d分站天线坐标相等.\n",sit.m_id);
-		}
-
-		sit.set( (sit.m_ant[0].x+sit.m_ant[1].x)/2,(sit.m_ant[0].y+sit.m_ant[1].y)/2);
-	}
-
-	fclose(fp);
-}
-void sit_list::read_ant_path(const char*fname)
-{
-	FILE*fp=fopen(fname,"r");
-	char buf[512],*p;
-	int t,id,pid;
-	char* s[20];
-	while((p=fgets(buf,sizeof(buf),fp)))
-	{
-		t=str_split(buf,&s[0]);
-		if(t<9)
-			continue;
-
-		id=atoi(s[0]);
-		if(id>(int)m_list.size())
-			continue;
-
-		pid=atoi(s[1]);
-		if(pid>2)
-          continue;
-
-        point p1(atof(s[2]),-atof(s[3]));
-        point p2(atof(s[5]),-atof(s[6]));
-        
-        if(pid == 0)
-        {
-            line_v l(p1,p2);
-            {
-                point px = l.line::projection(m_list[id]);
-                m_list[id].set(px);
-                for(int i=0;i<2;i++)
-                {
-                    path p;
-                    p.m_slope[0] = atof(s[8]);
-                    p.m_line[0] = line_v(px,l[i]);
-                    m_list[id].m_ant[i].m_path.push_back(p);
-                }
-            }
-        }
-        else 
-        {
-            ant &a = pid<0?m_list[id].m_ant[0]:m_list[id].m_ant[1];
-            if(a.m_path.size()!=0)
-            {
-                path &p = a.m_path[0];
-                p.m_line[abs(pid)-1] = line_v(p1,p2);
-                p.m_slope[abs(pid)-1] = atof(s[8]);
-            }
-            else
-            {
-                path p;
-                p.m_line[abs(pid)-1] = line_v(p1,p2);
-                p.m_slope[abs(pid)-1] = atof(s[8]);
-                a.m_path.push_back(p);
-            }
-            if(abs(pid)==1)
-				 m_list[id].set(p1);
-        }
-	}
-	fclose(fp);
-
-	for(auto&s:m_list)
-	{
-		if(s.m_id==-1)
-			continue;
-        s.swap();
-		if((s.path(0).empty() && s.path(1).empty()))
-			continue;
-        s.m_path_empty=false; 
-
-        for(auto &a:s.m_ant)
-        for(auto &p:a.m_path)
-        {
-            if(!p.m_line[0].empty())
-            {
-                point px = p.m_line[0].line::projection(a);
-                p.m_line[0]=line_v(px,p.m_line[0][1]);
-            }
-        }
-        std_info("%s",s.to_string().c_str());
-        //std_info("%f----%f",s.x,s.y);
-	}
-}
-
-
-
-loc_message::loc_message()
-	 :m_num_ticks(0)
-{
-}
-int loc_message::tool_index()const
-{
-	return m_sit.index();
-}
-
-algo_config site::g_config[]=
-{
-	{ "tof-1",  1, 2, 0.1, 1 },
-	{ "tdoa-1", 2, 2, 0.1, 1 },
-	{ "tof-2",  2, 3, 0.1, 1 },
-	{ "tdoa-2", 3, 3, 0.1, 1 },
-	{ "tof-3",  3, 4, 0.1, 1 },
-	{ "tdoa-3", 4, 4, 0.1, 1 }
-};
-
-template<> std::shared_ptr<sit_list> 
-single_base<sit_list, int, std::shared_ptr<site>>::m_instance=std::make_shared<sit_list>();
-#ifdef _TEST
-int main()
-{
-	log_init("./log.ini");
-    sit_list *sl = sit_list::instance();
-	sl->load("data_reader_antenna.txt","path_tof.txt");
-    (*sl)[219].solving(0,100);
-    (*sl)[219].solving(1,100.5);
-    std_info("---%d",(*sl)[209].m_ant[0].m_path.size());
-    std_info("---%d",(*sl)[209][0].size());
-    std_info("---%s",(*sl)[209][0][0][0].to_string().c_str());
-}
-#endif

+ 12 - 3
ant.h

@@ -1,3 +1,6 @@
+/**
+ * 分站数据结构 site_list
+ */
 #ifndef _ANT_LIST_HPP_
 #define _ANT_LIST_HPP_
 
@@ -130,6 +133,15 @@ struct site:point,std::enable_shared_from_this<site>
 
 
 	time_t m_time;
+    time_t m_rec_time;              // 接收数据的时间
+    time_t m_lost_time;		        // 丢失时间
+    time_t m_last_send_time;	    // 最后向前端发送时间
+
+    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=交流电供电状态
 
     site(int id=-1);
 
@@ -318,9 +330,6 @@ struct site:point,std::enable_shared_from_this<site>
         m_ant[0].m_path.clear();
         m_ant[1].m_path.clear();
     }
-
-	bool m_power_check_enable=false;//该分站是否启用交流掉电检测功能
-	bool m_power_ac_down=false;//交流电供电状态
 /*
 
 	处理分站供电状态,交流供电时,ac_down=false,直流供电时,ac_down=true

+ 0 - 293
ant.hbak

@@ -1,293 +0,0 @@
-#ifndef _ANT_LIST_HPP_
-#define _ANT_LIST_HPP_
-
-#include <math.h>
-#include <array>
-#include <deque>
-#include <tuple>
-#include <memory>
-#include <algorithm>
-#include <sstream>
-#include "log.h"
-#include "line.h"
-#include "point.h"
-#include "write-copy.h"
-
-struct path
-{
-    std::array<line_v,2>	m_line; 
-    std::array<double,2>    m_slope;
-    path()
-    {
-        for(auto &d:m_slope)
-            d=0;
-    }
-    std::string to_str() const
-    {
-        std::stringstream ss;
-        for(int i=0;i<2;i++)
-        {
-            ss<<"line:" <<m_line[i].to_string()<<"slope:"<<m_slope[i]<< " cos:"<<m_line[i].cos()<<" sin:"<<m_line[i].sin()<<" | ";
-        }
-        return ss.str();
-    }
-    bool vaild() const
-    {
-        return !m_line[0].empty();
-    }
-    line_v & operator[](int i)
-    {
-        return m_line[i];
-    }
-    const line_v & operator[](int i) const 
-    {
-        return m_line[i];
-    }
-   
-};
-//?
-struct algo_config
-{
-	const char*desc;
-	int min_msg_cnt;
-	int best_msg_cnt;
-	double min_wait_time;
-	double max_wait_time;
-};
-//
-struct ant :point
-{
-	std::vector<path> m_path;
-    path & operator[](int i)
-    {
-        return m_path[i];
-    }
-    const path & operator[](int i) const
-    {
-        return m_path[i];
-    }
-    size_t size() const
-    {
-        return m_path.size();
-    }
-    std::vector<point> getsol(const double &dist) const
-    {
-        std::vector<point> v;
-        for(const auto & p : m_path)
-        {
-            double d  = dist;
-            if(p.vaild())
-            {
-                point pt;
-                if(dist <= p.m_line[0].length() || (dist > p.m_line[0].length() && p.m_line[1].empty()))        
-                {
-                    d += d*p.m_slope[0];
-                    pt = point(p.m_line[0][0].x + d*p.m_line[0].cos() , p.m_line[0][0].y + d*p.m_line[0].sin());
-                }
-                else
-                {
-                    d -= p.m_line[0].length();
-                    d += d*p.m_slope[1];
-                    pt = point(p.m_line[1][0].x+d*p.m_line[1].cos(),p.m_line[1][0].y+d*p.m_line[1].sin());
-                }
-                v.push_back(pt);
-                std_info("get_sol:x:%.2f,y:%.2f",pt.x,pt.y);
-            }
-            else
-                std_error("%s","ant::getsol empty path..");
-        }
-        return std::move(v);
-    }
-
-};
-
-struct site:point
-{
-	static algo_config g_config[];
-	int      m_algo;			//TOF:0,TDOA:1
-	int      m_num_dims;	    //1维:0,2维:1,3维:2
-    double  m_scale = 2.0;  // 地图比例尺
-
-	point    m_position;
-	int index()const;
-	const algo_config&config()const;
-
-	site(int id=-1);
-
-	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;
-	mutable int m_ant_dist_cnt_new=0;
-
-    point get_dstp(const point pt) const 
-    {
-        point tmp;
-        for(const auto & p : m_ant[0].m_path)
-        {
-            for(int i=0;i<2;i++)
-            {
-                if(!p[i].empty())
-                {
-                    if(p[i].contain(pt,0.01))
-                    {
-                        //if(i==0)
-                         // return *this;
-                        //else
-                          tmp = p[i][0];
-                    }
-                }
-            }
-        }
-        return tmp;
-    }
-
-	void count_ant_dist(double dist_tof1, double dist_tof2)const
-	{
-		if(dist_tof1<10 || dist_tof2<10)
-			return;
-		double dist = fabs(dist_tof1 - dist_tof2);
-		if(dist>5)
-			return;
-		m_ant_dist_sum_new += dist;
-		m_ant_dist_cnt_new++;
-		
-		if(m_ant_dist_cnt_new >= 2500)
-		{
-			m_ant_dist = m_ant_dist_sum_new / m_ant_dist_cnt_new;
-			m_ant_dist_sum_new = 0;
-			m_ant_dist_cnt_new = 0;
-		}
-	}
-    void swap()
-    {
-       auto v0 =  m_ant[0].m_path;
-       auto v1 =  m_ant[1].m_path;
-       std::copy (std::begin(v0),std::end(v0),std::back_inserter(m_ant[1].m_path));
-       std::copy (std::begin(v1),std::end(v1),std::back_inserter(m_ant[0].m_path));
-    }
-	double ant_dist()const
-	{
-		return m_ant[0].dist(m_ant[1]);
-	}
-	
-	bool is_path_empty()const
-	{
-        return m_path_empty;
-	}
-
-	bool have_valid_path()const
-	{
-        return m_id != -1 && ant_dist() > 0.1;
-	}
-
-	std::string to_string()const
-	{
-        std::stringstream ss;
-        ss<<"site_id:"<<m_id<<"x:"<<x<<" y: "<<y;
-        for(const auto a:m_ant)
-        {  
-            ss<<"<";
-            for(const auto p:a.m_path)
-            {
-                ss<<"{"<<p.to_str()<<"}";
-            }
-            ss<<">";
-        }
-        return ss.str();
-	}
-
-	const point&path(int i)const
-	{
-        static point p;
-        if(i>=(int)m_ant[0].m_path.size())
-            return p ;
-		return m_ant[0].m_path[i].m_line[0][1];
-	}
-
-    std::vector<point> solving(int ant_id, double dist)const
-	{
-        const ant &a = m_ant[ant_id];
-        if(dist<50 && dist>0)
-		{
-			if(dist<m_height)
-			{
-				m_height=dist;
-				dist=0;				
-			}
-			else
-			{
-				dist=sqrt(dist*dist-m_height*m_height);
-			}
-		}
-        return std::move(a.getsol(dist));
-   	}
-    ant operator[](int i)
-    {
-        return m_ant[i];
-    }
-    const ant operator[](int i) const
-    {
-        return m_ant[i];
-    }
-};
-
-
-struct sit_list:single_base<sit_list,int,std::shared_ptr<site>>
-{
-
-	const site& operator[](int id) const;
-	static void load(const char*ant_file,const char*path_file)
-	{
-		read_sit_list(ant_file);
-		read_ant_path(path_file);
-	}
-
-	static void load_from_db()
-	{
-		load("data_reader_antenna.txt","path_tof.txt");
-	}
-
-	static void read_sit_list(const char*fname);
-	static void read_ant_path(const char*fname);
-};
-
-struct loc_message
-{
-	site     m_sit;
-	uint64_t m_num_ticks; //tof时间片m_tof或tdoa相对root时间
-	uint64_t m_loc_time;
-	uint32_t m_card_id;
-	int32_t	 m_card_ct;
-	int8_t   m_card_type;
-	int8_t   m_ant_id;
-	int16_t  m_rav;
-	int16_t  m_acc;
-	uint16_t m_sync_ct;
-	uint16_t m_rssi;
-
-
-	loc_message();
-	loc_message(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)
-		:m_sit(s)
-		 ,m_num_ticks(num_ticks)
-         ,m_loc_time(timestamp)
-        ,m_card_id(cardid)
-        ,m_card_ct(ct)
-        ,m_card_type(type)
-        ,m_ant_id(antid)
-        ,m_rav(rav)
-        ,m_acc(acc)
-        ,m_sync_ct(sync_ct)
-        ,m_rssi(rssi)
-	{}
-	int tool_index()const;
-};
-
-#endif
-

+ 3 - 82
area.cpp

@@ -13,6 +13,7 @@
 #include <boost/algorithm/string/classification.hpp>
 
 #include "area_business.h"
+#include "site_area.h"
 #include"card.h"
 
 template<> std::shared_ptr<area_list> 
@@ -63,6 +64,8 @@ area::area(int id,int limit_count_person, int limit_time_person,double scale,int
      ,m_vehicle_count(0)
     {
 		m_area_business_list=area_business::get_instance_list(m_area_type);
+		m_event_person_count = false;
+		m_event_vehicle_count = false;
     }
 
 
@@ -378,88 +381,6 @@ void area_list::init_from_db(int id/*=-1*/)
     init_monkeycar_area(id);
 }
 
-
-#if 0
-//新画禁区功能-给禁区中的卡发送警告及呼叫
-void area_list::CheckAreaType(int area_id,int new_area_type,int old_area_type)
-{
-    auto area_ptr = area_list::instance()->get(area_id);
-    if (!area_ptr) {
-        log_info("区域已经删除:areaid=%d", area_id);
-        return;
-    }
-    CheckAreaType(area_ptr,new_area_type,old_area_type);
-}
-void area_list::CheckAreaType( std::shared_ptr<area> pArea,int new_area_type,int old_area_type)
-{
-    if (nullptr == pArea)
-    {
-        return ;
-    }
-    if (new_area_type != AREA_TYPE::AREA_TYPE_FORBIDDEN && old_area_type != AREA_TYPE::AREA_TYPE_FORBIDDEN)
-    {
-        return;
-    }
-
-    struct local_visit:visitor<std::shared_ptr<card_location_base>>
-    {
-        std::shared_ptr<area> m_area;
-        int m_old_area_type;
-        bool visit(std::shared_ptr<card_location_base> c)
-        {
-            //处理
-            point pt(c->x,c->y,c->z);
-            std::shared_ptr<area> point_area = area_list::instance()->get_area(pt);
-            if (point_area == nullptr)
-            {
-                return true;
-            }
-            //不在区域里
-            if (m_area->m_id != point_area->m_id)
-            {
-                return true;
-            }
-
-            if (m_area->m_area_type == AREA_TYPE::AREA_TYPE_FORBIDDEN)
-            {
-                //发送进入禁区的警告
-                //呼叫
-                std::shared_ptr<area_hover> _area_hover = c->get_area_hover();
-                if (nullptr != _area_hover)
-                {
-                    _area_hover->m_area = m_area;
-                    _area_hover->m_area->on_enter(_area_hover,c);
-                }
-            }
-            else
-            {
-                if (m_old_area_type == AREA_TYPE::AREA_TYPE_FORBIDDEN)
-                {
-                    //之前是禁区,改成非禁区
-                    //发送一个离开禁区的警告
-                    //停止呼叫
-                    std::shared_ptr<area_hover> _area_hover = c->get_area_hover();
-                    if (nullptr != _area_hover)
-                    {
-                        _area_hover->m_area->on_leave(_area_hover,c);
-                    }
-                }
-                else
-                {
-                    return  false;
-                }
-            }
-
-            return true;
-        }
-    };
-    local_visit lv;
-    lv.m_area = pArea;
-    lv.m_old_area_type = old_area_type;
-    card_list::instance()->accept(lv);
-}
-
-#endif
 std::vector<point> area_list::init_path(std::string &str)
 {
 	if(str.empty())

+ 8 - 5
area.h

@@ -8,6 +8,7 @@
 #include <point.h>
 #include "common.h"
 #include <write-copy.h>
+#include <set>
 
 struct area_hover;
 struct point;
@@ -77,13 +78,17 @@ public:
 	*/
     int m_area_type;
 
-	//人卡超时及超员数量
+	//人卡超时及超员数量(阀值)
     int m_limit_person_second;
     int m_limit_person_count;
+    //是否人卡超员已有告警
+    bool m_event_person_count;
 
-	//人卡超时及超员数量
+	//人卡超时及超员数量(阀值)
     int m_limit_vehicle_second;
     int m_limit_vehicle_count;
+    //是否人卡超员已有告警
+    bool m_event_vehicle_count;
     double m_scale;
     int32_t m_mapid;
 
@@ -92,6 +97,7 @@ public:
     ///区域车卡数
     std::atomic<int> m_vehicle_count;
 
+
     //区域速度门限
     double m_over_speed_vehicle;
 
@@ -111,9 +117,6 @@ struct area_list:single_base<area_list,int,std::shared_ptr<area>>
     void init_monkeycar_area(int id=-1);
 private:
 	std::shared_ptr<area>  create(int type,int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t b_type);
-    //禁区功能-给禁区中的卡发送警告及呼叫
-    void CheckAreaType(int area_id,int new_area_type,int old_area_type);
-    void CheckAreaType( std::shared_ptr<area> pArea,int new_area_type,int old_area_type);
 };
 
 struct area_hover

+ 0 - 3
area_beh.h

@@ -1,3 +0,0 @@
-
-
-

+ 0 - 1
area_business.cpp

@@ -1,6 +1,5 @@
 
 #include <assert.h>
-
 #include "area_business.h"
 #include "area_business_car_attendance.h"
 #include "area_business_card_enter_or_leave.h"

+ 0 - 1
card.cpp

@@ -17,7 +17,6 @@
 #include "area.h"
 #include "card.h"
 #include "mine_business.h"
-#include "mine_module/MineCardManager.h"
 
 extern config_file config;
 void card_list::init_staffer(int64_t id64)

+ 0 - 945
card_path.cppbak

@@ -1,945 +0,0 @@
-#include <stdio.h>
-#include <algorithm>
-#include <unordered_map>
-#include <set>
-#include <memory>
-#include <atomic>
-#include <thread>
-#include "zlist.h"
-#include "line.h"
-#include "ant.h"
-
-#include "card_path.h"
-#include "visit.h"
-
-namespace{
-
-static const double PI=3.1416;
-inline bool eq(double a,double b,double e=0.0001)
-{
-	return fabs(a-b)<e;
-}
-
-struct vertex:point
-{
-	float level;
-	int sid0,sid1;
-	vertex()
-		:level(0)
-		,sid0(0)
-		,sid1(0)
-	{}
-
-	vertex(const point&pt,float level_=0,int site_id0=0,int site_id1=0)
-		:point(pt)
-		,level(level_)
-		,sid0(site_id0)
-		,sid1(site_id1)
-	{
-	}
-
-	std::string to_string()const
-	{
-		char buf[128];
-		sprintf(buf,"%.2f,%.3lf,%d,%d,%.2lf",x,y,sid0,sid1,level/PI*180);
-
-		return buf;
-	}
-};
-
-struct vertex_list;
-struct base_path:std::array<int,2>
-{
-	int sid;
-	base_path(int i1=-1,int i2=-1)
-	{
-		at(0)=i1;
-		at(1)=i2;
-	}
-
-	bool operator<(const base_path&o)const
-	{
-		int c=at(0)-o.at(0);
-		if(c!=0)
-			return c<0;
-
-		return at(1)-o.at(1)<0;
-	}
-
-	point  cross(const vertex_list&v_list, const base_path&o)const;
-	bool   contains(const vertex_list&v_list, const point&o, double e)const;
-	double arg(const vertex_list&v)const;
-	int    type(const vertex_list&v)const;
-	line_v as_line(const vertex_list&v)const;
-	int    level(const vertex_list&v)const;
-};
-
-struct vertex_list
-{
-	std::vector<vertex> v;
-
-	std::string to_string()const
-	{
-		std::string ret;
-		ret.reserve(1024);
-
-		char buf[128];
-		for(int i=0,len=v.size();i<len;i++)
-		{
-			sprintf(buf,"vertex:%3d,%s\n",i,v[i].to_string().c_str());
-
-			ret+=buf;
-		}
-
-		return std::move(ret);
-	}
-
-	void log()
-	{
-		printf("%s",to_string().c_str());
-	}
-
-
-	static unsigned hash(const point&p)
-	{
-		return (((((unsigned)p.x)>>2)<<16) + (((unsigned)p.y)>>2));
-	}
-
-	int find(const point&p,double x=1)const
-	{
-		int rc=-1;
-		double t;
-
-		for(int i=0,len=v.size();i<len;i++)
-		{
-			t=p.dist(v[i]);
-			if(t<x)
-			{
-				rc=i;
-				x=t;
-			}
-		}
-
-		return rc;
-	}
-
-	int add(const point&p,float level=0,int sid0=0,int sid1=0)
-	{
-		int i=find(p);
-
-		if(i<0)
-		{
-			v.push_back(vertex(p,level,sid0,sid1));
-			return v.size()-1;
-		}
-
-		vertex&v0=v[i];
-
-		v0.level=std::max(v0.level,level);
-
-		return i;
-	}
-
-	int size()const
-	{
-		return v.size();
-	}
-
-	const vertex&operator[](int i)const
-	{
-		return v[i];
-	}
-
-	vertex&operator[](int i)
-	{
-		return v[i];
-	}
-};
-
-int base_path::level(const vertex_list&v)const
-{
-	const vertex&p0=v[at(0)];
-	const vertex&p1=v[at(1)];
-
-	return p0.level+p1.level;
-}
-
-line_v base_path::as_line(const vertex_list&v)const
-{
-	const vertex&p0=v[at(0)];
-	const vertex&p1=v[at(1)];
-
-	return line_v(p0,p1);
-}
-
-double  base_path::arg(const vertex_list&v)const
-{
-	return as_line(v).arg();
-}
-
-bool  base_path::contains(const vertex_list&v, const point&o, double e)const
-{
-	return as_line(v).contain(o,e);
-}
-
-point  base_path::cross(const vertex_list&v, const base_path&o)const
-{
-	line_v l0=as_line(v);
-	line_v l1=o.as_line(v);
-
-	return l0.crossing(l1);
-}
-
-void log_path(const std::vector<base_path>&path,const vertex_list&v_list)
-{
-	printf("%s\n","----------------------------------------------------------------");
-	for(int i=0,len=path.size();i<len;i++)
-	{
-		double c=path[i].arg(v_list)/PI*180;
-		printf("base_path %.6lf, %03d,(%d,%s),(%d,%s)\n",c,i,path[i][0],v_list[path[i][0]].to_string().c_str(),path[i][1],v_list[path[i][1]].to_string().c_str());
-	}
-}
-struct handle_path :visitor<std::shared_ptr<site>>
-{
-	std::vector<base_path> ret;
-	bool visit(std::shared_ptr<site> sit)
-	{
-		//auto&s=sites[i];
-		const auto &s = *sit;
-
-		if(!s.have_valid_path())
-			continue;
-
-		if(s.path(0).empty()||s.path(1).empty())
-			continue;
-        if(s[0].size()<2)
-            continue;
-        line_v l000 = s[0][0][0];
-        line_v l010 = s[0][1][0];
-        if(l000.is_same(l010))
-        {
-            printf("same....%d",s.m_id);
-			int p0=v.add(point::min(s.path(0),s.path(1)),0,s.m_id);
-			int p1=v.add(point::max(s.path(0),s.path(1)),0,s.m_id);
-
-		    ret.push_back(base_path(p0,p1));
-			ret.back().sid=s.m_id;
-        }
-        else
-        {
-            point px = l000.line::crossing(l010);
-            for(int i=0;i<2;i++)
-            {
-			    int p0=v.add(point::min(px,s.path(i)),0,s.m_id);
-			    int p1=v.add(point::max(px,s.path(i)),0,s.m_id);
-
-		        ret.push_back(base_path(p0,p1));
-			    ret.back().sid=s.m_id;
-            }
-        }
-        for(int i=0;i<2;i++)
-        {
-            if(!s[0][i][1].empty())
-            {
-			    int p0=v.add(point::min(s[0][i][1][0],s[0][i][1][1]),0,s.m_id);
-			    int p1=v.add(point::max(s[0][i][1][0],s[0][i][1][1]),0,s.m_id);
-
-		        ret.push_back(base_path(p0,p1));
-			    ret.back().sid=s.m_id;
-            }
-        }
-		return true;
-	}
-};
-static std::vector<base_path> init_path(const sit_list&sites,vertex_list&v)
-{
-	std::vector<base_path> ret;
-//	for(uint32_t i=0;i<sites.m_list.size();i++)
-//	{
-//		auto&s=sites[i];
-//
-//		if(!s.have_valid_path())
-//			continue;
-//
-//		if(s.path(0).empty()||s.path(1).empty())
-//			continue;
-//        if(s[0].size()<2)
-//            continue;
-//        line_v l000 = s[0][0][0];
-//        line_v l010 = s[0][1][0];
-//        if(l000.is_same(l010))
-//        {
-//            printf("same....%d",s.m_id);
-//			int p0=v.add(point::min(s.path(0),s.path(1)),0,s.m_id);
-//			int p1=v.add(point::max(s.path(0),s.path(1)),0,s.m_id);
-//
-//		    ret.push_back(base_path(p0,p1));
-//			ret.back().sid=s.m_id;
-//        }
-//        else
-//        {
-//            point px = l000.line::crossing(l010);
-//            for(int i=0;i<2;i++)
-//            {
-//			    int p0=v.add(point::min(px,s.path(i)),0,s.m_id);
-//			    int p1=v.add(point::max(px,s.path(i)),0,s.m_id);
-//
-//		        ret.push_back(base_path(p0,p1));
-//			    ret.back().sid=s.m_id;
-//            }
-//        }
-//        for(int i=0;i<2;i++)
-//        {
-//            if(!s[0][i][1].empty())
-//            {
-//			    int p0=v.add(point::min(s[0][i][1][0],s[0][i][1][1]),0,s.m_id);
-//			    int p1=v.add(point::max(s[0][i][1][0],s[0][i][1][1]),0,s.m_id);
-//
-//		        ret.push_back(base_path(p0,p1));
-//			    ret.back().sid=s.m_id;
-//
-//            }
-//        }
-//    }
-
-/*
-
-		if(x.contain(s,2.5))
-		{
-			int p0=v.add(point::min(s.path(0),s.path(1)),0,s.m_id);
-			int p1=v.add(point::max(s.path(0),s.path(1)),0,s.m_id);
-
-		    ret.push_back(base_path(p0,p1));
-			ret.back().sid=s.m_id;
-			continue;
-		}
-
-		for(int j=0;j<2;j++)
-		{
-			if(!s.path(j).empty() && s.dist(s.path(j))<2)
-				continue;
-
-			point p=s.path(j);
-			int p0=v.add(point::min(s,p),0,s.m_id);
-			int p1=v.add(point::max(s,p),0,s.m_id);
-			ret.push_back(base_path(p0,p1));
-			ret.back().sid=s.m_id;
-		}
-	}
-*/
-	log_path(ret,v);
-    printf("++++++++++++++++++++++++++++++++++++++++++++");
-	std::sort(ret.begin(),ret.end());
-	log_path(ret,v);
-    printf("++++++++++++++++++++++++++++++++++++++++++++");
-	ret.erase(std::unique(ret.begin(),ret.end()),ret.end());
-	log_path(ret,v);
-    printf("++++++++++++++++++++++++++++++++++++++++++++");
-
-	std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
-		double arg=p1.arg(v)-p2.arg(v);
-
-		if(fabs(arg)<0.1)
-		{
-			return v[p1[0]]<v[p2[0]];
-		}
-
-		return arg<0;
-	});
-
-	log_path(ret,v);
-
-	for(int i=0,len=ret.size();i<len;i++)
-	{
-		line_v li=ret[i].as_line(v);
-		for(int j=i+1;j<len;j++)
-		{
-			line_v lj=ret[j].as_line(v);
-			if(!lj.is_same(li,2.5))
-				continue;
-
-			line_v ij=lj.projection(li);
-
-			if(ij.empty())
-				continue;
-
-			point p0=point::min(v[ret[j][0]],v[ret[i][0]]);
-			point p1=point::max(v[ret[j][1]],v[ret[i][1]]);
-
-			ret[j][0]=v.add(p0,0);
-			ret[j][1]=v.add(p1,0);
-
-			ret[i][0]=0;
-			ret[i][1]=0;
-			break;
-		}
-	}
-
-	ret.erase(std::remove_if(ret.begin(),ret.end(),[&v](const base_path&p){
-		return p[0]==0||p[1]==0;
-	}),ret.end());
-#ifdef __DEBUG__
-	std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
-		double arg=p1.arg(v)-p2.arg(v);
-
-		if(fabs(arg)<0.1)
-		{
-			return v[p1[0]]<v[p2[0]];
-		}
-
-		return arg<0;
-	});
-
-	log_path(ret,v);
-#endif
-
-	std::vector<std::vector<int>> p0(ret.size());
-	std::vector<base_path> ret2;
-	for(int i=0,len=ret.size();i<len;i++)
-	{
-		p0[i].push_back(ret[i][0]);
-		for(int j=i+1;j<len;j++)
-		{
-			if(i==j) continue;
-
-			point cr=ret[i].cross(v,ret[j]);
-			if(cr.empty())
-				continue;
-
-			double arg=fabs(ret[i].as_line(v).arg()-ret[j].as_line(v).arg());
-			while(arg>PI/2) 
-				arg-=PI/2;
-
-			if(arg/PI*180<5)//相交小于5度,不切分已有路径
-				continue;
-
-			int id=v.add(cr,arg,v[ret[i][0]].sid0,v[ret[j][0]].sid0);
-			p0[i].push_back(id);
-			p0[j].push_back(id);
-		}
-
-		p0[i].push_back(ret[i][1]);
-
-		std::sort(p0[i].begin(),p0[i].end(),[&v](int i0,int i1){
-			return v[i0]<v[i1];
-		});
-
-		auto it=std::unique(p0[i].begin(),p0[i].end());
-		p0[i].erase(it,p0[i].end());
-
-		for(int j=1,cnt=p0[i].size();j<cnt;j++)
-			ret2.push_back(base_path(p0[i][j-1],p0[i][j]));
-	}
-
-	ret2.erase(std::remove_if(ret2.begin(),ret2.end(),[&v](base_path&p){
-		point&p0=v[p[0]];
-		point&p1=v[p[1]];
-
-		return p0.dist(p1)<0.1;
-	}),ret2.end());
-
-	std::sort(ret2.begin(),ret2.end());
-	ret2.erase(std::unique(ret2.begin(),ret2.end()),ret2.end());
-
-/*
-	ret.clear();
-	for(int i=0,len=ret2.size();i<len;i++)
-	{
-		std::vector<line_v> tmp;
-		tmp.push_back(ret2[i].as_line(v));
-		for(int j=0;j<len;j++)
-		{
-			if(i==j) continue;
-
-			if(ret[j].level(v)<ret[i].level(v))
-				continue;
-
-			line l1=ret2[j].as_line(v);
-		}
-	}
-
-	std::sort(ret2.begin(),ret2.end(),[&v](base_path&p1,base_path&p2){
-		return p1.arg(v)<p2.arg(v);
-	});
-	*/
-
-#ifdef __DEBUG__
-	std::sort(ret2.begin(),ret2.end(),[&v](const base_path&p1,const base_path&p2){
-		double arg=p1.arg(v)-p2.arg(v);
-
-		if(fabs(arg)<0.1)
-		{
-			return v[p1[0]]<v[p2[0]];
-		}
-
-		return arg<0;
-	});
-
-	log_path(ret2,v);
-#endif
-
-	return std::move(ret2);
-}
-
-
-
-#if 0
-struct ghash
-{
-	static std::tuple<int,int> decode(unsigned h)
-	{
-		const uint64_t S=0x8000000000000000;
-
-		int x=0,y=0;
-		for(int i=0;i<64;i++)
-		{
-			x<<=1;
-			y<<=1;
-
-			if(h&S) 
-				x|=1;
-			h<<=1;
-
-			if(h&S) 
-				y|=1;
-			h<<=1;
-		}
-
-		return std::make_tuple(x-2147483648,y-2147483648);
-	}
-
-	static uint64_t encode(int64_t x, int64_t y)
-	{
-		return encode_(x+2147483648,y+2147483648);
-	}
-
-public: //test
-	static void test_code(int64_t x,int64_t y)
-	{
-		uint64_t h=ghash::encode(x,y);
-		auto t=ghash::decode(h);
-
-		printf("src x=%X,y=%X hash=%X,check x=%X,y=%X\n",x,y,h,std::get<0>(t),std::get<1>(t));
-	}
-
-	static void test()
-	{
-		for(int i=0;i<10;i++)
-		{
-			test_code((4<<i)-1,(4<<i)-1);
-			test_code((4<<i)-1,(4<<i));
-			test_code((4<<i)-1,(4<<i)-1);
-			test_code((4<<i),(4<<i)-1);
-		}
-	}
-private:
-	static unsigned encode_(unsigned short x, unsigned short y)
-	{
-		const unsigned S=0x8000;
-		unsigned r=0;
-		for(int i=0;i<16;i++)
-		{
-			r<<=2;
-			if(x&S)
-			{
-				r|=(y&S)?3:2;
-			}
-			else
-			{
-				if(y&S) r|=1;
-			}
-
-			x<<=1;
-			y<<=1;
-		}
-		
-		return r;
-	}
-};
-#endif
-
-
-struct geolist
-{
-	std::unordered_map<uint64_t,int> geo2path;
-public:
-
-	static uint64_t encode(double x0,double y0)
-	{
-		uint64_t x=(uint32_t)(x0*10);
-		uint64_t y=(uint32_t)(y0*10);
-
-		return (x<<32)|y;
-	}
-
-	int find(double x,double y)const
-	{
-		uint64_t h=encode(x,y);
-
-		auto it=geo2path.find(h);
-
-		if(it==geo2path.end())
-			return -1;
-
-		return it->second;
-	}
-
-	void add(double x,double y,int id)
-	{
-		uint64_t h=encode(x,y);
-		geo2path.insert(std::make_pair(h,id));
-	}
-
-	int size()
-	{
-		return geo2path.size();
-	}
-
-	void print()
-	{
-		for(auto it=geo2path.begin();it!=geo2path.end();++it)
-		{
-			//std::cout<<it->first<<"\n";
-            printf("%ld\n",it->first);
-		}
-	}
-
-	geolist()
-	{
-	}
-
-	~geolist()
-	{
-	}
-};
-
-struct graph
-{
-	vertex_list v;
-	std::vector<std::vector<int>>  d;   //索引为起始顶点,数组内容为目标点
-	std::vector<std::array<int,2>> l;	//bast_path list
-	geolist geo;
-
-	graph()
-	{}
-
-	void init(const vertex_list&v_,const std::vector<base_path>&bp)
-	{
-		for(auto&p:bp)
-		{
-			int from=v.add(v_[p[0]]);
-			int to=v.add(v_[p[1]]);
-
-			l.push_back({from,to});
-
-			int id=l.size()-1;
-
-			line_v lv(v[from],v[to]);
-
-			printf("line:%s\n",lv.to_string().c_str());
-
-			double cos=lv.cos_k();
-			double sin=lv.sin_k();
-
-			double x,y;
-			for(double r=0,len=lv.length();r<len+0.1;r+=0.05)
-			{
-				x=lv[0].x+r*cos;
-				y=lv[0].y+r*sin;
-
-//				printf("x=%lf,y=%lf\n",x,y);
-
-				for(int i=-1;i<=1;i++)
-				for(int j=-1;j<=1;j++)
-				{
-					geo.add(x+i/10.,y+j/10.,id);
-				}
-			}
-
-			add(from,to);
-		}
-	}
-
-	std::vector<line_v>  find_possible_path(const point&from,double dist) const
-	{
-		std::vector<line_v> ret;
-
-		int start_pt_id=v.find(from,dist);
-		if(start_pt_id==-1)
-			return std::move(ret);
-
-		point start_pt=v[start_pt_id];
-
-		for(uint32_t i=0;i<d[start_pt_id].size();i++)
-		{
-			ret.push_back(line_v(start_pt,v[d[start_pt_id][i]]));
-		}
-
-		return std::move(ret);
-	}
-
-	void add(int from,int to)
-	{
-		if((int)d.size()<=from) d.resize(from+1);
-		if((int)d.size()<=to) d.resize(to+1);
-
-		d[from].push_back(to);
-		d[to].push_back(from);
-	}
-
-	bool find(std::vector<int>&ret,int from,std::array<int,2>&to,std::set<int>&ex,int level)
-	{
-		if(level--<0)
-			return false;
-
-		ret.push_back(from);
-
-		for(int p:d[from]) //在当前路径
-		{
-			if(ex.find(p)!=ex.end()) //找过
-				continue;
-
-			if(p==to[0]||p==to[1])//找到
-				return true;
-//			{
-//				ret.push_back(p);
-//				return true;
-//			}
-		}
-
-		ex.insert(from);
-
-		for(int p:d[from])//在下级路径
-		{
-			if(ex.find(p)!=ex.end())//找过
-				continue;
-			if(find(ret,p,to,ex,level)) //找到
-			{
-				return true;
-			}
-		}
-
-		ret.pop_back();
-		return false;
-	}
-
-	bool is_at_path(const point&pt)const
-	{
-		return geo.find(pt.x,pt.y)>=0;
-	}
-
-	std::vector<point> find(const point&from,const point&to)
-	{
-		int f=geo.find(from.x,from.y);
-		int t=geo.find(to.x,to.y);
-
-		if(f<0 || t<0 || f==t)
-			return {};
-#if 0
-		std::vector<point> rc[2];
-		for(int i=0;i<2;i++)
-		{
-			std::vector<int> ret;
-			std::set<int> ex({l[f][1-i]});
-			if(find(ret,l[f][i],l[t],ex,2))
-			{
-				for(auto id:ret)
-					rc[i].push_back(v[id]);
-			}
-		}
-		if(!rc[0].empty() && (rc[1].empty() || rc[0].size() < rc[1].size()))
-			return std::move(rc[0]);
-		else if(!rc[1].empty())
-			return std::move(rc[1]);
-#endif
-		std::vector<int> ret;
-		int size=v.size();
-		std::vector<double> mat(size+1,-1);
-		std::vector<double> trace(size+1,-1);
-		std::vector<bool> val(size+2,false);
-		mat[l[t][0]]=to.dist(v[l[t][0]]);
-		mat[l[t][1]]=to.dist(v[l[t][1]]);
-		int f0=l[f][0],f1=l[f][1];
-		for(int i=0;i<2;i++)
-		{
-			if(mat[f0]!=-1 && mat[f1]!=-1)
-				break;
-			for(int j=0;j<size;j++)
-				if(mat[j]!=-1)val[j]=true;
-			for(int j=0;j<size;j++)
-			{
-				if(val[j]==false)continue;
-				for(unsigned int k=0;k<d[j].size();k++)
-				{
-					double dist=v[j].dist(v[d[j][k]]);
-					if(mat[d[j][k]]==-1 || mat[j]+dist < mat[d[j][k]])
-					{
-						mat[d[j][k]] = mat[j]+dist;
-						trace[d[j][k]] = j;
-					}
-				}
-			}
-		}
-		mat[f0]=mat[f0]+from.dist(v[l[f][0]]);
-		mat[f1]=mat[f1]+from.dist(v[l[f][1]]);
-		std::vector<point> rc;
-		if(mat[f0]!=-1 && (mat[f1]==-1 || mat[f0] < mat[f1]))
-		{
-			int temp=f0;
-			while(temp!=-1)
-			{
-				rc.push_back(v[temp]);
-				temp=trace[temp];
-			}
-			return std::move(rc);
-		}
-		else if(mat[f1]!=-1)
-		{
-			int temp=f1;
-			while(temp!=-1)
-			{
-				rc.push_back(v[temp]);
-				temp=trace[temp];
-			}
-			return std::move(rc);
-		}
-		return {};
-	}
-};
-
-
-std::atomic<int> g_init_flag(0);
-graph g_graph;
-
-}//namespace
-
-void card_path::init(const sit_list&sites)
-{
-    //Ensure only ont thread can init path.
-	int expect=0;
-	if(g_init_flag.compare_exchange_strong(expect,1))
-	{
-		vertex_list v_list;
-		v_list.add(point(0,0),0,-1);
-		//std::vector<base_path> opath=init_path(sites,v_list);
-		handle_path hp;
-		card_list::instance()->accept(hp);
-
-		g_graph.init(v_list,opath);
-
-		++g_init_flag;
-	}
-    //if != 2 then wait here until init over.
-	while(g_init_flag.load()!=2)
-	{
-		std::this_thread::sleep_for (std::chrono::seconds(1));
-	}
-}
-
-
-card_path&card_path::inst()
-{
-	static card_path path;
-	return path;
-}
-
-std::vector<point> card_path::find_path(const point&from,const point&to)const
-{
-	return g_graph.find(from,to);
-}
-
-bool card_path::is_at_path(const point&pt)const
-{
-	return g_graph.is_at_path(pt);
-}
-
-std::vector<line_v>  card_path::find_possible_path(const point&from,double dist) const
-{
-	return std::move(g_graph.find_possible_path(from,dist));
-}
-
-#ifdef __DEBUG__
-
-void test_at_path(card_path&cp,const point&pt)
-{
-	if(cp.is_at_path(pt))
-		printf("test (%.3lf,%.3lf) is-at-path:true\n",pt.x,pt.y);
-	else
-		printf("test (%.3lf,%.3lf) is-at-path:false\n",pt.x,pt.y);
-}
-
-void test_find_path(card_path&cp,const point&p1,const point&p2)
-{
-	printf("\nfind-path:  from=(%.3lf,%.3lf),to=(%.3lf,%.3lf)\n",p1.x,p1.y,p2.x,p2.y);
-	std::vector<point> rc=cp.find_path(p1,p2);
-	for(uint32_t i=0;i<rc.size();i++)
-		printf("x=%.3lf,y=%.3lf\n",rc[i].x,rc[i].y);
-}
-
-void test_find_poss_path(const card_path&cp ,const point&from)
-{
-	printf("\nfind-poss_path:  from=(%.3lf,%.3lf)\n",from.x,from.y);
-	std::vector<line_v> rc=cp.find_possible_path(from,3);
-	for(uint32_t i=0;i<rc.size();i++)
-	{
-		printf("poss path from=(%.3lf,%.3lf) to=(%.3lf,%.3lf)\n", rc[i][0].x,rc[i][0].y, rc[i][1].x,rc[i][1].y);
-	}
-}
-
-int main()
-{
-	std::unique_ptr<sit_list> sites(new sit_list());
-	sites->load("data_reader_antenna.txt","path_tof.txt");
-
-	card_path cp;
-
-	cp.init(*sites);
-#if 0
-	{
-		test_at_path(cp,point(4773.104654,-104.0887));
-
-		test_at_path(cp,point(4727,-74.8));
-		test_at_path(cp,point(4727,-75.0));
-		test_at_path(cp,point(4727,-75.2));
-		test_at_path(cp,point(4727,-75.8));
-		test_at_path(cp,point(4727,-90));
-		test_at_path(cp,point(4727,-89.6));
-		test_at_path(cp,point(4727,-89.8));
-		test_at_path(cp,point(4727,-90));
-		test_at_path(cp,point(4727,-90.2));
-		test_at_path(cp,point(4727,-90.4));
-	}
-#endif
-	//test_at_path(cp,point(4726.90,376.85));
-	test_find_path(cp,point(-227.6,174.9),point(-201.3,175.5));
-	test_find_path(cp,point(-227.625219,174.945670),point(-170.085722,176.101574));
-	test_find_path(cp,point(-393.1944,262.5324),point(-366.0754,274.1253));
-	//test_find_path(cp,point(4637.000000,-75),point(4727,135));
-#if 1
-	{
-		test_find_path(cp,point(4637.000000,-75),point(4727,135));
-		test_find_path(cp,point(4637.000000,-75),point(4727,120));
-		test_find_path(cp,point(4700,-75),point(4727,120));
-		test_find_path(cp,point(4725,-75),point(4727,135));
-		test_find_path(cp,point(4727,-89.7),point(6144.3,-523));
-	}
-#endif
-#if 0
-	{
-		test_find_poss_path(cp, point(4727,-89));
-		test_find_poss_path(cp, point(4727,-90));
-
-		test_find_poss_path(cp, point(4724,-75));
-		test_find_poss_path(cp, point(4725,-75));
-		test_find_poss_path(cp, point(4726,-75));
-		test_find_poss_path(cp, point(4727,-75));
-		test_find_poss_path(cp, point(4728,-75));
-		test_find_poss_path(cp, point(4727,-7));
-
-		test_find_poss_path(cp, point(4726.6,33));
-	}
-#endif
-	return 0;
-}
-#endif
-

+ 1 - 1
card_person.cpp

@@ -113,7 +113,7 @@ void person::handle_three_rates(const point & pt)
 	cp.work_line=m_workLine;
 	m_biz_stat=get_stat();
 	cp.biz_stat = m_biz_stat;
-	cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;	
+	cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
 	const auto lm = m_area_tool->getLandmark();
 //	cp.enter_time = std::get<0>(lm)*1000;
 //	cp.area_id = std::get<3>(lm);

+ 1 - 0
common_tool.h

@@ -83,6 +83,7 @@ public:
 		uint32_t cid = id & (~(type<<32));
 		return type_id_to_str(type,cid);
 	}
+
 	static uint64_t card_id_to_u64(const std::string & cardid)
 	{
 		return type_id_to_u64(card_id_to_type(cardid),card_id_to_id(cardid));

+ 5 - 2
event.h

@@ -34,11 +34,14 @@ enum OBJECT_TYPE
 };
 
 enum EVENT_TYPE{ // 事件类型
+    ET_OVER_COUNT_PERSON = 1,       // 井下人员超员
+    ET_OVER_COUNT_VEHICLE = 2,      // 井下车辆超员
     ET_AREA_OVER_COUNT_PERSON = 3,	// 区域人员超员
     ET_AREA_OVER_COUNT_VEHICLE = 4,	// 区域车辆超员
     ET_READER_ERROR = 6,
     ET_CARD_LOW_POWER_SERIOUS = 12, // 电量极低
-
+    ET_CARD_OVER_TIME_PERSON = 13, // 人员井下超时
+    ET_CARD_OVER_TIME_VEHICLE = 14, // 车辆井下超时
     ET_CARD_AREA_OVER_TIME_PERSON = 15, // 人员区域超时
     ET_CARD_AREA_OVER_TIME_VEHICLE = 16, // 车辆区域超时
 
@@ -49,7 +52,7 @@ enum EVENT_TYPE{ // 事件类型
     ET_CARD_HELP = 24, // 人员呼救
 
     ET_CARD_MOTIONLESS=32,//静止不动告警
-
+    ET_READER_POWER_BY_BATTERY=33,//分站电池:1为电池供电,0为交流电供电,当电池供电需要告警
     ET_VEHICLE_NEAR_GEOFAULT=38,//靠近断层告警
 
     CARD_EVENT_COUNT_MAX

+ 4 - 1
main.cpp

@@ -56,7 +56,10 @@ struct Init_Setting
         std_info("here....");
         area_list::instance()->init_from_db();
         std_info("here....");
-	
+        //test
+        //point pt(3348,100);
+        //int id = area_list::instance()->get_area(pt)->id();
+        //std_info("test area:%d",id);
         Landmark_list::instance()->init_from_db();
 
         //auto a = Landmark_list::instance()->get(5,id,pt);

+ 8 - 0
message.h

@@ -5,6 +5,14 @@
 
 struct zistream;
 
+#define CHAR_LOCATEDATA_TOF_EXTEND 0x843b			// TOF实时定位数据,请求、应答
+#define CHAR_LOCATEDATAHIS_TOF_EXTEND 0x853b		// TOF历史定位数据,请求、应答
+#define CHAR_LOCATEDATA_TDOA_EXTEND 0x863b			// TDOA实时定位数据,请求、应答
+#define CHAR_LOCATEDATAHIS_TDOA_EXTEND 0x873b		// TDOA历史定位数据,请求、应答
+#define CHAR_TDOA_READER_SYNC_TIME 0xa78d			// TDOA分站时间同步
+#define CHAR_ADHOC	0x803b							// 上传自组网数据
+#define CHAR_CTRL_READER_CMD 0x804c					// 向分站发送控制指令,控制分站向上位机发送数据
+
 //	分站传上来的卡定位数据,包括tof,tdoa
 struct message_locinfo
 {

+ 0 - 1
mine.cpp

@@ -1,7 +1,6 @@
 #include "mine.h"
 #include "common_tool.h"
 #include"tool_time.h"
-#include "mine_module/MineCardManager.h"
 
 void mine_tool::on_point(uint32_t card_id, int32_t type, int vehicle_category_id)
 {

+ 0 - 2
mine_business.cpp

@@ -7,14 +7,12 @@
 #include "mine_business.h"
 #include "log.h"
 #include "point.h"
-#include "db/db_api/CDBConnPool.h"
 #include "db/db_api/CDBSingletonDefine.h"
 #include "db/db_tool.h"
 #include "common_tool.h"
 #include "ant.h"
 #include "ya_setting.h"
 #include "card_path.h"
-#include "card_base.h"
 #include "card.h"
 struct card_sensor
 {

+ 0 - 197
mine_module/MineCardManager.cpp

@@ -1,197 +0,0 @@
-#include "MineCardManager.h"
-#include "ya_setting.h"
-#include "common_tool.h"
-#include "mine.h"
-
-CMineCardManager::CMineCardManager()
-{
-    m_minecards = std::make_shared<mine_card_info>();
-}
-
-std::shared_ptr<mine_card_info> CMineCardManager::GetMineCards() 
-{
-    return m_minecards;
-}
-
- /**
-     * @brief 获取事件ID
-     **/
-bool CMineCardManager::Exist(SET_CARDID &list,uint64_t id)
-{
-    if (list.find(id) == list.end())
-    {
-        return false;
-    }
-    return true;
-}
-
-bool CMineCardManager::Exist(SET_CARDID &list,int card_id,int card_type)
-{
-    return Exist(list,tool_other::type_id_to_u64(card_type,card_id));
-}
-/**
- * @brief 人员下井
- * @param card 卡
- **/
-void CMineCardManager::OnPersonDown(std::shared_ptr<card> card,bool bInit/* = false*/)
-{
-    if (nullptr == card)
-    {
-        return ;
-    }
-     //设置卡的状态
-    card->m_is_attendance = EAttendanceState::MineDown;
-   
-    uint64_t key = tool_other::type_id_to_u64(card->m_id,card->m_type);
-    if (this->Exist(m_minecards->m_down_person,key))
-    {
-        return ;
-    }   
-     //移除升井中的状态
-    m_minecards->m_up_person.erase(key);
-    //加入到井下列表中
-    m_minecards->m_down_person.insert(key);
-    if(!bInit)
-    {
-        //井下超员判断
-        this->OnPersonOvercrowdingWarning();
-    }
-}
-    /**
- * @brief 人员升井
- * @param card 卡
- **/
-void CMineCardManager::OnPersonUp(std::shared_ptr<card> card)
-{
-    if (nullptr == card)
-    {
-        return ;
-    }
-    card->m_is_attendance = EAttendanceState::MineUp;
-    uint64_t key = tool_other::type_id_to_u64(card->m_id,card->m_type);
-    if (this->Exist(m_minecards->m_up_person,key))
-    {
-        return ;
-    }   
-     //移除井下列表
-    m_minecards->m_down_person.erase(key);
-    //加入到升井列表中
-    m_minecards->m_up_person.insert(key);
-    
-    int max_person = CYaSetting::m_sys_setting.over_count_person;
-    //井下超员判断--取消
-    if (max_person != 0 && (int)m_minecards->m_down_person.size() < max_person )
-    {
-        //this->CancelEvent(EVENT_TYPE::ET_OVER_COUNT_PERSON,(int)m_minecards->m_down_person.size());
-    }
-    
-}
-
-/**
- * @brief 人员超员警告
-**/
-void CMineCardManager::OnPersonOvercrowdingWarning()
-{
-  //  int max_person = CYaSetting::m_sys_setting.over_count_person;
-  //  //井下超员判断
-  //  if (max_person != 0 && (int)m_minecards->m_down_person.size() > max_person )
-  //  {
-  //      std::string log = "";
-  //      for (uint64_t id : m_minecards->m_down_person)
-  //      {
-  //          std::shared_ptr<card_location_base> pitcard = card_list::instance()->get(id);
-  //          if (nullptr != pitcard)
-  //          {
-  //              log += tool_other::type_id_to_str(pitcard->m_type,pitcard->m_id);
-  //              log += "&";
-  //          }
-  //      }
-  //      //打印日志
-  //      log_info("[lemon mp_card_list_down_person:]:%s",log.c_str());
-
-  //      this->StartEvent(EVENT_TYPE::ET_OVER_COUNT_PERSON,max_person,(int)m_minecards->m_down_person.size());
-  //  }
-}
-
-/**
-* @brief 人员井下超时
-**/
-void CMineCardManager::OnPersonInMineOverTime(int card_id,int card_type)
-{
-  //  std::shared_ptr<card_location_base> card = card_list::instance()->get(tool_other::type_id_to_u64(card_type, card_id));
-  //  if (nullptr == card)
-  //  {
-  //      return ;
-  //  }
-
-  //  std::shared_ptr<mine_tool> mine = card->get_mine_tool();
-  //  if(nullptr == mine )
-  //  {
-  //      return ;
-  //  }
-
-  //  int sec= tool_time::to_ms(std::chrono::system_clock::now()) - mine->get_work_time();
-  //  if (!mine->m_is_overtime && sec > (int)CYaSetting::m_sys_setting.over_time_person)
-  //  {
-  //      //人员超时
-  //      mine->m_is_overtime = true;
-  //      mine->m_overtime = std::chrono::system_clock::now();
-  //  }
-  //  else if (mine->m_is_overtime && sec < (int)CYaSetting::m_sys_setting.over_time_person)
-  //  {
-  //      mine->m_is_overtime = false;
-  //      mine->m_overtime = std::chrono::system_clock::now();
-  //  }
-  //  else
-  //  {
-  //      return ;
-  //  }
-
-  //  // 发送警告
-  //  event_ptr evPtr = event_list::instance()->get_event_card(card->m_id,card->m_type,ET_CARD_OVER_TIME_PERSON);
-  //  if (nullptr == evPtr)
-  //  {
-  //      event_ptr evPtr = event_list::create_event_card(card->m_id, card->m_type, ET_CARD_OVER_TIME_PERSON);
-  //      event_list::instance()->copy_event(card, evPtr);
-  //      event_list::instance()->add(evPtr->get_list_id(), evPtr);
-  //  }
-  //  evPtr->m_limit_value = 0;
-  //  evPtr->m_cur_value = 0;
-  //  evPtr->m_is_display = false;
-  //  evPtr->m_status = mine->m_is_overtime ? ES_START : ES_END;
-  //  evPtr->m_cur_time = std::chrono::system_clock::now();
-
-  //  event_list::save_event(evPtr);
-
-  //  log_info("OnPersonInMineOverTime: send Event=ET_CARD_OVER_TIME_PERSON card=id,eventState=%d",card->m_id,evPtr->m_status);
-}
-    /**
- * @brief 车下井
- * @param card 卡
- **/
-void CMineCardManager::OnVehicleDown(std::shared_ptr<card> card,bool bInit/* = false*/)
-{
-    if (nullptr == card)
-    {
-        return ;
-    }
-}
-    /**
- * @brief 车升井
- * @param card 卡
- **/
-void CMineCardManager::OnVehicleUp(std::shared_ptr<card> card)
-{
-    if (nullptr == card)
-    {
-        return ;
-    }
-}
-
- /**
- * @brief 车辆超员警告
- **/
-void CMineCardManager::OnVehicleOvercrowdingWarning()
-{
-
-}

+ 0 - 90
mine_module/MineCardManager.h

@@ -1,90 +0,0 @@
-/*
-** 井中卡的数据:人员下井 ,人员升进,车下井升井数据
-** 对应的操作,井下人员超时,井下超员等
-*/
-#ifndef __MINECARDMANAGER_H
-#define __MINECARDMANAGER_H
-
-#include "minestruct.h"
-#include "card.h"
-
-//井下警告类型数量
-#define MAX_MINE_EVENT_NUM 3
-
-class CMineCardManager 
-{
-private:
-    CMineCardManager();
-
-private:
-    std::shared_ptr<mine_card_info> m_minecards;
-
-    //井下警告列表ID(下标为实践类型)
-    uint64_t m_evlist[MAX_MINE_EVENT_NUM];
-private:
-    /**
-     * @brief 获取事件ID
-     **/
-    uint64_t GetMineEventId(int evType);
-    /**
-     * @brief 判断是否已存在
-     **/
-    bool Exist(SET_CARDID &list,uint64_t id);
-    bool Exist(SET_CARDID &list,int card_id,int card_type);
-     /**
-     * @brief 创建警告事件
-     * @param evType 警告类型
-     * @param limitVal 限制数据(阀门值)
-     * @param curVal 当前数据
-     **/
-    void StartEvent(int evType,int limitVal,int curVal);
-    /**
-     * @brief 取消警告事件
-     * @param evType 警告类型
-     * @param curVal 当前数据
-     **/
-    void CancelEvent(int evType,int curVal);
-public:
-    //TODO: 获取信息
-    std::shared_ptr<mine_card_info> GetMineCards() ;
-    /**
-     * @brief 人员下井,超员警告
-     * @param card 卡
-     * @param bInit 是否初始化(程序启动加载井下人员)
-     **/
-    void OnPersonDown(std::shared_ptr<card> card,bool bInit = false);
-     /**
-     * @brief 人员升井,取消超员警告
-     * @param card 卡
-     **/
-    void OnPersonUp(std::shared_ptr<card> card);
-     /**
-     * @brief 人员超员警告
-     **/
-    void OnPersonOvercrowdingWarning();
-
-    /**
-     * @brief 人员井下超时
-     **/
-    void OnPersonInMineOverTime(int card_id,int card_type);
-public:
-     /**
-     * @brief 车下井 ,车辆超员警告
-     * @param card 卡
-     * @param bInit 是否初始化(程序启动加载井下车辆)
-     **/
-    void OnVehicleDown(std::shared_ptr<card> card,bool bInit = false);
-     /**
-     * @brief 车升井,车辆超员警告取消
-     * @param card 卡
-     **/
-    void OnVehicleUp(std::shared_ptr<card> card);
-    /**
-     * @brief 车辆超员警告
-     **/
-    void OnVehicleOvercrowdingWarning();
-
-
-};
-
-#endif //__MINECARDMANAGER_H

+ 0 - 16
mine_module/minestruct.h

@@ -1,16 +0,0 @@
-#pragma once
-
-#include <set>
-#include <stdint.h>
-
-// 卡在card_list的掩码由
-typedef std::set<uint64_t> SET_CARDID;
-
-struct mine_card_info
-{
-    SET_CARDID m_down_vehicle; // 井下车辆
-    SET_CARDID m_up_vehicle; // 升井车辆
-	SET_CARDID m_down_person;  // 井下人员
-	SET_CARDID m_up_person; // 升井人员
-	SET_CARDID m_down_adhoc;   //井下自组网卡
-};

+ 80 - 5
module_service/area_business_count_checker.cpp

@@ -1,6 +1,8 @@
 #include "area.h"
 #include "card_base.h"
-
+#include "common_tool.h"
+#include "log.h"
+#include "event.h"
 #include "area_business_count_checker.h"
 /*
 	判断当前区域a中的人数是否超过设定人数,超过后告警
@@ -11,8 +13,42 @@
 void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 						const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
 {
-
-
+    if (nullptr == a->m_area)
+    {
+        return ;
+    }
+	EVENT_TYPE ev = EVENT_TYPE::ET_OVER_COUNT_PERSON;
+	int limitVal = 0;
+	int curVal = 0;
+	//uint64_t key = tool_other::type_id_to_u64(c->m_id,c->m_type);
+	if (c->is_person())
+	{
+		a->m_area->m_person_count ++ ;
+		limitVal = a->m_area->m_limit_person_count;
+		curVal = a->m_area->m_person_count;
+		ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
+	}
+	else if (c->is_vehicle())
+	{
+		a->m_area->m_vehicle_count ++ ;
+		limitVal = a->m_area->m_limit_vehicle_count;
+		curVal = a->m_area->m_vehicle_count;
+		ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
+	}
+	if(curVal > limitVal)
+	{
+		if (c->is_vehicle())
+		{
+			a->m_area->m_event_vehicle_count = true;
+		}
+		else
+		{
+			a->m_area->m_event_person_count = true;
+		}
+		event_tool::instance()->handle_event(a->m_area->is_mine()? OT_MINE : OT_AREA,ev,a->m_area->id(),limitVal,curVal,true);
+		log_info("area_business_count_checker::on_enter : Event OVER_COUNT=%d AreaId=%d,Limit=%d,CurNum=%d"
+		            ,ev,a->m_area->id(),limitVal,curVal);
+	}
 }
 
 void area_business_count_checker::on_hover(const std::shared_ptr<area_hover>&a,
@@ -26,7 +62,46 @@ void area_business_count_checker::on_hover(const std::shared_ptr<area_hover>&a,
 void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
 						const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 {
-
-
+    if (nullptr == a->m_area)
+    {
+        return ;
+    }
+	int limitVal = 0;
+	int curVal = 0;
+	bool tmp_event = false;
+	EVENT_TYPE ev = EVENT_TYPE::ET_OVER_COUNT_PERSON;
+	if (c->is_person())
+	{
+		a->m_area->m_person_count -- ;
+		limitVal = a->m_area->m_limit_person_count;
+		curVal = a->m_area->m_person_count;
+		tmp_event = a->m_area->m_event_person_count;
+		ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
+	}
+	else if (c->is_vehicle())
+	{
+		a->m_area->m_vehicle_count -- ;
+		limitVal = a->m_area->m_limit_vehicle_count;
+		curVal = a->m_area->m_vehicle_count;
+		tmp_event = a->m_area->m_event_vehicle_count;
+		ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
+	}
+	else{
+		return ;
+	}
+	if(tmp_event && curVal < limitVal)
+	{
+		if (c->is_vehicle())
+		{
+			a->m_area->m_event_vehicle_count = false;
+		}
+		else
+		{
+			a->m_area->m_event_person_count = false;
+		}
+        log_info("area_business_count_checker::on_leave :Cancel Event OVER_COUNT=%d AreaId=%d,Limit=%d,CurNum=%d"
+        ,ev,a->m_area->id(),limitVal,curVal);
+		event_tool::instance()->handle_event(a->m_area->is_mine()? OT_MINE : OT_AREA,ev,a->m_area->id(),limitVal,curVal,false);
+	}
 }
 

+ 7 - 0
module_service/area_business_forbid.cpp

@@ -5,6 +5,7 @@
 #include"common_tool.h"
 #include"area.h"
 #include "card.h"
+#include "module_call.h"
 
 struct forbid_data:business_data
 {
@@ -29,6 +30,9 @@ void area_business_forbid::on_enter(const std::shared_ptr<area_hover>&a,
 
     uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
     event_tool::instance()->handle_event(OT_CARD, ev_type, id, 0, 0, true);
+
+    //呼叫
+    module_call::instance()->system_call_apoint(card_ptr->m_id,card_ptr->m_type);
 }
 
 void area_business_forbid::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
@@ -48,6 +52,9 @@ void area_business_forbid::on_leave(const std::shared_ptr<area_hover>&a,
 
     uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
     event_tool::instance()->handle_event(OT_CARD, ev_type, id, 0, 0, false);
+
+    //取消呼叫
+    module_call::instance()->system_cancel_call_apoint(card_ptr->m_id,card_ptr->m_type);
 }
 
 

+ 61 - 6
module_service/area_business_person_dwell_checker.cpp

@@ -1,7 +1,9 @@
 
 #include "area.h"
 #include "card_base.h"
-
+#include "event.h"
+#include "tool_time.h"
+#include "common_tool.h"
 #include "area_business_person_dwell_checker.h"
 /*
 	判断当前区域a中的人卡停留时间
@@ -9,13 +11,25 @@
 	人员&车辆的代码重用,请自行设计
 */
 
+struct SPersonDwellChecker : business_data
+{
+    uint64_t m_enter_time;
+    point m_enter_point;
+    SPersonDwellChecker()
+    {
+        m_enter_time = 0;
+    }
+};
 
 //进入区域,记录进入时间
 void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hover>&a,
 							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
 {
 
-
+    auto ptr_temp = std::make_shared<SPersonDwellChecker>();
+    ptr_temp->m_enter_point.set(c->x,c->y,c->z);
+    ptr_temp->m_enter_time = tool_time::now_to_ms();
+    ptr = ptr_temp;
 }
 
 
@@ -23,8 +37,33 @@ void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hov
 void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hover>&a,
 							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 {
-
-
+    auto ptr_temp = static_cast<SPersonDwellChecker*>(ptr.get());
+    if(nullptr == ptr_temp)
+    {
+        return ;
+    }
+	double limit_val = 0;
+	double cur_val = (tool_time::now_to_ms() - ptr_temp->m_enter_time)/1000;
+	EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
+	if(c->is_person())
+    {
+	    if (a->m_area->m_limit_person_second > cur_val)
+        {
+	        return;
+        }
+	    evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
+	    limit_val = a->m_area->m_limit_person_second;
+    }
+	else if (c->is_vehicle())
+    {
+	    return ;
+    }
+	else
+    {
+        return;
+    }
+    uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
+    event_tool::instance()->handle_event(OT_CARD,evType,id,limit_val,cur_val,true);
 }
 
 
@@ -32,7 +71,23 @@ void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hov
 void area_business_person_dwell_checker::on_leave(const std::shared_ptr<area_hover>&a,
 							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 {
-
-
+    auto ptr_temp = static_cast<SPersonDwellChecker*>(ptr.get());
+    if(nullptr == ptr_temp)
+    {
+        return ;
+    }
+    ptr_temp->m_enter_point.set(c->x,c->y,c->z);
+    ptr_temp->m_enter_time = tool_time::now_to_ms();
+    EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
+    if(c->is_person())
+    {
+        evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
+    }
+    else
+    {
+        return ;
+    }
+    uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
+    event_tool::instance()->handle_event(OT_CARD,evType,id,0,0,false);
 }
 

+ 9 - 6
net-service.cpp

@@ -45,7 +45,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 	is>>skip(2)>>cmd;
 	switch(cmd)
 	{
-		case 0x843b://tof
+		case CHAR_LOCATEDATA_TOF_EXTEND://tof-扩展
 			{
 				uint32_t site_id;
 				uint8_t  power;
@@ -72,6 +72,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 					m.load(is,false);
 					m.m_time_stamp=tstamp;
 					m.m_site_id=site_id;
+					//t_site->m_site_data = 0;
 
 					t->m_cmd_code=cmd;
 					t->m_hash_id=m.m_card_id;
@@ -81,7 +82,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 				}
 			}
 			break;
-		case 0x863b://tdoa
+		case CHAR_LOCATEDATA_TDOA_EXTEND://tdoa
 			{
 				uint32_t site_id;
 				is>>site_id>>skip(12);
@@ -98,7 +99,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 				}
 			}
 			break;
-		case 0xa78d://time sync
+		case CHAR_TDOA_READER_SYNC_TIME://time sync
 			{
 				message_tdoasync m;
 				m.load(is);
@@ -106,10 +107,12 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 			}
 			//site_message::on_sync(this,t.m_param1);
 			break;
-		case 0x853b://tof his
-		case 0x873b://tdoa his
+		case CHAR_LOCATEDATAHIS_TOF_EXTEND://tof his
+		case CHAR_LOCATEDATAHIS_TDOA_EXTEND://tdoa his
 			break;
-		case 0x804c://ctrl site message
+		case CHAR_CTRL_READER_CMD://ctrl site message
+			break;
+		case CHAR_ADHOC://自组网数据
 			break;
 	}
 }

+ 2 - 2
worker.cpp

@@ -106,14 +106,14 @@ struct worker_thread: zloop<task*> ,visitor<std::shared_ptr<card_location_base>>
 			case 0x843b://tof
 			case 0x863b://tdoa
 				log_info("card loc message%04X",t.m_cmd_code);
-
 				card_list::instance()->on_message(this,t.body<message_locinfo>(),false);
+
 				//card_message::on_loc_message(this,t.m_param1);
 			break;
 			case 0x853b://tof his
 			case 0x873b://tdoa his
 				log_info("site history message%04X",t.m_cmd_code);
-				card_list::instance()->on_message(this,t.body<message_locinfo>(),true);
+					card_list::instance()->on_message(this,t.body<message_locinfo>(),true);
 				//site_message::on_sync(this,t.m_param1);
 			break;
 

+ 1 - 0
ya_setting.cpp

@@ -27,6 +27,7 @@ bool CYaSetting::Init_sys_setting()
 			log_info("init_setting:%s,%s",N,val.c_str());\
 			K = atoi(val.c_str())*X;}\
 
+
 			D_GetValue(m_sys_setting.over_count_person,"over_count_person",1,"人员井下超员")
 			D_GetValue(m_sys_setting.over_count_vehicle,"over_count_vehicle",1,"车辆井下超员")
 			D_GetValue(m_sys_setting.over_time_person,"over_time_person",60,"人员井下超时")