1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#!/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}"
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"
import gpspoller
gpsp=""
try:
gpsp = GpsPoller(doc.gpsdevice)
gpsp.start()
except:
print "gps device not found"
import socket
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) #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)
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:
#pd needs \n at end of message
outsock.sendto( str(r[0])+' '+str(r[1])+'\n', (PD_IP, PD_PORT) )
|