SDR: Checking given parameters with a tollerance of up to 0.001

Rounding errors may cause given parameters to be changed a little.
When comparing the set-values with the get-value, a small amount
of tollerance must be allowed.

Thanx to Syvain, pointing to this bug!
This commit is contained in:
Andreas Eversberg
2017-05-17 19:59:28 +02:00
parent 683078a7a0
commit 0557bbbc43
2 changed files with 17 additions and 17 deletions

View File

@@ -78,7 +78,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what rate actually is */
got_rate = SoapySDRDevice_getSampleRate(sdr, SOAPY_SDR_TX, channel);
if (got_rate != rate) {
if (fabs(got_rate - rate) > 0.001) {
PDEBUG(DUHD, DEBUG_ERROR, "Given TX rate %.0f Hz is not supported, try %0.f Hz\n", rate, got_rate);
soapy_close();
return -EINVAL;
@@ -93,7 +93,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what gain actually is */
got_gain = SoapySDRDevice_getGain(sdr, SOAPY_SDR_TX, channel);
if (got_gain != tx_gain) {
if (fabs(got_gain - tx_gain) > 0.001) {
PDEBUG(DUHD, DEBUG_NOTICE, "Given TX gain %.0f is not supported, we use %0.f\n", tx_gain, got_gain);
tx_gain = got_gain;
}
@@ -107,7 +107,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what frequency actually is */
got_frequency = SoapySDRDevice_getFrequency(sdr, SOAPY_SDR_TX, channel);
if (got_frequency != tx_frequency) {
if (fabs(got_frequency - tx_frequency) > 0.001) {
PDEBUG(DUHD, DEBUG_ERROR, "Given TX frequency %.0f Hz is not supported, try %0.f Hz\n", tx_frequency, got_frequency);
soapy_close();
return -EINVAL;
@@ -122,7 +122,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what bandwidth actually is */
got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_TX, channel);
if (got_bandwidth != bandwidth) {
if (fabs(got_bandwidth - bandwidth) >= 0.001) {
PDEBUG(DUHD, DEBUG_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth);
soapy_close();
return -EINVAL;
@@ -154,7 +154,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what rate actually is */
got_rate = SoapySDRDevice_getSampleRate(sdr, SOAPY_SDR_RX, channel);
if (got_rate != rate) {
if (fabs(got_rate - rate) > 0.001) {
PDEBUG(DUHD, DEBUG_ERROR, "Given RX rate %.0f Hz is not supported, try %0.f Hz\n", rate, got_rate);
soapy_close();
return -EINVAL;
@@ -169,7 +169,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what gain actually is */
got_gain = SoapySDRDevice_getGain(sdr, SOAPY_SDR_RX, channel);
if (got_gain != rx_gain) {
if (fabs(got_gain - rx_gain) > 0.001) {
PDEBUG(DUHD, DEBUG_NOTICE, "Given RX gain %.3f is not supported, we use %.3f\n", rx_gain, got_gain);
rx_gain = got_gain;
}
@@ -183,7 +183,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what frequency actually is */
got_frequency = SoapySDRDevice_getFrequency(sdr, SOAPY_SDR_RX, channel);
if (got_frequency != rx_frequency) {
if (fabs(got_frequency - rx_frequency) > 0.001) {
PDEBUG(DUHD, DEBUG_ERROR, "Given RX frequency %.0f Hz is not supported, try %0.f Hz\n", rx_frequency, got_frequency);
soapy_close();
return -EINVAL;
@@ -198,7 +198,7 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
/* see what bandwidth actually is */
got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_RX, channel);
if (got_bandwidth != bandwidth) {
if (fabs(got_bandwidth - bandwidth) > 0.001) {
PDEBUG(DUHD, DEBUG_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %0.f Hz\n", bandwidth, got_bandwidth);
soapy_close();
return -EINVAL;