天天看点

GNUradio tools for packet-switched transmission(message source 和message sink)

in packet-switched transmission, packets of data arrive asynchronously from the data source on the transmit side and from the usrp on the receive side.

in order to accommodate the asynchronous nature of packet-switched transmission in the signal flow graph operation of gnuradio:

special source and sink blocks that contain buffers to hold packets are needed.

provisions for inserting packets into and extracting packets from the buffers in the source and sink blocks are needed.

the flow graph needs to be halted when the buffers are empty, and packets may need to be discarded when the buffers are full.

the gnuradio <code>gr_message</code> and

<code>gr_msq_queue</code> classes provide the underlying buffering support for packet-switched source and sink blocks.

a message is a <code>gr_message</code> class object, which is constructed by providing the<code>type</code>

(<code>0</code>=data,<code>1</code>=eof), 2 optional arguments (<code>arg1</code> and<code>arg2</code>), and

<code>length</code> of the message.

the following methods are provided to set the contents and access the various parameters of a message object:

<code>gr_make_message_from_string (const std::string s, long type, double arg1, double arg2)</code>

<code>to_string()</code>: returns the message string

<code>set_type(long type)</code> and

<code>type()</code>

<code>set_arg1(long arg1)</code> and

<code>arg1()</code>

<code>set_arg2(long arg1)</code> and

<code>arg2()</code>

<code>length()</code>

<code>msq()</code>: returns a pointer to the message string

a message queue is a <code>gr_msg_queue</code> class object, which is a linked list of

message objects. the maximum length <code>limit</code> of a message queue is set when constructing the queue.

thread synchronizing access to a message queue is provided by the following two methods:

<code>insert_tail(gr_message_sptr msg)</code>: inserts the message<code>msq</code> into the tail of the queue if queue is not full; otherwise waits until some messages are removed from

the queue by other threads.

<code>delete_head()</code>: greps a message from the head of the queue if queue is not empty; otherwise waits until some messages are inserted into the queue by other threads.

other methods (no thread synchronization) are also provided to manage a message queue:

<code>flush()</code>: deletes all messages from the queue

<code>empty_p()</code>: is the queue empty?

<code>full_p()</code>: is the queue full?

<code>count()</code>: returns number of messages in queue

<code>limit()</code>: returns the maximum queue length

use the gnuradio message source block <code>gr_message_source</code> to create a new

message queue (or use an existing queue).

the message source block extracts messages from the queue to provide a character stream to the next block in the signal flow graph until it encounters an eof message (<code>type</code>=-1). it waits (halts the output

character stream) when the queue is empty.

the message source block provides the method <code>msgq()</code> to expose the message queue. users can employ the<code>insert_tail()</code> method of exposed message queue to add packets

to the queue asynchronously.

the set of python programs starting at the top level with

<code>benchmark_tx.py</code> in the directory<code>$gr_install/share/gnuradio/examples/digital</code>

illustrates how to perform packet-switched transmission using the message source block.

on the receive side, since the packet arrival process is not known in advance, one must search for packets from the received signal samples obtained from the usrp. this means:

one must continuously perform carrier sensing, carrier synchronization, symbol synchronization, and demodulation (assuming high snr), and then acquisition to extract packets from the usrp signal samples.

the packet extraction function may be performed in a gnuradio sink block, which should also insert the extracted packets to a message queue. an example of such a sink block is the gnuradio block<code>gr_framer_sink_1</code>.

a separate process is needed to monitor the message queue. the process should initiate a<code>callback</code> when a packet is inserted into the queue by the sink block. this can be achieved by using the thread-synchronizing

message queue access method<code>delete_head()</code> in the monitoring process.

<code>benchmark_rx.py</code> in the directory<code>$gr_install/share/gnuradio/examples/digital</code>

illustrates how to perform packet-switched reception using the framer sink block<code>gr_framer_sink_1</code> and the message queue class.