generated from NeuroTech-UCSD/Project-Template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dsi_manual_simulator.py
46 lines (33 loc) · 983 Bytes
/
dsi_manual_simulator.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
import time
import asyncio
import socketio
import random
import settings
sio = socketio.AsyncClient()
PORT = settings.Configuration.app['port']
HOST = settings.Configuration.app['host']
@sio.event
async def connect():
print('dsi manual simulator connected')
@sio.event
async def connect_error(e):
print('Connection error:', e)
@sio.event
async def disconnect():
print('dsi manual simulator disconnected')
async def _dsi_simulator():
"""
:return:
"""
while True:
await sio.sleep(1)
print("Enter a message for dsi:", end=" ")
dsi_message = str(input())
print('DSI simulator sending message:', dsi_message)
await sio.emit('forward_message', dsi_message, namespace='/dsi')
async def dsi_simulator():
await sio.connect(f'http://{HOST}:{PORT}', namespaces=['/', '/dsi'])
await sio.start_background_task(_dsi_simulator)
await sio.wait()
if __name__ == '__main__':
asyncio.run(dsi_simulator())