Changeset 363
- Timestamp:
- 03/30/12 18:18:18 (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Puzzlebox/Synapse/Emotiv/Client.py
r357 r363 7 7 8 8 __changelog__ = """\ 9 Last Update: 2012.03. 299 Last Update: 2012.03.30 10 10 """ 11 11 … … 22 22 configuration.ENABLE_PYSIDE = False 23 23 else: 24 print "INFO: [Synapse: Client] Using PySide module"24 print "INFO: [Synapse:Emotiv:Client] Using PySide module" 25 25 26 26 if not configuration.ENABLE_PYSIDE: 27 print "INFO: [Synapse: Client] Using PyQt4 module"27 print "INFO: [Synapse:Emotiv:Client] Using PyQt4 module" 28 28 from PyQt4 import QtCore, QtGui, QtNetwork 29 29 … … 65 65 self.server_port = server_port 66 66 67 self.name = " EmotivClient"67 self.name = "Synapse:Emotiv:Client" 68 68 69 69 #self.configureNetwork() -
trunk/Puzzlebox/Synapse/Interface.py
r362 r363 268 268 self.updateDevices) 269 269 270 #self.connect(self.pushButtonBluetoothConnect, \271 #QtCore.SIGNAL("clicked()"), \272 #self.connectToThinkGearDevice)273 274 270 self.connect(self.pushButtonSynapseServer, \ 275 271 QtCore.SIGNAL("clicked()"), \ … … 311 307 device_model=eeg_headset_model, \ 312 308 device_address=device_address, \ 313 #device_model=None, \314 309 emulate_headset_data=emulate_headset_data, \ 315 310 DEBUG=DEBUG, \ 316 311 parent=self) 317 318 #self.connect(self.synapseServer, \319 #QtCore.SIGNAL("sendPacket()"), \320 #self.synapseServer.sendPacketQueue)321 312 322 313 self.synapseServer.start() … … 409 400 410 401 self.pushButtonBluetoothSearch.setEnabled(True) 411 #self.pushButtonBluetoothConnect.setEnabled(True)412 402 413 403 self.pushButtonSynapseServer.setChecked(False) … … 416 406 417 407 self.pushButtonBluetoothSearch.setEnabled(True) 418 419 #self.pushButtonBluetoothConnect.setText('Connect')420 #self.pushButtonBluetoothConnect.setChecked(False)421 408 422 409 self.comboBoxDeviceSelect.setEnabled(True) … … 457 444 def startThinkGearConnectClient(self): 458 445 459 # Ensure EEG device is connected first460 461 #if not self.pushButtonBluetoothConnect.isChecked():462 #self.connectToThinkGearDevice()463 #device_selection = self.comboBoxDeviceSelect.currentText()464 #self.textLabelBluetoothStatus.setText("Status: Connected")465 #self.pushButtonBluetoothSearch.setEnabled(False)466 #self.comboBoxDeviceSelect.setEnabled(False)467 #self.comboBoxEEGHeadsetModel.setEnabled(False)468 469 470 #self.pushButtonBluetoothSearch.setEnabled(False)471 #self.pushButtonBluetoothConnect.setEnabled(False)472 473 446 server_interface = str(self.lineEditSynapseHost.text()) 474 447 server_port = int(self.lineEditSynapsePort.text()) 475 #device_address = str(self.comboBoxDeviceSelect.currentText())476 #emulate_headset_data = (device_address == 'ThinkGear Emulator')477 478 479 #self.synapseServer = \480 #synapse_server.ThinkgearServer( \481 #self.log, \482 #server_interface=server_interface, \483 #server_port=server_port, \484 #device_address=device_address, \485 #device_model=None, \486 #emulate_headset_data=emulate_headset_data, \487 #DEBUG=DEBUG, \488 #parent=self)489 490 ##self.connect(self.synapseServer, \491 ##QtCore.SIGNAL("sendPacket()"), \492 ##self.synapseServer.sendPacketQueue)493 494 #self.synapseServer.start()495 496 448 497 449 if UPDATE_INTERFACE_VIA_TIMER: … … 508 460 509 461 self.thinkgearConnectClient.start() 510 511 512 #self.disconnect(self.pushButtonSynapseServer, \513 #QtCore.SIGNAL("clicked()"), \514 #self.startThinkGearConnectClient)515 516 #self.connect(self.pushButtonSynapseServer, \517 #QtCore.SIGNAL("clicked()"), \518 #self.stopThinkGearConnectClient)519 520 #self.lineEditSynapseHost.setEnabled(False)521 #self.lineEditSynapsePort.setEnabled(False)522 523 #self.pushButtonSynapseServer.setText('Stop')524 462 525 463 … … 537 475 print "Call failed to self.thinkgearConnectClient.disconnectFromHost():", 538 476 print e 539 540 #try:541 #self.synapseServer.exitThread()542 #except Exception, e:543 #if self.DEBUG:544 #print "Call failed to self.synapseServer.exitThread():",545 #print e546 547 #self.disconnect(self.pushButtonSynapseServer, \548 #QtCore.SIGNAL("clicked()"), \549 #self.stopSynapseServer)550 551 #self.connect(self.pushButtonSynapseServer, \552 #QtCore.SIGNAL("clicked()"), \553 #self.startSynapseServer)554 555 #self.lineEditSynapseHost.setEnabled(True)556 #self.lineEditSynapsePort.setEnabled(True)557 558 #self.pushButtonSynapseServer.setText('Start')559 560 ##self.pushButtonBluetoothSearch.setEnabled(True)561 ##self.pushButtonBluetoothConnect.setEnabled(True)562 563 #self.pushButtonSynapseServer.setChecked(False)564 565 566 ##################################################################567 568 #def connectToThinkGearDevice(self):569 570 #device_selection = self.comboBoxDeviceSelect.currentText()571 572 ##self.disconnect(self.pushButtonBluetoothConnect, \573 ##QtCore.SIGNAL("clicked()"), \574 ##self.connectToThinkGearDevice)575 576 ##self.connect(self.pushButtonBluetoothConnect, \577 ##QtCore.SIGNAL("clicked()"), \578 ##self.disconnectFromThinkGearDevice)579 580 #self.textLabelBluetoothStatus.setText("Status: Connected")581 582 #self.pushButtonBluetoothSearch.setEnabled(False)583 584 ##self.pushButtonBluetoothConnect.setText('Disconnect')585 ##self.pushButtonBluetoothConnect.setChecked(True)586 587 #self.comboBoxDeviceSelect.setEnabled(False)588 #self.comboBoxEEGHeadsetModel.setEnabled(False)589 590 591 ##################################################################592 593 #def disconnectFromThinkGearDevice(self):594 595 ##self.disconnect(self.pushButtonBluetoothConnect, \596 ##QtCore.SIGNAL("clicked()"), \597 ##self.disconnectFromThinkGearDevice)598 599 ##self.connect(self.pushButtonBluetoothConnect, \600 ##QtCore.SIGNAL("clicked()"), \601 ##self.connectToThinkGearDevice)602 603 #self.textLabelBluetoothStatus.setText("Status: Disconnected")604 605 #self.pushButtonBluetoothSearch.setEnabled(True)606 607 ##self.pushButtonBluetoothConnect.setText('Connect')608 ##self.pushButtonBluetoothConnect.setChecked(False)609 610 #self.comboBoxDeviceSelect.setEnabled(True)611 #self.comboBoxEEGHeadsetModel.setEnabled(True)612 613 614 #self.progressBarEEGDelta.setValue(0)615 #self.progressBarEEGTheta.setValue(0)616 #self.progressBarEEGLowAlpha.setValue(0)617 #self.progressBarEEGHighAlpha.setValue(0)618 #self.progressBarEEGLowBeta.setValue(0)619 #self.progressBarEEGHighBeta.setValue(0)620 #self.progressBarEEGLowGamma.setValue(0)621 #self.progressBarEEGMidGamma.setValue(0)622 623 #self.progressBarAttention.setValue(0)624 #self.progressBarMeditation.setValue(0)625 626 #self.progressBarSignalContactQuality.setValue(0)627 628 #self.maxEEGPower = THINKGEAR_EMULATION_MAX_EEG_POWER_VALUE629 630 ## In case the user connects to a MindSet, then disconnects631 ## and re-connects to a MindSet Emulator,632 ## we need to reset the max power values633 #self.progressBarEEGDelta.setMaximum(self.maxEEGPower)634 #self.progressBarEEGTheta.setMaximum(self.maxEEGPower)635 #self.progressBarEEGLowAlpha.setMaximum(self.maxEEGPower)636 #self.progressBarEEGHighAlpha.setMaximum(self.maxEEGPower)637 #self.progressBarEEGLowBeta.setMaximum(self.maxEEGPower)638 #self.progressBarEEGHighBeta.setMaximum(self.maxEEGPower)639 #self.progressBarEEGLowGamma.setMaximum(self.maxEEGPower)640 #self.progressBarEEGMidGamma.setMaximum(self.maxEEGPower)641 477 642 478 … … 677 513 self.progressBarAttention.setEnabled(False) 678 514 self.progressBarMeditation.setEnabled(False) 679 680 515 516 681 517 ################################################################## 682 518 … … 842 678 print "INFO [Synapse:Interface] Emotiv packet received:" 843 679 print packet 680 681 self.synapseServer.packet_queue.append(packet) 844 682 845 683 … … 887 725 888 726 session_time = time.time() - \ 889 server.protocol.session_start_timestamp 727 server.session_start_timestamp 728 #server.protocol.session_start_timestamp 890 729 891 730 session_time = int(session_time) -
trunk/Puzzlebox/Synapse/Server.py
r362 r363 13 13 14 14 import os, sys, time 15 #import signal16 #import math17 15 18 16 import simplejson as json … … 37 35 import Puzzlebox.Synapse.ThinkGear.Server as thinkgear_server 38 36 39 #import Protocol as thinkgear_protocol40 37 41 38 ##################################################################### … … 65 62 ENABLE_SIMULATE_HEADSET_DATA = configuration.THINKGEAR_ENABLE_SIMULATE_HEADSET_DATA 66 63 67 #BLINK_FREQUENCY_TIMER = configuration.THINKGEAR_BLINK_FREQUENCY_TIMER68 69 #DEFAULT_SAMPLE_WAVELENGTH = configuration.THINKGEAR_DEFAULT_SAMPLE_WAVELENGTH70 71 #THINKGEAR_EMULATION_MAX_ESENSE_VALUE = \72 #configuration.THINKGEAR_EMULATION_MAX_ESENSE_VALUE73 #THINKGEAR_EMULATION_MAX_EEG_POWER_VALUE = \74 #configuration.THINKGEAR_EMULATION_MAX_EEG_POWER_VALUE75 76 #THINKGEAR_ATTENTION_MULTIPLIER = configuration.THINKGEAR_ATTENTION_MULTIPLIER77 #THINKGEAR_MEDITATION_MULTIPLIER = configuration.THINKGEAR_MEDITATION_MULTIPLIER78 79 #THINKGEAR_EEG_POWER_MULTIPLIERS = configuration.THINKGEAR_EEG_POWER_MULTIPLIERS80 81 #DEFAULT_AUTHORIZATION_MESSAGE = \82 #{"isAuthorized": True}83 ## Tells the client whether the server has authorized84 ## access to the user's headset data. The value is85 ## either true or false.86 87 #DEFAULT_SIGNAL_LEVEL_MESSAGE = \88 #{"poorSignalLevel": 0}89 ## A quantifier of the quality of the brainwave signal.90 ## This is an integer value that is generally in the91 ## range of 0 to 200, with 0 indicating a92 ## good signal and 200 indicating an off-head state.93 94 #DEFAULT_EEG_POWER_MESSAGE = \95 #{"eegPower": { \96 #'delta': 0, \97 #'theta': 0, \98 #'lowAlpha': 0, \99 #'highAlpha': 0, \100 #'lowBeta': 0, \101 #'highBeta': 0, \102 #'lowGamma': 0, \103 #'highGamma': 0, \104 #}, \105 #} # A container for the EEG powers. These may106 ## be either integer or floating-point values.107 ## Maximum values are undocumented but assumed to be 65535108 109 #DEFAULT_ESENSE_MESSAGE = \110 #{"eSense": { \111 #'attention': 0, \112 #'meditation': 0, \113 #}, \114 #} # A container for the eSense⢠attributes.115 ## These are integer values between 0 and 100,116 ## where 0 is perceived as a lack of that attribute117 ## and 100 is an excess of that attribute.118 119 #DEFAULT_BLINK_MESSAGE = {"blinkStrength": 255}120 ## The strength of a detected blink. This is121 ## an integer in the range of 0-255.122 123 #DEFAULT_RAWEEG_MESSAGE = {"rawEeg": 255}124 ## The raw data reading off the forehead sensor.125 ## This may be either an integer or a floating-point value.126 127 64 DEFAULT_PACKET = {} 128 #DEFAULT_PACKET.update(DEFAULT_EEG_POWER_MESSAGE)129 #DEFAULT_PACKET.update(DEFAULT_SIGNAL_LEVEL_MESSAGE)130 #DEFAULT_PACKET.update(DEFAULT_ESENSE_MESSAGE)131 132 #DEFAULT_RESPONSE_MESSAGE = DEFAULT_SIGNAL_LEVEL_MESSAGE133 65 DEFAULT_RESPONSE_MESSAGE = DEFAULT_PACKET 134 66 … … 157 89 self.server_port = server_port 158 90 self.device_address = device_address 159 #self.device_id = device_id160 91 self.device_model = device_model 161 92 self.emulate_headset_data = emulate_headset_data 162 93 163 #self.message_frequency_timer = MESSAGE_FREQUENCY_TIMER164 #self.blink_frequency_timer = BLINK_FREQUENCY_TIMER165 166 94 self.connection_timestamp = time.time() 167 #self.blink_timestamp = time.time()95 self.session_start_timestamp = time.time() 168 96 169 97 self.connections = [] 170 98 self.packet_queue = [] 171 172 #self.serial_device = None173 #self.protocol = None174 99 175 100 self.connect(self, \ … … 182 107 183 108 self.configureNetwork() 184 185 186 #if (self.emulate_headset_data):187 #self.emulationTimer = QtCore.QTimer()188 #QtCore.QObject.connect(self.emulationTimer, \189 #QtCore.SIGNAL("timeout()"), \190 #self.emulationEvent)191 #self.emulationTimer.start(MESSAGE_FREQUENCY_TIMER)192 109 193 110 … … 195 112 196 113 def configureEEG(self): 197 198 print self.device_model199 114 200 115 if (self.device_model == 'NeuroSky MindWave' or \ … … 204 119 thinkgear_server.puzzlebox_synapse_server_thinkgear( \ 205 120 self.log, \ 206 #server_interface=server_interface, \207 #server_port=server_port, \208 121 device_model=self.device_model, \ 209 122 device_address=self.device_address, \ 210 #device_model=None, \211 123 emulate_headset_data=self.emulate_headset_data, \ 212 124 DEBUG=DEBUG, \ … … 220 132 221 133 self.protocolServers.append(self.thinkgearServer) 222 223 224 ##################################################################225 226 #def emulationEvent(self):227 228 #self.updateStatus()229 230 #if COMMUNICATION_MODE == 'Emit Signal':231 #self.emitSendPacketSignal()232 #else:233 #self.sendPacketQueue()234 134 235 135 … … 272 172 print self.socket.errorString() 273 173 274 #self.parent.stopThinkGearConnectServer()275 #self.parent.pushButtonThinkGearConnect.nextCheckState()276 #self.parent.pushButtonThinkGearConnect.toggle()277 #self.parent.pushButtonThinkGearConnect.test.emit(QtCore.SIGNAL("clicked()"))278 279 174 self.socket.close() 280 175 return … … 419 314 def sendPacketQueue(self): 420 315 421 print "send"422 423 #if self.DEBUG:424 #print "sendPacketQueue called"425 426 316 if self.connections != []: 427 317 … … 470 360 ################################################################## 471 361 472 #def validateChecksum(self, checksum): 473 474 #'''The key used by the client application to identify 475 #itself. This must be 40 hexadecimal characters, ideally generated 476 #using an SHA-1 digest. The appKey is an identifier that is unique 477 #to each application, rather than each instance of an application. 478 #It is used by the server to bypass the authorization process if a 479 #user had previously authorized the requesting client. To reduce 480 #the chance of overlap with the appKey of other applications, 481 #the appKey should be generated using an SHA-1 digest.''' 482 483 #is_valid = True 484 485 #hexadecimal_characters = '0123456789abcdef' 486 487 #if len(checksum) != 40: 488 #is_valid = False 489 #else: 490 #for character in checksum: 491 #if character not in hexadecimal_characters: 492 #is_valid = False 493 494 #return(is_valid) 495 496 497 ################################################################## 498 499 #def authorizeClient(self, data): 500 501 #'''The client must initiate an authorization request 502 #and the server must authorize the client before the 503 #server will start transmitting any headset data.''' 504 505 #is_authorized = self.validateChecksum(data['appKey']) 506 507 ## A human-readable name identifying the client 508 ## application. This can be a maximum of 255 characters. 509 510 #if len(data['appName']) > 255: 511 #is_authorized = False 512 513 514 #return(is_authorized) 515 516 517 ################################################################## 518 519 #def calculateWavePoint(self, x, max_height=100, wave_length=10): 520 521 ## start at 0, increase to max value at half of one 522 ## wavelength, decrease to 0 by end of wavelength 523 #y = ( (max_height/2) * \ 524 #math.sin ((x-1) * ( math.pi / (wave_length / 2)))) + \ 525 #(max_height/2) 526 527 ## start at max value, decrease to 0 at half of one 528 ## wavelegnth, increase to max by end of wavelength 529 ##y = ( (max_height/2) * \ 530 ##math.cos (x * ( math.pi / (wave_length / 2)))) + \ 531 ##(max_height/2) 532 533 534 #return(y) 535 536 537 ################################################################## 538 539 #def simulateHeadsetData(self): 540 541 #response = DEFAULT_PACKET 542 543 #response['timestamp'] = time.time() 544 545 #time_value = self.connection_timestamp - time.time() 546 547 #for key in response.keys(): 548 549 #if key == 'poorSignalLevel': 550 #pass 551 552 #elif key == 'eSense': 553 #plot = self.calculateWavePoint( \ 554 #time_value, \ 555 #max_height=100, \ 556 #wave_length=DEFAULT_SAMPLE_WAVELENGTH) 557 558 #for each in response[key].keys(): 559 560 #if ((each == 'attention') and \ 561 #(THINKGEAR_ATTENTION_MULTIPLIER != None)): 562 #value = plot * \ 563 #THINKGEAR_ATTENTION_MULTIPLIER 564 565 #elif ((each == 'meditation') and \ 566 #(THINKGEAR_MEDITATION_MULTIPLIER != None)): 567 #value = plot * \ 568 #THINKGEAR_MEDITATION_MULTIPLIER 569 570 571 #value = int(value) 572 573 574 #if value < 0: 575 #value = 0 576 #elif value > 100: 577 #value = 100 578 579 #response[key][each] = value 580 581 582 #elif key == 'eegPower': 583 #plot = self.calculateWavePoint( \ 584 #time_value, \ 585 #max_height=65535, \ 586 #wave_length=DEFAULT_SAMPLE_WAVELENGTH) 587 588 #for each in response[key].keys(): 589 #if ((THINKGEAR_EEG_POWER_MULTIPLIERS != None) and \ 590 #(each in THINKGEAR_EEG_POWER_MULTIPLIERS.keys())): 591 #value = THINKGEAR_EEG_POWER_MULTIPLIERS[each] * plot 592 #else: 593 #value = plot 594 #response[key][each] = value 595 596 597 #return(response) 598 599 600 ################################################################## 601 602 def processPacketThinkGear(self, packet): 362 def processPacketEmotiv(self, packet): 603 363 604 364 if self.DEBUG > 2: … … 615 375 616 376 if (self.parent != None): 617 #self.parent.processPacketThinkGear(self.protocol.data_packet)618 self.parent.processPacketThinkGear(packet)619 620 621 ##################################################################622 623 def processPacketEmotiv(self, packet):624 625 if self.DEBUG > 2:626 print packet627 628 if (packet != {}):629 self.packet_queue.append(packet)630 631 if COMMUNICATION_MODE == 'Emit Signal':632 self.emitSendPacketSignal()633 634 else:635 self.sendPacketQueue()636 637 if (self.parent != None):638 377 self.parent.processPacketEmotiv(packet) 639 378 … … 641 380 ################################################################## 642 381 643 #def updateStatus(self): 644 645 ## Craft a simulated data packet 646 #packet = self.simulateHeadsetData() 647 648 #self.packet_queue.append(packet) 649 650 ##if (self.parent != None): 651 ##self.parent.processPacketThinkGear(packet) 652 653 ## Include simulated blinks at desired frequency 654 #if ((self.blink_frequency_timer != None) and \ 655 #(self.blink_frequency_timer > 0) and \ 656 #(time.time() - self.blink_timestamp > \ 657 #self.blink_frequency_timer)): 658 659 #self.blink_timestamp = time.time() 660 661 #packet = DEFAULT_BLINK_MESSAGE 662 663 #packet['timestamp'] = self.blink_timestamp 664 665 #self.packet_queue.append(packet) 382 def updateSessionStartTime(self, session_start_timestamp): 383 384 self.session_start_timestamp = session_start_timestamp 666 385 667 386 … … 680 399 def exitThread(self, callThreadQuit=True): 681 400 682 #if (self.emulate_headset_data):683 #try:684 #self.emulationTimer.stop()685 #except Exception, e:686 #if self.DEBUG:687 #print "ERROR: Exception when stopping emulation timer:",688 #print e689 690 401 691 402 for server in self.protocolServers: … … 706 417 707 418 self.exitThread() 708 709 710 ################################################################## 711 712 #def resetDevice(self): 713 714 #if self.serial_device != None: 715 #self.serial_device.exitThread() 716 717 #if self.protocol != None: 718 #self.protocol.exitThread() 719 720 #self.configureEEG() 721 419 -
trunk/Puzzlebox/Synapse/ThinkGear/Protocol.py
r362 r363 189 189 self.packet_count = 0 190 190 self.bad_packets = 0 191 self.session_start_time = None191 self.session_start_timestamp = time.time() 192 192 193 193 self.keep_running = True … … 540 540 if self.DEBUG: 541 541 print "INFO: ThinkGear Headset Connect Success" 542 self.session_start_timestamp = time.time() 542 #self.session_start_timestamp = time.time() 543 self.resetSessionStartTime() 543 544 self.packet_count = 0 544 545 self.bad_packets = 0 … … 851 852 ################################################################## 852 853 854 def resetSessionStartTime(self): 855 856 self.session_start_timestamp = time.time() 857 858 if (self.parent != None): 859 860 self.parent.updateSessionStartTime(self.session_start_timestamp) 861 862 863 ################################################################## 864 853 865 def run(self): 854 866 855 867 self.packet_count = 0 856 868 self.bad_packets = 0 857 self.session_start_timestamp = time.time() 869 #self.session_start_timestamp = time.time() 870 self.resetSessionStartTime() 858 871 859 872 if self.device != None and self.device.device != None: -
trunk/Puzzlebox/Synapse/ThinkGear/Server.py
r362 r363 36 36 37 37 38 #try:39 #import PySide as PyQt440 #from PySide import QtCore, QtGui, QtNetwork41 #except:42 #print "Using PyQt4 module"43 #from PyQt4 import QtCore, QtGui, QtNetwork44 #else:45 #print "Using PySide module"46 47 ##from PyQt4 import QtNetwork48 49 #import Configuration as configuration50 38 import Puzzlebox.Synapse.ThinkGear.Protocol as thinkgear_protocol 51 39 52 ### GLOBALS ### 40 ##################################################################### 41 # Globals 42 ##################################################################### 53 43 54 44 DEBUG = configuration.DEBUG … … 57 47 #COMMUNICATION_MODE = 'Call Parent' 58 48 59 #SERVER_INTERFACE = configuration.THINKGEAR_SERVER_INTERFACE60 #SERVER_PORT = configuration.THINKGEAR_SERVER_PORT61 49 THINKGEAR_DEVICE_SERIAL_PORT = configuration.THINKGEAR_DEVICE_SERIAL_PORT 62 50 #THINKGEAR_DEVICE_ID = configuration.THINKGEAR_DEVICE_ID … … 140 128 DEFAULT_RESPONSE_MESSAGE = DEFAULT_SIGNAL_LEVEL_MESSAGE 141 129 142 ### CLASS MODULE ### 130 ##################################################################### 131 # Classes 132 ##################################################################### 143 133 144 134 class puzzlebox_synapse_server_thinkgear(QtCore.QThread): 145 135 146 136 def __init__(self, log, \ 147 #server_interface=SERVER_INTERFACE, \148 #server_port=SERVER_PORT, \149 137 device_address=THINKGEAR_DEVICE_SERIAL_PORT, \ 150 138 #device_id=THINKGEAR_DEVICE_ID, \ … … 160 148 self.parent = parent 161 149 162 #self.server_interface = server_interface163 #self.server_port = server_port164 150 self.device_address = device_address 165 151 #self.device_id = device_id … … 186 172 187 173 self.configureEEG() 188 189 #self.configureNetwork()190 191 174 192 175 if (self.emulate_headset_data): … … 243 226 ################################################################## 244 227 245 #def configureNetwork(self):246 247 ##self.blockSize = 0248 #self.socket = QtNetwork.QTcpServer()249 #self.socket.name = 'ThinkGear Server'250 251 #if self.DEBUG:252 #print "<---- [%s] Initializing server on %s:%i" % \253 #(self.socket.name, self.server_interface, self.server_port)254 255 256 #if ((self.server_interface == '') or \257 #(self.server_interface == '*')):258 #address=QtNetwork.QHostAddress.Any259 #else:260 ##address=self.server_interface261 #address=QtNetwork.QHostAddress(self.server_interface)262 263 264 #result = self.socket.listen(address, self.server_port)265 266 267 #if not result:268 #try:269 #QtGui.QMessageBox.information( \270 #self.parent, \271 #self.socket.name, \272 #"Unable to start the server on %s:%i" % \273 #(self.server_interface, self.server_port))274 #except:275 #pass276 277 #if self.DEBUG:278 #print "ERROR [%s] Unable to start the server:" % self.socket.name,279 #print self.socket.errorString()280 281 ##self.parent.stopThinkGearConnectServer()282 ##self.parent.pushButtonThinkGearConnect.nextCheckState()283 ##self.parent.pushButtonThinkGearConnect.toggle()284 ##self.parent.pushButtonThinkGearConnect.test.emit(QtCore.SIGNAL("clicked()"))285 286 #self.socket.close()287 #return288 289 290 #self.socket.newConnection.connect(self.processConnection)291 ##self.socket.error.connect(self.displayError)292 293 294 ##################################################################295 296 #def deleteDisconnected(self):297 298 #connection_index = 0299 300 #for connection in self.connections:301 302 #try:303 304 #if ((connection.state() != QtNetwork.QAbstractSocket.ConnectingState) and \305 #(connection.state() != QtNetwork.QAbstractSocket.ConnectedState)):306 307 #if self.DEBUG:308 #print "- - [%s] Deleting disconnected socket" % self.socket.name309 310 #connection.deleteLater()311 ## Delete references to disconnected sockets312 #del (self.connections[connection_index])313 314 #except:315 ## Delete references to sockets throwing exceptions316 #del (self.connections[connection_index])317 318 #connection_index += 1319 320 321 ##################################################################322 323 #def processConnection(self):324 325 #clientConnection = self.socket.nextPendingConnection()326 #clientConnection.disconnected.connect(self.deleteDisconnected)327 328 #self.connections.append(clientConnection)329 330 #self.clientConnection = clientConnection331 332 ## the next connected client to enter the readyRead state333 ## will be processed first334 #clientConnection.readyRead.connect(self.processClientConnection)335 336 337 ##################################################################338 339 #def processClientConnection(self):340 341 #clientConnection = self.clientConnection342 343 #socket_buffer = clientConnection.readAll()344 345 #for packet in socket_buffer.split(DELIMITER):346 347 #data_to_process = None348 349 #if packet != '':350 351 #try:352 #data_to_process = json.loads(packet.data())353 354 #except Exception, e:355 356 ## Special socket handling for Flash applications357 #if (packet == FLASH_POLICY_FILE_REQUEST):358 359 #if self.DEBUG:360 #print "--> [%s] Flash policy file requested" % self.socket.name361 362 #data_to_process = packet.data()363 364 365 #else:366 367 #if self.DEBUG:368 #print "--> [ThinkGear Emulator] Partial data received (or error:",369 #print e370 #print ")."371 372 #print "packet data:",373 #print packet.data()374 375 376 #else:377 378 #if self.DEBUG:379 #print "--> [%s] Received:" % self.socket.name,380 #print data_to_process381 382 383 #if (data_to_process != None):384 385 #response = self.processData(data_to_process)386 387 #if (response != None):388 389 #self.sendResponse(clientConnection, response)390 391 392 ##################################################################393 394 #def sendResponse(self, connection, response, disconnect_after_sending=False):395 396 ## Special socket handling for Flash applications397 #if (response == FLASH_SOCKET_POLICY_FILE):398 #data = response399 #else:400 #data = json.dumps(response)401 #data = data + DELIMITER402 403 #if connection.waitForConnected(CLIENT_NO_REPLY_WAIT):404 405 #if self.DEBUG > 1:406 #print "<-- [%s] Sending:" % self.socket.name,407 #print data408 409 #connection.write(data)410 411 #connection.waitForBytesWritten(CLIENT_NO_REPLY_WAIT)412 413 #if disconnect_after_sending:414 #connection.disconnectFromHost()415 416 417 ##################################################################418 419 228 def emitSendPacketSignal(self): 420 229 … … 432 241 433 242 #self.parent.sendPacketQueue() 434 435 436 ##################################################################437 438 #def sendPacketQueue(self):439 440 ##if self.DEBUG:441 ##print "sendPacketQueue called"442 443 #if self.connections != []:444 445 #while (len(self.packet_queue) > 0):446 447 #packet = self.packet_queue[0]448 #del self.packet_queue[0]449 450 #for connection in self.connections:451 452 #if connection.state() == QtNetwork.QAbstractSocket.ConnectedState:453 454 #self.sendResponse(connection, packet)455 456 457 ##if COMMUNICATION_MODE != 'Emit Signal' and (self.parent != None):458 ##self.parent.processPacketThinkGear(self.protocol.data_packet)459 243 460 244 … … 667 451 ################################################################## 668 452 453 def updateSessionStartTime(self, session_start_timestamp): 454 455 if self.parent != None: 456 self.parent.updateSessionStartTime(session_start_timestamp) 457 458 459 ################################################################## 460 669 461 def run(self): 670 462 -
trunk/synapse-client.py
r358 r363 2 2 # -*- coding: utf-8 -*- 3 3 4 # Copyright Puzzlebox Productions, LLC (2010 )4 # Copyright Puzzlebox Productions, LLC (2010-2012) 5 5 # 6 6 # This code is released under the GNU Pulic License (GPL) version 2 -
trunk/synapse-protocol.py
r276 r363 2 2 # -*- coding: utf-8 -*- 3 3 4 # Copyright Puzzlebox Productions, LLC (2010 )4 # Copyright Puzzlebox Productions, LLC (2010-2012) 5 5 # 6 6 # This code is released under the GNU Pulic License (GPL) version 2 7 7 # For more information please refer to http://www.gnu.org/copyleft/gpl.html 8 8 9 import Puzzlebox.Synapse. Protocol as tgProtocol10 import Puzzlebox.Synapse.Configuration as tgConf9 import Puzzlebox.Synapse.ThinkGear.Protocol as thinkgear_protocol 10 import Puzzlebox.Synapse.Configuration as configuration 11 11 import signal, sys 12 12 … … 32 32 33 33 if device_address == None: 34 if tgConf.THINKGEAR_DEVICE_BLUETOOTH_ADDRESS == '':35 device_address = tgConf.THINKGEAR_DEVICE_SERIAL_PORT34 if configuration.THINKGEAR_DEVICE_BLUETOOTH_ADDRESS == '': 35 device_address = configuration.THINKGEAR_DEVICE_SERIAL_PORT 36 36 else: 37 device_address = tgConf.THINKGEAR_DEVICE_BLUETOOTH_ADDRESS37 device_address = configuration.THINKGEAR_DEVICE_BLUETOOTH_ADDRESS 38 38 39 39 app = QtCore.QCoreApplication(sys.argv) 40 serial_device = t gProtocol.SerialDevice(log, device_address, DEBUG=DEBUG)41 protocol = t gProtocol.ProtocolHandler(log, serial_device, DEBUG=DEBUG)40 serial_device = thinkgear_protocol.SerialDevice(log, device_address, DEBUG=DEBUG) 41 protocol = thinkgear_protocol.puzzlebox_synapse_protocol_thinkgear(log, serial_device, DEBUG=DEBUG) 42 42 protocol.start() 43 43 serial_device.run() -
trunk/synapse-server.py
r276 r363 2 2 # -*- coding: utf-8 -*- 3 3 4 # Copyright Puzzlebox Productions, LLC (2010-201 1)4 # Copyright Puzzlebox Productions, LLC (2010-2012) 5 5 # 6 6 # This code is released under the GNU Pulic License (GPL) version 2 7 7 # For more information please refer to http://www.gnu.org/copyleft/gpl.html 8 8 9 import Puzzlebox.Synapse.Server as tgServer10 import Puzzlebox.Synapse.Configuration as tgConf9 import Puzzlebox.Synapse.Server as synapse_server 10 import Puzzlebox.Synapse.Configuration as configuration 11 11 12 12 import sys, signal … … 27 27 log = None 28 28 29 server_interface = tgConf.THINKGEAR_SERVER_INTERFACE30 server_port = tgConf.THINKGEAR_SERVER_PORT31 device_address = tgConf.THINKGEAR_DEVICE_SERIAL_PORT32 device_id = tgConf.THINKGEAR_DEVICE_ID29 server_interface = configuration.THINKGEAR_SERVER_INTERFACE 30 server_port = configuration.THINKGEAR_SERVER_PORT 31 device_address = configuration.THINKGEAR_DEVICE_SERIAL_PORT 32 #device_id = configuration.THINKGEAR_DEVICE_ID 33 33 34 34 for each in sys.argv: … … 45 45 46 46 app = QtCore.QCoreApplication(sys.argv) 47 server = tgServer.ThinkgearServer(log, server_interface, server_port, device_address, device_id, emulate_headset_data = tgConf.THINKGEAR_ENABLE_SIMULATE_HEADSET_DATA, DEBUG=DEBUG) 47 server = synapse_server.puzzlebox_synapse_server_thinkgear(log, \ 48 server_interface, \ 49 server_port, \ 50 device_address, \ 51 #device_id, \ 52 emulate_headset_data = configuration.THINKGEAR_ENABLE_SIMULATE_HEADSET_DATA, \ 53 DEBUG=DEBUG) 48 54 server.start() 49 55 sys.exit(app.exec_())
Note: See TracChangeset
for help on using the changeset viewer.