8std::unique_ptr<PGN127251> PGN127251::create(std::unique_ptr<Message2000> baseMessage) {
9 if (baseMessage->getCanFrameLength() != 8) {
10 std::string context =
"PGN127251::create()";
11 NMEALIB_RETURN_ERROR(InvalidCanFrameException(context,
"CAN frame must be 8 bytes for PGN127251"));
14 const uint8_t sequenceId = baseMessage->getCanFrame()[0];
15 const uint32_t rawRateBits =
static_cast<uint32_t
>(baseMessage->getCanFrame()[1]) |
16 (
static_cast<uint32_t
>(baseMessage->getCanFrame()[2]) << 8) |
17 (
static_cast<uint32_t
>(baseMessage->getCanFrame()[3]) << 16) |
18 (
static_cast<uint32_t
>(baseMessage->getCanFrame()[4]) << 24);
24 return std::unique_ptr<PGN127251>(
new PGN127251(std::move(*baseMessage),
32PGN127251::PGN127251(Message2000 baseMessage,
37 Byte reserved3) noexcept :
38 Message2000(std::move(baseMessage)),
39 sequenceId_(sequenceId),
41 reserved1_(reserved1),
42 reserved2_(reserved2),
43 reserved3_(reserved3) {}
45PGN127251::PGN127251(uint8_t sequenceId,
49 Byte reserved3) noexcept :
55 sequenceId_(sequenceId),
57 reserved1_(reserved1),
58 reserved2_(reserved2),
59 reserved3_(reserved3) {}
62 return std::unique_ptr<PGN127251>(
new PGN127251(*
this));
66 std::ostringstream oss;
69 oss << this->toString(
true);
72 oss <<
"\tSequence ID: " <<
static_cast<int>(sequenceId_) <<
"\n";
73 oss <<
"\tRate: " << rate_.toString() <<
" rad/s\n";
74 oss <<
"\tReserved1: " <<
static_cast<int>(reserved1_.getValue()) <<
"\n";
75 oss <<
"\tReserved2: " <<
static_cast<int>(reserved2_.getValue()) <<
"\n";
76 oss <<
"\tReserved3: " <<
static_cast<int>(reserved3_.getValue()) <<
"\n";
78 oss << this->toString(
false);
79 oss <<
"SeqID=" <<
static_cast<int>(sequenceId_)
80 <<
" Rate=" << rate_.toString() <<
"rad/s"
81 <<
" R1=" <<
static_cast<int>(reserved1_.getValue())
82 <<
" R2=" <<
static_cast<int>(reserved2_.getValue())
83 <<
" R3=" <<
static_cast<int>(reserved3_.getValue());
89std::string PGN127251::rawPayload(uint8_t sequenceId,
93 Byte reserved3)
noexcept {
94 std::vector<uint8_t> canFrame(8, 0);
95 canFrame[0] = sequenceId;
97 const uint32_t rawRateBits =
static_cast<uint32_t
>(rate.getRaw());
98 canFrame[1] =
static_cast<uint8_t
>(rawRateBits & 0xFFU);
99 canFrame[2] =
static_cast<uint8_t
>((rawRateBits >> 8) & 0xFFU);
100 canFrame[3] =
static_cast<uint8_t
>((rawRateBits >> 16) & 0xFFU);
101 canFrame[4] =
static_cast<uint8_t
>((rawRateBits >> 24) & 0xFFU);
102 canFrame[5] = reserved1.getRaw();
103 canFrame[6] = reserved2.getRaw();
104 canFrame[7] = reserved3.getRaw();
106 const uint32_t canId = (127251U << 8U);
107 std::ostringstream oss;
108 oss << std::hex << std::uppercase << std::setfill(
'0');
109 oss << std::setw(8) << canId <<
":";
110 for (uint8_t b : canFrame) {
111 oss << std::setw(2) << static_cast<int>(b);
138 sequenceId_ == other.sequenceId_ &&
139 rate_ == other.rate_ &&
140 reserved1_ == other.reserved1_ &&
141 reserved2_ == other.reserved2_ &&
142 reserved3_ == other.reserved3_;
static constexpr DataType fromRaw(RawType raw) noexcept
Constructs from a raw value.
Represents a generic NMEA 2000 message encapsulating a CAN frame.
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 bool operator==(const Message2000 &other) const noexcept
Strongly-typed class representing PGN 127251 - Rate of Turn.
Byte getReserved1() const noexcept
Byte getReserved2() const noexcept
PGN127251(uint8_t sequenceId, AngularRate rate, Byte reserved1=Byte::fromValue(0U), Byte reserved2=Byte::fromValue(0U), Byte reserved3=Byte::fromValue(0U)) noexcept
AngularRate getRate() const noexcept
std::unique_ptr< nmealib::Message > clone() const override
Creates a polymorphic deep copy of this Message2000.
std::string getStringContent(bool verbose) const noexcept override
Returns a human-readable string representation of the message.
bool operator==(const PGN127251 &other) const noexcept
uint8_t getSequenceId() const noexcept
Byte getReserved3() const noexcept
#define NMEALIB_RETURN_ERROR(exceptionExpr)
DataType< ByteTraits > Byte
Custom type representing 8 bits of data (0-255).
DataType< AngularRateTraits > AngularRate
Custom type representing angular rates in radians per second.