Changeset 54 for remote_control
- Timestamp:
- 06/18/10 15:42:59 (12 years ago)
- Location:
- remote_control
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
remote_control/puzzlebox_brainstorms_client_thinkgear.py
r53 r54 77 77 reactor.connectTCP(self.server_host, self.server_port, factory) 78 78 79 return factory.replyDefer79 ## return factory.replyDefer 80 80 81 81 … … 90 90 91 91 d = self.send_command(command) 92 d.addCallback(self.print_response)92 #d.addCallback(self.print_response) 93 93 94 94 … … 135 135 if self.DEBUG: 136 136 print "noReply failed to call callback" 137 #self.factory.log.error("noReply failed to call callback")138 139 ## self.transport.loseConnection()140 137 141 138 … … 169 166 print data 170 167 171 ## self.factory.send_command_and_print_response(data)172 173 168 174 169 ################################################################## … … 178 173 if self.DEBUG > 1: 179 174 print "Connection lost:", 175 print reason 176 177 178 ################################################################## 179 180 def connectionDone(self, reason): 181 182 if self.DEBUG > 1: 183 print "Connection done:", 180 184 print reason 181 185 … … 233 237 234 238 reactor.callWhenRunning( \ 235 thinkgear_client.send_command _and_print_response, \239 thinkgear_client.send_command, \ 236 240 thinkgear_parameters) 237 241 -
remote_control/puzzlebox_brainstorms_server.py
r52 r54 20 20 21 21 import puzzlebox_brainstorms_configuration as configuration 22 #import puzzlebox_brainstorms_client23 22 import puzzlebox_brainstorms_remote_control as remote_control 24 23 #import puzzlebox_logger -
remote_control/puzzlebox_brainstorms_server_thinkgear.py
r53 r54 20 20 21 21 import puzzlebox_brainstorms_configuration as configuration 22 #import puzzlebox_brainstorms_client23 22 #import puzzlebox_logger 24 23 … … 95 94 96 95 self.protocol = puzzlebox_brainstorms_server_protocol 96 97 self.status_packet = DEFAULT_PACKET 98 self.client_connected = False 97 99 98 100 … … 103 105 d = defer.Deferred() 104 106 105 ## response = '%s command received' % data106 107 107 response = DEFAULT_RESPONSE_MESSAGE 108 108 … … 111 111 print data 112 112 113 114 ## if DISCRETE_CONTROL_COMMANDS:115 ##116 ## self.execute_command(command)117 118 119 113 if response: 120 114 d.callback(response) 121 115 122 123 116 return d 124 117 … … 126 119 ################################################################## 127 120 128 ## def execute_command(self, command): 129 ## 130 ## #command_line = 'python puzzlebox_brainstorms_remote_control.py --command=%s' % command 131 ## 132 ## #os.system(command_line) 133 ## 134 ## rc = remote_control.puzzlebox_brainstorms_rc( \ 135 ## device=configuration.BLUETOOTH_DEVICE, \ 136 ## command=command, \ 137 ## DEBUG=DEBUG) 138 ## 139 ## if rc.connection != None: 140 ## rc.run(rc.command) 141 ## rc.stop() 142 143 144 ################################################################## 145 146 def process_connection_lost(self, data): 147 148 if not data: 149 150 #self.log.debug("Connection lost with no data") 151 152 if self.DEBUG: 153 print "--> [ThinkGear Emulator] Connection lost with no data" 154 155 156 else: 157 158 #self.log.debug("Connection lost") 159 160 #if self.DEBUG: 161 #print "--> [Server] Connection lost" 162 163 pass 164 165 166 ################################################################## 167 168 def send_packet(self): 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 176 pass 177 178 179 ################################################################## 180 181 def start(self): 182 183 self.looping_timer = task.LoopingCall(self.send_packet) 121 def process_connection_lost(self): 122 123 print "--> [ThinkGear Emulator] Connection lost" 124 self.client_connected = False 125 126 127 ################################################################## 128 129 def update_status(self): 130 131 if self.DEBUG > 1: 132 print "status:", 133 print self.status_packet 134 135 136 ################################################################## 137 138 def start_updating(self): 139 140 self.client_connected = True 141 self.looping_timer = task.LoopingCall(self.update_status) 184 142 self.looping_timer.start(MESSAGE_FREQUENCY_TIMER) 185 143 … … 204 162 def connectionMade(self): 205 163 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 164 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) 165 print "--> [ThinkGear Emulator] Client connected" 166 167 self.factory.start_updating() 168 226 169 227 170 ################################################################## … … 234 177 if self.DEBUG: 235 178 print "noReply failed to call callback" 236 #self.factory.log.error("noReply failed to call callback")237 179 238 180 self.transport.loseConnection() … … 260 202 261 203 def dataReceived(self, data): 262 263 ## if self.DEBUG:264 ## print "data received:",265 ## print data266 204 267 205 self.data_chunk += data … … 271 209 272 210 except Exception, e: 273 ## self.factory.log.error("Partial data received (or error:",274 ## e, ").")275 211 if DEBUG: 276 212 print "Partial data received (or error:", … … 289 225 def send_response(self, response): 290 226 291 if self.DEBUG: 292 print "--> [ThinkGear Emulator] Sending:", 293 print response 227 if self.factory.client_connected: 228 if self.DEBUG: 229 print "--> [ThinkGear Emulator] Sending:", 230 print response 294 231 295 232 response = json.dumps(response) 296 ## self.transport.write(response)297 233 self.sendLine(response) 298 234 299 ## reactor.callLater(MESSAGE_FREQUENCY_TIMER, self.send_response, DEFAULT_RESPONSE_MESSAGE) 300 reactor.callLater(MESSAGE_FREQUENCY_TIMER, self.send_response, DEFAULT_PACKET) 235 reactor.callLater(MESSAGE_FREQUENCY_TIMER, \ 236 self.send_response, \ 237 self.factory.status_packet) 301 238 302 239 … … 306 243 def connectionLost(self, reason): 307 244 308 self.factory.process_connection_lost( self.data)245 self.factory.process_connection_lost() 309 246 310 247 … … 339 276 port=server_port, \ 340 277 factory=thinkgear_server) 341 reactor.callWhenRunning(reactor.callLater, 0, thinkgear_server.start)342 278 reactor.run() 343 279
Note: See TracChangeset
for help on using the changeset viewer.