Skip to content

Commit 3c1a2b0

Browse files
committed
grok.py changes
1 parent b3f9a61 commit 3c1a2b0

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

grok.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,42 @@
99
CELL=4*MHZ
1010
THRESH=2*CELL-MHZ//2
1111

12-
b = bitarray()
13-
count, prev, run = 0, 128, 0
12+
class Bits:
13+
def __init__(self):
14+
self.b = bitarray()
15+
self.prev, self.run = 128, 0
16+
def process(self,line):
17+
for i in range(6, len(line)-1, 3):
18+
x = int(line[i:i+2], 16)
19+
for j in range(8):
20+
level = x & 128
21+
if level != self.prev:
22+
self.prev = level
23+
if level == 0:
24+
while self.run > THRESH:
25+
self.b.append(False)
26+
self.run -= CELL
27+
self.b.append(True)
28+
self.run = 0
29+
self.run += 1
30+
x <<= 1
31+
32+
wdata = Bits()
33+
rdata = Bits()
34+
wreq = Bits()
35+
count = 0
1436
for line in f:
15-
if count == 1000:
37+
if count == 100000:
1638
break
17-
if not line.startswith('RDATA'):
39+
if line.startswith('WDATA'):
40+
wdata.process(line)
41+
elif line.startswith('RDATA'):
42+
rdata.process(line)
43+
elif line.startswith('/WREQ'):
44+
wreq.process(line)
45+
else:
1846
continue
1947
count += 1
20-
for i in range(6, len(line)-1, 3):
21-
x = int(line[i:i+2], 16)
22-
for j in range(8):
23-
level = x & 128
24-
if level != prev:
25-
prev = level
26-
if level == 0:
27-
while run > THRESH:
28-
b.append(False)
29-
run -= CELL
30-
b.append(True)
31-
run = 0
32-
run += 1
33-
x <<= 1
34-
print(b)
48+
print(wdata.b)
49+
print(rdata.b)
50+
print(wreq.b)

0 commit comments

Comments
 (0)