Browse Source

fix algo bug

researchman 8 years ago
parent
commit
9025848fd1
6 changed files with 50 additions and 83 deletions
  1. 2 7
      MysqlConnPool.cpp
  2. 1 0
      MysqlConnPool.h
  3. 37 29
      YAServerDlg.cpp
  4. 8 5
      classdef.cpp
  5. 2 1
      classdef.h
  6. 0 41
      locate_algorithm.cpp

+ 2 - 7
MysqlConnPool.cpp

@@ -218,6 +218,7 @@ DWORD WINAPI CMysqlConnPool::thread_run( LPVOID pdata )
 			pConPool->InitNewConn();
 		}
 	}
+	
 	return 0;
 }
 
@@ -267,6 +268,7 @@ int CMysqlConn::Open()
 	HRESULT hr = ::CoInitialize(NULL);
 	if(FAILED(hr))
 		return -1;
+	//mysql_options(m_pConn, MYSQL_OPT_RECONNECT, m_option);
 	m_clientflag |=  CLIENT_MULTI_STATEMENTS;
 	if(!mysql_real_connect(m_pConn, m_host, m_user, m_pwd, m_db, m_port, m_unix_socket, m_clientflag))
 		return 1;
@@ -320,11 +322,4 @@ void CMysqlConn::MultiExecute( const char * strSQL, int &err)
 		pRes = mysql_use_result(m_pConn);
 		mysql_free_result(pRes);
 	} while (!mysql_next_result(m_pConn));
-
-	/*if (_error != 0)
-	{
-		CString str = _T("");
-		str = mysql_error(m_pConn);
-		TRACE(str);
-	}*/
 }

+ 1 - 0
MysqlConnPool.h

@@ -125,6 +125,7 @@ class CDBConnGuard{
 public:
 	CDBConnGuard(CMysqlConn* &pDbConn){
 		pDbConn = CMysqlConnPool::Instanse().GetNewConn();
+		//ÅжÏÁ¬½ÓµÄÓÐЧÐÔ
 		m_pDbConn = pDbConn;
 	}
 	virtual ~CDBConnGuard()

+ 37 - 29
YAServerDlg.cpp

@@ -6678,53 +6678,61 @@ void CYAServerDlg::Test()
 
 	//34
 	ReceiveData* prd2 = new ReceiveData();	
-	prd2->reader_id = 207;
+	prd2->reader_id = 209;
 	prd2->antenna_id = 1;
-	prd2->rec_time_stamp = 604176860373;
-	prd2->x = 578.7*dMapScale;
+	prd2->rec_time_stamp = 94885846535;
+	prd2->x = 512.36*dMapScale;
 	prd2->y = 341*dMapScale;
 	prd2->z = 0;
 	prd2->special = 0;
-	pRdm.insert(ReceiveDataMap::value_type(prd2->reader_id,*prd2));	
+	//pRdm.insert(ReceiveDataMap::value_type(prd2->reader_id,*prd2));	
+	pRdm[prd2->rec_time_stamp] = *prd2;
+
+	ReceiveData* prd1 = new ReceiveData();	
+	prd1->reader_id = 105;
+	prd1->antenna_id = 1;
+	prd1->rec_time_stamp = 94885870986;
+	prd1->x = 535.48*dMapScale;
+	prd1->y = 341.0*dMapScale;
+	prd1->z = 0;
+	prd1->special = 0;
+	//pRdm.insert(ReceiveDataMap::value_type(prd1->reader_id,*prd1));
+	pRdm[prd1->rec_time_stamp] = *prd1;
 
 	ReceiveData* prd3 = new ReceiveData();	
-	prd3->reader_id = 208;
+	prd3->reader_id = 210;
 	prd3->antenna_id = 1;
-	prd3->rec_time_stamp = 604176893106;
-	prd3->x = 547.34*dMapScale;
+	prd3->rec_time_stamp = 94885875667;
+	prd3->x = 479.62*dMapScale;
 	prd3->y = 341.0*dMapScale;
 	prd3->z = 0;
 	prd2->special = 0;
-	pRdm.insert(ReceiveDataMap::value_type(prd3->reader_id,*prd3));
+	//pRdm.insert(ReceiveDataMap::value_type(prd3->reader_id,*prd3));
+	pRdm[prd3->rec_time_stamp] = *prd3;
 
+	
 
-	ReceiveData* prd1 = new ReceiveData();	
-	prd1->reader_id = 206;
-	prd1->antenna_id = 1;
-	prd1->rec_time_stamp = 604176910940;
-	prd1->x = 627.92*dMapScale;
-	prd1->y = 341.0*dMapScale;
-	prd1->z = 0;
-	prd1->special = 0;
-	pRdm.insert(ReceiveDataMap::value_type(prd1->reader_id,*prd1));
+	
+	ReceiveData* prd5 = new ReceiveData();	
+	prd5->reader_id = 208;
+	prd5->antenna_id = 1;
+	prd5->rec_time_stamp = 94885882952;
+	prd5->x = 547.34*dMapScale;
+	prd5->y = 341.0*dMapScale;
+	prd5->z = 0;
+	//pRdm.insert(ReceiveDataMap::value_type(prd5->reader_id,*prd5));
+	pRdm[prd5->rec_time_stamp] = *prd5;
 
 	ReceiveData* prd4 = new ReceiveData();	
-	prd4->reader_id = 209;
+	prd4->reader_id = 211;
 	prd4->antenna_id = 1;
-	prd4->rec_time_stamp = 604176930074;
-	prd4->x = 512.36*dMapScale;
+	prd4->rec_time_stamp = 94885901369;
+	prd4->x = 455.38*dMapScale;
 	prd4->y = 341.0*dMapScale;
 	prd4->z = 0;
-	pRdm.insert(ReceiveDataMap::value_type(prd4->reader_id,*prd4));
+	//pRdm.insert(ReceiveDataMap::value_type(prd4->reader_id,*prd4));
+	pRdm[prd4->rec_time_stamp] = *prd4;
 
-	ReceiveData* prd5 = new ReceiveData();	
-	prd5->reader_id = 205;
-	prd5->antenna_id = 1;
-	prd5->rec_time_stamp = 604176974744;
-	prd5->x = 687.82*dMapScale;
-	prd5->y = 341.0*dMapScale;
-	prd5->z = 0;
-	pRdm.insert(ReceiveDataMap::value_type(prd5->reader_id,*prd5));
 
 	//ReceiveData* prd5 = new ReceiveData();	
 	//prd5->reader_id = 205;

+ 8 - 5
classdef.cpp

@@ -436,7 +436,8 @@ void Card::algo_tdoa(int cnt)
 				ins_direction = it_mpdl->second->ins_direction;
 			}
 		}
-		ReceiveDataMap::iterator prdm_it = pRdm.find(it_mpdl->second->reader_id);
+		//ReceiveDataMap::iterator prdm_it = pRdm.find(it_mpdl->second->reader_id);
+		ReceiveDataMap::iterator prdm_it = pRdm.find(it_mpdl->second->tt);
 		if(prdm_it == pRdm.end()){
 			if(it_mpdl->second->tt == LLONG_MAX ){
 				//如果同步时间戳存在异常值,则不走算法定位,直接返回上一次结果值
@@ -452,8 +453,10 @@ void Card::algo_tdoa(int cnt)
 			prd.y = it_mpdl->second->y*this->map_scale;
 			prd.z = it_mpdl->second->z*this->map_scale;
 			prd.special = it_mpdl->second->special;
-			pRdm[prd.reader_id] = prd;
-		}		
+			//pRdm[prd.reader_id] = prd;
+			pRdm[prd.rec_time_stamp] = prd;
+		}	
+		i++;
 	}
 	//for(int i=0;i<k;i++){
 	//	if(i==0){
@@ -1083,7 +1086,7 @@ bool Card::is_pos_state_changed( int nval )  // 
 
 void Card::add_dist(_coordinate* dist)
 {
-	//EnterCriticalSection(&m_csCard);
+	EnterCriticalSection(&m_csCard);
 	string s = concat(dist->reader_id, dist->antenna_id);
 	
 	int idx = FindDistMap(dist->t);
@@ -1109,7 +1112,7 @@ void Card::add_dist(_coordinate* dist)
 	}else{
 		this->b_pos_change = false;
 	}
-	//LeaveCriticalSection(&m_csCard);
+	LeaveCriticalSection(&m_csCard);
 }
 
 time_t Card::get_working_time()

+ 2 - 1
classdef.h

@@ -346,8 +346,9 @@ struct ReceiveData{
 	};
 };
 
-typedef unordered_map<int,ReceiveData> ReceiveDataMap;
+//typedef unordered_map<int,ReceiveData> ReceiveDataMap;
 //typedef unordered_map<int,ReceiveData*> ReceiveDataMap;
+typedef map<unsigned long long ,ReceiveData> ReceiveDataMap;
 
 struct INFO_PRE{
 	int t;

+ 0 - 41
locate_algorithm.cpp

@@ -863,8 +863,6 @@ POS* LocateAlgorithm::Pos(ReceiveDataMap* pRdm,TDOAReaderPathMap trpm)
 	int nDistReaders = 0;
 
 	ReceiveDataMap::iterator first = pRdm->begin();
-	//for(ReceiveDataMap::iterator first = pRdm->begin();first!=pRdm->end();++first){///11
-		//ReceiveDataMap::iterator second = pRdm->begin();
 	ReceiveDataMap::iterator second = first;
 	//偏移到第二个元素
 	std::advance(second,1);
@@ -1548,45 +1546,6 @@ bool LocateAlgorithm::CheckPosInValid(POS* pos,ReceiveDataMap* pRdm,double dScal
 		}	
 	}
 
-	//if(nSize >= 3){
-	//	//先找出未参与定位的分站
-	//	ReceiveDataMap::iterator f_it = pRdm->end();
-	//	ReceiveDataMap::iterator it = pRdm->begin();
-	//	int readers[2] = {0};
-	//	readers[0] = pos->nFirstReader;
-	//	readers[1] = pos->nSecondReader;
-
-	//	for(it;it!=pRdm->end();++it){
-	//		for(int i=0;i<2;i++){
-	//			if(it->first == readers[i]){
-	//				f_it = pRdm->end();
-	//				break;
-	//			}else{
-	//				f_it = it;
-	//			}
-	//		}
-	//	}
-
-	//	if(f_it != pRdm->end()){
-	//		ReceiveDataMap::iterator it = pRdm->find(pos->nFirstReader);
-
-	//		dist[0] = sqrt(pow(pos->posx - it->second.x,2) + pow(pos->posy - it->second.y,2)) / dScale;
-	//		dist[1] = sqrt(pow(pos->posx - f_it->second.x,2) + pow(pos->posy - f_it->second.y,2)) / dScale;
-
-	//		double dif1 = dist[0] - dist[1];
-
-	//		double dt = it->second.rec_time_stamp - f_it->second.rec_time_stamp;
-	//		double dif2 = CFunctions::getDistance(dt,CFunctions::TDOA);
-
-	//		double dif = fabs(dif1 - dif2);
-
-	//		if(dif - 1 <= 1E-4){
-	//			bRet = true;
-	//		}
-
-	//	}
-	//}
-
 	return bRet;
 }