card.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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. int m_vehicle_type_id=0;
  285. car(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
  286. int32_t categoryid, int type_id)
  287. :card_location_base(type,cardid,needdisplay,t,deptid)
  288. ,m_vehicle_category_id(categoryid)
  289. ,m_vehicle_type_id(type_id)
  290. {
  291. m_message_handle=new card_message_handle(this);
  292. }
  293. virtual void site_hover(int sid)
  294. {
  295. if(m_time<=0)
  296. {
  297. return;
  298. }
  299. m_site_area->on_point(m_id,sid,0, m_type);
  300. }
  301. virtual std::shared_ptr<area_hover> get_area_hover()
  302. {
  303. return m_area_tool->m_area_hover;
  304. }
  305. virtual std::shared_ptr<mine_tool> get_mine_tool()
  306. {
  307. return m_mine_tool;
  308. }
  309. virtual std::shared_ptr<site_area_hover> get_site_area()
  310. {
  311. return m_site_area;
  312. }
  313. virtual void do_business(const point &pt)
  314. {
  315. m_area_tool->on_point(m_id,pt,m_speed,m_type);
  316. m_site_area->on_point(m_id,0,this, m_type);
  317. m_mine_tool->on_point(m_id, m_type, m_vehicle_category_id);
  318. }
  319. void set(ev::dynamic_loop * loop)
  320. {
  321. log_info("cardid_id %d",m_id);
  322. m_loop = loop;
  323. m_timer.set(*m_loop);
  324. m_timer.set<car,&car::on_timer>(this);
  325. m_timer.start(1,1);
  326. }
  327. int get_vehicle_type_id()
  328. {
  329. return m_vehicle_type_id;
  330. }
  331. ~car(){}
  332. private:
  333. void on_timer()
  334. {
  335. make_package();
  336. }
  337. int statbiz(int32_t special_id)
  338. {
  339. int status = get_stat();
  340. if(status==STATUS_NORMAL)
  341. {
  342. //超速
  343. //超时
  344. //顺序不能变
  345. }
  346. if(status == STATUS_LOST)
  347. {
  348. if(!m_area_tool->special_area())
  349. {
  350. special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
  351. log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
  352. if(special_id != -1)
  353. m_area_tool->change_area(m_id,m_speed,m_type,special_id);//自动拖车
  354. }
  355. }
  356. return status;
  357. }
  358. void make_package()
  359. {
  360. int32_t special_id=-1;
  361. YA::_CARD_POS_ cp;
  362. point pt = getSmoothPoint();
  363. const auto lm = m_area_tool->getLandmark();
  364. cp.enter_area_time = std::get<0>(lm);
  365. cp.rec_time = std::get<1>(lm);
  366. cp.map_id = std::get<2>(lm);
  367. cp.area_id = std::get<3>(lm);
  368. cp.landmark_id = std::get<4>(lm);
  369. cp.lm_direction = std::get<5>(lm);
  370. cp.landmark_dis=std::get<6>(lm);
  371. int32_t biz_stat=statbiz(special_id);
  372. cp.biz_stat=biz_stat;
  373. //cp.down_time
  374. //cp.work_time;
  375. //cp.level_id;
  376. //for now
  377. cp.is_on_duty=1;
  378. upt_card_pos(cp,pt);
  379. if(biz_stat==STATUS_LOST && special_id != -1 && m_display==1)
  380. {
  381. cp.area_id = special_id;
  382. swsClientMgr.SendSpecialAreaProcess(cp);
  383. }
  384. }
  385. point getSmoothPoint()
  386. {
  387. loc_point lp = m_smo_tool->smooth_strategy();
  388. m_speed = lp.m_speed;
  389. m_stat = lp.m_stat;
  390. lp.y = -lp.y;
  391. return lp;
  392. }
  393. };
  394. loc_tool_main one_ct_message_handle::m_loc_tool;
  395. uint64_t card_list::getId(uint32_t cardid,uint64_t type)
  396. {
  397. return type<<32|cardid;
  398. }
  399. void card_list::init_vehicle()
  400. {
  401. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  402. std::string strategy = config.get("person.strategy","car1");
  403. const char *sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
  404. ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
  405. vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
  406. vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
  407. FROM dat_vehicle_extend ve \
  408. LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
  409. LEFT JOIN dat_card c ON ve.card_id = c.card_id \
  410. LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
  411. LEFT JOIN dat_group g ON ve.group_id = g.group_id \
  412. LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
  413. LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
  414. WHERE c.card_type_id = 2 AND c.state_id = 0;";
  415. std::string Error;
  416. YADB::CDBResultSet DBRes;
  417. sDBConnPool.Query(sql,DBRes,Error);
  418. int nCount = DBRes.GetRecordCount( Error );
  419. if (nCount > 0)
  420. {
  421. log_info( "init_staffer. The record count=%d\n", nCount );
  422. while ( DBRes.GetNextRecod(Error) )
  423. {
  424. unsigned int vehicle_id = 0;
  425. DBRes.GetField( "vehicle_id",vehicle_id, Error );
  426. std::string card_id;
  427. DBRes.GetField( "card_id",card_id, Error );
  428. uint32_t vsid = atoi(card_id.substr(3).c_str());
  429. unsigned int card_type_id = 0;
  430. DBRes.GetField( "card_type_id",card_type_id, Error );
  431. int dept_id = 0;
  432. DBRes.GetField( "dept_id",dept_id, Error );
  433. int group_id = 0;
  434. DBRes.GetField( "group_id",group_id, Error );
  435. int vehicle_type_id = 0;
  436. DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
  437. int vehicle_level_id = 0;
  438. DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
  439. int need_display = 0;
  440. DBRes.GetField( "need_display",need_display, Error );
  441. int power_alarm = 0;
  442. DBRes.GetField( "power_alarm",power_alarm, Error );
  443. int vehicle_category_id = 0;
  444. DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
  445. int bigger_car_flag= 0;
  446. DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
  447. double over_speed= 0;
  448. DBRes.GetField( "over_speed",over_speed, Error );
  449. //for now
  450. vehicle_id = vsid;
  451. std::shared_ptr<card_location_base> clb = std::make_shared<car>(strategy,vehicle_id,
  452. need_display,card_type_id,dept_id,vehicle_category_id, vehicle_type_id);
  453. uint64_t cardid = getId(vehicle_id,2);
  454. 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);
  455. map.insert({cardid,clb});
  456. }
  457. }
  458. card_list::instance()->add(map);
  459. }
  460. void card_list::init_staffer()
  461. {
  462. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  463. std::string strategy = config.get("person.strategy","person1");
  464. const char *sql = "SELECT staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
  465. ol.occupation_level_id,s.worktype_id,s.need_display \
  466. FROM dat_staff_extend s \
  467. LEFT JOIN dat_card c ON s.card_id = c.card_id \
  468. LEFT JOIN dat_occupation o ON s.occupation_id = o.occupation_id \
  469. LEFT JOIN dat_occupation_level ol ON ol.occupation_level_id = o.occupation_level_id \
  470. WHERE c.card_type_id = 1 AND s.duty_id = 0 AND c.state_id = 0;";
  471. std::string Error;
  472. YADB::CDBResultSet DBRes;
  473. sDBConnPool.Query(sql,DBRes,Error);
  474. int nCount = DBRes.GetRecordCount( Error );
  475. if (nCount > 0)
  476. {
  477. log_info( "init_staffer. The record count=%d\n", nCount );
  478. while ( DBRes.GetNextRecod(Error) )
  479. {
  480. unsigned int staff_id = 0;
  481. DBRes.GetField( "staff_id",staff_id, Error );
  482. std::string card_id;
  483. DBRes.GetField( "card_id",card_id, Error );
  484. uint32_t vsid = atoi(card_id.substr(3).c_str());
  485. unsigned int card_type_id = 0;
  486. DBRes.GetField( "card_type_id",card_type_id, Error );
  487. int dept_id = 0;
  488. DBRes.GetField( "dept_id",dept_id, Error );
  489. int group_id = 0;
  490. DBRes.GetField( "group_id",group_id, Error );
  491. int occupation_id = 0;
  492. DBRes.GetField( "occupation_id",occupation_id, Error );
  493. int occupation_level_id = 0;
  494. DBRes.GetField( "occupation_level_id",occupation_level_id, Error );
  495. int need_display = 0;
  496. DBRes.GetField( "need_display",need_display, Error );
  497. //for now;
  498. staff_id = vsid;
  499. std::shared_ptr<card_location_base> clb = std::make_shared<person>(strategy,staff_id,need_display,card_type_id,dept_id);
  500. uint64_t cardid = getId(staff_id,1);
  501. 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());
  502. map.insert({cardid,clb});
  503. }
  504. }
  505. card_list::instance()->add(map);
  506. }
  507. void card_list::init_card_from_db()
  508. {
  509. init_staffer();
  510. init_vehicle();
  511. }
  512. void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history)
  513. {
  514. //std::shared_ptr<card_location_base>c=get(loc.m_card_id);
  515. uint64_t cardid = getId(loc.m_card_id,loc.m_card_type);
  516. const auto c=get(cardid);
  517. if(c==nullptr)
  518. {
  519. log_warn("数据库中未定义该卡的信息,card_id=%d", loc.m_card_id);
  520. return;
  521. }
  522. log_info("card message:site=%d,ant=%d,card=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d,stamp=%llu",
  523. 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);
  524. c->on_message(loop,loc,is_history);
  525. }
  526. //-----------------card_location_base..
  527. card_location_base::card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid)
  528. :card(id,dis,t,deptid)
  529. {
  530. select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool);
  531. }
  532. void card_location_base::do_status(STATUS_CARD st)
  533. {
  534. module_mgr::do_status(st, m_id, m_type);
  535. }
  536. void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
  537. {
  538. //ct timestamp;
  539. m_ct = lm[0].m_card_ct;
  540. m_time = lm[0].m_loc_time;
  541. loc_point pt = m_sel_tool->select_solution(vp,lm);
  542. pt.y=-pt.y;
  543. if(pt.m_useless)
  544. {
  545. x = pt.x;
  546. y = pt.y;
  547. 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);
  548. do_business(pt);
  549. }
  550. }
  551. void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  552. {
  553. if(m_loop == nullptr && loop != nullptr)
  554. set(loop);
  555. m_message_handle->on_message(loop,loc,is_history);
  556. }
  557. //前端推送位置函数
  558. void card_location_base::upt_card_pos(YA::_CARD_POS_ &cp,const point &pt)
  559. {
  560. cp.x = pt.x;
  561. cp.y = pt.y;
  562. cp.z = pt.z;
  563. cp.Type=m_type;
  564. cp.ID = m_id;
  565. cp.speed = abs(ceil(m_speed));
  566. cp.running_stat = m_stat;
  567. cp.dept_id = m_deptid;
  568. cp.display=m_display;
  569. cp.rec_time=m_time;
  570. swsTimerThrd.upt_card_pos(cp);
  571. }
  572. int card_location_base::get_stat()
  573. {
  574. //盲区>呼救>呼叫>超时>超速>正常
  575. uint64_t now = time(0)*1000;
  576. if(now-m_time>CARD_LOST_TIME_OUT)
  577. {
  578. return STATUS_LOST;
  579. }
  580. else if(auto ev_ptr = event_list::instance()->get(m_id, ET_CARD_HELP))
  581. {
  582. return (ES_DEAL_HELP == ev_ptr->m_status) ? STATUS_HELP_DEALED : STATUS_HELP;
  583. }
  584. else if(CALL_NONE != get_mine_tool()->m_status_call)
  585. {
  586. return STATUS_CALL;
  587. }
  588. else if(event_list::instance()->get(
  589. m_id, is_person()? ET_CARD_AREA_OVER_TIME_PERSON: ET_CARD_AREA_OVER_TIME_VEHICLE))
  590. {
  591. return STATUS_AREA_OVER_TIME;
  592. }
  593. else if(event_list::instance()->get(m_id, ET_CARD_OVER_SPEED))
  594. {
  595. return STATUS_OVER_SPEED;
  596. }
  597. return STATUS_NORMAL;
  598. }
  599. void card_location_base::clear()
  600. {
  601. // uint16_t m_display; //1显示0不显示,往前端推送
  602. m_speed=0; //速度
  603. m_is_attendance=0; //井上井下状态 0初始状态 1 井上 2 井下
  604. m_stat=0; //运动静止状态
  605. //m_ct; //ct
  606. m_time=0; //时间戳
  607. }
  608. card_location_base::~card_location_base()
  609. {
  610. }
  611. template<> std::shared_ptr<card_list>
  612. single_base<card_list, uint64_t, std::shared_ptr<card_location_base>>::m_instance=std::make_shared<card_list>();