GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
rtl_tcp_signal_source_c.h
Go to the documentation of this file.
1/*!
2 * \file rtl_tcp_signal_source_c.h
3 * \brief Interface of an rtl_tcp signal source reader.
4 * \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
5 *
6 * The implementation of this block is a combination of various helpful
7 * sources. The data format and command structure is taken from the
8 * original Osmocom rtl_tcp_source_f (https://git.osmocom.org/gr-osmosdr).
9 * The asynchronous reading code comes from the examples provides
10 * by Boost.Asio and the bounded buffer producer-consumer solution is
11 * taken from the Boost.CircularBuffer examples (https://www.boost.org/).
12 *
13 * -----------------------------------------------------------------------------
14 *
15 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
16 * This file is part of GNSS-SDR.
17 *
18 * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
19 * SPDX-License-Identifier: GPL-3.0-or-later
20 *
21 * -----------------------------------------------------------------------------
22 */
23
24#ifndef GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H
25#define GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H
26
28#include "rtl_tcp_dongle_info.h"
29#include <boost/array.hpp>
30#include <boost/asio.hpp>
31#include <boost/circular_buffer.hpp>
32#include <boost/thread/condition.hpp>
33#include <boost/thread/mutex.hpp>
34#include <gnuradio/sync_block.h>
35#include <cstdint>
36#include <string>
37#include <vector>
38
39
40/** \addtogroup Signal_Source
41 * \{ */
42/** \addtogroup Signal_Source_gnuradio_blocks
43 * \{ */
44
45
47
48using rtl_tcp_signal_source_c_sptr = gnss_shared_ptr<rtl_tcp_signal_source_c>;
49
50#if USE_BOOST_ASIO_IO_CONTEXT
51using b_io_context = boost::asio::io_context;
52#else
53using b_io_context = boost::asio::io_service;
54#endif
55
56rtl_tcp_signal_source_c_sptr
57rtl_tcp_make_signal_source_c(const std::string &address,
58 int16_t port,
59 bool flip_iq = false);
60
61/*!
62 * \brief This class reads interleaved I/Q samples
63 * from an rtl_tcp server and outputs complex types.
64 */
65class rtl_tcp_signal_source_c : public gr::sync_block
66{
67public:
68 ~rtl_tcp_signal_source_c();
69
70 int work(int noutput_items,
71 gr_vector_const_void_star &input_items,
72 gr_vector_void_star &output_items);
73
74 void set_frequency(int frequency);
75 void set_sample_rate(int sample_rate);
76 void set_agc_mode(bool agc);
77 void set_gain(int gain);
78 void set_if_gain(int gain);
79
80private:
81 friend rtl_tcp_signal_source_c_sptr
82 rtl_tcp_make_signal_source_c(const std::string &address,
83 int16_t port,
84 bool flip_iq);
85
86 rtl_tcp_signal_source_c(const std::string &address,
87 int16_t port,
88 bool flip_iq);
89
90 // async read callback
91 void handle_read(const boost::system::error_code &ec,
92 size_t bytes_transferred);
93
94 inline bool not_full() const
95 {
96 return unread_ < buffer_.capacity();
97 }
98
99 inline bool not_empty() const
100 {
101 return unread_ > 0 || io_context_.stopped();
102 }
103
104 boost::circular_buffer_space_optimized<float> buffer_;
105 // producer-consumer helpers
106 boost::mutex mutex_;
107 boost::condition not_full_;
108 boost::condition not_empty_;
109
110 // lookup for scaling data
111 boost::array<float, 0xff> lookup_{};
112
113 // IO members
114 b_io_context io_context_;
115 boost::asio::ip::tcp::socket socket_;
116 std::vector<unsigned char> data_;
117
119 size_t unread_;
120 bool flip_iq_;
121};
122
123
124/** \} */
125/** \} */
126#endif // GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H
This class represents the dongle information which is sent by rtl_tcp.
This class reads interleaved I/Q samples from an rtl_tcp server and outputs complex types.
This interface represents a GNSS block.
Interface for a structure sent by rtl_tcp defining the hardware.