diff --git a/src/lib/air_modes_slicer.cc b/src/lib/air_modes_slicer.cc index 8cde4ce..e4b98e5 100644 --- a/src/lib/air_modes_slicer.cc +++ b/src/lib/air_modes_slicer.cc @@ -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) @@ -165,30 +179,18 @@ int air_modes_slicer::work(int noutput_items, uint64_t abs_sample_cnt = nitems_read(0); std::vector 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 diff --git a/src/lib/air_modes_slicer.h b/src/lib/air_modes_slicer.h index bf60d9c..636fc72 100644 --- a/src/lib/air_modes_slicer.h +++ b/src/lib/air_modes_slicer.h @@ -41,13 +41,14 @@ private: 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, diff --git a/src/python/modes_sql.py b/src/python/modes_sql.py index 6e188b9..96aaa89 100644 --- a/src/python/modes_sql.py +++ b/src/python/modes_sql.py @@ -68,7 +68,7 @@ class modes_output_sql(modes_parse.modes_parse): 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)