info.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # greaseweazle/tools/info.py
  2. #
  3. # Greaseweazle control script: Displat info about tools, firmware, and drive.
  4. #
  5. # Written & released by Keir Fraser <keir.xen@gmail.com>
  6. #
  7. # This is free and unencumbered software released into the public domain.
  8. # See the file COPYING for more details, or visit <http://unlicense.org>.
  9. description = "Display information about the Greaseweazle setup."
  10. import sys, serial
  11. from greaseweazle.tools import util
  12. from greaseweazle import usb as USB
  13. from greaseweazle import version
  14. model_id = { 1: { 0: 'F1',
  15. 1: 'F1 Plus',
  16. 2: 'F1 Plus (Unbuffered)' },
  17. 4: { 0: 'V4',
  18. 1: 'V4 Slim' },
  19. 7: { 0: 'F7 v1',
  20. 1: 'F7 Plus (Ant Goffart, v1)',
  21. 2: 'F7 Lightning',
  22. 3: 'F7 v2)',
  23. 4: 'F7 Plus (Ant Goffart, v2)',
  24. 5: 'F7 Lightning Plus',
  25. 6: 'F7 Slim',
  26. 7: 'F7 v3 "Thunderbolt"' } }
  27. speed_id = { 0: 'Full Speed (12 Mbit/s)',
  28. 1: 'High Speed (480 Mbit/s)' }
  29. def print_info_line(name, value, tab=0):
  30. print(''.ljust(tab) + (name + ':').ljust(12-tab) + value)
  31. def main(argv):
  32. parser = util.ArgumentParser(usage='%(prog)s [options]')
  33. parser.add_argument("--device", help="greaseweazle device name")
  34. parser.add_argument("--bootloader", action="store_true",
  35. help="display bootloader info (F7 only)")
  36. parser.description = description
  37. parser.prog += ' ' + argv[1]
  38. args = parser.parse_args(argv[2:])
  39. print_info_line('Host Tools', 'v%d.%d' % (version.major, version.minor))
  40. print('Greaseweazle:')
  41. try:
  42. usb = util.usb_open(args.device, mode_check=False)
  43. except serial.SerialException:
  44. print(' Not found')
  45. sys.exit(0)
  46. mode_switched = (usb.jumperless_update
  47. and usb.update_mode != args.bootloader
  48. and not (usb.update_mode and usb.update_jumpered))
  49. if mode_switched:
  50. usb = util.usb_reopen(usb, args.bootloader)
  51. port = usb.port_info
  52. if port.device:
  53. print_info_line('Device', port.device, tab=2)
  54. try:
  55. model = model_id[usb.hw_model][usb.hw_submodel]
  56. except KeyError:
  57. model = 'Unknown (0x%02X%02X)' % (usb.hw_model, usb.hw_submodel)
  58. print_info_line('Model', model, tab=2)
  59. fwver = 'v%d.%d' % (usb.major, usb.minor)
  60. if usb.update_mode:
  61. fwver += ' (Update Bootloader)'
  62. print_info_line('Firmware', fwver, tab=2)
  63. print_info_line('Serial', port.serial_number if port.serial_number
  64. else 'Unknown', tab=2)
  65. try:
  66. speed = speed_id[usb.usb_speed]
  67. except KeyError:
  68. speed = 'Unknown (0x%02X)' % usb.usb_speed
  69. print_info_line('USB Rate', speed, tab=2)
  70. if mode_switched:
  71. usb = util.usb_reopen(usb, not args.bootloader)
  72. if __name__ == "__main__":
  73. main(sys.argv)
  74. # Local variables:
  75. # python-indent: 4
  76. # End: