Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +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 | 462fa45 | 2015-07-20 17:46:52 +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_source_impl.h" |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 29 | #include "stdio.h" |
Martin Hauke | a7cafdd | 2015-08-01 13:01:13 +0200 | [diff] [blame] | 30 | #include <boost/scoped_ptr.hpp> |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 31 | #include <grgsm/gsmtap.h> |
| 32 | #include <grgsm/endian.h> |
| 33 | |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 34 | namespace gr { |
| 35 | namespace gsm { |
| 36 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 37 | burst_source::sptr |
| 38 | burst_source::make(const std::vector<int> &framenumbers, |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 39 | const std::vector<int> ×lots, |
| 40 | const std::vector<std::string> &burst_data) |
| 41 | { |
| 42 | return gnuradio::get_initial_sptr |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 43 | (new burst_source_impl(framenumbers, timeslots, burst_data)); |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | /* |
| 47 | * The private constructor |
| 48 | */ |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 49 | burst_source_impl::burst_source_impl(const std::vector<int> &framenumbers, |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 50 | const std::vector<int> ×lots, |
| 51 | const std::vector<std::string> &burst_data) |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 52 | : gr::block("burst_source", |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 53 | gr::io_signature::make(0, 0, 0), |
| 54 | gr::io_signature::make(0, 0, 0)), |
Vasil Velichkov | ff88ba4 | 2019-07-20 23:33:08 +0300 | [diff] [blame] | 55 | d_finished(false), |
| 56 | d_arfcn(0) |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 57 | { |
| 58 | message_port_register_out(pmt::mp("out")); |
| 59 | set_framenumbers(framenumbers); |
| 60 | set_timeslots(timeslots); |
| 61 | set_burst_data(burst_data); |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Our virtual destructor. |
| 66 | */ |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 67 | burst_source_impl::~burst_source_impl() |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 68 | { |
| 69 | if (d_finished == false){ |
| 70 | d_finished = true; |
| 71 | } |
| 72 | } |
| 73 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 74 | void burst_source_impl::set_framenumbers(const std::vector<int> &framenumbers) |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 75 | { |
| 76 | d_framenumbers = framenumbers; |
| 77 | } |
| 78 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 79 | void burst_source_impl::set_timeslots(const std::vector<int> ×lots) |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 80 | { |
| 81 | d_timeslots = timeslots; |
| 82 | } |
| 83 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 84 | void burst_source_impl::set_burst_data(const std::vector<std::string> &burst_data) |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 85 | { |
| 86 | d_burst_data = burst_data; |
| 87 | } |
| 88 | |
Vasil Velichkov | ff88ba4 | 2019-07-20 23:33:08 +0300 | [diff] [blame] | 89 | void burst_source_impl::set_arfcn(uint16_t arfcn) |
| 90 | { |
| 91 | d_arfcn = arfcn; |
| 92 | } |
| 93 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 94 | bool burst_source_impl::start() |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 95 | { |
| 96 | d_finished = false; |
| 97 | d_thread = boost::shared_ptr<gr::thread::thread> |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 98 | (new gr::thread::thread(boost::bind(&burst_source_impl::run, this))); |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 99 | return block::start(); |
| 100 | } |
| 101 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 102 | bool burst_source_impl::stop() |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 103 | { |
| 104 | d_finished = true; |
| 105 | d_thread->interrupt(); |
| 106 | d_thread->join(); |
| 107 | return block::stop(); |
| 108 | } |
| 109 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 110 | bool burst_source_impl::finished() |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 111 | { |
| 112 | return d_finished; |
| 113 | } |
| 114 | |
Roman Khassraf | 1ce4469 | 2015-08-03 11:16:10 +0200 | [diff] [blame] | 115 | void burst_source_impl::run() |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 116 | { |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 117 | for (int i=0; i<d_burst_data.size(); i++) |
| 118 | { |
| 119 | if (d_burst_data[i].length() == BURST_SIZE && |
| 120 | d_timeslots[i] >= 0 && d_timeslots[i] <= 7 && |
| 121 | d_framenumbers[i] >= 0 && d_framenumbers[i] <= (26 * 51 * 2048 - 1)) |
| 122 | { |
| 123 | boost::scoped_ptr<gsmtap_hdr> tap_header(new gsmtap_hdr()); |
| 124 | |
| 125 | tap_header->version = GSMTAP_VERSION; |
| 126 | tap_header->hdr_len = sizeof(gsmtap_hdr)/4; |
| 127 | tap_header->type = GSMTAP_TYPE_UM_BURST; |
| 128 | tap_header->timeslot = d_timeslots[i]; |
| 129 | tap_header->frame_number = htobe32(d_framenumbers[i]); |
| 130 | tap_header->sub_type = GSMTAP_BURST_NORMAL; |
Vasil Velichkov | ff88ba4 | 2019-07-20 23:33:08 +0300 | [diff] [blame] | 131 | tap_header->arfcn = d_arfcn; |
Roman Khassraf | 462fa45 | 2015-07-20 17:46:52 +0200 | [diff] [blame] | 132 | tap_header->signal_dbm = 0; |
| 133 | tap_header->snr_db = 0; |
| 134 | |
| 135 | uint8_t burst[BURST_SIZE]; |
| 136 | |
| 137 | for (int j=0; j<BURST_SIZE; j++) |
| 138 | { |
| 139 | if (d_burst_data[i][j] == '0') |
| 140 | { |
| 141 | burst[j] = 0; |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | burst[j] = 1; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | int8_t header_plus_burst[sizeof(gsmtap_hdr) + BURST_SIZE]; |
| 150 | memcpy(header_plus_burst, tap_header.get(), sizeof(gsmtap_hdr)); |
| 151 | memcpy(header_plus_burst + sizeof(gsmtap_hdr), burst, BURST_SIZE); |
| 152 | |
| 153 | pmt::pmt_t blob_header_plus_burst = pmt::make_blob(header_plus_burst, sizeof(gsmtap_hdr) + BURST_SIZE); |
| 154 | pmt::pmt_t msg = pmt::cons(pmt::PMT_NIL, blob_header_plus_burst); |
| 155 | |
| 156 | message_port_pub(pmt::mp("out"), msg); |
| 157 | } |
| 158 | } |
| 159 | post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::from_long(1))); |
| 160 | } |
| 161 | } /* namespace gsm */ |
| 162 | } /* namespace gr */ |
| 163 | |
| 164 | |