nmealib 0.0.4
NMEA 0183/NMEA 2000 parsing library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
nmealib::nmea0183::Message0183 Class Reference

Represents an NMEA 0183 sentence. More...

#include <nmea0183.h>

Inheritance diagram for nmealib::nmea0183::Message0183:
Inheritance graph
[legend]
Collaboration diagram for nmealib::nmea0183::Message0183:
Collaboration graph
[legend]

Public Member Functions

 Message0183 (const Message0183 &)=default
 Copy constructor.
 
Message0183operator= (const Message0183 &)=default
 Copy assignment operator.
 
 Message0183 (Message0183 &&) noexcept=default
 Move constructor.
 
Message0183operator= (Message0183 &&) noexcept=default
 Move assignment operator.
 
 ~Message0183 () override=default
 Destructor.
 
std::unique_ptr< nmealib::Messageclone () const override
 Creates a polymorphic deep copy of this Message0183.
 
char getStartChar () const noexcept
 Returns the start character of the NMEA 0183 sentence.
 
std::string getTalker () const noexcept
 Returns the talker identifier extracted from the sentence.
 
std::string getSentenceType () const noexcept
 Returns the sentence type identifier extracted from the sentence.
 
std::string getPayload () const noexcept
 Returns the payload of the NMEA 0183 sentence.
 
std::string getChecksumStr () const
 Get the checksum string extracted from the raw sentence.
 
std::string getCalculatedChecksumStr () const noexcept
 Get the calculated checksum string for the sentence payload.
 
virtual std::string getStringContent (bool verbose) const noexcept
 Returns a human-readable string representation of the message content.
 
std::string serialize () const override
 Returns the wire-format representation of the NMEA 0183 sentence, that is, the raw information that was passed when the message was created.
 
bool operator== (const Message0183 &other) const noexcept
 Compares two Message0183 objects for equality based on their content and timestamp.
 
bool validate () const noexcept override
 Returns whether the message is valid or not.
 
- Public Member Functions inherited from nmealib::Message
 Message ()
 
 Message (std::string raw, Type type=Type::Unknown, TimePoint ts=std::chrono::system_clock::now()) noexcept
 
virtual ~Message ()
 
 Message (const Message &)=default
 
Messageoperator= (const Message &)=default
 
 Message (Message &&) noexcept=default
 
Messageoperator= (Message &&) noexcept=default
 
Type getType () const noexcept
 Returns the message type.
 
const std::string & getRawData () const noexcept
 Returns the raw, unmodified data string as received.
 
TimePoint getTimestamp () const noexcept
 Returns the timestamp associated with this message.
 
bool operator== (const Message &other) const noexcept
 Compares two Message objects for equality based on their content.
 

Static Public Member Functions

static double convertNmeaCoordinateToDecimalDegrees (const std::string &nmeaCoordinate)
 Converts an NMEA coordinate in ddmm.mmmm / dddmm.mmmm format to decimal degrees.
 
- Static Public Member Functions inherited from nmealib::Message
static std::string typeToString (Type t)
 Converts a Message::Type enum value to its string representation.
 

Protected Member Functions

std::string toString (bool verbose) const noexcept
 Provides the common string representation for every NMEA 0183 message, which can be used by derived classes to implement their own getStringContent method.
 
- Protected Member Functions inherited from nmealib::Message
void setType (Type t) noexcept
 Sets the message type.
 
void setRaw (std::string r) noexcept
 Sets the raw data string.
 
void setTimestamp (TimePoint ts) noexcept
 Sets the message timestamp.
 

Static Protected Member Functions

static std::unique_ptr< Message0183create (const std::string &raw, TimePoint ts=std::chrono::system_clock::now())
 Protected factory method to create a Message0183 from a raw sentence string.
 

Protected Attributes

char startChar_
 
std::string talker_
 
std::string sentenceType_
 
std::string payload_
 
std::string checksumStr_
 
std::string calculatedChecksumStr_
 
- Protected Attributes inherited from nmealib::Message
std::string rawData_
 
Type type_ {Type::Unknown}
 
TimePoint timestamp_ {}
 

Friends

class Nmea0183Factory
 

Additional Inherited Members

- Public Types inherited from nmealib::Message
enum class  Type { Unknown , NMEA0183 , NMEA2000 }
 Defines the type of NMEA message, allowing for differentiation between various standards. More...
 
using TimePoint = std::chrono::system_clock::time_point
 

Detailed Description

Represents an NMEA 0183 sentence.

Attention
NMEA 0183 sentences are ASCII text strings that follow a specific format:
  • Messages have a maximum length of 82 characters, including the $ or ! starting character and the ending <LF>
  • The start character for each message can be either a $ (For conventional field delimited messages) or ! (for messages that have special encapsulation in them)
  • The next five characters identify the talker (two characters) and the type of message (three characters).
  • All data fields that follow are comma-delimited.
  • Where data is unavailable, the corresponding field remains blank
  • The first character that immediately follows the last data field character is an asterisk, but it is only included if a checksum is supplied.
  • The asterisk is immediately followed by a checksum represented as a two-digit hexadecimal number.
  • <CR><LF> ends the message.

Definition at line 98 of file nmea0183.h.

Constructor & Destructor Documentation

◆ Message0183() [1/2]

nmealib::nmea0183::Message0183::Message0183 ( const Message0183 )
default

Copy constructor.

◆ Message0183() [2/2]

nmealib::nmea0183::Message0183::Message0183 ( Message0183 &&  )
defaultnoexcept

Move constructor.

◆ ~Message0183()

nmealib::nmea0183::Message0183::~Message0183 ( )
overridedefault

Destructor.

Member Function Documentation

◆ clone()

std::unique_ptr< nmealib::Message > nmealib::nmea0183::Message0183::clone ( ) const
overridevirtual

Creates a polymorphic deep copy of this Message0183.

Returns
std::unique_ptr<nmealib::Message> A unique pointer to the cloned message.

Implements nmealib::Message.

Reimplemented in nmealib::nmea0183::MTW, nmealib::nmea0183::MWV, nmealib::nmea0183::RMA, nmealib::nmea0183::RMB, nmealib::nmea0183::RMC, nmealib::nmea0183::VHW, nmealib::nmea0183::VLW, nmealib::nmea0183::VTG, nmealib::nmea0183::VWR, nmealib::nmea0183::XDR, nmealib::nmea0183::XTE, and nmealib::nmea0183::ZDA.

Definition at line 105 of file nmea0183.cpp.

◆ convertNmeaCoordinateToDecimalDegrees()

double nmealib::nmea0183::Message0183::convertNmeaCoordinateToDecimalDegrees ( const std::string &  nmeaCoordinate)
static

Converts an NMEA coordinate in ddmm.mmmm / dddmm.mmmm format to decimal degrees.

Parameters
nmeaCoordinateCoordinate field as received from the sentence payload.
Returns
double Decimal degrees representation.

Definition at line 194 of file nmea0183.cpp.

◆ create()

std::unique_ptr< Message0183 > nmealib::nmea0183::Message0183::create ( const std::string &  raw,
TimePoint  ts = std::chrono::system_clock::now() 
)
staticprotected

Protected factory method to create a Message0183 from a raw sentence string.

Validates format and parses the raw sentence. Intended to be called from Nmea0183Factory or derived-class factories.

Parameters
rawThe raw NMEA 0183 sentence string to parse and validate.
tsOptional timestamp; defaults to the current system time.
Returns
std::unique_ptr<Message0183> A unique pointer to the created Message0183 instance.
Exceptions
TooLongSentenceExceptionIf the input string exceeds the maximum allowed length of 82 characters.
InvalidStartCharacterExceptionIf the input string does not start with either '$' or '!'.

Definition at line 47 of file nmea0183.cpp.

◆ getCalculatedChecksumStr()

std::string nmealib::nmea0183::Message0183::getCalculatedChecksumStr ( ) const
noexcept

Get the calculated checksum string for the sentence payload.

Returns
std::string The checksum string calculated from the payload of the NMEA 0183 sentence, represented as a two-digit hexadecimal string.

Definition at line 132 of file nmea0183.cpp.

◆ getChecksumStr()

std::string nmealib::nmea0183::Message0183::getChecksumStr ( ) const

Get the checksum string extracted from the raw sentence.

Returns
std::string The checksum string extracted from the raw NMEA 0183 sentence, if present.
Exceptions
NoChecksumExceptionIf the sentence does not contain a checksum (i.e., no '*' character followed by two hex digits).

Definition at line 125 of file nmea0183.cpp.

◆ getPayload()

std::string nmealib::nmea0183::Message0183::getPayload ( ) const
noexcept

Returns the payload of the NMEA 0183 sentence.

The payload is the portion of the sentence between the start character and the checksum delimiter '*' (or end of data if no checksum is present).

Returns
std::string The sentence payload string.

Definition at line 109 of file nmea0183.cpp.

◆ getSentenceType()

std::string nmealib::nmea0183::Message0183::getSentenceType ( ) const
noexcept

Returns the sentence type identifier extracted from the sentence.

Returns
std::string A three-character sentence type code (e.g., "GGA", "RMC").

Definition at line 121 of file nmea0183.cpp.

◆ getStartChar()

char nmealib::nmea0183::Message0183::getStartChar ( ) const
noexcept

Returns the start character of the NMEA 0183 sentence.

Returns
char Either '$' (field-delimited) or '!' (encapsulated) sentence start character.

Definition at line 113 of file nmea0183.cpp.

◆ getStringContent()

std::string nmealib::nmea0183::Message0183::getStringContent ( bool  verbose) const
virtualnoexcept

Returns a human-readable string representation of the message content.

Parameters
verboseSelects whether to print a one-liner or a more detailed multi-line string with field names and values.
Returns
std::string The string representation of the message content

Reimplemented in nmealib::nmea0183::APB, nmealib::nmea0183::DBT, nmealib::nmea0183::DPT, nmealib::nmea0183::GGA, nmealib::nmea0183::GLL, nmealib::nmea0183::GSA, nmealib::nmea0183::GSV, nmealib::nmea0183::HDG, nmealib::nmea0183::HDM, nmealib::nmea0183::MTW, nmealib::nmea0183::MWV, nmealib::nmea0183::RMA, nmealib::nmea0183::RMB, nmealib::nmea0183::RMC, nmealib::nmea0183::VHW, nmealib::nmea0183::VLW, nmealib::nmea0183::VTG, nmealib::nmea0183::VWR, nmealib::nmea0183::XDR, nmealib::nmea0183::XTE, and nmealib::nmea0183::ZDA.

Definition at line 136 of file nmea0183.cpp.

◆ getTalker()

std::string nmealib::nmea0183::Message0183::getTalker ( ) const
noexcept

Returns the talker identifier extracted from the sentence.

Returns
std::string A two-character talker ID (e.g., "GP" for GPS, "II" for integrated instrumentation).

Definition at line 117 of file nmea0183.cpp.

◆ operator=() [1/2]

Message0183 & nmealib::nmea0183::Message0183::operator= ( const Message0183 )
default

Copy assignment operator.

◆ operator=() [2/2]

Message0183 & nmealib::nmea0183::Message0183::operator= ( Message0183 &&  )
defaultnoexcept

Move assignment operator.

◆ operator==()

bool nmealib::nmea0183::Message0183::operator== ( const Message0183 other) const
noexcept

Compares two Message0183 objects for equality based on their content and timestamp.

Parameters
otherThe other Message0183 object to compare with.
Returns
true If all fields and the base Message data (including timestamp) are equal.
false Otherwise.

Definition at line 204 of file nmea0183.cpp.

◆ serialize()

std::string nmealib::nmea0183::Message0183::serialize ( ) const
overridevirtual

Returns the wire-format representation of the NMEA 0183 sentence, that is, the raw information that was passed when the message was created.

Returns
std::string A string with the wire-format

Implements nmealib::Message.

Definition at line 168 of file nmea0183.cpp.

◆ toString()

std::string nmealib::nmea0183::Message0183::toString ( bool  verbose) const
protectednoexcept

Provides the common string representation for every NMEA 0183 message, which can be used by derived classes to implement their own getStringContent method.

Parameters
verboseSelects wether to print a one-liner or a more detailed multi-line string with field names and values.
Returns
std::string the head of the stringified message

Definition at line 147 of file nmea0183.cpp.

◆ validate()

bool nmealib::nmea0183::Message0183::validate ( ) const
overridevirtualnoexcept

Returns whether the message is valid or not.

Returns
true If there is no checksum or if the checksum matches the calculated checksum for the payload
false If there is a checksum and it does not match the calculated checksum for the payload

Implements nmealib::Message.

Definition at line 172 of file nmea0183.cpp.

Friends And Related Symbol Documentation

◆ Nmea0183Factory

friend class Nmea0183Factory
friend

Definition at line 268 of file nmea0183.h.

Member Data Documentation

◆ calculatedChecksumStr_

std::string nmealib::nmea0183::Message0183::calculatedChecksumStr_
protected

Definition at line 225 of file nmea0183.h.

◆ checksumStr_

std::string nmealib::nmea0183::Message0183::checksumStr_
protected

Definition at line 224 of file nmea0183.h.

◆ payload_

std::string nmealib::nmea0183::Message0183::payload_
protected

Definition at line 223 of file nmea0183.h.

◆ sentenceType_

std::string nmealib::nmea0183::Message0183::sentenceType_
protected

Definition at line 222 of file nmea0183.h.

◆ startChar_

char nmealib::nmea0183::Message0183::startChar_
protected

Definition at line 220 of file nmea0183.h.

◆ talker_

std::string nmealib::nmea0183::Message0183::talker_
protected

Definition at line 221 of file nmea0183.h.


The documentation for this class was generated from the following files: