mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-24 13:55:51 +08:00
Added try...except to be more safe after pprzlink api changes. (#2548)
* Updated pprzlink library to the latest version * Added try...except to crazyradio2ivy.py to be safer after pprzlink API changes. paparazzi/pprzlink#117 * Updated request messages with the new pprzlink API * Added a #noqa comment so linters won't remove the seemingly unused import. * Updated the guided_mode_example.py to have a wait timeout.
This commit is contained in:
committed by
GitHub
parent
4575375876
commit
eeac31e1e4
@@ -98,7 +98,12 @@ class RadioBridge:
|
||||
print("Got message {} from {}".format(msg.name, sender_id))
|
||||
# Forward message to Ivy bus
|
||||
if self.is_connected:
|
||||
self._ivy.send(msg, sender_id=sender_id)
|
||||
try:
|
||||
self._ivy.send(msg, sender_id=sender_id)
|
||||
except RuntimeError as e:
|
||||
print("Runtime error {}".format(e))
|
||||
except ValueError as e:
|
||||
print("Invalid message error {}".format(e))
|
||||
|
||||
def _link_quality_cb(self, quality):
|
||||
pass
|
||||
|
||||
@@ -161,17 +161,26 @@ class IvyRequester(object):
|
||||
self._interface = None
|
||||
|
||||
def get_aircrafts(self):
|
||||
wait_step = 0.1
|
||||
timeout = 30 / wait_step # 30 seconds
|
||||
new_answer = False
|
||||
|
||||
def aircrafts_cb(ac_id, msg):
|
||||
global new_answer
|
||||
self.ac_list = [int(a) for a in msg['ac_list'].split(',') if a]
|
||||
print("aircrafts: {}".format(self.ac_list))
|
||||
new_answer = True
|
||||
|
||||
self._interface.subscribe(aircrafts_cb, "(.*AIRCRAFTS .*)")
|
||||
sender = 'get_aircrafts'
|
||||
request_id = '42_1' # fake request id, should be PID_index
|
||||
self._interface.send("{} {} AIRCRAFTS_REQ".format(sender, request_id))
|
||||
self._interface.send_request('ground', "AIRCRAFTS", aircrafts_cb)
|
||||
# hack: sleep briefly to wait for answer
|
||||
sleep(0.1)
|
||||
while not new_answer and timeout > 0:
|
||||
sleep(wait_step)
|
||||
timeout -= 1
|
||||
|
||||
if not new_answer:
|
||||
print("WARNING: Getting the list of aircraft timed out. The results might be outdated.")
|
||||
# Didn't raise an exception or return None in order to not break the API
|
||||
|
||||
return self.ac_list
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user