123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import os
- import time
- from concurrent.futures import ThreadPoolExecutor, as_completed
- from base import init_env
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "configs.production")
- init_env(interactive = False)
- from apps.web.constant import DeviceCmdCode
- from apps.web.core.networking import MessageSender
- from apps.web.device.models import Device
- from apps.web.core.adapter.base import fill_2_hexByte
- templateDevice = Device.objects(logicalCode = 'G405725').first() # type: Device
- def do_one(device):
- if device.ownerId not in ['5dce24750030489ab40171e3', '611b3cec00304839698572d0', '60de739f003048d84034f0ac']:
- return 'FAILURE owner id is: {}'.format(device.ownerId)
- if device.driverCode != '100206':
- return 'FAILURE driverCode is: {}'.format(device.driverCode)
- if 'V4003' in device.coreVer:
- version_path = "https://resource.washpayer.com/versions/one/4gcat1/V4003_V4017_4gcat1_6.1.161_101206.dfota.bin"
- elif 'V3037' in device.coreVer:
- version_path = "https://resource.washpayer.com/versions/one/4gcat1/V3037_V4017_4gcat1_6.1.161_101206.dfota.bin"
- elif 'V0034' in device.coreVer:
- version_path = "https://resource.washpayer.com/versions/one/4gcat1/V0034_V0034_4gcat1_6.1.161_101206.dfota.bin"
- else:
- return 'FAILURE {} core version is: {}'.format(str(device), device.coreVer)
- try:
- for i in range(10):
- portStr = fill_2_hexByte(hex(int(i)), 2)
- result = MessageSender.send(device, DeviceCmdCode.OPERATE_DEV_SYNC,
- {"funCode": '0D', 'data': portStr + '00'}, timeout = 30)
- if result['rst'] != 0:
- return "FAILURE 210 {} rst = {}".format(str(device), result['rst'])
- except Exception as e:
- return 'FAILURE stop {} port failure.'.format(str(device))
- time.sleep(5)
- cmdPara = {'cmd': 202, 'IMEI': device.devNo, 'ota_set': {'fw_url': version_path}}
- try:
- result = MessageSender.send(device = device, cmd = DeviceCmdCode.SET_DEVINFO, payload = cmdPara)
- if result['rst'] != 0:
- return "FAILURE 202 {} rst = {}".format(str(device), result['rst'])
- except Exception as e:
- return 'FAILURE upgrade {} port failure. error = {}'.format(str(device), str(e))
- time_over = int(time.time()) + 15 * 60
- while True:
- if int(time.time()) > time_over:
- return '{} timeout.'.format(str(device))
- time.sleep(60)
- myDeviceObj = Device.objects(devNo = device.devNo).first()
- if myDeviceObj.driverCode == '101206':
- myDeviceObj.devType = templateDevice.devType
- myDeviceObj.washConfig = templateDevice.washConfig
- myDeviceObj.otherConf = templateDevice.otherConf
- myDeviceObj.policyTemp = templateDevice.policyTemp
- myDeviceObj.tempWashConfig = templateDevice.tempWashConfig
- myDeviceObj.save()
- Device.invalid_device_cache(device.devNo)
- break
- return 'OK {}'.format(str(device))
- #
- # lList = [
- # 'G370955', 'G409410', 'G409411', 'G409415', 'G409417', 'G409418',
- # 'G409424', 'G409427', 'G409430', 'G409431', "G409437", "G409444",
- # "G409453", "G409455", "G409456", "G409458", "G409459", "G425098",
- # "G448757", "G448758", "G448762", "G409414", "G409422", "G409423",
- # "G409426", "G414216", "G414223", "G414248", "G414252", "G414254",
- # "G414255", "G414256", "G414257", "G414260", "G414264", "G414265",
- # "G414266", "G414267", "G414271", "G414272", "G414273", "G414278",
- # "G414279", "G414284", "G414285", "G414287", "G414288", "G439127",
- # "G414261", "G414276", "G414282", "G414209", "G414281", "G440944",
- # "G440945", "G440946", "G440948", "G320381", "G396991", "G396992",
- # "G396993", "G396996", "G414195", "G414228", "G396990", "G396994",
- # "G396997", "G440929", "G440931", "G440932", "G440933", "G440936",
- # "G440937", "G440939", "G440940", "G440941", "G440942"
- # ]
- lList = ["G400895", "G400898", "G400899", "G400910", "G400921", "G414144",
- "G414244", "G425079", "G425085", "G428979", "G454178"]
- with ThreadPoolExecutor(max_workers = 20) as executor:
- toDo = list()
- for l in lList:
- device = Device.get_dev_by_logicalCode(l)
- future = executor.submit(do_one, device)
- toDo.append(future)
- for f in as_completed(toDo):
- print f.result()
|