def aw_GSS7000GetStandardNMEA(self, sceneId, rmSrcFlag=True): ''' @summary: 获取6700/7000模拟器生成的标准nmea文件 @param sceneId: 场景编号 @param rmSrcFlag: 获取后是否删除标准nmea文件 @return: (SUC, success info) or (FAIL, fail info) @see: self.lbs.aw_checkCepTtffStandard({'COM1':19},20) @author: shaochanghong @attention: ''' posAppLogPath = getInstruments().get('Gss7000', {}).get('posAppLogPath') gssType = getInstruments().get('Gss7000', {}).get('type') if not os.path.exists(posAppLogPath): return FAIL, 'please check posAppLogPath.' if '7000' in gssType: ip = posAppLogPath.split(os.sep)[2] isSuc(self.sendMsg2Gss7000Server({'sceneId': sceneId}, ip, 9998)) srcPath = os.path.join(posAppLogPath, sceneId, 'nmea.txt') dstPath = os.path.join(getLbsCaseLogPath(), 'novatel.txt') if not os.path.exists(srcPath): return FAIL, 'has no nmea.txt' shutil.copyfile(srcPath, dstPath) if rmSrcFlag: os.remove(os.path.join(posAppLogPath, sceneId, 'nmea.txt')) return SUC, dstPath
def aw_GSS7000GetCurrentTime(self): runTime = isSuc(self.aw_GSS7000GetRunTime()) startTime = isSuc(self.aw_GSS7000GetStartTime()) startTime = time.mktime(time.strptime(startTime, "%Y-%m-%d %H:%M:%S")) curTime = startTime + runTime curDateTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(curTime)) return SUC, curDateTime
def aw_GSS7000ArmScenarioNoWait(self): """ @summary: 仿真当前场景,且使得在场景仿真期间可运行其他命令 @return: """ isSuc(self.aw_GSS7000EnsureReady()) self.__GSS7000SendCommand("AR_NOWAIT") time.sleep(2) return self.aw_GSS7000CheckExpectedStatus(SIMU_STATUS_DICT["Arming"], SIMU_STATUS_DICT["Armed"])
def aw_GSS7000ArmScenario(self): """ @summary: 准备播放场景 @return: """ isSuc(self.aw_GSS7000EnsureReady()) self.__GSS7000SendCommand("AR") time.sleep(2) return self.aw_GSS7000CheckExpectedStatus(SIMU_STATUS_DICT["Arming"], SIMU_STATUS_DICT["Armed"])
def aw_GSS7000SelectScenario(self, fileName): """ @summary: 选择要播放的场景 @param fileName:场景名称 @return: """ ret = self.aw_GSS7000CheckExpectedStatus( SIMU_STATUS_DICT["No scenario specified"], SIMU_STATUS_DICT["Ready"]) if ret[0] != SUC: isSuc(self.aw_GSS7000EnsureReady()) self.__GSS7000SendCommand("SC," + fileName) return self.aw_GSS7000CheckExpectedStatus(SIMU_STATUS_DICT["Ready"])
def aw_GSS7000Wait2Time(self, duration): ''' @summary: 等待场景播放多长时间 ''' runTime = isSuc(self.aw_GSS7000GetRunTime()) while runTime < duration: time.sleep(1) runTime = isSuc(self.aw_GSS7000GetRunTime()) startTime = isSuc(self.aw_GSS7000GetStartTime()) startTime = time.mktime(time.strptime(startTime, "%Y-%m-%d %H:%M:%S")) curTime = startTime + runTime curDateTime = time.strftime("%Y%m%d%H%M%S", time.localtime(curTime)) return SUC, curDateTime
def aw_GSS7000SetScenarioStart(self, timeStr, duration, satLoc): """ @summary: 设置场景开始和持续时间 @param timeStr: @param duration: @param satLoc: """ isSuc(self.aw_GSS7000EnsureReady()) cmd = 'START_TIME,' + timeStr if duration is not None: cmd = cmd + ',' + str(duration) if satLoc is not None: cmd = cmd + ',' + str(satLoc) return SUC, self.__GSS7000SendCommand(cmd)
def aw_copySceneSpanFromServer(self, sceneData, fileName): filePath = os.path.join(SCENE_PATH, sceneData['memoryLocation'], 'span', fileName, 'span') fileList = os.listdir(filePath) spanPath = None if sceneData['sapnPath'] == '': for file in fileList: if file.endswith('.kmz'): spanPath = os.path.join(filePath, file) isSuc(self.aw_copyFile2dstPath(spanPath, getLbsCaseLogPath())) return SUC, 'ok' else: spanPath = os.path.join(filePath, sceneData['sapnPath'] + '.kmz') isSuc(self.aw_copyFile2dstPath(spanPath, getLbsCaseLogPath())) return SUC, 'ok' return FAIL, 'has no found this span.'
def aw_GSS7000SetScenarioInitPosition(self, vehMot, lat, lon, height, timestamp): """ @summary: 设置静态场景初始化位置 @param vehMot: @param lat: @param lon: @param height: """ cmd = ','.join([ timestamp, 'INIT_POS', str(vehMot), str(lat), str(lon), str(height) ]) isSuc(self.aw_GSS7000EnsureReady()) return SUC, self.__GSS7000SendCommand(cmd)
def checkMaxAltitude(self, maxHeight): from aw.utils.kpireport.MaxSpeedAltReport import MaxSpeedAltReport standardTime, startTime = isSuc( MaxSpeedAltReport.getInstance().getnovatelMatchTime( 'alt', maxHeight)) for device in self.deviceList: MaxSpeedAltReport.getInstance().getTestNmeaData(device, startTime) return MaxSpeedAltReport.getInstance().checkMaxHeight( maxHeight, standardTime)
def aw_GSS7000SetScenarioTrigger(self, mode): """ @summary: 设置场景的trigger mode,必须在running前设置 @param mode:0/1/2三种模式 @return: """ curStatus = self.__GSS7000GetStatus() if curStatus == SIMU_STATUS_DICT["Armed"]: self.aw_GSS7000RunScenario() self.aw_GSS7000EndScenario(1) elif curStatus == SIMU_STATUS_DICT["Running"]: self.aw_GSS7000EndScenario(1) elif curStatus == SIMU_STATUS_DICT["Ended"]: self.aw_GSS7000RewindScenario() isSuc( self.aw_GSS7000CheckExpectedStatus( SIMU_STATUS_DICT["Ready"], SIMU_STATUS_DICT["No scenario specified"])) return SUC, self.__GSS7000SendCommand("TR," + str(mode))
def analysis_nmea(reportPath, config, testlog): db_path = os.path.join(reportPath, "logDB", 'lbs.db') analyze = AnalyzeNMEA(reportPath, config) # ret = analyze.setConfig(testlog) # print('2222', ret) # if ret[0] != DT_SUC: # return ret deviceInfo = config['deviceInfo'] print(deviceInfo) analyze.getKmz2DB(deviceInfo) isSuc(analyze.getDevicesNMEA2DB(deviceInfo)) if (config['is_need_single_analysis'] == True) and (os.path.exists( config['singleReportPath'])): analyze.getDevicesSingleLocationDB(config, deviceInfo) if os.path.exists(db_path): createKML(db_path, os.path.join(reportPath, 'report'), deviceInfo) print(deviceInfo) config['deviceInfo'] = deviceInfo return analyze_main(reportPath, config)
def aw_GSS7000GetRunTime(self, timestamp='-'): """ @summary: 获取场景运行的时间 @param timestamp: """ msg = self.__GSS7000SendCommand(timestamp + ",TIME") data = msg.split("data")[1] runTime = data.split(">")[1].split("<")[0].strip() if 'scenario is loading or has ended' in str(runTime): runTime = isSuc(self.aw_GSS7000GetScenarioDuration()) return SUC, float(runTime)
def injectEphemeris(self, remoteFile): ephFile = isSuc(self.downloadEphemeris(remoteFile)) with open(ephFile, 'rb') as rf: ephList = rf.read().split(b'\xf1\xd9') ephList = [b'\xf1\xd9' + msg for msg in ephList if msg] for device in self.deviceList: deviceType = device.get('deviceType') deviceObj = device.get('obj') if deviceType.lower() == 'hdbd': for msg in ephList: deviceObj.send(msg) time.sleep(0.1)
def aw_getAndformatSceneData(self): ''' @summary: 暂时弃用 ''' childSceneList = [] for sceneData in self.sceneList: if sceneData['sceneId'] not in self.sceneData: self.sceneData['sceneId'] = sceneData['sceneId'] self.sceneData['memoryLocation'] = sceneData['memoryLocation'] sceneData.pop('sceneId') sceneTimeData = isSuc(self.aw_formatSceneTime(sceneData)) sceneData.update(sceneTimeData) childSceneList.append(sceneData) self.sceneData['childSceneList'] = childSceneList return SUC, self.sceneData
def aw_nmeanalysis(self, starttime, endtime, sceneId=None, lonRef=None, latRef=None, altRef=None, isSingle=False): ''' @summary: 调用分析工具分析 @param starttime:场景开始 @param endtime:场景结束时间 @param isSingle:是否单点分析 @param sceneId:场景编号 @param latRef: 经度值 @param lonRef: 纬度值 @param altRef: 高度值 ''' config = isSuc( self._getnmeanalysisconfig(starttime, endtime, lonRef, latRef, altRef, isSingle)) path = getLbsCaseLogPath() if not sceneId: sceneId = getCurCaseName() try: configPath = os.path.join(getProjectPath(), 'aw', 'utils', 'nmeanalysis', 'config.py') with open(configPath, 'w') as f: f.write('#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n') f.write('config = ' + str(config)) f.close() nmeaAnalysisPath = os.path.join(getProjectPath(), 'aw', 'utils', 'nmeanalysis', 'AnalysisNMEA.py') cmd = r"python " + nmeaAnalysisPath + ' ' + path + ' ' + sceneId print(cmd) os.system(cmd) except Exception as e: return FAIL, e return SUC, 'OK'
def aw_copySceneFromSerevr2Labsat(self, sceneId, labsatPath=''): """ @summary: 拷贝要播放的场景到labsat @param sceneId:场景编号 @return: """ sceneData = isSuc(self.aw_getSceneMsg(sceneId)) sceneTimeData = isSuc(self.aw_formatSceneTime(sceneData)) self.sceneData.update(sceneData) self.sceneData.update(sceneTimeData) print(self.sceneData) fileName = sceneData['fileName'] filePath = os.path.join(SCENE_PATH, sceneData['memoryLocation'], fileName) print(filePath, os.path.join(labsatPath, fileName)) if not os.path.exists(os.path.join(labsatPath, fileName)): spaceMB = isSuc(self.getFreeSpaceMB(labsatPath)) realSize = isSuc(self.getDocRealSize(filePath)) if realSize < spaceMB -5: isSuc(self.aw_copyFile2dstPath(filePath, os.path.join(labsatPath, fileName))) else: listSenceFile = os.listdir(labsatPath) for senceFile in listSenceFile: shutil.rmtree(os.path.join(labsatPath, senceFile)) spaceMB = isSuc(self.getFreeSpaceMB(labsatPath)) if realSize < spaceMB -5: isSuc(self.aw_copyFile2dstPath(filePath, os.path.join(labsatPath, fileName))) break if 'Static' not in sceneData['sceneId']: isSuc(self.aw_copySceneSpanFromServer(sceneData, fileName)) return SUC, self.sceneData
def _getnmeanalysisconfig(self, starttime, endtime, lonRef=None, latRef=None, altRef=None, isSingle=False): ''' @summary: 分析工具写配置文件 @param starttime:场景开始 @param endtime:场景结束时间 @param latRef: 经度值 @param lonRef: 纬度值 @param altRef: 高度值 ''' path = getLbsCaseLogPath() comDict = isSuc(self._getSerialConfig()) config = { 'timeSlicing': { 'starttime': '2020-01-07 06:26:18', 'endtime': '2020-01-07 09:35:39' }, 'is_need_single_analysis': False, 'is_need_static_kpi': False, 'singleReportPath': '', 'static_kpi_values': { 'ref_longitude': 116, 'ref_alt': 0, 'ref_speed': 0, 'ref_heading': 0, 'ref_latitude': 40 }, 'satelliteInfo': {}, 'deviceInfo': [] } config['timeSlicing']['starttime'] = starttime config['timeSlicing']['endtime'] = endtime config['satelliteInfo'] = comDict if latRef and lonRef and altRef: config['is_need_static_kpi'] = True config['static_kpi_values']['ref_longitude'] = lonRef config['static_kpi_values']['ref_latitude'] = latRef config['static_kpi_values']['ref_alt'] = altRef if os.path.exists(os.path.join(path, getCurCaseName() + '.xls')): config['singleReportPath'] = os.path.join( path, getCurCaseName() + '.xls') if isSingle == True: config['is_need_single_analysis'] = True if os.path.exists(os.path.join(path, getCurCaseName() + '.xls')): config['singleReportPath'] = os.path.join( path, getCurCaseName() + '.xls') file_list = os.listdir(path) deviceInfo = {} for temp in file_list: deviceInfo = {} if temp.endswith('.kmz'): deviceInfo['timeZone'] = -18 deviceInfo['feature'] = 'kmz' deviceInfo['tech'] = 'novatel' deviceInfo['type'] = 'standard' deviceInfo['file_path'] = os.path.join(path, temp) config['deviceInfo'].append(deviceInfo) elif temp.split('.')[0] == 'novatel': deviceInfo['timeZone'] = 0 deviceInfo['feature'] = 'nmea' deviceInfo['tech'] = 'novatel' deviceInfo['type'] = 'standard' deviceInfo['file_path'] = os.path.join(path, temp) config['deviceInfo'].append(deviceInfo) elif temp.endswith('.txt') and temp.split('.')[0] != 'novatel': deviceInfo['timeZone'] = 0 deviceInfo['feature'] = 'nmea' if temp[:2].isdigit(): deviceInfo['tech'] = 'ip' + temp.split('_')[0].split( '.')[-1] + '_' + temp.split('_')[1] else: deviceInfo['tech'] = temp.split('_')[0] deviceInfo['type'] = 'test' deviceInfo['file_path'] = os.path.join(path, temp) config['deviceInfo'].append(deviceInfo) else: continue return SUC, config