blob: 5f1ae6442386c941e757eac03e4394acdf65740a [file] [log] [blame]
Roman Khassrafb8942892015-07-21 10:53:41 +02001/* -*- c++ -*- */
2/* @file
3 * @author Roman Khassraf <rkhassraf@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>
Roman Khassraf1ce44692015-08-03 11:16:10 +020028#include "burst_sink_impl.h"
Roman Khassrafb8942892015-07-21 10:53:41 +020029#include <stdio.h>
30#include <sstream>
iZsh868abf72015-08-16 13:50:20 +020031#include <grgsm/endian.h>
Roman Khassrafb8942892015-07-21 10:53:41 +020032#include <grgsm/gsmtap.h>
33
34namespace gr {
35 namespace gsm {
36
Roman Khassraf1ce44692015-08-03 11:16:10 +020037 burst_sink::sptr
38 burst_sink::make()
Roman Khassrafb8942892015-07-21 10:53:41 +020039 {
40 return gnuradio::get_initial_sptr
Roman Khassraf1ce44692015-08-03 11:16:10 +020041 (new burst_sink_impl());
Roman Khassrafb8942892015-07-21 10:53:41 +020042 }
43
44 /*
45 * The private constructor
46 */
Roman Khassraf1ce44692015-08-03 11:16:10 +020047 burst_sink_impl::burst_sink_impl()
48 : gr::block("burst_sink",
Roman Khassrafb8942892015-07-21 10:53:41 +020049 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(0, 0, 0))
51 {
52 message_port_register_in(pmt::mp("in"));
Roman Khassraf1ce44692015-08-03 11:16:10 +020053 set_msg_handler(pmt::mp("in"), boost::bind(&burst_sink_impl::process_burst, this, _1));
Roman Khassrafb8942892015-07-21 10:53:41 +020054 }
55
56 /*
57 * Our virtual destructor.
58 */
Roman Khassraf1ce44692015-08-03 11:16:10 +020059 burst_sink_impl::~burst_sink_impl()
Roman Khassrafb8942892015-07-21 10:53:41 +020060 {
61// for (int i=0; i<d_burst_data.size(); i++)
62// {
63// std::cout << d_framenumbers[i] << " " << d_timeslots[i] << " " << d_burst_data[i] << std::endl;
64// }
65 }
66
Roman Khassraf1ce44692015-08-03 11:16:10 +020067 void burst_sink_impl::process_burst(pmt::pmt_t msg)
Roman Khassrafb8942892015-07-21 10:53:41 +020068 {
69 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
70
71 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
72 int8_t * burst = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
73 size_t burst_len=pmt::blob_length(header_plus_burst)-sizeof(gsmtap_hdr);
74 uint32_t frame_nr = be32toh(header->frame_number);
75
76 std::stringstream burst_str;
77 for(int i=0; i<burst_len; i++)
78 {
79 if (static_cast<int>(burst[i]) == 0)
80 {
81 burst_str << "0";
82 }
83 else
84 {
85 burst_str << "1";
86 }
87 }
88
89 d_framenumbers.push_back(frame_nr);
90 d_timeslots.push_back(header->timeslot);
91 d_burst_data.push_back(burst_str.str());
92 }
93
Roman Khassraf1ce44692015-08-03 11:16:10 +020094 std::vector<int> burst_sink_impl::get_framenumbers()
Roman Khassrafb8942892015-07-21 10:53:41 +020095 {
96 return d_framenumbers;
97 }
98
Roman Khassraf1ce44692015-08-03 11:16:10 +020099 std::vector<int> burst_sink_impl::get_timeslots()
Roman Khassrafb8942892015-07-21 10:53:41 +0200100 {
101 return d_timeslots;
102 }
103
Roman Khassraf1ce44692015-08-03 11:16:10 +0200104 std::vector<std::string> burst_sink_impl::get_burst_data()
Roman Khassrafb8942892015-07-21 10:53:41 +0200105 {
106 return d_burst_data;
107 }
108
109 } /* namespace gsm */
110} /* namespace gr */
111