Browse Source

gw info: Display info about the Greaseweazle setup.

Keir Fraser 4 years ago
parent
commit
adff44c183
3 changed files with 63 additions and 2 deletions
  1. 57 0
      scripts/greaseweazle/tools/info.py
  2. 4 1
      scripts/greaseweazle/tools/util.py
  3. 2 1
      scripts/gw.py

+ 57 - 0
scripts/greaseweazle/tools/info.py

@@ -0,0 +1,57 @@
+# greaseweazle/tools/info.py
+#
+# Greaseweazle control script: Displat info about tools, firmware, and drive.
+#
+# Written & released by Keir Fraser <keir.xen@gmail.com>
+#
+# This is free and unencumbered software released into the public domain.
+# See the file COPYING for more details, or visit <http://unlicense.org>.
+
+description = "Display information about the Greaseweazle setup."
+
+import sys, serial
+
+from greaseweazle.tools import util
+from greaseweazle import usb as USB
+from greaseweazle import version
+
+def print_info_line(name, value, tab=0):
+    print(''.ljust(tab) + (name + ':').ljust(12-tab) + value)
+
+def main(argv):
+
+    parser = util.ArgumentParser()
+    parser.add_argument("device", nargs="?", default="auto",
+                        help="serial device")
+    parser.description = description
+    parser.prog += ' ' + argv[1]
+    args = parser.parse_args(argv[2:])
+
+    print_info_line('Host Tools', 'v%d.%d' % (version.major, version.minor))
+
+    print('Greaseweazle:')
+
+    try:
+        usb = util.usb_open(args.device, mode_check=False)
+    except serial.SerialException:
+        print('  Not found')
+        sys.exit(0)
+
+    port = usb.port_info
+    if port.device:
+        print_info_line('Device', port.device, tab=2)
+    print_info_line('Model', 'F%d' % usb.hw_type, tab=2)
+    fwver = 'v%d.%d' % (usb.major, usb.minor)
+    if usb.update_mode:
+        fwver += ' (Update Bootloader)'
+    print_info_line('Firmware', fwver, tab=2)
+    if port.serial_number:
+        print_info_line('Serial', port.serial_number, tab=2)
+
+
+if __name__ == "__main__":
+    main(sys.argv)
+
+# Local variables:
+# python-indent: 4
+# End:

+ 4 - 1
scripts/greaseweazle/tools/util.py

@@ -139,7 +139,7 @@ def usb_reopen(usb, is_update):
     raise serial.SerialException('Could not reopen port after mode switch')
 
 
-def usb_open(devicename, is_update=False):
+def usb_open(devicename, is_update=False, mode_check=True):
 
     if devicename == "auto":
         devicename = find_port()
@@ -147,6 +147,9 @@ def usb_open(devicename, is_update=False):
     usb = USB.Unit(serial.Serial(devicename))
     usb.port_info = port_info(devicename)
 
+    if not mode_check:
+        return usb
+
     print("** %s v%u.%u [F%u], Host Tools v%u.%u"
           % (("Greaseweazle", "Bootloader")[usb.update_mode],
              usb.major, usb.minor, usb.hw_type,

+ 2 - 1
scripts/gw.py

@@ -37,7 +37,8 @@ For installation instructions please read the wiki:
           % ', '.join(missing_modules))
     sys.exit(1)
 
-actions = [ 'read',
+actions = [ 'info',
+            'read',
             'write',
             'erase',
             'delays',