Handling Messages


#1

Hi,

I am trying to make a flowgraph as given:

signal source --> stream2vector --> fft --> c2m --> msg_sink

If the size of fft is 4096, then I want to retrieve these 4096 points in
python and then do simple maths and logic based on some of the values
within
these 4096 points within python.

And then based on the result, I want to initiate another flowgraph!

Currently, there is an error between the interface between c2m and
msg_sink.

The code is:

class top(gr.top_block):
def init(self):
gr.top_block.init(self)

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.sigsource = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE,

1000, 10, 0)
self.sigsource1 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE,
2000, 20, 0)
self.sigadder = gr.add_vcc(1)

        fftsize = 4096

        mywin = window.blackmanharris(fftsize)

        fft = gr.fft_vcc(fftsize, True, mywin)

        c2m = gr.complex_to_mag(fftsize)

        s2f1 = gr.short_to_float()

        s2f2 = gr.short_to_float()

        # Vector Sink/Source

        ss2v = gr.stream_to_vector(gr.sizeof_gr_complex, fftsize)

        v2ss = gr.vector_to_stream(gr.sizeof_float, fftsize)

        # Message Settings

        self.qsize = 10

        self.msgq0 = gr.msg_queue(self.qsize) # queue amplitude

        # Message sink

        m_sink0 = gr.message_sink(gr.sizeof_float, self.msgq0, True)

        self.connect((self.sigsource, 0), (self.sigadder, 0))
        self.connect((self.sigsource1, 0), (self.sigadder, 1))

        self.connect(self.sigadder, ss2v, fft, c2m, m_sink0)

def main ():

    # Start Top Block
    tb = top()

    #Start Flowgraph
    tb.start()

    # Read first message

    amsg = tb.msgq0.delete_head() # get first amplitude message

    raw_a = amsg.to_string() # raw amplitude data

    a_data = numpy.fromstring(raw_a, numpy.float32, count =

int(amsg.arg2())) # converted amplitude data

    print "Data in sink is: ",a_data

    tb.stop()

if name == ‘main’:

main ()

Regards,


#2

Hi,

I am trying to make a flowgraph as given:

signal source --> stream2vector --> fft --> c2m --> msg_sink

If the size of fft is 4096, then I want to retrieve these 4096 points in
python and then do simple maths and logic based on some of the values
within
these 4096 points within python.

And then based on the result, I want to initiate another flowgraph!

Currently, there is an error between the interface between c2m and
msg_sink.

The code is:

class top(gr.top_block):
def init(self):
gr.top_block.init(self)

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.sigsource = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE,

1000, 10, 0)
self.sigsource1 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE,
2000, 20, 0)
self.sigadder = gr.add_vcc(1)

        fftsize = 4096

        mywin = window.blackmanharris(fftsize)

        fft = gr.fft_vcc(fftsize, True, mywin)

        c2m = gr.complex_to_mag(fftsize)

        s2f1 = gr.short_to_float()

        s2f2 = gr.short_to_float()

        # Vector Sink/Source

        ss2v = gr.stream_to_vector(gr.sizeof_gr_complex, fftsize)

        v2ss = gr.vector_to_stream(gr.sizeof_float, fftsize)

        # Message Settings

        self.qsize = 10

        self.msgq0 = gr.msg_queue(self.qsize) # queue amplitude

        # Message sink

        m_sink0 = gr.message_sink(gr.sizeof_float, self.msgq0, True)

        self.connect((self.sigsource, 0), (self.sigadder, 0))
        self.connect((self.sigsource1, 0), (self.sigadder, 1))

        self.connect(self.sigadder, ss2v, fft, c2m, m_sink0)

def main ():

    # Start Top Block
    tb = top()

    #Start Flowgraph
    tb.start()

    # Read first message

    amsg = tb.msgq0.delete_head() # get first amplitude message

    raw_a = amsg.to_string() # raw amplitude data

    a_data = numpy.fromstring(raw_a, numpy.float32, count =

int(amsg.arg2())) # converted amplitude data

    print "Data in sink is: ",a_data

    tb.stop()

if name == ‘main’:

main ()

Regards,


#3

Hi Ali - I think the issue is that the output of the C2M is of
item_size ‘fftsize’, whereas the message_sink has item_size of
‘gr.sizeof_float’. Try incorporating the ‘gr.vector_to_stream’ you
created between the C2M and the message_sink. - MLD