def __init__(self, addr, port=2048): af,typ,proto,name,sa = getaddrinfo(addr,port,AF_UNSPEC,SOCK_STREAM)[0] self.sock = socket(af,typ,proto) self.sock.connect(sa) JennicProtocol.__init__(self) self.preferedblocksize=0xff self.addr=0x00
def __init__(self, addr, port=2048): af, typ, proto, name, sa = getaddrinfo(addr, port, AF_UNSPEC, SOCK_STREAM)[0] self.sock = socket(af, typ, proto) self.sock.connect(sa) JennicProtocol.__init__(self) self.preferedblocksize = 0xff self.addr = 0x00
def __init__(self, bl): self.fd = None self.wdata = None self.data = None self.fhead = None self.size = None if None is not None: self.bl = JennicProtocol() if bl is not None: self.bl = bl TWELogger.__init__(self)
def __init__(self, devname): self.DEFAULT_TIMEOUT = .2 self.MAX_TIMEOUT = 10 if devname == None: devname = '/dev/ttyUSB0' sys.stdout.write("waiting for %s.." % devname) sys.stdout.flush() while True: f = -1 try: f = open(devname) except IOError: pass else: break sys.stdout.write("done\n") self.ser = Serial(devname, 38400, timeout=.01, parity=PARITY_NONE, stopbits=1, bytesize=8, rtscts=0, dsrdtr=0) # make sure that the baudrate is set! self.ser.setBaudrate(115200) self.ser.setBaudrate(38400) # switch to programming mode for boards that support it, atm # there is the jnode and jbee platform self.ser.setDTR(0) sleep(.01) self.ser.setDTR(1) sleep(.2) # read everything that is clogging up the input buffer, until we can # be sure that we are in programming mode. sys.stdout.write("waiting until queues are emtpy..") sys.stdout.flush() while self.ser.inWaiting(): self.ser.read(self.ser.inWaiting()) sleep(.5) sys.stdout.write("done\n") # switch to maximum baudrate self.ser.write(pack("<BBBB", 3, 0x27, 1, self.crc([3, 0x27, 1], 3))) self.ser.read(3) self.ser.setBaudrate(1000000) JennicProtocol.__init__(self)
def __init__(self, device=None, initbaud=38400, progbaud=1000000, reset=-1, spimiso=-1): GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(spimiso, GPIO.OUT) GPIO.setup(reset, GPIO.OUT) self.INITBAUD, self.PROGBAUD = int(initbaud), int(progbaud) self.DEVICE = device self.RESET, self.SPIMISO, = reset, spimiso self.DEFAULT_TIMEOUT = .2 self.MAX_TIMEOUT = 10 JennicProtocol.__init__(self)
def __init__(self, device=None, initbaud=38400, progbaud=1000000): vid, pid, iserial = usbutils.query_usb_id(device) devserials= ftd2xx.listDevices(); dev = None for i, sn in enumerate(devserials): if sn == iserial.encode(): dev = ftd2xx.getDeviceInfoDetail(i) break if dev == None: raise Exception(device + " not found") self.INITBAUD, self.PROGBAUD = int(initbaud), int(progbaud) self.SERIAL = iserial JennicProtocol.__init__(self)
def __init__(self, pid=0x6001, devno=1, flag=None, baud_fast=True, ftdi_obj=None): self.DEFAULT_TIMEOUT = 1 # 100 for debug self.MAX_TIMEOUT = 3 # 100 fpr debug self.MAX_TIMEOUT_ERASEFULL = 8 self.MAX_TIMEOUT_ERASESECT = 2 self.BAUD_DEFAULT = 38400 self.b_ftdi_obj = False self.devno = 1 self.pid = pid self.isopen = False self.baud_fast = baud_fast if ftdi_obj is not None: self.ser = ftdi_obj self.b_ftdi_obj = True self.isopen = True else: if pid == None: pid = self.PRODICT_ID self.devno = None if devno.__class__ == int: self.devno = devno elif devno.__class__ == str: pass #self.devno = find_devno_by_serial(self.VENDOR_ID, pid, devno) else: self.devno = 1 self.pid = pid self.isopen = False self.baud_fast = baud_fast self.ser = Ftdi() self.open(baud=self.BAUD_DEFAULT) self.dev_prog() self.baud_default_to_fast() JennicProtocol.__init__(self)
class TWEProg(TWEProg_Common): def __init__(self, bl): if None is not None: self.bl = JennicProtocol() self.bl = bl self.rd = {} def open(self, comport, baud): pass def close(self): pass def identify_model(self): cid = self.bl.chipid & 0x0000FFFF e = None try: e = TWEModel(cid) except KeyError: e = TWEModel.UNKNOWN return e def get_info(self): self.rd = {} self.rd[TWEDict.flash_manufacturer] = self.bl.flash_manufacturer self.rd[TWEDict.flash_type] = self.bl.flash_type self.bl.read_chipid() self.rd[TWEDict.chip_id] = self.bl.chipid self.rd[TWEDict.model] = self.identify_model() self.rd[TWEDict.mac_custom] = list(self.bl.read_mac()) return self.rd def firm_prog(self, firmfile, verify=False): fp = TWEProg_Firm(self.bl) fp.open_file(firmfile) fp.write(verify=verify) """ bootloader コマンドによるリセット """ def reset_twe(self): self.bl.soft_reset()
def __init__(self, devname): self.DEFAULT_TIMEOUT = .2 self.MAX_TIMEOUT = 10 if devname==None: devname='/dev/ttyUSB0' sys.stdout.write("waiting for %s.."%devname) sys.stdout.flush() while True: f=-1 try: f=open(devname) except IOError: pass else: break sys.stdout.write("done\n") self.ser = Serial(devname, 38400, timeout=.01, parity=PARITY_NONE, stopbits=1, bytesize=8, rtscts=0, dsrdtr=0) # make sure that the baudrate is set! self.ser.setBaudrate(115200) self.ser.setBaudrate(38400) # switch to programming mode for boards that support it, atm # there is the jnode and jbee platform self.ser.setDTR(0); sleep(.01); self.ser.setDTR(1); sleep(.2) # read everything that is clogging up the input buffer, until we can # be sure that we are in programming mode. sys.stdout.write("waiting until queues are emtpy..") sys.stdout.flush() while self.ser.inWaiting(): self.ser.read(self.ser.inWaiting()) sleep(.5) sys.stdout.write("done\n") # switch to maximum baudrate #self.ser.write(pack("<BBBB", 3,0x27,1,self.crc([3,0x27,1],3))) #self.ser.read(3) #self.ser.setBaudrate(1000000) JennicProtocol.__init__(self)
def __init__(self, RESET=5, SPIMISO=4): self.f = Ftdi() self.RESET, self.SPIMISO, self.NONE = 1<<RESET, 1<<SPIMISO, 0x00 try: # Teco usbbridge self.f.usb_open(0x0403, 0xcc40) except: try: # FT232 chips self.f.usb_open(0x0403, 0x6001) except: # FT2232 chips self.f.usb_open(0x0403, 0x6010) # clear crap self.f.usb_reset() self.f.usb_purge_buffers() self.f.usb_purge_buffers() crap = cArray(1024) self.f.read_data(crap, 1024) self.enterprogrammingmode() self.doreset = 1 # clear crap self.f.usb_reset() self.f.usb_purge_buffers() self.f.usb_purge_buffers() crap = cArray(1024) self.f.read_data(crap, 1024) self.f.set_baudrate(38400) self.f.set_line_property(NONE, STOP_BIT_1, BITS_8) self.f.setrts(1) self.f.setflowctrl(SIO_RTS_CTS_HS) self.f.setrts(0) JennicProtocol.__init__(self)
def __init__(self, RESET=5, SPIMISO=4): self.f = Ftdi() self.RESET, self.SPIMISO, self.NONE = 1 << RESET, 1 << SPIMISO, 0x00 try: # Teco usbbridge self.f.usb_open(0x0403, 0xcc40) except: try: # FT232 chips self.f.usb_open(0x0403, 0x6001) except: # FT2232 chips self.f.usb_open(0x0403, 0x6010) # clear crap self.f.usb_reset() self.f.usb_purge_buffers() self.f.usb_purge_buffers() crap = cArray(1024) self.f.read_data(crap, 1024) self.enterprogrammingmode() self.doreset = 1 # clear crap self.f.usb_reset() self.f.usb_purge_buffers() self.f.usb_purge_buffers() crap = cArray(1024) self.f.read_data(crap, 1024) self.f.set_baudrate(38400) self.f.set_line_property(NONE, STOP_BIT_1, BITS_8) self.f.setrts(1) self.f.setflowctrl(SIO_RTS_CTS_HS) self.f.setrts(0) JennicProtocol.__init__(self)
def __init__(self, bl): if None is not None: self.bl = JennicProtocol() self.bl = bl self.rd = {}
class TWEProg_Firm(TWELogger): def __init__(self, bl): self.fd = None self.wdata = None self.data = None self.fhead = None self.size = None if None is not None: self.bl = JennicProtocol() if bl is not None: self.bl = bl TWELogger.__init__(self) def debug_print(self, s): self.print_debug(s, False) def debug_println(self, s): self.print_debug(s, True) def check_model(self): self.bl.read_chipid() self.debug_println("chipid = %x" % self.bl.chipid) if self.fhead is None: return None elif ( self.flash_size == 0x04 and self.ram_size == 0x03 and self.chip_type == 0x0008): # JN5164 return 'JN5164' else: return 'UNKNOWN' def open_file(self, filename): self.fd = open(filename, 'rb') # read bin size self.fd.seek(0, SEEK_END) self.size = self.fd.tell() - 4 # the first four bytes are arch in compile. self.fd.seek(0, SEEK_SET) self.fhead = self.fd .read(4) self.flash_size = self.fhead[0] self.ram_size = self.fhead[1] self.chip_type = self.fhead[2] << 8 | self.fhead[3] self.debug_println("FILEINFO: %02x %02x %04x" % (self.flash_size, self.ram_size, self.chip_type)) # set it at start point self.fd.seek(4, SEEK_SET) self.wdata = self.fd.read(self.size) self.fd.close() #del self.fd self.fd = None """ program flash content""" def write(self, verify=False): # start reading the file, 0x80 seems to be the only blocksize # working for the jennic bootloader with certain flashtypes block, i, start = 0x80, 0, time.time() data = self.wdata[0:block] # self.fd.read(block) addr = 0x0000 # erase flash self.bl.erase_flash_full() while len(data) != 0: self.bl.write_flash(addr, data) if verify: vrfy = self.bl.read_flash(addr, len(data)) if data != vrfy: msg = "verify error at %04x" % addr self.debug_println(msg) raise Exception(msg) addr += len(data) data = self.wdata[addr:addr+block] if addr > (self.size / 10.*i): self.debug_print("%i%%.." % (i * 10)) i += 1 kb, sec = self.size / 1000., (time.time() - start) self.debug_println("done - %0.2f kb/s" % (kb / sec))