discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Trouble with block output


From: Thunder87
Subject: [Discuss-gnuradio] Trouble with block output
Date: Sun, 25 Jul 2010 12:13:38 -0700 (PDT)

This block should take a bit from chunk, and produce an output (d_phase)
which would hold until next chunk comes in. Right now it does take chunk,
extract this bit, produce correct phase, but next moment block output drops
to 0+0j.

It gives me feeling that block is producing output all the time, while
making decision only when input chunk is present. And when there is no input
chunk no output decision is being made, and output is being set by default
0+0j.

Could this be? Is there any block that uses same method (holding output
until next input), so I could learn from it's source?



howto_diffconst_bc.h

#ifndef INCLUDED_HOWTO_DIFFCONST_BC_H
#define INCLUDED_HOWTO_DIFFCONST_BC_H

#include <gr_block.h>
#include <iostream>
using namespace std;


class howto_diffconst_bc;

typedef boost::shared_ptr<howto_diffconst_bc> howto_diffconst_bc_sptr;

howto_diffconst_bc_sptr howto_make_diffconst_bc ();

class howto_diffconst_bc : public gr_block
{
  private:
    friend howto_diffconst_bc_sptr howto_make_diffconst_bc ();
    howto_diffconst_bc ();
    int d_phase;
  public:
    ~howto_diffconst_bc ();
    int general_work (int noutput_items, gr_vector_int &ninput_items,
                      gr_vector_const_void_star &input_items,
                      gr_vector_void_star &output_items);
};

#endif

howto_diffconst_bc.cc

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <howto_diffconst_bc.h>
#include <gr_io_signature.h>
#include <iostream>
using namespace std;


howto_diffconst_bc_sptr howto_make_diffconst_bc ()
     {return howto_diffconst_bc_sptr (new howto_diffconst_bc ());}

howto_diffconst_bc::howto_diffconst_bc (): gr_block ("diffconst_bc",
                                           gr_make_io_signature (1, 1,
sizeof (unsigned char)),
                                           gr_make_io_signature (1, 1,
sizeof (gr_complex))){d_phase=0;}

howto_diffconst_bc::~howto_diffconst_bc () {}


int howto_diffconst_bc::general_work (int noutput_items, gr_vector_int
&ninput_items,
                                      gr_vector_const_void_star
&input_items,
                                      gr_vector_void_star &output_items)

{
const unsigned char *in  = (const unsigned char *) input_items [0];
gr_complex          *out = (gr_complex          *) output_items[0];

if ((int)(in[0])%2==1) {d_phase++; if (d_phase>3) d_phase=0;}
else {d_phase--; if (d_phase<0) d_phase=3;}

if      (d_phase==0) {out[0]=gr_complex( 1.0, 0.0);}
else if (d_phase==1) {out[0]=gr_complex( 0.0, 1.0);}
else if (d_phase==2) {out[0]=gr_complex(-1.0, 0.0);}
else if (d_phase==3) {out[0]=gr_complex( 0.0,-1.0);}

consume_each (noutput_items);
return noutput_items;
}

-- 
View this message in context: 
http://old.nabble.com/Trouble-with-block-output-tp29261420p29261420.html
Sent from the GnuRadio mailing list archive at Nabble.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]