21 NmeaException(context,
"NMEA 2000 PGN is invalid", details) {}
30 NmeaException(context,
"NMEA 2000 CAN frame is invalid", details) {}
39 NmeaException(context,
"NMEA 2000 CAN frame exceeds maximum length of 223 bytes", details) {}
82 const std::vector<uint8_t>&
getCanId() const noexcept;
87 const std::vector<uint8_t>&
getCanFrame() const noexcept;
169 uint32_t
getPgn() const noexcept;
192 virtual
bool operator==(const
Message2000& other) const noexcept;
211 TimePoint ts = std::chrono::system_clock::now());
216 std::
string toString(
bool verbose) const noexcept;
221 std::vector<uint8_t> canId,
222 std::vector<uint8_t> canFrame) noexcept;
229 static uint32_t extractPgnFromCanId(const std::vector<uint8_t>& canId) noexcept;
234 static
bool isValidPgn(uint32_t pgn) noexcept;
Defines a base class for NMEA messages, encapsulating common properties and behaviors.
std::chrono::system_clock::time_point TimePoint
Base exception class for all NMEA library errors.
Exception thrown when the CAN frame is invalid.
InvalidCanFrameException(const std::string &context, const std::string &details="")
Exception thrown when an NMEA 2000 PGN is outside the valid range.
InvalidPgnException(const std::string &context, const std::string &details="")
Represents a generic NMEA 2000 message encapsulating a CAN frame.
uint8_t getSourceAddress() const noexcept
Returns the source address of the transmitting device.
Message2000(const Message2000 &)=default
std::vector< uint8_t > canId_
29-bit CAN Id stored as 4 bytes (big-endian)
Message2000(Message2000 &&) noexcept=default
const std::vector< uint8_t > & getCanFrame() const noexcept
Returns the raw CAN frame payload (0-223 bytes).
bool getPriority2() const noexcept
Bit 3 of canId_[0].
std::string serialize() const override
Serializes the message to "CANID:data" hex format.
std::vector< uint8_t > canFrame_
CAN frame payload (0-223 bytes)
uint32_t getPgn() const noexcept
Returns the PGN (Parameter Group Number) extracted from the CAN Id.
bool getPriority3() const noexcept
Returns individual priority bits (P3 is the MSB).
uint8_t getPDUSpecific() const noexcept
Returns the PDU Specific byte (PS).
bool validate() const override
Returns true if the PGN fits in 18 bits and the frame is 0-223 bytes.
bool getHeaderReserved() const noexcept
Returns the Reserved bit (R1).
bool getDataPage() const noexcept
Returns the Data Page bit (DP).
std::string toString(bool verbose) const noexcept
Returns the base string common to all PGNs (used by getStringContent).
std::unique_ptr< nmealib::Message > clone() const override
Creates a polymorphic deep copy of this Message2000.
uint8_t getPDUFormat() const noexcept
Returns the PDU Format byte (PF).
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.
virtual std::string getStringContent(bool verbose) const noexcept
Returns a human-readable string representation of the message.
const std::vector< uint8_t > & getCanId() const noexcept
Returns the 29-bit CAN identifier as 4 bytes (big-endian).
uint8_t getCanFrameLength() const noexcept
Returns the number of bytes in the CAN frame payload.
Message2000 & operator=(const Message2000 &)=default
bool getPriority1() const noexcept
Bit 2 of canId_[0].
uint8_t getDestinationAddress() const noexcept
Returns the destination address.
uint8_t getPriority() const noexcept
Returns the 3-bit message priority (0 = highest, 7 = lowest).