GNU Radio Manual and C++ API Reference  3.10.9.1
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  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 
12 #ifndef VECTOR_SOURCE_H
13 #define VECTOR_SOURCE_H
14 
15 #include <gnuradio/blocks/api.h>
16 #include <gnuradio/sync_block.h>
17 #include <cstdint>
18 
19 namespace gr {
20 namespace blocks {
21 
22 /*!
23  * \brief Source that streams T items based on the input \p data vector.
24  * \ingroup misc_blk
25  *
26  * \details
27  * This block produces a stream of samples based on an input
28  * vector. In C++, this is a std::vector<T>, and in Python,
29  * this is either a list or tuple. The data can repeat infinitely
30  * until the flowgraph is terminated by some other event or, the
31  * default, run the data once and stop.
32  *
33  * The vector source can also produce stream tags with the
34  * data. Pass in a vector of gr::tag_t objects and they will be
35  * emitted based on the specified offset of the tag.
36  *
37  * GNU Radio provides a utility Python module in gr.tag_utils to
38  * convert between tags and Python objects:
39  * gr.tag_utils.python_to_tag.
40  *
41  * We can create tags as Python lists (or tuples) using the list
42  * structure [int offset, pmt key, pmt value, pmt srcid]. It is
43  * important to define the list/tuple with the values in the
44  * correct order and with the correct data type. A python
45  * dictionary can also be used using the keys: "offset", "key",
46  * "value", and "srcid" with the same data types as for the lists.
47  *
48  * When given a list of tags, the vector source will emit the tags
49  * repeatedly by updating the offset relative to the vector stream
50  * length. That is, if the vector has 500 items and a tag has an
51  * offset of 0, that tag will be placed on item 0, 500, 1000,
52  * 1500, etc.
53  */
54 template <class T>
55 class BLOCKS_API vector_source : virtual public sync_block
56 {
57 public:
58  // gr::blocks::vector_source::sptr
59  typedef std::shared_ptr<vector_source<T>> sptr;
60 
61  static sptr make(const std::vector<T>& data,
62  bool repeat = false,
63  unsigned int vlen = 1,
64  const std::vector<tag_t>& tags = std::vector<tag_t>());
65 
66  virtual void rewind() = 0;
67  virtual void set_data(const std::vector<T>& data,
68  const std::vector<tag_t>& tags = std::vector<tag_t>()) = 0;
69  virtual void set_repeat(bool repeat) = 0;
70 };
71 
77 } /* namespace blocks */
78 } /* namespace gr */
79 
80 #endif /* VECTOR_SOURCE_H */
repeat each input repeat times
Definition: repeat.h:30
Source that streams T items based on the input data vector.
Definition: vector_source.h:56
static sptr make(const std::vector< T > &data, bool repeat=false, unsigned int vlen=1, const std::vector< tag_t > &tags=std::vector< tag_t >())
std::shared_ptr< vector_source< T > > sptr
Definition: vector_source.h:59
virtual void set_repeat(bool repeat)=0
virtual void set_data(const std::vector< T > &data, const std::vector< tag_t > &tags=std::vector< tag_t >())=0
virtual void rewind()=0
synchronous 1:1 input to output with history
Definition: sync_block.h:26
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
vector_source< std::int32_t > vector_source_i
Definition: vector_source.h:74
vector_source< std::int16_t > vector_source_s
Definition: vector_source.h:73
vector_source< float > vector_source_f
Definition: vector_source.h:75
vector_source< std::uint8_t > vector_source_b
Definition: vector_source.h:72
vector_source< gr_complex > vector_source_c
Definition: vector_source.h:76
GNU Radio logging wrapper.
Definition: basic_block.h:29