aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-03-10 14:47:03 -0800
committerJosh Blum <josh@joshknows.com>2010-03-10 14:47:03 -0800
commit8e9a8464386db03a596e0b88d0714d22723d37d0 (patch)
treede6a35865ba1d54bb4d908d86397aeba459b3e01 /host/include
parentbb86022d5a5f7055cdeebaeb4a55216e1a056fd4 (diff)
downloaduhd-8e9a8464386db03a596e0b88d0714d22723d37d0.tar.gz
uhd-8e9a8464386db03a596e0b88d0714d22723d37d0.tar.bz2
uhd-8e9a8464386db03a596e0b88d0714d22723d37d0.zip
Added simple device to handle wrapping general properties up into simple api.
Added setting time capability to the usrp2 impl. Messing with props and time specs...
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/CMakeLists.txt1
-rw-r--r--host/include/uhd/props.hpp20
-rw-r--r--host/include/uhd/simple_device.hpp111
-rw-r--r--host/include/uhd/time_spec.hpp19
-rw-r--r--host/include/uhd/utils.hpp105
5 files changed, 180 insertions, 76 deletions
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt
index f4fb96786..522f43afd 100644
--- a/host/include/uhd/CMakeLists.txt
+++ b/host/include/uhd/CMakeLists.txt
@@ -26,6 +26,7 @@ INSTALL(FILES
gain_handler.hpp
metadata.hpp
props.hpp
+ simple_device.hpp
time_spec.hpp
utils.hpp
wax.hpp
diff --git a/host/include/uhd/props.hpp b/host/include/uhd/props.hpp
index cf301d4bd..dea2baf52 100644
--- a/host/include/uhd/props.hpp
+++ b/host/include/uhd/props.hpp
@@ -116,16 +116,16 @@ namespace uhd{
enum dboard_prop_t{
DBOARD_PROP_NAME, //ro, std::string
DBOARD_PROP_SUBDEV, //ro, wax::obj
- DBOARD_PROP_SUBDEV_NAMES, //ro, prop_names_t
- DBOARD_PROP_CODEC //ro, wax::obj
- };
+ DBOARD_PROP_SUBDEV_NAMES //ro, prop_names_t
+ //DBOARD_PROP_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet
+ };
- /*!
+ /*! ------ not dealing with yet, commented out ------------
* Possible device codec properties:
* A codec is expected to have a rate and gain elements.
* Other properties can be discovered through the others prop.
*/
- enum codec_prop_t{
+ /*enum codec_prop_t{
CODEC_PROP_NAME, //ro, std::string
CODEC_PROP_OTHERS, //ro, prop_names_t
CODEC_PROP_GAIN, //rw, gain_t
@@ -133,8 +133,8 @@ namespace uhd{
CODEC_PROP_GAIN_MIN, //ro, gain_t
CODEC_PROP_GAIN_STEP, //ro, gain_t
CODEC_PROP_GAIN_NAMES, //ro, prop_names_t
- CODEC_PROP_CLOCK_RATE //ro, freq_t
- };
+ //CODEC_PROP_CLOCK_RATE //ro, freq_t //----> not sure we care to know
+ };*/
/*!
* Possible device subdev properties
@@ -156,9 +156,9 @@ namespace uhd{
SUBDEV_PROP_QUADRATURE, //ro, bool
SUBDEV_PROP_IQ_SWAPPED, //ro, bool
SUBDEV_PROP_SPECTRUM_INVERTED, //ro, bool
- SUBDEV_PROP_IS_TX, //ro, bool
- SUBDEV_PROP_RSSI, //ro, gain_t
- SUBDEV_PROP_BANDWIDTH //rw, freq_t
+ SUBDEV_PROP_LO_INTERFERES //ro, bool
+ //SUBDEV_PROP_RSSI, //ro, gain_t //----> not on all boards, use named prop
+ //SUBDEV_PROP_BANDWIDTH //rw, freq_t //----> not on all boards, use named prop
};
} //namespace uhd
diff --git a/host/include/uhd/simple_device.hpp b/host/include/uhd/simple_device.hpp
new file mode 100644
index 000000000..64ec85a5c
--- /dev/null
+++ b/host/include/uhd/simple_device.hpp
@@ -0,0 +1,111 @@
+//
+// 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/>.
+//
+
+#include <boost/shared_ptr.hpp>
+#include <boost/utility.hpp>
+#include <uhd/device.hpp>
+#include <vector>
+
+#ifndef INCLUDED_UHD_SIMPLE_DEVICE_HPP
+#define INCLUDED_UHD_SIMPLE_DEVICE_HPP
+
+namespace uhd{
+
+/*!
+ * The tune result struct holds result of a 2-phase tuning:
+ * The struct hold the result of tuning the dboard as
+ * the target and actual intermediate frequency.
+ * The struct hold the result of tuning the DDC/DUC as
+ * the target and actual digital converter frequency.
+ * It also tell us weather or not the spectrum is inverted.
+ */
+struct tune_result_t{
+ double target_inter_freq;
+ double actual_inter_freq;
+ double target_dxc_freq;
+ double actual_dxc_freq;
+ bool spectrum_inverted;
+ tune_result_t(void);
+};
+
+/*!
+ * The simple UHD device class:
+ * A simple device facilitates ease-of-use for most use-case scenarios.
+ * The wrapper provides convenience functions to tune the devices
+ * as well as to set the dboard gains, antennas, and other properties.
+ */
+class simple_device : boost::noncopyable{
+public:
+ typedef boost::shared_ptr<simple_device> sptr;
+ static sptr make(const std::string &args);
+
+ virtual device::sptr get_device(void) = 0;
+
+ virtual std::string get_name(void) = 0;
+
+ /*******************************************************************
+ * Streaming
+ ******************************************************************/
+ virtual void set_streaming(bool enb) = 0;
+ virtual bool get_streaming(void) = 0;
+
+ /*******************************************************************
+ * RX methods
+ ******************************************************************/
+ virtual void set_rx_rate(double rate) = 0;
+ virtual double get_rx_rate(void) = 0;
+ virtual std::vector<double> get_rx_rates(void) = 0;
+
+ virtual tune_result_t set_rx_freq(double target_freq, double lo_offset) = 0;
+ virtual double get_rx_freq_min(void) = 0;
+ virtual double get_rx_freq_max(void) = 0;
+
+ virtual void set_rx_gain(float gain) = 0;
+ virtual float get_rx_gain(void) = 0;
+ virtual float get_rx_gain_min(void) = 0;
+ virtual float get_rx_gain_max(void) = 0;
+ virtual float get_rx_gain_step(void) = 0;
+
+ virtual void set_rx_antenna(const std::string &ant) = 0;
+ virtual std::string get_rx_antenna(void) = 0;
+ virtual std::vector<std::string> get_rx_antennas(void) = 0;
+
+ /*******************************************************************
+ * TX methods
+ ******************************************************************/
+ virtual void set_tx_rate(double rate) = 0;
+ virtual double get_tx_rate(void) = 0;
+ virtual std::vector<double> get_tx_rates(void) = 0;
+
+ virtual tune_result_t set_tx_freq(double target_freq, double lo_offset) = 0;
+ virtual double get_tx_freq_min(void) = 0;
+ virtual double get_tx_freq_max(void) = 0;
+
+ virtual void set_tx_gain(float gain) = 0;
+ virtual float get_tx_gain(void) = 0;
+ virtual float get_tx_gain_min(void) = 0;
+ virtual float get_tx_gain_max(void) = 0;
+ virtual float get_tx_gain_step(void) = 0;
+
+ virtual void set_tx_antenna(const std::string &ant) = 0;
+ virtual std::string get_tx_antenna(void) = 0;
+ virtual std::vector<std::string> get_tx_antennas(void) = 0;
+};
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_SIMPLE_DEVICE_HPP */
diff --git a/host/include/uhd/time_spec.hpp b/host/include/uhd/time_spec.hpp
index e5657e555..7e182236b 100644
--- a/host/include/uhd/time_spec.hpp
+++ b/host/include/uhd/time_spec.hpp
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include <boost/date_time/posix_time/posix_time.hpp>
#include <stdint.h>
#ifndef INCLUDED_UHD_TIME_SPEC_HPP
@@ -36,20 +37,22 @@ namespace uhd{
* Create a time_spec_t that holds a wildcard time.
* This will have implementation-specific meaning.
*/
- time_spec_t(void){
- secs = ~0;
- ticks = ~0;
- }
+ time_spec_t(void);
/*!
* Create a time_spec_t from seconds and ticks.
* \param new_secs the new seconds
* \param new_ticks the new ticks (default = 0)
*/
- time_spec_t(uint32_t new_secs, uint32_t new_ticks = 0){
- secs = new_secs;
- ticks = new_ticks;
- }
+ time_spec_t(uint32_t new_secs, uint32_t new_ticks = 0);
+
+ /*!
+ * Create a time_spec_t from boost posix time.
+ * \param time fine-grained boost posix time
+ * \param tick_rate the rate of ticks per second
+ */
+ time_spec_t(boost::posix_time::ptime time, double tick_rate);
+
};
} //namespace uhd
diff --git a/host/include/uhd/utils.hpp b/host/include/uhd/utils.hpp
index 9bbdc83c9..25a7b5abd 100644
--- a/host/include/uhd/utils.hpp
+++ b/host/include/uhd/utils.hpp
@@ -15,18 +15,14 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include <uhd/wax.hpp>
-#include <boost/foreach.hpp>
-#include <boost/format.hpp>
-#include <boost/function.hpp>
-#include <stdexcept>
-#include <algorithm>
-#include <vector>
-#include <map>
-
#ifndef INCLUDED_UHD_UTILS_HPP
#define INCLUDED_UHD_UTILS_HPP
+#include <stdexcept>
+#include <algorithm>
+#include <boost/format.hpp>
+#include <boost/current_function.hpp>
+
/*!
* Useful templated functions and classes that I like to pretend are part of stl
*/
@@ -40,7 +36,9 @@ namespace std{
};
#define ASSERT_THROW(_x) if (not (_x)) { \
- throw std::assert_error("Assertion Failed: " + std::string(#_x)); \
+ throw std::assert_error(str(boost::format( \
+ "Assertion Failed:\n %s:%d\n %s\n __/ %s __/" \
+ ) % __FILE__ % __LINE__ % BOOST_CURRENT_FUNCTION % std::string(#_x))); \
}
template<class T, class InputIterator, class Function>
@@ -57,9 +55,9 @@ namespace std{
return last != std::find(first, last, elem);
}
- template<class T, class V>
- bool has(const V &vector, const T &elem){
- return has(vector.begin(), vector.end(), elem);
+ template<class T, class Iterable>
+ bool has(const Iterable &iterable, const T &elem){
+ return has(iterable.begin(), iterable.end(), elem);
}
template<class T>
@@ -75,52 +73,43 @@ namespace std{
}//namespace std
-/*namespace uhd{
-
-inline void tune(
- freq_t target_freq,
- freq_t lo_offset,
- wax::obj subdev_freq_proxy,
- bool subdev_quadrature,
- bool subdev_spectrum_inverted,
- bool subdev_is_tx,
- wax::obj dsp_freq_proxy,
- freq_t dsp_sample_rate
-){
- // Ask the d'board to tune as closely as it can to target_freq+lo_offset
- subdev_freq_proxy = target_freq + lo_offset;
- freq_t inter_freq = wax::cast<freq_t>(subdev_freq_proxy);
-
- // Calculate the DDC setting that will downconvert the baseband from the
- // daughterboard to our target frequency.
- freq_t delta_freq = target_freq - inter_freq;
- freq_t delta_sign = std::signum(delta_freq);
- delta_freq *= delta_sign;
- delta_freq = fmod(delta_freq, dsp_sample_rate);
- bool inverted = delta_freq > dsp_sample_rate/2.0;
- freq_t dxc_freq = inverted? (delta_freq - dsp_sample_rate) : (-delta_freq);
- dxc_freq *= delta_sign;
-
- // If the spectrum is inverted, and the daughterboard doesn't do
- // quadrature downconversion, we can fix the inversion by flipping the
- // sign of the dxc_freq... (This only happens using the basic_rx board)
- if (subdev_spectrum_inverted){
- inverted = not inverted;
- }
- if (inverted and not subdev_quadrature){
- dxc_freq = -dxc_freq;
- inverted = not inverted;
- }
- if (subdev_is_tx){
- dxc_freq = -dxc_freq; // down conversion versus up conversion
+#include <boost/format.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
+
+namespace uhd{
+
+ /*!
+ * Check that an element is found in a container.
+ * If not, throw a meaningful assertion error.
+ * The "what" in the error will show what is
+ * being set and a list of known good values.
+ *
+ * \param iterable a list of possible settings
+ * \param elem an element that may be in the list
+ * \param what a description of what is being set
+ * \throw assertion_error when elem not in list
+ */
+ template<class T, class Iterable> void assert_has(
+ const Iterable &iterable,
+ const T &elem,
+ const std::string &what = "unknown"
+ ){
+ if (std::has(iterable, elem)) return;
+ std::string possible_values = "";
+ BOOST_FOREACH(T e, iterable){
+ if (e != iterable.begin()[0]) possible_values += ", ";
+ possible_values += boost::lexical_cast<std::string>(e);
+ }
+ throw std::assert_error(str(boost::format(
+ "Error: %s is not a valid %s. "
+ "Possible values are: [%s]."
+ )
+ % boost::lexical_cast<std::string>(elem)
+ % what % possible_values
+ ));
}
- dsp_freq_proxy = dxc_freq;
- //freq_t actual_dxc_freq = wax::cast<freq_t>(dsp_freq_proxy);
-
- //return some kind of tune result tuple/struct
-}
-
-} //namespace uhd*/
+}//namespace uhd
#endif /* INCLUDED_UHD_UTILS_HPP */