3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
23 #ifndef INCLUDED_GR_TEST_H
24 #define INCLUDED_GR_TEST_H
28 #include "gr_test_types.h"
31 typedef boost::shared_ptr<gr_test> gr_test_sptr;
34 gr_test_sptr gr_make_test (const std::string &name=std::string("gr_test"),
35 int min_inputs=1, int max_inputs=1, unsigned int sizeof_input_item=1,
36 int min_outputs=1, int max_outputs=1, unsigned int sizeof_output_item=1,
37 unsigned int history=1,unsigned int output_multiple=1,double relative_rate=1.0,
38 bool fixed_rate=true,gr_consume_type_t cons_type=CONSUME_NOUTPUT_ITEMS, gr_produce_type_t prod_type=PRODUCE_NOUTPUT_ITEMS);
41 * \brief Test class for testing runtime system (setting up buffers and such.)
44 * This block does not do any usefull actual data processing.
45 * It just exposes setting all standard block parameters using the contructor or public methods.
47 * This block can be usefull when testing the runtime system.
48 * You can force this block to have a large history, decimation
49 * factor and/or large output_multiple.
50 * The runtime system should detect this and create large enough buffers
51 * all through the signal chain.
58 class gr_test : public gr_block {
64 int general_work (int noutput_items,
65 gr_vector_int &ninput_items,
66 gr_vector_const_void_star &input_items,
67 gr_vector_void_star &output_items);
68 // ----------------------------------------------------------------
69 // override these to define your behavior
70 // ----------------------------------------------------------------
73 * \brief Estimate input requirements given output request
75 * \param noutput_items number of output items to produce
76 * \param ninput_items_required number of input items required on each input stream
78 * Given a request to product \p noutput_items, estimate the number of
79 * data items required on each input stream. The estimate doesn't have
80 * to be exact, but should be close.
82 void forecast (int noutput_items,
83 gr_vector_int &ninput_items_required)
85 unsigned ninputs = ninput_items_required.size ();
86 for (unsigned i = 0; i < ninputs; i++)
87 ninput_items_required[i] = (int)((double)noutput_items / relative_rate()) + (int)history();
92 * \brief Force check topology to return true or false.
94 * \param check_topology value to return when check_topology is called (true or false)
95 * default check_topology returns true
98 void set_check_topology (bool check_topology){ d_check_topology=check_topology;}
101 * \brief Confirm that ninputs and noutputs is an acceptable combination.
103 * \param ninputs number of input streams connected
104 * \param noutputs number of output streams connected
106 * \returns true if this is a valid configuration for this block.
108 * This function is called by the runtime system whenever the
109 * topology changes. Most classes do not need to override this.
110 * This check is in addition to the constraints specified by the input
111 * and output gr_io_signatures.
113 bool check_topology (int ninputs, int noutputs) { return d_check_topology;}
115 // ----------------------------------------------------------------
117 * The following two methods provide special case info to the
118 * scheduler in the event that a block has a fixed input to output
119 * ratio. gr_sync_block, gr_sync_decimator and gr_sync_interpolator
120 * override these. If you're fixed rate, subclass one of those.
123 * \brief Given ninput samples, return number of output samples that will be produced.
124 * N.B. this is only defined if fixed_rate returns true.
125 * Generally speaking, you don't need to override this.
127 int fixed_rate_ninput_to_noutput(int ninput) { return (int)((double)ninput/relative_rate()); }
130 * \brief Given noutput samples, return number of input samples required to produce noutput.
131 * N.B. this is only defined if fixed_rate returns true.
133 int fixed_rate_noutput_to_ninput(int noutput) { return (int)((double)noutput*relative_rate()); }
136 * \brief Set if fixed rate should return true.
137 * N.B. This is normally a private method but we make it available here as public.
139 void set_fixed_rate_public(bool fixed_rate){ set_fixed_rate(fixed_rate);}
142 * \brief Set the consume pattern.
144 * \param cons_type which consume pattern to use
146 void set_consume_type (gr_consume_type_t cons_type) { d_consume_type=cons_type;}
149 * \brief Set the consume limit.
151 * \param limit min or maximum items to consume (depending on consume_type)
153 void set_consume_limit (unsigned int limit) { d_min_consume=limit; d_max_consume=limit;}
156 * \brief Set the produce pattern.
158 * \param prod_type which produce pattern to use
160 void set_produce_type (gr_produce_type_t prod_type) { d_produce_type=prod_type;}
163 * \brief Set the produce limit.
165 * \param limit min or maximum items to produce (depending on produce_type)
167 void set_produce_limit (unsigned int limit) { d_min_produce=limit; d_max_produce=limit;}
169 // ----------------------------------------------------------------------------
174 unsigned int d_sizeof_input_item;
175 unsigned int d_sizeof_output_item;
176 bool d_check_topology;
178 gr_consume_type_t d_consume_type;
181 gr_produce_type_t d_produce_type;
184 gr_test (const std::string &name,int min_inputs, int max_inputs, unsigned int sizeof_input_item,
185 int min_outputs, int max_outputs, unsigned int sizeof_output_item,
186 unsigned int history,unsigned int output_multiple,double relative_rate,
187 bool fixed_rate,gr_consume_type_t cons_type, gr_produce_type_t prod_type);
191 friend gr_test_sptr gr_make_test (const std::string &name,int min_inputs, int max_inputs, unsigned int sizeof_input_item,
192 int min_outputs, int max_outputs, unsigned int sizeof_output_item,
193 unsigned int history,unsigned int output_multiple,double relative_rate,
194 bool fixed_rate,gr_consume_type_t cons_type, gr_produce_type_t prod_type);
199 #endif /* INCLUDED_GR_TEST_H */