ria-toolkit-oss/src/ria_toolkit_oss/sdr/__init__.py

43 lines
1.7 KiB
Python
Raw Normal View History

2025-09-12 11:32:49 -04:00
"""
2025-09-12 14:51:45 -04:00
This package provides a unified API for working with a variety of software-defined radios.
2025-09-12 11:32:49 -04:00
It streamlines tasks involving signal reception and transmission, as well as common administrative
operations such as detecting and configuring available devices.
"""
2026-03-31 13:51:10 -04:00
__all__ = ["SDR", "SDRError", "SDRParameterError", "MockSDR", "get_sdr_device"]
2025-09-12 11:32:49 -04:00
2026-03-31 13:51:10 -04:00
from .mock import MockSDR
M
2025-12-15 15:07:48 -05:00
from .sdr import SDR, SDRError, SDRParameterError
2026-03-31 13:51:10 -04:00
def get_sdr_device(device_type: str, ident: str | None = None, tx: bool = False) -> SDR:
"""Return an SDR instance for *device_type*.
For ``"mock"`` / ``"sim"`` device types, returns a :class:`MockSDR`
immediately (no hardware required). For all real device types, delegates
to ``ria_toolkit_oss_cli.ria_toolkit_oss.common.get_sdr_device`` if the
CLI package is installed; otherwise raises ``ImportError`` with a helpful
message.
Args:
device_type: Device name (``"mock"``, ``"pluto"``, ``"usrp"``, ).
ident: Optional device identifier (IP address, serial number, ).
tx: If True, require TX capability.
"""
if device_type in ("mock", "sim"):
return MockSDR()
# Delegate real device types to the CLI package which holds the driver
# imports behind hardware-specific optional dependencies.
try:
from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
get_sdr_device as _cli_get,
)
except ImportError as exc:
raise ImportError(
f"ria_toolkit_oss_cli is required to use hardware SDR device '{device_type}'. "
"Install it with: pip install ria-toolkit-oss-cli"
) from exc
return _cli_get(device_type, ident=ident, tx=tx)