[Discuss-gnuradio] Message passing as input and output in block (C++ cod
From:
Jose Torres Diaz
Subject:
[Discuss-gnuradio] Message passing as input and output in block (C++ coding)
Date:
Mon, 8 Oct 2012 15:26:13 +1030
Hi All,
I have another question about the message passing technique. In this opportunity, I would like to create a block that takes message as input, but also that post message downstream as output. In my initial attempt, I'm using the original blob_to_stream example (see below), the incoming message is taken using:
_msg = this->pop_msg_queue();
and then, in order to output the incoming message, it is used:
(1) Is it possible to use an alternative way like this:
post_msg(0,_msg.key, _msg.value,_id); ?
The goal is to output the same message to downstream.
**************Example blob to stream****************************
int work( const InputItems &input_items,
const OutputItems &output_items ){ //loop until we get a blob or interrupted while (_offset == 0){ _msg = this->pop_msg_queue(); if (pmt::pmt_is_blob(_msg.value)) break;
} if (pmt::pmt_blob_length(_msg.value) == 0) return -1; //empty blob, we are done here
//calculate the number of bytes to copy const size_t nblob_items = (pmt::pmt_blob_length(_msg.value) - _offset)/_item_size;
const size_t noutput_bytes = _item_size*std::min<size_t>(output_items[0].size(), nblob_items);
//perform memcpy from blob to output items const char *blob_mem = reinterpret_cast<const char *>(pmt::pmt_blob_data(_msg.value)) + _offset;
std::memcpy(output_items[0].get(), blob_mem, noutput_bytes);
//adjust the offset into the blob memory _offset += noutput_bytes; if (pmt::pmt_blob_length(_msg.value) == _offset) _offset = 0;