diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 468f051..0aed470 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -21,6 +21,7 @@ install(FILES foo_burst_tagger.xml foo_packet_dropper.xml foo_packet_pad.xml + foo_packet_pad2.xml foo_periodic_msg_source.xml foo_rtt_measure.xml foo_wireshark_connector.xml diff --git a/grc/foo_packet_pad2.xml b/grc/foo_packet_pad2.xml new file mode 100644 index 0000000..23d0a54 --- /dev/null +++ b/grc/foo_packet_pad2.xml @@ -0,0 +1,79 @@ + + + + Packet Pad2 + foo_packet_pad2 + Foo + import foo + foo.packet_pad2($debug, $delay, $delay_sec, $pad_front, $pad_tail) + + + Debug + debug + False + bool + + + + + + + Delay + delay + False + bool + + + + + + + Delay Sec + delay_sec + 0.001 + real + + + + Pad Front + pad_front + 0 + int + + + + Pad Tail + pad_tail + 0 + int + + + $pad_front >= 0 + $pad_tail >= 0 + $delay_sec > 0 + + + in + complex + 1 + + + + out + complex + 1 + + + diff --git a/include/foo/CMakeLists.txt b/include/foo/CMakeLists.txt index ab5f182..adee36c 100644 --- a/include/foo/CMakeLists.txt +++ b/include/foo/CMakeLists.txt @@ -25,6 +25,7 @@ install(FILES burst_tagger.h packet_dropper.h packet_pad.h + packet_pad2.h periodic_msg_source.h wireshark_connector.h rtt_measure.h diff --git a/include/foo/packet_pad2.h b/include/foo/packet_pad2.h new file mode 100644 index 0000000..788080a --- /dev/null +++ b/include/foo/packet_pad2.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 Bastian Bloessl + * + * 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 . + */ +#ifndef INCLUDED_FOO_PACKET_PAD2_H +#define INCLUDED_FOO_PACKET_PAD2_H + +#include +#include + +namespace gr { +namespace foo { + +class FOO_API packet_pad2 : virtual public gr::tagged_stream_block +{ +public: + + typedef boost::shared_ptr sptr; + static sptr make(bool debug = false, bool delay=false, double delay_sec=0.01, unsigned int pad_front = 0, unsigned int pad_tail = 0); + +}; + +} // namespace foo +} // namespace gr + +#endif /* INCLUDED_FOO_PACKET_PAD2_H */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4ca9006..5425311 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -35,6 +35,7 @@ list(APPEND foo_sources burst_tagger_impl.cc packet_dropper_impl.cc packet_pad_impl.cc + packet_pad2.cc periodic_msg_source_impl.cc wireshark_connector_impl.cc rtt_measure_impl.cc diff --git a/lib/packet_pad2.cc b/lib/packet_pad2.cc new file mode 100644 index 0000000..ab99226 --- /dev/null +++ b/lib/packet_pad2.cc @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2013 Bastian Bloessl + * + * 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 . + */ +#include + +#include +#include +#include + +using namespace gr::foo; + + +class packet_pad2_impl : public packet_pad2 { + +public: +packet_pad2_impl(bool debug, bool delay, double delay_sec, unsigned int pad_front, unsigned int pad_tail) : tagged_stream_block("foo_packet_pad2", + gr::io_signature::make(1, 1, sizeof(gr_complex)), + gr::io_signature::make(1, 1, sizeof(gr_complex)), + "packet_len"), + d_debug(debug), + d_delay(delay), + d_delay_sec(delay_sec), + d_pad_front(pad_front), + d_pad_tail(pad_tail) { + set_tag_propagation_policy(block::TPP_DONT); +} + +~packet_pad2_impl(){ +} + +int calculate_output_stream_length(const gr_vector_int &ninput_items) { + return ninput_items[0] + d_pad_front + d_pad_tail; +} + +int 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]; + + std::memset(out, 0x00, sizeof(gr_complex) * ninput_items[0] + d_pad_front + d_pad_tail); + + std::memcpy(out + d_pad_front, in, sizeof(gr_complex) * ninput_items[0]); + + + int produced = ninput_items[0] + d_pad_front + d_pad_tail; + const pmt::pmt_t value = pmt::PMT_T; + const pmt::pmt_t src = pmt::string_to_symbol(alias()); + + add_item_tag(0, nitems_written(0), pmt::mp("tx_sob"), value, src); + add_item_tag(0, nitems_written(0) + produced - 1, pmt::mp("tx_eob"), value, src); + + if(d_delay) { + static const pmt::pmt_t time_key = pmt::string_to_symbol("tx_time"); + struct timeval t; + gettimeofday(&t, NULL); + uhd::time_spec_t now = uhd::time_spec_t(t.tv_sec + t.tv_usec / 1000000.0) + + 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, nitems_written(0), time_key, time_value, src); + } + + return produced; +} + +private: + bool d_debug; + bool d_delay; + double d_delay_sec; + unsigned int d_pad_front; + unsigned int d_pad_tail; +}; + +packet_pad2::sptr +packet_pad2::make(bool debug, bool delay, double delay_sec, unsigned int pad_front, unsigned int pad_tail) { + return gnuradio::get_initial_sptr(new packet_pad2_impl(debug, delay, delay_sec, pad_front, pad_tail)); +} diff --git a/swig/foo_swig.i b/swig/foo_swig.i index b0e19bd..d781fd0 100644 --- a/swig/foo_swig.i +++ b/swig/foo_swig.i @@ -9,6 +9,7 @@ #include "foo/burst_tagger.h" #include "foo/packet_dropper.h" #include "foo/packet_pad.h" +#include "foo/packet_pad2.h" #include "foo/periodic_msg_source.h" #include "foo/wireshark_connector.h" #include "foo/rtt_measure.h" @@ -18,6 +19,7 @@ %include "foo/burst_tagger.h" %include "foo/packet_dropper.h" %include "foo/packet_pad.h" +%include "foo/packet_pad2.h" %include "foo/periodic_msg_source.h" %include "foo/wireshark_connector.h" %include "foo/rtt_measure.h" @@ -26,6 +28,7 @@ GR_SWIG_BLOCK_MAGIC2(foo, burst_tagger); GR_SWIG_BLOCK_MAGIC2(foo, packet_dropper); GR_SWIG_BLOCK_MAGIC2(foo, packet_pad); +GR_SWIG_BLOCK_MAGIC2(foo, packet_pad2); GR_SWIG_BLOCK_MAGIC2(foo, periodic_msg_source); GR_SWIG_BLOCK_MAGIC2(foo, wireshark_connector); GR_SWIG_BLOCK_MAGIC2(foo, rtt_measure);