From 3c6eb376ac75b7820810f709f14d5d48257e1d45 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 7 Feb 2021 14:20:47 -0500 Subject: [PATCH] console: Make baud an optional parameter Make the baud rate an optional parameter to the console.py tool. When not present, it will default to 250000. Signed-off-by: Kevin O'Connor --- docs/Debugging.md | 5 ++++- klippy/console.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/Debugging.md b/docs/Debugging.md index 4286a37a..6c19ce54 100644 --- a/docs/Debugging.md +++ b/docs/Debugging.md @@ -123,12 +123,15 @@ possible to manually send these MCU commands (functions marked with the DECL_COMMAND() macro in the Klipper source code). To do so, run: ``` -~/klippy-env/bin/python ./klippy/console.py /tmp/pseudoserial 250000 +~/klippy-env/bin/python ./klippy/console.py /tmp/pseudoserial ``` See the "HELP" command within the tool for more information on its functionality. +Some command-line options are available. For more information run: +`~/klippy-env/bin/python ./klippy/console.py --help` + Generating load graphs ====================== diff --git a/klippy/console.py b/klippy/console.py index ab501d9a..bbf5377d 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -202,11 +202,18 @@ class KeyboardReader: self.data = kbdlines[-1] def main(): - usage = "%prog [options] " + usage = "%prog [options] " opts = optparse.OptionParser(usage) + opts.add_option("-b", "--baud", type="int", dest="baud", help="baud rate") options, args = opts.parse_args() - serialport, baud = args - baud = int(baud) + if len(args) != 1: + opts.error("Incorrect number of arguments") + serialport = args[0] + + baud = options.baud + if baud is None and not (serialport.startswith("/dev/rpmsg_") + or serialport.startswith("/tmp/")): + baud = 250000 logging.basicConfig(level=logging.DEBUG) r = reactor.Reactor()