diff options
-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 |