📄 nmeaparser.cpp
字号:
/************************************************************************/
/* Bluteooth Test The.Berlin.Factor Juni 2003 */
/************************************************************************/
#include <E32Math.h>
#include "gps/nmea/NmeaParser.h"
void CNmeaParser::SetData( TDesC8 & aNmeaMessage ) {
iMessage = &aNmeaMessage;
iParsePosition = 0;
}
void CNmeaParser::GetNextTokenIntoL( TDes8 & aBuffer ) {
if ( iMessage == NULL )
User::Leave( KErrNotReady );
if ( iParsePosition >= iMessage->Length( ) )
User::Leave( KErrNotFound );
while ( iParsePosition < iMessage->Length( ) ) {
TUint8 nextChar = ( *iMessage )[ iParsePosition++ ];
if ( nextChar == ',' )
break;
aBuffer.Append( nextChar );
}
}
void CNmeaParser::SkipNextTokenL( ) {
if ( iMessage == NULL )
User::Leave( KErrNotReady );
if ( iParsePosition >= iMessage->Length( ) )
User::Leave( KErrNotFound );
while ( iParsePosition < iMessage->Length( ) ) {
TUint8 nextChar = ( *iMessage )[ iParsePosition++ ];
if ( nextChar == ',' )
break;
}
}
TReal CNmeaParser::GetNextTokensAsLatitudeL( ) {
TReal angle;
TBuf8< 15 > angleString;
GetNextTokenIntoL( angleString );
TBuf8< 5 > northSouth;
GetNextTokenIntoL( northSouth );
TLex8 latLexer( angleString );
TInt error = latLexer.Val( angle, '.' );
if ( error != KErrNone )
User::Leave( error );
TInt32 degrees;
Math::Int( degrees, angle / 100.0 );
TInt32 minutes;
Math::Int( minutes, angle - degrees * 100 );
TReal decimal;
Math::Frac( decimal, angle );
TReal latitude = degrees + ( minutes + decimal ) / 60.0;
if ( northSouth[ 0 ] == 'S' )
latitude = -latitude;
return( latitude );
}
TReal CNmeaParser::GetNextTokensAsLongitudeL( ) {
TReal angle;
TBuf8< 15 > angleString;
GetNextTokenIntoL( angleString );
TBuf8< 5 > northSouth;
GetNextTokenIntoL( northSouth );
TLex8 latLexer( angleString );
TInt error = latLexer.Val( angle, '.' );
if ( error != KErrNone )
User::Leave( error );
TInt32 degrees;
Math::Int( degrees, angle / 100.0 );
TInt32 minutes;
Math::Int( minutes, angle - degrees * 100 );
TReal decimal;
Math::Frac( decimal, angle );
TReal longitude = degrees + ( minutes + decimal ) / 60.0;
if ( northSouth[ 0 ] == 'W' )
longitude = -longitude;
return( longitude );
}
TInt CNmeaParser::GetNextTokenAsIntL( ) {
TInt result = 0;
TBuf8< 10 > intString;
GetNextTokenIntoL( intString );
TLex8 lexer( intString );
User::LeaveIfError( lexer.Val( result ) );
return( result );
}
TReal CNmeaParser::GetNextTokenAsRealL( ) {
TReal result = 0;
TBuf8< 10 > realString;
GetNextTokenIntoL( realString );
TLex8 lexer( realString );
User::LeaveIfError( lexer.Val( result ) );
return( result );
}
void CNmeaParser::ClearData( ) {
iMessage = NULL;
iParsePosition = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -