mavtables  0.2.1
MAVLink router and firewall.
Public Types | Public Member Functions | Related Functions | List of all members
Packet Class Referenceabstract

#include <Packet.hpp>

Inheritance diagram for Packet:
Inheritance graph
Collaboration diagram for Packet:
Collaboration graph

Public Types

enum  Version { V1 = 0x0100, V2 = 0x0200 }
 

Public Member Functions

 Packet (const Packet &other)=default
 
 Packet (Packet &&other)=default
 
 Packet (std::vector< uint8_t > data)
 
virtual ~Packet ()
 
virtual Version version () const =0
 
virtual unsigned long id () const =0
 
virtual std::string name () const =0
 
virtual MAVAddress source () const =0
 
virtual std::optional< MAVAddressdest () const =0
 
void connection (std::weak_ptr< Connection > connection)
 
const std::shared_ptr< Connectionconnection () const
 
const std::vector< uint8_t > & data () const
 
Packetoperator= (const Packet &other)=default
 
Packetoperator= (Packet &&other)=default
 

Related Functions

(Note that these are not member functions.)

bool operator== (const Packet &lhs, const Packet &rhs)
 
bool operator!= (const Packet &lhs, const Packet &rhs)
 
std::ostream & operator<< (std::ostream &os, const Packet &packet)
 

Detailed Description

A MAVLink packet.

This is an abstract class, it is meant to be overridden by classes implementing either version 1 or version 2 of the MAVLink packet wire protocol.

Definition at line 44 of file Packet.hpp.

Member Enumeration Documentation

◆ Version

Enumerator
V1 

MAVLink Version 1.0.

V2 

MAVLink Version 2.0.

Definition at line 47 of file Packet.hpp.

Constructor & Destructor Documentation

◆ Packet() [1/3]

Packet::Packet ( const Packet other)
default

Copy constructor.

Parameters
otherPacket to copy from.

◆ Packet() [2/3]

Packet::Packet ( Packet &&  other)
default

Move constructor.

Parameters
otherPacket to move from.

◆ Packet() [3/3]

Packet::Packet ( std::vector< uint8_t >  data)

Construct a packet.

Parameters
dataRaw packet data.

Definition at line 33 of file Packet.cpp.

◆ ~Packet()

Packet::~Packet ( )
virtual

Definition at line 42 of file Packet.cpp.

Member Function Documentation

◆ connection() [1/2]

void Packet::connection ( std::weak_ptr< Connection connection)

Set the source connection of the packet.

Parameters
connectionThe source connection.
See also
connection()

Definition at line 63 of file Packet.cpp.

References connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection() [2/2]

const std::shared_ptr< Connection > Packet::connection ( ) const

Get the source connection of the packet.

Returns
The source connection if set and it still exists, otherwise nullptr.
See also
connection(std::weak_ptr<Connection>)

Definition at line 75 of file Packet.cpp.

Here is the caller graph for this function:

◆ data()

const std::vector< uint8_t > & Packet::data ( ) const

Return the packet data.

Returns
The packet data as a vector of bytes.

Definition at line 52 of file Packet.cpp.

Here is the caller graph for this function:

◆ dest()

virtual std::optional<MAVAddress> Packet::dest ( ) const
pure virtual

Return destination address.

Where the packet is sent to. This is optional because not all packets have a destination. If a system is specified, but not a component, a component ID of 0 will be used (the broadcast ID).

Returns
The destination MAVLink address of the packet if not a broadcast packet. If the packet does not have a destination address then {} will be returned.

Implemented in packet_v2::Packet, and packet_v1::Packet.

Here is the caller graph for this function:

◆ id()

virtual unsigned long Packet::id ( ) const
pure virtual

Return MAVLink message ID.

Returns
The numeric message ID of the MAVLink packet (0 to 255).

Implemented in packet_v2::Packet, and packet_v1::Packet.

Here is the caller graph for this function:

◆ name()

virtual std::string Packet::name ( ) const
pure virtual

Return MAVLink message name.

Returns
The message name of the MAVLink packet.

Implemented in packet_v2::Packet, and packet_v1::Packet.

Here is the caller graph for this function:

◆ operator=() [1/2]

Packet& Packet::operator= ( const Packet other)
default

Assignment operator.

Parameters
otherPacket to copy from.

◆ operator=() [2/2]

Packet& Packet::operator= ( Packet &&  other)
default

Assignment operator (by move semantics).

Parameters
otherPacket to move from.

◆ source()

virtual MAVAddress Packet::source ( ) const
pure virtual

Return source address.

Where the packet came from.

Returns
The source MAVLink address of the packet.

Implemented in packet_v2::Packet, and packet_v1::Packet.

Here is the caller graph for this function:

◆ version()

virtual Version Packet::version ( ) const
pure virtual

Return packet version.

Returns
Two byte Packet version with major version in MSB and minor version in LSB.

Implemented in packet_v2::Packet, and packet_v1::Packet.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const Packet lhs,
const Packet rhs 
)
related

Inequality comparison.

Compares the raw packet data.

Parameters
lhsThe left hand side packet.
rhsThe right hand side packet.
Return values
trueif lhs and rhs do not have the same packet data.
falseif lhs and rhs have the same packet data.

Definition at line 107 of file Packet.cpp.

References data().

Here is the call graph for this function:

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const Packet packet 
)
related

Print the packet to the given output stream.

The format is "<Message Name> (#<Message ID>) from <Source Address> to <Destination Address> (v<Packet Version>)". However, "to <Destination Address>" is optional and will not be printed if the destination is the broadcast address 0.0.

Some examples are:

  • HEARTBEAT (#1) from 16.8 (v1.0)
  • PING (#4) from 128.4 to 16.8 (v2.0)
  • DATA_TRANSMISSION_HANDSHAKE (#130) from 16.8 (v2.0)
  • ENCAPSULATED_DATA (#131) from 128.4 (v2.0)
Parameters
osThe output stream to print to.
packetThe MAVLink packet to print.
Returns
The output stream.

Definition at line 131 of file Packet.cpp.

References dest(), id(), name(), source(), and version().

Here is the call graph for this function:

◆ operator==()

bool operator== ( const Packet lhs,
const Packet rhs 
)
related

Equality comparison.

Compares the raw packet data.

Parameters
lhsThe left hand side packet.
rhsThe right hand side packet.
Return values
trueif lhs and rhs have the same packet data.
falseif lhs and rhs do not have the same packet data.

Definition at line 91 of file Packet.cpp.

References data().

Here is the call graph for this function:

The documentation for this class was generated from the following files: