blob: bdc2192580fd8cbe580491a04aadbfe028c9661d [file] [log] [blame]
Roman Khassrafb8942892015-07-21 10:53:41 +02001/* -*- c++ -*- */
2/* @file
Piotr Krysika6268a52017-08-23 16:02:19 +02003 * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassrafb8942892015-07-21 10:53:41 +02004 * @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),
Piotr Krysikebf88802017-09-19 08:07:14 +020050 gr::io_signature::make(0, 0, 0)),
51 d_bursts(pmt::PMT_NIL)
Roman Khassrafb8942892015-07-21 10:53:41 +020052 {
53 message_port_register_in(pmt::mp("in"));
Roman Khassraf1ce44692015-08-03 11:16:10 +020054 set_msg_handler(pmt::mp("in"), boost::bind(&burst_sink_impl::process_burst, this, _1));
Roman Khassrafb8942892015-07-21 10:53:41 +020055 }
56
57 /*
58 * Our virtual destructor.
59 */
Roman Khassraf1ce44692015-08-03 11:16:10 +020060 burst_sink_impl::~burst_sink_impl()
Roman Khassrafb8942892015-07-21 10:53:41 +020061 {
62// for (int i=0; i<d_burst_data.size(); i++)
63// {
64// std::cout << d_framenumbers[i] << " " << d_timeslots[i] << " " << d_burst_data[i] << std::endl;
65// }
66 }
67
Roman Khassraf1ce44692015-08-03 11:16:10 +020068 void burst_sink_impl::process_burst(pmt::pmt_t msg)
Roman Khassrafb8942892015-07-21 10:53:41 +020069 {
70 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
71
72 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
73 int8_t * burst = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
74 size_t burst_len=pmt::blob_length(header_plus_burst)-sizeof(gsmtap_hdr);
75 uint32_t frame_nr = be32toh(header->frame_number);
76
77 std::stringstream burst_str;
78 for(int i=0; i<burst_len; i++)
79 {
80 if (static_cast<int>(burst[i]) == 0)
81 {
82 burst_str << "0";
83 }
84 else
85 {
86 burst_str << "1";
87 }
88 }
89
90 d_framenumbers.push_back(frame_nr);
91 d_timeslots.push_back(header->timeslot);
92 d_burst_data.push_back(burst_str.str());
93 }
94
Roman Khassraf1ce44692015-08-03 11:16:10 +020095 std::vector<int> burst_sink_impl::get_framenumbers()
Roman Khassrafb8942892015-07-21 10:53:41 +020096 {
97 return d_framenumbers;
98 }
99
Roman Khassraf1ce44692015-08-03 11:16:10 +0200100 std::vector<int> burst_sink_impl::get_timeslots()
Roman Khassrafb8942892015-07-21 10:53:41 +0200101 {
102 return d_timeslots;
103 }
104
Roman Khassraf1ce44692015-08-03 11:16:10 +0200105 std::vector<std::string> burst_sink_impl::get_burst_data()
Roman Khassrafb8942892015-07-21 10:53:41 +0200106 {
107 return d_burst_data;
108 }
Piotr Krysikebf88802017-09-19 08:07:14 +0200109 pmt::pmt_t burst_sink_impl::get_bursts()
110 {
111 return d_bursts;
112 }
Roman Khassrafb8942892015-07-21 10:53:41 +0200113 } /* namespace gsm */
114} /* namespace gr */
115