USRP Hardware Driver and USRP Manual  Version: 4.6.0.0
UHD and USRP Manual
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 
10 #include <boost/optional.hpp>
11 #include <memory>
12 #include <vector>
13 
14 namespace uhd { namespace utils { namespace chdr {
15 
21 {
22 public:
27  template <typename payload_t>
30  payload_t payload,
31  boost::optional<uint64_t> timestamp = boost::none,
32  std::vector<uint64_t> metadata = {});
33 
40  std::vector<uint8_t> payload_data,
41  boost::optional<uint64_t> timestamp = boost::none,
42  std::vector<uint64_t> mdata = {});
43 
48  uhd::rfnoc::chdr::chdr_header get_header() const;
49 
54  void set_header(uhd::rfnoc::chdr::chdr_header header);
55 
60  boost::optional<uint64_t> get_timestamp() const;
61 
66  void set_timestamp(boost::optional<uint64_t> timestamp);
67 
72  const std::vector<uint64_t>& get_metadata() const;
73 
78  void set_metadata(std::vector<uint64_t> metadata);
79 
85  std::vector<uint8_t> serialize_to_byte_vector(
86  endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
87 
94  template <typename OutputIterator>
95  void serialize(OutputIterator first,
96  OutputIterator last,
97  endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
98 
107  template <typename InputIterator>
108  static chdr_packet deserialize(uhd::rfnoc::chdr_w_t chdr_w,
109  InputIterator first,
110  InputIterator last,
111  endianness_t endianness = uhd::ENDIANNESS_LITTLE);
112 
117  size_t get_packet_len() const;
118 
123  const std::vector<uint8_t>& get_payload_bytes() const;
124 
129  void set_payload_bytes(std::vector<uint8_t> bytes);
130 
136  template <typename payload_t>
137  payload_t get_payload(uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
138 
145  template <typename payload_t>
146  void set_payload(
147  payload_t payload, uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE);
148 
150  const std::string to_string() const;
151 
153  template <typename payload_t>
154  const std::string to_string_with_payload(
155  uhd::endianness_t endianness = uhd::ENDIANNESS_LITTLE) const;
156 
157 private:
158  void serialize_ptr(endianness_t endianness, void* start, void* end) const;
159  static chdr_packet deserialize_ptr(uhd::rfnoc::chdr_w_t chdr_w,
160  endianness_t endianness,
161  const void* start,
162  const void* end);
163  inline void set_header_lengths()
164  {
165  _header.set_num_mdata(_mdata.size() / (uhd::rfnoc::chdr_w_to_bits(_chdr_w) / 64));
166  _header.set_length(get_packet_len());
167  }
168  uhd::rfnoc::chdr_w_t _chdr_w;
170  std::vector<uint8_t> _payload;
171  boost::optional<uint64_t> _timestamp;
172  std::vector<uint64_t> _mdata;
173 };
174 
175 }}} // namespace uhd::utils::chdr
176 
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
Definition: build_info.hpp:12
Definition: chdr_packet.hpp:20
Definition: chdr_types.hpp:34
endianness_t
Definition: endianness.hpp:30
Definition: endianness.hpp:30
#define UHD_API
Definition: config.h:87
chdr_w_t
Type that indicates the CHDR Width in bits.
Definition: rfnoc_types.hpp:19