GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
gr::digital::header_format_base Class Referenceabstract

Base header formatter class. More...

#include <gnuradio/digital/header_format_base.h>

Public Types

typedef std::shared_ptr< header_format_basesptr
 

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
 

Detailed Description

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:

  • header_format_base::parse: receive bits and extract the header info. These are expected to be hard bits (0 or 1) that have either been sliced or gone through an FEC decoder.
  • header_format_base::header_ok: checks to see if the received header is ok. Since the header often specifies the length of the frame to decode next, it is important that this information be correct.
  • header_format_base::header_payload: unpacks the header register (from the class header_buffer) as a set of bits into its component parts of the header. For example, this may find and extract the frame length field as a 16-bit value and/or flags related to the type of modulation and FEC codes used in the frame's payload.

Protected functions of this class that the child class should overload include:

  • enter_search
  • enter_have_sync
  • enter_have_header

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.

See also
header_format_default
header_format_counter

Member Typedef Documentation

◆ sptr

Member Enumeration Documentation

◆ state_t

Enumerator
STATE_SYNC_SEARCH 
STATE_HAVE_SYNC 

Constructor & Destructor Documentation

◆ header_format_base()

gr::digital::header_format_base::header_format_base ( )

◆ ~header_format_base()

virtual gr::digital::header_format_base::~header_format_base ( )
virtual

Member Function Documentation

◆ base()

sptr gr::digital::header_format_base::base ( )
inline

◆ enter_have_header()

virtual void gr::digital::header_format_base::enter_have_header ( int  payload_len)
protectedvirtual

Header found, setup for pulling in the hard decision bits.

Reimplemented in gr::digital::header_format_default.

◆ enter_have_sync()

virtual void gr::digital::header_format_base::enter_have_sync ( )
protectedvirtual

Access code found, start getting the header.

Reimplemented in gr::digital::header_format_default.

◆ enter_search()

virtual void gr::digital::header_format_base::enter_search ( )
protectedvirtual

Enter Search state of the state machine to find the access code.

◆ format()

virtual bool gr::digital::header_format_base::format ( int  nbytes_in,
const unsigned char *  input,
pmt::pmt_t output,
pmt::pmt_t info 
)
pure virtual

Function to creates a header. The child classes overload this function to format the header in the protocol-specific way.

Parameters
nbytes_inThe length (in bytes) of the input payload
inputAn array of unsigned chars of the packet payload
outputA pmt::u8vector with the new header prepended onto the input data.
infoA 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_ofdm, gr::digital::header_format_default, gr::digital::header_format_crc, and gr::digital::header_format_counter.

◆ formatter()

sptr gr::digital::header_format_base::formatter ( )
inline

◆ header_nbits()

virtual size_t gr::digital::header_format_base::header_nbits ( ) const
pure virtual

Returns the length of the formatted header in bits. MUST be overloaded.

Implemented in gr::digital::header_format_ofdm, gr::digital::header_format_default, gr::digital::header_format_crc, and gr::digital::header_format_counter.

◆ header_nbytes()

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().

◆ header_ok()

virtual bool gr::digital::header_format_base::header_ok ( )
protectedpure virtual

◆ header_payload()

virtual int gr::digital::header_format_base::header_payload ( )
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_ofdm, gr::digital::header_format_default, gr::digital::header_format_crc, and gr::digital::header_format_counter.

◆ parse()

virtual bool gr::digital::header_format_base::parse ( int  nbits_in,
const unsigned char *  input,
std::vector< pmt::pmt_t > &  info,
int &  nbits_processed 
)
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.

Parameters
nbits_inThe number of bits in the input array.
inputThe input as hard decision bits.
infoA 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_processedNumber 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_ofdm, gr::digital::header_format_default, and gr::digital::header_format_crc.

Member Data Documentation

◆ d_debug_logger

gr::logger_ptr gr::digital::header_format_base::d_debug_logger
protected

◆ d_hdr_reg

header_buffer gr::digital::header_format_base::d_hdr_reg
protected

header_buffer object to hold header bits

◆ d_info

pmt::pmt_t gr::digital::header_format_base::d_info
protected

info captured from the header

◆ d_logger

gr::logger_ptr gr::digital::header_format_base::d_logger
protected

Used by blocks to access the logger system.

◆ d_state

state_t gr::digital::header_format_base::d_state
protected

state of the state machine


The documentation for this class was generated from the following file: