def time(self): "Return the gpsd time fix" t = self.gpsd.fix.time if isinstance(t, int): return t if isinstance(t, float): if not gps.isfinite(t): return None return t return gps.isotime(t)
def read_gps(): global last_fix session = gps(mode=WATCH_ENABLE) while running: fix = session.next() if fix['class'] == 'TPV': fix = [fix.lon, fix.lat, fix.alt, isotime(fix.time)] last_fix.append(fix)
def parse_tdl(self, line): "Interpret one TDL directive." line = line.strip() if "#" in line: line = line[:line.find("#")] if line == '': return fields = line.split() command = fields[0] if command == "time": self.ksv.time = gps.isotime(fields[1]) elif command == "location": (self.lat, self.lon, self.alt) = list(map(float, fields[1:])) elif command == "course": self.ksv.time = float(fields[1]) elif command == "speed": self.ksv.speed = float(fields[1]) elif command == "climb": self.ksv.climb = float(fields[1]) elif command == "acceleration": (self.ksv.h_acc, self.ksv.h_acc) = list(map(float, fields[1:])) elif command == "snr": self.channels[int(fields[1])] = float(fields[2]) elif command == "go": self.go(int(fields[1])) elif command == "status": try: code = fields[1] self.status = { "no_fix": 0, "fix": 1, "dgps_fix": 2 }[code.lower()] except KeyError: raise gpssimException("invalid status code '%s'" % code, self.filename, self.lineno) elif command == "mode": try: code = fields[1] self.status = {"no_fix": 1, "2d": 2, "3d": 3}[code.lower()] except KeyError: raise gpssimException("invalid mode code '%s'" % code, self.filename, self.lineno) elif command == "satellites": self.satellites_used = int(fields[1]) elif command == "validity": self.validity = fields[1] else: raise gpssimException("unknown command '%s'" % fields[1], self.filename, self.lineno) # FIX-ME: add syntax for ephemeris elements self.lineno += 1
def parse_tdl(self, line): "Interpret one TDL directive." line = line.strip() if "#" in line: line = line[:line.find("#")] if line == '': return fields = line.split() command = fields[0] if command == "time": self.ksv.time = gps.isotime(fields[1]) elif command == "location": (self.lat, self.lon, self.alt) = list(map(float, fields[1:])) elif command == "course": self.ksv.time = float(fields[1]) elif command == "speed": self.ksv.speed = float(fields[1]) elif command == "climb": self.ksv.climb = float(fields[1]) elif command == "acceleration": (self.ksv.h_acc, self.ksv.h_acc) = list(map(float, fields[1:])) elif command == "snr": self.channels[int(fields[1])] = float(fields[2]) elif command == "go": self.go(int(fields[1])) elif command == "status": try: code = fields[1] self.status = {"no_fix": 0, "fix": 1, "dgps_fix": 2}[ code.lower()] except KeyError: raise gpssimException("invalid status code '%s'" % code, self.filename, self.lineno) elif command == "mode": try: code = fields[1] self.status = {"no_fix": 1, "2d": 2, "3d": 3}[code.lower()] except KeyError: raise gpssimException("invalid mode code '%s'" % code, self.filename, self.lineno) elif command == "satellites": self.satellites_used = int(fields[1]) elif command == "validity": self.validity = fields[1] else: raise gpssimException("unknown command '%s'" % fields[1], self.filename, self.lineno) # FIX-ME: add syntax for ephemeris elements self.lineno += 1
def update_time(self, data): if hasattr(data, "time"): return gps.isotime(data.time) else: return "n/a"