blob: 8be1422770f0d598eac2daa16ec2447e2fd5e317 [file] [log] [blame]
piotr6c692872014-02-08 14:16:26 +01001/* -*- c++ -*- */
ptrkrysik529895b2014-12-02 18:07:38 +01002/*
3 * @file
4 * @author Piotr Krysik <ptrkrysik@gmail.com>
5 * @section LICENSE
6 *
7 * Gr-gsm is free software; you can redistribute it and/or modify
piotr6c692872014-02-08 14:16:26 +01008 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
ptrkrysik529895b2014-12-02 18:07:38 +010011 *
12 * Gr-gsm is distributed in the hope that it will be useful,
piotr6c692872014-02-08 14:16:26 +010013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
ptrkrysik529895b2014-12-02 18:07:38 +010016 *
piotr6c692872014-02-08 14:16:26 +010017 * You should have received a copy of the GNU General Public License
ptrkrysik529895b2014-12-02 18:07:38 +010018 * along with gr-gsm; see the file COPYING. If not, write to
piotr6c692872014-02-08 14:16:26 +010019 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
ptrkrysik3be74a72014-12-13 10:11:00 +010028#include <grgsm/gsmtap.h>
piotr6d152d92014-02-21 00:02:44 +010029#include <iterator>
30#include <algorithm>
piotrfaacc722014-07-20 23:48:32 +020031#include "bursts_printer_impl.h"
piotrc00ce9c2014-08-04 11:21:24 +020032#include <unistd.h>
33
34#include <iostream>
piotr6c692872014-02-08 14:16:26 +010035
36namespace gr {
37 namespace gsm {
piotrc00ce9c2014-08-04 11:21:24 +020038 boost::mutex printer_mutex;
piotr6d152d92014-02-21 00:02:44 +010039 void bursts_printer_impl::bursts_print(pmt::pmt_t msg)
piotr6c692872014-02-08 14:16:26 +010040 {
ptrkrysik617ba032014-11-21 10:11:05 +010041 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
piotr6c692872014-02-08 14:16:26 +010042
ptrkrysik617ba032014-11-21 10:11:05 +010043 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
44 int8_t * burst = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
45 size_t burst_len=pmt::blob_length(header_plus_burst)-sizeof(gsmtap_hdr);
Roman Khassraf717b57b2015-04-12 18:09:45 +020046 uint32_t frame_nr;
ptrkrysik617ba032014-11-21 10:11:05 +010047
Jacob Gilbert607a09e2014-12-13 10:41:20 -080048 std::cout << d_prepend_string;
Roman Khassraf717b57b2015-04-12 18:09:45 +020049 if (d_prepend_fnr)
50 {
51 frame_nr = be32toh(header->frame_number);
52 std::cout << frame_nr << ":";
53 }
54
piotr6d152d92014-02-21 00:02:44 +010055 for(int ii=0; ii<burst_len; ii++)
piotr6c692872014-02-08 14:16:26 +010056 {
ptrkrysik617ba032014-11-21 10:11:05 +010057 std::cout << std::setprecision(1) << static_cast<int>(burst[ii]) << "";
piotr6c692872014-02-08 14:16:26 +010058 }
59 std::cout << std::endl;
60 }
piotrc00ce9c2014-08-04 11:21:24 +020061
piotr6c692872014-02-08 14:16:26 +010062 bursts_printer::sptr
Roman Khassraf717b57b2015-04-12 18:09:45 +020063 bursts_printer::make(pmt::pmt_t prepend_string, bool prepend_fnr)
piotr6c692872014-02-08 14:16:26 +010064 {
65 return gnuradio::get_initial_sptr
Roman Khassraf717b57b2015-04-12 18:09:45 +020066 (new bursts_printer_impl(prepend_string, prepend_fnr));
piotr6c692872014-02-08 14:16:26 +010067 }
68
69 /*
70 * The private constructor
71 */
Roman Khassraf717b57b2015-04-12 18:09:45 +020072 bursts_printer_impl::bursts_printer_impl(pmt::pmt_t prepend_string, bool prepend_fnr)
piotr6c692872014-02-08 14:16:26 +010073 : gr::block("bursts_printer",
74 gr::io_signature::make(0, 0, 0),
75 gr::io_signature::make(0, 0, 0))
76 {
Jacob Gilbert607a09e2014-12-13 10:41:20 -080077 d_prepend_string = prepend_string;
Roman Khassraf717b57b2015-04-12 18:09:45 +020078 d_prepend_fnr = prepend_fnr;
piotr6c692872014-02-08 14:16:26 +010079 message_port_register_in(pmt::mp("bursts"));
80 set_msg_handler(pmt::mp("bursts"), boost::bind(&bursts_printer_impl::bursts_print, this, _1));
81 }
82
83 /*
84 * Our virtual destructor.
85 */
86 bursts_printer_impl::~bursts_printer_impl()
87 {
88 }
89
90
91 } /* namespace gsm */
92} /* namespace gr */
93