diff --git a/grc/foo_packet_pad.xml b/grc/foo_packet_pad.xml
index 8b71562..4ca89e1 100644
--- a/grc/foo_packet_pad.xml
+++ b/grc/foo_packet_pad.xml
@@ -5,7 +5,7 @@
foo_packet_pad
Foo
import foo
- foo.packet_pad($debug, $pad_front, $pad_tail)
+ foo.packet_pad($debug, $delay, $delay_sec, $pad_front, $pad_tail)
Debug
@@ -22,6 +22,29 @@
False
+
+
+ Delay
+ delay
+ False
+ bool
+
+
+
+
+
+
+ Delay Sec
+ delay_sec
+ 0.001
+ real
+
Pad Front
@@ -39,6 +62,7 @@
$pad_front >= 0
$pad_tail >= 0
+ $delay_sec > 0
in
diff --git a/include/foo/packet_pad.h b/include/foo/packet_pad.h
index 81970da..d00cdd7 100644
--- a/include/foo/packet_pad.h
+++ b/include/foo/packet_pad.h
@@ -28,7 +28,7 @@ class FOO_API packet_pad : virtual public gr::block
public:
typedef boost::shared_ptr sptr;
- static sptr make(bool debug = false, unsigned int pad_front = 0, unsigned int pad_tail = 0);
+ static sptr make(bool debug = false, bool delay=false, double delay_sec=0.01, unsigned int pad_front = 0, unsigned int pad_tail = 0);
};
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 9db23b2..633cbbc 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -35,7 +35,7 @@ list(APPEND foo_sources
)
add_library(gnuradio-foo SHARED ${foo_sources})
-target_link_libraries(gnuradio-foo ${Boost_LIBRARIES} ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_PMT_LIBRARIES})
+target_link_libraries(gnuradio-foo ${Boost_LIBRARIES} ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_PMT_LIBRARIES} uhd)
set_target_properties(gnuradio-foo PROPERTIES DEFINE_SYMBOL "gnuradio_foo_EXPORTS")
########################################################################
diff --git a/lib/packet_pad_impl.cc b/lib/packet_pad_impl.cc
index e068f58..c0fc3c4 100644
--- a/lib/packet_pad_impl.cc
+++ b/lib/packet_pad_impl.cc
@@ -18,19 +18,24 @@
#include
#include
+#include
+#include
using namespace gr::foo;
#define dout d_debug && std::cout
-packet_pad_impl::packet_pad_impl(bool debug, unsigned int pad_front, unsigned int pad_tail) : block("packet_pad",
+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_eob(false),
+ d_delay(delay),
+ d_delay_sec(delay_sec) {
set_relative_rate(1);
set_tag_propagation_policy(block::TPP_DONT);
@@ -47,6 +52,20 @@ packet_pad_impl::add_sob(uint64_t item) {
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);
+
+ 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, item, time_key, time_value, srcid);
+ }
}
void
@@ -159,6 +178,6 @@ packet_pad_impl::forecast (int noutput_items, gr_vector_int &ninput_items_requir
}
packet_pad::sptr
-packet_pad::make(bool debug, unsigned int pad_front, unsigned int pad_tail) {
- return gnuradio::get_initial_sptr(new packet_pad_impl(debug, pad_front, pad_tail));
+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));
}
diff --git a/lib/packet_pad_impl.h b/lib/packet_pad_impl.h
index 5423610..0ee7091 100644
--- a/lib/packet_pad_impl.h
+++ b/lib/packet_pad_impl.h
@@ -31,6 +31,8 @@ namespace foo {
void add_sob(uint64_t item);
bool d_debug;
+ bool d_delay;
+ double d_delay_sec;
int d_pad_front;
int d_pad_tail;
@@ -39,8 +41,8 @@ namespace foo {
bool d_eob;
public:
- packet_pad_impl(bool debug, unsigned int pad_front,
- unsigned int pad_tail);
+ packet_pad_impl(bool debug, bool delay, double delay_sec,
+ unsigned int pad_front, unsigned int pad_tail);
~packet_pad_impl();