Commit e26e1af3 authored by Gus Grubba's avatar Gus Grubba

Merge pull request #2318 from dogmaphobic/linkSettings

Link Settings (WIP)
parents 73b18544 1a419660
......@@ -135,6 +135,9 @@ LinkConfiguration* LinkConfiguration::duplicateSettings(LinkConfiguration* sourc
dupe = new MockConfiguration(dynamic_cast<MockConfiguration*>(source));
break;
#endif
case TypeLast:
default:
break;
}
return dupe;
}
......
......@@ -33,6 +33,7 @@ class LinkInterface;
class LinkConfiguration : public QObject
{
Q_OBJECT
Q_ENUMS(LinkType)
public:
LinkConfiguration(const QString& name);
......@@ -41,6 +42,7 @@ public:
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(LinkInterface* link READ link WRITE setLink NOTIFY linkChanged)
Q_PROPERTY(LinkType linkType READ type CONSTANT)
// Property accessors
......@@ -51,7 +53,7 @@ public:
void setLink(LinkInterface* link);
/// The link types supported by QGC
enum {
enum LinkType {
#ifndef __ios__
TypeSerial, ///< Serial Link
#endif
......@@ -88,7 +90,7 @@ public:
* Pure virtual method returning one of the -TypeXxx types above.
* @return The type of links these settings belong to.
*/
virtual int type() = 0;
virtual LinkType type() = 0;
/*!
* @brief Load settings
......
......@@ -124,6 +124,9 @@ LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config)
pLink = new MockLink(dynamic_cast<MockConfiguration*>(config));
break;
#endif
case LinkConfiguration::TypeLast:
default:
break;
}
if(pLink) {
_addLink(pLink);
......@@ -661,3 +664,46 @@ void LinkManager::setAutoconnectPX4Flow(bool autoconnect)
}
}
QStringList LinkManager::linkTypeStrings(void) const
{
//-- Must follow same order as enum LinkType in LinkConfiguration.h
static QStringList list;
if(!list.size())
{
#ifndef __ios__
list += "Serial";
#endif
list += "UDP";
list += "TCP";
list += "Mock Link";
list += "Log Replay";
}
return list;
}
QStringList LinkManager::serialPortStrings(void)
{
#ifndef __ios__
if(!_commPortList.size())
{
QList<QSerialPortInfo> portList = QSerialPortInfo::availablePorts();
foreach (const QSerialPortInfo &info, portList)
{
QString name = info.portName();
_commPortList += name;
}
}
#endif
return _commPortList;
}
QStringList LinkManager::serialBaudRates(void)
{
#ifdef __ios__
QStringList foo;
return foo;
#else
return SerialConfiguration::supportedBaudRates();
#endif
}
......@@ -78,10 +78,17 @@ public:
Q_PROPERTY(bool autoconnectPixhawk READ autoconnectPixhawk WRITE setAutoconnectPixhawk NOTIFY autoconnectPixhawkChanged)
Q_PROPERTY(bool autoconnect3DRRadio READ autoconnect3DRRadio WRITE setAutoconnect3DRRadio NOTIFY autoconnect3DRRadioChanged)
Q_PROPERTY(bool autoconnectPX4Flow READ autoconnectPX4Flow WRITE setAutoconnectPX4Flow NOTIFY autoconnectPX4FlowChanged)
//-- LinkInterface
/// LinkInterface Accessor
Q_PROPERTY(QmlObjectListModel* links READ links CONSTANT)
//-- LinkConfiguration
/// LinkConfiguration Accessor
Q_PROPERTY(QmlObjectListModel* linkConfigurations READ linkConfigurations CONSTANT)
/// List of comm type strings
Q_PROPERTY(QStringList linkTypeStrings READ linkTypeStrings CONSTANT)
/// List of supported baud rates for serial links
Q_PROPERTY(QStringList serialBaudRates READ serialBaudRates CONSTANT)
/// List of comm ports
Q_PROPERTY(QStringList serialPortStrings READ serialPortStrings NOTIFY commPortStringsChanged)
// Property accessors
......@@ -92,14 +99,16 @@ public:
bool autoconnect3DRRadio(void) { return _autoconnect3DRRadio; }
bool autoconnectPX4Flow(void) { return _autoconnectPX4Flow; }
QmlObjectListModel* links(void) { return &_links; }
QmlObjectListModel* linkConfigurations(void) { return &_linkConfigurations; }
void setAutoconnectUDP(bool autoconnect);
void setAutoconnectPixhawk(bool autoconnect);
void setAutoconnect3DRRadio(bool autoconnect);
void setAutoconnectPX4Flow(bool autoconnect);
QmlObjectListModel* links (void) { return &_links; }
QmlObjectListModel* linkConfigurations (void) { return &_linkConfigurations; }
QStringList linkTypeStrings (void) const;
QStringList serialBaudRates (void);
QStringList serialPortStrings (void);
void setAutoconnectUDP (bool autoconnect);
void setAutoconnectPixhawk (bool autoconnect);
void setAutoconnect3DRRadio (bool autoconnect);
void setAutoconnectPX4Flow (bool autoconnect);
/// Load list of link configurations from disk
void loadLinkConfigurationList();
......@@ -178,6 +187,7 @@ signals:
void linkInactive(LinkInterface* link);
void linkConfigurationChanged();
void commPortStringsChanged();
private slots:
void _linkConnected(void);
......@@ -207,6 +217,7 @@ private:
QmlObjectListModel _autoconnectConfigurations;
QStringList _autoconnectWaitList;
QStringList _commPortList;
bool _autoconnectUDP;
bool _autoconnectPixhawk;
......
......@@ -45,7 +45,7 @@ public:
QString logFilenameShort(void);
// Virtuals from LinkConfiguration
virtual int type() { return LinkConfiguration::TypeLogReplay; }
virtual LinkType type() { return LinkConfiguration::TypeLogReplay; }
virtual void copyFrom(LinkConfiguration* source);
virtual void loadSettings(QSettings& settings, const QString& root);
virtual void saveSettings(QSettings& settings, const QString& root);
......
......@@ -54,7 +54,7 @@ public:
bool sendStatusText(void) { return _sendStatusText; }
// Overrides from LinkConfiguration
int type(void) { return LinkConfiguration::TypeMock; }
LinkType type(void) { return LinkConfiguration::TypeMock; }
void copyFrom(LinkConfiguration* source);
void loadSettings(QSettings& settings, const QString& root);
void saveSettings(QSettings& settings, const QString& root);
......
......@@ -28,6 +28,8 @@
QGC_LOGGING_CATEGORY(SerialLinkLog, "SerialLinkLog")
static QStringList kSupportedBaudRates;
SerialLink::SerialLink(SerialConfiguration* config)
{
_bytesRead = 0;
......@@ -481,3 +483,60 @@ void SerialConfiguration::loadSettings(QSettings& settings, const QString& root)
if(settings.contains("portName")) _portName = settings.value("portName").toString();
settings.endGroup();
}
QStringList SerialConfiguration::supportedBaudRates()
{
if(!kSupportedBaudRates.size())
_initBaudRates();
return kSupportedBaudRates;
}
void SerialConfiguration::_initBaudRates()
{
kSupportedBaudRates.clear();
#if USE_ANCIENT_RATES
#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_DARWIN)
kSupportedBaudRates << "50";
kSupportedBaudRates << "75";
#endif
kSupportedBaudRates << "110";
#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_DARWIN)
kSupportedBaudRates << "134";
kSupportedBaudRates << "150";
kSupportedBaudRates << "200";
#endif
kSupportedBaudRates << "300";
kSupportedBaudRates << "600";
kSupportedBaudRates << "1200";
#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_DARWIN)
kSupportedBaudRates << "1800";
#endif
#endif
kSupportedBaudRates << "2400";
kSupportedBaudRates << "4800";
kSupportedBaudRates << "9600";
#if defined(Q_OS_WIN)
kSupportedBaudRates << "14400";
#endif
kSupportedBaudRates << "19200";
kSupportedBaudRates << "38400";
#if defined(Q_OS_WIN)
kSupportedBaudRates << "56000";
#endif
kSupportedBaudRates << "57600";
kSupportedBaudRates << "115200";
#if defined(Q_OS_WIN)
kSupportedBaudRates << "128000";
#endif
kSupportedBaudRates << "230400";
#if defined(Q_OS_WIN)
kSupportedBaudRates << "256000";
#endif
kSupportedBaudRates << "460800";
#if defined(Q_OS_LINUX)
kSupportedBaudRates << "500000";
kSupportedBaudRates << "576000";
#endif
kSupportedBaudRates << "921600";
}
......@@ -81,13 +81,18 @@ public:
void setParity (int parity); ///< QSerialPort Enums
void setPortName (const QString& portName);
static QStringList supportedBaudRates();
/// From LinkConfiguration
int type() { return LinkConfiguration::TypeSerial; }
LinkType type() { return LinkConfiguration::TypeSerial; }
void copyFrom(LinkConfiguration* source);
void loadSettings(QSettings& settings, const QString& root);
void saveSettings(QSettings& settings, const QString& root);
void updateSettings();
private:
static void _initBaudRates();
private:
int _baud;
int _dataBits;
......
......@@ -103,7 +103,7 @@ public:
void setAddress (const QHostAddress& address);
/// From LinkConfiguration
int type() { return LinkConfiguration::TypeTcp; }
LinkType type() { return LinkConfiguration::TypeTcp; }
void copyFrom(LinkConfiguration* source);
void loadSettings(QSettings& settings, const QString& root);
void saveSettings(QSettings& settings, const QString& root);
......
......@@ -136,7 +136,7 @@ public:
void setLocalPort (quint16 port);
/// From LinkConfiguration
int type() { return LinkConfiguration::TypeUdp; }
LinkType type() { return LinkConfiguration::TypeUdp; }
void copyFrom(LinkConfiguration* source);
void loadSettings(QSettings& settings, const QString& root);
void saveSettings(QSettings& settings, const QString& root);
......
......@@ -178,6 +178,9 @@ void QGCLinkConfiguration::_fixUnnamed(LinkConfiguration* config)
QString("Mock Link"));
break;
#endif
case LinkConfiguration::TypeLast:
default:
break;
}
}
}
......
......@@ -63,57 +63,11 @@ SerialConfigurationWindow::SerialConfigurationWindow(SerialConfiguration *config
// Keep track of all desired baud rates by OS. These are iterated through
// later and added to _ui.baudRate.
QList<int> supportedBaudRates;
#if USE_ANCIENT_RATES
// Baud rates supported only by POSIX systems
#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_DARWIN)
supportedBaudRates << 50;
supportedBaudRates << 75;
supportedBaudRates << 134;
supportedBaudRates << 150;
supportedBaudRates << 200;
supportedBaudRates << 1800;
#endif
#endif //USE_ANCIENT_RATES
// Baud rates supported only by Windows
#if defined(Q_OS_WIN)
supportedBaudRates << 14400;
supportedBaudRates << 56000;
supportedBaudRates << 128000;
supportedBaudRates << 256000;
#endif
// Baud rates supported by everyone
#if USE_ANCIENT_RATES
supportedBaudRates << 110;
supportedBaudRates << 300;
supportedBaudRates << 600;
supportedBaudRates << 1200;
#endif //USE_ANCIENT_RATES
supportedBaudRates << 2400;
supportedBaudRates << 4800;
supportedBaudRates << 9600;
supportedBaudRates << 19200;
supportedBaudRates << 38400;
supportedBaudRates << 57600;
supportedBaudRates << 115200;
supportedBaudRates << 230400;
supportedBaudRates << 460800;
#if defined(Q_OS_LINUX)
// Baud rates supported only by Linux
supportedBaudRates << 500000;
supportedBaudRates << 576000;
#endif
supportedBaudRates << 921600;
QStringList supportedBaudRates = SerialConfiguration::supportedBaudRates();
// Now actually add all of our supported baud rates to the ui.
qSort(supportedBaudRates.begin(), supportedBaudRates.end());
for (int i = 0; i < supportedBaudRates.size(); ++i) {
_ui.baudRate->addItem(QString::number(supportedBaudRates.at(i)), supportedBaudRates.at(i));
_ui.baudRate->addItem(supportedBaudRates.at(i), supportedBaudRates.at(i).toInt());
}
// Connect the individual user interface inputs
......
......@@ -36,6 +36,8 @@ import QGroundControl.Palette 1.0
Rectangle {
id: _generalRoot
color: __qgcPal.window
anchors.fill: parent
anchors.margins: ScreenTools.defaultFontPixelWidth
QGCPalette {
id: qgcPal
......@@ -45,7 +47,6 @@ Rectangle {
Flickable {
clip: true
anchors.fill: parent
anchors.margins: ScreenTools.defaultFontPixelWidth
contentHeight: settingsColumn.height
contentWidth: _generalRoot.width
flickableDirection: Flickable.VerticalFlick
......@@ -56,12 +57,15 @@ Rectangle {
width: _generalRoot.width
anchors.margins: ScreenTools.defaultFontPixelWidth
spacing: ScreenTools.defaultFontPixelHeight / 2
QGCLabel {
text: "General Settings"
font.pixelSize: ScreenTools.mediumFontPixelSize
}
Rectangle {
height: 1
width: parent.width
color: qgcPal.button
}
Item {
height: ScreenTools.defaultFontPixelHeight / 2
width: parent.width
......
This diff is collapsed.
......@@ -36,6 +36,7 @@ import QGroundControl.Palette 1.0
Rectangle {
id: __mavlinkRoot
color: __qgcPal.window
anchors.fill: parent
QGCPalette {
id: qgcPal
......
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