researchman 8 years ago
parent
commit
826776a13a
11 changed files with 2062 additions and 327 deletions
  1. 1 0
      YAServer.vcxproj
  2. 6 0
      YAServer.vcxproj.filters
  3. 1433 287
      YAServerDlg.cpp
  4. 12 1
      YAServerDlg.h
  5. 165 19
      classdef.cpp
  6. 50 16
      classdef.h
  7. 17 3
      constdef.h
  8. 1 1
      def.h
  9. 326 0
      locate_algorithm.cpp
  10. 4 0
      locate_algorithm.h
  11. 47 0
      tdoa/TDOAFunctor.h

+ 1 - 0
YAServer.vcxproj

@@ -203,6 +203,7 @@ xcopy "$(SolutionDir)..\config.ini" "D:\0a-share\$(Configuration)\" /Y /C /D /S<
     <ClInclude Include="SysSetting.h" />
     <ClInclude Include="system_basic_info\SystemAnalysis.h" />
     <ClInclude Include="targetver.h" />
+    <ClInclude Include="tdoa\TDOAFunctor.h" />
     <ClInclude Include="YAServer.h" />
     <ClInclude Include="YAServerDlg.h" />
   </ItemGroup>

+ 6 - 0
YAServer.vcxproj.filters

@@ -288,6 +288,9 @@
     <ClInclude Include="system_basic_info\SystemAnalysis.h">
       <Filter>system_basic_info</Filter>
     </ClInclude>
+    <ClInclude Include="tdoa\TDOAFunctor.h">
+      <Filter>tdoa</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\config.ini" />
@@ -354,6 +357,9 @@
     <Filter Include="system_basic_info">
       <UniqueIdentifier>{dbd9d95d-a924-4777-9b9b-47465f33f304}</UniqueIdentifier>
     </Filter>
+    <Filter Include="tdoa">
+      <UniqueIdentifier>{9363126c-e934-4fdc-af0d-6898e16bc839}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="YAServer.rc">

File diff suppressed because it is too large
+ 1433 - 287
YAServerDlg.cpp


+ 12 - 1
YAServerDlg.h

@@ -206,7 +206,7 @@ public:
 	PatrolTaskCheckMap mp_card_task_list;
 
 	std::shared_ptr<TDOAReaderPathMap> mp_reader_path_list_tdoa;
-	std::shared_ptr<CardMap> mp_card_list_over_time_person;
+	std::shared_ptr<CardMap> mp_card_list_over_time_person;			
 	std::shared_ptr<CardMap> mp_card_list_forbidden_person;
 	std::shared_ptr<CardMap> mp_card_list_help;
 	std::shared_ptr<CardMap> mp_card_list_area_over_time_person;
@@ -238,6 +238,14 @@ public:
 	INT64 m_event_list[MINE_EVENT_COUNT];
 private:
 	int init_smart_pointer_var();
+
+#ifdef CERTIFY_READER_RANGE_AREA
+private:
+	AreaMap mp_reader_range_area_list; // ËùÓÐÇøÓò
+private:
+	int init_reader_range_area();
+#endif // CERTIFY_READER_RANGE_AREA
+
 public:
 	void init_ui();
 	void init_param();
@@ -353,10 +361,12 @@ public:
 	string get_json_event();
 	string get_json_call_list();
 	string get_json_new_device_state();
+	Json::Value get_json_count_list(int req_type,int area_id);
 
 	Json::Value get_section_json_alarm();
 	Json::Value get_light_json_alarm();
 	Json::Value get_red_light_json_alarm();
+	Json::Value get_card_info(std::shared_ptr<Card> pCard);
 
 	void send_json_data(string cmd, string data, bool is_login = false);
 	// ÒµÎñ´¦Àí
@@ -416,6 +426,7 @@ public:
 	void parse_json_data_clear_card(const char* sz);
 	void parse_json_data_deal_help(const char* sz);
 	int  parse_json_data_set_light_color(message::ptr const& data);
+	int  parse_json_data_request_counts_info(message::ptr const& data);
 
 	void deal_call_edit_map(int id, EDIT_TYPE_ID edit_type_id);
 	void deal_call_edit_area(int id, EDIT_TYPE_ID edit_type_id);

+ 165 - 19
classdef.cpp

@@ -114,6 +114,7 @@ Card::Card( string cardid, int cardtype, double z_offset, double offset_x /*= 12
 	m_nIsRailroad = 0;
 	mileage = 0;
 	diff_direction_counts = 0;
+	m_nStream = 0;
 
 	for(int i = 0; i < CARD_EVENT_COUNT; i++){
 		m_event_list[i] = 0;
@@ -121,6 +122,18 @@ Card::Card( string cardid, int cardtype, double z_offset, double offset_x /*= 12
 
 	_dists.swap(DistQueMap());
 	vt_his_speed.resize(0);
+
+	call_type = 0;
+	vt_deal_call_reader_id.resize(0);
+	recv_call_time = time(NULL);
+
+#ifdef CERTIFY_READER_RANGE_AREA
+	reader_area_id = 0;
+	cur_reader_area = 0;
+	old_reader_area = 0;
+
+	::GetLocalTime(&deal_reader_time);
+#endif
 }
 
 Card::Card( void )
@@ -185,7 +198,7 @@ void Card::inspect_coordinate(int acce_state)
 	if (acce_state == STATE_ACCE_STATIC)
 	{
 		this->isoutput = false;
-		TRACE(_T("is daisu \r\n"));
+		//TRACE(_T("is daisu \r\n"));
 	}
 	else
 	{
@@ -385,7 +398,7 @@ void Card::algo_tdoa(int cnt)
     LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_140);
 	GetLocalTime(&m_afmData.st);
 
-	TRACE(_T("enter algo \r\n"));
+	//TRACE(_T("enter algo \r\n"));
 
 	if(cnt < 2){
 		LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_141);
@@ -512,6 +525,7 @@ void Card::algo_tdoa(int cnt)
 			//满足此条件,表名标示卡的计数序号走完了65535的周期
 		}
 		else{
+			pRdm->clear();
 			this->x = this->last_locate.x;
 			this->y = this->last_locate.y;
 			//this->z = INVALID_COORDINATE;
@@ -529,20 +543,44 @@ void Card::algo_tdoa(int cnt)
 	this->time_stamp_last = this->time_stamp_cal;
 
 	int nCount = 0;
-	std::unique_ptr<POS> p = nullptr;
+	//std::unique_ptr<POS> p = nullptr;
+	std::shared_ptr<POS> p = nullptr;
 	std::unique_ptr<POS> p2 = nullptr;
 
 	bool bOutput = false;
 	this->z = 0;
 	i = 0;
 	
-	if(pTdoaReaderPathMap->size() > 0 && pRdm->size() > 1){
+	if(pRdm->size() > 1){
 		LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_147);
 		this->m_nCalcSyncNum = maxSyncTimes;
-		p = LocateAlgorithm::Pos(pRdm, pTdoaReaderPathMap);
-		p2 = LocateAlgorithm::CalcCardPosition(pRdm, pTdoaReaderPathMap);
+		//p = LocateAlgorithm::Pos(pRdm, pTdoaReaderPathMap);
+		//p2 = LocateAlgorithm::CalcCardPosition(pRdm, pTdoaReaderPathMap);
+
+		//std::shared_ptr<POS> p3 = LocateAlgorithm::Pos(pRdm);
+		p = LocateAlgorithm::Pos(pRdm);
+		if (p==nullptr)
+		{
+			p = std::make_shared<POS>();
+			p->posx = INVALID_COORDINATE;
+			p->posy = INVALID_COORDINATE;
+			p->posz = INVALID_COORDINATE;
+		}else{
+			debug_print_syslog(0, "CalcCardPosition cardid position by 3D, cx: %f, cy: %f, cz: %f",
+				p->posx, p->posy, p->posz);
+		}
 
-		double pos_diff = sqrt(pow(p->posx - p2->posx, 2) + pow(p->posy - p2->posy, 2));
+		/*if (p3!=nullptr)
+		{
+			debug_print_syslog(0, "CalcCardPosition cardid position by 3D, cx: %f, cy: %f, cz: %f",
+				p3->posx, p3->posy, p3->posz);
+
+			p->posx = p3->posx;
+			p->posy = p3->posy;
+			p->posz = p3->posz;
+		}*/
+		
+		/*double pos_diff = sqrt(pow(p->posx - p2->posx, 2) + pow(p->posy - p2->posy, 2));
 
 		if(pos_diff > 1)
 		{
@@ -550,7 +588,7 @@ void Card::algo_tdoa(int cnt)
 				p->posx, p->posy);
 		    debug_print_syslog(0, "CalcCardPosition cardid position error, cx: %f, cy: %f",
 				p2->posx, p2->posy);
-		}
+		}*/
 		
 		this->origin_locate.x = p->posx / (this->map_scale*1.0);
 		this->origin_locate.y = p->posy / (this->map_scale*1.0);
@@ -674,6 +712,7 @@ void Card::algo_tdoa(int cnt)
 							this->x = this->last_locate.x;
 							this->y = this->last_locate.y;
 							this->b_long_interval = false;
+							pRdm->clear();
 
 							m_afmData.bStatus = true;
 							m_afmData.strCardId = this->card_id;
@@ -690,6 +729,7 @@ void Card::algo_tdoa(int cnt)
 							this->x = this->last_locate.x;
 							this->y = this->last_locate.y;
 							this->b_long_interval = false;
+							pRdm->clear();
 
 							m_afmData.bStatus = true;
 							m_afmData.strCardId = this->card_id;
@@ -781,6 +821,7 @@ void Card::algo_tdoa(int cnt)
 							LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_169);
 							this->x = this->last_locate.x;
 							this->y = this->last_locate.y;
+							pRdm->clear();
 
 							m_afmData.bStatus = true;
 							m_afmData.strCardId = this->card_id;
@@ -796,6 +837,7 @@ void Card::algo_tdoa(int cnt)
 							//保留上次结果
 							this->x = this->last_locate.x;
 							this->y = this->last_locate.y;
+							pRdm->clear();
 
 							m_afmData.bStatus = true;
 							m_afmData.strCardId = this->card_id;
@@ -815,6 +857,7 @@ void Card::algo_tdoa(int cnt)
 						LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_173);
 						this->x = this->last_locate.x;
 						this->y = this->last_locate.y;
+						pRdm->clear();
 
 						m_afmData.bStatus = true;
 						m_afmData.strCardId = this->card_id;
@@ -984,6 +1027,7 @@ void Card::algo_tdoa(int cnt)
 						this->x = this->last_locate.x;
 						this->y = this->last_locate.y;
 						this->z = 0;
+						pRdm->clear();
 
 						m_afmData.bStatus = true;
 						m_afmData.strCardId = this->card_id;
@@ -1055,19 +1099,20 @@ void Card::algo_tdoa(int cnt)
 				kalman_p->posy = this->m_pKalmanFilter->m_pCar->x(2,0);//* this->map_scale
 				kalman_p->pos_radius = p->pos_radius;
 
-				if(!LocateAlgorithm::IsOnMap(kalman_p,pTdoaReaderPathMap)){
-					//再一次定位到地图集上
-					LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_205);
-					std::shared_ptr<POS> cp = LocateAlgorithm::Pos(kalman_p,pTdoaReaderPathMap);
+				//二维定位不需要再判定在地图集上了
+				//if(!LocateAlgorithm::IsOnMap(kalman_p,pTdoaReaderPathMap)){
+				//	//再一次定位到地图集上
+				//	LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_205);
+				//	std::shared_ptr<POS> cp = LocateAlgorithm::Pos(kalman_p,pTdoaReaderPathMap);
 
-					if(cp != nullptr){
-						LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_206);
-						this->m_pKalmanFilter->m_pCar->x(0,0) = cp->posx;
-						this->m_pKalmanFilter->m_pCar->x(2,0) = cp->posy;
-					}
+				//	if(cp != nullptr){
+				//		LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_206);
+				//		this->m_pKalmanFilter->m_pCar->x(0,0) = cp->posx;
+				//		this->m_pKalmanFilter->m_pCar->x(2,0) = cp->posy;
+				//	}
 
-					cp.reset();
-				}		
+				//	cp.reset();
+				//}		
 
 				this->x = this->m_pKalmanFilter->m_pCar->x(0,0) / this->map_scale;
 				this->y = this->m_pKalmanFilter->m_pCar->x(2,0) / this->map_scale;
@@ -1307,6 +1352,107 @@ void Card::algo_tdoa(int cnt)
 	pRdm->clear();
 }
 
+int Card::algo_tdoa_3d(int cnt)
+{
+	if (cnt < 3)
+	{
+		return 1;
+	}
+
+	int sync_num = 0;
+	int k = 0;
+	bool ret = false;
+
+	mp_dists_locate.clear();
+
+	for (DistMap::iterator it = _dists.front().distmap.begin();it!=_dists.front().distmap.end();++it,k++)
+	{
+		if (k==0)
+		{
+			sync_num = it->second->sync_num;
+		} 
+		else
+		{
+			int diff = abs(sync_num - it->second->sync_num);
+			if (diff >= 5)
+			{
+				ret = true;
+				break;
+			}
+		}
+		if (it->second->tt == LLONG_MAX)
+		{
+			ret = true;
+			break;
+		}
+		mp_dists_locate.insert(make_pair(it->second->tt,it->second));
+	}
+
+	if (ret)
+	{
+		return 1;
+	}
+
+	//构造数据
+	int i = 0;
+	int max_sync_time = 0;
+
+	std::shared_ptr<ReceiveDataMap> pRdm = std::make_shared<ReceiveDataMap>();
+	pRdm->clear();
+
+	for (map<unsigned long long ,std::shared_ptr<_coordinate>>::iterator it = mp_dists_locate.begin();it!=mp_dists_locate.end();++it)
+	{
+		int card_time_stamp = 0;
+
+		if (i==0)
+		{
+			max_sync_time = it->second->sync_num;
+			card_time_stamp = it->second->t;
+		}else{
+			if (max_sync_time < it->second->sync_num)
+			{
+				max_sync_time = it->second->sync_num;
+				card_time_stamp = it->second->t;
+			}
+		}
+
+		ReceiveDataMap::iterator rdm_it = pRdm->find(it->second->tt);
+		if (rdm_it == pRdm->end())
+		{
+			//保存信息用于定位
+			std::shared_ptr<ReceiveData> prd = std::make_shared<ReceiveData>();
+			prd->reader_id = it->second->reader_id;
+			prd->antenna_id = it->second->antenna_id;
+			prd->rec_time_stamp = it->second->tt;
+			prd->x = it->second->x*this->map_scale;
+			prd->y = it->second->y*this->map_scale;
+			prd->z = it->second->z*this->map_scale;
+			prd->special = it->second->special;
+			if (prd->rec_time_stamp > 0)
+			{
+				pRdm->insert(make_pair(prd->rec_time_stamp,prd));
+			}
+		}
+		i++;
+	}
+	
+	//if (time_stamp_last !=0 && time_stamp_last > time_stamp_cal)
+	//{
+	//	if ((time_stamp_last + time_stamp_cal)%65535 < 2)
+	//	{
+	//		return;
+	//	}
+	//}
+
+	if (pRdm->size() >2)
+	{
+		m_nCalcSyncNum = max_sync_time;
+		std::shared_ptr<POS> p = nullptr;
+		p = LocateAlgorithm::Pos(pRdm);
+	}
+	return 0;
+}
+
 /*
  * 根据算法计算新位置的坐标以及卡的上一次坐标,计算车辆偏移坐标
  *

+ 50 - 16
classdef.h

@@ -37,6 +37,9 @@
 #define ALGORITHM_TYPE_TDOA
 //#define ALGORITHM_TYPE_INS		//使用惯导判断
 
+//认证功能-分站识别区域
+#define CERTIFY_READER_RANGE_AREA
+
 //滤波功能开启
 //#define FILTER_KALMAN
 
@@ -71,7 +74,7 @@ const double INVALID_COORDINATE = -1000.0;
 const double CHAMBER_WIDTH = 10.0;		//特指前端展现巷道的宽度,单位为像素
 const double VEHICLE_WIDTH = 10.0;
 const int MAX_READER_TDOA_PATH_NUMS = 10;	//主要是因为拐弯处可能存在多解的原因
-const int LIGHT_CTRL_DELAY = 1000;
+const int LIGHT_CTRL_DELAY = 2000;
 
 enum ALARM_FLAG{
 	//AF_CARD_OVER_COUNT = 1,
@@ -204,18 +207,6 @@ enum LIGHTS_SELECT_TYPE
 	LST_SOME_LIGHTS = 3 // 指定灯
 };
 
-enum LIGHT_SHAPE{
-	RED_CIRCLE_SOLID = 1,	//红色实心圆
-	RED_CIRCLE = 2,			//红色空心圆
-	RED_CROSS = 3,			//红色叉形
-	GREEN_UP = 4,			//绿色上箭头
-	GREEN_DOWN = 5,			//绿色下箭头
-	GREEN_LEFT = 6,			//绿色左箭头
-	GREEN_RIGHT = 7,		//绿色右箭头
-	RED_SPARK = 8,			//红色闪烁
-	GREEN_SPARK = 9			//绿色闪烁
-};
-
 enum AREA_PROPERTY{
 	MAIN_TUNNEL = 0, // 主巷道
 	BRANCH_TUNNEL = 1, // 分支巷道
@@ -294,6 +285,14 @@ enum DEVICE_TYPE{
 	DT_LED = 6 // 显示屏
 };
 
+enum CALL_STATE{
+	CALL_NONE = 0,			//无呼叫信息
+	CALL_SUCCESSED = 1,		//呼叫成功
+	CALL_ING = 2,			//呼叫中
+	CALL_FAILED = 3,		//呼叫失败
+	
+};
+
 struct SQLTHREAD_DATA//写数据库线程传递的参数
 {
 	char* pText;//数据库语句地址指针
@@ -372,6 +371,10 @@ struct _point{ // 
 	double x;
 	double y;
 	double z;
+
+	_point(){
+		x = y = z =0;
+	}
 };
 
 struct sync_data{
@@ -413,7 +416,8 @@ struct _call_info_card
 	string str_card_id;
 	time_t start_time;
 	int time_out;
-	bool is_success;
+	//bool is_success;
+	int call_state;
 };
 //typedef map<std::string, _call_info_card*> CallInfoCardMap;
 typedef map<std::string, std::shared_ptr<_call_info_card>> CallInfoCardMap;
@@ -427,6 +431,7 @@ struct _call_info_reader
 	CallInfoCardMap mpCard;
 };
 typedef map<int, std::shared_ptr<_call_info_reader>> CallInfoReaderMap;
+
 struct _call_info_user
 {
 	std::string user_name;
@@ -840,6 +845,7 @@ public:
 	int map_id_old; // 上次测距所在地图
 	int area_id; // 当前区域	
 	int reader_id; // 当前分站
+
 	Reader* p_reader;
 	std::shared_ptr<ReaderPathMap> pReaderPathMap;
 	std::shared_ptr<TDOAReaderPathMap> pTdoaReaderPathMap;
@@ -914,6 +920,7 @@ public:
 	void inspect_coordinate(int acce_state);
 	void algo_tof(int cnt);
 	void algo_tdoa(int cnt);
+	int algo_tdoa_3d(int cnt);
 
 	void algo_calc_offset();		//计算偏移坐标
 	bool algo_is_same_direction(double x,double y,double z);	//检查此次方向
@@ -977,6 +984,19 @@ public: // 
 
 	string str_his_time;
 	string str_rec_time;
+
+	//呼叫信息
+	int call_type;
+	std::vector<int> vt_deal_call_reader_id;
+	time_t recv_call_time;	//卡接收到呼叫的时间戳
+
+#ifdef CERTIFY_READER_RANGE_AREA
+	int reader_area_id;
+	int cur_reader_area;	//卡当前所处的分站识别区域
+	int old_reader_area;	//卡原来所处的分站识别区域
+	SYSTEMTIME enter_reader_area_time;	//进入分站识别区域时间
+	SYSTEMTIME deal_reader_time;
+#endif
 };
 
 class Dept
@@ -1238,6 +1258,19 @@ enum EVENT_TYPE{ // 
 	ET_CARD_LOST = 27, // 标识卡信号丢失
 };
 
+enum REQUEST_COUNTS_TYPE{
+	REQUEST_ALL = 0,
+	REQUEST_ALL_OVER_TIME_PERSON,
+	REQUEST_AREA_OVER_TIME_PERSON,
+	REQUEST_SPECIAL_ERROR_PERSON,
+	REQUEST_ALL_OVER_TIME_VEHICLE,
+	REQUEST_AREA_OVER_TIME_VEHICLE,
+	REQUEST_ALL_OVER_PERSON,
+	REQUEST_AREA_OVER_PERSON,
+	REQUEST_ALL_OVER_VEHICLE,
+	REQUEST_AREA_OVER_VEHICLE
+};
+
 enum OBJECT_TYPE // 对象类型
 {
 	OT_MINE = 1, // 矿井
@@ -1275,6 +1308,7 @@ public:
 		limit_value = 0;
 		cur_value = 0;
 		desc = "";
+		is_count = false;
 	};
 	~YaEvent(){};
 public:
@@ -1293,8 +1327,8 @@ public:
 	double cur_value;
 	std::string desc;
 	
-	bool is_sent; // 已发送
-
+	bool is_sent;	// 已发送
+	bool is_count;	// 已统计,用于增量统计
 	INT64 get_id(){return ev_id;};
 };
 

+ 17 - 3
constdef.h

@@ -22,7 +22,6 @@
 #define JSON_CMD_VALUE_SET_LIMIT_VALUE "set_limit_value"
 #define JSON_CMD_VALUE_CALL_CARD "call_card"
 #define JSON_CMD_VALUE_CLEAR_CARD "clear_card"
-#define JSON_CMD_VALUE_CALL_CARD_LIST "callcardlist"
 #define JSON_CMD_VALUE_DEAL_HELP "helpme_done"   //deal_help
 #define JSON_CMD_VALUE_EDIT_MAP "edit_map"
 #define JSON_CMD_VALUE_EDIT_AREA "edit_area"
@@ -34,8 +33,12 @@
 #define JSON_CMD_VALUE_REQUEST_ALL_POSTION "request_all_postion"
 #define JSON_CMD_VALUE_SET_LIGHT_COLOR "set_light_color"
 
-#define JSON_CMD_VALUE_CALL_CARD_START "call_card_start"
-#define JSON_CMD_VALUE_CALL_CARD_CANCEL "call_card_cancel"
+//呼叫命令
+#define JSON_CMD_VALUE_CALL_CARD_REQUEST "call_card_req"
+#define JSON_CMD_VALUE_CALL_CARD_RESPONSE "call_card_resp"
+#define JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST "call_card_cancel_req"
+#define JSON_CMD_VALUE_CALL_CARD_CANCEL_RESPONSE "call_card_cancel_resp"
+#define JSON_CMD_VALUE_CALL_CARD_LIST "callcardlist"
 
 #define JSON_CMD_VALUE_META_DATA_CHANGED "meta_data_changed"
 #define JSON_CMD_VALUE_LIGHTS_CTRL_REQUEST "lights_ctrl_req"
@@ -203,6 +206,13 @@
 #define JSON_KEY_COUNTING_DEPT_COUNT_TOTAL "total"
 #define JSON_KEY_COUNTING_DEPT_COUNT_VEHICLE "vehicle"
 #define JSON_KEY_COUNTING_DEPT_COUNT_PERSON "staff"
+#define JSON_KEY_COUNTING_SPECIAL_ERROR_TOTAL "special_error_total"
+#define JSON_KEY_REQ_COUNTS_USER "req_user"
+#define JSON_KEY_REQ_COUNTS_TYPE "count_type"
+#define JSON_KEY_REQ_COUNTS_TIME "req_time"
+
+#define JSON_CMD_VALUE_REQUEST_COUNTS_INFO "count_detail_req"		//web端请求统计总数详细列表
+#define JSON_KEY_RESPONSE_COUNTS_DETAIL "count_detail_resp"
 
 #define JSON_KEY_EVENT_EVENT_ID "event_id"
 #define JSON_KEY_EVENT_STATUS "status"
@@ -224,6 +234,10 @@
 #define JSON_KEY_ALARM_OVER_TIME_VEHICLE "over_time_vehicle"
 #define JSON_KEY_ALARM_OVER_SPEED_VEHICLE "over_speed_vehicle"
 #define JSON_KEY_ALARM_AREA_FORBIDDEN "area_forbidden"
+#define JSON_KEY_ALARM_AREA_OVER_TIME_PERSON "area_over_time_person"
+#define JSON_KEY_ALARM_AREA_OVER_TIME_VEHICLE "area_over_time_vehicle"
+#define JSON_KEY_ALARM_AREA_OVER_PERSON "area_over_person"
+#define JSON_KEY_ALARM_AREA_OVER_VEHICLE "area_over_vehicle"
 
 #define JSON_KEY_ALARM_GLOBAL "global"
 #define JSON_KEY_ALARM_ITEM "item"

+ 1 - 1
def.h

@@ -67,7 +67,7 @@
 #define CONF_SECT_READER "READER_SET"
 #define CONF_READER_INTERVAL_TIME "interval_time"
 
-#define SQL_EXECUTE_SENTENCE_COUNT_MAX       50	//50
+#define SQL_EXECUTE_SENTENCE_COUNT_MAX       10	//50
 
 #define SQL_SENTENCE_LENGTH_MAX       8000
 

+ 326 - 0
locate_algorithm.cpp

@@ -580,6 +580,299 @@ POS* LocateAlgorithm::Pos(ReaderPathMap rpm,int sta_num,int ant,double dist,INFO
 	return p;
 }
 
+std::shared_ptr<POS> LocateAlgorithm::Pos(std::shared_ptr<ReceiveDataMap> pRdm)
+{
+	if (pRdm->size() < 3)
+	{
+		return nullptr;
+	}
+	std::shared_ptr<POS> p = std::make_shared<POS>();
+
+	//2D定位
+	std::vector<double> vtk;		//保存ki
+	std::vector<double> vtd;		//保存di
+	std::vector<_coordinate> vtc;	//保存xi,1  yi,1
+	std::vector<_point> vtp;	//保存三角形的顶点坐标
+	std::vector<int> vts;
+	
+	vtk.resize(0);
+	vtd.resize(0);
+	vtc.resize(0);
+	vts.resize(0);
+
+	_coordinate tc;
+	
+	int i = 0;
+	unsigned long long time_stamp = 0;	//保存第一次的插值时间戳
+	for (ReceiveDataMap::iterator it = pRdm->begin();it != pRdm->end()&&i<3;++it)
+	{
+		double k =  0 ;
+		k = pow(it->second->x,2) + pow(it->second->y,2) ;//+ pow(it->second->z,2)
+		vtk.push_back(k);
+
+		if (i == 0 )
+		{
+			time_stamp = it->second->rec_time_stamp;
+			tc.x = it->second->x;
+			tc.y = it->second->y;
+			//tc.z = it->second->z;
+		}
+		long long diff_time = it->second->rec_time_stamp - time_stamp;
+		double d = 0;
+		d = CFunctions::getDistance(diff_time,CFunctions::TDOA);
+		if (i>0)
+		{
+			if (d>0)
+			{
+				vts.push_back(1);
+			} 
+			else
+			{
+				vts.push_back(-1);
+			}
+		}
+		
+		vtd.push_back(d);
+
+		_coordinate dtc;
+		dtc.x = it->second->x - tc.x;
+		dtc.y = it->second->y - tc.y;
+		//dtc.z = it->second->z - tc.z;
+		vtc.push_back(dtc);
+
+		_point p;
+		p.x = it->second->x;
+		p.y = it->second->y;
+		vtp.push_back(p);
+		i++;
+	}
+
+	double a[20] = {0};
+	double dt = 0;
+
+	dt = vtd[1]*vtc[2].y - vtd[2]*vtc[1].y;
+	if (fabs(dt) < 1E-5)
+	{
+		return nullptr;
+	}
+	a[0] = (vtd[2]*vtc[1].x - vtd[1]*vtc[2].x)/dt;
+	a[1] = (-1)*((vtk[1] - vtk[0] - pow(vtd[1],2))*vtd[2] - (vtk[2] - vtk[0] - pow(vtd[2],2))*vtd[1])*0.5/dt;
+
+	if (fabs(vtd[1]) < 1E-5)
+	{
+		return nullptr;
+	}
+	a[2] = 0.5*(vtk[1] - vtk[0] - pow(vtd[1],2) - 2*vtc[1].y*a[1])/vtd[1];
+	a[3] = -1*(vtc[1].x + vtc[1].y*a[0])/vtd[1];
+
+	double A = 0, B = 0, C = 0;
+	A = pow(a[3],2) - 1 - pow(a[0],2);
+	B = 2*(a[2]*a[3] + tc.x + a[0]*(tc.y - a[1]));
+	C = pow(a[2],2) - pow(tc.x,2) - pow(tc.y-a[1],2);
+
+	_point pos[MAX_READER_TDOA_PATH_NUMS];
+	double delta = 0.0;
+	int count = 0;
+
+	delta = pow(B,2) - 4*A*C;
+	if (delta > 0)
+	{
+		pos[0].x = ((-1)*B + sqrt(delta))/(2*A);
+		pos[0].y = a[0]*pos[0].x + a[1];
+		//TRACE(_T("x1: %.2f , y1: %.2f \r\n"),pos[0].x,pos[0].y);
+		pos[1].x = ((-1)*B - sqrt(delta))/(2*A);
+		pos[1].y = a[0]*pos[1].x + a[1];
+		//TRACE(_T("x2: %.2f , y2: %.2f \r\n"),pos[1].x,pos[1].y);
+		count  = 2;
+	}else{
+		return nullptr;
+	}
+
+	int idx = -1;
+	int points = 0;
+	for (int i=0;i<count;i++)
+	{
+		if (IsInTriangle(vtp,pos[i]))
+		{
+			//TRACE(_T("point is in triangle. the index is : %d \r\n"),i);
+			bool condition[2] = {false,false};
+			double d1 = 0,d2 = 0;
+
+			//对两解进行判断,需要同时满足两个条件
+			//1.解到点1和点2的距离差的方向性和之前的参数相同
+			//2.解到点1和点3的距离差的方向性和之前的参数相同
+			d1 = sqrt(pow(vtp[1].x - pos[i].x,2) + pow(vtp[1].y - pos[i].y,2)) - sqrt(pow(vtp[0].x - pos[i].x,2) + pow(vtp[0].y - pos[i].y,2));
+			d2 = sqrt(pow(vtp[2].x - pos[i].x,2) + pow(vtp[2].y - pos[i].y,2)) - sqrt(pow(vtp[0].x - pos[i].x,2) + pow(vtp[0].y - pos[i].y,2));
+			
+			if ((d1<0&&vts[0]==-1)||(d1>0&&vts[0] == 1))
+			{
+				condition[0] = true;
+			}
+			if ((d2<0&&vts[1]==-1)||(d2>0&&vts[1] == 1))
+			{
+				condition[1] =true;
+			}
+
+			if (condition[0]&&condition[1])
+			{
+				idx = i;
+			}
+
+			//idx = i;	
+		}else{
+			//TRACE(_T("point is not in triangle. the index is : %d \r\n"),i);
+		}
+	}
+
+	if (points == 2)
+	{
+		idx = -1;
+		//TRACE(_T("There hava 2 point.\r\n"));
+	}
+
+	if (idx != -1)
+	{
+		//TRACE(_T("the idx is : %d \r\n"),idx);
+		p->posx = pos[idx].x;
+		p->posy = pos[idx].y;
+	}else{
+		return nullptr;
+	}
+
+	//算法一
+	//ReceiveDataMap::iterator first = pRdm->begin();
+
+	////////解
+	//Eigen::VectorXd x(3);
+	////需要设置初始坐标
+	//x[0] = 43;	//500,500,100	//4300,200,90
+	//x[1] = 2;
+	//x[2] = 0.9;
+
+	//Eigen::MatrixXd data(3,4),pos(1,3);
+
+	//pos(0,0) = first->second->x;
+	//pos(0,1) = first->second->y;
+	//pos(0,2) = first->second->z;
+
+	//int i = 0;
+	//ReceiveDataMap::iterator it = pRdm->begin();
+	//it++;
+	//for (;it!=pRdm->end();++it)
+	//{
+	//	data(i,0) = it->second->x;
+	//	data(i,1) = it->second->y;
+	//	data(i,2) = it->second->z;
+
+	//	data(i,3) = (it->second->rec_time_stamp - first->second->rec_time_stamp) * 15.65 * 2.99702547*0.0001;	//0.01
+	//	i++;
+	//}
+
+	//TdoaAlgo::TDOAFunctor functor(data,pos);
+	//Eigen::NumericalDiff<TdoaAlgo::TDOAFunctor> num_diff(functor);
+	//Eigen::LevenbergMarquardt<Eigen::NumericalDiff<TdoaAlgo::TDOAFunctor>,double> lm(num_diff);
+	//lm.parameters.maxfev = 2000;
+	//lm.parameters.xtol = 1.0e-10;
+
+	//int ret = lm.minimize(x);
+	//if (ret > 0)
+	//{
+	//	p->posx = x[0];
+	//	p->posy = x[1];
+	//	p->posz = x[2];
+	//	TRACE(_T("x: %.2f , y: %.2f , z: %.2f"),p->posx,p->posy,p->posz);
+	//}
+
+	//算法二
+	//std::vector<double> vtk;
+	//std::vector<double> vtd;
+	//vtk.resize(0);
+	//vtd.resize(0);
+
+	//_coordinate tc;
+	//std::vector<_coordinate> vtc;
+	//vtc.resize(0);
+
+	//int i = 0;
+	//unsigned long long time_stamp = 0;	//保存第一次的插值时间戳
+	//for (ReceiveDataMap::iterator it = pRdm->begin();it != pRdm->end();++it)
+	//{
+	//	double k =  0 ;
+	//	k = pow(it->second->x,2) + pow(it->second->y,2) + pow(it->second->z,2);
+	//	vtk.push_back(k);
+
+	//	if (i == 0 )
+	//	{
+	//		time_stamp = it->second->rec_time_stamp;
+	//		tc.x = it->second->x;
+	//		tc.y = it->second->y;
+	//		tc.z = it->second->z;
+	//	}
+	//	long long diff_time = it->second->rec_time_stamp - time_stamp;
+	//	double d = 0;
+	//	d = CFunctions::getDistance(diff_time,CFunctions::TDOA);
+	//	vtd.push_back(d);
+
+	//	_coordinate dtc;
+	//	dtc.x = it->second->x - tc.x;
+	//	dtc.y = it->second->y - tc.y;
+	//	dtc.z = it->second->z - tc.z;
+	//	vtc.push_back(dtc);
+	//	i++;
+	//}
+
+	//double a[20] = {0};
+
+	//a[0] = vtk[1] - pow(vtd[1],2) - vtk[0];
+	//a[1] = vtk[2] - pow(vtd[2],2) - vtk[0];
+	//a[2] = vtk[3] - pow(vtd[3],2) - vtk[0];
+	//double dt = vtc[2].y*vtd[1] - vtc[1].y*vtd[2];
+	//if (fabs(dt) < 1E-5)
+	//{
+	//	return nullptr;
+	//}
+	//a[3] = (vtc[1].x*vtd[2] - vtc[2].x*vtd[1])/dt;
+	//a[4] = (vtc[1].z*vtd[2] - vtc[2].z*vtd[1])/dt;
+	//a[5] = 0.5*(a[1]*vtd[1] - a[0]*vtd[2])/dt;
+	//
+	//dt = vtc[3].y*vtd[2] - vtc[2].y*vtd[3];
+	//if (fabs(dt) < 1E-5)
+	//{
+	//	return nullptr;
+	//}
+	//a[6] = (vtc[2].x*vtd[3] - vtc[3].x*vtd[2])/dt;
+	//a[7] = (vtc[2].z*vtd[3] - vtc[3].z*vtd[2])/dt;
+	//a[8] = 0.5*(a[2]*vtd[2] - a[1]*vtd[3])/dt;
+	//a[9] = (a[3] - a[6])/(a[7] - a[4]);
+	//a[10] = (a[5] - a[8])/(a[7] - a[4]);
+	//a[11] = a[7] + a[8]*a[10];
+	//a[12] = a[7]*a[10];
+	//a[13] = (-1)*(vtc[1].x/vtd[1] + vtc[1].y*a[11]/vtd[1] + vtc[1].z*a[9]/vtd[1]);
+	//a[14] = 0.5*a[0]/vtd[1] - vtc[1].y*a[12]/vtd[1] - vtc[1].z*a[10]/vtd[1];
+	//
+	//double A = 0, B = 0, C = 0;
+	//A = 1 + pow(a[11],2) + pow(a[9],2) - pow(a[13],2);
+	//B = (-2)*(tc.x + a[11]*(tc.y - a[12]) + a[9]*(tc.z - a[10]) + a[13]*a[14]);
+	//C = pow(tc.x,2) + pow(tc.y - a[12],2) + pow(tc.z - a[10],2) - pow(a[14],2);
+
+	//double x1 = 0,x2 = 0,y1 = 0, y2 = 0, z1 = 0, z2 = 0;
+	//double delta = 0;
+	//delta = pow(B,2) - 4*A*C;
+	//if (delta > 0)
+	//{
+	//	x1 = ((-1)*B + sqrt(delta))/(2*A);
+	//	y1 = a[11]*x1 + a[12];
+	//	z1 = a[9]*x1 + a[10];
+	//	x2 = ((-1)*B - sqrt(delta))/(2*A);
+	//	y2 = a[11]*x2 + a[12];
+	//	z2 = a[9]*x2 + a[10];
+	//}else{
+	//	return nullptr;
+	//}
+
+	return p;
+}
+
 SOLUTION* LocateAlgorithm::GetPos(ReaderPathMap rpm,int sta_num,int ant,double dist,int i)
 {
 	double x1 = 0.0;
@@ -1418,6 +1711,39 @@ bool LocateAlgorithm::IsOnMap(std::shared_ptr<POS> pos,std::shared_ptr<TDOAReade
 	return true;
 }
 
+double LocateAlgorithm::GetTriangleArea(_point p0,_point p1,_point p2)
+{
+	_point ab,bc;
+
+	ab.x = p1.x - p0.x;
+	ab.y = p1.y - p0.y;
+
+	bc.x = p2.x - p1.x;
+	bc.y = p2.y - p1.y;
+
+	return abs(ab.x*bc.y - ab.y*bc.x)/2.0;
+}
+
+bool LocateAlgorithm::IsInTriangle(std::vector<_point> vtp,_point p)
+{
+	double sabc = 0,sadb = 0,sbdc = 0,sadc = 0;
+	sabc = GetTriangleArea(vtp[0],vtp[1],vtp[2]);
+	sadb = GetTriangleArea(vtp[0],p,vtp[1]);
+	sbdc = GetTriangleArea(vtp[1],p,vtp[2]);
+	sadc = GetTriangleArea(vtp[0],p,vtp[2]);
+
+	double sum = 0.0;
+	sum = sadb + sbdc + sadc;
+	if ((sabc - sum) > -1E-5 && (sabc - sum) < 1E-5)
+	{
+		return true;
+	} 
+	else
+	{
+		return false;
+	}
+}
+
 bool LocateAlgorithm::CheckPosInValid(POS* pos,ReceiveDataMap* pRdm,double dScale)
 {
 	if(dScale <= 0.0){

+ 4 - 0
locate_algorithm.h

@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "classdef.h"
+#include "tdoa/TDOAFunctor.h"
 
 #define M_PI       3.14159265358979323846 // 角度转弧度 角度 * pi / 180
 #define M_PI_2     1.57079632679489661923
@@ -44,11 +45,14 @@ public:
 	//TDOA算法函数
 	static std::unique_ptr<POS> Pos(std::shared_ptr<ReceiveDataMap> pRdm,std::shared_ptr<TDOAReaderPathMap> trpm);
 	static std::shared_ptr<POS> Pos(std::shared_ptr<POS> pos,std::shared_ptr<TDOAReaderPathMap> trpm);
+	static std::shared_ptr<POS> Pos(std::shared_ptr<ReceiveDataMap> pRdm);
 
 	static std::unique_ptr<POS> CalcCardPosition(std::shared_ptr<ReceiveDataMap> pRdm,std::shared_ptr<TDOAReaderPathMap> trpm);
 	static std::unique_ptr<SOLUTION> GetPos(std::shared_ptr<ReaderPath> pRP,double dist,int i);
 	static bool CheckPosInValid(POS* pos,ReceiveDataMap* pRdm,double dScale);
 	static bool IsOnMap(std::shared_ptr<POS> pos,std::shared_ptr<TDOAReaderPathMap> trpm);
+	static double GetTriangleArea(_point p0,_point p1,_point p2);
+	static bool IsInTriangle(std::vector<_point> vtp,_point p);
 };
 
 #endif

+ 47 - 0
tdoa/TDOAFunctor.h

@@ -0,0 +1,47 @@
+#pragma once
+#include <Eigen/Dense>
+#include <unsupported/Eigen/NonLinearOptimization>
+#include <unsupported/Eigen/NumericalDiff>
+
+namespace TdoaAlgo{
+    template<typename _Scalar, int NX = Eigen::Dynamic, int NY = Eigen::Dynamic>
+    class Functor
+    {
+    private:
+        int m_inputs, m_values;
+    public:
+        typedef _Scalar Scalar;
+        enum {
+            InputsAtCompileTime = NX,
+            ValuesAtCompileTime = NY
+        };
+        typedef Eigen::Matrix<Scalar,InputsAtCompileTime,1> InputType;
+        typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,1> ValueType;
+        typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime> JacobianType;
+
+        Functor() : m_inputs(InputsAtCompileTime), m_values(ValuesAtCompileTime) {}
+        Functor(int inputs, int values) : m_inputs(inputs), m_values(values) {}
+
+        int inputs() const { return m_inputs; }
+        int values() const { return m_values; }
+
+    };
+
+    class TDOAFunctor : public Functor<double>
+    {
+    private:
+        Eigen::MatrixXd _data, _pos;
+    public:
+        TDOAFunctor(const Eigen::MatrixXd &data,const Eigen::MatrixXd &pos): Functor<double>(3,3),_data(data),_pos(pos) {}
+        int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
+        {
+            for (int i = 0; i < values(); i++)
+            {
+                fvec(i) = sqrt(pow(_data(i,0) - x(0),2) + pow(_data(i,1) - x(1),2) + pow(_data(i,2) - x(2),2)) 
+                        - sqrt(pow(_pos(0) - x(0),2) + pow(_pos(1) - x(1),2) + pow(_pos(2) - x(2),2)) 
+                        - _data(i,3);
+            }
+            return 0;
+        }
+    };
+}