1pragma ComponentBehavior: Bound
7import QGroundControl.Controls
8import QGroundControl.FactControls
10/// Serial device and baud rate of the GNSS receiver.
14 required property Fact deviceFact
15 required property Fact baudFact
16 /// The ports to offer.
17 property list<gpsSerialPortEntry> serialPorts
18 /// The explicit rates to offer, which the receiver accepts.
19 property list<int> serialBaudRates
20 /// When set, offers an empty device under this label for consumers that can find the receiver themselves.
21 property string anyDeviceLabel
22 /// Offers rate 0 as "Auto" for consumers that can detect the baud rate.
23 property bool allowAutoBaud: false
24 property bool editable: true
26 readonly property string _device: String(deviceFact.rawValue)
27 readonly property var _devices: {
28 const devices = root.serialPorts.slice()
29 if (root.anyDeviceLabel !== "")
30 devices.unshift({ value: "", label: root.anyDeviceLabel })
31 if (root._device !== "" && !root._listed(root._device))
32 devices.push({ value: root._device, label: qsTr("%1 (unavailable)").arg(root._device) })
33 if (devices.length === 0)
34 devices.push({ value: "", label: qsTr("<none available>") })
37 readonly property list<int> _rates: root.allowAutoBaud ? [0, ...root.serialBaudRates] : root.serialBaudRates
38 readonly property int _baudIndex: _rates.indexOf(Number(baudFact.rawValue))
39 readonly property bool customBaud: _customRequested || _baudIndex < 0
40 property bool _customRequested: false
42 spacing: ScreenTools.defaultFontPixelHeight / 4
44 function _listed(device) {
45 return root.serialPorts.some(port => port.value === device)
49 label: qsTr("Serial device")
52 objectName: "rtkSerialDevice"
53 Layout.fillWidth: true
54 Layout.minimumWidth: 0
55 enabled: root.editable && (root.serialPorts.length > 0 || root.anyDeviceLabel !== "")
58 currentIndex: root._devices.findIndex(device => device.value === root._device)
59 onActivated: index => {
60 if (index < 0 || index >= root._devices.length)
62 const value = root._devices[index].value
63 if (root._listed(value) || (value === "" && root.anyDeviceLabel !== ""))
64 root.deviceFact.rawValue = value
70 label: qsTr("Baud rate")
73 objectName: "rtkSerialBaudRate"
74 Layout.fillWidth: true
75 Layout.minimumWidth: 0
76 enabled: root.editable
77 model: root._rates.map(rate => rate === 0 ? qsTr("Auto") : String(rate)).concat([qsTr("Custom")])
78 currentIndex: root.customBaud ? root._rates.length : root._baudIndex
79 onActivated: index => {
80 root._customRequested = index === root._rates.length
81 if (index >= 0 && index < root._rates.length)
82 root.baudFact.rawValue = root._rates[index]
88 label: qsTr("Custom baud rate")
89 visible: root.customBaud
92 objectName: "rtkCustomBaudRate"
93 Layout.fillWidth: true
94 Layout.minimumWidth: 0
95 enabled: root.editable
101 target: root.baudFact
102 function onRawValueChanged() { root._customRequested = false }