Base header formatter class. More...
#include <gnuradio/digital/header_format_base.h>
Public Types | |
typedef boost::shared_ptr< header_format_base > | sptr |
Public Member Functions | |
header_format_base () | |
virtual | ~header_format_base () |
sptr | base () |
sptr | formatter () |
virtual bool | format (int nbytes_in, const unsigned char *input, pmt::pmt_t &output, pmt::pmt_t &info)=0 |
virtual bool | parse (int nbits_in, const unsigned char *input, std::vector< pmt::pmt_t > &info, int &nbits_processed)=0 |
virtual size_t | header_nbits () const =0 |
size_t | header_nbytes () const |
Protected Types | |
enum | state_t { STATE_SYNC_SEARCH, STATE_HAVE_SYNC } |
Protected Member Functions | |
virtual void | enter_search () |
Enter Search state of the state machine to find the access code. More... | |
virtual void | enter_have_sync () |
Access code found, start getting the header. More... | |
virtual void | enter_have_header (int payload_len) |
Header found, setup for pulling in the hard decision bits. More... | |
virtual bool | header_ok ()=0 |
Verify that the header is valid. More... | |
virtual int | header_payload ()=0 |
Protected Attributes | |
state_t | d_state |
state of the state machine More... | |
header_buffer | d_hdr_reg |
header_buffer object to hold header bits More... | |
pmt::pmt_t | d_info |
info captured from the header More... | |
gr::logger_ptr | d_logger |
gr::logger_ptr | d_debug_logger |
Base header formatter class.
Creates a base class that other packet formatters will inherit from. The child classes create and parse protocol-specific headers. To add a new protocol processing class, create a class that inherits from this and overload the necessary functions. The main functions to overload are:
Protected functions of this class that the child class should overload include:
These three function represent the different states of the parsing state machine. Expected behavior is that the protocol has some known word that we are first looking for the identify the start of the frame. The parsing FSM starts in a state to search for the beginning of the header, normally by looking for a known word (i.e., the access code). Then it changes state to read in the full header. We expect that the protocol provides the length of the header for processing, so the parsing looks pulls in the full length of the header. Then it changes state to the "have header" state for checking and processing. The base class provides the basic functionality for this state machine. However, most likely, each child class must manage these states for themselves.
This class is specifically designed to work with packets/frames in the asynchronous PDU architecture of GNU Radio. See the packet_format_async block for formatting the headers onto payloads and packet_parse_b block for parsing headers in a receiver.
The Packet Format block takes in a PDU and uses a formatter class derived from this class to add a header onto the packet. The Packet Format blocks takes in the PDU, unpacks the message, and passes it to a formatter class' format function, which builds a header based on the payload. The header is passed back and emitted from formatter block as a separate output. The async format block, packet_format_async, has two message output ports. The 'header' port passes the header out as a PDU and the 'payload' passes the payload out as a PDU. The flowgraph can then separately modulate and combine these two pieces in the follow-on processing.
The packet_sync_b block uses the formatter class by calling the 'parse' function to parse the received packet headers. This parser block is a sink for the data stream and emits a message from an 'info' port that contains an PMT dictionary of the information in the header. The formatter class determines the dictionary keys.
This is the base class for dealing with formatting headers for different protocols and purposes. For other header formatting behaviors, create a child class from here and overload the format, parse, and parsing state machine functions as necessary.
typedef boost::shared_ptr<header_format_base> gr::digital::header_format_base::sptr |
|
protected |
gr::digital::header_format_base::header_format_base | ( | ) |
|
virtual |
|
inline |
|
protectedvirtual |
Header found, setup for pulling in the hard decision bits.
Reimplemented in gr::digital::header_format_default.
|
protectedvirtual |
Access code found, start getting the header.
Reimplemented in gr::digital::header_format_default.
|
protectedvirtual |
Enter Search state of the state machine to find the access code.
|
pure virtual |
Function to creates a header. The child classes overload this function to format the header in the protocol-specific way.
nbytes_in | The length (in bytes) of the input payload |
input | An array of unsigned chars of the packet payload |
output | A pmt::u8vector with the new header prepended onto the input data. |
info | A pmt::dict containing meta data and info about the PDU (generally from the metadata portion of the input PDU). Data can be extracted from this for the header formatting or inserted. |
MUST be overloaded.
Implemented in gr::digital::header_format_default, gr::digital::header_format_counter, gr::digital::header_format_ofdm, and gr::digital::header_format_crc.
|
inline |
|
pure virtual |
Returns the length of the formatted header in bits. MUST be overloaded.
Implemented in gr::digital::header_format_default, gr::digital::header_format_ofdm, gr::digital::header_format_counter, and gr::digital::header_format_crc.
size_t gr::digital::header_format_base::header_nbytes | ( | ) | const |
Returns the length of the formatted header in bytes. Auto-calculated from the overloaded header_nbits().
|
protectedpure virtual |
Verify that the header is valid.
Implemented in gr::digital::header_format_default, gr::digital::header_format_counter, and gr::digital::header_format_crc.
|
protectedpure virtual |
Get info from the header; return payload length and package rest of data in d_info dictionary.
Implemented in gr::digital::header_format_default, gr::digital::header_format_counter, gr::digital::header_format_ofdm, and gr::digital::header_format_crc.
|
pure virtual |
Parses a header. This function is overloaded in the child class, which knows how to convert the incoming hard bits (0's and 1's) back into a packet header.
nbits_in | The number of bits in the input array. |
input | The input as hard decision bits. |
info | A vector of pmt::dicts to hold any meta data or info about the PDU. When parsing the header, the formatter can add info from the header into this dict. Each packet has a single PMT dictionary of info, so the vector length is the number of packets received extracted during one call to this parser function. |
nbits_processed | Number of input bits actually processed; If all goes well, this is nbits_in. A premature return after a bad header could be less than this. |
MUST be overloaded.
Implemented in gr::digital::header_format_default, gr::digital::header_format_ofdm, and gr::digital::header_format_crc.
|
protected |
|
protected |
header_buffer object to hold header bits
|
protected |
info captured from the header
|
protected |
Used by blocks to access the logger system.
|
protected |
state of the state machine