mirror of
https://github.com/okalachev/flix.git
synced 2026-09-05 16:00:56 +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
|
||||
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}')
|
||||
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
|
||||
except TimeoutError:
|
||||
continue
|
||||
|
||||
+5
-2
@@ -46,5 +46,8 @@ def test():
|
||||
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
|
||||
print("=== Check command errors")
|
||||
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