From c5145aa6519e0787457253749ea76456a0fb0011 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 15 Nov 2021 16:19:23 +0100 Subject: Implement basic framer --- src/gr-fadingui/python/datasource.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/gr-fadingui') diff --git a/src/gr-fadingui/python/datasource.py b/src/gr-fadingui/python/datasource.py index ddce468..2a54ce3 100644 --- a/src/gr-fadingui/python/datasource.py +++ b/src/gr-fadingui/python/datasource.py @@ -19,6 +19,8 @@ # Boston, MA 02110-1301, USA. # +import io + import numpy as np from gnuradio import gr @@ -30,9 +32,10 @@ class datasource(gr.sync_block): gr.sync_block.__init__(self, name="datasource", in_sig=None, - out_sig=[np.dtype('256b')]) + out_sig=[np.dtype('{vec_len}b')]) # parameters + self.header_size = 11 self.vec_len = vec_len self.sock_addr = sock_addr self.file_list = file_list @@ -49,15 +52,28 @@ class datasource(gr.sync_block): self.fdata = np.fromfile(fname, np.byte) self.fsize = len(self.data) - # TODO: remove + # TODO: remove debugging statements print(f"datasource: loaded file size={self.fsize}, head:") print(self.fdata[:10]) + def make_frame(self, data_size): + # TODO: check that data_size is not too big + pilot = 0x1248 + header = f"p{pilot:04x}s{data_size:04x}d".encode("ascii") + arr = np.array(bytearray(header)) + + assert(len(arr) == self.header_size) + return arr + def work(self, input_items, output_items): out = output_items[0] if self.fpos + self.vec_len > self.fsize: - # TODO: implement padding with zeroes + rest = self.fsize - self.fpos + + out[:rest] = self.fdata[self.fpos:rest] + out[rest:] = 0 # TODO: replace with 01010101.. seq or scramble + self.fpos = 0 return 0 -- cgit v1.2.1