summaryrefslogtreecommitdiff
path: root/gr-uhd/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/lib')
-rw-r--r--gr-uhd/lib/CMakeLists.txt3
-rw-r--r--gr-uhd/lib/Makefile.am5
-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.cc37
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc69
6 files changed, 146 insertions, 14 deletions
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/Makefile.am b/gr-uhd/lib/Makefile.am
index c322c6124..41ce79d87 100644
--- a/gr-uhd/lib/Makefile.am
+++ b/gr-uhd/lib/Makefile.am
@@ -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 @@ AM_CPPFLAGS = \
$(STD_DEFINES_AND_INCLUDES) \
$(WITH_INCLUDES) \
$(UHD_CPPFLAGS) \
+ -I$(srcdir) \
-Dgnuradio_uhd_EXPORTS
lib_LTLIBRARIES = libgnuradio-uhd.la
@@ -40,4 +41,4 @@ libgnuradio_uhd_la_LIBADD = \
libgnuradio_uhd_la_LDFLAGS = $(NO_UNDEFINED) $(LTVERSIONFLAGS)
-noinst_HEADERS =
+noinst_HEADERS = gr_uhd_common.h
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 05237100c..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);
@@ -278,6 +281,15 @@ public:
return _dev;
}
+ void set_user_register(const uint8_t addr, const uint32_t data, size_t mboard){
+ #ifdef UHD_USRP_MULTI_USRP_USER_REGS_API
+ _dev->set_user_register(addr, data, mboard);
+ #else
+ throw std::runtime_error("not implemented in this version");
+ #endif
+ }
+
+
/***********************************************************************
* Work
**********************************************************************/
@@ -372,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){
@@ -381,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(
@@ -423,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;
};
@@ -456,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 c599b2b3d..bd7f4e21d 100644
--- a/gr-uhd/lib/gr_uhd_usrp_source.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_source.cc
@@ -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);
@@ -290,6 +292,14 @@ public:
return _dev;
}
+ void set_user_register(const uint8_t addr, const uint32_t data, size_t mboard){
+ #ifdef UHD_USRP_MULTI_USRP_USER_REGS_API
+ _dev->set_user_register(addr, data, mboard);
+ #else
+ throw std::runtime_error("not implemented in this version");
+ #endif
+ }
+
/***********************************************************************
* Work
**********************************************************************/
@@ -363,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);
@@ -372,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;
@@ -410,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
@@ -440,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;
};
@@ -469,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)
);