Browse Source

分解loc_tool接口到单独的文件组

zzj 6 years ago
parent
commit
ffb6df3e8f
7 changed files with 236 additions and 222 deletions
  1. 5 7
      Makefile.am
  2. 0 152
      ant.cpp
  3. 0 63
      ant.h
  4. 2 0
      c2.cpp
  5. 1 0
      card.cpp
  6. 158 0
      loc_tool.cpp
  7. 70 0
      loc_tool.h

+ 5 - 7
Makefile.am

@@ -4,14 +4,14 @@ noinst_PROGRAMS=client async test
 AM_SOURCES= ant.cpp ant.h base64.cpp base64.h card.cpp card.h clock.h \
 io_buf.h line.h log.h message.cpp message.h point.cpp \
 point.h tdoa_sync.cpp tdoa_sync.h web-client.cpp web-client.h worker.cpp worker.h zio.h \
-zloop.h znet.cpp znet.h zstream.h net-service.h net-service.cpp
+zloop.h znet.cpp znet.h zstream.h net-service.h net-service.cpp loc_tool.h loc_tool.cpp
 
-AM_CPPFLAGS=-Wall -pthread -m64 -std=c++11 -fPIC
-AM_LDFLAGS= -Wall -pthread -m64 -std=c++11 -fPIC
+AM_CPPFLAGS=-Wall -pthread -m64 -std=c++11 -fPIC -I${prefix}/include
+AM_LDFLAGS= -Wall -pthread -m64 -std=c++11 -fPIC -L${prefix}/lib 
 
 yals_SOURCES=${AM_SOURCES} main.cpp 
-yals_CPPFLAGS=${AM_CPPFLAGS} -I${prefix}/include
-yals_LDFLAGS=${AM_LDFLAGS}  -L${prefix}/lib -lzlog -lrt
+yals_CPPFLAGS=${AM_CPPFLAGS} 
+yals_LDFLAGS=${AM_LDFLAGS}  -lzlog -lrt
 
 async_SOURCES=async.cpp
 async_CPPFLAGS=${AM_CPPFLAGS}
@@ -28,5 +28,3 @@ test_LDFLAGS=${AM_LDFLAGS}  -L. -lzlog -lrt
 DEFS= 
 EXTRA_DIST=message_file.h 
 
-
-

+ 0 - 152
ant.cpp

@@ -34,158 +34,6 @@ int loc_message::tool_index()const
 	return m_ant->index();
 }
 
-
-std::vector<point> loc_tool_tdoa_3_base::calc_location(const std::vector<loc_message>&locm)
-{
-	return std::vector<point>();
-}
-int loc_tool_tdoa_3_base::index() 
-{
-	return 5;
-}
-
-std::vector<point> loc_tool_tdoa_2_base::calc_location(const std::vector<loc_message>&locm)
-{
-	return std::vector<point>();
-}
-int loc_tool_tdoa_2_base::index() 
-{
-	return 3;
-}
-
-std::vector<point> loc_tool_tdoa_1_base::calc_location(const std::vector<loc_message>&locm)
-{
-	return std::vector<point>();
-}
-int loc_tool_tdoa_1_base::index() 
-{
-	return 1;
-}
-
-std::vector<point> loc_tool_tof_3_base::calc_location(const std::vector<loc_message>&locm)
-{
-	return std::vector<point>();
-}
-int loc_tool_tof_3_base::index() 
-{
-	return 4;
-}
-
-std::vector<point> loc_tool_tof_2_base::calc_location(const std::vector<loc_message>&locm)
-{
-	return std::vector<point>();
-}
-int loc_tool_tof_2_base::index() 
-{
-	return 2;
-}
-
-void loc_tool_tof_1_base::on_loc_message(ant*,const message_locinfo&m)
-{
-	log_info("tof1-message:site=%d,ant=%d,card=%d,ct=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d",
-			m.m_site_id,m.m_ant_id,m.m_card_id,m.m_card_ct,m.m_tof,m.m_rav,m.m_acc,m.m_rssi);
-}
-
-std::vector<point> loc_tool_tof_1_base::calc_location(const std::vector<loc_message>&locm)
-{
-	return std::vector<point>();
-}
-int loc_tool_tof_1_base::index() 
-{
-	return 0;
-}
-
-loc_tool_main::loc_tool_main()
-{
-	set_tool(new loc_tool_tof_1_base());
-	set_tool(new loc_tool_tof_2_base());
-	set_tool(new loc_tool_tof_3_base());
-	set_tool(new loc_tool_tdoa_1_base());
-	set_tool(new loc_tool_tdoa_2_base());
-	set_tool(new loc_tool_tdoa_3_base());
-}
-
-loc_tool_main::~loc_tool_main()
-{
-	for(auto&tool:g_tool)
-		delete tool;
-}
-
-loc_tool* loc_tool_main::get_tool(int index)
-{
-	if((uint32_t)index >= sizeof(g_tool)/sizeof(loc_tool*))
-		return nullptr;
-	
-	return g_tool[index];
-}
-
-void loc_tool_main::set_tool(loc_tool*tool)
-{
-	int index=tool->index();
-	if(g_tool[index])
-	{
-		delete g_tool[index];
-		g_tool[index]=0;
-	}
-	g_tool[index]=tool;
-}
-
-void loc_tool_main::on_loc_message(ant*a, const message_locinfo&m)
-{
-	loc_tool*lt=get_tool(a->index());
-	if(lt==nullptr)
-	{
-		log_warn("无法找到对应的loctool-message:site=%d,ant=%d,card=%d,ct=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d",
-				m.m_site_id,m.m_ant_id,m.m_card_id,m.m_card_ct,m.m_tof,m.m_rav,m.m_acc,m.m_rssi);
-		return;
-	}
-
-	lt->on_loc_message(a, m);
-}
-
-std::vector<point> loc_tool_main::calc_location(const std::vector<loc_message>&locm)
-{
-	if(locm.empty()) return {};
-	int tool_index=locm[0].tool_index(),i=1,len=locm.size();
-	for(;i<len;i++)
-	{
-		if(tool_index!=locm[i].tool_index())
-			break;
-	}
-
-	if(i==len)
-	{
-		return std::move(g_tool[tool_index]->calc_location(locm));
-	}
-
-	//包含至少两种定位方式的基站,目前只考虑两种
-	std::vector<loc_message> locm1,locm2;
-	locm1.assign(locm.begin(),locm.begin()+i);
-
-	for(;i<len;i++)
-	{
-		if(tool_index!=locm[i].tool_index())
-			locm2.push_back(locm[i]);
-		else
-			locm1.push_back(locm[i]);
-	}
-
-	std::vector<point> rc;
-	if(locm1[0].m_ant->config().best_msg_cnt<=(int)locm1.size())
-	{
-		rc=std::move(g_tool[tool_index]->calc_location(locm1));
-	}
-
-	if(locm1[1].m_ant->config().best_msg_cnt<=(int)locm2.size())
-	{
-		int index=locm2[0].tool_index();
-		auto v=std::move(g_tool[index]->calc_location(locm2));
-		rc.insert(rc.begin(),v.begin(),v.end());
-	}
-
-	return std::move(rc);
-}
-
 algo_config ant::g_config[]=
 {
 	{ "tof-1",  1, 2, 100, 1000 },

+ 0 - 63
ant.h

@@ -89,68 +89,5 @@ struct loc_message
 	int tool_index()const;
 };
 
-struct message_locinfo;
-struct loc_tool
-{
-	//将基础信息送入工具类,目前考虑各种算法输出不同的实时日志
-	virtual void on_loc_message(ant*a, const message_locinfo&m){};
-	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm)=0;
-	virtual int index()
-	{
-		return -1;
-	}
-	virtual ~loc_tool(){}
-};
-
-struct loc_tool_tdoa_3_base:loc_tool
-{
-	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
-	virtual int index();
-};
-
-struct loc_tool_tdoa_2_base:loc_tool
-{
-	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
-	virtual int index();
-};
-
-struct loc_tool_tdoa_1_base:loc_tool
-{
-	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
-	virtual int index();
-};
-
-struct loc_tool_tof_3_base:loc_tool
-{
-	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
-	virtual int index();
-};
-
-struct loc_tool_tof_2_base:loc_tool
-{
-	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
-	virtual int index();
-};
-
-struct loc_tool_tof_1_base:loc_tool
-{
-	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
-	virtual void on_loc_message(ant*a, const message_locinfo&m);
-	virtual int index();
-};
-
-struct loc_tool_main:loc_tool
-{
-	loc_tool* g_tool[6];
-
-	loc_tool_main();
-	~loc_tool_main();
-	void set_tool(loc_tool*tool);
-	loc_tool* get_tool(int index);
-
-	void on_loc_message(ant*a, const message_locinfo&m);
-	std::vector<point> calc_location(const std::vector<loc_message>&locm);
-};
-
 #endif
 

+ 2 - 0
c2.cpp

@@ -124,3 +124,5 @@ struct person_card:card
 	}
 };
 
+
+

+ 1 - 0
card.cpp

@@ -5,6 +5,7 @@
 #include <zloop.h>
 #include <ev++.h>
 #include <message.h>
+#include <loc_tool.h>
 
 struct card_location_base
 {

+ 158 - 0
loc_tool.cpp

@@ -0,0 +1,158 @@
+
+#include <vector>
+
+#include <log.h>
+#include <ant.h>
+#include <loc_tool.h>
+#include <message.h>
+
+std::vector<point> loc_tool_tdoa_3_base::calc_location(const std::vector<loc_message>&locm)
+{
+	return std::vector<point>();
+}
+int loc_tool_tdoa_3_base::index() 
+{
+	return 5;
+}
+
+std::vector<point> loc_tool_tdoa_2_base::calc_location(const std::vector<loc_message>&locm)
+{
+	return std::vector<point>();
+}
+int loc_tool_tdoa_2_base::index() 
+{
+	return 3;
+}
+
+std::vector<point> loc_tool_tdoa_1_base::calc_location(const std::vector<loc_message>&locm)
+{
+	return std::vector<point>();
+}
+int loc_tool_tdoa_1_base::index() 
+{
+	return 1;
+}
+
+std::vector<point> loc_tool_tof_3_base::calc_location(const std::vector<loc_message>&locm)
+{
+	return std::vector<point>();
+}
+int loc_tool_tof_3_base::index() 
+{
+	return 4;
+}
+
+std::vector<point> loc_tool_tof_2_base::calc_location(const std::vector<loc_message>&locm)
+{
+	return std::vector<point>();
+}
+int loc_tool_tof_2_base::index() 
+{
+	return 2;
+}
+
+void loc_tool_tof_1_base::on_loc_message(ant*,const message_locinfo&m)
+{
+	log_info("tof1-message:site=%d,ant=%d,card=%d,ct=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d",
+			m.m_site_id,m.m_ant_id,m.m_card_id,m.m_card_ct,m.m_tof,m.m_rav,m.m_acc,m.m_rssi);
+}
+
+std::vector<point> loc_tool_tof_1_base::calc_location(const std::vector<loc_message>&locm)
+{
+	return std::vector<point>();
+}
+int loc_tool_tof_1_base::index() 
+{
+	return 0;
+}
+
+loc_tool_main::loc_tool_main()
+{
+	set_tool(new loc_tool_tof_1_base());
+	set_tool(new loc_tool_tof_2_base());
+	set_tool(new loc_tool_tof_3_base());
+	set_tool(new loc_tool_tdoa_1_base());
+	set_tool(new loc_tool_tdoa_2_base());
+	set_tool(new loc_tool_tdoa_3_base());
+}
+
+loc_tool_main::~loc_tool_main()
+{
+	for(auto&tool:g_tool)
+		delete tool;
+}
+
+loc_tool* loc_tool_main::get_tool(int index)
+{
+	if((uint32_t)index >= sizeof(g_tool)/sizeof(loc_tool*))
+		return nullptr;
+	
+	return g_tool[index];
+}
+
+void loc_tool_main::set_tool(loc_tool*tool)
+{
+	int index=tool->index();
+	if(g_tool[index])
+	{
+		delete g_tool[index];
+		g_tool[index]=0;
+	}
+	g_tool[index]=tool;
+}
+
+void loc_tool_main::on_loc_message(ant*a, const message_locinfo&m)
+{
+	loc_tool*lt=get_tool(a->index());
+	if(lt==nullptr)
+	{
+		log_warn("无法找到对应的loctool-message:site=%d,ant=%d,card=%d,ct=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d",
+				m.m_site_id,m.m_ant_id,m.m_card_id,m.m_card_ct,m.m_tof,m.m_rav,m.m_acc,m.m_rssi);
+		return;
+	}
+
+	lt->on_loc_message(a, m);
+}
+
+std::vector<point> loc_tool_main::calc_location(const std::vector<loc_message>&locm)
+{
+	if(locm.empty()) return {};
+	int tool_index=locm[0].tool_index(),i=1,len=locm.size();
+	for(;i<len;i++)
+	{
+		if(tool_index!=locm[i].tool_index())
+			break;
+	}
+
+	if(i==len)
+	{
+		return std::move(g_tool[tool_index]->calc_location(locm));
+	}
+
+	//包含至少两种定位方式的基站,目前只考虑两种
+	std::vector<loc_message> locm1,locm2;
+	locm1.assign(locm.begin(),locm.begin()+i);
+
+	for(;i<len;i++)
+	{
+		if(tool_index!=locm[i].tool_index())
+			locm2.push_back(locm[i]);
+		else
+			locm1.push_back(locm[i]);
+	}
+
+	std::vector<point> rc;
+	if(locm1[0].m_ant->config().best_msg_cnt<=(int)locm1.size())
+	{
+		rc=std::move(g_tool[tool_index]->calc_location(locm1));
+	}
+
+	if(locm1[1].m_ant->config().best_msg_cnt<=(int)locm2.size())
+	{
+		int index=locm2[0].tool_index();
+		auto v=std::move(g_tool[index]->calc_location(locm2));
+		rc.insert(rc.begin(),v.begin(),v.end());
+	}
+
+	return std::move(rc);
+}

+ 70 - 0
loc_tool.h

@@ -0,0 +1,70 @@
+#ifndef __loc_tool_hpp__
+#define __loc_tool_hpp__
+
+struct ant;
+struct message_locinfo;
+
+struct loc_tool
+{
+	//将基础信息送入工具类,目前考虑各种算法输出不同的实时日志
+	virtual void on_loc_message(ant*a, const message_locinfo&m){};
+	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm)=0;
+	virtual int index()
+	{
+		return -1;
+	}
+	virtual ~loc_tool(){}
+};
+
+struct loc_tool_tdoa_3_base:loc_tool
+{
+	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
+	virtual int index();
+};
+
+struct loc_tool_tdoa_2_base:loc_tool
+{
+	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
+	virtual int index();
+};
+
+struct loc_tool_tdoa_1_base:loc_tool
+{
+	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
+	virtual int index();
+};
+
+struct loc_tool_tof_3_base:loc_tool
+{
+	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
+	virtual int index();
+};
+
+struct loc_tool_tof_2_base:loc_tool
+{
+	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
+	virtual int index();
+};
+
+struct loc_tool_tof_1_base:loc_tool
+{
+	virtual std::vector<point> calc_location(const std::vector<loc_message>&locm);
+	virtual void on_loc_message(ant*a, const message_locinfo&m);
+	virtual int index();
+};
+
+struct loc_tool_main:loc_tool
+{
+	loc_tool* g_tool[6];
+
+	loc_tool_main();
+	~loc_tool_main();
+	void set_tool(loc_tool*tool);
+	loc_tool* get_tool(int index);
+
+	void on_loc_message(ant*a, const message_locinfo&m);
+	std::vector<point> calc_location(const std::vector<loc_message>&locm);
+};
+
+#endif
+