diff options
author | Brent Stapleton <brent.stapleton@ettus.com> | 2017-12-13 15:59:18 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:05:58 -0800 |
commit | f7e88fbf03da8db2388aa3b16f9fa54c18bebfe8 (patch) | |
tree | a306090083e85595514bed316f08a145e934be75 /mpm/python | |
parent | 6e1213149a3a6fc113e1c2e031baf5f90b7d683f (diff) | |
download | uhd-f7e88fbf03da8db2388aa3b16f9fa54c18bebfe8.tar.gz uhd-f7e88fbf03da8db2388aa3b16f9fa54c18bebfe8.tar.bz2 uhd-f7e88fbf03da8db2388aa3b16f9fa54c18bebfe8.zip |
mpm: adding GPS time sensor
Adding GPS time sensor to MPM, and its respective getter.
Reviewed-By: Martin Braun <martin.braun@ettus.com>
Diffstat (limited to 'mpm/python')
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/n310.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 102ff4911..042cedd2e 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -243,6 +243,7 @@ class n310(PeriphManagerBase): mboard_sensor_callback_map = { 'ref_locked': 'get_ref_lock_sensor', 'gps_locked': 'get_gps_lock_sensor', + 'gps_time': 'get_gps_time_sensor', 'gps_tpv': 'get_gps_tpv_sensor', 'gps_sky': 'get_gps_sky_sensor', } @@ -659,6 +660,35 @@ class n310(PeriphManagerBase): 'value': str(gps_locked).lower(), } + def get_gps_time_sensor(self): + """ + Calculates GPS time using a TPV response from GPSd, and returns as a sensor dict + + This time is not high accuracy. + """ + self.log.trace("Polling GPS time results from GPSD") + with GPSDIface() as gps_iface: + response_mode = 0 + # Read responses from GPSD until we get a non-trivial mode + while response_mode <= 0: + gps_info = gps_iface.get_gps_info(resp_class='tpv', timeout=15) + self.log.trace("GPS info: {}".format(gps_info)) + response_mode = gps_info.get("mode", 0) + + import datetime + time_str = gps_info.get("time", "") + self.log.trace("GPS time string: {}".format(time_str)) + time_dt = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S.%fZ") + self.log.trace("GPS datetime: {}".format(time_dt)) + epoch_dt = datetime.datetime(1970, 1, 1) + gps_time = int((time_dt - epoch_dt).total_seconds()) + return { + 'name': 'gps_time', + 'type': 'INTEGER', + 'unit': 'seconds', + 'value': gps_time, + } + def get_gps_tpv_sensor(self): """ Get a TPV response from GPSd as a sensor dict |