Skip to content

Commit

Permalink
update mavlink
Browse files Browse the repository at this point in the history
  • Loading branch information
admercs committed Mar 22, 2024
1 parent 21d8f98 commit 399a1b2
Show file tree
Hide file tree
Showing 52 changed files with 199 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ArduRoverApi : public CarApiBase {
connection_info_.local_host_ip.c_str(), ip_.c_str()),
Utils::kLogLevelInfo);

udp_socket_ = std::make_unique<mavlinkcom::UdpSocket>();
udp_socket_ = std::make_unique<mavlink_comm::UdpSocket>();
udp_socket_->bind(connection_info_.local_host_ip, connection_info_.control_port_local);
}

Expand Down Expand Up @@ -273,7 +273,7 @@ class ArduRoverApi : public CarApiBase {

AutonomySimSettings::MavLinkConnectionInfo connection_info_;

std::unique_ptr<mavlinkcom::UdpSocket> udp_socket_;
std::unique_ptr<mavlink_comm::UdpSocket> udp_socket_;

uint16_t port_;
std::string ip_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ArduCopterApi : public MultirotorApiBase {
connection_info_.local_host_ip.c_str(), ip_.c_str()),
Utils::kLogLevelInfo);

udp_socket_ = std::make_unique<mavlinkcom::UdpSocket>();
udp_socket_ = std::make_unique<mavlink_comm::UdpSocket>();
udp_socket_->bind(connection_info_.local_host_ip, connection_info_.control_port_local);
}

Expand Down Expand Up @@ -447,7 +447,7 @@ class ArduCopterApi : public MultirotorApiBase {
uint16_t pwm[kArduCopterRotorControlCount];
};

std::unique_ptr<mavlinkcom::UdpSocket> udp_socket_;
std::unique_ptr<mavlink_comm::UdpSocket> udp_socket_;

AutonomySimSettings::MavLinkConnectionInfo connection_info_;
uint16_t port_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ class ArduCopterSoloApi : public MavLinkMultirotorApi {
ip.c_str()),
Utils::kLogLevelInfo);

udpSocket_ = mavlinkcom::AdHocConnection::connectLocalUdp("ArduCopterSoloConnector", ip,
connection_info_.control_port_local);
mavlinkcom::AdHocMessageHandler handler = [this](std::shared_ptr<mavlinkcom::AdHocConnection> connection,
const std::vector<uint8_t> &msg) {
this->rotorPowerMessageHandler(connection, msg);
};
udpSocket_ = mavlink_comm::AdHocConnection::connectLocalUdp("ArduCopterSoloConnector", ip,
connection_info_.control_port_local);
mavlink_comm::AdHocMessageHandler handler =
[this](std::shared_ptr<mavlink_comm::AdHocConnection> connection, const std::vector<uint8_t> &msg) {
this->rotorPowerMessageHandler(connection, msg);
};

rotorSubscriptionId_ = udpSocket_->subscribe(handler);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ class ArduCopterSoloApi : public MavLinkMultirotorApi {
uint16_t speed, direction, turbulance;
};

std::shared_ptr<mavlinkcom::AdHocConnection> udpSocket_;
std::shared_ptr<mavlink_comm::AdHocConnection> udpSocket_;
int rotorSubscriptionId_;

virtual void normalizeRotorControls() {
Expand All @@ -165,7 +165,7 @@ class ArduCopterSoloApi : public MavLinkMultirotorApi {
}
}

void rotorPowerMessageHandler(std::shared_ptr<mavlinkcom::AdHocConnection> connection,
void rotorPowerMessageHandler(std::shared_ptr<mavlink_comm::AdHocConnection> connection,
const std::vector<uint8_t> &msg) {
if (msg.size() != sizeof(RotorControlMessage)) {
Utils::log("Got rotor control message of size " + std::to_string(msg.size()) +
Expand Down

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions MavLinkCom/MavLinkComGenerator/MavLinkGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public void GenerateMessages(MavLink definitions, string outputDirectory)
header.WriteLine("#include <string>");
header.WriteLine("#include \"MavLinkMessageBase.hpp\"");
header.WriteLine("");
header.WriteLine("namespace mavlinkcom");
header.WriteLine("namespace mavlink_comm");
header.WriteLine("{");
header.WriteLine("");

impl.WriteLine("// Copyright (c) Microsoft Corporation. All rights reserved.");
impl.WriteLine("// Licensed under the MIT License.");
impl.WriteLine("#include \"MavLinkMessages.hpp\""); ;
impl.WriteLine("#include <sstream>");
impl.WriteLine("using namespace mavlinkcom;");
impl.WriteLine("using namespace mavlink_comm;");
impl.WriteLine("");

GenerateEnums();
Expand Down Expand Up @@ -435,7 +435,7 @@ private void GenerateMessages()
{
impl.Write(" << float_tostring(this->{0})", field.name);
}
else
else
{
impl.Write(" << this->{0}", field.name);
}
Expand Down Expand Up @@ -483,7 +483,7 @@ public void GenerateDecodeMethod()
impl.WriteLine("}");
}

public Tuple<string,int> ParseArrayType(string type)
public Tuple<string, int> ParseArrayType(string type)
{
int i = type.IndexOf('[');
int k = type.IndexOf(']', i);
Expand Down
2 changes: 1 addition & 1 deletion MavLinkCom/MavLinkMoCap/MavlinkMoCap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <chrono>
#include <thread>

using namespace mavlinkcom;
using namespace mavlink_comm;

void CheckResult(NPRESULT result) {
if (result != NPRESULT_SUCCESS) {
Expand Down
2 changes: 1 addition & 1 deletion MavLinkCom/MavLinkTest/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

using namespace std::filesystem;
using namespace mavlink_utils;
using namespace mavlinkcom;
using namespace mavlink_comm;

static std::vector<Command *> const *all_commands_;
std::vector<Command *> const *Command::getAllCommand() { return all_commands_; }
Expand Down
2 changes: 1 addition & 1 deletion MavLinkCom/MavLinkTest/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <string>
#include <vector>

using namespace mavlinkcom;
using namespace mavlink_comm;

// from main.cpp
void DebugOutput(const char *message, ...);
Expand Down
2 changes: 1 addition & 1 deletion MavLinkCom/MavLinkTest/UnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ STRICT_MODE_ON
#include <iostream>

using namespace mavlink_utils;
using namespace mavlinkcom;
using namespace mavlink_comm;

extern std::string replaceAll(std::string s, char toFind, char toReplace);

Expand Down
2 changes: 1 addition & 1 deletion MavLinkCom/MavLinkTest/UnitTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UnitTests {

private:
void RunTest(const std::string &name, TestHandler handler);
void VerifyFile(mavlinkcom::MavLinkFtpClient &ftp, const std::string &dir, const std::string &name, bool exists,
void VerifyFile(mavlink_comm::MavLinkFtpClient &ftp, const std::string &dir, const std::string &name, bool exists,
bool isdir);
ImageServer *server_;
std::string com_port_;
Expand Down
8 changes: 4 additions & 4 deletions MavLinkCom/MavLinkTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef mavlink_utils::Utils Utils;
typedef mavlink_utils::FileSystem FileSystem;
typedef unsigned int uint;

using namespace mavlinkcom;
using namespace mavlink_comm;

struct FlagName {
public:
Expand Down Expand Up @@ -1123,8 +1123,8 @@ void connectSitl(std::shared_ptr<MavLinkVehicle> mavLinkVehicle) {
// need a retry loop here because we don't know how quickly px4 will start accepting these connections...
for (int retries = 60; retries >= 0; retries--) {
try {
auto gcsConnection = mavlinkcom::MavLinkConnection::connectRemoteUdp("gcs", localEndPoint.addr,
sitlEndPoint.addr, sitlEndPoint.port);
auto gcsConnection = mavlink_comm::MavLinkConnection::connectRemoteUdp(
"gcs", localEndPoint.addr, sitlEndPoint.addr, sitlEndPoint.port);
mavLinkVehicle->connect(gcsConnection);
} catch (std::exception &) {
std::this_thread::sleep_for(std::chrono::seconds(1));
Expand All @@ -1151,7 +1151,7 @@ bool setupDrone() {
if (sitl) {
// then we need 2 mavlink channels, one for sending/receiving HIL_* messages and the other
// for controlling the drone.
hilNode = std::make_shared<mavlinkcom::MavLinkNode>(sim_sysid, sim_compid);
hilNode = std::make_shared<mavlink_comm::MavLinkNode>(sim_sysid, sim_compid);
hilNode->connect(droneConnection);
hilNode->startHeartbeat();

Expand Down
2 changes: 1 addition & 1 deletion MavLinkCom/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Welcome to MavLinkCom

This page has moved [here](https://github.com/nervosys/AutonomySim/blob/master/docs/mavlinkcom.md).
This page has moved [here](https://github.com/nervosys/AutonomySim/blob/master/docs/mavlink_comm.md).
3 changes: 2 additions & 1 deletion MavLinkCom/common/utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "MavLinkDebugLog.hpp"
#include "StrictMode.hpp"
#include "type_utils.hpp"

#include <array>
#include <chrono>
#include <cstdarg>
Expand Down Expand Up @@ -115,7 +116,7 @@ class Utils {
static constexpr int kLogLevelWarn = -1;
static constexpr int kLogLevelError = -2;
static void log(std::string message, int level = kLogLevelInfo) {
mavlinkcom::MavLinkDebugLog::getSetLogger()->log(level, message);
mavlink_comm::MavLinkDebugLog::getSetLogger()->log(level, message);
}

template <typename T> static int sign(T val) { return T(0) < val ? 1 : (T(0) > val ? -1 : 0); }
Expand Down
2 changes: 2 additions & 0 deletions MavLinkCom/common/utils/type_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include <valarray>

namespace mavlink_utils {

namespace type_utils {
// from: https://raw.githubusercontent.com/louisdx/cxx-prettyprint/master/prettyprint.hpp
// also see https://gist.github.com/louisdx/1076849

namespace detail {
// SFINAE type trait to detect whether T::const_iterator exists.

Expand Down
4 changes: 2 additions & 2 deletions MavLinkCom/include/AdHocConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace mavlinkcom_impl {
class AdHocConnectionImpl;
}

namespace mavlinkcom {
namespace mavlink_comm {

class AdHocConnection;

Expand Down Expand Up @@ -78,6 +78,6 @@ class AdHocConnection : public std::enable_shared_from_this<AdHocConnection> {
friend class MavLinkNode;
friend class mavlinkcom_impl::AdHocConnectionImpl;
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
4 changes: 2 additions & 2 deletions MavLinkCom/include/AsyncResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <memory>
#include <string>

namespace mavlinkcom {
namespace mavlink_comm {

template <class T> class AsyncResultState {
public:
Expand Down Expand Up @@ -123,6 +123,6 @@ template <class T> class AsyncResult {

std::shared_ptr<AsyncResultState<T>> state_;
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
4 changes: 2 additions & 2 deletions MavLinkCom/include/MavLinkConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MavLinkTcpServerImpl;
class MavLinkNodeImpl;
} // namespace mavlinkcom_impl

namespace mavlinkcom {
namespace mavlink_comm {

class MavLinkConnection;
class MavLinkNode;
Expand Down Expand Up @@ -161,6 +161,6 @@ class MavLinkConnection : public std::enable_shared_from_this<MavLinkConnection>
friend class mavlinkcom_impl::MavLinkConnectionImpl;
friend class mavlinkcom_impl::MavLinkTcpServerImpl;
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
4 changes: 2 additions & 2 deletions MavLinkCom/include/MavLinkDebugLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <iostream>
#include <string>

namespace mavlinkcom {
namespace mavlink_comm {

class MavLinkDebugLog {
public:
Expand All @@ -32,6 +32,6 @@ class MavLinkDebugLog {

virtual ~MavLinkDebugLog() = default;
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
4 changes: 2 additions & 2 deletions MavLinkCom/include/MavLinkFtpClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace mavlinkcom_impl {
class MavLinkFtpClientImpl;
}

namespace mavlinkcom {
namespace mavlink_comm {

struct MavLinkFileInfo {
public:
Expand Down Expand Up @@ -52,6 +52,6 @@ class MavLinkFtpClient : public MavLinkNode {

void cancel(); // cancel any pending operation.
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
10 changes: 5 additions & 5 deletions MavLinkCom/include/MavLinkLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

#define MAVLINK_STX_MAVLINK1 0xFE // marker for old protocol

namespace mavlinkcom {
namespace mavlink_comm {

// This abstract class defines the interface for logging MavLinkMessages.
class MavLinkLog {
public:
virtual void write(const mavlinkcom::MavLinkMessage &msg, uint64_t timestamp = 0) = 0;
virtual void write(const mavlink_comm::MavLinkMessage &msg, uint64_t timestamp = 0) = 0;
virtual ~MavLinkLog() = default;
};

Expand All @@ -37,10 +37,10 @@ class MavLinkFileLog : public MavLinkLog {
void openForReading(const std::string &filename);
void openForWriting(const std::string &filename, bool json = false);
void close();
virtual void write(const mavlinkcom::MavLinkMessage &msg, uint64_t timestamp = 0) override;
bool read(mavlinkcom::MavLinkMessage &msg, uint64_t &timestamp);
virtual void write(const mavlink_comm::MavLinkMessage &msg, uint64_t timestamp = 0) override;
bool read(mavlink_comm::MavLinkMessage &msg, uint64_t &timestamp);
static uint64_t getTimeStamp();
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
4 changes: 2 additions & 2 deletions MavLinkCom/include/MavLinkMessageBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MavLinkConnectionImpl;
class MavLinkNodeImpl;
} // namespace mavlinkcom_impl

namespace mavlinkcom {
namespace mavlink_comm {
class MavLinkConnection;

#define PayloadSize ((255 + 2 + 7) / 8)
Expand Down Expand Up @@ -180,6 +180,6 @@ class MavLinkTelemetry : public MavLinkMessageBase {
virtual int pack(char *buffer) const;
virtual int unpack(const char *buffer);
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
4 changes: 2 additions & 2 deletions MavLinkCom/include/MavLinkMessages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <stdint.h>
#include <string>

namespace mavlinkcom {
namespace mavlink_comm {

enum class MavLinkMessageIds {
MAVLINK_MSG_ID_HEARTBEAT = 0,
Expand Down Expand Up @@ -10679,6 +10679,6 @@ class MavCmdUser5 : public MavLinkCommand {
virtual void pack();
virtual void unpack();
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
4 changes: 2 additions & 2 deletions MavLinkCom/include/MavLinkNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace mavlinkcom_impl {
class MavLinkNodeImpl;
}

namespace mavlinkcom {
namespace mavlink_comm {

struct MavLinkParameter {
public:
Expand Down Expand Up @@ -105,6 +105,6 @@ class MavLinkNode {
protected:
std::unique_ptr<mavlinkcom_impl::MavLinkNodeImpl> pImpl;
};
} // namespace mavlinkcom
} // namespace mavlink_comm

#endif
Loading

0 comments on commit 399a1b2

Please sign in to comment.