8std::unique_ptr<PGN127257> PGN127257::create(std::unique_ptr<Message2000> baseMessage) {
9 if (baseMessage->getCanFrameLength() != 8) {
10 std::string context =
"PGN127257::create()";
11 NMEALIB_RETURN_ERROR(InvalidCanFrameException(context,
"CAN frame must be 8 bytes for PGN127257"));
14 const uint8_t sequenceId = baseMessage->getCanFrame()[0];
16 (
static_cast<uint16_t
>(baseMessage->getCanFrame()[2]) << 8));
18 (
static_cast<uint16_t
>(baseMessage->getCanFrame()[4]) << 8));
20 (
static_cast<uint16_t
>(baseMessage->getCanFrame()[6]) << 8));
23 return std::unique_ptr<PGN127257>(
new PGN127257(std::move(*baseMessage),
31PGN127257::PGN127257(Message2000 baseMessage,
36 Byte reserved) noexcept :
37 Message2000(std::move(baseMessage)),
38 sequenceId_(sequenceId),
42 reserved_(reserved) {}
44PGN127257::PGN127257(uint8_t sequenceId,
48 Byte reserved) noexcept :
54 sequenceId_(sequenceId),
58 reserved_(reserved) {}
61 return std::unique_ptr<PGN127257>(
new PGN127257(*
this));
65 std::ostringstream oss;
68 oss << this->toString(
true);
71 oss <<
"\tSequence ID: " <<
static_cast<int>(sequenceId_) <<
"\n";
72 oss <<
"\tYaw: " << yaw_.toString() <<
"rad, " << getYawDegrees() <<
"°\n";
73 oss <<
"\tPitch: " << pitch_.toString() <<
"rad, " << getPitchDegrees() <<
"°\n";
74 oss <<
"\tRoll: " << roll_.toString() <<
"rad, " << getRollDegrees() <<
"°\n";
76 oss << this->toString(
false);
77 oss <<
"SeqID=" <<
static_cast<int>(sequenceId_)
78 <<
" Yaw=" << getYawDegrees() <<
"°"
79 <<
" Pitch=" << getPitchDegrees() <<
"°"
80 <<
" Roll=" << getRollDegrees() <<
"°";
86std::string PGN127257::rawPayload(uint8_t sequenceId,
91 std::vector<uint8_t> canFrame(8, 0);
92 canFrame[0] = sequenceId;
93 canFrame[1] =
static_cast<uint8_t
>(yaw.
getRaw() & 0xFFU);
94 canFrame[2] =
static_cast<uint8_t
>((yaw.
getRaw() >> 8) & 0xFFU);
95 canFrame[3] =
static_cast<uint8_t
>(pitch.
getRaw() & 0xFFU);
96 canFrame[4] =
static_cast<uint8_t
>((pitch.
getRaw() >> 8) & 0xFFU);
97 canFrame[5] =
static_cast<uint8_t
>(roll.
getRaw() & 0xFFU);
98 canFrame[6] =
static_cast<uint8_t
>((roll.
getRaw() >> 8) & 0xFFU);
99 canFrame[7] = reserved.
getRaw();
101 const uint32_t canId = (127257U << 8U);
102 std::ostringstream oss;
103 oss << std::hex << std::uppercase << std::setfill(
'0');
104 oss << std::setw(8) << canId <<
":";
105 for (uint8_t b : canFrame) {
106 oss << std::setw(2) << static_cast<int>(b);
132 return yaw_.
getValue() * 180.0f /
static_cast<float>(M_PI);
136 return pitch_.
getValue() * 180.0f /
static_cast<float>(M_PI);
140 return roll_.
getValue() * 180.0f /
static_cast<float>(M_PI);
145 sequenceId_ == other.sequenceId_ &&
146 yaw_ == other.yaw_ &&
147 pitch_ == other.pitch_ &&
148 roll_ == other.roll_ &&
149 reserved_ == other.reserved_;
RawType getRaw() const noexcept
Converts physical value to raw integer representation.
static constexpr DataType fromRaw(RawType raw) noexcept
Constructs from a raw value.
constexpr TargetType getValue() const noexcept
Returns the normalized physical 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 127257 - Attitude.
Byte getReserved() const noexcept
float getPitchDegrees() const noexcept
std::unique_ptr< nmealib::Message > clone() const override
Creates a polymorphic deep copy of this Message2000.
float getRollDegrees() const noexcept
PGN127257(uint8_t sequenceId, SignedAngle yaw, SignedAngle pitch, SignedAngle roll, Byte reserved=Byte::fromValue(0U)) noexcept
std::string getStringContent(bool verbose) const noexcept override
Returns a human-readable string representation of the message.
SignedAngle getRoll() const noexcept
float getYawDegrees() const noexcept
SignedAngle getPitch() const noexcept
uint8_t getSequenceId() const noexcept
bool operator==(const PGN127257 &other) const noexcept
SignedAngle getYaw() const noexcept
#define NMEALIB_RETURN_ERROR(exceptionExpr)
DataType< SignedAngleTraits > SignedAngle
Custom type representing signed angles in radians.
DataType< ByteTraits > Byte
Custom type representing 8 bits of data (0-255).