def test_make_read(self): buf = array.array('B', [3] * 20) # Start with junk in the buffer. seq = 32 block = 1 byte = 8 length = 20 p = stentura._make_read(buf, seq, block, byte, length) for_crc = [seq, 18, 0, stentura._READC, 0, 1, 0, 0, 0, length, 0, block, 0, byte, 0] crc = stentura._crc(for_crc) expected = [1] + for_crc + [crc & 0xFF, crc >> 8] self.assertSequenceEqual(p, [chr(b) for b in expected])
def test_make_read(self): buf = bytearray(range(32)) # Start with junk in the buffer. seq = 32 block = 1 byte = 8 length = 20 p = stentura._make_read(buf, seq, block, byte, length) for_crc = [seq, 18, 0, stentura._READC, 0, 1, 0, 0, 0, length, 0, block, 0, byte, 0] crc = stentura._crc(for_crc) expected = bytearray([1] + for_crc + [crc & 0xFF, crc >> 8]) self.assertEqual(p, expected)
def make_readc_packets(data): requests, responses = [], [] seq = stentura._SequenceCounter() buf = bytearray(256) block, byte = 0, 0 while data: s = seq() chunk = data[0:512] data = data[512:] q = stentura._make_read(buf, s, block, byte) requests.append(bytes(q)) r = make_read_response(s, chunk) responses.append(bytes(r)) byte += len(chunk) if byte >= 512: block += 1 byte -= 512 s = seq() q = stentura._make_read(buf, s, block, byte) requests.append(bytes(q)) r = make_read_response(s) responses.append(bytes(r)) return requests, responses
def make_readc_packets(data): requests, responses = [], [] seq = stentura._SequenceCounter() buf = array.array('B') block, byte = 0, 0 while data: s = seq() chunk = buffer(data, 0, 512) data = buffer(data, 512) q = stentura._make_read(buf, s, block, byte) requests.append(str(q)) r = make_read_response(s, chunk) responses.append(str(r)) byte += len(chunk) if byte >= 512: block += 1 byte -= 512 s = seq() q = stentura._make_read(buf, s, block, byte) requests.append(str(q)) r = make_read_response(s) responses.append(str(r)) return requests, responses
def test_make_read(self): buf = array.array('B', [3] * 20) # Start with junk in the buffer. seq = 32 block = 1 byte = 8 length = 20 p = stentura._make_read(buf, seq, block, byte, length) for_crc = [ seq, 18, 0, stentura._READC, 0, 1, 0, 0, 0, length, 0, block, 0, byte, 0 ] crc = stentura._crc(for_crc) expected = [1] + for_crc + [crc & 0xFF, crc >> 8] self.assertSequenceEqual(p, [chr(b) for b in expected])