From b7e28404a9962cf220c51e1b83b81b6a2b6a3d87 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 5 May 2012 23:14:34 +0100 Subject: fix test gps status --- gpspoller.py | 62 ++++++++++++++++++++++++++++++++++++---------------------- testreceive.pd | 28 ++++++++++++++++---------- wim.py | 16 ++++++++++++--- 3 files changed, 70 insertions(+), 36 deletions(-) diff --git a/gpspoller.py b/gpspoller.py index 6f7c19c..13ad5bb 100644 --- a/gpspoller.py +++ b/gpspoller.py @@ -1,3 +1,5 @@ + + #!/usr/bin/python # Copyright (C) 2007 by Jaroslaw Zachwieja @@ -12,12 +14,15 @@ class GpsPoller(threading.Thread): latitude = 0 longitude = 0 changed = False + fix=0 + satellites=0 def __init__(self,port,test=False): self.test=test self.port=port self.gps = serial.Serial(port, 9600, timeout=1) threading.Thread.__init__(self) + self.fixname=("no fix","no fix","2D fix","3D fix") def check(self): if self.changed: @@ -42,32 +47,42 @@ class GpsPoller(threading.Thread): line = self.gps.read(1) line = line+self.gps.readline() datablock = line.split(',') + #print line + try: + if line[0:6] =='$GPGSV': + self.satellites=string.atoi(datablock[3]) + if line[0:6] =='$GPGSA': + self.fix=string.atoi(datablock[2]) + if line[0:6] == '$GPGGA': + + + latitude_in = string.atof(datablock[2]) + longitude_in = string.atof(datablock[4]) + + #altitude = string.atof(datablock[8]) + #speed_in = string.atof(datablock[7]) + #heading = string.atof(datablock[8]) - if line[0:6] == '$GPRMC': - latitude_in = string.atof(datablock[3]) - longitude_in = string.atof(datablock[5]) - altitude = string.atof(datablock[8]) - speed_in = string.atof(datablock[7]) - heading = string.atof(datablock[8]) - - if datablock[4] == 'S': - latitude_in = -latitude_in - if datablock[6] == 'W': - longitude_in = -longitude_in + if datablock[3] == 'S': + latitude_in = -latitude_in + if datablock[5] == 'W': + longitude_in = -longitude_in - latitude_degrees = int(latitude_in/100) - latitude_minutes = latitude_in - latitude_degrees*100 + latitude_degrees = int(latitude_in/100) + latitude_minutes = latitude_in - latitude_degrees*100 - longitude_degrees = int(longitude_in/100) - longitude_minutes = longitude_in - longitude_degrees*100 + longitude_degrees = int(longitude_in/100) + longitude_minutes = longitude_in - longitude_degrees*100 - latitude = latitude_degrees + (latitude_minutes/60) - longitude = longitude_degrees + (longitude_minutes/60) - - if latitude!=self.latitude or longitude!=self.longitude: - self.latitude=latitude - self.longitude=longitude - self.changed=True + latitude = latitude_degrees + (latitude_minutes/60) + longitude = longitude_degrees + (longitude_minutes/60) + + if latitude!=self.latitude or longitude!=self.longitude: + self.latitude=latitude + self.longitude=longitude + self.changed=True + except: + print "caught corrupt NMEA sentence" except StopIteration: @@ -82,7 +97,8 @@ if __name__ == '__main__': gpsp.start() while 1: # In the main thread, every 5 seconds print the current value - time.sleep(0.1) + time.sleep(1.0) check=gpsp.check() + print gpsp.fixname[gpsp.fix],":satellites in view", gpsp.satellites if check!=False: print "changed:",check[0],check[1] diff --git a/testreceive.pd b/testreceive.pd index 4cab815..1376a6c 100644 --- a/testreceive.pd +++ b/testreceive.pd @@ -1,14 +1,22 @@ -#N canvas 886 488 450 300 10; -#X obj 169 92 print udp; +#N canvas 210 148 450 300 10; #X msg 29 61 /pd 1; #X msg 82 26 /other 1; #X obj 169 50 netreceive 5401 1; #X obj 145 210 print play; -#X obj 266 211 print other; -#X obj 148 140 route play cc01; -#X connect 1 0 6 0; -#X connect 2 0 6 0; -#X connect 3 0 0 0; -#X connect 3 0 6 0; -#X connect 6 0 4 0; -#X connect 6 2 5 0; +#X obj 352 172 print other; +#X obj 148 140 route play cc01 gpsstatus; +#X obj 212 217 print cc01; +#X msg 296 204 set \$1; +#X floatatom 301 244 5 0 0 0 - - -; +#X obj 344 39 loadbang; +#X msg 341 86 set 0; +#X connect 0 0 5 0; +#X connect 1 0 5 0; +#X connect 2 0 5 0; +#X connect 5 0 3 0; +#X connect 5 1 6 0; +#X connect 5 2 7 0; +#X connect 5 3 4 0; +#X connect 7 0 8 0; +#X connect 9 0 10 0; +#X connect 10 0 8 0; diff --git a/wim.py b/wim.py index ce5c6ea..ccc0ac8 100755 --- a/wim.py +++ b/wim.py @@ -70,7 +70,7 @@ GUI_IP="0.0.0.0" GUI_PORT=5400 insock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) insock.bind( (GUI_IP,GUI_PORT) ) -insock.settimeout(0.01) #non blocking +insock.settimeout(0.05) #non blocking, this sets the frame rate of checking PD_IP="127.0.0.1" PD_PORT=5401 outsock = socket.socket( socket.AF_INET,socket.SOCK_DGRAM ) @@ -78,17 +78,27 @@ outsock = socket.socket( socket.AF_INET,socket.SOCK_DGRAM ) pos=latLng() posChanged=False +gpsfix=False + while True: data="" try: data, addr = insock.recvfrom(128) pos.parse(data) - if (debug): + if debug: print "received:",data posChanged=True except: nothing=None - if gpsp!="": + if gpsp!="": #gps available + if not gpsfix: + if gpsp.fix>1: + gpsfix=True + outsock.sendto( "gpsstatus 1\n", (PD_IP, PD_PORT) ) + if gpsfix: + if gpsp.fix<2: + gpsfix=False + outsock.sendto( "gpsstatus 0\n", (PD_IP, PD_PORT) ) check=gpsp.check() if check!=False: if debug: -- cgit v1.2.3