mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
pyterm: try to reconnect on SerialException during connect
This is what the user would do anyway.
This commit is contained in:
parent
008faef16a
commit
7a9010fefa
48
dist/tools/pyterm/pyterm
vendored
48
dist/tools/pyterm/pyterm
vendored
@ -25,6 +25,7 @@ except ImportError:
|
|||||||
import ConfigParser as configparser
|
import ConfigParser as configparser
|
||||||
|
|
||||||
import cmd
|
import cmd
|
||||||
|
import errno
|
||||||
import serial
|
import serial
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
@ -96,6 +97,7 @@ defaultprompt = '>'
|
|||||||
|
|
||||||
# repeat command on empty line instead of sending the line
|
# repeat command on empty line instead of sending the line
|
||||||
defaultrepeat_cmd_empty_line = True
|
defaultrepeat_cmd_empty_line = True
|
||||||
|
defaultreconnect = True
|
||||||
|
|
||||||
|
|
||||||
class SerCmd(cmd.Cmd):
|
class SerCmd(cmd.Cmd):
|
||||||
@ -109,7 +111,8 @@ class SerCmd(cmd.Cmd):
|
|||||||
confdir=None, conffile=None, host=None, run_name=None,
|
confdir=None, conffile=None, host=None, run_name=None,
|
||||||
log_dir_name=None, newline=None, formatter=None,
|
log_dir_name=None, newline=None, formatter=None,
|
||||||
set_rts=None, set_dtr=None, serprompt=None,
|
set_rts=None, set_dtr=None, serprompt=None,
|
||||||
repeat_command_on_empty_line=defaultrepeat_cmd_empty_line):
|
repeat_command_on_empty_line=defaultrepeat_cmd_empty_line,
|
||||||
|
reconnect=defaultreconnect):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -139,6 +142,7 @@ class SerCmd(cmd.Cmd):
|
|||||||
self.newline = newline
|
self.newline = newline
|
||||||
self.serprompt = serprompt
|
self.serprompt = serprompt
|
||||||
self.repeat_command_on_empty_line = repeat_command_on_empty_line
|
self.repeat_command_on_empty_line = repeat_command_on_empty_line
|
||||||
|
self.reconnect = reconnect
|
||||||
if formatter is not None:
|
if formatter is not None:
|
||||||
self.fmt_str = formatter
|
self.fmt_str = formatter
|
||||||
|
|
||||||
@ -245,16 +249,27 @@ class SerCmd(cmd.Cmd):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# otherwise go for the serial port
|
# otherwise go for the serial port
|
||||||
elif self.port:
|
elif self.port:
|
||||||
|
connected = False
|
||||||
self.logger.info("Connect to serial port %s" % self.port)
|
self.logger.info("Connect to serial port %s" % self.port)
|
||||||
try:
|
while not connected:
|
||||||
self.serial_connect()
|
try:
|
||||||
except OSError as e:
|
self.serial_connect()
|
||||||
self.logger.error("Cannot connect to serial port {}: {}"
|
except serial.SerialException as e:
|
||||||
.format(self.port, e.strerror))
|
self.logger.error("%s", e.strerror)
|
||||||
sys.exit(1)
|
if (not self.reconnect) or (e.errno == errno.ENOENT):
|
||||||
except serial.SerialException as e:
|
sys.exit(e.errno)
|
||||||
self.logger.error("%s", e.strerror)
|
self.logger.info("Trying to reconnect to {} in 10 sec"
|
||||||
sys.exit(1)
|
.format(self.port))
|
||||||
|
time.sleep(10)
|
||||||
|
except OSError as e:
|
||||||
|
self.logger.error("Cannot connect to serial port {}: {}"
|
||||||
|
.format(self.port, e.strerror))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error("Unexpected exception {}".format(e))
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
connected = True
|
||||||
|
|
||||||
# wait until connection is established and fire startup
|
# wait until connection is established and fire startup
|
||||||
# commands to the node
|
# commands to the node
|
||||||
@ -836,8 +851,19 @@ if __name__ == "__main__":
|
|||||||
dest='repeat_command_on_empty_line',
|
dest='repeat_command_on_empty_line',
|
||||||
action="store_false",
|
action="store_false",
|
||||||
help="Do not repeat command on empty line")
|
help="Do not repeat command on empty line")
|
||||||
|
parser.add_argument("--reconnect",
|
||||||
|
dest='reconnect',
|
||||||
|
action='store_true',
|
||||||
|
help="Try to reconnect when failing on connection "
|
||||||
|
"setup (Default)")
|
||||||
|
parser.add_argument("--no-reconnect",
|
||||||
|
dest='reconnect',
|
||||||
|
action="store_false",
|
||||||
|
help="Do not try to reconnect when failing on "
|
||||||
|
"connection setup (Default)")
|
||||||
parser.set_defaults(
|
parser.set_defaults(
|
||||||
repeat_command_on_empty_line=defaultrepeat_cmd_empty_line)
|
repeat_command_on_empty_line=defaultrepeat_cmd_empty_line,
|
||||||
|
reconnect=defaultreconnect)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user