upgrade_policy_jndz.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import os
  4. import time
  5. from concurrent.futures import ThreadPoolExecutor, as_completed
  6. from base import init_env
  7. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "configs.production")
  8. init_env(interactive = False)
  9. from apps.web.constant import DeviceCmdCode
  10. from apps.web.core.networking import MessageSender
  11. from apps.web.device.models import Device
  12. from apps.web.core.adapter.base import fill_2_hexByte
  13. templateDevice = Device.objects(logicalCode = 'G405725').first() # type: Device
  14. def do_one(device):
  15. if device.ownerId not in ['5dce24750030489ab40171e3', '611b3cec00304839698572d0', '60de739f003048d84034f0ac']:
  16. return 'FAILURE owner id is: {}'.format(device.ownerId)
  17. if device.driverCode != '100206':
  18. return 'FAILURE driverCode is: {}'.format(device.driverCode)
  19. if 'V4003' in device.coreVer:
  20. version_path = "https://resource.washpayer.com/versions/one/4gcat1/V4003_V4017_4gcat1_6.1.161_101206.dfota.bin"
  21. elif 'V3037' in device.coreVer:
  22. version_path = "https://resource.washpayer.com/versions/one/4gcat1/V3037_V4017_4gcat1_6.1.161_101206.dfota.bin"
  23. elif 'V0034' in device.coreVer:
  24. version_path = "https://resource.washpayer.com/versions/one/4gcat1/V0034_V0034_4gcat1_6.1.161_101206.dfota.bin"
  25. else:
  26. return 'FAILURE {} core version is: {}'.format(str(device), device.coreVer)
  27. try:
  28. for i in range(10):
  29. portStr = fill_2_hexByte(hex(int(i)), 2)
  30. result = MessageSender.send(device, DeviceCmdCode.OPERATE_DEV_SYNC,
  31. {"funCode": '0D', 'data': portStr + '00'}, timeout = 30)
  32. if result['rst'] != 0:
  33. return "FAILURE 210 {} rst = {}".format(str(device), result['rst'])
  34. except Exception as e:
  35. return 'FAILURE stop {} port failure.'.format(str(device))
  36. time.sleep(5)
  37. cmdPara = {'cmd': 202, 'IMEI': device.devNo, 'ota_set': {'fw_url': version_path}}
  38. try:
  39. result = MessageSender.send(device = device, cmd = DeviceCmdCode.SET_DEVINFO, payload = cmdPara)
  40. if result['rst'] != 0:
  41. return "FAILURE 202 {} rst = {}".format(str(device), result['rst'])
  42. except Exception as e:
  43. return 'FAILURE upgrade {} port failure. error = {}'.format(str(device), str(e))
  44. time_over = int(time.time()) + 15 * 60
  45. while True:
  46. if int(time.time()) > time_over:
  47. return '{} timeout.'.format(str(device))
  48. time.sleep(60)
  49. myDeviceObj = Device.objects(devNo = device.devNo).first()
  50. if myDeviceObj.driverCode == '101206':
  51. myDeviceObj.devType = templateDevice.devType
  52. myDeviceObj.washConfig = templateDevice.washConfig
  53. myDeviceObj.otherConf = templateDevice.otherConf
  54. myDeviceObj.policyTemp = templateDevice.policyTemp
  55. myDeviceObj.tempWashConfig = templateDevice.tempWashConfig
  56. myDeviceObj.save()
  57. Device.invalid_device_cache(device.devNo)
  58. break
  59. return 'OK {}'.format(str(device))
  60. #
  61. # lList = [
  62. # 'G370955', 'G409410', 'G409411', 'G409415', 'G409417', 'G409418',
  63. # 'G409424', 'G409427', 'G409430', 'G409431', "G409437", "G409444",
  64. # "G409453", "G409455", "G409456", "G409458", "G409459", "G425098",
  65. # "G448757", "G448758", "G448762", "G409414", "G409422", "G409423",
  66. # "G409426", "G414216", "G414223", "G414248", "G414252", "G414254",
  67. # "G414255", "G414256", "G414257", "G414260", "G414264", "G414265",
  68. # "G414266", "G414267", "G414271", "G414272", "G414273", "G414278",
  69. # "G414279", "G414284", "G414285", "G414287", "G414288", "G439127",
  70. # "G414261", "G414276", "G414282", "G414209", "G414281", "G440944",
  71. # "G440945", "G440946", "G440948", "G320381", "G396991", "G396992",
  72. # "G396993", "G396996", "G414195", "G414228", "G396990", "G396994",
  73. # "G396997", "G440929", "G440931", "G440932", "G440933", "G440936",
  74. # "G440937", "G440939", "G440940", "G440941", "G440942"
  75. # ]
  76. lList = ["G400895", "G400898", "G400899", "G400910", "G400921", "G414144",
  77. "G414244", "G425079", "G425085", "G428979", "G454178"]
  78. with ThreadPoolExecutor(max_workers = 20) as executor:
  79. toDo = list()
  80. for l in lList:
  81. device = Device.get_dev_by_logicalCode(l)
  82. future = executor.submit(do_one, device)
  83. toDo.append(future)
  84. for f in as_completed(toDo):
  85. print f.result()