def T_01_readObuId_A(product): u'''读取OBU内部标识-通过发卡器读取OBUID并与镭雕条码进行绑定''' manulCheck(u"操作提示", u"请将整机放置在发卡器上,待绿灯闪烁后确定", "ok") sc = __askForTrader() mac, contractSerial = readNember(sc) print "mac:", mac print "合同序列号:", contractSerial newMac = checkExcel(PARAM["excelPath"].decode('utf-8'), PARAM["excelSheet"], contractSerial) try: uiLog(u"切换至NuLink模式") nul = __getNuLink() infos = nul.readInfo() infos00 = infos[:8] + newMac + infos[16:32] infos40 = infos[128:154] nul.writeToInfo(infos00, infos40) except: raise TestItemFailException(failWeight=10, message=u'写入新的mac失败') manulCheck(u"操作提示", u"请将整机放置在发卡器上,待绿灯闪烁后确定", "ok") for i in range(3): nul.resetChip() time.sleep(1) checkMac, readContractSerial = readNember(sc) if checkMac == newMac: return {u"写入新Mac": u"成功"}
def __checkBoxTestStatus(boxBar): uiLog(u'检查小盒条码%s的包装情况...' % boxBar) with ServerBusiness(testflow=True) as sb: #这里不会混淆,因为小箱条码为18位,大箱为20位 status = sb.getProductTestStatus(productName="GS10包装 ", idCode=boxBar) if status is None: raise AbortTestException(message=u"条码为[%s]的小盒尚未包装,请勿进行大盒包装!" % boxBar)
def tearDown(self): try: GS25.closeHf() GS25.close() except Exception, e: print e uiLog(u"系统异常:" + str(e))
def clearFileInfo(self, updateApdu): ''' updateApdu: 0700d68200020000,0700d68300020000,0600d684000100 ''' try: self.rsu.open() beaconId = "a4".decode("hex") + struct.pack( ">I", random.randint(0, 1024 * 1024 * 16))[1:] currentTime = Utils.currentTime() res = self.rsu.initialization(beaconId, currentTime, 0, 1, "418729301a00290007", 0) macId = self.rsu.getCurrentMac() self.checkCpc(macId) vstInfo = DataParser.parseCpcVstApplication(res.application) self.analyzeVstInfo(vstInfo) mac = Utils.calculateMac(self.rsu, self.cpcId, self.provider, self.stationConfig) descryption = Utils.calculateAuthDataFromMac(mac) externalAuthCmd = "0d0082000108" + descryption res = self.rsu.transferChannel(1, 1, 1, 1, externalAuthCmd) uiLog(res.data) res = self.rsu.transferChannel(1, 1, 1, 1, updateApdu) uiLog(res.data) self.rsu.eventReport() finally: self.rsu.close()
def T_02_powerTest_A(product): u"功率测试-测试功率值是否达标,并记录功率值" manulCheck(u"操作提示", u"请将阅读器天线接口连接到频谱仪上,点击OK开始测试", "ok") sa = __getSpecAnlzr() sa.resetForRead() rd201 = __getReader() rd201.setting = True start_new_thread(__asynInven, (rd201, )) time.sleep(0.5) power = sa.readPowerValue() rd201.setting = False res = {u"阅读器发射功率": power} product.addBindingCode(u"发射功率", power) if not (SP("hr.reader.power.low", 34) <= power <= SP( "hr.reader.power.high", 35)): raise TestItemFailException(failWeight=10, message=u'发射功率值不合格', output=res) sa.setForIdleRead() time.sleep(0.5) idlePower = sa.readPowerValue() uiLog(u"空闲时功率:%f" % idlePower) if idlePower > 0: raise TestItemFailException(failWeight=10, message=u'空闲状态依然有功率值:%f' % idlePower, output=res) return res
def detectWakeupResults(data): # 分析CPC唤醒测试结果 uiLog(u"CPC唤醒测试结果:%s" % ord(data[-3])) c = ord(data[-3]) < PARAM["detectNumberOfWakes"] if c: raise TestItemFailException(failWeight=10, message=u"CPC唤醒测试结果值: %s" % ord(data[-3]))
def T_04_PSAMTest_A(product): u'PSAM卡接口测试-RSDB0单板连接RSIB0单板进行4个PSAM卡接口测试' errorList = [] proxy = PsamProxy(PARAM["writeIP"]) command = "00a4000002df01" try: for slot in range(4): ack = proxy.active(slot) if ack[0:4] != "e800": superUiLog(u"PSAM卡槽[%d]激活失败" % (slot + 1) + ack) errorList.append(str(slot + 1)) continue else: superUiLog(u"PSAM卡槽[%d]激活成功" % (slot + 1) + ack[4:]) ackRead = proxy.exchangeApdu(slot, command) if ackRead[0:4] != "e900": uiLog(u"命令执行失败 " + ack) else: uiLog(u"命令执行成功 " + ack[4:]) finally: proxy.close() if errorList != []: raise TestItemFailException(failWeight=10, message=u'PSAM卡槽%s激活失败' % ",".join(errorList)) return
def T_15_staticCurrent_A(product): u"静态电流测试-读取静态电流值,并判断是否在阈值范围内" try: #staticCurrentRLock.acquire() __stateAtSerial(product) __getIVB().obuTest(product.productSlot).OBUEnterSleep() __getIVB().peripheralCtrl(product.productSlot).channelSelect(0x03) __getIVB().peripheralCtrl(product.productSlot).obuPowerCtrl(0x02) uiLog(u"切换到休眠状态,关闭串口") time.sleep(0.5) vtg = __getIVB().peripheralCtrl( product.productSlot).readObuCurrentVoltage(100) #staticCurrent = (vtg*100)/14.99/1000.0 staticCurrent = (vtg / 1000.0) / 166375.0 resultMap = {u"静态电流": staticCurrent} sl, sh = SP('gs11.staticCurrent.low', 0), SP('gs11.staticCurrent.high', 12e-6) if staticCurrent < sl or staticCurrent > sh: raise TestItemFailException( failWeight=10, message=u'静态电流测试不通过,值:%.2e,正常阈值%.2e-%.2e' % (staticCurrent, sl, sh), output=resultMap) return resultMap except IntegratedVATBoard.DeviceNoResponseException, e: raise AbortTestException(message=u'工装板通信失败,无法继续测试')
def T_11_initParams_A(product): u"设置初始参数-设置链路模式、判决间隔、DATT、RSSI、方向等参数并进行验证" global CURRENT_TESTING_READER, TC reader = CURRENT_TESTING_READER clm,ji,sd,sr,sdr = \ SP("rd40.master.commLinkMode",0,int), \ SP("rd40.master.judgeInterval",30,int), \ SP("rd40.master.slaveDatt",0,int), \ SP("rd40.master.slaveRssi",95,int), \ SP("rd40.master.slaveDirection",1,int) reader.setCommLink(clm) uiLog(u"设置链路方式:%d" % clm) reader.setJudgeInterval(ji) uiLog(u"设置判决间隔:%d" % ji) reader.setSlaveDatt(1, sd) uiLog(u"设置DATT:%d" % sd) reader.setSlaveRssi(1, sr) uiLog(u"设置RSSI:%d" % sr) reader.setSlaveDirection(1, sdr) uiLog(u"设置显示方向:%d" % sdr) ret = reader.querySlaveInfo(1) TC.assertEqual(ret[0:12], SP("rd40.master.slaveVerifyStr", "0201005f1d01", str), u"参数设置验证失败") return {u"链路方式": clm, u"判决间隔": ji, u"DATT": sd, u"RSSI": sr, u"显示方向": sdr}
def __loadCsvFile(): from PyQt4 import QtCore, QtGui, uic fn = askForSomething(u"输入文件名路径", u"请输入您要读取的文件名", autoCommit=False) if fn == "": raise AbortTestException(message="用户取消了设置") uiLog(u"加载写码记录文件:" + fn) global g_csvFile g_csvFile = open(fn, 'r')
def T_01_readObuId_A(product): u"读取OBU内部标识-通过ICP方式读取OBU的内部标识" nul = board.__getNuLink() try: __switchToNulink() infos = nul.readInfo() superUiLog(u"信息区" + infos) currentSoftVersion = infos[18:26] vf = SP("gs11.vatVersion.filename", "GS11-VAT-09.00.00.version", str) targetVatSoftwareVersion = "".join( vf.split("-")[2].split(".")[:3]) + "00" if currentSoftVersion != targetVatSoftwareVersion: uiLog(u"整机内非测试版本,下载测试版本:" + vf) #下载测试版本 vf = getVersionFile( SP("gs11.vatVersion.filename", "GS11-VAT-09.00.00.version", str)) nul.downloadVersion(vf) #写入测试版本号 CONFIG_BUILD_INFO = infos[:32] CONFIG_RF_PARA = infos[128:154] CONFIG_BUILD_INFO = CONFIG_BUILD_INFO[: 18] + targetVatSoftwareVersion + CONFIG_BUILD_INFO[ 26:] nul.writeToInfo(CONFIG_BUILD_INFO, CONFIG_RF_PARA) except Exception, e: print e raise AbortTestException(u"无法读取内部标识及版本号")
def T_02_updateMac_A(product): u'''更新MAC地址-获取新的MAC地址并BSL写入''' manulCheck(u"操作提示", u"请连接整机和工装板的U口线,然后点击确定", "ok") if SESSION["testor"] != u"单机": obuid = serialCode("mac") else: obuid = "" while re.match("^([0-9]|[A-F]|[a-f]){8}$", obuid) is None: obuid = askForSomething(u"MAC地址", u"请输入MAC地址", autoCommit=False, defaultValue="24") uiLog(u"分配测试产品标识:" + obuid) sc = __askForPlateDeviceCom() product.setTestingProductIdCode(obuid) try: sc.startBslWriting(passwordFile) uiLog(u"开始写入MAC地址") sc.save_obu_id(__toBytesarray(obuid)) finally: sc.finishBslWritten() time.sleep(1) sc.clearSerialBuffer()
def downloadVersion(self, versionPathName, verify=True): '''下载版本''' #检查config uiLog(u"开始检查CFG") dr = self.__nulinkCmd("-r CFG0") if "0xFFFFFFFE" not in dr: self.initCfg() else: dr = self.__nulinkCmd("-r CFG1") if "0x0000FE00" not in dr: self.initCfg() #擦除版本文件 uiLog(u"开始擦除版本区") dr = self.__nulinkCmd("-e APROM") if "Erase APROM finish" in dr: uiLog(u"擦除版本区完成,开始写入版本") else: raise TestItemFailException(failWeight=10, message=u"版本区擦除失败") #下载版本文件 dr = self.__nulinkCmd("-w APROM %s" % versionPathName) if "Write APROM finish" in dr: uiLog(u"版本信息下载完成,开始校验") else: raise TestItemFailException(failWeight=10, message=u"版本区写入失败") #校验版本下载 if verify: dr = self.__nulinkCmd("-v APROM %s" % versionPathName) if "Verify APROM DATA success" in dr: uiLog(u"版本校验通过") else: raise TestItemFailException(failWeight=10, message=u"版本区校验失败")
def readAWholeFile(self, size, fileName): self.rsu.open() beaconId = "a4".decode("hex") + struct.pack( ">I", random.randint(0, 1024 * 1024 * 16))[1:] currentTime = Utils.currentTime() res = self.rsu.initialization(beaconId, currentTime, 0, 1, "418729301a00290007", 0) m = 83 bytesNeedRead = size loop = bytesNeedRead / m remain = bytesNeedRead % m route = "" myOffset = 0 selectFileCmd = "0700a4000002" + fileName self.rsu.transferChannel(1, 1, 1, 1, selectFileCmd) for i in range(loop): readBinaryCmd = "0500b0" + hex(myOffset)[2:].zfill(4) + hex( m)[2:].zfill(2) res = self.rsu.transferChannel(1, 1, 1, 1, readBinaryCmd) _len = int(res.data[0:2], 16) route = route + res.data[2:(_len + 1 - 2) * 2] myOffset = myOffset + m if (remain > 0): readBinaryCmd = "0500b0" + hex(myOffset)[2:].zfill(4) + hex( remain)[2:].zfill(2) res = self.rsu.transferChannel(1, 1, 1, 1, readBinaryCmd) _len = int(res.data[0:2], 16) route = route + res.data[2:(_len + 1 - 2) * 2] self.rsu.eventReport() self.rsu.close() uiLog(route)
def T_02_downloadBoot_A(product): u"下载Boot-写入Boot" versionFileName = SP("gs11.boot.filename", PARAM["defaultBootFile"], str) vf = getVersionFile(versionFileName) uiLog(u"版本文件:" + vf) __getNuLink(product.productSlot).downloadBoot(vf, verify=False) return {u"BOOT版本文件": versionFileName}
def T_10_currentTest_A(product): u"电流测试-电流测试" board = __downloadBoard() board.enterLowPowerMode(product.productSlot) time.sleep(0.6) board.switchMode(product.productSlot, "current") board.switchSampleResistance(product.productSlot, "20K") time.sleep(1) voltage = board.readVoltage(product.productSlot) readHighDC = 0 try: # if not (SP("cpc.voltage.low",0) <= voltage <= SP("cpc.voltage.high",1500)): # raise TestItemFailException(failWeight=10,message=u"电流测试不通过,值%d,阈值%d-%d"%\ # (voltage,SP("cpc.voltage.low",0),SP("cpc.voltage.high",1500))) readHighDC = board.choiceCrruentBadSlot(product.productSlot) if readHighDC >= 60: raise TestItemFailException(failWeight=10, message=u"电流波动大,02超限次数: %d" % readHighDC) finally: uiLog(u"槽[%d] , 测试版本超过门限电流的次数 : %d " % (int(product.productSlot), readHighDC)) uiLog(u"槽[%d] , 测试版本瞬时电流输出 : %d " % (int(product.productSlot), voltage)) board.switchSampleResistance(product.productSlot, "0.4") board.switchMode(product.productSlot, "download") time.sleep(0.02) return {u"电压": voltage}
def T_01_downloadVersion_A(product): u"下载版本-下载VAT版本" vdb = __getVersionDownloadBoard() channel = int(product.productSlot) vdb.powerOn(channel,True) time.sleep(0.3) sum3Vot = 0 for i in range(3): sum3Vot += vdb.readVoltage(channel) voltage = sum3Vot /3 #读3次,取平均 current = (voltage / 4096.0 * 3.3)/8*1000 # 毫安 uiLog(u"槽位[%d]电流:%3f"%(channel,current)) try: # 判断电压范围 # if voltage > 200: raise TestItemFailException(failWeight = 10,message = u"电流过大[%d]或者没有放置单板"%voltage) if current > PARAM["currentLimit"]: raise TestItemFailException(failWeight = 10,message = u"电流过大[%d]或者没有放置单板"%current) vdb.resetEnable(channel,True) vdb.dataClockEnable(channel,True) try: #vdb.reset(int(product.productSlot)) time.sleep(0.15) vdb.triggerDownload(channel) except Exception,e: # 第一次下载失败,那么复位一下,重试下载 #uiLog(u"槽位[%d]第一次版本下载失败:%s"%(channel,str(e))) #vdb.reset(channel) #time.sleep(0.5) #vdb.triggerDownload(channel) raise e except TestItemFailException,e: raise e
def T_04_writeOtherData_A(product): u"写入片内其他数据-配置地址0x40000,0x40080,0x40040的出厂数据" try: SKS.Senddataadd1(SKS.write_cmd, chr(0x00)) print u"地址0x40080写入数据:" readdata = '' readdata = SKS.revdata(10) #读取回复 resDataHex = SKS.hexShow(readdata) if SKS.RSP_FINISH in readdata: #执行完成回复码 uiLog(u"地址0x40080配置成功" + resDataHex) else: raise TestItemFailException(failWeight=10, message=u'地址0x40080配置失败' + resDataHex) SKS.Senddataadd2(SKS.write_cmd, chr(0x00)) readdata = '' readdata = SKS.revdata(10) #读取回复 resDataHex = SKS.hexShow(readdata) if SKS.RSP_FINISH in readdata: #执行完成回复码 uiLog(u"地址0x40040配置成功" + resDataHex) else: raise TestItemFailException(failWeight=10, message=u'地址0x40040配置失败' + resDataHex) except TestItemFailException, e: raise e
def bslWriteData(self,addressDataList): '''bsl方式写入参数,入参passwd:密码,addressDataList:[[地址,数据],[地址,数据]……],按顺序排列''' upload_data = memory.Memory() wholeStart = addressDataList[0][0] segmentStart = [0x1800,0x1880,0x1900,0x1980][int((wholeStart-0x1800)/0x80)] upload_data.append(memory.Segment(segmentStart, self.memory_read(segmentStart, 0x80))) for ad in addressDataList: address = ad[0] data = ad[1] upload_data.set(address, data) self.BSL_ERASE_SEGMENT(segmentStart) for segment in upload_data: print "Write segment at 0x%04x %d bytes\n" % (segment.startaddress, len(segment.data)) superUiLog("Write segment at 0x%04x %d bytes\n" % (segment.startaddress, len(segment.data))) data = segment.data if len(data) & 1: data += '\xff' self.memory_write(segment.startaddress, data) print 'bsl write successfully, starting read and verification.' uiLog(u"BSL 写入完成,正在校验...") for segment in upload_data: sg = self.memory_read(segment.startaddress, len(segment.data)) if sg != segment.data: raise print "verify %2.X OK"%segment.startaddress uiLog(u"BSL校验成功")
def T_03_updateInfoFields_A(product): u'''更新信息区数据-更新信息区数据''' sc = __askForPlateDeviceCom() readResult = sc.read_INFO( os.path.dirname(os.path.abspath(__file__)) + os.sep + "versions\\" + SESSION["versionFileName"], 0x1880) print "old CONFIG_BUILD_INFO:" + "".join(["%.2x" % c for c in readResult]) mac = bytearray([ int(SESSION["localMac"][i] + SESSION["localMac"][i + 1], 16) for i in range(0, len(SESSION["localMac"]), 2) ]) readResult[4] = mac[0] readResult[5] = mac[1] readResult[6] = mac[2] readResult[7] = mac[4] readResult[8] = int(SESSION["directIndicator"], 16) CONFIG_BUILD_INFO = readResult[:24] uiLog(u"开始写入CONFIG_BUILD_INFO,值:%s" % "".join(["%.2x" % c for c in CONFIG_BUILD_INFO])) sc.save_CONFIG_BUILD_INFO(CONFIG_BUILD_INFO) sc.finishBslWritten()
def T_05_esam_A(product): u'''ESAM测试-仅测试ESAM功能是否正常''' sc = board_digital.__askForPlateDeviceCom() response = sc.sendAndGet(request='TestESAM').strip() if response.startswith("TestESAMOK"): esam = response[11:] esamId = esam[22:30] uiLog(u"ESAM功能正常,地区分散码的验证请回到大线确定") return {"ESAM": esam, "ESAMID": esamId} elif response == "ResetFail": raise TestItemFailException(failWeight=10, message=u'ESAM复位失败,可能是焊接不良') elif response == "SelectMFFail": raise TestItemFailException(failWeight=10, message=u'ESAM选择MF文件失败,可能是焊接不良') elif response.startswith("SelectMFErrCode"): code = response[-2:] raise TestItemFailException(failWeight=10, message=u'ESAM选择MF文件错误,错误码:' + code) elif response == "ReadSysInfoFail": raise TestItemFailException(failWeight=10, message=u'ESAM读系统信息失败') elif response.startswith("ReadSysInfoErrCode"): code = response[-2:] raise TestItemFailException(failWeight=10, message=u'ESAM读系统信息返回错误,错误码:' + code) elif response == "SelectDFFail": raise TestItemFailException(failWeight=10, message=u'ESAM选择DF文件失败') elif response.startswith("SelectDFErrCode"): code = response[-2:] raise TestItemFailException(failWeight=10, message=u'ESAM选择DF文件返回错误,错误码:' + code)
def T_00_scanBarCode_A(product): u'''扫描条码-扫描条码,成功后合上夹具''' barCode = askForSomething(u"扫描条码", u"请扫描单板条码") while not __checkBarCode(barCode): barCode = askForSomething(u"扫描条码", u"条码扫描错误,请重新扫描") uiLog(u'单板条码扫描结果:' + barCode) product.setTestingSuiteBarCode(barCode) __closeClapFinallyAndStartTest(product)
def T_05_routeSign_A(product): u"路径标识-模拟路径标识信息" rsu = ENTRY.__getRsu() rsu.HFCloseRF() time.sleep(2) testRouteInfo = rsu.integrateCpcSignRoute(PARAM["psamSlotId"],product.getTestingProductIdCode()) uiLog(u"测试模拟路径:%s"%testRouteInfo) product.param["testRouteInfo"] = testRouteInfo
def detectingMonophonicResults(data): # 分析CPC单音测试结果 uiLog(u"CPC单音测试信号强度:%s" % ord(data[-3])) c = PARAM["minMonophonicSignalStrength"] <= ord( data[-3]) <= PARAM["maxMonophonicSignalStrength"] if not c: raise TestItemFailException(failWeight=10, message=u"CPC单音测试结果值: %s" % ord(data[-3]))
def T_04_downloadVatVersion_A(product): u"下载VAT版本-下载测试用的VAT版本" versionFileName = SP("gs11.vatVersion.filename", PARAM["defaultVatVersionFile"], str) vf = getVersionFile(versionFileName) uiLog(u"版本文件:" + vf) __getNuLink(product.productSlot).downloadVersion(vf, verify=False) return {u"VAT版本文件": versionFileName}
def detectBSTResults(data, item, detectParam): # 分析CPC BST测试结果 uiLog(u"CPC%s试结果:%s" % (item, ord(data[-3]))) c = ord(data[-3]) < detectParam if c: raise TestItemFailException(failWeight=10, message=u"CPC%s测试结果值: %s" % (item, ord(data[-3])))
def T_02_downloadVersionToBoard_A(product): u"下载版本到板卡-通过Nulink下载版本到板卡" versionFileName = SP("gs11.vatVersion.filename", PARAM["defaultVatVersionFile"], str) vf = getVersionFile(versionFileName) uiLog(u"开始下载槽位[%s],版本文件:%s" % (product.productSlot, vf)) __getNuLink(1).downloadVersion(vf, verify=False) uiLog(u"槽位[%s]版本下载成功,正在复位芯片" % product.productSlot)
def cpcHfActive(self): # 高频唤醒, self.__record('cpcHfactive.rq', u'send') ret,dataLength,Data,ReturnStatus = self.reader.HFActive(200) uiLog("cpcHfactive.rp: ret=%d,dataLength=%d,Data=%s,ReturnStatus=%d"%(ret,dataLength,Data,ReturnStatus)) if ret !=0: self.__record('cpcHfactive.rp', u'接收异常 error code = %d'%(ret)) raise TestItemFailException(failWeight = 10,message = u'高频唤醒失败')
def activePasm(self,psamSoftId): #复位PSAM self.__record('active psam_rq', 'send') ret, rlen, Data = self.reader.PSAM_Reset(psamSoftId, 0) uiLog('activePasm: ret=%d,len=%d,data=%s' % (ret, rlen, Data)) if ret != 0: self.__record('active psam_rp', u'通信异常 error code = %d' % ret) raise AbortTestException(message = u"复位PSAM失败") self.__record('active psam_rp', 'success')
def iccHFSelectDf01(self): APDU = "0700A40000021001" self.__record('iccHFSelectDf01.rq', u'send') ret, APDULIST, Data, ReturnStatus = self.reader.HFCmd(1, APDU) uiLog("iccHFSelectDf01.rp: ret=%dAPDULIST=%d,Data=%s,ReturnStatus=%d" % (ret, APDULIST, Data, ReturnStatus)) if ret != 0 or ReturnStatus != 0: self.__record('iccHFSelectDf01.rp', u'接收异常 error code = %d' % (ret)) raise TestItemFailException(failWeight = 10,message = u'iccHFSelectDf01异常:ret=%d,ReturnStatus=%d'%(ret,ReturnStatus)) self.__record('cpcHFSelectDf01.rp', u'success')