Skip to content

Commit

Permalink
update mavlinkcom to support mavlink2 protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Apr 30, 2017
1 parent d8e0093 commit 13b9560
Show file tree
Hide file tree
Showing 22 changed files with 962 additions and 8,681 deletions.
5 changes: 3 additions & 2 deletions MavLinkCom/MavLinkTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,9 @@ int console(std::stringstream& script) {
auto str = std::string(Command::kCommandLogPrefix) + line;
MavLinkStatustext st;
strncpy(st.text, str.c_str(), 50);
MavLinkMessage m;
st.encode(m, 0);
MavLinkMessage m;
st.encode(m);
droneConnection->prepareForSending(m);
std::lock_guard<std::mutex> lock(logLock);
inLogFile->write(m);
}
Expand Down
4 changes: 4 additions & 0 deletions MavLinkCom/include/MavLinkConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ namespace mavlinkcom {
//are bridged and you don't want certain connection to read ceratin messages.
void ignoreMessage(uint8_t message_id);

// Compute crc checksums, and pack according to mavlink1 or mavlink2 (depending on what target node supports) and do optional
// message signing according to the target node we are communicating with, and return the message length.
int prepareForSending(MavLinkMessage& msg);

protected:
void startListening(const std::string& nodeName, std::shared_ptr<Port> connectedPort);

Expand Down
33 changes: 18 additions & 15 deletions MavLinkCom/include/MavLinkMessageBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace mavlinkcom
{
class MavLinkConnection;

#define PayloadSize ((255 + 2 + 7) / 8)

// This is the raw undecoded message, use the msgid field to figure out which strongly typed
// MavLinkMessageBase subclass can be used to decode this message. For example, a heartbeat:
// MavLinkMessage msg;
Expand All @@ -26,17 +28,18 @@ namespace mavlinkcom
// }
class MavLinkMessage {
public:
// These are the raw packet message fields.
// See MavLinkMessage subclasses for the nice unpacked strongly typed fields.
uint16_t checksum; ///< sent at end of packet
uint8_t magic; ///< protocol magic marker
uint8_t len; ///< Length of payload
uint8_t seq; ///< Sequence of packet
uint8_t sysid; ///< ID of message sender system/aircraft
uint8_t compid; ///< ID of the message sender component
uint8_t msgid; ///< ID of message in payload
uint64_t payload64[(255 + 2 + 7) / 8];

uint16_t checksum; ///< sent at end of packet
uint8_t magic; ///< protocol magic marker
uint8_t len; ///< Length of payload
uint8_t incompat_flags; ///< flags that must be understood
uint8_t compat_flags; ///< flags that can be ignored if not understood
uint8_t seq; ///< Sequence of packet
uint8_t sysid; ///< ID of message sender system/aircraft
uint8_t compid; ///< ID of the message sender component
uint32_t msgid : 24; ///< ID of message in payload
uint64_t payload64[PayloadSize];
uint8_t ck[2]; ///< incoming checksum bytes
uint8_t signature[13];
};

// This is the base class for all the strongly typed messages define in MavLinkMessages.hpp
Expand All @@ -50,9 +53,8 @@ namespace mavlinkcom

// unpack the given message
void decode(const MavLinkMessage& msg);

// encode this message into given message buffer
void encode(MavLinkMessage& msg, int seq) const;
// pack this message into given message buffer
void encode(MavLinkMessage& msg) const;

// find what type of message this is and decode it on the heap (call delete when you are done with it).
static MavLinkMessageBase* lookup(const MavLinkMessage& msg);
Expand Down Expand Up @@ -100,7 +102,7 @@ namespace mavlinkcom
std::string int16_t_array_tostring(int len, const int16_t* field);
std::string uint16_t_array_tostring(int len, const uint16_t* field);
std::string float_array_tostring(int len, const float* field);
std::string float_tostring(float value);
std::string float_tostring(float value);
};

// Base class for all strongly typed MavLinkCommand classes defined in MavLinkMessages.hpp
Expand All @@ -120,6 +122,7 @@ namespace mavlinkcom
float param7 = 0;

friend class mavlinkcom_impl::MavLinkNodeImpl;
friend class mavlinkcom_impl::MavLinkConnectionImpl;
};


Expand Down
13 changes: 6 additions & 7 deletions MavLinkCom/mavlink/checksum.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifdef __cplusplus
#pragma once

#if defined(MAVLINK_USE_CXX_NAMESPACE)
namespace mavlink {
#elif defined(__cplusplus)
extern "C" {
#endif

#ifndef _CHECKSUM_H_
#define _CHECKSUM_H_

// Visual Studio versions before 2010 don't have stdint.h, so we just error out.
#if (defined _MSC_VER) && (_MSC_VER < 1600)
#error "The C-MAVLink implementation requires Visual Studio 2010 or greater"
Expand Down Expand Up @@ -89,8 +90,6 @@ static inline void crc_accumulate_buffer(uint16_t *crcAccum, const char *pBuffer
}
}

#endif /* _CHECKSUM_H_ */

#ifdef __cplusplus
#if defined(MAVLINK_USE_CXX_NAMESPACE) || defined(__cplusplus)
}
#endif
88 changes: 63 additions & 25 deletions MavLinkCom/mavlink/common/common.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions MavLinkCom/mavlink/common/mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define MAVLINK_PRIMARY_XML_IDX 1

#ifndef MAVLINK_STX
#define MAVLINK_STX 254
#define MAVLINK_STX 253
#endif

#ifndef MAVLINK_ENDIAN
Expand All @@ -25,7 +25,7 @@
#endif

#ifndef MAVLINK_COMMAND_24BIT
#define MAVLINK_COMMAND_24BIT 0
#define MAVLINK_COMMAND_24BIT 1
#endif

#include "version.h"
Expand Down
Loading

0 comments on commit 13b9560

Please sign in to comment.