Add test data and working manchester decoder

This commit is contained in:
jaseg 2024-06-23 23:13:34 +02:00
parent 8c5c8aee51
commit 66e0f462d3
19 changed files with 2692 additions and 4 deletions

View file

@ -5,7 +5,7 @@ import itertools
import textwrap
import click
from reedmuller import reedmuller
from reedmuller.reedmuller import ReedMuller
class Tag:
@ -81,15 +81,19 @@ class Tag:
@click.argument('outfile', type=click.File('w'), default='-')
def cli(data, outfile, height, text, font, font_size, bar_width, margin, color, text_color, dpi):
data = int(data, 16)
data &= 0x3ffffff
text_color = text_color or color
NUM_BITS = 26
rm = ReedMuller(3, 5)
data_bits = [bool(data & (1<<i)) for i in range(NUM_BITS)]
data_bits = [bool(data & (1<<i)) for i in range(rm.message_length())]
data_bits = rm.encode(data_bits)
print('Payload bits:', ''.join([str(int(x)) for x in data_bits]))
data_encoded = itertools.chain(*[
(a, not a) for a in data_bits
])
data_encoded = [True, False, True, False, *data_encoded, False, True, True, False, True]
print('Encoded data:', ''.join([str(int(x)) for x in data_encoded]))
width = len(data_encoded) * bar_width
# 1 px = 0.75 pt