From 72248eaecf63d028da1bd14bc6c27bd132c74514 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 19 Nov 2010 14:39:56 -0800 Subject: [PATCH] Timestamps work. --- src/lib/air_modes_slicer.cc | 35 +++++++++++++++++------------------ src/lib/air_modes_slicer.h | 1 + src/python/modes_print.py | 7 +++---- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/lib/air_modes_slicer.cc b/src/lib/air_modes_slicer.cc index 942869e..d83ecbb 100644 --- a/src/lib/air_modes_slicer.cc +++ b/src/lib/air_modes_slicer.cc @@ -55,6 +55,7 @@ air_modes_slicer::air_modes_slicer(int channel_rate, gr_msg_queue_sptr queue) : d_samples_per_symbol = d_samples_per_chip * 2; d_check_width = 120 * d_samples_per_symbol; //how far you will have to look ahead d_queue = queue; + d_secs_per_sample = 1.0 / channel_rate; set_output_multiple(1+d_check_width * 2); //how do you specify buffer size for sinks? } @@ -158,29 +159,30 @@ int air_modes_slicer::work(int noutput_items, } /******************** BEGIN TIMESTAMP BS ******************/ + rx_packet.timestamp_secs = 0; + rx_packet.timestamp_frac = 0; + uint64_t abs_sample_cnt = nitems_read(0); std::vector tags; + uint64_t timestamp_secs, timestamp_sample, timestamp_delta; + double timestamp_frac; - //printf("nitems_read: %i", abs_sample_cnt); pmt::pmt_t timestamp = pmt::mp(pmt::mp(0), pmt::mp(0)); //so we don't barf if there isn't one - get_tags_in_range(tags, 0, abs_sample_cnt, abs_sample_cnt + i); + get_tags_in_range(tags, 0, abs_sample_cnt, abs_sample_cnt + i, pmt::pmt_string_to_symbol("packet_time_stamp")); //tags.back() is the most recent timestamp, then. if(tags.size() > 0) { - std::sort(tags.begin(), tags.end(), pmtcompare); - - do { - timestamp = tags.back(); - tags.pop_back(); - } while(!pmt::pmt_eqv(gr_tags::get_key(timestamp), pmt::pmt_string_to_symbol("time"))); //only interested in timestamps + //if nobody but the USRP is producing timestamps this isn't necessary + //std::sort(tags.begin(), tags.end(), pmtcompare); + timestamp = tags.back(); - uint64_t timestamp_secs = pmt_to_uint64(pmt_tuple_ref(timestamp, 0)); - double timestamp_frac = pmt_to_double(pmt_tuple_ref(timestamp, 1)); - uint64_t timestamp_sample = gr_tags::get_nitems(timestamp); + 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 - uint64_t timestamp_delta = (abs_sample_cnt + i) - timestamp_sample; + timestamp_delta = (abs_sample_cnt + i) - timestamp_sample; - timestamp_frac += timestamp_delta * (1.0 / (d_samples_per_chip * d_chip_rate)); + timestamp_frac += timestamp_delta * d_secs_per_sample; if(timestamp_frac > 1.0) { timestamp_frac -= 1.0; timestamp_secs++; @@ -189,10 +191,6 @@ int air_modes_slicer::work(int noutput_items, rx_packet.timestamp_secs = timestamp_secs; rx_packet.timestamp_frac = timestamp_frac; } - else { - rx_packet.timestamp_secs = 0; - rx_packet.timestamp_frac = 0; - } /******************* END TIMESTAMP BS *********************/ @@ -287,7 +285,8 @@ 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 << " " << rx_packet.timestamp_frac; + << " " << rx_packet.timestamp_secs + << " " << std::setprecision(10) << std::setw(10) << rx_packet.timestamp_frac; gr_message_sptr msg = gr_make_message_from_string(std::string(d_payload.str())); d_queue->handle(msg); diff --git a/src/lib/air_modes_slicer.h b/src/lib/air_modes_slicer.h index 423b4a3..bf60d9c 100644 --- a/src/lib/air_modes_slicer.h +++ b/src/lib/air_modes_slicer.h @@ -45,6 +45,7 @@ private: 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; diff --git a/src/python/modes_print.py b/src/python/modes_print.py index 3d3d6ea..38a3c3a 100644 --- a/src/python/modes_print.py +++ b/src/python/modes_print.py @@ -31,14 +31,13 @@ class modes_output_print(modes_parse.modes_parse): def parse(self, message): [msgtype, shortdata, longdata, parity, ecc, reference, time_secs, time_frac] = message.split() - time_secs = long(time_secs) - time_frac = float(time_frac) - 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) msgtype = int(msgtype) @@ -58,7 +57,7 @@ class modes_output_print(modes_parse.modes_parse): output = "No handler for message type " + str(msgtype) + " from %x" % ecc if reference == 0.0: - refdb = 0.0 + refdb = -150.0 else: refdb = 10.0*math.log10(reference)