Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[gps] Add support for GPHDT heading from true north messages
(cherry picked from commit 6b5f983)
  • Loading branch information
nyalldawson authored and nirvn committed Dec 6, 2019
1 parent cc68811 commit 71c9503
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
34 changes: 34 additions & 0 deletions external/nmea/parse.c
Expand Up @@ -436,6 +436,40 @@ int nmea_parse_GPRMC( const char *buff, int buff_sz, nmeaGPRMC *pack )
return 1;
}

/**
* \brief Parse HDT packet from buffer.
* @param buff a constant character pointer of packet buffer.
* @param buff_sz buffer size.
* @param pack a pointer of packet which will filled by function.
* @return 1 (true) - if parsed successfully or 0 (false) - if fail.
*/
int nmea_parse_GPHDT( const char *buff, int buff_sz, nmeaGPHDT *pack )
{
NMEA_ASSERT( buff && pack );

memset( pack, 0, sizeof( nmeaGPHDT ) );

nmea_trace_buff( buff, buff_sz );

char type;

if ( 2 != nmea_scanf( buff, buff_sz,
"$GPHDT,%f,%C*",
&( pack->heading ), &( type ) ) )
{
nmea_error( "GPHDT parse error!" );
return 0;
}

if ( type != 'T' )
{
nmea_error( "GPHDT invalid type " );
return 0;
}

return 1;
}

/**
* \brief Parse VTG packet from buffer.
* @param buff a constant character pointer of packet buffer.
Expand Down
1 change: 1 addition & 0 deletions external/nmea/parse.h
Expand Up @@ -43,6 +43,7 @@ int nmea_parse_GPGSA( const char *buff, int buff_sz, nmeaGPGSA *pack );
int nmea_parse_GPGSV( const char *buff, int buff_sz, nmeaGPGSV *pack );
int nmea_parse_GPRMC( const char *buff, int buff_sz, nmeaGPRMC *pack );
int nmea_parse_GPVTG( const char *buff, int buff_sz, nmeaGPVTG *pack );
int nmea_parse_GPHDT( const char *buff, int buff_sz, nmeaGPHDT *pack );

void nmea_GPGGA2info( nmeaGPGGA *pack, nmeaINFO *info );
void nmea_GPGST2info( nmeaGPGST *pack, nmeaINFO *info );
Expand Down
11 changes: 11 additions & 0 deletions external/nmea/sentence.h
Expand Up @@ -133,6 +133,17 @@ typedef struct _nmeaGPVTG

} nmeaGPVTG;

/**
* HDT packet information structure (Heading from True North)
*/
typedef struct _nmeaGPHDT
{
double heading; //!< Heading in degrees
char dir_t; //!< Fixed text 'T' indicates that heading is relative to true north

} nmeaGPHDT;


void nmea_zero_GPGGA( nmeaGPGGA *pack );
void nmea_zero_GPGST( nmeaGPGST *pack );
void nmea_zero_GPGSA( nmeaGPGSA *pack );
Expand Down
5 changes: 4 additions & 1 deletion python/core/auto_generated/gps/qgsnmeaconnection.sip.in
Expand Up @@ -63,7 +63,10 @@ process GSA sentence
%Docstring
process GST sentence
%End

void processHdtSentence( const char *data, int len );
%Docstring
process HDT sentence
%End
};

/************************************************************************
Expand Down
20 changes: 20 additions & 0 deletions src/core/gps/qgsnmeaconnection.cpp
Expand Up @@ -136,6 +136,17 @@ void QgsNmeaConnection::processStringBuffer()
mStatus = GPSDataReceived;
QgsDebugMsg( QStringLiteral( "*******************GPS data received****************" ) );
}
else if ( substring.startsWith( QLatin1String( "$GPHDT" ) ) )
{
QgsDebugMsgLevel( substring, 2 );
processHdtSentence( ba.data(), ba.length() );
mStatus = GPSDataReceived;
QgsDebugMsgLevel( QStringLiteral( "*******************GPS data received****************" ), 2 );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "unknown nmea sentence: %1" ).arg( substring ), 2 );
}
emit nmeaSentenceReceived( substring ); // added to be able to save raw data
}
}
Expand Down Expand Up @@ -185,6 +196,15 @@ void QgsNmeaConnection::processGstSentence( const char *data, int len )
}
}

void QgsNmeaConnection::processHdtSentence( const char *data, int len )
{
nmeaGPHDT result;
if ( nmea_parse_GPHDT( data, len, &result ) )
{
mLastGPSInformation.direction = result.heading;
}
}

void QgsNmeaConnection::processRmcSentence( const char *data, int len )
{
nmeaGPRMC result;
Expand Down
3 changes: 2 additions & 1 deletion src/core/gps/qgsnmeaconnection.h
Expand Up @@ -58,7 +58,8 @@ class CORE_EXPORT QgsNmeaConnection: public QgsGpsConnection
void processGsaSentence( const char *data, int len );
//! process GST sentence
void processGstSentence( const char *data, int len );

//! process HDT sentence
void processHdtSentence( const char *data, int len );
};

#endif // QGSNMEACONNECTION_H

0 comments on commit 71c9503

Please sign in to comment.