Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
| 3 | * @author Piotr Krysik <ptrkrysik@gmail.com> |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 4 | * @author Vadim Yanitskiy <axilirator@gmail.com> |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 5 | * @section LICENSE |
| 6 | * |
| 7 | * Gr-gsm is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * Gr-gsm is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with gr-gsm; see the file COPYING. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include "config.h" |
| 26 | #endif |
| 27 | |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 28 | #include <assert.h> |
| 29 | |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 30 | #include <gnuradio/io_signature.h> |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 31 | #include <grgsm/gsm_constants.h> |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 32 | #include <grgsm/gsmtap.h> |
| 33 | |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 34 | #include "preprocess_tx_burst_impl.h" |
| 35 | |
| 36 | namespace gr { |
| 37 | namespace gsm { |
| 38 | |
| 39 | preprocess_tx_burst::sptr |
| 40 | preprocess_tx_burst::make() |
| 41 | { |
| 42 | return gnuradio::get_initial_sptr |
| 43 | (new preprocess_tx_burst_impl()); |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * The private constructor |
| 48 | */ |
| 49 | preprocess_tx_burst_impl::preprocess_tx_burst_impl() |
| 50 | : gr::block("preprocess_tx_burst", |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 51 | gr::io_signature::make(0, 0, 0), |
| 52 | gr::io_signature::make(0, 0, 0)) |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 53 | { |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 54 | message_port_register_in(pmt::mp("bursts_in")); |
| 55 | message_port_register_out(pmt::mp("bursts_out")); |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 56 | |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 57 | set_msg_handler(pmt::mp("bursts_in"), |
| 58 | boost::bind(&preprocess_tx_burst_impl::process_burst, this, _1)); |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* |
| 62 | * Our virtual destructor. |
| 63 | */ |
| 64 | preprocess_tx_burst_impl::~preprocess_tx_burst_impl() |
| 65 | { |
| 66 | } |
| 67 | |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 68 | void preprocess_tx_burst_impl::process_burst(pmt::pmt_t msg_in) |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 69 | { |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 70 | pmt::pmt_t blob_in = pmt::cdr(msg_in); |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 71 | |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 72 | // Extract GSMTAP header from message |
| 73 | gsmtap_hdr *burst_hdr = (gsmtap_hdr *) pmt::blob_data(blob_in); |
| 74 | |
| 75 | // Extract burst bits from message |
| 76 | uint8_t *burst_bits = (uint8_t *) |
| 77 | (pmt::blob_data(blob_in)) + sizeof(gsmtap_hdr); |
| 78 | |
| 79 | // Determine and check burst length |
| 80 | size_t burst_len = pmt::blob_length(blob_in) - sizeof(gsmtap_hdr); |
| 81 | assert(burst_len == BURST_SIZE); |
| 82 | |
| 83 | // The Access Burst last has reduced length |
| 84 | if (burst_hdr->sub_type == GSMTAP_BURST_ACCESS) |
| 85 | burst_len = ACCESS_BURST_SIZE; |
| 86 | |
| 87 | // Prepare an output message |
| 88 | pmt::pmt_t blob_out = pmt::make_blob(burst_bits, burst_len); |
Vadim Yanitskiy | 0be5e5b | 2017-11-30 06:15:58 +0700 | [diff] [blame] | 89 | pmt::pmt_t msg_out = pmt::cons(pmt::car(msg_in), blob_out); |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 90 | |
| 91 | /* Send a message to the output */ |
| 92 | message_port_pub(pmt::mp("bursts_out"), msg_out); |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 93 | } |
Vadim Yanitskiy | 70bec20 | 2017-11-29 22:44:18 +0700 | [diff] [blame] | 94 | |
Piotr Krysik | ccb5e68 | 2017-11-07 19:34:22 +0100 | [diff] [blame] | 95 | } /* namespace gsm */ |
| 96 | } /* namespace gr */ |