-
Notifications
You must be signed in to change notification settings - Fork 8
/
muse_pyliblo_server.py
159 lines (136 loc) · 5.71 KB
/
muse_pyliblo_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from liblo import *
import datetime
import sys
import time
import gc
from random import randint
class MuseServer(ServerThread):
#listen for messages on port 5000
def __init__(self, f):
self.f = f
ServerThread.__init__(self, 5000)
# receive horseshoe - status indicator values
@make_method('/muse/elements/horseshoe', 'ffff')
def isgood_callback(self, path, args):
f = self.f
ch1, ch2, ch3, ch4 = args
f.write("h " + str(ch1) + ' ' + str(ch2) + ' ' + str(ch3) + ' ' + str(ch4) + '\n')
#receive EEG data
@make_method('/muse/eeg', 'ffff')
def eeg_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("eeg " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/alpha_relative', 'ffff')
def alpha_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("a " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/beta_relative', 'ffff')
def beta_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("b " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/gamma_relative', 'ffff')
def gamma_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("g " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/delta_relative', 'ffff')
def delta_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("d " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/theta_relative', 'ffff')
def theta_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("t " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/alpha_absolute', 'ffff')
def alpha_absolute_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("Aa " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/beta_absolute', 'ffff')
def beta_absolute_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("Ab " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/gamma_absolute', 'ffff')
def gamma_absolute_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("Ag " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/delta_absolute', 'ffff')
def delta_absolute_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("Ad " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/theta_absolute', 'ffff')
def theta_absolute_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("At " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/alpha_session_score', 'ffff')
def alpha_session_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("as " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/beta_session_score', 'ffff')
def beta_session_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("bs " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/gamma_session_score', 'ffff')
def gamma_session_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("gs " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/delta_session_score', 'ffff')
def delta_session_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("ds " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/theta_session_score', 'ffff')
def theta_session_callback(self, path, args):
f = self.f
l_ear, l_forehead, r_forehead, r_ear = args
f.write("ts " + str(l_ear) + ' ' + str(l_forehead) + ' ' + str(r_forehead) + ' ' + str(r_ear) + '\n')
#receive elements data
@make_method('/muse/elements/experimental/concentration', 'f')
def conc_callback(self, path, arg):
f = self.f
concentration = arg[0]
f.write("c " + str(concentration) + '\n')
def initialize(f):
try:
server = MuseServer(f)
return server
except KeyboardInterrupt:
print ("End of program: Caught KeyboardInterrupt")
sys.exit()
except ServerError, err:
print str(err)
sys.exit()
if __name__ == "__main__":
f = open('test', 'w')
s = initialize(f)
time.sleep(3)
s.start()
time.sleep(5)
s.stop()