Commit d4e6eca7 authored by Dennis Shtatnov's avatar Dennis Shtatnov

Component for configuring CF2 Radio

parent ffdf08e8
......@@ -806,6 +806,8 @@ HEADERS+= \
src/AutoPilotPlugins/Common/MixersComponent.h \
src/AutoPilotPlugins/Common/MotorComponent.h \
src/AutoPilotPlugins/Common/RadioComponentController.h \
src/AutoPilotPlugins/Common/SyslinkComponent.h \
src/AutoPilotPlugins/Common/SyslinkComponentController.h \
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.h \
src/FirmwarePlugin/CameraMetaData.h \
src/FirmwarePlugin/FirmwarePlugin.h \
......@@ -829,6 +831,8 @@ SOURCES += \
src/AutoPilotPlugins/Common/MixersComponent.cc \
src/AutoPilotPlugins/Common/MotorComponent.cc \
src/AutoPilotPlugins/Common/RadioComponentController.cc \
src/AutoPilotPlugins/Common/SyslinkComponent.cc \
src/AutoPilotPlugins/Common/SyslinkComponentController.cc \
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.cc \
src/FirmwarePlugin/CameraMetaData.cc \
src/FirmwarePlugin/FirmwarePlugin.cc \
......
......@@ -24,6 +24,7 @@
<file alias="DebugWindow.qml">src/ui/preferences/DebugWindow.qml</file>
<file alias="ESP8266Component.qml">src/AutoPilotPlugins/Common/ESP8266Component.qml</file>
<file alias="ESP8266ComponentSummary.qml">src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml</file>
<file alias="SyslinkComponent.qml">src/AutoPilotPlugins/Common/SyslinkComponent.qml</file>
<file alias="FirmwareUpgrade.qml">src/VehicleSetup/FirmwareUpgrade.qml</file>
<file alias="FlightDisplayViewDummy.qml">src/FlightDisplay/FlightDisplayViewDummy.qml</file>
<file alias="FlightDisplayViewUVC.qml">src/FlightDisplay/FlightDisplayViewUVC.qml</file>
......
/****************************************************************************
*
* (c) 2009-2016 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 "SyslinkComponent.h"
#include "AutoPilotPlugin.h"
SyslinkComponent::SyslinkComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
: VehicleComponent(vehicle, autopilot, parent)
, _name(tr("Syslink"))
{
}
QString SyslinkComponent::name(void) const
{
return _name;
}
QString SyslinkComponent::description(void) const
{
return tr("The Syslink Component is used to setup the radio connection on Crazyflies.");
}
QString SyslinkComponent::iconResource(void) const
{
return "/qmlimages/wifi.svg";
}
bool SyslinkComponent::requiresSetup(void) const
{
return false;
}
bool SyslinkComponent::setupComplete(void) const
{
return true;
}
QStringList SyslinkComponent::setupCompleteChangedTriggerList(void) const
{
return QStringList();
}
QUrl SyslinkComponent::setupSource(void) const
{
return QUrl::fromUserInput("qrc:/qml/SyslinkComponent.qml");
}
QUrl SyslinkComponent::summaryQmlSource(void) const
{
return QUrl();
}
QString SyslinkComponent::prerequisiteSetup(void) const
{
return QString();
}
/****************************************************************************
*
* (c) 2009-2016 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.
*
****************************************************************************/
#ifndef SyslinkComponent_H
#define SyslinkComponent_H
#include "VehicleComponent.h"
class SyslinkComponent : public VehicleComponent
{
Q_OBJECT
public:
SyslinkComponent (Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent = NULL);
// Virtuals from VehicleComponent
QStringList setupCompleteChangedTriggerList() const;
// Virtuals from VehicleComponent
QString name () const;
QString description () const;
QString iconResource () const;
bool requiresSetup () const;
bool setupComplete () const;
QUrl setupSource () const;
QUrl summaryQmlSource () const;
QString prerequisiteSetup () const;
private:
const QString _name;
QVariantList _summaryItems;
};
#endif
/****************************************************************************
*
* (c) 2009-2016 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.
*
****************************************************************************/
import QtQuick 2.5
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.2
import QGroundControl 1.0
import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controllers 1.0
QGCView {
id: qgcView
viewPanel: panel
QGCPalette { id: palette; colorGroupEnabled: panel.enabled }
property real _margins: ScreenTools.defaultFontPixelHeight
property real _editFieldWidth: ScreenTools.defaultFontPixelWidth * 16
property real _labelWidth: ScreenTools.defaultFontPixelWidth * 18
SyslinkComponentController {
id: controller
factPanel: panel
}
QGCViewPanel {
id: panel
anchors.fill: parent
Flickable {
clip: true
anchors.fill: parent
contentHeight: mainCol.height
flickableDirection: Flickable.VerticalFlick
Column {
id: mainCol
spacing: _margins
anchors.horizontalCenter: parent.horizontalCenter
Item { width: 1; height: _margins * 0.5; }
Rectangle {
color: palette.windowShade
height: settingsRow.height + _margins * 2
Row {
id: settingsRow
spacing: _margins * 4
anchors.centerIn: parent
Column {
spacing: _margins * 0.5
anchors.verticalCenter: parent.verticalCenter
Row {
QGCLabel {
text: qsTr("NRF Radio Settings")
font.family: ScreenTools.demiboldFontFamily
}
}
Row {
QGCLabel {
text: qsTr("Channel")
width: _labelWidth
anchors.baseline: channelField.baseline
}
QGCTextField {
id: channelField
width: _editFieldWidth
text: controller.radioChannel
validator: IntValidator {bottom: 0; top: 125;}
inputMethodHints: Qt.ImhDigitsOnly
onEditingFinished: {
controller.radioChannel = text
}
}
}
Row {
anchors.right: parent.right
QGCLabel {
wrapMode: Text.WordWrap
text: qsTr("Channel can be between 0 and 125")
}
}
Row {
QGCLabel {
text: qsTr("Address")
width: _labelWidth
anchors.baseline: addressField.baseline
}
QGCTextField {
id: addressField
width: _editFieldWidth
text: controller.radioAddress
maximumLength: 10
validator: RegExpValidator { regExp: /^[0-9A-Fa-f]*$/ }
onEditingFinished: {
controller.radioAddress = text
}
}
}
Row {
anchors.right: parent.right
QGCLabel {
wrapMode: Text.WordWrap
text: qsTr("Address in hex. Default E7E7E7E7E7")
}
}
Row {
QGCLabel {
text: qsTr("Data Rate")
width: _labelWidth
anchors.baseline: rateField.baseline
}
QGCComboBox {
id: rateField
width: _editFieldWidth
model: controller.radioRates
currentIndex: controller.radioRate
onActivated: {
controller.radioRate = index
}
}
}
Row {
spacing: _margins
anchors.horizontalCenter: parent.horizontalCenter
QGCButton {
text: qsTr("Restore Defaults")
width: _editFieldWidth
onClicked: {
controller.resetDefaults()
}
}
}
}
}
}
}
}
}
}
/****************************************************************************
*
* (c) 2009-2016 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 "SyslinkComponentController.h"
#include "QGCApplication.h"
#include "UAS.h"
#include "ParameterManager.h"
#include <QHostAddress>
#include <QtEndian>
QGC_LOGGING_CATEGORY(SyslinkComponentControllerLog, "SyslinkComponentControllerLog")
//-----------------------------------------------------------------------------
SyslinkComponentController::SyslinkComponentController()
{
_dataRates.append("750Kb/s");
_dataRates.append("1Mb/s");
_dataRates.append("2Mb/s");
Fact* chan = getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN");
connect(chan, &Fact::valueChanged, this, &SyslinkComponentController::_channelChanged);
Fact* rate = getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE");
connect(rate, &Fact::valueChanged, this, &SyslinkComponentController::_rateChanged);
Fact* addr1 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1");
connect(addr1, &Fact::valueChanged, this, &SyslinkComponentController::_addressChanged);
Fact* addr2 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2");
connect(addr2, &Fact::valueChanged, this, &SyslinkComponentController::_addressChanged);
}
//-----------------------------------------------------------------------------
SyslinkComponentController::~SyslinkComponentController()
{
}
//-----------------------------------------------------------------------------
int
SyslinkComponentController::radioChannel()
{
return getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN")->rawValue().toUInt();
}
//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioChannel(int num)
{
Fact* f = getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN");
f->setRawValue(QVariant(num));
}
//-----------------------------------------------------------------------------
QString
SyslinkComponentController::radioAddress()
{
uint32_t val_uh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1")->rawValue().toUInt();
uint32_t val_lh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2")->rawValue().toUInt();
uint64_t val = (((uint64_t) val_uh) << 32) | ((uint64_t) val_lh);
return QString().number(val, 16);
}
//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioAddress(QString str)
{
Fact *uh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1");
Fact *lh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2");
uint64_t val = str.toULongLong(0, 16);
uint32_t val_uh = val >> 32;
uint32_t val_lh = val & 0xFFFFFFFF;
uh->setRawValue(QVariant(val_uh));
lh->setRawValue(QVariant(val_lh));
}
//-----------------------------------------------------------------------------
int
SyslinkComponentController::radioRate()
{
return getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE")->rawValue().toInt();
}
//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioRate(int idx)
{
if(idx >= 0 && idx <= 2 && idx != radioRate()) {
Fact* r = getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE");
r->setRawValue(idx);
}
}
//-----------------------------------------------------------------------------
void
SyslinkComponentController::resetDefaults()
{
Fact* chan = getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN");
Fact* rate = getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE");
Fact* addr1 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1");
Fact* addr2 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2");
chan->setRawValue(chan->rawDefaultValue());
rate->setRawValue(rate->rawDefaultValue());
addr1->setRawValue(addr1->rawDefaultValue());
addr2->setRawValue(addr2->rawDefaultValue());
}
//-----------------------------------------------------------------------------
void
SyslinkComponentController::_channelChanged(QVariant)
{
emit radioChannelChanged();
}
//-----------------------------------------------------------------------------
void
SyslinkComponentController::_addressChanged(QVariant)
{
emit radioAddressChanged();
}
//-----------------------------------------------------------------------------
void
SyslinkComponentController::_rateChanged(QVariant)
{
emit radioRateChanged();
}
/****************************************************************************
*
* (c) 2009-2016 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.
*
****************************************************************************/
#ifndef SyslinkComponentController_H
#define SyslinkComponentController_H
#include "FactPanelController.h"
#include "UASInterface.h"
#include "QGCLoggingCategory.h"
#include "AutoPilotPlugin.h"
Q_DECLARE_LOGGING_CATEGORY(SyslinkComponentControllerLog)
namespace Ui {
class SyslinkComponentController;
}
class SyslinkComponentController : public FactPanelController
{
Q_OBJECT
public:
SyslinkComponentController ();
~SyslinkComponentController ();
Q_PROPERTY(int radioChannel READ radioChannel WRITE setRadioChannel NOTIFY radioChannelChanged)
Q_PROPERTY(QString radioAddress READ radioAddress WRITE setRadioAddress NOTIFY radioAddressChanged)
Q_PROPERTY(int radioRate READ radioRate WRITE setRadioRate NOTIFY radioRateChanged)
Q_PROPERTY(QStringList radioRates READ radioRates CONSTANT)
Q_PROPERTY(Vehicle* vehicle READ vehicle CONSTANT)
Q_INVOKABLE void resetDefaults();
int radioChannel ();
QString radioAddress ();
int radioRate ();
QStringList radioRates () { return _dataRates; }
Vehicle* vehicle () { return _vehicle; }
void setRadioChannel (int num);
void setRadioAddress (QString str);
void setRadioRate (int idx);
signals:
void radioChannelChanged ();
void radioAddressChanged ();
void radioRateChanged ();
private slots:
void _channelChanged (QVariant value);
void _addressChanged (QVariant value);
void _rateChanged (QVariant value);
private:
QStringList _dataRates;
};
#endif // SyslinkComponentController_H
......@@ -40,6 +40,7 @@ PX4AutoPilotPlugin::PX4AutoPilotPlugin(Vehicle* vehicle, QObject* parent)
, _motorComponent(NULL)
, _tuningComponent(NULL)
, _mixersComponent(NULL)
, _syslinkComponent(NULL)
{
if (!vehicle) {
qWarning() << "Internal error";
......@@ -122,6 +123,12 @@ const QVariantList& PX4AutoPilotPlugin::vehicleComponents(void)
} else {
qWarning() << "Call to vehicleCompenents prior to parametersReady";
}
if(_vehicle->parameterManager()->parameterExists(_vehicle->id(), "SLNK_RADIO_CHAN")) {
_syslinkComponent = new SyslinkComponent(_vehicle, this);
_syslinkComponent->setupTriggerSignals();
_components.append(QVariant::fromValue((VehicleComponent*)_syslinkComponent));
}
} else {
qWarning() << "Internal error";
}
......
......@@ -24,6 +24,7 @@
#include "MotorComponent.h"
#include "PX4TuningComponent.h"
#include "MixersComponent.h"
#include "SyslinkComponent.h"
#include "Vehicle.h"
#include <QImage>
......@@ -44,7 +45,6 @@ public:
const QVariantList& vehicleComponents(void) override;
void parametersReadyPreChecks(void) override;
QString prerequisiteSetup(VehicleComponent* component) const override;
protected:
bool _incorrectParameterVersion; ///< true: parameter version incorrect, setup not allowed
PX4AirframeLoader* _airframeFacts;
......@@ -59,7 +59,7 @@ protected:
MotorComponent* _motorComponent;
PX4TuningComponent* _tuningComponent;
MixersComponent* _mixersComponent;
SyslinkComponent* _syslinkComponent;
private:
QVariantList _components;
};
......
......@@ -51,6 +51,7 @@
#include "ScreenToolsController.h"
#include "QFileDialogController.h"
#include "RCChannelMonitorController.h"
#include "SyslinkComponentController.h"
#include "AutoPilotPlugin.h"
#include "VehicleComponent.h"
#include "FirmwarePluginManager.h"
......@@ -390,6 +391,7 @@ void QGCApplication::_initCommon(void)
qmlRegisterType<RCChannelMonitorController> ("QGroundControl.Controllers", 1, 0, "RCChannelMonitorController");
qmlRegisterType<JoystickConfigController> ("QGroundControl.Controllers", 1, 0, "JoystickConfigController");
qmlRegisterType<LogDownloadController> ("QGroundControl.Controllers", 1, 0, "LogDownloadController");
qmlRegisterType<SyslinkComponentController> ("QGroundControl.Controllers", 1, 0, "SyslinkComponentController");
#ifndef __mobile__
qmlRegisterType<ViewWidgetController> ("QGroundControl.Controllers", 1, 0, "ViewWidgetController");
qmlRegisterType<CustomCommandWidgetController> ("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment