A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

  1. #!/usr/bin/env python
  2. import sys, time
  3. import pyad2usb.ad2usb
  4. def handle_firmware(stage):
  5. if stage == pyad2usb.ad2usb.util.Firmware.STAGE_START:
  6. handle_firmware.wait_tick = 0
  7. handle_firmware.upload_tick = 0
  8. elif stage == pyad2usb.ad2usb.util.Firmware.STAGE_WAITING:
  9. if handle_firmware.wait_tick == 0:
  10. sys.stdout.write('Waiting for device.')
  11. handle_firmware.wait_tick += 1
  12. sys.stdout.write('.')
  13. sys.stdout.flush()
  14. elif stage == pyad2usb.ad2usb.util.Firmware.STAGE_BOOT:
  15. if handle_firmware.wait_tick > 0: print ""
  16. print "Rebooting device.."
  17. elif stage == pyad2usb.ad2usb.util.Firmware.STAGE_LOAD:
  18. print 'Waiting for boot loader..'
  19. elif stage == pyad2usb.ad2usb.util.Firmware.STAGE_UPLOADING:
  20. if handle_firmware.upload_tick == 0:
  21. sys.stdout.write('Uploading firmware.')
  22. handle_firmware.upload_tick += 1
  23. if handle_firmware.upload_tick % 30 == 0:
  24. sys.stdout.write('.')
  25. sys.stdout.flush()
  26. elif stage == pyad2usb.ad2usb.util.Firmware.STAGE_DONE:
  27. print "\r\nDone!"
  28. def main():
  29. device = '/dev/ttyUSB0'
  30. firmware = None
  31. if len(sys.argv) < 2:
  32. print "Syntax: {0} <firmware> [interface]".format(sys.argv[0])
  33. sys.exit(1)
  34. firmware = sys.argv[1]
  35. if len(sys.argv) > 2:
  36. device = sys.argv[2]
  37. print "Flashing device: {0}\r\nFirmware: {1}".format(device, firmware)
  38. dev = pyad2usb.ad2usb.devices.SerialDevice(interface=device)
  39. dev.open(interface=device, baudrate=19200)
  40. time.sleep(3)
  41. pyad2usb.ad2usb.util.Firmware.upload(dev, firmware, handle_firmware)
  42. dev.close()
  43. if __name__ == "__main__":
  44. main()