aboutsummaryrefslogtreecommitdiffstats
path: root/src/gr-fadingui
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gr-fadingui/grc/CMakeLists.txt4
-rw-r--r--src/gr-fadingui/grc/fadingui_deframer.block.yml38
-rw-r--r--src/gr-fadingui/grc/fadingui_frame_obj.block.yml36
-rw-r--r--src/gr-fadingui/python/CMakeLists.txt4
-rw-r--r--src/gr-fadingui/python/__init__.py2
-rw-r--r--src/gr-fadingui/python/deframer.py26
-rw-r--r--src/gr-fadingui/python/frame_obj.py74
-rw-r--r--src/gr-fadingui/python/xor_frame_sync.py2
8 files changed, 183 insertions, 3 deletions
diff --git a/src/gr-fadingui/grc/CMakeLists.txt b/src/gr-fadingui/grc/CMakeLists.txt
index 1fe2b9c..92b6add 100644
--- a/src/gr-fadingui/grc/CMakeLists.txt
+++ b/src/gr-fadingui/grc/CMakeLists.txt
@@ -20,5 +20,7 @@
install(FILES
fadingui_datasource.block.yml
fadingui_dearpygui_sink.block.yml
- fadingui_xor_frame_sync.block.yml DESTINATION share/gnuradio/grc/blocks
+ fadingui_xor_frame_sync.block.yml
+ fadingui_deframer.block.yml
+ fadingui_frame_obj.block.yml DESTINATION share/gnuradio/grc/blocks
)
diff --git a/src/gr-fadingui/grc/fadingui_deframer.block.yml b/src/gr-fadingui/grc/fadingui_deframer.block.yml
new file mode 100644
index 0000000..b5d6cfe
--- /dev/null
+++ b/src/gr-fadingui/grc/fadingui_deframer.block.yml
@@ -0,0 +1,38 @@
+id: fadingui_deframer
+label: Deframer
+category: '[fadingui]'
+
+templates:
+ imports: import fadingui
+ make: fadingui.deframer(frame_obj=${frame_obj})
+
+# Make one 'parameters' list entry for every parameter you want settable from the GUI.
+# Keys include:
+# * id (makes the value accessible as \$keyname, e.g. in the make entry)
+# * label (label shown in the GUI)
+# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
+parameters:
+- id: frame_obj
+ label: Frame Object
+ dtype: raw
+
+# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
+# Keys include:
+# * label (an identifier for the GUI)
+# * domain (optional - stream or message. Default is stream)
+# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
+# * vlen (optional - data stream vector length. Default is 1)
+# * optional (optional - set to 1 for optional inputs. Default is 0)
+inputs:
+- label: in
+ domain: stream
+ dtype: byte
+
+outputs:
+- label: out
+ domain: stream
+ dtype: byte
+
+# 'file_format' specifies the version of the GRC yml format used in the file
+# and should usually not be changed.
+file_format: 1
diff --git a/src/gr-fadingui/grc/fadingui_frame_obj.block.yml b/src/gr-fadingui/grc/fadingui_frame_obj.block.yml
new file mode 100644
index 0000000..8fee3a3
--- /dev/null
+++ b/src/gr-fadingui/grc/fadingui_frame_obj.block.yml
@@ -0,0 +1,36 @@
+id: fadingui_frame_obj
+label: Frame Object
+category: '[fadingui]'
+
+templates:
+ imports: import fadingui
+ make: fadingui.frame_obj()
+
+# Make one 'parameters' list entry for every parameter you want settable from the GUI.
+# Keys include:
+# * id (makes the value accessible as \$keyname, e.g. in the make entry)
+# * label (label shown in the GUI)
+# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
+parameters:
+- id: preamble
+ label: Preamble
+ dtype: raw
+ default: [0xbe, 0xef]
+- id: payload_len
+ label: Payload length
+ dtype: int
+ default: 4096
+
+# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
+# Keys include:
+# * label (an identifier for the GUI)
+# * domain (optional - stream or message. Default is stream)
+# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
+# * vlen (optional - data stream vector length. Default is 1)
+# * optional (optional - set to 1 for optional inputs. Default is 0)
+inputs:
+outputs:
+
+# 'file_format' specifies the version of the GRC yml format used in the file
+# and should usually not be changed.
+file_format: 1
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