def setPowerOff(self, mode, dutNum, pwrDelayTime, timeout=0): ''' @summary: 设置测试板断电上电方式 @param pwrType:电源模式选择 @param main:主电 @param back:备电 @param boot:调试模式 @param reset: reset gpio 拉低 @param prtrg: prtrg gpio 拉低 @param dutNum: 0-15 选择对应的dut 16 全部dut @param pwrStatus: 0 下电 1 上电 @param pwrDelayTime: @param reset: 延迟时间 单位毫秒 ''' if mode.lower() not in ['main', 'back', 'boot', 'reset', 'prtrg']: return FAIL, 'has no this mode:%s' % mode for device in self.deviceList: newThreadFunc(self.__setPower, args=(device, mode, dutNum, 0, pwrDelayTime, timeout), daemon=True) endTime = time.time() + timeout while time.time() < endTime: time.sleep(1) if len(self.ttffStartTimeDict) == len(self.deviceList): return SUC, 'OK' failDeviceList = [] for device in self.deviceList: if device.get('sn') not in self.ttffStartTimeDict: failDeviceList.append(device.get('sn')) return FAIL, failDeviceList
def checkLocationFail(self, timeout=60, isTracking=False): ''' @summary: 检查设备是否失去定位 @param timeout: 超时时间 @return: (SUC, success info) or (FAIL, fail info) @see: self.hdbd.checkLocationFail(120) @author: shaochanghong @attention: 对tracking场景不适用 ''' sucDeviceDict = {} def check(sn, deviceObj): endTime = time.time() + timeout while time.time() < endTime: if not deviceObj.queue.empty(): nmeaType, nmeaMsg = deviceObj.queue.get_nowait() if nmeaType == 'GGA': ggaMsgs = nmeaMsg.split(',') try: if ggaMsgs[5] == '0' or ggaMsgs[5] == '': sucDeviceDict[sn] = "GGA:" + nmeaMsg break except: print(sn, nmeaMsg) raise else: time.sleep(0.9) for device in self.deviceList: sn = device.get('sn') deviceObj = device.get('obj') deviceObj.setParseNmeaEnable(True) newThreadFunc(check, args=(sn, deviceObj), daemon=True) PRINTI("正在查询定位结果,请耐心等待...") endTime = time.time() + timeout while time.time() < endTime: if len(sucDeviceDict) == len(self.deviceList): break time.sleep(1) if isTracking: for device in self.deviceList: sn = device.get('sn') deviceObj = device.get('obj') deviceObj.setParseNmeaEnable(False) if len(sucDeviceDict) == len(self.deviceList): return SUC, '所有设备失去定位' failDevices = [] for device in self.deviceList: sn = device.get('sn') if sn in sucDeviceDict: PRINTI(sn + '[%s]' % sucDeviceDict.get(sn)) else: failDevices.append(sn) PRINTE(sn + '[定位成功]') return FAIL, failDevices
def startReadPort(self): """ @summary: 开始读取串口信息 @return: 成功,失败信息 """ for device in self.deviceList: sn = device.get('sn') deviceObj = device.get('obj') newThreadFunc(func=deviceObj.startReciver, name=sn, args=(), daemon=True) # return SUC, 'start_success'
def startLocation(self, mode='cold', timeout=60, checkGGA=True): ''' @summary: 发起冷/热/温启动定位 @param mode: 启动方式 @param timeout: 超时时间 @return: (SUC, success info) or (FAIL, fail info) @see: self.hdbd.startLocation('cold', 120) @author: shaochanghong @attention: ''' if mode.lower() not in ['cold', 'warm', 'hot']: return FAIL, 'has no this mode:%s' % mode self.resetTestData() for device in self.deviceList: sn = device.get('sn') deviceObj = device.get('obj') deviceType = device.get('deviceType') newThreadFunc(self.__startLocation, args=(sn, deviceObj, deviceType, mode, timeout, checkGGA), daemon=True) sucDevices = [] endTime = time.time() + timeout while time.time() < endTime: sucDevices.clear() for device in self.deviceList: sn = device.get('sn') if sn in self.ttffStartTimeDict: if self.ttffStartTimeDict[sn].get('cmdState') == SUC: sucDevices.append(sn) if len(sucDevices) == len(self.deviceList): return SUC, '所有设备发起定位成功' time.sleep(1) failDevices = [] for device in self.deviceList: sn = device.get('sn') if sn not in sucDevices: failDevices.append(sn) PRINTE('%s:发起定位失败') return FAIL, '发起定位失败的设备:%s' % str(failDevices)
def checkLocationSuccess(self, timeout=60, isTracking=False, recordData=True): ''' @summary: 检查设备是否定位成功 @param timeout: 超时时间 @return: (SUC, success info) or (FAIL, fail info) @see: self.hdbd.checkLocationSuccess(120) @author: shaochanghong @attention: 对tracking场景不适用 ''' sucDeviceDict = {} def check(sn, deviceObj): endTime = time.time() + timeout while time.time() < endTime: if not deviceObj.queue.empty(): nmeaType, nmeaMsg = deviceObj.queue.get_nowait() if nmeaType == 'GGA': ggaMsgs = nmeaMsg.split(',') try: if ggaMsgs[5] != '0' and ggaMsgs[5] != '': sucDeviceDict[sn] = "GGA:" + nmeaMsg # self.ttffEndTimeDict[sn] = ggaMsgs[0] self.ttffEndTimeDict[sn] = { 'pcEndTime': time.time(), 'utc': ggaMsgs[0] } if ggaMsgs[10] != '': alt = float(ggaMsgs[8]) + float( ggaMsgs[10]) else: alt = float(ggaMsgs[8]) self.firstLocationDict[sn] = { 'lat': ggaMsgs[1], 'lon': ggaMsgs[3], 'alt': alt } break except: print(sn, nmeaMsg) raise else: time.sleep(0.9) for device in self.deviceList: sn = device.get('sn') deviceObj = device.get('obj') deviceObj.setParseNmeaEnable(True) newThreadFunc(check, args=(sn, deviceObj), daemon=True) PRINTI("正在查询定位结果,请耐心等待...") endTime = time.time() + timeout while time.time() < endTime: if len(sucDeviceDict) == len(self.deviceList): break time.sleep(1) if recordData: PRINTI("将首次定位信息写入表格") self.writeFirstFixLocationTTFF() if isTracking: for device in self.deviceList: sn = device.get('sn') deviceObj = device.get('obj') deviceObj.setParseNmeaEnable(False) if len(sucDeviceDict) == len(self.deviceList): return SUC, '所有设备定位成功' failDevices = [] for device in self.deviceList: sn = device.get('sn') if sn in sucDeviceDict: PRINTI(sn + '[%s]' % sucDeviceDict.get(sn)) else: failDevices.append(sn) PRINTE(sn + '[定位失败]') return FAIL, failDevices