lixioayao 6 år sedan
förälder
incheckning
06057441c8
16 ändrade filer med 476 tillägg och 43 borttagningar
  1. 17 2
      Makefile
  2. 1 1
      Makefile.am
  3. 17 2
      Makefile.in
  4. 4 4
      area.h
  5. 3 1
      card.cpp
  6. 3 6
      card_base.h
  7. 15 8
      card_car.cpp
  8. 3 3
      card_car.h
  9. 4 3
      card_person.cpp
  10. 2 2
      card_person.h
  11. 3 0
      main.cpp
  12. 285 10
      mine_business.cpp
  13. 8 0
      mine_business.h
  14. 1 1
      point.h
  15. 50 0
      ya_setting.cpp
  16. 60 0
      ya_setting.h

+ 17 - 2
Makefile

@@ -102,7 +102,7 @@ am__objects_3 = yals-ant.$(OBJEXT) yals-area.$(OBJEXT) \
 	yals-special_area.$(OBJEXT) yals-tdoa_sync.$(OBJEXT) \
 	yals-visit.$(OBJEXT) yals-web-client.$(OBJEXT) \
 	yals-worker.$(OBJEXT) yals-ya_event.$(OBJEXT) \
-	yals-znet.$(OBJEXT)
+	yals-znet.$(OBJEXT) yals-ya_setting.$(OBJEXT)
 am__objects_4 = $(am__objects_1) $(am__objects_2) $(am__objects_3)
 am_yals_OBJECTS = $(am__objects_4) yals-main.$(OBJEXT)
 yals_OBJECTS = $(am_yals_OBJECTS)
@@ -244,7 +244,7 @@ SRC_MAIN = ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_a
     	  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 ya_setting.cpp
 
 AM_SOURCES = $(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN)
 AM_CPPFLAGS = -Wall -pthread -m64 -std=c++11  -I${prefix}/include -I/usr/local/mysql/include -Iwebsocket -Iwebsocket/sio -I./db 
@@ -407,6 +407,7 @@ include ./$(DEPDIR)/yals-visit.Po
 include ./$(DEPDIR)/yals-web-client.Po
 include ./$(DEPDIR)/yals-worker.Po
 include ./$(DEPDIR)/yals-ya_event.Po
+include ./$(DEPDIR)/yals-ya_setting.Po
 include ./$(DEPDIR)/yals-znet.Po
 
 .cpp.o:
@@ -1039,6 +1040,20 @@ yals-znet.obj: znet.cpp
 #	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 #	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o yals-znet.obj `if test -f 'znet.cpp'; then $(CYGPATH_W) 'znet.cpp'; else $(CYGPATH_W) '$(srcdir)/znet.cpp'; fi`
 
+yals-ya_setting.o: ya_setting.cpp
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT yals-ya_setting.o -MD -MP -MF $(DEPDIR)/yals-ya_setting.Tpo -c -o yals-ya_setting.o `test -f 'ya_setting.cpp' || echo '$(srcdir)/'`ya_setting.cpp
+	$(am__mv) $(DEPDIR)/yals-ya_setting.Tpo $(DEPDIR)/yals-ya_setting.Po
+#	source='ya_setting.cpp' object='yals-ya_setting.o' libtool=no \
+#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
+#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o yals-ya_setting.o `test -f 'ya_setting.cpp' || echo '$(srcdir)/'`ya_setting.cpp
+
+yals-ya_setting.obj: ya_setting.cpp
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT yals-ya_setting.obj -MD -MP -MF $(DEPDIR)/yals-ya_setting.Tpo -c -o yals-ya_setting.obj `if test -f 'ya_setting.cpp'; then $(CYGPATH_W) 'ya_setting.cpp'; else $(CYGPATH_W) '$(srcdir)/ya_setting.cpp'; fi`
+	$(am__mv) $(DEPDIR)/yals-ya_setting.Tpo $(DEPDIR)/yals-ya_setting.Po
+#	source='ya_setting.cpp' object='yals-ya_setting.obj' libtool=no \
+#	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
+#	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o yals-ya_setting.obj `if test -f 'ya_setting.cpp'; then $(CYGPATH_W) 'ya_setting.cpp'; else $(CYGPATH_W) '$(srcdir)/ya_setting.cpp'; fi`
+
 yals-main.o: main.cpp
 	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT yals-main.o -MD -MP -MF $(DEPDIR)/yals-main.Tpo -c -o yals-main.o `test -f 'main.cpp' || echo '$(srcdir)/'`main.cpp
 	$(am__mv) $(DEPDIR)/yals-main.Tpo $(DEPDIR)/yals-main.Po

+ 1 - 1
Makefile.am

@@ -9,7 +9,7 @@ SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_ar
     	  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 ya_setting.cpp
 
 AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN)
 

+ 17 - 2
Makefile.in

@@ -102,7 +102,7 @@ am__objects_3 = yals-ant.$(OBJEXT) yals-area.$(OBJEXT) \
 	yals-special_area.$(OBJEXT) yals-tdoa_sync.$(OBJEXT) \
 	yals-visit.$(OBJEXT) yals-web-client.$(OBJEXT) \
 	yals-worker.$(OBJEXT) yals-ya_event.$(OBJEXT) \
-	yals-znet.$(OBJEXT)
+	yals-znet.$(OBJEXT) yals-ya_setting.$(OBJEXT)
 am__objects_4 = $(am__objects_1) $(am__objects_2) $(am__objects_3)
 am_yals_OBJECTS = $(am__objects_4) yals-main.$(OBJEXT)
 yals_OBJECTS = $(am_yals_OBJECTS)
@@ -244,7 +244,7 @@ SRC_MAIN = ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_a
     	  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 ya_setting.cpp
 
 AM_SOURCES = $(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN)
 AM_CPPFLAGS = -Wall -pthread -m64 -std=c++11  -I${prefix}/include -I/usr/local/mysql/include -Iwebsocket -Iwebsocket/sio -I./db 
@@ -407,6 +407,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/yals-web-client.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/yals-worker.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/yals-ya_event.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/yals-ya_setting.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/yals-znet.Po@am__quote@
 
 .cpp.o:
@@ -1039,6 +1040,20 @@ yals-znet.obj: znet.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o yals-znet.obj `if test -f 'znet.cpp'; then $(CYGPATH_W) 'znet.cpp'; else $(CYGPATH_W) '$(srcdir)/znet.cpp'; fi`
 
+yals-ya_setting.o: ya_setting.cpp
+@am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT yals-ya_setting.o -MD -MP -MF $(DEPDIR)/yals-ya_setting.Tpo -c -o yals-ya_setting.o `test -f 'ya_setting.cpp' || echo '$(srcdir)/'`ya_setting.cpp
+@am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/yals-ya_setting.Tpo $(DEPDIR)/yals-ya_setting.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='ya_setting.cpp' object='yals-ya_setting.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o yals-ya_setting.o `test -f 'ya_setting.cpp' || echo '$(srcdir)/'`ya_setting.cpp
+
+yals-ya_setting.obj: ya_setting.cpp
+@am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT yals-ya_setting.obj -MD -MP -MF $(DEPDIR)/yals-ya_setting.Tpo -c -o yals-ya_setting.obj `if test -f 'ya_setting.cpp'; then $(CYGPATH_W) 'ya_setting.cpp'; else $(CYGPATH_W) '$(srcdir)/ya_setting.cpp'; fi`
+@am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/yals-ya_setting.Tpo $(DEPDIR)/yals-ya_setting.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='ya_setting.cpp' object='yals-ya_setting.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o yals-ya_setting.obj `if test -f 'ya_setting.cpp'; then $(CYGPATH_W) 'ya_setting.cpp'; else $(CYGPATH_W) '$(srcdir)/ya_setting.cpp'; fi`
+
 yals-main.o: main.cpp
 @am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(yals_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT yals-main.o -MD -MP -MF $(DEPDIR)/yals-main.Tpo -c -o yals-main.o `test -f 'main.cpp' || echo '$(srcdir)/'`main.cpp
 @am__fastdepCXX_TRUE@	$(am__mv) $(DEPDIR)/yals-main.Tpo $(DEPDIR)/yals-main.Po

+ 4 - 4
area.h

@@ -137,9 +137,9 @@ struct area_hover
     {
         return m_area->id()<o.m_area->id();
     }
-    std::tuple<time_t,time_t,int,int,int,int,double> getLandmark()
+    std::tuple<time_t,time_t,int,int,int,int,double,double> getLandmark()
     {
-        return std::make_tuple(m_enter_time,m_last_time,mapid(),id(),landmark_id,landmark_dir,landmark_dis);
+        return std::make_tuple(m_enter_time,m_last_time,mapid(),id(),landmark_id,landmark_dir,landmark_dis,scale());
     }
     void setLandmark(const point &pt);
     void set(const point&pt)
@@ -169,12 +169,12 @@ struct area_tool
             return true;
         return m_area_hover->m_area->special();
     }
-    std::tuple<time_t,time_t,int,int,int,int,double> getLandmark()
+    std::tuple<time_t,time_t,int,int,int,int,double,double> getLandmark()
     {
         if(m_area_hover)
             return m_area_hover->getLandmark();
         else
-            return std::make_tuple(0,0,0,0,0,0,0);
+            return std::make_tuple(0,0,0,0,0,0,0,0);
 
     }
     //检测是否超时

+ 3 - 1
card.cpp

@@ -16,6 +16,7 @@
 #include "log.h"
 #include "area.h"
 #include "card.h"
+#include "mine_business.h"
 
 
 extern config_file config;
@@ -392,7 +393,8 @@ void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_
 
 bool card_list_visit::visit(std::shared_ptr<card_location_base> c)
 {
-	c->on_timer();
+	if(c->on_timer())
+		mine_business::inst()->put(c);
 	return true;	
 }
 

+ 3 - 6
card_base.h

@@ -65,26 +65,23 @@ struct card_location_base:card
     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 on_timer()=0;
+	virtual bool on_timer()=0;
 	virtual void site_hover(int sid)=0;
     virtual std::shared_ptr<area_hover> get_area_hover()=0;
     virtual std::shared_ptr<mine_tool> get_mine_tool()=0;
     virtual std::shared_ptr<site_area_hover> get_site_area()=0;
-
     virtual void clear();
-
 	virtual void reset(std::shared_ptr<monkey_person> mp){}
     virtual int get_vehicle_type_id(){return  0;}
-    virtual std::tuple<time_t,time_t,int,int,int,int,double> getLandmark()=0;
+    virtual std::tuple<time_t,time_t,int,int,int,int,double,double> getLandmark()=0;
 
     void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history);
     void on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm );
     void do_status(int st);
 	void upt_card_pos(YA::_CARD_POS_&cp, const point &pt);
 	void del_card_pos();
-	int get_stat();
+	int	 get_stat();
 	void put_three_rates(card_pos &);
-
     bool is_person() const;
     bool is_vehicle() const;
 

+ 15 - 8
card_car.cpp

@@ -10,7 +10,9 @@
 #include "websocket/ws_common.h"
 #include "special_area.h"
 #include "websocket/wsClientMgr.h"
-
+#include "common_tool.h"
+#include "tool_time.h"
+#include "mine_business.h"
 car::car(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
 		int32_t categoryid, int type_id,int32_t level_id,uint32_t cid)
 	:card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
@@ -54,6 +56,8 @@ void car::do_business(const point &pt,double acc)
 	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);
+	uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
+	mine_business::inst()->make_arg(id,*this,m_time);
 }
 
 int car::get_vehicle_type_id()
@@ -74,11 +78,9 @@ void car::handle_three_rates(const point &pt)
 	put_three_rates(cp);
 }
 
-void car::on_timer()
-
+bool car::on_timer()
 {
-	make_package();
-
+	return make_package();
 }
 int car::statbiz(int32_t special_id)
 {
@@ -95,8 +97,9 @@ int car::statbiz(int32_t special_id)
 	}
 	return status;
 }
-void car::make_package()
+bool car::make_package()
 {
+	bool f=false;
 	int32_t special_id=-1;
 	YA::_CARD_POS_ cp;
 	loc_point pt = getSmoothPoint();
@@ -114,7 +117,6 @@ void car::make_package()
 	cp.biz_stat=biz_stat;
 	cp.down_time = m_mine_tool->get_down_time();
 	cp.work_time = m_mine_tool->get_work_time();
-	//for now
 	cp.is_on_duty=m_mine_tool->is_on_duty();
 	upt_card_pos(cp,pt);
 	m_his_location_card->push(pt.m_time,pt,area_id,map_id);
@@ -123,6 +125,11 @@ void car::make_package()
 		cp.area_id = special_id;
 		swsClientMgr.SendSpecialAreaProcess(cp);
 	}
+	uint64_t _now=tool_time::now_to_ms();
+	uint64_t t=_now>m_time?_now-m_time:m_time-_now;
+	if(t<45*1000 && !empty())
+	  f=true;
+	return f;
 }
 loc_point car::getSmoothPoint()
 {
@@ -133,7 +140,7 @@ loc_point car::getSmoothPoint()
 	return lp;
 }
 
-std::tuple<time_t,time_t,int,int,int,int,double> car::getLandmark()
+std::tuple<time_t,time_t,int,int,int,int,double,double> car::getLandmark()
 {
 	return  m_area_tool->getLandmark();
 }

+ 3 - 3
card_car.h

@@ -35,12 +35,12 @@ public:
 
 private:
 	void handle_three_rates(const point &pt);
-	void on_timer();
+	bool on_timer();
 	int statbiz(int32_t special_id);
-	void make_package();
+	bool make_package();
 	loc_point getSmoothPoint();
 
-	virtual std::tuple<time_t,time_t,int,int,int,int,double> getLandmark();
+	virtual std::tuple<time_t,time_t,int,int,int,int,double,double> getLandmark();
 };
 
 

+ 4 - 3
card_person.cpp

@@ -96,7 +96,7 @@ void person::reset(std::shared_ptr<monkey_person> mp)
 	m_monkeyPerson = mp;
 }
 
-std::tuple<time_t,time_t,int,int,int,int,double> person::getLandmark()
+std::tuple<time_t,time_t,int,int,int,int,double,double> person::getLandmark()
 {
 	return  m_area_tool->getLandmark();
 }
@@ -112,10 +112,10 @@ void person::handle_three_rates(const point & pt)
 	put_three_rates(cp);
 }
 
-void person::on_timer()
+bool person::on_timer()
 {    
 	if(!m_mine_tool->is_attendance())
-		return;
+		return false;
 	YA::_CARD_POS_ cp;
 	if(m_display)
 	  mine_business::inst()->fetch_add();
@@ -140,6 +140,7 @@ void person::on_timer()
 	log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d",m_id,_time,pt.x,pt.y,area_id,map_id);
 	m_his_location_card->push(_time,pt,area_id,map_id);
 	upt_card_pos(cp,pt);
+	return false;
 }
 
 point person::getSmoothPoint(uint64_t& t)

+ 2 - 2
card_person.h

@@ -17,7 +17,7 @@ struct person:card_location_base, card_area
     void clear();
 	void reset(std::shared_ptr<monkey_person> mp);
 	void handle_three_rates(const point & pt);
-	void on_timer();
+	bool on_timer();
 	void IKSDK_DB(int);
 	point getSmoothPoint(uint64_t& t);
 
@@ -26,7 +26,7 @@ struct person:card_location_base, card_area
     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 std::tuple<time_t,time_t,int,int,int,int,double> getLandmark();
+    virtual std::tuple<time_t,time_t,int,int,int,int,double,double> getLandmark();
 };
 
 #endif

+ 3 - 0
main.cpp

@@ -20,6 +20,7 @@
 #include "three_rates.h"
 #include "mine_business.h"
 #include "main_test.h"
+#include "ya_setting.h"
 
 config_file config;
 static void handlereader(uint32_t readerid,bool duration,uint32_t t)
@@ -48,6 +49,8 @@ struct Init_Setting
         DBSetting.PoolSize = config.get("db.pool_size",30);
         _mysql_init(DBSetting);
 
+		CYaSetting::Init_sys_setting();
+
         sit_list::instance()->load_from_db();
 
         card_list::instance()->init_card_from_db();

+ 285 - 10
mine_business.cpp

@@ -11,12 +11,13 @@
 #include "db/db_tool.h"
 #include "common_tool.h"
 #include "ant.h"
-
+#include "ya_setting.h"
+#include "card_path.h"
 struct card_sensor
 {
 	card_sensor(int32_t wid,const point &p,const std::string &cid)
 		:card_id(cid)
-		,sid(0)
+		 ,sid(0)
 		 ,id(wid)
 		 ,bigger(-1),count(0),sum(0),ct(-1),stime(0),flag(false)
 	{
@@ -141,11 +142,87 @@ struct reverse_alarm_business
 	private:
 	std::map<uint64_t,std::shared_ptr<card_sensor_mgr>> m_sensor_mgr;
 };
+struct rear_end_collision_prevented_business
+{
+	rear_end_collision_prevented_business()
+	{
+		_time=0;m_v.clear();_flag=false;
+	}
+	void put(const std::shared_ptr<card_location_base>&c)
+	{
+		if(_flag)
+		  m_v.push_back(c);
+	}
+	bool rear_end_arg_algo(uint64_t u1,uint64_t u2);
+	void handle_message();
+	double get_absolute_distance(uint64_t c1,uint64_t c2);
+	struct car_data
+	{
+		car_data()
+			:_t(0),_arg(0x12345678)
+		{}
+		void push(uint64_t cid,const point &p,uint64_t t)
+		{
+			last_p=_p;_p=p;
+			if (last_p.empty() || _p.empty())
+			  return;
+			if (_p.dist(last_p)<0.5)
+			  return;
+
+			if ( t-_t<5*1000)
+			{
+				_arg = std::arg(std::complex<double>(_p.x,_p.y)-std::complex<double>(last_p.x,last_p.y));
+				line_v l(last_p,_p);_line=l;
+				std::string card_id = tool_other::get_string_cardid(cid);
+				log_info("[vehicle_alarm_arg ] %s,arg:%f (%.2f,%.2f)--(%.2f,%.2f)",card_id.c_str(),_arg,last_p.x,last_p.y,p.x,p.y);
+			}
+			_t=t;
+		}
 
+		point last_p,_p;
+		line_v _line;
+		uint64_t _t;
+		double _arg;
+	};
+	struct vInfo
+	{
+		vInfo()
+		{
+			is_alarm=false;
+			real_end_start_time=0;
+			backfired_start_time=0;
+		}
+		void push(const std::string & c1, const std::string &c2)
+		{
+			m_cid[0]=c1;
+			m_cid[1]=c2;
+			std::sort(m_cid.begin(),m_cid.end());
+		}
+		std::string getKey() const
+		{
+			return m_cid[0]+"&"+m_cid[1];
+		}
+		bool is_alarm;
+		std::array<std::string,2> m_cid;
+		time_t real_end_start_time ;
+		time_t backfired_start_time;
+	};
+	void make_arg(uint64_t cid, const point &p,uint64_t t)
+	{
+		m_map[cid].push(cid,p,t);
+	}
+	private:
+	time_t _time;
+	std::atomic<bool> _flag;
+	std::vector<std::shared_ptr<card_location_base>> m_v;
+	std::map<uint64_t,car_data> m_map;
+	std::map<std::string,vInfo> m_CloserVehicle;
+};
 mine_business::mine_business()
 {
 	m_staffer_num_ptr.reset(new staffer_num_business);
 	m_reverse_alarm_ptr.reset(new reverse_alarm_business);
+	m_rear_ended_ptr.reset(new rear_end_collision_prevented_business);
 }
 mine_business* mine_business::inst()
 {
@@ -154,8 +231,9 @@ mine_business* mine_business::inst()
 }
 void mine_business::run_business()
 {
-	mine_business::inst()->record_staffer_num();
-	mine_business::inst()->handle_reverse_alarm();
+	record_staffer_num();
+	handle_reverse_alarm();
+	handle_rear_end();
 }
 void mine_business::fetch_add()
 {
@@ -177,11 +255,23 @@ void mine_business::make_reverse_condition(uint64_t type,uint32_t id,int32_t ant
 {
 	m_reverse_alarm_ptr->make_condition(type,id,antid,ct,tof,sid);
 }
+void mine_business::put(const std::shared_ptr<card_location_base> &c)
+{
+	m_rear_ended_ptr->put(c);
+}
+void mine_business::make_arg(uint64_t cid,const point &p,uint64_t t)
+{
+	m_rear_ended_ptr->make_arg(cid,p,t);
+}
+void mine_business::handle_rear_end()
+{
+	m_rear_ended_ptr->handle_message();
+}
 ///////staffer_num_business
 /**********************************
 //每两分钟把人员数量入库。
 //不往前端推送的人员,不算在数量范围内
-*********************************/
+ *********************************/
 void staffer_num_business::record_staffer_num()
 {
 	static uint32_t min_num=0,max_num=0;
@@ -259,7 +349,11 @@ void reverse_alarm_business::load_sensor()
 		tm->push(workfaceid,sensor_id,p,card_id);
 	}
 }
-
+/************************************
+//获取传感器数据,从数据库中
+//每三分钟获取一次,判断其是否上升趋势。
+//如果上升趋势,则标识正在掘进中。开始判断反向
+ ************************************/
 void reverse_alarm_business::run_sensor()
 {
 	static time_t time_interval=0;
@@ -269,7 +363,7 @@ void reverse_alarm_business::run_sensor()
 		time_interval =t;
 		printf("reverse_alarm......\n");
 		for(const auto &x:m_sensor_mgr)
-			x.second->for_each();
+		  x.second->for_each();
 	}
 }
 
@@ -288,8 +382,8 @@ void card_sensor_mgr::for_each()
 		int nCount = DBRes.GetRecordCount( Error );
 		if (nCount < 1)
 		{
-		  log_error("load_sensor_data..failed[%s]", strsql);
-		  continue;
+			log_error("load_sensor_data..failed[%s]", strsql);
+			continue;
 		}
 
 		double prenum=-1;
@@ -344,12 +438,18 @@ void card_sensor_mgr::for_each()
 		}
 	}
 }
+/*****************************************
+//当判断为反向后,则开始手机数据。
+//在规定的时间内,记录反向的数量以及双天线数量。
+//正常的数量n 总数量s 时长m(秒)
+//n/s<0.2 && s/m>0.8则标识天线反向
+ ****************************************/
 void reverse_alarm_business::make_condition(uint64_t type,uint32_t id,int32_t antid,uint32_t ct,uint64_t tof,uint32_t sid)
 {
 	uint64_t cid = tool_other::type_id_to_u64(type,id);
 	auto it = m_sensor_mgr.find(cid);
 	if(it != m_sensor_mgr.end())
-		it->second->make_condition(antid,ct,tof,sid);
+	  it->second->make_condition(antid,ct,tof,sid);
 }
 void card_sensor_mgr::make_condition(int32_t antid,uint32_t ct,uint64_t tof,uint32_t sid)
 {
@@ -368,3 +468,178 @@ void card_sensor_mgr::make_condition(int32_t antid,uint32_t ct,uint64_t tof,uint
 		}
 	}
 }
+void rear_end_collision_prevented_business::handle_message()
+{
+	time_t now = time(0);
+	if(now-_time>3)
+	{
+		_flag=true;
+		_time=now;
+	}
+	auto it=m_v.cbegin();
+	for (;it!=m_v.cend();it++)
+	{
+		_flag=false;
+		auto c=*it;
+		if (c->empty())continue;
+		auto t=c->getLandmark();
+		double map_scale = std::get<7>(t);
+		for (auto prv_it=std::next(it);prv_it!=m_v.cend();++prv_it)
+		{
+			auto c2=*prv_it;
+			if (c2->empty())continue;
+			double dis = (*c).dist(*c2)*map_scale;
+			log_info("vehicle_alarm stpe3 : cid1:%d,cid2:%d (%.2f,%.2f),(%.2f,%.2f) %.2f,%f",c->m_id,c2->m_id,c->x,c->y,c2->x,c2->y,dis,map_scale);
+			if(dis>CYaSetting::m_sys_setting.rear_end_d)
+			  continue;
+			//判断反向行驶,平行行驶,背离行驶的车辆
+			uint64_t u1=tool_other::type_id_to_u64(c->m_type,c->m_id);uint64_t u2=tool_other::type_id_to_u64(c2->m_type,c2->m_id);
+			if (!rear_end_arg_algo(u1,u2))
+			  continue;
+			//
+			std::string card1=tool_other::type_id_to_str(c->m_type,c->m_id);std::string card2=tool_other::type_id_to_str(c2->m_type,c2->m_id);
+			vInfo v;
+			v.push(card1,card2);
+			std::string cardid=v.getKey();
+			if(m_CloserVehicle.find(cardid) == m_CloserVehicle.end())
+			{
+				m_CloserVehicle.insert(std::make_pair(cardid,v));
+				log_info("vehicle_alarm_insert %s",cardid.c_str());
+			}
+		}
+	}
+	//clear()...
+	m_v.clear();
+
+	auto it_cv=m_CloserVehicle.begin();
+	for (;it_cv != m_CloserVehicle.end();)
+	{
+		vInfo & vinfo = it_cv->second;
+		std::string vvid = it_cv->first;
+		uint64_t u1=tool_other::card_id_to_u64(vinfo.m_cid[0]);
+		uint64_t u2=tool_other::card_id_to_u64(vinfo.m_cid[1]);
+		uint64_t t=now*1000;
+		uint64_t ct=m_map[u1]._t ;uint64_t rt = t>ct?t-ct:ct-t;
+		uint64_t ct_=m_map[u2]._t; uint64_t rt_ = t>ct_?t-ct_:ct_-t;
+		if (rt>45*1000 || rt_>45*1000 )
+		{
+			log_info("vehicle_alarm_time_ %s",vvid.c_str());
+			if (vinfo.is_alarm){}
+			//告警
+			//deal_alarm_vehicle(vvid,it_vlist_2->second);
+			it_cv = m_CloserVehicle.erase(it_cv);
+			continue;
+		}
+		auto c=card_list::instance()->get(u1);
+		if(!c) continue;
+		auto lm=c->getLandmark();
+		double map_scale = std::get<7>(lm);
+		double dis = get_absolute_distance(u1,u2)*map_scale;
+		log_info("vehicle_alarm_distance %s %f",vvid.c_str(),dis);
+
+		time_t tt = time(0);
+		if (dis>CYaSetting::m_sys_setting.rear_end_d ||!rear_end_arg_algo(u1,u2))
+		{
+			if (vinfo.backfired_start_time==0)
+			  vinfo.backfired_start_time=tt;
+			vinfo.real_end_start_time=0;
+			if (tt-vinfo.backfired_start_time>CYaSetting::m_sys_setting.rear_end_t)
+			{
+				log_info("vehicle_alarm_backfired_timeout %s",vvid.c_str());
+				if(vinfo.is_alarm){}
+				  //告警
+				  //deal_alarm_vehicle(vvid,it_vlist_1->second);
+				it_cv = m_CloserVehicle.erase(it_cv);
+				continue;
+			}
+		}
+		else
+		{
+			vinfo.backfired_start_time =0;
+			if (vinfo.real_end_start_time==0)
+			  vinfo.real_end_start_time=tt;
+			if (tt-vinfo.real_end_start_time>CYaSetting::m_sys_setting.rear_end_t)
+			{
+				//	debug_print_syslog(0,"vehicle_alarm_real_end_timeout %s",vvid.c_str());
+				if (!vinfo.is_alarm)
+				{
+					log_info("vehicle_alarm_real_end_timeout_exec %s",vvid.c_str());
+					//deal_alarm_vehicle(vvid,it_vlist_1->second);
+					//告警
+					vinfo.is_alarm = true;
+				}
+			}
+		}
+		++it_cv;
+	}
+
+}
+double rear_end_collision_prevented_business::get_absolute_distance(uint64_t c1,uint64_t c2)
+{
+	point pp1=m_map[c1]._p;point pp2=m_map[c2]._p;
+	double arg1=m_map[c1]._arg;double arg2=m_map[c2]._arg;
+	point p1(pp1.x,-pp1.y);
+	point p2(pp2.x,-pp2.y);
+
+	if (fabs(arg1-arg2)<1e-10)
+	  return p1.dist(p2);
+	std::stringstream ss;
+	std::vector<point> v = card_path::inst().find_path(p1,p2);
+	point pt = p1;double dis = 0;
+	for (const auto & p:v)
+	{
+		dis += pt.dist(p);
+		pt=p;
+	}
+	dis += pt.dist(p2);
+	return dis;
+}
+bool rear_end_collision_prevented_business::rear_end_arg_algo(uint64_t u1,uint64_t u2)
+{
+	point p_1=m_map[u1].last_p;point p_2=m_map[u2].last_p;
+	double arg_1=m_map[u1]._arg;double arg_2=m_map[u2]._arg;
+	line_v l_1=m_map[u1]._line;line_v l_2=m_map[u2]._line;
+	std::string card1=tool_other::get_string_cardid(u1);std::string card2=tool_other::get_string_cardid(u2);
+	if(p_1.empty() || p_2.empty())
+	  return false;
+	log_info("[vehicle_alarm_begin_algo]%s&%s %f,%f (%s)(%s)--(%.2f,%.2f)(%.2f,%.2f)",card1.c_str(),card2.c_str(),arg_1,arg_2,l_1.to_string().c_str(),l_2.to_string().c_str(),p_1.x,p_1.y,p_2.x,p_2.y);
+	if (point::eq(arg_1,0x12345678,1e-10) || point::eq(arg_2,0x12345678,1e-10))
+	{
+		log_info("[vehicle_alarm_invalid]%s&%s  %f,%f",card1.c_str(),card2.c_str(),arg_1,arg_2);
+		return false;
+	}
+	if (!point::eq(arg_1,0,1e-10))
+	  if (fabs(fabs(arg_1-arg_2)-3.141593)< 0.000005)
+	  {
+		  log_info("[vehicle_alarm_opposite]%s&%s",card1.c_str(),card2.c_str());
+		  return false;
+	  }
+	if (point::eq(arg_1,arg_2,1e-10))
+	{
+		double arg = std::arg(std::complex<double>(p_1.x,p_1.y)-std::complex<double>(p_2.x,p_2.y));
+		if (!(fabs(fabs(arg)-fabs(arg_1))<1e-10 || fabs(fabs(arg)+fabs(arg_2)-3.141593)< 0.000005))
+		{
+			log_info("[vehicle_alarm_parallel]%s&%s  %f,%f()",card1.c_str(),card2.c_str(),arg,arg_1);
+			return false;
+		}
+	}
+	if(!point::eq(arg_1,arg_2,1e-10))
+	{
+		point p = l_1.line::crossing(l_2);
+		if (p==l_1[1] || p==l_2[1])
+		{
+			log_info("[vehicle_alarm_point]%s&%s",card1.c_str(),card2.c_str());
+			return true;
+		}
+		double arg1 = std::arg(std::complex<double>(p.x,p.y)-std::complex<double>(l_1[1].x,l_1[1].y));
+		double arg2 = std::arg(std::complex<double>(p.x,p.y)-std::complex<double>(l_2[1].x,l_2[1].y));
+		if (fabs(fabs(arg1-arg_1)-3.141593)<0.000005 && fabs(fabs(arg2-arg_2)-3.141593)<0.000005)
+		{
+			log_info(0,"[vehicle_alarm_backfired]%s&%s",card1.c_str(),card2.c_str());
+			return false;
+		}
+	}
+	log_info("[vehicle_alarm_end]%s&%s  %f,%f",card1.c_str(),card2.c_str(),arg_1,arg_2);
+	return true;
+}
+

+ 8 - 0
mine_business.h

@@ -3,8 +3,11 @@
 #include <atomic>
 #include <ctime>
 #include <memory>
+#include "point.h"
 class staffer_num_business;
 class reverse_alarm_business;
+class rear_end_collision_prevented_business;
+class card_location_base;
 struct mine_business
 {
 	static mine_business *inst();
@@ -14,11 +17,16 @@ struct mine_business
 //天线反向功能
 	void load();
 	void make_reverse_condition(uint64_t type,uint32_t id,int32_t antid,uint32_t ct,uint64_t tof,uint32_t sid);
+//车辆防追尾告警
+	void put(const std::shared_ptr<card_location_base>&);
+	void make_arg(uint64_t cid,const point &p,uint64_t t);
 private:
 	mine_business();
 	void handle_reverse_alarm();
 	void record_staffer_num();
+	void handle_rear_end();
 	std::unique_ptr<staffer_num_business> m_staffer_num_ptr;
 	std::unique_ptr<reverse_alarm_business> m_reverse_alarm_ptr;
+	std::unique_ptr<rear_end_collision_prevented_business> m_rear_ended_ptr;
 };
 #endif

+ 1 - 1
point.h

@@ -58,7 +58,7 @@ struct point
 	{
 		return fabs(l-r)<=deta;
 	}
-	
+
 	bool empty()const
 	{
 		return x==0 && y==0 && z==0;

+ 50 - 0
ya_setting.cpp

@@ -0,0 +1,50 @@
+#include "ya_setting.h"
+#include "db/db_api/CDBSingletonDefine.h"
+#include "log.h"
+
+SSys_setting CYaSetting::m_sys_setting;
+/*
+* 从数据库的dat_setting表初始化系统阈值,
+* 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
+*/
+bool CYaSetting::Init_sys_setting()
+{
+	std::string Error;
+	YADB::CDBResultSet DBRes;
+	std::string sql = "select setting_id, name, type, value from dat_setting;";
+	sDBConnPool.Query(sql.c_str(),DBRes,Error);
+	int nCount = DBRes.GetRecordCount( Error );
+	if (nCount > 0)
+	{
+		while ( DBRes.GetNextRecod(Error) )
+		{
+			std::string strVal = "";
+			std::string val="";
+			DBRes.GetField("name",strVal, Error );
+#define D_GetValue(K,N,X,PS) \
+			if(strVal==N)\
+			{DBRes.GetField("value",val, Error);\
+			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,"人员井下超时")
+			D_GetValue(m_sys_setting.over_time_vehicle,"over_time_vehicle",60,"车辆井下超时")
+			D_GetValue(m_sys_setting.over_speed,"over_speed",1,"车辆超速限值")
+			D_GetValue(m_sys_setting.att_starttime_offset_staff,"att_starttime_offset_staff",60,"考勤开始时间向前偏移分钟数")
+			D_GetValue(m_sys_setting.att_endtime_offset_staff,"att_endtime_offset_staff",60,"车辆考勤开始时间向前偏移分钟数")
+			D_GetValue(m_sys_setting.att_starttime_offset_vehicle,"att_starttime_offset_vehicle",60,"车辆考勤结束时间向后偏移分钟数")
+			D_GetValue(m_sys_setting.att_endtime_offset_vehicle,"att_endtime_offset_vehicle",60,"车辆考勤结束时间向后偏移分钟数")
+			D_GetValue(m_sys_setting.att_person_thre_hour,"att_person_thre_hour",60*60,"")
+			D_GetValue(m_sys_setting.rear_end_d,"rear_end_distance",1,"")
+			D_GetValue(m_sys_setting.rear_end_t,"rear_end_time",1,"")
+			D_GetValue(m_sys_setting.geofault_warn_dis,"geofault_warn",1,"")
+#undef D_GetValue
+		}
+		log_info("init_setting:rear_end_d:%f,t:%ld,person:%u,v:%u,tp:%u,tv:%u,s:%f",m_sys_setting.rear_end_d,m_sys_setting.rear_end_t,
+					m_sys_setting.over_count_person,m_sys_setting.over_count_vehicle,m_sys_setting.over_time_person,m_sys_setting.over_time_vehicle,m_sys_setting.over_speed);
+	}
+
+    return true;
+}

+ 60 - 0
ya_setting.h

@@ -0,0 +1,60 @@
+#ifndef _YASL_SETTINS_H
+#define _YASL_SETTINS_H
+
+#include <time.h>
+#include <map>
+
+// 系统设置,,读取DB.dat_setting
+struct  SSys_setting // system_limit_setting
+{
+	unsigned int over_count_person; // 井下人员超员
+	unsigned int over_count_vehicle; // 井下车辆超员
+	unsigned int over_time_person; // 井下人员超时
+	unsigned int over_time_vehicle; // 井下车辆超时
+	double over_speed; // 井下车辆超速
+
+	// lihongzhen  2017/8/18 考勤偏移时间
+	int att_starttime_offset_staff;
+	int att_endtime_offset_staff;
+	int att_starttime_offset_vehicle;
+	int att_endtime_offset_vehicle; 
+	uint64_t att_person_thre_hour;
+	//车辆防追尾配置数据
+	double rear_end_d;
+	time_t rear_end_t;
+	double geofault_warn_dis;
+    SSys_setting()
+    {
+        init();
+    }
+    void init()
+    {
+        over_count_person = 1000;
+        over_count_vehicle = 100;
+        over_speed = 30;
+        over_time_person = 36000;
+        over_time_vehicle = 18000;
+        att_endtime_offset_staff = 600;
+        att_endtime_offset_vehicle = 600;
+        att_starttime_offset_staff = 900;
+        att_starttime_offset_vehicle = 600;
+        att_person_thre_hour = 0;
+        rear_end_d = 0;
+        rear_end_t = 0;
+        geofault_warn_dis=50; 
+    }
+};
+
+class CYaSetting
+{
+public:
+    /*
+    * 从数据库的dat_setting表初始化系统阈值,
+    * 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
+    */
+    static SSys_setting m_sys_setting;
+    static bool Init_sys_setting();
+
+};
+
+#endif