mavtables  0.2.1
MAVLink router and firewall.
PacketVersion2.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef PACKETVERSION2_HPP_
19 #define PACKETVERSION2_HPP_
20 
21 
22 #include <cstdint>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include "mavlink.hpp"
28 #include "Packet.hpp"
29 
30 
31 namespace packet_v2
32 {
33 
34  /** MAVLink v2.0 start byte (0xFD).
35  */
36  const uint8_t START_BYTE = MAVLINK_STX;
37 
38 
39  /** MAVLink v2.0 header length (10 bytes).
40  */
41  const size_t HEADER_LENGTH = MAVLINK_NUM_HEADER_BYTES;
42 
43 
44  /** MAVLink v2.0 checksum length (2 bytes).
45  */
46  const size_t CHECKSUM_LENGTH = MAVLINK_NUM_CHECKSUM_BYTES;
47 
48 
49  /** MAVLink v2.0 signature length (13 bytes) if signed.
50  */
51  const size_t SIGNATURE_LENGTH = MAVLINK_SIGNATURE_BLOCK_LEN;
52 
53 
54  /** MAVLink v2.0 version..
55  */
56  const ::Packet::Version VERSION = ::Packet::V2;
57 
58 
59  /** A MAVLink packet with the version 2 wire protocol.
60  */
61  class Packet : public ::Packet
62  {
63  public:
64  /** Copy constructor.
65  *
66  * \param other Packet to copy from.
67  */
68  Packet(const Packet &other) = default;
69  /** Move constructor.
70  *
71  * \param other Packet to move from.
72  */
73  Packet(Packet &&other) = default;
74  Packet(std::vector<uint8_t> data);
75  virtual ::Packet::Version version() const;
76  virtual unsigned long id() const;
77  virtual std::string name() const;
78  virtual MAVAddress source() const;
79  virtual std::optional<MAVAddress> dest() const;
80  /** Assignment operator.
81  *
82  * \param other Packet to copy from.
83  */
84  Packet &operator=(const Packet &other) = default;
85  /** Assignment operator (by move semantics).
86  *
87  * \param other Packet to move from.
88  */
89  Packet &operator=(Packet &&other) = default;
90  };
91 
92  bool is_signed(const std::vector<uint8_t> &data);
93  bool header_complete(const std::vector<uint8_t> &data);
94  bool packet_complete(const std::vector<uint8_t> &data);
95  const struct mavlink::v2_header *header(
96  const std::vector<uint8_t> &data);
97 
98 }
99 
100 
101 #endif // PACKETVERSION2_HPP_
const size_t CHECKSUM_LENGTH
bool packet_complete(const std::vector< uint8_t > &data)
bool header_complete(const std::vector< uint8_t > &data)
virtual ::Packet::Version version() const
const size_t HEADER_LENGTH
const struct mavlink::v2_header * header(const std::vector< uint8_t > &data)
const size_t SIGNATURE_LENGTH
MAVLink Version 2.0.
Definition: Packet.hpp:50
Packet & operator=(const Packet &other)=default
virtual std::string name() const
virtual MAVAddress source() const
const ::Packet::Version VERSION
const uint8_t START_BYTE
bool is_signed(const std::vector< uint8_t > &data)
Packet(const Packet &other)=default
virtual std::optional< MAVAddress > dest() const
const std::vector< uint8_t > & data() const
Definition: Packet.cpp:52
virtual unsigned long id() const