Added new block: Pad Tagged Stream

This commit is contained in:
Cyancali
2019-10-12 12:10:49 +02:00
committed by Bastian Bloessl
parent e618e70b12
commit e3ada6d33e
10 changed files with 286 additions and 2 deletions
+1
View File
@@ -39,6 +39,7 @@ list(APPEND foo_sources
random_periodic_msg_source_impl.cc
rtt_measure_impl.cc
wireshark_connector_impl.cc
pad_tagged_stream_impl.cc
)
set(foo_sources "${foo_sources}" PARENT_SCOPE)
+86
View File
@@ -0,0 +1,86 @@
/* -*- c++ -*- */
/*
* Copyright 2019 "Cyancali".
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "pad_tagged_stream_impl.h"
namespace gr {
namespace foo {
pad_tagged_stream::sptr
pad_tagged_stream::make(int buffer_size, const std::string len_tag_name)
{
return gnuradio::get_initial_sptr
(new pad_tagged_stream_impl(buffer_size, len_tag_name));
}
/*
* The private constructor
*/
pad_tagged_stream_impl::pad_tagged_stream_impl(int buffer_size, const std::string len_tag_name)
: gr::tagged_stream_block("pad_tagged_stream",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex)),
len_tag_name),
d_buf_len(buffer_size),
d_len_tag(len_tag_name)
{
set_tag_propagation_policy(TPP_DONT);
}
/*
* Our virtual destructor.
*/
pad_tagged_stream_impl::~pad_tagged_stream_impl()
{
}
int
pad_tagged_stream_impl::calculate_output_stream_length(const gr_vector_int &ninput_items)
{
return d_buf_len;
}
int
pad_tagged_stream_impl::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];
noutput_items = d_buf_len;
memcpy((void*)out, (const void*)in, ninput_items[0]);
if (ninput_items[0] < noutput_items) memset((void*) (out+ninput_items[0]), 0, noutput_items-ninput_items[0]);
return noutput_items;
}
} /* namespace foo */
} /* namespace gr */
+52
View File
@@ -0,0 +1,52 @@
/* -*- c++ -*- */
/*
* Copyright 2019 "Cyancali".
*
* 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_PAD_TAGGED_STREAM_IMPL_H
#define INCLUDED_FOO_PAD_TAGGED_STREAM_IMPL_H
#include <foo/pad_tagged_stream.h>
namespace gr {
namespace foo {
class pad_tagged_stream_impl : public pad_tagged_stream
{
private:
int d_buf_len;
std::string d_len_tag;
public:
pad_tagged_stream_impl(int buffer_size, const std::string len_tag_name);
~pad_tagged_stream_impl();
int calculate_output_stream_length(const gr_vector_int &ninput_items);
// Where all the action really happens
int work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace foo
} // namespace gr
#endif /* INCLUDED_FOO_PAD_TAGGED_STREAM_IMPL_H */