@@ -14,6 +14,8 @@ import QGroundControl
1414import QGroundControl.Controls
1515import QGroundControl.FactControls
1616
17+ import "FailureInjectionInstances.js" as Instances
18+
1719SetupPage {
1820 id: failureInjectionPage
1921 pageComponent: pageComponent
@@ -81,21 +83,8 @@ SetupPage {
8183 0 , 0 , 0 ) // param5..7
8284 }
8385
84- // Map the current instance selection to the command form:
85- // All -> {p3:0, p4:0}; one instance n -> {p3:n, p4:0}; many -> {p3:NaN, p4:bitmask}.
8686 function _instanceSend () {
87- var sel = _selectedInstances .slice ().sort (function (a , b ){ return a - b })
88- if (sel .indexOf (0 ) >= 0 ) {
89- return { param3: 0 , param4: 0 , label: " all" }
90- }
91- if (sel .length === 1 ) {
92- return { param3: sel[0 ], param4: 0 , label: " " + sel[0 ] }
93- }
94- var mask = 0
95- for (var i = 0 ; i < sel .length ; ++ i) {
96- mask |= (1 << (sel[i] - 1 ))
97- }
98- return { param3: NaN , param4: mask, label: sel .join (" , " ) }
87+ return Instances .instanceSend (_selectedInstances)
9988 }
10089
10190 // Queue one command; kick off sending if the queue was idle.
@@ -150,12 +139,7 @@ SetupPage {
150139 }
151140
152141 function _toggleInstance (n ) {
153- var arr = _selectedInstances .slice ()
154- var zero = arr .indexOf (0 ) // picking a specific instance clears the "All" selection
155- if (zero >= 0 ) { arr .splice (zero, 1 ) }
156- var idx = arr .indexOf (n)
157- if (idx >= 0 ) { arr .splice (idx, 1 ) } else { arr .push (n) }
158- _selectedInstances = arr
142+ _selectedInstances = Instances .toggleInstance (_selectedInstances, n)
159143 }
160144
161145 function _setEnabled (on ) {
@@ -166,17 +150,11 @@ SetupPage {
166150 }
167151
168152 function _unitName (unitEnum ) {
169- for (var i = 0 ; i < _units .length ; ++ i) {
170- if (_units[i].unit === unitEnum) { return _units[i].name }
171- }
172- return " " + unitEnum
153+ return Instances .unitName (_units, unitEnum)
173154 }
174155
175156 function _typeName (typeEnum ) {
176- for (var i = 0 ; i < _types .length ; ++ i) {
177- if (_types[i].type === typeEnum) { return _types[i].name }
178- }
179- return " " + typeEnum
157+ return Instances .typeName (_types, typeEnum)
180158 }
181159
182160 // Send FAILURE_TYPE_OK (all instances) to every unit injected this session and log each as a row.
@@ -226,24 +204,28 @@ SetupPage {
226204 spacing: ScreenTools .defaultFontPixelWidth * 2
227205
228206 QGCCheckBox {
207+ objectName: " failureInjection_enableCheckbox"
229208 text: qsTr (" SYS_FAILURE_EN" )
230209 enabled: _sysFailureEn !== null
231210 checked: _paramSet
232211 onClicked: _setEnabled (checked)
233212 }
234213 QGCLabel {
214+ objectName: " failureInjection_pendingRebootLabel"
235215 Layout .fillWidth : true
236216 color: qgcPal .colorOrange
237217 visible: _pendingReboot
238218 text: qsTr (" Parameter written — reboot required before it takes effect." )
239219 }
240220 QGCLabel {
221+ objectName: " failureInjection_armedLabel"
241222 Layout .fillWidth : true
242223 color: qgcPal .colorGreen
243224 visible: _armed && ! _pendingReboot
244225 text: qsTr (" Active — injection armed." )
245226 }
246227 QGCButton {
228+ objectName: " failureInjection_rebootButton"
247229 text: qsTr (" Reboot Vehicle" )
248230 visible: _pendingReboot
249231 onClicked: {
@@ -299,6 +281,7 @@ SetupPage {
299281 }
300282 Item { Layout .fillWidth : true }
301283 QGCButton {
284+ objectName: " failureInjection_injectButton"
302285 text: qsTr (" Inject failure" )
303286 primary: true
304287 enabled: _armed && _selectedInstances .length > 0
@@ -363,7 +346,7 @@ SetupPage {
363346 enabled: _armed
364347 opacity: _armed ? 1.0 : 0.4
365348 QGCLabel { Layout .fillWidth : true ; text: qsTr (" Activity — newest first" ) }
366- QGCButton { text: qsTr (" Reset all" ); onClicked: _resetAll () }
349+ QGCButton { objectName : " failureInjection_resetAllButton " ; text: qsTr (" Reset all" ); onClicked: _resetAll () }
367350 }
368351 // Column header, aligned with the rows below.
369352 RowLayout {
@@ -388,21 +371,25 @@ SetupPage {
388371 opacity: _armed ? 1.0 : 0.4
389372
390373 QGCListView {
374+ objectName: " failureInjection_activityList"
391375 anchors .fill : parent
392376 anchors .margins : ScreenTools .defaultFontPixelWidth
393377 clip: true
394378 model: FailureInjection .activity
395379 delegate: RowLayout {
396380 required property var modelData
381+ required property int index
397382 readonly property bool _pending: modelData .result === " pending"
398383 readonly property bool _accepted: modelData .result === " accepted"
384+ objectName: " failureInjection_activityRow_" + index
399385 width: ListView .view .width
400386 spacing: ScreenTools .defaultFontPixelWidth * 2
401387 QGCLabel { Layout .preferredWidth : _colTimeWidth; font .family : ScreenTools .fixedFontFamily ; color: qgcPal .colorOrange ; text: modelData .time }
402- QGCLabel { Layout .preferredWidth : _colUnitWidth; font .family : ScreenTools .fixedFontFamily ; text: modelData .unitName }
403- QGCLabel { Layout .preferredWidth : _colTypeWidth; font .family : ScreenTools .fixedFontFamily ; text: modelData .typeName }
404- QGCLabel { Layout .fillWidth : true ; font .family : ScreenTools .fixedFontFamily ; elide: Text .ElideRight ; text: modelData .instance }
388+ QGCLabel { objectName : " failureInjection_unitName_ " + index; Layout .preferredWidth : _colUnitWidth; font .family : ScreenTools .fixedFontFamily ; text: modelData .unitName }
389+ QGCLabel { objectName : " failureInjection_typeName_ " + index; Layout .preferredWidth : _colTypeWidth; font .family : ScreenTools .fixedFontFamily ; text: modelData .typeName }
390+ QGCLabel { objectName : " failureInjection_instance_ " + index; Layout .fillWidth : true ; font .family : ScreenTools .fixedFontFamily ; elide: Text .ElideRight ; text: modelData .instance }
405391 QGCLabel {
392+ objectName: " failureInjection_result_" + index
406393 font .family : ScreenTools .fixedFontFamily
407394 color: _pending ? qgcPal .colorOrange : (_accepted ? qgcPal .colorGreen : qgcPal .colorRed )
408395 text: _pending ? qsTr (" …" ) : (_accepted ? qsTr (" ✓ Accepted" ) : (" ✗ " + modelData .result ))
0 commit comments