Skip to content

Commit 4877c94

Browse files
committed
Add support for secondary DMA interfaces (rx2)
Signed-off-by: Travis F. Collins <[email protected]>
1 parent 7b429d4 commit 4877c94

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

bindings/python/genalyzer/pai_inf.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def fft(
1515
window=gn.Window.NO_WINDOW,
1616
axis_type=gn.FreqAxisType.DC_CENTER,
1717
axis_fmt=gn.FreqAxisFormat.FREQ,
18+
rx_device=None,
1819
):
1920
"""Perform FFT based off pyadi-iio interface.
2021
@@ -42,6 +43,8 @@ def fft(
4243
4344
``axis_fmt``: frequency axis format from gn.FreqAxisFormat enum.
4445
46+
``rx_ref``: optional pyadi-iio rx instance for secondary DMA channels. This is of type adi.rx or adi.obs.
47+
4548
Returns:
4649
``fft_out``: FFT output as a numpy array or list of numpy arrays (for multiple channels).
4750
@@ -50,61 +53,66 @@ def fft(
5053
``fft_freq_out``: frequency axis as a numpy array or list of numpy arrays (for multiple channels).
5154
"""
5255
# Checks
53-
assert hasattr(
54-
interface, "_rxadc"
55-
), "Non standard pyadi-iio device. interface must have _rxadc attribute"
56+
if rx_device is None:
57+
assert hasattr(
58+
interface, "_rxadc"
59+
), "Non standard pyadi-iio device. i_face must have _rxadc attribute"
60+
i_face = interface
61+
else:
62+
# This is the case when obs exists for secondary DMAs
63+
i_face = rx_device
5664

5765
# assert isinstance(
58-
# interface._rxadc, iio.Device
59-
# ), "interface must be an iio.Device as _rxadc attribute"
66+
# i_face._rxadc, iio.Device
67+
# ), "i_face must be an iio.Device as _rxadc attribute"
6068
if not isinstance(data, (np.ndarray, list)) and not all(
6169
isinstance(d, np.ndarray) for d in data
6270
):
6371
raise ValueError("data must be a numpy array or a list of numpy arrays")
6472
assert navg > 0 and isinstance(navg, int), "navg must be a positive integer"
6573

6674
# Check data meets channels
67-
if len(interface.rx_enabled_channels) > 1:
75+
if len(i_face.rx_enabled_channels) > 1:
6876
if not isinstance(data, list):
6977
raise ValueError("data must be a list when multiple channels are enabled")
70-
if len(data) != len(interface.rx_enabled_channels):
78+
if len(data) != len(i_face.rx_enabled_channels):
7179
raise ValueError("data length must match number of enabled channels")
7280
elif isinstance(data, list):
7381
raise ValueError("data must be a numpy array when a single channel is enabled")
74-
elif len(interface.rx_enabled_channels) == 0:
75-
raise ValueError("No enabled channels found in interface")
82+
elif len(i_face.rx_enabled_channels) == 0:
83+
raise ValueError("No enabled channels found in i_face")
7684

77-
if hasattr(interface, "rx_sample_rate"):
78-
fs = int(interface.rx_sample_rate)
79-
elif hasattr(interface, "sample_rate"):
80-
fs = int(interface.sample_rate)
85+
if hasattr(i_face, "rx_sample_rate"):
86+
fs = int(i_face.rx_sample_rate)
87+
elif hasattr(i_face, "sample_rate"):
88+
fs = int(i_face.sample_rate)
8189
else:
82-
raise ValueError("Sample rate not found in interface")
90+
raise ValueError("Sample rate not found in i_face")
8391

8492
fft_out = {}
8593
fft_out_db = {}
8694
fft_freq_out = {}
8795

88-
for i, rx_ch in enumerate(interface.rx_enabled_channels):
96+
for i, rx_ch in enumerate(i_face.rx_enabled_channels):
8997
if isinstance(rx_ch, int):
90-
name = interface._rx_channel_names[rx_ch]
98+
name = i_face._rx_channel_names[rx_ch]
9199
channel = None
92-
for ch in interface._rxadc.channels:
100+
for ch in i_face._rxadc.channels:
93101
if ch.name == name or ch.id == name:
94102
channel = ch
95103
break
96104
if channel is None:
97105
raise ValueError(
98-
f"Channel {rx_ch} not found in device {interface._rxadc.name}"
106+
f"Channel {rx_ch} not found in device {i_face._rxadc.name}"
99107
)
100108
elif isinstance(rx_ch, str):
101-
channel = interface._rxadc.find_channel(rx_ch, False)
109+
channel = i_face._rxadc.find_channel(rx_ch, False)
102110
else:
103111
raise ValueError("rx_channel must be int or str")
104112

105113
if not channel:
106114
raise ValueError(
107-
f"Channel {rx_ch} not found in device {interface._rxadc.name}"
115+
f"Channel {rx_ch} not found in device {i_face._rxadc.name}"
108116
)
109117

110118
df = channel.data_format

0 commit comments

Comments
 (0)