diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/main_common.c | 21 | ||||
-rw-r--r-- | src/common/sdr.c | 10 | ||||
-rw-r--r-- | src/common/sdr.h | 2 | ||||
-rw-r--r-- | src/common/soapy.c | 30 | ||||
-rw-r--r-- | src/common/soapy.h | 2 | ||||
-rw-r--r-- | src/common/uhd.c | 40 | ||||
-rw-r--r-- | src/common/uhd.h | 2 |
7 files changed, 91 insertions, 16 deletions
diff --git a/src/common/main_common.c b/src/common/main_common.c index 4d74685..ae52456 100644 --- a/src/common/main_common.c +++ b/src/common/main_common.c @@ -62,6 +62,7 @@ const char *write_rx_wave = NULL; const char *write_tx_wave = NULL; const char *read_rx_wave = NULL; static const char *sdr_args = ""; +static double sdr_bandwidth = 0.0; static int sdr_uhd = 0; static int sdr_soapy = 0; double sdr_rx_gain = 0, sdr_tx_gain = 0; @@ -139,6 +140,8 @@ void print_help_common(const char *arg0, const char *ext_usage) printf(" --sdr-args <args>\n"); printf(" Optional SDR device arguments, seperated by comma\n"); printf(" e.g. --sdr-args <key>=<value>[,<key>=<value>[,...]]\n"); + printf(" --sdr-bandwidth <bandwidth>\n"); + printf(" Give IF filter bandwidth to use. If not, sample rate is used.\n"); printf(" --sdr-rx-gain <gain>\n"); printf(" SDR device's RX gain in dB (default = %.1f)\n", sdr_rx_gain); printf(" --sdr-tx-gain <gain>\n"); @@ -174,10 +177,11 @@ void print_hotkeys_common(void) #define OPT_SDR_ARGS 1102 #define OPT_SDR_RX_GAIN 1103 #define OPT_SDR_TX_GAIN 1104 -#define OPT_WRITE_IQ_RX_WAVE 1105 -#define OPT_WRITE_IQ_TX_WAVE 1106 -#define OPT_READ_IQ_RX_WAVE 1107 -#define OPT_READ_IQ_TX_WAVE 1108 +#define OPT_SDR_BANDWIDTH 1105 +#define OPT_WRITE_IQ_RX_WAVE 1106 +#define OPT_WRITE_IQ_TX_WAVE 1107 +#define OPT_READ_IQ_RX_WAVE 1108 +#define OPT_READ_IQ_TX_WAVE 1109 static struct option long_options_common[] = { {"help", 0, 0, 'h'}, @@ -203,6 +207,7 @@ static struct option long_options_common[] = { {"sdr-uhd", 0, 0, OPT_SDR_UHD}, {"sdr-soapy", 0, 0, OPT_SDR_SOAPY}, {"sdr-args", 1, 0, OPT_SDR_ARGS}, + {"sdr-bandwidth", 1, 0, OPT_SDR_BANDWIDTH}, {"sdr-rx-gain", 1, 0, OPT_SDR_RX_GAIN}, {"sdr-tx-gain", 1, 0, OPT_SDR_TX_GAIN}, {"write-iq-rx-wave", 1, 0, OPT_WRITE_IQ_RX_WAVE}, @@ -364,6 +369,10 @@ void opt_switch_common(int c, char *arg0, int *skip_args) sdr_args = strdup(optarg); *skip_args += 2; break; + case OPT_SDR_BANDWIDTH: + sdr_bandwidth = atof(optarg); + *skip_args += 2; + break; case OPT_SDR_RX_GAIN: sdr_rx_gain = atof(optarg); *skip_args += 2; @@ -470,7 +479,9 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void), #endif #ifdef HAVE_SDR - rc = sdr_init(sdr_uhd, sdr_soapy, sdr_args, sdr_rx_gain, sdr_tx_gain, write_iq_rx_wave, write_iq_tx_wave, read_iq_rx_wave, read_iq_tx_wave); + if (sdr_bandwidth == 0.0) + sdr_bandwidth = samplerate; + rc = sdr_init(sdr_uhd, sdr_soapy, sdr_args, sdr_rx_gain, sdr_tx_gain, sdr_bandwidth, write_iq_rx_wave, write_iq_tx_wave, read_iq_rx_wave, read_iq_tx_wave); if (rc < 0) return; #endif diff --git a/src/common/sdr.c b/src/common/sdr.c index dfb1614..e18ef92 100644 --- a/src/common/sdr.c +++ b/src/common/sdr.c @@ -59,14 +59,16 @@ static int sdr_use_uhd, sdr_use_soapy; static const char *sdr_device_args; static double sdr_rx_gain, sdr_tx_gain; const char *sdr_write_iq_rx_wave, *sdr_write_iq_tx_wave, *sdr_read_iq_rx_wave, *sdr_read_iq_tx_wave; +static double sdr_bandwidth; -int sdr_init(int sdr_uhd, int sdr_soapy, const char *device_args, double rx_gain, double tx_gain, const char *write_iq_rx_wave, const char *write_iq_tx_wave, const char *read_iq_rx_wave, const char *read_iq_tx_wave) +int sdr_init(int sdr_uhd, int sdr_soapy, const char *device_args, double rx_gain, double tx_gain, double bandwidth, const char *write_iq_rx_wave, const char *write_iq_tx_wave, const char *read_iq_rx_wave, const char *read_iq_tx_wave) { sdr_use_uhd = sdr_uhd; sdr_use_soapy = sdr_soapy; sdr_device_args = strdup(device_args); sdr_rx_gain = rx_gain; sdr_tx_gain = tx_gain; + sdr_bandwidth = bandwidth; sdr_write_iq_rx_wave = write_iq_rx_wave; sdr_write_iq_tx_wave = write_iq_tx_wave; sdr_read_iq_rx_wave = read_iq_rx_wave; @@ -87,7 +89,7 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq display_spectrum_init(samplerate); bandwidth = 2.0 * (max_deviation + max_modulation); - PDEBUG(DSDR, DEBUG_INFO, "Using Bandwidth of 2 * (%.1f + %.1f) = %.1f\n", max_deviation / 1000, max_modulation / 1000, bandwidth / 1000); + PDEBUG(DSDR, DEBUG_INFO, "Require bandwidth of 2 * (%.1f + %.1f) = %.1f\n", max_deviation / 1000, max_modulation / 1000, bandwidth / 1000); if (channels < 1) { PDEBUG(DSDR, DEBUG_ERROR, "No channel given, please fix!\n"); @@ -216,7 +218,7 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq #ifdef HAVE_UHD if (sdr_use_uhd) { - rc = uhd_open(sdr_device_args, tx_center_frequency, rx_center_frequency, sdr->samplerate, sdr_rx_gain, sdr_tx_gain); + rc = uhd_open(sdr_device_args, tx_center_frequency, rx_center_frequency, sdr->samplerate, sdr_rx_gain, sdr_tx_gain, sdr_bandwidth); if (rc) goto error; } @@ -224,7 +226,7 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq #ifdef HAVE_SOAPY if (sdr_use_soapy) { - rc = soapy_open(sdr_device_args, tx_center_frequency, rx_center_frequency, sdr->samplerate, sdr_rx_gain, sdr_tx_gain); + rc = soapy_open(sdr_device_args, tx_center_frequency, rx_center_frequency, sdr->samplerate, sdr_rx_gain, sdr_tx_gain, sdr_bandwidth); if (rc) goto error; } diff --git a/src/common/sdr.h b/src/common/sdr.h index e1bbd65..40de056 100644 --- a/src/common/sdr.h +++ b/src/common/sdr.h @@ -1,5 +1,5 @@ -int sdr_init(int sdr_uhd, int sdr_soapy, const char *device_args, double rx_gain, double tx_gain, const char *write_iq_rx_wave, const char *write_iq_tx_wave, const char *read_iq_rx_wave, const char *read_iq_tx_wave); +int sdr_init(int sdr_uhd, int sdr_soapy, const char *device_args, double rx_gain, double tx_gain, double bandwidth, const char *write_iq_rx_wave, const char *write_iq_tx_wave, const char *read_iq_rx_wave, const char *read_iq_tx_wave); int sdr_start(void *inst); void *sdr_open(const char *audiodev, double *tx_frequency, double *rx_frequency, int channels, double paging_frequency, int samplerate, double bandwidth, double sample_deviation); void sdr_close(void *inst); diff --git a/src/common/soapy.c b/src/common/soapy.c index 76e213e..1f56456 100644 --- a/src/common/soapy.c +++ b/src/common/soapy.c @@ -35,9 +35,9 @@ static double samplerate; static long long rx_count = 0; static long long tx_count = 0; -int soapy_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain) +int soapy_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain, double bandwidth) { - double got_frequency, got_rate, got_gain; + double got_frequency, got_rate, got_gain, got_bandwidth; size_t channel = 0; char *arg_string = strdup(device_args), *key, *val; SoapySDRKwargs args; @@ -144,6 +144,32 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency return -EINVAL; } + /* set bandwidth */ + if (SoapySDRDevice_setBandwidth(sdr, SOAPY_SDR_TX, channel, bandwidth) != 0) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX bandwidth to %.0f Hz\n", bandwidth); + soapy_close(); + return -EIO; + } + if (SoapySDRDevice_setBandwidth(sdr, SOAPY_SDR_RX, channel, bandwidth) != 0) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX bandwidth to %.0f Hz\n", bandwidth); + soapy_close(); + return -EIO; + } + + /* see what bandwidth actually is */ + got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_TX, channel); + if (got_bandwidth != bandwidth) { + PDEBUG(DUHD, DEBUG_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth); + soapy_close(); + return -EINVAL; + } + got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_RX, channel); + if (got_bandwidth != bandwidth) { + PDEBUG(DUHD, DEBUG_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth); + soapy_close(); + return -EINVAL; + } + /* set up streamer */ if (SoapySDRDevice_setupStream(sdr, &txStream, SOAPY_SDR_TX, SOAPY_SDR_CF32, &channel, 1, NULL) != 0) { PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX streamer args\n"); diff --git a/src/common/soapy.h b/src/common/soapy.h index dcfadde..c51d34e 100644 --- a/src/common/soapy.h +++ b/src/common/soapy.h @@ -1,5 +1,5 @@ -int soapy_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain); +int soapy_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain, double bandwidth); int soapy_start(void); void soapy_close(void); int soapy_send(float *buff, int num); diff --git a/src/common/uhd.c b/src/common/uhd.c index 1423703..dcbc390 100644 --- a/src/common/uhd.c +++ b/src/common/uhd.c @@ -45,10 +45,10 @@ 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) +int uhd_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain, double bandwidth) { uhd_error error; - double got_frequency, got_rate, got_gain; + double got_frequency, got_rate, got_gain, got_bandwidth; size_t channel = 0; samplerate = rate; @@ -202,6 +202,42 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency, return -EINVAL; } + /* set bandwidth */ + if (uhd_usrp_set_tx_bandwidth(usrp, bandwidth, channel) != 0) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX bandwidth to %.0f Hz\n", bandwidth); + uhd_close(); + return -EIO; + } + if (uhd_usrp_set_rx_bandwidth(usrp, bandwidth, channel) != 0) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX bandwidth to %.0f Hz\n", bandwidth); + uhd_close(); + return -EIO; + } + + /* see what bandwidth actually is */ + error = uhd_usrp_get_tx_bandwidth(usrp, channel, &got_bandwidth); + if (error) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX bandwidth\n"); + uhd_close(); + return -EIO; + } + if (got_bandwidth != bandwidth) { + PDEBUG(DUHD, DEBUG_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth); + uhd_close(); + return -EINVAL; + } + error = uhd_usrp_get_rx_bandwidth(usrp, channel, &got_bandwidth); + if (error) { + PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX bandwidth\n"); + uhd_close(); + return -EIO; + } + if (got_bandwidth != bandwidth) { + PDEBUG(DUHD, DEBUG_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth); + uhd_close(); + return -EINVAL; + } + /* set up streamer */ memset(&stream_args, 0, sizeof(stream_args)); stream_args.cpu_format = "fc32"; diff --git a/src/common/uhd.h b/src/common/uhd.h index 686d658..fd224e1 100644 --- a/src/common/uhd.h +++ b/src/common/uhd.h @@ -1,5 +1,5 @@ -int uhd_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain); +int uhd_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain, double bandwidth); int uhd_start(void); void uhd_close(void); int uhd_send(float *buff, int num); |