blob: 5d3ae9af40372e6a514fbacba060a62c2752fff5 [file] [log] [blame]
Piotr Krysikccb5e682017-11-07 19:34:22 +01001/* -*- c++ -*- */
2/* @file
3 * @author Piotr Krysik <ptrkrysik@gmail.com>
4 * @section LICENSE
5 *
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.
10 *
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.
15 *
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.
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
28#include <grgsm/gsmtap.h>
29#include <grgsm/gsm_constants.h>
30#include "preprocess_tx_burst_impl.h"
31
32namespace gr {
33 namespace gsm {
34
35 preprocess_tx_burst::sptr
36 preprocess_tx_burst::make()
37 {
38 return gnuradio::get_initial_sptr
39 (new preprocess_tx_burst_impl());
40 }
41
42 /*
43 * The private constructor
44 */
45 preprocess_tx_burst_impl::preprocess_tx_burst_impl()
46 : gr::block("preprocess_tx_burst",
47 gr::io_signature::make(0, 0, 0),
48 gr::io_signature::make(0, 0, 0))
49 {
50 message_port_register_in(pmt::intern("bursts_in"));
51 message_port_register_out(pmt::intern("bursts_out"));
52
53 set_msg_handler(pmt::intern("bursts_in"), boost::bind(&preprocess_tx_burst_impl::process_burst, this, _1));
54 }
55
56 /*
57 * Our virtual destructor.
58 */
59 preprocess_tx_burst_impl::~preprocess_tx_burst_impl()
60 {
61 }
62
63 void preprocess_tx_burst_impl::process_burst(pmt::pmt_t burst)
64 {
65 int8_t * header_bits = (int8_t *)(pmt::blob_data(pmt::cdr(burst)));
66 int8_t * burst_bits = (int8_t *)(pmt::blob_data(pmt::cdr(burst)))+sizeof(gsmtap_hdr);
67
68 pmt::pmt_t header_bits_pmt = pmt::make_blob(header_bits,sizeof(gsmtap_hdr));
69
70 size_t burst_size = pmt::blob_length(pmt::cdr(burst))-sizeof(gsmtap_hdr);
71 if(((gsmtap_hdr*)header_bits)->sub_type == GSMTAP_BURST_ACCESS){ //cut unneeded bits from the end of access bursts
72 burst_size = ACCESS_BURST_SIZE;
73 }
74 pmt::pmt_t burst_bits_pmt = pmt::make_blob(burst_bits, burst_size);
75
76 pmt::pmt_t pdu_first_part = pmt::car(burst);
77// pmt::pmt_t new_pdu_first_part = pmt::dict_add( pdu_first_part, pmt::intern("gsmtap_header"), header_bits_pmt );
78 pmt::pmt_t new_pdu_first_part = pdu_first_part;
79
80 pmt::pmt_t new_msg = pmt::cons(new_pdu_first_part, burst_bits_pmt);
81 message_port_pub(pmt::intern("bursts_out"), new_msg);
82 }
83 } /* namespace gsm */
84} /* namespace gr */
85