info.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. 4: { 0: 'V4' },
  17. 7: { 0: 'F7 v1',
  18. 1: 'F7 Plus (Ant Goffart, v1)',
  19. 2: 'F7 Lightning',
  20. 3: 'F7 v2)',
  21. 4: 'F7 Plus (Ant Goffart, v2)',
  22. 5: 'F7 Lightning Plus',
  23. 6: 'F7 Slim',
  24. 7: 'F7 v3 "Thunderbolt"' } }
  25. speed_id = { 0: 'Full Speed (12 Mbit/s)',
  26. 1: 'High Speed (480 Mbit/s)' }
  27. def print_info_line(name, value, tab=0):
  28. print(''.ljust(tab) + (name + ':').ljust(12-tab) + value)
  29. def main(argv):
  30. parser = util.ArgumentParser(usage='%(prog)s [options]')
  31. parser.add_argument("--device", help="greaseweazle device name")
  32. parser.add_argument("--bootloader", action="store_true",
  33. help="display bootloader info (F7 only)")
  34. parser.description = description
  35. parser.prog += ' ' + argv[1]
  36. args = parser.parse_args(argv[2:])
  37. print_info_line('Host Tools', 'v%d.%d' % (version.major, version.minor))
  38. print('Greaseweazle:')
  39. try:
  40. usb = util.usb_open(args.device, mode_check=False)
  41. except serial.SerialException:
  42. print(' Not found')
  43. sys.exit(0)
  44. mode_switched = (usb.jumperless_update
  45. and usb.update_mode != args.bootloader)
  46. if mode_switched:
  47. usb = util.usb_reopen(usb, args.bootloader)
  48. port = usb.port_info
  49. if port.device:
  50. print_info_line('Device', port.device, tab=2)
  51. try:
  52. model = model_id[usb.hw_model][usb.hw_submodel]
  53. except KeyError:
  54. model = 'Unknown (0x%02X%02X)' % (usb.hw_model, usb.hw_submodel)
  55. print_info_line('Model', model, tab=2)
  56. fwver = 'v%d.%d' % (usb.major, usb.minor)
  57. if usb.update_mode:
  58. fwver += ' (Update Bootloader)'
  59. print_info_line('Firmware', fwver, tab=2)
  60. print_info_line('Serial', port.serial_number if port.serial_number
  61. else 'Unknown', tab=2)
  62. try:
  63. speed = speed_id[usb.usb_speed]
  64. except KeyError:
  65. speed = 'Unknown (0x%02X)' % usb.usb_speed
  66. print_info_line('USB Rate', speed, tab=2)
  67. if mode_switched:
  68. usb = util.usb_reopen(usb, not args.bootloader)
  69. if __name__ == "__main__":
  70. main(sys.argv)
  71. # Local variables:
  72. # python-indent: 4
  73. # End: