Skip to content

Commit

Permalink
Modified to work with proposed gr-uhd tags timestamp interface. Proba…
Browse files Browse the repository at this point in the history
…bly going to change.
  • Loading branch information
Nick Foster committed May 17, 2011
1 parent 462b7fb commit 773ddf8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
34 changes: 14 additions & 20 deletions src/lib/air_modes_slicer.cc
Expand Up @@ -161,39 +161,34 @@ int air_modes_slicer::work(int noutput_items,
}

/******************** BEGIN TIMESTAMP BS ******************/
rx_packet.timestamp_secs = 0;
rx_packet.timestamp_frac = 0;
rx_packet.timestamp = 0;

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

pmt::pmt_t timestamp;

get_tags_in_range(tags, 0, abs_sample_cnt, abs_sample_cnt + i, pmt::pmt_string_to_symbol("packet_time_stamp"));
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();

}

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);
//now we have to offset the timestamp based on the current sample number
timestamp_delta = (abs_sample_cnt + i) - timestamp_sample;

timestamp_frac += timestamp_delta * d_secs_per_sample;
if(timestamp_frac > 1.0) {
timestamp_frac -= 1.0;
timestamp_secs++;
}

rx_packet.timestamp_secs = timestamp_secs;
rx_packet.timestamp_frac = timestamp_frac;
}

//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 Expand Up @@ -272,8 +267,7 @@ int air_modes_slicer::work(int noutput_items,
}

d_payload << " " << std::setw(6) << rx_packet.parity << " " << std::dec << rx_packet.reference_level
<< " " << rx_packet.timestamp_secs
<< " " << std::setprecision(10) << std::setw(10) << rx_packet.timestamp_frac;
<< " " << std::setprecision(10) << std::setw(10) << rx_packet.timestamp;
gr_message_sptr msg = gr_make_message_from_string(std::string(d_payload.str()));
d_queue->handle(msg);

Expand Down
3 changes: 1 addition & 2 deletions src/lib/air_modes_types.h
Expand Up @@ -36,8 +36,7 @@ struct modes_packet {
framer_packet_type type; //what length packet are we
unsigned int message_type;
float reference_level;
unsigned long timestamp_secs; //timestamp from tags
double timestamp_frac;
double timestamp;
};

#endif
7 changes: 3 additions & 4 deletions src/python/modes_print.py
Expand Up @@ -30,14 +30,13 @@ def __init__(self, mypos):
modes_parse.modes_parse.__init__(self, mypos)

def parse(self, message):
[msgtype, shortdata, longdata, parity, ecc, reference, time_secs, time_frac] = message.split()
[msgtype, shortdata, longdata, parity, ecc, reference, timestamp] = message.split()
shortdata = long(shortdata, 16)
longdata = long(longdata, 16)
parity = long(parity, 16)
ecc = long(ecc, 16)
reference = float(reference)
time_secs = long(time_secs)
time_frac = float(time_frac)
timestamp = float(timestamp)

msgtype = int(msgtype)

Expand All @@ -62,7 +61,7 @@ def parse(self, message):
refdb = 10.0*math.log10(reference)

if output is not None:
output = "(%.0f %u %f) " % (refdb, time_secs, time_frac) + output
output = "(%.0f %f) " % (refdb, timestamp) + output
print output

def print0(self, shortdata, parity, ecc):
Expand Down

0 comments on commit 773ddf8

Please sign in to comment.