blob: 2023ee65243b4f3db1cc6226b6ec3357a87bfedc [file] [log] [blame]
Piotr Krysikccb5e682017-11-07 19:34:22 +01001/* -*- c++ -*- */
2/* @file
3 * @author Piotr Krysik <ptrkrysik@gmail.com>
Vadim Yanitskiy70bec202017-11-29 22:44:18 +07004 * @author Vadim Yanitskiy <axilirator@gmail.com>
Piotr Krysikccb5e682017-11-07 19:34:22 +01005 * @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 Yanitskiy70bec202017-11-29 22:44:18 +070028#include <assert.h>
29
Piotr Krysikccb5e682017-11-07 19:34:22 +010030#include <gnuradio/io_signature.h>
Piotr Krysikccb5e682017-11-07 19:34:22 +010031#include <grgsm/gsm_constants.h>
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070032#include <grgsm/gsmtap.h>
33
Piotr Krysikccb5e682017-11-07 19:34:22 +010034#include "preprocess_tx_burst_impl.h"
35
36namespace 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 Yanitskiy70bec202017-11-29 22:44:18 +070051 gr::io_signature::make(0, 0, 0),
52 gr::io_signature::make(0, 0, 0))
Piotr Krysikccb5e682017-11-07 19:34:22 +010053 {
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070054 message_port_register_in(pmt::mp("bursts_in"));
55 message_port_register_out(pmt::mp("bursts_out"));
Piotr Krysikccb5e682017-11-07 19:34:22 +010056
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070057 set_msg_handler(pmt::mp("bursts_in"),
Vadim Yanitskiya1169202021-05-03 19:00:43 +020058 boost::bind(&preprocess_tx_burst_impl::process_burst, this, boost::placeholders::_1));
Piotr Krysikccb5e682017-11-07 19:34:22 +010059 }
60
61 /*
62 * Our virtual destructor.
63 */
64 preprocess_tx_burst_impl::~preprocess_tx_burst_impl()
65 {
66 }
67
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070068 void preprocess_tx_burst_impl::process_burst(pmt::pmt_t msg_in)
Piotr Krysikccb5e682017-11-07 19:34:22 +010069 {
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070070 pmt::pmt_t blob_in = pmt::cdr(msg_in);
Piotr Krysikccb5e682017-11-07 19:34:22 +010071
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070072 // 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 Yanitskiy0be5e5b2017-11-30 06:15:58 +070089 pmt::pmt_t msg_out = pmt::cons(pmt::car(msg_in), blob_out);
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070090
91 /* Send a message to the output */
92 message_port_pub(pmt::mp("bursts_out"), msg_out);
Piotr Krysikccb5e682017-11-07 19:34:22 +010093 }
Vadim Yanitskiy70bec202017-11-29 22:44:18 +070094
Piotr Krysikccb5e682017-11-07 19:34:22 +010095 } /* namespace gsm */
96} /* namespace gr */