|
@@ -11,12 +11,13 @@
|
|
#include "db/db_tool.h"
|
|
#include "db/db_tool.h"
|
|
#include "common_tool.h"
|
|
#include "common_tool.h"
|
|
#include "ant.h"
|
|
#include "ant.h"
|
|
-
|
|
|
|
|
|
+#include "ya_setting.h"
|
|
|
|
+#include "card_path.h"
|
|
struct card_sensor
|
|
struct card_sensor
|
|
{
|
|
{
|
|
card_sensor(int32_t wid,const point &p,const std::string &cid)
|
|
card_sensor(int32_t wid,const point &p,const std::string &cid)
|
|
:card_id(cid)
|
|
:card_id(cid)
|
|
- ,sid(0)
|
|
|
|
|
|
+ ,sid(0)
|
|
,id(wid)
|
|
,id(wid)
|
|
,bigger(-1),count(0),sum(0),ct(-1),stime(0),flag(false)
|
|
,bigger(-1),count(0),sum(0),ct(-1),stime(0),flag(false)
|
|
{
|
|
{
|
|
@@ -141,11 +142,87 @@ struct reverse_alarm_business
|
|
private:
|
|
private:
|
|
std::map<uint64_t,std::shared_ptr<card_sensor_mgr>> m_sensor_mgr;
|
|
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()
|
|
mine_business::mine_business()
|
|
{
|
|
{
|
|
m_staffer_num_ptr.reset(new staffer_num_business);
|
|
m_staffer_num_ptr.reset(new staffer_num_business);
|
|
m_reverse_alarm_ptr.reset(new reverse_alarm_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()
|
|
mine_business* mine_business::inst()
|
|
{
|
|
{
|
|
@@ -154,8 +231,9 @@ mine_business* mine_business::inst()
|
|
}
|
|
}
|
|
void mine_business::run_business()
|
|
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()
|
|
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);
|
|
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
|
|
///////staffer_num_business
|
|
/**********************************
|
|
/**********************************
|
|
//每两分钟把人员数量入库。
|
|
//每两分钟把人员数量入库。
|
|
//不往前端推送的人员,不算在数量范围内
|
|
//不往前端推送的人员,不算在数量范围内
|
|
-*********************************/
|
|
|
|
|
|
+ *********************************/
|
|
void staffer_num_business::record_staffer_num()
|
|
void staffer_num_business::record_staffer_num()
|
|
{
|
|
{
|
|
static uint32_t min_num=0,max_num=0;
|
|
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);
|
|
tm->push(workfaceid,sensor_id,p,card_id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+/************************************
|
|
|
|
+//获取传感器数据,从数据库中
|
|
|
|
+//每三分钟获取一次,判断其是否上升趋势。
|
|
|
|
+//如果上升趋势,则标识正在掘进中。开始判断反向
|
|
|
|
+ ************************************/
|
|
void reverse_alarm_business::run_sensor()
|
|
void reverse_alarm_business::run_sensor()
|
|
{
|
|
{
|
|
static time_t time_interval=0;
|
|
static time_t time_interval=0;
|
|
@@ -269,7 +363,7 @@ void reverse_alarm_business::run_sensor()
|
|
time_interval =t;
|
|
time_interval =t;
|
|
printf("reverse_alarm......\n");
|
|
printf("reverse_alarm......\n");
|
|
for(const auto &x:m_sensor_mgr)
|
|
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 );
|
|
int nCount = DBRes.GetRecordCount( Error );
|
|
if (nCount < 1)
|
|
if (nCount < 1)
|
|
{
|
|
{
|
|
- log_error("load_sensor_data..failed[%s]", strsql);
|
|
|
|
- continue;
|
|
|
|
|
|
+ log_error("load_sensor_data..failed[%s]", strsql);
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
|
|
double prenum=-1;
|
|
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)
|
|
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);
|
|
uint64_t cid = tool_other::type_id_to_u64(type,id);
|
|
auto it = m_sensor_mgr.find(cid);
|
|
auto it = m_sensor_mgr.find(cid);
|
|
if(it != m_sensor_mgr.end())
|
|
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)
|
|
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;
|
|
|
|
+}
|
|
|
|
+
|