tester.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import inquirer
  2. import time
  3. import os
  4. from artery_loader import FlashAT32
  5. import colorama
  6. from colorama import Fore
  7. class Tester:
  8. def __init__(self, debug_port):
  9. self.debug_port = debug_port
  10. colorama.init(autoreset=True)
  11. def menu(self):
  12. questions = [
  13. inquirer.List('action',
  14. message="Что делаем",
  15. choices=['Прошить IAP и FW [MDIO_88]',
  16. 'Прошить IAP и FW [MAI_12]',
  17. 'Прошить IAP и FW [MAO_4]',
  18. 'Получить системные настройки'],
  19. ),
  20. ]
  21. answers = inquirer.prompt(questions)
  22. if answers['action'] == 'Прошить IAP и FW [MDIO_88]':
  23. self.write_iap_fw('bin_dio/fw.bin', 'bin_iap/iap.bin')
  24. elif answers['action'] == 'Прошить IAP и FW [MAI_12]':
  25. self.write_iap_fw('bin_ai/fw.bin', 'bin_iap/iap.bin')
  26. elif answers['action'] == 'Прошить IAP и FW [MAO_4]':
  27. self.write_iap_fw('bin_ao/fw.bin', 'bin_iap/iap.bin')
  28. def write_iap_fw(self, path_to_fw, path_to_iap):
  29. print(Fore.YELLOW + "Переведите устройство в режим загрузчика и нажмите 'Enter'")
  30. input()
  31. print('Начало обновления...')
  32. start_time = time.time()
  33. d = FlashAT32(self.debug_port, 115200 * 8)
  34. d.DEBUG_PRINT = False
  35. try:
  36. d.connect()
  37. except Exception as e:
  38. print(e)
  39. print(Fore.RED + 'Что-то пошло не так!!!')
  40. return
  41. print(f'Flash size: {d.get_flash_size()} kB')
  42. print(f'Chip ID: {d.get_uid_str()}')
  43. d.erase_flash()
  44. iap_path = path_to_iap
  45. fw_path = path_to_fw
  46. iap_path_r = 'artery_iap.bin'
  47. fw_path_r = 'artery_fw.bin'
  48. print('IPA loading...')
  49. d.write_file_to_flash(0x08000000, iap_path)
  50. print('FW loading...')
  51. d.write_file_to_flash(0x08021000, fw_path)
  52. print(Fore.GREEN + f'Запись прошла успешно за {time.time() - start_time} сек.')
  53. class DUT:
  54. def __init__(self):
  55. pass
  56. def main():
  57. tester = Tester('COM53')
  58. tester.menu()
  59. if __name__ == '__main__':
  60. main()