- # Long bit is 889μs (0) or 1333μs (1)
- ctrl = width > 1111 # If 1333, ctrl == True and carrier is off
- start = x + 2 if ctrl else x + 3 # Skip 2nd long bit
-
- # Regenerate bitstream
- bits = 1 # MSB is a dummy 1 to mark start of bitstream
- bit = int(ctrl)
- for x in range(start, nedges - 1):
+ # 2nd bit of last 0 is 444μs (0) or 1333μs (1)
+ if not 222 < width < 1555:
+ self.verbose and print('Bad block 1 Width', width, 'x', x)
+ raise RuntimeError(BADBLOCK)
+ short = width < 889
+ v = int(not short)
+ bit = v
+ bits = 1 # Bits decoded
+ x += 1 + int(short)
+ width = ticks_diff(self._times[x + 1], self._times[x])
+ if not 222 < width < 1555:
+ self.verbose and print('Bad block 2 Width', width, 'x', x)
+ raise RuntimeError(BADBLOCK)
+ short = width < 1111
+ if not short:
+ bit ^= 1
+ x += 1 + int(short) # If it's short, we know width of next
+ v <<= 1
+ v |= bit # MSB of result
+ bits += 1
+ # Decode bitstream
+ while bits < 17:
+ # -1 convert count to index, -1 because we look ahead
+ if x > nedges - 2:
+ raise RuntimeError(BADBLOCK)
+ # width is 444/889 nominal