Skip to content

Commit

Permalink
Make sdrplay-specific bandwidth tweak based on driver key.
Browse files Browse the repository at this point in the history
This is a little more generic than having hardware-specific
flags in the SOAPY struct: look at the driver key and decide
to override defaults based on that.

(also, the old code would trigger if _any_ connected device
was a sdrplay, not only if the selected device was)
  • Loading branch information
mutability committed Aug 7, 2023
1 parent 662789a commit 9f7cfff
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions sdr_soapy.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ typedef struct _gain_element_config {
static struct {
SoapySDRDevice *dev;
SoapySDRStream *stream;
bool dev_sdrplay;

iq_convert_fn converter;
struct converter_state *converter_state;
Expand All @@ -54,7 +53,6 @@ void soapyInitConfig()
{
SOAPY.dev = NULL;
SOAPY.stream = NULL;
SOAPY.dev_sdrplay = false;
SOAPY.converter = NULL;
SOAPY.converter_state = NULL;
SOAPY.channel = 0;
Expand Down Expand Up @@ -177,20 +175,43 @@ bool soapyOpen(void)

SoapySDRKwargs result = SoapySDRDevice_getHardwareInfo(SOAPY.dev);
if (result.size > 0) {
fprintf(stderr, "soapy: hardware info: ");
for (size_t i = 0; i < result.size; ++i) {
printf("%s=%s", result.keys[i], result.vals[i]);
if (i+1 < result.size) printf(", ");
if (i) fprintf(stderr, ", ");
fprintf(stderr, "%s=%s", result.keys[i], result.vals[i]);
}
printf("\n");
fprintf(stderr, "\n");
}
SoapySDRKwargs_clear(&result);

char* driver_key = SoapySDRDevice_getDriverKey(SOAPY.dev);
if (driver_key) {
fprintf(stderr, "soapy: driver key: %s\n", driver_key);

// Apply driver-specific defaults
if (!strcmp(driver_key, "SDRplay")) {
// Default to 5MHz bandwidth
if (SOAPY.bandwidth == 0)
SOAPY.bandwidth = 5.0e6;
}

SoapySDR_free(driver_key);
}

char* hw_key = SoapySDRDevice_getHardwareKey(SOAPY.dev);
if (hw_key) {
printf("soapy: hardware key is %s\n", hw_key);
fprintf(stderr, "soapy: hardware key: %s\n", hw_key);
SoapySDR_free(hw_key);
}

//
// Apply generic defaults
//

if (SOAPY.bandwidth == 0) {
SOAPY.bandwidth = 3.0e6;
}

if (SOAPY.channel) {
size_t supported_channels = SoapySDRDevice_getNumChannels(SOAPY.dev, SOAPY_SDR_RX);
if (SOAPY.channel >= supported_channels) {
Expand Down Expand Up @@ -272,16 +293,9 @@ bool soapyOpen(void)
fprintf(stderr, "\n");
}

double bandwidth = SOAPY.bandwidth;
if (bandwidth == 0) {
// bandwidth by default is 3 MHz or 5 MHz if a SDRPlay device
if (SOAPY.dev_sdrplay)
bandwidth = 5.0e6;
else
bandwidth = 3.0e6;
}
if (SoapySDRDevice_setBandwidth(SOAPY.dev, SOAPY_SDR_RX, SOAPY.channel, bandwidth) != 0) {
fprintf(stderr, "soapy: setBandwidth failed: %s\n", SoapySDRDevice_lastError());

if (SoapySDRDevice_setBandwidth(SOAPY.dev, SOAPY_SDR_RX, SOAPY.channel, SOAPY.bandwidth) != 0) {
fprintf(stderr, "soapy: setBandwidth(%.1f MHz) failed: %s\n", SOAPY.bandwidth / 1e6, SoapySDRDevice_lastError());
goto error;
}

Expand Down

0 comments on commit 9f7cfff

Please sign in to comment.