summaryrefslogtreecommitdiff
path: root/controller/fw/tools/reed_solomon.py
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-05-05 17:50:09 +0200
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-05-05 17:50:09 +0200
commitdb50711ba4a1f41f4082981bae58f213d48d96a1 (patch)
tree6480922fdc46a51bfb2e22e57d02cc0d3aef9d06 /controller/fw/tools/reed_solomon.py
parent9918eb505321183e20357221a4dcf2aa9c1e057c (diff)
downloadmaster-thesis-db50711ba4a1f41f4082981bae58f213d48d96a1.tar.gz
master-thesis-db50711ba4a1f41f4082981bae58f213d48d96a1.tar.bz2
master-thesis-db50711ba4a1f41f4082981bae58f213d48d96a1.zip
fw: Tie together all parts for an end-to-end demo
Diffstat (limited to 'controller/fw/tools/reed_solomon.py')
-rw-r--r--controller/fw/tools/reed_solomon.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/controller/fw/tools/reed_solomon.py b/controller/fw/tools/reed_solomon.py
index 9eee6be..c4ca6e4 100644
--- a/controller/fw/tools/reed_solomon.py
+++ b/controller/fw/tools/reed_solomon.py
@@ -64,6 +64,14 @@ def cmdline_func_test(args, print=lambda *args, **kwargs: None, benchmark=False)
).decode().replace('0', '.'))
assert test_data == decoded
+def cmdline_func_encode(args, **kwargs):
+ data = np.frombuffer(binascii.unhexlify(args.hex_str), dtype=np.uint8)
+ # Map 8 bit input to 6 bit symbol string
+ data = np.packbits(np.pad(np.unpackbits(data).reshape((-1, 6)), ((0,0),(2, 0))).flatten())
+ encoded = encode(data.tobytes(), nbits=args.bits)
+ print('symbol array:', ', '.join(f'0x{x:02x}' for x in encoded))
+ print('hex string:', binascii.hexlify(encoded).decode())
+
if __name__ == '__main__':
parser = argparse.ArgumentParser()
cmd_parser = parser.add_subparsers(required=True)
@@ -75,7 +83,9 @@ if __name__ == '__main__':
test_parser.add_argument('-s', '--seed', type=int, default=0, help='Random seed')
test_parser.set_defaults(func=cmdline_func_test)
enc_parser = cmd_parser.add_parser('encode', help='RS-Encode given hex string')
- enc_parser.add_argument('hex_str')
+ enc_parser.set_defaults(func=cmdline_func_encode)
+ enc_parser.add_argument('-b', '--bits', type=int, default=8, help='Symbol bit size')
+ enc_parser.add_argument('hex_str', type=str, help='Input data as hex string')
args = parser.parse_args()
- args.func(args, print=print)
+ args.func(args)