SDR: Add option to give channel number

Using SoapySDR server allows to run different networks on multi channel
SDR devices.
This commit is contained in:
Andreas Eversberg 2017-05-31 18:14:20 +02:00
parent aef4cf0997
commit 329463bb8c
7 changed files with 28 additions and 19 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);