info.py 2.7 KB

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