diff --git a/grok.py b/grok.py index e91e7a07..0cf631d9 100644 --- a/grok.py +++ b/grok.py @@ -9,26 +9,42 @@ CELL=4*MHZ THRESH=2*CELL-MHZ//2 -b = bitarray() -count, prev, run = 0, 128, 0 +class Bits: + def __init__(self): + self.b = bitarray() + self.prev, self.run = 128, 0 + def process(self,line): + for i in range(6, len(line)-1, 3): + x = int(line[i:i+2], 16) + for j in range(8): + level = x & 128 + if level != self.prev: + self.prev = level + if level == 0: + while self.run > THRESH: + self.b.append(False) + self.run -= CELL + self.b.append(True) + self.run = 0 + self.run += 1 + x <<= 1 + +wdata = Bits() +rdata = Bits() +wreq = Bits() +count = 0 for line in f: - if count == 1000: + if count == 100000: break - if not line.startswith('RDATA'): + if line.startswith('WDATA'): + wdata.process(line) + elif line.startswith('RDATA'): + rdata.process(line) + elif line.startswith('/WREQ'): + wreq.process(line) + else: continue count += 1 - for i in range(6, len(line)-1, 3): - x = int(line[i:i+2], 16) - for j in range(8): - level = x & 128 - if level != prev: - prev = level - if level == 0: - while run > THRESH: - b.append(False) - run -= CELL - b.append(True) - run = 0 - run += 1 - x <<= 1 -print(b) +print(wdata.b) +print(rdata.b) +print(wreq.b)