-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSCserver_dataRecorder.py
67 lines (47 loc) · 1.38 KB
/
OSCserver_dataRecorder.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
# Program to record motion data from OSC
# Listens on port 9050 (normally the Processing port)
# Stores all data in files in tests/data/
from liblo import *
from OSC import *
from time import *
import json
from datetime import datetime, timedelta
from DataIOClasses import DataWriter, DataReader
startTime = []
timestr = strftime("%Y%m%d-%H%M%S")
filename = 'tests/data/' + timestr + '.txt'
datawriter = DataWriter(filename)
startTime = datetime.now()
# Threaded server code from "serverThread.py" in pyliblo
class MyServer(ServerThread):
def __init__(self):
ServerThread.__init__(self, 9050)
@make_method('/foo', 'ifs')
def foo_callback(self, path, args):
i, f, s = args
print "received message '%s' with arguments: %d, %f, %s" % (path, i, f, s)
@make_method(None, None)
def fallback(self, path, args):
print "received unknown message '%s', '%s'" % (path, args)
print path
print args
msgJSON = {}
msgJSON['path'] = path
msgJSON['data'] = args
msgJSON['time'] = datetime.now()-startTime
datawriter.addEntry(msgJSON)
try:
server = MyServer()
except ServerError, err:
print str(err)
sys.exit()
server.start()
startTime = datetime.now()
while True:
try:
print "loop!"
sleep(5)
except KeyboardInterrupt:
break
server.stop()
datawriter.close()