Browse Source

增加反向告警和追尾告警,修复了vim造成得tab问题

lixioayao 6 years ago
parent
commit
b3344efd35
9 changed files with 579 additions and 545 deletions
  1. 1 2
      card.cpp
  2. 1 0
      card_base.h
  3. 4 5
      card_car.cpp
  4. 1 1
      card_car.h
  5. 25 16
      event.cpp
  6. 5 4
      event.h
  7. 532 517
      mine_business.cpp
  8. 1 0
      mine_business.h
  9. 9 0
      net-service.cpp

+ 1 - 2
card.cpp

@@ -407,8 +407,7 @@ 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)
 {
-//	if(c->on_timer())
-//		mine_business::inst()->put(c);
+	c->get_card();
 	return true;	
 }
 

+ 1 - 0
card_base.h

@@ -93,6 +93,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
     virtual std::shared_ptr<area_tool> get_area_tool()=0;
     virtual int get_vehicle_category_id(){return -1;}
     virtual int get_workline(){return -1;}
+	virtual void get_card(){};
 
     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 );

+ 4 - 5
card_car.cpp

@@ -137,11 +137,10 @@ 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;
+}
+void car::get_card()
+{
+	mine_business::inst()->put(shared_from_this());
 }
 loc_point car::getSmoothPoint()
 {

+ 1 - 1
card_car.h

@@ -19,7 +19,6 @@ struct car:card_location_base,card_area
 {
 	int m_vehicle_category_id=0;
     int m_vehicle_type_id=0;
-    //double m_acc =0;
 
 public:
 
@@ -45,6 +44,7 @@ public:
     }
 
 	virtual void set_area_info(int mapid,double scale,int areaid,uint64_t t,int type);
+	virtual void get_card();
 private:
 	void handle_three_rates(const point &pt);
 	void on_timer();

+ 25 - 16
event.cpp

@@ -26,7 +26,7 @@ struct Event
     Event(OBJECT_TYPE oid)
         :m_oid(oid)
     {}
-    void handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f);
+    void handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f,const std::string &desc="");
     virtual std::shared_ptr<ya_event> on_message(EVENT_TYPE et,uint64_t id,bool f)=0;
     std::shared_ptr<ya_event> create_event(std::string obj_id,EVENT_TYPE ev_type);
     virtual ~Event(){}
@@ -73,9 +73,9 @@ void event_tool::make_event_object()
     m_map[OT_CARD] = std::make_shared<card_event>();
 }
 
-void event_tool::handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f)
+void event_tool::handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f,const std::string &desc/*=""*/)
 {
-    m_map[ot]->handle_alarm_event(et,id,limit_value,cur_value,f);
+    m_map[ot]->handle_alarm_event(et,id,limit_value,cur_value,f,desc);
 }
 
 std::shared_ptr<ya_event> Event::create_event(std::string obj_id,EVENT_TYPE ev_type)
@@ -87,7 +87,7 @@ std::shared_ptr<ya_event> Event::create_event(std::string obj_id,EVENT_TYPE ev_t
     return ev_ptr;
 }
 
-void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f)
+void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f,const std::string &desc/*=""*/)
 {
     std::shared_ptr<ya_event> ev_ptr = nullptr;
     uint64_t eid = event_list::to_list_id(et,m_oid,id);
@@ -102,9 +102,17 @@ void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,doub
         }
         else
         {
-            ev_ptr=on_message(et,id,f);
+            uint64_t _id=id;
+            log_info("Create_Event:desc[%s],id:%d,et:%d",desc.c_str(),id,et);
+            if(et == ET_READER_LOCATION_REVERSAL&&!desc.empty())
+            {
+                std::string cardid = desc.substr(0,desc.find_first_of('&'));
+                _id = tool_other::card_id_to_u64(cardid);
+            }
+            ev_ptr=on_message(et,_id,f);
             ev_ptr->m_cur_value=cur_value;
             ev_ptr->m_limit_value=limit_value;
+            ev_ptr->m_desc=desc;
             //保存告警信息
             event_list::instance()->add(eid,ev_ptr);
         }
@@ -117,6 +125,7 @@ void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,doub
             event_ptr->m_cur_time = std::chrono::system_clock::now();
             event_ptr->m_status = ES_END;
             event_ptr->m_cur_value = cur_value;
+            ev_ptr->m_desc=desc;
             event_ptr->m_is_sent=false;
             ev_ptr=event_ptr;
         }
@@ -200,17 +209,17 @@ std::shared_ptr<ya_event> card_event::on_message(EVENT_TYPE et,uint64_t id,bool
         event_ptr->x = card_ptr->x;
         event_ptr->y = card_ptr->y;
         event_ptr->m_is_display = card_ptr->m_display;
-        //const auto lm = card_ptr->getLandmark();
-		auto area_info_map = card_ptr->get_area_tool()->m_area_info;
-		if(!area_info_map.empty())
-		{
-			auto lm = area_info_map.begin()->second;
-			event_ptr->m_area_id = std::get<0>(lm);
-       		event_ptr->m_map_id = card_ptr->get_area_tool()->m_mapid;
-       		event_ptr->m_landmarkid = std::get<1>(lm);
-       		event_ptr->m_landmarkdist = std::get<3>(lm);
-       		event_ptr->m_landmarkdirect = std::get<2>(lm);
-		}
+
+        auto area_info_map = card_ptr->get_area_tool()->m_area_info;
+        if(!area_info_map.empty())
+        {
+            auto lm = area_info_map.begin()->second;
+            event_ptr->m_area_id = std::get<0>(lm);
+            event_ptr->m_map_id = card_ptr->get_area_tool()->m_mapid;
+            event_ptr->m_landmarkid = std::get<1>(lm);
+            event_ptr->m_landmarkdist = std::get<3>(lm);
+            event_ptr->m_landmarkdirect = std::get<2>(lm);
+        }
     }
     return event_ptr;
 }

+ 5 - 4
event.h

@@ -53,8 +53,9 @@ enum EVENT_TYPE{ // 事件类型
 
     ET_CARD_MOTIONLESS=32,//静止不动告警
     ET_READER_POWER_BY_BATTERY=33,//分站电池:1为电池供电,0为交流电供电,当电池供电需要告警
+	ET_VEHICLE_REAR_END=36,
     ET_VEHICLE_NEAR_GEOFAULT=38,//靠近断层告警
-
+	ET_READER_LOCATION_REVERSAL=39,
     CARD_EVENT_COUNT_MAX
 };
 
@@ -140,11 +141,11 @@ class Event;
 struct event_tool
 {
 	template <class UnaryPredicate>
-	void handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,UnaryPredicate p)
+	void handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,UnaryPredicate p,const std::string &desc="")
 	{
-		handle_event(ot,et,id,limit_value,cur_value,p());
+		handle_event(ot,et,id,limit_value,cur_value,p(),desc);
 	}
-	void handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f);
+	void handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double limit_value,double cur_value,bool f,const std::string &desc="");
 	static event_tool * instance();
 private:
     event_tool()

File diff suppressed because it is too large
+ 532 - 517
mine_business.cpp


+ 1 - 0
mine_business.h

@@ -22,6 +22,7 @@ struct mine_business
 //车辆防追尾告警
 	void put(const std::shared_ptr<card_location_base>&);
 	void make_arg(uint64_t cid,const point &p,uint64_t t);
+	void clear_vehicle();
 private:
 	mine_business();
 	void handle_reverse_alarm();

+ 9 - 0
net-service.cpp

@@ -31,8 +31,17 @@ net_service::~net_service()
 
 void net_service::on_timer()
 {
+	static int version = -1;
 	visit_site_status vss;
 	sit_list::instance()->accept(vss);
+	int v = card_list::instance()->version();
+	if(v != version)
+	{
+		version=v;
+		mine_business::inst()->clear_vehicle();
+		card_list_visit clv;
+		card_list::instance()->accept(clv);
+	}
 	mine_business::inst()->run_business();
 }