Packet Communications: Difference between revisions
(Revisions for version 3.10 - Simulating Packet Comms Using Messages) |
|||
Line 1: | Line 1: | ||
<b>NOTE: This document is being revised. The previous version can be found in [[Packet_Communications_Test_Page]].</b> | <b>NOTE: This document is being revised. The previous version can be found in [[Packet_Communications_Test_Page]].</b><br> | ||
<br> | |||
This tutorial presents methods to transmit and receive packet data. 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. | This tutorial presents methods to transmit and receive packet data. 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. | ||
Line 11: | Line 10: | ||
* [[Stream Tags|'''Stream Tags''']] | * [[Stream Tags|'''Stream Tags''']] | ||
* [[Message Passing|'''Message Passing''']] | * [[Message Passing|'''Message Passing''']] | ||
== Header Format Object == | == Header Format Object == | ||
Line 27: | Line 24: | ||
* digital.header_format_counter(access_code, threshold, bps) | * digital.header_format_counter(access_code, threshold, bps) | ||
== Using | == Simulating Packet Comms Using Messages == | ||
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. | |||
=== Building the flowgraph === | |||
Build the following flowgraph using the details given below: | |||
[[File:Pkt_8_fg.png|800px]] | |||
<hr> | |||
This flowgraph can be downloaded from [[Media:Pkt_8.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 twice per second. | |||
; CRC Append | |||
The CRC Append block computes the CRC32 of the payload (message) and appends the value to it. | |||
; 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_default(access_key, 0) | |||
It generates a header with the access code and the 16-bit payload length (repeated). | |||
; Protocol Formatter (Async) | |||
The entry for the Format Obj. is 'hdr_format'. It produces separate header and payload output messages. | |||
; PDU to Tagged Stream | |||
Converts received PDUs into a tagged stream by adding length tags. | |||
; Tagged Stream Mux | |||
The Tagged Stream Mux combines the header and the payload into a single stream. | |||
; Correlate Access Code - Tag Stream | |||
This block searches the input stream for a match to the given Access Code. The code is given as a ''string'' with the 32 bit value (ones and zeros). | |||
; CRC Check | |||
The CRC Check block computes the CRC of the payload and compares it to the CRC in the message. If they match, the payload is output to the "ok" port with the CRC stripped from the message. If the CRC does not match, the entire message with CRC is output to the "fail" port. | |||
<hr> | |||
=== Testing === | |||
1. Open a new terminal window.<br> | |||
2. Create a working directory, e.g. `~/GRdev`: | |||
mkdir ~/GRdev | |||
3. Change to that directory: | |||
cd ~/GRdev | |||
4. Execute `gnuradio-companion`. | |||
gnuradio-companion | |||
5. Open the `pkt_8.grc` flowgraph.<br> | |||
6. Click 'Generate the flowgraph' or press F5.<br> | |||
7. Exit `gnuradio-companion` by clicking the "X" in the upper right corner of the screen.<br> | |||
8. On the same terminal screen, execute `pkt_8`: | |||
python3 -u pkt_8.py | |||
9. A new window will open showing two Time Sinks which are the input and output of the 'Correlate Access Code - Tag Stream' block.<br> | |||
10. Once the Correlate Output shows a signal, wait one second, then terminate that window (titled `pkt_8`) by clicking the "X" in the upper right corner.<br> | |||
11. The terminal screen should show repeats of this message:<br> | |||
<pre> | |||
***** VERBOSE PDU DEBUG PRINT ****** | |||
() | |||
pdu length = 9 bytes | |||
pdu vector contents = | |||
0000: 47 4e 55 20 52 61 64 69 6f | |||
************************************ | |||
</pre> | |||
The "pdu vector contents" are the character codes for "GNU Radio". | |||
== Simulating Packet Comms Using Streams == | |||
=== Building the flowgraph === | === Building the flowgraph === | ||
Line 39: | Line 107: | ||
; File Source | ; File Source | ||
The File Source reads a padded text file and outputs to a stream. | The File Source reads a padded text file and outputs to a stream. | ||
; Stream to Tagged Stream | ; Stream to Tagged Stream | ||
Converts a regular stream into a tagged stream by adding length tags in regular intervals. | Converts a regular stream into a tagged stream by adding length tags in regular intervals. | ||
; Stream CRC32 | ; Stream CRC32 | ||
The Stream CRC32 block computes the CRC of the payload and appends the value to it. | The Stream CRC32 block computes the CRC of the payload and appends the value to it. | ||
Line 119: | Line 184: | ||
* Run the Python program to produce a padded text file. | * Run the Python program to produce a padded text file. | ||
* Execute the flowgraph. | * Execute the flowgraph. | ||
* A new window will open showing various controls, a waterfall display, and a Frequency display. The frequency can be changed by clicking on the digits, where clicking on the uppper part of the digit increases the value, and clicking on the lower part of the digit decreases the value. | |||
* To terminate that window, click the "X" in the upper right corner. | |||
* Examine the output file "output.txt". The output file will be the same as the original file, but will have trailing spaces at the end as a result of the padding. | * Examine the output file "output.txt". The output file will be the same as the original file, but will have trailing spaces at the end as a result of the padding. | ||
<hr> | <hr> | ||
== | == Observations == | ||
During the development and testing for this tutorial, the following items were observed: | During the development and testing for this tutorial, the following items were observed: | ||
Line 145: | Line 195: | ||
* The 'Header/Payload Demux' and 'Protocol Parser' blocks seem to work only with the 'digital.header_format_crc' format. | * The 'Header/Payload Demux' and 'Protocol Parser' blocks seem to work only with the 'digital.header_format_crc' format. | ||
* The 'Correlate Access Code - Tag Stream' block requires the Default Header Format Obj. and expects a 32-bit access code. | * The 'Correlate Access Code - Tag Stream' block requires the Default Header Format Obj. and expects a 32-bit access code. | ||
<hr> | |||
<code>Tested with v3.10.9.2</code><br> | |||
[[Category:Tutorials]] | [[Category:Tutorials]] | ||
[[Category:Tested With 3.10]] | [[Category:Tested With 3.10]] |
Revision as of 13:16, 29 January 2025
NOTE: This document is being revised. The previous version can be found in Packet_Communications_Test_Page.
This tutorial presents methods to transmit and receive packet data. 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.
Prerequisites
- QPSK Modulation / Demodulation
- BPSK Demodulation
- Polymorphic Types (PMTs)
- Stream Tags
- Message Passing
Header Format Object
The following blocks:
- Protocol_Formatter,
- Protocol_Formatter_(Async),
- Protocol_Parser,
- Packet_Header_Generator, and
- Packet_Header_Parser
use a "Header Format Object", but there is no block with that name. To create such an object, a Variable block is used. The 'Value' field can be one of several chioces depending on what type of header is needed, such as:
* digital.header_format_default(access_code, threshold) * digital.header_format_crc(len_key, num_key) * digital.header_format_counter(access_code, threshold, bps)
Simulating Packet Comms Using Messages
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.
Building the flowgraph
Build the following flowgraph using the details given below:
This flowgraph can be downloaded from Media:Pkt_8.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 twice per second.
- CRC Append
The CRC Append block computes the CRC32 of the payload (message) and appends the value to it.
- 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_default(access_key, 0)
It generates a header with the access code and the 16-bit payload length (repeated).
- Protocol Formatter (Async)
The entry for the Format Obj. is 'hdr_format'. It produces separate header and payload output messages.
- PDU to Tagged Stream
Converts received PDUs into a tagged stream by adding length tags.
- Tagged Stream Mux
The Tagged Stream Mux combines the header and the payload into a single stream.
- Correlate Access Code - Tag Stream
This block searches the input stream for a match to the given Access Code. The code is given as a string with the 32 bit value (ones and zeros).
- CRC Check
The CRC Check block computes the CRC of the payload and compares it to the CRC in the message. If they match, the payload is output to the "ok" port with the CRC stripped from the message. If the CRC does not match, the entire message with CRC is output to the "fail" port.
Testing
1. Open a new terminal window.
2. Create a working directory, e.g. `~/GRdev`:
mkdir ~/GRdev
3. Change to that directory:
cd ~/GRdev
4. Execute `gnuradio-companion`.
gnuradio-companion
5. Open the `pkt_8.grc` flowgraph.
6. Click 'Generate the flowgraph' or press F5.
7. Exit `gnuradio-companion` by clicking the "X" in the upper right corner of the screen.
8. On the same terminal screen, execute `pkt_8`:
python3 -u pkt_8.py
9. A new window will open showing two Time Sinks which are the input and output of the 'Correlate Access Code - Tag Stream' block.
10. Once the Correlate Output shows a signal, wait one second, then terminate that window (titled `pkt_8`) by clicking the "X" in the upper right corner.
11. The terminal screen should show repeats of this message:
***** VERBOSE PDU DEBUG PRINT ****** () pdu length = 9 bytes pdu vector contents = 0000: 47 4e 55 20 52 61 64 69 6f ************************************
The "pdu vector contents" are the character codes for "GNU Radio".
Simulating Packet Comms Using Streams
Building the flowgraph
Build the following flowgraph using the details given below:
This flowgraph can be downloaded from Media:Str_pkt_10.grc.
- File Source
The File Source reads a padded text file and outputs to a stream.
- Stream to Tagged Stream
Converts a regular stream into a tagged stream by adding length tags in regular intervals.
- Stream CRC32
The Stream CRC32 block computes the CRC of the payload and appends the value to it.
- Protocol Formatter
The entry for the Format Obj. is 'hdr_format'. The Protocol Formatter produces the header for the packet.
- Tagged Stream Mux
The Mux combines the protocol header and the payload data into one packet.
- Correlate Access Code - Tag Stream
The Access Code is a string with the 32 bit value.
Testing
The success of this methodology is based on the input file being padded to a multiple of 'packet_len' bytes so that the last few bytes of the source file are not lost in a partial unprocessed packet. To create a padded file for input to the flowgraph, the following Python program can be used:
#!/usr/bin/python3 # -*- coding: utf-8 -*- # Padded_File_Source.py import os.path import sys Pkt_len = 252 _debug = 1 # set to zero to turn off diagnostics if (len(sys.argv) < 2): print ('Usage: python3 Padded_File_Source.py <input file>') print ('Number of arguments=', len(sys.argv)) print ('Argument List:', str(sys.argv)) exit (1) # test if file exists fn = sys.argv[1] if (_debug): print (fn) if not(os.path.exists(fn)): print('The input file does not exist') exit (1) # open input file f_in = open (fn, 'r') # open output file f_out = open ("padded.txt", 'w') while True: buff = f_in.read (Pkt_len) b_len = len(buff) if (_debug): print (b_len) if b_len == 0: print ('End of file') break while (b_len < Pkt_len): buff += ' ' b_len += 1 # write output f_out.write (buff) f_in.close() f_out.close()
Note that the 'Pkt_len' in the Python program and the 'packet_len' value in the flowgraph 'Stream to Tagged Stream' block must be the same. The output of the Python program is a file named "padded.txt".
To test the flowgraph:
- Run the Python program to produce a padded text file.
- Execute the flowgraph.
- A new window will open showing various controls, a waterfall display, and a Frequency display. The frequency can be changed by clicking on the digits, where clicking on the uppper part of the digit increases the value, and clicking on the lower part of the digit decreases the value.
- To terminate that window, click the "X" in the upper right corner.
- Examine the output file "output.txt". The output file will be the same as the original file, but will have trailing spaces at the end as a result of the padding.
Observations
During the development and testing for this tutorial, the following items were observed:
- The 'Header/Payload Demux' and 'Protocol Parser' blocks seem to work only with the 'digital.header_format_crc' format.
- The 'Correlate Access Code - Tag Stream' block requires the Default Header Format Obj. and expects a 32-bit access code.
Tested with v3.10.9.2