From 773ddf8dec1b94f8c45ae9842e22d34bbe013042 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Mon, 16 May 2011 18:06:54 -0700 Subject: [PATCH] Modified to work with proposed gr-uhd tags timestamp interface. Probably going to change. --- src/lib/air_modes_slicer.cc | 34 ++++++++++++++-------------------- src/lib/air_modes_types.h | 3 +-- src/python/modes_print.py | 7 +++---- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/lib/air_modes_slicer.cc b/src/lib/air_modes_slicer.cc index 21a79e8..8cde4ce 100644 --- a/src/lib/air_modes_slicer.cc +++ b/src/lib/air_modes_slicer.cc @@ -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 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 @@ -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); diff --git a/src/lib/air_modes_types.h b/src/lib/air_modes_types.h index bc8af53..560ed6a 100644 --- a/src/lib/air_modes_types.h +++ b/src/lib/air_modes_types.h @@ -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 diff --git a/src/python/modes_print.py b/src/python/modes_print.py index 38a3c3a..4d60ed5 100644 --- a/src/python/modes_print.py +++ b/src/python/modes_print.py @@ -30,14 +30,13 @@ class modes_output_print(modes_parse.modes_parse): 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) @@ -62,7 +61,7 @@ class modes_output_print(modes_parse.modes_parse): 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):