Skip to content

Commit

Permalink
use model property instead of device_name
Browse files Browse the repository at this point in the history
Consistency with base sigan interface
  • Loading branch information
aromanielloNTIA committed Jan 29, 2024
1 parent 0ea50a9 commit 9e3d509
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
18 changes: 8 additions & 10 deletions src/scos_tekrsa/hardware/tekrsa_sigan.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,16 @@ def connect(self):
self.rsa.DEVICE_SearchAndConnect()
except Exception as e:
self._is_available = False
self.device_name = "NONE: Failed to connect to TekRSA"
self._model = "NONE: Failed to connect to TekRSA"
logger.exception("Unable to connect to TEKRSA")
raise e
# Finish setup with either real or Mock RSA device
self.device_name = self.rsa.DEVICE_GetNomenclature()
self._model = self.rsa.DEVICE_GetNomenclature()
self._firmware_version = self.rsa.DEVICE_GetFWVersion()
self._api_version = self.rsa.DEVICE_GetAPIVersion()
self.get_constraints()
logger.debug("Using the following Tektronix RSA device:")
logger.debug(
f"{self.device_name} ({self.min_frequency}-{self.max_frequency} Hz)"
)
logger.debug(f"{self._model} ({self.min_frequency}-{self.max_frequency} Hz)")
# Populate instance variables for parameters on connect
self._preamp_enable = self.preamp_enable
self._attenuation = self.attenuation
Expand Down Expand Up @@ -215,7 +213,7 @@ def reference_level(self, reference_level):

@property
def attenuation(self):
if self.device_name not in ["RSA306B", "RSA306"]:
if self._model not in ["RSA306B", "RSA306"]:
# API returns attenuation as negative value. Convert to positive.
self._attenuation = abs(self.rsa.CONFIG_GetRFAttenuator())
else:
Expand All @@ -226,7 +224,7 @@ def attenuation(self):
@attenuation.setter
def attenuation(self, attenuation):
"""Set device attenuation, in dB, for RSA 500/600 series devices"""
if self.device_name not in ["RSA306B", "RSA306"]:
if self._model not in ["RSA306B", "RSA306"]:
if self.min_attenuation <= abs(attenuation) <= self.max_attenuation:
self.rsa.CONFIG_SetAutoAttenuationEnable(False)
# API requires attenuation set as a negative number. Convert to negative.
Expand All @@ -245,7 +243,7 @@ def attenuation(self, attenuation):

@property
def preamp_enable(self):
if self.device_name not in ["RSA306B", "RSA306"]:
if self._model not in ["RSA306B", "RSA306"]:
self._preamp_enable = self.rsa.CONFIG_GetRFPreampEnable()
else:
logger.debug("Tektronix RSA 300 series device has no built-in preamp.")
Expand All @@ -254,7 +252,7 @@ def preamp_enable(self):

@preamp_enable.setter
def preamp_enable(self, preamp_enable):
if self.device_name not in ["RSA306B", "RSA306"]:
if self._model not in ["RSA306B", "RSA306"]:
if self.preamp_enable != preamp_enable:
logger.debug("Switching preamp to " + str(preamp_enable))
self.rsa.CONFIG_SetRFPreampEnable(preamp_enable)
Expand Down Expand Up @@ -386,7 +384,7 @@ def acquire_time_domain_samples(
"sample_rate": self.rsa.IQSTREAM_GetAcqParameters()[1],
"capture_time": self._capture_time,
}
if self.device_name not in ["RSA306B", "RSA306"]:
if self._model not in ["RSA306B", "RSA306"]:
measurement_result["attenuation"] = self.attenuation
measurement_result["preamp_enable"] = self.preamp_enable
return measurement_result
18 changes: 9 additions & 9 deletions tests/test_tekrsa_sigan.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ def test_attenuation(self):
setattr(self.rx, "attenuation", self.rx.max_attenuation + 1)

# Test handling for RSA without manual attenuator
old_dev_name = self.rx.device_name
setattr(self.rx, "device_name", "RSA306B")
old_dev_name = self.rx.model
setattr(self.rx, "model", "RSA306B")
assert self.rx.attenuation is None
setattr(self.rx, "attenuation", 50)
assert self.rx.attenuation is None
setattr(self.rx, "device_name", old_dev_name)
setattr(self.rx, "model", old_dev_name)

def test_preamp_enable(self):
assert isinstance(self.rx.preamp_enable, bool)
Expand All @@ -149,12 +149,12 @@ def test_preamp_enable(self):
assert self.rx.preamp_enable == True

# Test handling for RSA without preamp
old_dev_name = self.rx.device_name
setattr(self.rx, "device_name", "RSA306B")
old_dev_name = self.rx.model
setattr(self.rx, "model", "RSA306B")
assert self.rx.preamp_enable is None
setattr(self.rx, "preamp_enable", False)
assert self.rx.preamp_enable is None
setattr(self.rx, "device_name", old_dev_name)
setattr(self.rx, "model", old_dev_name)

def test_acquire_samples_retry(self):
# Not enough retries = acquisition should fail
Expand Down Expand Up @@ -193,16 +193,16 @@ def test_acquire_samples(self):
assert isinstance(r["capture_time"], str) # Can't predict this value

# Attenuation/preamp keys should not exist for RSA30X
old_dev_name = self.rx.device_name
setattr(self.rx, "device_name", "RSA306B")
old_dev_name = self.rx.model
setattr(self.rx, "model", "RSA306B")
r = self.rx.acquire_time_domain_samples(
int(self.rx.iq_bandwidth * 0.001), cal_adjust=False
)
with pytest.raises(KeyError):
_ = r["attenuation"]
with pytest.raises(KeyError):
_ = r["preamp_enable"]
setattr(self.rx, "device_name", old_dev_name)
setattr(self.rx, "model", old_dev_name)

# Acquire n_samps resulting in integer number of milliseconds
for duration_ms in [1, 2, 3, 7, 10]:
Expand Down

0 comments on commit 9e3d509

Please sign in to comment.