- sreqpkt = SerialReqPacket((MSG_READ, img_num, 0, 16, []))
-
- if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()):
- packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
- sreplypkt = SerialReplyPacket(packet[1])
- if sreplypkt.error == ERROR_SUCCESS:
- r.extend(sreplypkt.data)
-
- # Gets the "ident" portion of the image
- sreqpkt["offset"] = 16 + (2 * DELUGE_MAX_PAGES)
- sreqpkt["len"] = DELUGE_METADATA_SIZE
- if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()):
- packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
- sreplypkt = SerialReplyPacket(packet[1])
- if sreplypkt.error == ERROR_SUCCESS:
- r.extend(sreplypkt.data)
-
- # Checks for valid CRC and timestamp
- if crc16(r[6:8]) == toInt(r[8:10]) and r[84:88] != [0xFF, 0xFF, 0xFF, 0xFF]:
- return r
- else:
- print "ERROR: Unable to retrieve image information"
+ sreqpkt = SerialReqPacket((MSG_READ, img_num, offset, length, []))
+ while True:
+ if sreqpkt['len'] > SERIAL_DATA_LENGTH:
+ sreqpkt['len'] = SERIAL_DATA_LENGTH
+
+ if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()):
+ packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
+ sreplypkt = SerialReplyPacket(packet[1])
+ if sreplypkt.error == ERROR_SUCCESS:
+ r.extend(sreplypkt.data)
+ else:
+ r = None
+ break