8std::unique_ptr<PGN127250> PGN127250::create(std::unique_ptr<Message2000> baseMessage) {
9 if (baseMessage->getCanFrameLength() != 8) {
10 std::string context =
"PGN127250::create()";
11 NMEALIB_RETURN_ERROR(InvalidCanFrameException(context,
"CAN frame must be 8 bytes for PGN127250"));
14 uint8_t sequenceId = baseMessage->getCanFrame()[0];
15 Angle heading =
Angle::fromRaw(baseMessage->getCanFrame()[1] | (baseMessage->getCanFrame()[2] << 8));
21 return std::unique_ptr<PGN127250>(
new PGN127250(std::move(*baseMessage),
30PGN127250::PGN127250(Message2000 baseMessage,
36 Byte reserved) noexcept :
37 Message2000(std::move(baseMessage)),
38 sequenceId_(sequenceId),
40 deviation_(deviation),
41 variation_(variation),
42 headingReference_(headingReference),
43 reserved_(reserved) {}
45PGN127250::PGN127250(uint8_t sequenceId,
50 Byte reserved) noexcept :
57 sequenceId_(sequenceId),
59 deviation_(deviation),
60 variation_(variation),
61 headingReference_(headingReference),
62 reserved_(reserved) {}
66 return std::unique_ptr<PGN127250>(
new PGN127250(*
this));
70 std::ostringstream oss;
73 oss << this->toString(
true);
76 oss <<
"\tSequence ID: " <<
static_cast<int>(sequenceId_) <<
"\n";
77 oss <<
"\tHeading: " << heading_.toString() <<
"rad, " << getHeadingDegrees() <<
"°" <<
"\n";
78 oss <<
"\tDeviation: " << deviation_.toString() <<
"rad, " << getDeviationDegrees() <<
"°" <<
"\n";
79 oss <<
"\tVariation: " << variation_.toString() <<
"rad, " << getVariationDegrees() <<
"°" <<
"\n";
80 oss <<
"\tHeading Reference: ";
81 switch (headingReference_.getValue()) {
82 case 0: oss <<
"True";
break;
83 case 1: oss <<
"Magnetic";
break;
84 case 2: oss <<
"Error";
break;
85 case 3: oss <<
"Null";
break;
86 default: oss <<
"Unavailable/Reserved";
break;
90 oss << this->toString(
false);
91 oss <<
"SeqID=" <<
static_cast<int>(sequenceId_)
92 <<
" Heading=" << getHeadingDegrees() <<
"°"
93 <<
" Deviation=" << getDeviationDegrees() <<
"°"
94 <<
" Variation=" << getVariationDegrees() <<
"°"
95 <<
" HeadingRef=" <<
static_cast<int>(headingReference_.getValue());
100std::string PGN127250::rawPayload(uint8_t sequenceId,
106 std::vector<uint8_t> canFrame(8, 0);
107 canFrame[0] = sequenceId;
108 canFrame[1] = heading.
getRaw() & 0xFF;
109 canFrame[2] = (heading.
getRaw() >> 8) & 0xFF;
110 canFrame[3] = deviation.
getRaw() & 0xFF;
111 canFrame[4] = (deviation.
getRaw() >> 8) & 0xFF;
112 canFrame[5] = variation.
getRaw() & 0xFF;
113 canFrame[6] = (variation.
getRaw() >> 8) & 0xFF;
115 canFrame[7] = (reserved.
getRaw() << 6) | (headingReference.
getRaw() & 0x03);
119 const uint32_t canId = (127250U << 8U);
120 std::ostringstream oss;
121 oss << std::hex << std::uppercase << std::setfill(
'0');
122 oss << std::setw(8) << canId <<
":";
123 for (uint8_t b : canFrame) {
124 oss << std::setw(2) << static_cast<int>(b);
142 return headingReference_;
145 return heading_.
getValue() * 180.0f /
static_cast<float>(M_PI);
148 return deviation_.
getValue() * 180.0f /
static_cast<float>(M_PI);
151 return variation_.
getValue() * 180.0f /
static_cast<float>(M_PI);
156 sequenceId_ == other.sequenceId_ &&
157 heading_ == other.heading_ &&
158 deviation_ == other.deviation_ &&
159 variation_ == other.variation_ &&
160 headingReference_ == other.headingReference_ &&
161 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 127250 - Heading.
HalfByte getHeadingReference() const noexcept
SignedAngle getVariation() const noexcept
PGN127250(uint8_t sequenceId, Angle heading, SignedAngle deviation, SignedAngle variation, HalfByte headingReference, Byte reserved=Byte::fromValue(0U)) noexcept
bool operator==(const PGN127250 &other) const noexcept
std::unique_ptr< nmealib::Message > clone() const override
Creates a polymorphic deep copy of this Message2000.
float getVariationDegrees() const noexcept
float getHeadingDegrees() const noexcept
Angle getHeading() const noexcept
uint8_t getSequenceId() const noexcept
float getDeviationDegrees() const noexcept
SignedAngle getDeviation() const noexcept
std::string getStringContent(bool verbose) const noexcept override
Returns a human-readable string representation of the message.
#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).
DataType< HalfByteTraits > HalfByte
Custom type representing 4 bits of data (0-15).
DataType< AngleTraits > Angle
Custom type representing angles in radians.