summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-uhd/include/gr_uhd_usrp_sink.h13
-rw-r--r--gr-uhd/include/gr_uhd_usrp_source.h29
-rw-r--r--gr-uhd/lib/CMakeLists.txt3
-rw-r--r--gr-uhd/lib/gr_uhd_amsg_source.cc4
-rw-r--r--gr-uhd/lib/gr_uhd_common.h42
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_sink.cc28
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc63
-rw-r--r--gr-uhd/swig/__init__.py4
8 files changed, 171 insertions, 15 deletions
diff --git a/gr-uhd/include/gr_uhd_usrp_sink.h b/gr-uhd/include/gr_uhd_usrp_sink.h
index d6cbe2fdc..ff4856f9b 100644
--- a/gr-uhd/include/gr_uhd_usrp_sink.h
+++ b/gr-uhd/include/gr_uhd_usrp_sink.h
@@ -118,6 +118,19 @@ class GR_UHD_API uhd_usrp_sink : virtual public gr_sync_block{
public:
/*!
+ * Set the start time for outgoing samples.
+ * To control when samples are transmitted,
+ * set this value before starting the flow graph.
+ * The value is cleared after each run.
+ * When not specified, the start time will be:
+ * - Immediately for the one channel case
+ * - in the near future for multi-channel
+ *
+ * \param time the absolute time for transmission to begin
+ */
+ virtual void set_start_time(const uhd::time_spec_t &time) = 0;
+
+ /*!
* Set the frontend specification.
* \param spec the subdev spec markup string
* \param mboard the motherboard index 0 to M-1
diff --git a/gr-uhd/include/gr_uhd_usrp_source.h b/gr-uhd/include/gr_uhd_usrp_source.h
index cf2186bc0..abf3512f6 100644
--- a/gr-uhd/include/gr_uhd_usrp_source.h
+++ b/gr-uhd/include/gr_uhd_usrp_source.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2011 Free Software Foundation, Inc.
+ * Copyright 2010-2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -110,6 +110,19 @@ class GR_UHD_API uhd_usrp_source : virtual public gr_sync_block{
public:
/*!
+ * Set the start time for incoming samples.
+ * To control when samples are received,
+ * set this value before starting the flow graph.
+ * The value is cleared after each run.
+ * When not specified, the start time will be:
+ * - Immediately for the one channel case
+ * - in the near future for multi-channel
+ *
+ * \param time the absolute time for reception to begin
+ */
+ virtual void set_start_time(const uhd::time_spec_t &time) = 0;
+
+ /*!
* Set the frontend specification.
* \param spec the subdev spec markup string
* \param mboard the motherboard index 0 to M-1
@@ -469,10 +482,22 @@ public:
* Convenience function for finite data acquisition.
* This is not to be used with the scheduler; rather,
* one can request samples from the USRP in python.
- * //TODO multi-channel
* //TODO assumes fc32
+ * \param nsamps the number of samples
+ * \return a vector of complex float samples
*/
virtual std::vector<std::complex<float> > finite_acquisition(const size_t nsamps) = 0;
+
+ /*!
+ * Convenience function for finite data acquisition.
+ * This is the multi-channel version of finite_acquisition;
+ * This is not to be used with the scheduler; rather,
+ * one can request samples from the USRP in python.
+ * //TODO assumes fc32
+ * \param nsamps the number of samples per channel
+ * \return a vector of buffers, where each buffer represents a channel
+ */
+ virtual std::vector<std::vector<std::complex<float> > > finite_acquisition_v(const size_t nsamps) = 0;
};
#endif /* INCLUDED_GR_UHD_USRP_SOURCE_H */
diff --git a/gr-uhd/lib/CMakeLists.txt b/gr-uhd/lib/CMakeLists.txt
index 432ed1ab6..1f44b0630 100644
--- a/gr-uhd/lib/CMakeLists.txt
+++ b/gr-uhd/lib/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011-2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -23,6 +23,7 @@
include_directories(
${GNURADIO_CORE_INCLUDE_DIRS}
${GR_UHD_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_BINARY_DIR}
)
include_directories(${UHD_INCLUDE_DIRS})
diff --git a/gr-uhd/lib/gr_uhd_amsg_source.cc b/gr-uhd/lib/gr_uhd_amsg_source.cc
index 08941584b..67e402f6b 100644
--- a/gr-uhd/lib/gr_uhd_amsg_source.cc
+++ b/gr-uhd/lib/gr_uhd_amsg_source.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Free Software Foundation, Inc.
+ * Copyright 2011-2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -22,6 +22,7 @@
#include <gr_uhd_amsg_source.h>
#include <boost/bind.hpp>
#include <gruel/thread.h>
+#include "gr_uhd_common.h"
/***********************************************************************
* UHD Asynchronous Message Source Impl
@@ -87,6 +88,7 @@ boost::shared_ptr<uhd_amsg_source> uhd_make_amsg_source(
const uhd::device_addr_t &device_addr,
gr_msg_queue_sptr msgq
){
+ gr_uhd_check_abi();
return boost::shared_ptr<uhd_amsg_source>(
new uhd_amsg_source_impl(device_addr, msgq)
);
diff --git a/gr-uhd/lib/gr_uhd_common.h b/gr-uhd/lib/gr_uhd_common.h
new file mode 100644
index 000000000..940f17692
--- /dev/null
+++ b/gr-uhd/lib/gr_uhd_common.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_UHD_COMMON_H
+#define INCLUDED_GR_UHD_COMMON_H
+
+#include <uhd/version.hpp>
+#include <boost/format.hpp>
+#include <stdexcept>
+
+static inline void gr_uhd_check_abi(void){
+ #ifdef UHD_VERSION_ABI_STRING
+ if (std::string(UHD_VERSION_ABI_STRING) == uhd::get_abi_string()) return;
+ throw std::runtime_error(str(boost::format(
+ "\nGR-UHD detected ABI compatibility mismatch with UHD library.\n"
+ "GR-UHD was build against ABI: %s,\n"
+ "but UHD library reports ABI: %s\n"
+ "Suggestion: install an ABI compatible version of UHD,\n"
+ "or rebuild GR-UHD component against this ABI version.\n"
+ ) % UHD_VERSION_ABI_STRING % uhd::get_abi_string()));
+ #endif
+}
+
+#endif /* INCLUDED_GR_UHD_COMMON_H */
diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc
index 7d173d972..7e7875898 100644
--- a/gr-uhd/lib/gr_uhd_usrp_sink.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2011 Free Software Foundation, Inc.
+ * Copyright 2010-2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -23,6 +23,7 @@
#include <gr_io_signature.h>
#include <stdexcept>
#include <boost/make_shared.hpp>
+#include "gr_uhd_common.h"
static const pmt::pmt_t SOB_KEY = pmt::pmt_string_to_symbol("tx_sob");
static const pmt::pmt_t EOB_KEY = pmt::pmt_string_to_symbol("tx_eob");
@@ -56,7 +57,9 @@ public:
gr_make_io_signature(0, 0, 0)
),
_stream_args(stream_args),
- _nchan(std::max<size_t>(1, stream_args.channels.size()))
+ _nchan(std::max<size_t>(1, stream_args.channels.size())),
+ _stream_now(_nchan == 1),
+ _start_time_set(false)
{
if (stream_args.cpu_format == "fc32") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_FLOAT32);
if (stream_args.cpu_format == "sc16") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_INT16);
@@ -381,6 +384,12 @@ public:
}
}
+ void set_start_time(const uhd::time_spec_t &time){
+ _start_time = time;
+ _start_time_set = true;
+ _stream_now = false;
+ }
+
//Send an empty start-of-burst packet to begin streaming.
//Set at a time in the near future to avoid late packets.
bool start(void){
@@ -390,8 +399,14 @@ public:
_metadata.start_of_burst = true;
_metadata.end_of_burst = false;
- _metadata.has_time_spec = _nchan > 1;
- _metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01);
+ _metadata.has_time_spec = not _stream_now;
+ if (_start_time_set){
+ _start_time_set = false; //cleared for next run
+ _metadata.time_spec = _start_time;
+ }
+ else{
+ _metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01);
+ }
#ifdef GR_UHD_USE_STREAM_API
_tx_stream->send(
@@ -432,9 +447,13 @@ private:
uhd::tx_streamer::sptr _tx_stream;
#endif
size_t _nchan;
+ bool _stream_now;
uhd::tx_metadata_t _metadata;
double _sample_rate;
+ uhd::time_spec_t _start_time;
+ bool _start_time_set;
+
//stream tags related stuff
std::vector<gr_tag_t> _tags;
};
@@ -465,6 +484,7 @@ boost::shared_ptr<uhd_usrp_sink> uhd_make_usrp_sink(
const uhd::device_addr_t &device_addr,
const uhd::stream_args_t &stream_args
){
+ gr_uhd_check_abi();
return boost::shared_ptr<uhd_usrp_sink>(
new uhd_usrp_sink_impl(device_addr, stream_args)
);
diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc
index 5d3a3321e..b17481adc 100644
--- a/gr-uhd/lib/gr_uhd_usrp_source.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_source.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2011 Free Software Foundation, Inc.
+ * Copyright 2010-2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -25,6 +25,7 @@
#include <iostream>
#include <boost/format.hpp>
#include <boost/make_shared.hpp>
+#include "gr_uhd_common.h"
static const pmt::pmt_t TIME_KEY = pmt::pmt_string_to_symbol("rx_time");
@@ -58,7 +59,8 @@ public:
_stream_args(stream_args),
_nchan(std::max<size_t>(1, stream_args.channels.size())),
_stream_now(_nchan == 1),
- _tag_now(false)
+ _tag_now(false),
+ _start_time_set(false)
{
if (stream_args.cpu_format == "fc32") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_FLOAT32);
if (stream_args.cpu_format == "sc16") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_INT16);
@@ -371,6 +373,12 @@ public:
return num_samps;
}
+ void set_start_time(const uhd::time_spec_t &time){
+ _start_time = time;
+ _start_time_set = true;
+ _stream_now = false;
+ }
+
bool start(void){
#ifdef GR_UHD_USE_STREAM_API
_rx_stream = _dev->get_rx_stream(_stream_args);
@@ -380,7 +388,13 @@ public:
static const double reasonable_delay = 0.1; //order of magnitude over RTT
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
stream_cmd.stream_now = _stream_now;
- stream_cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay);
+ if (_start_time_set){
+ _start_time_set = false; //cleared for next run
+ stream_cmd.time_spec = _start_time;
+ }
+ else{
+ stream_cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay);
+ }
_dev->issue_stream_cmd(stream_cmd);
_tag_now = true;
return true;
@@ -418,17 +432,48 @@ public:
}
std::vector<std::complex<float> > finite_acquisition(const size_t nsamps){
+ if (_nchan != 1) throw std::runtime_error("finite_acquisition: usrp source has multiple channels, call finite_acquisition_v");
+ return finite_acquisition_v(nsamps).front();
+ }
+
+ std::vector<std::vector<std::complex<float> > > finite_acquisition_v(const size_t nsamps){
#ifdef GR_UHD_USE_STREAM_API
+
+ //kludgy way to ensure rx streamer exsists
+ if (!_rx_stream){
+ this->start();
+ this->stop();
+ }
+
+ //flush so there is no queued-up data
+ this->flush();
+
+ //create a multi-dimensional container to hold an array of sample buffers
+ std::vector<std::vector<std::complex<float> > > samps(_nchan, std::vector<std::complex<float> >(nsamps));
+
+ //load the void* vector of buffer pointers
+ std::vector<void *> buffs(_nchan);
+ for (size_t i = 0; i < _nchan; i++){
+ buffs[i] = &samps[i].front();
+ }
+
+ //tell the device to stream a finite amount
uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
cmd.num_samps = nsamps;
- cmd.stream_now = true;
+ cmd.stream_now = _stream_now;
+ static const double reasonable_delay = 0.1; //order of magnitude over RTT
+ cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay);
_dev->issue_stream_cmd(cmd);
- std::vector<std::complex<float> > samps(nsamps);
+ //receive samples until timeout
const size_t actual_num_samps = _rx_stream->recv(
- &samps.front(), nsamps, _metadata, 0.1
+ buffs, nsamps, _metadata, 1.0
);
- samps.resize(actual_num_samps);
+
+ //resize the resulting sample buffers
+ for (size_t i = 0; i < _nchan; i++){
+ samps[i].resize(actual_num_samps);
+ }
return samps;
#else
@@ -448,6 +493,9 @@ private:
bool _stream_now, _tag_now;
uhd::rx_metadata_t _metadata;
pmt::pmt_t _id;
+
+ uhd::time_spec_t _start_time;
+ bool _start_time_set;
};
@@ -477,6 +525,7 @@ boost::shared_ptr<uhd_usrp_source> uhd_make_usrp_source(
const uhd::device_addr_t &device_addr,
const uhd::stream_args_t &stream_args
){
+ gr_uhd_check_abi();
return boost::shared_ptr<uhd_usrp_source>(
new uhd_usrp_source_impl(device_addr, stream_args)
);
diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py
index d098a7b8a..82dbdd9e7 100644
--- a/gr-uhd/swig/__init__.py
+++ b/gr-uhd/swig/__init__.py
@@ -55,6 +55,10 @@ def _prepare_uhd_swig():
def __new__(self, *args): return str.__new__(self)
def __getitem__(self, key): return self.get(key)
def __setitem__(self, key, val): self.set(key, val)
+ def __init__(self, *args, **kwargs):
+ super(device_addr_t, self).__init__(*args)
+ if args and isinstance(args[0], device_addr_t):
+ for key in args[0].keys(): self[key] = args[0][key]
setattr(uhd_swig, 'device_addr_t', device_addr_t)
#make the streamer args take **kwargs on init