From dc4cb983444ccb765f739b9b07e54bcff4ca48e5 Mon Sep 17 00:00:00 2001 From: Piotr Krysik Date: Tue, 16 Jul 2019 15:39:11 +0200 Subject: trx: renaming of old freq hopping block and creation of a new one The old freq_hopper -controlling USRP frequency with use of tags - was renamed to freq_hopper_tag. The new one - freq_hopper_msg - that uses uhd_source or uhd_sink control message input was created. Change-Id: Ic867446314ef2ee6903cef85d48c280981132dae --- grc/gsm_block_tree.xml | 3 +- grc/trx/CMakeLists.txt | 3 +- grc/trx/gsm_freq_hopper_msg.xml | 81 +++++++++++ grc/trx/gsm_freq_hopper_tag.xml | 33 +++++ grc/trx/gsm_freq_hopping.xml | 33 ----- include/grgsm/trx/CMakeLists.txt | 3 +- include/grgsm/trx/freq_hopper_msg.h | 74 ++++++++++ include/grgsm/trx/freq_hopper_tag.h | 67 +++++++++ include/grgsm/trx/freq_hopping.h | 68 --------- lib/trx/CMakeLists.txt | 3 +- lib/trx/freq_hopper_msg_impl.cc | 273 ++++++++++++++++++++++++++++++++++++ lib/trx/freq_hopper_msg_impl.h | 84 +++++++++++ lib/trx/freq_hopper_tag_impl.cc | 178 +++++++++++++++++++++++ lib/trx/freq_hopper_tag_impl.h | 55 ++++++++ lib/trx/freq_hopping_impl.cc | 179 ----------------------- lib/trx/freq_hopping_impl.h | 55 -------- swig/grgsm_swig.i | 9 +- 17 files changed, 859 insertions(+), 342 deletions(-) create mode 100644 grc/trx/gsm_freq_hopper_msg.xml create mode 100644 grc/trx/gsm_freq_hopper_tag.xml delete mode 100644 grc/trx/gsm_freq_hopping.xml create mode 100644 include/grgsm/trx/freq_hopper_msg.h create mode 100644 include/grgsm/trx/freq_hopper_tag.h delete mode 100644 include/grgsm/trx/freq_hopping.h create mode 100644 lib/trx/freq_hopper_msg_impl.cc create mode 100644 lib/trx/freq_hopper_msg_impl.h create mode 100644 lib/trx/freq_hopper_tag_impl.cc create mode 100644 lib/trx/freq_hopper_tag_impl.h delete mode 100644 lib/trx/freq_hopping_impl.cc delete mode 100644 lib/trx/freq_hopping_impl.h diff --git a/grc/gsm_block_tree.xml b/grc/gsm_block_tree.xml index 1773df3..026d00b 100644 --- a/grc/gsm_block_tree.xml +++ b/grc/gsm_block_tree.xml @@ -32,7 +32,8 @@ Transceiver gsm_trx_burst_if - gsm_freq_hopping + gsm_freq_hopper_tag + gsm_freq_hopper_msg Logical channels demapping diff --git a/grc/trx/CMakeLists.txt b/grc/trx/CMakeLists.txt index 0c7a636..81ef6ed 100644 --- a/grc/trx/CMakeLists.txt +++ b/grc/trx/CMakeLists.txt @@ -19,6 +19,7 @@ install(FILES gsm_trx_burst_if.xml - gsm_freq_hopping.xml + gsm_freq_hopper_tag.xml + gsm_freq_hopper_msg.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/trx/gsm_freq_hopper_msg.xml b/grc/trx/gsm_freq_hopper_msg.xml new file mode 100644 index 0000000..0175816 --- /dev/null +++ b/grc/trx/gsm_freq_hopper_msg.xml @@ -0,0 +1,81 @@ + + + freq_hopper_msg + gsm_freq_hopper_msg + import grgsm + grgsm.freq_hopper_msg($samp_rate, $start_fc_rx, $start_fc_tx, $rx_hopping, $tx_hopping, $freq_change_period) + + + + + + + + + + + + Sample rate + samp_rate + samp_rate + float + part + + + + start_fc_rx + start_fc_rx + fc + float + part + + + + start_fc_tx + start_fc_tx + fc + float + part + + + + rx_hopping + rx_hopping + True + float + part + + + + tx_hopping + tx_hopping + True + float + part + + + + freq_change_period + freq_change_period + 0.0046 + float + part + + + + in + complex + + + + + + + + + + control + message + 1 + + diff --git a/grc/trx/gsm_freq_hopper_tag.xml b/grc/trx/gsm_freq_hopper_tag.xml new file mode 100644 index 0000000..b9d1372 --- /dev/null +++ b/grc/trx/gsm_freq_hopper_tag.xml @@ -0,0 +1,33 @@ + + + freq_hopper_tag + gsm_freq_hopper_tag + import grgsm + grgsm.freq_hopper_tag($hopping_cmd) + + + Initial hopping command + hopping_cmd + pmt.to_pmt({'cmd': 'start', 'hopping_params': {'hsn': 1, 'maio': 0, 'ma': [1,2,3,4]} }) + raw + part + + + + hopping_cmd + message + 1 + + + + bursts_in + message + 1 + + + + bursts_out + message + 1 + + diff --git a/grc/trx/gsm_freq_hopping.xml b/grc/trx/gsm_freq_hopping.xml deleted file mode 100644 index 9e71e53..0000000 --- a/grc/trx/gsm_freq_hopping.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - freq_hopping - gsm_freq_hopping - import grgsm - grgsm.freq_hopping($hopping_cmd) - - - Initial hopping command - hopping_cmd - pmt.to_pmt({'cmd': 'start', 'hopping_params': {'hsn': 1, 'maio': 0, 'ma': [1,2,3,4]} }) - raw - part - - - - hopping_cmd - message - 1 - - - - bursts_in - message - 1 - - - - bursts_out - message - 1 - - diff --git a/include/grgsm/trx/CMakeLists.txt b/include/grgsm/trx/CMakeLists.txt index 0addc79..346a807 100644 --- a/include/grgsm/trx/CMakeLists.txt +++ b/include/grgsm/trx/CMakeLists.txt @@ -21,7 +21,8 @@ # Install public header files ######################################################################## install(FILES - freq_hopping.h + freq_hopper_tag.h + freq_hopper_msg.h trx_burst_if.h DESTINATION include/grgsm/trx ) diff --git a/include/grgsm/trx/freq_hopper_msg.h b/include/grgsm/trx/freq_hopper_msg.h new file mode 100644 index 0000000..12a9fe0 --- /dev/null +++ b/include/grgsm/trx/freq_hopper_msg.h @@ -0,0 +1,74 @@ +/* -*- c++ -*- */ +/* @file + * @author Piotr Krysik + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + + +#ifndef INCLUDED_GSM_FREQ_HOPPER_MSG_H +#define INCLUDED_GSM_FREQ_HOPPER_MSG_H + +#include +#include + +namespace gr { + namespace gsm { + + /*! + * \brief <+description of block+> + * \ingroup gsm + * + */ + class GRGSM_API freq_hopper_msg : virtual public sync_block + { + public: + typedef boost::shared_ptr sptr; + + static sptr make( + double samp_rate = 1e6, + double start_fc_rx = 1e9, + double start_fc_tx = 1e9, + bool rx_hopping=true, + bool tx_hopping=true, + double freq_change_period=0.0046); + + /*! + * hopping_cmd is a pmt dictionary with following fields: + * "cmd": string with type of command, possible values: + * -"start" - immediately start hopping or if there is "fn" + * field defined start from frame number defined + * by that field + * -"stop" - immediately stop hopping or if there is "fn" + * field defined start from frame number defined + * by that field + * -"discard" - discard all queued "start_fn" and "stop_fn" + * (this command doesn't require hopping parameters or frame number) + * "hopping_params": dictionary with hopping parameters in following form: + * {"hsn": hopping_sequence_number(uint64), + * "ma": mobile_allocation(list of arfcns), + * "maio": mobile_allocation_index_offset(uint64), + * "n_arfcn": number_of_arfcns_in_ma} + * "fn": frame number when to start or stop hopping + */ +// virtual void add_hopping_cmd(pmt::pmt_t hopping_cmd=pmt::PMT_NIL) = 0; + }; + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_GSM_FREQ_HOPPER_MSG_H */ diff --git a/include/grgsm/trx/freq_hopper_tag.h b/include/grgsm/trx/freq_hopper_tag.h new file mode 100644 index 0000000..fc4f8c3 --- /dev/null +++ b/include/grgsm/trx/freq_hopper_tag.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* @file + * @author Piotr Krysik + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + + +#ifndef INCLUDED_GSM_FREQ_HOPPER_TAG_H +#define INCLUDED_GSM_FREQ_HOPPER_TAG_H + +#include +#include + +namespace gr { + namespace gsm { + + /*! + * \brief <+description of block+> + * \ingroup gsm + * + */ + class GRGSM_API freq_hopper_tag : virtual public gr::block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * hopping_cmd is a pmt dictionary with following fields: + * "cmd": string with type of command, possible values: + * -"start" - immediately start hopping or if there is "fn" + * field defined start from frame number defined + * by that field + * -"stop" - immediately stop hopping or if there is "fn" + * field defined start from frame number defined + * by that field + * -"discard" - discard all queued "start_fn" and "stop_fn" + * (this command doesn't require hopping parameters or frame number) + * "hopping_params": dictionary with hopping parameters in following form: + * {"hsn": hopping_sequence_number(uint64), + * "ma": mobile_allocation(list of arfcns), + * "maio": mobile_allocation_index_offset(uint64), + * "n_arfcn": number_of_arfcns_in_ma} + * "fn": frame number when to start or stop hopping + */ + static sptr make(pmt::pmt_t hopping_cmd); + virtual void add_hopping_cmd(pmt::pmt_t hopping_cmd=pmt::PMT_NIL) = 0; + }; + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_GSM_FREQ_HOPPER_TAG_H */ diff --git a/include/grgsm/trx/freq_hopping.h b/include/grgsm/trx/freq_hopping.h deleted file mode 100644 index eeb3a53..0000000 --- a/include/grgsm/trx/freq_hopping.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- c++ -*- */ -/* @file - * @author Piotr Krysik - * @section LICENSE - * - * Gr-gsm is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * Gr-gsm is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gr-gsm; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - * - */ - - -#ifndef INCLUDED_GSM_FREQ_HOPPING_H -#define INCLUDED_GSM_FREQ_HOPPING_H - -#include -#include - -namespace gr { - namespace gsm { - - /*! - * \brief <+description of block+> - * \ingroup gsm - * - */ - class GRGSM_API freq_hopping : virtual public gr::block - { - public: - typedef boost::shared_ptr sptr; - - /*! - * hopping_cmd is a pmt dictionary with following fields: - * "cmd": string with type of command, possible values: - * -"start" - immediately start hopping or if there is "fn" - * field defined start from frame number defined - * by that field - * -"stop" - immediately stop hopping or if there is "fn" - * field defined start from frame number defined - * by that field - * -"discard" - discard all queued "start_fn" and "stop_fn" - * (this command doesn't require hopping parameters or frame number) - * "hopping_params": dictionary with hopping parameters in following form: - * {"hsn": hopping_sequence_number(uint64), - * "ma": mobile_allocation(list of arfcns), - * "maio": mobile_allocation_index_offset(uint64), - * "n_arfcn": number_of_arfcns_in_ma} - * "fn": frame number when to start or stop hopping - */ - static sptr make(pmt::pmt_t hopping_cmd); - virtual void add_hopping_cmd(pmt::pmt_t hopping_cmd=pmt::PMT_NIL) = 0; - }; - } // namespace gsm -} // namespace gr - -#endif /* INCLUDED_GSM_FREQ_HOPPING_H */ - diff --git a/lib/trx/CMakeLists.txt b/lib/trx/CMakeLists.txt index 0bfbe34..cd8f556 100644 --- a/lib/trx/CMakeLists.txt +++ b/lib/trx/CMakeLists.txt @@ -19,6 +19,7 @@ add_sources( trx_burst_if_impl.cc - freq_hopping_impl.cc + freq_hopper_tag_impl.cc + freq_hopper_msg_impl.cc ) diff --git a/lib/trx/freq_hopper_msg_impl.cc b/lib/trx/freq_hopper_msg_impl.cc new file mode 100644 index 0000000..678b577 --- /dev/null +++ b/lib/trx/freq_hopper_msg_impl.cc @@ -0,0 +1,273 @@ +/* -*- c++ -*- */ +/* @file + * @author Piotr Krysik + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "freq_hopper_msg_impl.h" +#include "../misc_utils/freq_hopping_utils.h" +extern "C" { +#include +} + +namespace gr { + namespace gsm { + using namespace pmt; + + freq_hopper_msg::sptr + freq_hopper_msg::make( + double samp_rate, + double start_fc_rx, + double start_fc_tx, + bool rx_hopping, + bool tx_hopping, + double freq_change_period) + { + return gnuradio::get_initial_sptr + (new freq_hopper_msg_impl(samp_rate, start_fc_rx, start_fc_tx, + rx_hopping, tx_hopping, freq_change_period)); + } + + /* + * The private constructor + */ + freq_hopper_msg_impl::freq_hopper_msg_impl( + double samp_rate, + double start_fc_rx, + double start_fc_tx, + bool rx_hopping, + bool tx_hopping, + double freq_change_period) : + sync_block("freq_hopper_msg", + gr::io_signature::make(1, 1, sizeof(gr_complex)), + gr::io_signature::make(0, 0, 0)), + d_samp_rate(samp_rate), + d_fc_rx(start_fc_rx), + d_fc_tx(start_fc_tx), + d_rx_hopping(rx_hopping), + d_tx_hopping(tx_hopping), + d_freq_change_period(freq_change_period), + d_rx_time_received(false), + d_last_rx_time(0.0), + d_current_time(0.0), + d_current_start_offset(0.0), + d_i(0), + d_start_time(1.0), + d_next_change_time(time_spec_t(2.0)), + d_change_advance(0.15), + d_rx_time_key(string_to_symbol("rx_time")) +// d_hopping_cmd(PMT_NIL), +// d_hopping_enable(false), +// d_base_freq(890e6) + { + // Register I/O ports +// message_port_register_in(mp("hopping_cmd")); + message_port_register_out(mp("control")); +// d_f.push_back(-0.3e6); +// d_f.push_back(-0.2e6); +// d_f.push_back(-0.1e6); +// d_f.push_back(0); +// d_f.push_back(0.1e6); +// d_f.push_back(0.2e6); +// d_f.push_back(0.3e6); + + d_ma.push_back(51); + d_ma.push_back(2); + d_ma.push_back(37); + d_ma.push_back(45); + d_hsn = 0; + d_maio = 0; + d_current_fn = 0; +// // Bind message handlers +// set_msg_handler(mp("hopping_cmd"), +// boost::bind(&freq_hopper_msg_impl::add_hopping_cmd, +// this, _1)); + +// add_hopping_cmd(hopping_cmd); + } + + /* + * Our virtual destructor. + */ + freq_hopper_msg_impl::~freq_hopper_msg_impl() + { + } + + int freq_hopper_msg_impl::work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + std::vector rx_time_tags; + get_tags_in_window(rx_time_tags, 0, 0, noutput_items, d_rx_time_key); + if(rx_time_tags.size() > 0){ + tag_t rx_time_tag = rx_time_tags[0]; + uint64_t rx_time_full_part = to_uint64(tuple_ref(rx_time_tag.value,0)); + double rx_time_frac_part = to_double(tuple_ref(rx_time_tag.value,1)); + d_last_rx_time = time_spec_t(rx_time_full_part, rx_time_frac_part); + d_current_start_offset = rx_time_tag.offset; + d_rx_time_received = true; + } + if(d_rx_time_received){ + uint64_t buffer_end_offset = nitems_read(0) + noutput_items; + d_current_time = time_spec_t::from_ticks(buffer_end_offset - d_current_start_offset, d_samp_rate) + d_last_rx_time; + } + +// Freq. control messages generation + if ((d_current_time.get_real_secs() > d_start_time) && + ((d_next_change_time-d_current_time).get_real_secs() < d_change_advance)){ + pmt_t freq_change_time_pmt = cons( + from_uint64(d_next_change_time.get_full_secs()), + from_double(d_next_change_time.get_frac_secs()) + ); + d_next_change_time = d_next_change_time + d_freq_change_period; + double dsp_freq = get_dsp_freq(d_current_fn); + if(d_tx_hopping){ + pmt_t tx_tune_msg = dict_add(make_dict(), mp("lo_freq"), from_double(d_fc_tx)); +// tx_tune_msg = dict_add(tx_tune_msg, mp("dsp_freq"), from_double(d_f[d_i % d_f.size()])); + tx_tune_msg = dict_add(tx_tune_msg, mp("dsp_freq"), from_double(dsp_freq)); + tx_tune_msg = dict_add(tx_tune_msg, mp("time"), freq_change_time_pmt); + tx_tune_msg = dict_add(tx_tune_msg, mp("direction"), mp("TX")); + message_port_pub(mp("control"), tx_tune_msg); +// std::cout << "tx: " << tx_tune_msg << std::endl; + } + if(d_rx_hopping){ + pmt_t rx_tune_msg = dict_add(make_dict(), mp("lo_freq"), from_double(d_fc_rx)); +// rx_tune_msg = dict_add(rx_tune_msg, mp("dsp_freq"), from_double(-d_f[d_i % d_f.size()])); + rx_tune_msg = dict_add(rx_tune_msg, mp("dsp_freq"), from_double(-dsp_freq)); + rx_tune_msg = dict_add(rx_tune_msg, mp("time"), freq_change_time_pmt); + rx_tune_msg = dict_add(rx_tune_msg, mp("direction"), mp("RX")); + message_port_pub(mp("control"), rx_tune_msg); +// std::cout << "rx: " << rx_tune_msg << std::endl; + } + d_i++; + d_current_fn++; + } + return noutput_items; + } + + double freq_hopper_msg_impl::get_dsp_freq(uint64_t fn){ //TODO: jak otrzymac fn + int mai = calculate_ma_sfh(d_maio, d_hsn, d_ma.size(), fn); + uint16_t arfcn = d_ma[mai]; + double dsp_freq = static_cast(gsm_arfcn2freq10(arfcn, 0)) * 1.0e5 - d_fc_rx; + } +/* + void freq_hopper_msg_impl::add_hopping_cmd(pmt_t cmd) //TODO: fn and discard not supported at the moment + { + if(dict_ref(cmd,intern("cmd"), PMT_NIL) == intern("start")) { + if(dict_ref(cmd,intern("fn"), PMT_NIL) != PMT_NIL){ + //TODO add the command to the map + } else { + pmt_t hopping_params = dict_ref(cmd, intern("hopping_params"), PMT_NIL); + d_hopping_enable = set_hopping_params(hopping_params); + } + } else if(dict_ref(cmd,intern("cmd"), PMT_NIL) == intern("stop")) { + if(dict_ref(cmd,intern("fn"),PMT_NIL) != PMT_NIL){ + //TODO add the command to the map + + } else { + d_hopping_enable = false; + } + } + } + + void freq_hopper_msg_impl::set_freq_metadata(pmt_t burst) + { + + if(d_hopping_enable) { + pmt_t pdu_header = car(burst); + pmt_t tx_time = dict_ref(pdu_header, intern("tx_time"),PMT_NIL); + if(tx_time != PMT_NIL){ + pmt_t tx_command_time = cons(tuple_ref(tx_time,0),tuple_ref(tx_time,1)); + pmt_t header_plus_burst = cdr(burst); + uint32_t frame_nr = 0; + + pmt_t fn = dict_ref(pdu_header,intern("fn"),PMT_NIL); + if(fn == PMT_NIL){ + gsmtap_hdr *header = (gsmtap_hdr *)blob_data(header_plus_burst); + uint32_t frame_nr = be32toh(header->frame_number); + } else { + frame_nr = to_uint64(fn); + } + + int mai = calculate_ma_sfh(d_maio, d_hsn, d_ma.size(), frame_nr); + uint16_t arfcn = d_ma[mai]; + + // if(fn == PMT_NIL){ + // header->arfcn = htobe16(arfcn); + // header->arfcn = header->arfcn | 0x8000; // set uplink flag + // } + + //compute the frequences to be set in the burst header + double freq_uplink = static_cast(gsm_arfcn2freq10(arfcn, 1)) * 1.0e5; + double freq_downlink = static_cast(gsm_arfcn2freq10(arfcn, 0)) * 1.0e5; + + pmt_t tx_command = dict_add(make_dict(),intern("lo_freq"),from_double(d_base_freq)); + tx_command = dict_add(tx_command,intern("dsp_freq"),from_double(freq_uplink-d_base_freq)); + tx_command = dict_add(tx_command,intern("time"),tx_command_time); + + pmt_t rx_command = dict_add(make_dict(),intern("lo_freq"),from_double(d_base_freq)); + rx_command = dict_add(rx_command,intern("dsp_freq"),from_double(freq_uplink-d_base_freq)); + rx_command = dict_add(rx_command,intern("time"),tx_command_time); + rx_command = dict_add(rx_command,intern("direction"),intern("RX")); + + pdu_header = dict_add(pdu_header, intern("tx_command"),tx_command); +// pdu_header = dict_add(pdu_header, intern("tx_command"),rx_command); +// std::cout << "arfcn " << arfcn << " mai " << mai << " d_ma.size() " << d_ma.size() << " d_hsn " << d_hsn << std::endl; + std::cout << "arfcn_uplink " << arfcn << std::endl; +// std::cout << "freq_downlink " << freq_downlink << std::endl; +// std::cout << "pdu_header " << pdu_header << std::endl; +// std::cout << "size_header_plus_burst " << length(header_plus_burst) << std::endl; + message_port_pub(mp("bursts_out"), cons(pdu_header,header_plus_burst)); + } + } else { + message_port_pub(mp("bursts_out"), burst); + } + } + + bool freq_hopper_msg_impl::set_hopping_params(pmt_t hopping_params){ + bool retval = false; + if(hopping_params != PMT_NIL){ + //set hopping parameters immediately + pmt_t hsn = dict_ref(hopping_params, intern("hsn"), PMT_NIL); + pmt_t maio = dict_ref(hopping_params, intern("maio"), PMT_NIL);; + pmt_t ma = dict_ref(hopping_params, intern("ma"), PMT_NIL); + + if(is_vector(ma) && is_integer(hsn) && is_integer(maio)){ //TODO: checking the values + d_hsn = to_uint64(hsn); + d_maio = to_uint64(maio); + d_ma.resize(length(ma)); + for(int i=0; i + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef INCLUDED_GSM_FREQ_HOPPER_MSG_IMPL_H +#define INCLUDED_GSM_FREQ_HOPPER_MSG_IMPL_H + +#include +#include +#include +#include + + +namespace gr { + namespace gsm { + + class freq_hopper_msg_impl : public freq_hopper_msg + { + private: + double d_samp_rate; + double d_fc_rx; + double d_fc_tx; + bool d_rx_hopping; + bool d_tx_hopping; + double d_freq_change_period; + bool d_rx_time_received; + time_spec_t d_last_rx_time; + time_spec_t d_current_time; + uint64_t d_current_start_offset; //!!zmienic nazwe - ta zmienna okresla pozycje ostatniego rx_time + uint64_t d_i; + std::vector d_f; + double d_start_time; + time_spec_t d_next_change_time; + double d_change_advance; + pmt::pmt_t d_rx_time_key; + +// bool d_hopping_enable; //if true block do the hopping, if not block just passes the bursts + uint64_t d_hsn; //hopping sequence number + uint64_t d_maio; //mobile allocation index offset + std::vector d_ma; //mobile allocation + + uint64_t d_current_fn;//!! + +// pmt::pmt_t d_hopping_cmd; //TODO: change this a std::map +// void set_freq_metadata(pmt::pmt_t cmd); +// bool set_hopping_params(pmt::pmt_t hopping_params); + double get_dsp_freq(uint64_t fn); + public: + freq_hopper_msg_impl( + double samp_rate, + double start_fc_rx, + double start_fc_tx, + bool rx_hopping, + bool tx_hopping, + double freq_change_period); + ~freq_hopper_msg_impl(); + + int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + +// void add_hopping_cmd(pmt::pmt_t hopping_cmd); + }; + + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_GSM_FREQ_HOPPER_MSG_IMPL_H */ diff --git a/lib/trx/freq_hopper_tag_impl.cc b/lib/trx/freq_hopper_tag_impl.cc new file mode 100644 index 0000000..aeed88a --- /dev/null +++ b/lib/trx/freq_hopper_tag_impl.cc @@ -0,0 +1,178 @@ +/* -*- c++ -*- */ +/* @file + * @author Piotr Krysik + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "freq_hopper_tag_impl.h" +#include "../misc_utils/freq_hopping_utils.h" +extern "C" { +#include +} + +namespace gr { + namespace gsm { + using namespace pmt; + + freq_hopper_tag::sptr + freq_hopper_tag::make( + pmt_t hopping_cmd) + { + return gnuradio::get_initial_sptr + (new freq_hopper_tag_impl(hopping_cmd)); + } + + /* + * The private constructor + */ + freq_hopper_tag_impl::freq_hopper_tag_impl( + pmt_t hopping_cmd + ) : gr::block("freq_hopper_tag", + gr::io_signature::make(0, 0, 0), + gr::io_signature::make(0, 0, 0)), + d_hopping_cmd(PMT_NIL), + d_hopping_enable(false), + d_base_freq(890e6) + { + // Register I/O ports + message_port_register_in(mp("hopping_cmd")); + message_port_register_in(mp("bursts_in")); + message_port_register_out(mp("bursts_out")); + + // Bind message handlers + set_msg_handler(mp("hopping_cmd"), + boost::bind(&freq_hopper_tag_impl::add_hopping_cmd, + this, _1)); + + set_msg_handler(mp("bursts_in"), + boost::bind(&freq_hopper_tag_impl::set_freq_metadata, + this, _1)); + + add_hopping_cmd(hopping_cmd); + } + + /* + * Our virtual destructor. + */ + freq_hopper_tag_impl::~freq_hopper_tag_impl() + { + } + + void freq_hopper_tag_impl::add_hopping_cmd(pmt_t cmd) //TODO: fn and discard not supported at the moment + { + if(dict_ref(cmd,intern("cmd"), PMT_NIL) == intern("start")) { + if(dict_ref(cmd,intern("fn"), PMT_NIL) != PMT_NIL){ + //TODO add the command to the map + } else { + pmt_t hopping_params = dict_ref(cmd, intern("hopping_params"), PMT_NIL); + d_hopping_enable = set_hopping_params(hopping_params); + } + } else if(dict_ref(cmd,intern("cmd"), PMT_NIL) == intern("stop")) { + if(dict_ref(cmd,intern("fn"),PMT_NIL) != PMT_NIL){ + //TODO add the command to the map + + } else { + d_hopping_enable = false; + } + } + } + + void freq_hopper_tag_impl::set_freq_metadata(pmt_t burst) + { + + if(d_hopping_enable) { + pmt_t pdu_header = car(burst); + pmt_t tx_time = dict_ref(pdu_header, intern("tx_time"),PMT_NIL); + if(tx_time != PMT_NIL){ + pmt_t tx_command_time = cons(tuple_ref(tx_time,0),tuple_ref(tx_time,1)); + pmt_t header_plus_burst = cdr(burst); + uint32_t frame_nr = 0; + + pmt_t fn = dict_ref(pdu_header,intern("fn"),PMT_NIL); + if(fn == PMT_NIL){ + gsmtap_hdr *header = (gsmtap_hdr *)blob_data(header_plus_burst); + uint32_t frame_nr = be32toh(header->frame_number); + } else { + frame_nr = to_uint64(fn); + } + + int mai = calculate_ma_sfh(d_maio, d_hsn, d_ma.size(), frame_nr); + uint16_t arfcn = d_ma[mai]; + + // if(fn == PMT_NIL){ + // header->arfcn = htobe16(arfcn); + // header->arfcn = header->arfcn | 0x8000; // set uplink flag + // } + + //compute the frequences to be set in the burst header + double freq_uplink = static_cast(gsm_arfcn2freq10(arfcn, 1)) * 1.0e5; + double freq_downlink = static_cast(gsm_arfcn2freq10(arfcn, 0)) * 1.0e5; + + pmt_t tx_command = dict_add(make_dict(),intern("lo_freq"),from_double(d_base_freq)); + tx_command = dict_add(tx_command,intern("dsp_freq"),from_double(freq_uplink-d_base_freq)); + tx_command = dict_add(tx_command,intern("time"),tx_command_time); + + pmt_t rx_command = dict_add(make_dict(),intern("lo_freq"),from_double(d_base_freq)); + rx_command = dict_add(rx_command,intern("dsp_freq"),from_double(freq_uplink-d_base_freq)); + rx_command = dict_add(rx_command,intern("time"),tx_command_time); + rx_command = dict_add(rx_command,intern("direction"),intern("RX")); + + pdu_header = dict_add(pdu_header, intern("tx_command"),tx_command); +// pdu_header = dict_add(pdu_header, intern("tx_command"),rx_command); +// std::cout << "arfcn " << arfcn << " mai " << mai << " d_ma.size() " << d_ma.size() << " d_hsn " << d_hsn << std::endl; + std::cout << "arfcn_uplink " << arfcn << std::endl; +// std::cout << "freq_downlink " << freq_downlink << std::endl; +// std::cout << "pdu_header " << pdu_header << std::endl; +// std::cout << "size_header_plus_burst " << length(header_plus_burst) << std::endl; + message_port_pub(mp("bursts_out"), cons(pdu_header,header_plus_burst)); + } + } else { + message_port_pub(mp("bursts_out"), burst); + } + } + + bool freq_hopper_tag_impl::set_hopping_params(pmt_t hopping_params){ + bool retval = false; + if(hopping_params != PMT_NIL){ + //set hopping parameters immediately + pmt_t hsn = dict_ref(hopping_params, intern("hsn"), PMT_NIL); + pmt_t maio = dict_ref(hopping_params, intern("maio"), PMT_NIL);; + pmt_t ma = dict_ref(hopping_params, intern("ma"), PMT_NIL); + + if(is_vector(ma) && is_integer(hsn) && is_integer(maio)){ //TODO: checking the values + d_hsn = to_uint64(hsn); + d_maio = to_uint64(maio); + d_ma.resize(length(ma)); + for(int i=0; i + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef INCLUDED_GSM_FREQ_HOPPER_TAG_IMPL_H +#define INCLUDED_GSM_FREQ_HOPPER_TAG_IMPL_H + +#include +#include +#include + +namespace gr { + namespace gsm { + + class freq_hopper_tag_impl : public freq_hopper_tag + { + private: + bool d_hopping_enable; //if true block do the hopping, if not block just passes the bursts + uint64_t d_hsn; //hopping sequence number + uint64_t d_maio; //mobile allocation index offset + double d_base_freq; //local oscillator frequency + std::vector d_ma; //mobile allocation + + pmt::pmt_t d_hopping_cmd; //TODO: change this uint64_to a std::map + void set_freq_metadata(pmt::pmt_t cmd); + bool set_hopping_params(pmt::pmt_t hopping_params); + public: + freq_hopper_tag_impl(pmt::pmt_t hopping_cmd); + ~freq_hopper_tag_impl(); + + void add_hopping_cmd(pmt::pmt_t hopping_cmd); + }; + + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_GSM_FREQ_HOPPER_TAG_IMPL_H */ diff --git a/lib/trx/freq_hopping_impl.cc b/lib/trx/freq_hopping_impl.cc deleted file mode 100644 index d6a2fb5..0000000 --- a/lib/trx/freq_hopping_impl.cc +++ /dev/null @@ -1,179 +0,0 @@ - -/* -*- c++ -*- */ -/* @file - * @author Piotr Krysik - * @section LICENSE - * - * Gr-gsm is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * Gr-gsm is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gr-gsm; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include "freq_hopping_impl.h" -#include "../misc_utils/freq_hopping_utils.h" -extern "C" { -#include -} - -namespace gr { - namespace gsm { - using namespace pmt; - - freq_hopping::sptr - freq_hopping::make( - pmt_t hopping_cmd) - { - return gnuradio::get_initial_sptr - (new freq_hopping_impl(hopping_cmd)); - } - - /* - * The private constructor - */ - freq_hopping_impl::freq_hopping_impl( - pmt_t hopping_cmd - ) : gr::block("freq_hopping", - gr::io_signature::make(0, 0, 0), - gr::io_signature::make(0, 0, 0)), - d_hopping_cmd(PMT_NIL), - d_hopping_enable(false), - d_base_freq(890e6) - { - // Register I/O ports - message_port_register_in(mp("hopping_cmd")); - message_port_register_in(mp("bursts_in")); - message_port_register_out(mp("bursts_out")); - - // Bind message handlers - set_msg_handler(mp("hopping_cmd"), - boost::bind(&freq_hopping_impl::add_hopping_cmd, - this, _1)); - - set_msg_handler(mp("bursts_in"), - boost::bind(&freq_hopping_impl::set_freq_metadata, - this, _1)); - - add_hopping_cmd(hopping_cmd); - } - - /* - * Our virtual destructor. - */ - freq_hopping_impl::~freq_hopping_impl() - { - } - - void freq_hopping_impl::add_hopping_cmd(pmt_t cmd) //TODO: fn and discard not supported at the moment - { - if(dict_ref(cmd,intern("cmd"), PMT_NIL) == intern("start")) { - if(dict_ref(cmd,intern("fn"), PMT_NIL) != PMT_NIL){ - //TODO add the command to the map - } else { - pmt_t hopping_params = dict_ref(cmd, intern("hopping_params"), PMT_NIL); - d_hopping_enable = set_hopping_params(hopping_params); - } - } else if(dict_ref(cmd,intern("cmd"), PMT_NIL) == intern("stop")) { - if(dict_ref(cmd,intern("fn"),PMT_NIL) != PMT_NIL){ - //TODO add the command to the map - - } else { - d_hopping_enable = false; - } - } - } - - void freq_hopping_impl::set_freq_metadata(pmt_t burst) - { - - if(d_hopping_enable) { - pmt_t pdu_header = car(burst); - pmt_t tx_time = dict_ref(pdu_header, intern("tx_time"),PMT_NIL); - if(tx_time != PMT_NIL){ - pmt_t tx_command_time = cons(tuple_ref(tx_time,0),tuple_ref(tx_time,1)); - pmt_t header_plus_burst = cdr(burst); - uint32_t frame_nr = 0; - - pmt_t fn = dict_ref(pdu_header,intern("fn"),PMT_NIL); - if(fn == PMT_NIL){ - gsmtap_hdr *header = (gsmtap_hdr *)blob_data(header_plus_burst); - uint32_t frame_nr = be32toh(header->frame_number); - } else { - frame_nr = to_uint64(fn); - } - - int mai = calculate_ma_sfh(d_maio, d_hsn, d_ma.size(), frame_nr); - uint16_t arfcn = d_ma[mai]; - - // if(fn == PMT_NIL){ - // header->arfcn = htobe16(arfcn); - // header->arfcn = header->arfcn | 0x8000; // set uplink flag - // } - - //compute the frequences to be set in the burst header - double freq_uplink = static_cast(gsm_arfcn2freq10(arfcn, 1)) * 1.0e5; - double freq_downlink = static_cast(gsm_arfcn2freq10(arfcn, 0)) * 1.0e5; - - pmt_t tx_command = dict_add(make_dict(),intern("lo_freq"),from_double(d_base_freq)); - tx_command = dict_add(tx_command,intern("dsp_freq"),from_double(freq_uplink-d_base_freq)); - tx_command = dict_add(tx_command,intern("time"),tx_command_time); - - pmt_t rx_command = dict_add(make_dict(),intern("lo_freq"),from_double(d_base_freq)); - rx_command = dict_add(rx_command,intern("dsp_freq"),from_double(freq_uplink-d_base_freq)); - rx_command = dict_add(rx_command,intern("time"),tx_command_time); - rx_command = dict_add(rx_command,intern("direction"),intern("RX")); - - pdu_header = dict_add(pdu_header, intern("tx_command"),tx_command); -// pdu_header = dict_add(pdu_header, intern("tx_command"),rx_command); -// std::cout << "arfcn " << arfcn << " mai " << mai << " d_ma.size() " << d_ma.size() << " d_hsn " << d_hsn << std::endl; - std::cout << "arfcn_uplink " << arfcn << std::endl; -// std::cout << "freq_downlink " << freq_downlink << std::endl; -// std::cout << "pdu_header " << pdu_header << std::endl; -// std::cout << "size_header_plus_burst " << length(header_plus_burst) << std::endl; - message_port_pub(mp("bursts_out"), cons(pdu_header,header_plus_burst)); - } - } else { - message_port_pub(mp("bursts_out"), burst); - } - } - - bool freq_hopping_impl::set_hopping_params(pmt_t hopping_params){ - bool retval = false; - if(hopping_params != PMT_NIL){ - //set hopping parameters immediately - pmt_t hsn = dict_ref(hopping_params, intern("hsn"), PMT_NIL); - pmt_t maio = dict_ref(hopping_params, intern("maio"), PMT_NIL);; - pmt_t ma = dict_ref(hopping_params, intern("ma"), PMT_NIL); - - if(is_vector(ma) && is_integer(hsn) && is_integer(maio)){ //TODO: checking the values - d_hsn = to_uint64(hsn); - d_maio = to_uint64(maio); - d_ma.resize(length(ma)); - for(int i=0; i - * @section LICENSE - * - * Gr-gsm is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * Gr-gsm is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gr-gsm; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef INCLUDED_GSM_FREQ_HOPPING_IMPL_H -#define INCLUDED_GSM_FREQ_HOPPING_IMPL_H - -#include -#include -#include - -namespace gr { - namespace gsm { - - class freq_hopping_impl : public freq_hopping - { - private: - bool d_hopping_enable; //if true block do the hopping, if not block just passes the bursts - uint64_t d_hsn; //hopping sequence number - uint64_t d_maio; //mobile allocation index offset - double d_base_freq; //local oscillator frequency - std::vector d_ma; //mobile allocation - - pmt::pmt_t d_hopping_cmd; //TODO: change this uint64_to a std::map - void set_freq_metadata(pmt::pmt_t cmd); - bool set_hopping_params(pmt::pmt_t hopping_params); - public: - freq_hopping_impl(pmt::pmt_t hopping_cmd); - ~freq_hopping_impl(); - - void add_hopping_cmd(pmt::pmt_t hopping_cmd); - }; - - } // namespace gsm -} // namespace gr - -#endif /* INCLUDED_GSM_FREQ_HOPPING_IMPL_H */ diff --git a/swig/grgsm_swig.i b/swig/grgsm_swig.i index 8035dc5..d48e8ba 100644 --- a/swig/grgsm_swig.i +++ b/swig/grgsm_swig.i @@ -76,7 +76,8 @@ #include "grgsm/transmitter/txtime_setter.h" #include "grgsm/transmitter/preprocess_tx_burst.h" #include "grgsm/transmitter/gen_test_ab.h" -#include "grgsm/trx/freq_hopping.h" +#include "grgsm/trx/freq_hopper_tag.h" +#include "grgsm/trx/freq_hopper_msg.h" #include "grgsm/trx/trx_burst_if.h" %} @@ -155,8 +156,10 @@ GR_SWIG_BLOCK_MAGIC2(gsm, controlled_fractional_resampler_cc); GR_SWIG_BLOCK_MAGIC2(gsm, extract_cmc); %include "grgsm/misc_utils/extract_assignment_cmd.h" GR_SWIG_BLOCK_MAGIC2(gsm, extract_assignment_cmd); -%include "grgsm/trx/freq_hopping.h" -GR_SWIG_BLOCK_MAGIC2(gsm, freq_hopping); +%include "grgsm/trx/freq_hopper_tag.h" +GR_SWIG_BLOCK_MAGIC2(gsm, freq_hopper_tag); +%include "grgsm/trx/freq_hopper_msg.h" +GR_SWIG_BLOCK_MAGIC2(gsm, freq_hopper_msg); %include "grgsm/trx/trx_burst_if.h" GR_SWIG_BLOCK_MAGIC2(gsm, trx_burst_if); %include "grgsm/misc_utils/burst_to_fn_time.h" -- cgit v1.2.3