-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·60 lines (43 loc) · 1.25 KB
/
server.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
#!/usr/bin/env python
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
import socketio
import time
from bridge import Bridge
from conf import conf
sio = socketio.Server(async_mode='gevent')
msgs = []
dbw_enable = False
@sio.on('connect')
def connect(sid, environ):
print("connect ", sid)
def send(topic, data):
sio.emit(topic, data=data, skip_sid=True)
bridge = Bridge(conf, send)
@sio.on('telemetry')
def telemetry(sid, data):
global dbw_enable
if data["dbw_enable"] != dbw_enable:
dbw_enable = data["dbw_enable"]
bridge.publish_dbw_status(dbw_enable)
bridge.publish_odometry(data)
@sio.on('control')
def control(sid, data):
bridge.publish_controls(data)
@sio.on('obstacle')
def obstacle(sid, data):
bridge.publish_obstacles(data)
@sio.on('lidar')
def obstacle(sid, data):
bridge.publish_lidar(data)
@sio.on('trafficlights')
def trafficlights(sid, data):
bridge.publish_traffic(data)
@sio.on('image')
def image(sid, data):
bridge.publish_camera(data)
if __name__ == '__main__':
# Create socketio WSGI application
app = socketio.WSGIApp(sio)
# deploy as an gevent WSGI server
pywsgi.WSGIServer(('', 4567), app, handler_class=WebSocketHandler).serve_forever()