mirror of
https://github.com/brmlab/kalibrate-rtl.git
synced 2025-08-01 21:53:37 +02:00
use rtl-sdr instead of USRP
Signed-off-by: Steve Markgraf <steve@steve-m.de>
This commit is contained in:
parent
c58471bb42
commit
c3366bda71
8 changed files with 120 additions and 102 deletions
2
AUTHORS
2
AUTHORS
|
@ -1,3 +1,3 @@
|
||||||
Joshua Lackey <jl@thre.at>
|
Joshua Lackey <jl@thre.at>
|
||||||
Alexander Chemeris <alexander.chemeris@gmail.com>
|
Alexander Chemeris <alexander.chemeris@gmail.com>
|
||||||
|
Steve Markgraf <steve@steve-m.de>
|
||||||
|
|
3
README
3
README
|
@ -5,3 +5,6 @@ offset.
|
||||||
See http://thre.at/kalibrate
|
See http://thre.at/kalibrate
|
||||||
|
|
||||||
Copyright (c) 2010, Joshua Lackey (jl@thre.at)
|
Copyright (c) 2010, Joshua Lackey (jl@thre.at)
|
||||||
|
|
||||||
|
modified for use with rtl-sdr devices,
|
||||||
|
Copyright (c) 2012, Steve Markgraf (steve@steve-m.de)
|
||||||
|
|
|
@ -26,9 +26,9 @@ PKG_CHECK_MODULES(FFTW3, fftw3 >= 3.0)
|
||||||
AC_SUBST(FFTW3_LIBS)
|
AC_SUBST(FFTW3_LIBS)
|
||||||
AC_SUBST(FFTW3_CFLAGS)
|
AC_SUBST(FFTW3_CFLAGS)
|
||||||
|
|
||||||
PKG_CHECK_MODULES(USRP, usrp >= 3.3)
|
PKG_CHECK_MODULES(LIBRTLSDR, librtlsdr)
|
||||||
AC_SUBST(USRP_LIBS)
|
AC_SUBST(LIBRTLSDR_LIBS)
|
||||||
AC_SUBST(USRP_CFLAGS)
|
AC_SUBST(LIBRTLSDR_CFLAGS)
|
||||||
|
|
||||||
# OSX doesn't support System V shared memory
|
# OSX doesn't support System V shared memory
|
||||||
AC_CANONICAL_HOST
|
AC_CANONICAL_HOST
|
||||||
|
|
|
@ -19,5 +19,5 @@ kal_SOURCES = \
|
||||||
util.h\
|
util.h\
|
||||||
version.h
|
version.h
|
||||||
|
|
||||||
kal_CXXFLAGS = $(FFTW3_CFLAGS) $(USRP_CFLAGS)
|
kal_CXXFLAGS = $(FFTW3_CFLAGS) $(LIBRTLSDR_CFLAGS)
|
||||||
kal_LDADD = $(FFTW3_LIBS) $(USRP_LIBS)
|
kal_LDADD = $(FFTW3_LIBS) $(LIBRTLSDR_LIBS)
|
||||||
|
|
51
src/kal.cc
51
src/kal.cc
|
@ -67,7 +67,8 @@ int g_debug = 0;
|
||||||
|
|
||||||
void usage(char *prog) {
|
void usage(char *prog) {
|
||||||
|
|
||||||
printf("kalibrate v%s, Copyright (c) 2010, Joshua Lackey\n", kal_version_string);
|
printf("kalibrate v%s-rtl, Copyright (c) 2010, Joshua Lackey\n", kal_version_string);
|
||||||
|
printf("modified for use with rtl-sdr devices, Copyright (c) 2012, Steve Markgraf");
|
||||||
printf("\nUsage:\n");
|
printf("\nUsage:\n");
|
||||||
printf("\tGSM Base Station Scan:\n");
|
printf("\tGSM Base Station Scan:\n");
|
||||||
printf("\t\t%s <-s band indicator> [options]\n", basename(prog));
|
printf("\t\t%s <-s band indicator> [options]\n", basename(prog));
|
||||||
|
@ -80,10 +81,9 @@ void usage(char *prog) {
|
||||||
printf("\t-f\tfrequency of nearby GSM base station\n");
|
printf("\t-f\tfrequency of nearby GSM base station\n");
|
||||||
printf("\t-c\tchannel of nearby GSM base station\n");
|
printf("\t-c\tchannel of nearby GSM base station\n");
|
||||||
printf("\t-b\tband indicator (GSM850, GSM900, EGSM, DCS, PCS)\n");
|
printf("\t-b\tband indicator (GSM850, GSM900, EGSM, DCS, PCS)\n");
|
||||||
printf("\t-R\tside A (0) or B (1), defaults to B\n");
|
printf("\t-g\tgain in dB\n");
|
||||||
printf("\t-A\tantenna TX/RX (0) or RX2 (1), defaults to RX2\n");
|
printf("\t-d\trtl-sdr device index\n");
|
||||||
printf("\t-g\tgain as %% of range, defaults to 45%%\n");
|
printf("\t-e\tinitial frequency error in ppm\n");
|
||||||
printf("\t-F\tFPGA master clock frequency, defaults to 52MHz\n");
|
|
||||||
printf("\t-v\tverbose\n");
|
printf("\t-v\tverbose\n");
|
||||||
printf("\t-D\tenable debug messages\n");
|
printf("\t-D\tenable debug messages\n");
|
||||||
printf("\t-h\thelp\n");
|
printf("\t-h\thelp\n");
|
||||||
|
@ -95,13 +95,14 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
char *endptr;
|
char *endptr;
|
||||||
int c, antenna = 1, bi = BI_NOT_DEFINED, chan = -1, bts_scan = 0;
|
int c, antenna = 1, bi = BI_NOT_DEFINED, chan = -1, bts_scan = 0;
|
||||||
unsigned int subdev = 1, decimation = 192;
|
int ppm_error = 0;
|
||||||
|
unsigned int subdev = 0, decimation = 192;
|
||||||
long int fpga_master_clock_freq = 52000000;
|
long int fpga_master_clock_freq = 52000000;
|
||||||
float gain = 0.45;
|
float gain = 0;
|
||||||
double freq = -1.0, fd;
|
double freq = -1.0, fd;
|
||||||
usrp_source *u;
|
usrp_source *u;
|
||||||
|
|
||||||
while((c = getopt(argc, argv, "f:c:s:b:R:A:g:F:vDh?")) != EOF) {
|
while((c = getopt(argc, argv, "f:c:s:b:R:A:g:e:d:vDh?")) != EOF) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'f':
|
case 'f':
|
||||||
freq = strtod(optarg, 0);
|
freq = strtod(optarg, 0);
|
||||||
|
@ -163,11 +164,7 @@ int main(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
gain = strtod(optarg, 0);
|
gain = strtof(optarg, 0) * 10;
|
||||||
if((gain > 1.0) && (gain <= 100.0))
|
|
||||||
gain /= 100.0;
|
|
||||||
if((gain < 0.0) || (1.0 < gain))
|
|
||||||
usage(argv[0]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'F':
|
case 'F':
|
||||||
|
@ -181,6 +178,14 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
ppm_error = strtol(optarg, 0, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
subdev = strtol(optarg, 0, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
g_verbosity++;
|
g_verbosity++;
|
||||||
break;
|
break;
|
||||||
|
@ -221,6 +226,7 @@ int main(int argc, char **argv) {
|
||||||
chan = freq_to_arfcn(freq, &bi);
|
chan = freq_to_arfcn(freq, &bi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
// sanity check clock
|
// sanity check clock
|
||||||
if(fpga_master_clock_freq < 48000000) {
|
if(fpga_master_clock_freq < 48000000) {
|
||||||
fprintf(stderr, "error: FPGA master clock too slow: %li\n", fpga_master_clock_freq);
|
fprintf(stderr, "error: FPGA master clock too slow: %li\n", fpga_master_clock_freq);
|
||||||
|
@ -230,7 +236,7 @@ int main(int argc, char **argv) {
|
||||||
// calculate decimation -- get as close to GSM rate as we can
|
// calculate decimation -- get as close to GSM rate as we can
|
||||||
fd = (double)fpga_master_clock_freq / GSM_RATE;
|
fd = (double)fpga_master_clock_freq / GSM_RATE;
|
||||||
decimation = (unsigned int)fd;
|
decimation = (unsigned int)fd;
|
||||||
|
#endif
|
||||||
if(g_debug) {
|
if(g_debug) {
|
||||||
#ifdef D_HOST_OSX
|
#ifdef D_HOST_OSX
|
||||||
printf("debug: Mac OS X version\n");
|
printf("debug: Mac OS X version\n");
|
||||||
|
@ -251,10 +257,19 @@ int main(int argc, char **argv) {
|
||||||
fprintf(stderr, "error: usrp_source::open\n");
|
fprintf(stderr, "error: usrp_source::open\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
u->set_antenna(antenna);
|
// u->set_antenna(antenna);
|
||||||
if(!u->set_gain(gain)) {
|
if (gain != 0) {
|
||||||
fprintf(stderr, "error: usrp_source::set_gain\n");
|
if(!u->set_gain(gain)) {
|
||||||
return -1;
|
fprintf(stderr, "error: usrp_source::set_gain\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ppm_error != 0) {
|
||||||
|
if(u->set_freq_correction(ppm_error) < 0) {
|
||||||
|
fprintf(stderr, "error: usrp_source::set_freq_correction\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bts_scan) {
|
if(!bts_scan) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ int offset_detect(usrp_source *u) {
|
||||||
unsigned int s_len, b_len, consumed, count;
|
unsigned int s_len, b_len, consumed, count;
|
||||||
float offset = 0.0, min = 0.0, max = 0.0, avg_offset = 0.0,
|
float offset = 0.0, min = 0.0, max = 0.0, avg_offset = 0.0,
|
||||||
stddev = 0.0, sps, offsets[AVG_COUNT];
|
stddev = 0.0, sps, offsets[AVG_COUNT];
|
||||||
|
double total_ppm;
|
||||||
complex *cbuf;
|
complex *cbuf;
|
||||||
fcch_detector *l;
|
fcch_detector *l;
|
||||||
circular_buffer *cb;
|
circular_buffer *cb;
|
||||||
|
@ -118,5 +119,8 @@ int offset_detect(usrp_source *u) {
|
||||||
printf("overruns: %u\n", overruns);
|
printf("overruns: %u\n", overruns);
|
||||||
printf("not found: %u\n", notfound);
|
printf("not found: %u\n", notfound);
|
||||||
|
|
||||||
|
total_ppm = u->m_freq_corr - (avg_offset / u->m_center_freq) * 1000000;
|
||||||
|
|
||||||
|
printf("average absolute error: %.3f ppm\n", total_ppm);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
|
||||||
#include <usrp/usrp_standard.h>
|
|
||||||
#include <usrp/usrp_subdev_spec.h>
|
|
||||||
#include <usrp/usrp_dbid.h>
|
|
||||||
|
|
||||||
#include "usrp_source.h"
|
#include "usrp_source.h"
|
||||||
|
|
||||||
extern int g_verbosity;
|
extern int g_verbosity;
|
||||||
|
@ -49,8 +45,6 @@ usrp_source::usrp_source(float sample_rate, long int fpga_master_clock_freq) {
|
||||||
m_desired_sample_rate = sample_rate;
|
m_desired_sample_rate = sample_rate;
|
||||||
m_sample_rate = 0.0;
|
m_sample_rate = 0.0;
|
||||||
m_decimation = 0;
|
m_decimation = 0;
|
||||||
m_u_rx.reset();
|
|
||||||
m_db_rx.reset();
|
|
||||||
m_cb = new circular_buffer(CB_LEN, sizeof(complex), 0);
|
m_cb = new circular_buffer(CB_LEN, sizeof(complex), 0);
|
||||||
|
|
||||||
pthread_mutex_init(&m_u_mutex, 0);
|
pthread_mutex_init(&m_u_mutex, 0);
|
||||||
|
@ -61,8 +55,6 @@ usrp_source::usrp_source(unsigned int decimation, long int fpga_master_clock_fre
|
||||||
|
|
||||||
m_fpga_master_clock_freq = fpga_master_clock_freq;
|
m_fpga_master_clock_freq = fpga_master_clock_freq;
|
||||||
m_sample_rate = 0.0;
|
m_sample_rate = 0.0;
|
||||||
m_u_rx.reset();
|
|
||||||
m_db_rx.reset();
|
|
||||||
m_cb = new circular_buffer(CB_LEN, sizeof(complex), 0);
|
m_cb = new circular_buffer(CB_LEN, sizeof(complex), 0);
|
||||||
|
|
||||||
pthread_mutex_init(&m_u_mutex, 0);
|
pthread_mutex_init(&m_u_mutex, 0);
|
||||||
|
@ -79,6 +71,7 @@ usrp_source::~usrp_source() {
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
delete m_cb;
|
delete m_cb;
|
||||||
|
rtlsdr_close(dev);
|
||||||
pthread_mutex_destroy(&m_u_mutex);
|
pthread_mutex_destroy(&m_u_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +79,6 @@ usrp_source::~usrp_source() {
|
||||||
void usrp_source::stop() {
|
void usrp_source::stop() {
|
||||||
|
|
||||||
pthread_mutex_lock(&m_u_mutex);
|
pthread_mutex_lock(&m_u_mutex);
|
||||||
if(m_db_rx)
|
|
||||||
m_db_rx->set_enable(0);
|
|
||||||
if(m_u_rx)
|
|
||||||
m_u_rx->stop();
|
|
||||||
pthread_mutex_unlock(&m_u_mutex);
|
pthread_mutex_unlock(&m_u_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +86,6 @@ void usrp_source::stop() {
|
||||||
void usrp_source::start() {
|
void usrp_source::start() {
|
||||||
|
|
||||||
pthread_mutex_lock(&m_u_mutex);
|
pthread_mutex_lock(&m_u_mutex);
|
||||||
if(m_db_rx)
|
|
||||||
m_db_rx->set_enable(1);
|
|
||||||
if(m_u_rx)
|
|
||||||
m_u_rx->start();
|
|
||||||
pthread_mutex_unlock(&m_u_mutex);
|
pthread_mutex_unlock(&m_u_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +94,7 @@ void usrp_source::calculate_decimation() {
|
||||||
|
|
||||||
float decimation_f;
|
float decimation_f;
|
||||||
|
|
||||||
decimation_f = (float)m_u_rx->fpga_master_clock_freq() / m_desired_sample_rate;
|
// decimation_f = (float)m_u_rx->fpga_master_clock_freq() / m_desired_sample_rate;
|
||||||
m_decimation = (unsigned int)round(decimation_f) & ~1;
|
m_decimation = (unsigned int)round(decimation_f) & ~1;
|
||||||
|
|
||||||
if(m_decimation < 4)
|
if(m_decimation < 4)
|
||||||
|
@ -128,31 +113,42 @@ float usrp_source::sample_rate() {
|
||||||
|
|
||||||
int usrp_source::tune(double freq) {
|
int usrp_source::tune(double freq) {
|
||||||
|
|
||||||
int r;
|
int r = 0;
|
||||||
usrp_tune_result tr;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&m_u_mutex);
|
pthread_mutex_lock(&m_u_mutex);
|
||||||
r = m_u_rx->tune(0, m_db_rx, freq, &tr);
|
if (freq != m_center_freq) {
|
||||||
|
r = rtlsdr_set_center_freq(dev, (uint32_t)freq);
|
||||||
|
// fprintf(stderr, "Tuned to %i Hz.\n", (uint32_t)freq);
|
||||||
|
m_center_freq = freq;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&m_u_mutex);
|
pthread_mutex_unlock(&m_u_mutex);
|
||||||
|
|
||||||
return r;
|
return (r < 0) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int usrp_source::set_freq_correction(int ppm) {
|
||||||
|
m_freq_corr = ppm;
|
||||||
|
return rtlsdr_set_freq_correction(dev, ppm);
|
||||||
|
}
|
||||||
|
|
||||||
bool usrp_source::set_antenna(int antenna) {
|
bool usrp_source::set_antenna(int antenna) {
|
||||||
|
|
||||||
return m_db_rx->select_rx_antenna(antenna);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool usrp_source::set_gain(float gain) {
|
bool usrp_source::set_gain(float gain) {
|
||||||
|
int r, g = gain * 10;
|
||||||
|
|
||||||
float min = m_db_rx->gain_min(), max = m_db_rx->gain_max();
|
/* Enable manual gain */
|
||||||
|
r = rtlsdr_set_tuner_gain_mode(dev, 1);
|
||||||
|
if (r < 0)
|
||||||
|
fprintf(stderr, "WARNING: Failed to enable manual gain.\n");
|
||||||
|
|
||||||
if((gain < 0.0) || (1.0 < gain))
|
fprintf(stderr, "Setting gain: %.1f dB\n", gain/10);
|
||||||
return false;
|
r = rtlsdr_set_tuner_gain(dev, g);
|
||||||
|
|
||||||
return m_db_rx->set_gain(min + gain * (max - min));
|
return (r < 0) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,75 +156,73 @@ bool usrp_source::set_gain(float gain) {
|
||||||
* open() should be called before multiple threads access usrp_source.
|
* open() should be called before multiple threads access usrp_source.
|
||||||
*/
|
*/
|
||||||
int usrp_source::open(unsigned int subdev) {
|
int usrp_source::open(unsigned int subdev) {
|
||||||
|
int i, r, device_count, count;
|
||||||
|
uint32_t dev_index = subdev;
|
||||||
|
uint32_t samp_rate = 270833;
|
||||||
|
|
||||||
int do_set_decim = 0;
|
m_sample_rate = 270833.002142;
|
||||||
usrp_subdev_spec ss(subdev, 0);
|
|
||||||
|
|
||||||
if(!m_u_rx) {
|
device_count = rtlsdr_get_device_count();
|
||||||
if(!m_decimation) {
|
if (!device_count) {
|
||||||
do_set_decim = 1;
|
fprintf(stderr, "No supported devices found.\n");
|
||||||
m_decimation = 4;
|
exit(1);
|
||||||
}
|
|
||||||
if(!(m_u_rx = usrp_standard_rx::make(0, m_decimation,
|
|
||||||
NCHAN, INITIAL_MUX, usrp_standard_rx::FPGA_MODE_NORMAL,
|
|
||||||
FUSB_BLOCK_SIZE, FUSB_NBLOCKS, FPGA_FILENAME()))) {
|
|
||||||
fprintf(stderr, "error: usrp_standard_rx::make: "
|
|
||||||
"failed!\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
m_u_rx->set_fpga_master_clock_freq(m_fpga_master_clock_freq);
|
|
||||||
m_u_rx->stop();
|
|
||||||
|
|
||||||
if(do_set_decim) {
|
|
||||||
calculate_decimation();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_u_rx->set_decim_rate(m_decimation);
|
|
||||||
m_sample_rate = (double)m_u_rx->fpga_master_clock_freq() / m_decimation;
|
|
||||||
|
|
||||||
if(g_verbosity > 1) {
|
|
||||||
fprintf(stderr, "FPGA clock : %ld\n", m_u_rx->fpga_master_clock_freq());
|
|
||||||
fprintf(stderr, "Decimation : %u\n", m_decimation);
|
|
||||||
fprintf(stderr, "Sample rate: %f\n", m_sample_rate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!m_u_rx->is_valid(ss)) {
|
|
||||||
fprintf(stderr, "error: invalid daughterboard\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!(m_db_rx = m_u_rx->selected_subdev(ss))) {
|
|
||||||
fprintf(stderr, "error: no daughterboard\n");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_u_rx->set_mux(m_u_rx->determine_rx_mux_value(ss));
|
fprintf(stderr, "Found %d device(s):\n", device_count);
|
||||||
|
for (i = 0; i < device_count; i++)
|
||||||
|
fprintf(stderr, " %d: %s\n", i, rtlsdr_get_device_name(i));
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
set_gain(0.45);
|
fprintf(stderr, "Using device %d: %s\n",
|
||||||
m_db_rx->select_rx_antenna(1); // this is a nop for most db
|
dev_index,
|
||||||
|
rtlsdr_get_device_name(dev_index));
|
||||||
|
|
||||||
|
r = rtlsdr_open(&dev, dev_index);
|
||||||
|
if (r < 0) {
|
||||||
|
fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the sample rate */
|
||||||
|
r = rtlsdr_set_sample_rate(dev, samp_rate);
|
||||||
|
if (r < 0)
|
||||||
|
fprintf(stderr, "WARNING: Failed to set sample rate.\n");
|
||||||
|
|
||||||
|
/* Reset endpoint before we start reading from it (mandatory) */
|
||||||
|
r = rtlsdr_reset_buffer(dev);
|
||||||
|
if (r < 0)
|
||||||
|
fprintf(stderr, "WARNING: Failed to reset buffers.\n");
|
||||||
|
|
||||||
|
// r = rtlsdr_set_offset_tuning(dev, 1);
|
||||||
|
// if (r < 0)
|
||||||
|
// fprintf(stderr, "WARNING: Failed to enable offset tuning\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define USB_PACKET_SIZE (2 * 16384)
|
||||||
|
#define FLUSH_SIZE 512
|
||||||
|
|
||||||
#define USB_PACKET_SIZE 512
|
|
||||||
|
|
||||||
int usrp_source::fill(unsigned int num_samples, unsigned int *overrun_i) {
|
int usrp_source::fill(unsigned int num_samples, unsigned int *overrun_i) {
|
||||||
|
|
||||||
bool overrun;
|
bool overrun;
|
||||||
unsigned char ubuf[USB_PACKET_SIZE];
|
unsigned char ubuf[USB_PACKET_SIZE];
|
||||||
short *s = (short *)ubuf;
|
|
||||||
unsigned int i, j, space, overruns = 0;
|
unsigned int i, j, space, overruns = 0;
|
||||||
complex *c;
|
complex *c;
|
||||||
|
int n_read;
|
||||||
|
|
||||||
while((m_cb->data_available() < num_samples) && (m_cb->space_available() > 0)) {
|
while((m_cb->data_available() < num_samples) && (m_cb->space_available() > 0)) {
|
||||||
|
|
||||||
// read one usb packet from the usrp
|
// read one usb packet from the usrp
|
||||||
pthread_mutex_lock(&m_u_mutex);
|
pthread_mutex_lock(&m_u_mutex);
|
||||||
if(m_u_rx->read(ubuf, sizeof(ubuf), &overrun) != sizeof(ubuf)) {
|
|
||||||
|
if (rtlsdr_read_sync(dev, ubuf, sizeof(ubuf), &n_read) < 0) {
|
||||||
pthread_mutex_unlock(&m_u_mutex);
|
pthread_mutex_unlock(&m_u_mutex);
|
||||||
fprintf(stderr, "error: usrp_standard_rx::read\n");
|
fprintf(stderr, "error: usrp_standard_rx::read\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&m_u_mutex);
|
pthread_mutex_unlock(&m_u_mutex);
|
||||||
if(overrun)
|
if(overrun)
|
||||||
overruns++;
|
overruns++;
|
||||||
|
@ -237,12 +231,11 @@ int usrp_source::fill(unsigned int num_samples, unsigned int *overrun_i) {
|
||||||
c = (complex *)m_cb->poke(&space);
|
c = (complex *)m_cb->poke(&space);
|
||||||
|
|
||||||
// set space to number of complex items to copy
|
// set space to number of complex items to copy
|
||||||
if(space > (USB_PACKET_SIZE >> 2))
|
space = n_read / 2;
|
||||||
space = USB_PACKET_SIZE >> 2;
|
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
for(i = 0, j = 0; i < space; i += 1, j += 2)
|
for(i = 0, j = 0; i < space; i += 1, j += 2)
|
||||||
c[i] = complex(s[j], s[j + 1]);
|
c[i] = complex((ubuf[j] - 127) * 256, (ubuf[j + 1] - 127) * 256);
|
||||||
|
|
||||||
// update cb
|
// update cb
|
||||||
m_cb->wrote(i);
|
m_cb->wrote(i);
|
||||||
|
@ -290,7 +283,7 @@ circular_buffer *usrp_source::get_buffer() {
|
||||||
int usrp_source::flush(unsigned int flush_count) {
|
int usrp_source::flush(unsigned int flush_count) {
|
||||||
|
|
||||||
m_cb->flush();
|
m_cb->flush();
|
||||||
fill(flush_count * USB_PACKET_SIZE, 0);
|
fill(flush_count * FLUSH_SIZE, 0);
|
||||||
m_cb->flush();
|
m_cb->flush();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <usrp/usrp_standard.h>
|
#include <rtl-sdr.h>
|
||||||
|
|
||||||
#include "usrp_complex.h"
|
#include "usrp_complex.h"
|
||||||
#include "circular_buffer.h"
|
#include "circular_buffer.h"
|
||||||
|
@ -41,6 +41,7 @@ public:
|
||||||
int read(complex *buf, unsigned int num_samples, unsigned int *samples_read);
|
int read(complex *buf, unsigned int num_samples, unsigned int *samples_read);
|
||||||
int fill(unsigned int num_samples, unsigned int *overrun);
|
int fill(unsigned int num_samples, unsigned int *overrun);
|
||||||
int tune(double freq);
|
int tune(double freq);
|
||||||
|
int set_freq_correction(int ppm);
|
||||||
bool set_antenna(int antenna);
|
bool set_antenna(int antenna);
|
||||||
bool set_gain(float gain);
|
bool set_gain(float gain);
|
||||||
void start();
|
void start();
|
||||||
|
@ -53,11 +54,13 @@ public:
|
||||||
static const unsigned int side_A = 0;
|
static const unsigned int side_A = 0;
|
||||||
static const unsigned int side_B = 1;
|
static const unsigned int side_B = 1;
|
||||||
|
|
||||||
|
double m_center_freq;
|
||||||
|
int m_freq_corr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void calculate_decimation();
|
void calculate_decimation();
|
||||||
|
|
||||||
usrp_standard_rx_sptr m_u_rx;
|
rtlsdr_dev_t *dev;
|
||||||
db_base_sptr m_db_rx;
|
|
||||||
|
|
||||||
float m_sample_rate;
|
float m_sample_rate;
|
||||||
float m_desired_sample_rate;
|
float m_desired_sample_rate;
|
||||||
|
@ -74,7 +77,7 @@ private:
|
||||||
pthread_mutex_t m_u_mutex;
|
pthread_mutex_t m_u_mutex;
|
||||||
|
|
||||||
static const unsigned int FLUSH_COUNT = 10;
|
static const unsigned int FLUSH_COUNT = 10;
|
||||||
static const unsigned int CB_LEN = (1 << 20);
|
static const unsigned int CB_LEN = (16 * 16384);
|
||||||
static const int NCHAN = 1;
|
static const int NCHAN = 1;
|
||||||
static const int INITIAL_MUX = -1;
|
static const int INITIAL_MUX = -1;
|
||||||
static const int FUSB_BLOCK_SIZE = 1024;
|
static const int FUSB_BLOCK_SIZE = 1024;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue