-
Notifications
You must be signed in to change notification settings - Fork 0
/
aclauncher.py
75 lines (59 loc) · 2.24 KB
/
aclauncher.py
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
#!/usr/bin/env python
import sys, time
from daemon import Daemon
from i2armchair import FileThread
import argparse
import socket
import signal
import sys
class aclauncher(Daemon):
def run(self):
# parser = argparse.ArgumentParser(description="Navigation simulator. Plays back log files over the network")
# parser.add_argument('--rate', type=int, default=1 , nargs='?', help='how long to sleep for between sending each NMEA sentance')
# parser.add_argument( 'infile', nargs='?', type=argparse.FileType('r'), help='File with log in')
# args = parser.parse_args()
# print args
#logFile = open(,'r')
sentance = ""
TCP_PORT = 2114
UDP_PORT = 51423
BUFFER_SIZE = 20 # Normally 1024, but we want fast response
udpSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
udpSocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
udpSocket.bind(( '' , UDP_PORT))
global fileThread
print "make file"
fileThread = FileThread(open ("/home/david/git/i2captain/examples/swellies","r"),1)
fileThread.addSocket(udpSocket)
print "starting thread"
fileThread.start()
print "thread started"
#ser = serial.Serial('/dev/ttyUSB0', 4800, timeout=1)
#x = ser.read() # read one byte
#s = ser.read(10) # read up to ten bytes (timeout)
#line = ser.readline() # read a '\n' terminated line
server = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
server.bind ( ( '', TCP_PORT ) )
server.listen ( 1 )
while True:
conn, addr = server.accept()
print ("Connection from", addr)
fileThread.addSocket(conn)
server.close()
if __name__ == "__main__":
daemon = aclauncher('/tmp/i2armchair.pid','/dev/null','/tmp/out','/tmp/err')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)