info.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. submodel_id = { 1: { 0: 'Basic USB-FS' },
  15. 7: { 0: 'Basic USB-FS' } }
  16. speed_id = { 0: 'Full Speed (12 Mbit/s)',
  17. 1: 'High Speed (480 Mbit/s)' }
  18. def print_info_line(name, value, tab=0):
  19. print(''.ljust(tab) + (name + ':').ljust(12-tab) + value)
  20. def main(argv):
  21. parser = util.ArgumentParser()
  22. parser.add_argument("device", nargs="?", default="auto",
  23. help="serial device")
  24. parser.description = description
  25. parser.prog += ' ' + argv[1]
  26. args = parser.parse_args(argv[2:])
  27. print_info_line('Host Tools', 'v%d.%d' % (version.major, version.minor))
  28. print('Greaseweazle:')
  29. try:
  30. usb = util.usb_open(args.device, mode_check=False)
  31. except serial.SerialException:
  32. print(' Not found')
  33. sys.exit(0)
  34. port = usb.port_info
  35. if port.device:
  36. print_info_line('Device', port.device, tab=2)
  37. try:
  38. submodel = submodel_id[usb.hw_model][usb.hw_submodel]
  39. except KeyError:
  40. submodel = 'Unknown'
  41. submodel = '%02X (%s)' % (usb.hw_submodel, submodel)
  42. print_info_line('Model', 'F%d' % usb.hw_model, tab=2)
  43. print_info_line('Submodel', submodel, tab=2)
  44. fwver = 'v%d.%d' % (usb.major, usb.minor)
  45. if usb.update_mode:
  46. fwver += ' (Update Bootloader)'
  47. print_info_line('Firmware', fwver, tab=2)
  48. print_info_line('Serial', port.serial_number if port.serial_number
  49. else 'Unknown', tab=2)
  50. try:
  51. speed = speed_id[usb.usb_speed]
  52. except KeyError:
  53. speed = 'Unknown (0x%02X)' % usb.usb_speed
  54. print_info_line('USB Rate', speed, tab=2)
  55. if __name__ == "__main__":
  56. main(sys.argv)
  57. # Local variables:
  58. # python-indent: 4
  59. # End: