GNU Radio 3.6.4.2 C++ API
gr_test.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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 #ifndef INCLUDED_GR_TEST_H
24 #define INCLUDED_GR_TEST_H
25 
26 #include <gr_core_api.h>
27 #include <gr_block.h>
28 #include <string>
29 #include "gr_test_types.h"
30 
31 class gr_test;
33 
34 // public constructor
35 GR_CORE_API gr_test_sptr gr_make_test (const std::string &name=std::string("gr_test"),
36  int min_inputs=1, int max_inputs=1, unsigned int sizeof_input_item=1,
37  int min_outputs=1, int max_outputs=1, unsigned int sizeof_output_item=1,
38  unsigned int history=1,unsigned int output_multiple=1,double relative_rate=1.0,
40 
41 /*!
42  * \brief Test class for testing runtime system (setting up buffers and such.)
43  * \ingroup misc
44  *
45  * This block does not do any usefull actual data processing.
46  * It just exposes setting all standard block parameters using the contructor or public methods.
47  *
48  * This block can be usefull when testing the runtime system.
49  * You can force this block to have a large history, decimation
50  * factor and/or large output_multiple.
51  * The runtime system should detect this and create large enough buffers
52  * all through the signal chain.
53  */
54 class GR_CORE_API gr_test : public gr_block {
55 
56  public:
57 
58  ~gr_test (){}
59 
60 int general_work (int noutput_items,
61  gr_vector_int &ninput_items,
62  gr_vector_const_void_star &input_items,
63  gr_vector_void_star &output_items);
64  // ----------------------------------------------------------------
65  // override these to define your behavior
66  // ----------------------------------------------------------------
67 
68  /*!
69  * \brief Estimate input requirements given output request
70  *
71  * \param noutput_items number of output items to produce
72  * \param ninput_items_required number of input items required on each input stream
73  *
74  * Given a request to product \p noutput_items, estimate the number of
75  * data items required on each input stream. The estimate doesn't have
76  * to be exact, but should be close.
77  */
78  void forecast (int noutput_items,
79  gr_vector_int &ninput_items_required)
80  {
81  unsigned ninputs = ninput_items_required.size ();
82  for (unsigned i = 0; i < ninputs; i++)
83  ninput_items_required[i] = (int)((double)noutput_items / relative_rate()) + (int)history();
84  }
85 
86 
87  /*!
88  * \brief Force check topology to return true or false.
89  *
90  * \param check_topology value to return when check_topology is called (true or false)
91  * default check_topology returns true
92  *
93  */
94  void set_check_topology (bool check_topology){ d_check_topology=check_topology;}
95 
96  /*!
97  * \brief Confirm that ninputs and noutputs is an acceptable combination.
98  *
99  * \param ninputs number of input streams connected
100  * \param noutputs number of output streams connected
101  *
102  * \returns true if this is a valid configuration for this block.
103  *
104  * This function is called by the runtime system whenever the
105  * topology changes. Most classes do not need to override this.
106  * This check is in addition to the constraints specified by the input
107  * and output gr_io_signatures.
108  */
109  bool check_topology (int ninputs, int noutputs) { return d_check_topology;}
110 
111  // ----------------------------------------------------------------
112  /*
113  * The following two methods provide special case info to the
114  * scheduler in the event that a block has a fixed input to output
115  * ratio. gr_sync_block, gr_sync_decimator and gr_sync_interpolator
116  * override these. If you're fixed rate, subclass one of those.
117  */
118  /*!
119  * \brief Given ninput samples, return number of output samples that will be produced.
120  * N.B. this is only defined if fixed_rate returns true.
121  * Generally speaking, you don't need to override this.
122  */
123  int fixed_rate_ninput_to_noutput(int ninput) { return (int)((double)ninput/relative_rate()); }
124 
125  /*!
126  * \brief Given noutput samples, return number of input samples required to produce noutput.
127  * N.B. this is only defined if fixed_rate returns true.
128  */
129  int fixed_rate_noutput_to_ninput(int noutput) { return (int)((double)noutput*relative_rate()); }
130 
131  /*!
132  * \brief Set if fixed rate should return true.
133  * N.B. This is normally a private method but we make it available here as public.
134  */
135  void set_fixed_rate_public(bool fixed_rate){ set_fixed_rate(fixed_rate);}
136 
137  /*!
138  * \brief Set the consume pattern.
139  *
140  * \param cons_type which consume pattern to use
141  */
142  void set_consume_type (gr_consume_type_t cons_type) { d_consume_type=cons_type;}
143 
144  /*!
145  * \brief Set the consume limit.
146  *
147  * \param limit min or maximum items to consume (depending on consume_type)
148  */
149  void set_consume_limit (unsigned int limit) { d_min_consume=limit; d_max_consume=limit;}
150 
151  /*!
152  * \brief Set the produce pattern.
153  *
154  * \param prod_type which produce pattern to use
155  */
156  void set_produce_type (gr_produce_type_t prod_type) { d_produce_type=prod_type;}
157 
158  /*!
159  * \brief Set the produce limit.
160  *
161  * \param limit min or maximum items to produce (depending on produce_type)
162  */
163  void set_produce_limit (unsigned int limit) { d_min_produce=limit; d_max_produce=limit;}
164 
165  // ----------------------------------------------------------------------------
166 
167 
168 
169  protected:
170  unsigned int d_sizeof_input_item;
171  unsigned int d_sizeof_output_item;
173  char d_temp;
180  gr_test (const std::string &name,int min_inputs, int max_inputs, unsigned int sizeof_input_item,
181  int min_outputs, int max_outputs, unsigned int sizeof_output_item,
182  unsigned int history,unsigned int output_multiple,double relative_rate,
183  bool fixed_rate,gr_consume_type_t cons_type, gr_produce_type_t prod_type);
184 
185 
186 
187  friend GR_CORE_API gr_test_sptr gr_make_test (const std::string &name,int min_inputs, int max_inputs, unsigned int sizeof_input_item,
188  int min_outputs, int max_outputs, unsigned int sizeof_output_item,
189  unsigned int history,unsigned int output_multiple,double relative_rate,
190  bool fixed_rate,gr_consume_type_t cons_type, gr_produce_type_t prod_type);
191 };
192 
193 
194 
195 #endif /* INCLUDED_GR_TEST_H */
void set_produce_type(gr_produce_type_t prod_type)
Set the produce pattern.
Definition: gr_test.h:156
virtual bool check_topology(int ninputs, int noutputs)
int d_max_consume
Definition: gr_test.h:176
unsigned history(void) const
Test class for testing runtime system (setting up buffers and such.)This block does not do any useful...
Definition: gr_test.h:54
unsigned int d_sizeof_output_item
Definition: gr_test.h:171
~gr_test()
Definition: gr_test.h:58
size_t output_multiple(void) const
Get the output multiple setting.
Definition: gr_test_types.h:38
void set_check_topology(bool check_topology)
Force check topology to return true or false.
Definition: gr_test.h:94
void set_fixed_rate(const bool fixed_rate)
Definition: gr_block.h:37
void set_fixed_rate_public(bool fixed_rate)
Set if fixed rate should return true. N.B. This is normally a private method but we make it available...
Definition: gr_test.h:135
shared_ptr documentation stub
Definition: shared_ptr_docstub.h:15
Definition: gr_test_types.h:26
#define GR_CORE_API
Definition: gr_core_api.h:30
bool check_topology(int ninputs, int noutputs)
Confirm that ninputs and noutputs is an acceptable combination.
Definition: gr_test.h:109
gr_consume_type_t
Definition: gr_test_types.h:25
void set_consume_type(gr_consume_type_t cons_type)
Set the consume pattern.
Definition: gr_test.h:142
unsigned int d_sizeof_input_item
Definition: gr_test.h:170
void set_consume_limit(unsigned int limit)
Set the consume limit.
Definition: gr_test.h:149
virtual int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
compute output items from input items
gr_produce_type_t
Definition: gr_test_types.h:37
gr_produce_type_t d_produce_type
Definition: gr_test.h:177
int fixed_rate_ninput_to_noutput(int ninput)
Given ninput samples, return number of output samples that will be produced. N.B. this is only define...
Definition: gr_test.h:123
bool d_check_topology
Definition: gr_test.h:172
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
int d_min_produce
Definition: gr_test.h:178
void set_produce_limit(unsigned int limit)
Set the produce limit.
Definition: gr_test.h:163
int d_max_produce
Definition: gr_test.h:179
bool fixed_rate(void) const
Get the fixed rate setting.
char d_temp
Definition: gr_test.h:173
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
Estimate input requirements given output request.
Definition: gr_test.h:78
int fixed_rate_noutput_to_ninput(int noutput)
Given noutput samples, return number of input samples required to produce noutput. N.B. this is only defined if fixed_rate returns true.
Definition: gr_test.h:129
double relative_rate(void) const
Get the relative rate setting.
GR_CORE_API gr_test_sptr gr_make_test(const std::string &name=std::string("gr_test"), int min_inputs=1, int max_inputs=1, unsigned int sizeof_input_item=1, int min_outputs=1, int max_outputs=1, unsigned int sizeof_output_item=1, unsigned int history=1, unsigned int output_multiple=1, double relative_rate=1.0, bool fixed_rate=true, gr_consume_type_t cons_type=CONSUME_NOUTPUT_ITEMS, gr_produce_type_t prod_type=PRODUCE_NOUTPUT_ITEMS)
int d_min_consume
Definition: gr_test.h:175
gr_consume_type_t d_consume_type
Definition: gr_test.h:174