From 272ebeb0aef054731ebb9800f7a44157b736b7ad Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 8 Jan 2017 12:10:56 +0100 Subject: SDR: Minor fixes --- src/common/sdr.c | 13 ++++++------- src/common/uhd.c | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src/common') diff --git a/src/common/sdr.c b/src/common/sdr.c index 93e591d..60ac610 100644 --- a/src/common/sdr.c +++ b/src/common/sdr.c @@ -147,7 +147,7 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq /* range of TX */ range = tx_high_frequency - tx_low_frequency; if (range) - PDEBUG(DSDR, DEBUG_INFO, "Range between all TX Frequencies: %.6f MHz\n", range / 1e6); + PDEBUG(DSDR, DEBUG_DEBUG, "Range between all TX Frequencies: %.6f MHz\n", range / 1e6); if (range * 2 > sdr->samplerate) { // why that? actually i don't know. i just want to be safe.... PDEBUG(DSDR, DEBUG_NOTICE, "The sample rate must be at least twice the range between frequencies.\n"); @@ -156,29 +156,28 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq goto error; } tx_center_frequency = (tx_high_frequency + tx_low_frequency) / 2.0; - PDEBUG(DSDR, DEBUG_INFO, "Using TX center frequency: %.6f MHz\n", tx_center_frequency / 1e6); /* range of RX */ range = rx_high_frequency - rx_low_frequency; if (range) - PDEBUG(DSDR, DEBUG_INFO, "Range between all RX Frequencies: %.6f MHz\n", range / 1e6); + PDEBUG(DSDR, DEBUG_DEBUG, "Range between all RX Frequencies: %.6f MHz\n", range / 1e6); if (range * 2.0 > sdr->samplerate) { // why that? actually i don't know. i just want to be safe.... PDEBUG(DSDR, DEBUG_NOTICE, "The sample rate must be at least twice the range between frequencies. Please increment samplerate!\n"); goto error; } rx_center_frequency = (rx_high_frequency + rx_low_frequency) / 2.0; - PDEBUG(DSDR, DEBUG_INFO, "Using RX center frequency: %.6f MHz\n", rx_center_frequency / 1e6); + PDEBUG(DSDR, DEBUG_INFO, "Using center frequency: TX %.6f MHz, RX %.6f\n", tx_center_frequency / 1e6, rx_center_frequency / 1e6); /* set offsets to center frequency */ for (c = 0; c < channels; c++) { double rx_offset; sdr->chan[c].offset = sdr->chan[c].tx_frequency - tx_center_frequency; rx_offset = sdr->chan[c].rx_frequency - rx_center_frequency; sdr->chan[c].rx_rot = 2 * M_PI * -rx_offset / sdr->samplerate; - PDEBUG(DSDR, DEBUG_INFO, "Frequency #%d: TX offset: %.6f MHz, RX offset: %.6f MHz\n", c, sdr->chan[c].offset / 1e6, rx_offset / 1e6); + PDEBUG(DSDR, DEBUG_DEBUG, "Frequency #%d: TX offset: %.6f MHz, RX offset: %.6f MHz\n", c, sdr->chan[c].offset / 1e6, rx_offset / 1e6); } if (sdr->paging_channel) { sdr->chan[sdr->paging_channel].offset = sdr->chan[sdr->paging_channel].tx_frequency - tx_center_frequency; - PDEBUG(DSDR, DEBUG_INFO, "Paging Frequency: TX offset: %.6f MHz\n", sdr->chan[sdr->paging_channel].offset / 1e6); + PDEBUG(DSDR, DEBUG_DEBUG, "Paging Frequency: TX offset: %.6f MHz\n", sdr->chan[sdr->paging_channel].offset / 1e6); } PDEBUG(DSDR, DEBUG_INFO, "Using gain: TX %.1f dB, RX %.1f dB\n", sdr_tx_gain, sdr_rx_gain); @@ -302,7 +301,7 @@ int sdr_read(void *inst, int16_t **samples, int num, int channels) filter_lowpass_process(&sdr->chan[c].rx_lp[1], Q, count, 1); last_phase = sdr->chan[c].rx_last_phase; for (s = 0; s < count; s++) { - phase = atan2(I[s], Q[s]); + phase = atan2(Q[s], I[s]); dev = (phase - last_phase) / 2 / M_PI; last_phase = phase; if (dev < -0.49) diff --git a/src/common/uhd.c b/src/common/uhd.c index a5a600a..cef9e00 100644 --- a/src/common/uhd.c +++ b/src/common/uhd.c @@ -43,6 +43,7 @@ static time_t rx_time_secs = 0; static double rx_time_fract_sec = 0.0; static time_t tx_time_secs = 0; static double tx_time_fract_sec = 0.0; +static int rx_gap = 0; /* if we missed samples, we fill our rx data with zeroes */ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain) { @@ -316,6 +317,16 @@ int uhd_receive(float *buff, int max) time_t last_secs = rx_time_secs; double last_fract_sec = rx_time_fract_sec; + /* fill gap this time */ + if (rx_gap) { + count = rx_gap; + if ((int)count > max) + count = max; + rx_gap -= count; + memset(buff, 0, count * sizeof(*buff) * 2); + return count; + } + if (max < (int)rx_samps_per_buff) { PDEBUG(DUHD, DEBUG_ERROR, "SDR rx buffer too small, please fix!\n"); return 0; @@ -343,9 +354,8 @@ int uhd_receive(float *buff, int max) PDEBUG(DUHD, DEBUG_ERROR, "Received rate (%.0f) does not match defined rate (%.0f), use diffrent sample rate that UHD device can handle!\n", (double)count / got, samplerate); return -EPERM; } - int gap = diff * (double)samplerate; - PDEBUG(DUHD, DEBUG_ERROR, "Detected a gap of %.6f secods (%d samples), \n", diff, gap); -#warning fill gap + rx_gap = diff * (double)samplerate + 0.5; + PDEBUG(DUHD, DEBUG_ERROR, "Lost rx frame(s): A gap of %.6f secods (%d samples), \n", diff, rx_gap); } check_rate = 0; } -- cgit v1.2.3