-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlcd.py
executable file
·70 lines (54 loc) · 1.56 KB
/
lcd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
# Copyright (C) J. Neuschäfer
#
# Analysis of SSPI command logs
import re, sys
re_sspi = re.compile('^\[.*\] SSPI.WR[A-Z]* ([01]), .*\[([0-9]*),([0-9]*)\] *([0-9a-f ]*) -> ([0-9a-f ]*)$')
def parse_hex(h):
h = h.strip()
if h == '':
return b''
return bytes([int(x, 16) for x in h.strip().split(' ')])
last_row = 0
matrix = {}
def render():
if 0 not in matrix:
return
print(' ' + '-' * len(matrix[0]))
for row in matrix:
data = matrix[row]
if data == b'\0' * len(data):
continue
for i in range(8):
line = ''
for byte in data:
if byte & (1 << i):
line += 'o'
else:
line += ' '
print(line)
def crunch(fn):
f = open(fn, 'r')
for line in f.readlines():
m = re_sspi.match(line)
if not m:
continue
cs = int(m.group(1))
send_len = int(m.group(2))
recv_len = int(m.group(3))
send_data = parse_hex(m.group(4))
recv_data = parse_hex(m.group(5))
assert len(send_data) == send_len
assert len(recv_data) == recv_len
if cs == 0 and send_len == 4:
assert send_data[0] == 0x46
assert send_data[1] in range(0xb0, 0xbf)
last_row = send_data[1] - 0xb0
if cs == 1:
matrix[last_row] = send_data
render()
if len(sys.argv) == 2:
crunch(sys.argv[1])
else:
print("Usage: lcd.py trace.log")