Skip to content

Commit

Permalink
Allow support for array properties in pybench
Browse files Browse the repository at this point in the history
Signed-off-by: Travis F. Collins <[email protected]>
  • Loading branch information
tfcollins committed Nov 1, 2024
1 parent c22157b commit e9da9e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
13 changes: 11 additions & 2 deletions bench/cli/iiotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,21 @@ def capture_data(ctx, filename, device, channel, samples, props):
for prop in props:
if "=" not in prop:
raise ValueError(
f"Invalid property: {prop}. Must be in the form key=value"
f"Invalid property: {prop}. Must be in the form key=value\n",
"or key=value,index for array properties",
)
k, v = prop.split("=")
if "," in v:
v = v.split(",")
assert len(v) == 2, "Invalid array property"
v = v[0]
assert v.isdigit(), "Invalid array index property"
index = int(v[1])
else:
index = -1
if v.isdigit():
v = int(v)
oprops[k] = v
oprops[k] = {"value": v, "index": index}
props = oprops

capture_iq_datafile(
Expand Down
18 changes: 15 additions & 3 deletions bench/keysight/dwta/data_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ def capture_iq_datafile(
device = getattr(adi, device_name)(uri)

# Assume kwargs are attributes to set
for key, value in kwargs.items():
print(f"Setting {key} to {value}")
for key, value_index in kwargs.items():
value = value_index["value"]
index = value_index["index"]
if not hasattr(device, key):
raise AttributeError(f"Device does not have attribute: {key}")
setattr(device, key, value)
if index == -1:
print(f"Setting {key} to {value}")
setattr(device, key, value)
else:
prop = getattr(device, key)
if prop is not list:
raise ValueError(f"Property {key} is not an array")
assert index < len(prop), f"Index out of range for {key}"
prop[index] = value
print(f"Setting {key}[{index}] to {value}")
setattr(device, key, prop)


# Capture data
device.rx_enabled_channels = [channel]
Expand Down

0 comments on commit e9da9e5

Please sign in to comment.