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",    None)
         self.mincycle    = default("mincycle", None)
     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 type(self.fix.time) == type(0.0):
                 self.fix.time = self.utc
             else:
                 self.fix.time = isotime(self.utc.encode("ascii"))
         self.fix.ept =       default("ept",   None, TIMERR_SET)
         self.fix.latitude =  default("lat",   None, LATLON_SET)
         self.fix.longitude = default("lon",   None)
         self.fix.altitude =  default("alt",   None, ALTITUDE_SET)
         self.fix.epx =       default("epx",   None, HERR_SET)
         self.fix.epy =       default("epy",   None, HERR_SET)
         self.fix.epv =       default("epv",   None, VERR_SET)
         self.fix.track =     default("track", None, TRACK_SET)
         self.fix.speed =     default("speed", None, SPEED_SET)
         self.fix.climb =     default("climb", None, CLIMB_SET)
         self.fix.epd =       default("epd",   None)
         self.fix.eps =       default("eps",   None, SPEEDERR_SET)
         self.fix.epc =       default("epc",   None, 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", None, 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
                if type(self.fix.time) == type(0.0):
                    self.fix.time = self.utc
                else:
                    self.fix.time = isotime(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 = isotime(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())
                    newsats = []
                    for i in range(d1):
                        newsats.append(
                            gps.satellite(*map(int, satellites[i].split())))
                    self.satellites = newsats
                    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 None
                         else:
                             try:
                                 value = cnv(fields[i])
                             except ValueError:
                                 return None
                             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 = isotime(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())
                 newsats = []
                 for i in range(d1):
                     newsats.append(gps.satellite(*map(int, satellites[i].split())))
                 self.satellites = newsats
                 self.valid |= SATELLITE_SET