def __init__(self, eng, k): super(GWPSTester, self).__init__(eng) self.eng = eng self.k = k self.uploader = SpyUploader() self.init() self.setup_eng1()
def __init__(self, eng): super(RfTester, self).__init__() self.eng = eng self.eng.retry = 5 self.eng.add_rpc_func("tellVmStat", self.tellVmStat) self.eng.add_rpc_func("su_recvd_reboot", self.su_recvd_reboot) self.eng.set_hook( snap.hooks.HOOK_OTA_UPGRADE_COMPLETE, self.upgrade_complete_hook) self.eng.set_hook( snap.hooks.HOOK_OTA_UPGRADE_STATUS, self.upgrade_status_hook) self.uploader = SpyUploader()
class GWPSTester(rftester.RfTester): def __init__(self, eng, k): super(GWPSTester, self).__init__(eng) self.eng = eng self.k = k self.uploader = SpyUploader() self.init() self.setup_eng1() def setup_eng1(self): self.eng.open_usb_serial(eng1_usb_serial) self.eng.disable_crc(eng1_mac) eng1_os_version_read = self.eng.read_snappy_os_version(eng1_mac) print 'eng1_os_version_read =', eng1_os_version_read if eng1_os_version_read != eng1_firmware_version: self.firmware_upgrade(eng1_mac, eng1_firmware_file) sleep(2) # self.spy_up(eng1_mac, eng1_spy_file) self.eng.close_usb_serial(eng1_usb_serial) def finishedSpyUpgrade(self, errCode): self.errCode = errCode def tellVmStat(self, arg, val): try: print '.', if self.uploader.snapConn: self.uploader.snapConn.spy_upload_mgr.onTellVmStat( self.uploader.snapConn.rpc_source_addr(), arg, val) except AttributeError: pass def su_recvd_reboot(self, dummy): try: if self.uploader.snapConn: self.uploader.snapConn.spy_upload_mgr.on_recvd_reboot( self.uploader.snapConn.rpc_source_addr()) except AttributeError: pass def spy_up(self, mac, spy_file): self.uploader.assign_SnapCom(self.eng) self.uploader.assign_Callback(self) #self.eng.save_nv_param(snap.NV_FEATURE_BITS_ID, 0) self.uploader.beginUpload(mac, spy_file) while self.uTurnPSOffploader.progInProgress: self.eng.poll() while self.uploader.progInProgress: self.eng.poll() errmsg = "spy_uploader_errCode = %s" % str(self.errCode) if self.errCode != snap.SNAPPY_PROGRESS_COMPLETE: raise Exception(errmsg) def upgrade_complete_hook(self, addr, status, message): self.upgrade_status = status if status == snap.OTA_PROGRESS_COMPLETE: print("Upgrade Complete for %r" % addr) else: print("Upgrade Failed for %r: %r (Status=%r)" % (addr, message, status)) def upgrade_status_hook(self, addr, percent_complete): # This displays a percentage complete, # but it prints a lot so you might not want it on print("Upgrade Status: %r %r" % (addr, percent_complete)) pass def firmware_upgrade(self, mac, firmware_file): self.upgrade_status = None upgrade = self.eng.upgrade_firmware(mac, firmware_file) if not upgrade: raise Exception("Something went wrong while starting the upgrade!") while self.upgrade_status is None: self.eng.poll() def start_loop(self): wo = scan_workorder_number() while True: self.k.TurnPSOff() sn = scan_serial_number() if sn == '0': self.k.TurnPSOff() break while raw_input('Place the board on the fixture,\n' 'close the fixture, and then\n' 'press Enter to start the test') != '': pass self.e20pstester(wo, sn) def alt_buzz(self, sn): if self.passed: sounder.play(sound_passed_clap, repeat=False) sounder.sound_and_confirm('%s has passed the test' % sn, sound_passed, repeat=True) tp5_poly else: sounder.play(sound_failed_noo, repeat=Ftp5_polyalseself) sounder.sound_and_confirm('%s has failed the test' % sn, sound_failed, repeat=True) def buzz(self, sn): if self.passed: sounder.sound_and_confirm('%s has passed the test' % sn, sound_passed, repeat=True) else: sounder.sound_and_confirm('%s has failed the test' % sn, sound_failed, repeat=True) def BK_TurnPSOff(self): # channel 1 self.k.TurnPSOff() def BK_TurnPSOn(self): # channel 1 self.k.TurnPSOn() def powerOn(self): print "Powering UUT On" self.BK_TurnPSOn() sleep(2)# Pause to allow powerup return True def powerOff(self): print "Powering UUT Off" self.BK_TurnPSOff() sleep(2)# Pause to allow powerup return True def init(self): if (DEBUG): print "--> init: Initilizing serial communications" self.eng.open_usb_serial(eng1_usb_serial) self.eng.disable_crc(eng1_mac) self.eng.call(eng1_mac, 'txPwr', 0) self.eng.print_info('eng1', eng1_mac) # self.eng.close_usb_serial(eng1_usb_serial) if (DEBUG): print "--> init: Initilizing BK 1788 Power Supply" self.k.SetMaxVoltage(24.0) self.k.SetOutCurrent(5.0) self.k.SetRemoteControl() self.k.SetOutVoltage(12.0) self.eng.call(hl_enb_mac, 'setPinDir', hl_enb_gpio, True) self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, True) self.eng.call(fl_enb_mac, 'setPinDir', fl_enb_gpio, True) self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, False) self.eng.call(tp1_24v_meas_mac, 'setPinDir', tp1_24v_meas_channel, False) self.eng.call(tp3_24v_meas_mac, 'setPinDir', tp3_24v_meas_channel, False) self.eng.call(tp4_5v_meas_mac, 'setPinDir', tp4_5v_meas_channel, False) self.eng.call(tp5_5v_meas_mac, 'setPinDir', tp5_5v_meas_channel, False) self.eng.call(tp7_5v_meas_mac, 'setPinDir', tp7_5v_meas_channel, False) #======================================================= #======================================================= #TODO -- Insert header data log print def e20pstester(self, wo, sn): try: self.sequence_start( sn, self.__class__.__name__, get_revision()) self.init() vfile = open('results.csv','ab') sleep(1) # ---------------------------------------------------------- # Initialize # ---------------------------------------------------------- self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, True) self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, True) # ----------------------------------------------Turn on Power self.powerOn() # sleep(1) # ---------------------------------------------------------- #======================================================= # PASS 1 #======================================================= print "-------------------------------" print " Supply Measurement - @ 12 Vin" print "-------------------------------" # self.step('tp1_12v_meas', # (self.eng.read_voltage, # tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_poly), # '%.3f', lim=limit_tp1_12v, unit='V') #TODO -- Insert data log print # ---------------------------Check Input Power Secondary stage (TP3) # self.step('tp3_meas', # (self.eng.read_voltage, # tp3_24v_meas_mac, tp3_24v_meas_channel, tp3_poly), # '%.3f', lim=limit_tp4_0v, unit='V') # ---------------------------Check Input Power Secondary stage (TP5) self.step('tp5_5v_meas', (self.eng.read_voltage, tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), '%.3f', lim=limit_tp5_5v, unit='V') # # -----------------------------------------Check Output Power (TP7) self.step('tp7_5v_meas', (self.eng.read_voltage, tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), '%.3f', lim=limit_tp7_5v, unit='V') # ---------------------------Check Input Power Secondary stage (TP4) self.step('tp4_5v_meas', (self.eng.read_voltage, tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), '%.3f', lim=limit_tp4_5v, unit='V') # # ---------------------------------------------------------- # # Setup gpio for Half-Load current loading # # ---------------------------------------------------------- # self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, True) # self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, True) # # ---------------------------------------------------------- # # # --------------------------------------------Check Input Power (TP1) # print "-----------------------------" # print "Supply Measurement - Pass 1 B" # print "-----------------------------" # ## self.step('tp1_12v_meas', ## (self.eng.read_voltage, ## tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp1_12v, unit='V') # #TODO -- Insert data log print # # ---------------------------Check Input Power Secondary stage (TP3) ## self.step('tp3_12v_meas', ## (self.eng.read_voltage, ## tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp4_0v, unit='V') # # ---------------------------Check Input Power Secondary stage (TP5) # self.step('tp5_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp5_5v, unit='V') # # ## # -----------------------------------------Check Output Power (TP7) # self.step('tp7_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp7_5v, unit='V') # # # ---------------------------Check Input Power Secondary stage (TP4) # self.step('tp4_5v_meas', # (self.eng.read_voltage, # tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), # '%.3f', lim=limit_tp4_5v, unit='V') # # # ---------------------------------------------------------- # # Setup gpio for Half-Load current loading # # ---------------------------------------------------------- # self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, False) # self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, True) # # ---------------------------------------------------------- # print "-----------------------------" # print "Supply Measurement - Pass 1 C" # print "-----------------------------" # ## self.step('tp1_12v_meas', ## (self.eng.read_voltage, ## tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp1_12v, unit='V') # #TODO -- Insert data log print # # ---------------------------Check Input Power Secondary stage (TP3) ## self.step('tp3_12v_meas', ## (self.eng.read_voltage, ## tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp4_0v, unit='V') ### tp3_24v_meas_channel),) # # ---------------------------Check Input Power Secondary stage (TP5) # self.step('tp5_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp5_5v, unit='V') # # ## # -----------------------------------------Check Output Power (TP7) # self.step('tp7_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp7_5v, unit='V') # # # ---------------------------Check Input Power Secondary stage (TP4) # self.step('tp4_5v_meas', # (self.eng.read_voltage, # tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), # '%.3f', lim=limit_tp4_5v, unit='V') # ---------------------------------------------------------- # Turn Off Power to UUT # ---------------------------------------------------------- self.powerOff() # ---------------------------------------------------------- # Change Power to 18.0v # ---------------------------------------------------------- self.k.SetOutVoltage(18.0) # ---------------------------------------------------------- # Turn On Power to UUT # ---------------------------------------------------------- self.powerOn() # sleep(3) # # Disable Half Load and full load self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, False) self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, False) #======================================================= # PASS # 2 #======================================================= # ---------------------------------------------------------- print "-------------------------------" print " Supply Measurement - @ 18 Vin" print "-------------------------------" # self.step('tp1_18v_meas', # (self.eng.read_voltage, # tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_18_poly), # '%.3f', lim=limit_tp1_18v, unit='V') #TODO -- Insert data log print # self.step('tp3_12v_meas', # (self.eng.read_voltage, # tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), # '%.3f', lim=limit_tp4_0v, unit='V') # ---------------------------Check Input Power Secondary stage (TP3) # self.step('tp3_12v_meas', # (self.eng.read_voltage, # tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), # '%.3f', lim=limit_tp4_0v, unit='V') # ---------------------------Check Input Power Secondary stage (TP5) self.step('tp5_5v_meas', (self.eng.read_voltage, tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), '%.3f', lim=limit_tp5_5v, unit='V') # # -----------------------------------------Check Output Power (TP7) self.step('tp7_5v_meas', (self.eng.read_voltage, tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), '%.3f', lim=limit_tp7_5v, unit='V') # ---------------------------Check Input Power Secondary stage (TP4) self.step('tp4_5v_meas', (self.eng.read_voltage, tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), '%.3f', lim=limit_tp4_5v, unit='V') # # ---------------------------------------------------------- # # Setup gpio for Half-Load current loading # # ---------------------------------------------------------- # self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, True) # self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, True) # # ---------------------------------------------------------- # # # --------------------------------------------Check Input Power (TP1) # print "-----------------------------" # print "Supply Measurement - Pass 2 B" # print "-----------------------------" # ## self.step('tp1_18v_meas', ## (self.eng.read_voltage, ## tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_18_poly), ## '%.3f', lim=limit_tp1_18v, unit='V') # #TODO -- Insert data log print # # ---------------------------Check Input Power Secondary stage (TP3) ## self.step('tp3_12v_meas', ## (self.eng.read_voltage, ## tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp4_0v, unit='V') # # ---------------------------Check Input Power Secondary stage (TP5) # self.step('tp5_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp5_5v, unit='V') # ## # -----------------------------------------Check Output Power (TP7) # self.step('tp7_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp7_5v, unit='V') # # # ---------------------------Check Input Power Secondary stage (TP4) # self.step('tp4_5v_meas', # (self.eng.read_voltage, # tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), # '%.3f', lim=limit_tp4_5v, unit='V') # # ## # ---------------------------------------------------------- ## # Setup gpio for Half-Load current loading ## # ---------------------------------------------------------- # self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, False) # self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, True) # # ---------------------------------------------------------- # print "-----------------------------" # print "Supply Measurement - Pass 2 C" # print "-----------------------------" # ## self.step('tp1_18v_meas', ## (self.eng.read_voltage, ## tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_18_poly), ## '%.3f', lim=limit_tp1_18v, unit='V') # #TODO -- Insert data log print # # ---------------------------Check Input Power Secondary stage (TP3) ## self.step('tp3_12v_meas', ## (self.eng.read_voltage, ## tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp4_0v, unit='V') # # ---------------------------Check Input Power Secondary stage (TP5) # self.step('tp5_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp5_5v, unit='V') # ## # -----------------------------------------Check Output Power (TP7) # self.step('tp7_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp7_5v, unit='V') # # # ---------------------------Check Input Power Secondary stage (TP4) # self.step('tp4_5v_meas', # (self.eng.read_voltage, # tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), # '%.3f', lim=limit_tp4_5v, unit='V') # ---------------------------------------------------------- # Turn Off Power to UUT # ---------------------------------------------------------- self.powerOff() # ---------------------------------------------------------- # Change Power to 24.0v # ---------------------------------------------------------- self.k.SetOutVoltage(24.0) # ---------------------------------------------------------- # Turn On Power to UUT # ---------------------------------------------------------- self.powerOn() # sleep(2) # # Disable Half Load and full load self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, True) self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, True) #======================================================= # PASS # 3 #======================================================= # --------------------------------------------Check Input Power (TP1) print "-------------------------------" print " Supply Measurement - @ 24 Vin " print "-------------------------------" # self.step('tp1_24v_meas', # (self.eng.read_voltage, # tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_24_poly), # '%.3f', lim=limit_tp1_24v, unit='V') #TODO -- Insert data log print # ---------------------------Check Input Power Secondary stage (TP3) # self.step('tp3_12v_meas', # (self.eng.read_voltage, # tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), # '%.3f', lim=limit_tp4_0v, unit='V') # ----------- self.step('tp3_12v_meas', # (self.eng.read_voltage, # tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), # '%.3f', lim=limit_tp4_0v, unit='V') #----------------Check Input Power Secondary stage (TP5) self.step('tp5_5v_meas', (self.eng.read_voltage, tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), '%.3f', lim=limit_tp5_5v, unit='V') # # -----------------------------------------Check Output Power (TP7) self.step('tp7_5v_meas', (self.eng.read_voltage, tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), '%.3f', lim=limit_tp7_5v, unit='V') # ---------------------------Check Input Power Secondary stage (TP4) self.step('tp4_5v_meas', (self.eng.read_voltage, tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), '%.3f', lim=limit_tp4_5v, unit='V') # # ---------------------------------------------------------- # # Setup gpio for Half-Load current loading # # ---------------------------------------------------------- # self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, False) # self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, True) # # ---------------------------------------------------------- ## self.step('tp3_12v_meas', ## (self.eng.read_voltage, ## tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp4_5v, unit='V') # # # --------------------------------------------Check Input Power (TP1) # print "-----------------------------" # print "Supply Measurement - Pass 3 B" # print "-----------------------------" # ## self.step('tp1_24v_meas', ## (self.eng.read_voltage, ## tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_24_poly), ## '%.3f', lim=limit_tp1_24v, unit='V') # #TODO -- Insert data log print # # ---------------------------Check Input Power Secondary stage (TP3) ## self.step('tp3_12v_meas', ## (self.eng.read_voltage, ## tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp4_0v, unit='V') # # ---------------------------Check Input Power Secondary stage (TP5) # self.step('tp5_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp5_5v, unit='V') # ## # -----------------------------------------Check Output Power (TP7) # self.step('tp7_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp7_5v, unit='V') # # # ---------------------------Check Input Power Secondary stage (TP4) # self.step('tp4_5v_meas', # (self.eng.read_voltage, # tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), # '%.3f', lim=limit_tp4_5v, unit='V') # # ## # ---------------------------------------------------------- ## # Setup gpio for Half-Load current loading ## # ---------------------------------------------------------- # self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, False) # self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, False) # # ---------------------------------------------------------- # print "-----------------------------" # print "Supply Measurement - Pass 3 C" # print "-----------------------------" # ## self.step('tp1_24v_meas', ## (self.eng.read_voltage, ## tp1_12v_meas_mac, tp1_12v_meas_channel, tp1_24_poly), ## '%.3f', lim=limit_tp1_24v, unit='V') # #TODO -- Insert data log print ## # ---------------------------Check Input Power Secondary stage (TP3) ## self.step('tp3_12v_meas', ## (self.eng.read_voltage, ## tp3_24v_meas_mac, tp3_24v_meas_channel, tp1_poly), ## '%.3f', lim=limit_tp4_5v, unit='V') # # ---------------------------Check Input Power Secondary stage (TP5) # self.step('tp5_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp5_5v, unit='V') # ## # -----------------------------------------Check Output Power (TP7) # self.step('tp7_5v_meas', # (self.eng.read_voltage, # tp5_5v_meas_mac, tp5_5v_meas_channel, tp5_poly), # '%.3f', lim=limit_tp7_5v, unit='V') # # # ---------------------------Check Input Power Secondary stage (TP4) # self.step('tp4_5v_meas', # (self.eng.read_voltage, # tp4_5v_meas_mac, tp4_5v_meas_channel, tp4_poly), # '%.3f', lim=limit_tp4_5v, unit='V') # ---------------------------------------------------------- # Turn Off Power to UUT # ---------------------------------------------------------- self.powerOff() # vstring = (time.strftime('%x %X') + "," + hostname + "," + wo \ # + "," + sn + "\n") vstring = (time.strftime('%x %X') + "," + wo + ","\ + hostname + "," + sn + "," + "\n") #write string to file print '========---Writing Data to file---=======' vfile.write(vstring) vfile.close() #------------------------------------------------------------------------ # End of Test #------------------------------------------------------------------------ except: self.powerOff() self.passed = False print 'Exception while testing:', sn print '-' * 60 traceback.print_exc(file=sys.stdout) print '-' * 60 finally: self.powerOff() try: self.init() except: pass self.sequence_finish() tester.print_outcome(self.passed) self.alt_buzz(sn)
class RfTester(tester.Tester): def __init__(self, eng): super(RfTester, self).__init__() self.eng = eng self.eng.retry = 5 self.eng.add_rpc_func("tellVmStat", self.tellVmStat) self.eng.add_rpc_func("su_recvd_reboot", self.su_recvd_reboot) self.eng.set_hook( snap.hooks.HOOK_OTA_UPGRADE_COMPLETE, self.upgrade_complete_hook) self.eng.set_hook( snap.hooks.HOOK_OTA_UPGRADE_STATUS, self.upgrade_status_hook) self.uploader = SpyUploader() def tellVmStat(self, arg, val): try: print '.', if self.uploader.snapConn: self.uploader.snapConn.spy_upload_mgr.onTellVmStat( self.uploader.snapConn.rpc_source_addr(), arg, val) except AttributeError: pass def su_recvd_reboot(self, dummy): try: if self.uploader.snapConn: self.uploader.snapConn.spy_upload_mgr.on_recvd_reboot( self.uploader.snapConn.rpc_source_addr()) except AttributeError: pass def spy_up(self, mac, spy_file, unreset_delay=None, unreset_func=None): self.errCode = None val = None self.uploader.assign_SnapCom(self.eng) self.uploader.assign_Callback(self) #self.eng.save_nv_param(snap.NV_FEATURE_BITS_ID, 0) self.uploader.beginUpload(mac, spy_file) unreset_time = time() + unreset_delay if unreset_delay else None while self.uploader.progInProgress: self.eng.poll() if unreset_time: if time() >= unreset_time: val = unreset_func() if isinstance( unreset_func, collections.Callable ) else unreset_func[0](*unreset_func[1:]) unreset_time = None #self.eng.save_nv_param(snap.NV_FEATURE_BITS_ID, 0x100) #if self.errCode != snap.SNAPPY_PROGRESS_COMPLETE: #self.uploader.beginUpload(mac, spy_file) #while self.uploader.progInProgress: #self.eng.poll() #self.uploader.beginUpload(mac, spy_file) #while self.uploader.progInProgress: #self.eng.poll() if self.errCode != snap.SNAPPY_PROGRESS_COMPLETE: raise Exception("spy_uploader_errCode = %s" % str(self.errCode)) return val def finishedSpyUpgrade(self, errCode): """Report the final result to the user""" # How to format and print the result is up to you self.errCode = errCode print "errCode=" + str(errCode) def upgrade_complete_hook(self, addr, status, message): self.upgrade_status = status #if status == snap.OTA_PROGRESS_COMPLETE: #print("Upgrade Complete for %r" % addr) #else: #print("Upgrade Failed for %r: %r (Status=%r)" % #(addr, message, status)) def upgrade_status_hook(self, addr, percent_complete): # This displays a percentage complete, # but it prints a lot so you might not want it on print("Upgrade Status: %r %r" % (addr, percent_complete)) pass def firmware_upgrade(self, mac, firmware_file, unreset_delay=None, unreset_func=None): self.upgrade_status = None val = None upgrade = self.eng.upgrade_firmware(mac, firmware_file) unreset_time = time() + unreset_delay if unreset_delay else None if not upgrade: raise Exception("Something went wrong while starting the upgrade!") while self.upgrade_status is None: self.eng.poll() if unreset_time: if time() >= unreset_time: print 'calling unreset' val = unreset_func() if isinstance( unreset_func, collections.Callable ) else unreset_func[0](*unreset_func[1:]) unreset_time = None return val
class GWPSTester(tester.Tester): def __init__(self, eng): super(GWPSTester, self).__init__() self.eng = eng self.eng.add_rpc_func("tellVmStat", self.tellVmStat) self.eng.add_rpc_func("su_recvd_reboot", self.su_recvd_reboot) self.eng.set_hook( snap.hooks.HOOK_OTA_UPGRADE_COMPLETE, self.upgrade_complete_hook) self.eng.set_hook( snap.hooks.HOOK_OTA_UPGRADE_STATUS, self.upgrade_status_hook) self.errCode = None self.uploader = SpyUploader() self.setup_eng1() self.init() def setup_eng1(self): self.eng.enable_crc(eng1_mac) eng1_os_version_read = self.eng.read_snappy_os_version(eng1_mac) print 'eng1_os_version_read =', eng1_os_version_read if eng1_os_version_read != eng1_firmware_version: self.firmware_upgrade(eng1_mac, eng1_firmware_file) sleep(2) self.spy_up(eng1_mac, eng1_spy_file) def finishedSpyUpgrade(self, errCode): self.errCode = errCode def tellVmStat(self, arg, val): try: print '.', if self.uploader.snapConn: self.uploader.snapConn.spy_upload_mgr.onTellVmStat( self.uploader.snapConn.rpc_source_addr(), arg, val) except AttributeError: pass def su_recvd_reboot(self, dummy): try: if self.uploader.snapConn: self.uploader.snapConn.spy_upload_mgr.on_recvd_reboot( self.uploader.snapConn.rpc_source_addr()) except AttributeError: pass def spy_up(self, mac, spy_file): self.uploader.assign_SnapCom(self.eng) self.uploader.assign_Callback(self) #self.eng.save_nv_param(snap.NV_FEATURE_BITS_ID, 0) self.uploader.beginUpload(mac, spy_file) while self.uploader.progInProgress: self.eng.poll() #self.eng.save_nv_param(snap.NV_FEATURE_BITS_ID, 0x100) #if self.errCode != snap.SNAPPY_PROGRESS_COMPLETE: #self.uploader.beginUpload(mac, spy_file) #while self.uploader.progInProgress: #self.eng.poll() #self.uploader.beginUpload(mac, spy_file) while self.uploader.progInProgress: self.eng.poll() errmsg = "spy_uploader_errCode = %s" % str(self.errCode) if self.errCode != snap.SNAPPY_PROGRESS_COMPLETE: raise Exception(errmsg) def upgrade_complete_hook(self, addr, status, message): self.upgrade_status = status if status == snap.OTA_PROGRESS_COMPLETE: print("Upgrade Complete for %r" % addr) else: print("Upgrade Failed for %r: %r (Status=%r)" % (addr, message, status)) def upgrade_status_hook(self, addr, percent_complete): # This displays a percentage complete, # but it prints a lot so you might not want it on print("Upgrade Status: %r %r" % (addr, percent_complete)) pass def firmware_upgrade(self, mac, firmware_file): self.upgrade_status = None upgrade = self.eng.upgrade_firmware(mac, firmware_file) if not upgrade: raise Exception("Something went wrong while starting the upgrade!") while self.upgrade_status is None: self.eng.poll() def start_loop(self): while True: sn = scan_serial_number() if sn == '0': break while raw_input('Place the board on the fixture,\n' 'close the fixture, and then\n' 'press Enter to start the test') != '': pass self.runtest(sn) def buzz(self, sn): if self.passed: sounder.sound_and_confirm('%s has passed the test' % sn, sound_passed, repeat=True) else: sounder.sound_and_confirm('%s has failed the test' % sn, sound_failed, repeat=True) def init(self): self.set_power_state(PowerState.off) self.eng.call(tp_sgnd_mac, 'setPinDir', tp_sgnd_gpio, False) self.eng.call(tp_sgnd_mac, 'setPinPullup', tp_sgnd_gpio, False) self.eng.call(tp_dco_mac, 'setPinDir', tp_dco_gpio, True) self.eng.call(tp_dco_mac, 'writePin', tp_dco_gpio, False) self.eng.call(tp_3p3v_meas_mac, 'setPinDir', tp_3p3v_meas_gpio, False) self.set_i2c_address(None) # disable 24V self.eng.call(tp_24v_ena_mac, 'setPinDir', tp_24v_ena_gpio, True) self.eng.call(tp_24v_ena_mac, 'writePin', tp_24v_ena_gpio, True) #======================================================= # Control UUT Power #======================================================= def set_power_state(self, state): if state == PowerState.off: # disable 3.3V A self.eng.call(tp_3p3v_ena_mac, 'setPinDir', tp_3p3v_ena_gpio, True) self.eng.call(tp_3p3v_ena_mac, 'writePin', tp_3p3v_ena_gpio, False) # disable 3.3V B self.eng.call(tp_3p3v_enb_mac, 'setPinDir', tp_3p3v_enb_gpio, True) self.eng.call(tp_3p3v_enb_mac, 'writePin', tp_3p3v_enb_gpio, False) elif state == PowerState.on: # disable 3.3V A self.eng.call(tp_3p3v_ena_mac, 'setPinDir', tp_3p3v_ena_gpio, True) self.eng.call(tp_3p3v_ena_mac, 'writePin', tp_3p3v_ena_gpio, False) # disable 3.3V B self.eng.call(tp_3p3v_enb_mac, 'setPinDir', tp_3p3v_enb_gpio, True) self.eng.call(tp_3p3v_enb_mac, 'writePin', tp_3p3v_enb_gpio, True) elif state == PowerState.bothhigh: raise Exception('Because of a broken test board,' ' this mode is currently not supported') else: raise Exception('Unexpected Parameter') #======================================================= # i2c #======================================================= def set_i2c_address(self, addr): if addr is None: self.eng.call(tp_addr_sel_mac, 'setPinDir', tp_addr_sel_gpio, False) elif addr == 0: self.eng.call(tp_addr_sel_mac, 'setPinDir', tp_addr_sel_gpio, True) self.eng.call(tp_addr_sel_mac, 'writePin', tp_addr_sel_gpio, False) elif addr == 1: self.eng.call(tp_addr_sel_mac, 'setPinDir', tp_addr_sel_gpio, True) self.eng.call(tp_addr_sel_mac, 'writePin', tp_addr_sel_gpio, False) else: raise Exception('i2c addr parameter has to be 0 or 1 or None') self.i2c_address = addr if addr else 1 #======================================================= # Programming #======================================================= def program(self): program_retry = 1 while True: try: if program_retry > 1: self.log('programming attempt #%d' % program_retry) with MspDebug() as mspdebug: mspdebug.send('prog %s\r\n' % gwps_firmware_file) mspdebug.ex('Erasing...', ex_timeout=5) mspdebug.ex('Writing 4096 bytes at e000...', ex_timeout=5) mspdebug.ex('Writing 4062 bytes at f000...', ex_timeout=5) mspdebug.ex('Writing 32 bytes at ffe0...', ex_timeout=5) mspdebug.ex('Done, 8190 bytes total', ex_timeout=5) mspdebug.ex('(mspdebug) ', ex_timeout=5) mspdebug.send('verify %s\r\n' % gwps_firmware_file) mspdebug.ex('Verifying 4096 bytes at e000...', ex_timeout=5) mspdebug.ex('Verifying 4062 bytes at f000...', ex_timeout=5) mspdebug.ex('Verifying 32 bytes at ffe0...', ex_timeout=5) mspdebug.ex('Done, 8190 bytes total', ex_timeout=5) mspdebug.ex('(mspdebug) ', ex_timeout=5) return except: sleep(.5) program_retry += 1 if program_retry > 3: raise Exception('Programming the STM8 failed') #======================================================= # readCurrent #======================================================= def readCurrent(self, ix): rc = self.eng.call(eng1_mac, 'readCurrent', self.i2c_address, ix) rci = struct.unpack("<I", rc) #print repr(rc), rci, type(rci) return rci[0] #======================================================= # #======================================================= def turnOnAndReadVersion(self, retry=10): while True: try: self.set_power_state(PowerState.on) sleep(2) self.eng.call(eng1_mac, 'i2cInit', False) sleep(1) retval = self.eng.call( eng1_mac, 'getSCBVersion', self.i2c_address) if retval is None: raise Exception('getSCBVersion returned None') if len(retval) == 0: raise Exception('getSCBVersion returned zero length') return retval except: retry -= 1 if retry == 0: raise Exception( 'Cannot communicate with the UUT through I2C') self.set_power_state(PowerState.off) sleep(1) #======================================================= # #======================================================= #TODO -- Insert header data log print def runtest(self, sn): try: self.sequence_start( sn, self.__class__.__name__, get_revision()) self.log( 'tp_3v3_isol_max_error: %.3f[Volt]' % tp_3v3_isol_max_error) self.init() sleep(1) # ---------------------------------------------------------- # Initialize # ---------------------------------------------------------- #TODO Setup gpio for no current loading # ----------------------------------------------Turn on Power self.set_power_state(PowerState.on) # ----------------------------------------------Check Input Power (TP1) if input_power_check_enabled: self.step( 'tp1_24v_meas', [self.eng.read_voltage, tp1_24v_meas_mac, tp1_24v_meas_channel, 0.00], '%.3f', retry=5, lim='x > 23.5 and x < 24.5' #TODO -- Insert data log print ) # ----------------------------------------------Check Input Power Secondary stage (TP3) self.step( 'tp3_24v_meas', [self.eng.read_voltage, tp3_24v_meas_mac, tp3_24v_meas_channel, 0.00], '%.3f', retry=5, lim='x > 23.5 and x < 24.5' #TODO -- Insert data log output ) # ----------------------------------------------Check Input Power Secondary stage (TP4) self.step( 'tp4_5v_meas', [self.eng.read_voltage, tp4_5v_meas_mac, tp4_5v_meas_channel, 0.00], '%.3f', retry=5, lim='x > 4.75 and x < 5.25' #TODO -- Insert data log output ) # ----------------------------------------------Check Input Power Secondary stage (TP5) self.step( 'tp5_5v_meas', [self.eng.read_voltage, tp4_5v_meas_mac, tp4_5v_meas_channel, 0.00], '%.3f', retry=5, lim='x > 4.75 and x < 5.25' #TODO -- Insert data log output ) # ----------------------------------------------Check Output Power (TP7) self.step( 'tp7_5v_meas', [self.eng.read_voltage, tp7_5v_meas_mac, tp7_5v_meas_channel, 0.00], '%.3f', retry=5, lim='x > 4.75 and x < 5.25' #TODO -- Insert data log output ) # ---------------------------------------------------------- # Setup gpio for Half-Load current loading # ---------------------------------------------------------- #hl_enb_mac # Enable Half Load self.eng.call(hl_enb_mac, 'setPinDir', hl_enb_gpio, True) self.eng.call(hl_enb_mac, 'writePin', hl_enb_gpio, False) # ----------------------------------------------Check Output Power under half load(TP7) self.step( 'tp7_5v_meas', [self.eng.read_voltage, tp7_5v_meas_mac, tp7_5v_meas_channel, 0.00], '%.3f', retry=5, lim='x > 4.75 and x < 5.25' #TODO -- Insert data log output ) # ---------------------------------------------------------- # Setup gpio for Half-Load current loading # ---------------------------------------------------------- #fl_enb_mac self.eng.call(fl_enb_mac, 'setPinDir', fl_enb_gpio, True) self.eng.call(fl_enb_mac, 'writePin', fl_enb_gpio, False) # ----------------------------------------------Check Output Power under full load(TP7) self.step( 'tp7_5v_meas', [self.eng.read_voltage, tp7_5v_meas_mac, tp7_5v_meas_channel, 0.00], '%.3f', retry=5, lim='x > 4.75 and x < 5.25' #TODO -- Insert data log output ) # ---------------------------------------------------------- # Turn Off Power to UUT # ---------------------------------------------------------- self.set_power_state(PowerState.off) #self.step( #'TEMPERATURE', #(self.eng.call, eng1_mac, 'getTemperature', self.i2c_address), #retry=3, #lim='x >= 200 and x <= 350' #) # ---------------------------------------------------------- # Current Test # ---------------------------------------------------------- if current_test_enabled: sleep(5) self.step( 'CURRENT0', self.readCurrent(0), lim='x >= 202 and x <= 207' ) self.step( 'CURRENT1', self.readCurrent(1), lim='x >= 144 and x <= 149' ) self.step( 'CURRENT2', self.readCurrent(2), lim='x >= 126 and x <= 130' ) except: self.passed = False print 'Exception while testing:', sn print '-' * 60 traceback.print_exc(file=sys.stdout) print '-' * 60 finally: # TBD try: self.init() except: pass self.sequence_finish() tester.print_outcome(self.passed) self.buzz(sn)