blob: c16f13330ae6b3abacb954d1c9969dfa2aa5daa5 [file] [log] [blame]
Roman Khassraf1e82b8d2015-07-29 11:01:34 +02001/* -*- c++ -*- */
2/* @file
Piotr Krysika6268a52017-08-23 16:02:19 +02003 * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassraf1e82b8d2015-07-29 11:01:34 +02004 * @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 "message_sink_impl.h"
29#include <stdio.h>
30#include <sstream>
31
32namespace gr {
33 namespace gsm {
34
35 message_sink::sptr
36 message_sink::make()
37 {
38 return gnuradio::get_initial_sptr
39 (new message_sink_impl());
40 }
41
42 /*
43 * The private constructor
44 */
45 message_sink_impl::message_sink_impl()
46 : gr::block("message_sink",
47 gr::io_signature::make(0, 0, 0),
48 gr::io_signature::make(0, 0, 0))
49 {
50 message_port_register_in(pmt::mp("in"));
51 set_msg_handler(pmt::mp("in"), boost::bind(&message_sink_impl::process_message, this, _1));
52 }
53
54 /*
55 * Our virtual destructor.
56 */
57 message_sink_impl::~message_sink_impl()
58 {
59 for (int i=0; i<d_messages.size(); i++)
60 {
61 std::cout << d_messages[i].c_str() << std::endl;
62 }
63 }
64
65 void message_sink_impl::process_message(pmt::pmt_t msg)
66 {
67 pmt::pmt_t message_plus_header_blob = pmt::cdr(msg);
68 uint8_t * message_plus_header = (uint8_t *)pmt::blob_data(message_plus_header_blob);
69 size_t message_plus_header_len = pmt::blob_length(message_plus_header_blob);
70
71 std::stringstream s_msg_stream;
72 for (int i=0; i<message_plus_header_len; i++)
73 {
74 if (i>0)
75 {
76 s_msg_stream << (" ");
77 }
78 s_msg_stream << std::hex << std::setw(2) << std::setfill('0') << (unsigned)message_plus_header[i];
79 }
80 d_messages.push_back(s_msg_stream.str());
81 }
82
83 std::vector<std::string> message_sink_impl::get_messages()
84 {
85 return d_messages;
86 }
87
88 } /* namespace gsm */
89} /* namespace gr */
90