From ccd9ed9cab560590f2ec4af41abdbf2d28c094f7 Mon Sep 17 00:00:00 2001 From: Piotr Krysik Date: Thu, 30 Nov 2017 12:48:01 +0100 Subject: Going back to previous coding style - without returns --- lib/transmitter/txtime_setter_impl.cc | 94 ++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 45 deletions(-) (limited to 'lib') diff --git a/lib/transmitter/txtime_setter_impl.cc b/lib/transmitter/txtime_setter_impl.cc index f6141f0..33bc994 100644 --- a/lib/transmitter/txtime_setter_impl.cc +++ b/lib/transmitter/txtime_setter_impl.cc @@ -30,6 +30,9 @@ #include "txtime_setter_impl.h" +#define UNKNOWN_FN 0xffffffff +#define MAX_EARLY_TIME_DIFF 10.0 + namespace gr { namespace gsm { @@ -114,52 +117,53 @@ namespace gr { void txtime_setter_impl::process_txtime_of_burst(pmt::pmt_t msg_in) { - // Nothing to do... - if (d_fn_ref == 0xffffffff) - return; - - pmt::pmt_t blob = pmt::cdr(msg_in); - - // Extract GSMTAP header from message - gsmtap_hdr *header = (gsmtap_hdr *) pmt::blob_data(blob); - uint32_t frame_nr = be32toh(header->frame_number); - uint32_t ts_num = header->timeslot; - - time_format txtime = fn_time_delta_cpp(d_fn_ref, d_time_ref, - frame_nr, d_time_hint, ts_num, d_ts_ref); - - time_spec_t txtime_spec = time_spec_t(txtime.first, txtime.second); - txtime_spec -= d_delay_correction; - txtime_spec -= d_timing_advance; - - // FIXME: better name? - time_spec_t foo = time_spec_t(d_time_hint.first, d_time_hint.second); - - // Drop too late / early bursts - if (txtime_spec <= foo) { - std::cout << "lB" << std::flush; - return; - } else if (txtime_spec > foo + 10.0) { - std::cout << "eB" << std::flush; - return; + if (d_fn_ref != UNKNOWN_FN) + { + pmt::pmt_t blob = pmt::cdr(msg_in); + + // Extract GSMTAP header from message + gsmtap_hdr *header = (gsmtap_hdr *) pmt::blob_data(blob); + uint32_t frame_nr = be32toh(header->frame_number); + uint32_t ts_num = header->timeslot; + + time_format txtime = fn_time_delta_cpp(d_fn_ref, d_time_ref, + frame_nr, d_time_hint, ts_num, d_ts_ref); + + time_spec_t txtime_spec = time_spec_t(txtime.first, txtime.second); + txtime_spec -= d_delay_correction; + txtime_spec -= d_timing_advance; + + time_spec_t current_time_estimate = time_spec_t(d_time_hint.first, d_time_hint.second); + + if (txtime_spec <= current_time_estimate) { // Drop too late bursts + std::cout << "lB" << std::flush; + } else if (txtime_spec > current_time_estimate + MAX_EARLY_TIME_DIFF) { // Drop too early bursts + std::cout << "eB" << std::flush; //TODO: too early condition might happen when changing BTSes. + //Wrong fn_time is applied to new or old bursts in such situation. + //This solution is not perfect as MS might be blocked upto + //MAX_EARLY_TIME_DIFF seconds. + //Better solution would be to indentify fn_time and burst coming + //from given BTS (i.e. based on ARFCN) and dropping bursts for which + //the bts_id doesn't match with bts_id of fn_time. + } else { //process bursts that are in the right time-frame + pmt::pmt_t tags_dict = pmt::dict_add( + pmt::make_dict(), + pmt::intern("tx_time"), + pmt::make_tuple( + pmt::from_uint64(txtime_spec.get_full_secs()), + pmt::from_double(txtime_spec.get_frac_secs())) + ); + + tags_dict = pmt::dict_add(tags_dict, + pmt::intern("fn"), pmt::from_uint64(frame_nr)); + tags_dict = pmt::dict_add(tags_dict, + pmt::intern("ts"), pmt::from_uint64(ts_num)); + + // Send a message to the output + pmt::pmt_t msg_out = pmt::cons(tags_dict, pmt::cdr(msg_in)); + message_port_pub(pmt::mp("bursts_out"), msg_out); + } } - - pmt::pmt_t tags_dict = pmt::dict_add( - pmt::make_dict(), - pmt::intern("tx_time"), - pmt::make_tuple( - pmt::from_uint64(txtime_spec.get_full_secs()), - pmt::from_double(txtime_spec.get_frac_secs())) - ); - - tags_dict = pmt::dict_add(tags_dict, - pmt::intern("fn"), pmt::from_uint64(frame_nr)); - tags_dict = pmt::dict_add(tags_dict, - pmt::intern("ts"), pmt::from_uint64(ts_num)); - - // Send a message to the output - pmt::pmt_t msg_out = pmt::cons(tags_dict, pmt::cdr(msg_in)); - message_port_pub(pmt::mp("bursts_out"), msg_out); } void txtime_setter_impl::set_fn_time_reference( -- cgit v1.2.3