discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] State Machine that drops samples (Problems with retur


From: Felipe Domingues
Subject: [Discuss-gnuradio] State Machine that drops samples (Problems with return and consume_each in general_work)
Date: Mon, 3 Aug 2015 20:17:32 +0100

Dear all,

I'm trying to implement a simple state machine to receive bursty data and write it in a file.

To accomplish this I have created a general block that accepts complex samples and has two states:

0 - Just drops data. If one of the samples is 0, go to state 1.

1 - Copy inputs to outputs. If one of the samples is 1, go to state 0.

I will use this block in the future to wrap another more complex signal processing block that will generate a proper parameter for state transition.

However I'm failing to make even this simple one work. Here's my general_work: 

--------------------------------------------------------------------------------------------------     
        for (int i = 0; i < noutput_items; i++) {

          currentState = nextState;

          if(in[i] == std::complex<float> (0,0)){

            if(currentState == 0){
              nextState = 1;
              consume_each(i);
              return 0;

            }

            if(currentState == 1){
              for (int j = 0; j < i; j++) {
                out[j] = in[j];
              }
              nextState = 0;
              consume_each(i);
              return i;
            }

          }

        }

        if (currentState == 0){ 
          consume_each (noutput_items);
          return 0;
        }

        if (currentState == 1){   
          for (int j = 0; j < noutput_items; j++) {
            out[j] = in[j];
          }
          consume_each (noutput_items);
          return noutput_items;
        }

--------------------------------------------------------------------------------------------------     

Here's what it does:

1) Receive new state

2) Checks for state transition condition. If true:

2A) If it's in state 0: Change state to 1, consume all inputs processed so far (which makes non-processed inputs to go back to the queue in the next call of general_work, correct?) and returns 0 (which is equivalent to not generating outputs, right?)

2B) If it's in state 1: Same as 2A, but copy ( i ) inputs to the output (number of samples before state transition happens) and returns i samples.


3) If the loop ends without any state transition, the same thing that happened in 2A) and 2B) is executed, however noutput_items are processed/consumed/returned instead.

I'm testing this block in the attached flow graph, however the generated file is blank. Both nextState and currentState are private attributes of the block and are initialized in the constructor with 0.

My questions are:

1) Am I misunderstanding the way consume_each and return works?

2) What should I do with the forecast() function? I cannot guarantee that any numbers of inputs will actually produce an output.

3) Is this really the best way to accomplish what I want?


Thank you all for your assistance,


Attachment: fg.png
Description: PNG image


reply via email to

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