blob: e145b77f34e9a6690fe81880c219ca9013101a4f [file] [log] [blame]
Piotr Krysik74c4f2c2016-07-15 13:12:46 +02001/* -*- c++ -*- */
2/* @file
Piotr Krysika6268a52017-08-23 16:02:19 +02003 * @author (C) 2016 by Piotr Krysik <ptrkrysik@gmail.com>
Piotr Krysik74c4f2c2016-07-15 13:12:46 +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 "msg_to_tag_impl.h"
29
30namespace gr {
31 namespace gsm {
32
33 msg_to_tag::sptr
34 msg_to_tag::make()
35 {
36 return gnuradio::get_initial_sptr
37 (new msg_to_tag_impl());
38 }
39
40 void msg_to_tag_impl::queue_msg(pmt::pmt_t msg){
41 if(pmt::is_dict(msg)){
42 try {
43 pmt::pmt_t keys = pmt::dict_keys(msg);
44 } catch (const pmt::wrong_type &e) {
45 msg = pmt::dict_add(pmt::make_dict(), pmt::car(msg), pmt::cdr(msg));
46 }
47 }
48 d_msg_queue.push_back(msg);
49 }
50
51 /*
52 * The private constructor
53 */
54 msg_to_tag_impl::msg_to_tag_impl()
55 : gr::sync_block("msg_to_tag",
56 gr::io_signature::make(1, 1, sizeof(gr_complex)),
57 gr::io_signature::make(1, 1, sizeof(gr_complex)))
58 {
59 message_port_register_in(pmt::mp("msg"));
Vadim Yanitskiya1169202021-05-03 19:00:43 +020060 set_msg_handler(pmt::mp("msg"), boost::bind(&msg_to_tag_impl::queue_msg, this, boost::placeholders::_1));
Piotr Krysik74c4f2c2016-07-15 13:12:46 +020061 }
62
63 /*
64 * Our virtual destructor.
65 */
66 msg_to_tag_impl::~msg_to_tag_impl()
67 {
68 }
69
70 int
71 msg_to_tag_impl::work(int noutput_items,
72 gr_vector_const_void_star &input_items,
73 gr_vector_void_star &output_items)
74 {
75 while(!d_msg_queue.empty()){
76 pmt::pmt_t msg(d_msg_queue.front());
77 d_msg_queue.pop_front();
78 if(pmt::is_dict(msg)){
79 pmt::pmt_t klist(pmt::dict_keys(msg));
80 for (size_t i = 0; i < pmt::length(klist); i++) {
81 pmt::pmt_t k(pmt::nth(i, klist));
82 pmt::pmt_t v(pmt::dict_ref(msg, k, pmt::PMT_NIL));
83 add_item_tag(0, nitems_written(0), k, v, alias_pmt());
84 }
85 } else if(pmt::is_number(msg)) {
86 add_item_tag(0, nitems_written(0), pmt::intern(""), msg, alias_pmt());
87 } else if(pmt::is_symbol(msg)) {
88 add_item_tag(0, nitems_written(0), msg, pmt::intern(""), alias_pmt());
89 }
90 }
91
92 memcpy(output_items[0], input_items[0], sizeof(gr_complex)*noutput_items);
93 // Tell runtime system how many output items we produced.
94 return noutput_items;
95 }
96
Piotr Krysik264fbf62017-11-05 12:25:51 +010097 } /* namespace gsm */
Piotr Krysik74c4f2c2016-07-15 13:12:46 +020098} /* namespace gr */
99