Skip to content

Commit c865445

Browse files
committed
Initialise OOK modulator rate limiting on first call.
1 parent 92dddaf commit c865445

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

gnuradio/gr-scratch_radio/lib/ook_modulator_impl.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ namespace gr {
4646
gr::io_signature::make(1, 1, sizeof(uint8_t)),
4747
gr::io_signature::make(1, 1, sizeof(gr_complex)))
4848
{
49-
struct timespec ts_now;
5049
d_sample_rate = sample_rate;
5150
d_sample_count = 0;
5251
d_current_symbol = 0;
53-
clock_gettime (CLOCK_MONOTONIC, &ts_now);
54-
d_timestamp = (int64_t) ts_now.tv_sec * 1000000000 + ts_now.tv_nsec;
52+
d_timestamp = 0;
53+
d_first_call = true;
5554

5655
// Build the table of modulated symbol samples.
5756
d_symbol_length = sample_rate / baud_rate;
@@ -83,6 +82,7 @@ namespace gr {
8382
gr_vector_const_void_star &input_items,
8483
gr_vector_void_star &output_items)
8584
{
85+
struct timespec ts_now;
8686
const uint8_t *in = (const uint8_t *) input_items[0];
8787
gr_complex *out = (gr_complex *) output_items[0];
8888
int in_i = 0;
@@ -91,8 +91,12 @@ namespace gr {
9191
// Perform basic output rate limiting to prevent transmit buffer
9292
// bloat. This approach should be replaced by proper output buffer
9393
// latency management when possible. Stalls on idle cycles only.
94+
if (d_first_call) {
95+
d_first_call = false;
96+
clock_gettime (CLOCK_MONOTONIC, &ts_now);
97+
d_timestamp = (int64_t) ts_now.tv_sec * 1000000000 + ts_now.tv_nsec;
98+
}
9499
if (in[0] == 0xFF) {
95-
struct timespec ts_now;
96100
int64_t now;
97101
clock_gettime (CLOCK_MONOTONIC, &ts_now);
98102
now = (int64_t) ts_now.tv_sec * 1000000000 + ts_now.tv_nsec;

gnuradio/gr-scratch_radio/lib/ook_modulator_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <scratch_radio/ook_modulator.h>
2525

26-
#define OUTPUT_LATENCY 1000
26+
#define OUTPUT_LATENCY 250
2727

2828
namespace gr {
2929
namespace scratch_radio {
@@ -35,6 +35,7 @@ namespace gr {
3535
int d_sample_count;
3636
int d_current_symbol;
3737
int64_t d_timestamp;
38+
bool d_first_call;
3839
int d_symbol_length;
3940
gr_complex* d_sample_table;
4041

0 commit comments

Comments
 (0)