Agora  1.2.0
Agora project
radio_socket.h
Go to the documentation of this file.
1 
5 #ifndef RADIO_SOCKET_H_
6 #define RADIO_SOCKET_H_
7 
8 #include <complex>
9 #include <cstddef>
10 #include <memory>
11 #include <queue>
12 #include <string>
13 #include <vector>
14 
15 #include "udp_server.h"
16 
18 class RadioSocket {
19  public:
20  RadioSocket();
21  ~RadioSocket();
22  //Allow move, and disallow copy
23  RadioSocket(RadioSocket&&) noexcept = default;
24  explicit RadioSocket(const RadioSocket&) = delete;
25 
26  void Create(size_t samples_per_symbol, const std::string& local_addr,
27  const std::string& remote_addr, const std::string& local_port,
28  const std::string& remote_port);
29  inline const std::string& Address() const { return socket_->Address(); }
30  inline const std::string& Port() const { return socket_->Port(); };
31 
32  int RxSamples(std::vector<void*>& out_data, long long& rx_time_ns,
33  size_t req_samples_per_channel);
34  void Flush();
35 
36  private:
37  bool CheckSymbolComplete(const std::byte* in_data, const int& in_count);
38  size_t InspectRx(const std::byte* in_data, size_t in_count,
39  long long& rx_time_ticks, size_t& burst_count) const;
40  size_t UnpackSamples(std::vector<void*>& out_samples, size_t req_samples,
41  long long& rx_time);
42 
43  size_t LoadSamples(std::vector<void*>& out_samples,
44  const std::complex<int16_t>* in_samples,
45  size_t num_in_samples);
46 
47  size_t GetUnpackedSamples(std::vector<void*>& out_samples, long long& rx_time,
48  size_t req_total_samples);
49 
50  size_t GetPackedSamples(std::vector<void*>& out_samples, long long& rx_time,
51  size_t sample_offset, size_t req_samples);
52 
53  std::unique_ptr<UDPServer> socket_;
54  std::vector<std::byte> rx_buffer_;
55  std::queue<size_t> rx_pkt_byte_count_;
56 
57  //Buffer to place "extra" samples that come during a socket read
58  std::vector<std::complex<int16_t>> sample_buffer_;
59  long long rx_time_unpacked_{0};
60 
61  size_t rx_bytes_{0};
62  size_t rx_samples_{0};
63 
65  const size_t bytes_per_element_{3u};
66 };
67 #endif // RADIO_SOCKET_H_
RadioSocket::InspectRx
size_t InspectRx(const std::byte *in_data, size_t in_count, long long &rx_time_ticks, size_t &burst_count) const
Definition: radio_socket.cc:497
RadioSocket::rx_time_unpacked_
long long rx_time_unpacked_
Definition: radio_socket.h:59
fmt::v8::detail::byte
byte
Definition: core.h:388
RadioSocket
Class to commicate with the Radios. Including symbol parsing, packing and unpacking based on control ...
Definition: radio_socket.h:18
fmt::v8::printf
auto printf(const S &fmt, const T &... args) -> int
Definition: printf.h:631
RadioSocket::GetUnpackedSamples
size_t GetUnpackedSamples(std::vector< void * > &out_samples, long long &rx_time, size_t req_total_samples)
Definition: radio_socket.cc:547
RadioSocket::Port
const std::string & Port() const
Definition: radio_socket.h:30
RadioSocket::bytes_per_element_
const size_t bytes_per_element_
Definition: radio_socket.h:65
HAS_TIME_RX_bf
#define HAS_TIME_RX_bf
Definition: radio_socket.cc:72
ValidateSamples
static size_t ValidateSamples(long long &stream_rx_time, const long long &pkt_rx_time, size_t previous_samples, size_t new_samples, size_t requested_samples, size_t burst_samples, size_t output_dim)
Definition: radio_socket.cc:84
RadioSocket::RxSamples
int RxSamples(std::vector< void * > &out_data, long long &rx_time_ns, size_t req_samples_per_channel)
Definition: radio_socket.cc:159
udp_server.h
Provides the UDPServer functions from the UDPComm class. Receiver only support.
RadioSocket::UnpackSamples
size_t UnpackSamples(std::vector< void * > &out_samples, size_t req_samples, long long &rx_time)
Definition: radio_socket.cc:264
AGORA_LOG_ERROR
#define AGORA_LOG_ERROR(...)
Definition: logger.h:39
spdlog::details::os::now
SPDLOG_INLINE spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT
Definition: os-inl.h:71
IrisCommData
Definition: radio_socket.cc:75
AGORA_LOG_TRACE
#define AGORA_LOG_TRACE(...)
Definition: logger.h:92
IS_TRIGGER_bf
#define IS_TRIGGER_bf
Definition: radio_socket.cc:64
IS_BURST_bf
#define IS_BURST_bf
Definition: radio_socket.cc:66
RadioSocket::sample_buffer_
std::vector< std::complex< int16_t > > sample_buffer_
Definition: radio_socket.h:58
kMaxMTU
static constexpr size_t kMaxMTU
Definition: radio_socket.cc:13
RX_TIME_ERROR_bf
#define RX_TIME_ERROR_bf
Definition: radio_socket.cc:70
RadioSocket::LoadSamples
size_t LoadSamples(std::vector< void * > &out_samples, const std::complex< int16_t > *in_samples, size_t num_in_samples)
Definition: radio_socket.cc:465
RadioSocket::CheckSymbolComplete
bool CheckSymbolComplete(const std::byte *in_data, const int &in_count)
Definition: radio_socket.cc:386
RadioSocket::~RadioSocket
~RadioSocket()
Definition: radio_socket.cc:135
u
Plot Rx waveform for u
Definition: inspect_single_frame.m:108
RadioSocket::GetPackedSamples
size_t GetPackedSamples(std::vector< void * > &out_samples, long long &rx_time, size_t sample_offset, size_t req_samples)
Definition: radio_socket.cc:588
kDebugIrisRx
static constexpr bool kDebugIrisRx
Definition: radio_socket.cc:18
kRxBufferSize
static constexpr size_t kRxBufferSize
Definition: radio_socket.cc:15
RadioSocket::Create
void Create(size_t samples_per_symbol, const std::string &local_addr, const std::string &remote_addr, const std::string &local_port, const std::string &remote_port)
Definition: radio_socket.cc:137
RadioSocket::Address
const std::string & Address() const
Definition: radio_socket.h:29
RadioSocket::socket_
std::unique_ptr< UDPServer > socket_
Definition: radio_socket.h:53
std
Definition: json.hpp:5213
RX_OVERFLOW_bf
#define RX_OVERFLOW_bf
Definition: radio_socket.cc:68
kRxSampleRemBufSize
static constexpr size_t kRxSampleRemBufSize
Definition: radio_socket.cc:17
RtAssert
static void RtAssert(bool condition, const char *throw_str)
Definition: utils.h:104
RadioSocket::rx_samples_
size_t rx_samples_
Definition: radio_socket.h:62
AGORA_LOG_WARN
#define AGORA_LOG_WARN(...)
Definition: logger.h:53
IrisCommData::header_
uint64_t header_[2u]
Definition: radio_socket.cc:76
IrisCommData::data_
uint8_t data_[]
Definition: radio_socket.cc:78
rx_data
case QPSK rx_data
Definition: generate_data.m:160
DEBUG_OUTPUT
#define DEBUG_OUTPUT(...)
Definition: radio_socket.cc:26
RadioSocket::rx_bytes_
size_t rx_bytes_
Definition: radio_socket.h:61
RadioSocket::rx_buffer_
std::vector< std::byte > rx_buffer_
Definition: radio_socket.h:54
RadioSocket::samples_per_symbol_
size_t samples_per_symbol_
Definition: radio_socket.h:64
__attribute__
struct IrisCommData __attribute__((packed))
radio_socket.h
Declaration file for the RadioSocket class.
kSockBufSize
static constexpr size_t kSockBufSize
Definition: channel_sim.cc:26
RadioSocket::RadioSocket
RadioSocket()
Definition: radio_socket.cc:126
RadioSocket::rx_pkt_byte_count_
std::queue< size_t > rx_pkt_byte_count_
Definition: radio_socket.h:55
RadioSocket::Flush
void Flush()
Definition: radio_socket.cc:420