1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-14 01:06:51 +00:00
gnss-sdr/src/algorithms/signal_source/gnuradio_blocks/rtl_tcp_signal_source_c.h

132 lines
3.9 KiB
C
Raw Normal View History

2015-05-08 06:59:38 +00:00
/*!
2015-05-09 02:20:44 +00:00
* \file rtl_tcp_signal_source_c.h
2015-05-08 06:59:38 +00:00
* \brief Interface of an rtl_tcp signal source reader.
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
*
2015-05-09 02:20:44 +00:00
* The implementation of this block is a combination of various helpful
* sources. The data format and command structure is taken from the
* original Osmocom rtl_tcp_source_f (https://git.osmocom.org/gr-osmosdr).
2015-05-09 02:20:44 +00:00
* The aynchronous reading code comes from the examples provides
* by Boost.Asio and the bounded buffer producer-consumer solution is
* taken from the Boost.CircularBuffer examples (https://www.boost.org/).
2015-05-09 02:20:44 +00:00
*
2015-05-08 06:59:38 +00:00
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
2015-05-08 06:59:38 +00:00
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
2015-05-08 06:59:38 +00:00
*
* -------------------------------------------------------------------------
*/
2019-09-07 14:42:22 +00:00
#ifndef GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H_
#define GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H_
2015-05-08 06:59:38 +00:00
2015-05-10 13:42:13 +00:00
#include "rtl_tcp_dongle_info.h"
2015-05-08 06:59:38 +00:00
#include <boost/array.hpp>
#include <boost/asio.hpp>
2015-05-08 06:59:38 +00:00
#include <boost/circular_buffer.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/mutex.hpp>
#include <gnuradio/sync_block.h>
#include <cstdint>
#include <string>
#include <vector>
2015-05-08 06:59:38 +00:00
2015-05-09 02:20:44 +00:00
class rtl_tcp_signal_source_c;
2015-05-08 06:59:38 +00:00
using rtl_tcp_signal_source_c_sptr = boost::shared_ptr<rtl_tcp_signal_source_c>;
2015-05-08 06:59:38 +00:00
2019-05-08 14:15:59 +00:00
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;
#else
using b_io_context = boost::asio::io_service;
#endif
2015-05-09 02:20:44 +00:00
rtl_tcp_signal_source_c_sptr
rtl_tcp_make_signal_source_c(const std::string &address,
int16_t port,
bool flip_iq = false);
2015-05-08 06:59:38 +00:00
/*!
* \brief This class reads interleaved I/Q samples
2015-05-09 02:20:44 +00:00
* from an rtl_tcp server and outputs complex types.
2015-05-08 06:59:38 +00:00
*/
2015-05-09 02:20:44 +00:00
class rtl_tcp_signal_source_c : public gr::sync_block
2015-05-08 06:59:38 +00:00
{
public:
2015-05-09 02:20:44 +00:00
~rtl_tcp_signal_source_c();
2015-05-08 06:59:38 +00:00
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
2015-05-08 06:59:38 +00:00
void set_frequency(int frequency);
void set_sample_rate(int sample_rate);
void set_agc_mode(bool agc);
void set_gain(int gain);
void set_if_gain(int gain);
2015-05-10 12:57:43 +00:00
2015-05-08 06:59:38 +00:00
private:
using buffer_type = boost::circular_buffer_space_optimized<float>;
2015-05-10 12:57:43 +00:00
2015-05-09 02:20:44 +00:00
friend rtl_tcp_signal_source_c_sptr
2016-05-02 21:46:30 +00:00
rtl_tcp_make_signal_source_c(const std::string &address,
int16_t port,
bool flip_iq);
2015-05-08 06:59:38 +00:00
2015-05-09 02:20:44 +00:00
rtl_tcp_signal_source_c(const std::string &address,
int16_t port,
bool flip_iq);
2015-05-08 06:59:38 +00:00
Rtl_Tcp_Dongle_Info info_;
2015-05-10 13:42:13 +00:00
2015-05-09 02:20:44 +00:00
// IO members
2019-05-08 14:15:59 +00:00
b_io_context io_context_;
2015-05-08 06:59:38 +00:00
boost::asio::ip::tcp::socket socket_;
2015-05-09 02:20:44 +00:00
std::vector<unsigned char> data_;
2015-05-10 12:57:43 +00:00
bool flip_iq_;
2015-05-09 02:20:44 +00:00
// producer-consumer helpers
2015-05-08 06:59:38 +00:00
boost::mutex mutex_;
boost::condition not_full_;
boost::condition not_empty_;
2015-05-09 02:20:44 +00:00
buffer_type buffer_;
2015-05-08 06:59:38 +00:00
size_t unread_;
2015-05-10 12:57:43 +00:00
// lookup for scaling data
2019-07-20 09:13:28 +00:00
boost::array<float, 0xff> lookup_{};
2015-05-08 06:59:38 +00:00
2015-05-09 02:20:44 +00:00
// async read callback
void handle_read(const boost::system::error_code &ec,
size_t bytes_transferred);
2015-05-10 12:57:43 +00:00
inline bool not_full() const
2017-10-18 07:08:13 +00:00
{
return unread_ < buffer_.capacity();
2015-05-08 06:59:38 +00:00
}
inline bool not_empty() const
2017-10-18 07:08:13 +00:00
{
return unread_ > 0 || io_context_.stopped();
2015-05-08 06:59:38 +00:00
}
};
2019-09-07 14:42:22 +00:00
#endif // GNSS_SDR_RTL_TCP_SIGNAL_SOURCE_C_H_