diff options
author | Martin Braun <martin.braun@ettus.com> | 2020-11-19 15:27:22 +0100 |
---|---|---|
committer | michael-west <michael.west@ettus.com> | 2020-12-04 12:06:14 -0800 |
commit | fc2fc14b1ad796c94532315bfc09a1e8d030f7c5 (patch) | |
tree | 4d77b21baa57edb34fcf572cca3f738271ccb36d /host/python | |
parent | 31c544650f6004e8968d65f50db804f1b6164e7d (diff) | |
download | uhd-fc2fc14b1ad796c94532315bfc09a1e8d030f7c5.tar.gz uhd-fc2fc14b1ad796c94532315bfc09a1e8d030f7c5.tar.bz2 uhd-fc2fc14b1ad796c94532315bfc09a1e8d030f7c5.zip |
python: multi_usrp: Add get_mpm_client() API call
This is a new API call, only available on Python, and only available for
MPM devices (it is added dynamically). It returns an object that allows
calling RPC calls in a Pythonic manner.
Example:
>>> rpcc = usrp.get_mpm_client()
>>> print(rpcc.get_device_info()) # Will print device info, as returned
# by uhd_find_devices
Diffstat (limited to 'host/python')
-rw-r--r-- | host/python/uhd/usrp/multi_usrp.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/host/python/uhd/usrp/multi_usrp.py b/host/python/uhd/usrp/multi_usrp.py index adb03d436..7fb73c97e 100644 --- a/host/python/uhd/usrp/multi_usrp.py +++ b/host/python/uhd/usrp/multi_usrp.py @@ -11,6 +11,16 @@ import numpy as np from .. import libpyuhd as lib +def _get_mpm_client(token, mb_args): + """ + Wrapper function to dynamically generate a Pythonic MPM client from + MultiUSRP. + """ + from uhd.utils import mpmtools + rpc_addr = mb_args.get('mgmt_addr') + rpc_port = mb_args.get('rpc_port', mpmtools.MPM_RPC_PORT) + return mpmtools.MPMClient(mpmtools.InitMode.Hijack, rpc_addr, rpc_port, token) + class MultiUSRP(lib.usrp.multi_usrp): """ MultiUSRP object for controlling devices @@ -18,6 +28,13 @@ class MultiUSRP(lib.usrp.multi_usrp): def __init__(self, args=""): """MultiUSRP constructor""" super(MultiUSRP, self).__init__(args) + # If we're on an MPM device, dynamically add this method to access the + # MPM client + if self.get_tree().exists("/mboards/0/token"): + token = self.get_tree().access_str("/mboards/0/token").get() + mb_args = \ + self.get_tree().access_device_addr("/mboards/0/args").get().to_dict() + setattr(self, 'get_mpm_client', lambda: _get_mpm_client(token, mb_args)) def recv_num_samps(self, num_samps, freq, rate=1e6, channels=(0,), gain=10): """ @@ -124,5 +141,3 @@ class MultiUSRP(lib.usrp.multi_usrp): # Help the garbage collection streamer = None return send_samps - - |