blob: de26d3926c3b2582adbc75bd14ccdf5c60e9c058 [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>
31#include <grgsm/gsmtap.h>
32
33namespace gr {
34 namespace gsm {
35
Roman Khassraf1ce44692015-08-03 11:16:10 +020036 burst_sink::sptr
37 burst_sink::make()
Roman Khassrafb8942892015-07-21 10:53:41 +020038 {
39 return gnuradio::get_initial_sptr
Roman Khassraf1ce44692015-08-03 11:16:10 +020040 (new burst_sink_impl());
Roman Khassrafb8942892015-07-21 10:53:41 +020041 }
42
43 /*
44 * The private constructor
45 */
Roman Khassraf1ce44692015-08-03 11:16:10 +020046 burst_sink_impl::burst_sink_impl()
47 : gr::block("burst_sink",
Roman Khassrafb8942892015-07-21 10:53:41 +020048 gr::io_signature::make(0, 0, 0),
49 gr::io_signature::make(0, 0, 0))
50 {
51 message_port_register_in(pmt::mp("in"));
Roman Khassraf1ce44692015-08-03 11:16:10 +020052 set_msg_handler(pmt::mp("in"), boost::bind(&burst_sink_impl::process_burst, this, _1));
Roman Khassrafb8942892015-07-21 10:53:41 +020053 }
54
55 /*
56 * Our virtual destructor.
57 */
Roman Khassraf1ce44692015-08-03 11:16:10 +020058 burst_sink_impl::~burst_sink_impl()
Roman Khassrafb8942892015-07-21 10:53:41 +020059 {
60// for (int i=0; i<d_burst_data.size(); i++)
61// {
62// std::cout << d_framenumbers[i] << " " << d_timeslots[i] << " " << d_burst_data[i] << std::endl;
63// }
64 }
65
Roman Khassraf1ce44692015-08-03 11:16:10 +020066 void burst_sink_impl::process_burst(pmt::pmt_t msg)
Roman Khassrafb8942892015-07-21 10:53:41 +020067 {
68 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
69
70 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
71 int8_t * burst = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
72 size_t burst_len=pmt::blob_length(header_plus_burst)-sizeof(gsmtap_hdr);
73 uint32_t frame_nr = be32toh(header->frame_number);
74
75 std::stringstream burst_str;
76 for(int i=0; i<burst_len; i++)
77 {
78 if (static_cast<int>(burst[i]) == 0)
79 {
80 burst_str << "0";
81 }
82 else
83 {
84 burst_str << "1";
85 }
86 }
87
88 d_framenumbers.push_back(frame_nr);
89 d_timeslots.push_back(header->timeslot);
90 d_burst_data.push_back(burst_str.str());
91 }
92
Roman Khassraf1ce44692015-08-03 11:16:10 +020093 std::vector<int> burst_sink_impl::get_framenumbers()
Roman Khassrafb8942892015-07-21 10:53:41 +020094 {
95 return d_framenumbers;
96 }
97
Roman Khassraf1ce44692015-08-03 11:16:10 +020098 std::vector<int> burst_sink_impl::get_timeslots()
Roman Khassrafb8942892015-07-21 10:53:41 +020099 {
100 return d_timeslots;
101 }
102
Roman Khassraf1ce44692015-08-03 11:16:10 +0200103 std::vector<std::string> burst_sink_impl::get_burst_data()
Roman Khassrafb8942892015-07-21 10:53:41 +0200104 {
105 return d_burst_data;
106 }
107
108 } /* namespace gsm */
109} /* namespace gr */
110