aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2021-06-02 13:05:57 +0200
committerAaron Rossetto <aaron.rossetto@ni.com>2021-06-03 09:35:09 -0500
commitd7ba6ae7c2d53d86a295117d0af8f97cacd03b3a (patch)
tree415f190cf58fa9b1fd64ef3cacee04961b07c3f3 /mpm/python
parent15b94c53edc86031c74b27cd3d824d2291c0c91f (diff)
downloaduhd-d7ba6ae7c2d53d86a295117d0af8f97cacd03b3a.tar.gz
uhd-d7ba6ae7c2d53d86a295117d0af8f97cacd03b3a.tar.bz2
uhd-d7ba6ae7c2d53d86a295117d0af8f97cacd03b3a.zip
mpm: gpsd_iface: Make GPGGA generation more robust
The GPGGA string generation relies on TPV and SKY messages being accurate, meaning they are a list of dictionaries. There have been cases where this was inaccurate (an empty list was returned). MPM would show errors as such: [ERROR] [MPM.RPCServer] Uncaught exception in method get_mb_sensor :list index out of range Traceback (most recent call last): File "/usr/lib/python3.7/site-packages/usrp_mpm/rpc_server.py", line 184, in new_claimed_function return function(*args) File "/usr/lib/python3.7/site-packages/usrp_mpm/periph_manager/base.py", line 1000, in get_mb_sensor self, self.mboard_sensor_callback_map.get(sensor_name) File "/usr/lib/python3.7/site-packages/usrp_mpm/gpsd_iface.py", line 313, in get_gps_gpgga_sensor tpv_sensor_data = gps_info.get('tpv', [{}])[0] IndexError: list index out of range This is a patch to check that the lists are not empty before directly referencing index 0 therein.
Diffstat (limited to 'mpm/python')
-rw-r--r--mpm/python/usrp_mpm/gpsd_iface.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/mpm/python/usrp_mpm/gpsd_iface.py b/mpm/python/usrp_mpm/gpsd_iface.py
index 68747dff5..8d6b7049a 100644
--- a/mpm/python/usrp_mpm/gpsd_iface.py
+++ b/mpm/python/usrp_mpm/gpsd_iface.py
@@ -381,12 +381,15 @@ class GPSDIfaceExtension:
while True:
gps_info = self._gpsd_iface.get_gps_info(resp_class='', timeout=15)
self._log.trace("GPS info: {}".format(gps_info))
- tpv_sensor_data = gps_info.get('tpv', [{}])[0]
- sky_sensor_data = gps_info.get('sky', [{}])[0]
- if tpv_sensor_data and \
- sky_sensor_data and \
- tpv_sensor_data.get("mode", 0) > 0:
- break
+ # Response types are 'list of dicts', but they can be empty lists so
+ # we need to prepare for that:
+ tpv_sensor_data = gps_info.get('tpv')
+ sky_sensor_data = gps_info.get('sky')
+ if tpv_sensor_data and sky_sensor_data:
+ tpv_sensor_data = tpv_sensor_data[0]
+ sky_sensor_data = sky_sensor_data[0]
+ if tpv_sensor_data.get("mode", 0) > 0:
+ break
return {
'name': 'gpgga',
'type': 'STRING',