Timestamps work.
This commit is contained in:
+17
-18
@@ -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<pmt::pmt_t> 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);
|
||||
|
||||
Reference in New Issue
Block a user