mavlink_convert.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright 2015,2016 Vladimir Ermakov.
8  *
9  * This file is part of the mavros package and subject to the license terms
10  * in the top-level LICENSE file of the mavros repository.
11  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
12  */
13 
14 #pragma once
15 
16 #include <algorithm>
17 #include <mavros_msgs/Mavlink.h>
18 #include <mavconn/mavlink_dialect.h>
19 
20 namespace mavros_msgs {
21 namespace mavlink {
22 
23 using ::mavlink::mavlink_message_t;
24 
25 // [[[cog:
26 // FIELD_NAMES = [
27 // "magic",
28 // "len",
29 // "incompat_flags",
30 // "compat_flags",
31 // "seq",
32 // "sysid",
33 // "compid",
34 // "msgid",
35 // "checksum",
36 // ]
37 // ]]]
38 // [[[end]]] (checksum: d41d8cd98f00b204e9800998ecf8427e)
39 
50 inline bool convert(const mavros_msgs::Mavlink &rmsg, mavlink_message_t &mmsg)
51 {
52  if (rmsg.payload64.size() > sizeof(mmsg.payload64) / sizeof(mmsg.payload64[0])) {
53  return false;
54  }
55 
56  if (!rmsg.signature.empty() && rmsg.signature.size() != sizeof(mmsg.signature)) {
57  return false;
58  }
59 
60  // [[[cog:
61  // for f in FIELD_NAMES:
62  // cog.outl("mmsg.%s = rmsg.%s;" % (f, f))
63  // ]]]
64  mmsg.magic = rmsg.magic;
65  mmsg.len = rmsg.len;
66  mmsg.incompat_flags = rmsg.incompat_flags;
67  mmsg.compat_flags = rmsg.compat_flags;
68  mmsg.seq = rmsg.seq;
69  mmsg.sysid = rmsg.sysid;
70  mmsg.compid = rmsg.compid;
71  mmsg.msgid = rmsg.msgid;
72  mmsg.checksum = rmsg.checksum;
73  // [[[end]]] (checksum: 2ef42a7798f261bfd367bf4157b11ec0)
74  std::copy(rmsg.payload64.begin(), rmsg.payload64.end(), mmsg.payload64);
75  std::copy(rmsg.signature.begin(), rmsg.signature.end(), mmsg.signature);
76 
77  return true;
78 }
79 
88 inline bool convert(const mavlink_message_t &mmsg, mavros_msgs::Mavlink &rmsg, uint8_t framing_status = mavros_msgs::Mavlink::FRAMING_OK)
89 {
90  const size_t payload64_len = (mmsg.len + 7) / 8;
91 
92  rmsg.framing_status = framing_status;
93 
94  // [[[cog:
95  // for f in FIELD_NAMES:
96  // cog.outl("rmsg.%s = mmsg.%s;" % (f, f))
97  // ]]]
98  rmsg.magic = mmsg.magic;
99  rmsg.len = mmsg.len;
100  rmsg.incompat_flags = mmsg.incompat_flags;
101  rmsg.compat_flags = mmsg.compat_flags;
102  rmsg.seq = mmsg.seq;
103  rmsg.sysid = mmsg.sysid;
104  rmsg.compid = mmsg.compid;
105  rmsg.msgid = mmsg.msgid;
106  rmsg.checksum = mmsg.checksum;
107  // [[[end]]] (checksum: 4f0a50d2fcd7eb8823aea3e0806cd698)
108  rmsg.payload64 = std::move(mavros_msgs::Mavlink::_payload64_type(mmsg.payload64, mmsg.payload64 + payload64_len));
109 
110  // copy signature block only if message is signed
111  if (mmsg.incompat_flags & MAVLINK_IFLAG_SIGNED)
112  rmsg.signature = std::move(mavros_msgs::Mavlink::_signature_type(mmsg.signature, mmsg.signature + sizeof(mmsg.signature)));
113  else
114  rmsg.signature.clear();
115 
116  return true;
117 }
118 
119 } // namespace mavlink
120 } // namespace mavros_msgs


mavros_msgs
Author(s): Vladimir Ermakov
autogenerated on Mon Jul 8 2019 03:20:08