Difference between revisions of "Breaking the Ice"

From MyLabWiki
Jump to: navigation, search
(Add code template for connection to gr-ctrlport)
Line 18: Line 18:
 
== Hello gr-ctrlport ==
 
== Hello gr-ctrlport ==
  
The [http://doc.zeroc.com/display/Ice/Ice+Manual Ice Manual] contains a [http://doc.zeroc.com/pages/viewpage.action?pageId=5048454 Hello World application] that we can use as template.
+
The [http://doc.zeroc.com/display/Ice/Ice+Manual Ice Manual] contains a [http://doc.zeroc.com/pages/viewpage.action?pageId=5048454 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.
  
 
[[Category:GNU Radio]]
 
[[Category:GNU Radio]]

Revision as of 18:24, 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.