Move mavlink commands handlers to a separated function

It's more convenient to handle error that way.
This commit is contained in:
Oleg Kalachev
2026-08-29 17:50:29 +03:00
parent 9465c94d66
commit 5d670dcc69
5 changed files with 38 additions and 28 deletions
+1 -1
View File
@@ -1 +1 @@
from .flix import Flix
from .flix import Flix, mavlink
+3 -1
View File
@@ -262,7 +262,9 @@ class Flix:
try:
logger.debug(f'Send command {command} with params {params} (attempt #{attempt + 1})')
self.mavlink.command_long_send(self.system_id, 0, command, 0, *params) # type: ignore
self.wait('mavlink.COMMAND_ACK', value=lambda msg: msg.command == command and msg.result == mavlink.MAV_RESULT_ACCEPTED, timeout=0.1)
ack = self.wait('mavlink.COMMAND_ACK', value=lambda msg: msg.command == command, timeout=0.1)
if ack.result != mavlink.MAV_RESULT_ACCEPTED:
raise RuntimeError(f'Command {command} failed with result {ack.result}')
return
except TimeoutError:
continue
+5 -2
View File
@@ -2,10 +2,10 @@
# Script for testing pyflix and the simulation.
from pytest import approx
from pytest import approx, raises
from math import isnan, isfinite
import time
from pyflix import Flix
from pyflix import Flix, mavlink
def test():
print('=== Connect...')
@@ -45,3 +45,6 @@ def test():
flix.wait('mode', 'ACRO')
flix.set_mode('AUTO')
flix.wait('mode', 'AUTO')
raises(RuntimeError, lambda: flix._command_send(mavlink.MAV_CMD_DO_SET_MODE, [0, 99, 0, 0, 0, 0, 0])) # invalid mode
raises(RuntimeError, lambda: flix._command_send(mavlink.MAV_CMD_DO_PARACHUTE, [0, 0, 0, 0, 0, 0, 0])) # unsupported command