info.py 2.9 KB

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