Bladeren bron

fix morecard bug, && web bug

lixioayao 6 jaren geleden
bovenliggende
commit
f4f8eeb8cf
6 gewijzigde bestanden met toevoegingen van 49 en 37 verwijderingen
  1. 5 2
      bindmorecard.cpp
  2. 6 2
      bindmorecard.h
  3. 21 27
      card.cpp
  4. 14 5
      card.h
  5. 2 0
      cardMgr.cpp
  6. 1 1
      main.cpp

+ 5 - 2
bindmorecard.cpp

@@ -1,17 +1,20 @@
 #include "bindmorecard.h"
 #include <config_file.h>
+
 extern config_file config;
 
 RemoteCardFactory::RemoteCardFactory(cardMgr * owner)
 		:CardFactory(owner)
 {
 	int remote_hours = config.get("BindMoreCard.timeAlarm_remote",1);
-	m_remote_slot =(int)((remote_hours*60*1000)/TIME_WIN_MILLISEC);
+	m_remote_slot =(int)((remote_hours*60 *60*1000)/TIME_WIN_MILLISEC);
+	std_info("remote:%d",m_remote_slot);
 }
 
 CloserCardFactory::CloserCardFactory(cardMgr * owner)
 		:CardFactory(owner)
 {
 	int closer_hours = config.get("BindMoreCard.timeAlarm_closer",3);
-	m_closer_slot =(int)((closer_hours*60*1000)/TIME_WIN_MILLISEC);
+	m_closer_slot =(int)((closer_hours*60*60*1000)/TIME_WIN_MILLISEC);
+	std_info("closer:%d",m_closer_slot);
 }

+ 6 - 2
bindmorecard.h

@@ -22,7 +22,11 @@ struct MyHash
 	typedef uint64_t result_type;
 	result_type operator ()(uint64_t c1,uint64_t c2) const
 	{
-		std::string s = std::to_string(c1) + std::to_string(c2);
+		std::string s;
+		if(c1<c2)
+		  s = std::to_string(c1) + std::to_string(c2);
+		else 
+		  s = std::to_string(c2) + std::to_string(c1);
 		result_type st1 = std::hash<std::string>{}(s);
 		return st1;
 	}
@@ -74,7 +78,6 @@ struct TcardInterface
 		  grow(tsp);
 		uint64_t tmp_tsp_min = back(0).m_timestamp;
 		uint64_t tmp_tsp_max = back(0).m_timestamp + TIME_WIN_MILLISEC;
-		log_info("setindex:%lld,%lld",tsp,tmp_tsp_min);
 		assert(tsp >= tmp_tsp_min);
 
 		do
@@ -257,6 +260,7 @@ struct CardFactory
 			  ptr = iter->second;
 			else
 			{
+				log_info("handlecard..%lld,%lld,%lld",id,cardid,cid);
 				ptr = make_shared_(cardid,cid,cttime,id);
 				m_map.insert({id,ptr});
 				backup(cid,cardid);

+ 21 - 27
card.cpp

@@ -20,6 +20,7 @@
 #include "ant.h"
 #include "mine.h"
 #include "module_service/module_mgr.h"
+#include "visit.h"
 
 extern config_file config;
 //一张卡一个ct的所有不同天线的信息
@@ -214,10 +215,6 @@ struct person:card_location_base, card_area
 
     void clear()
     {
-        //清除定时器
-        m_timer.stop();
-        m_loop = nullptr;
-
         m_site_area.reset(new site_area_hover);
         m_area_tool.reset(new area_tool);
         m_mine_tool.reset(new mine_tool);
@@ -259,17 +256,6 @@ struct person:card_location_base, card_area
 	}
 	//人卡升井后该线程要停掉
 	//手动升级需要补全区域得同时,需要进区域走区域业务
-	void set(ev::dynamic_loop * loop)
-	{
-		if(!m_mine_tool->is_attendance())
-		  return;
-		log_info("person_is_on_att......%d",m_id);
-	    m_loop = loop;
-	
-	    m_timer.set(*m_loop);
-	    m_timer.set<person,&person::on_timer>(this);
-		m_timer.start(10,1);
-	}
 	void reset(std::shared_ptr<monkey_person> mp)
 	{
 		m_monkeyPerson = mp;
@@ -278,6 +264,8 @@ struct person:card_location_base, card_area
 private:
 	void on_timer()
 	{    
+		if(!m_mine_tool->is_attendance())
+		  return;
 		YA::_CARD_POS_ cp;
 		point pt = getSmoothPoint();
 		const auto lm = m_area_tool->getLandmark();
@@ -364,16 +352,6 @@ struct car:card_location_base,card_area
         m_mine_tool->on_point(m_id, m_type, m_vehicle_category_id);
 	}
 
-	void set(ev::dynamic_loop * loop)
-	{
-		log_info("cardid_id %d",m_id);
-	    m_loop = loop;
-	
-	    m_timer.set(*m_loop);
-	    m_timer.set<car,&car::on_timer>(this);
-		m_timer.start(1,1);
-	}
-
     int get_vehicle_type_id()
     {
         return  m_vehicle_type_id;
@@ -594,6 +572,7 @@ void card_list::load_his_card_postion_from_db()
 {
     load_his_card_postion_vehicle();
     load_his_card_postion_staff();
+	run();
 
     for(auto&iter: m_map)
     {
@@ -875,6 +854,23 @@ void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_
 
 	c->on_message(loop,loc,is_history);
 }
+struct local_visit:visitor<std::shared_ptr<card_location_base>>
+{
+	bool visit(std::shared_ptr<card_location_base> c)
+	{
+		c->on_timer();
+		return true;	
+	}
+};
+void card_list::onTimer()
+{
+	local_visit lv;
+	while(!m_bflag)
+	{
+		card_list::instance()->accept(lv);	
+		std::this_thread::sleep_for(std::chrono::seconds(1));
+	}
+}
 //-----------------card_location_base..
 card_location_base::card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid,int32_t level_id)
 	:card(id,dis,t,deptid,level_id)
@@ -912,8 +908,6 @@ void card_location_base::on_location(const std::vector<point>&vp,const std::vect
 
 void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
 {
-	if(m_loop == nullptr && loop != nullptr)
-		set(loop);
 	m_ct = loc.m_card_ct;
 	m_time = loc.m_time_stamp;
 	m_message_handle->on_message(loop,loc,is_history);

+ 14 - 5
card.h

@@ -10,6 +10,7 @@
 #include "area.h"
 #include "site_area.h"
 #include "loc_message.h"
+#include "thread"
 #define CARD_LOST_TIME_OUT (30*1000)
 
 struct task;
@@ -52,14 +53,15 @@ struct card_location_base:card
     std::unique_ptr<select_tool> m_sel_tool;
     std::unique_ptr<smooth_tool> m_smo_tool;
 	card_message_handle *m_message_handle=nullptr;
-    ev::dynamic_loop * m_loop = nullptr;
-    ev::timer m_timer;
+  //  ev::dynamic_loop * m_loop = nullptr;
+ //   ev::timer m_timer;
 
     card_location_base()=default;
     card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t,int32_t );
 
 	virtual void do_business(const point &pt)=0;
-	virtual void set(ev::dynamic_loop * loop)=0;
+//	virtual void set(ev::dynamic_loop * loop)=0;
+	virtual void on_timer()=0;
 	virtual void site_hover(int sid)=0;
     virtual std::shared_ptr<area_hover> get_area_hover()=0;
     virtual std::shared_ptr<mine_tool> get_mine_tool()=0;
@@ -99,8 +101,15 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
     void load_his_card_postion_vehicle();
     void load_his_card_postion_staff();
     void load_his_card_postion_from_db();
-
+	std::unique_ptr<std::thread> m_pThread;
+	bool m_bflag=false;
+	void run()
+	{
+		m_pThread.reset(new std::thread(std::bind(&card_list::onTimer,this)));
+	}
+	void onTimer();
     /// (类型<<32)|卡号
+	//公用函数最好不要使用成员函数,改成公共函数。
     static uint64_t to_id64(int32_t type, uint32_t id)
     {
         return (static_cast<uint64_t>(type)<<32)|id;
@@ -113,7 +122,7 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
 
         return std::string(sql);
     }
-    ~card_list(){}
+    ~card_list(){m_bflag=true;}
 };
 
 #endif

+ 2 - 0
cardMgr.cpp

@@ -64,6 +64,8 @@ void cardMgr::handleMessage(const Msg &m)
 
 		if (!map2.empty())
 		{
+			for(const auto x:map2)
+				log_info("---LemonHash----[%s]%s",i?"Remote":"Closer",x.second.c_str());
 			//m_owner->uwb_alarm(map2,i,c);
 		}
 		if (!rc.empty())

+ 1 - 1
main.cpp

@@ -124,7 +124,7 @@ void usage(char ** argv)
 	}
 	else if(cmd == "--version" || cmd == "-v")
 	{
-		printf("yals (采集程序) 1.0.0\n");
+		printf("yals (采集程序) 0.1.0\n");
 	}
 	else
 	{