|
@@ -22,6 +22,8 @@
|
|
|
#include "tool_time.h"
|
|
|
#include "tool_byte.h"
|
|
|
#include "struct_def.h"
|
|
|
+#include "load_raw.h"
|
|
|
+#include "tunnel.h"
|
|
|
|
|
|
extern config_file config;
|
|
|
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)
|
|
@@ -133,6 +135,45 @@ void card_location_base::make_his_location(uint64_t t,const point & pt,bool bclo
|
|
|
m_his_location_card->insert(t, pt, area_id, map_id, site_id, scale);
|
|
|
}
|
|
|
|
|
|
+void card_location_base::make_his_location_simplify(uint64_t t, const loc_point & pt)
|
|
|
+{
|
|
|
+ m_his_location_card->insert_simplify(pt, t);
|
|
|
+}
|
|
|
+
|
|
|
+void card_location_base::make_his_location_cell_card(uint64_t t, const loc_point & pt)
|
|
|
+{
|
|
|
+ m_his_location_card->insert_cell_card(pt, t);
|
|
|
+}
|
|
|
+
|
|
|
+void card_location_base::make_his_location_cell_reader(uint64_t t, const loc_point & pt)
|
|
|
+{
|
|
|
+ m_his_location_card->insert_cell_reader(pt, t);
|
|
|
+}
|
|
|
+
|
|
|
+float get_pdoa(const double poa[], const double& offset)
|
|
|
+{
|
|
|
+ if (poa == nullptr) {
|
|
|
+ return -10.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ float poa1 = poa[0];
|
|
|
+ float poa2 = poa[1];
|
|
|
+ //float poa3 = poa[2];
|
|
|
+
|
|
|
+ float pdoa = poa2 - poa1 - offset;
|
|
|
+ while (pdoa >= TPI) {
|
|
|
+ pdoa -= TPI;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (pdoa < 0) {
|
|
|
+ pdoa += TPI;
|
|
|
+ }
|
|
|
+
|
|
|
+ pdoa -= PI;
|
|
|
+
|
|
|
+ return pdoa;
|
|
|
+}
|
|
|
+
|
|
|
//坐标点输入业务入口
|
|
|
/*
|
|
|
定位的逻辑处理
|
|
@@ -167,6 +208,12 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ if (m_last_site_id != lm[0].m_sit->m_id)
|
|
|
+ {
|
|
|
+ m_deque_speed.clear();
|
|
|
+ }
|
|
|
+
|
|
|
loc_point pt = m_sel_tool->select_solution(vp, lm);
|
|
|
//pt.y = pt.y;
|
|
|
|
|
@@ -185,9 +232,13 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ int cell_index_diff = int(pt.m_dist);
|
|
|
m_v_point.x = tool_other::round(pt.x, 3);
|
|
|
m_v_point.y = tool_other::round(pt.y, 3);
|
|
|
log_info("useful loc m_v_point: type=%d, card=%d, site=%d, ct=%d, timestamp=%llu, x=%f, y=%f, speed=%.2f, acc=%.2f", m_type, m_id, sid, m_ct, m_time, m_v_point.x, m_v_point.y, m_speed, lm[0].m_acc);
|
|
|
+ pt.m_site_cell_index = lm[0].m_sit->m_cell_index;
|
|
|
+ int cell_index_current = pt.m_site_cell_index - cell_index_diff;
|
|
|
+ m_v_cell_index = cell_index_current;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -204,22 +255,6 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- double acc = lm[0].m_acc;
|
|
|
- m_acc = lm[0].m_acc;
|
|
|
- log_info("useful loc point: type=%d, card=%d, site=%d, ct=%d, timestamp=%llu, x=%f, y=%f, speed=%.2f, acc=%.2f",m_type,m_id,sid,m_ct,m_time,x,y, m_speed, acc);
|
|
|
- do_business(lm.front().m_sit, pt, acc);
|
|
|
-
|
|
|
- // 呼救128,正常0
|
|
|
- int val = (lm[0].m_rav?STATUS_HELP:STATUS_NORMAL);
|
|
|
- if(m_battery_value > 3){
|
|
|
- val += STATUS_POWER_NORMAL;
|
|
|
- }else{
|
|
|
- val += STATUS_POWER_LOWER_SERIOUS;
|
|
|
- }
|
|
|
-
|
|
|
- log_info("[help-battery] card_id=%d, battery=%d, val=%d", m_id, m_battery_value, val);
|
|
|
- do_status(val);
|
|
|
-
|
|
|
// 姿态判断
|
|
|
if (is_vehicle())
|
|
|
{
|
|
@@ -335,7 +370,204 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
|
|
|
}
|
|
|
m_speed_last = m_speed;
|
|
|
m_stat_last = m_stat;
|
|
|
+
|
|
|
+ pt.m_stat = m_stat;
|
|
|
+
|
|
|
+ pt.m_cid = lm[0].m_card_id;
|
|
|
+ pt.m_sid = lm[0].m_sit->m_id;
|
|
|
+ pt.m_site_cell_index = lm[0].m_sit->m_cell_index;
|
|
|
+
|
|
|
+ std::string str_time = "";
|
|
|
+ if (load_raw::m_is_history)
|
|
|
+ {
|
|
|
+
|
|
|
+ str_time = load_raw::m_vec_date[load_raw::m_index];
|
|
|
+ }
|
|
|
+
|
|
|
+ double pdoa = get_pdoa(lm[0].m_poa, lm[0].m_sit->m_pdoa_offset);
|
|
|
+
|
|
|
+ int cell_index_diff = int(pt.m_dist);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ while (m_deque_speed.size() >= 5)
|
|
|
+ {
|
|
|
+ m_deque_speed.pop_front();
|
|
|
+ }
|
|
|
+
|
|
|
+ m_deque_speed.push_back(pt.m_speed);
|
|
|
+
|
|
|
+ double speed_avg = 0.0;
|
|
|
+ for (auto iter = m_deque_speed.begin(); iter != m_deque_speed.end(); iter++)
|
|
|
+ {
|
|
|
+ speed_avg += *iter;
|
|
|
+ }
|
|
|
+ speed_avg /= m_deque_speed.size();
|
|
|
+
|
|
|
+ point point_cell;
|
|
|
+
|
|
|
+ int cell_index_current = pt.m_site_cell_index - cell_index_diff;
|
|
|
+
|
|
|
+ s_tunnel.get_position_by_cell_index(cell_index_current, point_cell);
|
|
|
+
|
|
|
+ double dt = (lm[0].m_time_tmp - m_time_tmp_last)*1.0 / 1000.0;
|
|
|
+ if (dt == 0)
|
|
|
+ {
|
|
|
+ dt = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ double seconds_diff = 1.0;
|
|
|
+ if (m_time_tmp_last != 0)
|
|
|
+ {
|
|
|
+ seconds_diff = (lm[0].m_time_tmp - m_time_tmp_last) / 1000.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_cell_index_last != -1000)
|
|
|
+ {
|
|
|
+ speed_avg = fabs(cell_index_current - m_cell_index_last) / seconds_diff;
|
|
|
+
|
|
|
+ pt.m_speed = speed_avg;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ speed_avg = 0.0;
|
|
|
+ }
|
|
|
+ //速度大于3倍平均速度,判断相反距离的速度
|
|
|
+ if (speed_avg > m_avg_speed_for_count * 3)
|
|
|
+ {
|
|
|
+ int cell_index_diff_tmp = int(-pt.m_dist);
|
|
|
+ int cell_index_current_tmp = pt.m_site_cell_index - cell_index_diff_tmp;
|
|
|
+ int speed_avg_tmp = fabs(cell_index_current_tmp - m_cell_index_last) / seconds_diff;
|
|
|
+ //相反距离平均速度在正常范围内,则取相反距离
|
|
|
+ if (speed_avg_tmp <= m_avg_speed_for_count * 3)
|
|
|
+ {
|
|
|
+ speed_avg = speed_avg_tmp;
|
|
|
+ cell_index_current = cell_index_current_tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ double speed_diff = 0.0;
|
|
|
+ if (seconds_diff != 0.0)
|
|
|
+ {
|
|
|
+ speed_diff = (speed_avg - m_avg_speed_last) / seconds_diff;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (speed_avg > 0)
|
|
|
+ {
|
|
|
+ //最多累积一万个速度求平均
|
|
|
+ if (m_speed_count < 10000)
|
|
|
+ {
|
|
|
+ m_speed_count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ speed_avg = m_avg_speed_for_count + (speed_avg - m_avg_speed_for_count) / m_speed_count;
|
|
|
+ m_avg_speed_for_count = speed_avg;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cell_index_current - m_cell_index_last == 0)
|
|
|
+ {
|
|
|
+ pt.m_direction = m_direction_last;
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pt.m_direction = (cell_index_current - m_cell_index_last) > 0 ? "-" : "+";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //如果在基站附近
|
|
|
+ if (fabs(pt.m_dist) < 10.0)
|
|
|
+ {
|
|
|
+ //掉头了
|
|
|
+ if (pt.m_direction != m_direction_last)
|
|
|
+ {
|
|
|
+ int cell_index_diff_tmp = int(-pt.m_dist);
|
|
|
+ int cell_index_current_tmp = pt.m_site_cell_index - cell_index_diff_tmp;
|
|
|
+ int speed_avg_tmp = fabs(cell_index_current_tmp - m_cell_index_last) / seconds_diff;
|
|
|
+ //取反试试速度,正常则不掉头。
|
|
|
+ if (speed_avg_tmp <= m_avg_speed_for_count * 3)
|
|
|
+ {
|
|
|
+ speed_avg = speed_avg_tmp;
|
|
|
+ cell_index_current = cell_index_current_tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pt.m_time_tmp = lm[0].m_time_tmp;
|
|
|
+ pt.m_speed_avg = speed_avg;
|
|
|
+ pt.m_acc = lm[0].m_acc;
|
|
|
+ pt.m_rav = lm[0].m_rav;
|
|
|
+ pt.m_cell_index = cell_index_current;
|
|
|
+
|
|
|
+ pt.m_speed_change_rate = speed_diff;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ log_info("[pdoa] card_location_base::on_location ,obj_id=%d, time=%s, reader_id=%d, ct=%d, poa1=%.4f, poa2=%.4f, poa3=%.4f, pdoa=%.4f, pdoa_offset=%.4f, speed=%f, avg_speed=%f, begin_pt.x=%f, begin_pt.y=%f, gesture=%d, dist_original=%f, dist=%f, angle=%f, acc=%.2f, rav=%d, cell_index=%d, cell_x=%f, cell_y=%f, site_cell_index=%d, cell_count=%d, moving_direct=%s, speed_diff=%f",
|
|
|
+ pt.m_cid,
|
|
|
+ tool_time::to_str_ex(lm[0].m_time_tmp).c_str(),
|
|
|
+ pt.m_sid,
|
|
|
+ m_ct,
|
|
|
+ lm[0].m_poa[0],
|
|
|
+ lm[0].m_poa[1],
|
|
|
+ lm[0].m_poa[2],
|
|
|
+ pdoa,
|
|
|
+ lm[0].m_sit->m_pdoa_offset,
|
|
|
+ pt.m_speed,
|
|
|
+ speed_avg,
|
|
|
+ pt.x,
|
|
|
+ pt.y,
|
|
|
+ pt.m_stat,
|
|
|
+ (pdoa > 0 ? 1 : -1) * fabs(pt.m_dist),
|
|
|
+ pt.m_dist,
|
|
|
+ pt.m_angle,
|
|
|
+ lm[0].m_acc,
|
|
|
+ lm[0].m_rav,
|
|
|
+ cell_index_current,
|
|
|
+ point_cell.x,
|
|
|
+ point_cell.y,
|
|
|
+ pt.m_site_cell_index,
|
|
|
+ s_tunnel.get_cells_count(),
|
|
|
+ pt.m_direction.c_str(),
|
|
|
+ speed_diff);
|
|
|
+
|
|
|
+ m_speed = pt.m_speed;
|
|
|
+ m_stat = pt.m_stat;
|
|
|
+ m_cell_index_last = cell_index_current;
|
|
|
+ m_avg_speed_last = speed_avg;
|
|
|
+ m_direction_last = pt.m_direction;
|
|
|
+ m_time_tmp_last = lm[0].m_time_tmp;
|
|
|
+ pt.x = point_cell.x;
|
|
|
+ pt.y = point_cell.y;
|
|
|
+
|
|
|
+ //make_his_location_simplify(time(0) * 1000, pt);
|
|
|
+ make_his_location_cell_card(pt.m_time_tmp, pt);
|
|
|
+ make_his_location_cell_reader(pt.m_time_tmp, pt);
|
|
|
}
|
|
|
+
|
|
|
+ //pt.m_speed *= 20;
|
|
|
+
|
|
|
+ double acc = lm[0].m_acc;
|
|
|
+ m_acc = lm[0].m_acc;
|
|
|
+ log_info("useful loc point: type=%d, card=%d, site=%d, ct=%d, timestamp=%llu, x=%f, y=%f, speed=%.2f, acc=%.2f", m_type, m_id, sid, m_ct, m_time, x, y, m_speed, acc);
|
|
|
+ do_business(lm.front().m_sit, pt, acc, pt.m_cell_index);
|
|
|
+
|
|
|
+ // 呼救128,正常0
|
|
|
+ int val = (lm[0].m_rav ? STATUS_HELP : STATUS_NORMAL);
|
|
|
+ if (m_battery_value > 3) {
|
|
|
+ val += STATUS_POWER_NORMAL;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ val += STATUS_POWER_LOWER_SERIOUS;
|
|
|
+ }
|
|
|
+
|
|
|
+ log_info("[help-battery] card_id=%d, battery=%d, val=%d", m_id, m_battery_value, val);
|
|
|
+ do_status(val);
|
|
|
}
|
|
|
else
|
|
|
{
|