This repository was archived by the owner on Jan 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdriverStationServer.py
executable file
·71 lines (48 loc) · 2.01 KB
/
driverStationServer.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
#!/usr/bin/env python3
import json
from os.path import dirname, join
import tornado.web
from tornado.ioloop import IOLoop
from tornado.options import define, options, parse_command_line
from networktables import NetworkTable
from pynetworktables2js import get_handlers, NonCachingStaticFileHandler
import logging
logger = logging.getLogger('dashboard')
# Setup logging
log_datefmt = "%H:%M:%S"
log_format = "%(asctime)s:%(msecs)03d %(levelname)-8s: %(name)-20s: %(message)s"
logging.basicConfig(datefmt=log_datefmt,
format=log_format,
level=logging.DEBUG)
class ConfigHandler(tornado.web.RequestHandler):
'''Writes JSON that the HTML page can retrieve'''
def get(self):
self.write('var Config = ' + json.dumps({
'frontcam': options.frontcam,
'backcam': options.backcam
}) + ';')
def init_networktables(ipaddr):
logger.info("Connecting to networktables at %s" % ipaddr)
NetworkTable.setIPAddress(ipaddr)
NetworkTable.setClientMode()
NetworkTable.initialize()
logger.info("Networktables Initialized")
def main():
define("frontcam", default="http://10.14.18.2:5800", help="URL for the front camera", type=str)
define("backcam", default="http://10.14.18.2:5801", help="URL for the back camera", type=str)
define("host", default='127.0.0.1', help="Hostname of robot", type=str)
define("port", default=8888, help="run on the given port", type=int)
parse_command_line()
init_networktables(options.host)
app = tornado.web.Application(
get_handlers() + [
(r"/config.js", ConfigHandler),
(r"/()", NonCachingStaticFileHandler, {"path": join(dirname(__file__), 'UI_MainPage.html')}),
(r"/(.*)", NonCachingStaticFileHandler, {"path": dirname(__file__)}),
]
)
logger.info("Listening on http://localhost:%s/" % options.port)
app.listen(options.port)
IOLoop.instance().start()
if __name__ == '__main__':
main()