elif o == "-d": send_dl = True elif o == "-f": blfile = a else: assert False, "Unhandled option." ser = QCSerial(port, 115200, 1) if(ser.connect() != 0): msgerr("Connection to device failed.") sys.exit(-1) if send_dl: ser.send(DOWNLOAD_CMD) status = ser.recv(4) if status == DOWNLOAD_CMD: msginfo("Download mode command sent.") sys.exit(0) else: msgerr("Failed to send command mode.") sys.exit(-1) fd = open(blfile, 'rb') msginfo("Pinging target..."); ser.send(ping_command()) if ser.recv(5) != REPLY_PACKET: msgerr("Device didn't reply or in wrong mode.") fd.close()
elif o == "-d": send_dl = True elif o == "-f": blfile = a else: assert False, "Unhandled option." ser = QCSerial(port, 115200, 1) if (ser.connect() != 0): msgerr("Connection to device failed.") sys.exit(-1) if send_dl: ser.send(DOWNLOAD_CMD) status = ser.recv(4) if status == DOWNLOAD_CMD: msginfo("Download mode command sent.") sys.exit(0) else: msgerr("Failed to send command mode.") sys.exit(-1) fd = open(blfile, 'rb') msginfo("Pinging target...") ser.send(ping_command()) if ser.recv(5) != REPLY_PACKET: msgerr("Device didn't reply or in wrong mode.") fd.close()
sys.exit(-1) fd = open(nv_file, 'rb') for i in range(0, filesize / NVITEM_SIZE): nv_item = fd.read(NVITEM_SIZE) item_cmd, item_num, item_data = struct.unpack("<cH128s", nv_item) if (write_all or (item_num == item)): packet = nvram_write_command(item_num, item_data) ser.send(packet) status = ser.recv(1) if (len(status) == 0): msgerr("Reply packet size is 0 bytes. Something is wrong.") break if (status == '\x42'): msgerr("Unknown reply code.") continue reply = ser.recv(len(packet) - 1) status = reply[-5] if (status == '\x07'): msgerr("NV item {0} is read-only.".format(item_num)) elif (status == '\x05'):
sys.exit(-1) fd = open(nv_file, 'rb') for i in range(0, filesize / NVITEM_SIZE): nv_item = fd.read(NVITEM_SIZE) item_cmd, item_num, item_data = struct.unpack("<cH128s", nv_item) if(write_all or (item_num == item)): packet = nvram_write_command(item_num, item_data) ser.send(packet) status = ser.recv(1); if (len(status) == 0): msgerr("Reply packet size is 0 bytes. Something is wrong.") break if (status == '\x42'): msgerr("Unknown reply code.") continue reply = ser.recv(len(packet) - 1) status = reply[-5] if (status == '\x07'): msgerr("NV item {0} is read-only.".format(item_num)) elif (status == '\x05'):