summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-02-23 19:44:32 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-02-23 19:44:32 +0000
commit9c5de0a5887461b53037904ccad7126ccfdebb9c (patch)
treeb37c7dc1f90d8152dade5098ff99e8b61d72f4d3
parent759f861994de2f9f73f4417de6076d0759d2089c (diff)
downloadgpsd-9c5de0a5887461b53037904ccad7126ccfdebb9c.tar.gz
Make gpsprobe work again (gpsd.py was broken).
-rwxr-xr-xgps.py20
-rwxr-xr-xgpsd.py16
-rwxr-xr-xgpsprobe28
3 files changed, 28 insertions, 36 deletions
diff --git a/gps.py b/gps.py
index 962a19c0..63ad4d1d 100755
--- a/gps.py
+++ b/gps.py
@@ -41,37 +41,35 @@ class gpsdata:
def __init__(self):
# Initialize all data members
- now = time.time()
-
self.online = False # True if GPS on, False if not
- self.online_stamp = gps.timestamp(now)
+ self.online_stamp = gps.timestamp(0)
self.utc = ""
self.latitude = self.longitude = 0.0
- self.latlon_stamp = gps.timestamp(now)
+ self.latlon_stamp = gps.timestamp(0)
self.altitude = 0.0 # Meters
- self.altitude_stamp = gps.timestamp(now)
+ self.altitude_stamp = gps.timestamp(0)
self.speed = 0.0 # Knots
- self.speed_stamp = gps.timestamp(now)
+ self.speed_stamp = gps.timestamp(0)
self.track = 0.0 # Degrees from true north
- self.track_stamp = gps.timestamp(now)
+ self.track_stamp = gps.timestamp(0)
self.status = STATUS_NO_FIX
- self.status_stamp = gps.timestamp(now)
+ self.status_stamp = gps.timestamp(0)
self.mode = MODE_NO_FIX
- self.mode_stamp = gps.timestamp(now)
+ self.mode_stamp = gps.timestamp(0)
self.satellites_used = 0 # Satellites used in last fix
self.pdop = self.hdop = self.vdop = 0.0
- self.fix_quality_stamp = gps.timestamp(now)
+ self.fix_quality_stamp = gps.timestamp(0)
self.satellites = [] # satellite objects in view
- self.satellite_stamp = gps.timestamp(now)
+ self.satellite_stamp = gps.timestamp(0)
self.await = self.parts = 0
self.gps_id = None
diff --git a/gpsd.py b/gpsd.py
index a216afac..b99e665d 100755
--- a/gpsd.py
+++ b/gpsd.py
@@ -236,8 +236,7 @@ class NMEA:
else:
return self.logger(0, "Not NMEA\n")
- def handler(self, fd, raw_hook):
- linebuf = os.read(fd, gps.NMEA_MAX)
+ def handler(self, linebuf, raw_hook):
self.handle_line(linebuf[:-2])
if raw_hook:
raw_hook(linebuf)
@@ -294,14 +293,21 @@ class gpsd(gps.gpsdata):
def send(self, buf):
os.write(self.ttyfd, self.parser.add_checksum(buf))
+ def readline(self):
+ buf = ""
+ while len(buf) < gps.NMEA_MAX:
+ buf += os.read(self.ttyfd, gps.NMEA_MAX-len(buf))
+ if buf.endswith("\r\n"):
+ break
+ return buf
+
def set_speed(self, speed):
self.raw[4] = self.raw[5] = eval("termios.B" + `speed`)
termios.tcflush(self.ttyfd, termios.TCIOFLUSH)
termios.tcsetattr(self.ttyfd, termios.TCSANOW, self.raw)
termios.tcflush(self.ttyfd, termios.TCIOFLUSH)
time.sleep(1)
- firstline = os.read(self.ttyfd, gps.NMEA_MAX*2)
- if firstline.find("$GP") > -1:
+ if self.readline().find("$GP") > -1:
self.bps = speed
return 1
else:
@@ -383,7 +389,7 @@ class gpsd(gps.gpsdata):
else:
self.online = True
self.online_stamp.refresh()
- self.devtype.parser.handler(self.ttyfd, self.raw_hook)
+ self.devtype.parser.handler(self.readline(), self.raw_hook)
# count the good fixes
if self.status > gps.STATUS_NO_FIX:
diff --git a/gpsprobe b/gpsprobe
index ecabe132..e06ca3c8 100755
--- a/gpsprobe
+++ b/gpsprobe
@@ -68,7 +68,6 @@ triggers = {
"PRWIZCH": "# This GPS has a Rockwell Zodiac chipset.\n"
}
-SIRF = "# This GPS probably has a SiRF-II or Evermore chipset.\n"
GE301 = "# GPVTG format indicates NMEA version >= 3.01.\n"
if __name__ == '__main__':
@@ -161,17 +160,14 @@ if __name__ == '__main__':
baton = Baton("Looking for first fix", "done")
countdown = await
while countdown > 0:
- status = dev.poll()
- if status > 0:
- if dev.status > gps.STATUS_NO_FIX and dev.mode > gps.MODE_NO_FIX:
- if not fixes:
- fixtime = (time.time()-starttime,)
- baton.end("got it")
- baton = Baton("Gathering fixes")
- fixes.append((dev.latitude, dev.longitude))
- countdown -= 1
- if '.' in dev.utc:
- register(SIRF)
+ if dev.poll() > 0 and dev.latlon_stamp.seen():
+ if not fixes:
+ fixtime = (time.time()-starttime,)
+ baton.end("got it")
+ baton = Baton("Gathering fixes", "done")
+ fixes.append((dev.latitude, dev.longitude))
+ baton.twirl()
+ countdown -= 1
baton.end()
del last_seen
@@ -201,7 +197,6 @@ if __name__ == '__main__':
cycles[key] = interval
maxfreq = distribution[interval]
print "# This is a gnuplot script generated by gpsprobe at %s\n" % time.asctime()
- print protocol
print "# First fix in %f seconds." % fixtime
for key in cycles:
if len(frequencies[key].values()) == 1:
@@ -220,10 +215,6 @@ if __name__ == '__main__':
else:
print "# Send cycle is once per %d seconds." % sendcycle
- # SiRF-II speaks 2.2, but with the 3.01 VTG format
- if SIRF in notifications and GE301 in notifications:
- notifications.remove(GE301)
-
# Step four: print out registered traits
sys.stdout.write("".join(notifications) + "\n")
@@ -274,6 +265,3 @@ if __name__ == '__main__':
sys.stdout.write("end\n")
except KeyboardInterrupt:
print "Aborted."
-
-
-