Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 3 | * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com> |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 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 Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 28 | #include "burst_sink_impl.h" |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <sstream> |
iZsh | 868abf7 | 2015-08-16 13:50:20 +0200 | [diff] [blame] | 31 | #include <grgsm/endian.h> |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 32 | #include <grgsm/gsmtap.h> |
| 33 | |
| 34 | namespace gr { |
| 35 | namespace gsm { |
| 36 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 37 | burst_sink::sptr |
| 38 | burst_sink::make() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 39 | { |
| 40 | return gnuradio::get_initial_sptr |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 41 | (new burst_sink_impl()); |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* |
| 45 | * The private constructor |
| 46 | */ |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 47 | burst_sink_impl::burst_sink_impl() |
| 48 | : gr::block("burst_sink", |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 49 | 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 Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 53 | set_msg_handler(pmt::mp("in"), boost::bind(&burst_sink_impl::process_burst, this, _1)); |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Our virtual destructor. |
| 58 | */ |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 59 | burst_sink_impl::~burst_sink_impl() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 60 | { |
| 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 Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 67 | void burst_sink_impl::process_burst(pmt::pmt_t msg) |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 68 | { |
| 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 Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 94 | std::vector<int> burst_sink_impl::get_framenumbers() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 95 | { |
| 96 | return d_framenumbers; |
| 97 | } |
| 98 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 99 | std::vector<int> burst_sink_impl::get_timeslots() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 100 | { |
| 101 | return d_timeslots; |
| 102 | } |
| 103 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 104 | std::vector<std::string> burst_sink_impl::get_burst_data() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 105 | { |
| 106 | return d_burst_data; |
| 107 | } |
| 108 | |
| 109 | } /* namespace gsm */ |
| 110 | } /* namespace gr */ |
| 111 | |