Browse Source

Done with desktop

QGC4.4
Gus Grubba 6 years ago
parent
commit
72f1a42b34
  1. 68
      src/Taisync/TaisyncManager.cc
  2. 6
      src/Taisync/TaisyncManager.h
  3. 14
      src/Taisync/TaisyncSettings.cc
  4. 67
      src/Taisync/TaisyncSettings.qml

68
src/Taisync/TaisyncManager.cc

@ -24,6 +24,9 @@ static const char *kVIDEO_RATE = "VideoRate";
static const char *kLOCAL_IP = "LocalIP"; static const char *kLOCAL_IP = "LocalIP";
static const char *kREMOTE_IP = "RemoteIP"; static const char *kREMOTE_IP = "RemoteIP";
static const char *kNET_MASK = "NetMask"; static const char *kNET_MASK = "NetMask";
static const char *kRTSP_URI = "RTSPURI";
static const char *kRTSP_ACCOUNT = "RTSPAccount";
static const char *kRTSP_PASSWORD = "RTSPPassword";
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
TaisyncManager::TaisyncManager(QGCApplication* app, QGCToolbox* toolbox) TaisyncManager::TaisyncManager(QGCApplication* app, QGCToolbox* toolbox)
@ -33,9 +36,12 @@ TaisyncManager::TaisyncManager(QGCApplication* app, QGCToolbox* toolbox)
_workTimer.setSingleShot(true); _workTimer.setSingleShot(true);
QSettings settings; QSettings settings;
settings.beginGroup(kTAISYNC_GROUP); settings.beginGroup(kTAISYNC_GROUP);
_localIPAddr = settings.value(kLOCAL_IP, QString("192.168.199.33")).toString(); _localIPAddr = settings.value(kLOCAL_IP, QString("192.168.199.33")).toString();
_remoteIPAddr = settings.value(kREMOTE_IP, QString("192.168.199.16")).toString(); _remoteIPAddr = settings.value(kREMOTE_IP, QString("192.168.199.16")).toString();
_netMask = settings.value(kNET_MASK, QString("255.255.255.0")).toString(); _netMask = settings.value(kNET_MASK, QString("255.255.255.0")).toString();
_rtspURI = settings.value(kRTSP_URI, QString("rtsp://192.168.0.2")).toString();
_rtspAccount = settings.value(kRTSP_ACCOUNT, QString("admin")).toString();
_rtspPassword = settings.value(kRTSP_PASSWORD, QString("12345678")).toString();
settings.endGroup(); settings.endGroup();
} }
@ -80,6 +86,8 @@ TaisyncManager::_reset()
_close(); _close();
_isConnected = false; _isConnected = false;
emit connectedChanged(); emit connectedChanged();
_linkConnected = false;
emit linkConnectedChanged();
_taiSettings = new TaisyncSettings(this); _taiSettings = new TaisyncSettings(this);
connect(_taiSettings, &TaisyncSettings::updateSettings, this, &TaisyncManager::_updateSettings); connect(_taiSettings, &TaisyncSettings::updateSettings, this, &TaisyncManager::_updateSettings);
connect(_taiSettings, &TaisyncSettings::connected, this, &TaisyncManager::_connected); connect(_taiSettings, &TaisyncSettings::connected, this, &TaisyncManager::_connected);
@ -186,7 +194,23 @@ bool
TaisyncManager::setRTSPSettings(QString uri, QString account, QString password) TaisyncManager::setRTSPSettings(QString uri, QString account, QString password)
{ {
if(_taiSettings) { if(_taiSettings) {
return _taiSettings->setRTSPSettings(uri, account, password); if(_taiSettings->setRTSPSettings(uri, account, password)) {
_rtspURI = uri;
_rtspAccount = account;
_rtspPassword = password;
QSettings settings;
settings.beginGroup(kTAISYNC_GROUP);
settings.setValue(kRTSP_URI, _rtspURI);
settings.setValue(kRTSP_ACCOUNT, _rtspAccount);
settings.setValue(kRTSP_PASSWORD, _rtspPassword);
settings.endGroup();
emit rtspURIChanged();
emit rtspAccountChanged();
emit rtspPasswordChanged();
_needReboot = true;
emit needRebootChanged();
return true;
}
} }
return false; return false;
} }
@ -198,10 +222,14 @@ TaisyncManager::setIPSettings(QString localIP_, QString remoteIP_, QString netMa
bool res = false; bool res = false;
if(_localIPAddr != localIP_ || _remoteIPAddr != remoteIP_ || _netMask != netMask_) { if(_localIPAddr != localIP_ || _remoteIPAddr != remoteIP_ || _netMask != netMask_) {
//-- If we are connected to the Taisync //-- If we are connected to the Taisync
if(_linkConnected) { if(_isConnected) {
if(_taiSettings) { if(_taiSettings) {
//-- Change IP settings //-- Change IP settings
res = _taiSettings->setIPSettings(localIP_, remoteIP_, netMask_); res = _taiSettings->setIPSettings(localIP_, remoteIP_, netMask_);
if(res) {
_needReboot = true;
emit needRebootChanged();
}
} }
} else { } else {
//-- We're not connected. Record the change and restart. //-- We're not connected. Record the change and restart.
@ -369,6 +397,8 @@ TaisyncManager::_connected()
qCDebug(TaisyncLog) << "Taisync Settings Connected"; qCDebug(TaisyncLog) << "Taisync Settings Connected";
_isConnected = true; _isConnected = true;
emit connectedChanged(); emit connectedChanged();
_needReboot = false;
emit needRebootChanged();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -378,6 +408,10 @@ TaisyncManager::_disconnected()
qCDebug(TaisyncLog) << "Taisync Settings Disconnected"; qCDebug(TaisyncLog) << "Taisync Settings Disconnected";
_isConnected = false; _isConnected = false;
emit connectedChanged(); emit connectedChanged();
_needReboot = false;
emit needRebootChanged();
_linkConnected = false;
emit linkConnectedChanged();
_reset(); _reset();
} }
@ -424,6 +458,17 @@ TaisyncManager::_checkTaisync()
_taiSettings->requestIPSettings(); _taiSettings->requestIPSettings();
break; break;
} }
//-- Check link status
if(_timeoutTimer.elapsed() > 3000) {
//-- Give up and restart
_disconnected();
break;
}
//-- If it's been too long since we last heard, ping it.
if(_timeoutTimer.elapsed() > 1000) {
_taiSettings->requestLinkStatus();
break;
}
break; break;
} }
} }
@ -435,6 +480,7 @@ TaisyncManager::_checkTaisync()
void void
TaisyncManager::_updateSettings(QByteArray jSonData) TaisyncManager::_updateSettings(QByteArray jSonData)
{ {
_timeoutTimer.start();
qCDebug(TaisyncVerbose) << jSonData; qCDebug(TaisyncVerbose) << jSonData;
QJsonParseError jsonParseError; QJsonParseError jsonParseError;
QJsonDocument doc = QJsonDocument::fromJson(jSonData, &jsonParseError); QJsonDocument doc = QJsonDocument::fromJson(jSonData, &jsonParseError);
@ -522,20 +568,32 @@ TaisyncManager::_updateSettings(QByteArray jSonData)
//-- RTSP URI Settings? //-- RTSP URI Settings?
} else if(jSonData.contains("\"rtspURI\":")) { } else if(jSonData.contains("\"rtspURI\":")) {
QString value; QString value;
bool changed = false;
value = jObj["rtspURI"].toString(_rtspURI); value = jObj["rtspURI"].toString(_rtspURI);
if(value != _rtspURI) { if(value != _rtspURI) {
_rtspURI = value; _rtspURI = value;
changed = true;
emit rtspURIChanged(); emit rtspURIChanged();
} }
value = jObj["account"].toString(_rtspAccount); value = jObj["account"].toString(_rtspAccount);
if(value != _rtspAccount) { if(value != _rtspAccount) {
_rtspAccount = value; _rtspAccount = value;
changed = true;
emit rtspAccountChanged(); emit rtspAccountChanged();
} }
value = jObj["passwd"].toString(_rtspPassword); value = jObj["passwd"].toString(_rtspPassword);
if(value != _rtspPassword) { if(value != _rtspPassword) {
_rtspPassword = value; _rtspPassword = value;
changed = true;
emit rtspPasswordChanged(); emit rtspPasswordChanged();
} }
if(changed) {
QSettings settings;
settings.beginGroup(kTAISYNC_GROUP);
settings.setValue(kRTSP_URI, _rtspURI);
settings.setValue(kRTSP_ACCOUNT, _rtspAccount);
settings.setValue(kRTSP_PASSWORD, _rtspPassword);
settings.endGroup();
}
} }
} }

6
src/Taisync/TaisyncManager.h

@ -19,6 +19,7 @@
#endif #endif
#include <QTimer> #include <QTimer>
#include <QTime>
class AppSettings; class AppSettings;
class QGCApplication; class QGCApplication;
@ -31,6 +32,7 @@ public:
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
Q_PROPERTY(bool linkConnected READ linkConnected NOTIFY linkConnectedChanged) Q_PROPERTY(bool linkConnected READ linkConnected NOTIFY linkConnectedChanged)
Q_PROPERTY(bool needReboot READ needReboot NOTIFY needRebootChanged)
Q_PROPERTY(QString linkVidFormat READ linkVidFormat NOTIFY linkChanged) Q_PROPERTY(QString linkVidFormat READ linkVidFormat NOTIFY linkChanged)
Q_PROPERTY(int uplinkRSSI READ uplinkRSSI NOTIFY linkChanged) Q_PROPERTY(int uplinkRSSI READ uplinkRSSI NOTIFY linkChanged)
Q_PROPERTY(int downlinkRSSI READ downlinkRSSI NOTIFY linkChanged) Q_PROPERTY(int downlinkRSSI READ downlinkRSSI NOTIFY linkChanged)
@ -58,6 +60,7 @@ public:
bool connected () { return _isConnected; } bool connected () { return _isConnected; }
bool linkConnected () { return _linkConnected; } bool linkConnected () { return _linkConnected; }
bool needReboot () { return _needReboot; }
QString linkVidFormat () { return _linkVidFormat; } QString linkVidFormat () { return _linkVidFormat; }
int uplinkRSSI () { return _downlinkRSSI; } int uplinkRSSI () { return _downlinkRSSI; }
int downlinkRSSI () { return _uplinkRSSI; } int downlinkRSSI () { return _uplinkRSSI; }
@ -88,6 +91,7 @@ signals:
void localIPAddrChanged (); void localIPAddrChanged ();
void remoteIPAddrChanged (); void remoteIPAddrChanged ();
void netMaskChanged (); void netMaskChanged ();
void needRebootChanged ();
private slots: private slots:
void _connected (); void _connected ();
@ -135,6 +139,7 @@ private:
bool _enableVideo = true; bool _enableVideo = true;
bool _enabled = true; bool _enabled = true;
bool _linkConnected = false; bool _linkConnected = false;
bool _needReboot = false;
QTimer _workTimer; QTimer _workTimer;
QString _linkVidFormat; QString _linkVidFormat;
int _downlinkRSSI = 0; int _downlinkRSSI = 0;
@ -163,4 +168,5 @@ private:
QString _localIPAddr; QString _localIPAddr;
QString _remoteIPAddr; QString _remoteIPAddr;
QString _netMask; QString _netMask;
QTime _timeoutTimer;
}; };

14
src/Taisync/TaisyncSettings.cc

@ -158,12 +158,18 @@ void
TaisyncSettings::_readBytes() TaisyncSettings::_readBytes()
{ {
QByteArray bytesIn = _tcpSocket->read(_tcpSocket->bytesAvailable()); QByteArray bytesIn = _tcpSocket->read(_tcpSocket->bytesAvailable());
//qCDebug(TaisyncVerbose) << "Taisync settings data:" << bytesIn.size();
//qCDebug(TaisyncVerbose) << QString(bytesIn);
//-- Go straight to Json payload //-- Go straight to Json payload
int idx = bytesIn.indexOf('{'); int idx = bytesIn.indexOf('{');
if(idx > 0) { //-- We may receive more than one response within one TCP packet.
emit updateSettings(bytesIn.mid(idx)); while(idx >= 0) {
bytesIn = bytesIn.mid(idx);
idx = bytesIn.indexOf('}');
if(idx > 0) {
QByteArray data = bytesIn.left(idx + 1);
emit updateSettings(data);
bytesIn = bytesIn.mid(idx+1);
idx = bytesIn.indexOf('{');
}
} }
} }

67
src/Taisync/TaisyncSettings.qml

@ -58,6 +58,13 @@ QGCView {
width: _qgcView.width width: _qgcView.width
spacing: ScreenTools.defaultFontPixelHeight * 0.5 spacing: ScreenTools.defaultFontPixelHeight * 0.5
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelWidth
QGCLabel {
text: qsTr("Reboot ground unit for changes to take effect.")
color: qgcPal.colorOrange
visible: QGroundControl.taisyncManager.needReboot
font.family: ScreenTools.demiboldFontFamily
anchors.horizontalCenter: parent.horizontalCenter
}
//----------------------------------------------------------------- //-----------------------------------------------------------------
//-- General //-- General
Item { Item {
@ -86,13 +93,14 @@ QGCView {
FactCheckBox { FactCheckBox {
text: qsTr("Enable Taisync") text: qsTr("Enable Taisync")
fact: _taisyncEnabledFact fact: _taisyncEnabledFact
enabled: !QGroundControl.taisyncManager.needReboot
visible: _taisyncEnabledFact.visible visible: _taisyncEnabledFact.visible
} }
FactCheckBox { FactCheckBox {
text: qsTr("Enable Taisync Video") text: qsTr("Enable Taisync Video")
fact: _taisyncVideoEnabledFact fact: _taisyncVideoEnabledFact
visible: _taisyncVideoEnabledFact.visible visible: _taisyncVideoEnabledFact.visible
enabled: _taisyncEnabled enabled: _taisyncEnabled && !QGroundControl.taisyncManager.needReboot
} }
} }
} }
@ -245,7 +253,7 @@ QGCView {
FactComboBox { FactComboBox {
fact: QGroundControl.taisyncManager.radioMode fact: QGroundControl.taisyncManager.radioMode
indexModel: true indexModel: true
enabled: QGroundControl.taisyncManager.linkConnected enabled: QGroundControl.taisyncManager.linkConnected && !QGroundControl.taisyncManager.needReboot
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
QGCLabel { QGCLabel {
@ -254,7 +262,7 @@ QGCView {
FactComboBox { FactComboBox {
fact: QGroundControl.taisyncManager.radioChannel fact: QGroundControl.taisyncManager.radioChannel
indexModel: true indexModel: true
enabled: QGroundControl.taisyncManager.linkConnected && QGroundControl.taisyncManager.radioMode.rawValue > 0 enabled: QGroundControl.taisyncManager.linkConnected && QGroundControl.taisyncManager.radioMode.rawValue > 0 && !QGroundControl.taisyncManager.needReboot
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
} }
@ -298,7 +306,7 @@ QGCView {
FactComboBox { FactComboBox {
fact: QGroundControl.taisyncManager.videoOutput fact: QGroundControl.taisyncManager.videoOutput
indexModel: true indexModel: true
enabled: QGroundControl.taisyncManager.linkConnected enabled: QGroundControl.taisyncManager.linkConnected && !QGroundControl.taisyncManager.needReboot
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
QGCLabel { QGCLabel {
@ -307,7 +315,7 @@ QGCView {
FactComboBox { FactComboBox {
fact: QGroundControl.taisyncManager.videoMode fact: QGroundControl.taisyncManager.videoMode
indexModel: true indexModel: true
enabled: QGroundControl.taisyncManager.linkConnected enabled: QGroundControl.taisyncManager.linkConnected && !QGroundControl.taisyncManager.needReboot
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
QGCLabel { QGCLabel {
@ -316,7 +324,7 @@ QGCView {
FactComboBox { FactComboBox {
fact: QGroundControl.taisyncManager.videoRate fact: QGroundControl.taisyncManager.videoRate
indexModel: true indexModel: true
enabled: QGroundControl.taisyncManager.linkConnected enabled: QGroundControl.taisyncManager.linkConnected && !QGroundControl.taisyncManager.needReboot
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
} }
@ -329,7 +337,7 @@ QGCView {
height: rtspSettingsLabel.height height: rtspSettingsLabel.height
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
visible: _taisyncEnabled && QGroundControl.taisyncManager.linkConnected visible: _taisyncEnabled && QGroundControl.taisyncManager.connected
QGCLabel { QGCLabel {
id: rtspSettingsLabel id: rtspSettingsLabel
text: qsTr("Streaming Settings") text: qsTr("Streaming Settings")
@ -340,7 +348,7 @@ QGCView {
height: rtspSettingsCol.height + (ScreenTools.defaultFontPixelHeight * 2) height: rtspSettingsCol.height + (ScreenTools.defaultFontPixelHeight * 2)
width: _panelWidth width: _panelWidth
color: qgcPal.windowShade color: qgcPal.windowShade
visible: _taisyncEnabled && QGroundControl.taisyncManager.linkConnected visible: _taisyncEnabled && QGroundControl.taisyncManager.connected
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
Column { Column {
@ -360,7 +368,7 @@ QGCView {
QGCTextField { QGCTextField {
id: rtspURI id: rtspURI
text: QGroundControl.taisyncManager.rtspURI text: QGroundControl.taisyncManager.rtspURI
enabled: QGroundControl.taisyncManager.linkConnected enabled: QGroundControl.taisyncManager.connected && !QGroundControl.taisyncManager.needReboot
inputMethodHints: Qt.ImhUrlCharactersOnly inputMethodHints: Qt.ImhUrlCharactersOnly
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
@ -370,7 +378,7 @@ QGCView {
QGCTextField { QGCTextField {
id: rtspAccount id: rtspAccount
text: QGroundControl.taisyncManager.rtspAccount text: QGroundControl.taisyncManager.rtspAccount
enabled: QGroundControl.taisyncManager.linkConnected enabled: QGroundControl.taisyncManager.connected && !QGroundControl.taisyncManager.needReboot
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
QGCLabel { QGCLabel {
@ -379,28 +387,46 @@ QGCView {
QGCTextField { QGCTextField {
id: rtspPassword id: rtspPassword
text: QGroundControl.taisyncManager.rtspPassword text: QGroundControl.taisyncManager.rtspPassword
enabled: QGroundControl.taisyncManager.linkConnected enabled: QGroundControl.taisyncManager.connected && !QGroundControl.taisyncManager.needReboot
inputMethodHints: Qt.ImhHiddenText inputMethodHints: Qt.ImhHiddenText
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
} }
Item {
width: 1
height: ScreenTools.defaultFontPixelHeight
}
QGCButton { QGCButton {
function testEnabled() { function testEnabled() {
if(!QGroundControl.taisyncManager.linkConnected) if(!QGroundControl.taisyncManager.connected)
return false return false
if(rtspPassword.text === QGroundControl.taisyncManager.rtspPassword && if(rtspPassword.text === QGroundControl.taisyncManager.rtspPassword &&
rtspAccount === QGroundControl.taisyncManager.rtspAccount && rtspAccount.text === QGroundControl.taisyncManager.rtspAccount &&
rtspURI === QGroundControl.taisyncManager.rtspURI) rtspURI.text === QGroundControl.taisyncManager.rtspURI)
return false return false
if(rtspURI === "") if(rtspURI === "")
return false return false
return true return true
} }
enabled: testEnabled() enabled: testEnabled() && !QGroundControl.taisyncManager.needReboot
text: qsTr("Apply") text: qsTr("Apply")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
onClicked: { onClicked: {
setRTSPDialog.open()
}
MessageDialog {
id: setRTSPDialog
icon: StandardIcon.Warning
standardButtons: StandardButton.Yes | StandardButton.No
title: qsTr("Set Streaming Settings")
text: qsTr("Once changed, you will need to reboot the ground unit for the changes to take effect.\n\nConfirm change?")
onYes: {
QGroundControl.taisyncManager.setRTSPSettings(rtspURI.text, rtspAccount.text, rtspPassword.text)
setRTSPDialog.close()
}
onNo: {
setRTSPDialog.close()
}
} }
} }
} }
@ -443,6 +469,7 @@ QGCView {
QGCTextField { QGCTextField {
id: localIP id: localIP
text: QGroundControl.taisyncManager.localIPAddr text: QGroundControl.taisyncManager.localIPAddr
enabled: !QGroundControl.taisyncManager.needReboot
inputMethodHints: Qt.ImhFormattedNumbersOnly inputMethodHints: Qt.ImhFormattedNumbersOnly
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
@ -452,6 +479,7 @@ QGCView {
QGCTextField { QGCTextField {
id: remoteIP id: remoteIP
text: QGroundControl.taisyncManager.remoteIPAddr text: QGroundControl.taisyncManager.remoteIPAddr
enabled: !QGroundControl.taisyncManager.needReboot
inputMethodHints: Qt.ImhFormattedNumbersOnly inputMethodHints: Qt.ImhFormattedNumbersOnly
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
@ -461,10 +489,15 @@ QGCView {
QGCTextField { QGCTextField {
id: netMask id: netMask
text: QGroundControl.taisyncManager.netMask text: QGroundControl.taisyncManager.netMask
enabled: !QGroundControl.taisyncManager.needReboot
inputMethodHints: Qt.ImhFormattedNumbersOnly inputMethodHints: Qt.ImhFormattedNumbersOnly
Layout.minimumWidth: _valueWidth Layout.minimumWidth: _valueWidth
} }
} }
Item {
width: 1
height: ScreenTools.defaultFontPixelHeight
}
QGCButton { QGCButton {
function validateIPaddress(ipaddress) { function validateIPaddress(ipaddress) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
@ -481,7 +514,7 @@ QGCView {
if(!validateIPaddress(netMask.text)) return false if(!validateIPaddress(netMask.text)) return false
return true return true
} }
enabled: testEnabled() enabled: testEnabled() && !QGroundControl.taisyncManager.needReboot
text: qsTr("Apply") text: qsTr("Apply")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
onClicked: { onClicked: {

Loading…
Cancel
Save