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