zhuyf 3 years ago
parent
commit
ebd80ee470
69 changed files with 948 additions and 397 deletions
  1. 5 3
      ant.cpp
  2. 23 17
      area.cpp
  3. 1 3
      area_business.cpp
  4. 6 7
      async.cpp
  5. 14 19
      card.cpp
  6. 2 0
      card.h
  7. 11 4
      cardMgr.cpp
  8. 45 12
      card_base.cpp
  9. 16 14
      card_base.h
  10. 22 4
      card_car.cpp
  11. 96 37
      card_person.cpp
  12. 2 2
      card_person.h
  13. 1 0
      common.h
  14. 61 5
      common_tool.h
  15. 1 1
      db/db_card.cpp
  16. 1 1
      db/db_tool.h
  17. 1 2
      event.cpp
  18. 12 0
      event.h
  19. 4 4
      his_location.cpp
  20. 10 10
      his_location.h
  21. 3 2
      loc_message.h
  22. 45 18
      main.cpp
  23. 5 4
      message.cpp
  24. 4 1
      mine.cpp
  25. 3 4
      mine.h
  26. 9 0
      mine_business.cpp
  27. 1 15
      module_service/area_business_car_attendance.cpp
  28. 12 2
      module_service/area_business_car_attendance.h
  29. 1 0
      module_service/area_business_card_enter_or_leave.cpp
  30. 12 0
      module_service/area_business_card_enter_or_leave.h
  31. 11 0
      module_service/area_business_count_checker.h
  32. 11 0
      module_service/area_business_forbid.h
  33. 11 0
      module_service/area_business_geofault.h
  34. 10 12
      module_service/area_business_motionless_persion.cpp
  35. 33 22
      module_service/area_business_person_attendance.cpp
  36. 10 1
      module_service/area_business_person_dwell_checker.cpp
  37. 0 2
      module_service/area_business_person_dwell_checker.h
  38. 72 23
      module_service/module_call.cpp
  39. 24 6
      module_service/module_call.h
  40. 21 2
      module_service/module_call_help.h
  41. 12 19
      module_service/module_meta_data_changed.cpp
  42. 42 10
      module_service/module_mgr.cpp
  43. 1 1
      module_service/module_mgr.h
  44. 21 9
      module_service/module_other_alarm.cpp
  45. 1 3
      module_service/module_other_alarm.h
  46. 1 1
      module_service/module_traffic_light.cpp
  47. 2 2
      module_service/module_traffic_light_manager.cpp
  48. 5 6
      module_service/module_traffic_light_manager.h
  49. 55 5
      module_service/module_web.cpp
  50. 1 1
      module_service/module_web.h
  51. 4 4
      net-service.cpp
  52. 12 1
      net-service.h
  53. 3 1
      sys_setting.h
  54. 1 1
      tqueue.h
  55. 0 3
      web-client.cpp
  56. 11 8
      websocket/jsonBuilder.cpp
  57. 1 3
      websocket/jsonBuilder.h
  58. 1 3
      websocket/jsonCommon.h
  59. 2 4
      websocket/web_connect.cpp
  60. 1 3
      websocket/web_connect.h
  61. 72 8
      websocket/wsClient.cpp
  62. 7 1
      websocket/wsClient.h
  63. 1 1
      websocket/wsClientMgr.cpp
  64. 2 2
      websocket/wsClientMgr.h
  65. 22 4
      websocket/wsTimerThread.cpp
  66. 2 4
      websocket/wsTimerThread.h
  67. 28 7
      websocket/ws_common.h
  68. 3 3
      worker.cpp
  69. 2 20
      znet.cpp

+ 5 - 3
ant.cpp

@@ -223,9 +223,9 @@ std::vector<point> ant::getsol(const double &dist) const
 
 bool visit_site_status::visit(std::shared_ptr<site> s)
 {
-	time_t now=time(0);
+	time_t now = time(0);
 	int diff = now-s->m_time;
-	event_tool::instance()->handle_event(OT_DEVICE_READER,ET_READER_ERROR,s->m_id,READER_TIMEOUT,diff,diff>READER_TIMEOUT);
+	event_tool::instance()->handle_event(OT_DEVICE_READER, ET_READER_ERROR, s->m_id, READER_TIMEOUT, diff, diff>READER_TIMEOUT);
 	return true;
 }
 
@@ -607,6 +607,7 @@ void site::on_power_status(bool ac_down)//电源状态
     event_tool::instance()->handle_event(OT_DEVICE_READER,ET_READER_POWER_BY_BATTERY,id(),tool_time::now_to_seconds(),ac_down,m_power_ac_down);
     log_info("[event warning: reader power supply by battery] reader_id: Power %d->%d.",id(),!m_power_ac_down,m_power_ac_down);
 }
+
 algo_config site::g_config[]=
 {
 	{ "tof-1",  1, 2, 0.1, 1 },
@@ -616,7 +617,7 @@ algo_config site::g_config[]=
 	{ "tof-3",  3, 4, 0.1, 1 },
 	{ "tdoa-3", 4, 4, 0.1, 1 }
 };
-
+/*
 #ifdef _TEST
 int main()
 {
@@ -630,3 +631,4 @@ int main()
     //std_info("---%s",(*sl)[209][0][0][0].to_string().c_str());
 }
 #endif
+*/

+ 23 - 17
area.cpp

@@ -23,8 +23,6 @@
 #include "ant.h"
 #include "event.h"
 
-//template<> std::shared_ptr<area_list> single_base<area_list, int, std::shared_ptr<area>>::m_instance=std::make_shared<area_list>();
-
 struct underground_area:area
 {
     underground_area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t biz_type)
@@ -57,7 +55,7 @@ struct special_area:area
 	virtual	void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c)
 	{
         area::on_enter(a, c);
-		YA::_CARD_POS_ cp;
+		sys::_CARD_POS_ cp;
 		cp.area_id = m_id;
 		swsClientMgr.SendSpecialAreaProcess(cp);
 	}
@@ -163,11 +161,15 @@ void area::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<ca
 	}
 }
 
+/*
+ *  处理所有区域业务逻辑
+ * */
 void area::on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c)
 {
-	log_info("on_enter..%d  areaId:%d",c->m_id,m_id);
-	a->m_enter_time=tool_time::now_to_ms();
-	a->m_enter_point=*c;
+	log_info("on_enter..%d  areaId:%d", c->m_id, m_id);
+	// 更新进入区域的时间
+    a->m_enter_time = tool_time::now_to_ms();
+	a->m_enter_point = *c;
  	for(const auto &i:m_area_business_list)
 	{
 		auto &x=a->get_business_data(i->area_business_type());
@@ -198,6 +200,7 @@ void area::on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<ca
 		i->on_leave(a,c,x);
 	}
 }
+
 bool area::in_area(const point &p)
 {
     if(m_bound.empty())
@@ -225,6 +228,7 @@ bool area::in_area(const point &p)
 	}
 	return (counter % 2 == 0) ? false : true;
 }
+
 bool area::in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>&c, const point & p,int & sarid)
 {
     switch(m_area_type){
@@ -555,7 +559,7 @@ std::vector<point> area_list::init_path(std::string &str_0,int area_id)
 	const std::string str=str_0;
 	if(str.empty())
 	{
-	  log_error("area path is empty,area_id=%d.",area_id);
+        log_error("area path is empty,area_id=%d.",area_id);
 	}
 	std::vector<point> vp;
 	std::vector<std::string> vs;
@@ -580,24 +584,26 @@ std::vector<std::shared_ptr<area>> area_list::get_area(const std::shared_ptr<sit
 {
 	std::vector<std::shared_ptr<area>> ret;
 
-	if(tool_other::is_person(c->type_())&&s&&s->is_up_site())
+    // 人卡且是井上分站,获得井上分站区域
+	if(tool_other::is_person(c->type_()) && s && s->is_up_site())
 	{
 		ret.push_back(s->get_area());//地面分站的区域
 	    return std::move(ret);
 	}
 
+    // 如果卡在区域内,获得区域
 	auto&map = area_list::instance()->m_map;
-
 	for(const auto &a:map)
 	{
-		if(a.second->in_area(s,c,pt,sarid))
+		if(a.second->in_area(s, c, pt, sarid))
 			ret.push_back(a.second);
 	}
 
+    // 分站存在,获得分站所在区域
     if(s){
         ret.push_back(s->get_area());
-        int area_id=s->m_area_id;
-        if(auto area_=area_list::instance()->get(area_id))
+        int area_id = s->m_area_id;
+        if(auto area_= area_list::instance()->get(area_id))
 	        ret.push_back(area_);
     }
 	//区域覆盖不完全地图,很多车辆人行驶在地图外,如何确认.
@@ -660,8 +666,8 @@ void area_list::init_area_persons_dynamic_thre_from_db(int area_id/* = -1*/)
 area_hover::area_hover(const std::shared_ptr<area>&area,const point&pt)
 	:m_area(area)
 {
-    m_enter_time=m_last_time=tool_time::now_to_ms();
-    m_enter_point=m_last_point=pt;
+    m_enter_time = m_last_time = tool_time::now_to_ms();
+    m_enter_point = m_last_point = pt;
 }
 
 void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const point&pt)
@@ -670,7 +676,7 @@ void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const poin
     if(pt.empty())	return;
 
 	int special_area=-1;
-	std::vector<std::shared_ptr<area>> areas=area_list::instance()->get_area(m_site,c, pt,special_area);
+	std::vector<std::shared_ptr<area>> areas=area_list::instance()->get_area(m_site, c, pt,special_area);
 	if(special_area != -1)
 	{
 		areas.clear();
@@ -684,8 +690,8 @@ void area_tool::on_point(const std::shared_ptr<card_location_base>& c,const poin
 				});
 	}
 
-	auto c1=m_hover_list.begin(),ce=m_hover_list.end();
-	auto a1=areas.begin() ,ae=areas.end();
+	auto c1 = m_hover_list.begin(), ce = m_hover_list.end();
+	auto a1 = areas.begin() , ae = areas.end();
 
 	std::vector<std::shared_ptr<area_hover>> nlist;
 	while (c1!=ce && a1!=ae)

+ 1 - 3
area_business.cpp

@@ -14,8 +14,6 @@
 #include "area_business_geofault.h"
 #include "area_business_work_rate.h"
 
-
-
 struct area_business_factory
 {
 	void regist(int type,area_business* ab)
@@ -77,7 +75,7 @@ struct area_business_factory
 		regist(6, new area_business_forbid);
 		regist(7, new area_business_card_enter_or_leave);
 		regist(8, new area_business_motionless_persion);
-		regist(9,new area_business_geofault);
+		regist(9, new area_business_geofault);
 		regist(10,new area_business_work_rate);
 	}
 

+ 6 - 7
async.cpp

@@ -1,6 +1,4 @@
-
 #include <log.h>
-
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -15,7 +13,6 @@
 #define EV_ASYNC_ENABLE 1
 #define EV_USE_FLOOR 1
 #include <ev++.h>
-
 #include <clock.h>
 #include <zio.h>
 #include <znet.h>
@@ -51,18 +48,20 @@ struct io_thread:ev::dynamic_loop
 			ev::dynamic_loop::break_loop(ev::ALL);
 			
 		++m_count;
-        std_info("on_async%d:%d",std::this_thread::get_id(),m_count);
+        //std_info("on_async%d:%d",std::this_thread::get_id(),m_count);
 	}
+    
     void on_timer()
     {
-        std_info("on_timer....");
+        //std_info("on_timer....");
         m_timer.start(2,0);
     }
-	void run()
+	
+    void run()
 	{
 		dynamic_loop::run(0);
 		//log_info("thread exit.");
-        std_info("thread exit.%d",std::this_thread::get_id());
+        //std_info("thread exit.%d",std::this_thread::get_id());
 	}
 
 	void destroy()

+ 14 - 19
card.cpp

@@ -20,6 +20,7 @@
 extern config_file config;
 int three_rates_flag    = 0;
 int traffic_light_flag  = 0;
+int anti_coll_flag      = 0;
 
 static void request(uint64_t id,uint32_t hash_id,uint16_t dis)
 {
@@ -60,17 +61,16 @@ void card_list::init_staffer(const std::string & lszId64)
             person* tmp_ptr= static_cast<person*>(card_ptr.get());
             person* db_person_ptr= static_cast<person*>(db_person.get());
 
-            card_ptr->set_base_data(db_person_ptr->m_cid,db_person_ptr->m_type,db_person_ptr->m_deptid,db_person_ptr->m_level_id);
+            card_ptr->set_base_data(db_person_ptr->m_cid, db_person_ptr->m_type, db_person_ptr->m_deptid, db_person_ptr->m_level_id);
             //group_id
             //occ_id
-            tmp_ptr->m_workLine = db_person_ptr->m_workLine;
-            tmp_ptr->m_stafferName = db_person_ptr->m_stafferName;
-            tmp_ptr->m_deptName = db_person_ptr->m_deptName;
-            tmp_ptr->m_worktype_id = db_person_ptr->m_worktype_id;
+            tmp_ptr->m_workLine     = db_person_ptr->m_workLine;
+            tmp_ptr->m_stafferName  = db_person_ptr->m_stafferName;
+            tmp_ptr->m_deptName     = db_person_ptr->m_deptName;
+            tmp_ptr->m_worktype_id  = db_person_ptr->m_worktype_id;
             if(db_person_ptr->m_display!=tmp_ptr->m_display){
-                request(id64,tmp_ptr->m_id,db_person_ptr->m_display);
-            }
-            
+                request(id64, tmp_ptr->m_id, db_person_ptr->m_display);
+            } 
 		}
 		else
 		{
@@ -113,7 +113,6 @@ void card_list::init_vehicle(const std::string & lszId64)
             if(db_car->m_display!=tmp_ptr->m_display){
                 request(id64,tmp_ptr->m_id,db_car->m_display);
             }
-
 		}
 		else
 		{
@@ -321,7 +320,7 @@ void card_list::load_his_card_postion_staff()
             auto mine_tool_ptr = card_ptr->get_mine_tool();
             mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
             mine_tool_ptr->m_is_attendance = true;
-            log_info("person加载考勤,考勤开始时间:%s,[%s]cur_time:%s 卡id=%s areainfo=%s",start_time.c_str(),tool_time::to_str(mine_tool_ptr->m_attendance_start_time).c_str(),cur_time.c_str(),card_id.c_str(),strAreaInfo.c_str());
+            log_info("[person_att] person加载考勤,考勤开始时间:%s,[%s]cur_time:%s 卡id=%s 考勤状态:%d, areainfo=%s",start_time.c_str(),tool_time::to_str(mine_tool_ptr->m_attendance_start_time).c_str(),cur_time.c_str(), card_id.c_str(), (mine_tool_ptr->m_is_attendance?1:0),strAreaInfo.c_str());
 
             //分站设置
             auto area_tool=card_ptr->get_area_tool();
@@ -366,14 +365,14 @@ void card_list::load_his_card_postion_staff()
 
 void card_list::on_message(zloop<task*> *loop, message_locinfo&loc,bool is_history)
 {
-	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_type,loc.m_card_id);
+	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_type, loc.m_card_id);
 	const auto &c=card_list::instance()->get(cardid);
 	if(!c)
 	{
-		log_warn("数据库中未定义该卡的信息,card_id=%d, card_type=%d, cardid:%lld",loc.m_card_id,loc.m_card_type,cardid);
+		log_warn("数据库中未定义该卡的信息,card_id=%d, card_type=%d, cardid:%lld", loc.m_card_id, loc.m_card_type, cardid);
 		return;
 	}
-	double dist_tof=loc.m_tof*15.65*2.996*1e-4;
+	double dist_tof = loc.m_tof*15.65*2.996*1e-4;
 	logn_info(3,"card_message:site=%d,ant=%d,type=%lu,card=%d,ct=%d,tof=%lld(%.2lfm),rav=%02X,acc=%02X,rssi=%d,bat=%02X,stamp=%llu",
 			loc.m_site_id,loc.m_ant_id,loc.m_card_type,loc.m_card_id,loc.m_card_ct,loc.m_tof,dist_tof,
 			(loc.m_card_type==1?loc.m_callinfo:loc.m_rav),
@@ -389,7 +388,7 @@ void card_list::on_message(zloop<task*> *loop, message_locinfo&loc,bool is_histo
 
 void card_list::on_message(zloop<task*>* loop, message_tdoa_locinfo& loc, bool is_history)
 {
-	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_msg.m_type,loc.m_card_msg.m_id);
+	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_msg.m_type, loc.m_card_msg.m_id);
 	const auto &c=card_list::instance()->get(cardid);
 	if(!c)
 	{
@@ -402,7 +401,7 @@ void card_list::on_message(zloop<task*>* loop, message_tdoa_locinfo& loc, bool i
 
 void card_list::on_message(zloop<task*>* loop, message_pdoa_locinfo& loc, bool is_history)
 {
-	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_type,loc.m_card_id);
+	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_type, loc.m_card_id);
 	const auto &c = card_list::instance()->get(cardid);
 	if(!c)
 	{
@@ -428,7 +427,3 @@ bool card_list_visit::visit(std::shared_ptr<card_location_base> c)
 	c->get_card(_flag);
 	return true;	
 }
-
-
-//template<> std::shared_ptr<card_list> single_base<card_list, uint64_t, std::shared_ptr<card_location_base>>::m_instance=std::make_shared<card_list>();
-

+ 2 - 0
card.h

@@ -4,8 +4,10 @@
 #include <ev++.h>
 #include "card_base.h"
 #include "write-copy.h"
+
 extern int three_rates_flag;
 extern int traffic_light_flag;
+extern int anti_coll_flag;
 
 struct card_list_visit:visitor<std::shared_ptr<card_location_base>>
 {

+ 11 - 4
cardMgr.cpp

@@ -1,7 +1,7 @@
 #include "cardMgr.h" 
 #include "bindmorecard.h"
 #include "common.h"
-#include"common_tool.h"
+#include "common_tool.h"
 
 cardMgr::cardMgr()
 :m_queue(2048)
@@ -11,6 +11,7 @@ cardMgr::cardMgr()
 	m_cf[0] = std::make_shared<CloserCardFactory>(this);
 	m_cf[1] = std::make_shared<RemoteCardFactory>(this);
 }
+
 void cardMgr::run()
 {
 	while(!m_bstop)	
@@ -20,6 +21,7 @@ void cardMgr::run()
 		onMessage(m);
 	}
 }
+
 void cardMgr::onMessage(const Msg &m)
 {
 	switch(m.cmd)
@@ -45,6 +47,7 @@ void cardMgr::clear(uint64_t cardid)
 		m_cgraph.remove_edge(cardid,cid);
 	}
 }
+
 void cardMgr::handleMessage(const Msg &m)
 {
     //更新卡位置信息
@@ -54,7 +57,7 @@ void cardMgr::handleMessage(const Msg &m)
     //查找该卡1个像素点内得卡号信息(有车卡)
 	std::vector<uint64_t> rc=m_glist.find_near(m.cardid,1);
     //打印找到得卡数据信息	
-	log_info("LemonHash+..%d,size:%d,(%d,%d)",m.cardid,rc.size(),m.x,m.y);
+	log_info("Hash+..%d,size:%d,(%d,%d)",m.cardid,rc.size(),m.x,m.y);
 	std::map<uint64_t,std::string> map1;
 	std::map<uint64_t,std::string> map2;
 	for(int i = m_cf.size()-1;i>=0;i--)
@@ -80,21 +83,25 @@ void cardMgr::handleMessage(const Msg &m)
 		}
 	}
 }
+
 void cardMgr::erase(const std::map<uint64_t,std::string> &m)
 {
 	for(auto &p:m)
-	  erase(p.first);
+        erase(p.first);
 }
+
 void cardMgr::erase(uint64_t id)
 {
 	for(const auto & t:m_cf)
-	  t->erase(id);
+        t->erase(id);
 }
+
 cardMgr::~cardMgr()
 {
 	m_bstop = true;
 	m_pThread->join();
 }
+
 cardMgr* cardMgr::instance()
 {
 	static cardMgr cd;

+ 45 - 12
card_base.cpp

@@ -19,14 +19,16 @@
 #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"
 
 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)
+	: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));
+    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);
@@ -96,6 +98,7 @@ void card_location_base::do_status(int st)
 
     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*/)
 {
@@ -117,7 +120,7 @@ void card_location_base::make_his_location(uint64_t t,const point & pt,bool bclo
 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;
+    //pt.y = pt.y;
     
 	auto site_ptr = get_area_tool()->m_site;
 	int sid = 0;
@@ -132,7 +135,7 @@ void card_location_base::on_location(const std::vector<point>&vp,const std::vect
         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);
@@ -215,19 +218,29 @@ void card_location_base::on_message(zloop<task*>* loop, message_pdoa_locinfo& lo
     auto area_tool=get_area_tool();
 	area_tool->set_site(site_ptr);
 
+    // 此条件用于解决井下有的基站不能送出电量值时,会将卡的电量值按0输出,这种情况,默认卡的电量为初始值或之前值
+    if(loc.m_batty_status > 0){
+        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());
+        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{
+        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);
+
         m_message_handle->on_message(loop, loc, is_history);
     }
 }
 
 //前端推送位置函数.
-void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
+void card_location_base::upt_card_pos(sys::_CARD_POS_&cp, point &pt)
 {
     point _p;
     if(pt.empty())
@@ -248,7 +261,11 @@ void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
 	cp.display  = m_display;
 	cp.rec_time = m_time;
 	cp.level_id = m_level_id;
-	cp.stat     = m_pwr_stat;
+    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);
@@ -256,7 +273,7 @@ void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
 
 void card_location_base::del_card_pos()
 {
-	YA::_CARD_POS_ cp;
+	sys::_CARD_POS_ cp;
 	cp.ID = m_id;
 	cp.Type=m_type;
 	swsTimerThrd.del_card_pos(cp);
@@ -393,11 +410,27 @@ 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);
+	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,
+/*
+ * @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> 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);
+	return std::make_shared<car>(type, cardid, needdisplay, t, deptid, categoryid, type_id, level_id, cid);
 }

+ 16 - 14
card_base.h

@@ -1,6 +1,5 @@
 #ifndef _CARD_BASE_HPP_
 #define _CARD_BASE_HPP_
-
 #include <vector>
 #include <memory>
 #include <atomic>
@@ -27,7 +26,7 @@ struct area_tool;
 struct message_tdoa_locinfo;
 struct message_pdoa_locinfo;
 
-namespace YA{
+namespace sys{
     struct _CARD_POS_;
 }
 
@@ -62,7 +61,8 @@ struct card:point
 	int		 m_stat;			//运动静止状态
 	int		 m_biz_stat;
 	int	     m_pwr_stat;		//电量状态
-	uint16_t m_display;			//1显示0不显示,往前端推送
+	int      m_battery_value = 10;   //电量值
+    uint16_t m_display;			//1显示0不显示,往前端推送
 	uint16_t m_ct;				//ct
     uint8_t  m_freq_id;         // 频率索引
     double   m_freq;            // 频率值
@@ -79,10 +79,12 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
     {
         m_display_old = m_display;
     }
+
     bool eq_display()
     {
         return m_display_old == m_display;
     }
+
     std::uint8_t m_event[CARD_EVENT_COUNT_MAX]{0};
     std::unique_ptr<select_tool> m_sel_tool;
     std::unique_ptr<smooth_tool> m_smo_tool;
@@ -90,19 +92,19 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 	std::unique_ptr<location_card> m_his_location_card;
 	std::atomic<int> m_upmine_flag{0};
 
-	time_t m_help_last_time=0;
+	time_t m_help_last_time=0;                  // 呼救持续时间
 	int    m_help_bit=0;
 
     //pdoa
-    int16_t m_last_ct = -1;
-    float m_last_dist = 0.0;
-    uint16_t m_last_site_id = 0;                // 卡上一次定位的分站id
-    uint64_t m_last_recv_time = 0;              // 卡上一次接收时间
-    int m_last_site_dir = -1;                   // 卡上一次定位的分站天线1朝向
-    bool m_last_over_site = false;              // 卡是否过分站
-    int m_cache_nums = 0;                       // 过分站后缓存的数据个数
-    int m_buff_size = 0;
-    float m_pdoa_diff = 100.0;                  // pdoa分站当前上传相位差
+    int16_t m_last_ct           = -1;
+    float m_last_dist           = 0.0;
+    uint16_t m_last_site_id     = 0;        // 卡上一次定位的分站id
+    uint64_t m_last_recv_time   = 0;        // 卡上一次接收时间
+    int m_last_site_dir         = -1;       // 卡上一次定位的分站天线1朝向
+    bool m_last_over_site       = false;    // 卡是否过分站
+    int m_cache_nums            = 0;        // 过分站后缓存的数据个数
+    int m_buff_size             = 0;
+    float m_pdoa_diff           = 100.0;    // pdoa分站当前上传相位差
     float m_last_pdoa_diff = 100.0;             // pdoa 分站上一帧数据的相位差
     boost::circular_buffer<float> m_cb_pdoa;    // the list of current pdoa's different of phase;
     boost::circular_buffer<float> m_cb_tof;     // the list of tof that is pdoa history value
@@ -140,7 +142,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 
     void on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm );
     void do_status(int st);
-	void upt_card_pos(YA::_CARD_POS_&cp, point &pt);
+	void upt_card_pos(sys::_CARD_POS_&cp, point &pt);
 	void del_card_pos();
 	int	 get_stat();
 	void put_three_rates(card_pos &);

+ 22 - 4
card_car.cpp

@@ -44,7 +44,8 @@ void car::do_business(const std::shared_ptr<site>&site,const point &pt,double ac
 	m_timeval = m_time;
 	handle_three_rates(pt);
     handle_traffic_light(pt, site->m_id);
-    if(m_enable_anti_collision){
+    //if(m_enable_anti_collision){
+    if(CYaSetting::m_sys_setting.m_enable_anti_coll){
         handle_anti_coll(pt, site->m_id);
     }
 	uint64_t id=tool_other::type_id_to_u64(m_type,m_id);
@@ -66,7 +67,7 @@ void car::handle_anti_coll(const point& pt, const int& sid)
     double min_d = 9999999.9;
     double cur_v = 0.0;
     for(auto k : CYaSetting::m_sys_setting.mp_anti_collision){
-        log_info("[anti_coll] key=%d, value=%.2f", k.first, k.second);
+        //log_info("[anti_coll] key=%d, value=%.2f", k.first, k.second);
         for(auto& c : tmp_cards)
         {
             if(c.second->m_type == CT_VEHICLE){
@@ -136,13 +137,21 @@ void car::handle_anti_coll(const point& pt, const int& sid)
         }
         cards.insert(std::make_pair(m_id, call_card(m_id, 2, call_level, CCT_CALL_APOINT, sid)));
     }else{
-        log_info("[anti_coll] no card trigger anti collision rules.");
+        //log_info("[anti_coll] no card trigger anti collision rules.");
         return;
     } 
 
     module_call::instance()->send_anti_collision(cards);
 }
 
+/*
+ * @brief       三率业务处理模块
+ * @param       const point& pt     定位数据
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
 void car::handle_three_rates(const point &pt)
 {
 	card_pos cp;
@@ -156,6 +165,15 @@ void car::handle_three_rates(const point &pt)
 	put_three_rates(cp);
 }
 
+/*
+ * @brief       红绿灯业务模块
+ * @param       const point& p      定位数据
+ * @param       const int& sid      分站id
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
 void car::handle_traffic_light(const point& p, const int& sid)
 {
     card_pos cp;
@@ -189,7 +207,7 @@ int car::get_area()
 
 void car::make_package()
 {
-	YA::_CARD_POS_ cp;
+	sys::_CARD_POS_ cp;
 	loc_point pt = getSmoothPoint();
 	cp.area_info = m_area_tool->m_area_info;	
 	cp.map_id    = m_area_tool->get_mapid();

+ 96 - 37
card_person.cpp

@@ -20,12 +20,14 @@
 #include "cardMgr.h"
 #include "card.h"
 #include "db_api/CDBSingletonDefine.h"
+#include "module_service/module_screen.h"
+
 extern config_file config;
 int person::m_limit_detained_time=-1;
 int person::m_auto_up_mine_time=-1;
 int person::m_person_cards_flag=-1;
 person::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 worketype_id)
-	:card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
+	:card_location_base(type, cardid, needdisplay, t, deptid, level_id, cid)
 	,m_workLine(wl)
 	,m_worktype_id(worketype_id)
 	,m_stafferName(sname)
@@ -33,10 +35,10 @@ person::person(const std::string &type,uint32_t cardid,uint16_t needdisplay,int1
 {
     if(person::m_auto_up_mine_time==-1){
         //显示超时的界限 h
-        person::m_limit_detained_time=config.get("service.detained_time",10);
+        person::m_limit_detained_time = config.get("service.detained_time",10);
         //打印输出超过该时长的数据信息
-        person::m_auto_up_mine_time=config.get("service.auto_up_mine_time",20);
-        person::m_person_cards_flag=config.get("service.person_cards_flag",0);
+        person::m_auto_up_mine_time = config.get("service.auto_up_mine_time",20);
+        person::m_person_cards_flag = config.get("service.person_cards_flag",0);
     }
 	m_message_handle.reset(new card_message_handle(this));
 	//m_his_location_card.reset(new location_staff(m_id,m_type,cid));
@@ -48,8 +50,12 @@ person::~person()
 
 void person::clear()
 {
-    log_info("make_his_location clear");
+    log_info("%d make_his_location clear", m_id);
     make_his_location(m_time,*this,true);
+
+    bool is_att = m_mine_tool->m_is_attendance;
+    std::chrono::system_clock::time_point att_start_time = m_mine_tool->m_attendance_start_time;
+    
     //初始化区域和井下部分基础信息
     m_mine_tool->clear();
     m_area_tool->clear();
@@ -66,22 +72,41 @@ void person::clear()
             m_event[i]=0;
         }
     }
+    
     //清除一人多卡功能内存中的人卡相关数据,
     if(m_person_cards_flag){
     	Msg m;
-    	m.cmd=CMD_CLEAR;m.cardid=m_type<<32|m_id;
+    	m.cmd = CMD_CLEAR;
+        m.cardid = m_type<<32|m_id;
     	cardMgr::instance()->tryPut(m);
     }
+
+    m_mine_tool->m_is_attendance = is_att;
+    m_mine_tool->m_attendance_start_time = att_start_time;
 }
+
 //设置区域和地标信息
 void person::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)
 {
 	m_area_tool->set_area_info(mapid,scale,areaid,*this,t,type);
 }
+
+/*
+ * @brief       井口虹膜考勤联动以及大屏事宜处理
+ * @parma       int sid     分站号
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
 void person::site_hover(int sid)
 {
+    // 更新新城金矿大屏所需井口人员的时间信息
+    mine_person p(m_id, m_battery_value);
+    module_screen::instance()->put(p);
 	IKSDK_DB(sid);
 }
+
 //虹膜识别入库功能 输入到his_att_interface表.目前主要最小系统输入这个表,与井口闸机联动
 void person::IKSDK_DB(int sid)
 {
@@ -114,43 +139,64 @@ std::shared_ptr<mine_tool> person::get_mine_tool()
 {
 	return m_mine_tool;
 }
+
+/*
+ * @brief   人卡业务处理
+ * @param   const std::shared_ptr<site>& site   分站信息
+ * @param   const point& pt                     定位点
+ * @param   double acc                          加速度状态
+ * @return  无
+ * @note
+ * @bug
+ * @warning
+ * */
 void person::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
-{
-    m_mine_tool->m_is_attendance = true;
+{ 
     //区域相关逻辑驱动
-	m_area_tool->on_point(shared_from_this(),pt);
+	m_area_tool->on_point(shared_from_this(), pt);
     //处理历史轨迹
-    log_info("make_his_location  person");
-    make_his_location(m_time,pt);
-	m_timeval=m_time;
+    log_info("[person_att] %d is attendance: %d", m_id, (m_mine_tool->m_is_attendance?1:0));
+    make_his_location(m_time, pt);
+	m_timeval = m_time;
     //三率数据处理
-	handle_three_rates(pt);
+	//handle_three_rates(pt);
     //一人多卡数据输入
     if(m_person_cards_flag){
 	    Msg m;
-	    m.type=m_type;
+	    m.type = m_type;
         m.x=(int)x;
         m.y=(int)y;
-        m.cmd=CMD_HANDLE;
+        m.cmd = CMD_HANDLE;
         m.cardid=m_type<<32|m_id;
 	    cardMgr::instance()->tryPut(m);
     }
 }
+
 //设置人员上猴车
 void person::reset(std::shared_ptr<monkey_person> mp)
 {
 	m_monkeyPerson = mp;
 }
 
+/*
+ * @brief   处理三率模块
+ * @param   const point& pt
+ * @return  无
+ * @note
+ * @bug
+ * @warning
+ * */
 void person::handle_three_rates(const point & pt)
 {
 	card_pos cp;
-	cp.work_line=m_workLine;
+	cp.work_line    = m_workLine;
+	cp.work_type_id = m_worktype_id;
+	m_biz_stat      = get_stat();
+	cp.biz_stat     = m_biz_stat;
+	cp.x = pt.x;
+    cp.y = pt.y;
+    cp.z = pt.z;
 	cp.work_type_id = m_worktype_id;
-	m_biz_stat=get_stat();
-	cp.biz_stat = m_biz_stat;
-	cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
-	cp.work_type_id=m_worktype_id;
 	put_three_rates(cp);
 }
 
@@ -161,45 +207,55 @@ void person::on_timer()
 	{
 		if(m_upmine_flag.load())
 		{
-			log_warn("up_mine:att=false,upmine_flag=%d",m_upmine_flag.load());
+			log_warn("up_mine:att=false,upmine_flag=%d", m_upmine_flag.load());
 			m_upmine_flag=0;
 		}
         
-        //log_info("[person] person is not attendance");
+        //log_info("[person_att] person %d is not attendance", m_id);
 		return;
 	}
 
-	YA::_CARD_POS_ cp;
-	uint64_t _time=0;
-	point pt = getSmoothPoint(_time);
-    
-	cp.area_info=m_area_tool->m_area_info;	
-	cp.map_id =m_area_tool->get_mapid();
+	sys::_CARD_POS_ cp;
+	uint64_t _time = 0;
+	//point pt = getSmoothPoint(_time);
+    point pt = point(x, y);
+
+	cp.area_info = m_area_tool->m_area_info;	
+	cp.map_id    = m_area_tool->get_mapid();
 
-	cp.biz_stat = m_biz_stat;
+	cp.biz_stat  = m_biz_stat;
 	cp.down_time = m_mine_tool->get_down_time();
 	cp.work_time = m_mine_tool->get_work_time();
 	cp.is_on_duty= m_mine_tool->is_on_duty();
     cp.m_freq = m_freq;
 	cp.speed = m_speed;
+    
+    if(auto site_ptr = m_area_tool->m_site){
+        cp.area_id = site_ptr->m_area_id;
+    }
+    cp.dept_id = m_deptid;
+    //cp.stat = m_battery_value;
+
     upt_card_pos(cp,pt);
 	log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d--%d,speed=%.2f",m_id,_time,pt.x,pt.y,cp.map_id,cp.area_info.size(),person::m_limit_detained_time,m_speed);
     //int sid=0; if(auto st=m_area_tool->m_site)sid=st->m_area_id; m_his_location_card->push(_time,pt,sid,cp.map_id);
 
-	uint64_t _now=tool_time::now_to_ms();
-	uint64_t t=_now>m_timeval?_now-m_timeval:m_timeval-_now;
-	if(t>10*1000)
+	uint64_t _now = tool_time::now_to_ms();
+	uint64_t t    = _now>m_timeval?_now-m_timeval:m_timeval-_now;
+	if(t > 10*1000)
 	{
 		m_area_tool->on_point(shared_from_this(),pt);
 		m_biz_stat=get_stat();
 	}
+    
     print_card_detained();
 
+    // 自动升井
 	if(m_upmine_flag.load())
 	{
-		log_info("card=%d user-id=%d up_mine:upmine_flag=%d",m_id,m_cid, m_upmine_flag.load());
+		log_info("card=%d user-id=%d up_mine:upmine_flag=%d",m_id, m_cid, m_upmine_flag.load());
 		m_area_tool->on_leave(shared_from_this());
-		m_upmine_flag=0;
+		m_upmine_flag = 0;
 	}
 }
 
@@ -222,7 +278,7 @@ void person::print_card_detained()
         uint32_t min=work_time/1000/60;
         uint32_t lmin=lost_time/1000/60;
         double dist=p.dist(*this);
-        std::string last_time=tool_time::to_str_ex(m_time);
+        std::string last_time = tool_time::to_str_ex(m_time);
         std::string alarm_time{"No Alarm."};
         auto event_power=event_list::instance()->get_event_card(m_id,m_type,ET_CARD_LOW_POWER_SERIOUS);
         if(event_power)
@@ -235,6 +291,7 @@ void person::print_card_detained()
             inc_upmine_flag(2);
     }
 }
+
 //获取web输入坐标点
 point person::getSmoothPoint(uint64_t& t)
 {
@@ -243,7 +300,7 @@ point person::getSmoothPoint(uint64_t& t)
 	m_speed = lp.m_speed;
 	m_stat  = lp.m_stat;
 	pt.x = lp.x;
-	pt.y = -lp.y;
+	pt.y = lp.y;
 	t=lp.m_time;
 	if(auto  p = m_monkeyPerson.lock() ){
 		if(p->is_on_bus()){
@@ -255,6 +312,7 @@ point person::getSmoothPoint(uint64_t& t)
 	}
 	return pt;
 }
+
 //人员显示输入
 void person::get_card(bool f)
 {
@@ -262,6 +320,7 @@ void person::get_card(bool f)
 		return ;
 	mine_business::inst()->fetch_add(m_display);
 }
+
 //新协议处理逻辑。
 //0-4包为一组处理
 //其中0-1为充电时间  2-3 为放电时间 4为电量标识
@@ -284,7 +343,7 @@ void person::handle_message(uint16_t ct,uint8_t &value)
     }
     //老卡
     if(m_card_generation==1){
-        value=value&0x03;
+        value = value&0x03;
         return;
     }
     //新卡继续往下走,获取数据

+ 2 - 2
card_person.h

@@ -1,6 +1,5 @@
 #ifndef _card_person_h_
 #define _card_person_h_
-
 #include "card_base.h"
 #include "card_area.h"
 
@@ -14,7 +13,7 @@ struct person:card_location_base, card_area
     uint16_t m_ctflag{0};
     uint8_t m_power{0};
     uint8_t m_index{0};
-    uint8_t m_card_generation{0};
+    uint8_t m_card_generation{1};
     time_t m_iris_recognition_timeval = 0;
     static int m_limit_detained_time;
     static int m_auto_up_mine_time;
@@ -39,6 +38,7 @@ struct person:card_location_base, card_area
     virtual void do_business(const std::shared_ptr<site>&site,const point &pt,double acc);
 	virtual void set_area_info(int mapid,double scale,int areaid,uint64_t t,int type);
     virtual void handle_message(uint16_t ct,uint8_t &value);
+    
     virtual std::shared_ptr<area_tool> get_area_tool()
     {
         return m_area_tool;

+ 1 - 0
common.h

@@ -104,6 +104,7 @@ enum OBJECT_TYPE
     OT_AREA = 2,
     ///分站
     OT_DEVICE_READER = 4,
+    //OT_COMM_READER,
     ///标识卡,包括人员、车辆、自组网等
     OT_CARD = 9,
     //一人多卡

+ 61 - 5
common_tool.h

@@ -1,7 +1,5 @@
 #ifndef COMMON_TOOL_H
 #define COMMON_TOOL_H
-
-
 #include <chrono>
 #include <string>
 #include <sys/time.h>
@@ -9,14 +7,12 @@
 #include <rapidjson/writer.h>
 #include <rapidjson/stringbuffer.h>
 #include <rapidjson/prettywriter.h>
-
 #include <boost/function.hpp>
 #include <boost/bind.hpp>
-
+#include <boost/algorithm/string.hpp>
 #include "websocket/sio/sio_client.h"
 #include "common.h"
 
-
 class tool_other
 {
     public:
@@ -32,6 +28,7 @@ class tool_other
             dRetval/=pow(10.0,iPlaces);
             return(dRetval);
         }
+        
         static std::string to13str(std::string& str)
         {
             if(str.size()<13)
@@ -39,6 +36,14 @@ class tool_other
             return str;
         }
 
+        static std::string to_cid(int ctype, int cid)
+        {
+            char buf[20] = {0};
+            sprintf(buf, "%.3d%.10d", ctype, cid);
+
+            return std::string(buf);
+        }
+
         static std::string to13str(uint64_t data)
         {
             char ss[20]={0};
@@ -56,24 +61,29 @@ class tool_other
         {
             return std::stoi(to13str(str).substr(0, 3));
         }
+        
         static int card_id_to_type(const std::string &cardid)
         {
             return std::stoi(cardid.substr(0,3));
         }
+        
         static int card_id_to_id(const std::string &cardid)
         {
             return atoi(cardid.substr(3).c_str());
         }
+        
         static std::string type_id_to_str(int32_t type,uint32_t id)  
         {
             char sql[15] = {0};
             snprintf(sql, 15,"%03d%010d", type, id);
             return std::string(sql);
         }
+        
         static uint64_t type_id_to_u64(uint64_t type,uint32_t id)
         {
             return type<<32|id;
         }
+        
         static bool is_person(int32_t type)
         {
             return CT_PERSON == type;
@@ -83,6 +93,7 @@ class tool_other
         {
             return CT_VEHICLE == type || CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
         }
+        
         static std::string get_string_cardid(uint64_t id)
         {
             uint64_t type = id>>32;
@@ -99,14 +110,59 @@ class tool_other
         {
             return CT_COAL_CUTTER == type || vtype==VT_COAL_CUTTER;
         }
+        
         static bool is_driving(int32_t type,int32_t vtype)
         {
             return CT_HEADING_MACHINE == type || vtype==VT_HEADING_MACHINE;
         }
+        
         static bool is_coal_or_driving(int32_t type,int32_t vtype)
         {
             return is_coal(type,vtype) || is_driving(type,vtype);
         }
+
+        static double get_pdoa(float poa[], const  double& offset)
+        {
+            if(poa == nullptr)
+            {
+                return -10.0;
+            }
+
+            float pdoa = poa[1] - poa[0] - offset;
+            while(pdoa >= TPI){
+                pdoa -= TPI;
+            }
+
+            while(pdoa < 0){
+                pdoa += TPI;
+            }
+
+            pdoa -= PI;
+
+            return pdoa;
+        }
+
+        template<class T>
+        static void memcpy_int(std::vector<char>& msg, T val)
+        {
+            for(int i = sizeof(T)-1; i >=0; --i){
+                msg.push_back((val>>(i*8))&0xFF);
+            }
+        }
+
+        /*
+         * @brief
+         * @param
+         * @return
+         * @note
+         * @warning
+         * @bug
+         * */
+        static std::string replace(std::string val, std::string d, std::string n)
+        {
+            boost::replace_all(val, d, n);
+            return val;
+        }
 };
 
 class tool_map

+ 1 - 1
db/db_card.cpp

@@ -222,7 +222,7 @@ namespace db_card
             }
 
             std::shared_ptr<card_location_base> clb =
-                    std::make_shared<person>(strategy,vsid,need_display,card_type_id,dept_id,occupation_level_id,staff_id,work_line,staffer_name,dept_name,worktype_id);
+                    std::make_shared<person>(strategy, vsid, need_display, card_type_id, dept_id, occupation_level_id, staff_id, work_line, staffer_name, dept_name, worktype_id);
             uint64_t cardid = tool_other::type_id_to_u64(card_type_id,vsid);
             clb->m_freq = freq;
 

+ 1 - 1
db/db_tool.h

@@ -2,7 +2,7 @@
 #define _tool_db_h_
 
 #include <memory>
-#include<chrono>
+#include <chrono>
 struct card_location_base;
 struct area_hover;
 namespace db_tool

+ 1 - 2
event.cpp

@@ -17,7 +17,6 @@ uint64_t ya_event::get_list_id()
     return m_id;
 }
 
-
 struct Event
 {
     OBJECT_TYPE m_oid;
@@ -113,7 +112,7 @@ void Event::handle_alarm_event(EVENT_TYPE et,uint64_t id,double limit_value,doub
         else
         {
             uint64_t _id=id;
-            log_info("Create_Event:desc[%s],id:%d,et:%d",desc.c_str(),id,et);
+            //log_info("Create_Event:desc[%s],id:%d,et:%d",desc.c_str(),id,et);
             if((et==ET_UWB_MORE_CARD||et == ET_VEHICLE_REAR_END)&&!desc.empty())//防追尾告警特殊处理
             {
                 std::string cardid = desc.substr(0,desc.find_first_of('&'));

+ 12 - 0
event.h

@@ -1,3 +1,15 @@
+/*
+ * @file
+ * @brief
+ * @version
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ * */
+
 #ifndef __EVENT_HPP__
 #define __EVENT_HPP__
 #include <memory>

+ 4 - 4
his_location.cpp

@@ -254,7 +254,7 @@ void location_card::insert(uint64_t timestamp, const point & p, int32_t areaid,
 
     char sql[512] = {0};
     snprintf(sql, 512, "replace into his_location_simplify(obj_id, card_type_id, ident, loc_time, map_id, area_id, begin_pt, reader_id, speed) values (%d, %d, %d, '%s', %d, %d, '%.2f,%.2f', %d, %.2f);", m_objid, m_type, m_cardid, tool_time::to_str(timestamp/1000).c_str(), mapid, areaid, p.x, p.y, siteid, speed);
-    log_info("his_location_simplify: %d-%lu: %s", m_cardid, timestamp, sql);
+    logn_info(2, "his_location_simplify: %d-%lu: %s", m_cardid, timestamp, sql);
     sDBConnPool.PushAsync(sql);
 }
 
@@ -265,7 +265,7 @@ void location_card::insert()
     const char * sql = "replace into his_location (obj_id,card_type_id,ident,begin_time,map_id,area_id,begin_pt,direction,reader_id)"
                        "values(%d,%d,%d,'%s',%d,%d,'%.2f,%.2f',%f,%d);";
     snprintf(nsql,512,sql,m_objid,m_type,m_cardid,tool_time::to_str(m_timestamp/1000).c_str(),m_mapid,m_areaid,m_p.x,m_p.y,m_arg,m_siteid);
-    log_info("his_location[%d,%lu]:%s",m_cardid,m_timestamp,nsql);
+    logn_info(2, "his_location[%d,%lu]:%s", m_cardid, m_timestamp, nsql);
     sDBConnPool.PushAsync(nsql);
 }
 
@@ -279,7 +279,7 @@ void location_card::update(const point &p,uint64_t timestamp,int flag/*=0*/,int
     double avge_speed = dist/t;
     if(std::isnan(avge_speed)|| std::isinf(avge_speed))avge_speed=0;
 
-    log_info("his_location_time[%d]:%d[%lu,%lu,%lu]",m_cardid,flag,last_timestamp,timestamp,m_timestamp);
+    logn_info(2, "his_location_time[%d]:%d[%lu,%lu,%lu]", m_cardid, flag, last_timestamp, timestamp, m_timestamp);
     if(last_timestamp != 0)
     {
         const char * ss = "update his_location set last_time='%s',speed=%.3f,direction=%f,location_flag=%d where obj_id=%d and begin_time='%s' and last_time = '%s';";
@@ -290,7 +290,7 @@ void location_card::update(const point &p,uint64_t timestamp,int flag/*=0*/,int
     if(flag==1) last_timestamp=timestamp;
     else last_timestamp=0;
 
-    log_info("his_location[%d]:%s[%lu,%lu]",m_cardid,nsql,timestamp,m_timestamp);
+    logn_info(2, "his_location[%d]:%s[%lu,%lu]", m_cardid, nsql, timestamp, m_timestamp);
     sDBConnPool.PushAsync(nsql);
 }
 

+ 10 - 10
his_location.h

@@ -10,21 +10,21 @@
 struct location_card
 {
 	location_card(uint32_t id,uint64_t type,uint32_t objid);
-	uint32_t    m_cardid;//卡id
-	uint16_t	m_type;//卡类型
+	uint32_t    m_cardid;       //卡id
+	uint16_t	m_type;         //卡类型
 	uint32_t    m_objid;
-	double		m_arg;//运动方向角度值
-	int 		m_areaid;//区域
-	int 		m_mapid;//地图
-    int         m_siteid;   //分站
-	uint64_t	m_timestamp;//入库后的时间
-	point		m_p;//入库后的点
+	double		m_arg;          //运动方向角度值
+	int 		m_areaid;       //区域
+	int 		m_mapid;        //地图
+    int         m_siteid;       //分站
+	uint64_t	m_timestamp;    //入库后的时间
+	point		m_p;            //入库后的点
     int         m_direct_index;
     uint64_t    last_timestamp;
     bool 		m_isInsert ;	//是否
     static uint32_t  m_difftime;//进入盲区得时长限制 时长 
-    static int  m_distance;//进入盲区后,第一个点与之前得距离  像素距离
-    void set_cid(uint32_t cid){m_objid=cid;}
+    static int  m_distance;     //进入盲区后,第一个点与之前得距离  像素距离
+    void set_cid(uint32_t cid){ m_objid=cid; }
 	struct mini_data
 	{
 		mini_data(const point &p,uint64_t t)

+ 3 - 2
loc_message.h

@@ -176,11 +176,12 @@ struct pdoa_message: public point{
     double x_ant;
     double y_ant;
     double pdoa;
+    double relative_angle;
 
-    pdoa_message(const double& _x, const double& _y, const double& _angle, const double& _distance, const double& _ax, const double& _ay, const double& _pdoa):point(_x, _y), angle(_angle), distance(_distance), x_ant(_ax), y_ant(_ay), pdoa(_pdoa)
+    pdoa_message(const double& _x, const double& _y, const double& _angle, const double& _distance, const double& _ax, const double& _ay, const double& _pdoa, const double& _relative_angle):point(_x, _y), angle(_angle), distance(_distance), x_ant(_ax), y_ant(_ay), pdoa(_pdoa), relative_angle(_relative_angle)
     {}
 
-    pdoa_message():point(0.0, 0.0),angle(0.0), distance(0.0), x_ant(0.0), y_ant(0.0), pdoa(0.0)
+    pdoa_message():point(0.0, 0.0),angle(0.0), distance(0.0), x_ant(0.0), y_ant(0.0), pdoa(0.0), relative_angle(0.0)
     {}
 };
 

+ 45 - 18
main.cpp

@@ -40,10 +40,13 @@ void Handle_ThreeRates_Event_Callback(const int evType, const int evId, uint64_t
 
 struct Init_Setting
 {
+    // 初始化系统参数
     void init()
     {
-        three_rates_flag=config.get("service.three_rates_flag", 0);
-        traffic_light_flag = config.get("service.traffic_light_flag", 0);
+        three_rates_flag    = config.get("service.three_rates_flag", 0);
+        traffic_light_flag  = config.get("service.traffic_light_flag", 0);
+        anti_coll_flag      = config.get("service.anti_collision_flag", 0);
+
         YADB::_DB_POOL_SETTING_ DBSetting;
         DBSetting.Host = config.get("db.host","127.0.0.1");
         DBSetting.User = config.get("db.user","root");
@@ -75,6 +78,7 @@ struct Init_Setting
             log_warn("连接webServer[%s] 失败!",url.c_str());
         }
 		CYaSetting::Init_sys_setting();
+        CYaSetting::m_sys_setting.m_enable_anti_coll = anti_coll_flag;
         //公告牌功能
         //bulletin_broad_show::inst()->OnInit(&config);
 
@@ -88,16 +92,16 @@ struct Init_Setting
         //special_area_list::instance()->init_from_db();
 		mine_business::inst()->load();
         card_list::instance()->load_his_card_postion_from_db();
-        //event_list::instance()->load_his_data_from_db();
+        event_list::instance()->load_his_data_from_db();
         if(three_rates_flag){
             db_para dp;	
-            dp.Host=DBSetting.Host;
-            dp.User=DBSetting.User;
-            dp.PWD=DBSetting.PWD ;
-            dp.DBName=DBSetting.DBName;
-            dp.CharSet=DBSetting.CharSet ;
-            dp.TimeOut=DBSetting.TimeOut;
-            dp.PoolSize=DBSetting.PoolSize;
+            dp.Host     = DBSetting.Host;
+            dp.User     = DBSetting.User;
+            dp.PWD      = DBSetting.PWD ;
+            dp.DBName   = DBSetting.DBName;
+            dp.CharSet  = DBSetting.CharSet ;
+            dp.TimeOut  = DBSetting.TimeOut;
+            dp.PoolSize = DBSetting.PoolSize;
 		    init_three_rates(dp);
         }
 
@@ -105,7 +109,8 @@ struct Init_Setting
             init_traffic_light();
         }
 
-        init_ant_sync();
+        // tdoa基站天线间时间同步数据
+        //init_ant_sync();
 
         log_info("Init_Setting::init  Success. \n" );
     }
@@ -145,7 +150,7 @@ struct Init_Setting
 
     bool wsClientMgr_init(const std::vector<std::string>&uri_list,int32_t st)
     {
-        std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE> MsgFuncList;
+        std::map<std::string, sys::MSG_HANDLE_FUNC_TYPE> MsgFuncList;
         module_mgr::init(config, MsgFuncList);
 
         web_connect::init(uri_list, st, MsgFuncList);
@@ -172,7 +177,14 @@ struct Init_Setting
     }
 };
 
-
+/*
+ * @brief       停止业务模块和websocket server的连接
+ * @param       无
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
 void cleanup()
 {
     module_mgr::stop();
@@ -200,6 +212,15 @@ void usage(char ** argv)
     }
 }
 
+/*
+ * @brief   主程序入口
+ * @param   [in] int argc
+ * @param   [in] char* argv[]
+ * @return  0表示正常运行,非零值表示错误
+ * @note
+ * @warning
+ * @bug
+ * */
 int main(int argc ,char * argv[])
 {
     if(argc >1)
@@ -208,34 +229,40 @@ int main(int argc ,char * argv[])
         return 0;
     }
 
+    // 加载共享内存
     log_init("../etc/log.ini");
     if(config.open("../etc/config.ini"))
         return -1;
 
+    // 系统初始化
     Init_Setting is;
     is.init();
 
+    // 业务模块服务启动
     module_mgr::start();
     //web_connect::start_beatheart_monitor();
     //atexit(&cleanup);
 
-    net_service mh;
-    int port = config.get("service.port",4000);
-
+    // 提供数据给第三方服务
     int interface_port = config.get("service.interface_port",7001);
     log_info("service-position.run(%d)",interface_port);
     std_info("service-position.run(%d)",interface_port);
     ios_service::start_service_position(interface_port);
 
+    // 启动网络模块服务
+    net_service mh;
+    int port = config.get("service.port",4000);
+
     log_info("service_handle::instance(&mh)->run(%d)",port);
     std_info("service_handle::instance(&mh)->run(%d)",port);
 
     service_handle::instance(&mh)->run(port);
-    
+ 
+    // 关闭数据库连接池
     sDBConnPool.Close();
 
     sleep(1);
-    printf("YA-SERV Server Exit ...\n");
+    printf("Collector Server Exit ...\n");
 
     return 0;
 }

+ 5 - 4
message.cpp

@@ -352,14 +352,15 @@ void message_pdoa_locinfo::load(zistream& is)
     is>>id>>m_card_ct;
     m_card_id = id;
 
-    if(m_card_ct % 5 == 4){
+    /*if(m_card_ct % 5 == 4){
         m_batty_status = (m_batty_status>>4)&0xFF;
-    }
+    }*/
     
     //角速度值:人卡车卡表示含义不同
     is>>b;
     if(m_card_type == 1){
-        m_callinfo = b;
+        // 1表示呼救;2表示呼叫
+        m_callinfo = ((b&0x80) >> 7);
     }else{
         m_rav = ((b&0x80)?-1.:1.)*(b&0x7F)*3;
     }
@@ -390,5 +391,5 @@ void message_pdoa_locinfo::load(zistream& is)
         m_poa[i] = (float)((((short)_poa)*1.0)/1000.0);
     }
 
-    logn_info(3,"[pdoa] card_type=%d, card_id=%d, ct=%d, status=%d, rav=%d, acc=%d, tof=%llu, ant_id=%d, rssi=%d, poa1=%.2f, poa2=%.2f, poa3=%.2f", m_card_type, m_card_id, m_card_ct, m_batty_status, m_rav, m_acc, m_tof, m_ant_id, m_rssi, m_poa[0], m_poa[1], m_poa[2]);
+    logn_info(3,"[pdoa] card_type=%d, card_id=%d, ct=%d, status=%d, call_type=%d, rav=%d, acc=%d, tof=%llu, ant_id=%d, rssi=%d, poa1=%.2f, poa2=%.2f, poa3=%.2f", m_card_type, m_card_id, m_card_ct, m_batty_status, m_callinfo, m_rav, m_acc, m_tof, m_ant_id, m_rssi, m_poa[0], m_poa[1], m_poa[2]);
 }

+ 4 - 1
mine.cpp

@@ -1,15 +1,18 @@
 #include "mine.h"
 #include "common_tool.h"
-#include"tool_time.h"
+#include "tool_time.h"
 #include "log.h"
+
 uint64_t mine_tool::get_down_time()
 {
 	return tool_time::to_ms(m_attendance_start_time);
 }
+
 uint64_t mine_tool::get_work_time()
 {
 	return tool_time::elapse_ms(m_attendance_start_time);
 }
+
 int32_t mine_tool::is_on_duty()
 {
     uint64_t dt=get_down_time();

+ 3 - 4
mine.h

@@ -22,10 +22,9 @@ struct mine_tool
 		m_normal_speed_count=0;
 		m_status_call=0;
         m_is_attendance=false;
-		m_attendance_start_time=std::chrono::system_clock::time_point(std::chrono::seconds(0));
-		m_is_overtime=false;
-		m_overtime=std::chrono::system_clock::time_point(std::chrono::seconds(0));
-        
+		m_attendance_start_time = std::chrono::system_clock::time_point(std::chrono::seconds(0));
+		m_is_overtime = false;
+		m_overtime=std::chrono::system_clock::time_point(std::chrono::seconds(0));        
     }
     int    m_over_speed_count;
     int    m_normal_speed_count;

+ 9 - 0
mine_business.cpp

@@ -272,6 +272,15 @@ void mine_business::record_staffer_num()
 {
     m_staffer_num_ptr->record_staffer_num();
 }
+
+/*
+ * @brief   加载传感器数据 
+ * @param
+ * @return
+ * @note
+ * @warning
+ * @bug
+ * */
 void mine_business::load()
 {
     m_reverse_alarm_ptr->load_sensor(); 

+ 1 - 15
module_service/area_business_car_attendance.cpp

@@ -51,23 +51,13 @@ void area_business_car_attendance::on_enter(const std::shared_ptr<area_hover>&ar
     mine_tool_ptr->m_is_attendance=false;
     //作为一条结束考勤记录保存到数据库
     db_tool::save_attendance(card_ptr, area_hover_ptr);
-
-    //save_attendance(card_ptr, area_hover_ptr);
-
-    //    auto ptr_temp = std::make_shared<car_attendance_data>();
-    //    ptr = ptr_temp;
-
-    //    ptr_temp->m_is_attendance = true;
-    //    ptr_temp->m_attendance_start_time = std::chrono::system_clock::now();
-
-    //    //作为一条开始考勤记录保存到数据库
-    //    db_tool::save_attendance(card_ptr, ptr_temp->m_is_attendance, ptr_temp->m_attendance_start_time);
 }
 
 void area_business_car_attendance::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 {
 
 }
+
 //记录离开考勤区域信息,开始考勤
 void area_business_car_attendance::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
                                             const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
@@ -90,10 +80,6 @@ void area_business_car_attendance::on_leave(const std::shared_ptr<area_hover>&ar
 
         //作为一条开始考勤记录保存到数据库
         db_tool::save_attendance(card_ptr, area_hover_ptr);
-
-        //                log_info("车卡考勤开始:卡id=%d,卡type=%d,区域id=%d, stat_attendance=%d",
-        //                         card_ptr->m_id, card_ptr->m_type,
-        //                         area_ptr->m_id,mine_tool_ptr->m_stat_attendance);
     }
 }
 

+ 12 - 2
module_service/area_business_car_attendance.h

@@ -1,11 +1,21 @@
+/*
+ * @file
+ * @brief
+ * @version
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ * */
+
 #ifndef AREA_BUSINESS_CAR_ATTENDANCE_H
 #define AREA_BUSINESS_CAR_ATTENDANCE_H
 
-
 #include"area_business.h"
 #include"unordered_map"
 
-
 class area_business_car_attendance:public area_business
 {
 public:

+ 1 - 0
module_service/area_business_card_enter_or_leave.cpp

@@ -68,6 +68,7 @@ void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hove
         db_tool::PushAsync(sql);
     }
 }
+
 //出区域则入库
 void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
                                                  const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)

+ 12 - 0
module_service/area_business_card_enter_or_leave.h

@@ -1,3 +1,15 @@
+/*
+ * @file
+ * @brief
+ * @version
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ * */
+
 #ifndef _area_business_card_enter_or_leave_hpp_
 #define _area_business_card_enter_or_leave_hpp_
 

+ 11 - 0
module_service/area_business_count_checker.h

@@ -1,3 +1,14 @@
+/*
+ * @file
+ * @brief
+ * @version
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ * */
 #ifndef _area_business_count_checker_hpp_
 #define _area_business_count_checker_hpp_
 

+ 11 - 0
module_service/area_business_forbid.h

@@ -1,3 +1,14 @@
+/*
+ * @file
+ * @brief
+ * @version
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ * */
 #ifndef AREA_BUSINESS_FORBID_H
 #define AREA_BUSINESS_FORBID_H
 

+ 11 - 0
module_service/area_business_geofault.h

@@ -1,3 +1,14 @@
+/*
+ * @file
+ * @brief
+ * @version
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ * */
 #ifndef AREA_BUSINESS_GEOFAULT
 #define AREA_BUSINESS_GEOFAULT
 

+ 10 - 12
module_service/area_business_motionless_persion.cpp

@@ -1,15 +1,13 @@
-#include"area_business_motionless_persion.h"
-
-#include<chrono>
-
-#include"common_tool.h"
-#include"log.h"
-#include"area.h"
-#include"event.h"
-#include"tool_time.h"
-#include"area_business.h"
-#include"card.h"
-#include"config_file.h"
+#include "area_business_motionless_persion.h"
+#include <chrono>
+#include "common_tool.h"
+#include "log.h"
+#include "area.h"
+#include "event.h"
+#include "tool_time.h"
+#include "area_business.h"
+#include "card.h"
+#include "config_file.h"
 
 struct motionless_data:business_data
 {

+ 33 - 22
module_service/area_business_person_attendance.cpp

@@ -1,37 +1,40 @@
 #include "area_business_person_attendance.h"
-
 #include "db/db_tool.h"
-#include"db/db_api/CDBSingletonDefine.h"
-#include"log.h"
-#include"card.h"
+#include "db/db_api/CDBSingletonDefine.h"
+#include "log.h"
+#include "card.h"
 #include "card_person.h"
-#include"area.h"
-#include"common_tool.h"
-#include"mine.h"
-#include"websocket/constdef.h"
+#include "area.h"
+#include "common_tool.h"
+#include "mine.h"
+#include "websocket/constdef.h"
 #include "websocket/wsClientMgr.h"
 #include "websocket/wsTimerThread.h"
-#include"tool_time.h"
+#include "tool_time.h"
 #include "module_meta_data_changed.h"
 #include "his_location.h"
+
 //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
 void area_business_person_attendance::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
                                                const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
 {
-    log_info("on_enter:person_att:%d",card_ptr->m_id);
+    log_info("on_enter:person_att: %d, area_id: %d",card_ptr->m_id, area_hover_ptr->id());
     if(!card_ptr->is_person())
         return;
 
     auto mine_tool_ptr = card_ptr->get_mine_tool();
     if(!mine_tool_ptr->m_is_attendance)
     {
-        mine_tool_ptr->m_is_attendance=true;
-        mine_tool_ptr->m_attendance_start_time=
-                std::chrono::system_clock::time_point(std::chrono::milliseconds(area_hover_ptr->m_enter_time));
-
+        mine_tool_ptr->m_is_attendance = true;
+        mine_tool_ptr->m_attendance_start_time = std::chrono::system_clock::time_point(std::chrono::milliseconds(area_hover_ptr->m_enter_time));
+
+        /*if(area_hover_ptr){
+            log_info("[person_att] enter_time: %d, %s", area_hover_ptr->m_enter_time, mine_tool_ptr->m_attendance_start_time);
+        }else{
+            log_info("[person_att] area_hover_ptr is nullptr.");
+        }*/
         //作为一条开始考勤记录保存到数据库
         db_tool::save_attendance(card_ptr, area_hover_ptr);
-
     }
 }
 
@@ -39,16 +42,25 @@ void area_business_person_attendance::on_hover(const std::shared_ptr<area_hover>
 {
 
 }
+
 //记录离开考勤区域信息,开始考勤
-void area_business_person_attendance::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
+void area_business_person_attendance::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr, const std::shared_ptr<card_location_base>&card_ptr, std::shared_ptr<business_data> ptr)
 {
-    if(!card_ptr->is_person())return;
+    if(!card_ptr->is_person())
+    {
+        return;
+    }
+
     auto mine_tool_ptr = card_ptr->get_mine_tool();
-    if(!mine_tool_ptr->m_is_attendance)return;
+    if(!mine_tool_ptr->m_is_attendance)
+    {
+        log_info("[person_att] %d is not attendance", card_ptr->m_id);
+        return;
+    }
 
-    log_info("on_leave_person_att:%d",card_ptr->m_id);
+    log_info("on_leave_person_att:%d", card_ptr->m_id);
     //考勤结束
-    mine_tool_ptr->m_is_attendance=false;
+    mine_tool_ptr->m_is_attendance = false;
 	if(card_ptr->upmine_flag()){
         auto start = mine_tool_ptr->m_attendance_start_time;
         std::string start_time = tool_time::to_str(start);
@@ -61,7 +73,7 @@ void area_business_person_attendance::on_leave(const std::shared_ptr<area_hover>
     //作为一条结束考勤记录保存到数据库
     db_tool::save_attendance(card_ptr, area_hover_ptr);
 
-	YA::_CARD_POS_ cp;
+	sys::_CARD_POS_ cp;
 	cp.Type=card_ptr->m_type;
 	cp.ID = card_ptr->m_id;
 	swsTimerThrd.del_card_pos(cp);
@@ -169,7 +181,6 @@ void area_business_person_attendance::_to_json_card_up_one(std::shared_ptr<card_
     //速度
     data.PushBack(card_ptr->m_speed, allocator);
 
-
     out_datas.PushBack(data, allocator);
 }
 

+ 10 - 1
module_service/area_business_person_dwell_checker.cpp

@@ -1,4 +1,3 @@
-
 #include "area.h"
 #include "card_base.h"
 #include "event.h"
@@ -7,6 +6,16 @@
 #include "log.h"
 #include "area_business_person_dwell_checker.h"
 
+/*
+ * @brief       加载人员历史区域停留时长数据
+ * @param       const std::shared_ptr<area_hover>& a
+ * @param       const std::shared_ptr<card_location_base>& c    卡对象
+ * @param       std::shared_ptr<business_data>& ptr             业务数据
+ * @return
+ * @note
+ * @warning
+ * @bug
+ * */
 void area_business_person_dwell_checker::on_load_his(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
 {
     if(!c->is_person())

+ 0 - 2
module_service/area_business_person_dwell_checker.h

@@ -18,9 +18,7 @@ struct area_business_person_dwell_checker:area_business
 	void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
 	//如果有超时告警,取消超时告警
 	void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
-
 };
 
-
 #endif
 

+ 72 - 23
module_service/module_call.cpp

@@ -15,18 +15,41 @@
 #include "crc.h"
 #include "mine.h"
 #include "event.h"
-#include "tool_byte.h"
 
+/*
+ * @brief   根据卡类型与卡号构造key
+ * @param   无
+ * @return  返回生成值
+ * @note
+ * @warning
+ * @bug
+ * */
 uint64_t call_card::to_id64()
 {
     return tool_other::type_id_to_u64(cardtype, cardid);
 }
 
+/*
+ * @brief   根据卡类型与卡号构造卡字符串,形如:0010000001200
+ * @param   无
+ * @return  返回卡号
+ * @note
+ * @warning
+ * @bug
+ * */
 std::string call_card::to_id64_str()
 {
     return tool_other::type_id_to_str(cardtype, cardid);
 }
 
+/*
+ * @brief   根据卡类型与卡号构造key
+ * @param   无
+ * @return  返回生成值
+ * @note
+ * @warning
+ * @bug
+ * */
 bool call_card::is_timeout()
 {
     uint32_t seconds = tool_time::elapse_seconds(call_time);
@@ -179,32 +202,34 @@ web发给采集:发起呼叫
 {
     cmd: 'call_card_req',
     data: {
-      call_type_id: this.cal_type, // 全员呼叫:0 定员呼叫:1
-      call_time_out: this.choosedTime, // 呼叫时长
+      call_type_id: this.cal_type,      // 全员呼叫:0 定员呼叫:1
+      call_time_out: this.choosedTime,  // 呼叫时长
       call_level_id: this.call_type_id, // 呼叫类型 一般呼叫:1 紧急呼叫:2
-      user_name: xdata.userName, // 呼叫人
-      call_time: time, // 呼叫时间戳
-      stations: [{ stationid: 0 }], // 分站 0为全员
-      cards: cards // 人员 0为全员   //旧代码为map格式 [{ stationid: 0 }]
+      user_name: xdata.userName,        // 呼叫人
+      call_time: time,                  // 呼叫时间戳
+      stations: [{ stationid: 0 }],     // 分站 0为全员
+      cards: cards // 人员 0为全员      //旧代码为map格式 [{ stationid: 0 }]
     }
 }
 */
 void module_call::accept_call(sio::message::ptr const& data)
 {
-    int call_type = -1, call_level = 1, call_time_interval=-1;
+    int call_type = -1, call_level = 1, call_time_interval = -1;
     uint32_t call_time_out = 0;
-    std::string user_name;
+    std::string user_name = "";
+
+    call_time_interval = 5;
 
     if(!tool_map::try_get_value(call_type, JSON_KEY_CALL_CARD_CALL_TYPE, data)
             || !tool_map::try_get_value(call_level, JSON_KEY_CALL_CARD_CALL_LEVEL, data)
             || !tool_map::try_get_value(call_time_out, JSON_KEY_CALL_CARD_CALL_TIME_OUT, data)
+            //|| !tool_map::try_get_value(call_time_interval, JSON_KEY_CALL_CARD_CALL_TIME, data)
             || !tool_map::try_get_value(user_name, JSON_KEY_CALL_CARD_USER_NAME, data)
-            || !tool_map::try_get_value(call_time_interval, JSON_KEY_CALL_CARD_CALL_TIME, data)
             )
     {
-        log_error("发起呼叫: 收到的json不对,解析不出call_type = -1, call_level = -1, \
-                  call_time_out=-1, call_time_interval=-1,user_name");
-                return;
+        log_error("发起呼叫: 收到的json不对,解析不出call_type = %d, call_level = %d, \
+                  call_time_out=%d, call_time_interval=%d,user_name=%s", call_type, call_level, call_time_out, call_time_interval, user_name.c_str());
+        return;
     }
 
     if(user_name.empty())
@@ -218,14 +243,14 @@ void module_call::accept_call(sio::message::ptr const& data)
     call_user_ptr user_ptr;
     if(CCT_CALL_ALL==call_type)// 全员
     {
-        user_ptr=call_user_ptr(new call_user());
+        user_ptr = call_user_ptr(new call_user());
 
-        user_ptr->call_time=std::chrono::system_clock::now();
-        user_ptr->call_time_out=call_time_out;
+        user_ptr->call_time          = std::chrono::system_clock::now();
+        user_ptr->call_time_out      = call_time_out;
         user_ptr->call_time_interval = call_time_interval;
-        user_ptr->call_type_id=call_type;
-        user_ptr->call_level_id=call_level;
-        user_ptr->user_name=user_name;
+        user_ptr->call_type_id       = call_type;
+        user_ptr->call_level_id      = call_level;
+        user_ptr->user_name          = user_name;
 
         call_card_ptr temp(new call_card());
         copy(user_ptr, temp);
@@ -337,14 +362,14 @@ void module_call::accept_cancel(sio::message::ptr const& node_data)
 {
     int call_type = -1;//, call_level = -1;
     std::string user_name;
-    int64_t call_time;
+    int64_t call_time = 0;
 
     if(!tool_map::try_get_value(call_type, JSON_KEY_CALL_CARD_CALL_TYPE, node_data)
             || !tool_map::try_get_value(call_time, JSON_KEY_CALL_CARD_CALL_TIME, node_data)
             || !tool_map::try_get_value(user_name, JSON_KEY_CALL_CARD_USER_NAME, node_data)
             )
     {
-        log_error("取消呼叫: 收到的json不对,解析不出int call_type = -1, call_level = -1,user_name");
+        log_error("取消呼叫: 收到的json不对,解析不出int call_type = %d, call_time = %d,user_name=%s", call_type, call_time, user_name.c_str());
         return;
     }
 
@@ -763,13 +788,37 @@ void module_call::system_cancel_call_apoint(int card_id,int card_type)
     response_accept_cancel(result_user_ptr);
 }
 
+/*
+ * @brief       发送防碰撞告警
+ * @param       const std::map<int, call_card>& cards       key为车id,val为人卡信息
+ * @return
+ * @note
+ * @warning
+ * @bug
+ *
+ * */
 void module_call::send_anti_collision(const std::map<int, call_card>& cards)
 {
     std::vector<call_card_ptr> vt_cards;
+    std::string vmsg = "";
+    std::string pmsg = "";
+
     for(auto c : cards){
+        char buf[100] = {0};
+        snprintf(buf, 100, "%d,", c.second.cardid);
+
+        switch(c.second.cardtype){
+            case 1:
+                pmsg += std::string(buf);
+                break;
+            case 2:
+                vmsg += std::string(buf);
+                break;
+        }
+        
         vt_cards.push_back(std::make_shared<call_card>(c.second));
     }
-    log_info("[anti_coll] card's size = %d, vt_cards's size = %d", cards.size(), vt_cards.size());
+    log_info("[anti_coll] vehicle's cid = %s, person's cid = %s", vmsg.c_str(), pmsg.c_str());
 
     call_site_map site_map;
     get_site_map(vt_cards, site_map);
@@ -828,7 +877,7 @@ std::string module_call::get_json_anti_collision()
             sprintf(szID, "%03d%.10d", 1, atoi(vt_cid_d[0].c_str()));
             str_vid = szID;
             */
-            o.SetString(tool_byte::to_cardid(1, atoi(vt_cid_d[0].c_str())).c_str(), allocator);
+            o.SetString(tool_other::to_cid(1, atoi(vt_cid_d[0].c_str())).c_str(), allocator);
             e.PushBack(o, allocator);
 
             o.SetDouble(atof(vt_cid_d[1].c_str()));

+ 24 - 6
module_service/module_call.h

@@ -1,3 +1,21 @@
+/*
+ * @file
+ *      module_call.h
+ *
+ * @brief
+ *      呼叫业务
+ * @version
+ *      V1.0
+ * @author
+ *
+ * @date
+ *      2021/05/10
+ * @note
+ *
+ * @warning
+ * @bug
+ * @copyright
+ * */
 #ifndef MODULE_CALL_H
 #define MODULE_CALL_H
 
@@ -8,13 +26,13 @@
 #include <boost/thread.hpp>
 #include <boost/enable_shared_from_this.hpp>
 #include <atomic>
-#include"rapidjson/document.h"
+#include "rapidjson/document.h"
 #include "rapidjson/prettywriter.h"
-#include"module_singleton_base.h"
-#include"card.h"
-#include"websocket/sio/sio_client.h"
-#include"module_i_thread.h"
-#include"config_file.h"
+#include "module_singleton_base.h"
+#include "card.h"
+#include "websocket/sio/sio_client.h"
+#include "module_i_thread.h"
+#include "config_file.h"
 
 
 /**

+ 21 - 2
module_service/module_call_help.h

@@ -1,9 +1,28 @@
+/*
+ * @file
+ *      module_call_help.h
+ *
+ * @brief
+ *      呼救业务模块
+ *
+ * @version
+ *      V1.0
+ *
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ *
+ * */
+
 #ifndef MODULE_CALL_HELP_H
 #define MODULE_CALL_HELP_H
 
 #include "module_singleton_base.h"
-#include"card.h"
-#include"websocket/sio/sio_client.h"
+#include "card.h"
+#include "websocket/sio/sio_client.h"
 
 /**
  * @brief 呼救类

+ 12 - 19
module_service/module_meta_data_changed.cpp

@@ -31,12 +31,12 @@ void module_meta_data_changed::accept(sio::message::ptr const& data)
     }
 
     std::string szParam = "0";
-    tool_map::try_get_value(szParam,JSON_KEY_ID,data);
+    tool_map::try_get_value(szParam, JSON_KEY_ID, data);
 
     std::string op_type="";
     tool_map::try_get_value(op_type, JSON_KEY_OP_TYPE, data);
 
-    log_info("web发来数据:cmd=meta_data_changed.name:%s Param:%s OpType:%s",name.c_str(),szParam.c_str(),op_type.c_str());
+    log_info("web发来数据:cmd=meta_data_changed.name:%s Param:%s OpType:%s", name.c_str(), szParam.c_str(), op_type.c_str());
     if(!szParam.empty() && !op_type.empty())
     {
         EDIT_TYPE_ID edit_type_id;
@@ -162,7 +162,7 @@ void module_meta_data_changed::deal_call_edit_vehicle_or_staff(const std::string
         if (ET_UPDATE == edit_type_id)
         {
             auto c = card_list::instance()->get_card_by_cid(cid);
-            if (nullptr != c && tool_other::type_id_to_str(c->m_type,c->m_id) != lsz_card_id)
+            if (nullptr != c && tool_other::type_id_to_str(c->m_type, c->m_id) != lsz_card_id)
             {
                 //如果修改了卡号,则删除原来的卡的数据
                 remove_card(c);
@@ -370,6 +370,14 @@ void module_meta_data_changed::remove_card(uint32_t id, int32_t type) {
     remove_card(card_ptr);
 }
 
+/*
+ * @brief       从内存中删除卡
+ * @param       std::shared_ptr<card_location_base> card_ptr    卡对象
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_meta_data_changed::remove_card(std::shared_ptr<card_location_base> card_ptr)
 {
     if (!card_ptr)
@@ -377,22 +385,7 @@ void module_meta_data_changed::remove_card(std::shared_ptr<card_location_base> c
         return;
     }
     log_info("基础数据, 在全局列表中删除卡成功, type=%d, id=%d",card_ptr->m_type, card_ptr->m_id);
-    //    auto area_hover_ptr = card_ptr->get_area_hover();
-    //    if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
-    //    {
-    //        module_area::on_leave(card_ptr->m_id, area_hover_ptr, card_ptr->m_type);
-    //    }
-
-    //    if(card_ptr->is_person())
-    //    {
-    //        module_attendance_person::up_mine(card_ptr, nullptr);
-    //    }
-    //    else
-    //    {
-    //        module_attendance_vehicle::save_attendance(card_ptr, nullptr);
-
-    //        module_meta_data_changed::clear_card(card_ptr);
-    //    }
+    
     module_meta_data_changed::clear_card(card_ptr);
     // 避免状态重置
     uint64_t card_id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);

+ 42 - 10
module_service/module_mgr.cpp

@@ -10,22 +10,36 @@
 #include "log.h"
 #include "common_tool.h"
 #include "config_file.h"
+#include "module_screen.h"
 
 /**
- * @brief 注册web回调函数,读配置文件,启动向web发送线程
+ * @brief       注册web回调函数,读配置文件,启动向web发送线程
+ * @param       config_file& config
+ * @param       std::map<std::string, sys::MSG_HANDLE_FUNC_TYPE>& MsgFuncList
+ * @return
+ * @note
+ * @warning
+ * @bug
  */
-void module_mgr::init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
+void module_mgr::init(config_file& config, std::map<std::string, sys::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
 {
     module_web::instance()->init(config, MsgFuncList);
     module_call::instance()->init(config);
 
     area_business_motionless_persion::init(config);
     area_business_geofault::init(config);
+
+    module_screen::instance()->start();
 }
 
-/**
-     * @brief 启动线程start:向web发送事件
-     */
+/*
+ * @brief 启动线程start:向web发送事件
+ * @param
+ * @return
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_mgr::start()
 {
     area_business_geofault::init_geofault_from_db();
@@ -36,16 +50,34 @@ void module_mgr::start()
     //module_motionless_persion::instance()->start();
 }
 
-/**
-     * @brief 结束线程stop
-     */
+/*
+ * @brief 结束线程stop
+ * @param
+ * @return
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_mgr::stop()
 {
     module_web::instance()->stop();
     module_call::instance()->stop();
     //module_motionless_persion::instance()->stop();
+    module_screen::instance()->stop();
 }
 
+/*
+ * @brief       1.电量告警逻辑处理
+ *              2.呼叫呼救状态检查
+ *
+ * @param       STATUS_CARD st
+ * @param       uint32_t card_id
+ * @param       int32_t type
+ * @return
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_mgr::do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
 {
     auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
@@ -77,8 +109,8 @@ void module_mgr::do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
     {
         if(card_ptr->get_event_flag(ET_CARD_LOW_POWER_SERIOUS))
         {
-            card_ptr->set_event_flag(ET_CARD_LOW_POWER_SERIOUS,0);
-            module_other_alarm::power_nomarl(card_ptr);
+            card_ptr->set_event_flag(ET_CARD_LOW_POWER_SERIOUS, 0);
+            module_other_alarm::power_normal(card_ptr);
         }
     }
 }

+ 1 - 1
module_service/module_mgr.h

@@ -18,7 +18,7 @@ public:
     /**
      * @brief 注册web回调函数,读配置文件,启动向web发送线程
      */
-    static void init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList);
+    static void init(config_file& config, std::map<std::string, sys::MSG_HANDLE_FUNC_TYPE>& MsgFuncList);
 
     /**
      * @brief 启动线程start:向web发送事件

+ 21 - 9
module_service/module_other_alarm.cpp

@@ -1,20 +1,32 @@
-#include"module_other_alarm.h"
-
-#include"event.h"
-#include"common_tool.h"
-#include"log.h"
-
+#include "module_other_alarm.h"
+#include "event.h"
+#include "common_tool.h"
+#include "log.h"
 
+/*
+ * @brief       低电量报警
+ * @param       std::shared_ptr<card_location_base> card_ptr    卡对象
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_other_alarm::power_lower_serious(std::shared_ptr<card_location_base> card_ptr)
 {
     uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
     event_tool::instance()->handle_event(OT_CARD, ET_CARD_LOW_POWER_SERIOUS, id, 0, 0, true);
 }
 
-void module_other_alarm::power_nomarl(std::shared_ptr<card_location_base> card_ptr)
+/*
+ * @brief       电量正常时,取消电量低报警
+ * @param       std::shared_ptr<card_location_base> card_ptr
+ * @return      无
+ * @note
+ * @warning
+ * @bug
+ * */
+void module_other_alarm::power_normal(std::shared_ptr<card_location_base> card_ptr)
 {
     uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
     event_tool::instance()->handle_event(OT_CARD, ET_CARD_LOW_POWER_SERIOUS, id, 0, 0, false);
 }
-
-

+ 1 - 3
module_service/module_other_alarm.h

@@ -3,7 +3,6 @@
 #include "module_singleton_base.h"
 #include "card.h"
 
-
 class module_other_alarm:public singleton_base<module_other_alarm>
 {
 private:
@@ -14,8 +13,7 @@ private:
 
 public:
     static void power_lower_serious(std::shared_ptr<card_location_base> card_ptr);
-
-    static void power_nomarl(std::shared_ptr<card_location_base> card_ptr);
+    static void power_normal(std::shared_ptr<card_location_base> card_ptr);
 };
 
 #endif // MODULE_OTHER_ALARM_H

+ 1 - 1
module_service/module_traffic_light.cpp

@@ -142,7 +142,7 @@ void traffic_light_group::send_cmd_light(traffic_light_ptr& ptl)
         return;
     } 
 
-    YA::light_state ls(m_group_id, ptl->m_light_id, ptl->m_state, ((m_card_id == 0)?"":tool_byte::to_cardid(2,m_card_id)));
+    sys::light_state ls(m_group_id, ptl->m_light_id, ptl->m_state, ((m_card_id == 0)?"":tool_other::to_cid(2, m_card_id)));
     swsTimerThrd.upt_light_state(ls);
 
     traffic_light_manager::instance()->send_light_data(ptl->m_light_id, DT_LIGHT, ptl->m_state);

+ 2 - 2
module_service/module_traffic_light_manager.cpp

@@ -552,11 +552,11 @@ std::string traffic_light_manager::get_light_state()
 {
     std::lock_guard<std::mutex> lg(m_vtlg_mutex);
 
-    std::vector<YA::light_state> lights;
+    std::vector<sys::light_state> lights;
 
     for(auto itg : m_unmap_groups){
         for(auto itl : itg.second->m_vt_lights){
-            YA::light_state state;
+            sys::light_state state;
 
             state.m_group_id = itg.second->m_group_id;
             state.m_light_id = itl->m_light_id;

+ 5 - 6
module_service/module_traffic_light_manager.h

@@ -8,7 +8,7 @@
 #include "geo_hash.h"
 #include "log.h"
 #include "websocket/sio/sio_client.h"
-#include "tool_byte.h"
+#include "common_tool.h"
 #include "crc.h"
 #include "protocol.h"
 #include "websocket/wsTimerThread.h"
@@ -184,9 +184,8 @@ struct traffic_light_manager{
         std::vector<char> msg;
 
         uint16_t cmd = THIRD_PARTY_CHAR_LIGHT_SETUP_STATE;
-        tool_byte::memcpy_int<uint16_t>(msg, cmd);
-
-        tool_byte::memcpy_int<uint32_t>(msg, light_id);
+        tool_other::memcpy_int<uint16_t>(msg, cmd);
+        tool_other::memcpy_int<uint32_t>(msg, light_id);
 
         msg.push_back(0x05);
 
@@ -200,7 +199,7 @@ struct traffic_light_manager{
         it = msg.begin();
         msg.insert(it, (len>>8)&0xff);
 
-        tool_byte::memcpy_int<int16_t>(msg, crc);
+        tool_other::memcpy_int<int16_t>(msg, crc);
 
         auto light_ptr = get(light_id);
 
@@ -283,7 +282,7 @@ struct traffic_light_manager{
     std::map<int, std::vector<line_v>> m_map_path;
     std::map<uint64_t, std::list<traffic_light_group_ptr>> m_vehicle_traffic_groups;
 
-    YA::jsonBuilder m_jsBuilder;//json构造器类
+    sys::jsonBuilder m_jsBuilder;//json构造器类
 
 };
 

+ 55 - 5
module_service/module_web.cpp

@@ -8,6 +8,18 @@
 #include "log.h"
 #include "module_traffic_light_manager.h"
 
+/*
+ * @brief   处理请求端的请求类型,根据不同请求类型调用不同的业务模块处理
+ * @param   int ID                          回调函数id
+ * @param   std::string const& name         请求命令字
+ * @param   sio::message::ptr const& data   json数据字符串
+ * @param   bool need_ack                   是否响应
+ * @param   sio::message::list& ack_resp    响应状态
+ * @return  无
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_web::accept( int ID, std::string const& name,
                          sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
 {
@@ -26,16 +38,18 @@ void module_web::accept( int ID, std::string const& name,
 
     log_info("web发来的数据 cmd=%s", cmd.c_str());
 
-    if(JSON_CMD_VALUE_CLEAR_CARD == cmd)//手动升井
+    if(JSON_CMD_VALUE_CLEAR_CARD == cmd)
     {
+        // 手动升井
         area_business_person_attendance::handle_up_mine(data);
     }
-    else if (JSON_CMD_VALUE_REQUEST_ALL_DATA == cmd)//web登录请求所有信息
+    else if (JSON_CMD_VALUE_REQUEST_ALL_DATA == cmd)
     {
+        // web登录请求所有信息
         module_web::instance()->response_login();
     }else if(JSON_CMD_REQ_ALL_PERSON_ON_CAR == cmd)
     {
-        //人上车数据
+        // 人上车数据
     }else if(JSON_CMD_VALUE_LIGHTS_CTRL_REQUEST == cmd){
         // 红绿灯手动控制
         traffic_light_manager::instance()->manual_ctrl(data);   
@@ -68,6 +82,16 @@ void module_web::accept( int ID, std::string const& name,
     }
 }
 
+/*
+ * @brief   客户端发起请求所有数据请求,采集构造相关事件数据并发送给请求端
+ * @param   无
+ * @return  无
+ * @note
+ * 1.增加红绿灯告警         2021/03/05
+ * 2.增加人车防碰撞告警     2021/03/16
+ * @warning
+ * @bug
+ * */
 void module_web::response_login()
 {
     rapidjson::Document doc(rapidjson::kObjectType);
@@ -111,6 +135,14 @@ void module_web::response_login()
     }
 }
 
+/*
+ * @brief   构造事件列表,并发送给请求端
+ * @param   无
+ * @return  无
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_web::run()
 {
     std::vector<std::shared_ptr<ya_event>> arr;
@@ -124,6 +156,7 @@ void module_web::run()
         swsClientMgr.send(JSON_CMD_VALUE_PUSH, tmp);
     }
 
+    // 向web端发送呼救数据
     std::string help = module_call_help::get_json_help();
     if(!help.empty())
     {
@@ -131,13 +164,23 @@ void module_web::run()
     }
 }
 
+/*
+ * @brief   获得所有未发送的系统事件
+ * @param   [in] std::vector<std::shared_ptr<ya_event>>& arr    事件数组
+ * @param   [in] bool f 是否需要加入事件列表标志
+ * @return  无
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_web::_get_all_events(std::vector<std::shared_ptr<ya_event>>& arr,bool f)
 {
     auto _map = event_list::instance()->m_map;
     auto it_map = _map.begin();
     for(;it_map!=_map.end();++it_map)
     {
-        if(f && it_map->second->m_is_sent && !it_map->second->is_end())
+        //if(f && it_map->second->m_is_sent && !it_map->second->is_end())
+        if(f && !it_map->second->is_end())
             continue;
         else 
             it_map->second->m_is_sent=true;
@@ -145,7 +188,14 @@ void module_web::_get_all_events(std::vector<std::shared_ptr<ya_event>>& arr,boo
     }
 }
 
-///在全局列表中删除已经处理或结束了的告警
+/*
+ * @brief   在全局列表中删除已经处理或结束了的告警
+ * @param   std::vector<std::shared_ptr<ya_event>>& arr     事件数组
+ * @return  无
+ * @note
+ * @warning
+ * @bug
+ * */
 void module_web::_delete_end(std::vector<std::shared_ptr<ya_event>>& arr)
 {
     std::vector<uint64_t> todelete;

+ 1 - 1
module_service/module_web.h

@@ -37,7 +37,7 @@ public:
      * @brief 注册web请求回调函数
      * @param MsgFuncList
      */
-    void init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
+    void init(config_file& config, std::map<std::string, sys::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
     {
         sleep_ms = std::stoi(config.get("service.interval_send_json_alarm_ms","10000"));
 

+ 4 - 4
net-service.cpp

@@ -213,7 +213,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
                         logn_error(1,"在全局分站列表中找不到分站:%d", site_id);
                         break;
                     }else{
-                        logn_info(3, "[pdoa] site_id:%d, x:%.4f, y:%.4f", site_ptr->m_id, site_ptr->x, site_ptr->y);
+                        //logn_info(3, "[pdoa] site_id:%d, x:%.4f, y:%.4f", site_ptr->m_id, site_ptr->x, site_ptr->y);
                     }
                     
                     if(clt->type() != 2){
@@ -240,7 +240,7 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
                         m.m_loc_type = LDT_PDOA;
                         t->m_cmd_code = cmd;
                         t->m_hash_id = m.m_card_id;
-                        pdoa = get_pdoa(m.m_poa, site_ptr->m_pdoa_offset);
+                        pdoa = tool_other::get_pdoa(m.m_poa, site_ptr->m_pdoa_offset);
                         logn_info(3, "[pdoa] site_id=%d, card_id=%d, ct=%d, dist=%.3f, rav=%d, poa1=%.4f, poa2=%.4f, poa3=%.4f, pdoa=%.4f, pdoa_offset=%.4f", site_id, m.m_card_id, m.m_card_ct, dist, m.m_rav, m.m_poa[0], m.m_poa[1], m.m_poa[2], pdoa, site_ptr->m_pdoa_offset);
                      
                         if(m.m_poa[1] == 10.0){
@@ -514,7 +514,7 @@ void net_service::parse_data_card()
 {
 }
 
-float net_service::get_pdoa(float poa[], const double& offset)
+/*float net_service::get_pdoa(float poa[], const double& offset)
 {
     if(poa == nullptr){
         return -10.0;
@@ -535,4 +535,4 @@ float net_service::get_pdoa(float poa[], const double& offset)
     pdoa -= PI;
 
     return pdoa;
-}
+}*/

+ 12 - 1
net-service.h

@@ -1,3 +1,14 @@
+/*
+ * @file
+ * @brief
+ * @version
+ * @author
+ * @date
+ * @note
+ * @warning
+ * @bug
+ * @copyright
+ * */
 #ifndef __net_service_hpp__
 #define __net_service_hpp__
 
@@ -23,7 +34,7 @@ struct net_service:service_callback
     int32_t parse_data_anchor(const std::shared_ptr<client>& clt, zistream& s);
     int32_t parse_data_anchor_opt(const std::shared_ptr<client>& clt, zistream& s);
     void parse_data_card();
-    float get_pdoa(float poa[], const double& offset);
+    //float get_pdoa(float poa[], const double& offset);
 };
 
 #endif

+ 3 - 1
sys_setting.h

@@ -30,6 +30,7 @@ struct  SSys_setting // system_limit_setting
     std::string rav_disable;
     int light_group_count;
     // 人车防碰撞参数,三个档位
+    bool m_enable_anti_coll;    // 功能使能
     std::map<int, float> mp_anti_collision;
 
     SSys_setting()
@@ -58,9 +59,10 @@ struct  SSys_setting // system_limit_setting
         att_person_thre_hour = 0;
         rear_end_d = 0;
         rear_end_t = 0;
-        geofault_warn_dis=50; 
+        geofault_warn_dis = 50; 
         rav_disable = "";
         light_group_count = 1;
+        m_enable_anti_coll = false;
         mp_anti_collision.erase(mp_anti_collision.begin(), mp_anti_collision.end());
     }
 

+ 1 - 1
tqueue.h

@@ -1,11 +1,11 @@
 #ifndef INCLUDED_QUEUE_H
 #define INCLUDED_QUEUE_H
 
-
 #include <mutex>
 #include <condition_variable>
 #include <vector>
 #include <iostream>
+
 template<class T>
 class BoundedQueue 
 {

+ 0 - 3
web-client.cpp

@@ -1,9 +1,7 @@
-
 #include <functional>
 #include <thread>
 #include <memory>
 #include <ev++.h>
-
 #include "zio.h"
 #include "log.h"
 #include "zloop.h"
@@ -169,7 +167,6 @@ struct web_client_net_impl: web_client,zloop_base
 	}
 };
 
-
 web_client*web_client::instance(const char*ip,int port,const char*path)
 {
 	static web_client_net_impl impl;

+ 11 - 8
websocket/jsonBuilder.cpp

@@ -5,7 +5,8 @@
 #include <rapidjson/prettywriter.h>
 #include "constdef.h"
 #include "log.h"
-namespace YA
+
+namespace sys
 {
 	jsonBuilder::jsonBuilder()
 	{
@@ -104,8 +105,8 @@ namespace YA
 		Array.PushBack( tmp_object, Allocator );
 
 		//6 工作时长
-		tmp_object.SetDouble(CardPos.z);
-        //tmp_object.SetDouble( CardPos.work_time );
+		//tmp_object.SetDouble(CardPos.z);
+        tmp_object.SetDouble( CardPos.work_time );
 		Array.PushBack( tmp_object, Allocator );
 
 		//7 地图编号
@@ -121,7 +122,8 @@ namespace YA
 		Array.PushBack( tmp_object, Allocator );
 
 		//10 电量状态
-		tmp_object.SetInt( CardPos.stat );
+		//tmp_object.SetInt( CardPos.stat );
+        tmp_object.SetInt(CardPos.battery_val);     // 电量值,1~10
 		Array.PushBack( tmp_object, Allocator );
 
 		//11 运行状态
@@ -148,8 +150,9 @@ namespace YA
 		//tmp_object.SetDouble( CardPos.landmark_dis );
 		//Array.PushBack( tmp_object, Allocator );
 
-		//17 级别编号
-		tmp_object.SetInt( CardPos.level_id );
+		//17 级别编号,对于不要级别编号的(可以用于传输接收分站的区域id)
+		//tmp_object.SetInt( CardPos.level_id );
+        tmp_object.SetInt(CardPos.area_id);
 		Array.PushBack( tmp_object, Allocator );
 
 		//18 车辆当天出勤的标识
@@ -157,7 +160,7 @@ namespace YA
 		Array.PushBack( tmp_object, Allocator );
         //log_debug("websocket..%d",CardPos.area_info.size());
 		rapidjson::Value Array_1( rapidjson::kArrayType );
-		for(const auto &a:CardPos.area_info)	
+		for(const auto & a : CardPos.area_info)	
 		{
 			rapidjson::Value _DetailItem;
 			rapidjson::Value Array_2( rapidjson::kArrayType );
@@ -444,7 +447,7 @@ namespace YA
 			//{
 			//	continue;
 			//}
-            if(p2s && mit_card->second.Type == 1)continue;
+            //if(p2s && mit_card->second.Type == 1)continue;
 			rapidjson::Value DetailItem;
 			if ( !__BuildDetail( mit_card->second, Allocator, DetailItem ) )
 			{

+ 1 - 3
websocket/jsonBuilder.h

@@ -21,14 +21,12 @@ json构造器类
 
 #ifndef _JSONBUILDER_H_
 #define _JSONBUILDER_H_
-
 #include <map>
 #include <rapidjson/document.h>
-
 #include "jsonCommon.h"
 #include "ws_common.h"
 
-namespace YA
+namespace sys
 {
 	class jsonBuilder
 	{

+ 1 - 3
websocket/jsonCommon.h

@@ -21,15 +21,13 @@ V 1.0.0
 
 #ifndef _JSON_COMMON_H_
 #define _JSON_COMMON_H_
-
 #include <string>
 #include <vector>
-
 #include <rapidjson/document.h>
 #include <rapidjson/pointer.h>
 #include "constdef.h"
 
-namespace YA
+namespace sys
 {
 
 /**

+ 2 - 4
websocket/web_connect.cpp

@@ -1,9 +1,7 @@
 #include "web_connect.h"
-
 #include<thread>
 #include<chrono>
 #include <tool_time.h>
-
 #include"log.h"
 #include"wsClientMgr.h"
 #include"wsTimerThread.h"
@@ -16,14 +14,14 @@ web_connect::web_connect()
 
 //std::atomic<int> web_connect::_beatheart_count;
 
-void web_connect::init(const std::vector<std::string>&uri_list,int32_t st, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
+void web_connect::init(const std::vector<std::string>&uri_list,int32_t st, std::map<std::string, sys::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
 {
     //MsgFuncList.insert( std::make_pair( "beatheart", &web_connect::_beatheart_callback ) );
 
     swsClientMgr.Build( uri_list, MsgFuncList );
 
     //init thread...
-    YA::_THREAD_CONFIG_ Config;
+    sys::_THREAD_CONFIG_ Config;
     Config.SendInterval = st;
     swsTimerThrd.Init( Config );
 }

+ 1 - 3
websocket/web_connect.h

@@ -1,11 +1,9 @@
 #ifndef WEB_CONNECT_H
 #define WEB_CONNECT_H
-
 #include<atomic>
 #include<vector>
 #include<string>
 #include<memory>
-
 #include"sio_message.h"
 #include"wsClient.h"
 
@@ -14,7 +12,7 @@ class web_connect
 public:
     web_connect();
 
-    static void init(const std::vector<std::string>&uri_list,int32_t st, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList);
+    static void init(const std::vector<std::string>&uri_list,int32_t st, std::map<std::string, sys::MSG_HANDLE_FUNC_TYPE>& MsgFuncList);
 
     static void start_beatheart_monitor();
 

+ 72 - 8
websocket/wsClient.cpp

@@ -3,10 +3,10 @@
 #include <thread>
 #include <chrono>
 #include <boost/locale.hpp>
-#include"log.h"
+#include "log.h"
+#include "common_tool.h"
 
-
-namespace YA
+namespace sys
 {
 	const int _LOGIN_SLEEP_TIME_      = 500;//登录前的等待时间(单位:毫秒)
 	const int _OPEN_SOCKET_WAIT_TIME_ = 100;//等待打开socket时间(单位:毫秒)
@@ -38,9 +38,9 @@ namespace YA
 	{
 		std::shared_ptr<wsClient> ret=std::make_shared<wsClient>();
 
-		ret->__ID=__ID;
-		ret->__uri=__uri;
-		ret->__MsgFuncList=__MsgFuncList;
+		ret->__ID           = __ID;
+		ret->__uri          = __uri;
+		ret->__MsgFuncList  = __MsgFuncList;
 
 		return ret;
 	}
@@ -147,7 +147,7 @@ namespace YA
 
 		std::this_thread::sleep_for( std::chrono::milliseconds( _LOGIN_SLEEP_TIME_ ) );
 		
-		YA::_JS_LOGIN_ Login;
+		sys::_JS_LOGIN_ Login;
 		Login.user_name = JSON_VALUE_USERNAME;
 		Login.user_password = JSON_VALUE_PASSWORD;
 
@@ -196,6 +196,9 @@ namespace YA
 	{
         log_info("websocket %d close()",__ID);
 		_reset();
+
+        // 启动重连线程,尝试每隔10s连接一次,连接成功就事件阻塞
+        //reconnect();
 	}
 
 	void wsClient::_on_reconnect( unsigned p1, unsigned p2 )
@@ -254,7 +257,9 @@ namespace YA
             rapidjson::Document doc;
             int len = data->to_string().length();
             std::string str = data->to_string().substr(1, len-2);
+            //log_info("web-message: begin parse...");
             doc.Parse(str.c_str());
+            //log_info("web-message: end parse...");
             if(!doc.HasParseError()){
                 std::string cmd = doc[JSON_ROOT_KEY_CMD].GetString();
                 auto mit_func = __MsgFuncList.find(cmd);
@@ -262,6 +267,14 @@ namespace YA
                 if(mit_func != __MsgFuncList.end()){
                     sio::message::ptr msg = to_sio_message(str);  
                     mit_func->second(GetID(), name, msg, need_ack, ack_resp);
+
+                    /*sio::message::ptr msg;
+                    if(cmd == "call_card_req"){
+                        msg = call_to_sio_message(str);
+                    }else{
+                        msg = to_sio_message(str);
+                    }
+                    mit_func->second(GetID(), name, msg, need_ack, ack_resp);*/
                 }else{
                     log_info("web-message: not found cmd, MsgFuncList.size()=%d", __MsgFuncList.size());
                     for(auto it = __MsgFuncList.begin(); it != __MsgFuncList.end(); ++it){
@@ -321,8 +334,31 @@ namespace YA
 	{
 		__wsclient.sync_close();
 //		__wsclient.close();
+        log_info("[wsclient] %d close, reason=%s", __ID, GetLastError().c_str());
 	}
 
+    void wsClient::reconnect()
+    {
+        __wsclient.sync_close();
+
+        while(!IsConnected()){
+            try{
+                if(connect() < 0){
+                    log_info("[wsclient] error=%s", GetLastError().c_str());
+                    std::this_thread::sleep_for(std::chrono::seconds(3));
+                    continue;
+                }
+                login();
+                std::this_thread::sleep_for(std::chrono::seconds(10));
+            }catch(...)
+            {
+                log_info("[wsclient] connect error");
+            }
+        }
+
+        log_info("[wsClient] %d reconnect successful.", __ID);
+    }
+
 	std::string wsClient::GetLastError()
 	{
 		return __LastError;
@@ -337,12 +373,40 @@ namespace YA
     {
         sio::message::ptr message = sio::object_message::create();
         rapidjson::Document doc;
+        
         doc.Parse(val.c_str());
 
         log_info("[change sio message] val=%s", val.c_str());
         for(auto it = doc.MemberBegin(); it != doc.MemberEnd(); ++it){
             std::string key = it->name.GetString();
-            log_info("[change sio message] name=%s", key.c_str());
+            //log_info("[change sio message] name=%s", key.c_str());
+            if(it->value.IsString()){
+                static_cast<sio::object_message*>(message.get())->get_map()[key.c_str()] = sio::string_message::create(it->value.GetString());
+            }else if(it->value.IsObject()){
+                static_cast<sio::object_message*>(message.get())->get_map()[key.c_str()] = from_json(it->value);
+            }else if(it->value.IsArray()){
+                static_cast<sio::object_message*>(message.get())->get_map()[key.c_str()] = from_array(it->value);
+            }
+        }
+
+        return message;
+    }
+
+    sio::message::ptr wsClient::call_to_sio_message(const std::string& val)
+    {
+        sio::message::ptr message = sio::object_message::create();
+        rapidjson::Document doc;
+
+        doc.Parse(val.c_str());
+
+        if(doc.HasParseError()){
+            log_info("[change sio message] rapidjson::Document pares error.");
+            return message;
+        }
+
+        for(auto it = doc.MemberBegin(); it != doc.MemberEnd(); ++it){
+            std::string key = it->name.GetString();
+            //log_info("[change sio message] key=%s", key.c_str());
             if(it->value.IsString()){
                 static_cast<sio::object_message*>(message.get())->get_map()[key.c_str()] = sio::string_message::create(it->value.GetString());
             }else if(it->value.IsObject()){

+ 7 - 1
websocket/wsClient.h

@@ -35,7 +35,7 @@ websocket客户端类
 #include "jsonBuilder.h"
 #include "sio_message.h"
 
-namespace YA
+namespace sys
 {
 	//消息处理函数类型
 	typedef boost::function<void( int, std::string const&, sio::message::ptr const&, bool, sio::message::list & )> MSG_HANDLE_FUNC_TYPE;
@@ -183,7 +183,13 @@ namespace YA
 		*/
 		int GetPingTime() const ;
 
+        /*
+         * @brief   重连
+         * */
+        void reconnect();
+
         sio::message::ptr to_sio_message(const std::string& val);
+        sio::message::ptr call_to_sio_message(const std::string& val);  // 呼叫类型
         sio::message::ptr from_json(const rapidjson::Value& val);
         sio::message::ptr from_array(const rapidjson::Value& val);
 	};

+ 1 - 1
websocket/wsClientMgr.cpp

@@ -2,7 +2,7 @@
 #include "log.h"
 #include<thread>
 
-namespace YA
+namespace sys
 {
 	wsClientMgr::wsClientMgr()
 	{

+ 2 - 2
websocket/wsClientMgr.h

@@ -29,7 +29,7 @@ websocket客户端管理器类
 #include "ws_common.h"
 #include "jsonBuilder.h"
 
-namespace YA
+namespace sys
 {
 	class wsClientMgr
 	{
@@ -141,6 +141,6 @@ namespace YA
 }
 
 //单件相关定义
-typedef boost::serialization::singleton<YA::wsClientMgr> singleton_wsClientMgr;
+typedef boost::serialization::singleton<sys::wsClientMgr> singleton_wsClientMgr;
 #define swsClientMgr singleton_wsClientMgr::get_mutable_instance()
 #define swsClientMgr_const singleton_wsClientMgr::get_const_instance()

+ 22 - 4
websocket/wsTimerThread.cpp

@@ -4,8 +4,9 @@
 #include "constdef.h"
 #include "log.h"
 #include "sys_setting.h"
+#include "module_service/module_screen.h"
 
-namespace YA
+namespace sys
 {
 	wsTimerThread::wsTimerThread()
 	{
@@ -64,12 +65,29 @@ namespace YA
 
 	void wsTimerThread::__SendCardPos()
 	{
-		std::map<uint64_t, _CARD_POS_> CardPosList;
+        // 大屏只显示人卡相关数据
+        std::map<uint64_t, _CARD_POS_> cpl;
+        __CardPosList.copy(cpl);
+        for(auto it = cpl.begin();it != cpl.end();){
+            if(1 == it->second.Type){
+                cpl.insert(std::make_pair(it->first, it->second));
+                it++;
+            }else{
+                cpl.erase(it++);
+            }
+        }
+        // 大屏相关数据业务处理
+        if(cpl.size() > 0){
+            module_screen::instance()->do_write(cpl);
+        }
+        
+        // 人车数据发送给web端
+        std::map<uint64_t, _CARD_POS_> CardPosList;
 		if(__CardPosList.empty())
 		    return;
-		__CardPosList.copy( CardPosList );
+        __CardPosList.copy( CardPosList );
      
-        std::string jsCardPos = __jsBuilder.BuildCardPos( CardPosList );
+        std::string jsCardPos = __jsBuilder.BuildCardPos(CardPosList);
 
         if(jsCardPos == ""){
             return;

+ 2 - 4
websocket/wsTimerThread.h

@@ -27,14 +27,12 @@ websocket定时发送线程类
 #include <boost/shared_ptr.hpp>
 #include <boost/thread/condition.hpp>
 #include <boost/serialization/singleton.hpp>
-
 #include <ctime>
-
 #include "thread_safe_map.h"
 #include "ws_common.h"
 #include "jsonBuilder.h"
 
-namespace YA
+namespace sys
 {
 	class wsTimerThread
 	{
@@ -208,6 +206,6 @@ namespace YA
 }
 
 //单件定义
-typedef boost::serialization::singleton<YA::wsTimerThread> singleton_wsTimerThread;
+typedef boost::serialization::singleton<sys::wsTimerThread> singleton_wsTimerThread;
 #define swsTimerThrd singleton_wsTimerThread::get_mutable_instance()
 #define swsTimerThrd_const singleton_wsTimerThread::get_const_instance()

+ 28 - 7
websocket/ws_common.h

@@ -22,7 +22,7 @@
 #ifndef _WS_COMMON_INC_H_
 #define _WS_COMMON_INC_H_
 #include <map>
-namespace YA
+namespace sys
 {
     const int MIN_SEND_INTERVAL = 1;//最小发送时间间隔
 
@@ -111,12 +111,14 @@ namespace YA
     struct _CARD_POS_ : public _BASE_CARD_
     {
         std::map<int,std::tuple<int,int,int,double,uint64_t>> area_info;
-        int landmark_id;//地标编号
-        int lm_direction;//地标方向
-        int landmark_dis;//距离地标的距离
-        int level_id;//级别编号
-        int is_on_duty;//车辆是否是当天出勤的标识(1:出勤,0:不出勤)
-        int display;//是否显示(1:显示,0:不显示)
+        int landmark_id;    //地标编号
+        int lm_direction;   //地标方向
+        int landmark_dis;   //距离地标的距离
+        int level_id;       //级别编号
+        int is_on_duty;     //车辆是否是当天出勤的标识(1:出勤,0:不出勤)
+        int display;        //是否显示(1:显示,0:不显示)
+        int battery_stat;   //卡电量状态
+        int battery_val;    //卡电量值
         void Clear()
         {
             landmark_id  = 0;
@@ -125,6 +127,8 @@ namespace YA
             level_id     = 0;
             is_on_duty   = 0;
             display      = 1;//默认显示
+            battery_stat = 0;
+            battery_val  = 10;
         }
         _CARD_POS_()
         {
@@ -167,6 +171,23 @@ namespace YA
         {}
     };
 
+    // 设备状态信息
+    struct device_state{
+        uint8_t  m_type;        // 设备类型
+        uint32_t m_id;          // 设备ID
+        uint64_t m_cur_time;    // 接收时间
+
+        device_state(uint8_t type, uint32_t id, uint64_t ctime)
+            : m_type(type), 
+            m_id(id),
+            m_cur_time(ctime)
+        {}
+
+        device_state()
+            : m_id(0),
+            m_cur_time(0)
+        {}
+    };
 }
 
 #endif

+ 3 - 3
worker.cpp

@@ -99,8 +99,8 @@ struct timer_worker_thread: loop_thread
 		int v = card_list::instance()->version();
 		card_list_visit clv;
 		if(v != version){
-			version=v;
-			clv._flag=true;
+			version = v;
+			clv._flag = true;
 			mine_business::inst()->clear_vehicle();
 		}
 		card_list::instance()->accept(clv);
@@ -169,7 +169,7 @@ struct worker_thread: loop_thread ,visitor<std::shared_ptr<card_location_base>>
 	void on_timeout()
 	{
 		update_local_cards();
-		for(auto&c:m_local_card_list)
+		for(auto &c : m_local_card_list)
 		{
 			c->on_timer();
 		}

+ 2 - 20
znet.cpp

@@ -12,13 +12,11 @@
 #include <algorithm>
 #include <fstream>
 #include <time.h>
-
 #include <zio.h>
 #include <znet.h>
 #include <zloop.h>
 #include <clock.h>
 #include <worker.h>
-
 #include "config_file.h"
 #include "crc.h"
 
@@ -61,7 +59,6 @@ public:
 	}
 	void on_timer()
 	{
-//		logn_info(1,"tick timer timeout.");
 		m_serv.on_timer();	
 	}
 	void on_connect(const std::shared_ptr<client> &clt)
@@ -199,12 +196,10 @@ struct sock_client:fd_io,client_ex
 	std::mutex m_mutex;
 	std::list<std::vector<char>> m_olist;
 	std::vector<char> m_obuf;
-	size_t m_opos=0;
-	bool   m_can_write{false};
+	size_t  m_opos=0;
+	bool    m_can_write{false};
     int     m_site_id{-1};
 
-//	char m_timestamp[8];
-
 	sock_client(io_context&ic,const char*name,int fd,int recv_time_out,int max_package_size)
 		:fd_io(ic,fd,EV_READ|EV_WRITE)
 		,m_ic(ic)
@@ -215,7 +210,6 @@ struct sock_client:fd_io,client_ex
 		m_max_package_size=max_package_size;
 		m_recv_time_out=recv_time_out;
 
-//		m_recv_timer.set(ic);
 		m_recv_timer.set<sock_client,&sock_client::on_recv_timeout>(this);
 		int recv_timeout_first=config.get("service.recv_timeout_first",10);
 
@@ -303,8 +297,6 @@ struct sock_client:fd_io,client_ex
 		struct timeval tv;
 		gettimeofday(&tv,0);
 
-//		tv.tv_sec+=365*86400;
-
 		struct tm buff={0};
 		const struct tm*t=localtime_r(&tv.tv_sec,&buff);
 
@@ -495,8 +487,6 @@ struct sock_client:fd_io,client_ex
 			{
 				m_can_write=false;
 				set(EV_READ|EV_WRITE);
-//				m_send_timer.set(5);
-//				m_send_timer.start();
 				break;
 			}
 			else
@@ -509,7 +499,6 @@ struct sock_client:fd_io,client_ex
 		if(m_olist.empty() && m_can_write)
 		{
 			set(EV_READ);
-//			m_send_timer.stop();
 		}
 
 		return 0;
@@ -521,7 +510,6 @@ struct sock_client:fd_io,client_ex
 		{
 			logn_debug(1,"socket %d(%s) can write,flag=%d." ,m_fd,m_name.c_str(),flag);
 			m_can_write=true;
-//			m_send_timer.stop();
 			if(io_write()<0)
 			{
 				close_impl();
@@ -531,15 +519,12 @@ struct sock_client:fd_io,client_ex
 
 		if(flag & EV_READ)
 		{
-//			log_debug("socket %d(%s) can read,flag=%d." ,m_fd,m_name.c_str(),flag);
-//			zclock c;
 			if(io_read()<0)
 			{
 				close_impl();
 				return;
 			}
 
-//			log_info("use time %d ms.",c.count_us());
 			m_recv_timer.start(m_recv_time_out);
 		}
 	}
@@ -605,7 +590,6 @@ struct signal_w:ev::sig
 		:ev::sig(ic)
 		,m_ic(ic)
 	{
-		//this->set(m_ic);
 		this->set(this);
 		this->set(s);
 		this->start();
@@ -638,7 +622,6 @@ struct main_loop:io_context
 		}
 
 		sock_listen _1(*this,fd);
-//		stdin_io _2(*this);
 		block_sig(SIGPIPE);
 		signal_w sint(*this,SIGINT),term(*this,SIGTERM);
 
@@ -676,7 +659,6 @@ struct main_loop:io_context
 	}
 };
 
-
 service_handle*service_handle::instance(service_callback*sc)
 {
 	static main_loop _impl(*sc);