Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/rtl_power_fftw.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ The program can be stopped gracefully by sending the SIGINT signal to it (pressi
`-r <Hz>`, `--rate <Hz>`
: Sample rate of the receiver in Hz.

`-D <int>`, `--diret-sampling <0,1,2>`
: Set direct sampling (0=NO,1=I,2=Q).

`-s <bytes>`, `--buffer-size <bytes>`
: Size of the read buffers (leave it as it is unless you know what you are doing).

Expand Down
18 changes: 18 additions & 0 deletions src/device.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ std::vector<int> 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) {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class Rtlsdr {

// Reading parameters & data.
std::vector<int> 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);
Expand Down
3 changes: 3 additions & 0 deletions src/params.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Params::Params(int argc, char** argv) {
cmd.add( arg_bufferlen );
TCLAP::ValueArg<int> arg_rate("r","rate","Sample rate of the receiver.",false,sample_rate,"samples/s");
cmd.add( arg_rate );
TCLAP::ValueArg<int> 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<int> arg_ppm("p","ppm","Set custom ppm error in RTL-SDR device.", false, ppm_error, "ppm");
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/rtl_power_fftw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down