123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- #include <memory>
- #include <message.h>
- #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 "three_rates.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"
- 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));
- }
- }
- void card_location_base::do_status(int st)
- {
- time_t now=time(0);
- bool help_flag=false;
- 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("handle_m_help,card_id:%d\n",m_id);
- help_flag=true;
- }
- m_help_last_time=now;
- m_help_bit<<=1;
- m_help_bit|=1;
- }
- else
- {
- // 11111111100000
- // ^
- if(now-m_help_last_time>60)
- {
- m_help_bit=0;
- }
- }
- 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;
- }
-
- //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::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
- {
- loc_point pt = m_sel_tool->select_solution(vp, lm);
- pt.y = pt.y;
-
- auto site_ptr = get_area_tool()->m_site;
- int sid = 0;
- if(site_ptr)
- sid = site_ptr->m_id;
- if(pt.m_useless)
- {
- x = tool_other::round(pt.x,3);
- y = tool_other::round(pt.y,3);
- 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);
- }
- else
- {
- log_warn("坐标不可用:site=%d,type=%d,card=%d,ct=%d,x=%f,y=%f",sid,m_type,m_id,m_ct,pt.x,pt.y);
- }
- }
- void card_location_base::on_message(zloop<task*>* 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);
- }
- }
- /*
- * tdoa 调用算法库定位
- * */
- void card_location_base::on_message(zloop<task*>* 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<task*>* 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;
- }
- 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{
- m_message_handle->on_message(loop, loc, is_history);
- }
- }
- //前端推送位置函数.
- void card_location_base::upt_card_pos(YA::_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.stat = m_pwr_stat;
- cp.m_freq = m_freq;
-
- swsTimerThrd.upt_card_pos(cp);
- }
- void card_location_base::del_card_pos()
- {
- YA::_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_cb_pdoa.clear();
- m_cb_tof.clear();
- m_cb_point.clear();
- }
- void card_location_base::put_three_rates(card_pos & cp)
- {
- if(!three_rates_flag)
- return;
-
- cp.rec_time = m_time;
- cp.type = m_type;
- cp.id = m_id;
- cp.identifier_id= m_cid;
- cp.running_stat = m_stat;
- cp.final_v = m_speed;
- cp.dpt_id = m_deptid;
- std::shared_ptr<area_tool> _areatool = get_area_tool();
- if(nullptr != _areatool && nullptr != _areatool->m_site)
- {
- cp.reader_x = _areatool->m_site->x;
- cp.reader_y = _areatool->m_site->y;
- cp.reader_id = _areatool->m_site->m_id;
- }
- log_info("three_rates:type:%d,id:%d,cid:%d",cp.type,cp.id,cp.identifier_id);
- three_rates::get_instance()->put(cp);
- }
- 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;
- 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", m_id, m_type, x, y);
- 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> 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<person>(type,cardid,needdisplay,t, deptid,level_id,cid,wl,sname,dname,worktype_id);
- }
- std::shared_ptr<card_location_base> 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<car>(type,cardid,needdisplay,t, deptid, categoryid, type_id,level_id,cid);
- }
|