ControlPort client library
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is the basic Android library to build ControlPort clients into
your Android application.

Currently, ControlPort runs using the Thrift backend. We need Thrift
0.9.3 for this to apply the 'generated_annotations=suppress' option to
avoid issues with Android javax classes. As of writing this, 0.9.3 is
not yet out, so just use the master branch of the Thrift git repo.

To get and compile the GNU Radio Thrift interface file:

$ cd GrControlPort/library/src/main/java
$ wget
$ thrift -out . --gen java:android,generated_annotations=suppress gnuradio.thrift

This places the required Java interface classes to ControlPort into
org/gnuradio/controlport for use by the rest of the library.

Now build the library and you can integrate this into your own
ControlPort-based application.

* Example Usage

To make and use a ControlPort client in your Java app, you need to
have this library available, make the radio client connection, and
then perform the ControlPort operations on it.

With GrControlPort pulled down into your local machine, you need to
add this as an external library to your new ControlPort client
app. In Android Studio, go to "File -> New -> Import Module" and
navigate to the location of GrControlPort. Bring this in as
"library." Now go to "File -> Project Structure", click on "app", to
to the Dependencies tab, click the + button, select Module
Dependencies, and chose "library."

The following example application shows how to access the various
getters and setters provided for by ControlPort. For a given
flowgraph, the block names (e.g., "throttle0") and the name of the
application (e.g., "Top Block") will change, so you'll need to know
what the interface points are to know how to connect to their

public class App {

    public static void main(String [] args) {
        try {
            String hostname = "";
            Integer portnum = 9090;
            RPCConnection conn = new RPCConnectionThrift(hostname, portnum);

            List<String> knobs = new ArrayList<String>();

            // Get all knobs -- pass an empty list
            //Map<String, RPCConnection.KnobInfo> x = conn.getKnobs(knobs);

            // Get exact knob
            //knobs.add("throttle0::work time");
            //Map<String, RPCConnection.KnobInfo> x = conn.getKnobs(knobs);

            // Get knob based on a regular expression
            knobs.add(".*::work time");
            Map<String, RPCConnection.KnobInfo> x = conn.getRe(knobs);

            for (Map.Entry<String, RPCConnection.KnobInfo> e : x.entrySet()) {
                System.out.println("X: " + e.getValue().key + ", " + e.getValue().value
                                   + " (" + e.getValue().ktype + ")");

            // Set a knob that takes a specific parameter type.
            // The throttle block exposes the sample_rate interface
            // that takes in a double, so this changes the throttle's
            // rate to 100 ksps.
            RPCConnection.KnobInfo thr_sr =
                new RPCConnection.KnobInfo("throttle0::sample_rate", 100e3,
            Map<String, RPCConnection.KnobInfo> y =
                new HashMap<String, RPCConnection.KnobInfo>();
            y.put("throttle0::sample_rate", thr_sr);

            // Set a knob that's just a toggle. This type of setter
            // does not require a KnobInfo defined, just the name of
            // the setter to trigger.
            // In this case, it locks and stops the flowgraph. Calling
            // "Top Block::unlock" would reset and restart the
            // flowgraph running.
            List<RPCConnection.KnobInfo> z = new ArrayList<RPCConnection.KnobInfo>();
            z.add(new RPCConnection.KnobInfo("Top Block::lock"));
            z.add(new RPCConnection.KnobInfo("Top Block::stop"));

            //List<RPCConnection.KnobInfo> z = new ArrayList<RPCConnection.KnobInfo>();
            //z.add(new RPCConnection.KnobInfo("Top Block::unlock"));
        catch (Exception e) {