فهرست منبع

add site coverage and net log function

zhuyf 3 سال پیش
والد
کامیت
3e15c1fb73
9فایلهای تغییر یافته به همراه229 افزوده شده و 114 حذف شده
  1. 131 100
      ant.cpp
  2. 14 0
      ant.h
  3. 41 0
      card_base.cpp
  4. 1 0
      card_base.h
  5. 2 12
      his_location.cpp
  6. 3 0
      module_service/module_traffic_light.h
  7. 26 0
      module_service/module_traffic_light_manager.cpp
  8. 8 2
      net-service.cpp
  9. 3 0
      znet.cpp

+ 131 - 100
ant.cpp

@@ -457,106 +457,137 @@ void sit_list::read_ant_path(int id)
 
 void sit_list::init_site(const std::string &ids /*=""*/)
 {
-     std::string sql = "SELECT reader_id, reader_type_id, dat_reader.map_id, \
-             area_id, device_type_id, dimension, dat_map.scale,need_power_alarm \
-			 ,x,y, pdoa_offset, pdoa_direction, isSpecial, down_stream_idx \
-             FROM dat_reader, dat_map where \
-             dat_reader.map_id=dat_map.map_id and state=0";
-
-     if(ids.empty())
-     {
-         sql.append(";");
-     }
-     else
-     {
-         sql.append(" AND reader_id in (");
-         sql+=ids;
-         sql.append(");");
-
-         std_debug("增加或修改分站 sql=%s", sql.c_str());
-         log_info("增加或修改分站 sql=%s", sql.c_str());
-     }
-
-     std::string Error;
-     YADB::CDBResultSet DBRes;
-     sDBConnPool.Query(sql.c_str(),DBRes,Error);
-     int nCount = DBRes.GetRecordCount( Error );
-     if (nCount < 1)
-     {
-         log_error("增加或修改失败,数据库中找不到: 分站id=%s", ids.c_str());
-         return ;
-     }
-
-     log_info( "init_site. The record count=%ld\n", nCount );
-
-     while ( DBRes.GetNextRecod(Error) )
-     {
-         int reader_id  = 0;
-         DBRes.GetField( "reader_id",reader_id, Error );
-
-         auto site_ptr=sit_list::instance()->get(reader_id);
-         if(nullptr==site_ptr)
-         {
-             site_ptr = std::make_shared<site>(reader_id);
-             sit_list::instance()->add(reader_id,site_ptr);
-         }
-
-         int reader_type_id  = 0;
-         DBRes.GetField( "reader_type_id",reader_type_id, Error );
-
-         int map_id  = 0;
-         DBRes.GetField( "map_id",map_id, Error );
-
-         int area_id  = 0;
-         DBRes.GetField( "area_id",area_id, Error );
-
-         int device_type_id  = 0;
-         DBRes.GetField( "device_type_id",device_type_id, Error );
-
-         int dimension  = 0;
-         DBRes.GetField( "dimension",dimension, Error );
-
-         double scale= 0;
-         DBRes.GetField( "scale",scale, Error );
-
-         int power_alarm  = 0;
-         DBRes.GetField( "need_power_alarm",power_alarm, Error );
-
-		 int down_stream_idx = 0;
-		 DBRes.GetField("down_stream_idx", down_stream_idx, Error);
-
-         site_ptr->m_reader_type_id = reader_type_id;
-         site_ptr->m_map_id = map_id;
-         site_ptr->m_area_id = area_id;
-         site_ptr->m_power_check_enable=power_alarm;
-         site_ptr->m_device_type_id = device_type_id;
-         site_ptr->m_num_dims = dimension;
-         site_ptr->m_scale = scale;
-		 site_ptr->m_down_stream_idx = down_stream_idx;
-         site_ptr->create_area();
-
-         double x = 0, y = 0;
-         DBRes.GetField("x", x, Error);
-         DBRes.GetField("y", y, Error);
-         site_ptr->x = x;
-         site_ptr->y = y;
-
-         double offset = 0.0;
-         DBRes.GetField("pdoa_offset", offset, Error);
-         site_ptr->m_pdoa_offset = offset;
-
-         int direction = 0;
-         if(DBRes.GetField("pdoa_direction", direction, Error)){
-            site_ptr->m_pdoa_direction = direction;
-         }
-
-         int special = 0;
-         if(DBRes.GetField("isSpecial", special, Error)){
-            site_ptr->m_special = special;
-         }
-
-		 log_info ("site_position: site=%d, x=%.2lf, y=%.2lf, area_id=%d, m_scale=%.2f, pdoa_offset=%.2f, pdoa_direction=%d, special=%d, device_type_id=%d", reader_id, x, y, area_id, scale, offset, direction, special, device_type_id);
-     }
+	/*std::string sql = "SELECT reader_id, reader_type_id, dat_reader.map_id, \
+	  area_id, device_type_id, dimension, dat_map.scale,need_power_alarm \
+	  ,x,y, pdoa_offset, pdoa_direction, isSpecial, down_stream_idx \
+	  FROM dat_reader, dat_map where \
+	  dat_reader.map_id=dat_map.map_id and state=0";*/
+	std::string sql = "SELECT r.reader_id, r.reader_type_id, r.map_id, r.area_id, r.device_type_id, r.dimension, m.scale, r.need_power_alarm, r.x, r.y, \
+					   r.pdoa_offset, r.pdoa_direction, r.isSpecial, r.down_stream_idx, \
+					   rc.plus_dist, rc.plus_card_id, rc.plus_occur_time, rc.minus_dist, rc.minus_card_id, rc.minus_occur_time \
+					   FROM dat_reader AS r \
+					   LEFT JOIN dat_map AS m ON r.map_id=m.map_id \
+					   LEFT JOIN his_reader_coverage AS rc ON r.reader_id = rc.reader_id \
+					   WHERE r.state=0;";
+
+	if(ids.empty())
+	{
+		sql.append(";");
+	}
+	else
+	{
+		sql.append(" AND reader_id in (");
+		sql+=ids;
+		sql.append(");");
+
+		std_debug("增加或修改分站 sql=%s", sql.c_str());
+		log_info("增加或修改分站 sql=%s", sql.c_str());
+	}
+
+	std::string Error;
+	YADB::CDBResultSet DBRes;
+	sDBConnPool.Query(sql.c_str(),DBRes,Error);
+	int nCount = DBRes.GetRecordCount( Error );
+	if (nCount < 1)
+	{
+		log_error("增加或修改失败,数据库中找不到: 分站id=%s", ids.c_str());
+		return ;
+	}
+
+	log_info( "init_site. The record count=%ld\n", nCount );
+
+	while ( DBRes.GetNextRecod(Error) )
+	{
+		int reader_id  = 0;
+		DBRes.GetField( "reader_id",reader_id, Error );
+
+		auto site_ptr=sit_list::instance()->get(reader_id);
+		if(nullptr==site_ptr)
+		{
+			site_ptr = std::make_shared<site>(reader_id);
+			sit_list::instance()->add(reader_id,site_ptr);
+		}
+
+		int reader_type_id  = 0;
+		DBRes.GetField( "reader_type_id",reader_type_id, Error );
+
+		int map_id  = 0;
+		DBRes.GetField( "map_id",map_id, Error );
+
+		int area_id  = 0;
+		DBRes.GetField( "area_id",area_id, Error );
+
+		int device_type_id  = 0;
+		DBRes.GetField( "device_type_id",device_type_id, Error );
+
+		int dimension  = 0;
+		DBRes.GetField( "dimension",dimension, Error );
+
+		double scale= 0;
+		DBRes.GetField( "scale",scale, Error );
+
+		int power_alarm  = 0;
+		DBRes.GetField( "need_power_alarm",power_alarm, Error );
+
+		int down_stream_idx = 0;
+		DBRes.GetField("down_stream_idx", down_stream_idx, Error);
+
+		site_ptr->m_reader_type_id = reader_type_id;
+		site_ptr->m_map_id = map_id;
+		site_ptr->m_area_id = area_id;
+		site_ptr->m_power_check_enable=power_alarm;
+		site_ptr->m_device_type_id = device_type_id;
+		site_ptr->m_num_dims = dimension;
+		site_ptr->m_scale = scale;
+		site_ptr->m_down_stream_idx = down_stream_idx;
+		site_ptr->create_area();
+
+		double x = 0, y = 0;
+		DBRes.GetField("x", x, Error);
+		DBRes.GetField("y", y, Error);
+		site_ptr->x = x;
+		site_ptr->y = y;
+
+		double offset = 0.0;
+		DBRes.GetField("pdoa_offset", offset, Error);
+		site_ptr->m_pdoa_offset = offset;
+
+		int direction = 0;
+		if(DBRes.GetField("pdoa_direction", direction, Error)){
+			site_ptr->m_pdoa_direction = direction;
+		}
+
+		int special = 0;
+		if(DBRes.GetField("isSpecial", special, Error)){
+			site_ptr->m_special = special;
+		}
+
+		double dist = 0;
+		DBRes.GetField("plus_dist", dist, Error);
+		site_ptr->m_coverage[0].m_distance = dist;
+
+		std::string ctx = "";
+		DBRes.GetField("plus_card_id", ctx, Error);
+		site_ptr->m_coverage[0].m_cid = ctx;
+
+		ctx.clear();
+		DBRes.GetField("plus_occur_time", ctx, Error);
+		site_ptr->m_coverage[0].m_time = tool_time::to_time(ctx);
+
+		dist = 0;
+		DBRes.GetField("plus_dist", dist, Error);
+		site_ptr->m_coverage[1].m_distance = dist;
+
+		ctx.clear();
+		DBRes.GetField("plus_card_id", ctx, Error);
+		site_ptr->m_coverage[1].m_cid = ctx;
+
+		ctx.clear();
+		DBRes.GetField("plus_occur_time", ctx, Error);
+		site_ptr->m_coverage[1].m_time = tool_time::to_time(ctx);
+
+		log_info ("site_position: site=%d, x=%.2lf, y=%.2lf, area_id=%d, m_scale=%.2f, pdoa_offset=%.2f, pdoa_direction=%d, special=%d, device_type_id=%d, plus_dist=%.2f, minus_dist=%.2f", reader_id, x, y, area_id, scale, offset, direction, special, device_type_id, site_ptr->m_coverage[0].m_distance, site_ptr->m_coverage[1].m_distance);
+	}
 }
 
 void sit_list::read_sit_list(int id)

+ 14 - 0
ant.h

@@ -62,6 +62,19 @@ struct algo_config
     double min_wait_time;
     double max_wait_time;
 };
+
+// 基站覆盖范围信息
+struct site_coverage_info{
+	double m_distance;	// 距离
+	std::string m_cid;	// 卡号
+	uint64_t m_time;	// 时间
+
+	site_coverage_info()
+		: m_distance(0.0)
+		, m_cid("")
+		, m_time(0)
+	{}
+};
 //
 struct ant :point
 {
@@ -140,6 +153,7 @@ struct site:point,std::enable_shared_from_this<site>
     bool m_path_empty;
 
 	std::array<int,32>	m_timeoff_count;
+	std::array<site_coverage_info, 2> m_coverage;	// 0为正向参数,1为负向参数
 	int  m_package_count=0;
     int  m_special = 0;
 	int  m_down_stream_idx = 0;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 41 - 0
card_base.cpp


+ 1 - 0
card_base.h

@@ -154,6 +154,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
     void put_traffic_light(card_pos& cp);
     void set_event_flag(EVENT_TYPE et,std::uint8_t f=1){m_event[et]=f;}
     bool get_event_flag(EVENT_TYPE et){return m_event[et];}
+	void do_site_coverage(message_pdoa_locinfo& loc);
 
     bool is_person() const;
     bool is_vehicle() const;

+ 2 - 12
his_location.cpp

@@ -88,18 +88,8 @@ bool location_card::line_changed(const point &pt)//,int &df)
     //change_flag为true,标识没有发生变化
     // if(change_flag)m_direct_index=0;
     log_info("his_location:line_changed:%d,%f,m_arg:%f,%s,%f,%f",m_cardid,arg,m_arg, change_flag?"same":"not same",m_arg-arg,dis);
-    //if(dis<0.5 && fabs(fabs(arg)+fabs(m_arg)-3.141593)< 0.000005)
-    //   return false;
-    //判断10次反向才做下一步动作
-    // if(fabs(fabs(arg)+fabs(m_arg)-3.141593)< 0.000005)
-    // {
-    //     if(++m_direct_index<=10)
-    //     {
-    //         df=1;return false;
-    //     }
-    // }
-    //return !point::eq(arg,m_arg,1e-10);
-    return !change_flag;
+    
+	return !change_flag;
 }
 
 bool location_card::is_speed_changed(const point& pt,uint64_t time)

+ 3 - 0
module_service/module_traffic_light.h

@@ -29,16 +29,19 @@ struct traffic_light: point{
     int m_stream;               // 上下行标志,1为上行,2为下行
     int m_area_id;
     int m_map_id;
+	int m_device_type_id;		// 红绿灯设备类型号
 
     std::shared_ptr<client> m_clt;
 
     traffic_light(): m_light_id(0), m_group_id(0), m_ip(""), m_state(0), m_port(0), m_phy_light_id(0), m_phy_direction(0), m_rec_time(0), m_special(0), m_direct_distance(0.0), m_stream(0), m_area_id(0), m_map_id(0)
     {
+		m_device_type_id=3;
         m_clt = nullptr;
     }
 
     traffic_light(double x, double y, double z, int light_id, int group_id, std::string ip, int state, int port, int pli, int pd, int special, int stream): point(x, y, z), m_light_id(light_id), m_group_id(group_id), m_ip(ip), m_state(state), m_port(port), m_phy_light_id(pli), m_phy_direction(pd), m_special(special), m_stream(stream)
     {
+		m_device_type_id=3;
         m_clt = nullptr;
     }
 

+ 26 - 0
module_service/module_traffic_light_manager.cpp

@@ -534,6 +534,15 @@ int traffic_light_manager::remove_light(const int& id)
     return 0;
 }
 
+/*
+ * @brief       删除红绿灯组
+ * @param       红绿灯组id号
+ * @return      成功返回0
+ * @note
+ * @warning
+ * @bug
+ * */
+
 int traffic_light_manager::remove_light_group(const int& id)
 {
     std::lock_guard<std::mutex> lg(m_mutex);
@@ -548,6 +557,15 @@ int traffic_light_manager::remove_light_group(const int& id)
     return 0;
 }
 
+/*
+ * @brief       获得红绿灯实时状态
+ * @param       无
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
+
 std::string traffic_light_manager::get_light_state()
 {
     std::lock_guard<std::mutex> lg(m_vtlg_mutex);
@@ -570,6 +588,14 @@ std::string traffic_light_manager::get_light_state()
     return m_jsBuilder.build_traffic_light(lights);
 }
 
+/*
+ * @brief       红绿灯通信异常告警
+ * @param       无
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
 void traffic_light_manager::visit_light_status()
 {
     std::lock_guard<std::mutex> lg(m_mutex);

+ 8 - 2
net-service.cpp

@@ -19,6 +19,7 @@
 #include "mine_business.h"
 #include "tool_time.h"
 #include "module_service/module_traffic_light_manager.h"
+#include "module_service/module_device_net.h"
 
 net_service::net_service()
 {
@@ -219,6 +220,8 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					    //site_ptr->on_power_status((power&1)==0);
                     }
 
+					module_device_net::instance()->do_business(clt->name(), site_ptr->m_id, site_ptr->m_device_type_id);
+
                     site_ptr->set_algo(LDT_PDOA);
                     //log_info("[scale_test] %.2f", site_ptr->m_scale);
                     struct timeval tv;
@@ -325,6 +328,8 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					site_ptr->m_time = time(0);
 					//site_ptr->m_device_type_id = 0x08;
 					site_ptr->m_net_device_status = 1;
+
+					module_device_net::instance()->do_business(clt->name(), site_ptr->m_id, site_ptr->m_device_type_id);
                 }
                 break;
             case 0x793B: //虚拟推送的心跳测试
@@ -348,8 +353,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
                         traffic_light_manager::instance()->send_light_data(id, DT_LIGHT, light_shape::green_all_on);
                     }else{
                         traffic_light_manager::instance()->send_light_data(id, DT_LIGHT, light_shape::green_spark);
-                    }
-
+                    }	
                 }
                 break;
             case THIRD_PARTY_CHAR_LIGHT_HEART:
@@ -376,6 +380,8 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 
                     light_ptr->m_state = status;
                     light_ptr->m_rec_time = time(0);
+					
+					module_device_net::instance()->do_business(clt->name(), light_ptr->m_light_id, light_ptr->m_device_type_id);
 
                     /*if((stamp%10) == 0){
                         int shape = (status == light_shape::red_spark)?light_shape::green_spark:light_shape::red_spark;

+ 3 - 0
znet.cpp

@@ -19,6 +19,7 @@
 #include <worker.h>
 #include "config_file.h"
 #include "crc.h"
+#include "module_service/module_device_net.h"
 
 extern config_file config;
 struct client_ex:client
@@ -392,6 +393,8 @@ struct sock_client:fd_io,client_ex
 	{
 		m_recv_timer.stop();
 		fd_io::stop();
+		// 清除网络下的所有设备
+		module_device_net::instance()->clear(m_name);
 		logn_info(1,"socket %s closed.",m_name.c_str());
 		m_ic.on_close(shared_from_this());
 	}