USRP Hardware Driver and USRP Manual: chdr_packet.hpp Source File

| USRP Hardware Driver and USRP Manual Version: 4.8.0.makepkg-0-g308126a4 UHD and USRP Manual |

Loading...
Searching...
No Matches
chdr_packet.hpp
Go to the documentation of this file.
1//
2// Copyright 2020 Ettus Research, a National Instruments Brand
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7#pragma once
8
9#include <uhd/config.hpp>
10#include <uhd/rfnoc/chdr_types.hpp>
11#include <uhd/rfnoc/rfnoc_types.hpp>
12#include <uhd/types/endianness.hpp>
13#include <boost/none.hpp>
14#include <boost/optional.hpp>
15#include <cstddef>
16#include <cstdint>
17#include <string>
18#include <vector>
19
20 namespace uhd { namespace utils { namespace chdr {
21
26 class UHD_API chdr_packet
27{
28public:
33 template <typename payload_t>
34 chdr_packet(uhd::rfnoc::chdr_w_t chdr_w,
35 uhd::rfnoc::chdr::chdr_header header,
36 payload_t payload,
37 boost::optional<uint64_t> timestamp = boost::none,
38 std::vector<uint64_t> metadata = {});
39
44 chdr_packet(uhd::rfnoc::chdr_w_t chdr_w,
45 uhd::rfnoc::chdr::chdr_header header,
46 std::vector<uint8_t> payload_data,
47 boost::optional<uint64_t> timestamp = boost::none,
48 std::vector<uint64_t> mdata = {});
49
54 uhd::rfnoc::chdr::chdr_header get_header() const;
55
60 void set_header(uhd::rfnoc::chdr::chdr_header header);
61
66 boost::optional<uint64_t> get_timestamp() const;
67
72 void set_timestamp(boost::optional<uint64_t> timestamp);
73
78 const std::vector<uint64_t>& get_metadata() const;
79
84 void set_metadata(std::vector<uint64_t> metadata);
85
91 std::vector<uint8_t> serialize_to_byte_vector(
92 endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
93
100 template <typename OutputIterator>
101 void serialize(OutputIterator first,
102 OutputIterator last,
103 endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
104
113 template <typename InputIterator>
114 static chdr_packet deserialize(uhd::rfnoc::chdr_w_t chdr_w,
115 InputIterator first,
116 InputIterator last,
117 endianness_t endianness = uhd::ENDIANNESS_LITTLE);
118
123 size_t get_packet_len() const;
124
129 const std::vector<uint8_t>& get_payload_bytes() const;
130
135 void set_payload_bytes(std::vector<uint8_t> bytes);
136
142 template <typename payload_t>
143 payload_t get_payload(uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
144
151 template <typename payload_t>
152 void set_payload(
153 payload_t payload, uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE);
154
156 std::string to_string() const;
157
159 template <typename payload_t>
160 std::string to_string_with_payload(
161 uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
162
163private:
164 void serialize_ptr(endianness_t endianness, void* start, void* end) const;
165 static chdr_packet deserialize_ptr(uhd::rfnoc::chdr_w_t chdr_w,
166 endianness_t endianness,
167 const void* start,
168 const void* end);
169 inline void set_header_lengths()
170 {
171 _header.set_num_mdata(_mdata.size() / (uhd::rfnoc::chdr_w_to_bits(_chdr_w) / 64));
172 _header.set_length(get_packet_len());
173 }
174 uhd::rfnoc::chdr_w_t _chdr_w;
175 uhd::rfnoc::chdr::chdr_header _header;
176 std::vector<uint8_t> _payload;
177 boost::optional<uint64_t> _timestamp;
178 std::vector<uint64_t> _mdata;
179};
180
181}}} // namespace uhd::utils::chdr
182
183#include <uhd/utils/chdr/chdr_packet.ipp>
chdr_packet.ipp
chdr_types.hpp
uhd::rfnoc::chdr::chdr_header
Definition chdr_types.hpp:35
uhd::utils::chdr::chdr_packet::get_header
uhd::rfnoc::chdr::chdr_header get_header() const
uhd::utils::chdr::chdr_packet::serialize_to_byte_vector
std::vector< uint8_t > serialize_to_byte_vector(endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
uhd::utils::chdr::chdr_packet::to_string_with_payload
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.
Definition chdr_packet.ipp:81
uhd::utils::chdr::chdr_packet::set_payload
void set_payload(payload_t payload, uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE)
Definition chdr_packet.ipp:64
uhd::utils::chdr::chdr_packet::get_packet_len
size_t get_packet_len() const
uhd::utils::chdr::chdr_packet::get_metadata
const std::vector< uint64_t > & get_metadata() const
uhd::utils::chdr::chdr_packet::set_metadata
void set_metadata(std::vector< uint64_t > metadata)
uhd::utils::chdr::chdr_packet::set_timestamp
void set_timestamp(boost::optional< uint64_t > timestamp)
uhd::utils::chdr::chdr_packet::set_header
void set_header(uhd::rfnoc::chdr::chdr_header header)
uhd::utils::chdr::chdr_packet::to_string
std::string to_string() const
Return a string representation of this object.
uhd::utils::chdr::chdr_packet::set_payload_bytes
void set_payload_bytes(std::vector< uint8_t > bytes)
uhd::utils::chdr::chdr_packet::get_payload_bytes
const std::vector< uint8_t > & get_payload_bytes() const
uhd::utils::chdr::chdr_packet::chdr_packet
chdr_packet(uhd::rfnoc::chdr_w_t chdr_w, uhd::rfnoc::chdr::chdr_header header, std::vector< uint8_t > payload_data, boost::optional< uint64_t > timestamp=boost::none, std::vector< uint64_t > mdata={})
uhd::utils::chdr::chdr_packet::chdr_packet
chdr_packet(uhd::rfnoc::chdr_w_t chdr_w, uhd::rfnoc::chdr::chdr_header header, payload_t payload, boost::optional< uint64_t > timestamp=boost::none, std::vector< uint64_t > metadata={})
Definition chdr_packet.ipp:16
uhd::utils::chdr::chdr_packet::get_payload
payload_t get_payload(uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
Definition chdr_packet.ipp:47
uhd::utils::chdr::chdr_packet::deserialize
static chdr_packet deserialize(uhd::rfnoc::chdr_w_t chdr_w, InputIterator first, InputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE)
Definition chdr_packet.ipp:36
uhd::utils::chdr::chdr_packet::get_timestamp
boost::optional< uint64_t > get_timestamp() const
uhd::utils::chdr::chdr_packet::serialize
void serialize(OutputIterator first, OutputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
Definition chdr_packet.ipp:27
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
endianness.hpp
uhd::rfnoc::chdr_w_t
chdr_w_t
Type that indicates the CHDR Width in bits.
Definition rfnoc_types.hpp:19
uhd::rfnoc::chdr_w_to_bits
constexpr size_t chdr_w_to_bits(chdr_w_t chdr_w)
Conversion from chdr_w_t to a number of bits.
Definition rfnoc_types.hpp:22
uhd::utils::chdr
Definition chdr_packet.hpp:20
uhd::utils
Definition chdr_packet.hpp:20
uhd
Definition build_info.hpp:12
uhd::endianness_t
endianness_t
Definition endianness.hpp:30
uhd::ENDIANNESS_LITTLE
@ ENDIANNESS_LITTLE
Definition endianness.hpp:30
rfnoc_types.hpp