-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_for_wichers.py
executable file
·77 lines (58 loc) · 1.73 KB
/
parser_for_wichers.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
#!/bin/python
import fileinput
import sys
import csv
last = None
lin = 0
buff = []
dataPos = 0
stdin = fileinput.input()
reader = csv.reader(stdin)
def printBuff(typ, buff):
if not buff:
return
sys.stdout.write(typ)
sys.stdout.write(': ')
sys.stdout.write(' '.join(buff))
sys.stdout.write('\n')
def getNextOfType(oldTyp, reader):
for _ in range(0, 1000):
row = next(reader)
time, typ, data = row
if typ == oldTyp:
return row
raise RuntimeError('Failed to get next.')
for line in reader:
time, typ, data = line
lin += 1
#if typ not in ['TX', 'RX']:
if typ not in ['TX']:
sys.stderr.write('Skipping line {}.\n'.format(lin))
continue
assert(data == '0x01')
# Count
counterRow = getNextOfType(typ, reader)
counterTime, counterTyp, counterData = counterRow
assert(counterTyp == typ)
# Action
actionRow = getNextOfType(typ, reader)
actionTime, actionTyp, actionData = actionRow
assert(actionTyp == typ)
# Payload count
payloadCountRow = getNextOfType(typ, reader)
payloadCountTime, payloadCountTyp, payloadCountData = payloadCountRow
assert(payloadCountTyp == typ)
payloadCountInDec = int(payloadCountData, 16)
for i in range(0, payloadCountInDec):
payloadRow = getNextOfType(typ, reader)
payloadTime, payloadTyp, payloadData = payloadRow
# check 1
check1Row = getNextOfType(typ, reader)
check1Time, check1Typ, check1Data = check1Row
# check 2
check2Row = getNextOfType(typ, reader)
check2Time, check2Typ, check2Data = check2Row
# last byte
endRow = getNextOfType(typ, reader)
endTime, endTyp, endData = endRow
assert(endData == '0x04')