aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-07-18 15:47:54 +0800
committerTat-Chee Wan (USM)2011-07-18 15:47:54 +0800
commitc3a288fc5a3db3383dbc9e85bee032e4cd1b7c8d (patch)
tree798ebed87e298971e07a27ab789abf461e933552
parentb14d454a454ffc35a94c3f99e176c40a68b31c0f (diff)
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.
-rwxr-xr-xHost/nxt-gdb-server.py22
1 files 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 <ENTER> 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()