Difference between revisions of "Breaking the Ice"

From MyLabWiki
Jump to: navigation, search
(Add example build script)
(Add section about fetching exported knobs.)
Line 15: Line 15:
  
 
Test that gr-ctrlport is working properly by running the gr-blocks/examples/ctrlport/pfb_sync_test-qt.grc application in the source tree and the PREFIX/bin/gr-ctrlport-monitor python application (started automatically by pfb_sync_test-qt).
 
Test that gr-ctrlport is working properly by running the gr-blocks/examples/ctrlport/pfb_sync_test-qt.grc application in the source tree and the PREFIX/bin/gr-ctrlport-monitor python application (started automatically by pfb_sync_test-qt).
 +
  
 
== Hello gr-ctrlport ==
 
== Hello gr-ctrlport ==
Line 39: Line 40:
 
       Ice::CommunicatorPtr ic;
 
       Ice::CommunicatorPtr ic;
 
          
 
          
       try {
+
       try
 +
      {
 
           ic = Ice::initialize(argc, argv);
 
           ic = Ice::initialize(argc, argv);
 
           '''Ice::ObjectPrx base = ic->stringToProxy("gnuradio:tcp -h localhost -p 43243");'''
 
           '''Ice::ObjectPrx base = ic->stringToProxy("gnuradio:tcp -h localhost -p 43243");'''
Line 48: Line 50:
 
               throw "Invalid proxy";
 
               throw "Invalid proxy";
 
    
 
    
       } catch (const Ice::Exception& ex) {
+
       }
 +
      catch (const Ice::Exception& ex)
 +
      {
 
           cerr << ex << endl;
 
           cerr << ex << endl;
 
           status = 1;
 
           status = 1;
       } catch (const char* msg) {
+
       }
 +
      catch (const char* msg)
 +
      {
 
           cerr << msg << endl;
 
           cerr << msg << endl;
 
           status = 1;
 
           status = 1;
Line 68: Line 74:
 
   c++ -I. -I$ICE_HOME/include -c gnuradio.cpp client.cpp
 
   c++ -I. -I$ICE_HOME/include -c gnuradio.cpp client.cpp
 
   c++ -o client gnuradio.o client.o -L$ICE_HOME/lib -lIce -lIceUtil
 
   c++ -o client gnuradio.o client.o -L$ICE_HOME/lib -lIce -lIceUtil
 +
 +
 +
== Get list of parameters (aka. knobs) ==
 +
 +
Reverse engineered from gnuradio.h
 +
 +
We can use ControlPortPrx::properties to get a list og knobs and their properties:
 +
 +
  class ControlPort : virtual public ::Ice::Object
 +
  {
 +
  public:
 +
      ...
 +
      virtual ::GNURadio::KnobPropMap properties(const ::GNURadio::KnobIDList&, const ::Ice::Current& = ::Ice::Current()) = 0;
 +
 +
We ignore Ice::Current for now. The other GNURadio types are defined as:
 +
 +
  typedef ::std::vector< ::std::string> KnobIDList;
 +
  typedef ::std::map< ::std::string, ::GNURadio::KnobProp> KnobPropMap;
 +
 +
If we use an empty KnobIDList we will get a map containing all exported knobs. The following client.cpp update fetches this list and prints map key represented by the string:
 +
 +
  #include <Ice/Ice.h>
 +
  #include <gnuradio.h>
 +
 
 +
  using namespace std;
 +
  using namespace GNURadio;
 +
 
 +
  int main(int argc, char* argv[])
 +
  {
 +
      int status = 0;
 +
      Ice::CommunicatorPtr ic;
 +
 
 +
      '''GNURadio::KnobIDList  empty_list;  // vector<string>'''
 +
      '''GNURadio::KnobPropMap  knob_props;  // map<string, GNURadio::KnobProp>'''
 +
       
 +
      try
 +
      {
 +
          // Get proxy object
 +
          ic = Ice::initialize(argc, argv);
 +
          Ice::ObjectPrx base = ic->stringToProxy("gnuradio:tcp -h localhost -p 43243");
 +
          ControlPortPrx ctrlport = ControlPortPrx::checkedCast(base);
 +
 
 +
          if (!ctrlport)
 +
              throw "Invalid proxy";
 +
 
 +
          '''// Get list of knobs'''
 +
          '''knob_props = ctrlport->properties(empty_list);'''
 +
          '''cout << "Exported knobs: " << knob_props.size() << endl;'''
 +
 
 +
          '''for (KnobPropMap::iterator it = knob_props.begin(); it != knob_props.end(); ++it)'''
 +
              '''cout << "  " << it->first << endl;'''
 +
 
 +
      }
 +
      catch (const Ice::Exception& ex)
 +
      {
 +
          cerr << ex << endl;
 +
          status = 1;
 +
      }
 +
      catch (const char* msg)
 +
      {
 +
          cerr << msg << endl;
 +
          status = 1;
 +
      }
 +
 
 +
      if (ic)
 +
          ic->destroy();
 +
 
 +
      return status;
 +
  }
 +
  
  
 
[[Category:GNU Radio]]
 
[[Category:GNU Radio]]

Revision as of 19:04, 2 April 2013

Tips & tricks about creating a custom client to gr-ctrlport enabled flow graph.

Enable gr-ctrlport

Add to ~/.gnuradio/config.conf

 [ControlPort]
 on = True
 edges_list = False
 config = /home/directory/.gnuradio/ctrlport.conf

Next, create ~/.gnuradio/ctrlport.conf (based on PREFIX/etc/gnuradio/ctrlport.conf.example):

 ControlPort.Endpoints = tcp -t 300 -h 127.0.0.1 -p 43243

Test that gr-ctrlport is working properly by running the gr-blocks/examples/ctrlport/pfb_sync_test-qt.grc application in the source tree and the PREFIX/bin/gr-ctrlport-monitor python application (started automatically by pfb_sync_test-qt).


Hello gr-ctrlport

The Ice Manual contains a Hello World application that we can use as template. Read that chapter and try the example.

Translate gnuradio-runtime/lib/gnuradio.ice to C++ code:

 $ slice2cpp gnuradio.ice

This will generate a gnuradio.h and gnuradio.cpp file.

Create a client.cpp file that can connect to gnuradio:

 #include <Ice/Ice.h>
 #include <gnuradio.h>
 
 using namespace std;
 using namespace GNURadio;
 
 int main(int argc, char* argv[])
 {
     int status = 0;
     Ice::CommunicatorPtr ic;
       
     try
     {
         ic = Ice::initialize(argc, argv);
         Ice::ObjectPrx base = ic->stringToProxy("gnuradio:tcp -h localhost -p 43243");
 
         ControlPortPrx ctrlport = ControlPortPrx::checkedCast(base);
 
         if (!ctrlport)
             throw "Invalid proxy";
 
     }
     catch (const Ice::Exception& ex)
     {
         cerr << ex << endl;
         status = 1;
     }
     catch (const char* msg)
     {
         cerr << msg << endl;
         status = 1;
     }
 
     if (ic)
         ic->destroy();
 
     return status;
 }

The above code will do nothing except establish a connection.

You can put the code below into a script for easy compilation of the client.cpp:

 c++ -I. -I$ICE_HOME/include -c gnuradio.cpp client.cpp
 c++ -o client gnuradio.o client.o -L$ICE_HOME/lib -lIce -lIceUtil


Get list of parameters (aka. knobs)

Reverse engineered from gnuradio.h

We can use ControlPortPrx::properties to get a list og knobs and their properties:

 class ControlPort : virtual public ::Ice::Object
 {
 public:
     ...
     virtual ::GNURadio::KnobPropMap properties(const ::GNURadio::KnobIDList&, const ::Ice::Current& = ::Ice::Current()) = 0;

We ignore Ice::Current for now. The other GNURadio types are defined as:

 typedef ::std::vector< ::std::string> KnobIDList;
 typedef ::std::map< ::std::string, ::GNURadio::KnobProp> KnobPropMap;

If we use an empty KnobIDList we will get a map containing all exported knobs. The following client.cpp update fetches this list and prints map key represented by the string:

 #include <Ice/Ice.h>
 #include <gnuradio.h>
 
 using namespace std;
 using namespace GNURadio;
 
 int main(int argc, char* argv[])
 {
     int status = 0;
     Ice::CommunicatorPtr ic;
 
     GNURadio::KnobIDList   empty_list;  // vector<string>
     GNURadio::KnobPropMap  knob_props;  // map<string, GNURadio::KnobProp>
       
     try
     {
         // Get proxy object
         ic = Ice::initialize(argc, argv);
         Ice::ObjectPrx base = ic->stringToProxy("gnuradio:tcp -h localhost -p 43243");
         ControlPortPrx ctrlport = ControlPortPrx::checkedCast(base);
 
         if (!ctrlport)
             throw "Invalid proxy";
 
         // Get list of knobs
         knob_props = ctrlport->properties(empty_list);
         cout << "Exported knobs: " << knob_props.size() << endl;
 
         for (KnobPropMap::iterator it = knob_props.begin(); it != knob_props.end(); ++it)
             cout << "  " << it->first << endl;
 
     }
     catch (const Ice::Exception& ex)
     {
         cerr << ex << endl;
         status = 1;
     }
     catch (const char* msg)
     {
         cerr << msg << endl;
         status = 1;
     }
 
     if (ic)
         ic->destroy();
 
     return status;
 }