Exemple #1
0
 def __oldstyle_shim(self):
     # The rest is backwards compatibility for the old interface
     def default(k, dflt, vbit=0):
         if k not in self.data.keys():
             return dflt
         else:
             self.valid |= vbit
             return self.data[k]
     if self.data.get("class") == "VERSION":
         self.version = self.data
     elif self.data.get("class") == "DEVICE":
         self.valid = ONLINE_SET | DEVICE_SET
         self.path = self.data["path"]
         self.activated = default("activated", None)
         driver = default("driver", None, DEVICEID_SET) 
         subtype = default("subtype", None, DEVICEID_SET) 
         self.gps_id = driver
         if subtype:
             self.gps_id += " " + subtype
         self.driver_mode = default("native", 0)
         self.baudrate = default("bps", 0)
         self.serialmode = default("serialmode", "8N1")
         self.cycle = default("cycle",    NaN)
         self.mincycle = default("mincycle", NaN)
     elif self.data.get("class") == "TPV":
         self.valid = ONLINE_SET
         self.utc = default("time", None, TIME_SET)
         if self.utc is not None:
             # Time can be either Unix time as a float or an ISO8601 string
             if isinstance(self.fix.time, float):    # changed from type(self.fix.time) == type(0.0):
                 self.fix.time = self.utc
             elif isinstance(self.fix.time, bytes):  # added
                 self.fix.time = iso_time(self.utc.encode("ascii"))
             else:
                 self.fix.time = iso_time(self.utc)  # changed from iso_time(self.utc.encode("ascii"))
         self.fix.ept = default("ept",   NaN, TIMERR_SET)
         self.fix.latitude = default("lat",   NaN, LATLON_SET)
         self.fix.longitude = default("lon",   NaN)
         self.fix.altitude = default("alt",   NaN, ALTITUDE_SET)
         self.fix.epx = default("epx",   NaN, HERR_SET)
         self.fix.epy = default("epy",   NaN, HERR_SET)
         self.fix.epv = default("epv",   NaN, VERR_SET)
         self.fix.track = default("track", NaN, TRACK_SET)
         self.fix.speed = default("speed", NaN, SPEED_SET)
         self.fix.climb = default("climb", NaN, CLIMB_SET)
         self.fix.epd = default("epd",   NaN)
         self.fix.eps = default("eps",   NaN, SPEEDERR_SET)
         self.fix.epc = default("epc",   NaN, CLIMBERR_SET)
         self.fix.mode = default("mode",  0,   MODE_SET)
     elif self.data.get("class") == "SKY":
         for attrp in ("x", "y", "v", "h", "p", "g"):
             setattr(self, attrp+"dop", default(attrp+"dop", NaN, DOP_SET))
         if "satellites" in self.data.keys():
             self.satellites = [] 
             for sat in self.data['satellites']:
                 self.satellites.append(GPS.Satellite(PRN=sat['PRN'], elevation=sat['el'], azimuth=sat['az'], ss=sat['ss'], used=sat['used']))
         self.satellites_used = 0
         for sat in self.satellites:
             if sat.used:
                 self.satellites_used += 1
         self.valid = ONLINE_SET | SATELLITE_SET
Exemple #2
0
 def __oldstyle_shim(self):
     # The rest is backwards compatibility for the old interface
     def default(k, dflt, vbit=0):
         if k not in self.data.keys():
             return dflt
         else:
             self.valid |= vbit
             return self.data[k]
     if self.data.get("class") == "VERSION":
         self.version = self.data
     elif self.data.get("class") == "DEVICE":
         self.valid = ONLINE_SET | DEVICE_SET
         self.path = self.data["path"]
         self.activated = default("activated", None)
         driver = default("driver", None, DEVICEID_SET) 
         subtype = default("subtype", None, DEVICEID_SET) 
         self.gps_id = driver
         if subtype:
             self.gps_id += " " + subtype
         self.driver_mode = default("native", 0)
         self.baudrate = default("bps", 0)
         self.serialmode = default("serialmode", "8N1")
         self.cycle = default("cycle",    NaN)
         self.mincycle = default("mincycle", NaN)
     elif self.data.get("class") == "TPV":
         self.valid = ONLINE_SET
         self.utc = default("time", None, TIME_SET)
         if self.utc is not None:
             # Time can be either Unix time as a float or an ISO8601 string
             logger.info("GPS: received fix.time type={}".format(type(self.fix.time)))     # TODO: Remove after verified
             if isinstance(self.fix.time, float):    # changed from type(self.fix.time) == type(0.0):
                 self.fix.time = self.utc
             elif isinstance(self.fix.time, bytes):  # added
                 self.fix.time = iso_time(self.utc.encode("ascii"))
             else:
                 self.fix.time = iso_time(self.utc)  # changed from iso_time(self.utc.encode("ascii"))
         self.fix.ept = default("ept",   NaN, TIMERR_SET)
         self.fix.latitude = default("lat",   NaN, LATLON_SET)
         self.fix.longitude = default("lon",   NaN)
         self.fix.altitude = default("alt",   NaN, ALTITUDE_SET)
         self.fix.epx = default("epx",   NaN, HERR_SET)
         self.fix.epy = default("epy",   NaN, HERR_SET)
         self.fix.epv = default("epv",   NaN, VERR_SET)
         self.fix.track = default("track", NaN, TRACK_SET)
         self.fix.speed = default("speed", NaN, SPEED_SET)
         self.fix.climb = default("climb", NaN, CLIMB_SET)
         self.fix.epd = default("epd",   NaN)
         self.fix.eps = default("eps",   NaN, SPEEDERR_SET)
         self.fix.epc = default("epc",   NaN, CLIMBERR_SET)
         self.fix.mode = default("mode",  0,   MODE_SET)
     elif self.data.get("class") == "SKY":
         for attrp in ("x", "y", "v", "h", "p", "g"):
             setattr(self, attrp+"dop", default(attrp+"dop", NaN, DOP_SET))
         if "satellites" in self.data.keys():
             self.satellites = [] 
             for sat in self.data['satellites']:
                 self.satellites.append(GPS.Satellite(PRN=sat['PRN'], elevation=sat['el'], azimuth=sat['az'], ss=sat['ss'], used=sat['used']))
         self.satellites_used = 0
         for sat in self.satellites:
             if sat.used:
                 self.satellites_used += 1
         self.valid = ONLINE_SET | SATELLITE_SET
Exemple #3
0
 def __oldstyle_unpack(self, buf):
     # unpack a daemon response into the gps instance members
     self.fix.time = 0.0
     fields = buf.strip().split(",")
     if fields[0] == "GPSD":
         for field in fields[1:]:
             if not field or field[1] != '=':
                 continue
             cmd = field[0].upper()
             data = field[2:]
             if data[0] == "?":
                 continue
             if cmd == 'F':
                 self.device = data
             elif cmd == 'I':
                 self.gps_id = data
             elif cmd == 'O':
                 fields = data.split()
                 if fields[0] == '?':
                     self.fix.mode = MODE_NO_FIX
                 else:
                     def default(i, vbit=0, cnv=float):
                         if fields[i] == '?':
                             return NaN
                         else:
                             try:
                                 value = cnv(fields[i])
                             except ValueError:
                                 return NaN
                             self.valid |= vbit
                             return value
                     # clear all valid bits that might be set again below
                     self.valid &= ~(
                         TIME_SET | TIMERR_SET | LATLON_SET | ALTITUDE_SET |
                         HERR_SET | VERR_SET | TRACK_SET | SPEED_SET |
                         CLIMB_SET | SPEEDERR_SET | CLIMBERR_SET | MODE_SET
                     )
                     self.utc = fields[1]
                     self.fix.time = default(1, TIME_SET)
                     if not isnan(self.fix.time):
                         self.utc = iso_time(self.fix.time)
                     self.fix.ept = default(2, TIMERR_SET)
                     self.fix.latitude = default(3, LATLON_SET)
                     self.fix.longitude = default(4)
                     self.fix.altitude = default(5, ALTITUDE_SET)
                     self.fix.epx = self.epy = default(6, HERR_SET)
                     self.fix.epv = default(7, VERR_SET)
                     self.fix.track = default(8, TRACK_SET)
                     self.fix.speed = default(9, SPEED_SET)
                     self.fix.climb = default(10, CLIMB_SET)
                     self.fix.epd = default(11)
                     self.fix.eps = default(12, SPEEDERR_SET)
                     self.fix.epc = default(13, CLIMBERR_SET)
                     if len(fields) > 14:
                         self.fix.mode = default(14, MODE_SET, int)
                     else:
                         if self.valid & ALTITUDE_SET:
                             self.fix.mode = MODE_2D
                         else:
                             self.fix.mode = MODE_3D
                         self.valid |= MODE_SET
             elif cmd == 'X':
                 self.online = float(data)
                 self.valid |= ONLINE_SET
             elif cmd == 'Y':
                 satellites = data.split(":")
                 prefix = satellites.pop(0).split()
                 d1 = int(prefix.pop())
                 new_sats = []
                 for i in range(d1):
                     new_sats.append(GPS.Satellite(*map(int, satellites[i].split())))
                 self.satellites = new_sats
                 self.valid |= SATELLITE_SET
Exemple #4
0
 def __oldstyle_unpack(self, buf):
     # unpack a daemon response into the gps instance members
     self.fix.time = 0.0
     fields = buf.strip().split(",")
     if fields[0] == "GPSD":
         for field in fields[1:]:
             if not field or field[1] != '=':
                 continue
             cmd = field[0].upper()
             data = field[2:]
             if data[0] == "?":
                 continue
             if cmd == 'F':
                 self.device = data
             elif cmd == 'I':
                 self.gps_id = data
             elif cmd == 'O':
                 fields = data.split()
                 if fields[0] == '?':
                     self.fix.mode = MODE_NO_FIX
                 else:
                     def default(i, vbit=0, cnv=float):
                         if fields[i] == '?':
                             return NaN
                         else:
                             try:
                                 value = cnv(fields[i])
                             except ValueError:
                                 return NaN
                             self.valid |= vbit
                             return value
                     # clear all valid bits that might be set again below
                     self.valid &= ~(
                         TIME_SET | TIMERR_SET | LATLON_SET | ALTITUDE_SET |
                         HERR_SET | VERR_SET | TRACK_SET | SPEED_SET |
                         CLIMB_SET | SPEEDERR_SET | CLIMBERR_SET | MODE_SET
                     )
                     self.utc = fields[1]
                     self.fix.time = default(1, TIME_SET)
                     if not isnan(self.fix.time):
                         self.utc = iso_time(self.fix.time)
                     self.fix.ept = default(2, TIMERR_SET)
                     self.fix.latitude = default(3, LATLON_SET)
                     self.fix.longitude = default(4)
                     self.fix.altitude = default(5, ALTITUDE_SET)
                     self.fix.epx = self.epy = default(6, HERR_SET)
                     self.fix.epv = default(7, VERR_SET)
                     self.fix.track = default(8, TRACK_SET)
                     self.fix.speed = default(9, SPEED_SET)
                     self.fix.climb = default(10, CLIMB_SET)
                     self.fix.epd = default(11)
                     self.fix.eps = default(12, SPEEDERR_SET)
                     self.fix.epc = default(13, CLIMBERR_SET)
                     if len(fields) > 14:
                         self.fix.mode = default(14, MODE_SET, int)
                     else:
                         if self.valid & ALTITUDE_SET:
                             self.fix.mode = MODE_2D
                         else:
                             self.fix.mode = MODE_3D
                         self.valid |= MODE_SET
             elif cmd == 'X':
                 self.online = float(data)
                 self.valid |= ONLINE_SET
             elif cmd == 'Y':
                 satellites = data.split(":")
                 prefix = satellites.pop(0).split()
                 d1 = int(prefix.pop())
                 new_sats = []
                 for i in range(d1):
                     new_sats.append(GPS.Satellite(*map(int, satellites[i].split())))
                 self.satellites = new_sats
                 self.valid |= SATELLITE_SET