def reset(self, enter_bootstub=False, enter_bootloader=False): # reset try: if enter_bootloader: self._handle.controlWrite(Panda.REQUEST_IN, 0xd1, 0, 0, b'') else: if enter_bootstub: self._handle.controlWrite(Panda.REQUEST_IN, 0xd1, 1, 0, b'') else: self._handle.controlWrite(Panda.REQUEST_IN, 0xd8, 0, 0, b'') except Exception: pass if not enter_bootloader: self.close() time.sleep(1.0) success = False # wait up to 15 seconds for i in range(0, 15): try: self.connect() success = True break except Exception: print("reconnecting is taking %d seconds..." % (i + 1)) try: dfu = PandaDFU( PandaDFU.st_serial_to_dfu_serial(self._serial)) dfu.recover() except Exception: pass time.sleep(1.0) if not success: raise Exception("reset failed")
def recover(self): self.reset(enter_bootloader=True) while len(PandaDFU.list()) == 0: print("waiting for DFU...") time.sleep(0.1) dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(self._serial)) dfu.recover() # reflash after recover self.connect(True, True) self.flash()
def reconnect(self): self.close() time.sleep(1.0) success = False # wait up to 15 seconds for i in range(0, 15): try: self.connect() success = True break except Exception: print("reconnecting is taking %d seconds..." % (i + 1)) try: dfu = PandaDFU( PandaDFU.st_serial_to_dfu_serial(self._serial)) dfu.recover() except Exception: pass time.sleep(1.0) if not success: raise Exception("reconnect failed")
def recover(self): self.reset(enter_bootloader=True) while len(PandaDFU.list()) == 0: print("waiting for DFU...") time.sleep(0.1) dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(self._serial)) dfu.recover() # reflash after recover self.connect(True, True) self.flash()
def recover(self, timeout=None): self.reset(enter_bootloader=True) t_start = time.time() while len(PandaDFU.list()) == 0: print("waiting for DFU...") time.sleep(0.1) if timeout is not None and (time.time() - t_start) > timeout: return False dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(self._serial)) dfu.recover() # reflash after recover self.connect(True, True) self.flash() return True