44 const std::vector<uint8_t> &packet_data = this->
data();
47 if (packet_data.empty())
49 throw std::length_error(
"Packet is empty.");
59 ss <<
"Invalid packet starting byte (0x" 60 << std::uppercase << std::hex
61 <<
static_cast<unsigned int>(packet_data.front())
62 << std::nouppercase <<
"), v2.0 packets should start with 0x" 63 << std::uppercase << std::hex
65 << std::nouppercase <<
".";
66 throw std::invalid_argument(ss.str());
71 throw std::length_error(
72 "Packet (" + std::to_string(packet_data.size()) +
73 " bytes) is shorter than a v2.0 header (" +
80 if (mavlink_get_message_info_by_id(
header(packet_data)->
msgid) ==
89 std::string prefix =
"Packet";
90 size_t expected_length =
96 prefix =
"Signed packet";
99 throw std::length_error(
100 prefix +
" is " + std::to_string(packet_data.size()) +
101 " bytes, should be " +
102 std::to_string(expected_length) +
" bytes.");
129 if (
const mavlink_message_info_t *msg_info =
130 mavlink_get_message_info_by_id(
header(
data())->msgid))
132 return std::string(msg_info->name);
157 if (
const mavlink_msg_entry_t *msg_entry =
160 int dest_system = -1;
161 int dest_component = 0;
164 if (msg_entry->flags & MAV_MSG_ENTRY_FLAG_HAVE_TARGET_SYSTEM)
169 if (msg_entry->target_system_ofs <
header(
data())->len)
172 size_t offset = msg_entry->target_system_ofs +
174 dest_system =
data()[offset];
183 if (msg_entry->flags & MAV_MSG_ENTRY_FLAG_HAVE_TARGET_COMPONENT)
188 if (msg_entry->target_component_ofs <
header(
data())->len)
191 size_t offset = msg_entry->target_component_ofs +
193 dest_component =
data()[offset];
202 if (dest_system >= 0)
204 return MAVAddress(static_cast<unsigned int>(dest_system),
205 static_cast<unsigned int>(dest_component));
232 throw std::invalid_argument(
"Header is incomplete or invalid.");
235 return (
header(data)->incompat_flags & MAVLINK_IFLAG_SIGNED);
267 size_t expected_length =
270 if (
header(data)->incompat_flags & MAVLINK_IFLAG_SIGNED)
275 return data.size() == expected_length;
290 const std::vector<uint8_t> &data)
294 return reinterpret_cast <
const size_t CHECKSUM_LENGTH
bool header_complete(const std::vector< uint8_t > &data)
virtual ::Packet::Version version() const
const struct mavlink::v2_header * header(const std::vector< uint8_t > &data)
const size_t HEADER_LENGTH
const struct mavlink::v2_header * header(const std::vector< uint8_t > &data)
const size_t SIGNATURE_LENGTH
bool is_signed(const std::vector< uint8_t > &data)
bool header_complete(const std::vector< uint8_t > &data)
virtual std::string name() const
virtual MAVAddress source() const
bool packet_complete(const std::vector< uint8_t > &data)
Packet(const Packet &other)=default
virtual std::optional< MAVAddress > dest() const
const std::vector< uint8_t > & data() const
virtual unsigned long id() const