コード例 #1
0
def get_data_dev(sector):
	drive.seek((2000+sector)*512)
	data = drive.read(512)
	if len(data) != 512:
		data = ''
		return data

	read_crc = struct.unpack('H', data[-2:])[0]
	calc_crc = shimmerUtil.crc_compute(data[0:-2])
	if read_crc != calc_crc:
		data = ''
	return data
コード例 #2
0
def get_data_port(sector):
	"""
	Reads a sector off of the SHIMMER sd card.

	This function returns the 512 bytes read from sd card on the
	sector specified.  Sector 0 is the file header, and the data is on
	the following sectors.	If there was a problem reading from the sd
	card, the empty string is returned.
	"""

	data = ''
	marker_not_found = 1

	# Command to read sector
	ser.write('f' + struct.pack('I', sector)) 

	# Look for start marker
	markers_seen = 0
	marker_found = 0
	while not marker_found:
		char = ser.read(1)
		# check for timeout
		if char == '':
			return data 
		if char == '\xaa':
			markers_seen += 1
			if markers_seen == 4:
				marker_found = 1
		else:
			markers_seen = 0
	# Found start of sector
	data = ser.read(512)
	if len(data) != 512:
		data = ''
		return data

	read_crc = struct.unpack('H', data[-2:])[0]
	calc_crc = shimmerUtil.crc_compute(data[0:-2])
	if read_crc != calc_crc:
		data = ''
	return data
コード例 #3
0
new_offset = struct.unpack('d',offset_str)[0]

if new_offset != offset:
    print "Error writing offset to SHIMMER.  Please try again."
    ser.close()
    sys.exit(1)

# We are now ready to generate our marker block.  The marker starts
# with the 0x0000 (normally the SHIMMER timestamp goes here) and then
# the 8 byte offset offset followed by 500 bytes of random characters
# and a 2 byte checksum.

data = '\x00\x00' + offset_str
for i in range(500):
    data += chr(random.randint(0,255))
data += struct.pack('H',shimmerUtil.crc_compute(data))

# Now send this marker to SHIMMER
# We have the offset.  Now store it on the SHIMMER
ser.write('m')
ser.write(data)

ser.write('e')
new_data = ser.read(512)

if new_data != data:
    print "File marker mismatch.  Please try again."
    ser.close()
    sys.exit(1)

now = time.strftime('%m/%d/%Y %H:%M:%S',