card.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. #include <memory>
  2. #include <log.h>
  3. #include <zloop.h>
  4. #include "select_tool.h"
  5. #include "loc_tool.h"
  6. #include <area.h>
  7. #include <site_area.h>
  8. #include <card.h>
  9. #include "config_file.h"
  10. #include "db_api/CDBConnPool.h"
  11. #include "websocket/wsTimerThread.h"
  12. #include "websocket/wsClientMgr.h"
  13. #include "timestamp.h"
  14. #include "monkey_car/monkeycar_area.h"
  15. #include "monkey_car/monkeycar_person.h"
  16. #include "special_area.h"
  17. #include "mine.h"
  18. #include "module_service/module_mgr.h"
  19. extern config_file config;
  20. //一张卡一个ct的所有不同天线的信息
  21. struct one_ct_message_handle
  22. {
  23. static loc_tool_main m_loc_tool;
  24. ev::timer m_min_timer,m_max_timer;
  25. //loc_message.
  26. std::vector<loc_message> m_msg_list;
  27. card_location_base*m_card;
  28. const algo_config*m_ac=nullptr;
  29. int m_ct;
  30. bool m_min_timeout=false;
  31. ev::dynamic_loop * m_loop = nullptr;
  32. one_ct_message_handle(card_location_base*card)
  33. {
  34. m_card=card;
  35. m_ct=-1;
  36. }
  37. void reset()
  38. {
  39. m_ct=-1;
  40. m_min_timeout=false;
  41. m_msg_list.clear();
  42. }
  43. void on_min_timer()
  44. {
  45. m_min_timer.stop();
  46. if((int)m_msg_list.size()>=m_ac->best_msg_cnt)
  47. {
  48. m_max_timer.stop();
  49. calc_location();
  50. return;
  51. }
  52. m_min_timeout=true;
  53. }
  54. void on_max_timer()
  55. {
  56. m_max_timer.stop();
  57. calc_location();
  58. }
  59. void set(ev::dynamic_loop * loop)
  60. {
  61. m_loop = loop;
  62. m_min_timer.set(*m_loop);
  63. m_min_timer.set<one_ct_message_handle,&one_ct_message_handle::on_min_timer>(this);
  64. m_max_timer.set(*m_loop);
  65. m_max_timer.set<one_ct_message_handle,&one_ct_message_handle::on_max_timer>(this);
  66. }
  67. void on_message(ev::dynamic_loop *loop,const message_locinfo&loc)
  68. {
  69. if(m_loop == nullptr && loop!=nullptr)
  70. set(loop);
  71. else if(loop == nullptr)
  72. return;
  73. if(!m_msg_list.empty()&& m_ct!=loc.m_card_ct)
  74. {
  75. m_msg_list.clear();
  76. }
  77. auto sitPtr = sit_list::instance()->get(loc.m_site_id);
  78. if(sitPtr==nullptr)
  79. {
  80. log_warn("分站信息缺失,SitId:%d",loc.m_site_id);
  81. return;
  82. }
  83. const site &s=*(sit_list::instance()->get(loc.m_site_id));
  84. if(m_msg_list.empty())
  85. {
  86. m_ct=loc.m_card_ct;
  87. m_ac=&s.config();
  88. m_min_timeout=false;
  89. //这里构造loc_message 保存数据
  90. m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
  91. loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
  92. loc.m_sync_ct,loc.m_rssi));
  93. //启动本CT的最小、最大两个定时器
  94. m_min_timer.start(m_ac->min_wait_time);
  95. m_max_timer.start(m_ac->min_wait_time);
  96. return;
  97. }
  98. m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
  99. loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
  100. loc.m_sync_ct,loc.m_rssi));
  101. if(m_min_timeout && (int)m_msg_list.size()>=m_ac->best_msg_cnt)
  102. {
  103. calc_location();
  104. m_max_timer.stop();
  105. }
  106. }
  107. void calc_location()
  108. {
  109. auto v = m_msg_list;
  110. std::vector<point> rc=std::move(m_loc_tool.calc_location(v));
  111. if(!rc.empty()) m_card->on_location(std::move(rc),v);
  112. reset();
  113. }
  114. };
  115. struct card_message_handle
  116. {
  117. card_location_base*m_card;
  118. std::array<one_ct_message_handle*,16> m_ct_list;
  119. card_message_handle(card_location_base*card)
  120. {
  121. m_card=card;
  122. for(size_t i=0;i<m_ct_list.size();i++)
  123. {
  124. m_ct_list[i]=new one_ct_message_handle(card);
  125. }
  126. }
  127. ~card_message_handle()
  128. {
  129. for(auto&it:m_ct_list)
  130. {
  131. delete it;
  132. }
  133. }
  134. void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  135. {
  136. if(is_history)
  137. {
  138. log_warn("%s","当前代码没有处理历史消息记录。");
  139. return;
  140. }
  141. //
  142. m_card->site_hover(loc.m_site_id);
  143. if(loc.m_batty_status == 2)
  144. {
  145. //m_card->do_status(STA_TYPE::STATUS_LOW_POWER_);
  146. m_card->do_status(STATUS_POWER_LOWER);
  147. }
  148. else if(loc.m_callinfo == 0x80)
  149. {
  150. //m_card->do_status(STA_TYPE::STATUS_HELP_);
  151. m_card->do_status(STATUS_HELP);
  152. }
  153. else if(loc.m_callinfo == 0x01 || loc.m_callinfo == 0x02)
  154. {
  155. m_card->do_status(STATUS_CALL);
  156. }
  157. m_ct_list[loc.m_card_ct&(m_ct_list.size()-1)]->on_message(loop,loc);
  158. }
  159. };
  160. struct card_area
  161. {
  162. card_area()
  163. {
  164. m_site_area.reset(new site_area_hover);
  165. m_area_tool.reset(new area_tool);
  166. m_mine_tool.reset(new mine_tool);
  167. }
  168. std::shared_ptr<site_area_hover> m_site_area=nullptr;
  169. std::shared_ptr<area_tool> m_area_tool=nullptr;
  170. std::shared_ptr<mine_tool> m_mine_tool=nullptr;
  171. };
  172. struct person:card_location_base,private card_area
  173. {
  174. std::weak_ptr<monkey_person> m_monkeyPerson;
  175. person(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid)
  176. :card_location_base(type,cardid,needdisplay,t,deptid)
  177. {
  178. m_message_handle = new card_message_handle(this);
  179. }
  180. void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  181. {
  182. m_message_handle->on_message(loop,loc,is_history);
  183. }
  184. void clear()
  185. {
  186. //清除定时器
  187. m_timer.stop();
  188. m_loop = nullptr;
  189. m_site_area.reset(new site_area_hover);
  190. m_area_tool.reset(new area_tool);
  191. m_mine_tool.reset(new mine_tool);
  192. card_location_base::clear();
  193. }
  194. virtual void site_hover(int sid)
  195. {
  196. if(m_time<=0)
  197. {
  198. return;
  199. }
  200. m_site_area->on_point(m_id,sid,nullptr, m_type);
  201. }
  202. virtual std::shared_ptr<area_hover> get_area_hover()
  203. {
  204. return m_area_tool->m_area_hover;
  205. }
  206. virtual std::shared_ptr<mine_tool> get_mine_tool()
  207. {
  208. return m_mine_tool;
  209. }
  210. virtual std::shared_ptr<site_area_hover> get_site_area()
  211. {
  212. return m_site_area;
  213. }
  214. virtual void do_business(const point &pt)
  215. {
  216. //区域
  217. m_area_tool->on_point(m_id,pt,m_speed,m_type);
  218. //考勤
  219. m_site_area->on_point(m_id,0,this, m_type);
  220. //
  221. }
  222. //人卡升井后该线程要停掉
  223. //手动升级需要补全区域得同时,需要进区域走区域业务
  224. void set(ev::dynamic_loop * loop)
  225. {
  226. log_info("cardid_id %d",m_id);
  227. m_loop = loop;
  228. m_timer.set(*m_loop);
  229. m_timer.set<person,&person::on_timer>(this);
  230. m_timer.start(1,1);
  231. }
  232. void reset(std::shared_ptr<monkey_person> mp)
  233. {
  234. m_monkeyPerson = mp;
  235. }
  236. ~person(){}
  237. private:
  238. void on_timer()
  239. {
  240. YA::_CARD_POS_ cp;
  241. point pt = getSmoothPoint();
  242. const auto lm = m_area_tool->getLandmark();
  243. cp.enter_area_time = std::get<0>(lm);
  244. cp.rec_time = std::get<1>(lm);
  245. cp.map_id = std::get<2>(lm);
  246. cp.area_id = std::get<3>(lm);
  247. cp.landmark_id = std::get<4>(lm);
  248. cp.lm_direction = std::get<5>(lm);
  249. cp.landmark_dis=std::get<6>(lm);
  250. cp.biz_stat = state();
  251. upt_card_pos(cp,pt);
  252. }
  253. int state()
  254. {
  255. int status = get_stat();
  256. if(status == STATUS_NORMAL)
  257. {
  258. //超时
  259. }
  260. return status;
  261. }
  262. point getSmoothPoint()
  263. {
  264. point pt;
  265. loc_point lp = m_smo_tool->smooth_strategy();
  266. m_speed = lp.m_speed;
  267. m_stat = lp.m_stat;
  268. pt.x = lp.x;
  269. pt.y = -lp.y;
  270. if(auto p = m_monkeyPerson.lock() )
  271. {
  272. if(p->is_on_bus())
  273. {
  274. m_stat = 7;
  275. pt = p->getPoint();
  276. }
  277. }
  278. return pt;
  279. }
  280. };
  281. struct car:card_location_base,private card_area
  282. {
  283. int m_vehicle_category_id=0;
  284. car(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t categoryid)
  285. :card_location_base(type,cardid,needdisplay,t,deptid)
  286. ,m_vehicle_category_id(categoryid)
  287. {
  288. m_message_handle=new card_message_handle(this);
  289. }
  290. virtual void site_hover(int sid)
  291. {
  292. if(m_time<=0)
  293. {
  294. return;
  295. }
  296. m_site_area->on_point(m_id,sid,0, m_type);
  297. }
  298. virtual std::shared_ptr<area_hover> get_area_hover()
  299. {
  300. return m_area_tool->m_area_hover;
  301. }
  302. virtual std::shared_ptr<mine_tool> get_mine_tool()
  303. {
  304. return m_mine_tool;
  305. }
  306. virtual std::shared_ptr<site_area_hover> get_site_area()
  307. {
  308. return m_site_area;
  309. }
  310. virtual void do_business(const point &pt)
  311. {
  312. m_area_tool->on_point(m_id,pt,m_speed,m_type);
  313. m_site_area->on_point(m_id,0,this, m_type);
  314. m_mine_tool->on_point(m_id, m_type, m_vehicle_category_id);
  315. }
  316. void set(ev::dynamic_loop * loop)
  317. {
  318. log_info("cardid_id %d",m_id);
  319. m_loop = loop;
  320. m_timer.set(*m_loop);
  321. m_timer.set<car,&car::on_timer>(this);
  322. m_timer.start(1,1);
  323. }
  324. ~car(){}
  325. private:
  326. void on_timer()
  327. {
  328. make_package();
  329. }
  330. int statbiz(int32_t special_id)
  331. {
  332. int status = get_stat();
  333. if(status==STATUS_NORMAL)
  334. {
  335. //超速
  336. //超时
  337. //顺序不能变
  338. }
  339. if(status == STATUS_LOST)
  340. {
  341. if(!m_area_tool->special_area())
  342. {
  343. special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
  344. log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
  345. if(special_id != -1)
  346. m_area_tool->change_area(m_id,m_speed,m_type,special_id);//自动拖车
  347. }
  348. }
  349. return status;
  350. }
  351. void make_package()
  352. {
  353. int32_t special_id=-1;
  354. YA::_CARD_POS_ cp;
  355. point pt = getSmoothPoint();
  356. const auto lm = m_area_tool->getLandmark();
  357. cp.enter_area_time = std::get<0>(lm);
  358. cp.rec_time = std::get<1>(lm);
  359. cp.map_id = std::get<2>(lm);
  360. cp.area_id = std::get<3>(lm);
  361. cp.landmark_id = std::get<4>(lm);
  362. cp.lm_direction = std::get<5>(lm);
  363. cp.landmark_dis=std::get<6>(lm);
  364. int32_t biz_stat=statbiz(special_id);
  365. cp.biz_stat=biz_stat;
  366. //cp.down_time
  367. //cp.work_time;
  368. //cp.level_id;
  369. //for now
  370. cp.is_on_duty=1;
  371. upt_card_pos(cp,pt);
  372. if(biz_stat==STATUS_LOST && special_id != -1 && m_display==1)
  373. {
  374. cp.area_id = special_id;
  375. swsClientMgr.SendSpecialAreaProcess(cp);
  376. }
  377. }
  378. point getSmoothPoint()
  379. {
  380. loc_point lp = m_smo_tool->smooth_strategy();
  381. m_speed = lp.m_speed;
  382. m_stat = lp.m_stat;
  383. lp.y = -lp.y;
  384. return lp;
  385. }
  386. };
  387. loc_tool_main one_ct_message_handle::m_loc_tool;
  388. uint64_t card_list::getId(uint32_t cardid,uint64_t type)
  389. {
  390. return type<<32|cardid;
  391. }
  392. void card_list::init_vehicle()
  393. {
  394. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  395. std::string strategy = config.get("person.strategy","car1");
  396. const char *sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
  397. ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
  398. vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
  399. vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
  400. FROM dat_vehicle_extend ve \
  401. LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
  402. LEFT JOIN dat_card c ON ve.card_id = c.card_id \
  403. LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
  404. LEFT JOIN dat_group g ON ve.group_id = g.group_id \
  405. LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
  406. LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
  407. WHERE c.card_type_id = 2 AND c.state_id = 0;";
  408. std::string Error;
  409. YADB::CDBResultSet DBRes;
  410. sDBConnPool.Query(sql,DBRes,Error);
  411. int nCount = DBRes.GetRecordCount( Error );
  412. if (nCount > 0)
  413. {
  414. log_info( "init_staffer. The record count=%d\n", nCount );
  415. while ( DBRes.GetNextRecod(Error) )
  416. {
  417. unsigned int vehicle_id = 0;
  418. DBRes.GetField( "vehicle_id",vehicle_id, Error );
  419. std::string card_id;
  420. DBRes.GetField( "card_id",card_id, Error );
  421. uint32_t vsid = atoi(card_id.substr(3).c_str());
  422. unsigned int card_type_id = 0;
  423. DBRes.GetField( "card_type_id",card_type_id, Error );
  424. int dept_id = 0;
  425. DBRes.GetField( "dept_id",dept_id, Error );
  426. int group_id = 0;
  427. DBRes.GetField( "group_id",group_id, Error );
  428. int vehicle_type_id = 0;
  429. DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
  430. int vehicle_level_id = 0;
  431. DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
  432. int need_display = 0;
  433. DBRes.GetField( "need_display",need_display, Error );
  434. int power_alarm = 0;
  435. DBRes.GetField( "power_alarm",power_alarm, Error );
  436. int vehicle_category_id = 0;
  437. DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
  438. int bigger_car_flag= 0;
  439. DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
  440. double over_speed= 0;
  441. DBRes.GetField( "over_speed",over_speed, Error );
  442. //for now
  443. vehicle_id = vsid;
  444. std::shared_ptr<card_location_base> clb = std::make_shared<car>(strategy,vehicle_id,need_display,card_type_id,dept_id,vehicle_category_id);
  445. uint64_t cardid = getId(vehicle_id,2);
  446. log_info("cardId:%llu,vehicle_id:%d dept_id:%d,need_display:%d---cardid:%s,categoryid:%d",cardid,vehicle_id,dept_id,need_display,card_id.c_str(),vehicle_category_id);
  447. map.insert({cardid,clb});
  448. }
  449. }
  450. card_list::instance()->add(map);
  451. }
  452. void card_list::init_staffer()
  453. {
  454. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  455. std::string strategy = config.get("person.strategy","person1");
  456. const char *sql = "SELECT staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
  457. ol.occupation_level_id,s.worktype_id,s.need_display \
  458. FROM dat_staff_extend s \
  459. LEFT JOIN dat_card c ON s.card_id = c.card_id \
  460. LEFT JOIN dat_occupation o ON s.occupation_id = o.occupation_id \
  461. LEFT JOIN dat_occupation_level ol ON ol.occupation_level_id = o.occupation_level_id \
  462. WHERE c.card_type_id = 1 AND s.duty_id = 0 AND c.state_id = 0;";
  463. std::string Error;
  464. YADB::CDBResultSet DBRes;
  465. sDBConnPool.Query(sql,DBRes,Error);
  466. int nCount = DBRes.GetRecordCount( Error );
  467. if (nCount > 0)
  468. {
  469. log_info( "init_staffer. The record count=%d\n", nCount );
  470. while ( DBRes.GetNextRecod(Error) )
  471. {
  472. unsigned int staff_id = 0;
  473. DBRes.GetField( "staff_id",staff_id, Error );
  474. std::string card_id;
  475. DBRes.GetField( "card_id",card_id, Error );
  476. uint32_t vsid = atoi(card_id.substr(3).c_str());
  477. unsigned int card_type_id = 0;
  478. DBRes.GetField( "card_type_id",card_type_id, Error );
  479. int dept_id = 0;
  480. DBRes.GetField( "dept_id",dept_id, Error );
  481. int group_id = 0;
  482. DBRes.GetField( "group_id",group_id, Error );
  483. int occupation_id = 0;
  484. DBRes.GetField( "occupation_id",occupation_id, Error );
  485. int occupation_level_id = 0;
  486. DBRes.GetField( "occupation_level_id",occupation_level_id, Error );
  487. int need_display = 0;
  488. DBRes.GetField( "need_display",need_display, Error );
  489. //for now;
  490. staff_id = vsid;
  491. std::shared_ptr<card_location_base> clb = std::make_shared<person>(strategy,staff_id,need_display,card_type_id,dept_id);
  492. uint64_t cardid = getId(staff_id,1);
  493. log_info("cardId:%llu,staff_id:%d dept_id:%d,need_display:%d--c-ard:%s",cardid,staff_id,dept_id,need_display,card_id.c_str());
  494. map.insert({cardid,clb});
  495. }
  496. }
  497. card_list::instance()->add(map);
  498. }
  499. void card_list::init_card_from_db()
  500. {
  501. init_staffer();
  502. init_vehicle();
  503. }
  504. void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history)
  505. {
  506. //std::shared_ptr<card_location_base>c=get(loc.m_card_id);
  507. uint64_t cardid = getId(loc.m_card_id,loc.m_card_type);
  508. const auto c=get(cardid);
  509. if(c==nullptr)
  510. {
  511. log_warn("数据库中未定义该卡的信息,card_id=%d", loc.m_card_id);
  512. return;
  513. }
  514. log_info("card message:site=%d,ant=%d,card=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d,stamp=%llu",
  515. loc.m_site_id,loc.m_ant_id,loc.m_card_id,loc.m_tof,loc.m_rav,loc.m_acc,loc.m_rssi,loc.m_time_stamp);
  516. c->on_message(loop,loc,is_history);
  517. }
  518. //-----------------card_location_base..
  519. card_location_base::card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid)
  520. :card(id,dis,t,deptid)
  521. {
  522. select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool);
  523. }
  524. void card_location_base::do_status(STATUS_CARD st)
  525. {
  526. module_mgr::do_status(st, m_id, m_type);
  527. }
  528. void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
  529. {
  530. //ct timestamp;
  531. m_ct = lm[0].m_card_ct;
  532. m_time = lm[0].m_loc_time;
  533. loc_point pt = m_sel_tool->select_solution(vp,lm);
  534. pt.y=-pt.y;
  535. if(pt.m_useless)
  536. {
  537. x = pt.x;
  538. y = pt.y;
  539. log_info("card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%.2f,y:%.2f ",m_id,m_ct,m_time,pt.x,pt.y);
  540. do_business(pt);
  541. }
  542. }
  543. void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  544. {
  545. if(m_loop == nullptr && loop != nullptr)
  546. set(loop);
  547. m_message_handle->on_message(loop,loc,is_history);
  548. }
  549. //前端推送位置函数
  550. void card_location_base::upt_card_pos(YA::_CARD_POS_ &cp,const point &pt)
  551. {
  552. cp.x = pt.x;
  553. cp.y = pt.y;
  554. cp.z = pt.z;
  555. cp.Type=m_type;
  556. cp.ID = m_id;
  557. cp.speed = abs(ceil(m_speed));
  558. cp.running_stat = m_stat;
  559. cp.dept_id = m_deptid;
  560. cp.display=m_display;
  561. cp.rec_time=m_time;
  562. swsTimerThrd.upt_card_pos(cp);
  563. }
  564. int card_location_base::get_stat()
  565. {
  566. //盲区>呼救>呼叫>超时>超速>正常
  567. uint64_t now = time(0)*1000;
  568. if(now-m_time>CARD_LOST_TIME_OUT)
  569. {
  570. return STATUS_LOST;
  571. }
  572. else if(auto ev_ptr = event_list::instance()->get(m_id, ET_CARD_HELP))
  573. {
  574. return (ES_DEAL_HELP == ev_ptr->m_status) ? STATUS_HELP_DEALED : STATUS_HELP;
  575. }
  576. else if(0 != get_mine_tool()->m_status_call)
  577. {
  578. return STATUS_CALL;
  579. }
  580. else if(event_list::instance()->get(m_id, ET_CARD_AREA_OVER_TIME_PERSON))
  581. {
  582. return STATUS_AREA_OVER_TIME;
  583. }
  584. else if(event_list::instance()->get(m_id, ET_CARD_OVER_SPEED))
  585. {
  586. return STATUS_OVER_SPEED;
  587. }
  588. return STATUS_NORMAL;
  589. }
  590. void card_location_base::clear()
  591. {
  592. // uint16_t m_display; //1显示0不显示,往前端推送
  593. m_speed=0; //速度
  594. m_is_attendance=0; //井上井下状态 0初始状态 1 井上 2 井下
  595. m_stat=0; //运动静止状态
  596. //m_ct; //ct
  597. m_time=0; //时间戳
  598. }
  599. card_location_base::~card_location_base()
  600. {
  601. }
  602. template<> std::shared_ptr<card_list>
  603. single_base<card_list, uint64_t, std::shared_ptr<card_location_base>>::m_instance=std::make_shared<card_list>();