From c865445bf928e0b6e8775cc4ab086dd3748399cb Mon Sep 17 00:00:00 2001 From: Chris Holgate Date: Wed, 20 Jun 2018 16:59:57 +0000 Subject: [PATCH] Initialise OOK modulator rate limiting on first call. --- gnuradio/gr-scratch_radio/lib/ook_modulator_impl.cc | 12 ++++++++---- gnuradio/gr-scratch_radio/lib/ook_modulator_impl.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.cc b/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.cc index 44cc3f1..45702ba 100644 --- a/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.cc +++ b/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.cc @@ -46,12 +46,11 @@ namespace gr { gr::io_signature::make(1, 1, sizeof(uint8_t)), gr::io_signature::make(1, 1, sizeof(gr_complex))) { - struct timespec ts_now; d_sample_rate = sample_rate; d_sample_count = 0; d_current_symbol = 0; - clock_gettime (CLOCK_MONOTONIC, &ts_now); - d_timestamp = (int64_t) ts_now.tv_sec * 1000000000 + ts_now.tv_nsec; + d_timestamp = 0; + d_first_call = true; // Build the table of modulated symbol samples. d_symbol_length = sample_rate / baud_rate; @@ -83,6 +82,7 @@ namespace gr { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + struct timespec ts_now; const uint8_t *in = (const uint8_t *) input_items[0]; gr_complex *out = (gr_complex *) output_items[0]; int in_i = 0; @@ -91,8 +91,12 @@ namespace gr { // Perform basic output rate limiting to prevent transmit buffer // bloat. This approach should be replaced by proper output buffer // latency management when possible. Stalls on idle cycles only. + if (d_first_call) { + d_first_call = false; + clock_gettime (CLOCK_MONOTONIC, &ts_now); + d_timestamp = (int64_t) ts_now.tv_sec * 1000000000 + ts_now.tv_nsec; + } if (in[0] == 0xFF) { - struct timespec ts_now; int64_t now; clock_gettime (CLOCK_MONOTONIC, &ts_now); now = (int64_t) ts_now.tv_sec * 1000000000 + ts_now.tv_nsec; diff --git a/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.h b/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.h index a0f5a75..9efc6dc 100644 --- a/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.h +++ b/gnuradio/gr-scratch_radio/lib/ook_modulator_impl.h @@ -23,7 +23,7 @@ #include -#define OUTPUT_LATENCY 1000 +#define OUTPUT_LATENCY 250 namespace gr { namespace scratch_radio { @@ -35,6 +35,7 @@ namespace gr { int d_sample_count; int d_current_symbol; int64_t d_timestamp; + bool d_first_call; int d_symbol_length; gr_complex* d_sample_table;