Skip to content

Commit

Permalink
updated tagged_stream_fixed_length_padder
Browse files Browse the repository at this point in the history
  • Loading branch information
swarnavaghosh04 committed Dec 14, 2023
1 parent 1661fb1 commit 5485f65
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 25 deletions.
6 changes: 5 additions & 1 deletion grc/UTAT_HERON_tagged_stream_fixed_length_padder.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ category: '[UTAT]/Fixes'

templates:
imports: from gnuradio import UTAT_HERON
make: UTAT_HERON.tagged_stream_fixed_length_padder(${len_tag_key}, ${final_samples_per_symbol}, ${final_buffer_len}, ${filler})
make: UTAT_HERON.tagged_stream_fixed_length_padder(${len_tag_key}, ${final_samples_per_symbol}, ${final_buffer_len}, ${filler}, ${additional_symb_overflow})

# Make one 'parameters' list entry for every parameter you want settable from the GUI.
# Keys include:
Expand All @@ -27,6 +27,10 @@ parameters:
label: Filler
dtype: byte
default: 0x00
- id: additional_symb_overflow
label: Additional Symbols Overflow
dtype: int
default: 1

# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
# Keys include:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class UTAT_HERON_API tagged_stream_fixed_length_padder
const std::string& len_tag_key,
double final_samples_per_symbol,
int final_buffer_len,
uint8_t filler
uint8_t filler,
int additional_symb_overflow
);
};

Expand Down
67 changes: 47 additions & 20 deletions lib/tagged_stream_fixed_length_padder_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ tagged_stream_fixed_length_padder::sptr tagged_stream_fixed_length_padder::make(
const std::string& len_tag_key,
double final_samples_per_symbol,
int final_buffer_len,
uint8_t filler
uint8_t filler,
int additional_symb_overflow
)
{
return gnuradio::make_block_sptr<tagged_stream_fixed_length_padder_impl>(
len_tag_key,
final_samples_per_symbol,
final_buffer_len,
filler
filler,
additional_symb_overflow
);
}

Expand All @@ -37,7 +39,8 @@ tagged_stream_fixed_length_padder_impl::tagged_stream_fixed_length_padder_impl(
const std::string& len_tag_key,
double final_samples_per_symbol,
int final_buffer_len,
uint8_t filler
uint8_t filler,
int additional_symb_overflow
) :
gr::tagged_stream_block(
"tagged_stream_fixed_length_padder",
Expand All @@ -47,7 +50,9 @@ tagged_stream_fixed_length_padder_impl::tagged_stream_fixed_length_padder_impl(
d_sps(final_samples_per_symbol),
d_buffer_len(final_buffer_len),
d_filler(filler),
d_samps_out(0)
d_samps_overflow(0),
d_len(0),
d_additional_symb_overflow(additional_symb_overflow)
{}

/*
Expand All @@ -58,10 +63,16 @@ tagged_stream_fixed_length_padder_impl::~tagged_stream_fixed_length_padder_impl(
int tagged_stream_fixed_length_padder_impl::calculate_output_stream_length(
const gr_vector_int& ninput_items)
{
int len = (double)(d_buffer_len - d_samps_out)/d_sps + 1;
if(len < ninput_items[0])
throw std::runtime_error("Input needs to be smaller!");
return len;
d_len = std::ceil((d_buffer_len - d_samps_overflow)/d_sps);

while(d_len < ninput_items[0])
d_len += std::ceil(d_buffer_len/d_sps);

d_len += d_additional_symb_overflow;

d_logger->info("len: {}", d_len);

return d_len;
}

int tagged_stream_fixed_length_padder_impl::work(int noutput_items,
Expand All @@ -72,22 +83,38 @@ int tagged_stream_fixed_length_padder_impl::work(int noutput_items,
auto in = static_cast<const input_type*>(input_items[0]);
auto out = static_cast<output_type*>(output_items[0]);

int produced = 0;

std::memcpy(out, in, ninput_items[0]*sizeof(input_type));
d_samps_out += ninput_items[0]*d_sps;
produced = ninput_items[0];
int fill_len = d_len-ninput_items[0];
auto fill_start = out+ninput_items[0];

while(d_samps_out <= d_buffer_len && produced < noutput_items){
out[produced++] = d_filler;
d_samps_out += d_sps;
if(fill_len < 0){
d_logger->alert("\n"
"\tcalculate_output_stream_length() did not return correct length required\n"
"\td_len = {}, ninput_items = {}", d_len, ninput_items[0]);
return 0;
}
if(noutput_items < ninput_items[0]+fill_len){
d_logger->alert("output requested is too small");
return 0;
}

int samps_in_output_buffer = std::lround(d_samps_overflow + d_len*d_sps);
d_samps_overflow = samps_in_output_buffer % d_buffer_len;

/*
if you want d_samps_overflow to be double, the top two lines can be converted to:
double samps_in_output_buffer = d_samps_overflow + d_len*d_sps;
d_samps_overflow = std::fmod(samps_in_output_buffer, (double)d_buffer_len);
*/

std::memcpy(out, in, ninput_items[0]*sizeof(input_type));
std::memset(fill_start, d_filler, fill_len);

if(d_samps_out < d_buffer_len)
throw std::runtime_error("Output needs to be larger!");
d_logger->info("\n"
"\tfill_len: {}\n"
"\td_samps_overflow: {}\n",
fill_len, d_samps_overflow);

d_samps_out -= d_buffer_len;
return produced;
return d_len;

}

Expand Down
8 changes: 6 additions & 2 deletions lib/tagged_stream_fixed_length_padder_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class tagged_stream_fixed_length_padder_impl : public tagged_stream_fixed_length
double d_sps;
int d_buffer_len;
uint8_t d_filler;
double d_samps_out;
int d_samps_overflow;
int d_len;
int d_additional_samp_overflow;
int d_additional_symb_overflow;

protected:
int calculate_output_stream_length(const gr_vector_int& ninput_items);
Expand All @@ -30,7 +33,8 @@ class tagged_stream_fixed_length_padder_impl : public tagged_stream_fixed_length
const std::string& len_tag_key,
double final_samples_per_symbol,
int final_buffer_len,
uint8_t filler
uint8_t filler,
int additional_symb_overflow
);
~tagged_stream_fixed_length_padder_impl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(tagged_stream_fixed_length_padder.h) */
/* BINDTOOL_HEADER_FILE_HASH(496d118218ce70cd353a80d130b1035b) */
/* BINDTOOL_HEADER_FILE_HASH(f5c6ef1aefc57fa194152ee4e8f08f13) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand Down Expand Up @@ -45,6 +45,7 @@ void bind_tagged_stream_fixed_length_padder(py::module& m)
py::arg("final_samples_per_symbol"),
py::arg("final_buffer_len"),
py::arg("filler"),
py::arg("additional_symb_overflow"),
D(tagged_stream_fixed_length_padder, make))


Expand Down

0 comments on commit 5485f65

Please sign in to comment.