Browse Source

Merge branch 'master' of http://local.beijingyongan.com:3000/linux-dev/ya-serv

chensongchao 6 years ago
parent
commit
5700b07a70

+ 6 - 1
card_base.cpp

@@ -21,7 +21,7 @@
 
 extern config_file config;
 
-card_location_base::card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid)
+card_location_base::card_location_base(const std::string&type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid)
 	:card(id,dis,t,deptid,level_id,cid)
 {
     select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool);
@@ -70,6 +70,11 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 	}
 	else
 	{
+		if(site_ptr->is_path_empty())
+		{
+			log_warn("接收到分站%d的数据,CT=%d,但是分站路径为空",site_ptr->id(),loc.m_card_ct);
+		}
+
 		m_message_handle->on_message(loop,loc,is_history);
 	}
 }

+ 1 - 1
card_base.h

@@ -71,7 +71,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 	std::unique_ptr<location_card> m_his_location_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 );
+    card_location_base(const std::string&type,uint32_t id,uint16_t dis,int16_t t,int32_t,int32_t,uint32_t );
 
 	virtual void do_business(const std::shared_ptr<site>&site,const point &pt,double acc)=0;
 	virtual void on_timer()=0;

+ 1 - 1
card_car.cpp

@@ -11,7 +11,7 @@
 #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,
+car::car(const 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)
 	,m_vehicle_category_id(categoryid)

+ 1 - 1
card_car.h

@@ -22,7 +22,7 @@ struct car:card_location_base,card_area
 
 public:
 
-    car(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
+    car(const 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);
 	~car();
 

+ 23 - 23
card_message_handle.cpp

@@ -14,13 +14,13 @@ struct one_ct_message_handle
 {
 	static loc_tool_main m_loc_tool;
 	ev::timer m_min_timer,m_max_timer;
-    //loc_message.
+	//loc_message.
 	std::vector<loc_message> m_msg_list;
 	card_location_base*m_card;
 	const algo_config*m_ac=nullptr;
 	int  m_ct;
 	bool m_min_timeout=false;
-    ev::dynamic_loop * m_loop = nullptr;
+	ev::dynamic_loop * m_loop = nullptr;
 	one_ct_message_handle(card_location_base*card)
 	{
 		m_card=card;
@@ -42,7 +42,7 @@ struct one_ct_message_handle
 		{
 			m_max_timer.stop();
 			calc_location();
-            return;
+			return;
 		}
 		m_min_timeout=true;
 	}
@@ -53,23 +53,23 @@ struct one_ct_message_handle
 		calc_location();
 	}
 
-    void set(ev::dynamic_loop * loop)
-    {
-        m_loop = loop;
+	void set(ev::dynamic_loop * loop)
+	{
+		m_loop = loop;
 
-        m_min_timer.set(*m_loop);
-	    m_min_timer.set<one_ct_message_handle,&one_ct_message_handle::on_min_timer>(this);
-	    m_max_timer.set(*m_loop);
-	    m_max_timer.set<one_ct_message_handle,&one_ct_message_handle::on_max_timer>(this);
-    }
+		m_min_timer.set(*m_loop);
+		m_min_timer.set<one_ct_message_handle,&one_ct_message_handle::on_min_timer>(this);
+		m_max_timer.set(*m_loop);
+		m_max_timer.set<one_ct_message_handle,&one_ct_message_handle::on_max_timer>(this);
+	}
 
 	void on_message(ev::dynamic_loop *loop,const message_locinfo&loc)
 	{
-        if(m_loop == nullptr && loop!=nullptr)
-            set(loop);
-        else if(loop == nullptr)
-          return;
-   		if(!m_msg_list.empty()&& m_ct!=loc.m_card_ct)
+		if(m_loop == nullptr && loop!=nullptr)
+			set(loop);
+		else if(loop == nullptr)
+			return;
+		if(!m_msg_list.empty()&& m_ct!=loc.m_card_ct)
 		{
 			m_msg_list.clear();
 		}
@@ -85,10 +85,10 @@ struct one_ct_message_handle
 			m_ct=loc.m_card_ct;
 			m_ac=&s->config();
 			m_min_timeout=false;
-            //这里构造loc_message 保存数据
+			//这里构造loc_message 保存数据
 			m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
-							loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
-							loc.m_sync_ct,loc.m_rssi));
+						loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
+						loc.m_sync_ct,loc.m_rssi));
 
 			//启动本CT的最小、最大两个定时器
 			m_min_timer.start(m_ac->min_wait_time);
@@ -97,8 +97,8 @@ struct one_ct_message_handle
 		}
 
 		m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
-						loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
-						loc.m_sync_ct,loc.m_rssi));
+					loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
+					loc.m_sync_ct,loc.m_rssi));
 
 		if(m_min_timeout && (int)m_msg_list.size()>=m_ac->best_msg_cnt)
 		{
@@ -107,7 +107,7 @@ struct one_ct_message_handle
 		}
 	}
 
-    void calc_location()
+	void calc_location()
 	{
 		auto v = m_msg_list;
 		if(v.empty())
@@ -119,7 +119,7 @@ struct one_ct_message_handle
 
 		std::vector<point> rc=std::move(m_loc_tool.calc_location(v));
 		log_info("calc_location:%d size:%d",m_card->m_id,rc.size());
-        
+
 		if(!rc.empty()) m_card->on_location(std::move(rc),v);
 
 		reset();

+ 4 - 2
client.cpp

@@ -9,7 +9,7 @@ int main()
 {
 	int sock=zio::build_stream();
 
-	if(zio::connect(sock,"127.0.0.1",4000))
+	if(zio::connect(sock,"127.0.0.1",9001))
 	//if(zio::connect(sock,"192.168.8.116",4000))
 	{
 		return -1;
@@ -21,7 +21,9 @@ int main()
 	int count=0x400+2;
 	char buf[8192];
 	uint64_t time;
-#if 0
+#if 1
+
+	///socket.io/?EIO=4&transport=websocket&t=1551320786
 
 	for(int i=0;i<8000;i++)
 	{

+ 2 - 2
common.h

@@ -118,10 +118,10 @@ enum EVENT_TYPE{ // 事件类型
     ET_CARD_DRIVINGFACE_WARNING_AREA = 28, //掘进面靠近预警区域告警
     ET_CARD_MOTIONLESS=32,//静止不动告警
     ET_READER_POWER_BY_BATTERY=33,//分站电池:1为电池供电,0为交流电供电,当电池供电需要告警
-	ET_VEHICLE_REAR_END=36,
+	ET_VEHICLE_REAR_END=36,//车辆防追尾告警
 	ET_COALING_DRIVING_DRIVER = 37,//工作面(采煤面和掘进面)司机与车卡告警;
     ET_VEHICLE_NEAR_GEOFAULT=38,//靠近断层告警
-	ET_READER_LOCATION_REVERSAL=39,
+	ET_READER_LOCATION_REVERSAL=39,//掘进面天线反向告警
     CARD_EVENT_COUNT_MAX
 };
 

+ 1 - 1
db/Makefile.am

@@ -1,6 +1,6 @@
 AUTOMAKE_OPTIONS=foreign
 
-noinst_LIBRARIES=libyadb.a
+lib_LIBRARIES=libyadb.a
 
 
 CXXFLAGS=-fPIC -g

+ 3 - 7
db/db_tool.cpp

@@ -32,11 +32,7 @@ namespace db_tool
     {
         char sql[LENGTH_SQL] = {0};
 
-        std::string call("add_att_staff");
-        if(card_ptr->is_vehicle())//车卡
-        {
-            call="add_att_vehicle";
-        }
+        std::string call(card_ptr->is_person()?"add_att_staff":"add_att_vehicle");
 
         auto mine_tool_ptr = card_ptr->get_mine_tool();
 
@@ -50,7 +46,7 @@ namespace db_tool
         std::string start_str = tool_time::to_str(start);
         std::string end_str = tool_time::to_str(end);
 		auto map_area_info = card_ptr->get_area_tool()->m_area_info;
-        int landmarkid,landmarkdirect=0;
+        int landmarkid=0,landmarkdirect=0;
         double landmarkdist=0;
 		if(!map_area_info.empty())
 		{
@@ -60,7 +56,7 @@ namespace db_tool
        		landmarkdist=std::get<3>(lm);
 		}
 
-        sprintf(sql, "CALL %s(%s, %d, '%s', '%s', %d, %d, %.3f);", call.c_str(),
+        sprintf(sql, "CALL %s(%s, %d, '%s', '%s', %d, %d, %.3lf);", call.c_str(),
                type_id_to_str(card_ptr->m_type,card_ptr->m_id).c_str(),
                 card_ptr->m_cid, start_str.c_str(), end_str.c_str(),
                 landmarkid, landmarkdirect, landmarkdist);

+ 4 - 4
event.cpp

@@ -28,7 +28,7 @@ struct Event
     {}
     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);
+    std::shared_ptr<ya_event> create_event(const std::string&obj_id,EVENT_TYPE ev_type);
     virtual ~Event(){}
 };
 struct mine_event:Event
@@ -78,7 +78,7 @@ void event_tool::handle_event(OBJECT_TYPE ot,EVENT_TYPE et,uint64_t id,double li
     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)
+std::shared_ptr<ya_event> Event::create_event(const std::string&obj_id,EVENT_TYPE ev_type)
 {
     auto ev_ptr = std::make_shared<ya_event>(tool_time::now_to_us());
     ev_ptr->m_ev_type = ev_type;
@@ -115,9 +115,9 @@ void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,doub
                 ev_ptr->m_limit_value=limit_value;
                 ev_ptr->m_desc=desc;
                 ev_ptr->m_id=eid;
+                //保存告警信息
+                event_list::instance()->add(eid,ev_ptr);
             }
-            //保存告警信息
-            event_list::instance()->add(eid,ev_ptr);
         }
     }
     else

+ 1 - 1
main.cpp

@@ -161,7 +161,7 @@ void usage(char ** argv)
     }
     else if(cmd == "--version" || cmd == "-v")
     {
-        printf("yals (采集程序) 2.0.0\n");
+        printf("yals (采集程序) 2.0.0 build 11\n");
     }
     else
     {

+ 4 - 4
module_service/area_business_count_checker.cpp

@@ -46,7 +46,7 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 	{
 		a->m_area->m_person_count ++ ;
         int pc=a->m_area->m_person_count.load();
-		if (!a->m_area->m_event_person_count && pc > a->m_area->m_limit_person_count)
+		if (pc > a->m_area->m_limit_person_count)
 		{
 			a->m_area->m_event_person_count = true;
 			EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
@@ -60,7 +60,7 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		a->m_area->m_vehicle_count ++ ;
         int vc=a->m_area->m_vehicle_count.load();
 		log_info("area_id:%d,v_count:%d",a->m_area->m_id,vc);
-		if (vc > a->m_area->m_limit_vehicle_count && !a->m_area->m_event_vehicle_count)
+		if (vc > a->m_area->m_limit_vehicle_count)
 		{
 			a->m_area->m_event_vehicle_count = true;
 			EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
@@ -95,7 +95,7 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
 		curVal = a->m_area->m_person_count.load();
 		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 ;
-		if(tmp_event && curVal < limitVal)
+		if(tmp_event && curVal <= limitVal)
 		{
 			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"
@@ -110,7 +110,7 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
 		curVal = a->m_area->m_vehicle_count.load();
 		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 ;
-		if(tmp_event && curVal < limitVal)
+		if(tmp_event && curVal <= limitVal)
 		{
 			a->m_area->m_event_vehicle_count = false;
 			log_info("area_business_count_checker::on_leave :Cancel Event OVER_COUNT=%d AreaId=%d,Limit=%d,CurNum=%d"

+ 4 - 7
module_service/area_business_geofault.cpp

@@ -95,13 +95,10 @@ void area_business_geofault::on_hover(const std::shared_ptr<area_hover>&area_hov
     {
         ptr_temp->m_near_geofault_count=_geofault_count_limit;
 
-        if(!ptr_temp->m_is_warning)
-        {
-            ptr_temp->m_is_warning = true;
-            uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-            event_tool::instance()->handle_event(OT_CARD, ET_VEHICLE_NEAR_GEOFAULT, id,
-                                                 CYaSetting::m_sys_setting.geofault_warn_dis, dist, true);
-        }
+        ptr_temp->m_is_warning = true;
+        uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+        event_tool::instance()->handle_event(OT_CARD, ET_VEHICLE_NEAR_GEOFAULT, id,
+                                             CYaSetting::m_sys_setting.geofault_warn_dis, dist, true);
     }
 
     //确定正常

+ 1 - 1
module_service/area_business_person_dwell_checker.cpp

@@ -34,7 +34,7 @@ void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hov
 	double limit_val = a->m_area->m_limit_person_second;
 	double cur_val = ( tool_time::now_to_seconds() - a->m_enter_time / 1000);
 	EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
-	if (!c->get_event_flag(evType) && limit_val < cur_val)
+	if (limit_val < cur_val)
     {
         c->set_event_flag(evType);
         uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);

+ 6 - 6
module_service/area_business_speed_checker.cpp

@@ -65,11 +65,11 @@ void area_business_speed_checker::on_hover(const std::shared_ptr<area_hover>&are
 
     auto ptr_temp = static_cast<over_speed_data*>(ptr.get());
     double limit = ptr_temp->m_limit_speed;
-
+    int _id = area_hover_ptr->id();
     if(limit < card_ptr->m_speed)//超速
     {
         ptr_temp->m_normal_speed_count=0;
-        log_info("[speed_checker:on_hover_1]%d %.2f,%.2f",card_ptr->m_id,limit,card_ptr->m_speed);
+        log_info("[speed_checker:on_hover_1]%d %.2f,%.2f areaid:%d",card_ptr->m_id,limit,card_ptr->m_speed,_id);
         if(!ptr_temp->m_is_warning && ++ptr_temp->m_over_speed_count>=SPEED_COUNT_LIMIT)
         {
             EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;
@@ -77,14 +77,14 @@ void area_business_speed_checker::on_hover(const std::shared_ptr<area_hover>&are
             card_ptr->set_event_flag(ev_type);
             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, limit, card_ptr->m_speed, true);
-            log_info("[speed_checker:on_hover_true]%d",card_ptr->m_id);
+            log_info("[speed_checker:on_hover_true]%d,id:%d",card_ptr->m_id,_id);
         }
 
     }
     else//速度正常
     {
         ptr_temp->m_over_speed_count=0;
-        log_info("[speed_checker:on_hover_2]%d %.2f,%.2f",card_ptr->m_id,limit,card_ptr->m_speed);
+        log_info("[speed_checker:on_hover_2]%d %.2f,%.2f id:%d",card_ptr->m_id,limit,card_ptr->m_speed,_id);
         if(ptr_temp->m_is_warning && ++ptr_temp->m_normal_speed_count>=SPEED_COUNT_LIMIT)
         {
             EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;
@@ -92,7 +92,7 @@ void area_business_speed_checker::on_hover(const std::shared_ptr<area_hover>&are
             card_ptr->set_event_flag(ev_type,0);
             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, limit, card_ptr->m_speed, false);
-            log_info("[speed_checker:on_hover_false]%d",card_ptr->m_id);
+            log_info("[speed_checker:on_hover_false]%d id:%d",card_ptr->m_id,_id);
         }
     }
 
@@ -117,7 +117,7 @@ void area_business_speed_checker::on_leave(const std::shared_ptr<area_hover>&are
         double limit = ptr_temp ->m_limit_speed;
         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, limit, card_ptr->m_speed, ptr_temp->m_is_warning=false);
-        log_info("[speed_checker:on_leave_false]%d",card_ptr->m_id);
+        log_info("[speed_checker:on_leave_false]%d,id:%d",card_ptr->m_id,area_hover_ptr->id());
     }
 }
 

+ 1 - 1
module_service/module_web.cpp

@@ -138,7 +138,7 @@ void module_web::_delete_end(std::vector<std::shared_ptr<ya_event>>& arr)
         }
     }
 
-    if(todelete.size())
+    if(!todelete.empty())
     {
         event_list::instance()->remove(todelete);
     }

+ 4 - 4
tool_time.h

@@ -46,7 +46,7 @@ public:
     {
         char _time[25] = {0};
         time_t tt = std::chrono::system_clock::to_time_t(time);
-        struct tm local_time;
+        struct tm local_time={0};
         localtime_r(&tt, &local_time);
         strftime(_time, 22, "%Y-%m-%d %H:%M:%S", &local_time);
 
@@ -61,10 +61,10 @@ public:
 		return now*1000;
 	}
     //"%Y-%m-%d %H:%M:%S"
-    static time_t to_time(std::string str)
+    static time_t to_time(const std::string&str)
     {
         time_t t_;
-        tm tm_;
+        tm tm_={0};
         strptime(str.c_str(), "%Y-%m-%d %H:%M:%S", &tm_); //将字符串转换为tm时间
         t_ = mktime(&tm_); //将tm时间转换为秒时间
 
@@ -72,7 +72,7 @@ public:
     }
 
     ////"%d-%02d-%02d %02d:%02d:%02d.%03d"
-    static std::chrono::system_clock::time_point to_time_ex(std::string str)
+    static std::chrono::system_clock::time_point to_time_ex(const std::string&str)
     {
         uint64_t pos = str.length()-3;
 

+ 11 - 0
znet.cpp

@@ -558,3 +558,14 @@ service_handle*service_handle::instance(service_callback*sc)
 	return &_impl;
 }
 
+
+
+
+
+
+
+
+
+
+
+