Browse Source

将区域相关的业务结构进行了调整,接口基本梳理完成,设想如下:

区域相关的逻辑:

1、每个区域加载为area对象,或者它的子类对象,所有区域对象存储于area_list单例
2、区域可以归属不同的业务类型
	-进入退出记录:定位卡进入、退出某一区域时,记录到日志和数据库
	-定位卡位置:推送人员/车辆位置区域,需唯一,可选择优先级
	-超时:进入区域超过区域规定时间
	-超员:进入区域的人员数量超过区域规定数量
	-超速:定位卡在该区域移动的速度在设定时间内大于该区域给定值
	-人员考勤:进入再离开井下分站覆盖范围,记录一次考勤
	-车辆考勤:离开再进入一次该类型的区域,且时间大于设定时间,记录一次考勤
	-禁区:人/车进入区域进行告警
3、特殊区域
	-井下区域,井下分站收到卡信息的区域
	-井上区域,井上分站收到卡信息的区域
	-用户自定义区域,用户设定的多边形区域

	4、区域表
		-业务类型:(bit)
			1:位置[优先级]
			2:超时[超时时间分钟数]
			3:超员[人员数量、车辆数量]
			4:超速[超速值、判断策略]
			5:人员考勤
			6:车辆考勤[离开最小,离开最小距离]
			7:禁区[进入时长]
			8:猴车区域
		-基本类型:(enum)
			1:井上
			2:井下
			3:自定义多边形
	-多边形定义
	-附加属性
	注:有些业务同时涉及到人员或车辆,具体如何处理,可以各部分处理。
zzj 6 years ago
parent
commit
5056e94235
26 changed files with 366 additions and 99 deletions
  1. 4 1
      Makefile.am
  2. 1 1
      ant.h
  3. 27 29
      area.cpp
  4. 65 35
      area.h
  5. 3 0
      area_beh.h
  6. 157 0
      area_business.cpp
  7. 16 0
      area_business.h
  8. 1 1
      card_base.cpp
  9. 4 2
      card_base.h
  10. 4 2
      card_car.cpp
  11. 2 1
      card_car.h
  12. 2 2
      card_message_handle.cpp
  13. 2 2
      card_person.cpp
  14. 1 2
      card_person.h
  15. 2 0
      db/Makefile.am
  16. 3 3
      db/db_card.cpp
  17. 9 2
      db/db_tool.cpp
  18. 3 5
      loc_message.h
  19. 2 2
      loc_point.cpp
  20. 8 7
      loc_tool.cpp
  21. 4 0
      monkey_car/monkeycar_area.h
  22. 1 1
      select_tool.cpp
  23. 7 0
      select_tool.h
  24. 1 1
      tool_time.h
  25. 2 0
      websocket/Makefile.am
  26. 35 0
      zexception.h

+ 4 - 1
Makefile.am

@@ -9,7 +9,10 @@ SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp card_area.cpp card_base.c
     	  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 ya_event.cpp znet.cpp
+		  web-client.cpp worker.cpp ya_event.cpp znet.cpp area_business.cpp
+
+
+CXXFLAGS=-g
 
 AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN)
 

+ 1 - 1
ant.h

@@ -104,7 +104,7 @@ struct ant :point
 
 };
 
-struct site:point
+struct site:point,std::enable_shared_from_this<site>
 {
     static algo_config g_config[];
     int      m_algo;			//TOF:0,TDOA:1

+ 27 - 29
area.cpp

@@ -7,6 +7,7 @@
 #include "point.h"
 #include "monkey_car/monkeycar_area.h"
 #include "landmark.h"
+#include "area_business.h"
 
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/classification.hpp>
@@ -16,30 +17,26 @@
 template<> std::shared_ptr<area_list> 
 single_base<area_list, int, std::shared_ptr<area>>::m_instance=std::make_shared<area_list>();
 
-void area::on_hover(uint32_t card_id,std::shared_ptr<area_hover>&c,double speed,int32_t type)
- {
- 	//check超时
-	log_info("on_hover..%d  areaId:%d",card_id,m_id);
-// 	time_t now = time(NULL);
-// 	if(now-c->m_enter_time>m_limit_time_second && !c->m_is_over_time)
-// 	{
-// 		c->m_is_over_time=true;
-// 		//产生告警
-// 	}
-    module_area::on_hover(card_id,c,type);
- }
-
-void area::on_enter(uint32_t card_id,std::shared_ptr<area_hover>&c,double speed,int32_t type)
+void area::on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
 {
-	log_info("on_enter..%d  areaId:%d",card_id,m_id);
-    module_area::on_enter(card_id,c,type);
+ 	for(auto i:m_area_business_list)
+		i->on_hover(a,c);
 }
 
-void area::on_leave(uint32_t card_id,std::shared_ptr<area_hover>&c,double speed,int32_t type)
+void area::on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
 {
-	log_info("on_leave..%d  areaId:%d",card_id,m_id);
-    module_area::on_leave(card_id,c,type);
+	log_info("on_enter..%d  areaId:%d",c->m_id,m_id);
+ 	for(auto i:m_area_business_list)
+		i->on_enter(a,c);
 }
+
+void area::on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+{
+	log_info("on_leave..%d  areaId:%d",c->m_id,m_id);
+ 	for(auto i:m_area_business_list)
+		i->on_leave(a,c);
+}
+
 bool area::in_area(const point & p)
 {
 	if(m_bound.empty())
@@ -477,6 +474,7 @@ std::vector<point> area_list::init_path(std::string &str)
 	}
 	return std::move(vp);
 }
+
 std::shared_ptr<area> area_list::get_area(const point&pt)
 {
 	std::shared_ptr<area> ret=nullptr;
@@ -492,15 +490,14 @@ std::shared_ptr<area> area_list::get_area(const point&pt)
 	return ret;
 }
 
-
-void area_tool::on_point(uint32_t card_id,const point&pt,double speed,int16_t type)
+void area_tool::on_point(const std::shared_ptr<site>&s,std::shared_ptr<card_location_base> c,const point&pt)
 {
-	log_info("on_point...cardid:%d,type:%d",card_id,type);
+	log_info("on_point...cardid:%d,type:%d",c->m_id,c->m_type);
 	//获取地标信息
 	setLandmark(pt);
 	if(m_area_hover != nullptr && m_area_hover->m_area->in_area(pt))
 	{
-		do_hover_biz(card_id,speed,type);
+//		do_hover_biz(card_id,speed,type);
 	}
 	else
 	{
@@ -508,23 +505,24 @@ void area_tool::on_point(uint32_t card_id,const point&pt,double speed,int16_t ty
 		if(area == nullptr)
 		{
 			//这里使用分站区域比较合理
-			log_error("Cardid:%d can not find area..[x:%.2f,y:%.2f]",card_id,pt.x,pt.y);
+//			log_error("Cardid:%d can not find area..[x:%.2f,y:%.2f]",card_id,pt.x,pt.y);
 			return;
 		}
 		if(m_area_hover==nullptr)
 		{
-			m_area_hover = std::make_shared<area_hover>(area,pt,speed);
-			do_enter_biz(card_id,speed,type);
+//			m_area_hover = std::make_shared<area_hover>(area,pt,speed);
+//			do_enter_biz(card_id,speed,type);
 		}
 		else
 		{
-			do_leave_biz(card_id,speed,type);
+//			do_leave_biz(card_id,speed,type);
 
-			m_area_hover.reset(new area_hover(area,pt,speed));
-			do_enter_biz(card_id,speed,type);
+//			m_area_hover.reset(new area_hover(area,pt,speed));
+//			do_enter_biz(card_id,speed,type);
 		}
 	}
 }
+
 void area_hover::setLandmark(const point &pt)
 {
 	set(pt);

+ 65 - 35
area.h

@@ -7,9 +7,15 @@
 #include <point.h>
 #include "common.h"
 #include <write-copy.h>
+
 struct area_hover;
 struct point;
+struct area_business;
+struct card_location_base;
 
+/*
+	每个区域对应一个area对象。
+*/
 struct area
 {
     area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type)
@@ -24,9 +30,10 @@ struct area
     {
     }
 
-    virtual void on_hover(uint32_t card_id,std::shared_ptr<area_hover>&c,double speed,int32_t type);
-    virtual void on_enter(uint32_t card_id,std::shared_ptr<area_hover>&c,double speed,int32_t type);
-    virtual void on_leave(uint32_t card_id,std::shared_ptr<area_hover>&c,double speed,int32_t type);
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c);
+	virtual	void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c);
+	virtual	void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c);
+
     bool in_area(const point & p);
     int id()const
     {
@@ -63,17 +70,33 @@ struct area
         m_limit_vehicle_count=limit_count_vehicle;
         m_limit_vehicle_second=limit_time_vehicle;
     }
-
-    std::vector<point> m_bound;
 public:
+	std::vector<std::shared_ptr<area_business>> m_area_business_list;
+public:
+    std::vector<point> m_bound;
     //std::atomic<int> m_card_count;
+	//数据库唯一ID
     int    m_id;
     ///区域类型  AREA_TYPE
+
+	//用户定义的业务类型,BIT集合
+	/*
+	    1:位置[优先级]
+		2:超时[超时时间分钟数]
+		3:超员[人员数量、车辆数量]
+		4:超速[超速值、判断策略N/M]
+		5:人员考勤
+		6:车辆考勤[离开最小,离开最小距离]
+		7:禁区[进入时长]
+		8:猴车区域
+	*/
     int m_area_type;
 
+	//人卡超时及超员数量
     int m_limit_person_second;
     int m_limit_person_count;
 
+	//人卡超时及超员数量
     int m_limit_vehicle_second;
     int m_limit_vehicle_count;
     double m_scale;
@@ -108,6 +131,13 @@ struct area_hover
     int landmark_id;
     int landmark_dir;
     double landmark_dis;
+
+	/*
+		记录该业务所关心的需持续使用的数据,每个业务一个指针
+		建议该数据项在on_enter时初始化,on_leave时清除
+	*/
+	std::vector<void*> m_hover_data;
+
     area_hover()=default;
     area_hover(std::shared_ptr<area>&area,const point&pt,double speed)
         :m_area(area)
@@ -154,10 +184,13 @@ struct area_hover
 
 //每张卡包含一个对象
 //在解析出数据点时,调用on_point
+struct site;
 struct area_tool
 {
     std::shared_ptr<area_hover> m_area_hover=nullptr;
-    void on_point(uint32_t card_id,const point&pt,double speed,int16_t type);
+
+	void on_point(const std::shared_ptr<site>&s,std::shared_ptr<card_location_base> c,const point&pt);
+
     void setLandmark(const point &pt)
     {
         if(m_area_hover)
@@ -172,43 +205,40 @@ struct area_tool
             return true;
         return m_area_hover->m_area->special();
     }
+
     std::tuple<time_t,time_t,int,int,int,int,double> getLandmark()
     {
         if(m_area_hover)
             return m_area_hover->getLandmark();
         else
             return std::make_tuple(0,0,0,0,0,0,0);
-
-    }
-    //检测是否超时
-    void on_timer(int64_t card_id)
-    {
-
-    }
-
-    void do_hover_biz(uint32_t card_id,double speed,int16_t type)
-    {
-        m_area_hover->m_area->on_hover(card_id,m_area_hover,speed,type);
-    }
-
-    void do_enter_biz(uint32_t card_id,double speed,int16_t type)
-    {
-        m_area_hover->m_area->on_enter(card_id,m_area_hover,speed,type);
-    }
-
-    void do_leave_biz(uint32_t card_id,double speed,int16_t type)
-    {
-        m_area_hover->m_area->on_leave(card_id,m_area_hover,speed,type);
     }
 
-    void change_area(uint32_t card_id,double speed,int16_t type,int32_t new_areaid)
-    {
-        do_leave_biz(card_id,speed,type);
-        auto area = area_list::instance()->get(new_areaid);
-        point pt;
-        m_area_hover.reset(new area_hover(area,pt,speed));
-        do_enter_biz(card_id,speed,type);
-    }
+	void do_hover_biz(uint32_t card_id,double speed,int16_t type)
+	{
+//		m_area_hover->m_area->on_hover(card_id,m_area_hover,speed,type);
+	}
+
+	void do_enter_biz(uint32_t card_id,double speed,int16_t type)
+	{
+//		m_area_hover->m_area->on_enter(card_id,m_area_hover,speed,type);
+	}
+
+	void do_leave_biz(uint32_t card_id,double speed,int16_t type)
+	{
+//		m_area_hover->m_area->on_leave(card_id,m_area_hover,speed,type);
+	}
+
+	void change_area(uint32_t card_id,double speed,int16_t type,int32_t new_areaid)
+	{
+#if 0
+		do_leave_biz(card_id,speed,type);
+		auto area = area_list::instance()->get(new_areaid);
+		point pt;
+		m_area_hover.reset(new area_hover(area,pt,speed));
+		do_enter_biz(card_id,speed,type);
+#endif
+	}
 };
 
 #endif

+ 3 - 0
area_beh.h

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

+ 157 - 0
area_business.cpp

@@ -0,0 +1,157 @@
+
+#include <assert.h>
+
+#include "card_base.h"
+#include "area_business.h"
+
+struct area_business_factory
+{
+	area_business_factory()
+	{
+	
+	}
+
+	void regist(int type,std::shared_ptr<area_business> ab)
+	{
+		if(type>=(int)m_check_list.size())
+		{
+			m_check_list.resize(type+1);
+		}
+
+		assert(m_check_list[type]);
+
+		m_check_list[type]=ab;
+	}
+
+	std::vector<std::shared_ptr<area_business>> get_check_list(int business_type)
+	{
+		std::vector<std::shared_ptr<area_business>> check_list;
+		for(int i=0,B=1;i<32;i++)
+		{
+			if((B&business_type)==0)
+				continue;
+
+			check_list.push_back(m_check_list[i]);
+		}
+
+		return std::move(m_check_list);
+	}
+
+	std::vector<std::shared_ptr<area_business>> m_check_list;
+	static area_business_factory& instance()
+	{
+		static area_business_factory _instance;
+		return _instance;
+	}
+};
+
+/*
+	判断车辆超速,确定超速后记录日志、数据库并告警
+	每张卡在每个区域的超速相关的数据信息记录在 area_hover 对象
+	人员&车辆的代码重用,请自行设计
+*/
+
+struct area_business_speed_checker:area_business
+{
+	//在area_hover对象中初始化超速检测所需的对象
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+
+	//根据超速检测的策略,进行超速判断,超速时进行告警
+	//建议使用最近M秒内N秒超时进行判断,M=20,N=15,策略数据记录在area_hove中
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+
+	//清除超速检测所需的对象
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	}
+};
+
+/*
+	判断当前区域a中的人数是否超过设定人数,超过后告警
+	区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
+*/
+struct area_business_person_count_checker:area_business
+{
+	//增加计数,并进行判断
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+
+	//减少计数
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+};
+
+//同人员计数
+struct area_business_car_count_checker:area_business
+{
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+};
+
+/*
+	判断当前区域a中的人卡停留时间
+	人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
+	人员&车辆的代码重用,请自行设计
+*/
+
+struct area_business_person_dwell_checker:area_business
+{
+	//初始化 area_hover 的相关数据项
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+
+	//更新 area_hover 的相关数据项,并进行超时判断
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+};
+
+
+/*
+	判断逻辑同人员超时
+*/
+struct area_business_car_dwell_checker:area_business
+{
+	//初始化 area_hover 的相关数据项
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+
+	//更新 area_hover 的相关数据项,并进行超时判断
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
+	{
+	
+	}
+};
+
+std::vector<std::shared_ptr<area_business>> area_business::get_instance_list(int business_type)
+{
+	return area_business_factory::instance().get_check_list(business_type);
+}
+

+ 16 - 0
area_business.h

@@ -0,0 +1,16 @@
+#ifndef _area_business_hpp_
+#define _area_business_hpp_
+
+#include <vector>
+#include <memory>
+
+struct area_business
+{
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
+	virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
+
+	static std::vector<std::shared_ptr<area_business>> get_instance_list(int business_type);
+};
+#endif
+

+ 1 - 1
card_base.cpp

@@ -44,7 +44,7 @@ void card_location_base::on_location(const std::vector<point>&vp,const std::vect
 		//cardMgr::instance()->tryPut(m);
 		double acc = lm[0].m_acc;
 		log_info("useful:card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%.2f,y:%.2f acc:%.2f",m_id,m_ct,m_time,pt.x,pt.y,acc);
-		do_business(pt,acc);
+		do_business(lm.front().m_sit, pt, acc);
 	}
 }
 

+ 4 - 2
card_base.h

@@ -21,6 +21,7 @@ struct location_card;
 struct card_pos;
 struct area_hover;
 struct site_area_hover;
+struct site;
 
 namespace YA{struct _CARD_POS_;}
 
@@ -54,7 +55,7 @@ struct card:point
 	int32_t  m_level_id;		//部门级别
 };
 
-struct card_location_base:card
+struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 {
     std::unique_ptr<select_tool> m_sel_tool;
     std::unique_ptr<smooth_tool> m_smo_tool;
@@ -64,7 +65,8 @@ struct card_location_base:card
     card_location_base()=default;
     card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t,int32_t,uint32_t );
 
-	virtual void do_business(const point &pt,double acc)=0;
+	virtual void do_business(const std::shared_ptr<site>&,const point &pt,double acc)=0;
+
 	virtual void on_timer()=0;
 	virtual void site_hover(int sid)=0;
     virtual std::shared_ptr<area_hover> get_area_hover()=0;

+ 4 - 2
card_car.cpp

@@ -47,10 +47,10 @@ std::shared_ptr<site_area_hover> car::get_site_area()
 	return m_site_area;
 }
 
-void car::do_business(const point &pt,double acc)
+void car::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
 {
 	m_acc=acc;
-	m_area_tool->on_point(m_id,pt,m_speed,m_type);
+	m_area_tool->on_point(site,shared_from_this(),pt);
 	m_site_area->on_point(m_id,0,this, m_type);
 	m_mine_tool->on_point(m_id, m_type, m_vehicle_category_id);
 	handle_three_rates(pt);
@@ -90,7 +90,9 @@ int car::statbiz(int32_t special_id)
 			special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
 			log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
 			if(special_id != -1)
+			{
 				m_area_tool->change_area(m_id,m_speed,m_type,special_id);//自动拖车
+			}
 		}
 	}
 	return status;

+ 2 - 1
card_car.h

@@ -12,6 +12,7 @@
 
 struct area_hover;
 struct mine_tool;
+struct site;
 struct site_area_hover;
 
 struct car:card_location_base,card_area
@@ -30,7 +31,7 @@ public:
     virtual std::shared_ptr<area_hover> get_area_hover();
     virtual std::shared_ptr<mine_tool> get_mine_tool();
     virtual std::shared_ptr<site_area_hover> get_site_area();
-	virtual void do_business(const point &pt,double acc);
+	virtual void do_business(const std::shared_ptr<site>&site,const point &pt,double acc);
     int get_vehicle_type_id();
 
 private:

+ 2 - 2
card_message_handle.cpp

@@ -79,11 +79,11 @@ struct one_ct_message_handle
 			log_warn("分站信息缺失,SitId:%d",loc.m_site_id);
 			return;
 		}
-		const site &s=*(sit_list::instance()->get(loc.m_site_id));
+		auto s=sit_list::instance()->get(loc.m_site_id);
 		if(m_msg_list.empty())
 		{
 			m_ct=loc.m_card_ct;
-			m_ac=&s.config();
+			m_ac=&s->config();
 			m_min_timeout=false;
             //这里构造loc_message 保存数据
 			m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,

+ 2 - 2
card_person.cpp

@@ -84,9 +84,9 @@ std::shared_ptr<site_area_hover> person::get_site_area()
 	return m_site_area;
 }
 
-void person::do_business(const point &pt,double acc)
+void person::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
 {
-	m_area_tool->on_point(m_id,pt,m_speed,m_type);
+	m_area_tool->on_point(site,shared_from_this(),pt);
 	m_site_area->on_point(m_id,0,this, m_type);
 	handle_three_rates(pt);
 }

+ 1 - 2
card_person.h

@@ -25,11 +25,10 @@ struct person:card_location_base, card_area
     virtual std::shared_ptr<area_hover> get_area_hover();
     virtual std::shared_ptr<mine_tool> get_mine_tool();
     virtual std::shared_ptr<site_area_hover> get_site_area();
-	virtual void do_business(const point &pt,double acc);
+	virtual void do_business(const std::shared_ptr<site>&site,const point &pt,double acc);
     virtual std::tuple<time_t,time_t,int,int,int,int,double> getLandmark();
 };
 
 #endif
 
 
-

+ 2 - 0
db/Makefile.am

@@ -2,6 +2,8 @@ AUTOMAKE_OPTIONS=foreign
 
 noinst_LIBRARIES=libyadb.a
 
+
+CXXFLAGS=-g
 AM_CPPFLAGS=-Wall -pthread -m64 -std=c++11  -I${prefix}/include -I/usr/local/mysql/include -I. -I..
 AM_LDFLAGS =-Wall -pthread -m64 -std=c++11  -L${prefix}/lib  -L/usr/local/mysql/lib
 

+ 3 - 3
db/db_card.cpp

@@ -7,9 +7,9 @@
 #include "db_api/CDBSingletonDefine.h"
 
 #include "../card_base.h"
-#include "../common.h"
 #include "../card_person.h"
-#include "../common_tool.h"
+#include "../common.h"
+//#include "../common_tool.h"
 extern config_file config;
 namespace db_card
 {
@@ -205,7 +205,7 @@ namespace db_card
 
             std::shared_ptr<card_location_base> clb =
                     std::make_shared<person>(strategy,vsid,need_display,card_type_id,dept_id,occupation_level_id,staff_id,work_line,staffer_name,dept_name);
-            uint64_t cardid = tool_other::type_id_to_u64(vsid,card_type_id);
+            uint64_t cardid = getId(vsid,card_type_id);
             log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d,card:%s:work_line:%d,staff_id:%d,type:%d,staffer_name:%s,dept_name:%s",
                      cardid,vsid,dept_id,need_display,card_id.c_str(),work_line,staff_id,card_type_id,staffer_name.c_str(),dept_name.c_str());
 			map.insert({cardid,clb});

+ 9 - 2
db/db_tool.cpp

@@ -8,7 +8,7 @@
 
 #include "tool_time.h"
 #include "db_tool.h"
-#include "../common_tool.h"
+//#include "../common_tool.h"
 namespace db_tool
 {
     void PushAsync(char* sql)
@@ -19,6 +19,13 @@ namespace db_tool
         }
     }
 
+	static std::string type_id_to_str(int32_t type,uint32_t id)
+	{
+		char sql[15] = {0};
+		snprintf(sql, 15,"%03d%010d", type, id);
+		return std::string(sql);
+	}
+
     void save_attendance(const std::shared_ptr<card_location_base>& card_ptr)
     {
         char sql[LENGTH_SQL] = {0};
@@ -53,7 +60,7 @@ namespace db_tool
         }
 
         sprintf(sql, "CALL %s(%s, %d, '%s', '%s', %d, %d, %.3f);", call.c_str(),
-               tool_other::type_id_to_str(card_ptr->m_type,card_ptr->m_id).c_str(),
+               type_id_to_str(card_ptr->m_type,card_ptr->m_id).c_str(),
                 card_ptr->m_id, start_str.c_str(), end_str.c_str(),
                 landmarkid, landmarkdirect, landmarkdist);
 

+ 3 - 5
loc_message.h

@@ -3,7 +3,7 @@
 #include "ant.h"
 struct loc_message
 {
-    site     m_sit;
+    std::shared_ptr<site> m_sit;
     uint64_t m_num_ticks; //tof时间片m_tof或tdoa相对root时间
     uint64_t m_loc_time;
     uint32_t m_card_id;
@@ -21,12 +21,10 @@ struct loc_message
 	}
 	int tool_index()const
 	{
-		return m_sit.index();
+		return m_sit->index();
 	}
 
-
-
-    loc_message(site s,uint64_t num_ticks,uint64_t timestamp,
+    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)
         :m_sit(s)

+ 2 - 2
loc_point.cpp

@@ -88,7 +88,7 @@ int loc_point::cl()const
 
 void loc_point::set_source(const loc_message&li,const loc_message&li2)
 {
-    m_sid = li.m_sit.m_id;
+    m_sid = li.m_sit->m_id;
 	m_cid = li.m_card_id;
     m_time=std::min(li.m_loc_time,li2.m_loc_time);
     m_ct=li.m_card_ct;
@@ -101,8 +101,8 @@ void loc_point::set_source(const loc_message&li,const loc_message&li2)
 
 void loc_point::set_source(const loc_message&li)
 {
+    m_sid = li.m_sit->m_id;
 	m_cid = li.m_card_id;
-    m_sid = li.m_sit.m_id;
     m_time=li.m_loc_time;
     m_ct=li.m_card_ct;
     m_acc=li.m_acc *10;// 1270.;

+ 8 - 7
loc_tool.cpp

@@ -57,17 +57,18 @@ std::vector<point> loc_tool_tof_1_base::calc_location(std::vector<loc_message>&l
     int32_t last_ct = -1;
     std::vector<point> vec;
     std::vector<loc_message> lm;
-    for(auto rit = locm.crbegin();rit != locm.crend();rit++)
+    for(auto rit = locm.rbegin();rit != locm.rend();rit++)
     {
-        site s = rit->m_sit;
-        if(s.is_path_empty() || rit->m_num_ticks == 0)
+//        site s = rit->m_sit;
+
+        if(rit->m_sit->is_path_empty() || rit->m_num_ticks == 0)
           continue;
         if(last_ct == -1)
           last_ct = rit->m_card_ct;
         else if(last_ct != rit->m_card_ct)
           continue;
-		double dist_tof=rit->m_num_ticks*15.65*2.996*1e-4/s.m_scale;
-        auto v = s.solving(rit->m_ant_id,dist_tof);
+		double dist_tof=rit->m_num_ticks*15.65*2.996*1e-4/rit->m_sit->m_scale;
+        auto v = rit->m_sit->solving(rit->m_ant_id,dist_tof);
         lm.insert(lm.begin(),*rit);
         vec.insert(std::end(vec),std::begin(v),std::end(v));
     }
@@ -136,13 +137,13 @@ std::vector<point> loc_tool_main::calc_location(std::vector<loc_message>&locm)
     if(locm2[0].tool_index() > tool_index)
         flag = true;
     std::vector<point> rc;
-    if(flag && (locm2[0].m_sit.config().best_msg_cnt<=(int)locm2.size()))
+    if(flag && (locm2[0].m_sit->config().best_msg_cnt<=(int)locm2.size()))
     {
 		int index=locm2[0].tool_index();
 		rc = std::move(g_tool[index]->calc_location(locm2));
         locm.swap(locm2);
     }
-    else if(locm1[0].m_sit.config().best_msg_cnt<=(int)locm1.size())
+    else if(locm1[0].m_sit->config().best_msg_cnt<=(int)locm1.size())
 	{
 	    rc = std::move(g_tool[tool_index]->calc_location(locm1));
         locm.swap(locm1);

+ 4 - 0
monkey_car/monkeycar_area.h

@@ -30,6 +30,10 @@ public:
 	{}
 	std::shared_ptr<monkey_person> find(uint32_t cardid);
 
+    virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
+	virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
+	virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c){}
+
     virtual void on_hover(int64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
     virtual void on_enter(int64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);
     virtual void on_leave(int64_t card_id,std::shared_ptr<area_hover>&c,double speed,uint64_t type);

+ 1 - 1
select_tool.cpp

@@ -34,7 +34,7 @@ loc_point select_point_object::select_solution_impl(const std::vector<point> vp,
     }
     if(flag)
     {
-        if(!select_solution(vp,&lm[0].m_sit,lp))
+        if(!select_solution(vp,lm[0].m_sit.get(),lp))
         {
             m_cur_fit.reset();
             return lp;

+ 7 - 0
select_tool.h

@@ -7,6 +7,7 @@
 #include "ant.h"
 #include "card_path.h"
 #include "loc_message.h"
+#include <zexception.h>
 struct solpoint:point
 {
 	solpoint()
@@ -1137,6 +1138,8 @@ struct smooth_tool_drivingface_car_1:smooth_tool
 	virtual void smooth_dist(point &pt, double t, int ct, const site*sit, point dstp, loc_point *m_lp = nullptr){}
 };
 //---------------------------------
+
+DEF_EXCEPTION (no_tool);
 struct select_tool_manage
 {
    void create_tool(const std::string &s,std::unique_ptr <select_tool> &set,std::unique_ptr <smooth_tool> &smt)
@@ -1163,6 +1166,10 @@ struct select_tool_manage
 			//set.reset(new select_tool_drivingface_car_1());
 			//smt.reset(new smooth_tool_drivingface_car_1(set));
         }
+		else
+		{
+			THROW_EXCEPTION(no_tool,"未定义%s的策略,需要在config.ini中定义",s.c_str());
+		}
    }
    static select_tool_manage * instance();
 };

+ 1 - 1
tool_time.h

@@ -77,7 +77,7 @@ public:
         uint64_t pos = str.length()-3;
 
         time_t t_;
-        tm tm_;
+        tm tm_={0};
         strptime(str.substr(0,pos).c_str(), "%Y-%m-%d %H:%M:%S", &tm_); //将字符串转换为tm时间
         t_ = mktime(&tm_); //将tm时间转换为秒时间
 

+ 2 - 0
websocket/Makefile.am

@@ -2,6 +2,8 @@ AUTOMAKE_OPTIONS=foreign
 
 noinst_LIBRARIES=libwebsocket.a
 
+CXXFLAGS=-g
+
 AM_CPPFLAGS=-Wall -pthread -m64 -std=c++11  -I${prefix}/include -I. -I.. -I./sio
 AM_LDFLAGS =-Wall -pthread -m64 -std=c++11  -L${prefix}/lib  
 

+ 35 - 0
zexception.h

@@ -0,0 +1,35 @@
+#ifndef _zexception_hpp_
+#define _zexception_hpp_
+
+#include <stdarg.h>
+#include <exception>
+#include <string>
+
+#define DEF_EXCEPTION(clsname)\
+class clsname##_exception:public std::exception\
+{\
+	std::string m_what;\
+public:\
+    clsname##_exception(const std::string&msg) throw():m_what(msg) { } \
+    ~clsname##_exception() throw()  { } \
+	const char* what() const throw() { return m_what.c_str(); }\
+};
+
+inline const char*eformat(char*buf,const char*fmt,...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	vsprintf(buf,fmt,ap);
+	va_end(ap);
+
+	return buf;
+}
+#define THROW_EXCEPTION(clsname,fmt,...)	{\
+	char ___fmt0[512]; \
+	char ___buf[2048]; \
+	sprintf(___fmt0,"[%s:%d]%s",__FILE__,__LINE__,fmt);\
+	eformat(___buf,fmt,##__VA_ARGS__);\
+	throw clsname##_exception(___buf);\
+}
+
+#endif