8std::unique_ptr<PGN128001> PGN128001::create(std::unique_ptr<Message2000> baseMessage) {
9 if (baseMessage->getCanFrameLength() != 8) {
10 std::string context =
"PGN128001::create()";
11 NMEALIB_RETURN_ERROR(InvalidCanFrameException(context,
"CAN frame must be 8 bytes for PGN128001"));
14 const uint8_t sequenceId = baseMessage->getCanFrame()[0];
17 (
static_cast<uint16_t
>(baseMessage->getCanFrame()[2]) << 8)));
20 (
static_cast<uint16_t
>(baseMessage->getCanFrame()[4]) << 8)));
23 (
static_cast<uint16_t
>(baseMessage->getCanFrame()[6]) << 8)));
26 return std::unique_ptr<PGN128001>(
new PGN128001(std::move(*baseMessage),
28 longitudinalAcceleration,
29 transverseAcceleration,
34PGN128001::PGN128001(Message2000 baseMessage,
39 Byte reserved) noexcept :
40 Message2000(std::move(baseMessage)),
41 sequenceId_(sequenceId),
42 longitudinalAcceleration_(longitudinalAcceleration),
43 transverseAcceleration_(transverseAcceleration),
44 verticalAcceleration_(verticalAcceleration),
45 reserved_(reserved) {}
47PGN128001::PGN128001(uint8_t sequenceId,
51 Byte reserved) noexcept :
53 longitudinalAcceleration,
54 transverseAcceleration,
57 sequenceId_(sequenceId),
58 longitudinalAcceleration_(longitudinalAcceleration),
59 transverseAcceleration_(transverseAcceleration),
60 verticalAcceleration_(verticalAcceleration),
61 reserved_(reserved) {}
64 return std::unique_ptr<PGN128001>(
new PGN128001(*
this));
68 std::ostringstream oss;
71 oss << this->toString(
true);
74 oss <<
"\tSequence ID: " <<
static_cast<int>(sequenceId_) <<
"\n";
75 oss <<
"\tLongitudinal Acceleration: " << longitudinalAcceleration_.toString() <<
" m/s^2"
76 <<
" (" << getLongitudinalAccelerationG() <<
" g)\n";
77 oss <<
"\tTransverse Acceleration: " << transverseAcceleration_.toString() <<
" m/s^2"
78 <<
" (" << getTransverseAccelerationG() <<
" g)\n";
79 oss <<
"\tVertical Acceleration: " << verticalAcceleration_.toString() <<
" m/s^2"
80 <<
" (" << getVerticalAccelerationG() <<
" g)\n";
81 oss <<
"\tReserved: " <<
static_cast<int>(reserved_.getValue()) <<
"\n";
83 oss << this->toString(
false);
84 oss <<
"SeqID=" <<
static_cast<int>(sequenceId_)
85 <<
" Long=" << longitudinalAcceleration_.toString() <<
"m/s^2"
86 <<
" Trans=" << transverseAcceleration_.toString() <<
"m/s^2"
87 <<
" Vert=" << verticalAcceleration_.toString() <<
"m/s^2";
93std::string PGN128001::rawPayload(uint8_t sequenceId,
98 std::vector<uint8_t> canFrame(8, 0);
99 canFrame[0] = sequenceId;
101 const uint16_t rawLongitudinal =
static_cast<uint16_t
>(longitudinalAcceleration.
getRaw());
102 const uint16_t rawTransverse =
static_cast<uint16_t
>(transverseAcceleration.
getRaw());
103 const uint16_t rawVertical =
static_cast<uint16_t
>(verticalAcceleration.
getRaw());
105 canFrame[1] =
static_cast<uint8_t
>(rawLongitudinal & 0xFFU);
106 canFrame[2] =
static_cast<uint8_t
>((rawLongitudinal >> 8) & 0xFFU);
107 canFrame[3] =
static_cast<uint8_t
>(rawTransverse & 0xFFU);
108 canFrame[4] =
static_cast<uint8_t
>((rawTransverse >> 8) & 0xFFU);
109 canFrame[5] =
static_cast<uint8_t
>(rawVertical & 0xFFU);
110 canFrame[6] =
static_cast<uint8_t
>((rawVertical >> 8) & 0xFFU);
111 canFrame[7] = reserved.
getRaw();
113 const uint32_t canId = (128001U << 8U);
114 std::ostringstream oss;
115 oss << std::hex << std::uppercase << std::setfill(
'0');
116 oss << std::setw(8) << canId <<
":";
117 for (uint8_t b : canFrame) {
118 oss << std::setw(2) << static_cast<int>(b);
128 return longitudinalAcceleration_;
132 return transverseAcceleration_;
136 return verticalAcceleration_;
140 return longitudinalAcceleration_.
getValue() / 9.80665f;
144 return transverseAcceleration_.
getValue() / 9.80665f;
148 return verticalAcceleration_.
getValue() / 9.80665f;
153 sequenceId_ == other.sequenceId_ &&
154 longitudinalAcceleration_ == other.longitudinalAcceleration_ &&
155 transverseAcceleration_ == other.transverseAcceleration_ &&
156 verticalAcceleration_ == other.verticalAcceleration_ &&
157 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 128001 - Vessel Acceleration.
Acceleration getLongitudinalAcceleration() const noexcept
std::string getStringContent(bool verbose) const noexcept override
Returns a human-readable string representation of the message.
float getTransverseAccelerationG() const noexcept
bool operator==(const PGN128001 &other) const noexcept
float getLongitudinalAccelerationG() const noexcept
Acceleration getTransverseAcceleration() const noexcept
Acceleration getVerticalAcceleration() const noexcept
uint8_t getSequenceId() const noexcept
std::unique_ptr< nmealib::Message > clone() const override
Creates a polymorphic deep copy of this Message2000.
float getVerticalAccelerationG() const noexcept
PGN128001(uint8_t sequenceId, Acceleration longitudinalAcceleration, Acceleration transverseAcceleration, Acceleration verticalAcceleration, Byte reserved=Byte::fromRaw(255)) noexcept
#define NMEALIB_RETURN_ERROR(exceptionExpr)
DataType< AccelerationTraits > Acceleration
Custom type representing accelerations in meters per second squared.
DataType< ByteTraits > Byte
Custom type representing 8 bits of data (0-255).