Skip to content

Commit

Permalink
Tags updated for sparse tags (which aren't actually in gr-uhd yet).
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Foster committed May 31, 2011
1 parent 773ddf8 commit 46573db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
36 changes: 19 additions & 17 deletions src/lib/air_modes_slicer.cc
Expand Up @@ -68,6 +68,20 @@ static bool pmtcompare(pmt::pmt_t x, pmt::pmt_t y)
return t_x < t_y;
}

static double pmt_to_timestamp(pmt::pmt_t tstamp, sample_cnt, secs_per_sample) {
double frac;
uint64_t secs, sample, sample_age;

if(gr_tags::get_name(tstamp) != "time") return 0;

secs = pmt_to_uint64(pmt_tuple_ref(gr_tags::get_value(tstamp), 0));
frac = pmt_to_double(pmt_tuple_ref(gr_tags::get_value(tstamp), 1));
sample = gr_tags::get_nitems(d_timestamp);
//now we have to offset the timestamp based on the current sample number
sample_age = (sample_cnt + i) - sample;
return sample_age * secs_per_sample + frac + secs;
}

int air_modes_slicer::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
Expand Down Expand Up @@ -165,30 +179,18 @@ int air_modes_slicer::work(int noutput_items,

uint64_t abs_sample_cnt = nitems_read(0);
std::vector<pmt::pmt_t> tags;
static uint64_t timestamp_secs, timestamp_sample, timestamp_delta;
static double timestamp_frac;
double timestamp_total;

pmt::pmt_t timestamp;
uint64_t timestamp_secs, timestamp_sample, timestamp_delta;
double timestamp_frac;

get_tags_in_range(tags, 0, abs_sample_cnt, abs_sample_cnt + i, pmt::pmt_string_to_symbol("time"));
//tags.back() is the most recent timestamp, then.
if(tags.size() > 0) {
//if nobody but the USRP is producing timestamps this isn't necessary
//std::sort(tags.begin(), tags.end(), pmtcompare);
timestamp = tags.back();
d_timestamp = tags.back();
}

if(timestamp.get()) {
timestamp_secs = pmt_to_uint64(pmt_tuple_ref(gr_tags::get_value(timestamp), 0));
timestamp_frac = pmt_to_double(pmt_tuple_ref(gr_tags::get_value(timestamp), 1));
timestamp_sample = gr_tags::get_nitems(timestamp);
if(d_timestamp) {
rx_packet.timestamp = pmt_to_timestamp(d_timestamp, abs_sample_cnt + i, d_secs_per_sample);
}
//now we have to offset the timestamp based on the current sample number
timestamp_delta = (abs_sample_cnt + i) - timestamp_sample;
timestamp_total = timestamp_delta * d_secs_per_sample + timestamp_frac + timestamp_secs;

rx_packet.timestamp = timestamp_total;
/******************* END TIMESTAMP BS *********************/

//increment for the next round
Expand Down
13 changes: 7 additions & 6 deletions src/lib/air_modes_slicer.h
Expand Up @@ -41,13 +41,14 @@ class air_modes_slicer : public gr_sync_block
friend air_modes_slicer_sptr air_make_modes_slicer(int channel_rate, gr_msg_queue_sptr queue);
air_modes_slicer(int channel_rate, gr_msg_queue_sptr queue);

int d_check_width;
int d_chip_rate;
int d_samples_per_chip;
int d_samples_per_symbol;
double d_secs_per_sample;
gr_msg_queue_sptr d_queue;
int d_check_width;
int d_chip_rate;
int d_samples_per_chip;
int d_samples_per_symbol;
double d_secs_per_sample;
gr_msg_queue_sptr d_queue;
std::ostringstream d_payload;
pmt::pmt_t d_timestamp;

public:
int work (int noutput_items,
Expand Down
2 changes: 1 addition & 1 deletion src/python/modes_sql.py
Expand Up @@ -68,7 +68,7 @@ def insert(self, message):
def make_insert_query(self, message):
#assembles a SQL query tailored to our database
#this version ignores anything that isn't Type 17 for now, because we just don't care
[msgtype, shortdata, longdata, parity, ecc, reference, time_secs, time_frac] = message.split()
[msgtype, shortdata, longdata, parity, ecc, reference, time_secs] = message.split()

shortdata = long(shortdata, 16)
longdata = long(longdata, 16)
Expand Down

0 comments on commit 46573db

Please sign in to comment.