delete packet_pad block

This commit is contained in:
Bastian Bloessl
2025-01-30 17:02:07 +01:00
parent 0a34f68565
commit 4c2a471b04
11 changed files with 0 additions and 437 deletions
-1
View File
@@ -23,7 +23,6 @@ list(APPEND foo_sources
channel_model_impl.cc
packet_dropper_impl.cc
packet_pad2.cc
packet_pad_impl.cc
periodic_msg_source_impl.cc
random_periodic_msg_source_impl.cc
rtt_measure_impl.cc
-190
View File
@@ -1,190 +0,0 @@
/*
* Copyright (C) 2013 Bastian Bloessl <bloessl@ccs-labs.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "packet_pad_impl.h"
#include <chrono>
#include <gnuradio/io_signature.h>
#include <iostream>
#ifdef FOO_UHD
#include <uhd/types/time_spec.hpp>
#endif
using namespace gr::foo;
#define dout d_debug && std::cout
packet_pad_impl::packet_pad_impl(bool debug, bool delay, double delay_sec,
unsigned int pad_front, unsigned int pad_tail) : block("packet_pad",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex))),
d_debug(debug),
d_pad_front(pad_front),
d_pad_tail(pad_tail),
d_pad(0),
d_eob(false),
d_delay(delay),
d_delay_sec(delay_sec) {
set_relative_rate(1);
set_tag_propagation_policy(block::TPP_DONT);
}
packet_pad_impl::~packet_pad_impl(){
}
void
packet_pad_impl::add_sob(uint64_t item) {
dout << "PACKET PAD: insert sob at: " << item << std::endl;
static const pmt::pmt_t sob_key = pmt::string_to_symbol("tx_sob");
static const pmt::pmt_t value = pmt::PMT_T;
static const pmt::pmt_t srcid = pmt::string_to_symbol(alias());
add_item_tag(0, item, sob_key, value, srcid);
#ifdef FOO_UHD
if(d_delay) {
static const pmt::pmt_t time_key = pmt::string_to_symbol("tx_time");
double t_now(
std::chrono::duration<double>(std::chrono::system_clock::now()
.time_since_epoch()
).count()
);
uhd::time_spec_t now = uhd::time_spec_t(t_now)
+ uhd::time_spec_t(d_delay_sec);
const pmt::pmt_t time_value = pmt::make_tuple(
pmt::from_uint64(now.get_full_secs()),
pmt::from_double(now.get_frac_secs())
);
add_item_tag(0, item, time_key, time_value, srcid);
}
#endif
}
void
packet_pad_impl::add_eob(uint64_t item) {
dout << "PACKET PAD: insert eob at: " << item << std::endl;
static const pmt::pmt_t eob_key = pmt::string_to_symbol("tx_eob");
static const pmt::pmt_t value = pmt::PMT_T;
static const pmt::pmt_t srcid = pmt::string_to_symbol(alias());
add_item_tag(0, item, eob_key, value, srcid);
}
int
packet_pad_impl::general_work (int noutput_items, gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items) {
const gr_complex *in = (const gr_complex*)input_items[0];
gr_complex *out = (gr_complex*)output_items[0];
int ninput = ninput_items[0];
int noutput = noutput_items;
dout << "call: pad " << d_pad << " ninput " << ninput << " noutput " << noutput << std::endl;
// pad zeros
if(d_pad) {
int n = std::min(d_pad, noutput);
std::memset(out, 0, n * sizeof(gr_complex));
d_pad -= n;
dout << "padded zeros: " << n << std::endl;
// add end of burst tag
if(!d_pad && d_eob) {
d_eob = false;
add_eob(nitems_written(0) + n - 1);
}
return n;
}
// search for tags
const uint64_t nread = this->nitems_read(0);
std::vector<gr::tag_t> tags;
get_tags_in_range(tags, 0, nread, nread + ninput);
std::sort(tags.begin(), tags.end(), tag_t::offset_compare);
uint64_t n = std::min(ninput, noutput);
if(tags.size()) {
tag_t t = tags[0];
dout << "found tag: " << pmt::symbol_to_string(t.key) << std::endl;
uint64_t read = nitems_read(0);
if(t.offset != read) {
dout << "tag does not start at current offset" << std::endl;
n = std::min(n, t.offset - read);
} else {
if(pmt::equal(t.key, pmt::mp("tx_sob"))) {
dout << "tx_sob tag" << std::endl;
add_sob(nitems_written(0));
d_pad = d_pad_front;
remove_item_tag(0, t);
return 0;
} else if(pmt::equal(t.key, pmt::mp("tx_eob"))) {
dout << "tx_eob tag" << std::endl;
d_pad = d_pad_tail;
d_eob = true;
if(n) {
if(!d_pad) {
add_eob(nitems_written(0));
d_eob = false;
}
memcpy(out, in, sizeof(gr_complex));
consume(0, 1);
return 1;
}
return 0;
} else {
dout << "unknown tag" << std::endl;
if(tags.size() > 1) {
n = std::min(n, tags[1].offset - read);
}
}
}
}
dout << "copying : " << n << std::endl;
std::memcpy(out, in, n * sizeof(gr_complex));
consume(0, n);
return n;
}
void
packet_pad_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
if(d_pad) {
ninput_items_required[0] = 0;
} else {
ninput_items_required[0] = noutput_items;
}
}
packet_pad::sptr
packet_pad::make(bool debug, bool delay, double delay_sec, unsigned int pad_front, unsigned int pad_tail) {
return gnuradio::get_initial_sptr(new packet_pad_impl(debug, delay, delay_sec, pad_front, pad_tail));
}
-61
View File
@@ -1,61 +0,0 @@
/*
* Copyright 2013 Bastian Bloessl <bloessl@ccs-labs.org>.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_FOO_PACKET_PAD_IMPL_H
#define INCLUDED_FOO_PACKET_PAD_IMPL_H
#include <foo/packet_pad.h>
namespace gr {
namespace foo {
class packet_pad_impl : public packet_pad {
private:
void add_eob(uint64_t item);
void add_sob(uint64_t item);
bool d_debug;
bool d_delay;
double d_delay_sec;
int d_pad_front;
int d_pad_tail;
int d_pad;
bool d_eob;
public:
packet_pad_impl(bool debug, bool delay, double delay_sec,
unsigned int pad_front, unsigned int pad_tail);
~packet_pad_impl();
int general_work (int noutput_items,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items);
void forecast (int noutput_items,
gr_vector_int &ninput_items_required);
};
} // namespace foo
} // namespace gr
#endif /* INCLUDED_FOO_BURST_TAGGER_IMPL_H */