-def op_ident(s):
- sreqpkt = SerialReqPacket((MSG_IDENT, 0, 0, 0, []))
- 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:
- return toInt(sreplypkt.data)
- return 0
-
-# Checks for valid CRC and image timestamp
-def verifyMetaData(r):
- if r != None:
- if crc16(r[6:8]) == toInt(r[8:10]) and r[84:88] != [0xFF, 0xFF, 0xFF, 0xFF]:
- return True
- else:
- print "WARNING: Invalid image format detected"
-
- return False
-
-# Returns the metadata (first 16 bytes of the image) plus the "ident"
-# (DELUGE_IDENT_SIZE bytes after CRC)
-def getMetaData(s, img_num):
- # Gets the metadata (first 16 bytes of the image)
- r = op_read(s, img_num, DELUGE_METADATA_OFFSET, DELUGE_METADATA_SIZE)
-
- # Gets the "ident" portion of the image
- if r != None:
- temp = op_read(s, img_num, DELUGE_IDENT_OFFSET, DELUGE_IDENT_SIZE)
- if temp != None:
- r.extend(temp)
- return r
-
- print "ERROR: Unable to retrieve image information over serial"
- return None
-
-# Prints status of the image in the external flash
-def op_ping(s, img_num):
- uid = op_ident(s)
- metadata = getMetaData(s, img_num)
- if not metadata == None:
- if verifyMetaData(metadata) == True:
- print "Connected to Deluge node."
- # Prints out image status
- print "--------------------------------------------------"
- print "Currently Executing:"
- print " UID: %d" % (uid)
- print "Stored image %d" % img_num
- print toStatusStr(2, metadata)
- print "--------------------------------------------------"
- return True
-
- return False
-
-# Erases an image volume
-def op_erase(s, img_num):
- sreqpkt = SerialReqPacket((MSG_ERASE, img_num, 0, 0, []))
- success = s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload())
- if success == True:
- packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
- sreplypkt = SerialReplyPacket(packet[1])
- if sreplypkt.error == ERROR_SUCCESS:
- return True
- else:
- print "ERROR: Unable to erase the flash volume"
- return False
-
- print "ERROR: Unable to send the command"
- return False