mcr error for usb devices in uhd, and type mismatch error in blade

This commit is contained in:
A ash 2025-10-06 00:06:33 -04:00
parent 25e5a4c6a6
commit 5c9e50fa48
2 changed files with 33 additions and 19 deletions

View File

@ -375,14 +375,18 @@ class Blade(SDR):
return samples
def _convert_tx_samples(self, samples):
tx_samples = np.empty(samples.size * 2, dtype=np.float32)
tx_samples[::2] = np.real(samples) # Real part
tx_samples[1::2] = np.imag(samples) # Imaginary part
# Normalize to maximum amplitude to prevent overflow
max_val = np.max(np.abs(samples))
if max_val > 0:
samples = samples / max_val # Normalize to [-1, 1]
# Scale to Q11 format (use 2047 instead of 2048 to avoid overflow)
# and interleave I/Q samples
tx_samples = np.zeros(len(samples) * 2, dtype=np.int16)
tx_samples[0::2] = (np.real(samples) * 2047).astype(np.int16) # I samples
tx_samples[1::2] = (np.imag(samples) * 2047).astype(np.int16) # Q samples
tx_samples *= 2048
tx_samples = tx_samples.astype(np.int16)
byte_array = tx_samples.tobytes()
return byte_array
def _set_rx_channel(self, channel):

View File

@ -100,6 +100,11 @@ class USRP(SDR):
self.usrp.set_rx_gain(abs_gain, channel)
# check if sample rate arg is valid
# Note: B200/B210 devices auto-adjust master clock rate, so get_rx_rates() returns
# the range for the CURRENT master clock, not the maximum possible range.
# Skip validation for B-series devices and let UHD handle it.
device_type = self.device_dict.get("type", "").lower()
if device_type not in ["b200", "b210"]:
sample_rate_range = self.usrp.get_rx_rates()
if sample_rate < sample_rate_range.start() or sample_rate > sample_rate_range.stop():
raise IOError(
@ -317,6 +322,11 @@ class USRP(SDR):
self.usrp.set_tx_gain(abs_gain, channel)
# check if sample rate arg is valid
# Note: B200/B210 devices auto-adjust master clock rate, so get_tx_rates() returns
# the range for the CURRENT master clock, not the maximum possible range.
# Skip validation for B-series devices and let UHD handle it.
device_type = self.device_dict.get("type", "").lower()
if device_type not in ["b200", "b210"]:
sample_rate_range = self.usrp.get_tx_rates()
if sample_rate < sample_rate_range.start() or sample_rate > sample_rate_range.stop():
raise IOError(