[USRP-users] UHD C++ API Questions

Radio User radiogeek381 at gmail.com
Tue Dec 2 10:07:00 EST 2014


Peter,

>>* I had a couple questions come up as I was following the example:
**---snip---
*>* 5.  In the two versions of rx_samples_to_file that I found, I noted a
*>* difference in the way data is read from the device via recv().
*>* Namely, I'm lost on the last two parameters that are passed in.  Do I
*>* have to specify an io_type and are there different options than
*>* RECV_MODE_FULL_BUFF?  Do I have to use a STL vector or can I pass it a
*>* different data structure (like a C-style buffer/array)?  I guess I
*>* just need to be pointed to a good few lines of code on how recv()
*>* works and is implemented.  Also, does recv() throw exceptions?
*>


Good questions.  I think Michael answered them for the most part, but
as for question 5, I don't believe the documentation answers it
well. The buffer pointer argument to recv is a reference to a
"buffs_type" object. This is an alias for a
ref_vector<void*>. Therefore, the buffer argument is a reference to a
ref_vector<void*>. A ref vector is a vector of pointers into one or
more storage blocks.  So, you can pass one or more buffers into recv
via the buffs_type object.  This is the mechanism that libuhd uses to
capture data from more than one channel at a time. (Michael, please
correct me if I'm wrong.)

But ref_vector has a constructor that converts a pointer to anything
into a ref_vector. In that case, calling ....recv(foo, ...)  will
convert foo (assuming it is a pointer to something) into a single
ref_vector with one element -- a pointer to the block of data that foo
points to.

ref_vector also has a constructor that can convert a reference to an
STL vector object into a ref_vector. The STL vector object is assumed
to be a vector of pointers that each point to some storage.  The
ref_vector will contain those same pointers. So, this code (or
something like it...)

   std::complex<float> fred[1024], barney[1024];
   stl::vector<std::complex<float> *> buffs(2)
   buffs[0] = fred;
   buffs[1] = barney;
   ...recv(buffs....)

will fire off a receive request that will fill fred with data from one
channel, and barney with data from another channel.

So, you can pass an stl vector of pointers to storage, or a pointer to
the storage.... The magic of templates makes it all work.

rg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ettus.com/pipermail/usrp-users_lists.ettus.com/attachments/20141202/1f29ce63/attachment-0002.html>


More information about the USRP-users mailing list