diff options
author | Nao Pross <np@0hm.ch> | 2021-11-19 21:29:45 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2021-11-19 21:29:45 +0100 |
commit | ac8ef5f69a69f11fd202470da68709cd3006d547 (patch) | |
tree | 89cea172b61703acb728e1937dedec0e909da85b /src/gr-fadingui/python | |
parent | Remove PDF (diff) | |
download | Fading-ac8ef5f69a69f11fd202470da68709cd3006d547.tar.gz Fading-ac8ef5f69a69f11fd202470da68709cd3006d547.zip |
Frames
Diffstat (limited to 'src/gr-fadingui/python')
-rw-r--r-- | src/gr-fadingui/python/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/gr-fadingui/python/__init__.py | 2 | ||||
-rw-r--r-- | src/gr-fadingui/python/deframer.py | 26 | ||||
-rw-r--r-- | src/gr-fadingui/python/frame_obj.py | 74 | ||||
-rw-r--r-- | src/gr-fadingui/python/xor_frame_sync.py | 2 |
5 files changed, 106 insertions, 2 deletions
diff --git a/src/gr-fadingui/python/CMakeLists.txt b/src/gr-fadingui/python/CMakeLists.txt index 4845bd9..c277a73 100644 --- a/src/gr-fadingui/python/CMakeLists.txt +++ b/src/gr-fadingui/python/CMakeLists.txt @@ -34,7 +34,9 @@ GR_PYTHON_INSTALL( __init__.py datasource.py dearpygui_sink.py - xor_frame_sync.py DESTINATION ${GR_PYTHON_DIR}/fadingui + xor_frame_sync.py + deframer.py + frame_obj.py DESTINATION ${GR_PYTHON_DIR}/fadingui ) ######################################################################## diff --git a/src/gr-fadingui/python/__init__.py b/src/gr-fadingui/python/__init__.py index f62e3cf..5fdfea4 100644 --- a/src/gr-fadingui/python/__init__.py +++ b/src/gr-fadingui/python/__init__.py @@ -35,5 +35,7 @@ except ImportError: from .datasource import datasource from .dearpygui_sink import dearpygui_sink from .xor_frame_sync import xor_frame_sync +from .deframer import deframer +from .frame_obj import frame_obj # diff --git a/src/gr-fadingui/python/deframer.py b/src/gr-fadingui/python/deframer.py new file mode 100644 index 0000000..b7ee663 --- /dev/null +++ b/src/gr-fadingui/python/deframer.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2021 Naoki Pross. + +import numpy as np +from gnuradio import gr + +class deframer(gr.sync_block): + """ + docstring for block deframer + """ + def __init__(self): + gr.sync_block.__init__(self, + name="deframer", + in_sig=[np.byte], + out_sig=[np.byte]) + + + def work(self, input_items, output_items): + in0 = input_items[0] + out = output_items[0] + + out[:] = in0 + return len(output_items[0]) + diff --git a/src/gr-fadingui/python/frame_obj.py b/src/gr-fadingui/python/frame_obj.py new file mode 100644 index 0000000..b9dae70 --- /dev/null +++ b/src/gr-fadingui/python/frame_obj.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2021 Naoki Pross. + +from functools import reduce +import operator as op + +import numpy as np +from gnuradio import gr + + +class frame_obj(gr.basic_block): + """ + Frame Object: Contains informations about a data frame. + + ------------------------------------------------------------------------------- + | Preamble | Padding | ID | Data Length | Parity | Payload | Padding | + | k bytes | 1 bit | 4 bits | 22 bits | 5 bits | | if necessary | + ------------------------------------------------------------------------------- + | (31, 26) Hamming code EC | + ----------------------------------- + + - The preamble is user defined. + - The ID (11 bits) + Data length (22 bits) together are a 31 bits, followed + by 26 parity bits computed using a (31,26) hamming code. + + This constraints the maximum payload size to 64 MB and the number IDs to + 1024 (i.e. max file size is 1 GB, more than enough for many thing) + + """ + def __init__(self, preamble, payload_len): + gr.basic_block.__init__(self, name="frame_obj", + in_sig=None, out_sig=None) + + self.preamble = np.array(preamble, dtype=np.uint8) + + self.preamble_len = len(self.preamble) + self.payload_len = payload_len + + @property + def length(self): + """Frame lenght in bytes""" + return self.preamble_len + self.payload_len + 8 + + def parity(self, bits): + """Compute the 5 parity bits for an unpacked array of 26 bits""" + assert(len(bits) == 26) + # FIXME: does not work + # gen = np.array( + # [[1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0], + # [0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1], + # [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0], + # [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0], + # [0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1]], + # dtype=np.uint8) + # return np.matmul(bits, gen) % 2 + return np.array([0, 0, 0, 0, 0]) + + def make(self, idv, data_len, data): + """Make a frame""" + return np.concatenate(self.preamble, np.packbits(hamming), data) + + def syndrome(self, bits): + """Compute the syndrome (check Hamming code) for an unpacked array of 31 bits""" + assert(len(bits) == 31) + return reduce(op.xor, [i for i, bit in enumerate(bits) if bit]) + + def general_work(self, input_items, output_items): + """ + This block has no inputs or output + """ + return 0; + diff --git a/src/gr-fadingui/python/xor_frame_sync.py b/src/gr-fadingui/python/xor_frame_sync.py index af7aa85..e8d202c 100644 --- a/src/gr-fadingui/python/xor_frame_sync.py +++ b/src/gr-fadingui/python/xor_frame_sync.py @@ -89,7 +89,7 @@ class xor_frame_sync(gr.sync_block): if self.xcorrs[peak] != self.nbits: self.synchronized = False - print(f"Warning! XOR correlation is not perfect (peak value = {self.xcorrs[peak]})") + print(f"Warning! XOR correlation did not find a peak (max = {self.xcorrs[peak]} should be {self.nbits})") # return data with delay |