Skip to content

Commit

Permalink
Comms: Update Mocklink Threading
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Jan 7, 2025
1 parent dc51270 commit 41c5085
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 131 deletions.
2 changes: 2 additions & 0 deletions src/Comms/MockLink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")

target_sources(MockLink
PRIVATE
MockConfiguration.cc
MockConfiguration.h
MockLink.cc
MockLink.h
MockLinkFTP.cc
Expand Down
76 changes: 76 additions & 0 deletions src/Comms/MockLink/MockConfiguration.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/****************************************************************************
*
* (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/

#include "MockConfiguration.h"
#include "QGCLoggingCategory.h"

QGC_LOGGING_CATEGORY(MockConfigurationLog, "qgc.comms.mocklink.mockconfiguration")

MockConfiguration::MockConfiguration(const QString &name, QObject *parent)
: LinkConfiguration(name, parent)
{
// qCDebug(MockConfigurationLog) << Q_FUNC_INFO << this;
}

MockConfiguration::MockConfiguration(const MockConfiguration *copy, QObject *parent)
: LinkConfiguration(copy, parent)
, _firmwareType(copy->firmwareType())
, _vehicleType(copy->vehicleType())
, _sendStatusText(copy->sendStatusText())
, _incrementVehicleId(copy->incrementVehicleId())
, _failureMode(copy->failureMode())
{
// qCDebug(MockConfigurationLog) << Q_FUNC_INFO << this;
}

MockConfiguration::~MockConfiguration()
{
// qCDebug(MockConfigurationLog) << Q_FUNC_INFO << this;
}

void MockConfiguration::copyFrom(const LinkConfiguration *source)
{
Q_ASSERT(source);
LinkConfiguration::copyFrom(source);

const MockConfiguration* const mockLinkSource = qobject_cast<const MockConfiguration*>(source);
Q_ASSERT(mockLinkSource);

setFirmwareType(mockLinkSource->firmwareType());
setVehicleType(mockLinkSource->vehicleType());
setSendStatusText(mockLinkSource->sendStatusText());
setIncrementVehicleId(mockLinkSource->incrementVehicleId());
setFailureMode(mockLinkSource->failureMode());
}

void MockConfiguration::loadSettings(QSettings &settings, const QString &root)
{
settings.beginGroup(root);

setFirmwareType(static_cast<MAV_AUTOPILOT>(settings.value(_firmwareTypeKey, static_cast<int>(MAV_AUTOPILOT_PX4)).toInt()));
setVehicleType(static_cast<MAV_TYPE>(settings.value(_vehicleTypeKey, static_cast<int>(MAV_TYPE_QUADROTOR)).toInt()));
setSendStatusText(settings.value(_sendStatusTextKey, false).toBool());
setIncrementVehicleId(settings.value(_incrementVehicleIdKey, true).toBool());
setFailureMode(static_cast<FailureMode_t>(settings.value(_failureModeKey, static_cast<int>(FailNone)).toInt()));

settings.endGroup();
}

void MockConfiguration::saveSettings(QSettings &settings, const QString &root)
{
settings.beginGroup(root);

settings.setValue(_firmwareTypeKey, firmwareType());
settings.setValue(_vehicleTypeKey, vehicleType());
settings.setValue(_sendStatusTextKey, sendStatusText());
settings.setValue(_incrementVehicleIdKey, incrementVehicleId());
settings.setValue(_failureModeKey, failureMode());

settings.endGroup();
}
88 changes: 88 additions & 0 deletions src/Comms/MockLink/MockConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/****************************************************************************
*
* (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/

#pragma once

#include "LinkConfiguration.h"
#include "MAVLinkLib.h"

#include <QtCore/QLoggingCategory>

Q_DECLARE_LOGGING_CATEGORY(MockConfigurationLog)

class MockConfiguration : public LinkConfiguration
{
Q_OBJECT
Q_PROPERTY(int firmware READ firmware WRITE setFirmware NOTIFY firmwareChanged)
Q_PROPERTY(int vehicle READ vehicle WRITE setVehicle NOTIFY vehicleChanged)
Q_PROPERTY(bool sendStatus READ sendStatusText WRITE setSendStatusText NOTIFY sendStatusChanged)
Q_PROPERTY(bool incrementVehicleId READ incrementVehicleId WRITE setIncrementVehicleId NOTIFY incrementVehicleIdChanged)

public:
explicit MockConfiguration(const QString &name, QObject *parent = nullptr);
explicit MockConfiguration(const MockConfiguration *copy, QObject *parent = nullptr);
~MockConfiguration();

LinkType type() const final { return LinkConfiguration::TypeMock; }
void copyFrom(const LinkConfiguration *source) final;
void loadSettings(QSettings &settings, const QString &root) final;
void saveSettings(QSettings &settings, const QString &root) final;
QString settingsURL() final { return QStringLiteral("MockLinkSettings.qml"); }
QString settingsTitle() final { return tr("Mock Link Settings"); }

int firmware() const { return static_cast<int>(_firmwareType); }
void setFirmware(int type) { _firmwareType = static_cast<MAV_AUTOPILOT>(type); emit firmwareChanged(); }
int vehicle() const { return static_cast<int>(_vehicleType); }
void setVehicle(int type) { _vehicleType = static_cast<MAV_TYPE>(type); emit vehicleChanged(); }
bool incrementVehicleId() const { return _incrementVehicleId; }
void setIncrementVehicleId(bool incrementVehicleId) { _incrementVehicleId = incrementVehicleId; emit incrementVehicleIdChanged(); }
MAV_AUTOPILOT firmwareType() const { return _firmwareType; }
void setFirmwareType(MAV_AUTOPILOT firmwareType) { _firmwareType = firmwareType; emit firmwareChanged(); }
uint16_t boardVendorId() const { return _boardVendorId; }
uint16_t boardProductId() const { return _boardProductId; }
void setBoardVendorProduct(uint16_t vendorId, uint16_t productId) { _boardVendorId = vendorId; _boardProductId = productId; }
MAV_TYPE vehicleType() const { return _vehicleType; }
void setVehicleType(MAV_TYPE vehicleType) { _vehicleType = vehicleType; emit vehicleChanged(); }
bool sendStatusText() const { return _sendStatusText; }
void setSendStatusText(bool sendStatusText) { _sendStatusText = sendStatusText; emit sendStatusChanged(); }

enum FailureMode_t {
FailNone, // No failures
FailParamNoReponseToRequestList, // Do no respond to PARAM_REQUEST_LIST
FailMissingParamOnInitialReqest, // Not all params are sent on initial request, should still succeed since QGC will re-query missing params
FailMissingParamOnAllRequests, // Not all params are sent on initial request, QGC retries will fail as well
FailInitialConnectRequestMessageAutopilotVersionFailure, // REQUEST_MESSAGE:AUTOPILOT_VERSION returns failure
FailInitialConnectRequestMessageAutopilotVersionLost, // REQUEST_MESSAGE:AUTOPILOT_VERSION success, AUTOPILOT_VERSION never sent
FailInitialConnectRequestMessageProtocolVersionFailure, // REQUEST_MESSAGE:PROTOCOL_VERSION returns failure
FailInitialConnectRequestMessageProtocolVersionLost, // REQUEST_MESSAGE:PROTOCOL_VERSION success, PROTOCOL_VERSION never sent
};
FailureMode_t failureMode() const { return _failureMode; }
void setFailureMode(FailureMode_t failureMode) { _failureMode = failureMode; }

signals:
void firmwareChanged();
void vehicleChanged();
void sendStatusChanged();
void incrementVehicleIdChanged();

private:
MAV_AUTOPILOT _firmwareType = MAV_AUTOPILOT_PX4;
MAV_TYPE _vehicleType = MAV_TYPE_QUADROTOR;
bool _sendStatusText = false;
FailureMode_t _failureMode = FailNone;
bool _incrementVehicleId = true;
uint16_t _boardVendorId = 0;
uint16_t _boardProductId = 0;

static constexpr const char *_firmwareTypeKey = "FirmwareType";
static constexpr const char *_vehicleTypeKey = "VehicleType";
static constexpr const char *_sendStatusTextKey = "SendStatusText";
static constexpr const char *_incrementVehicleIdKey = "IncrementVehicleId";
static constexpr const char *_failureModeKey = "FailureMode";
};
56 changes: 0 additions & 56 deletions src/Comms/MockLink/MockLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1438,62 +1438,6 @@ void MockLink::_sendStatusTextMessages(void)
_sendChunkedStatusText(4, true /* missingChunks */); // This should cause the timeout to fire
}

MockConfiguration::MockConfiguration(const QString& name)
: LinkConfiguration(name)
{

}

MockConfiguration::MockConfiguration(const MockConfiguration* source)
: LinkConfiguration(source)
{
_firmwareType = source->_firmwareType;
_vehicleType = source->_vehicleType;
_sendStatusText = source->_sendStatusText;
_incrementVehicleId = source->_incrementVehicleId;
_failureMode = source->_failureMode;
}

void MockConfiguration::copyFrom(const LinkConfiguration *source)
{
LinkConfiguration::copyFrom(source);
const MockConfiguration* usource = qobject_cast<const MockConfiguration*>(source);

if (!usource) {
qCWarning(MockLinkLog) << "dynamic_cast failed" << source << usource;
return;
}

_firmwareType = usource->_firmwareType;
_vehicleType = usource->_vehicleType;
_sendStatusText = usource->_sendStatusText;
_incrementVehicleId = usource->_incrementVehicleId;
_failureMode = usource->_failureMode;
}

void MockConfiguration::saveSettings(QSettings& settings, const QString& root)
{
settings.beginGroup(root);
settings.setValue(_firmwareTypeKey, (int)_firmwareType);
settings.setValue(_vehicleTypeKey, (int)_vehicleType);
settings.setValue(_sendStatusTextKey, _sendStatusText);
settings.setValue(_incrementVehicleIdKey, _incrementVehicleId);
settings.setValue(_failureModeKey, (int)_failureMode);
settings.sync();
settings.endGroup();
}

void MockConfiguration::loadSettings(QSettings& settings, const QString& root)
{
settings.beginGroup(root);
_firmwareType = (MAV_AUTOPILOT)settings.value(_firmwareTypeKey, (int)MAV_AUTOPILOT_PX4).toInt();
_vehicleType = (MAV_TYPE)settings.value(_vehicleTypeKey, (int)MAV_TYPE_QUADROTOR).toInt();
_sendStatusText = settings.value(_sendStatusTextKey, false).toBool();
_incrementVehicleId = settings.value(_incrementVehicleIdKey, true).toBool();
_failureMode = (FailureMode_t)settings.value(_failureModeKey, (int)FailNone).toInt();
settings.endGroup();
}

MockLink* MockLink::_startMockLink(MockConfiguration* mockConfig)
{
mockConfig->setDynamic(true);
Expand Down
76 changes: 1 addition & 75 deletions src/Comms/MockLink/MockLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#pragma once

#include "MockConfiguration.h"
#include "MockLinkMissionItemHandler.h"
#include "MockLinkFTP.h"
#include "QGCMAVLink.h"
Expand All @@ -26,81 +27,6 @@ Q_DECLARE_LOGGING_CATEGORY(MockLinkVerboseLog)

class LinkManager;

class MockConfiguration : public LinkConfiguration
{
Q_OBJECT

public:
MockConfiguration(const QString& name);
MockConfiguration(const MockConfiguration* source);

Q_PROPERTY(int firmware READ firmware WRITE setFirmware NOTIFY firmwareChanged)
Q_PROPERTY(int vehicle READ vehicle WRITE setVehicle NOTIFY vehicleChanged)
Q_PROPERTY(bool sendStatus READ sendStatusText WRITE setSendStatusText NOTIFY sendStatusChanged)
Q_PROPERTY(bool incrementVehicleId READ incrementVehicleId WRITE setIncrementVehicleId NOTIFY incrementVehicleIdChanged)

int firmware (void) { return (int)_firmwareType; }
void setFirmware (int type) { _firmwareType = (MAV_AUTOPILOT)type; emit firmwareChanged(); }
int vehicle (void) { return (int)_vehicleType; }
bool incrementVehicleId (void) const { return _incrementVehicleId; }
void setVehicle (int type) { _vehicleType = (MAV_TYPE)type; emit vehicleChanged(); }
void setIncrementVehicleId (bool incrementVehicleId) { _incrementVehicleId = incrementVehicleId; emit incrementVehicleIdChanged(); }


MAV_AUTOPILOT firmwareType (void) { return _firmwareType; }
uint16_t boardVendorId (void) { return _boardVendorId; }
uint16_t boardProductId (void) { return _boardProductId; }
MAV_TYPE vehicleType (void) { return _vehicleType; }
bool sendStatusText (void) const { return _sendStatusText; }

void setFirmwareType (MAV_AUTOPILOT firmwareType) { _firmwareType = firmwareType; emit firmwareChanged(); }
void setBoardVendorProduct(uint16_t vendorId, uint16_t productId) { _boardVendorId = vendorId; _boardProductId = productId; }
void setVehicleType (MAV_TYPE vehicleType) { _vehicleType = vehicleType; emit vehicleChanged(); }
void setSendStatusText (bool sendStatusText) { _sendStatusText = sendStatusText; emit sendStatusChanged(); }

typedef enum {
FailNone, // No failures
FailParamNoReponseToRequestList, // Do no respond to PARAM_REQUEST_LIST
FailMissingParamOnInitialReqest, // Not all params are sent on initial request, should still succeed since QGC will re-query missing params
FailMissingParamOnAllRequests, // Not all params are sent on initial request, QGC retries will fail as well
FailInitialConnectRequestMessageAutopilotVersionFailure, // REQUEST_MESSAGE:AUTOPILOT_VERSION returns failure
FailInitialConnectRequestMessageAutopilotVersionLost, // REQUEST_MESSAGE:AUTOPILOT_VERSION success, AUTOPILOT_VERSION never sent
FailInitialConnectRequestMessageProtocolVersionFailure, // REQUEST_MESSAGE:PROTOCOL_VERSION returns failure
FailInitialConnectRequestMessageProtocolVersionLost, // REQUEST_MESSAGE:PROTOCOL_VERSION success, PROTOCOL_VERSION never sent
} FailureMode_t;
FailureMode_t failureMode(void) { return _failureMode; }
void setFailureMode(FailureMode_t failureMode) { _failureMode = failureMode; }

// Overrides from LinkConfiguration
LinkType type (void) const override { return LinkConfiguration::TypeMock; }
void copyFrom (const LinkConfiguration* source) override;
void loadSettings (QSettings& settings, const QString& root) override;
void saveSettings (QSettings& settings, const QString& root) override;
QString settingsURL (void) override { return "MockLinkSettings.qml"; }
QString settingsTitle (void) override { return tr("Mock Link Settings"); }

signals:
void firmwareChanged (void);
void vehicleChanged (void);
void sendStatusChanged (void);
void incrementVehicleIdChanged (void);

private:
MAV_AUTOPILOT _firmwareType = MAV_AUTOPILOT_PX4;
MAV_TYPE _vehicleType = MAV_TYPE_QUADROTOR;
bool _sendStatusText = false;
FailureMode_t _failureMode = FailNone;
bool _incrementVehicleId = true;
uint16_t _boardVendorId = 0;
uint16_t _boardProductId = 0;

static constexpr const char* _firmwareTypeKey = "FirmwareType";
static constexpr const char* _vehicleTypeKey = "VehicleType";
static constexpr const char* _sendStatusTextKey = "SendStatusText";
static constexpr const char* _incrementVehicleIdKey = "IncrementVehicleId";
static constexpr const char* _failureModeKey = "FailureMode";
};

class MockLink : public LinkInterface
{
Q_OBJECT
Expand Down

0 comments on commit 41c5085

Please sign in to comment.