From c3a288fc5a3db3383dbc9e85bee032e4cd1b7c8d Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Mon, 18 Jul 2011 15:47:54 +0800 Subject: added explicit wait for nxt brick to be ready before client connection Python startup delay may be incurred where the GDB Client connection retransmits requests since no reply has been received from the NXT brick. This causes GDB to go out of sync. --- Host/nxt-gdb-server.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Host/nxt-gdb-server.py b/Host/nxt-gdb-server.py index fea3d9e..a631952 100755 --- a/Host/nxt-gdb-server.py +++ b/Host/nxt-gdb-server.py @@ -22,6 +22,7 @@ import select #import usb import pyfantom import struct +import sys CTRLC = chr(3) NAKCHAR = '-' @@ -156,14 +157,17 @@ class NXTGDBServer: s.setsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind (('', self.port)) s.listen (1) - print "Waiting for GDB connection on port %s..." % self.port while True: - # Wait for a connection. - client, addr = s.accept () - print "Client from", addr + # We should open the NXT connection first, otherwise Python startup delay + # may cause GDB to misbehave + dummy = raw_input('Waiting...Press when NXT GDB Stub is ready. ') # Open connection to the NXT brick. brick = nxt.locator.find_one_brick () brick.sock.debug = DEBUG + # Wait for a connection. + print "Waiting for GDB connection on port %s..." % self.port + client, addr = s.accept () + print "Client from", addr # Work loop, wait for a message from client socket or NXT brick. while client is not None: data = '' @@ -213,7 +217,7 @@ class NXTGDBServer: client.send (data) data = '' brick.sock.close() - print "Connection closed, waiting for GDB connection on port %s..." % self.port + print "Connection closed." if __name__ == '__main__': # Read options from command line. @@ -226,5 +230,9 @@ if __name__ == '__main__': if args: parser.error ("Too many arguments") # Run. - s = NXTGDBServer (options.port) - s.run () + try: + s = NXTGDBServer (options.port) + s.run () + except KeyboardInterrupt: + print "\n\nException caught. Bye!" + sys.exit() -- cgit v1.2.3