mirror of
https://github.com/okalachev/flix.git
synced 2026-09-06 00:10:58 +00:00
Make failed mavlink commands exception more verbose in pytflix
This commit is contained in:
@@ -264,7 +264,9 @@ class Flix:
|
|||||||
self.mavlink.command_long_send(self.system_id, 0, command, 0, *params) # type: ignore
|
self.mavlink.command_long_send(self.system_id, 0, command, 0, *params) # type: ignore
|
||||||
ack = self.wait('mavlink.COMMAND_ACK', value=lambda msg: msg.command == command, 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:
|
if ack.result != mavlink.MAV_RESULT_ACCEPTED:
|
||||||
raise RuntimeError(f'Command {command} failed with result {ack.result}')
|
name = getattr(mavlink.enums['MAV_CMD'].get(command, {}), 'name', f'UNKNOWN({command})')
|
||||||
|
result = getattr(mavlink.enums['MAV_RESULT'].get(ack.result, {}), 'name', f'UNKNOWN({ack.result})')
|
||||||
|
raise RuntimeError(f'Command {name} failed with result {result}')
|
||||||
return
|
return
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
continue
|
continue
|
||||||
|
|||||||
+5
-2
@@ -46,5 +46,8 @@ def test():
|
|||||||
flix.set_mode('AUTO')
|
flix.set_mode('AUTO')
|
||||||
flix.wait('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
|
print("=== Check command errors")
|
||||||
raises(RuntimeError, lambda: flix._command_send(mavlink.MAV_CMD_DO_PARACHUTE, [0, 0, 0, 0, 0, 0, 0])) # unsupported command
|
with raises(RuntimeError, match='MAV_RESULT_DENIED'):
|
||||||
|
flix._command_send(mavlink.MAV_CMD_DO_SET_MODE, [0, 99, 0, 0, 0, 0, 0]) # invalid mode
|
||||||
|
with raises(RuntimeError, match='MAV_RESULT_UNSUPPORTED'):
|
||||||
|
flix._command_send(mavlink.MAV_CMD_DO_PARACHUTE, [0, 0, 0, 0, 0, 0, 0]) # unsupported command
|
||||||
|
|||||||
Reference in New Issue
Block a user