From 58d91dc207d1208ed9bfc52aad63577223d2a9de Mon Sep 17 00:00:00 2001 From: blackwiz4rd Date: Fri, 14 May 2021 12:20:04 +0200 Subject: [PATCH 1/2] added direct_sampling --- src/device.cxx | 18 ++++++++++++++++++ src/device.h | 2 ++ src/params.cxx | 3 +++ src/params.h | 1 + src/rtl_power_fftw.cxx | 5 +++++ 5 files changed, 29 insertions(+) diff --git a/src/device.cxx b/src/device.cxx index af1d880..2565cda 100644 --- a/src/device.cxx +++ b/src/device.cxx @@ -69,6 +69,16 @@ std::vector Rtlsdr::gains() const { return gains; } +uint32_t Rtlsdr::direct_sampling() const { + uint32_t direct_sampling = rtlsdr_get_direct_sampling(dev); + if (direct_sampling != 0 && direct_sampling != 1 && direct_sampling != 2) { + throw RPFexception( + "RTL device: could not read direct sampling.", + ReturnValue::HardwareError); + } + return direct_sampling; +} + uint32_t Rtlsdr::sample_rate() const { uint32_t sample_rate = rtlsdr_get_sample_rate(dev); if (sample_rate == 0) { @@ -108,6 +118,14 @@ void Rtlsdr::set_gain(int gain) { } } +void Rtlsdr::set_direct_sampling(int direct_sampling) { + if (rtlsdr_set_direct_sampling(dev, direct_sampling)) { + throw RPFexception( + "RTL device: could not set direct sampling.", + ReturnValue::HardwareError); + } +} + void Rtlsdr::set_frequency(uint32_t frequency) { if (rtlsdr_set_center_freq(dev, frequency) < 0) { throw RPFexception( diff --git a/src/device.h b/src/device.h index ec516cf..f80ee2e 100644 --- a/src/device.h +++ b/src/device.h @@ -35,12 +35,14 @@ class Rtlsdr { // Reading parameters & data. std::vector gains() const; + uint32_t direct_sampling() const; uint32_t sample_rate() const; uint32_t frequency() const ; bool read(Buffer& buffer) const; // Parameter setting. void set_gain(int gain); + void set_direct_sampling(int direct_sampling); void set_frequency(uint32_t frequency); void set_freq_correction(int ppm_error); void set_sample_rate(uint32_t sample_rate); diff --git a/src/params.cxx b/src/params.cxx index fcf521f..ed4cee1 100644 --- a/src/params.cxx +++ b/src/params.cxx @@ -113,6 +113,8 @@ Params::Params(int argc, char** argv) { cmd.add( arg_bufferlen ); TCLAP::ValueArg arg_rate("r","rate","Sample rate of the receiver.",false,sample_rate,"samples/s"); cmd.add( arg_rate ); + TCLAP::ValueArg arg_direct_sampling("D","direct-sampling","Direct sampling of the receiver.",false,direct_sampling,"0=NO,1=I,2=Q"); + cmd.add( arg_direct_sampling ); TCLAP::SwitchArg arg_quiet("q","quiet","Limit verbosity.", talkless); cmd.add( arg_quiet ); TCLAP::ValueArg arg_ppm("p","ppm","Set custom ppm error in RTL-SDR device.", false, ppm_error, "ppm"); @@ -156,6 +158,7 @@ Params::Params(int argc, char** argv) { linear = arg_linear.getValue(); gain = arg_gain.getValue(); sample_rate = arg_rate.getValue(); + direct_sampling = arg_direct_sampling.getValue(); buffers = arg_buffers.getValue(); buf_length = arg_bufferlen.getValue(); endless = arg_continue.getValue(); diff --git a/src/params.h b/src/params.h index 43d7c68..2c72ac8 100644 --- a/src/params.h +++ b/src/params.h @@ -60,6 +60,7 @@ class Params { bool talkless = false; // default: verbose bool matrixMode = false; // default: original rtl-power-fftw output format int finalfreq = 0; + int direct_sampling = 0; std::string matrix_file; // just name without extension std::string bin_file; // name with .bin extension std::string freq_file; // name with .frq extension diff --git a/src/rtl_power_fftw.cxx b/src/rtl_power_fftw.cxx index 17726e0..c0d5a32 100644 --- a/src/rtl_power_fftw.cxx +++ b/src/rtl_power_fftw.cxx @@ -81,6 +81,11 @@ int main(int argc, char **argv) << " (" << 0.1*gain << " dB)" << std::endl; rtldev.set_gain(gain); + // Set direct sampling + rtldev.set_direct_sampling(params.direct_sampling); + int direct_sampling = rtldev.direct_sampling(); + std::cerr << "Actual direct sampling: " << direct_sampling << std::endl; + // Temporarily set the frequency to params.cfreq, just so that the device does not // complain upon setting the sample rate. If this fails, it's not a big deal: // the sample rate will be read out just fine, but librtlsdr _might_ print an From b7244c7b519304096acc57bed2caf780627e2fdf Mon Sep 17 00:00:00 2001 From: blackwiz4rd Date: Fri, 14 May 2021 12:24:16 +0200 Subject: [PATCH 2/2] direct sampling in readme --- doc/rtl_power_fftw.1.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/rtl_power_fftw.1.md b/doc/rtl_power_fftw.1.md index d7364fb..77a4fdf 100644 --- a/doc/rtl_power_fftw.1.md +++ b/doc/rtl_power_fftw.1.md @@ -65,6 +65,9 @@ The program can be stopped gracefully by sending the SIGINT signal to it (pressi `-r `, `--rate ` : Sample rate of the receiver in Hz. +`-D `, `--diret-sampling <0,1,2>` +: Set direct sampling (0=NO,1=I,2=Q). + `-s `, `--buffer-size ` : Size of the read buffers (leave it as it is unless you know what you are doing).