diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2017-05-31 18:14:20 +0200 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2017-06-10 13:08:25 +0200 |
commit | 329463bb8c5c14a1f54f0a057bacaf1441f01ed0 (patch) | |
tree | 6240dd75c46382785e64e7b6cb99d934edbf2000 | |
parent | aef4cf09977a7b58d0b3e3671da7aa6b3ae6405c (diff) |
SDR: Add option to give channel number
Using SoapySDR server allows to run different networks on multi channel
SDR devices.
-rw-r--r-- | src/common/main_common.c | 27 | ||||
-rw-r--r-- | src/common/sdr.c | 8 | ||||
-rw-r--r-- | src/common/sdr.h | 2 | ||||
-rw-r--r-- | src/common/soapy.c | 3 | ||||
-rw-r--r-- | src/common/soapy.h | 2 | ||||
-rw-r--r-- | src/common/uhd.c | 3 | ||||
-rw-r--r-- | src/common/uhd.h | 2 |
7 files changed, 28 insertions, 19 deletions
diff --git a/src/common/main_common.c b/src/common/main_common.c index 32c1a78..acbca01 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; int use_sdr = 0; +int sdr_channel = 0; static const char *sdr_args = ""; static double sdr_bandwidth = 0.0; #ifdef HAVE_SDR @@ -140,6 +141,8 @@ void print_help_common(const char *arg0, const char *ext_usage) printf(" --sdr-soapy\n"); printf(" Force SoapySDR driver\n"); #endif + printf(" --sdr-channel <channel #>\n"); + printf(" Give channel number for multi channel SDR device (default = %d)\n", sdr_channel); printf(" --sdr-args <args>\n"); printf(" Optional SDR device arguments, seperated by comma\n"); printf(" e.g. --sdr-args <key>=<value>[,<key>=<value>[,...]]\n"); @@ -182,14 +185,15 @@ void print_hotkeys_common(void) #define OPT_SDR_UHD 1100 #define OPT_SDR_SOAPY 1101 -#define OPT_SDR_ARGS 1102 -#define OPT_SDR_RX_GAIN 1103 -#define OPT_SDR_TX_GAIN 1104 -#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 +#define OPT_SDR_CHANNEL 1102 +#define OPT_SDR_ARGS 1103 +#define OPT_SDR_RX_GAIN 1104 +#define OPT_SDR_TX_GAIN 1105 +#define OPT_SDR_BANDWIDTH 1106 +#define OPT_WRITE_IQ_RX_WAVE 1107 +#define OPT_WRITE_IQ_TX_WAVE 1108 +#define OPT_READ_IQ_RX_WAVE 1109 +#define OPT_READ_IQ_TX_WAVE 1110 static struct option long_options_common[] = { {"help", 0, 0, 'h'}, @@ -214,6 +218,7 @@ static struct option long_options_common[] = { {"read-rx-wave", 1, 0, OPT_READ_RX_WAVE}, {"sdr-uhd", 0, 0, OPT_SDR_UHD}, {"sdr-soapy", 0, 0, OPT_SDR_SOAPY}, + {"sdr-channel", 1, 0, OPT_SDR_CHANNEL}, {"sdr-args", 1, 0, OPT_SDR_ARGS}, {"sdr-bandwidth", 1, 0, OPT_SDR_BANDWIDTH}, {"sdr-rx-gain", 1, 0, OPT_SDR_RX_GAIN}, @@ -385,6 +390,10 @@ void opt_switch_common(int c, char *arg0, int *skip_args) #endif *skip_args += 1; break; + case OPT_SDR_CHANNEL: + sdr_channel = atoi(optarg); + *skip_args += 2; + break; case OPT_SDR_ARGS: sdr_args = strdup(optarg); *skip_args += 2; @@ -489,7 +498,7 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void), 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); + rc = sdr_init(sdr_uhd, sdr_soapy, sdr_channel, 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 b654b4f..e24c8bd 100644 --- a/src/common/sdr.c +++ b/src/common/sdr.c @@ -56,15 +56,17 @@ typedef struct sdr { } sdr_t; static int sdr_use_uhd, sdr_use_soapy; +static int sdr_channel; 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, 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_init(int sdr_uhd, int sdr_soapy, int channel, 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_channel = channel; sdr_device_args = strdup(device_args); sdr_rx_gain = rx_gain; sdr_tx_gain = tx_gain; @@ -240,7 +242,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, sdr_bandwidth); + rc = uhd_open(sdr_channel, sdr_device_args, tx_center_frequency, rx_center_frequency, sdr->samplerate, sdr_rx_gain, sdr_tx_gain, sdr_bandwidth); if (rc) goto error; } @@ -248,7 +250,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, sdr_bandwidth); + rc = soapy_open(sdr_channel, 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 40de056..5e2aaf4 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, 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_init(int sdr_uhd, int sdr_soapy, int channel, 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 4a762cd..d1b37c0 100644 --- a/src/common/soapy.c +++ b/src/common/soapy.c @@ -35,10 +35,9 @@ static double samplerate; static uint64_t rx_count = 0; static uint64_t tx_count = 0; -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_open(size_t channel, 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, got_bandwidth; - size_t channel = 0; char *arg_string = strdup(device_args), *key, *val; SoapySDRKwargs args; diff --git a/src/common/soapy.h b/src/common/soapy.h index c51d34e..525899f 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, double bandwidth); +int soapy_open(size_t channel, 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 5c8da64..6d79b26 100644 --- a/src/common/uhd.c +++ b/src/common/uhd.c @@ -45,11 +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, double bandwidth) +int uhd_open(size_t channel, 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, got_bandwidth; - size_t channel = 0; samplerate = rate; check_rate = 1; diff --git a/src/common/uhd.h b/src/common/uhd.h index fd224e1..55f1bb8 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, double bandwidth); +int uhd_open(size_t channel, 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); |