You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.8 KiB
69 lines
2.8 KiB
#!/usr/bin/env python3 |
|
"""Transmit a tx_file.py recording with an ADALM-Pluto (via pyadi-iio). |
|
|
|
UNTESTED: written without hardware. Start with a cabled test through |
|
30-40 dB of attenuation into the receiver, at the default low gain. |
|
|
|
pip install pyadi-iio # needs libiio installed |
|
./tools/pluto_tx.py hello --seconds 20 |
|
./tools/pluto_tx.py hello --uri ip:192.168.2.1 --gain -20 --seconds 60 |
|
|
|
The recording is loaded into the Pluto's cyclic buffer and replays back to |
|
back until --seconds have passed (or Ctrl-C), then the buffer is destroyed |
|
and transmission stops. The SDR's LO is set from the SigMF core:frequency |
|
(the signal sits --if-offset above it, as written by tx_file.py). |
|
""" |
|
import os, sys, time |
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) |
|
import argparse |
|
import numpy as np |
|
import iq_io |
|
|
|
|
|
def main(): |
|
ap = argparse.ArgumentParser(description=__doc__, |
|
formatter_class=argparse.RawDescriptionHelpFormatter) |
|
ap.add_argument("recording", help="SigMF recording from tx_file.py") |
|
ap.add_argument("--uri", default="ip:192.168.2.1") |
|
ap.add_argument("--gain", type=float, default=-30.0, |
|
help="TX hardware gain, dB (-89.75..0); default is deliberately low") |
|
ap.add_argument("--seconds", type=float, default=10.0, help="how long to transmit") |
|
a = ap.parse_args() |
|
|
|
m = iq_io.read_sigmf_meta(a.recording) |
|
if m["fmt"] != "cf32_le": |
|
sys.exit("expects a cf32_le recording (tx_file.py default)") |
|
x = iq_io.read_raw(m["data_path"], m["fmt"]) |
|
fs, lo, ext = m["fs"], m["fc"], m["ext"] |
|
if np.max(np.abs(x)) > 1.0: |
|
sys.exit("recording exceeds full scale") |
|
if len(x) > iq_io.PLUTO_MAX_SAMPLES: |
|
sys.exit(f"recording has {len(x) / 1e6:.1f} M samples; the Pluto's cyclic TX buffer " |
|
f"tops out around {iq_io.PLUTO_MAX_SAMPLES / 1e6:g} M. Use fewer --repeat " |
|
f"frames (it loops anyway) or a lower --fs.") |
|
try: |
|
import adi |
|
except ImportError: |
|
sys.exit("needs pyadi-iio: pip install pyadi-iio (and libiio)") |
|
|
|
sdr = adi.Pluto(a.uri) |
|
sdr.sample_rate = int(fs) |
|
sdr.tx_rf_bandwidth = int(min(fs, 2 * (abs(ext.get("if_offset", 0)) + ext.get("bw", 125e3)))) |
|
sdr.tx_lo = int(round(lo)) |
|
sdr.tx_hardwaregain_chan0 = a.gain |
|
sdr.tx_cyclic_buffer = True |
|
print(f"Pluto {a.uri}: LO {lo / 1e6:.6f} MHz, {fs / 1e6:g} MS/s, gain {a.gain:+.1f} dB; " |
|
f"signal at {ext.get('signal_freq', lo) / 1e6:.6f} MHz; " |
|
f"{len(x) / fs:.2f} s recording, looping for {a.seconds:g} s") |
|
sdr.tx((x * 2 ** 14).astype(np.complex64)) |
|
try: |
|
time.sleep(a.seconds) |
|
except KeyboardInterrupt: |
|
pass |
|
finally: |
|
sdr.tx_destroy_buffer() |
|
print("stopped") |
|
|
|
|
|
if __name__ == "__main__": |
|
main()
|
|
|