From 0dc51a31732c3a868a0fa06e927553664f0c3203 Mon Sep 17 00:00:00 2001 From: Michael Pergament Date: Tue, 10 May 2016 10:23:11 +0200 Subject: [PATCH 1/2] Adjust writing rate to the baud rate The consoles have a 32 byte buffer, this gets overwritten when you go more than 9600b/s. --- lib/netconify/tty_telnet.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/netconify/tty_telnet.py b/lib/netconify/tty_telnet.py index f86f1a5..138b0c1 100644 --- a/lib/netconify/tty_telnet.py +++ b/lib/netconify/tty_telnet.py @@ -31,6 +31,7 @@ def __init__(self, host, port, **kvargs): self.host = host self.port = port self.timeout = kvargs.get('timeout', self.TIMEOUT) + self.baudrate = kvargs.get('baudrate', 9600) self._tty_name = "{0}:{1}".format(host, port) Terminal.__init__(self, **kvargs) @@ -62,12 +63,24 @@ def _tty_close(self): # ------------------------------------------------------------------------- def write(self, content): - """ write content + """ - self._tn.write(content + '\n') + # Write data according to defined baudrate + # per 8 bit of data there are 2 additional bits on the line + # (parity and stop bits) + for char in content: + self._tn.write(char) + wtime = 10/float(self.baudrate) + sleep(wtime) # do not remove + self._tn.write('\n') def rawwrite(self, content): - """ write content as-is """ - self._tn.write(content) + # Write data according to defined baudrate + # per 1 byte of data there are 2 additional bits on the line + # (parity and stop bits) + for char in content: + self._tn.write(char) + wtime = 10/float(self.baudrate) + sleep(wtime) # do not remove + self._tn.write('\n’) def read(self): """ read a single line """ From 6d023e070d6971d72f59b9a8c759ce32bbc65094 Mon Sep 17 00:00:00 2001 From: Michael Pergament Date: Wed, 11 May 2016 16:38:29 +0200 Subject: [PATCH 2/2] Pass baud to Telnet, check if baud set to 0 --- lib/netconify/cmdo.py | 1 + lib/netconify/tty_telnet.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/netconify/cmdo.py b/lib/netconify/cmdo.py index d0e57d9..8626bf8 100644 --- a/lib/netconify/cmdo.py +++ b/lib/netconify/cmdo.py @@ -317,6 +317,7 @@ def _tty_login(self): host, port = re.split('[,:]', self._args.telnet) tty_args['host'] = host tty_args['port'] = port + tty_args['baud'] = self._args.baud self.console = ('telnet', host, port) self._tty = netconify.Telnet(**tty_args) elif self._args.ssh is not None: diff --git a/lib/netconify/tty_telnet.py b/lib/netconify/tty_telnet.py index 138b0c1..1ab06a4 100644 --- a/lib/netconify/tty_telnet.py +++ b/lib/netconify/tty_telnet.py @@ -31,7 +31,7 @@ def __init__(self, host, port, **kvargs): self.host = host self.port = port self.timeout = kvargs.get('timeout', self.TIMEOUT) - self.baudrate = kvargs.get('baudrate', 9600) + self.baud = kvargs.get('baud', 9600) self._tty_name = "{0}:{1}".format(host, port) Terminal.__init__(self, **kvargs) @@ -63,22 +63,32 @@ def _tty_close(self): # ------------------------------------------------------------------------- def write(self, content): - # Write data according to defined baudrate + # If baud set to 0 write full speed + if (int(self.baud) == 0): + self._tn.write(content + '\n') + return None + + # Write data according to defined baud # per 8 bit of data there are 2 additional bits on the line # (parity and stop bits) for char in content: self._tn.write(char) - wtime = 10/float(self.baudrate) + wtime = 10/float(self.baud) sleep(wtime) # do not remove self._tn.write('\n') def rawwrite(self, content): - # Write data according to defined baudrate + # If baud set to 0 write full speed + if (int(self.baud) == 0): + self._tn.write(content + '\n') + return None + + # Write data according to defined baud # per 1 byte of data there are 2 additional bits on the line # (parity and stop bits) for char in content: self._tn.write(char) - wtime = 10/float(self.baudrate) + wtime = 10/float(self.baud) sleep(wtime) # do not remove self._tn.write('\n’)