def get_version(obj): version_cmd = poll_command(obj, MON_VER_ID, [], 40) if (len(version_cmd) == 0): PRINTE("get version fail") version = "Version: [%s], [%s]\r\n" % (version_cmd[22:38].decode("utf8"), version_cmd[6:22].decode("utf8")) return version.replace("\0", "")
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 _connect(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) for connTimes in range(1, CONNECT_RETRY_TIMES + 1): try: s.connect((self.__host, self.__port)) return s except: s.close() PRINTE('第%s次连接失败...' % connTimes) if connTimes == CONNECT_RETRY_TIMES: PRINTTRAC('请检查网络是否异常') raise
def __connect(self): for connTimes in range(1, CONNECT_RETRY_TIMES + 1): try: serObj = serial.Serial() serObj.port = self.__port serObj.baudrate = self.__baud # serObj.timeout = self.__timeout serObj.open() serObj.flushInput() serObj.flushOutput() return serObj except: PRINTE('第%s次连接失败...' % connTimes) if connTimes == CONNECT_RETRY_TIMES: PRINTTRAC('请检串口连接是否异常') raise
def __GSS7000SendCommand(self, command): try: self.__connectGSS7000() try: GSS7000.tn.write(command.encode("ascii")) except: self.__close() self.__connectGSS7000() GSS7000.tn.write(command.encode("ascii")) msg = GSS7000.tn.read_until( "</msg>".encode("ascii")).decode("ascii") time.sleep(0.1) except: PRINTTRAC() if "error" in msg or "fatal" in msg: PRINTE("status error,please check it") return msg
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