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 eb2e314 commit 9cdcde4
Show file tree
Hide file tree
Showing 6 changed files with 1,101 additions and 1,095 deletions.
2 changes: 1 addition & 1 deletion src/Comms/LinkManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ bool LinkManager::createConnectedLink(SharedLinkConfigurationPtr &config)
return false;
}

(void) _rgLinks.append(link);
_rgLinks.append(link);
config->setLink(link);

(void) connect(link.get(), &LinkInterface::communicationError, qgcApp(), &QGCApplication::showAppMessage);
Expand Down
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";
};
Loading

0 comments on commit 9cdcde4

Please sign in to comment.