Преглед изворни кода

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

lixioayao пре 5 година
родитељ
комит
c7b4bb6fc2
12 измењених фајлова са 151 додато и 76 уклоњено
  1. 15 7
      area.cpp
  2. 14 10
      card.cpp
  3. 22 4
      card_base.cpp
  4. 2 0
      card_base.h
  5. 3 2
      card_person.cpp
  6. 16 8
      his_location.cpp
  7. 2 1
      his_location.h
  8. 67 37
      message.cpp
  9. 6 2
      message.h
  10. 3 3
      net-service.cpp
  11. 1 1
      websocket/jsonBuilder.cpp
  12. 0 1
      ya_setting.h

+ 15 - 7
area.cpp

@@ -193,7 +193,7 @@ void area::on_load_his(const std::shared_ptr<area_hover>&a,const std::shared_ptr
 
 void area::on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c)
 {
-	log_info("on_leave..%d  areaId:%d",c->m_id,m_id);
+	log_info("on_leave..card=%d  areaId=%d",c->m_id,m_id);
 	a->m_last_time=tool_time::now_to_ms();
 	a->m_last_point=*c;
  	for(const auto &i:m_area_business_list)
@@ -724,6 +724,7 @@ void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const poin
 		}
 	}
 
+
 	while(c1!=ce)
 	{
 		if((*c1)->m_area->get_frozen_count()==0)
@@ -767,11 +768,16 @@ void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const poin
                  strAreaInfo += tmpArea;
              }
          }
-         char sql[1024] = {0};
-         std::string _time=tool_time::to_str_ex(c->time_());
-         snprintf(sql, 1024, "REPLACE INTO rt_location (card_id, site_id,cur_time, x, y, z, state, area_info) VALUES (%s, %d,'%s',%lf, %lf, %lf, 0, '%s');",
-             tool_other::type_id_to_str(c->m_type, c->m_id).c_str(), m_site->id(),_time.c_str(), pt.x, pt.y, pt.z, strAreaInfo.c_str());
-         db_tool::PushAsync(sql);
+		 if(!strAreaInfo.empty())
+		 {
+			 char sql[1024] = {0};
+			 std::string _time=tool_time::to_str_ex(c->time_());
+			 snprintf(sql, 1024, "REPLACE INTO rt_location (card_id, site_id,cur_time, x, y, z, state, area_info) VALUES (%s, %d,'%s',%lf, %lf, %lf, 0, '%s');",
+			 tool_other::type_id_to_str(c->m_type, c->m_id).c_str(), m_site->id(),_time.c_str(), pt.x, pt.y, pt.z, strAreaInfo.c_str());
+			 db_tool::PushAsync(sql);
+			 log_info("insert rt_location: card=%d site_id=%d,point=%.2f-%.2f,area_info=%s"
+			 ,c->m_id,m_site->id(),pt.x,pt.y,strAreaInfo.c_str());
+		 }
     }
 }
 
@@ -779,8 +785,10 @@ void area_tool::on_leave(const std::shared_ptr<card_location_base>& c)
 {
     for(const auto& t:m_hover_list)
     {
-        t->m_area->on_leave(t, c);
+		t->m_area->on_leave(t, c);
     }
+
+	m_hover_list.clear(); //手动升井、自动升井清除该卡区域列表
 }
 
 void area_tool::set_area_info(int mapid,double scale,int areaid,const point &pt,uint64_t t,int type)

+ 14 - 10
card.cpp

@@ -249,14 +249,20 @@ void card_list::load_his_card_postion_vehicle()
 
 void card_list::load_his_card_postion_staff()
 {
-    const char *sql = "select l.card_id,l.site_id, l.cur_time, l.x, l.y, l.z, l.area_info, l.state, \
+    std::string init_limit_hour = config.get("service.init_limit_hour","48");
+
+    std::string sql = "select l.card_id,l.site_id, l.cur_time, l.x, l.y, l.z, l.area_info, l.state, \
             att.start_time, att.end_time \
             from rt_location l, rt_att_staff att, dat_card c, dat_staff_extend s \
             where l.card_id = c.card_id and l.card_id = att.card_id and l.card_id=s.card_id\
-            and c.state_id=0;";
+            and c.state_id=0 and end_time is null ";
+    sql += " and timestampdiff(hour ,att.start_time,now()) <= " + init_limit_hour + ";";
+
+	log_info("load_his_card_postion_staff:%s ",sql.c_str());
+
     std::string Error;
     YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql,DBRes,Error);
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
     if(!Error.empty())
         log_error("load_his_card_postion_staff列表 Error,%s",Error.c_str());
     uint64_t nCount = DBRes.GetRecordCount( Error );
@@ -312,14 +318,12 @@ void card_list::load_his_card_postion_staff()
             card_ptr->set(x,y,z);
             card_ptr->m_time = tool_time::to_time(cur_time)*1000;
 
-            if(end_time.empty())
-            {
-                auto mine_tool_ptr = card_ptr->get_mine_tool();
-                mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
-                mine_tool_ptr->m_is_attendance = true;
-                log_info("person加载考勤,考勤开始时间: %s, 卡id=%s", start_time.c_str(), card_id.c_str());
-            }
+            auto mine_tool_ptr = card_ptr->get_mine_tool();
+            mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
+            mine_tool_ptr->m_is_attendance = true;
+            log_info("person加载考勤,考勤开始时间:%s,卡id=%s areainfo=%s", start_time.c_str(), card_id.c_str(),strAreaInfo.c_str());
 
+            //分站设置
             auto area_tool=card_ptr->get_area_tool();
             auto sit_ptr=sit_list::instance()->get(site_id);
             if(sit_ptr)

+ 22 - 4
card_base.cpp

@@ -76,13 +76,30 @@ void card_location_base::do_status(int st)
 		st = st & (0xFFFFFFFF ^ STATUS_HELP);
 	}
 
+	if((STATUS_POWER_LOWER_SERIOUS & st) != 0)
+	{
+		m_pwr_stat=STATUS_POWER_LOWER_SERIOUS;
+	}
+	else
+	{
+		m_pwr_stat=0;
+	}
+
+
     module_mgr::do_status((STATUS_CARD)st, m_id, m_type);
 }
+
 void card_location_base::make_his_location(uint64_t t,const point & pt,bool bclose /*= false*/)
 {
-     int sid=0,mapid=0;
-	if(auto site_ptr=get_area_tool()->m_site){sid=site_ptr->m_area_id;mapid=site_ptr->m_map_id;}
-    m_his_location_card->push(t,pt,sid,mapid,bclose);
+	int area_id=0,map_id=0,site_id=0;
+	if(auto site_ptr=get_area_tool()->m_site)
+	{
+		area_id=site_ptr->m_area_id;
+		map_id=site_ptr->m_map_id;
+		site_id=site_ptr->m_id;
+	}
+
+	m_his_location_card->push(t,pt,area_id,map_id,site_id,bclose);
 }
 
 void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
@@ -189,7 +206,7 @@ void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
    //     list_1318.emplace_back(x,y,speed);
    // }
    // else
-        cp.speed = abs(ceil(m_speed));
+	cp.speed = abs(ceil(m_speed));
 
 	cp.x = tool_other::round(_p.x,3);
 	cp.y = tool_other::round(_p.y,3);
@@ -199,6 +216,7 @@ void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
 	cp.display=m_display;
 	cp.rec_time=m_time;
 	cp.level_id = m_level_id;
+	cp.stat=m_pwr_stat;
 	
 	swsTimerThrd.upt_card_pos(cp);
 }

+ 2 - 0
card_base.h

@@ -39,6 +39,7 @@ struct card:point
 		,m_level_id(level_id)
 		,m_stat(0)
 		,m_biz_stat(0)
+		,m_pwr_stat(0)
 		,m_display(dis)
 		,m_ct(0)
         ,m_acc(0)
@@ -55,6 +56,7 @@ struct card:point
 	int32_t  m_level_id;		//职务级别
 	int		 m_stat;			//运动静止状态
 	int		 m_biz_stat;
+	int	     m_pwr_stat;		//电量状态
 	uint16_t m_display;			//1显示0不显示,往前端推送
 	uint16_t m_ct;				//ct
     ///人卡(加速度状态),其值就是0和1,掘进机和采煤机,其值就是0~255,车辆,其值就需要乘以0.01,用于表示加速度值

+ 3 - 2
card_person.cpp

@@ -166,7 +166,7 @@ void person::on_timer()
 	cp.work_time = m_mine_tool->get_work_time();
 	cp.is_on_duty= m_mine_tool->is_on_duty();
 	upt_card_pos(cp,pt);
-	log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d--%d",m_id,_time,pt.x,pt.y,cp.map_id,cp.area_info.size(),person::m_limit_detained_time);
+	log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d--%d,speed=%.2f",m_id,_time,pt.x,pt.y,cp.map_id,cp.area_info.size(),person::m_limit_detained_time,m_speed);
     //int sid=0; if(auto st=m_area_tool->m_site)sid=st->m_area_id; m_his_location_card->push(_time,pt,sid,cp.map_id);
 
 	uint64_t _now=tool_time::now_to_ms();
@@ -177,9 +177,10 @@ void person::on_timer()
 		m_biz_stat=get_stat();
 	}
     print_card_detained();
+
 	if(m_upmine_flag.load())
 	{
-		log_info("card=%d cid=%d up_mine:upmine_flag=%d",m_id,m_cid, m_upmine_flag.load());
+		log_info("card=%d user-id=%d up_mine:upmine_flag=%d",m_id,m_cid, m_upmine_flag.load());
 		m_area_tool->on_leave(shared_from_this());
 		m_upmine_flag=0;
 	}

+ 16 - 8
his_location.cpp

@@ -27,6 +27,7 @@ void location_card::init()
 {
     m_areaid=-1;
     m_mapid=-1;
+    m_siteid = -1;
     m_timestamp=0;
     m_p.set(0,0);
     std::queue<mini_data> tmp;
@@ -124,6 +125,8 @@ bool location_card::time_out(const point &p,uint64_t time)
         return true;
     return false;
 }
+
+//区域是否发生变化
 bool location_card::is_area_changed(int new_areaid)
 {
     bool flag =false;
@@ -134,6 +137,8 @@ bool location_card::is_area_changed(int new_areaid)
     }
     return flag;
 }
+
+//地图是否发生变化
 bool location_card::is_map_changed(int new_mapid)
 {
     bool flag =false;
@@ -144,7 +149,8 @@ bool location_card::is_map_changed(int new_mapid)
     }
     return flag;
 }
-void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,bool bclose/* = false*/)
+
+void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,int32_t siteid,bool bclose/* = false*/)
 {
     if (bclose) //卡移除后直接更新his_location
     {
@@ -152,10 +158,12 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
         init();
         return;
     }
-    if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0)
+    if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0 || m_siteid < 0)
     {
         set(p,timestamp);
-        m_areaid=areaid;m_mapid=mapid;
+        m_areaid = areaid;
+        m_mapid  = mapid;
+        m_siteid = siteid;
         m_d.emplace(p,timestamp);
         return ;
     }
@@ -197,7 +205,7 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
     if(is_area_changed(areaid))
         if(!flag)iflag=3;
     if(is_map_changed(mapid))
-        if(!flag)iflag=4;
+        if(!flag)iflag=4;  
     log_info("his_location cardid:%d:%d",m_cardid,iflag);
     if(iflag)
     {
@@ -213,9 +221,9 @@ void location_card::insert()
 {
     //std::string tabName=getTabName();
     char nsql[512]={0};
-    const char * sql = "replace into his_location (obj_id,card_type_id,ident,begin_time,map_id,area_id,begin_pt,direction)"
-                       "values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f);";
-    snprintf(nsql,512,sql,m_objid,m_type,m_cardid,tool_time::to_str(m_timestamp/1000).c_str(),m_mapid,m_areaid,m_p.x,m_p.y,m_arg);
+    const char * sql = "replace into his_location (obj_id,card_type_id,ident,begin_time,map_id,area_id,begin_pt,direction,reader_id)"
+                       "values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f,%d);";
+    snprintf(nsql,512,sql,m_objid,m_type,m_cardid,tool_time::to_str(m_timestamp/1000).c_str(),m_mapid,m_areaid,m_p.x,m_p.y,m_arg,m_siteid);
     log_info("his_location[%d,%lu]:%s",m_cardid,m_timestamp,nsql);
     sDBConnPool.PushAsync(nsql);
 }
@@ -226,7 +234,7 @@ void location_card::update(const point &p,uint64_t timestamp,int flag/*=0*/,int
     const char * sql = "update his_location set last_time='%s',speed=%.3f,direction=%f,location_flag=%d where obj_id=%d and begin_time='%s' and last_time is null;";
     double dist = m_p.dist(p);
     double t	= (timestamp - m_timestamp)/1000;
-    double avge_speed= dist/t;
+    double avge_speed = dist/t;
     if(std::isnan(avge_speed)|| std::isinf(avge_speed))avge_speed=0;
 
     log_info("his_location_time[%d]:%d[%lu,%lu,%lu]",m_cardid,flag,last_timestamp,timestamp,m_timestamp);

+ 2 - 1
his_location.h

@@ -16,6 +16,7 @@ struct location_card
 	double		m_arg;//运动方向角度值
 	int 		m_areaid;//区域
 	int 		m_mapid;//地图
+    int         m_siteid;   //分站
 	uint64_t	m_timestamp;//入库后的时间
 	point		m_p;//入库后的点
     int         m_direct_index;
@@ -55,7 +56,7 @@ struct location_card
     // 地图变化
 	bool is_map_changed(int new_mapid);
     // 计算当前点是否需要记录到DB中
-	void push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,bool bclose = false);
+	void push(uint64_t timestamp,const point & p,int32_t areaid,int32_t mapid,int32_t siteid,bool bclose = false);
 
 	void insert();
 

+ 67 - 37
message.cpp

@@ -7,8 +7,6 @@
 
 void message_locinfo::zero_this()
 {
-//	m_time_stamp=
-//	m_site_id=
 	m_site_time=
 	m_tof=
 	m_card_type=
@@ -21,13 +19,33 @@ void message_locinfo::zero_this()
 	m_ant_id=
 	m_sync_ct=
 	m_rssi=0;
+    m_distance = 0.0;
 }
 
-message_locinfo*message_locinfo::clone()
+task* message_locinfo::clone(message_locinfo* ml)
 {
-
-
-	return nullptr;
+    log_info("clone: enter");
+    task* t = task::alloc<message_locinfo>(); 
+    message_locinfo& m = t->body<message_locinfo>(); 
+    m.zero_this();
+   
+    log_info("clone: begin copy");
+    m.m_time_stamp = ml->m_time_stamp;
+    m.m_site_time = ml->m_site_time;
+    m.m_tof = ml->m_tof;
+    m.m_site_id = ml->m_site_id;
+    m.m_card_type = ml->m_card_type;
+    m.m_card_id = ml->m_card_id;
+    m.m_card_ct = ml->m_card_ct;
+    m.m_batty_status = ml->m_batty_status;
+    m.m_callinfo = ml->m_callinfo;
+    m.m_rav = ml->m_rav;
+    m.m_acc = ml->m_acc;
+    m.m_ant_id = ml->m_ant_id;
+    m.m_sync_ct = ml->m_sync_ct;
+    m.m_rssi = ml->m_rssi;
+    log_info("clone: end copy");
+	return std::move(t);
 }
 
 void message_locinfo::load(zistream&is,bool tdoa)
@@ -81,11 +99,12 @@ void message_locinfo::load(zistream&is,bool tdoa)
 			m_time_stamp,m_card_type,m_card_id,m_site_id,m_card_ct,m_batty_status,m_acc,m_tof,m_ant_id,m_rssi);
 }
 
-std::vector<task*> message_locinfo::load_753C(zistream&is)
+//优化协议数据解析
+std::vector<task*> message_locinfo::load_opt(zistream&is)
 {
 	std::vector<task*> rc;
-	task*t=task::alloc<message_locinfo>();
-
+	
+    task* t=task::alloc<message_locinfo>();
 	message_locinfo&m=t->body<message_locinfo>();
 	m.zero_this();
 
@@ -94,6 +113,7 @@ std::vector<task*> message_locinfo::load_753C(zistream&is)
 	is>>b>>m.m_card_id>>m.m_card_ct;
 	m.m_card_type=b&0xF;
 	m.m_batty_status=b>>4;
+    m.m_card_id = card_id;
 
 	is>>b;
 	if(m.m_card_type==1)
@@ -105,40 +125,50 @@ std::vector<task*> message_locinfo::load_753C(zistream&is)
 		m.m_rav=((b&0x80)?-1.:1.)*(b&0x7f)*3;
 	}
 
-	//加速度
+    //加速度
 	is>>b;
     auto c=card_list::instance()->get(tool_other::type_id_to_u64(m.m_card_type,m.m_card_id));
 	if(m.m_card_type == 1 ||(c && tool_other::is_coal_or_driving(m.m_card_type,c->get_vehicle_type_id())))
 		m.m_acc=b;
 	else
 		m.m_acc=((b&0x80)?-1.:1.)*(b&0x7f)*0.01;
-
-#if 0
-	//TOF
-	is>>b>>i; 	
-	m_tof=b;
-	m_tof=(m_tof<<32)|i;
-
-	//天线号
-	is>>m_ant_id;
-	--m_ant_id;
-
-	if(tdoa)
-	{
-		//同步序号,冲击响应丢弃
-		is>>m_sync_ct>>skip(2);
-	}
-
-	//信号电平值
-	uint16_t sp1=0,sp2=0;
-	is>>sp1>>sp2;
-	m_rssi=10*log10(1.*sp1*(1<<17)/pow(sp2-64.,2))-121.74;
-	log_info("timestamp=%llu,type:%d,card_id:%d,site:%d,ct:%d,status:%d,acc=%d,tof=%llu,ant_id:%d,spq=%d",
-			m_time_stamp,m_card_type,m_card_id,m_site_id,m_card_ct,m_batty_status,m_acc,m_tof,m_ant_id,m_rssi);
-#endif
-	rc.push_back(t);
-
-	return std::move(rc);
+   
+    //log_info("load_opt: card_type: %d,card_id: %d,ct:%d, callinfo:%d, rav:%d,acc:%.2f",m.m_card_type,m.m_card_id,m.m_card_ct,m.m_callinfo,m.m_rav,m.m_acc);
+	 
+    //天线
+    is>>b;
+    m.m_ant_id = b-1; 
+    //分站RSSI
+    int8_t val;
+    is>>val;
+    m.m_rssi = val;
+    //天线1距离
+    uint16_t d;
+    is>>d;
+    m.m_distance = d*0.02;
+
+    //log_info("load_opt: ant1 ant_id:%d, rssi: %d, d: %.2f",m.m_ant_id,m.m_rssi,m.m_distance);
+
+    task* t2 = message_locinfo::clone(&m);
+    message_locinfo& m2 = t2->body<message_locinfo>();
+
+    m2.m_ant_id = m.m_ant_id==0?1:0;
+    //分站RSSI
+    is>>val;
+    m2.m_rssi = val;
+    //天线2距离
+    is>>d;
+    m2.m_distance = d*0.02;
+    
+    //log_info("load_opt: ant2 ant_id:%d, rssi: %d, d: %.2f",m2.m_ant_id,m2.m_rssi,m2.m_distance);
+
+
+    log_info("load_opt: type=%d, card_id=%d,ct=%d, callinfo=%d, rav=%d, acc=%d, ant1=%d, tof1=%.2f, spq1=%d, ant2=%d, tof2=%.2f, sqp2=%d",m.m_card_type,m.m_card_id,m.m_card_ct,m.m_callinfo,m.m_rav,m.m_acc,m.m_ant_id,m.m_distance,m.m_rssi,m2.m_ant_id,m2.m_distance,m2.m_rssi);
+
+    rc.push_back(t);
+    rc.push_back(t2);
+	
+    return std::move(rc);
 }
 
 void message_tdoasync::zero_this()

+ 6 - 2
message.h

@@ -15,6 +15,7 @@ struct zistream;
 #define CHAR_ADHOC	0x803b							// 上传自组网数据
 #define CHAR_CTRL_READER_CMD 0x804c					// 向分站发送控制指令,控制分站向上位机发送数据
 #define CHAR_VIRTUAL_DATA_PUSH_CMD 0x699a			//虚拟数据推送
+#define CHAR_LOCATEDATA_TOF_OPTIMIZE 0x753d         // TOF优化协议
 
 //	分站传上来的卡定位数据,包括tof,tdoa
 struct message_locinfo:task
@@ -35,11 +36,14 @@ struct message_locinfo:task
 	uint16_t m_sync_ct;
 	int16_t  m_rssi;
 
+    //优化协议
+    float m_distance;
+
 	void zero_this();
     void load(zistream&is,bool tdoa);
     void set_rav(uint8_t rav){m_rav=rav;}
-    static std::vector<task*> load_753C(zistream&is);
-	static message_locinfo*clone();
+    static std::vector<task*> load_opt(zistream&is);
+    static task* clone(message_locinfo* ml);
 
 	int64_t long_id()const 
 	{

+ 3 - 3
net-service.cpp

@@ -121,7 +121,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					}
 				}
 				break;
-			case 0x753C://tof-优化,大小分站
+			case CHAR_LOCATEDATA_TOF_OPTIMIZE://tof-优化,大小分站
 				{
 					uint16_t site_id=-1;
 					uint16_t site_ct=-1;
@@ -186,8 +186,8 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
 					{
 						uint64_t tstamp = t -1000 + 50 + index* 45;
 						index++;
-
-						for(auto&tk:message_locinfo::load_753C(is))//未写完
+                        
+						for(auto & tk : message_locinfo::load_opt(is))
 						{
 							message_locinfo&m=tk->body<message_locinfo>();
 							m.m_site_id=site_id;

+ 1 - 1
websocket/jsonBuilder.cpp

@@ -120,7 +120,7 @@ namespace YA
 		tmp_object.SetInt( CardPos.dept_id );
 		Array.PushBack( tmp_object, Allocator );
 
-		//10 状态
+		//10 电量状态
 		tmp_object.SetInt( CardPos.stat );
 		Array.PushBack( tmp_object, Allocator );
 

+ 0 - 1
ya_setting.h

@@ -63,7 +63,6 @@ public:
     */
     static SSys_setting m_sys_setting;
     static bool Init_sys_setting();
-
 };
 
 #endif