• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    NMEA Parser
    Last Modify : 04 January, 2011(03:18)
    //
    // DATE		: April 03, 2006
    // CODER	: Kurome (aucd29@gmail.com)
    //
    // ------------------------------------------------------
    // NOTE
    // ------------------------------------------------------
    // * NMEA 파셔
    //
    // -----------------------------------------------------------
    // FIX : June 14, 2007 18:4:0
    // -----------------------------------------------------------
    // * <list>를 <vector>로 교체
    //
    
    
    #include "StdAfx.h"
    #include "NMEAParser.h"
    
    CNMEAParser::CNMEAParser(void)
    //: m_bIndex(true)
    {
    		
    }
    
    CNMEAParser::~CNMEAParser(void)
    {
    }
    
    void CNMEAParser::Parsing(CString szFullText)
    {
    	/*
    	-------------------------------------------------------------------------------------------
    	+GPSTRACKD: 77, "$GPGGA,084816.000,3728.6289,N,12652.8449,E,1,09,0.9,89.4,M,19.3,M,,0000*69
    	"
    
    	+GPSTRACKD: 52, "$GPGLL,3728.6289,N,12652.8449,E,084816.000,A,A*52
    	"
    
    	+GPSTRACKD: 58, "$GPGSA,A,3,09,21,18,26,22,12,05,24,29,,,,1.8,0.9,1.5*3A
    	"
    
    	+GPSTRACKD: 71, "$GPGSV,3,1,12,09,81,154,45,18,56,317,46,21,45,233,45,26,33,059,44*7D
    	"
    
    	+GPSTRACKD: 71, "$GPGSV,3,2,12,24,26,189,42,29,24,066,40,22,23,310,44,12,13,155,41*70
    	"
    
    	+GPSTRACKD: 71, "$GPGSV,3,3,12,05,11,166,38,10,04,126,36,14,02,266,34,28,02,032,35*7D
    	"
    
    	+GPSTRACKD: 73, "$GPRMC,084816.000,A,3728.6289,N,12652.8449,E,0.12,139.66,030407,,,A*6D
    	"
    
    	+GPSTRACKD: 39, "$GPVTG,139.66,T,,M,0.12,N,0.2,K,A*07
    	"
    
    	+GPSTRACKD: 36, "$GPZDA,084816.000,03,04,2007,,*57
    	"
    	-------------------------------------------------------------------------------------------
    	*/
    
    	m_szFullText = szFullText;
    	SetDefineType();
    	Divide();
    	NMEATrace();
    }
    
    void CNMEAParser::SetDefineType(void)
    {
    	m_Type.push_back(L"$GPGGA");
    	m_Type.push_back(L"$GPGLL");
    	m_Type.push_back(L"$GPGSA");
    	m_Type.push_back(L"$GPGSV");
    	m_Type.push_back(L"$GPRMC");
    	m_Type.push_back(L"$GPVTG");
    	m_Type.push_back(L"$GPZDA");
    }
    
    void CNMEAParser::Divide(void)
    {
    	//it = m_Type.begin();
    	int i = 0;
    	int nLength = static_cast<int>(m_Type.size());
    	//CString szField;
    
    	//while (nLength--)
    	for (i=0; i<nLength; ++i)
    	{
    		//szField = *it++;
    		m_Divide[m_Type[i]] = GetDivideString(m_Type[i]);
    	}
    
    	TraceDivide();
    
    	ParsingGGA();
    	ParsingGLL();
    	ParsingGSA();
    	ParsingGSV();
    	ParsingRMC();
    	ParsingVTG();
    	ParsingZDA();
    }
    
    CString CNMEAParser::GetDivideString(CString szString)
    {
    	CString szReturnData;
    	int nPosition = 0;
    	int nEndPoint = 0;
    
    	nPosition = m_szFullText.Find(szString);
    	if (nPosition == -1)
    	{
    		return L"";
    	}
    
    	// GSV는 여려개가 들어올 수 있다.
    	if (szString == L"$GPGSV")
    	{
    		// GSV 는 여려개 출력될 수 있다.
    		nEndPoint	 = m_szFullText.Find(L"\"", nPosition);
    		szReturnData = m_szFullText.Mid(nPosition, nEndPoint - nPosition);
    		m_GSV.push_back(szReturnData.Trim());
    
    		while (true)
    		{
    			nPosition = m_szFullText.Find(szString, nEndPoint);
    			if (nPosition == -1)
    			{
    				break;
    			}
    
    			nEndPoint    = m_szFullText.Find(L"\"", nPosition);
    			szReturnData = m_szFullText.Mid(nPosition, nEndPoint - nPosition);
    			m_GSV.push_back(szReturnData.Trim());
    		}
    	}
    	else
    	{
    		// GSV 는 여려개 출력될 수 있다.
    		nEndPoint	 = m_szFullText.Find(L"\"", nPosition);
    		szReturnData = m_szFullText.Mid(nPosition, nEndPoint - nPosition);
    		szReturnData = szReturnData.Trim();
    	}
    
    	return szReturnData;
    }
    
    void CNMEAParser::TraceDivide(void)
    {
    	/*
    
    	TRACE DATA
    
    	[$GPGGA] $GPGGA,084816.000,3728.6289,N,12652.8449,E,1,09,0.9,89.4,M,19.3,M,,0000*69
    	[$GPGLL] $GPGLL,3728.6289,N,12652.8449,E,084816.000,A,A*52
    	[$GPGSA] $GPGSA,A,3,09,21,18,26,22,12,05,24,29,,,,1.8,0.9,1.5*3A	
    	[$GPVTG] $GPVTG,139.66,T,,M,0.12,N,0.2,K,A*07	
    	[$GPRMC] $GPRMC,084816.000,A,3728.6289,N,12652.8449,E,0.12,139.66,030407,,,A*6D
    	[$GPGSV] $GPGSV,3,1,12,09,81,154,45,18,56,317,46,21,45,233,45,26,33,059,44*7D
    	[$GPGSV] $GPGSV,3,2,12,24,26,189,42,29,24,066,40,22,23,310,44,12,13,155,41*70
    	[$GPGSV] $GPGSV,3,3,12,05,11,166,38,10,04,126,36,14,02,266,34,28,02,032,35*7D
    	*/
    
    	//it = m_Type.begin();
    	int i;
    	int nLength = static_cast<int>(m_Type.size());
    
    	TRACE(L"---------------------------------------------------\n");
    	TRACE(L"| NMEA                                            |\n");
    	TRACE(L"---------------------------------------------------\n");
    	//while (nLength--)
    	for (i=0; i<nLength; ++i)
    	{
    		TRACE(L"[%s]", m_Type[i]);
    		TRACE(L" %s\n", m_Divide[m_Type[i]]);
    		//TRACE(L"[%s]", *it);
    		//TRACE(L" %s\n", m_Divide[*it]);
    
    		// *it++;
    	}
    
    	nLength = static_cast<int>(m_GSV.size());
    	for(i=0; i<nLength; ++i)
    	{
    		TRACE(L"[$GPGSV] %s\n", m_GSV[i]);
    	}
    	TRACE(L"---------------------------------------------------\n");
    }
    
    
    void CNMEAParser::ParsingGGA(void)
    {
    	/*
    	-----------------------------------------------------------------------------
    	Name					Example		Unit	Description
    	-----------------------------------------------------------------------------
    	Message ID				$GPGGA		GGA		protocol header
    	UTC Time				161229.487			hhmmss.sss
    	Latitude				3723.2475			ddmm.mmmm
    	N/S Indicator			N					N=north or S=south
    	Longitude				12158.3416			dddmm.mmmm
    	E/W Indicator			W					E=east or W=west
    	Position Fix Indicator	1					See Table 1-4
    	Satellites Used			07					Range 0 to 12
    	HDOP					1.0					Horizontal Dilution of Precision
    	MSL Altitude			9.0			meters	
    	Units					M			meters	
    	Geoid Separation					meters	
    	Units					M			meters	
    	Age of Diff. Corr					second	Null fields when DGPS is not used
    	Diff. Ref. Station ID	0000		
    	Checksum				*18		
    	<CR><LF>									End of message termination
    	-----------------------------------------------------------------------------
    	[$GPGGA] $GPGGA,084816.000,3728.6289,N,12652.8449,E,1,09,0.9,89.4,M,19.3,M,,0000*69
    	-----------------------------------------------------------------------------
    	*/
    	TRACE(L"--------------------------------------------------------------\n");
    	TRACE(L"| %s\n", m_Divide[L"$GPGGA"]);
    	TRACE(L"--------------------------------------------------------------\n");
    
    	int nPos = 0, nPos2 = 0, index = 0;
    	CString szGp;
    	while (true)
    	{
    		nPos2 = m_Divide[L"$GPGGA"].Find(L",", nPos);
    		szGp  = m_Divide[L"$GPGGA"].Mid(nPos, nPos2 - nPos);
    		TRACE(L"| GGA index:%d : %s\n", index, szGp);
    		
    		switch(index)
    		{
    		case 1:
    			//m_nmeaData[m_bIndex].SetUTCTime(szGp);
    			m_nmeaData.SetUTCTime(szGp);
    			break;
    		case 2:
    			//m_nmeaData[m_bIndex].SetLatitude(szGp);
    			m_nmeaData.SetLatitude(szGp);
    			break;
    		case 3:
    			//m_nmeaData[m_bIndex].SetNS(szGp);
    			m_nmeaData.SetNS(szGp);
    			break;
    		case 4:
    			//m_nmeaData[m_bIndex].SetLongitude(szGp);
    			m_nmeaData.SetLongitude(szGp);
    			break;
    		case 5:
    			//m_nmeaData[m_bIndex].SetEW(szGp);
    			m_nmeaData.SetEW(szGp);
    			break;
    		case 6:
    			//m_nmeaData[m_bIndex].SetPositionFix(szGp);
    			m_nmeaData.SetPositionFix(szGp);
    			break;
    		case 7:
    			//m_nmeaData[m_bIndex].SetSatelliteUsed(szGp);
    			m_nmeaData.SetSatelliteUsed(szGp);
    			break;
    		case 9:
    			//m_nmeaData[m_bIndex].SetAltitude(szGp);
    			m_nmeaData.SetAltitude(szGp);
    			break;
    		default:
    			break;
    		}
    
    		index++;
    
    		if (nPos2 == -1)
    		{
    			break;
    		}
    		nPos = nPos2 + 1;
    	}
    }
    
    void CNMEAParser::ParsingGLL(void)
    {
    	/*
    	-----------------------------------------------------------------------------
    	Name					Example		Unit	Description
    	-----------------------------------------------------------------------------
    	Message ID				$GPGLL		GLL 	protocol header
    	Latitude				3723.2475			ddmm.mmmm
    	N/S Indicator			N					N=north or S=south
    	Longitude				12158.3416			dddmm.mmmm
    	E/W Indicator			W					E=east or W=west
    	UTC Time			
    	Status					A					A=data valid or V=data not valid
    	Mode					A					A=Autonomous, D=DGPS, E=DR (Only present in NMEA version 3.0)
    	Checksum				*41		
    	<CR><LF>									End of message termination
    	-----------------------------------------------------------------------------
    	[$GPGLL] $GPGLL,3728.6289,N,12652.8449,E,084816.000,A,A*52
    	-----------------------------------------------------------------------------
    	*/
    	
    	TRACE(L"--------------------------------------------------------------\n");
    	TRACE(L"| %s\n", m_Divide[L"$GPGLL"]);
    	TRACE(L"--------------------------------------------------------------\n");
    
    	int nPos = 0, nPos2 = 0, index = 0;
    	CString szGp;
    	while (true)
    	{
    		nPos2 = m_Divide[L"$GPGLL"].Find(L",", nPos);
    		szGp  = m_Divide[L"$GPGLL"].Mid(nPos, nPos2 - nPos);
    		TRACE(L"| GPGLL index:%d : %s\n", index, szGp);
    
    		switch(index)
    		{
    		case 7:
    			//m_nmeaData[m_bIndex].SetStatus(szGp);
    			m_nmeaData.SetStatus(szGp);
    			return;
    			break;
    		}
    
    		index++;
    		nPos = nPos2 + 1;
    	}
    }
    
    void CNMEAParser::ParsingGSA(void)
    {
    	/*
    	-----------------------------------------------------------------------------
    	Name					Example		Unit	Description
    	-----------------------------------------------------------------------------
    	Message ID				$GPGSA				GSA protocol header
    	Mode1					A					See Table 1-7
    	Mode2					3					See Table 1-8
    	Satellite Used1			07					Sv on Channel 1
    	Satellite Used1			02					Sv on Channel 2
    	….			….
    	Satellite Used1								Sv on Channel 12
    	PDOP					1.8		
    	HDOP					1.0		
    	VDOP					1.5		
    	Checksum				*33		
    	<CR><LF>									End of message termination
    	-----------------------------------------------------------------------------
    	[$GPGSA] $GPGSA,A,3,09,21,18,26,22,12,05,24,29,,,,1.8,0.9,1.5*3A
    	-----------------------------------------------------------------------------
    	*/
    
    	TRACE(L"--------------------------------------------------------------\n");
    	TRACE(L"| %s\n", m_Divide[L"$GPGSA"]);
    	TRACE(L"--------------------------------------------------------------\n");
    
    	int nPos = 0, nPos2 = 0, index = 0;
    	CString szGp;
    	while (true)
    	{
    		nPos2 = m_Divide[L"$GPGSA"].Find(L",", nPos);
    		szGp  = m_Divide[L"$GPGSA"].Mid(nPos, nPos2 - nPos);
    		TRACE(L"| GPGSA index:%d : %s\n", index, szGp);
    
    		switch(index)
    		{
    		case 0: break;
    		case 1:
    			//m_nmeaData[m_bIndex].SetMode1(szGp);
    			m_nmeaData.SetMode1(szGp);
    			break;
    		case 2:
    			//m_nmeaData[m_bIndex].SetMode2(szGp);
    			m_nmeaData.SetMode2(szGp);
    			break;
    		default:
    
    			if (index == 15)
    			{
    				return;
    			}
    
    			// 내용이 존재할 때만 insert
    			if (szGp.GetLength())
    			{
    				//m_nmeaData[m_bIndex].PutSatelliteUsed(szGp);
    				m_nmeaData.PutSatelliteUsed(szGp);
    			}
    			
    			break;
    		}
    
    		index++;
    		nPos = nPos2 + 1;
    	}
    }
    
    void CNMEAParser::ParsingGSV(void)
    {
    	/*
    	-----------------------------------------------------------------------------
    	Name					Example		Unit	Description
    	-----------------------------------------------------------------------------
    	Message ID				$GPGSA				GSA protocol header
    	Number of Message1		2					Range 1 to 3
    	Message Number1			1					Range 1 to 3
    	Satellite in View		07			
    	Satellite ID			07					Channel 1 (Range 1 to 32)
    	Elevation				79			degrees	Channel 1 (Maximum 90) 
    	Azimuth					048			degrees	Channel 1 (True, Range 0 to 359)
    	SNR (C/No)				42			dBHz	Range 0 to 99, null when not tracking
    	….			….
    	Satellite ID			27			Channel 4 (Range 1 to 32)
    	Elevation				27			degrees	Channel 4 (Maximum 90)
    	Azimuth					138			degrees	Channel 4 (True, Range 0 to 359)
    	SNR (C/No)				42			dBHz	Range 0 to 99, null when not tracking
    	Checksum				*71		
    	<CR><LF>									End of message termination
    	-----------------------------------------------------------------------------
    	[$GPGSV] $GPGSV,3,1,12,09,81,154,45,18,56,317,46,21,45,233,45,26,33,059,44*7D
    			 $GPGSV,3,2,12,24,26,189,42,29,24,066,40,22,23,310,44,12,13,155,41*70
    			 $GPGSV,3,3,12,05,11,166,38,10,04,126,36,14,02,266,34,28,02,032,35*7D
    	-----------------------------------------------------------------------------
    	                    SAT1          SAT2          SAT3          SAT4
    	-----------------------------------------------------------------------------
    	$GPGSV,3,1,12, 09,81,154,45, 18,56,317,46, 21,45,233,45, 26,33,059,44 *7D
    	$GPGSV,3,2,12, 24,26,189,42, 29,24,066,40, 22,23,310,44, 12,13,155,41 *70
    	$GPGSV,3,3,12, 05,11,166,38, 10,04,126,36, 14,02,266,34, 28,02,032,35 *7D
    	-----------------------------------------------------------------------------
    	CONVERT
    	-----------------------------------------------------------------------------
    	[szHeader] $GPGSV,3,1,12,
    	[$GPGSV] 09,81,154,45, 18,56,317,46, 21,45,233,45, 26,33,059,44
    			 24,26,189,42, 29,24,066,40, 22,23,310,44, 12,13,155,41
    			 05,11,166,38, 10,04,126,36, 14,02,266,34, 28,02,032,35
    	-----------------------------------------------------------------------------
    	*/
    
    	int nSize = static_cast<int>(m_GSV.size());
    	//m_nmeaData[m_bIndex].SetSatelliteView(m_GSV[0].Mid(11, 2));
    	m_nmeaData.SetSatelliteView(m_GSV[0].Mid(11, 2));
    	//it		  = m_GSV.begin();
    	//m_nmeaData[m_bIndex].SetSatelliteView(it->Mid(11, 2));
    
    	//
    	// Convert
    	//
    	CGSV gsvData;
    	int i = 0;
    	int nPos  = 0;
    	int nPos2 = 0;
    	//while (nSize--)
    	for (i=0; i<nSize; ++i)
    	{
    		m_GSV[i] = m_GSV[i].Mid(14, m_GSV[i].GetLength() - 17);
    		// *it = it->Mid(14, it->GetLength() - 17);
    
    		TRACE(L"--------------------------------------------------------------\n");
    		//TRACE(L"| $GPGSV : %s\n", *it);
    		TRACE(L"| $GPGSV : %s\n", m_GSV[i]);
    		TRACE(L"--------------------------------------------------------------\n");		
    
    		//
    		// 이런 데이터를 쪼갠다.
    		// 09,81,154,45, 18,56,317,46, 21,45,233,45, 26,33,059,44
    		//
    		nPos2 = m_GSV[i].Find(L",", nPos);
    		while (true)
    		{
    			//
    			// id
    			//
    			gsvData.SetID(m_GSV[i].Mid(nPos, nPos2 - nPos));
    
    			//
    			// Elevation
    			//
    			nPos  = nPos2 + 1;
    			nPos2 = m_GSV[i].Find(L",", nPos);
    			gsvData.SetElevation(m_GSV[i].Mid(nPos, nPos2 - nPos));
    
    			//
    			// Azimuth
    			//
    			nPos  = nPos2 + 1;
    			nPos2 = m_GSV[i].Find(L",", nPos);
    			gsvData.SetAzimuth(m_GSV[i].Mid(nPos, nPos2 - nPos));
    
    			//
    			// SNR
    			//
    			nPos  = nPos2 + 1;
    			nPos2 = m_GSV[i].Find(L",", nPos);
    			
    			if (nPos2 == -1)
    			{
    				gsvData.SetSNR(m_GSV[i].Mid(nPos, 2));
    			}
    			else
    			{
    				gsvData.SetSNR(m_GSV[i].Mid(nPos, nPos2 - nPos));
    			}
    
    			gsvData.Trace();
    			//m_nmeaData[m_bIndex].PutSatelliteView(gsvData);
    			m_nmeaData.PutSatelliteView(gsvData);
    
    			if (nPos2 == -1)
    			{
    				break;
    			}
    			
    			nPos  = nPos2 + 1;
    			nPos2 = m_GSV[i].Find(L",", nPos);
    		}
    
    		//
    		// init variant
    		//
    		nPos = 0;
    		
    		//it++;
    	}
    }
    
    void CNMEAParser::ParsingRMC(void)
    {
    	/*
    	-----------------------------------------------------------------------------
    	Name					Example		Unit	Description
    	-----------------------------------------------------------------------------
    	Message ID				$GPGSA				RMC protocol header
    	UTC Time				161229.487			hhmmss.sss
    	Status	A									A=data valid or V=data not valid
    	Latitude				3723.2475			ddmm.mmmm
    	N/S Indicator			N					N=north, S=south
    	Longitude				12158.3416			ddd mm.mmmm
    	E/W Indicator			W					E=east or W=west
    	Speed Over Ground		0.13		knots	
    	Course Over Ground		309.62		degrees	true
    	Date					120598				ddmmyy
    	Magnetic Variation					degrees	E=east or W=west
    	Mode					A					A=Autonomous, D=DGPS, E=DR
    	Checksum	*10		
    	<CR><LF>									End of message termination
    	-----------------------------------------------------------------------------
    	*/
    
    	TRACE(L"--------------------------------------------------------------\n");
    	TRACE(L"| %s\n", m_Divide[L"$GPRMC"]);
    	TRACE(L"--------------------------------------------------------------\n");
    
    	int nPos = 0, nPos2 = 0, index = 0;
    	CString szGp;
    	while (true)
    	{
    		nPos2 = m_Divide[L"$GPRMC"].Find(L",", nPos);
    		szGp  = m_Divide[L"$GPRMC"].Mid(nPos, nPos2 - nPos);
    		TRACE(L"| GPRMC index:%d : %s\n", index, szGp);
    
    		switch(index)
    		{
    		case 8:
    			//m_nmeaData[m_bIndex].SetCourseOverGround(szGp);
    			m_nmeaData.SetCourseOverGround(szGp);
    			return;
    			break;
    		}
    
    		index++;
    		nPos = nPos2 + 1;
    	}
    }
    
    void CNMEAParser::ParsingVTG(void)
    {
    	/*
    	-----------------------------------------------------------------------------
    	Name					Example		Unit	Description
    	-----------------------------------------------------------------------------
    	Message ID				$GPVTG		VTG		protocol header
    	Course					309.62		degrees	Measured heading
    	Reference				T			true
    	Course								degrees	Measured heading
    	Reference				M					Magnetic
    	Speed					0.13		knots	Measured horizontal speed
    	Units					N			Knots
    	Speed					0.2			km/hr	Measured horizontal speed
    	Units					K					Kilometers per hour
    	Mode					A					A=Autonomous, D=DPGS, E=DR
    	Checksum				*23		
    	<CR><LF>									End of message termination
    	-----------------------------------------------------------------------------
    	*/
    
    	TRACE(L"--------------------------------------------------------------\n");
    	TRACE(L"| %s\n", m_Divide[L"$GPVTG"]);
    	TRACE(L"--------------------------------------------------------------\n");
    
    	int nPos = 0, nPos2 = 0, index = 0;
    	CString szGp;
    	while (true)
    	{
    		nPos2 = m_Divide[L"$GPVTG"].Find(L",", nPos);
    		szGp  = m_Divide[L"$GPVTG"].Mid(nPos, nPos2 - nPos);
    		TRACE(L"| GPVTG index:%d : %s\n", index, szGp);
    
    		switch(index)
    		{
    		case 1:
    			//m_nmeaData[m_bIndex].SetTrueCourse(szGp);
    			m_nmeaData.SetTrueCourse(szGp);
    			break;
    		case 3:
    			//m_nmeaData[m_bIndex].SetCompaseCourse(szGp);
    			m_nmeaData.SetCompaseCourse(szGp);
    			break;
    		case 5:
    			//m_nmeaData[m_bIndex].SetKont(szGp);
    			m_nmeaData.SetKont(szGp);
    			break;
    		case 7:
    			//m_nmeaData[m_bIndex].SetKm(szGp);
    			m_nmeaData.SetKm(szGp);
    			return;
    			break;
    		}
    
    		index++;
    		nPos = nPos2 + 1;
    	}
    }
    
    void CNMEAParser::ParsingZDA(void)
    {
    	/*
    	-----------------------------------------------------------------------------
    	Name					Example		Unit	Description
    	-----------------------------------------------------------------------------
    	Message ID				$GPVTG				VTG protocol header
    	UTC time				181813				Either using valid IONO/UTC or estimated from default leap seconds
    	Day						14					01 to 31
    	Month					10					01 to 12
    	Year					2003				1980 to 2079
    	Local zone hour			00			knots	offset from UTC (set to 00)
    	Local zone minutes		00					offset from UTC (set to 00)
    	Checksum			
    	<CR><LF>									End of message termination
    	-----------------------------------------------------------------------------
    	*/
    
    	TRACE(L"--------------------------------------------------------------\n");
    	TRACE(L"| %s\n", m_Divide[L"$GPZDA"]);
    	TRACE(L"--------------------------------------------------------------\n");
    
    	int nPos = 0, nPos2 = 0, index = 0;
    	CString szGp;
    	while (true)
    	{
    		nPos2 = m_Divide[L"$GPZDA"].Find(L",", nPos);
    		szGp  = m_Divide[L"$GPZDA"].Mid(nPos, nPos2 - nPos);
    		TRACE(L"| GPZDA index:%d : %s\n", index, szGp);
    
    		switch(index)
    		{
    		case 2:
    			m_nmeaData.SetDay(szGp);
    			//m_nmeaData[m_bIndex].SetDay(szGp);
    			break;
    		case 3:
    			m_nmeaData.SetMonth(szGp);
    			//m_nmeaData[m_bIndex].SetMonth(szGp);
    			break;
    		case 4:
    			m_nmeaData.SetYear(szGp);
    			//m_nmeaData[m_bIndex].SetYear(szGp);
    			break;
    		case 5:
    			//m_nmeaData[m_bIndex].SetHour(szGp);
    			m_nmeaData.SetHour(szGp);
    			break;
    		case 6:
    			//m_nmeaData[m_bIndex].SetMinutes(szGp);
    			m_nmeaData.SetMinutes(szGp);
    			return;
    			break;
    		}
    
    		index++;
    		nPos = nPos2 + 1;
    	}
    }
    
    void CNMEAParser::NMEATrace(void)
    {
    	//m_nmeaData[m_bIndex].Trace();
    	m_nmeaData.Trace();
    }
    
    #pragma once
    
    #include <vector>
    #include <list>
    #include <map>
    using namespace std;
    
    class CGSV
    {
    protected:
    	int m_nSatelliteID;
    	int m_nElevation;
    	int m_nAzimuth;
    	int m_nSNR;
    
    public:
    	CGSV(void)
    		: m_nSatelliteID(0)
    		, m_nElevation(0)
    		, m_nAzimuth(0)
    		, m_nSNR(0)
    	{
    
    	}
    
    	void SetID(CString szID)
    	{
    		m_nSatelliteID = _wtoi(szID);
    	}
    
    	void SetElevation(CString szElevation)
    	{
    		m_nElevation = _wtoi(szElevation);
    	}
    
    	void SetAzimuth(CString szAzimuth)
    	{
    		m_nAzimuth = _wtoi(szAzimuth);
    	}
    
    	void SetSNR(CString szSNR)
    	{
    		m_nSNR = _wtoi(szSNR);
    	}
    
    	int GetID(void)
    	{
    		return m_nSatelliteID;
    	}
    
    	int GetElevation(void)
    	{
    		return m_nElevation;
    	}
    
    	int GetAzimuth(void)
    	{
    		return m_nAzimuth;
    	}
    
    	int GetSNR(void)
    	{
    		return m_nSNR;
    	}
    
    	void Trace(void)
    	{
    		TRACE(L"|	SatelliteID : %d\n", m_nSatelliteID);
    		TRACE(L"|	Elevation	: %d\n", m_nElevation);
    		TRACE(L"|	Azimuth		: %d\n", m_nAzimuth);
    		TRACE(L"|	SNR			: %d\n", m_nSNR);
    		TRACE(L"|\n");
    	}
    };
    
    class CNMEAData
    {
    protected:
    	//
    	// GGA
    	// $GPGGA,084816.000,3728.6289,N,12652.8449,E,1,09,0.9,89.4,M,19.3,M,,0000*69
    	//
    	int m_nPositionFix;
    	int m_nSatelliteUsed;
    	double m_dUTCTime;
    	double m_dLatitude;
    	double m_dLongitude;
    	double m_dAltitude;
    	CString m_szNS;
    	CString m_szEW;
    
    	//
    	// GLL
    	//
    	CString m_szStatus;
    
    	//
    	// GSA
    	// $GPGSA,A,3,09,21,18,26,22,12,05,24,29,,,,1.8,0.9,1.5*3A
    	//
    	int m_nMode2;			// 1(Fix not available), 2(2D), 3(3D)
    	//list<int> m_listSatelliteUsed;
    	vector<int> m_listSatelliteUsed;
    	CString m_szMode1;		// M(Manual), A(Automatic)
    
    	//
    	// GSV
    	//
    	/*
    	-------------------------------------------------------------------------
    					   SAT1          SAT2          SAT3          SAT4
        -------------------------------------------------------------------------
    	$GPGSV,3,1,12, 09,81,154,45, 18,56,317,46, 21,45,233,45, 26,33,059,44 *7D
    	$GPGSV,3,2,12, 24,26,189,42, 29,24,066,40, 22,23,310,44, 12,13,155,41 *70
    	$GPGSV,3,3,12, 05,11,166,38, 10,04,126,36, 14,02,266,34, 28,02,032,35 *7D
    	*/
    	int m_nSatelliteView;
    	//list<CGSV> m_listSatelliteView;
    	vector<CGSV> m_listSatelliteView;
    
    	//
    	// RMC
    	// $GPRMC,084816.000,A,3728.6289,N,12652.8449,E,0.12,139.66,030407,,,A*6D
    	//
    	double m_fCourseOverGround;
    	
    	//
    	// VTG
    	// $GPVTG,139.66,T,,M,0.12,N,0.2,K,A*07
    	//
    	double m_fTrueCourse;		// 진침로
    	double m_fCompaseCourse;	// 나침로
    	double m_fKont;
    	double m_fKm;
    
    	//
    	// ZDA
    	//
    	int m_nDay;
    	int m_nMonth;
    	int m_nYear;
    	int m_nHour;
    	int m_nMinutes;
    	
    public:
    	CNMEAData(void)
    		: m_dUTCTime(0.0f)
    		, m_dLatitude(0.0f)
    		, m_szNS(L"")
    		, m_dLongitude(0.0f)
    		, m_szEW(L"")
    		, m_nPositionFix(0)
    		, m_nSatelliteUsed(0)
    		, m_nSatelliteView(0)
    		, m_dAltitude(0.0)
    		, m_szStatus(L"")
    		, m_szMode1(L"")
    		, m_nMode2(0)
    		, m_fCourseOverGround(0.0f)
    		, m_fTrueCourse(0.0f)
    		, m_fCompaseCourse(0.0f)
    		, m_fKont(0.0f)
    		, m_fKm(0.0f)
    		, m_nDay(0)
    		, m_nMonth(0)
    		, m_nYear(0)
    		, m_nHour(0)
    		, m_nMinutes(0)
    	{
    
    	}
    
    	void SetUTCTime(CString szUTC)
    	{
    		m_dUTCTime = _wtof(szUTC);
    	}
    
    	void SetLatitude(CString szLatitude)
    	{
    		m_dLatitude = _wtof(szLatitude);
    	}
    
    	void SetNS(CString szNS)
    	{
    		m_szNS = szNS;
    	}
    
    	void SetLongitude(CString szLongitude)
    	{
    		m_dLongitude = _wtof(szLongitude);
    	}
    
    	void SetEW(CString szEW)
    	{
    		m_szEW = szEW;
    	}
    
    	void SetPositionFix(CString szPositionFix)
    	{
    		m_nPositionFix = _wtoi(szPositionFix);
    	}
    
    	void SetSatelliteUsed(CString nSatelliteUsed)
    	{
    		m_nSatelliteUsed = _wtoi(nSatelliteUsed);
    	}
    
    	void SetAltitude(CString szAltitude)
    	{
    		m_dAltitude = _wtof(szAltitude);
    	}
    
    	void SetStatus(CString szStatus)
    	{
    		m_szStatus = szStatus;
    	}
    
    	bool GetStatus(void)
    	{
    		// A=data valid or V=data not valid
    		return m_szStatus == L"A" ? true : false;
    	}
    
    	void SetMode1(CString szMode1)
    	{
    		m_szMode1 = szMode1;
    	}
    
    	void SetMode2(CString szMode2)
    	{
    		m_nMode2 = _wtoi(szMode2);
    	}
    
    	void PutSatelliteUsed(CString szSatelliteUsed)
    	{
    		m_listSatelliteUsed.push_back(_wtoi(szSatelliteUsed));
    	}
    
    	void SetSatelliteView(CString nSatelliteView)
    	{
    		m_nSatelliteView = _wtoi(nSatelliteView);
    	}
    
    	void PutSatelliteView(CGSV clsSatelliteView)
    	{
    		m_listSatelliteView.push_back(clsSatelliteView);
    	}
    
    	void SetCourseOverGround(CString szCourseOverGround)
    	{
    		m_fCourseOverGround = _wtof(szCourseOverGround);
    	}
    
    	void SetTrueCourse(CString szTrueCourse)
    	{
    		m_fTrueCourse = _wtof(szTrueCourse);
    	}
    
    	void SetCompaseCourse(CString szCompaseCourse)
    	{
    		m_fCompaseCourse = _wtof(szCompaseCourse);
    	}
    
    	void SetKont(CString szKont)
    	{
    		m_fKont = _wtof(szKont);
    	}
    
    	void SetKm(CString szKm)
    	{
    		m_fKm = _wtof(szKm);
    	}
    
    	void SetDay(CString szDay)
    	{
    		m_nDay = _wtoi(szDay);
    	}
    
    	void SetMonth(CString szMonth)
    	{
    		m_nMonth = _wtoi(szMonth);
    	}
    
    	void SetYear(CString szYear)
    	{
    		m_nYear = _wtoi(szYear);
    	}
    
    	void SetHour(CString szHour)
    	{
    		m_nHour = _wtoi(szHour);
    	}
    
    	void SetMinutes(CString szMinutes)
    	{
    		m_nMinutes = _wtoi(szMinutes);
    	}
    
    	void Trace(void)
    	{
    		TRACE(L"-----------------------------------------------------\n");
    		TRACE(L"| GPS DATA                                          |\n");
    		TRACE(L"-----------------------------------------------------\n");
    		TRACE(L"| SetUTCTime		: %f\n", m_dUTCTime);
    		TRACE(L"| SetLatitude		: %f\n", m_dLatitude);
    		TRACE(L"| SetNS				: %s\n", m_szNS);
    		TRACE(L"| SetLongitude		: %f\n", m_dLongitude);
    		TRACE(L"| SetEW				: %s\n", m_szEW);
    		TRACE(L"| SetPositionFix	: %d\n", m_nPositionFix);
    		TRACE(L"| PutSatelliteUsed  : \n");
    		TRACE(L"-----------------------------------------------------\n");		
    		
    		//size_t nSize = m_listSatelliteUsed.size();
    		int i;
    		int nSize = static_cast<int>(m_listSatelliteUsed.size());
    		//list<int>::iterator it = m_listSatelliteUsed.begin();
    		//while (nSize--)
    		for (i=0; i<nSize; ++i)
    		{
    			//TRACE(L"|	SatelliteID : %d\n", *it++);
    			TRACE(L"|	SatelliteID : %d\n", m_listSatelliteUsed[i]);
    		}
    
    		TRACE(L"-----------------------------------------------------\n");
    		TRACE(L"| SatelliteView		: %d\n", m_nSatelliteView);
    		TRACE(L"-----------------------------------------------------\n");
    		
    		nSize = static_cast<int>(m_listSatelliteView.size());
    		//list<CGSV>::iterator itCGSV = m_listSatelliteView.begin();
    		//while (nSize--)
    		for (i=0; i<nSize; ++i)
    		{
    			m_listSatelliteView[i].Trace();
    			//itCGSV->Trace();
    			//itCGSV++;
    		}
    
    		TRACE(L"-----------------------------------------------------\n");
    		TRACE(L"| CourseOverGround	: %f\n", m_fCourseOverGround);
    		TRACE(L"| TrueCourse		: %f\n", m_fTrueCourse);
    		TRACE(L"| CompaseCourse		: %f\n", m_fCompaseCourse);
    		TRACE(L"| Kont				: %f\n", m_fKont);
    		TRACE(L"| Km				: %f\n", m_fKm);
    		TRACE(L"| Day				: %d\n", m_nDay);
    		TRACE(L"| Month				: %d\n", m_nMonth);
    		TRACE(L"| Year				: %d\n", m_nYear);
    		TRACE(L"| Hour				: %d\n", m_nHour);
    		TRACE(L"| Minutes			: %d\n", m_nMinutes);
    		TRACE(L"-----------------------------------------------------\n");
    	}
    };
    
    class CGPSFix
    {
    public:
    	CGPSFix(void)
    	{
    
    	}
    
    	bool GetGPSStatus(CString szData)
    	{
    		//
    		// GPS 가 FIX되어 있는지 검사를 해보자.
    		//
    		if (szData.Find(L"+GPSFIXREQ: 1") != -1)
    		{
    			return true;
    		}
    
    		return false;
    	}
    
    };
    
    class CNMEAParser
    {
    public:
    	CNMEAParser(void);
    	~CNMEAParser(void);
    
    protected:
    	CString m_szFullText;
    	//bool m_bIndex;
    	//list<CString> m_Type;
    	vector<CString> m_Type;
    	
    	// serial로 받은 데이터 각 label로 분리시킨
    	// 변수들
    	map<CString, CString> m_Divide;
    	vector<CString> m_GSV;
    	//list<CString> m_GSV;
    	//list<CString>::iterator it;
    	void ParsingGGA(void);
    	void ParsingGLL(void);
    	void ParsingGSA(void);
    	void ParsingGSV(void);
    	void ParsingRMC(void);
    	void ParsingVTG(void);
    	void ParsingZDA(void);
    
    public:
    	CNMEAData m_nmeaData;
    
    public:
    	virtual void SetDefineType(void);
    	//void SetFullText(CString szFullText);
    	void Parsing(CString szFullText);
    	virtual void Divide(void);
    	void TraceDivide(void);
    	//void SetQueue(int nSize);
    	void NMEATrace(void);
    	CString GetDivideString(CString szString);
    	bool IsGpsData(void);
    };
    
    class CLocationTrackingParser : public CNMEAParser
    {
    public:
    	CLocationTrackingParser(void);
    	~CLocationTrackingParser(void);
    
    protected:
    	vector<CNMEAData> m_nmeaData;
    };
    

    Comment


    입력하3 1498665007



    Locations of visitors to this page