summaryrefslogtreecommitdiff
path: root/gr-blocks/examples/ctrlport/usrp_source_controller.py
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2015-12-06 18:23:19 -0500
committerTom Rondeau <tom@trondeau.com>2015-12-06 18:23:19 -0500
commitbd339909e6a89fc2e9db582ba01960a0283b4506 (patch)
treea3643a4e7dbc446dabd0e93c322518e274581f38 /gr-blocks/examples/ctrlport/usrp_source_controller.py
parentd55fde354f257a1dd615a66c4ca98e3b6c6a5854 (diff)
uhd: Added controlport interface for UHD sink's "command" message handler.
Also added an example, usrp_sink_controller.py, to excercise this feature. Fixed up the source example, too, to better manage parsing options and setting the UHD source block alias (defaults to 'gr uhd usrp source0', which is the default for any flowgraph with a single UHD source block).
Diffstat (limited to 'gr-blocks/examples/ctrlport/usrp_source_controller.py')
-rwxr-xr-xgr-blocks/examples/ctrlport/usrp_source_controller.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/gr-blocks/examples/ctrlport/usrp_source_controller.py b/gr-blocks/examples/ctrlport/usrp_source_controller.py
index 77a6cb482b..02d30a9d37 100755
--- a/gr-blocks/examples/ctrlport/usrp_source_controller.py
+++ b/gr-blocks/examples/ctrlport/usrp_source_controller.py
@@ -3,24 +3,37 @@
import sys
import pmt
from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient
+from optparse import OptionParser
-args = sys.argv
-if(len(args) < 4):
- sys.stderr.write('Not enough arguments: usrp_source_controller.py <host> <port> <command> <value>\n')
+parser = OptionParser(usage="%prog: [options]")
+parser.add_option("-H", "--host", type="string", default="localhost",
+ help="Hostname to connect to (default=%default)")
+parser.add_option("-p", "--port", type="int", default=9090,
+ help="Port of Controlport instance on host (default=%default)")
+parser.add_option("-a", "--alias", type="string", default="gr uhd usrp source0",
+ help="The UHD block's alias to control (default=%default)")
+options, args = parser.parse_args()
+
+if(len(args) < 2):
+ sys.stderr.write('Not enough arguments: usrp_source_controller.py [options] <command> <value>\n')
sys.stderr.write('See the "UHD Interface" section of the manual for available commands.\n\n')
sys.exit(1)
-alias = 'usrp_source0'
port = 'command'
+alias = options.alias
+hostname = options.host
+portnum = options.port
+cmd = args[0]
+val = args[1]
-hostname = args[1]
-portnum = int(args[2])
-cmd = args[3].lower()
-
+if(cmd == "tune" or cmd == "time"):
+ sys.stderr.write("This application currently does not support the 'tune' or 'time' UHD "
+ "message commands.\n\n")
+ sys.exit(1)
if(cmd == "antenna"):
- val = pmt.intern(args[4])
+ val = pmt.intern(val)
else:
- val = pmt.from_double(float(args[4]))
+ val = pmt.from_double(float(val))
argv = [None, hostname, portnum]
radiosys = GNURadioControlPortClient(argv=argv, rpcmethod='thrift')