Selaa lähdekoodia

check memory leak

researchman 8 vuotta sitten
vanhempi
commit
3346aa5841
4 muutettua tiedostoa jossa 36 lisäystä ja 87 poistoa
  1. 0 1
      QueueStrManager.h
  2. 2 48
      SyncTime/SyncManager.cpp
  3. 17 17
      YAServerDlg.cpp
  4. 17 21
      classdef.cpp

+ 0 - 1
QueueStrManager.h

@@ -14,7 +14,6 @@ public:
 	QueueStrManager(void);
 	QueueStrManager(int c, int l, PFCALLBACK func ): m_max_couter(c), m_max_length(l), m_couter(0), m_length(0), m_pfunc(func)
 	{
-		m_pfunc = NULL;
 		m_chr = new char[m_max_length];
 		InitializeCriticalSection(&m_csQueueList);
 	};

+ 2 - 48
SyncTime/SyncManager.cpp

@@ -125,48 +125,6 @@ HostServer::Position HostServer::SyncManager::analyzeTagMsg(TagMsg &tagMsg, unsi
     auto it = begin;
     it++;
 
-    //Eigen::VectorXd x(3);
-    //Eigen::MatrixXd data(3,4), pos(1,3);
-    //pos(0,0) = _anchors[begin->first].x;
-    //pos(0,1) = _anchors[begin->first].y;
-    //pos(0,2) = _anchors[begin->first].z;
-
-    //// 设置tag的初始坐标
-    // x << 500,500,100;
-    //cout << begin->first << "  " << pos(0,0) << ", "<< pos(0,1) << ", "<< pos(0,2) << endl;
-
-
-    //ofstream fout("test/linar_" + to_string(tagId) + ".txt",ios::app);
-
-    //for (int i = 0; it != times.end(); it++, i++)
-    //{
-    //    data(i,0) = _anchors[it->first].x;
-    //    data(i,1) = _anchors[it->first].y;
-    //    data(i,2) = _anchors[it->first].z;
-
-    //    data(i,3) = (it->second - begin->second)  * 15.65 * 2.99702547 * 0.01;
-    //    cout << it->first << "  " << data(i,0) << ", " << data(i,1) << ", " << data(i,2) << ", "<< data(i,3) <<";" << endl;
-
-    //    fout << hex <<  it->first << ' ' << begin->first << ' ' << data(i,3) << endl;
-    //}
-
-    //TDOAFunctor functor(data, pos);
-    //Eigen::NumericalDiff<TDOAFunctor> numDiff(functor);
-    //Eigen::LevenbergMarquardt<Eigen::NumericalDiff<TDOAFunctor>,double> lm(numDiff);
-    //lm.parameters.maxfev = 2000;
-    //lm.parameters.xtol = 1.0e-10;
-
-    //// 计算后,如果计算出结果则返回该结果
-    //int ret = lm.minimize(x);
-    //if(ret > 0) 
-    //{
-    //    Position p(x[0],x[1],x[2]);
-    //    cout << p.x * 17 / 15<< "   " << p.y * 17 / 15<< "   " << p.z * 17 / 15<< endl;
-    //    fout << p.x * 17 / 15<< "   " << p.y * 17 / 15<< "   " << p.z * 17 / 15<< endl;
-    //    fout << endl;
-    //    fout.close();
-    //    return p;
-    //}
     return Position(DBL_MAX, DBL_MAX, DBL_MAX);
 }
 
@@ -180,14 +138,14 @@ unsigned long long HostServer::SyncManager::calTimeByLinar(TagMsg &tag)
 	//if(_syncTimeMsgs.count(tag.SyncNum) > 0 && _syncTimeMsgs[tag.SyncNum].count(tag.StationIdCode) > 0 
 	//	&&  _syncTimeMsgs[tag.SyncNum][tag.StationIdCode].SyncLevel() == 0)
 	unordered_map<unsigned short, unordered_map<unsigned long long, SyncTimeMsg>>::iterator it_msg = _syncTimeMsgs.find(tag.SyncNum);
-	if(it_msg != _syncTimeMsgs.end() && _syncTimeMsgs.count(tag.SyncNum) > 0)
+	if(it_msg != _syncTimeMsgs.end() && it_msg->second.size() > 0 && _syncTimeMsgs.count(tag.SyncNum) > 0)
 	{
 		unordered_map<unsigned long long, SyncTimeMsg>::iterator it = _syncTimeMsgs.find(tag.SyncNum)->second.find(tag.StationIdCode);
 		if(it != _syncTimeMsgs[tag.SyncNum].end()){
 			if(_syncTimeMsgs[tag.SyncNum][tag.StationIdCode].SyncLevel() == 0){
 				return tag.ReceiveTime;
 			}
-		}	
+		}
 	}
 
     while(hisSync.size() < 2 && i < MAX_SYNCTIME_NUM)
@@ -234,10 +192,6 @@ unsigned long long HostServer::SyncManager::calTimeByLinar(TagMsg &tag)
     res = X(2);
     res &= TIME_MAX;
 
-    //fout << hex << tag.SyncNum << ' ' << tag.StationIdCode << endl
-    //    << "RecieveTime " << hisSync.at(0).RealReceiveTime() << ' ' << hisSync.at(1).RealReceiveTime() << ' ' << tag.ReceiveTime << endl
-    //    << "RootTime    " <<  hisSync.at(0).RealSendTime() << ' ' << hisSync.at(1).RealSendTime() << ' ' << res << endl
-    //    << "TimeDelay   " << hisSync.at(0).TimeDelay() << ' ' << hisSync.at(1).TimeDelay() << " " << endl;
     return res;
 }
 

+ 17 - 17
YAServerDlg.cpp

@@ -1576,11 +1576,11 @@ void CYAServerDlg::parse_data(BYTE *pData, int nLen,  DWORD dwConnID)
 			if(tmplen > nLen){
 				tmplen = nLen;
 			}
-			TRACE(_T("1  \n"));
+			//TRACE(_T("1  \n"));
 			memcpy(it->second->pData, pData, tmplen);
 		}else{ // 接着上一次收取
 			tmplen = min(nLen, it->second->wLen - it->second->wReadLen);
-			TRACE(_T("2  \n"));
+			//TRACE(_T("2  \n"));
 			memcpy(&it->second->pData[it->second->wReadLen], pData, tmplen);
 		}
 		it->second->wReadLen += tmplen;
@@ -1594,7 +1594,7 @@ void CYAServerDlg::parse_data(BYTE *pData, int nLen,  DWORD dwConnID)
 		_sockbuf->dwConnID = dwConnID;
 		_sockbuf->wLen = MAKEWORD(pData[1], pData[0]) + sizeof(WORD); // 加上描述长度的两个字节
 		memset(_sockbuf->pData, 0, LENGTH_MSG_4K);
-		TRACE(_T("3  \n"));
+		//TRACE(_T("3  \n"));
 		memcpy(_sockbuf->pData, pData, nLen);
 		_sockbuf->wReadLen += nLen;
 		mp_socket_buffer_list.insert(make_pair(dwConnID, _sockbuf));
@@ -1634,7 +1634,7 @@ void CYAServerDlg::parse_data_receive(BYTE *pData, int nLen, DWORD dwConnID )
 		TRACE("new memory = %d\n",pkg_len);
 		BYTE* DataBuffer = new BYTE[pkg_len];
 		memset(DataBuffer, 0, pkg_len);
-		TRACE(_T("4  \n"));
+		//TRACE(_T("4  \n"));
 		memcpy(DataBuffer, &pData[total_pos], pkg_len + sizeof(WORD)); // 一个数据包		
 		parse_package_data(DataBuffer, pkg_len + sizeof(WORD), dwConnID);	// 解析数据包
 		
@@ -1789,7 +1789,7 @@ void CYAServerDlg::parse_data_locate_reader(BYTE * DataBuffer, int& nCurPos, int
 	// 分站时间
 	// 7字节 从第一个字节开始,分别表示秒、分、时、天、周、月、年
 	BYTE btSec = 0;
-	TRACE(_T("5  \n"));
+	//TRACE(_T("5  \n"));
 	memcpy(&btSec, &DataBuffer[nCurPos], sizeof(BYTE));
 	nCurPos += sizeof(BYTE);
 	BYTE btMin = 0;
@@ -1844,7 +1844,7 @@ void CYAServerDlg::parse_data_locate_card(BYTE* DataBuffer, int& nCurPos, int re
 	ReaderMap::iterator it = mp_reader_list.find(reader_id);
 	// 卡类型
 	BYTE btCardType = 0;
-	TRACE(_T("6  \n"));
+	//TRACE(_T("6  \n"));
 	memcpy(&btCardType, &DataBuffer[nCurPos], sizeof(BYTE));
 	nCurPos += sizeof(BYTE);
 	// 卡号
@@ -1859,7 +1859,7 @@ void CYAServerDlg::parse_data_locate_card(BYTE* DataBuffer, int& nCurPos, int re
 	if(it_card != mp_card_list_all.end()){
 		card = it_card->second;
 	}else{
-		return;
+		//return;
 		isErrorCard = true;
 		card = new Card(str_card_id, btCardType, theApp.z_offset);
 		TRACE(_T("parse_data_locate_card : new Card \n"));
@@ -1922,7 +1922,7 @@ void CYAServerDlg::parse_data_locate_card_vehicle(BYTE* DataBuffer, int& nCurPos
 	nCurPos += sizeof(WORD);
 
 	BYTE btTypeAndPower;
-	TRACE(_T("7  \n"));
+	//TRACE(_T("7  \n"));
 	memcpy(&btTypeAndPower, &DataBuffer[nCurPos], sizeof(BYTE));
 	nCurPos += sizeof(BYTE);
 	//报文类型
@@ -2021,7 +2021,7 @@ void CYAServerDlg::parse_data_adhoc( BYTE* DataBuffer, int& nCurPos, int reader_
 	ReaderMap::iterator it = mp_reader_list.find(reader_id);
 
 	BYTE nlen = 0, nDeal = nCurPos;
-	TRACE(_T("8  \n"));
+	//TRACE(_T("8  \n"));
 	memcpy(&nlen, &DataBuffer[nCurPos], sizeof(BYTE));
 	nCurPos += sizeof(BYTE);
 	while (nlen > nCurPos - nDeal){
@@ -5587,7 +5587,7 @@ EnHandleResult CYAServerDlg::OnReceive( ITcpServer* pSender, CONNID dwConnID, co
 	data->dwConnID = dwConnID;
 	data->len = iLength;
 	memset(data->buf, 0, LENGTH_MSG_4K);
-	TRACE(_T("9  \n"));
+	//TRACE(_T("9  \n"));
 	memcpy(data->buf, pData, iLength);
 
 	QueueUserWorkItem(_parse_data_server, (LPVOID)data, WT_EXECUTEDEFAULT);
@@ -5645,7 +5645,7 @@ void CYAServerDlg::parse_data_locate_card_his( BYTE* DataBuffer, int& nCurPos, i
 
 	// 数据保存时间 7字节,年,月,周,日,时,分,秒
 	BYTE btSec = 0;
-	TRACE(_T("10  \n"));
+	//TRACE(_T("10  \n"));
 	memcpy(&btSec, &DataBuffer[nCurPos], sizeof(BYTE));
 	nCurPos += sizeof(BYTE);
 	BYTE btMin = 0;
@@ -5795,7 +5795,7 @@ void CYAServerDlg::parse_data_reader_synctime(BYTE *DataBuffer, int nLen, int& n
 		nCurPos += sizeof(DWORD);
 
 		BYTE btAnt = 0; // 本机发送天线
-		TRACE(_T("11  \n"));
+		//TRACE(_T("11  \n"));
 		memcpy(&btAnt, &DataBuffer[nCurPos], sizeof(BYTE));
 		nCurPos += sizeof(BYTE);
 
@@ -6125,7 +6125,7 @@ void CYAServerDlg::parse_data_server( const BYTE * pData, int nLen, DWORD dwConn
 	BYTE *Buf = new BYTE[LENGTH_MSG_1M];
 	memset(Buf, 0, LENGTH_MSG_1M);
 
-	TRACE(_T("12  \n"));
+	//TRACE(_T("12  \n"));
 	SocketBufferMap::iterator it = mp_socket_buffer_list.find(dwConnId);
 	if(it != mp_socket_buffer_list.end()){ // 有此socket数据
 		if(nLen + it->second->wReadLen > LENGTH_MSG_1M){
@@ -6201,7 +6201,7 @@ void CYAServerDlg::parse_data_server( const BYTE * pData, int nLen, DWORD dwConn
 				int tt = it->second->wReadLen;
 			}
 			try{
-				TRACE(_T("13  \n"));
+				//TRACE(_T("13  \n"));
 				memcpy(&it->second->pData[it->second->wReadLen], &Buf[read_length], nLen - read_length);
 			}catch(...){
 				int tt = it->second->wReadLen;
@@ -6287,11 +6287,11 @@ void CYAServerDlg::deal_card_msg( Card* card, bool is_hist /*= false*/ )
 			}else{
 				dist->tt = syncmanager.calTimeByLinar(tagMsg);
 			}
-			TRACE(_T("liner: %d\r\n"), ::GetTickCount() - dw);
+			//TRACE(_T("liner: %d\r\n"), ::GetTickCount() - dw);
 			dw = ::GetTickCount();
 			//dist->tt = syncmanager.calTimeByLinar(tagMsg);
 			card->add_dist(dist);
-			TRACE(_T("add_dist: %d\r\n"), ::GetTickCount() - dw);
+			//TRACE(_T("add_dist: %d\r\n"), ::GetTickCount() - dw);
 			//LeaveCriticalSection(&m_csAddDist);
 			if(m_log_locate_data){
 				CString strLog = _T("");
@@ -6327,7 +6327,7 @@ void CYAServerDlg::deal_card_msg( Card* card, bool is_hist /*= false*/ )
 	card_enter_map(card); // 切换地图
 	card_enter_area(card); //, card->deal_time);
 	deal_card_state(card);
-	TRACE(_T("logic: %d\r\n"), ::GetTickCount() -dw);
+	//TRACE(_T("logic: %d\r\n"), ::GetTickCount() -dw);
 	card->isdealed = true;
 	if(LT_READER != theApp.locate_type){
 		card->issent = false;

+ 17 - 21
classdef.cpp

@@ -614,9 +614,9 @@ void Card::get_coordinate( int cnt )
 			if(p->posx == INVALID_COORDINATE && p->posy == INVALID_COORDINATE){
 				this->m_pKalmanFilter->m_bFlag = false;	
 				if(this->m_pKalmanFilter->m_nCounts < 3 || this->m_pKalmanFilter->m_pCar->P(0,0) > 2){
-					this->last_x = this->x = this->last_locate.x;
-					this->last_y = this->y = this->last_locate.y;
-					this->last_z = this->z = INVALID_COORDINATE;
+					this->x = this->last_locate.x;
+					this->y = this->last_locate.y;
+					this->z = INVALID_COORDINATE;
 					return;
 				}
 				
@@ -640,10 +640,6 @@ void Card::get_coordinate( int cnt )
 				y = p->posy / (this->map_scale*1.0);
 				z = p->posz / (this->map_scale*1.0);
 
-				if(y > 640.0){
-					int tttt = x;
-					tttt*=2;
-				}
 				if(deltaT != 0){
 					vx = (this->x - this->last_locate.x)/deltaT;
 					vy = (this->y - this->last_locate.y)/deltaT;
@@ -749,8 +745,8 @@ void Card::get_coordinate( int cnt )
 			}		
 
 			TRACE(_T("before kalman (x,y):(%f,%f) \n"),this->x,this->y);
-			this->last_x = this->last_locate.x = this->x = this->m_pKalmanFilter->m_pCar->x(0,0);
-			this->last_y = this->last_locate.y = this->y = this->m_pKalmanFilter->m_pCar->x(2,0);
+			this->last_locate.x = this->x = this->m_pKalmanFilter->m_pCar->x(0,0);
+			this->last_locate.y = this->y = this->m_pKalmanFilter->m_pCar->x(2,0);
 			TRACE(_T("after kalman (x,y):(%f,%f) \n"),this->x,this->y);
 			this->last_locate.z = this->z;
 			this->last_locate.t = this->t;
@@ -815,6 +811,18 @@ void Card::get_coordinate( int cnt )
 		delete p;
 		p = NULL;
 	}
+/*
+	ReceiveDataMap::iterator it = pRdm.begin();
+	for(;it!=pRdm.end();it++){
+		ReceiveData* p = it;
+	}
+
+	ReceiveDataMap::iterator prdm_it = pRdm.find(p_dists_locate[i]->reader_id);
+		if(prdm_it == pRdm.end()){	
+			ReceiveData* prd = new ReceiveData();
+			pRdm.insert(ReceiveDataMap::value_type(prd->reader_id,*prd));
+		}*/		
+
 #else
 
 #endif
@@ -1074,18 +1082,6 @@ double Area::get_vertex( std::string src)
 
 bool Area::is_in_polygon( _point p )
 {
-	//int   i,j=polySides-1 ;
-	//bool  oddNodes=NO     ;
-
-	//for (i=0;i<polySides; i++) {
-	//	if((polyY[i]< y && polyY[j]>=y
-	//		||   polyY[j]<y && polyY[i]>=y)
-	//		&& (polyX[i]<=x || polyX[j]<=x)) {
-	//			oddNodes^=(polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x);}
-	//	j=i;}
-
-	//returnoddNodes;
-
 	int counter = 0;
 	int i;
 	double xinters;