GNU Radio 3.6.5 C++ API

gr_test.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_GR_TEST_H
00024 #define INCLUDED_GR_TEST_H
00025 
00026 #include <gr_core_api.h>
00027 #include <gr_block.h>
00028 #include <string>
00029 #include "gr_test_types.h"
00030 
00031 class gr_test;
00032 typedef boost::shared_ptr<gr_test> gr_test_sptr;
00033 
00034 // public constructor
00035 GR_CORE_API gr_test_sptr gr_make_test (const std::string &name=std::string("gr_test"),
00036         int min_inputs=1, int max_inputs=1, unsigned int sizeof_input_item=1,
00037         int min_outputs=1, int max_outputs=1, unsigned int sizeof_output_item=1,
00038         unsigned int history=1,unsigned int output_multiple=1,double relative_rate=1.0,
00039         bool fixed_rate=true,gr_consume_type_t cons_type=CONSUME_NOUTPUT_ITEMS, gr_produce_type_t prod_type=PRODUCE_NOUTPUT_ITEMS);
00040 
00041 /*!
00042  * \brief Test class for testing runtime system (setting up buffers and such.)
00043  * \ingroup misc
00044  *
00045  * This block does not do any usefull actual data processing.
00046  * It just exposes setting all standard block parameters using the contructor or public methods.
00047  *
00048  * This block can be usefull when testing the runtime system.
00049  * You can force this block to have a large history, decimation
00050  * factor and/or large output_multiple.
00051  * The runtime system should detect this and create large enough buffers
00052  * all through the signal chain.
00053  */
00054 class GR_CORE_API gr_test : public gr_block {
00055 
00056  public:
00057 
00058   ~gr_test (){}
00059 
00060 int general_work (int noutput_items,
00061                             gr_vector_int &ninput_items,
00062                             gr_vector_const_void_star &input_items,
00063                             gr_vector_void_star &output_items);
00064   // ----------------------------------------------------------------
00065   //            override these to define your behavior
00066   // ----------------------------------------------------------------
00067 
00068   /*!
00069    * \brief  Estimate input requirements given output request
00070    *
00071    * \param noutput_items           number of output items to produce
00072    * \param ninput_items_required   number of input items required on each input stream
00073    *
00074    * Given a request to product \p noutput_items, estimate the number of
00075    * data items required on each input stream.  The estimate doesn't have
00076    * to be exact, but should be close.
00077    */
00078    void forecast (int noutput_items,
00079                          gr_vector_int &ninput_items_required)
00080    {
00081      unsigned ninputs = ninput_items_required.size ();
00082      for (unsigned i = 0; i < ninputs; i++)
00083        ninput_items_required[i] = (int)((double)noutput_items / relative_rate()) + (int)history();
00084    }
00085 
00086 
00087   /*!
00088    * \brief Force check topology to return true or false.
00089    *
00090    * \param check_topology      value to return when check_topology is called (true or false)
00091    * default check_topology returns true
00092    *
00093    */
00094    void set_check_topology (bool check_topology){ d_check_topology=check_topology;}
00095 
00096   /*!
00097    * \brief Confirm that ninputs and noutputs is an acceptable combination.
00098    *
00099    * \param ninputs     number of input streams connected
00100    * \param noutputs    number of output streams connected
00101    *
00102    * \returns true if this is a valid configuration for this block.
00103    *
00104    * This function is called by the runtime system whenever the
00105    * topology changes.  Most classes do not need to override this.
00106    * This check is in addition to the constraints specified by the input
00107    * and output gr_io_signatures.
00108    */
00109   bool check_topology (int ninputs, int noutputs) { return d_check_topology;}
00110 
00111   // ----------------------------------------------------------------
00112   /*
00113    * The following two methods provide special case info to the
00114    * scheduler in the event that a block has a fixed input to output
00115    * ratio.  gr_sync_block, gr_sync_decimator and gr_sync_interpolator
00116    * override these.  If you're fixed rate, subclass one of those.
00117    */
00118   /*!
00119    * \brief Given ninput samples, return number of output samples that will be produced.
00120    * N.B. this is only defined if fixed_rate returns true.
00121    * Generally speaking, you don't need to override this.
00122    */
00123   int fixed_rate_ninput_to_noutput(int ninput) { return (int)((double)ninput/relative_rate()); }
00124 
00125   /*!
00126    * \brief Given noutput samples, return number of input samples required to produce noutput.
00127    * N.B. this is only defined if fixed_rate returns true.
00128    */
00129   int fixed_rate_noutput_to_ninput(int noutput)  { return (int)((double)noutput*relative_rate()); }
00130 
00131   /*!
00132    * \brief Set if fixed rate should return true.
00133    * N.B. This is normally a private method but we make it available here as public.
00134    */
00135   void set_fixed_rate_public(bool fixed_rate){ set_fixed_rate(fixed_rate);}
00136 
00137   /*!
00138    * \brief Set the consume pattern.
00139    *
00140    * \param cons_type   which consume pattern to use
00141    */
00142   void set_consume_type (gr_consume_type_t cons_type) { d_consume_type=cons_type;}
00143 
00144   /*!
00145    * \brief Set the consume limit.
00146    *
00147    * \param limit       min or maximum items to consume (depending on consume_type)
00148    */
00149   void set_consume_limit (unsigned int limit) { d_min_consume=limit; d_max_consume=limit;}
00150 
00151   /*!
00152    * \brief Set the produce pattern.
00153    *
00154    * \param prod_type   which produce pattern to use
00155    */
00156   void set_produce_type (gr_produce_type_t prod_type) { d_produce_type=prod_type;}
00157 
00158   /*!
00159    * \brief Set the produce limit.
00160    *
00161    * \param limit       min or maximum items to produce (depending on produce_type)
00162    */
00163   void set_produce_limit (unsigned int limit) { d_min_produce=limit; d_max_produce=limit;}
00164 
00165   // ----------------------------------------------------------------------------
00166 
00167 
00168 
00169  protected:
00170   unsigned int d_sizeof_input_item;
00171   unsigned int d_sizeof_output_item;
00172   bool d_check_topology;
00173   char d_temp;
00174   gr_consume_type_t d_consume_type;
00175   int d_min_consume;
00176   int d_max_consume;
00177   gr_produce_type_t d_produce_type;
00178   int d_min_produce;
00179   int d_max_produce;
00180   gr_test (const std::string &name,int min_inputs, int max_inputs, unsigned int sizeof_input_item,
00181                                    int min_outputs, int max_outputs, unsigned int sizeof_output_item,
00182                                    unsigned int history,unsigned int output_multiple,double relative_rate,
00183                                    bool fixed_rate,gr_consume_type_t cons_type, gr_produce_type_t prod_type);
00184 
00185 
00186 
00187   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,
00188                                    int min_outputs, int max_outputs, unsigned int sizeof_output_item,
00189                                    unsigned int history,unsigned int output_multiple,double relative_rate,
00190                                    bool fixed_rate,gr_consume_type_t cons_type, gr_produce_type_t prod_type);
00191 };
00192 
00193 
00194 
00195 #endif /* INCLUDED_GR_TEST_H */