QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSResilienceIndicator.qml
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10import QtQuick
11import QtQuick.Layouts
12
13import QGroundControl
14import QGroundControl.Controls
15
16//-------------------------------------------------------------------------
17//-- GPS Resilience Indicator
18Item {
19 id: control
20 width: height
21 anchors.top: parent.top
22 anchors.bottom: parent.bottom
23 visible: showIndicator
24
25 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
26 property var _gpsAggregate: _activeVehicle ? _activeVehicle.gpsAggregate : null
27
28 property var qgcPal: QGroundControl.globalPalette
29
30 property bool showIndicator: _activeVehicle && _gpsAggregate && (
31 (_gpsAggregate.authenticationState.value > 0 && _gpsAggregate.authenticationState.value < 255) ||
32 (_gpsAggregate.spoofingState.value > 0 && _gpsAggregate.spoofingState.value < 255) ||
33 (_gpsAggregate.jammingState.value > 0 && _gpsAggregate.jammingState.value < 255)
34 )
35
36 // Authentication Icon (Outer/Bottom Layer)
37 QGCColoredImage {
38 id: authIcon
39 width: parent.height * 0.95
40 height: parent.height * 0.95
41 anchors.centerIn: parent
42 source: "/qmlimages/GpsAuthentication.svg"
43 fillMode: Image.PreserveAspectFit
44 sourceSize.height: height
45 color: _authColor()
46 visible: _gpsAggregate && _gpsAggregate.authenticationState.value > 0 && _gpsAggregate.authenticationState.value < 255
47 }
48
49 // Interference Icon (Inner/Top Layer)
50 QGCColoredImage {
51 id: interfIcon
52 width: parent.height * 0.55
53 height: parent.height * 0.55
54 anchors.centerIn: parent
55 source: "/qmlimages/GpsInterference.svg"
56 fillMode: Image.PreserveAspectFit
57 sourceSize.height: height
58 color: _interfColor()
59 visible: _gpsAggregate && (Math.max(_gpsAggregate.spoofingState.value, _gpsAggregate.jammingState.value) > 0) && (Math.max(_gpsAggregate.spoofingState.value, _gpsAggregate.jammingState.value) < 255)
60 }
61
62 function _authColor() {
63 if (!_gpsAggregate) return qgcPal.colorGrey;
64 switch (_gpsAggregate.authenticationState.value) {
65 case 1: return qgcPal.colorYellow; // Initializing
66 case 2: return qgcPal.colorRed; // Error
67 case 3: return qgcPal.colorGreen; // OK
68 default: return qgcPal.colorGrey; // Unknown or Disabled
69 }
70 }
71
72 function _interfColor() {
73 if (!_gpsAggregate) return qgcPal.colorGrey;
74 let maxState = Math.max(_gpsAggregate.spoofingState.value, _gpsAggregate.jammingState.value);
75 switch (maxState) {
76 case 1: return qgcPal.colorGreen; // Not spoofed/jammed
77 case 2: return qgcPal.colorOrange; // Mitigated
78 case 3: return qgcPal.colorRed; // Detected
79 default: return qgcPal.colorGrey; // Unknown
80 }
81 }
82
83 MouseArea {
84 anchors.fill: parent
85 onClicked: mainWindow.showIndicatorDrawer(resiliencePopup, control)
86 }
87
88 Component {
89 id: resiliencePopup
90 ToolIndicatorPage {
91 showExpand: expandedComponent ? true : false
92 contentComponent: resilienceContent
93 }
94 }
95
96 Component {
97 id: resilienceContent
98 ColumnLayout {
99 spacing: ScreenTools.defaultFontPixelHeight / 2
100
101 // Unified GPS Resilience Status
102 SettingsGroupLayout {
103 heading: qsTr("GPS Resilience Status")
104 showDividers: true
105
106 LabelledLabel {
107 label: qsTr("GPS Jamming")
108 labelText: _gpsAggregate ? (_gpsAggregate.jammingState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
109 visible: _gpsAggregate && _gpsAggregate.jammingState.value > 0 && _gpsAggregate.jammingState.value < 255
110 }
111
112 LabelledLabel {
113 label: qsTr("GPS Spoofing")
114 labelText: _gpsAggregate ? (_gpsAggregate.spoofingState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
115 visible: _gpsAggregate && _gpsAggregate.spoofingState.value > 0 && _gpsAggregate.spoofingState.value < 255
116 }
117
118 LabelledLabel {
119 label: qsTr("GPS Authentication")
120 labelText: _gpsAggregate ? (_gpsAggregate.authenticationState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
121 visible: _gpsAggregate && _gpsAggregate.authenticationState.value > 0 && _gpsAggregate.authenticationState.value < 255
122 }
123 }
124
125 // GPS 1 Details
126 SettingsGroupLayout {
127 heading: qsTr("GPS 1 Details")
128 showDividers: true
129 visible: _activeVehicle && _activeVehicle.gps && (
130 (_activeVehicle.gps.jammingState.value > 0 && _activeVehicle.gps.jammingState.value < 255) ||
131 (_activeVehicle.gps.spoofingState.value > 0 && _activeVehicle.gps.spoofingState.value < 255) ||
132 (_activeVehicle.gps.authenticationState.value > 0 && _activeVehicle.gps.authenticationState.value < 255)
133 )
134
135 LabelledLabel {
136 label: qsTr("Jamming")
137 labelText: (_activeVehicle && _activeVehicle.gps) ? (_activeVehicle.gps.jammingState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
138 visible: _activeVehicle.gps.jammingState.value > 0 && _activeVehicle.gps.jammingState.value < 255
139 }
140 LabelledLabel {
141 label: qsTr("Spoofing")
142 labelText: (_activeVehicle && _activeVehicle.gps) ? (_activeVehicle.gps.spoofingState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
143 visible: _activeVehicle.gps.spoofingState.value > 0 && _activeVehicle.gps.spoofingState.value < 255
144 }
145 LabelledLabel {
146 label: qsTr("Authentication")
147 labelText: (_activeVehicle && _activeVehicle.gps) ? (_activeVehicle.gps.authenticationState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
148 visible: _activeVehicle.gps.authenticationState.value > 0 && _activeVehicle.gps.authenticationState.value < 255
149 }
150 }
151
152 // GPS 2 Details
153 SettingsGroupLayout {
154 heading: qsTr("GPS 2 Details")
155 showDividers: true
156 visible: _activeVehicle && _activeVehicle.gps2 && (
157 (_activeVehicle.gps2.jammingState.value > 0 && _activeVehicle.gps2.jammingState.value < 255) ||
158 (_activeVehicle.gps2.spoofingState.value > 0 && _activeVehicle.gps2.spoofingState.value < 255) ||
159 (_activeVehicle.gps2.authenticationState.value > 0 && _activeVehicle.gps2.authenticationState.value < 255)
160 )
161
162 LabelledLabel {
163 label: qsTr("Jamming")
164 labelText: (_activeVehicle && _activeVehicle.gps2) ? (_activeVehicle.gps2.jammingState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
165 visible: _activeVehicle.gps2.jammingState.value > 0 && _activeVehicle.gps2.jammingState.value < 255
166 }
167 LabelledLabel {
168 label: qsTr("Spoofing")
169 labelText: (_activeVehicle && _activeVehicle.gps2) ? (_activeVehicle.gps2.spoofingState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
170 visible: _activeVehicle.gps2.spoofingState.value > 0 && _activeVehicle.gps2.spoofingState.value < 255
171 }
172 LabelledLabel {
173 label: qsTr("Authentication")
174 labelText: (_activeVehicle && _activeVehicle.gps2) ? (_activeVehicle.gps2.authenticationState.enumStringValue || qsTr("n/a")) : qsTr("n/a")
175 visible: _activeVehicle.gps2.authenticationState.value > 0 && _activeVehicle.gps2.authenticationState.value < 255
176 }
177 }
178 }
179 }
180}