- Timestamp:
- 06/28/10 13:24:11 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
remote_control/puzzlebox_brainstorms_client_interface_qt.py
r70 r71 44 44 SERVER_PORT = configuration.SERVER_PORT 45 45 46 THINKGEAR_SERVER_HOST = configuration.THINKGEAR_SERVER_HOST 47 THINKGEAR_SERVER_PORT = configuration.THINKGEAR_SERVER_PORT 48 49 THINKGEAR_DELIMITER = '\r' 50 51 THINKGEAR_PARAMETERS = {"enableRawOutput": False, "format": "Json"} 52 46 53 ##################################################################### 47 54 # Classes … … 165 172 #self.blockSize = 0 166 173 self.brainstormsClientTcpSocket = QtNetwork.QTcpSocket(self) 174 self.brainstormsClientTcpSocket.name = 'Brainstorms Server' 167 175 168 176 #self.brainstormsClientTcpSocket.readyRead.connect(self.printReply) … … 171 179 172 180 self.thinkgearClientTcpSocket = QtNetwork.QTcpSocket(self) 181 self.thinkgearClientTcpSocket.name = 'ThinkGear Server' 173 182 174 183 self.thinkgearClientTcpSocket.readyRead.connect(self.printReply) 175 184 self.thinkgearClientTcpSocket.error.connect(self.displayError) 185 186 self.sendCommand(THINKGEAR_PARAMETERS, self.thinkgearClientTcpSocket, THINKGEAR_SERVER_HOST, THINKGEAR_SERVER_PORT) 176 187 177 188 … … 179 190 180 191 def printReply(self, reply=None): 181 182 if (reply != None): 183 184 print "reply:", 185 print reply 186 187 192 193 socket = self.thinkgearClientTcpSocket 194 195 socket_buffer = socket.readAll() 196 197 for packet in socket_buffer.split(THINKGEAR_DELIMITER): 198 199 if packet != '': 200 201 data = json.loads(packet.data()) 202 203 if self.DEBUG: 204 print "<-- [%s] Received:" % socket.name, 205 print data 206 207 self.processPacketThinkGear(data) 208 209 210 ################################################################## 211 212 def processPacketThinkGear(self, packet): 213 214 if ('eSense' in packet.keys()): 215 216 if ('attention' in packet['eSense'].keys()): 217 self.progressBarConcentration.setValue(packet['eSense']['attention']) 218 219 if ('meditation' in packet['eSense'].keys()): 220 self.progressBarRelaxation.setValue(packet['eSense']['meditation']) 221 222 188 223 ################################################################## 189 224 … … 212 247 213 248 def turnLeft(self): 214 self.sendCommand('turn_left' )249 self.sendCommand('turn_left', self.brainstormsClientTcpSocket) 215 250 216 251 def driveForward(self): 217 self.sendCommand('drive_forward' )252 self.sendCommand('drive_forward', self.brainstormsClientTcpSocket) 218 253 219 254 def turnRight(self): 220 self.sendCommand('turn_right' )255 self.sendCommand('turn_right', self.brainstormsClientTcpSocket) 221 256 222 257 def turnLeftInReverse(self): 223 self.sendCommand('turn_left_in_reverse' )258 self.sendCommand('turn_left_in_reverse', self.brainstormsClientTcpSocket) 224 259 225 260 def driveReverse(self): 226 self.sendCommand('drive_reverse' )261 self.sendCommand('drive_reverse', self.brainstormsClientTcpSocket) 227 262 228 263 def turnRightInReverse(self): 229 self.sendCommand('turn_right_in_reverse' )264 self.sendCommand('turn_right_in_reverse', self.brainstormsClientTcpSocket) 230 265 231 266 def stopMotors(self): 232 self.sendCommand('stop_motors' )233 234 235 ################################################################## 236 237 def sendCommand(self, command ):267 self.sendCommand('stop_motors', self.brainstormsClientTcpSocket) 268 269 270 ################################################################## 271 272 def sendCommand(self, command, socket, host=SERVER_HOST, port=SERVER_PORT): 238 273 239 274 if self.DEBUG: 240 print " Sending:",275 print "--> [%s] Sending:" % socket.name, 241 276 print command 242 277 243 278 #self.blockSize = 0 244 self.brainstormsClientTcpSocket.abort() 245 self.brainstormsClientTcpSocket.connectToHost(SERVER_HOST, SERVER_PORT) 279 ## self.brainstormsClientTcpSocket.abort() 280 ## self.brainstormsClientTcpSocket.connectToHost(SERVER_HOST, SERVER_PORT) 281 ## 282 ## data = json.dumps(command) 283 ## self.brainstormsClientTcpSocket.write(data) 284 285 socket.abort() 286 socket.connectToHost(host, port) 246 287 247 288 data = json.dumps(command) 248 s elf.brainstormsClientTcpSocket.write(data)289 socket.write(data) 249 290 250 291
Note: See TracChangeset
for help on using the changeset viewer.