-
Notifications
You must be signed in to change notification settings - Fork 13
/
replay_server.py
42 lines (32 loc) · 933 Bytes
/
replay_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
import time
import sys, signal, struct
import socket
import json
from bdf import BDFReader, WAVReader
from pyqtgraph import QtCore, QtGui
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = QtCore.QCoreApplication(sys.argv)
#app = QtGui.QApplication(sys.argv)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def send_packet(channels):
data = json.dumps(channels)
sock.sendto(data.encode('utf-8'), ('localhost', 8888))
data = struct.pack('=f', channels[0] * 0.022351744455307063)
sock.sendto(data, ('localhost', 9999))
filename = sys.argv[1]
filehandler = open(filename, 'rb')
if filename.lower().endswith('.wav'):
bdf = WAVReader(filehandler)
else:
bdf = BDFReader(filehandler)
def handle_timeout():
packet = bdf.readPacket()
if packet:
send_packet(packet)
else:
app.quit()
timer = QtCore.QTimer()
timer.timeout.connect(handle_timeout)
#timer.start(1000 / 250)
timer.start(3)
app.exec_()