From 472e9dc583e7f61f4d7cfbc4c02a5690230b2c88 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 5 May 2012 14:44:58 +0100 Subject: checking gps --- tomorrowtheground.py | 104 --------------------------------------------------- wim.py | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 104 deletions(-) delete mode 100755 tomorrowtheground.py create mode 100755 wim.py diff --git a/tomorrowtheground.py b/tomorrowtheground.py deleted file mode 100755 index a3d47bc..0000000 --- a/tomorrowtheground.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/python -#UDP listener - -import signal,sys - -def signal_handler(signal, frame): - insock.close() - print "tomorrowtheground: interrupted" - sys.exit(0) - -signal.signal(signal.SIGINT, signal_handler) - -from latLng import * -from layers import * -from xml2obj import * - - -if len(sys.argv)<2: - print "usage: tomorrowtheground configfile [-D] (debug)]" - -debug=False -if len(sys.argv)>2: - if sys.argv[1]=="-D" or sys.argv[1]=="-d": - debug=True - -doc=xml2obj(open(sys.argv[1])) -gpslayers=[] - -#catch invalid xml -try: - for i in doc.gps.index: - #catch invalid xml - try: - g=indexlayer(i.file,i.ll1,i.ll2) - for t in i.trigger: - g.triggers.append(trigger(int(t.id),t.command,t.param)) - gpslayers.append(g) - except: - print "error parsing xml index entry" -except: - print "no index layers found" - -#catch invalid xml -try: - for i in doc.gps.scale: - #catch invalid xml - try: - g=scalelayer(i.file,i.ll1,i.ll2) - g.setcommand(i.command) - gpslayers.append(g) - except: - print "error parsing xml index entry" -except: - print "no scale layers found" - -from gpspoller import * -gpsp="" - -try: - gpsp = GpsPoller(doc.gpsdevice) - gpsp.start() -except: - print "gps device not found" - - -import socket - -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 -PD_IP="127.0.0.1" -PD_PORT=5401 -outsock = socket.socket( socket.AF_INET,socket.SOCK_DGRAM ) - -pos=latLng() -posChanged=False - -while True: - data="" - try: - data, addr = insock.recvfrom(128) - pos.parse(data) - if (debug): - print "received:",data - posChanged=True - except: - nothing=None - if gpsp!="": - check=gpsp.check() - if check!=False: - pos=latLng(check[0],check[1]) - posChanged=True - if posChanged: - posChanged=False - for layer in gpslayers: - r=layer.checkcoord(pos) #returns a message or None - if r!=None: - if (debug): - print "sending:",str(r[0]),str(r[1]) - #pd needs \n at end of message - outsock.sendto( str(r[0])+' '+str(r[1])+'\n', (PD_IP, PD_PORT) ) - \ No newline at end of file diff --git a/wim.py b/wim.py new file mode 100755 index 0000000..a3d47bc --- /dev/null +++ b/wim.py @@ -0,0 +1,104 @@ +#!/usr/bin/python +#UDP listener + +import signal,sys + +def signal_handler(signal, frame): + insock.close() + print "tomorrowtheground: interrupted" + sys.exit(0) + +signal.signal(signal.SIGINT, signal_handler) + +from latLng import * +from layers import * +from xml2obj import * + + +if len(sys.argv)<2: + print "usage: tomorrowtheground configfile [-D] (debug)]" + +debug=False +if len(sys.argv)>2: + if sys.argv[1]=="-D" or sys.argv[1]=="-d": + debug=True + +doc=xml2obj(open(sys.argv[1])) +gpslayers=[] + +#catch invalid xml +try: + for i in doc.gps.index: + #catch invalid xml + try: + g=indexlayer(i.file,i.ll1,i.ll2) + for t in i.trigger: + g.triggers.append(trigger(int(t.id),t.command,t.param)) + gpslayers.append(g) + except: + print "error parsing xml index entry" +except: + print "no index layers found" + +#catch invalid xml +try: + for i in doc.gps.scale: + #catch invalid xml + try: + g=scalelayer(i.file,i.ll1,i.ll2) + g.setcommand(i.command) + gpslayers.append(g) + except: + print "error parsing xml index entry" +except: + print "no scale layers found" + +from gpspoller import * +gpsp="" + +try: + gpsp = GpsPoller(doc.gpsdevice) + gpsp.start() +except: + print "gps device not found" + + +import socket + +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 +PD_IP="127.0.0.1" +PD_PORT=5401 +outsock = socket.socket( socket.AF_INET,socket.SOCK_DGRAM ) + +pos=latLng() +posChanged=False + +while True: + data="" + try: + data, addr = insock.recvfrom(128) + pos.parse(data) + if (debug): + print "received:",data + posChanged=True + except: + nothing=None + if gpsp!="": + check=gpsp.check() + if check!=False: + pos=latLng(check[0],check[1]) + posChanged=True + if posChanged: + posChanged=False + for layer in gpslayers: + r=layer.checkcoord(pos) #returns a message or None + if r!=None: + if (debug): + print "sending:",str(r[0]),str(r[1]) + #pd needs \n at end of message + outsock.sendto( str(r[0])+' '+str(r[1])+'\n', (PD_IP, PD_PORT) ) + \ No newline at end of file -- cgit v1.2.3