QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NtripConnectionStatus.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7import QGroundControl.FactControls
8
9SettingsGroupLayout {
10 Layout.fillWidth: true
11 heading: qsTr("Connection")
12 visible: _ntrip.userVisible
13
14 QGCPalette { id: qgcPal }
15
16 property var _ntrip: QGroundControl.settingsManager.ntripSettings
17 property Fact _enabled: _ntrip.ntripServerConnectEnabled
18 property var _ntripMgr: QGroundControl.ntripManager
19 property bool _isConnected: _ntripMgr.connectionStatus === NTRIPManager.Connected
20 property bool _isConnecting: _ntripMgr.connectionStatus === NTRIPManager.Connecting
21 property bool _isReconnecting: _ntripMgr.connectionStatus === NTRIPManager.Reconnecting
22 property bool _isError: _ntripMgr.connectionStatus === NTRIPManager.Error
23 property bool _isActive: _enabled.rawValue
24 property bool _hasHost: _ntrip.ntripServerHostAddress.rawValue !== ""
25
26 RowLayout {
27 Layout.fillWidth: true
28 spacing: ScreenTools.defaultFontPixelWidth
29
30 Rectangle {
31 width: ScreenTools.defaultFontPixelHeight * 0.75
32 height: width
33 radius: width / 2
34 color: {
35 switch (_ntripMgr.connectionStatus) {
36 case NTRIPManager.Connected: return qgcPal.colorGreen
37 case NTRIPManager.Connecting:
38 case NTRIPManager.Reconnecting: return qgcPal.colorOrange
39 case NTRIPManager.Error: return qgcPal.colorRed
40 default: return qgcPal.colorGrey
41 }
42 }
43 Layout.alignment: Qt.AlignVCenter
44 }
45
46 QGCLabel {
47 Layout.fillWidth: true
48 text: _ntripMgr.statusMessage || qsTr("Disconnected")
49 wrapMode: Text.WordWrap
50 }
51
52 QGCButton {
53 text: {
54 if (_isConnecting) return qsTr("Connecting…")
55 if (_isReconnecting) return qsTr("Reconnecting…")
56 if (_isConnected) return qsTr("Disconnect")
57 return qsTr("Connect")
58 }
59 enabled: !_isConnecting && (_isActive || _hasHost)
60 onClicked: _enabled.rawValue = !_enabled.rawValue
61 }
62 }
63
64 QGCLabel {
65 Layout.fillWidth: true
66 visible: _isConnected && _ntripMgr.messagesReceived > 0
67 text: {
68 var parts = [qsTr("%1 messages").arg(_ntripMgr.messagesReceived),
69 formatBytes(_ntripMgr.bytesReceived)]
70 if (_ntripMgr.dataRateBytesPerSec > 0)
71 parts.push(formatRate(_ntripMgr.dataRateBytesPerSec))
72 if (_ntripMgr.ggaSource)
73 parts.push(qsTr("GGA: %1").arg(_ntripMgr.ggaSource))
74 return parts.join(" · ")
75 }
76 font.pointSize: ScreenTools.smallFontPointSize
77 color: qgcPal.colorGrey
78
79 function formatBytes(bytes) {
80 if (bytes < 1024) return bytes + " B"
81 if (bytes < 1048576) return (bytes / 1024).toFixed(1) + " KB"
82 return (bytes / 1048576).toFixed(1) + " MB"
83 }
84
85 function formatRate(bytesPerSec) {
86 if (bytesPerSec < 1024) return bytesPerSec.toFixed(0) + " B/s"
87 return (bytesPerSec / 1024).toFixed(1) + " KB/s"
88 }
89 }
90
91 QGCLabel {
92 Layout.fillWidth: true
93 visible: _isError && _ntripMgr.statusMessage !== ""
94 text: _ntripMgr.statusMessage
95 wrapMode: Text.WordWrap
96 color: qgcPal.colorRed
97 font.pointSize: ScreenTools.smallFontPointSize
98 }
99}