diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-11-18 18:40:12 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 12:21:34 -0800 |
commit | 9ede696528a57c3a810b7897d7d40abb21d89b24 (patch) | |
tree | 7f7c6ca73be128224b33f98301045c5ce071aff4 /mpm/python/usrp_mpm/gpsd_iface.py | |
parent | 3132634bb427044e123b072658690ce47c56fd48 (diff) | |
download | uhd-9ede696528a57c3a810b7897d7d40abb21d89b24.tar.gz uhd-9ede696528a57c3a810b7897d7d40abb21d89b24.tar.bz2 uhd-9ede696528a57c3a810b7897d7d40abb21d89b24.zip |
mpm: e310: Enable GPS sensors
The GPS sensors are pulled in via gpsd_iface.
Diffstat (limited to 'mpm/python/usrp_mpm/gpsd_iface.py')
-rw-r--r-- | mpm/python/usrp_mpm/gpsd_iface.py | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/mpm/python/usrp_mpm/gpsd_iface.py b/mpm/python/usrp_mpm/gpsd_iface.py index cbd43f0a6..72cde22b1 100644 --- a/mpm/python/usrp_mpm/gpsd_iface.py +++ b/mpm/python/usrp_mpm/gpsd_iface.py @@ -191,18 +191,26 @@ class GPSDIfaceExtension(object): """ def __init__(self): self._gpsd_iface = GPSDIface() - self._gpsd_iface.open() self._log = self._gpsd_iface.log + self._initialized = False + try: + self._gpsd_iface.open() + self._initialized = True + except (ConnectionRefusedError, ConnectionResetError): + self._log.warning( + "Could not connect to GPSd! None of the GPS sensors will work!") def __del__(self): - self._gpsd_iface.close() + if self._initialized: + self._gpsd_iface.close() def extend(self, context): """Register the GSPDIfaceExtension object's public function with `context`""" new_methods = [method_name for method_name in dir(self) if not method_name.startswith('_') \ and callable(getattr(self, method_name)) \ - and method_name != "extend"] + and method_name.endswith("sensor") \ + and self._initialized] for method_name in new_methods: new_method = getattr(self, method_name) self._log.trace("%s: Adding %s method", context, method_name) @@ -377,6 +385,26 @@ class GPSDIfaceExtension(object): 'value': gpgga, } + def get_gps_lock(self): + """ + Get the GPS lock status using the TPV data. + + The Jackson Labs GPS modules have a pin to query GPS lock, which is a + better option. + """ + if not self._initialized: + self._log.warning("Cannot query GPS lock, GPSd not initialized!") + return False + # Read responses from GPSD until we get a non-trivial mode + while True: + gps_info = self._gpsd_iface.get_gps_info(resp_class='tpv', timeout=15) + self._log.trace("GPS info: {}".format(gps_info)) + if gps_info.get("mode", 0) > 0: + break + # 2 == 2D fix, 3 == 3D fix. + # https://gpsd.gitlab.io/gpsd/gpsd_json.html + return gps_info.get("mode", 0) >= 2 + def main(): """Test functionality of the GPSDIface class""" @@ -401,8 +429,6 @@ def main(): gps_ext = GPSDIfaceExtension() for _ in range(10): print(gps_ext.get_gps_time_sensor().get('value')) - #TODO Add GPSDIfaceExtension code - if __name__ == "__main__": main() |