Beispiel #1
0
 def test_query_invalid_crc_response(self):
     response = b'12345678901234567890123456'
     connection = create_autospec(Connection)
     connection.read.return_value = response
     protocol = Protocol(connection)
     with self.assertRaises(ValidationException) as context:
         protocol.query(Range(0xa000, 8))
     self.assertEqual('Incorrect CRC (0x958a)', context.exception.args[0])
Beispiel #2
0
 def test_query_hello(self):
     connection = create_autospec(Connection)
     connection.read.return_value = b'\x51\x00\x00\xa0\x00\x00\x9d\x4b\x01\x00\xd8\x19'
     protocol = Protocol(connection)
     self.assertEqual(b'\x01\0', protocol.query(Range(0xa000, 1)))
     connection.write.assert_called_once_with(
         b'\x51\x00\x00\xa0\x00\x00\x9d\x4b')
Beispiel #3
0
 def test_read_retry(self):
     connection = create_autospec(Connection)
     connection.read.side_effect = [
         b'\x51',
         b'\x00\x00',
         b'\xa0',
         b'\x00',
         b'\x00',
         b'\x9d\x4b\x01\x00',
         b'\xd8',
         b'\x19',
     ]
     protocol = Protocol(connection)
     self.assertEqual(b'\x01\0', protocol.query(Range(0xa000, 1)))
     connection.read.assert_has_calls([
         call(12),
         call(11),
         call(9),
         call(8),
         call(7),
         call(6),
         call(2),
         call(1),
     ])
     connection.write.assert_called_once_with(
         b'\x51\x00\x00\xa0\x00\x00\x9d\x4b')
Beispiel #4
0
 def test_query_hash(self):
     sent = b'Q\x07\x00\x00\x1f\x00\xcfb'
     read = b"Q\x07\x00\x00\x1f\x00\xcfbz\xb2\x9f\xdeh\x1a\xe0\xb1\'\'\x08\x8f\x80\xc4\xba\x8b\xa0@"
     connection = create_autospec(Connection)
     connection.read.return_value = read
     protocol = Protocol(connection)
     self.assertEqual(
         b'z\xb2\x9f\xdeh\x1a\xe0\xb1\'\'\x08\x8f\x80\xc4\xba\x8b',
         protocol.query(Range(0x1f0000, 8)))
     connection.write.assert_called_once_with(sent)
Beispiel #5
0
 def test_query_short_response(self):
     connection = create_autospec(Connection)
     connection.read.side_effect = [
         b'123456',
         b'',
         b'',
         b'',
         b'',
         b'',
         b'',
         b'',
         b'',
         b'',
         b'',
     ]
     protocol = Protocol(connection)
     with self.assertRaises(BufferError) as context:
         protocol.query(Range(0xa000, 9))
     self.assertEqual('Expected 28 bytes, but only able to read 6',
                      context.exception.args[0])
Beispiel #6
0
def run(args):
    protocol = Protocol(connection.create())
    protocol.login()

    # Before 0xa001 we don't get anything back
    start = 0xa001
    # How much to get at a time
    fetch_words = 0x100
    line_words = 0x10
    # When to stop
    end = 0xa301
    print(
        '          1   2   3   4   5   6   7   8   9   a   b   c   d   e   f   0'
    )
    for address in range(start, end, fetch_words):
        memory = protocol.query(Range(address, fetch_words))
        for offset in range(0, fetch_words, line_words):
            start_bytes = offset * 2
            end_bytes = (offset + line_words) * 2
            sub_memory = memory[start_bytes:end_bytes]
            hex_memory = binascii.hexlify(sub_memory)
            hex_address = binascii.hexlify(struct.pack(">H", address + offset))
            print(b''.join([b'0x', hex_address, b' ',
                            hex_memory]).decode('utf-8'))