aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-05-17 19:59:28 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2017-05-17 20:06:47 +0200
commit0557bbbc438790c4710a5c85970d10e5ba41ef0d (patch)
tree665185e5cac49d0fd1b96a8fc3a4db19c4a0572a
parent683078a7a01903c9bcbac196148f132fc00be6ad (diff)
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!
-rw-r--r--src/common/soapy.c16
-rw-r--r--src/common/uhd.c18
2 files changed, 17 insertions, 17 deletions
diff --git a/src/common/soapy.c b/src/common/soapy.c
index 28dedde..4a762cd 100644
--- a/src/common/soapy.c
+++ b/src/common/soapy.c
@@ -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;
diff --git a/src/common/uhd.c b/src/common/uhd.c
index c039f67..5c8da64 100644
--- a/src/common/uhd.c
+++ b/src/common/uhd.c
@@ -87,7 +87,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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);
uhd_close();
return -EINVAL;
@@ -108,7 +108,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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;
}
@@ -132,7 +132,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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);
uhd_close();
return -EINVAL;
@@ -152,7 +152,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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);
uhd_close();
return -EINVAL;
@@ -213,7 +213,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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);
uhd_close();
return -EINVAL;
@@ -234,7 +234,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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;
}
@@ -258,7 +258,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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);
uhd_close();
return -EINVAL;
@@ -278,7 +278,7 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
uhd_close();
return -EIO;
}
- 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);
uhd_close();
return -EINVAL;
@@ -439,10 +439,10 @@ int uhd_receive(float *buff, int max)
PDEBUG(DUHD, DEBUG_ERROR, "Received rate (%.0f) does not match defined rate (%.0f), use diffrent sample rate that UHD device can handle!\n", (double)got / got_time, samplerate);
return -EPERM;
}
- check_rate = 0;
rx_gap = diff_time * (double)samplerate + 0.5;
PDEBUG(DUHD, DEBUG_ERROR, "Lost rx frame(s): A gap of %.6f seconds (%d samples), \n", diff_time, rx_gap);
}
+ check_rate = 0;
}
break;
}