#include #include #include "card_message_handle.h" #include "card_person.h" #include "card_car.h" #include "config_file.h" #include "select_tool.h" #include "module_service/module_mgr.h" #include "websocket/wsClientMgr.h" #include "websocket/wsTimerThread.h" #include "his_location.h" #include "event.h" #include "module_service/module_call.h" #include "mine.h" #include "common_tool.h" #include "ant.h" #include "area.h" #include "loc_point.h" #include "loc_message.h" #include "module_service/module_traffic_light_manager.h" #include "db/db_tool.h" #include "tool_time.h" #include "tool_byte.h" #include "struct_def.h" #include "sys_setting.h" #include "ya_setting.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) :card(id, dis, t, deptid, level_id, cid) ,m_display_old(dis) { select_tool_manage::instance()->create_tool(type, m_sel_tool, m_smo_tool); m_his_location_card.reset(new location_card(m_id, m_type, cid)); m_cb_pdoa.set_capacity(5); m_cb_tof.set_capacity(5); m_cb_point.set_capacity(5); for(int index = 0; index < 5; ++index){ m_cb_pdoa.push_back(100); m_cb_tof.push_back(0); m_cb_point.push_back(point(0,0)); } m_cb_stream_idx.set_capacity(2); m_cb_stream_idx.push_back(0); m_cb_stream_idx.push_back(0); } void card_location_base::do_status(int st) { time_t now = time(0); //bool help_flag = false; //log_info("[help-battery] card_id=%d, help_bit=%d, status=%d", m_id, m_help_bit, st); // 呼救 if((m_help_bit & 1) && (st & STATUS_HELP)) { // 1111111111 // ^ m_help_last_time = now; } else if((m_help_bit & 1) && (st & STATUS_HELP)==0) { // 11111111100000 // ^ m_help_bit<<=1; } else if((m_help_bit & 1)==0 && (st & STATUS_HELP)) { // 00000000011111 // ^ // 呼救开始 if((m_help_bit&0x3)==2) { //log_warn("[help-battery] handle_m_help, card_id=%d",m_id); //help_flag=true; } m_help_last_time = now; m_help_bit<<=1; m_help_bit|=1; log_info("[help-battery] begin help, card_id=%d, help_bit=%d, status=%d", m_id, m_help_bit, st); } else { // 11111111100000 // ^ // 呼救结束后持续1分钟 if(now - m_help_last_time > 60) { m_help_bit = 0; log_info("[help-battery] end help, card_id=%d, help_bit=%d, status=%d", m_id, m_help_bit, st); } } /*if(!help_flag) { 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 area_id = 0, map_id = 0, site_id = 0; double scale = 0.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; scale = site_ptr->m_scale; } auto mine_ptr = get_mine_tool(); if(m_time < mine_ptr->get_down_time()) { return; } m_his_location_card->push(t, pt, area_id, map_id, site_id, bclose); m_his_location_card->insert(t, pt, area_id, map_id, site_id, scale); } void card_location_base::make_his_location_cell_card_tdoa(uint64_t t, const sys::tdoa_2d_data& tdoa2d) { log_info("upt_tdoa_2d_data6"); m_his_location_card->insert_cell_card_tdoa(tdoa2d, t); } //坐标点输入业务入口 void card_location_base::on_location(const std::vector&vp, const std::vector &lm) { auto site_ptr = get_area_tool()->m_site; int sid = 0; // 天线间间距默认为3米,实际取基站上的天线间距离配置参数 double ant_dist = 3.0; if(site_ptr){ sid = site_ptr->m_id; ant_dist = site_ptr->m_pdoa_offset; }else{ return; } if (site_ptr->m_num_dims == 2) { if (vp.size() < 1) { return; } if (lm.size() < 1) { return; } } double ptx = 0.0; double pty = 0.0; bool useless = false; if(site_ptr->m_num_dims == 2){ ptx = vp[0].x; pty = vp[0].y; useless = true; } if(useless) { if(site_ptr->m_num_dims == 2){ // data inclue: site_id, dist, pdoa, speed; std::string str_info = ""; // calc delay time by card's ct double dt = 0.0; if (m_ct > lm[0].m_card_ct) { dt = (m_ct - lm[0].m_card_ct) / 1000.0; } else { dt = (m_ct + 65535 - lm[0].m_card_ct) / 1000.0; } for (auto itl : lm) { auto its_info = d3_last_site_info.find(itl.m_sit->m_id); if (its_info == d3_last_site_info.end()) { sinfo si; si.sct = lm[0].m_card_ct; si.sdist = itl.m_num_ticks*15.65*2.996*1E-4; si.angle = 0.0; d3_last_site_info.insert(std::make_pair(itl.m_sit->m_id, si)); its_info = d3_last_site_info.find(itl.m_sit->m_id); } // angle double angle = 0.0; // current distance for site double dist = itl.m_num_ticks*15.65*2.996*1E-4; // calc speed double v = (dist - its_info->second.sdist) / dt; // site info: id, dist, angle, speed str_info += std::to_string(itl.m_sit->m_id) + ","; str_info += std::to_string(dist) + ","; str_info += std::to_string(angle) + ","; str_info += std::to_string(v) + ";"; // save data for next calc its_info->second.sct = lm[0].m_card_ct; its_info->second.sdist = dist; its_info->second.angle = angle; } // this is not add move state int move_state = 0; double dx, dy = 0.0; dx = (ptx - x) / dt; dy = (pty - y) / dt; auto lm0 = lm[0]; double acc = lm0.m_ins_data.get_acc(); double acc_x = lm0.m_ins_data.get_acc(0); double acc_y = lm0.m_ins_data.get_acc(1); double acc_z = lm0.m_ins_data.get_acc(2); double ang = lm0.m_ins_data.get_gyro(); double ang_x = lm0.m_ins_data.get_gyro(0); double ang_y = lm0.m_ins_data.get_gyro(1); double ang_z = lm0.m_ins_data.get_gyro(2); // insert data to database char sql[1024] = { 0 }; std::string cid = tool_byte::to_cardid(m_type, m_id); std::string cid_tmp = cid; std::string ctime = tool_time::to_str_ex(tool_time::now_to_ms()); if (vp.size() == 1) { for (auto iter0 = lm.begin(); iter0 != lm.end(); ++iter0) { for (auto iter1 = iter0 + 1; iter1 != lm.end(); ++iter1) { for (auto iter2 = iter1 + 1; iter2 != lm.end(); ++iter2) { std::list site_id_list; site_id_list.push_back(iter0->m_sit->id()); site_id_list.push_back(iter1->m_sit->id()); site_id_list.push_back(iter2->m_sit->id()); site_id_list.sort(); auto iter_begin = site_id_list.begin(); int site1 = *iter_begin; iter_begin++; int site2 = *iter_begin; iter_begin++; int site3 = *iter_begin; if (true) { int i = -1; char site_list[1024] = { 0 }; snprintf(site_list, 1024, "%d,%d,%d", site1, site2, site3); std::string str_site_list = site_list; int nSidIndex = CYaSetting::m_sys_setting.mp_sids_index[str_site_list]; char sidIndex[1024] = { 0 }; snprintf(sidIndex, 1024, "%d", nSidIndex); std::string strSidIndex = sidIndex; if (nSidIndex != 0) { cid = strSidIndex + cid_tmp; } for (int site_index = 0; site_index < vp.size(); site_index++) { std::list id_list; id_list.push_back(vp[site_index].site1); id_list.push_back(vp[site_index].site2); id_list.push_back(vp[site_index].site3); id_list.sort(); auto iter_ = id_list.begin(); int site1_tmp = *iter_; iter_++; int site2_tmp = *iter_; iter_++; int site3_tmp = *iter_; if (site1 == site1_tmp && site2 == site2_tmp && site3 == site3_tmp) { i = site_index; } } if (i == -1) { continue; } sys::tdoa_2d_data tdoa2d(vp[i].x, vp[i].y, dx, dy, acc, acc_x, acc_y, acc_z, ang, ang_x, ang_y, ang_z, cid, vp[i].d1, vp[i].d2, vp[i].d3, ctime, str_info, move_state); swsTimerThrd.upt_tdoa_2d_data(std::move(tdoa2d)); m_last_x = vp[i].x; m_last_y = vp[i].y; make_his_location_cell_card_tdoa(time(0) * 1000, tdoa2d); } } } } } else if (vp.size() > 1) { int iSelected = 0; double min_distance = 0.0; for (auto iter0 = lm.begin(); iter0 != lm.end(); ++iter0) { for (auto iter1 = iter0 + 1; iter1 != lm.end(); ++iter1) { for (auto iter2 = iter1 + 1; iter2 != lm.end(); ++iter2) { std::list site_id_list; site_id_list.push_back(iter0->m_sit->id()); site_id_list.push_back(iter1->m_sit->id()); site_id_list.push_back(iter2->m_sit->id()); site_id_list.sort(); auto iter_begin = site_id_list.begin(); int site1 = *iter_begin; iter_begin++; int site2 = *iter_begin; iter_begin++; int site3 = *iter_begin; if (true) { int i = -1; char site_list[1024] = { 0 }; snprintf(site_list, 1024, "%d,%d,%d", site1, site2, site3); std::string str_site_list = site_list; int nSidIndex = CYaSetting::m_sys_setting.mp_sids_index[str_site_list]; char sidIndex[1024] = { 0 }; snprintf(sidIndex, 1024, "%d", nSidIndex); std::string strSidIndex = sidIndex; if (nSidIndex != 0) { cid = strSidIndex + cid_tmp; } for (int site_index = 0; site_index < vp.size(); site_index++) { std::list id_list; id_list.push_back(vp[site_index].site1); id_list.push_back(vp[site_index].site2); id_list.push_back(vp[site_index].site3); id_list.sort(); auto iter_ = id_list.begin(); int site1_tmp = *iter_; iter_++; int site2_tmp = *iter_; iter_++; int site3_tmp = *iter_; if (site1 == site1_tmp && site2 == site2_tmp && site3 == site3_tmp) { i = site_index; } log_info("site1%d,site2%d,site3%d,%d,%d,%d", site1, site2, site3, site1_tmp, site2_tmp, site3_tmp); } if (i == -1) { continue; } auto d = sqrt((m_last_x - vp[i].x) * (m_last_x - vp[i].x) + (m_last_y - vp[i].y) * (m_last_y - vp[i].y)); if (d < min_distance) { iSelected = i; min_distance = d; } sys::tdoa_2d_data tdoa2d(vp[i].x, vp[i].y, dx, dy, acc, acc_x, acc_y, acc_z, ang, ang_x, ang_y, ang_z, cid, vp[i].d1, vp[i].d2, vp[i].d3, ctime, str_info, move_state); swsTimerThrd.upt_tdoa_2d_data(std::move(tdoa2d)); m_last_x = vp[i].x; m_last_y = vp[i].y; } } } } // sys::tdoa_2d_data tdoa2d(vp[iSelected].x, vp[iSelected].y, dx, dy, acc, acc_x, acc_y, acc_z, ang, ang_x, ang_y, ang_z, cid, vp[iSelected].d1, vp[iSelected].d2, vp[iSelected].d3, ctime, str_info, move_state); // swsTimerThrd.upt_tdoa_2d_data(std::move(tdoa2d)); // m_last_x = vp[iSelected].x; // m_last_y = vp[iSelected].y; } } } else { log_warn("坐标不可用:site=%d, type=%d, card=%d, ct=%d, x=%f, y=%f", sid, m_type, m_id, m_ct, ptx, pty); } } void card_location_base::on_message(zloop* loop, message_locinfo& loc,bool is_history) { m_ct = loc.m_card_ct; m_time = loc.m_time_stamp; auto site_ptr = sit_list::instance()->get(loc.m_site_id); if(!site_ptr) { log_warn("接收到分站的数据,site=%d,card=%d,ct=%d,但是分站未定义",loc.m_site_id,m_id,loc.m_card_ct); return; } auto area_tool=get_area_tool(); area_tool->set_site(site_ptr); handle_message(loc.m_card_ct,loc.m_batty_status); if(site_ptr->is_up_site()) { log_info("card=%d被井上分站[site=%d]收到",m_id,site_ptr->id()); area_tool->on_point(shared_from_this(),point(1,1)); this->site_hover(loc.m_site_id); } else { if(site_ptr->is_path_empty()) { log_warn("接收到分站的数据,site=%d,card=%d,ct=%d,但是分站路径为空",site_ptr->id(),m_id,loc.m_card_ct); return; } m_message_handle->on_message(loop,loc,is_history); } } /* * 实心球原始数据调用算法模块进行定位处理 * */ void card_location_base::on_message(zloop* loop, message_ins_locinfo& loc,bool is_history) { /*m_ct = loc.m_card_ct; m_time = loc.m_time_stamp; auto site_ptr = sit_list::instance()->get(loc.m_site_id); if(!site_ptr) { log_warn("接收到分站的数据,site=%d,card=%d,ct=%d,但是分站未定义",loc.m_site_id,m_id,loc.m_card_ct); return; }*/ if (false) if (loc.m_site_id == 22 || loc.m_site_id == 23) { //m_message_handle->on_message(loop, loc, is_history); log_info("[solid_ball] start calc location"); auto itm = m_msg_list.find(loc.m_card_ct); if (itm == m_msg_list.end()) { std::vector vtm; vtm.push_back(loc); m_msg_list.insert(std::make_pair(loc.m_card_ct, vtm)); itm = m_msg_list.find(loc.m_card_ct); } else { itm->second.push_back(loc); } if (itm->second.size() < 2) { return; } // ct切换了 m_ct = loc.m_card_ct; m_time = loc.m_time_stamp; auto site_ptr = sit_list::instance()->get(loc.m_site_id); if (!site_ptr) { log_warn("接收到分站的数据,site=%d,card=%d,ct=%d,但是分站未定义", loc.m_site_id, m_id, loc.m_card_ct); return; } // 卡号 std::string sid = tool_byte::to_cardid(m_type, m_id); std::string site_info = ""; std::string now = tool_time::to_str_ex(tool_time::now_to_ms()); int nIndex = 0; int siteId1 = 0; int siteId2 = 0; double distance1 = 0; double distance2 = 0; // 存入数据库 for (auto itl : itm->second) { site_info += std::to_string(itl.m_site_id); double d = itl.m_tof * 15.65 * 2.996 * 1E-4; site_info += "," + std::to_string(d); site_info += ",0.0"; double v = 0.0; auto its = last_site_info.find(itl.m_site_id); if (its == last_site_info.end()) { sinfo si; si.sct = m_ct; si.sdist = d; last_site_info.insert(std::make_pair(itl.m_site_id, si)); v = 0.0; } else { double dt = 0.0; if (m_ct > its->second.sct) { dt = (m_ct - its->second.sct) / 1000.0; } else { dt = (m_ct + 65535 - its->second.sct) / 1000.0; } v = (d - its->second.sdist) / dt; its->second.sct = m_ct; its->second.sdist = d; } site_info += "," + std::to_string(v); site_info += ";"; if (nIndex == 0) { siteId1 = itl.m_site_id; distance1 = d; nIndex++; } else if (nIndex == 1) { siteId2 = itl.m_site_id; distance2 = d; } } // 数据入库 char sql[1024] = { 0 }; snprintf(sql, 1024, "insert into his_raw_data_sb(card_id, site_id, distance, acc, acc_x, acc_y, acc_z, ang, ang_x, ang_y, ang_z, cur_time) values('%s', %d, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, '%s')", sid.c_str(), siteId1, distance1, loc.m_ins_data.get_acc(), loc.m_ins_data.get_acc(0), loc.m_ins_data.get_acc(1), loc.m_ins_data.get_acc(2), loc.m_ins_data.get_gyro(), loc.m_ins_data.get_gyro(0), loc.m_ins_data.get_gyro(1), loc.m_ins_data.get_gyro(2), now.c_str() ); db_tool::PushAsync(sql); log_info("[sql] %s", sql); memset(sql, 0, 1024); snprintf(sql, 1024, "insert into his_raw_data_sb(card_id, site_id, distance, acc, acc_x, acc_y, acc_z, ang, ang_x, ang_y, ang_z, cur_time) values('%s', %d, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, '%s')", sid.c_str(), siteId2, distance2, loc.m_ins_data.get_acc(), loc.m_ins_data.get_acc(0), loc.m_ins_data.get_acc(1), loc.m_ins_data.get_acc(2), loc.m_ins_data.get_gyro(), loc.m_ins_data.get_gyro(0), loc.m_ins_data.get_gyro(1), loc.m_ins_data.get_gyro(2), now.c_str() ); db_tool::PushAsync(sql); log_info("[sql] %s", sql); // 更新数据到发送线程 sys::sb_data sd; sd.cid = sid; sd.speed = 0.0; sd.site_info = site_info; sd.acc = loc.m_ins_data.get_acc(); sd.ang = loc.m_ins_data.get_gyro(); std::copy(loc.m_ins_data.m_acc_data.begin(), loc.m_ins_data.m_acc_data.end(), sd.m_acc_data.begin()); std::copy(loc.m_ins_data.m_ang_data.begin(), loc.m_ins_data.m_ang_data.end(), sd.m_ang_data.begin()); sd.cur_time = now; swsTimerThrd.upt_sb_data(std::move(sd)); logn_info(3, "[solid_ball] cid='%s', stamp=%d, sinfo='%s', acc = %.2f, acc_x = %.2f, acc_y = %.2f, acc_z = %.2f, ang = %.2f, ang_x = %.2f, ang_y = %.2f, ang_z = %.2f, t = '%s')", sid.c_str(), m_ct, site_info.c_str(), loc.m_ins_data.get_acc(), loc.m_ins_data.get_acc(0), loc.m_ins_data.get_acc(1), loc.m_ins_data.get_acc(2), loc.m_ins_data.get_gyro(), loc.m_ins_data.get_gyro(0), loc.m_ins_data.get_gyro(1), loc.m_ins_data.get_gyro(2), now.c_str() ); //清除数据 m_msg_list.erase(itm); //m_message_handle->on_message(loop, loc, is_history);*/ return; } m_ct = loc.m_card_ct; m_time = loc.m_time_stamp; auto site_ptr = sit_list::instance()->get(loc.m_site_id); if(!site_ptr) { log_warn("接收到分站的数据,site=%d,card=%d,ct=%d,但是分站未定义",loc.m_site_id,m_id,loc.m_card_ct); return; } m_message_handle->on_message(loop, loc, is_history); } /* * tdoa 调用算法库定位 * */ void card_location_base::on_message(zloop* loop, message_tdoa_locinfo& loc, bool is_history) { log_info("[tdoa] start calc location."); m_ct = loc.m_card_msg.m_sync_num; auto site_ptr = sit_list::instance()->get(loc.m_site_msg.m_site_id); if(!site_ptr){ log_warn("[tdoa] 接收到分站的数据:site=%d, card=%d, ct=%d, 但是分站未定义", loc.m_site_msg.m_site_id, m_id, loc.m_card_msg.m_time_stamp); return; } auto area_tool=get_area_tool(); area_tool->set_site(site_ptr); handle_message(loc.m_card_msg.m_time_stamp, loc.m_card_msg.m_battery_status); if(site_ptr->is_up_site()) {} else{ m_message_handle->on_message(loop, loc, is_history); } } /* * pdoa 调用算法库定位 * * */ void card_location_base::on_message(zloop* loop, message_pdoa_locinfo& loc, bool is_history) { m_ct = loc.m_card_ct; m_time = loc.m_time_stamp; auto site_ptr = sit_list::instance()->get(loc.m_site_id); if(!site_ptr){ log_warn("[pdoa] 接收到分站的数据:site=%d, card=%d, ct=%d, 但是分站未定义", loc.m_site_id, m_id, loc.m_card_ct); return; } site_ptr->m_loc_time = time(0); // 基站覆盖距离检测 do_site_coverage(loc); auto area_tool=get_area_tool(); area_tool->set_site(site_ptr); m_battery_value = loc.m_batty_status; // 电量值 handle_message(loc.m_card_ct, loc.m_batty_status); if(site_ptr->is_up_site()){ log_info("card=%d被井上分站[site=%d]收到", m_id, site_ptr->id()); area_tool->on_point(shared_from_this(), point(1,1)); this->site_hover(loc.m_site_id); m_last_site_id = site_ptr->id(); //m_last_down_stream_idx = site_ptr->m_down_stream_idx; m_cb_stream_idx.push_back(site_ptr->m_down_stream_idx); } else{ char sql[1024] = {0}; snprintf(sql, 1024, "insert into his_distance_reader(card_type, ident, reader_id, dist, dir, cur_time) values(%d, %d, %d, %.2f, %d, '%s')", loc.m_card_type, loc.m_card_id, loc.m_site_id, loc.m_tof*15.65*2.996*1E-4, (tool_other::get_pdoa(loc.m_poa, site_ptr->m_pdoa_offset)>=0?1:-1), tool_time::to_str(time(NULL)).c_str()); db_tool::PushAsync(sql); log_info("[sql] %s", sql); do_site_locate_event(loc); do_card_locate_event(loc); m_message_handle->on_message(loop, loc, is_history); } } //前端推送位置函数. void card_location_base::upt_card_pos(sys::_CARD_POS_&cp, point &pt) { point _p; if(pt.empty()) { _p = *this; pt = _p; } else _p = pt; cp.Type = m_type; cp.ID = m_id; cp.speed = abs(ceil(m_speed)); cp.x = tool_other::round(_p.x,3); cp.y = tool_other::round(_p.y,3); cp.running_stat = m_stat; cp.dept_id = m_deptid; cp.display = m_display; cp.rec_time = m_time; cp.level_id = m_level_id; cp.battery_val = m_battery_value; if(m_pwr_stat > 0){ cp.battery_stat = (m_pwr_stat<3?1:0); } cp.m_freq = m_freq; swsTimerThrd.upt_card_pos(cp); } void card_location_base::del_card_pos() { sys::_CARD_POS_ cp; cp.ID = m_id; cp.Type=m_type; swsTimerThrd.del_card_pos(cp); } int card_location_base::get_stat() { //盲区>呼救>呼叫>超时>超速>正常 uint64_t now = time(0)*1000; uint64_t tlost=now>m_time?now-m_time:m_time-now; if(tlost>CARD_LOST_TIME_OUT) { // 人卡盲区: 当人卡丢失信号大于60s,判定人卡进入盲区 return STATUS_LOST; } else if(auto ev_ptr = event_list::instance()->get_event_card(m_id, m_type, ET_CARD_HELP)) { return (ES_DEAL_HELP == ev_ptr->m_status) ? STATUS_HELP_DEALED : STATUS_HELP; } else if(CALL_NONE != get_mine_tool()->m_status_call) { return STATUS_CALL; } else if(is_person()) { if(event_list::instance()->get_event_card(m_id, m_type,ET_CARD_AREA_OVER_TIME_PERSON)|| event_list::instance()->get_event_card(m_id, m_type,ET_CARD_OVER_TIME_PERSON)) return STATUS_AREA_OVER_TIME; } else if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_OVER_SPEED)) { return STATUS_OVER_SPEED; } return STATUS_NORMAL; } void card_location_base::clear() { // uint16_t m_display; //1显示0不显示,往前端推送 m_speed=0; //速度 m_stat=0; //运动静止状态 //m_ct; //ct m_time=0; //时间戳 //pdoa location info clear m_buff_size = 0; m_last_recv_time = 0; m_last_point = point(0,0); m_last_site_id = 0; m_last_site_dir = -1; m_last_ct = 0; m_last_dist = 0.0; m_pdoa_diff = m_last_pdoa_diff = 100.0; m_last_over_site = false; m_cache_nums = 0; m_cb_pdoa.clear(); m_cb_tof.clear(); m_cb_point.clear(); } void card_location_base::put_traffic_light(card_pos& cp) { if(!traffic_light_flag){ return; } light_message lm; lm.m_cmd = cmd_card_data; lm.m_pos.x = cp.x; lm.m_pos.y = cp.y; lm.m_pos.z = cp.z; lm.m_pos.m_card_id = m_id; lm.m_pos.m_type = m_type; lm.m_pos.m_site_id = cp.reader_id; auto site_ptr = get_area_tool()->m_site; if(site_ptr){ lm.m_pos.m_area_id = site_ptr->m_area_id; } //lm.m_pos.m_bigger = 0; lm.m_pos.m_speed = m_speed; log_info("[traffic_light] put locate info into traffic light module, card_id=%d, ctype=%d, x=%.2f, y=%.2f, site_id=%d", m_id, m_type, x, y, cp.reader_id); traffic_light_manager::instance()->put(lm); } bool card_location_base::is_person() const { return tool_other::is_person(m_type); } bool card_location_base::is_vehicle() const { return tool_other::is_vehicle(m_type); } void card_location_base::set_base_data(uint32_t cid,uint16_t type,uint32_t deptid,int32_t level_id) { m_cid = cid; m_type = type; m_deptid = deptid; m_level_id = level_id; m_his_location_card->set_cid(cid); } card_location_base::~card_location_base() { } std::shared_ptr card_location_base::make_person(const std::string&type,uint32_t cardid,uint16_t needdisplay,int16_t t, int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string &sname,const std::string & dname,int worktype_id) { return std::make_shared(type, cardid, needdisplay, t, deptid, level_id, cid, wl, sname, dname, worktype_id); } /* * @brief 创建车辆对象 * @param const std::string& type * @param uint32_t cardid 卡id * @param uint16_t needdisplay 是否需要显示 * @param int16_t t * @param int32_t deptid 部门id * @param int32_t categoryid * @param int type_id 卡类型id * @param int32_t level_id 职级id * @param uint32_t cid * @return 车辆对象 * @note * @bug * @warning * */ std::shared_ptr card_location_base::make_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) { return std::make_shared(type, cardid, needdisplay, t, deptid, categoryid, type_id, level_id, cid); } /* * @brief 基站覆盖距离检测 * @param message_pdoa_locinfo& loc 卡数据 * @return 无 * @note * @bug * @warning * */ void card_location_base::do_site_coverage(message_pdoa_locinfo& loc) { auto site_ptr = sit_list::instance()->get(loc.m_site_id); if(!site_ptr){ log_warn("[pdoa] 接收到分站的数据:site=%d, card=%d, ct=%d, 但是分站未定义", loc.m_site_id, m_id, loc.m_card_ct); return; } double pdoa = tool_other::get_pdoa(loc.m_poa, site_ptr->m_pdoa_offset); double dist = loc.m_tof*15.65*2.996*1e-4; bool is_update = false; if(pdoa > 0){ if(dist > site_ptr->m_coverage[0].m_distance){ site_ptr->m_coverage[0].m_distance = dist; site_ptr->m_coverage[0].m_cid = tool_byte::to_cardid(loc.m_card_type, loc.m_card_id); site_ptr->m_coverage[0].m_time = time(0); is_update = true; } }else{ if(dist > site_ptr->m_coverage[1].m_distance){ site_ptr->m_coverage[1].m_distance = dist; site_ptr->m_coverage[1].m_cid = tool_byte::to_cardid(loc.m_card_type, loc.m_card_id); site_ptr->m_coverage[1].m_time = time(0); is_update = true; } } if(is_update){ char sql[1024] = {0}; snprintf(sql, 1024, "REPLACE INTO his_reader_coverage(reader_id, plus_dist, plus_card_id, plus_occur_time, minus_dist, minus_card_id, minus_occur_time, last_update) VALUES(%d,%.2f,'%s','%s',%.2f,'%s','%s','%s');", site_ptr->m_id, site_ptr->m_coverage[0].m_distance, site_ptr->m_coverage[0].m_cid.c_str(), tool_time::to_str(site_ptr->m_coverage[0].m_time).c_str(), site_ptr->m_coverage[1].m_distance, site_ptr->m_coverage[1].m_cid.c_str(), tool_time::to_str(site_ptr->m_coverage[1].m_time).c_str(), tool_time::to_str(time(0)).c_str()); db_tool::PushAsync(sql); logn_info(2, "[sql] %s", sql); } } /* * @brief 卡定位异常检测 * @param message_pdoa_locinfo& loc 卡数据 * @return 无 * @note * @bug * @warning * */ void card_location_base::do_card_locate_event(const message_pdoa_locinfo& loc) { bool status = false; status = ((loc.m_tof == 0)?true:false); uint64_t id = tool_other::type_id_to_u64(m_type, m_id); event_tool::instance()->handle_event(OT_CARD, ET_CARD_LOCATE_ERROR, id, 0, 0, status); //log_info("[card-locate-event] card_id=%d, ct=%d, tof=%lld", m_id, m_ct, loc.m_tof); } /* * @brief 基站定位异常检测 * @param message_pdoa_locinfo& loc 卡数据 * @return 无 * @note * @bug * @warning * */ void card_location_base::do_site_locate_event(const message_pdoa_locinfo& loc) { //log_info("[site-locate-event] cur_ct=%d, ct=%d, m_last_ct=%d, m_last_site_id=%d, loc.m_site_id=%d", loc.m_card_ct, ct, m_last_ct, m_last_site_id, loc.m_site_id); if(m_last_ct <= 0 || m_last_site_id == 0){ return; } if(loc.m_site_id != m_last_site_id){ return; } int dt = 0; if(loc.m_card_ct > m_last_ct){ dt = loc.m_card_ct - m_last_ct; }else{ dt = 65535 + loc.m_card_ct - m_last_ct; } event_tool::instance()->handle_event(OT_DEVICE_READER, ET_READER_LONG_TIME_NO_POSITION, loc.m_site_id, 3, dt, (dt>=3)); log_info("[site-locate-event] site_id=%d, card_id=%d, ct=%d, dt=%d", loc.m_site_id, m_id, loc.m_card_ct, dt); }