- Timestamp:
- 03/29/12 23:04:08 (9 years ago)
- Location:
- trunk/Puzzlebox/Synapse
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Puzzlebox/Synapse/Configuration.py
r328 r352 8 8 9 9 __changelog__ = """\ 10 Last Update: 2012.03. 1310 Last Update: 2012.03.29 11 11 """ 12 12 … … 96 96 THINKGEAR_SERVER_PORT = 13854 97 97 98 EMOTIV_SERVER_HOST = '127.0.0.1' 99 EMOTIV_SERVER_PORT_CONTROL_PANEL = 3008 100 EMOTIV_SERVER_PORT_EMOCOMPOSER = 1726 98 101 99 102 ##################################################################### -
trunk/Puzzlebox/Synapse/Emotiv/Client.py
r351 r352 10 10 """ 11 11 12 #import os, sys 13 #import simplejson as json 14 15 import Configuration as configuration 12 import Puzzlebox.Synapse.Configuration as configuration 16 13 17 14 if configuration.ENABLE_PYSIDE: … … 41 38 SERVER_PORT = configuration.EMOTIV_SERVER_PORT_EMOCOMPOSER 42 39 43 #CLIENT_NO_REPLY_WAIT = configuration.CLIENT_NO_REPLY_WAIT * 1000 44 45 #DELIMITER = configuration.THINKGEAR_DELIMITER 46 47 #THINKGEAR_CONFIGURATION_PARAMETERS = configuration.THINKGEAR_CONFIGURATION_PARAMETERS 48 49 #ENABLE_THINKGEAR_AUTHORIZATION = configuration.ENABLE_THINKGEAR_AUTHORIZATION 50 #AUTHORIZATION_REQUEST = configuration.THINKGEAR_AUTHORIZATION_REQUEST 40 TIMER_BASED__LOOP = True 41 EVENT_TIMER_BASED_LOOP = True 42 EVENT_TIMER_FREQUENCY = 0.25 * 1000 # 4 Hz 51 43 52 44 ##################################################################### … … 54 46 ##################################################################### 55 47 56 class QtClient(QtCore.QThread): 48 #class puzzlebox_synapse_client_emotiv(QtCore.QThread): 49 class puzzlebox_synapse_client_emotiv(): 57 50 58 51 def __init__(self, log, \ … … 62 55 parent=None): 63 56 64 QtCore.QThread.__init__(self,parent)57 #QtCore.QThread.__init__(self,parent) 65 58 66 59 self.log = log … … 71 64 self.server_port = server_port 72 65 73 #self.is_authorized = True 66 self.name = "Emotiv Client" 67 68 #self.protocol = emotiv_protocol 69 70 #self.configureNetwork() 71 72 #if EVENT_TIMER_BASED_LOOP: 73 #self.eventTimer = QtCore.QTimer() 74 #QtCore.QObject.connect(self.eventTimer, \ 75 #QtCore.SIGNAL("timeout()"), \ 76 #self.processEvent) 77 #self.eventTimer.start(EVENT_TIMER_FREQUENCY) 78 79 80 ################################################################## 81 82 def processEvent(self): 83 84 print "yoda" 85 86 emotiv_protocol.start(host=self.server_host, port=self.server_port, initialized=True, parent=self) 87 88 print "brah" 89 90 91 ################################################################## 92 93 def configureNetwork(self): 94 95 print "here" 96 97 emotiv_protocol.start(host=self.server_host, \ 98 port=self.server_port, \ 99 initialized=False, \ 100 parent=self) 101 102 print "there" 103 104 105 ################################################################## 106 107 def processPacketEmotiv(self, packet): 108 109 # Pass GUI updating to Interface application or parent object 110 if (self.parent != None): 111 self.parent.processPacketEmotiv(packet) 112 113 114 #print "yoda" 115 116 #emotiv_protocol.start(host=self.server_host, port=self.server_port, initialized=True, parent=self) 117 118 #print "brah" 119 120 121 ################################################################## 122 123 #def run(self): 124 def start(self): 125 126 if self.DEBUG: 127 print "<---- [%s] Main thread running" % self.name 74 128 75 129 self.configureNetwork() 76 77 78 ################################################################## 79 80 def configureNetwork(self): 81 82 ##self.blockSize = 0 83 #self.socket = QtNetwork.QTcpSocket() 84 #self.socket.name = 'ThinkGear Client' 85 86 #if self.server_host == '*': 87 #self.server_host = '127.0.0.1' 88 89 #self.server_host=QtNetwork.QHostAddress(self.server_host) 90 91 #self.socket.readyRead.connect(self.printReply) 92 #self.socket.error.connect(self.displayError) 93 94 ## Perform ThinkGear authorization if enabled 95 #if ENABLE_THINKGEAR_AUTHORIZATION: 96 #self.sendCommand(AUTHORIZATION_REQUEST) 97 #self.socket.waitForReadyRead() 98 #self.socket.disconnectFromHost() 99 100 #self.sendCommand(THINKGEAR_CONFIGURATION_PARAMETERS) 101 102 103 ################################################################## 104 105 def printReply(self): 106 107 socket_buffer = self.socket.readAll() 108 109 for packet in socket_buffer.split(DELIMITER): 130 131 #self.exec_() 132 133 134 ################################################################## 135 136 def stop(self): 137 138 #try: 139 #self.disconnectFromHost() 140 #except: 141 #pass 142 143 emotiv_protocol.KEEP_RUNNING = False 144 145 pass 146 147 148 ################################################################## 149 150 def exitThread(self, callThreadQuit=True): 151 152 self.stop() 153 154 #if callThreadQuit: 155 #QtCore.QThread.quit(self) 156 157 158 ##################################################################### 159 # Command line class 160 ##################################################################### 161 162 #class CLIClient(QtClient): 163 164 #def __init__(self, log, \ 165 #command_parameters, \ 166 #server_host=SERVER_HOST, \ 167 #server_port=SERVER_PORT, \ 168 #DEBUG=DEBUG): 169 170 #self.log = log 171 #self.DEBUG = DEBUG 172 #self.parent = None 173 174 #self.command_parameters = command_parameters 175 #self.server_host = server_host 176 #self.server_port = server_port 177 178 #self.configureNetwork() 179 180 #self.execute_command_line() 181 182 183 ################################################################### 184 185 #def execute_command_line(self): 186 187 #(command) = self.parse_command_line(self.command_parameters) 188 189 #if (command != None): 190 191 #self.sendCommand(command) 110 192 111 if packet != '': 112 113 try: 114 115 data = json.loads(packet.data()) 116 117 118 except Exception, e: 119 120 if self.DEBUG: 121 print "ERROR [%s]: Exception parsing packet:" % self.socket.name, 122 print packet.data() 123 print "ERROR [%s]: Data packet" % self.socket.name, 124 print e 125 126 continue 127 128 129 else: 130 131 if self.DEBUG > 1: 132 print "--> [%s] Received:" % self.socket.name, 133 print data 134 135 self.processPacketThinkGear(data) 136 137 138 ################################################################## 139 140 def displayError(self, socketError): 141 142 if self.DEBUG: 143 if ((socketError != QtNetwork.QAbstractSocket.RemoteHostClosedError) and \ 144 (socketError != QtNetwork.QAbstractSocket.SocketTimeoutError)): 145 print "ERROR [%s]:" % self.socket.name, 146 print self.socket.errorString() 147 148 149 if (self.parent != None): 150 151 if ((socketError == QtNetwork.QAbstractSocket.RemoteHostClosedError) or \ 152 (socketError != QtNetwork.QAbstractSocket.SocketTimeoutError)): 153 pass 154 155 elif socketError == QtNetwork.QAbstractSocket.HostNotFoundError: 156 try: 157 QtGui.QMessageBox.information(self.parent, \ 158 self.socket.name, \ 159 "The server host was not found. Please check the host name and " 160 "port settings.") 161 except: 162 pass 163 164 if self.DEBUG: 165 print "The server host was not found. ", 166 print "Please check the host name and ", 167 print "port settings." 168 169 170 elif socketError == QtNetwork.QAbstractSocket.ConnectionRefusedError: 171 try: 172 QtGui.QMessageBox.information(self.parent, \ 173 self.socket.name, 174 "The server connection was refused by the peer. Make sure the " 175 "server is running, and check that the host name " 176 "and port settings are correct.") 177 except: 178 pass 179 180 if self.DEBUG: 181 print "The server connection was refused by the peer. ", 182 print "Make sure the ", 183 print "server is running, and check that the host name ", 184 print "and port settings are correct." 185 186 187 else: 188 ## try: 189 ## QtGui.QMessageBox.information(self.parent, \ 190 ## self.socket.name, \ 191 ## "The following error occurred: %s." % \ 192 ## self.socket.errorString()) 193 ## except: 194 ## pass 195 196 if self.DEBUG: 197 print "The following error occurred: %s." % \ 198 self.socket.errorString() 199 200 201 ################################################################## 202 203 def sendCommand(self, command): 204 205 if self.DEBUG: 206 print "<-- [%s] Sending:" % self.socket.name, 207 print command 208 209 self.socket.abort() 210 self.socket.connectToHost(self.server_host, self.server_port) 211 212 data = json.dumps(command) 213 214 self.socket.waitForConnected(CLIENT_NO_REPLY_WAIT) 215 216 self.socket.write(data) 217 218 try: 219 self.socket.waitForBytesWritten(CLIENT_NO_REPLY_WAIT) 220 except Exception, e: 221 print "ERROR [%s]: Exception:" % self.socket.name, 222 print e 223 224 225 ################################################################## 226 227 def processPacketEmotiv(self, packet): 228 229 if ('isAuthorized' in packet.keys()): 230 self.isAuthorized = packet['isAuthorized'] 231 232 # Pass GUI updating to Client Interface application 233 if (self.parent != None): 234 self.parent.processPacketThinkGear(packet) 235 236 237 ################################################################## 238 239 def disconnectFromHost(self): 240 241 self.socket.disconnectFromHost() 242 243 244 ################################################################## 245 246 def run(self): 247 248 if self.DEBUG: 249 print "<---- [%s] Main thread running" % self.socket.name 250 251 self.exec_() 252 253 254 ################################################################## 255 256 def stop(self): 257 258 try: 259 self.disconnectFromHost() 260 except: 261 pass 262 263 264 ################################################################## 265 266 def exitThread(self, callThreadQuit=True): 267 268 self.stop() 269 270 if callThreadQuit: 271 QtCore.QThread.quit(self) 272 273 274 ##################################################################### 275 # Command line class 276 ##################################################################### 277 278 class CLIClient(QtClient): 279 280 def __init__(self, log, \ 281 command_parameters, \ 282 server_host=SERVER_HOST, \ 283 server_port=SERVER_PORT, \ 284 DEBUG=DEBUG): 285 286 self.log = log 287 self.DEBUG = DEBUG 288 self.parent = None 289 290 self.command_parameters = command_parameters 291 self.server_host = server_host 292 self.server_port = server_port 293 294 self.configureNetwork() 295 296 self.execute_command_line() 297 298 299 ################################################################## 300 301 def execute_command_line(self): 302 303 (command) = self.parse_command_line(self.command_parameters) 304 305 if (command != None): 306 307 self.sendCommand(command) 308 309 self.socket.waitForReadyRead(CLIENT_NO_REPLY_WAIT) 310 311 312 ################################################################## 313 314 def parse_command_line(self, command_parameters): 315 316 command = None 317 318 for each in command_parameters: 319 if each.startswith("--command="): 320 command = each[ len("--command="): ] 321 322 323 return(command) 324 193 #self.socket.waitForReadyRead(CLIENT_NO_REPLY_WAIT) 194 195 196 ################################################################### 197 198 #def parse_command_line(self, command_parameters): 199 200 #command = None 201 202 #for each in command_parameters: 203 #if each.startswith("--command="): 204 #command = each[ len("--command="): ] 205 206 207 #return(command) 208 -
trunk/Puzzlebox/Synapse/Interface.py
r332 r352 6 6 # For more information please refer to http://www.gnu.org/copyleft/gpl.html 7 7 8 # Old Class Names:9 # puzzlebox_synapse_interface = QtUI10 11 8 __changelog__ = """\ 12 Last Update: 2012.03.2 19 Last Update: 2012.03.29 13 10 """ 14 11 … … 70 67 from Interface_Design import Ui_Form as Design 71 68 69 #try: 70 #import Emotiv.Protocol as emotiv_protocol 71 #except: 72 #emotiv_protocol = None 73 72 74 #import Configuration as configuration 73 75 import Server as synapse_server 74 76 import Client as thinkgear_client 77 import Puzzlebox.Synapse.Emotiv.Client as emotiv_client 75 78 #import puzzlebox_logger 76 79 … … 381 384 elif (eeg_headset_model == 'Emotiv EPOC'): 382 385 383 import Emotiv.Protocol 384 385 self.emotiv_protocol = \ 386 Emotiv.Protocol.ProtocolHandler( \ 387 log=self.log, \ 388 serial_device=device_address, \ 389 device_model=eeg_headset_model, \ 390 parent=self) 391 392 self.emotiv_protocol.start() 386 self.startEmotivServer() 387 388 389 ################################################################## 390 391 def processPacketEmotiv(self, packet): 392 393 print 394 print "Booyah" 395 print 396 print packet 397 print 398 print 399 400 401 ################################################################## 402 403 def startEmotivServer(self): 404 405 eeg_headset_model = str(self.comboBoxEEGHeadsetModel.currentText()) 406 device_address = str(self.comboBoxDeviceSelect.currentText()) 407 408 409 self.emotivClient = \ 410 emotiv_client.puzzlebox_synapse_client_emotiv( \ 411 log=self.log, \ 412 #server_host=device_address, \ 413 DEBUG=DEBUG, \ 414 parent=self) 415 416 self.emotivClient.start() 417 418 #if emotiv_protocol != None: 419 420 #self.emotiv_protocol = \ 421 #emotiv_protocol.ProtocolHandler( \ 422 #log=self.log, \ 423 #serial_device=device_address, \ 424 #device_model=eeg_headset_model, \ 425 #parent=self) 426 427 #self.emotiv_protocol.start() 428 429 430 #self.progressBarEEGDelta.setValue(0) 431 #self.progressBarEEGTheta.setValue(0) 432 #self.progressBarEEGLowAlpha.setValue(0) 433 #self.progressBarEEGHighAlpha.setValue(0) 434 #self.progressBarEEGLowBeta.setValue(0) 435 #self.progressBarEEGHighBeta.setValue(0) 436 #self.progressBarEEGLowGamma.setValue(0) 437 #self.progressBarEEGMidGamma.setValue(0) 438 439 #self.progressBarAttention.setValue(0) 440 #self.progressBarMeditation.setValue(0) 441 442 443 #self.progressBarEEGDelta.setEnabled(False) 444 #self.progressBarEEGTheta.setEnabled(False) 445 #self.progressBarEEGLowAlpha.setEnabled(False) 446 #self.progressBarEEGHighAlpha.setEnabled(False) 447 #self.progressBarEEGLowBeta.setEnabled(False) 448 #self.progressBarEEGHighBeta.setEnabled(False) 449 #self.progressBarEEGLowGamma.setEnabled(False) 450 #self.progressBarEEGMidGamma.setEnabled(False) 451 452 #self.progressBarAttention.setEnabled(False) 453 #self.progressBarMeditation.setEnabled(False) 393 454 394 455
Note: See TracChangeset
for help on using the changeset viewer.