import usb.core as ucore from binascii import * from .util import assert_status, unhex from struct import unpack from usb.util import claim_interface, release_interface from queue import Queue from threading import Thread from usb.core import USBError from .blobs import init_hardcoded, init_hardcoded_clean_slate class Usb(): def __init__(self): self.trace_enabled = False self.queue = Queue(maxsize=10) self.quit = None def purge_int_queue(self): try: while True: self.queue.get_nowait() except: pass def open(self, vendor=0x06cb, product=0x009a): self.dev = ucore.find(idVendor=vendor, idProduct=product) self.dev.default_timeout = 15000 self.thread = Thread(target=lambda: self.int_thread()) self.thread.daemon = True self.thread.start() def usb_dev(self): return self.dev def send_init(self): #self.dev.set_configuration() # TODO analyse responses, detect hardware type assert_status(self.cmd(unhexlify('01'))) assert_status(self.cmd(unhexlify('19'))) # 43 -- get partition header(?) (02 -- fwext partition) # c28c745a in response is a FwextBuildtime = 0x5A748CC2 rsp=self.cmd(unhexlify('4302')) assert_status(self.cmd(init_hardcoded)) (err,), rsp = unpack('cmd> %s' % hexlify(out).decode()) self.dev.write(1, out) resp = self.dev.read(129, 100*1024) resp = bytes(resp) self.trace('