diff options
Diffstat (limited to 'tomorrowtheground.py')
| -rwxr-xr-x | tomorrowtheground.py | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/tomorrowtheground.py b/tomorrowtheground.py index 2ffdf7e..5553b42 100755 --- a/tomorrowtheground.py +++ b/tomorrowtheground.py @@ -1,6 +1,21 @@ #!/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) + +import gpspoller +gpsp="" +if len(sys.argv)>1: + gpsp = GpsPoller(sys.argv[1]) + gpsp.start() + from latLng import * from layers import * from xml2obj import * @@ -8,7 +23,7 @@ from xml2obj import * doc=xml2obj(open("ttg01.xml")) gpslayers=[] for i in doc.gps.index: - #should catch invalid xml + #catch invalid xml g=indexlayer(i.file,i.ll1,i.ll2) for t in i.trigger: g.triggers.append(trigger(int(t.id),t.command,t.param)) @@ -20,7 +35,7 @@ GUI_IP="127.0.0.1" GUI_PORT=5400 insock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) insock.bind( (GUI_IP,GUI_PORT) ) -insock.settimeout(0.01) +insock.settimeout(0.01) #non blocking PD_IP="127.0.0.1" PD_PORT=5401 outsock = socket.socket( socket.AF_INET,socket.SOCK_DGRAM ) @@ -35,11 +50,17 @@ while True: pos.parse(data) posChanged=True except: - nothing=None + nothing=None + if gpsp!="": + check=gpsp.check() + if check!=False: + pos=latLng(check[0],check[1]) + posChanged=True if posChanged: - print "received message:", data + posChanged=False for layer in gpslayers: - r=layer.checkcoord(pos) - if layer.checkcoord!=None: - outsock.sendto( r, (PD_IP, PD_PORT) ) + r=layer.checkcoord(pos) #returns a message or None + if r!=None: + #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 |
