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), |
Piotr Krysik | ebf8880 | 2017-09-19 08:07:14 +0200 | [diff] [blame] | 50 | gr::io_signature::make(0, 0, 0)), |
| 51 | d_bursts(pmt::PMT_NIL) |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 52 | { |
| 53 | message_port_register_in(pmt::mp("in")); |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 54 | 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] | 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Our virtual destructor. |
| 59 | */ |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 60 | burst_sink_impl::~burst_sink_impl() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 61 | { |
| 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 Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 68 | void burst_sink_impl::process_burst(pmt::pmt_t msg) |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 69 | { |
| 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()); |
Vasil Velichkov | ff88ba4 | 2019-07-20 23:33:08 +0300 | [diff] [blame] | 93 | d_sub_types.push_back(header->sub_type); |
| 94 | d_sub_slots.push_back(header->sub_slot); |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 97 | std::vector<int> burst_sink_impl::get_framenumbers() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 98 | { |
| 99 | return d_framenumbers; |
| 100 | } |
| 101 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 102 | std::vector<int> burst_sink_impl::get_timeslots() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 103 | { |
| 104 | return d_timeslots; |
| 105 | } |
| 106 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 107 | std::vector<std::string> burst_sink_impl::get_burst_data() |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 108 | { |
| 109 | return d_burst_data; |
| 110 | } |
Piotr Krysik | ebf8880 | 2017-09-19 08:07:14 +0200 | [diff] [blame] | 111 | pmt::pmt_t burst_sink_impl::get_bursts() |
| 112 | { |
| 113 | return d_bursts; |
| 114 | } |
Vasil Velichkov | ff88ba4 | 2019-07-20 23:33:08 +0300 | [diff] [blame] | 115 | std::vector<uint8_t> burst_sink_impl::get_sub_types() |
| 116 | { |
| 117 | return d_sub_types; |
| 118 | } |
| 119 | std::vector<uint8_t> burst_sink_impl::get_sub_slots() |
| 120 | { |
| 121 | return d_sub_slots; |
| 122 | } |
Roman Khassraf | b894289 | 2015-07-21 10:53:41 +0200 | [diff] [blame] | 123 | } /* namespace gsm */ |
| 124 | } /* namespace gr */ |
| 125 | |