USRP Hardware Driver and Device Manual Version: 4.10.0.0
UHD and USRP Manual
Loading...
Searching...
No Matches
uhd::utils::chdr::chdr_packet Class Reference

#include <uhd/utils/chdr/chdr_packet.hpp>

Detailed Description

A Generic class that represents a CHDR Packet

This class is not used by UHD, it is a helper class for writing tests or other types of utilities. The class has the capability of representing any CHDR packet, and serializing this class into a CHDR packet (or deserializing from a buffer to populate this class). It is not optimized for high performance. For example, this is used in UHD unit tests, and in the USRP simulator to provide an easy way to generate CHDR packets from Python.

Whether the packet has a specific type of payload is not specified, but of course the CHDR header can be set as desired, and a payload can be provided to the constructor.

Public Member Functions

template<typename payload_t>
 chdr_packet (uhd::rfnoc::chdr_w_t chdr_w, uhd::rfnoc::chdr::chdr_header header, payload_t payload, std::optional< uint64_t > timestamp={}, std::vector< uint64_t > metadata={})
 chdr_packet (uhd::rfnoc::chdr_w_t chdr_w, uhd::rfnoc::chdr::chdr_header header, std::vector< uint8_t > payload_data, std::optional< uint64_t > timestamp={}, std::vector< uint64_t > metadata={})
uhd::rfnoc::chdr::chdr_header get_header () const
void set_header (uhd::rfnoc::chdr::chdr_header header)
std::optional< uint64_t > get_timestamp () const
void set_timestamp (std::optional< uint64_t > timestamp)
const std::vector< uint64_t > & get_metadata () const
void set_metadata (std::vector< uint64_t > metadata)
std::vector< uint8_t > serialize_to_byte_vector (endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
template<typename OutputIterator>
void serialize (OutputIterator first, OutputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
size_t get_packet_len () const
const std::vector< uint8_t > & get_payload_bytes () const
void set_payload_bytes (std::vector< uint8_t > bytes)
template<typename payload_t>
payload_t get_payload (uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
template<typename payload_t>
void set_payload (payload_t payload, uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE)
std::string to_string () const
 Return a string representation of this object.
template<typename payload_t>
std::string to_string_with_payload (uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
 Return a string representation of this object and deserialize its payload.
template<typename OutputIterator>
void serialize (OutputIterator first, OutputIterator last, uhd::endianness_t endianness) const
template<typename InputIterator>
chdr_packet deserialize (uhd::rfnoc::chdr_w_t chdr_w, InputIterator first, InputIterator last, uhd::endianness_t endianness)

Static Public Member Functions

template<typename InputIterator>
static chdr_packet deserialize (uhd::rfnoc::chdr_w_t chdr_w, InputIterator first, InputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE)

Constructor & Destructor Documentation

◆ chdr_packet() [1/2]

template<typename payload_t>
uhd::utils::chdr::chdr_packet::chdr_packet ( uhd::rfnoc::chdr_w_t chdr_w,
uhd::rfnoc::chdr::chdr_header header,
payload_t payload,
std::optional< uint64_t > timestamp = {},
std::vector< uint64_t > metadata = {} )

Constructs a CHDR Packet from a header and a payload

This is commonly used to create a non-data packet (e.g., control, stream status, etc.).

Parameters
chdr_wCHDR width
headerCHDR header
payloadThe payload object (e.g., a chdr_rfnoc::ctrl_payload if that's the type of payload_t).
timestampTimestamp, defaults to no timestamp in the header.
metadataMetadata, defaults to no metadata.

◆ chdr_packet() [2/2]

uhd::utils::chdr::chdr_packet::chdr_packet ( uhd::rfnoc::chdr_w_t chdr_w,
uhd::rfnoc::chdr::chdr_header header,
std::vector< uint8_t > payload_data,
std::optional< uint64_t > timestamp = {},
std::vector< uint64_t > metadata = {} )

Construct a CHDR Packet from a header and raw payload words

This is the typical way to construct data packets, or to manually construct non-data packets by bypassing the corresponding payload types.

Parameters
chdr_wCHDR width
headerCHDR header
payload_dataThe payload data as bytes, i.e., whatever follows the CHDR header.
timestampTimestamp, defaults to no timestamp in the header.
metadataMetadata, defaults to no metadata.

Member Function Documentation

◆ deserialize() [1/2]

template<typename InputIterator>
chdr_packet uhd::utils::chdr::chdr_packet::deserialize ( uhd::rfnoc::chdr_w_t chdr_w,
InputIterator first,
InputIterator last,
endianness_t endianness = uhd::ENDIANNESS_LITTLE )
static

Deserialize a CHDR Packet from a buffer of bytes

Parameters
chdr_wthe CHDR_W of the incoming packet
endiannessthe endianness of the input buffer (link endianness)
firstthe start of the input buffer
lastthe end of the input buffer
Returns
a CHDR Packet with an unspecified payload type

◆ deserialize() [2/2]

template<typename InputIterator>
chdr_packet uhd::utils::chdr::chdr_packet::deserialize ( uhd::rfnoc::chdr_w_t chdr_w,
InputIterator first,
InputIterator last,
uhd::endianness_t endianness )

◆ get_header()

uhd::rfnoc::chdr::chdr_header uhd::utils::chdr::chdr_packet::get_header ( ) const

Returns the contents of the CHDR header

Returns
The CHDR header

◆ get_metadata()

const std::vector< uint64_t > & uhd::utils::chdr::chdr_packet::get_metadata ( ) const

Returns a const reference to the metadata

Returns
The metadata reference

◆ get_packet_len()

size_t uhd::utils::chdr::chdr_packet::get_packet_len ( ) const

Get the total serialized length of the packet

Returns
The length of the packet in bytes

◆ get_payload()

template<typename payload_t>
payload_t uhd::utils::chdr::chdr_packet::get_payload ( uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const

Parses the data out of this objects payload field into a payload_t object

Parameters
endiannessThe link endianness of the CHDR Link
Returns
The parsed payload_t object

◆ get_payload_bytes()

const std::vector< uint8_t > & uhd::utils::chdr::chdr_packet::get_payload_bytes ( ) const

Returns a const reference to the payload bytes

Returns
The payload reference

◆ get_timestamp()

std::optional< uint64_t > uhd::utils::chdr::chdr_packet::get_timestamp ( ) const

Returns the timestamp in the packet as an optional value

Returns
A std::optional which if initialized has the timestamp

◆ serialize() [1/2]

template<typename OutputIterator>
void uhd::utils::chdr::chdr_packet::serialize ( OutputIterator first,
OutputIterator last,
endianness_t endianness = uhd::ENDIANNESS_LITTLE ) const

Serialize a CHDR Packet into a buffer

Parameters
endiannessthe endianness of the output buffer (link endianness)
firstthe start of the output buffer
lastthe end of the output buffer

◆ serialize() [2/2]

template<typename OutputIterator>
void uhd::utils::chdr::chdr_packet::serialize ( OutputIterator first,
OutputIterator last,
uhd::endianness_t endianness ) const

◆ serialize_to_byte_vector()

std::vector< uint8_t > uhd::utils::chdr::chdr_packet::serialize_to_byte_vector ( endianness_t endianness = uhd::ENDIANNESS_LITTLE) const

Serialize a CHDR Packet into a vector of bytes

Parameters
endiannessthe endianness of the returned vector (link endianness)
Returns
a vector of bytes which represents the CHDR Packet in serialize form

◆ set_header()

void uhd::utils::chdr::chdr_packet::set_header ( uhd::rfnoc::chdr::chdr_header header)

Change this object's header

Parameters
headerThe new CHDR header

◆ set_metadata()

void uhd::utils::chdr::chdr_packet::set_metadata ( std::vector< uint64_t > metadata)

Sets the metadata for a CHDR packet and updates the headers

Parameters
metadataA vector containing the new metadata

◆ set_payload()

template<typename payload_t>
void uhd::utils::chdr::chdr_packet::set_payload ( payload_t payload,
uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE )

Serializes the payload object into bytes and stores it in this object's payload field

Parameters
payloadthe payload object to store
endiannessThe link endianness of the CHDR Link

◆ set_payload_bytes()

void uhd::utils::chdr::chdr_packet::set_payload_bytes ( std::vector< uint8_t > bytes)

Sets the current payload

Parameters
bytesthe payload to store inside this object (It is moved from)

◆ set_timestamp()

void uhd::utils::chdr::chdr_packet::set_timestamp ( std::optional< uint64_t > timestamp)

Sets the timestamp in the packet

Parameters
timestampthe timestamp to set, or an empty optional for no timestamp

◆ to_string()

std::string uhd::utils::chdr::chdr_packet::to_string ( ) const

Return a string representation of this object.

◆ to_string_with_payload()

template<typename payload_t>
std::string uhd::utils::chdr::chdr_packet::to_string_with_payload ( uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const

Return a string representation of this object and deserialize its payload.


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