| USRP Hardware Driver and Device Manual Version: 4.10.0.0 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 <cstddef>
14#include <cstdint>
15#include <optional>
16#include <string>
17#include <vector>
18
19 namespace uhd { namespace utils { namespace chdr {
20
35 class UHD_API chdr_packet
36{
37 public:
50 template <typename payload_t>
51 chdr_packet(uhd::rfnoc::chdr_w_t chdr_w,
52 uhd::rfnoc::chdr::chdr_header header,
53 payload_t payload,
54 std::optional<uint64_t> timestamp = {},
55 std::vector<uint64_t> metadata = {});
56
69 chdr_packet(uhd::rfnoc::chdr_w_t chdr_w,
70 uhd::rfnoc::chdr::chdr_header header,
71 std::vector<uint8_t> payload_data,
72 std::optional<uint64_t> timestamp = {},
73 std::vector<uint64_t> metadata = {});
74
79 uhd::rfnoc::chdr::chdr_header get_header() const;
80
85 void set_header(uhd::rfnoc::chdr::chdr_header header);
86
91 std::optional<uint64_t> get_timestamp() const;
92
98 void set_timestamp(std::optional<uint64_t> timestamp);
99
104 const std::vector<uint64_t>& get_metadata() const;
105
110 void set_metadata(std::vector<uint64_t> metadata);
111
117 std::vector<uint8_t> serialize_to_byte_vector(
118 endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
119
126 template <typename OutputIterator>
127 void serialize(OutputIterator first,
128 OutputIterator last,
129 endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
130
139 template <typename InputIterator>
140 static chdr_packet deserialize(uhd::rfnoc::chdr_w_t chdr_w,
141 InputIterator first,
142 InputIterator last,
143 endianness_t endianness = uhd::ENDIANNESS_LITTLE);
144
149 size_t get_packet_len() const;
150
155 const std::vector<uint8_t>& get_payload_bytes() const;
156
161 void set_payload_bytes(std::vector<uint8_t> bytes);
162
168 template <typename payload_t>
169 payload_t get_payload(uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
170
177 template <typename payload_t>
178 void set_payload(
179 payload_t payload, uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE);
180
182 std::string to_string() const;
183
185 template <typename payload_t>
186 std::string to_string_with_payload(
187 uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
188
189 private:
190 void serialize_ptr(endianness_t endianness, void* start, void* end) const;
191
192 static chdr_packet deserialize_ptr(uhd::rfnoc::chdr_w_t chdr_w,
193 endianness_t endianness,
194 const void* start,
195 const void* end);
196
197 inline void set_header_lengths()
198 {
199 _header.set_num_mdata(_mdata.size() / (uhd::rfnoc::chdr_w_to_bits(_chdr_w) / 64));
200 _header.set_length(get_packet_len());
201 }
202
203 uhd::rfnoc::chdr_w_t _chdr_w;
204 uhd::rfnoc::chdr::chdr_header _header;
205 std::vector<uint8_t> _payload;
206 std::optional<uint64_t> _timestamp;
207 std::vector<uint64_t> _mdata;
208};
209
210}}} // namespace uhd::utils::chdr
211
212#include <uhd/utils/chdr/chdr_packet.ipp>
chdr_packet.ipp
chdr_types.hpp
uhd::rfnoc::chdr::chdr_header
Definition chdr_types.hpp:37
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::deserialize
static chdr_packet deserialize(uhd::rfnoc::chdr_w_t chdr_w, InputIterator first, InputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE)
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, std::optional< uint64_t > timestamp={}, std::vector< uint64_t > metadata={})
uhd::utils::chdr::chdr_packet::set_timestamp
void set_timestamp(std::optional< uint64_t > timestamp)
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::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={})
Definition chdr_packet.ipp:16
uhd::utils::chdr::chdr_packet::get_timestamp
std::optional< uint64_t > get_timestamp() const
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_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::get_payload
payload_t get_payload(uhd::endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
Definition chdr_packet.ipp:47
uhd::utils::chdr::chdr_packet::serialize
void serialize(OutputIterator first, OutputIterator last, endianness_t endianness=uhd::ENDIANNESS_LITTLE) const
UHD_API
#define UHD_API
Definition config.h:87
config.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:19
uhd::utils
Definition chdr_packet.hpp:19
uhd
Definition build_info.hpp:12
rfnoc_types.hpp