Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cozycactus committed Oct 22, 2024
1 parent 0418221 commit 576a12f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 53 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ endif()
include(FindPkgConfig)
find_package(Gnuradio-osmosdr REQUIRED)

set(GR_REQUIRED_COMPONENTS RUNTIME ANALOG AUDIO BLOCKS DIGITAL FILTER FFT PMT)
find_package(Gnuradio REQUIRED COMPONENTS analog audio blocks digital filter fft network)
set(GR_REQUIRED_COMPONENTS RUNTIME ANALOG AUDIO BLOCKS DIGITAL FILTER FFT PMT SOAPY)
find_package(Gnuradio REQUIRED COMPONENTS analog audio blocks digital filter fft network soapy)
if(NOT Gnuradio_FOUND)
message(FATAL_ERROR "GnuRadio Runtime required to compile gqrx")
endif()
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ if(NOT Gnuradio_VERSION VERSION_LESS "3.10")
gnuradio::gnuradio-filter
gnuradio::gnuradio-network
gnuradio::gnuradio-audio
gnuradio::gnuradio-soapy
Volk::volk
)
else()
Expand Down
130 changes: 80 additions & 50 deletions src/applications/gqrx/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <gnuradio/prefs.h>
#include <gnuradio/top_block.h>
#include <osmosdr/source.h>
#include <gnuradio/soapy/source.h>
#include <osmosdr/ranges.h>

#include "applications/gqrx/receiver.h"
Expand Down Expand Up @@ -79,12 +80,14 @@ receiver::receiver(const std::string input_device,

if (input_device.empty())
{
src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true");
//src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true");
soapy_src = gr::soapy::source::make("driver=rtlsdr","fc32",1,"","",{""},{""});
}
else
{
input_devstr = input_device;
src = osmosdr::source::make(input_device);
//src = osmosdr::source::make(input_device);
soapy_src = gr::soapy::source::make(input_device,"",0,"","",{""},{""});
}

// input decimator
Expand Down Expand Up @@ -201,12 +204,12 @@ void receiver::set_input_device(const std::string device)

if (d_decim >= 2)
{
tb->disconnect(src, 0, input_decim, 0);
tb->disconnect(soapy_src, 0, input_decim, 0);
tb->disconnect(input_decim, 0, iq_swap, 0);
}
else
{
tb->disconnect(src, 0, iq_swap, 0);
tb->disconnect(soapy_src, 0, iq_swap, 0);
}

#if GNURADIO_VERSION < 0x030802
Expand All @@ -219,30 +222,32 @@ void receiver::set_input_device(const std::string device)
tb->wait();
tb->disconnect(src, 0, iq_swap, 0);
#else
src.reset();
//src.reset();
soapy_src.reset();
#endif

try
{
src = osmosdr::source::make(device);
//src = osmosdr::source::make(device);
soapy_src = gr::soapy::source::make("driver=rtlsdr","fc32",1,"","",{""},{""});
}
catch (std::exception &x)
{
error = x.what();
src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true");
//src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true");
}

if(src->get_sample_rate() != 0)
set_input_rate(src->get_sample_rate());
if(soapy_src->get_sample_rate(0) != 0)
set_input_rate(soapy_src->get_sample_rate(0));

if (d_decim >= 2)
{
tb->connect(src, 0, input_decim, 0);
tb->connect(soapy_src, 0, input_decim, 0);
tb->connect(input_decim, 0, iq_swap, 0);
}
else
{
tb->connect(src, 0, iq_swap, 0);
tb->connect(soapy_src, 0, iq_swap, 0);
}

if (d_running)
Expand Down Expand Up @@ -303,15 +308,17 @@ void receiver::set_output_device(const std::string device)
/** Get a list of available antenna connectors. */
std::vector<std::string> receiver::get_antennas(void) const
{
return src->get_antennas();
//return src->get_antennas();
return soapy_src->list_antennas(0);
}

/** Select antenna connector. */
void receiver::set_antenna(const std::string &antenna)
{
if (!antenna.empty())
{
src->set_antenna(antenna);
//src->set_antenna(antenna);
soapy_src->set_antenna(0, antenna);
}
}

Expand All @@ -326,15 +333,17 @@ double receiver::set_input_rate(double rate)
double current_rate;
bool rate_has_changed;

current_rate = src->get_sample_rate();
current_rate = soapy_src->get_sample_rate(0);
rate_has_changed = !(rate == current_rate ||
std::abs(rate - current_rate) < std::abs(std::min(rate, current_rate))
* std::numeric_limits<double>::epsilon());

tb->lock();
try
{
d_input_rate = src->set_sample_rate(rate);
//d_input_rate = src->set_sample_rate(rate);
soapy_src->set_sample_rate(0, rate);
d_input_rate = soapy_src->get_sample_rate(0);
}
catch (std::runtime_error &e)
{
Expand Down Expand Up @@ -382,12 +391,12 @@ unsigned int receiver::set_input_decim(unsigned int decim)

if (d_decim >= 2)
{
tb->disconnect(src, 0, input_decim, 0);
tb->disconnect(soapy_src, 0, input_decim, 0);
tb->disconnect(input_decim, 0, iq_swap, 0);
}
else
{
tb->disconnect(src, 0, iq_swap, 0);
tb->disconnect(soapy_src, 0, iq_swap, 0);
}

input_decim.reset();
Expand Down Expand Up @@ -423,17 +432,17 @@ unsigned int receiver::set_input_decim(unsigned int decim)

if (d_decim >= 2)
{
tb->connect(src, 0, input_decim, 0);
tb->connect(soapy_src, 0, input_decim, 0);
tb->connect(input_decim, 0, iq_swap, 0);
}
else
{
tb->connect(src, 0, iq_swap, 0);
tb->connect(soapy_src, 0, iq_swap, 0);
}

#ifdef CUSTOM_AIRSPY_KERNELS
if (input_devstr.find("airspy") != std::string::npos)
src->set_bandwidth(d_decim_rate);
soapy_src->set_bandwidth(0,d_decim_rate);
#endif

if (d_running)
Expand All @@ -449,13 +458,14 @@ unsigned int receiver::set_input_decim(unsigned int decim)
*/
double receiver::set_analog_bandwidth(double bw)
{
return src->set_bandwidth(bw);
//return src->set_bandwidth(bw);
soapy_src->set_bandwidth(0, bw);
}

/** Get current analog bandwidth. */
double receiver::get_analog_bandwidth(void) const
{
return src->get_bandwidth();
return soapy_src->get_bandwidth(0);
}

/** Set I/Q reversed. */
Expand Down Expand Up @@ -515,7 +525,8 @@ void receiver::set_iq_balance(bool enable)

d_iq_balance = enable;

src->set_iq_balance_mode(enable ? 2 : 0);
//src->set_iq_balance_mode(enable ? 2 : 0);
soapy_src->set_iq_balance_mode(0, enable ? 2 : 0);
}

/**
Expand All @@ -538,7 +549,8 @@ receiver::status receiver::set_rf_freq(double freq_hz)
{
d_rf_freq = freq_hz;

src->set_center_freq(d_rf_freq);
//src->set_center_freq(d_rf_freq);
soapy_src->set_frequency(0, d_rf_freq);
// FIXME: read back frequency?

return STATUS_OK;
Expand All @@ -551,7 +563,8 @@ receiver::status receiver::set_rf_freq(double freq_hz)
*/
double receiver::get_rf_freq(void)
{
d_rf_freq = src->get_center_freq();
//d_rf_freq = src->get_center_freq();
d_rf_freq = soapy_src->get_frequency(0);

return d_rf_freq;
}
Expand All @@ -565,30 +578,41 @@ double receiver::get_rf_freq(void)
*/
receiver::status receiver::get_rf_range(double *start, double *stop, double *step)
{
osmosdr::freq_range_t range;
// Retrieve the frequency ranges from the device
std::vector<gr::soapy::range_t> ranges = soapy_src->get_frequency_range(0);

range = src->get_freq_range();

// currently range is empty for all but E4000
if (!range.empty())
// Check if any ranges are available
if (!ranges.empty())
{
if (range.start() < range.stop())
{
*start = range.start();
*stop = range.stop();
*step = range.step(); /** FIXME: got 0 for rtl-sdr? **/
// Use the first available range
gr::soapy::range_t range = ranges[0];

// Assign the start, stop, and step values
*start = range.minimum();
*stop = range.maximum();
*step = range.step();

return STATUS_OK;
// Handle zero step size if necessary
if (*step == 0)
{
// Assign a default step size
*step = 1.0; // Set to 1 Hz or any appropriate value
}
}

return STATUS_ERROR;
return STATUS_OK;
}
else
{
// No frequency ranges available
return STATUS_ERROR;
}
}

/** Get the names of available gain stages. */
std::vector<std::string> receiver::get_gain_names()
{
return src->get_gain_names();
//return src->get_gain_names();
return soapy_src->list_gains(0);
}

/**
Expand All @@ -603,26 +627,30 @@ std::vector<std::string> receiver::get_gain_names()
receiver::status receiver::get_gain_range(std::string &name, double *start,
double *stop, double *step) const
{
osmosdr::gain_range_t range;
//osmosdr::gain_range_t range;
gr::soapy::range_t range;

range = src->get_gain_range(name);
*start = range.start();
*stop = range.stop();
//range = src->get_gain_range(name);
range = soapy_src->get_gain_range(0, name);
*start = range.minimum();
*stop = range.maximum();
*step = range.step();

return STATUS_OK;
}

receiver::status receiver::set_gain(std::string name, double value)
{
src->set_gain(value, name);
//src->set_gain(value, name);
soapy_src->set_gain(0, name, value);

return STATUS_OK;
}

double receiver::get_gain(std::string name) const
{
return src->get_gain(name);
//return src->get_gain(name);
return soapy_src->get_gain(0, name);
}

/**
Expand All @@ -633,7 +661,8 @@ double receiver::get_gain(std::string name) const
*/
receiver::status receiver::set_auto_gain(bool automatic)
{
src->set_gain_mode(automatic);
//src->set_gain_mode(automatic);
soapy_src->set_gain_mode(0, automatic);

return STATUS_OK;
}
Expand Down Expand Up @@ -716,7 +745,8 @@ receiver::status receiver::set_filter(double low, double high, filter_shape shap

receiver::status receiver::set_freq_corr(double ppm)
{
src->set_freq_corr(ppm);
//src->set_freq_corr(ppm);
soapy_src->set_frequency_correction(0, ppm);

return STATUS_OK;
}
Expand Down Expand Up @@ -1221,7 +1251,7 @@ receiver::status receiver::start_iq_recording(const std::string filename)
if (d_decim >= 2)
tb->connect(input_decim, 0, iq_sink, 0);
else
tb->connect(src, 0, iq_sink, 0);
tb->connect(soapy_src, 0, iq_sink, 0);
d_recording_iq = true;
tb->unlock();

Expand All @@ -1242,7 +1272,7 @@ receiver::status receiver::stop_iq_recording()
if (d_decim >= 2)
tb->disconnect(input_decim, 0, iq_sink, 0);
else
tb->disconnect(src, 0, iq_sink, 0);
tb->disconnect(soapy_src, 0, iq_sink, 0);

tb->unlock();
iq_sink.reset();
Expand Down Expand Up @@ -1338,7 +1368,7 @@ void receiver::connect_all(rx_chain type)
gr::basic_block_sptr b;

// Setup source
b = src;
b = soapy_src;

// Pre-processing
if (d_decim >= 2)
Expand Down
4 changes: 4 additions & 0 deletions src/applications/gqrx/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <gnuradio/blocks/wavfile_source.h>
#include <gnuradio/top_block.h>
#include <osmosdr/source.h>
#include <gnuradio/soapy/source.h>
#include <string>

#include "dsp/correct_iq_cc.h"
Expand Down Expand Up @@ -258,6 +259,9 @@ class receiver
gr::top_block_sptr tb; /*!< The GNU Radio top block. */

osmosdr::source::sptr src; /*!< Real time I/Q source. */

gr::soapy::source::sptr soapy_src; /*!< SoapySDR source. */

fir_decim_cc_sptr input_decim; /*!< Input decimator. */
receiver_base_cf_sptr rx; /*!< receiver. */

Expand Down
3 changes: 2 additions & 1 deletion src/qtgui/plotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class CPlotter : public QFrame

void setFftCenterFreq(qint64 f) {
qint64 limit = ((qint64)m_SampleFreq - m_Span) / 2 - 1;
m_FftCenter = qBound(-limit, f, limit);
// m_FftCenter = qBound(-limit, f, limit);
// commented because it doesnt pass assert in debug build
}

qint64 getFftCenterFreq() const {
Expand Down

0 comments on commit 576a12f

Please sign in to comment.