Skip to content

Commit 75dd010

Browse files
- Moved map to MAVlink constants
- Changed max data stream rate to 15 - Included logging statements and stream rate validation in backend - Formatted
1 parent 30b6e67 commit 75dd010

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

gcs/src/components/settingsModal.jsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,10 @@ import {
3333
} from "../helpers/notification"
3434
import { useDispatch } from "react-redux"
3535
import { emitSetStreamRates } from "../redux/slices/droneConnectionSlice"
36+
import { DATA_STREAM_MAP } from "../helpers/mavlinkConstants"
3637

3738
const octokit = new Octokit({})
3839

39-
const STREAM_MAP = {
40-
MAV_DATA_STREAM_ALL: 0,
41-
MAV_DATA_STREAM_RAW_SENSORS: 1,
42-
MAV_DATA_STREAM_EXTENDED_STATUS: 2,
43-
MAV_DATA_STREAM_RC_CHANNELS: 3,
44-
MAV_DATA_STREAM_RAW_CONTROLLER: 4,
45-
MAV_DATA_STREAM_POSITION: 6,
46-
MAV_DATA_STREAM_EXTRA1: 10,
47-
MAV_DATA_STREAM_EXTRA2: 11,
48-
MAV_DATA_STREAM_EXTRA3: 12,
49-
}
50-
5140
const isValidNumber = (num, range) => {
5241
return (
5342
num &&
@@ -216,7 +205,7 @@ function SetRatesRow() {
216205
const dispatch = useDispatch()
217206

218207
const onClick = () => {
219-
for (const [name, value] of Object.entries(STREAM_MAP)) {
208+
for (const [name, value] of Object.entries(DATA_STREAM_MAP)) {
220209
let rate = getSetting(`Developer.${name}`)
221210
dispatch(emitSetStreamRates({ stream: value, rate: rate }))
222211
}

gcs/src/helpers/mavlinkConstants.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,15 @@ export const EXCLUDE_PARAMS_LOAD = [
536536
"STAT_RESET",
537537
"STAT_RUNTIME",
538538
]
539+
540+
export const DATA_STREAM_MAP = {
541+
MAV_DATA_STREAM_ALL: 0,
542+
MAV_DATA_STREAM_RAW_SENSORS: 1,
543+
MAV_DATA_STREAM_EXTENDED_STATUS: 2,
544+
MAV_DATA_STREAM_RC_CHANNELS: 3,
545+
MAV_DATA_STREAM_RAW_CONTROLLER: 4,
546+
MAV_DATA_STREAM_POSITION: 6,
547+
MAV_DATA_STREAM_EXTRA1: 10,
548+
MAV_DATA_STREAM_EXTRA2: 11,
549+
MAV_DATA_STREAM_EXTRA3: 12,
550+
}

radio/app/endpoints/states.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,12 @@ def set_stream_rate(data: SetStreamRateType):
125125
if not droneStatus.drone:
126126
return
127127

128-
print("Setting data stream rate")
129-
droneStatus.drone.sendDataStreamRequestMessage(data["stream"], data["rate"])
128+
if (rate := data.get("rate", None)) is None:
129+
return missingParameterError("set_state", "state")
130+
131+
if rate > 15 or rate < 0:
132+
logger.error("Cannot set data stream rate outside of range [0, 15]")
133+
return
134+
135+
logger.info(f"Setting data stream rate {data['rate']}")
136+
droneStatus.drone.sendDataStreamRequestMessage(data["stream"], rate)

0 commit comments

Comments
 (0)