GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
vector_source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2008,2012-2013,2018 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * 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.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * 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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #ifndef VECTOR_SOURCE_H
25 #define VECTOR_SOURCE_H
26 
27 #include <gnuradio/blocks/api.h>
28 #include <gnuradio/sync_block.h>
29 #include <cstdint>
30 
31 namespace gr {
32 namespace blocks {
33 
34 /*!
35  * \brief Source that streams T items based on the input \p data vector.
36  * \ingroup misc_blk
37  *
38  * \details
39  * This block produces a stream of samples based on an input
40  * vector. In C++, this is a std::vector<T>, and in Python,
41  * this is either a list or tuple. The data can repeat infinitely
42  * until the flowgraph is terminated by some other event or, the
43  * default, run the data once and stop.
44  *
45  * The vector source can also produce stream tags with the
46  * data. Pass in a vector of gr::tag_t objects and they will be
47  * emitted based on the specified offset of the tag.
48  *
49  * GNU Radio provides a utility Python module in gr.tag_utils to
50  * convert between tags and Python objects:
51  * gr.tag_utils.python_to_tag.
52  *
53  * We can create tags as Python lists (or tuples) using the list
54  * structure [int offset, pmt key, pmt value, pmt srcid]. It is
55  * important to define the list/tuple with the values in the
56  * correct order and with the correct data type. A python
57  * dictionary can also be used using the keys: "offset", "key",
58  * "value", and "srcid" with the same data types as for the lists.
59  *
60  * When given a list of tags, the vector source will emit the tags
61  * repeatedly by updating the offset relative to the vector stream
62  * length. That is, if the vector has 500 items and a tag has an
63  * offset of 0, that tag will be placed on item 0, 500, 1000,
64  * 1500, etc.
65  */
66 template <class T>
67 class BLOCKS_API vector_source : virtual public sync_block
68 {
69 public:
70  // gr::blocks::vector_source::sptr
71  typedef boost::shared_ptr<vector_source<T>> sptr;
72 
73  static sptr make(const std::vector<T>& data,
74  bool repeat = false,
75  unsigned int vlen = 1,
76  const std::vector<tag_t>& tags = std::vector<tag_t>());
77 
78  virtual void rewind() = 0;
79  virtual void set_data(const std::vector<T>& data,
80  const std::vector<tag_t>& tags = std::vector<tag_t>()) = 0;
81  virtual void set_repeat(bool repeat) = 0;
82 };
83 
89 } /* namespace blocks */
90 } /* namespace gr */
91 
92 #endif /* VECTOR_SOURCE_H */
vector_source< gr_complex > vector_source_c
Definition: vector_source.h:88
vector_source< std::int32_t > vector_source_i
Definition: vector_source.h:86
vector_source< std::uint8_t > vector_source_b
Definition: vector_source.h:84
Source that streams T items based on the input data vector.
Definition: vector_source.h:67
boost::shared_ptr< vector_source< T > > sptr
Definition: vector_source.h:71
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
vector_source< std::int16_t > vector_source_s
Definition: vector_source.h:85
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:30
synchronous 1:1 input to output with historyOverride work to provide the signal processing implementa...
Definition: sync_block.h:37
repeat each input repeat timesMessage Ports:
Definition: repeat.h:41
vector_source< float > vector_source_f
Definition: vector_source.h:87