Packet Communications: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
Line 88: Line 88:


== Using BPSK with a Hardware Simulation ==
== Using BPSK with a Hardware Simulation ==
The Protocol Formatter supports three header format types: default, count, and crc. The crc style is illustrated in the simulation above.
In order to create a preamble, a default header, and the payload data in one PDU message, an Embedded Python block was created. The code is contained in the GRC file, but also is shown here:
<pre>
"""
Embedded Python Block
"""
import numpy as np
from gnuradio import gr
import pmt
class blk(gr.sync_block):
    """Packet Format"""
    def __init__(self):
        gr.sync_block.__init__(self,
            name = "Packet Format",
            in_sig = None,
            out_sig = None)
        self.message_port_register_in(pmt.intern('PDU_in'))
        self.message_port_register_out(pmt.intern('PDU_out'))
        self.set_msg_handler(pmt.intern('PDU_in'), self.handle_msg)
    def handle_msg(self, msg):
        inMsg = pmt.to_python (msg)
        pld = inMsg[1]
        # print (pld)
        mLen = len(pld)
        # print (mLen)
        if (mLen > 0):
            char_list = [85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,225,90,232,147]
            char_list.append (mLen >> 8)
            char_list.append (mLen & 255)
            char_list.append (mLen >> 8)
            char_list.append (mLen & 255)
            char_list.extend (pld)
            # print (char_list)
            out_len = len(char_list)
            # print (out_len)
            self.message_port_pub(pmt.intern('PDU_out'), pmt.cons(pmt.PMT_NIL,pmt.init_u8vector(out_len,(char_list))))
</pre>


=== Transmitting a Signal ===
=== Transmitting a Signal ===
Build the following flowgraph using the details given below:
[[File:Pkt_xmt_fg.png|800px]]
<hr>
This flowgraph can be downloaded from [[Media:Pkt_xmt.grc]].


=== Receiving a Signal ===
=== Receiving a Signal ===

Revision as of 02:06, 23 October 2021

DRAFT (A Work in Progress)

This tutorial presents methods to transmit and receive packet data using burst transmissions. The examples show data originating from a PDU message source. A hardware simulation is shown using BPSK modulation.

Prerequisites

Simulating Baseband Packet Processing

In order to grasp the basics of packet processing, this section presents a transmitter and receiver simulation using standard GNU Radio blocks without any modulation or channel impairments. As was shown in the QPSK and BPSK tutorials, the received bit data stream could be verified by comparing it to the (delayed) transmitted data. However, there was no way to recover the byte alignment of those bits. That is where packet processing comes into play.

Building the flowgraph

Build the following flowgraph using the details given below:

Pkt 7 base fg.png


This flowgraph can be downloaded from Media:Pkt_7_base.grc.

Message Strobe

For the Message Strobe to generate a PDU, the Message PMT must be of the form

 pmt.cons(pmt.PMT_NIL,pmt.init_u8vector(9,(71,78,85,32,82,97,100,105,111)))

This specific vector has a length of 9 and the character values of "GNU Radio". It is sent every two seconds.

Variable, Id: hdr_format

The Protocol Formatter uses a Format Object to define its parameters. The one used in this example is

 hdr_format digital.header_format_crc(len_key, num_key)

It generates a header with the packet length, packet number, and a 16-bit CRC. No access code is created.

Protocol Formatter

The entry for the Format Obj. is 'hdr_format'

Header/Payload Demux

The Header/Payload Demux block synchronizes with the header data and then outputs the payload data.

Protocol Parser

The entry for the Format Obj. is 'hdr_format'

Testing

To test the flowgraph, click the "Execute the flowgraph" icon, or press F6. An example of the output is:

***** VERBOSE PDU DEBUG PRINT ******
()
pdu length = 4 bytes
pdu vector contents = 
0000: 0d 10 00 3a 
************************************
***** VERBOSE PDU DEBUG PRINT ******
()
pdu length = 13 bytes
pdu vector contents = 
0000: 47 4e 55 20 52 61 64 69 6f 8f aa 09 f1 
************************************

----------------------------------------------------------------------
Tag Debug: 
Input Stream: 00
  Offset: 13  Source: n/a     Key: packet_len   Value: 13
  Offset: 13  Source: n/a     Key: packet_num   Value: 1
----------------------------------------------------------------------
***** VERBOSE PDU DEBUG PRINT ******
((packet_num . 1))
pdu length = 9 bytes
pdu vector contents = 
0000: 47 4e 55 20 52 61 64 69 6f 
************************************

The first PDU DEBUG PRINT is the header data containing the payload length, packet number, and a CRC16 of the header.

The second PDU DEBUG PRINT is the payload including a CRC32 of the data.

The Tag Debug shows the length tag and the packet number tag.

The third PDU DEBUG PRINT is the received payload ("GNU Radio").

Using BPSK with a Hardware Simulation

The Protocol Formatter supports three header format types: default, count, and crc. The crc style is illustrated in the simulation above.

In order to create a preamble, a default header, and the payload data in one PDU message, an Embedded Python block was created. The code is contained in the GRC file, but also is shown here:

"""
Embedded Python Block
"""

import numpy as np
from gnuradio import gr
import pmt

class blk(gr.sync_block):
    """Packet Format"""

    def __init__(self):
        gr.sync_block.__init__(self,
            name = "Packet Format",
            in_sig = None,
            out_sig = None)
        self.message_port_register_in(pmt.intern('PDU_in'))
        self.message_port_register_out(pmt.intern('PDU_out'))
        self.set_msg_handler(pmt.intern('PDU_in'), self.handle_msg)

    def handle_msg(self, msg):
        inMsg = pmt.to_python (msg)
        pld = inMsg[1]
        # print (pld)
        mLen = len(pld)
        # print (mLen)
        if (mLen > 0):
            char_list = [85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,225,90,232,147]
            char_list.append (mLen >> 8)
            char_list.append (mLen & 255)
            char_list.append (mLen >> 8)
            char_list.append (mLen & 255)
            char_list.extend (pld)
            # print (char_list)
            out_len = len(char_list)
            # print (out_len)
            self.message_port_pub(pmt.intern('PDU_out'), pmt.cons(pmt.PMT_NIL,pmt.init_u8vector(out_len,(char_list))))

Transmitting a Signal

Build the following flowgraph using the details given below:

Pkt xmt fg.png


This flowgraph can be downloaded from Media:Pkt_xmt.grc.

Receiving a Signal