rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 3 | * @author (C) 2015 by Pieter Robyns <pieter.robyns@uhasselt.be> |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 4 | * @section LICENSE |
Martin Jesper Low Madsen | f3105d9 | 2015-06-24 13:33:56 +0200 | [diff] [blame] | 5 | * |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 6 | * Gr-gsm is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3, or (at your option) |
| 9 | * any later version. |
Martin Jesper Low Madsen | f3105d9 | 2015-06-24 13:33:56 +0200 | [diff] [blame] | 10 | * |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 11 | * Gr-gsm is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Martin Jesper Low Madsen | f3105d9 | 2015-06-24 13:33:56 +0200 | [diff] [blame] | 15 | * |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with gr-gsm; see the file COPYING. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 19 | * Boston, MA 02110-1301, USA. |
Martin Jesper Low Madsen | f3105d9 | 2015-06-24 13:33:56 +0200 | [diff] [blame] | 20 | * |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #include <gnuradio/io_signature.h> |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 28 | #include <grgsm/gsmtap.h> |
Martin Jesper Low Madsen | f3105d9 | 2015-06-24 13:33:56 +0200 | [diff] [blame] | 29 | #include <grgsm/endian.h> |
rpp | 11b549e | 2015-06-11 10:25:19 +0200 | [diff] [blame] | 30 | #include <boost/algorithm/clamp.hpp> |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 31 | #include "cx_channel_hopper_impl.h" |
Piotr Krysik | b7cce89 | 2018-05-11 11:37:21 +0200 | [diff] [blame] | 32 | #include "../misc_utils/freq_hopping_utils.h" |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 33 | |
| 34 | namespace gr { |
| 35 | namespace gsm { |
| 36 | |
| 37 | cx_channel_hopper::sptr |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 38 | cx_channel_hopper::make(const std::vector<int> &ma, int maio, int hsn) |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 39 | { |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 40 | return gnuradio::get_initial_sptr |
| 41 | (new cx_channel_hopper_impl(ma, maio, hsn)); |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* |
| 45 | * The private constructor |
| 46 | */ |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 47 | cx_channel_hopper_impl::cx_channel_hopper_impl(const std::vector<int> &ma, int maio, int hsn) |
| 48 | : gr::block("cx_channel_hopper", |
| 49 | gr::io_signature::make(0, 0, 0), |
| 50 | gr::io_signature::make(0, 0, 0)), |
| 51 | d_ma(ma), |
| 52 | d_maio(maio), |
| 53 | d_hsn(hsn) |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 54 | { |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 55 | d_narfcn = ma.size(); |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 56 | |
rpp | 11b549e | 2015-06-11 10:25:19 +0200 | [diff] [blame] | 57 | // Check user input for GSM 05.02, p16 compliance |
| 58 | if(d_narfcn < 1 || d_narfcn > 64) { |
| 59 | std::cerr << "warning: clamping number of RFCNs in the MA (" << d_narfcn << "), which should be 1 <= N <= 64." << std::endl; |
| 60 | d_narfcn = boost::algorithm::clamp(d_narfcn, 1, 64); |
| 61 | d_ma.resize(d_narfcn); |
| 62 | } |
| 63 | |
| 64 | if(d_maio < 0 || d_maio >= d_narfcn) { |
| 65 | std::cerr << "warning: clamping MAIO (" << d_maio << "), which should be 0 <= MAIO < N." << std::endl; |
| 66 | d_maio = boost::algorithm::clamp(d_maio, 0, d_narfcn - 1); |
| 67 | } |
| 68 | |
| 69 | if(d_hsn < 0 || d_hsn > 63) { |
| 70 | std::cerr << "warning: clamping HSN (" << d_hsn << "), which should be 0 <= HSN < 64." << std::endl; |
| 71 | d_hsn = boost::algorithm::clamp(d_hsn, 0, 63); |
| 72 | } |
| 73 | |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 74 | message_port_register_in(pmt::mp("CX")); |
| 75 | set_msg_handler(pmt::mp("CX"), boost::bind(&cx_channel_hopper_impl::assemble_bursts, this, _1)); |
| 76 | message_port_register_out(pmt::mp("bursts")); |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Our virtual destructor. |
| 81 | */ |
| 82 | cx_channel_hopper_impl::~cx_channel_hopper_impl() |
| 83 | { |
| 84 | } |
| 85 | |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 86 | /** |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 87 | * Given MA, MAIO, HSN, and FN, decide which frames |
| 88 | * to forward to the demapper. |
| 89 | */ |
| 90 | void cx_channel_hopper_impl::assemble_bursts(pmt::pmt_t msg) |
| 91 | { |
| 92 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 93 | gsmtap_hdr *header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
| 94 | |
| 95 | uint32_t frame_nr = be32toh(header->frame_number); |
Piotr Krysik | 938cda4 | 2016-07-14 11:44:45 +0200 | [diff] [blame] | 96 | uint16_t frame_ca = be16toh(header->arfcn) & 0x3FFF; //change highest bits to '0' |
| 97 | //in order to leave only ARFCN number |
Your Name | a7976a3 | 2016-07-12 17:23:13 +0430 | [diff] [blame] | 98 | |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 99 | int mai = calculate_ma_sfh(d_maio, d_hsn, d_narfcn, frame_nr); |
Piotr Krysik | b7cce89 | 2018-05-11 11:37:21 +0200 | [diff] [blame] | 100 | /* |
rpp | 11b549e | 2015-06-11 10:25:19 +0200 | [diff] [blame] | 101 | if(d_ma[mai] == (int)frame_ca) { |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 102 | message_port_pub(pmt::mp("bursts"), msg); |
Piotr Krysik | b7cce89 | 2018-05-11 11:37:21 +0200 | [diff] [blame] | 103 | }*/ |
rpp | 267214a | 2015-06-10 11:49:55 +0200 | [diff] [blame] | 104 | } |
| 105 | |
rpp | 4f0f3b5 | 2015-06-10 10:23:30 +0200 | [diff] [blame] | 106 | } /* namespace gsm */ |
| 107 | } /* namespace gr */ |