diff options
Diffstat (limited to 'gnuradio-runtime/python')
4 files changed, 71 insertions, 81 deletions
diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/GNURadioControlPortClient.py b/gnuradio-runtime/python/gnuradio/ctrlport/GNURadioControlPortClient.py index b9d0e40972..c17a4279d0 100644 --- a/gnuradio-runtime/python/gnuradio/ctrlport/GNURadioControlPortClient.py +++ b/gnuradio-runtime/python/gnuradio/ctrlport/GNURadioControlPortClient.py @@ -128,72 +128,63 @@ Args: host: hostname of the connection """ -from gnuradio.ctrlport.GNURadio.ttypes import BaseTypes - class RPCConnectionThrift(RPCConnection): def __init__(self, host=None, port=None): - if port is None: port = 9090 + from gnuradio.ctrlport.GNURadio.ttypes import BaseTypes + self.BaseTypes = BaseTypes + + if port is None: + port = 9090 super(RPCConnectionThrift, self).__init__(method='thrift', port=port, host=host) self.newConnection(host, port) + class Knob(): + def __init__(self, key, value): + (self.key, self.value) = (key, value) + + self.types_dict = { + self.BaseTypes.BOOL: lambda k,b: Knob(k, b.value.a_bool), + self.BaseTypes.BYTE: lambda k,b: Knob(k, b.value.a_byte), + self.BaseTypes.SHORT: lambda k,b: Knob(k, b.value.a_short), + self.BaseTypes.INT: lambda k,b: Knob(k, b.value.a_int), + self.BaseTypes.LONG: lambda k,b: Knob(k, b.value.a_long), + self.BaseTypes.DOUBLE: lambda k,b: Knob(k, b.value.a_double), + self.BaseTypes.STRING: lambda k,b: Knob(k, b.value.a_string), + self.BaseTypes.COMPLEX: lambda k,b: Knob(k, b.value.a_complex), + self.BaseTypes.F32VECTOR: lambda k,b: Knob(k, b.value.a_f32vector), + self.BaseTypes.F64VECTOR: lambda k,b: Knob(k, b.value.a_f64vector), + self.BaseTypes.S64VECTOR: lambda k,b: Knob(k, b.value.a_s64vector), + self.BaseTypes.S32VECTOR: lambda k,b: Knob(k, b.value.a_s32vector), + self.BaseTypes.S16VECTOR: lambda k,b: Knob(k, b.value.a_s16vector), + self.BaseTypes.S8VECTOR: lambda k,b: Knob(k, b.value.a_s8vector), + self.BaseTypes.C32VECTOR: lambda k,b: Knob(k, b.value.a_c32vector), + } + def newConnection(self, host=None, port=None): from gnuradio.ctrlport.ThriftRadioClient import ThriftRadioClient self.thriftclient = ThriftRadioClient(self.getHost(), self.getPort()) def properties(self, *args): - return self.thriftclient.radio.properties(*args) + knobprops = self.thriftclient.radio.properties(*args) + for key, knobprop in knobprops.iteritems(): +# print("key:", key, "value:", knobprop, "type:", knobprop.type) + knobprops[key].min = self.types_dict[knobprop.type](key, knobprop.min) + knobprops[key].max = self.types_dict[knobprop.type](key, knobprop.max) + knobprops[key].defaultvalue = self.types_dict[knobprop.type](key, knobprop.defaultvalue) - def getKnobs(self, *args): - class Knob(): - def __init__(self, key, value): - (self.key, self.value) = (key, value) + return knobprops + def getKnobs(self, *args): result = {} for key, knob in self.thriftclient.radio.getKnobs(*args).iteritems(): - if knob.type == BaseTypes.BOOL: result[key] = Knob(key, knob.value.a_bool) - elif knob.type == BaseTypes.BYTE: result[key] = Knob(key, knob.value.a_byte) - elif knob.type == BaseTypes.SHORT: result[key] = Knob(key, knob.value.a_short) - elif knob.type == BaseTypes.INT: result[key] = Knob(key, knob.value.a_int) - elif knob.type == BaseTypes.LONG: result[key] = Knob(key, knob.value.a_long) - elif knob.type == BaseTypes.DOUBLE: result[key] = Knob(key, knob.value.a_double) - elif knob.type == BaseTypes.STRING: result[key] = Knob(key, knob.value.a_string) - elif knob.type == BaseTypes.COMPLEX: result[key] = Knob(key, knob.value.a_complex) - elif knob.type == BaseTypes.F32VECTOR: result[key] = Knob(key, knob.value.a_f32vector) - elif knob.type == BaseTypes.F64VECTOR: result[key] = Knob(key, knob.value.a_f64vector) - elif knob.type == BaseTypes.S64VECTOR: result[key] = Knob(key, knob.value.a_s64vector) - elif knob.type == BaseTypes.S32VECTOR: result[key] = Knob(key, knob.value.a_s32vector) - elif knob.type == BaseTypes.S16VECTOR: result[key] = Knob(key, knob.value.a_s16vector) - elif knob.type == BaseTypes.S8VECTOR: result[key] = Knob(key, knob.value.a_s8vector) - elif knob.type == BaseTypes.C32VECTOR: result[key] = Knob(key, knob.value.a_c32vector) - else: - raise exceptions.ValueError - +# print("key:", key, "value:", knob, "type:", knob.type) + result[key] = self.types_dict[knob.type](key, knob) return result def getRe(self,*args): - class Knob(): - def __init__(self, key, value): - (self.key, self.value) = (key, value) - result = {} for key, knob in self.thriftclient.radio.getRe(*args).iteritems(): - if knob.type == BaseTypes.BOOL: result[key] = Knob(key, knob.value.a_bool) - elif knob.type == BaseTypes.BYTE: result[key] = Knob(key, knob.value.a_byte) - elif knob.type == BaseTypes.SHORT: result[key] = Knob(key, knob.value.a_short) - elif knob.type == BaseTypes.INT: result[key] = Knob(key, knob.value.a_int) - elif knob.type == BaseTypes.LONG: result[key] = Knob(key, knob.value.a_long) - elif knob.type == BaseTypes.DOUBLE: result[key] = Knob(key, knob.value.a_double) - elif knob.type == BaseTypes.STRING: result[key] = Knob(key, knob.value.a_string) - elif knob.type == BaseTypes.COMPLEX: result[key] = Knob(key, knob.value.a_complex) - elif knob.type == BaseTypes.F32VECTOR: result[key] = Knob(key, knob.value.a_f32vector) - elif knob.type == BaseTypes.F64VECTOR: result[key] = Knob(key, knob.value.a_f64vector) - elif knob.type == BaseTypes.S64VECTOR: result[key] = Knob(key, knob.value.a_s64vector) - elif knob.type == BaseTypes.S32VECTOR: result[key] = Knob(key, knob.value.a_s32vector) - elif knob.type == BaseTypes.S16VECTOR: result[key] = Knob(key, knob.value.a_s16vector) - elif knob.type == BaseTypes.S8VECTOR: result[key] = Knob(key, knob.value.a_s8vector) - elif knob.type == BaseTypes.C32VECTOR: result[key] = Knob(key, knob.value.a_c32vector) - else: - raise exceptions.ValueError + result[key] = self.types_dict[knob.type](key, knob) return result def setKnobs(self,*args): diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py b/gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py index 243cc822f7..661705d613 100644 --- a/gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py +++ b/gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py @@ -442,8 +442,7 @@ class GrDataPlotterValueTable: units = str(knobprops[itemKey].units) descr = str(knobprops[itemKey].description) - # TODO: FIX COMPLEX - if False: #if(type(v) == GNURadio.complex): + if(type(v) == GNURadio.complex): v = v.re + v.im*1j # If it's a byte stream, Python thinks it's a string. # Unpack and convert to floats for plotting. @@ -469,8 +468,7 @@ class GrDataPlotterValueTable: for k in knobs.keys(): if k not in foundKeys: v = knobs[k].value - # TODO: Fix Handle of Complex - if False: #if(type(v) == GNURadio.complex): + if(type(v) == GNURadio.complex): v = v.re + v.im*1j # If it's a byte stream, Python thinks it's a string. # Unpack and convert to floats for plotting. diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/gr-ctrlport-monitor b/gnuradio-runtime/python/gnuradio/ctrlport/gr-ctrlport-monitor index 5411b244b0..251b4bc03c 100644 --- a/gnuradio-runtime/python/gnuradio/ctrlport/gr-ctrlport-monitor +++ b/gnuradio-runtime/python/gnuradio/ctrlport/gr-ctrlport-monitor @@ -20,15 +20,12 @@ # Boston, MA 02110-1301, USA. # -# from gnuradio import gr, ctrlport - from PyQt4 import QtCore,Qt import PyQt4.QtGui as QtGui import os, sys, time, struct -# from gnuradio.ctrlport.IceRadioClient import * +from gnuradio import gr, ctrlport from gnuradio.ctrlport.GrDataPlotter import * -# from gnuradio.ctrlport import GNURadio class RateDialog(QtGui.QDialog): def __init__(self, delay, parent=None): @@ -79,7 +76,7 @@ class MAINWindow(QtGui.QMainWindow): self.setUnifiedTitleAndToolBarOnMac(True) self.newCon(radioclient) - icon = QtGui.QIcon(sys.argv[0] + "/icon.png" ) + icon = QtGui.QIcon(ctrlport.__path__[0] + "/icon.png" ) self.setWindowIcon(icon) # Locally turn off ControlPort export from GR. This prevents @@ -179,8 +176,10 @@ class MAINWindow(QtGui.QMainWindow): uid = tree.uid knobprop = self.knobprops[uid][tag] - r = str(tree.radio).split(" ") - title = "{0}:{1}".format(r[3], r[5]) + strr = str(tree.radioclient) + print(strr) +# r = strr.split(" ") + title = strr #title = "{0}:{1}".format(r[3], r[5]) pmin,pmax = get_minmax(knobprop) disp = knobprop.display @@ -301,13 +300,12 @@ class MAINWindow(QtGui.QMainWindow): def update(self, knobs, uid): #sys.stderr.write("KNOB KEYS: {0}\n".format(knobs.keys())) for plot in self.plots[uid]: - print("update plotuid:", uid) data = [] for n in plot.knobnames: - print("update plotuid:", uid, "name:", n) d = knobs[n].value - if(type(d) == GNURadio.complex): - d = [d.re, d.im] + # TODO: FIX COMPLEX! +# if(type(d) == GNURadio.complex): +# d = [d.re, d.im] # If it's a byte stream, Python thinks it's a string. # Unpack and convert to floats for plotting. @@ -735,10 +733,11 @@ def get_minmax(p): pmax = p.max.value # Find min/max or real or imag for GNURadio::complex - if(type(pmin) == GNURadio.complex): - pmin = min(pmin.re, pmin.im) - if(type(pmax) == GNURadio.complex): - pmax = max(pmax.re, pmax.im) + # TODO: fix complex +# if(type(pmin) == GNURadio.complex): +# pmin = min(pmin.re, pmin.im) +# if(type(pmax) == GNURadio.complex): +# pmax = max(pmax.re, pmax.im) # If it's a byte stream, Python thinks it's a string. if(type(pmin) == str): @@ -757,9 +756,15 @@ def get_minmax(p): return pmin, pmax +# class MyClient(IceRadioClient): +# def __init__(self): +# IceRadioClient.__init__(self, MAINWindow) +# +# sys.exit(MyClient().main(sys.argv)) + class MyApp(object): def __init__(self, args): - from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient + from GNURadioControlPortClient import GNURadioControlPortClient GNURadioControlPortClient(args, 'thrift', self.run, QtGui.QApplication(sys.argv).exec_) def run(self, client): diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/gr-perf-monitorx b/gnuradio-runtime/python/gnuradio/ctrlport/gr-perf-monitorx index c39df034ea..c066542ac7 100644 --- a/gnuradio-runtime/python/gnuradio/ctrlport/gr-perf-monitorx +++ b/gnuradio-runtime/python/gnuradio/ctrlport/gr-perf-monitorx @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # # Copyright 2012-2013 Free Software Foundation, Inc. # @@ -29,17 +29,13 @@ from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar from matplotlib.figure import Figure -from gnuradio import gr, ctrlport - from PyQt4 import QtCore,Qt,Qwt5 import PyQt4.QtGui as QtGui import sys, time, re, pprint import itertools - +from gnuradio import gr, ctrlport from gnuradio.ctrlport.GrDataPlotter import * -#from gnuradio.ctrlport import GNURadio - class MAINWindow(QtGui.QMainWindow): def minimumSizeHint(self): @@ -85,7 +81,7 @@ class MAINWindow(QtGui.QMainWindow): self.mdiArea.currentSubWindow().showMaximized() def newCon(self, csomeBool): - child = MForm(self.radioclient, len(self.conns), self, prompt= not csomeBool) + child = MForm(self.radioclient, len(self.conns), self, dialogprompt = not csomeBool) if(child.radioclient is not None): child.setWindowTitle(str(child.radioclient)) self.mdiArea.addSubWindow(child) @@ -362,8 +358,9 @@ class DataTableBuffers(DataTable): blockport_fullness = {} for blk in buffer_fullness: bdata = buffer_fullness[blk] - for port in range(0,len(bdata)): - blockport_fullness["%s:%d"%(blk,port)] = bdata[port]; + if bdata: + for port in range(0,len(bdata)): + blockport_fullness["%s:%d"%(blk,port)] = bdata[port]; self.table_update(blockport_fullness); @@ -473,7 +470,7 @@ class MForm(QtGui.QWidget): # strip values out of ctrlport response buf_vals = dict(zip( map(lambda x: x.split("::")[0], buf_knobs.keys()), - map(lambda x: x, buf_knobs.values()))) + map(lambda x: x.value, buf_knobs.values()))) # get work time for all blocks kl = map(lambda x: "%s::%swork time" % \ @@ -503,7 +500,7 @@ class MForm(QtGui.QWidget): # get the right output buffer/port weight for each edge sourceport = e[2]["sourceport"]; if(e[2]["type"] == "stream"): - newweight = buf_vals[n].value[sourceport] + newweight = buf_vals[n][sourceport] e[2]["weight"] = newweight; for n in nodes_msg: @@ -511,7 +508,6 @@ class MForm(QtGui.QWidget): for e in ne: # iterate over edges from this block sourceport = e[2]["sourceport"]; if(e[2]["type"] == "msg"): - #newweight = buf_vals[n][sourceport] newweight = 0.01; e[2]["weight"] = newweight; @@ -596,12 +592,12 @@ class MForm(QtGui.QWidget): km[self.clockKey] = k[self.clockKey]; self.radioclient.setKnobs(km); - def __init__(self, radioclient, uid=0, parent=None, prompt = False): + def __init__(self, radioclient, uid=0, parent=None, dialogprompt = False): super(MForm, self).__init__() self.radioclient = radioclient # print("before radioclient.getHost()", radioclient.getHost(), radioclient.getPort(), "prompt", prompt) - if(prompt or radioclient.getHost() is None or radioclient.getPort() is None): + if(dialogprompt or radioclient.getHost() is None or radioclient.getPort() is None): # print("before ConInfoDialog") askinfo = ConInfoDialog(self); if askinfo.exec_(): |