GNU Radio 3.4.2 C++ API
gr_block Class Reference

The abstract base class for all 'terminal' processing blocks.A signal processing flow is constructed by creating a tree of hierarchical blocks, which at any level may also contain terminal nodes that actually implement signal processing functions. This is the base class for all such leaf nodes. More...

#include <gr_block.h>

Inherits gr_basic_block.

Inherited by atsc_bit_timing_loop, atsc_field_sync_demux, gr_align_on_samplenumbers_ss, gr_clock_recovery_mm_cc, gr_clock_recovery_mm_ff, gr_copy, gr_fractional_interpolator_cc, gr_fractional_interpolator_ff, gr_keep_one_in_n, gr_mpsk_receiver_cc, gr_nop, gr_ofdm_bpsk_demapper, gr_ofdm_frame_acquisition, gr_ofdm_insert_preamble, gr_ofdm_sampler, gr_packed_to_unpacked_bb, gr_packed_to_unpacked_ii, gr_packed_to_unpacked_ss, gr_pfb_arb_resampler_ccf, gr_pfb_channelizer_ccf, gr_pfb_clock_sync_ccf, gr_pfb_clock_sync_fff, gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, gr_rational_resampler_base_scc, gr_simple_correlator, gr_simple_framer, gr_skiphead, gr_squelch_base_cc, gr_squelch_base_ff, gr_stream_mux, gr_sync_block, gr_test, gr_unpacked_to_packed_bb, gr_unpacked_to_packed_ii, gr_unpacked_to_packed_ss, howto_square_ff, noaa_hrpt_deframer, pager_flex_sync, qtgui_sink_c, qtgui_sink_f, qtgui_time_sink_c, qtgui_time_sink_f, trellis_metrics_c, trellis_metrics_f, trellis_metrics_i, trellis_metrics_s, trellis_pccc_decoder_b, trellis_pccc_decoder_combined_cb, trellis_pccc_decoder_combined_ci, trellis_pccc_decoder_combined_cs, trellis_pccc_decoder_combined_fb, trellis_pccc_decoder_combined_fi, trellis_pccc_decoder_combined_fs, trellis_pccc_decoder_i, trellis_pccc_decoder_s, trellis_sccc_decoder_b, trellis_sccc_decoder_combined_cb, trellis_sccc_decoder_combined_ci, trellis_sccc_decoder_combined_cs, trellis_sccc_decoder_combined_fb, trellis_sccc_decoder_combined_fi, trellis_sccc_decoder_combined_fs, trellis_sccc_decoder_i, trellis_sccc_decoder_s, trellis_siso_combined_f, trellis_siso_f, trellis_viterbi_b, trellis_viterbi_combined_cb, trellis_viterbi_combined_ci, trellis_viterbi_combined_cs, trellis_viterbi_combined_fb, trellis_viterbi_combined_fi, trellis_viterbi_combined_fs, trellis_viterbi_combined_ib, trellis_viterbi_combined_ii, trellis_viterbi_combined_is, trellis_viterbi_combined_sb, trellis_viterbi_combined_si, trellis_viterbi_combined_ss, trellis_viterbi_i, and trellis_viterbi_s.

List of all members.

Public Types

enum  { WORK_CALLED_PRODUCE = -2, WORK_DONE = -1 }
 Magic return values from general_work. More...
enum  tag_propagation_policy_t { TPP_DONT = 0, TPP_ALL_TO_ALL = 1, TPP_ONE_TO_ONE = 2 }

Public Member Functions

virtual ~gr_block ()
unsigned history () const
void set_history (unsigned history)
bool fixed_rate () const
 Return true if this block has a fixed input to output rate.
virtual void forecast (int noutput_items, gr_vector_int &ninput_items_required)
 Estimate input requirements given output request.
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)=0
 compute output items from input items
virtual bool start ()
 Called to enable drivers, etc for i/o devices.
virtual bool stop ()
 Called to disable drivers, etc for i/o devices.
void set_output_multiple (int multiple)
 Constrain the noutput_items argument passed to forecast and general_work.
int output_multiple () const
void consume (int which_input, int how_many_items)
 Tell the scheduler how_many_items of input stream which_input were consumed.
void consume_each (int how_many_items)
 Tell the scheduler how_many_items were consumed on each input stream.
void produce (int which_output, int how_many_items)
 Tell the scheduler how_many_items were produced on output stream which_output.
void set_relative_rate (double relative_rate)
 Set the approximate output rate / input rate.
double relative_rate () const
 return the approximate output rate / input rate
virtual 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 defined if fixed_rate returns true. Generally speaking, you don't need to override this.
virtual 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. Generally speaking, you don't need to override this.
uint64_t nitems_read (unsigned int which_input)
 Return the number of items read on input stream which_input.
uint64_t nitems_written (unsigned int which_output)
 Return the number of items written on output stream which_output.
tag_propagation_policy_t tag_propagation_policy ()
 Asks for the policy used by the scheduler to moved tags downstream.
void set_tag_propagation_policy (tag_propagation_policy_t p)
 Set the policy by the scheduler to determine how tags are moved downstream.
gr_block_detail_sptr detail () const
void set_detail (gr_block_detail_sptr detail)

Protected Member Functions

 gr_block (void)
 gr_block (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature)
void set_fixed_rate (bool fixed_rate)
void add_item_tag (unsigned int which_output, uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid=pmt::PMT_F)
 Adds a new tag onto the given output buffer.
void get_tags_in_range (std::vector< pmt::pmt_t > &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end)
 Given a [start,end), returns a vector of all tags in the range.
void get_tags_in_range (std::vector< pmt::pmt_t > &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end, const pmt::pmt_t &key)
 Given a [start,end), returns a vector of all tags in the range with a given key.

Detailed Description

The abstract base class for all 'terminal' processing blocks.

A signal processing flow is constructed by creating a tree of hierarchical blocks, which at any level may also contain terminal nodes that actually implement signal processing functions. This is the base class for all such leaf nodes.

Blocks have a set of input streams and output streams. The input_signature and output_signature define the number of input streams and output streams respectively, and the type of the data items in each stream.

Although blocks may consume data on each input stream at a different rate, all outputs streams must produce data at the same rate. That rate may be different from any of the input rates.

User derived blocks override two methods, forecast and general_work, to implement their signal processing behavior. forecast is called by the system scheduler to determine how many items are required on each input stream in order to produce a given number of output items.

general_work is called to perform the signal processing in the block. It reads the input items and writes the output items.


Member Enumeration Documentation

anonymous enum

Magic return values from general_work.

Enumerator:
WORK_CALLED_PRODUCE 
WORK_DONE 
Enumerator:
TPP_DONT 
TPP_ALL_TO_ALL 
TPP_ONE_TO_ONE 

Constructor & Destructor Documentation

virtual gr_block::~gr_block ( ) [virtual]
gr_block::gr_block ( void  ) [inline, protected]
gr_block::gr_block ( const std::string &  name,
gr_io_signature_sptr  input_signature,
gr_io_signature_sptr  output_signature 
) [protected]

Member Function Documentation

void gr_block::add_item_tag ( unsigned int  which_output,
uint64_t  abs_offset,
const pmt::pmt_t &  key,
const pmt::pmt_t &  value,
const pmt::pmt_t &  srcid = pmt::PMT_F 
) [protected]

Adds a new tag onto the given output buffer.

Parameters:
which_outputan integer of which output stream to attach the tag
abs_offseta uint64 number of the absolute item number assicated with the tag. Can get from nitems_written.
keythe tag key as a PMT symbol
valueany PMT holding any value for the given key
srcidoptional source ID specifier; defaults to PMT_F

Referenced by tag_source_demo::make_eob_tag(), tag_source_demo::make_sob_tag(), and tag_source_demo::make_time_tag().

void gr_block::consume ( int  which_input,
int  how_many_items 
)

Tell the scheduler how_many_items of input stream which_input were consumed.

void gr_block::consume_each ( int  how_many_items)

Tell the scheduler how_many_items were consumed on each input stream.

gr_block_detail_sptr gr_block::detail ( ) const [inline]

Referenced by set_detail().

bool gr_block::fixed_rate ( ) const [inline]

Return true if this block has a fixed input to output rate.

If true, then fixed_rate_in_to_out and fixed_rate_out_to_in may be called.

Referenced by set_fixed_rate().

virtual int gr_block::fixed_rate_ninput_to_noutput ( int  ninput) [virtual]

Given ninput samples, return number of output samples that will be produced. N.B. this is only defined if fixed_rate returns true. Generally speaking, you don't need to override this.

Reimplemented in gr_test, gr_sync_block, gr_sync_decimator, and gr_sync_interpolator.

virtual int gr_block::fixed_rate_noutput_to_ninput ( int  noutput) [virtual]

Given noutput samples, return number of input samples required to produce noutput. N.B. this is only defined if fixed_rate returns true. Generally speaking, you don't need to override this.

Reimplemented in gr_test, gr_sync_block, gr_sync_decimator, and gr_sync_interpolator.

virtual void gr_block::forecast ( int  noutput_items,
gr_vector_int ninput_items_required 
) [virtual]

Estimate input requirements given output request.

Parameters:
noutput_itemsnumber of output items to produce
ninput_items_requirednumber of input items required on each input stream

Given a request to product noutput_items, estimate the number of data items required on each input stream. The estimate doesn't have to be exact, but should be close.

Reimplemented in gr_fractional_interpolator_cc, gr_fractional_interpolator_ff, gr_align_on_samplenumbers_ss, gr_clock_recovery_mm_cc, gr_clock_recovery_mm_ff, gr_mpsk_receiver_cc, gr_ofdm_sampler, gr_simple_framer, gr_stream_mux, gr_test, gr_sync_block, gr_sync_decimator, gr_sync_interpolator, atsc_bit_timing_loop, atsc_equalizer, atsc_field_sync_demux, atsc_field_sync_mux, atsc_pad, pager_flex_sync, trellis_siso_combined_f, trellis_siso_f, gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, gr_rational_resampler_base_scc, gr_packed_to_unpacked_bb, gr_packed_to_unpacked_ii, gr_packed_to_unpacked_ss, gr_unpacked_to_packed_bb, gr_unpacked_to_packed_ii, gr_unpacked_to_packed_ss, trellis_metrics_c, trellis_metrics_f, trellis_metrics_i, trellis_metrics_s, trellis_pccc_decoder_b, trellis_pccc_decoder_combined_cb, trellis_pccc_decoder_combined_ci, trellis_pccc_decoder_combined_cs, trellis_pccc_decoder_combined_fb, trellis_pccc_decoder_combined_fi, trellis_pccc_decoder_combined_fs, trellis_pccc_decoder_i, trellis_pccc_decoder_s, trellis_sccc_decoder_b, trellis_sccc_decoder_combined_cb, trellis_sccc_decoder_combined_ci, trellis_sccc_decoder_combined_cs, trellis_sccc_decoder_combined_fb, trellis_sccc_decoder_combined_fi, trellis_sccc_decoder_combined_fs, trellis_sccc_decoder_i, trellis_sccc_decoder_s, trellis_viterbi_b, trellis_viterbi_combined_cb, trellis_viterbi_combined_ci, trellis_viterbi_combined_cs, trellis_viterbi_combined_fb, trellis_viterbi_combined_fi, trellis_viterbi_combined_fs, trellis_viterbi_combined_ib, trellis_viterbi_combined_ii, trellis_viterbi_combined_is, trellis_viterbi_combined_sb, trellis_viterbi_combined_si, trellis_viterbi_combined_ss, trellis_viterbi_i, and trellis_viterbi_s.

virtual int gr_block::general_work ( int  noutput_items,
gr_vector_int ninput_items,
gr_vector_const_void_star input_items,
gr_vector_void_star output_items 
) [pure virtual]

compute output items from input items

Parameters:
noutput_itemsnumber of output items to write on each output stream
ninput_itemsnumber of input items available on each input stream
input_itemsvector of pointers to the input items, one entry per input stream
output_itemsvector of pointers to the output items, one entry per output stream
Returns:
number of items actually written to each output stream, or -1 on EOF. It is OK to return a value less than noutput_items. -1 <= return value <= noutput_items

general_work must call consume or consume_each to indicate how many items were consumed on each input stream.

Implemented in gr_fractional_interpolator_cc, gr_fractional_interpolator_ff, gr_pfb_arb_resampler_ccf, gr_pfb_channelizer_ccf, gr_pfb_clock_sync_ccf, gr_pfb_clock_sync_fff, gr_align_on_samplenumbers_ss, gr_clock_recovery_mm_cc, gr_clock_recovery_mm_ff, gr_copy, gr_keep_one_in_n, gr_mpsk_receiver_cc, gr_nop, gr_ofdm_bpsk_demapper, gr_ofdm_frame_acquisition, gr_ofdm_insert_preamble, gr_ofdm_sampler, gr_simple_correlator, gr_simple_framer, gr_skiphead, gr_squelch_base_cc, gr_squelch_base_ff, gr_stream_mux, gr_test, gr_sync_block, gr_sync_decimator, gr_sync_interpolator, atsc_bit_timing_loop, atsc_field_sync_demux, howto_square_ff, noaa_hrpt_deframer, pager_flex_sync, qtgui_sink_c, qtgui_sink_f, qtgui_time_sink_c, qtgui_time_sink_f, trellis_siso_combined_f, trellis_siso_f, gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, gr_rational_resampler_base_scc, gr_packed_to_unpacked_bb, gr_packed_to_unpacked_ii, gr_packed_to_unpacked_ss, gr_unpacked_to_packed_bb, gr_unpacked_to_packed_ii, gr_unpacked_to_packed_ss, trellis_metrics_c, trellis_metrics_f, trellis_metrics_i, trellis_metrics_s, trellis_pccc_decoder_b, trellis_pccc_decoder_combined_cb, trellis_pccc_decoder_combined_ci, trellis_pccc_decoder_combined_cs, trellis_pccc_decoder_combined_fb, trellis_pccc_decoder_combined_fi, trellis_pccc_decoder_combined_fs, trellis_pccc_decoder_i, trellis_pccc_decoder_s, trellis_sccc_decoder_b, trellis_sccc_decoder_combined_cb, trellis_sccc_decoder_combined_ci, trellis_sccc_decoder_combined_cs, trellis_sccc_decoder_combined_fb, trellis_sccc_decoder_combined_fi, trellis_sccc_decoder_combined_fs, trellis_sccc_decoder_i, trellis_sccc_decoder_s, trellis_viterbi_b, trellis_viterbi_combined_cb, trellis_viterbi_combined_ci, trellis_viterbi_combined_cs, trellis_viterbi_combined_fb, trellis_viterbi_combined_fi, trellis_viterbi_combined_fs, trellis_viterbi_combined_ib, trellis_viterbi_combined_ii, trellis_viterbi_combined_is, trellis_viterbi_combined_sb, trellis_viterbi_combined_si, trellis_viterbi_combined_ss, trellis_viterbi_i, and trellis_viterbi_s.

void gr_block::get_tags_in_range ( std::vector< pmt::pmt_t > &  v,
unsigned int  which_input,
uint64_t  abs_start,
uint64_t  abs_end 
) [protected]

Given a [start,end), returns a vector of all tags in the range.

Range of counts is from start to end-1.

Tags are tuples of: (item count, source id, key, value)

Parameters:
va vector reference to return tags into
which_inputan integer of which input stream to pull from
abs_starta uint64 count of the start of the range of interest
abs_enda uint64 count of the end of the range of interest

Referenced by tag_sink_demo::work().

void gr_block::get_tags_in_range ( std::vector< pmt::pmt_t > &  v,
unsigned int  which_input,
uint64_t  abs_start,
uint64_t  abs_end,
const pmt::pmt_t &  key 
) [protected]

Given a [start,end), returns a vector of all tags in the range with a given key.

Range of counts is from start to end-1.

Tags are tuples of: (item count, source id, key, value)

Parameters:
va vector reference to return tags into
which_inputan integer of which input stream to pull from
abs_starta uint64 count of the start of the range of interest
abs_enda uint64 count of the end of the range of interest
keya PMT symbol key to filter only tags of this key
unsigned gr_block::history ( ) const [inline]

Assume block computes y_i = f(x_i, x_i-1, x_i-2, x_i-3...) History is the number of x_i's that are examined to produce one y_i. This comes in handy for FIR filters, where we use history to ensure that our input contains the appropriate "history" for the filter. History should be equal to the number of filter taps.

Reimplemented in gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, and gr_rational_resampler_base_scc.

Referenced by gr_delay::delay(), gr_test::forecast(), and set_history().

uint64_t gr_block::nitems_read ( unsigned int  which_input)

Return the number of items read on input stream which_input.

Referenced by tag_sink_demo::work().

uint64_t gr_block::nitems_written ( unsigned int  which_output)

Return the number of items written on output stream which_output.

Referenced by tag_source_demo::work().

int gr_block::output_multiple ( ) const [inline]
void gr_block::produce ( int  which_output,
int  how_many_items 
)

Tell the scheduler how_many_items were produced on output stream which_output.

If the block's general_work method calls produce, general_work must return WORK_CALLED_PRODUCE.

double gr_block::relative_rate ( ) const [inline]

return the approximate output rate / input rate

Referenced by gr_test::fixed_rate_ninput_to_noutput(), gr_test::fixed_rate_noutput_to_ninput(), and gr_test::forecast().

void gr_block::set_detail ( gr_block_detail_sptr  detail) [inline]

References detail().

void gr_block::set_fixed_rate ( bool  fixed_rate) [inline, protected]

References fixed_rate().

Referenced by gr_test::set_fixed_rate_public().

void gr_block::set_output_multiple ( int  multiple)

Constrain the noutput_items argument passed to forecast and general_work.

set_output_multiple causes the scheduler to ensure that the noutput_items argument passed to forecast and general_work will be an integer multiple of

Parameters:
multipleThe default value of output multiple is 1.

Referenced by gr_sync_interpolator::set_interpolation().

void gr_block::set_relative_rate ( double  relative_rate)

Set the approximate output rate / input rate.

Provide a hint to the buffer allocator and scheduler. The default relative_rate is 1.0

decimators have relative_rates < 1.0 interpolators have relative_rates > 1.0

Referenced by gr_sync_decimator::set_decimation(), gr_sync_interpolator::set_interpolation(), and gr_pfb_arb_resampler_ccf::set_rate().

void gr_block::set_tag_propagation_policy ( tag_propagation_policy_t  p)

Set the policy by the scheduler to determine how tags are moved downstream.

virtual bool gr_block::start ( ) [virtual]

Called to enable drivers, etc for i/o devices.

This allows a block to enable an associated driver to begin transfering data just before we start to execute the scheduler. The end result is that this reduces latency in the pipeline when dealing with audio devices, usrps, etc.

Reimplemented in audio_osx_sink, audio_osx_source, msdd_rs_source_simple, msdd_source_simple, usrp_sink_base, usrp_source_base, usrp2_base, and usrp2_source_base.

virtual bool gr_block::stop ( ) [virtual]

Called to disable drivers, etc for i/o devices.

Reimplemented in audio_osx_sink, audio_osx_source, msdd_rs_source_simple, msdd_source_simple, usrp_sink_base, usrp_source_base, usrp2_base, and usrp2_source_base.

tag_propagation_policy_t gr_block::tag_propagation_policy ( )

Asks for the policy used by the scheduler to moved tags downstream.


The documentation for this class was generated from the following file: