summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-19 22:23:46 -0800
committerJosh Blum <josh@joshknows.com>2011-01-19 22:23:46 -0800
commit9239878b0b81c3a368bf11cfc2fe48bfb05ff902 (patch)
treef41a5e58eac89b35cb99537a0a0b64662384a9f2 /host/include
parentfc138381ee4bd8d191795230b7447071a85e1f28 (diff)
parent7d918c5f6acc9a5d2c8ae03e2e67b403f7efd5ff (diff)
downloaduhd-9239878b0b81c3a368bf11cfc2fe48bfb05ff902.tar.gz
uhd-9239878b0b81c3a368bf11cfc2fe48bfb05ff902.tar.bz2
uhd-9239878b0b81c3a368bf11cfc2fe48bfb05ff902.zip
Merge branch 'next'
Conflicts: host/lib/usrp/usrp2/codec_impl.cpp
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/CMakeLists.txt3
-rw-r--r--host/include/uhd/config.hpp92
-rw-r--r--host/include/uhd/convert.hpp90
-rw-r--r--host/include/uhd/transport/CMakeLists.txt7
-rw-r--r--host/include/uhd/transport/alignment_buffer.hpp69
-rw-r--r--host/include/uhd/transport/alignment_buffer.ipp144
-rw-r--r--host/include/uhd/transport/bounded_buffer.ipp13
-rw-r--r--host/include/uhd/transport/buffer_pool.hpp59
-rw-r--r--host/include/uhd/transport/convert_types.hpp96
-rw-r--r--host/include/uhd/transport/convert_types.ipp43
-rw-r--r--host/include/uhd/transport/if_addrs.hpp8
-rw-r--r--host/include/uhd/types/CMakeLists.txt4
-rw-r--r--host/include/uhd/types/clock_config.hpp9
-rw-r--r--host/include/uhd/types/dict.hpp24
-rw-r--r--host/include/uhd/types/dict.ipp23
-rw-r--r--host/include/uhd/types/ranges.hpp44
-rw-r--r--host/include/uhd/types/ranges.ipp188
-rw-r--r--host/include/uhd/types/sensors.hpp131
-rw-r--r--host/include/uhd/usrp/CMakeLists.txt1
-rw-r--r--host/include/uhd/usrp/codec_props.hpp6
-rw-r--r--host/include/uhd/usrp/dboard_iface.hpp8
-rw-r--r--host/include/uhd/usrp/gps_ctrl.hpp56
-rw-r--r--host/include/uhd/usrp/mboard_props.hpp2
-rw-r--r--host/include/uhd/usrp/multi_usrp.hpp40
-rw-r--r--host/include/uhd/usrp/single_usrp.hpp28
-rw-r--r--host/include/uhd/usrp/subdev_props.hpp6
-rw-r--r--host/include/uhd/utils/algorithm.hpp31
-rw-r--r--host/include/uhd/utils/gain_group.hpp10
-rw-r--r--host/include/uhd/utils/static.hpp15
29 files changed, 519 insertions, 731 deletions
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt
index ad528c9fb..fee1270e9 100644
--- a/host/include/uhd/CMakeLists.txt
+++ b/host/include/uhd/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010 Ettus Research LLC
+# Copyright 2010-2011 Ettus Research LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@ ADD_SUBDIRECTORY(utils)
INSTALL(FILES
config.hpp
+ convert.hpp
device.hpp
device.ipp
version.hpp
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp
index 9a29fb246..912fbc204 100644
--- a/host/include/uhd/config.hpp
+++ b/host/include/uhd/config.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -18,9 +18,10 @@
#ifndef INCLUDED_UHD_CONFIG_HPP
#define INCLUDED_UHD_CONFIG_HPP
-// suppress warnings
#include <boost/config.hpp>
+
#ifdef BOOST_MSVC
+// suppress warnings
//# pragma warning(push)
//# pragma warning(disable: 4511) // copy constructor can't not be generated
//# pragma warning(disable: 4512) // assignment operator can't not be generated
@@ -37,76 +38,43 @@
//# pragma warning(disable: 4511) // 'class' : copy constructor could not be generated
//# pragma warning(disable: 4250) // 'class' : inherits 'method' via dominance
# pragma warning(disable: 4200) // nonstandard extension used : zero-sized array in struct/union
-#endif
// define logical operators
-#ifdef BOOST_MSVC
- #include <ciso646>
-#endif
+#include <ciso646>
// define ssize_t
-#ifdef BOOST_MSVC
- #include <cstddef>
- typedef ptrdiff_t ssize_t;
-#endif
-
-// http://gcc.gnu.org/wiki/Visibility
-// Generic helper definitions for shared library support
-#if defined(BOOST_HAS_DECLSPEC)
- #define UHD_HELPER_DLL_IMPORT __declspec(dllimport)
- #define UHD_HELPER_DLL_EXPORT __declspec(dllexport)
- #define UHD_HELPER_DLL_LOCAL
- #define UHD_HELPER_EXIM_TMPL
-#elif defined(__GNUG__) && __GNUG__ >= 4
- #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default")))
- #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default")))
- #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden")))
- #define UHD_HELPER_EXIM_TMPL extern
-#else
- #define UHD_HELPER_DLL_IMPORT
- #define UHD_HELPER_DLL_EXPORT
- #define UHD_HELPER_DLL_LOCAL
- #define UHD_HELPER_EXIM_TMPL extern
-#endif
-
-// Now we use the generic helper definitions above to define UHD_API and UHD_LOCAL.
-// UHD_API is used for the public API symbols. It either DLL imports or DLL exports (or does nothing for static build)
-// UHD_LOCAL is used for non-api symbols.
-
-#define UHD_DLL // defined here, put into configuration if we need to make static libs
+#include <cstddef>
+typedef ptrdiff_t ssize_t;
-#ifdef UHD_DLL // defined if UHD is compiled as a DLL
- #ifdef UHD_DLL_EXPORTS // defined if we are building the UHD DLL (instead of using it)
- #define UHD_API UHD_HELPER_DLL_EXPORT
- #define UHD_EXIM_TMPL UHD_HELPER_EXIM_TMPL
- #else
- #define UHD_API UHD_HELPER_DLL_IMPORT
- #define UHD_EXIM_TMPL UHD_HELPER_EXIM_TMPL
- #endif // UHD_DLL_EXPORTS
- #define UHD_LOCAL UHD_HELPER_DLL_LOCAL
-#else // UHD_DLL is not defined: this means UHD is a static lib.
- #define UHD_API
- #define UHD_LOCAL
- #define UHD_EXIM_TMPL
-#endif // UHD_DLL
+#endif //BOOST_MSVC
-// Define force inline macro
-#if defined(BOOST_MSVC)
- #define UHD_INLINE __forceinline
+//define cross platform attribute macros
+#if defined(BOOST_MSVC) || defined(BOOST_HAS_DECLSPEC)
+ #define UHD_EXPORT __declspec(dllexport)
+ #define UHD_IMPORT __declspec(dllimport)
+ #define UHD_INLINE __forceinline
+ #define UHD_DEPRECATED __declspec(deprecated)
+ #define UHD_ALIGNED(x) __declspec(align(x))
#elif defined(__GNUG__) && __GNUG__ >= 4
- #define UHD_INLINE inline __attribute__((always_inline))
+ #define UHD_EXPORT __attribute__((visibility("default")))
+ #define UHD_IMPORT __attribute__((visibility("default")))
+ #define UHD_INLINE inline __attribute__((always_inline))
+ #define UHD_DEPRECATED __attribute__((deprecated))
+ #define UHD_ALIGNED(x) __attribute__((aligned(x)))
#else
- #define UHD_INLINE inline
+ #define UHD_EXPORT
+ #define UHD_IMPORT
+ #define UHD_INLINE inline
+ #define UHD_DEPRECATED
+ #define UHD_ALIGNED(x)
#endif
-// Define deprecated attribute macro
-#if defined(BOOST_MSVC)
- #define UHD_DEPRECATED __declspec(deprecated)
-#elif defined(__GNUG__) && __GNUG__ >= 4
- #define UHD_DEPRECATED __attribute__ ((deprecated))
+// Define API declaration macro
+#ifdef UHD_DLL_EXPORTS
+ #define UHD_API UHD_EXPORT
#else
- #define UHD_DEPRECATED
-#endif
+ #define UHD_API UHD_IMPORT
+#endif // UHD_DLL_EXPORTS
// Platform defines for conditional parts of headers:
// Taken from boost/config/select_platform_config.hpp,
@@ -117,6 +85,8 @@
#define UHD_PLATFORM_WIN32
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
#define UHD_PLATFORM_MACOS
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ #define UHD_PLATFORM_BSD
#endif
#endif /* INCLUDED_UHD_CONFIG_HPP */
diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp
new file mode 100644
index 000000000..bfe8c8267
--- /dev/null
+++ b/host/include/uhd/convert.hpp
@@ -0,0 +1,90 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program 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 of the License, or
+// (at your option) any later version.
+//
+// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_CONVERT_HPP
+#define INCLUDED_UHD_CONVERT_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/types/io_type.hpp>
+#include <uhd/types/otw_type.hpp>
+#include <boost/function.hpp>
+#include <string>
+#include <vector>
+
+namespace uhd{ namespace convert{
+
+ typedef std::vector<void *> output_type;
+ typedef std::vector<const void *> input_type;
+ typedef boost::function<void(input_type&, output_type&, size_t)> function_type;
+
+ /*!
+ * Describe the priority of a converter function.
+ * A higher priority function takes precedence.
+ * The general case function are the lowest.
+ * Next comes the liborc implementations.
+ * Custom intrinsics implementations are highest.
+ */
+ enum priority_type{
+ PRIORITY_GENERAL = 0,
+ PRIORITY_LIBORC = 1,
+ PRIORITY_CUSTOM = 2,
+ PRIORITY_EMPTY = -1,
+ };
+
+ /*!
+ * Register a converter function that converts cpu type to/from otw type.
+ * \param markup representing the signature
+ * \param fcn a pointer to the converter
+ * \param prio the function priority
+ */
+ UHD_API void register_converter(
+ const std::string &markup,
+ function_type fcn,
+ priority_type prio
+ );
+
+ /*!
+ * Get a converter function that converts cpu to otw.
+ * \param io_type the type of the input samples
+ * \param otw_type the type of the output samples
+ * \param num_input_buffs the number of inputs
+ * \param num_output_buffs the number of outputs
+ */
+ UHD_API const function_type &get_converter_cpu_to_otw(
+ const io_type_t &io_type,
+ const otw_type_t &otw_type,
+ size_t num_input_buffs,
+ size_t num_output_buffs
+ );
+
+ /*!
+ * Get a converter function that converts otw to cpu.
+ * \param io_type the type of the input samples
+ * \param otw_type the type of the output samples
+ * \param num_input_buffs the number of inputs
+ * \param num_output_buffs the number of outputs
+ */
+ UHD_API const function_type &get_converter_otw_to_cpu(
+ const io_type_t &io_type,
+ const otw_type_t &otw_type,
+ size_t num_input_buffs,
+ size_t num_output_buffs
+ );
+
+}} //namespace
+
+#endif /* INCLUDED_UHD_CONVERT_HPP */
diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt
index 2c84c0724..14ca82226 100644
--- a/host/include/uhd/transport/CMakeLists.txt
+++ b/host/include/uhd/transport/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010 Ettus Research LLC
+# Copyright 2010-2011 Ettus Research LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,12 +17,9 @@
INSTALL(FILES
- alignment_buffer.hpp
- alignment_buffer.ipp
bounded_buffer.hpp
bounded_buffer.ipp
- convert_types.hpp
- convert_types.ipp
+ buffer_pool.hpp
if_addrs.hpp
udp_simple.hpp
udp_zero_copy.hpp
diff --git a/host/include/uhd/transport/alignment_buffer.hpp b/host/include/uhd/transport/alignment_buffer.hpp
deleted file mode 100644
index f44a037f8..000000000
--- a/host/include/uhd/transport/alignment_buffer.hpp
+++ /dev/null
@@ -1,69 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_HPP
-#define INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_HPP
-
-#include <uhd/config.hpp>
-#include <uhd/transport/bounded_buffer.hpp> //time_duration_t
-#include <boost/shared_ptr.hpp>
-#include <vector>
-
-namespace uhd{ namespace transport{
-
- /*!
- * Implement a templated alignment buffer:
- * Used for aligning asynchronously pushed elements with matching ids.
- */
- template <typename elem_type, typename seq_type> class alignment_buffer{
- public:
- typedef boost::shared_ptr<alignment_buffer<elem_type, seq_type> > sptr;
-
- /*!
- * Make a new alignment buffer object.
- * \param capacity the maximum elements per index
- * \param width the number of elements to align
- */
- static sptr make(size_t capacity, size_t width);
-
- /*!
- * Push an element with sequence id into the buffer at index.
- * \param elem the element to push
- * \param seq the sequence identifier
- * \param index the buffer index
- * \return true if the element fit without popping for space
- */
- virtual bool push_with_pop_on_full(
- const elem_type &elem, const seq_type &seq, size_t index
- ) = 0;
-
- /*!
- * Pop an aligned set of elements from this alignment buffer.
- * \param elems a collection to store the aligned elements
- * \param timeout the timeout in seconds
- * \return false when the operation times out
- */
- virtual bool pop_elems_with_timed_wait(
- std::vector<elem_type> &elems, double timeout
- ) = 0;
- };
-
-}} //namespace
-
-#include <uhd/transport/alignment_buffer.ipp>
-
-#endif /* INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_HPP */
diff --git a/host/include/uhd/transport/alignment_buffer.ipp b/host/include/uhd/transport/alignment_buffer.ipp
deleted file mode 100644
index 833b5d399..000000000
--- a/host/include/uhd/transport/alignment_buffer.ipp
+++ /dev/null
@@ -1,144 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_IPP
-#define INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_IPP
-
-#include <uhd/transport/bounded_buffer.hpp>
-#include <boost/thread/condition_variable.hpp>
-#include <utility>
-
-namespace uhd{ namespace transport{ namespace{ /*anon*/
-
- /*!
- * Imlement a templated alignment buffer:
- * Used for aligning asynchronously pushed elements with matching ids.
- */
- template <typename elem_type, typename seq_type>
- class alignment_buffer_impl : public alignment_buffer<elem_type, seq_type>{
- public:
-
- alignment_buffer_impl(size_t capacity, size_t width) : _last_seqs(width){
- for (size_t i = 0; i < width; i++){
- _buffs.push_back(bounded_buffer<buff_contents_type>::make(capacity));
- _all_indexes.push_back(i);
- }
- _there_was_a_clear = false;
- }
-
- UHD_INLINE bool push_with_pop_on_full(
- const elem_type &elem, const seq_type &seq, size_t index
- ){
- //clear the buffer for this index if the seqs are mis-ordered
- if (seq < _last_seqs[index]){
- _buffs[index]->clear();
- _there_was_a_clear = true;
- } _last_seqs[index] = seq;
- return _buffs[index]->push_with_pop_on_full(buff_contents_type(elem, seq));
- }
-
- UHD_INLINE bool pop_elems_with_timed_wait(
- std::vector<elem_type> &elems, double timeout
- ){
- boost::system_time exit_time = boost::get_system_time() + to_time_dur(timeout);
- buff_contents_type buff_contents_tmp;
- std::list<size_t> indexes_to_do(_all_indexes);
-
- //do an initial pop to load an initial sequence id
- size_t index = indexes_to_do.front();
- if (not _buffs[index]->pop_with_timed_wait(
- buff_contents_tmp, from_time_dur(exit_time - boost::get_system_time())
- )) return false;
- elems[index] = buff_contents_tmp.first;
- seq_type expected_seq_id = buff_contents_tmp.second;
- indexes_to_do.pop_front();
-
- //get an aligned set of elements from the buffers:
- while(indexes_to_do.size() != 0){
-
- //respond to a clear by starting from scratch
- if(_there_was_a_clear){
- _there_was_a_clear = false;
- indexes_to_do = _all_indexes;
- index = indexes_to_do.front();
- if (not _buffs[index]->pop_with_timed_wait(
- buff_contents_tmp, from_time_dur(exit_time - boost::get_system_time())
- )) return false;
- elems[index] = buff_contents_tmp.first;
- expected_seq_id = buff_contents_tmp.second;
- indexes_to_do.pop_front();
- }
-
- //pop an element off for this index
- index = indexes_to_do.front();
- if (not _buffs[index]->pop_with_timed_wait(
- buff_contents_tmp, from_time_dur(exit_time - boost::get_system_time())
- )) return false;
-
- //if the sequence id matches:
- // store the popped element into the output,
- // remove this index from the list and continue
- if (buff_contents_tmp.second == expected_seq_id){
- elems[index] = buff_contents_tmp.first;
- indexes_to_do.pop_front();
- continue;
- }
-
- //if the sequence id is older:
- // continue with the same index to try again
- if (buff_contents_tmp.second < expected_seq_id){
- continue;
- }
-
- //if the sequence id is newer:
- // store the popped element into the output,
- // add all other indexes back into the list
- if (buff_contents_tmp.second > expected_seq_id){
- elems[index] = buff_contents_tmp.first;
- expected_seq_id = buff_contents_tmp.second;
- indexes_to_do = _all_indexes;
- indexes_to_do.remove(index);
- continue;
- }
- }
- return true;
- }
-
- private:
- //a vector of bounded buffers for each index
- typedef std::pair<elem_type, seq_type> buff_contents_type;
- std::vector<typename bounded_buffer<buff_contents_type>::sptr> _buffs;
- std::vector<seq_type> _last_seqs;
- std::list<size_t> _all_indexes;
- bool _there_was_a_clear;
- };
-
-}}} //namespace
-
-namespace uhd{ namespace transport{
-
- template <typename elem_type, typename seq_type>
- typename alignment_buffer<elem_type, seq_type>::sptr
- alignment_buffer<elem_type, seq_type>::make(size_t capacity, size_t width){
- return typename alignment_buffer<elem_type, seq_type>::sptr(
- new alignment_buffer_impl<elem_type, seq_type>(capacity, width)
- );
- }
-
-}} //namespace
-
-#endif /* INCLUDED_UHD_TRANSPORT_ALIGNMENT_BUFFER_IPP */
diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp
index edc7faa06..f7915d866 100644
--- a/host/include/uhd/transport/bounded_buffer.ipp
+++ b/host/include/uhd/transport/bounded_buffer.ipp
@@ -26,14 +26,6 @@
namespace uhd{ namespace transport{ namespace{ /*anon*/
- static UHD_INLINE boost::posix_time::time_duration to_time_dur(double timeout){
- return boost::posix_time::microseconds(long(timeout*1e6));
- }
-
- static UHD_INLINE double from_time_dur(const boost::posix_time::time_duration &time_dur){
- return 1e-6*time_dur.total_microseconds();
- }
-
template <typename elem_type>
class bounded_buffer_impl : public bounded_buffer<elem_type>{
public:
@@ -127,6 +119,11 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
_buffer.pop_back();
return elem;
}
+
+ static UHD_INLINE boost::posix_time::time_duration to_time_dur(double timeout){
+ return boost::posix_time::microseconds(long(timeout*1e6));
+ }
+
};
}}} //namespace
diff --git a/host/include/uhd/transport/buffer_pool.hpp b/host/include/uhd/transport/buffer_pool.hpp
new file mode 100644
index 000000000..84a338097
--- /dev/null
+++ b/host/include/uhd/transport/buffer_pool.hpp
@@ -0,0 +1,59 @@
+//
+// Copyright 2011-2011 Ettus Research LLC
+//
+// This program 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 of the License, or
+// (at your option) any later version.
+//
+// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_TRANSPORT_BUFFER_POOL_HPP
+#define INCLUDED_UHD_TRANSPORT_BUFFER_POOL_HPP
+
+#include <uhd/config.hpp>
+#include <boost/utility.hpp>
+#include <boost/shared_ptr.hpp>
+
+namespace uhd{ namespace transport{
+
+ /*!
+ * A buffer pool manages memory for a homogeneous set of buffers.
+ * Each buffer is the pool start at a 16-byte alignment boundary.
+ */
+ class UHD_API buffer_pool : boost::noncopyable{
+ public:
+ typedef boost::shared_ptr<buffer_pool> sptr;
+ typedef void * ptr_type;
+
+ /*!
+ * Make a new buffer pool.
+ * \param num_buffs the number of buffers to allocate
+ * \param buff_size the size of each buffer in bytes
+ * \param alignment the alignment boundary in bytes
+ * \return a new buffer pool buff_size X num_buffs
+ */
+ static sptr make(
+ const size_t num_buffs,
+ const size_t buff_size,
+ const size_t alignment = 16
+ );
+
+ //! Get a pointer to the buffer start at the specified index
+ virtual ptr_type at(const size_t index) const = 0;
+
+ //! Get the number of buffers in this pool
+ virtual size_t size(void) const = 0;
+ };
+
+}} //namespace
+
+
+#endif /* INCLUDED_UHD_TRANSPORT_BUFFER_POOL_HPP */
diff --git a/host/include/uhd/transport/convert_types.hpp b/host/include/uhd/transport/convert_types.hpp
deleted file mode 100644
index dc7fa6c1a..000000000
--- a/host/include/uhd/transport/convert_types.hpp
+++ /dev/null
@@ -1,96 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_HPP
-#define INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_HPP
-
-#include <uhd/config.hpp>
-#include <uhd/types/io_type.hpp>
-#include <uhd/types/otw_type.hpp>
-#include <vector>
-
-namespace uhd{ namespace transport{
-
-/*!
- * Convert IO samples to OWT samples.
- *
- * \param io_buff memory containing samples
- * \param io_type the type of these samples
- * \param otw_buff memory to write converted samples
- * \param otw_type the type of these samples
- * \param num_samps the number of samples in io_buff
- */
-UHD_API void convert_io_type_to_otw_type(
- const void *io_buff, const io_type_t &io_type,
- void *otw_buff, const otw_type_t &otw_type,
- size_t num_samps
-);
-
-/*!
- * Convert IO samples to OWT samples + interleave.
- *
- * \param io_buffs buffers containing samples
- * \param io_type the type of these samples
- * \param otw_buff memory to write converted samples
- * \param otw_type the type of these samples
- * \param nsamps_per_io_buff samples per io_buff
- */
-UHD_API void convert_io_type_to_otw_type(
- const std::vector<const void *> &io_buffs,
- const io_type_t &io_type,
- void *otw_buff,
- const otw_type_t &otw_type,
- size_t nsamps_per_io_buff
-);
-
-/*!
- * Convert OTW samples to IO samples.
- *
- * \param otw_buff memory containing samples
- * \param otw_type the type of these samples
- * \param io_buff memory to write converted samples
- * \param io_type the type of these samples
- * \param num_samps the number of samples in io_buff
- */
-UHD_API void convert_otw_type_to_io_type(
- const void *otw_buff, const otw_type_t &otw_type,
- void *io_buff, const io_type_t &io_type,
- size_t num_samps
-);
-
-/*!
- * Convert OTW samples to IO samples + de-interleave.
- *
- * \param otw_buff memory containing samples
- * \param otw_type the type of these samples
- * \param io_buffs buffers to write converted samples
- * \param io_type the type of these samples
- * \param nsamps_per_io_buff samples per io_buff
- */
-UHD_API void convert_otw_type_to_io_type(
- const void *otw_buff,
- const otw_type_t &otw_type,
- std::vector<void *> &io_buffs,
- const io_type_t &io_type,
- size_t nsamps_per_io_buff
-);
-
-}} //namespace
-
-#include <uhd/transport/convert_types.ipp>
-
-#endif /* INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_HPP */
diff --git a/host/include/uhd/transport/convert_types.ipp b/host/include/uhd/transport/convert_types.ipp
deleted file mode 100644
index 914ca6f17..000000000
--- a/host/include/uhd/transport/convert_types.ipp
+++ /dev/null
@@ -1,43 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP
-#define INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP
-
-UHD_INLINE void uhd::transport::convert_io_type_to_otw_type(
- const void *io_buff, const io_type_t &io_type,
- void *otw_buff, const otw_type_t &otw_type,
- size_t num_samps
-){
- std::vector<const void *> buffs(1, io_buff);
- return uhd::transport::convert_io_type_to_otw_type(
- buffs, io_type, otw_buff, otw_type, num_samps
- );
-}
-
-UHD_INLINE void uhd::transport::convert_otw_type_to_io_type(
- const void *otw_buff, const otw_type_t &otw_type,
- void *io_buff, const io_type_t &io_type,
- size_t num_samps
-){
- std::vector<void *> buffs(1, io_buff);
- return uhd::transport::convert_otw_type_to_io_type(
- otw_buff, otw_type, buffs, io_type, num_samps
- );
-}
-
-#endif /* INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP */
diff --git a/host/include/uhd/transport/if_addrs.hpp b/host/include/uhd/transport/if_addrs.hpp
index fbbb35e1d..c831750d7 100644
--- a/host/include/uhd/transport/if_addrs.hpp
+++ b/host/include/uhd/transport/if_addrs.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -15,8 +15,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#ifndef INCLUDED_UHD_IFADDRS_HPP
-#define INCLUDED_UHD_IFADDRS_HPP
+#ifndef INCLUDED_UHD_TRANSPORT_IF_ADDRS_HPP
+#define INCLUDED_UHD_TRANSPORT_IF_ADDRS_HPP
#include <uhd/config.hpp>
#include <string>
@@ -44,4 +44,4 @@ namespace uhd{ namespace transport{
}} //namespace
-#endif /* INCLUDED_UHD_IFADDRS_HPP */
+#endif /* INCLUDED_UHD_TRANSPORT_IF_ADDRS_HPP */
diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt
index 1d2c0c41c..51be164aa 100644
--- a/host/include/uhd/types/CMakeLists.txt
+++ b/host/include/uhd/types/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010 Ettus Research LLC
+# Copyright 2010-2011 Ettus Research LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,8 +25,8 @@ INSTALL(FILES
mac_addr.hpp
metadata.hpp
otw_type.hpp
- ranges.ipp
ranges.hpp
+ sensors.hpp
serial.hpp
stream_cmd.hpp
time_spec.hpp
diff --git a/host/include/uhd/types/clock_config.hpp b/host/include/uhd/types/clock_config.hpp
index 9342fbb7b..a72eb63de 100644
--- a/host/include/uhd/types/clock_config.hpp
+++ b/host/include/uhd/types/clock_config.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -28,16 +28,19 @@ namespace uhd{
* The source and polarity for the PPS clock.
*/
struct UHD_API clock_config_t{
+ //------ simple usage --------//
+ static clock_config_t external(void);
+ static clock_config_t internal(void);
+
+ //------ advanced usage --------//
enum ref_source_t {
REF_AUTO = 'a', //automatic (device specific)
REF_INT = 'i', //internal reference
REF_SMA = 's', //external sma port
- REF_MIMO = 'm' //mimo cable (usrp2 only)
} ref_source;
enum pps_source_t {
PPS_INT = 'i', //there is no internal
PPS_SMA = 's', //external sma port
- PPS_MIMO = 'm' //mimo cable (usrp2 only)
} pps_source;
enum pps_polarity_t {
PPS_NEG = 'n', //negative edge
diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp
index 6166140a0..97fa8f09c 100644
--- a/host/include/uhd/types/dict.hpp
+++ b/host/include/uhd/types/dict.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -54,14 +54,14 @@ namespace uhd{
* Key order depends on insertion precedence.
* \return vector of keys
*/
- const std::vector<Key> keys(void) const;
+ std::vector<Key> keys(void) const;
/*!
* Get a list of the values in this dict.
* Value order depends on insertion precedence.
* \return vector of values
*/
- const std::vector<Val> vals(void) const;
+ std::vector<Val> vals(void) const;
/*!
* Does the dictionary contain this key?
@@ -73,10 +73,24 @@ namespace uhd{
/*!
* Get a value in the dict or default.
* \param key the key to look for
- * \param def use if key not found
+ * \param other use if key not found
* \return the value or default
*/
- const Val &get(const Key &key, const Val &def) const;
+ const Val &get(const Key &key, const Val &other) const;
+
+ /*!
+ * Get a value in the dict or throw.
+ * \param key the key to look for
+ * \return the value or default
+ */
+ const Val &get(const Key &key) const;
+
+ /*!
+ * Set a value in the dict at the key.
+ * \param key the key to set at
+ * \param val the value to set
+ */
+ void set(const Key &key, const Val &val);
/*!
* Get a value for the given key if it exists.
diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp
index f037d7988..0c014474e 100644
--- a/host/include/uhd/types/dict.ipp
+++ b/host/include/uhd/types/dict.ipp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -59,7 +59,7 @@ namespace uhd{
}
template <typename Key, typename Val>
- const std::vector<Key> dict<Key, Val>::keys(void) const{
+ std::vector<Key> dict<Key, Val>::keys(void) const{
std::vector<Key> keys;
BOOST_FOREACH(const pair_t &p, _map){
keys.push_back(p.first);
@@ -68,7 +68,7 @@ namespace uhd{
}
template <typename Key, typename Val>
- const std::vector<Val> dict<Key, Val>::vals(void) const{
+ std::vector<Val> dict<Key, Val>::vals(void) const{
std::vector<Val> vals;
BOOST_FOREACH(const pair_t &p, _map){
vals.push_back(p.second);
@@ -85,11 +85,24 @@ namespace uhd{
}
template <typename Key, typename Val>
- const Val &dict<Key, Val>::get(const Key &key, const Val &def) const{
+ const Val &dict<Key, Val>::get(const Key &key, const Val &other) const{
BOOST_FOREACH(const pair_t &p, _map){
if (p.first == key) return p.second;
}
- return def;
+ return other;
+ }
+
+ template <typename Key, typename Val>
+ const Val &dict<Key, Val>::get(const Key &key) const{
+ BOOST_FOREACH(const pair_t &p, _map){
+ if (p.first == key) return p.second;
+ }
+ throw key_not_found<Key, Val>(key);
+ }
+
+ template <typename Key, typename Val>
+ void dict<Key, Val>::set(const Key &key, const Val &val){
+ (*this)[key] = val;
}
template <typename Key, typename Val>
diff --git a/host/include/uhd/types/ranges.hpp b/host/include/uhd/types/ranges.hpp
index 366efb1f3..f0d0e1c0b 100644
--- a/host/include/uhd/types/ranges.hpp
+++ b/host/include/uhd/types/ranges.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -22,7 +22,6 @@
#include <uhd/utils/pimpl.hpp>
#include <string>
#include <vector>
-#include <string>
namespace uhd{
@@ -30,14 +29,15 @@ namespace uhd{
* A range object describes a set of discrete values of the form:
* y = start + step*n, where n is an integer between 0 and (stop - start)/step
*/
- template <typename T> class range_t{
+ class UHD_API range_t{
public:
+
/*!
* Create a range from a single value.
* The step size will be taken as zero.
* \param value the only possible value in this range
*/
- range_t(const T &value = T(0));
+ range_t(double value = 0);
/*!
* Create a range from a full set of values.
@@ -46,28 +46,27 @@ namespace uhd{
* \param stop the maximum value for this range
* \param step the step size for this range
*/
- range_t(const T &start, const T &stop, const T &step = T(0));
+ range_t(double start, double stop, double step = 0);
//! Get the start value for this range.
- const T start(void) const;
+ double start(void) const;
//! Get the stop value for this range.
- const T stop(void) const;
+ double stop(void) const;
//! Get the step value for this range.
- const T step(void) const;
+ double step(void) const;
//! Convert this range to a printable string
const std::string to_pp_string(void) const;
- private:
- UHD_PIMPL_DECL(impl) _impl;
+ private: UHD_PIMPL_DECL(impl) _impl;
};
/*!
* A meta-range object holds a list of individual ranges.
*/
- template <typename T> struct meta_range_t : std::vector<range_t<T> >{
+ struct UHD_API meta_range_t : std::vector<range_t>{
//! A default constructor for an empty meta-range
meta_range_t(void);
@@ -79,7 +78,8 @@ namespace uhd{
* \param last the end iterator
*/
template <typename InputIterator>
- meta_range_t(InputIterator first, InputIterator last);
+ meta_range_t(InputIterator first, InputIterator last):
+ std::vector<range_t>(first, last){ /* NOP */ }
/*!
* A convenience constructor for a single range.
@@ -88,16 +88,16 @@ namespace uhd{
* \param stop the maximum value for this range
* \param step the step size for this range
*/
- meta_range_t(const T &start, const T &stop, const T &step = T(0));
+ meta_range_t(double start, double stop, double step = 0);
//! Get the overall start value for this meta-range.
- const T start(void) const;
+ double start(void) const;
//! Get the overall stop value for this meta-range.
- const T stop(void) const;
+ double stop(void) const;
//! Get the overall step value for this meta-range.
- const T step(void) const;
+ double step(void) const;
/*!
* Clip the target value to a possible range value.
@@ -105,22 +105,16 @@ namespace uhd{
* \param clip_step if true, clip to steps as well
* \return a value that is in one of the ranges
*/
- const T clip(const T &value, bool clip_step = false) const;
+ double clip(double value, bool clip_step = false) const;
//! Convert this meta-range to a printable string
const std::string to_pp_string(void) const;
};
- //!typedef for a gain meta-range
- typedef meta_range_t<float> gain_range_t;
-
- //!typedef for a frequency meta-range
- typedef meta_range_t<double> freq_range_t;
-
+ typedef meta_range_t gain_range_t;
+ typedef meta_range_t freq_range_t;
} //namespace uhd
-#include <uhd/types/ranges.ipp>
-
#endif /* INCLUDED_UHD_TYPES_RANGES_HPP */
diff --git a/host/include/uhd/types/ranges.ipp b/host/include/uhd/types/ranges.ipp
deleted file mode 100644
index 944ada51f..000000000
--- a/host/include/uhd/types/ranges.ipp
+++ /dev/null
@@ -1,188 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_TYPES_RANGES_IPP
-#define INCLUDED_UHD_TYPES_RANGES_IPP
-
-#include <boost/math/special_functions/round.hpp>
-#include <boost/foreach.hpp>
-#include <algorithm>
-#include <stdexcept>
-#include <sstream>
-
-namespace uhd{
-
- /*******************************************************************
- * range_t implementation code
- ******************************************************************/
- template <typename T> struct range_t<T>::impl{
- impl(const T &start, const T &stop, const T &step):
- start(start), stop(stop), step(step)
- {
- /* NOP */
- }
- const T start, stop, step;
- };
-
- template <typename T> range_t<T>::range_t(const T &value):
- _impl(UHD_PIMPL_MAKE(impl, (value, value, T(0))))
- {
- /* NOP */
- }
-
- template <typename T> range_t<T>::range_t(
- const T &start, const T &stop, const T &step
- ):
- _impl(UHD_PIMPL_MAKE(impl, (start, stop, step)))
- {
- if (stop < start){
- throw std::invalid_argument("cannot make range where stop < start");
- }
- }
-
- template <typename T> const T range_t<T>::start(void) const{
- return _impl->start;
- }
-
- template <typename T> const T range_t<T>::stop(void) const{
- return _impl->stop;
- }
-
- template <typename T> const T range_t<T>::step(void) const{
- return _impl->step;
- }
-
- template <typename T> const std::string range_t<T>::to_pp_string(void) const{
- std::stringstream ss;
- ss << "(" << this->start();
- if (this->start() != this->stop()) ss << ", " << this->stop();
- if (this->step() != T(0)) ss << ", " << this->step();
- ss << ")";
- return ss.str();
- }
-
- /*******************************************************************
- * meta_range_t implementation code
- ******************************************************************/
-
- namespace /*anon*/{
- template <typename T> inline
- void check_meta_range_monotonic(const meta_range_t<T> &mr){
- if (mr.empty()){
- throw std::runtime_error("meta-range cannot be empty");
- }
- for (size_t i = 1; i < mr.size(); i++){
- if (mr.at(i).start() < mr.at(i-1).stop()){
- throw std::runtime_error("meta-range is not monotonic");
- }
- }
- }
- } //namespace /*anon*/
-
-
- template <typename T> meta_range_t<T>::meta_range_t(void){
- /* NOP */
- }
-
- template <typename T> template <typename InputIterator>
- meta_range_t<T>::meta_range_t(
- InputIterator first, InputIterator last
- ):
- std::vector<range_t<T> >(first, last)
- {
- /* NOP */
- }
-
- template <typename T> meta_range_t<T>::meta_range_t(
- const T &start, const T &stop, const T &step
- ):
- std::vector<range_t<T> > (1, range_t<T>(start, stop, step))
- {
- /* NOP */
- }
-
- template <typename T> const T meta_range_t<T>::start(void) const{
- check_meta_range_monotonic(*this);
- T min_start = this->front().start();
- BOOST_FOREACH(const range_t<T> &r, (*this)){
- min_start = std::min(min_start, r.start());
- }
- return min_start;
- }
-
- template <typename T> const T meta_range_t<T>::stop(void) const{
- check_meta_range_monotonic(*this);
- T max_stop = this->front().stop();
- BOOST_FOREACH(const range_t<T> &r, (*this)){
- max_stop = std::max(max_stop, r.stop());
- }
- return max_stop;
- }
-
- template <typename T> const T meta_range_t<T>::step(void) const{
- check_meta_range_monotonic(*this);
- std::vector<T> non_zero_steps;
- range_t<T> last = this->front();
- BOOST_FOREACH(const range_t<T> &r, (*this)){
- //steps at each range
- if (r.step() > T(0)) non_zero_steps.push_back(r.step());
- //and steps in-between ranges
- T ibtw_step = r.start() - last.stop();
- if (ibtw_step > T(0)) non_zero_steps.push_back(ibtw_step);
- //store ref to last
- last = r;
- }
- if (non_zero_steps.empty()) return T(0); //all zero steps, its zero...
- return *std::min_element(non_zero_steps.begin(), non_zero_steps.end());
- }
-
- template <typename T> const T meta_range_t<T>::clip(
- const T &value, bool clip_step
- ) const{
- check_meta_range_monotonic(*this);
- T last_stop = this->front().stop();
- BOOST_FOREACH(const range_t<T> &r, (*this)){
- //in-between ranges, clip to nearest
- if (value < r.start()){
- return (std::abs(value - r.start()) < std::abs(value - last_stop))?
- r.start() : last_stop;
- }
- //in this range, clip here
- if (value <= r.stop()){
- if (not clip_step or r.step() == T(0)) return value;
- return boost::math::round((value - r.start())/r.step())*r.step() + r.start();
- }
- //continue on to the next range
- last_stop = r.stop();
- }
- return last_stop;
- }
-
- template <typename T> const std::string meta_range_t<T>::to_pp_string(void) const{
- std::stringstream ss;
- BOOST_FOREACH(const range_t<T> &r, (*this)){
- ss << r.to_pp_string() << std::endl;
- }
- return ss.str();
- }
-
- UHD_EXIM_TMPL template struct UHD_API meta_range_t<float>;
- UHD_EXIM_TMPL template struct UHD_API meta_range_t<double>;
-
-} //namespace uhd
-
-#endif /* INCLUDED_UHD_TYPES_RANGES_IPP */
diff --git a/host/include/uhd/types/sensors.hpp b/host/include/uhd/types/sensors.hpp
new file mode 100644
index 000000000..6f003bb40
--- /dev/null
+++ b/host/include/uhd/types/sensors.hpp
@@ -0,0 +1,131 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program 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 of the License, or
+// (at your option) any later version.
+//
+// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_SENSORS_HPP
+#define INCLUDED_UHD_TYPES_SENSORS_HPP
+
+#include <uhd/config.hpp>
+#include <string>
+
+namespace uhd{
+
+ /*!
+ * A sensor value stores a sensor reading as a string with unit and data type.
+ * The sensor value class can be used in the following way:
+ *
+ * sensor_value_t ref_lock_sensor("Reference", my_lock, "unlocked", "locked");
+ * std::cout << ref_lock_sensor.to_pp_string() << std::endl;
+ * //prints Reference: locked
+ *
+ * sensor_value_t temp_sensor("Temperature", my_temp, "C");
+ * std::cout << temp_sensor.to_pp_string() << std::endl;
+ * //prints Temperature: 38.5 C
+ */
+ struct UHD_API sensor_value_t{
+
+ //! typedef for the signed integer type
+ typedef signed int_type;
+
+ //! typedef for the real number type
+ typedef double real_type;
+
+ /*!
+ * Create a sensor value from a boolean.
+ * \param name the name of the sensor
+ * \param value the value true or false
+ * \param ufalse the unit string when value is false
+ * \param utrue the unit string when value is true
+ */
+ sensor_value_t(
+ const std::string &name,
+ bool value,
+ const std::string &ufalse,
+ const std::string &utrue
+ );
+
+ /*!
+ * Create a sensor value from an integer.
+ * \param name the name of the sensor
+ * \param value the signed integer value
+ * \param unit the associated unit type
+ * \param formatter the formatter string
+ */
+ sensor_value_t(
+ const std::string &name,
+ int_type value,
+ const std::string &unit,
+ const std::string &formatter = "%d"
+ );
+
+ /*!
+ * Create a sensor value from a real number.
+ * \param name the name of the sensor
+ * \param value the real number value
+ * \param unit the associated unit type
+ * \param formatter the formatter string
+ */
+ sensor_value_t(
+ const std::string &name,
+ real_type value,
+ const std::string &unit,
+ const std::string &formatter = "%f"
+ );
+
+ /*!
+ * Create a sensor value from a string.
+ * \param name the name of the sensor
+ * \param value the real number value
+ * \param unit the associated unit type
+ */
+ sensor_value_t(
+ const std::string &name,
+ const std::string &value,
+ const std::string &unit
+ );
+
+ //! The name of the sensor value
+ const std::string name;
+
+ /*!
+ * The sensor value as a string.
+ * For integer and real number types, this will be the output of the formatter.
+ * For boolean types, the value will be the string literal "true" or "false".
+ */
+ const std::string value;
+
+ /*!
+ * The sensor value's unit type.
+ * For boolean types, this will be the one of the two units
+ * depending upon the value of the boolean true or false.
+ */
+ const std::string unit;
+
+ //! The data type of the value
+ const enum{
+ BOOLEAN = 'b',
+ INTEGER = 'i',
+ REALNUM = 'r',
+ STRING = 's'
+ } type;
+
+ //! Convert this sensor value into a printable string
+ std::string to_pp_string(void) const;
+ };
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_TYPES_SENSORS_HPP */
diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt
index c8d7281d3..f60b35e59 100644
--- a/host/include/uhd/usrp/CMakeLists.txt
+++ b/host/include/uhd/usrp/CMakeLists.txt
@@ -34,6 +34,7 @@ INSTALL(FILES
### utilities ###
dsp_utils.hpp
+ gps_ctrl.hpp
mboard_eeprom.hpp
misc_utils.hpp
subdev_spec.hpp
diff --git a/host/include/uhd/usrp/codec_props.hpp b/host/include/uhd/usrp/codec_props.hpp
index ab09b1703..5d0a2913c 100644
--- a/host/include/uhd/usrp/codec_props.hpp
+++ b/host/include/uhd/usrp/codec_props.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -30,8 +30,8 @@ namespace uhd{ namespace usrp{
enum codec_prop_t{
CODEC_PROP_NAME = 'n', //ro, std::string
CODEC_PROP_OTHERS = 'o', //ro, prop_names_t
- CODEC_PROP_GAIN_I = 'i', //rw, float
- CODEC_PROP_GAIN_Q = 'q', //rw, float
+ CODEC_PROP_GAIN_I = 'i', //rw, double
+ CODEC_PROP_GAIN_Q = 'q', //rw, double
CODEC_PROP_GAIN_RANGE = 'r', //ro, gain_range_t
CODEC_PROP_GAIN_NAMES = 'G' //ro, prop_names_t
};
diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp
index b04756c47..cfb727017 100644
--- a/host/include/uhd/usrp/dboard_iface.hpp
+++ b/host/include/uhd/usrp/dboard_iface.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -102,7 +102,7 @@ public:
* \param which_dac the dac index 0, 1, 2, 3...
* \param value the value in volts
*/
- virtual void write_aux_dac(unit_t unit, aux_dac_t which_dac, float value) = 0;
+ virtual void write_aux_dac(unit_t unit, aux_dac_t which_dac, double value) = 0;
/*!
* Read from an aux adc.
@@ -111,7 +111,7 @@ public:
* \param which_adc the adc index 0, 1, 2, 3...
* \return the value in volts
*/
- virtual float read_aux_adc(unit_t unit, aux_adc_t which_adc) = 0;
+ virtual double read_aux_adc(unit_t unit, aux_adc_t which_adc) = 0;
/*!
* Set a daughterboard output pin control source.
@@ -191,8 +191,6 @@ public:
*/
virtual boost::uint16_t get_gpio_out(unit_t unit);
- UHD_DEPRECATED void write_gpio(unit_t unit, boost::uint16_t value){set_gpio_out(unit, value);}
-
/*!
* Setup the GPIO debug mux.
*
diff --git a/host/include/uhd/usrp/gps_ctrl.hpp b/host/include/uhd/usrp/gps_ctrl.hpp
new file mode 100644
index 000000000..74f984ee0
--- /dev/null
+++ b/host/include/uhd/usrp/gps_ctrl.hpp
@@ -0,0 +1,56 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program 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 of the License, or
+// (at your option) any later version.
+//
+// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_GPS_CTRL_HPP
+#define INCLUDED_GPS_CTRL_HPP
+
+#include <boost/shared_ptr.hpp>
+#include <boost/utility.hpp>
+#include <boost/function.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+using namespace boost::posix_time;
+
+typedef boost::function<void(std::string)> gps_send_fn_t;
+typedef boost::function<std::string(void)> gps_recv_fn_t;
+
+class gps_ctrl : boost::noncopyable{
+public:
+ typedef boost::shared_ptr<gps_ctrl> sptr;
+
+ /*!
+ * Make a GPS config for Jackson Labs or generic NMEA GPS devices
+ */
+ static sptr make(gps_send_fn_t, gps_recv_fn_t);
+
+ /*!
+ * Get the current GPS time and date
+ * \return current GPS time and date as boost::posix_time::ptime object
+ */
+ virtual ptime get_time(void) = 0;
+
+ /*!
+ * Tell you if there's a supported GPS connected or not
+ * \return true if a supported GPS is connected
+ */
+ virtual bool gps_detected(void) = 0;
+
+ //TODO: other fun things you can do with a GPS.
+
+};
+
+#endif /* INCLUDED_GPS_CTRL_HPP */
diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp
index df94d1678..c82bfc21a 100644
--- a/host/include/uhd/usrp/mboard_props.hpp
+++ b/host/include/uhd/usrp/mboard_props.hpp
@@ -43,7 +43,7 @@ namespace uhd{ namespace usrp{
MBOARD_PROP_TX_SUBDEV_SPEC = 'R', //rw, subdev_spec_t
MBOARD_PROP_CLOCK_CONFIG = 'C', //rw, clock_config_t
MBOARD_PROP_TIME_NOW = 't', //rw, time_spec_t
- MBOARD_PROP_TIME_NEXT_PPS = 'T', //wo, time_spec_t
+ MBOARD_PROP_TIME_PPS = 'T', //wo, time_spec_t
MBOARD_PROP_STREAM_CMD = 's', //wo, stream_cmd_t
MBOARD_PROP_EEPROM_MAP = 'M' //wr, mboard_eeprom_t::sptr
};
diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp
index 98ba07fc0..b603d4324 100644
--- a/host/include/uhd/usrp/multi_usrp.hpp
+++ b/host/include/uhd/usrp/multi_usrp.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -51,7 +51,8 @@ namespace uhd{ namespace usrp{
*
* //create a multi_usrp with two boards in the configuration
* device_addr_t dev_addr;
- * dev_addr["addr"] = "192.168.10.2 192.168.10.3";
+ * dev_addr["addr0"] = "192.168.10.2"
+ * dev_addr["addr1"] = "192.168.10.3";
* multi_usrp::sptr dev = multi_usrp::make(dev_addr);
*
* //set the board on 10.2 to use the A RX subdevice (RX channel 0)
@@ -108,12 +109,18 @@ public:
virtual std::string get_mboard_name(size_t mboard) = 0;
/*!
- * Gets the current time in the usrp time registers.
+ * Get the current time in the usrp time registers.
* \return a timespec representing current usrp time
*/
virtual time_spec_t get_time_now(void) = 0;
/*!
+ * Get the time when the last pps pulse occured.
+ * \return a timespec representing the last pps
+ */
+ virtual time_spec_t get_time_last_pps(void) = 0;
+
+ /*!
* Set the time registers on the usrp at the next pps tick.
* The values will not be latched in until the pulse occurs.
* It is recommended that the user sleep(1) after calling to ensure
@@ -133,14 +140,13 @@ public:
* Ex: Host machine is not attached to serial port of GPSDO
* and can therefore not query the GPSDO for the PPS edge.
*
- * This is a 3-step process, and will take at most 3 seconds to complete.
+ * This is a 2-step process, and will take at most 2 seconds to complete.
* Upon completion, the times will be synchronized to the time provided.
*
- * - Step1: set the time at the next pps (potential race condition)
- * - Step2: wait for the seconds to rollover to catch the pps edge
- * - Step3: set the time at the next pps (synchronous for all boards)
+ * - Step1: wait for the last pps time to transition to catch the edge
+ * - Step2: set the time at the next pps (synchronous for all boards)
*
- * \param time_spec the time to latch into the usrp device
+ * \param time_spec the time to latch at the next pps after catching the edge
*/
virtual void set_time_unknown_pps(const time_spec_t &time_spec) = 0;
@@ -251,10 +257,10 @@ public:
* \param name the name of the gain element
* \param chan the channel index 0 to N-1
*/
- virtual void set_rx_gain(float gain, const std::string &name, size_t chan) = 0;
+ virtual void set_rx_gain(double gain, const std::string &name, size_t chan) = 0;
//! A convenience wrapper for setting overall RX gain
- void set_rx_gain(float gain, size_t chan){
+ void set_rx_gain(double gain, size_t chan){
return this->set_rx_gain(gain, ALL_GAINS, chan);
}
@@ -265,10 +271,10 @@ public:
* \param chan the channel index 0 to N-1
* \return the gain in dB
*/
- virtual float get_rx_gain(const std::string &name, size_t chan) = 0;
+ virtual double get_rx_gain(const std::string &name, size_t chan) = 0;
//! A convenience wrapper for getting overall RX gain
- float get_rx_gain(size_t chan){
+ double get_rx_gain(size_t chan){
return this->get_rx_gain(ALL_GAINS, chan);
}
@@ -342,7 +348,7 @@ public:
* \return the rssi in dB
* \throw exception if RSSI readback not supported
*/
- virtual float read_rssi(size_t chan) = 0;
+ virtual double read_rssi(size_t chan) = 0;
/*!
* Get the dboard interface object for the RX subdevice.
@@ -430,10 +436,10 @@ public:
* \param name the name of the gain element
* \param chan the channel index 0 to N-1
*/
- virtual void set_tx_gain(float gain, const std::string &name, size_t chan) = 0;
+ virtual void set_tx_gain(double gain, const std::string &name, size_t chan) = 0;
//! A convenience wrapper for setting overall TX gain
- void set_tx_gain(float gain, size_t chan){
+ void set_tx_gain(double gain, size_t chan){
return this->set_tx_gain(gain, ALL_GAINS, chan);
}
@@ -444,10 +450,10 @@ public:
* \param chan the channel index 0 to N-1
* \return the gain in dB
*/
- virtual float get_tx_gain(const std::string &name, size_t chan) = 0;
+ virtual double get_tx_gain(const std::string &name, size_t chan) = 0;
//! A convenience wrapper for getting overall TX gain
- float get_tx_gain(size_t chan){
+ double get_tx_gain(size_t chan){
return this->get_tx_gain(ALL_GAINS, chan);
}
diff --git a/host/include/uhd/usrp/single_usrp.hpp b/host/include/uhd/usrp/single_usrp.hpp
index 26303fe10..d80999300 100644
--- a/host/include/uhd/usrp/single_usrp.hpp
+++ b/host/include/uhd/usrp/single_usrp.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -77,12 +77,18 @@ public:
virtual std::string get_mboard_name(void) = 0;
/*!
- * Gets the current time in the usrp time registers.
+ * Get the current time in the usrp time registers.
* \return a timespec representing current usrp time
*/
virtual time_spec_t get_time_now(void) = 0;
/*!
+ * Get the time when the last pps pulse occured.
+ * \return a timespec representing the last pps
+ */
+ virtual time_spec_t get_time_last_pps(void) = 0;
+
+ /*!
* Sets the time registers on the usrp immediately.
* \param time_spec the time to latch into the usrp device
*/
@@ -184,10 +190,10 @@ public:
* \param name the name of the gain element
* \param chan the channel index 0 to N-1
*/
- virtual void set_rx_gain(float gain, const std::string &name, size_t chan = 0) = 0;
+ virtual void set_rx_gain(double gain, const std::string &name, size_t chan = 0) = 0;
//! A convenience wrapper for setting overall RX gain
- void set_rx_gain(float gain, size_t chan = 0){
+ void set_rx_gain(double gain, size_t chan = 0){
return this->set_rx_gain(gain, ALL_GAINS, chan);
}
@@ -198,10 +204,10 @@ public:
* \param chan the channel index 0 to N-1
* \return the gain in dB
*/
- virtual float get_rx_gain(const std::string &name, size_t chan = 0) = 0;
+ virtual double get_rx_gain(const std::string &name, size_t chan = 0) = 0;
//! A convenience wrapper for getting overall RX gain
- float get_rx_gain(size_t chan = 0){
+ double get_rx_gain(size_t chan = 0){
return this->get_rx_gain(ALL_GAINS, chan);
}
@@ -275,7 +281,7 @@ public:
* \return the rssi in dB
* \throw exception if RSSI readback not supported
*/
- virtual float read_rssi(size_t chan = 0) = 0;
+ virtual double read_rssi(size_t chan = 0) = 0;
/*!
* Get the dboard interface object for the RX subdevice.
@@ -353,10 +359,10 @@ public:
* \param name the name of the gain element
* \param chan the channel index 0 to N-1
*/
- virtual void set_tx_gain(float gain, const std::string &name, size_t chan = 0) = 0;
+ virtual void set_tx_gain(double gain, const std::string &name, size_t chan = 0) = 0;
//! A convenience wrapper for setting overall TX gain
- void set_tx_gain(float gain, size_t chan = 0){
+ void set_tx_gain(double gain, size_t chan = 0){
return this->set_tx_gain(gain, ALL_GAINS, chan);
}
@@ -367,10 +373,10 @@ public:
* \param chan the channel index 0 to N-1
* \return the gain in dB
*/
- virtual float get_tx_gain(const std::string &name, size_t chan = 0) = 0;
+ virtual double get_tx_gain(const std::string &name, size_t chan = 0) = 0;
//! A convenience wrapper for getting overall TX gain
- float get_tx_gain(size_t chan = 0){
+ double get_tx_gain(size_t chan = 0){
return this->get_tx_gain(ALL_GAINS, chan);
}
diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp
index 8f096ffe4..8d05f4c27 100644
--- a/host/include/uhd/usrp/subdev_props.hpp
+++ b/host/include/uhd/usrp/subdev_props.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@ namespace uhd{ namespace usrp{
enum subdev_prop_t{
SUBDEV_PROP_NAME = 'n', //ro, std::string
SUBDEV_PROP_OTHERS = 'o', //ro, prop_names_t
- SUBDEV_PROP_GAIN = 'g', //rw, float
+ SUBDEV_PROP_GAIN = 'g', //rw, double
SUBDEV_PROP_GAIN_RANGE = 'r', //ro, gain_range_t
SUBDEV_PROP_GAIN_NAMES = 'G', //ro, prop_names_t
SUBDEV_PROP_FREQ = 'f', //rw, double
@@ -55,7 +55,7 @@ namespace uhd{ namespace usrp{
SUBDEV_PROP_CONNECTION = 'c', //ro, subdev_conn_t
SUBDEV_PROP_ENABLED = 'e', //rw, bool
SUBDEV_PROP_USE_LO_OFFSET = 'l', //ro, bool
- SUBDEV_PROP_RSSI = 'R', //ro, float
+ SUBDEV_PROP_RSSI = 'R', //ro, double
SUBDEV_PROP_BANDWIDTH = 'B' //rw, double
};
diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp
index 53c571e4e..5e2230371 100644
--- a/host/include/uhd/utils/algorithm.hpp
+++ b/host/include/uhd/utils/algorithm.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -22,9 +22,6 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>
-#include <boost/algorithm/string.hpp>
-#include <vector>
-#include <string>
/*! \file algorithm.hpp
* Useful templated functions and classes that I like to pretend are part of stl.
@@ -33,24 +30,6 @@
namespace std{
/*!
- * Split a string at the separation characters.
- * \param string the string to split
- * \param sep the separator characters
- * \return a range of strings
- */
- inline std::vector<std::string> split_string(
- const std::string &string, const std::string &sep = "\t "
- ){
- std::vector<std::string> strings;
- if (not string.empty()) boost::split(
- // do not split an empty string:
- // let me tell you about the time when boost::split segfaulted...
- strings, string, boost::is_any_of(sep)
- );
- return strings;
- }
-
- /*!
* A wrapper around std::copy that takes ranges instead of iterators.
*
* Copy the elements of the source range into the destination range.
@@ -164,8 +143,12 @@ namespace std{
* \param bound2 the upper or lower bound
* \return the value clipped at the bounds
*/
- template<typename T> inline T clip(T val, T bound1, T bound2){
- return std::min(std::max(val, std::min(bound1, bound2)), std::max(bound1, bound2));
+ template<typename T> inline T clip(const T &val, const T &bound1, const T &bound2){
+ const T minimum = std::min(bound1, bound2);
+ if (val < minimum) return minimum;
+ const T maximum = std::max(bound1, bound2);
+ if (val > maximum) return maximum;
+ return val;
}
}//namespace std
diff --git a/host/include/uhd/utils/gain_group.hpp b/host/include/uhd/utils/gain_group.hpp
index c863248ce..7ef7bdcf5 100644
--- a/host/include/uhd/utils/gain_group.hpp
+++ b/host/include/uhd/utils/gain_group.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -33,8 +33,8 @@ namespace uhd{
*/
struct UHD_API gain_fcns_t{
boost::function<gain_range_t(void)> get_range;
- boost::function<float(void)> get_value;
- boost::function<void(float)> set_value;
+ boost::function<double(void)> get_value;
+ boost::function<void(double)> set_value;
};
class UHD_API gain_group : boost::noncopyable{
@@ -56,7 +56,7 @@ public:
* \param name name of the gain element (optional)
* \return a gain value of the element or all elements
*/
- virtual float get_value(const std::string &name = "") = 0;
+ virtual double get_value(const std::string &name = "") = 0;
/*!
* Set the gain value for the gain element specified by name.
@@ -66,7 +66,7 @@ public:
* \param gain the gain to set for the lement or across the group
* \param name name of the gain element (optional)
*/
- virtual void set_value(float gain, const std::string &name = "") = 0;
+ virtual void set_value(double gain, const std::string &name = "") = 0;
/*!
* Get a list of names of registered gain elements.
diff --git a/host/include/uhd/utils/static.hpp b/host/include/uhd/utils/static.hpp
index c61f10884..82cdf36d9 100644
--- a/host/include/uhd/utils/static.hpp
+++ b/host/include/uhd/utils/static.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -30,8 +30,17 @@
/*!
* Defines a static code block that will be called before main()
- * \param _x the name of the defined struct (must be unique in file)
+ * The static block will catch and print exceptions to std error.
+ * \param _x the unique name of the fixture (unique per source)
*/
-#define UHD_STATIC_BLOCK(_x) static struct _x{_x();}_x;_x::_x()
+#define UHD_STATIC_BLOCK(_x) \
+ void _x(void); \
+ static _uhd_static_fixture _x##_fixture(&_x, #_x); \
+ void _x(void)
+
+//! Helper for static block, constructor calls function
+struct UHD_API _uhd_static_fixture{
+ _uhd_static_fixture(void (*)(void), const char *);
+};
#endif /* INCLUDED_UHD_UTILS_STATIC_HPP */