forked from woodenphone/lego_dimensions_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_log.py
78 lines (63 loc) · 2.39 KB
/
parse_log.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
71
72
73
74
75
76
77
78
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: User
#
# Created: 14/11/2015
# Copyright: (c) User 2015
# Licence: <your licence>
#-------------------------------------------------------------------------------
# Gather data
input_file = open("usb.log","r")
output_file = open("usb.log","a")
endpoint_bins = {}# { "01" : [ [0x55,...], ...] }
previous_byte_string_list = None
previous_byte_list = None
correct_guesses = 0
line_number = 0
for line in input_file:
line = line.lower()# Fuck case sensitivity
line = line.strip()# No newlines
line_number += 1
print "line_number: "+repr(line_number)
if correct_guesses % 100 ==0:
print "correct_guesses: "+repr(correct_guesses)
if line[2] == u"[":
print "\n\n"
print "line: "+repr(line)
#01[32]: 55 14 c6 11 01 1e 01 ff 00 00 01 1e 01 ff 00 00 01 1e 01 ff 00 00 9d 00 00 00 00 00 00 00 00 00
endpoint = line[:2]# "01"
data_string = line.split(": ")[-1]# "55 14 c6 11 01 1e 01 ff 00 00 01 1e 01 ff 00 00 01 1e 01 ff 00 00 9d 00 00 00 00 00 00 00 00 00"
byte_string_list = data_string.split(" ")# ["55",...]
print "byte_string_list: "+repr(byte_string_list)
byte_list = []
for byte_string in byte_string_list:
byte_list.append(int(byte_string, 16))
print "byte_list: "+repr(byte_list)
if endpoint == "01":
assert(byte_string_list[0] == "55")# Byte 0 always 0x55
# Command 1?
# 01[32]: 55 14 c6 11 01 1e 01 ff 00 00 01 1e 01 ff 00 00 01 1e 01 ff 00 00 9d 00 00 00 00 00 00 00 00 00
if byte_string_list[1] == "14":
print "cmd1"
assert(byte_string_list[2] == "c6")# Byte 2 always 0xc6
if previous_byte_list is not None:# Byte 3 looks like a counter
expected_byte_3_value = previous_byte_list[3]+1
assert(byte_list[3] == expected_byte_3_value)
# Command 2?
elif byte_string_list[1] == "15":
print "cmd2"
else:
assert(False)# We don't know about this case
# If no test failed
correct_guesses += 1
else:
print "line: "+repr(line)
# Parse data
input_file.close()
output_file.close()
def main():
pass
if __name__ == '__main__':
main()