|
nmealib 0.0.4
NMEA 0183/NMEA 2000 parsing library
|
Represents a generic NMEA 2000 message encapsulating a CAN frame. More...
#include <nmea2000.h>


Public Member Functions | |
| Message2000 (const Message2000 &)=default | |
| Message2000 & | operator= (const Message2000 &)=default |
| Message2000 (Message2000 &&) noexcept=default | |
| Message2000 & | operator= (Message2000 &&)=default |
| ~Message2000 () override=default | |
| std::unique_ptr< nmealib::Message > | clone () const override |
| Creates a polymorphic deep copy of this Message2000. | |
| const std::vector< uint8_t > & | getCanId () const noexcept |
| Returns the 29-bit CAN identifier as 4 bytes (big-endian). | |
| const std::vector< uint8_t > & | getCanFrame () const noexcept |
| Returns the raw CAN frame payload (0-223 bytes). | |
| uint8_t | getCanFrameLength () const noexcept |
| Returns the number of bytes in the CAN frame payload. | |
| uint8_t | getPriority () const noexcept |
| Returns the 3-bit message priority (0 = highest, 7 = lowest). | |
| bool | getPriority3 () const noexcept |
| Returns individual priority bits (P3 is the MSB). | |
| bool | getPriority2 () const noexcept |
| Bit 3 of canId_[0]. | |
| bool | getPriority1 () const noexcept |
| Bit 2 of canId_[0]. | |
| bool | getHeaderReserved () const noexcept |
| Returns the Reserved bit (R1). | |
| bool | getDataPage () const noexcept |
| Returns the Data Page bit (DP). | |
| uint8_t | getPDUFormat () const noexcept |
| Returns the PDU Format byte (PF). | |
| uint8_t | getPDUSpecific () const noexcept |
| Returns the PDU Specific byte (PS). | |
| uint8_t | getSourceAddress () const noexcept |
| Returns the source address of the transmitting device. | |
| uint8_t | getDestinationAddress () const noexcept |
| Returns the destination address. | |
| uint32_t | getPgn () const noexcept |
| Returns the PGN (Parameter Group Number) extracted from the CAN Id. | |
| virtual std::string | getStringContent (bool verbose) const noexcept |
| Returns a human-readable string representation of the message. | |
| std::string | serialize () const override |
| Serializes the message to "CANID:data" hex format. | |
| virtual bool | operator== (const Message2000 &other) const noexcept |
| bool | validate () const override |
| Returns true if the PGN fits in 18 bits and the frame is 0-223 bytes. | |
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 | |
| Message & | operator= (const Message &)=default |
| Message (Message &&) noexcept=default | |
| Message & | operator= (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. | |
Protected Member Functions | |
| std::string | toString (bool verbose) const noexcept |
| Returns the base string common to all PGNs (used by getStringContent). | |
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< Message2000 > | create (std::string raw, TimePoint ts=std::chrono::system_clock::now()) |
| Protected factory — parses "CANID:data" (and variant formats) into a Message2000. | |
Protected Attributes | |
| std::vector< uint8_t > | canId_ |
| 29-bit CAN Id stored as 4 bytes (big-endian) | |
| std::vector< uint8_t > | canFrame_ |
| CAN frame payload (0-223 bytes) | |
Protected Attributes inherited from nmealib::Message | |
| std::string | rawData_ |
| Type | type_ {Type::Unknown} |
| TimePoint | timestamp_ {} |
Friends | |
| class | Nmea2000Factory |
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 |
Static Public Member Functions inherited from nmealib::Message | |
| static std::string | typeToString (Type t) |
| Converts a Message::Type enum value to its string representation. | |
Represents a generic NMEA 2000 message encapsulating a CAN frame.
An NMEA 2000 message is built on the CAN 2.0B protocol (29-bit extended identifier). The 29-bit CAN Id is stored as 4 bytes (big-endian, value right-aligned):
canId_[0]: [ 0 0 0 P3 P2 P1 R1 DP ] canId_[1]: [PF8 PF7 PF6 PF5 PF4 PF3 PF2 PF1] ← PDU Format canId_[2]: [PS8 PS7 PS6 PS5 PS4 PS3 PS2 PS1] ← PDU Specific canId_[3]: [SA8 SA7 SA6 SA5 SA4 SA3 SA2 SA1] ← Source Address
PGN extraction follows the ISO 11783 / NMEA 2000 rules:
RTR and DLC are CAN bus framing fields managed by hardware/drivers and are NOT part of the 29-bit CAN Id; they are not stored here.
Payload: up to 223 bytes (single-frame: 0-8 bytes, fast-packet: 0-223 bytes).
Definition at line 62 of file nmea2000.h.
|
default |
|
defaultnoexcept |
|
overridedefault |
|
overridevirtual |
Creates a polymorphic deep copy of this Message2000.
Implements nmealib::Message.
Reimplemented in nmealib::nmea2000::PGN127245, nmealib::nmea2000::PGN127250, nmealib::nmea2000::PGN127251, nmealib::nmea2000::PGN127257, nmealib::nmea2000::PGN128001, nmealib::nmea2000::PGN128259, nmealib::nmea2000::PGN129025, nmealib::nmea2000::PGN129026, and nmealib::nmea2000::PGN130306.
Definition at line 242 of file nmea2000.cpp.
|
staticprotected |
Protected factory — parses "CANID:data" (and variant formats) into a Message2000.
| InvalidCanFrameException | If the format is unrecognized. |
| InvalidPgnException | If the extracted PGN exceeds 18 bits. |
| FrameTooLongException | If the payload exceeds 223 bytes. |
Definition at line 109 of file nmea2000.cpp.
|
noexcept |
Returns the raw CAN frame payload (0-223 bytes).
Definition at line 308 of file nmea2000.cpp.
|
noexcept |
Returns the number of bytes in the CAN frame payload.
Definition at line 312 of file nmea2000.cpp.
|
noexcept |
Returns the 29-bit CAN identifier as 4 bytes (big-endian).
Definition at line 304 of file nmea2000.cpp.
|
noexcept |
|
noexcept |
Returns the destination address.
For PDU1 messages (PF < 0xF0) this is getPDUSpecific(). For PDU2 messages the destination is always 255 (global).
Definition at line 283 of file nmea2000.cpp.
|
noexcept |
Returns the Reserved bit (R1).
Always 0 in NMEA 2000; non-zero in J1939. Bit 1 of canId_[0]
Definition at line 266 of file nmea2000.cpp.
|
noexcept |
Returns the PDU Format byte (PF).
Determines addressing mode: PF < 0xF0 → PDU1 (addressed): canId_[2] is the destination address. PF >= 0xF0 → PDU2 (broadcast): canId_[2] is the PGN group extension. canId_[1]
Definition at line 272 of file nmea2000.cpp.
|
noexcept |
Returns the PDU Specific byte (PS).
Interpretation depends on PDU Format (see getPDUFormat()). canId_[2]
Definition at line 276 of file nmea2000.cpp.
|
noexcept |
Returns the PGN (Parameter Group Number) extracted from the CAN Id.
The PGN fits in 18 bits (0x00000 - 0x3FFFF).
Definition at line 296 of file nmea2000.cpp.
|
noexcept |
Returns the 3-bit message priority (0 = highest, 7 = lowest).
Definition at line 256 of file nmea2000.cpp.
|
noexcept |
Bit 2 of canId_[0].
Definition at line 263 of file nmea2000.cpp.
|
noexcept |
Bit 3 of canId_[0].
Definition at line 262 of file nmea2000.cpp.
|
noexcept |
Returns individual priority bits (P3 is the MSB).
Bit 4 of canId_[0]
Definition at line 261 of file nmea2000.cpp.
|
noexcept |
Returns the source address of the transmitting device.
0-253 = valid node address, 254 = anonymous, 255 = broadcast/global. canId_[3]
Definition at line 279 of file nmea2000.cpp.
|
virtualnoexcept |
Returns a human-readable string representation of the message.
Verbose: multi-line dump of all fields. Non-verbose: single-line summary.
Reimplemented in nmealib::nmea2000::PGN127245, nmealib::nmea2000::PGN127250, nmealib::nmea2000::PGN127251, nmealib::nmea2000::PGN127257, nmealib::nmea2000::PGN128001, nmealib::nmea2000::PGN128259, nmealib::nmea2000::PGN129025, nmealib::nmea2000::PGN129026, and nmealib::nmea2000::PGN130306.
Definition at line 320 of file nmea2000.cpp.
|
default |
|
default |
|
virtualnoexcept |
Reimplemented in nmealib::nmea2000::PGN127245, nmealib::nmea2000::PGN127250, nmealib::nmea2000::PGN127251, nmealib::nmea2000::PGN127257, nmealib::nmea2000::PGN128001, nmealib::nmea2000::PGN128259, nmealib::nmea2000::PGN129025, nmealib::nmea2000::PGN129026, and nmealib::nmea2000::PGN130306.
Definition at line 401 of file nmea2000.cpp.
|
overridevirtual |
Serializes the message to "CANID:data" hex format.
Implements nmealib::Message.
Definition at line 380 of file nmea2000.cpp.
|
protectednoexcept |
Returns the base string common to all PGNs (used by getStringContent).
Definition at line 337 of file nmea2000.cpp.
|
overridevirtual |
Returns true if the PGN fits in 18 bits and the frame is 0-223 bytes.
Implements nmealib::Message.
Definition at line 407 of file nmea2000.cpp.
|
friend |
Definition at line 236 of file nmea2000.h.
|
protected |
CAN frame payload (0-223 bytes)
Definition at line 201 of file nmea2000.h.
|
protected |
29-bit CAN Id stored as 4 bytes (big-endian)
Definition at line 200 of file nmea2000.h.