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