Changeset 53 for remote_control
- Timestamp:
- 06/18/10 14:41:18 (12 years ago)
- Location:
- remote_control
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
remote_control/puzzlebox_brainstorms_client_thinkgear.py
r52 r53 9 9 # For more information please refer to http://www.gnu.org/copyleft/gpl.html 10 10 # 11 # Last Update: 2010.06.1 611 # Last Update: 2010.06.18 12 12 # 13 13 ##################################################################### … … 34 34 NO_REPLY_WAIT = configuration.NO_REPLY_WAIT 35 35 36 THINKGEAR_DELIMITER = '\r' 36 37 37 38 AUTHORIZATION_REQUEST = configuration.THINKGEAR_AUTHORIZATION_REQUEST … … 108 109 basic.LineReceiver): 109 110 110 delimiter ='\r'111 delimiter = THINKGEAR_DELIMITER 111 112 112 113 def __init__(self): … … 119 120 def connectionMade(self): 120 121 121 #data = pickle.dumps(self.factory.command)122 122 data = json.dumps(self.factory.command) 123 self. transport.write(data)124 125 self.factory.noReply = reactor.callLater(NO_REPLY_WAIT, self.noReply)123 self.sendLine(data) 124 125 ## self.factory.noReply = reactor.callLater(NO_REPLY_WAIT, self.noReply) 126 126 127 127 … … 137 137 #self.factory.log.error("noReply failed to call callback") 138 138 139 self.transport.loseConnection()139 ## self.transport.loseConnection() 140 140 141 141 … … 147 147 if not line: 148 148 return 149 150 151 data = json.loads(line) 149 150 try: 151 data = json.loads(line) 152 except Exception, e: 153 if DEBUG: 154 print "Partial data received (or error:", 155 print e 156 print ")." 157 158 print "line:", 159 print line 160 152 161 153 162 if self.DEBUG: … … 160 169 print data 161 170 162 171 ## self.factory.send_command_and_print_response(data) 172 173 174 ################################################################## 175 176 def connectionLost(self, reason): 177 178 if self.DEBUG > 1: 179 print "Connection lost:", 180 print reason 181 182 163 183 ##################################################################### 164 184 # ThinkGear Client Factory class -
remote_control/puzzlebox_brainstorms_server_thinkgear.py
r52 r53 9 9 # For more information please refer to http://www.gnu.org/copyleft/gpl.html 10 10 # 11 # Last Update: 2010.06.1 611 # Last Update: 2010.06.18 12 12 # 13 13 ##################################################################### … … 17 17 18 18 from twisted.internet import reactor, protocol, defer, task 19 from twisted.protocols import basic 19 20 20 21 import puzzlebox_brainstorms_configuration as configuration … … 30 31 SERVER_INTERFACE = configuration.SERVER_INTERFACE 31 32 SERVER_PORT = configuration.THINKGEAR_SERVER_PORT 33 34 THINKGEAR_DELIMITER = '\r' 32 35 33 36 MESSAGE_FREQUENCY_TIMER = 1 # 1 Hz … … 52 55 'theta': 0, \ 53 56 }, \ 54 } 57 } # A container for the EEG powers. These may 58 # be either integer or floating-point values. 55 59 56 60 DEFAULT_ESENSE_MESSAGE = \ … … 59 63 'attention': 0, \ 60 64 }, \ 61 } 65 } # A container for the eSense⢠attributes. 66 # These are integer values between 0 and 100, 67 # where 0 is perceived as a lack of that attribute 68 # and 100 is an excess of that attribute. 62 69 63 70 DEFAULT_BLINK_MESSAGE = {"blinkStrength": 100} 71 # The strength of a detected blink. This is 72 # an integer in the range of 0-255. 64 73 65 74 DEFAULT_RAWEEG_MESSAGE = {"rawEeg": 255} 75 # The raw data reading off the forehead sensor. 76 # This may be either an integer or a floating-point value. 66 77 67 78 DEFAULT_PACKET = {} … … 97 108 98 109 if self.DEBUG: 99 print '--> [ThinkGear Emulator] %s data received' % data 110 print "--> [ThinkGear Emulator] Received:", 111 print data 100 112 101 113 … … 156 168 def send_packet(self): 157 169 170 ## print dir(self.protocol) 171 ## print self.protocol.connected 172 ## if self.protocol.transport != None: 173 ## data = json.dumps(DEFAULT_SIGNAL_LEVEL_MESSAGE) 174 ## self.transport.write(data) 175 158 176 pass 159 177 … … 171 189 ##################################################################### 172 190 173 class puzzlebox_brainstorms_server_protocol(protocol.Protocol): 191 class puzzlebox_brainstorms_server_protocol(basic.LineReceiver): 192 193 delimiter='\r' 174 194 175 195 def __init__(self): 176 196 197 self.DEBUG = DEBUG 177 198 self.data = None 178 199 self.data_chunk = "" 179 200 201 202 ################################################################## 203 204 def connectionMade(self): 205 206 ## data = json.dumps(self.factory.command) 207 ## self.transport.write(data) 208 ## 209 ## self.factory.noReply = reactor.callLater(NO_REPLY_WAIT, self.noReply) 210 211 212 if self.DEBUG: 213 print "connectionMade" 214 215 216 response = DEFAULT_RESPONSE_MESSAGE 217 218 219 if self.DEBUG: 220 print "--> [ThinkGear Emulator] Sending:", 221 print response 222 223 response = json.dumps(response) 224 ## self.transport.write(response) 225 self.sendLine(response) 226 227 ################################################################## 228 229 def noReply(self): 230 231 try: 232 self.factory.replyDefer.callback('NO_REPLY') 233 except: 234 if self.DEBUG: 235 print "noReply failed to call callback" 236 #self.factory.log.error("noReply failed to call callback") 237 238 self.transport.loseConnection() 239 240 241 ################################################################## 242 243 def lineReceived(self, line): 244 245 # Ignore blank lines 246 if not line: 247 return 248 249 self.data = json.loads(line) 250 251 if self.DEBUG: 252 print "line received:", 253 print self.data 254 255 d = self.factory.process_data("%s" % self.data) 256 d.addCallback(self.send_response) 257 180 258 181 259 ################################################################## … … 183 261 def dataReceived(self, data): 184 262 185 print data 263 ## if self.DEBUG: 264 ## print "data received:", 265 ## print data 186 266 187 267 self.data_chunk += data … … 208 288 209 289 def send_response(self, response): 210 290 291 if self.DEBUG: 292 print "--> [ThinkGear Emulator] Sending:", 293 print response 294 211 295 response = json.dumps(response) 212 213 self.transport.write(response) 296 ## self.transport.write(response) 297 self.sendLine(response) 298 299 ## reactor.callLater(MESSAGE_FREQUENCY_TIMER, self.send_response, DEFAULT_RESPONSE_MESSAGE) 300 reactor.callLater(MESSAGE_FREQUENCY_TIMER, self.send_response, DEFAULT_PACKET) 301 214 302 215 303
Note: See TracChangeset
for help on using the changeset viewer.