summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-03-21 00:58:34 -0700
committerJosh Blum <josh@joshknows.com>2010-03-21 00:58:34 -0700
commitd1ecc555e53770f1a5608000352f56f48c36c310 (patch)
treeccccaac506fa6fe0812fce202121a4ad85d3f752 /host/lib
parent26ada5ee709fc4d7e195d19720b467c14368bc05 (diff)
downloaduhd-d1ecc555e53770f1a5608000352f56f48c36c310.tar.gz
uhd-d1ecc555e53770f1a5608000352f56f48c36c310.tar.bz2
uhd-d1ecc555e53770f1a5608000352f56f48c36c310.zip
Moved typedefs from props.hpp into new file types.hpp.
Created structs to replace range tuples, and clock config struct. Merged clock config props into one property using config struct. Added templated dict construction to use the assign::map_list_of. Added gcc flag to set visibility to hidden and use the api macro.
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/CMakeLists.txt3
-rw-r--r--host/lib/gain_handler.cpp28
-rw-r--r--host/lib/simple_device.cpp33
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp (renamed from host/lib/transport/udp_zero_copy_none.cpp)0
-rw-r--r--host/lib/types.cpp57
-rw-r--r--host/lib/usrp/dboard/basic.cpp1
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp74
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp11
8 files changed, 115 insertions, 92 deletions
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index 875a065af..563ffb340 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -25,6 +25,7 @@ SET(libuhd_sources
metadata.cpp
simple_device.cpp
time_spec.cpp
+ types.cpp
wax.cpp
transport/udp_simple.cpp
transport/vrt.cpp
@@ -44,7 +45,7 @@ SET(libuhd_sources
# Conditionally add the udp sources
########################################################################
LIST(APPEND libuhd_sources
- transport/udp_zero_copy_none.cpp
+ transport/udp_zero_copy_asio.cpp
)
########################################################################
diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp
index 847bc0528..7dd1547cb 100644
--- a/host/lib/gain_handler.cpp
+++ b/host/lib/gain_handler.cpp
@@ -17,10 +17,12 @@
#include <uhd/gain_handler.hpp>
#include <uhd/utils.hpp>
+#include <uhd/types.hpp>
#include <uhd/props.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
+#include <cmath>
#include <vector>
using namespace uhd;
@@ -99,12 +101,10 @@ gain_t gain_handler_impl::get_overall_gain_val(void){
gain_range_t gain_handler_impl::get_overall_gain_range(void){
gain_t gain_min = 0, gain_max = 0, gain_step = 0;
BOOST_FOREACH(std::string name, get_gain_names()){
- gain_t gain_min_tmp, gain_max_tmp, gain_step_tmp;
- boost::tie(gain_min_tmp, gain_max_tmp, gain_step_tmp) = \
- get_named_prop<gain_range_t>(_props.range, name);
- gain_min += gain_min_tmp;
- gain_max += gain_max_tmp;
- gain_step = std::max(gain_step, gain_step_tmp);
+ gain_range_t gain_tmp = get_named_prop<gain_range_t>(_props.range, name);
+ gain_min += gain_tmp.min;
+ gain_max += gain_tmp.max;
+ gain_step = std::max(gain_step, gain_tmp.step);
}
return gain_range_t(gain_min, gain_max, gain_step);
}
@@ -150,12 +150,10 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val)
//not a wildcard... dont handle (but check name and range)
if (name != ""){
assert_has(get_gain_names(), name, "gain name");
- gain_t gain_min, gain_max, gain_step;
- boost::tie(gain_min, gain_max, gain_step) = \
- get_named_prop<gain_range_t>(_props.range, name);
- if (gain_val > gain_max or gain_val < gain_min) throw std::range_error(str(
+ gain_range_t gain = get_named_prop<gain_range_t>(_props.range, name);
+ if (gain_val > gain.max or gain_val < gain.min) throw std::range_error(str(
boost::format("A value of %f for gain %s is out of range of (%f, %f)")
- % gain_val % name % gain_min % gain_max
+ % gain_val % name % gain.min % gain.max
));
return false;
}
@@ -163,14 +161,12 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val)
//set the overall gain
BOOST_FOREACH(std::string name, get_gain_names()){
//get the min, max, step for this gain name
- gain_t gain_min, gain_max, gain_step;
- boost::tie(gain_min, gain_max, gain_step) = \
- get_named_prop<gain_range_t>(_props.range, name);
+ gain_range_t gain = get_named_prop<gain_range_t>(_props.range, name);
//clip g to be within the allowed range
- gain_t g = std::min(std::max(gain_val, gain_min), gain_max);
+ gain_t g = std::min(std::max(gain_val, gain.min), gain.max);
//set g to be a multiple of the step size
- g -= fmod(g, gain_step);
+ g -= std::fmod(g, gain.step);
//set g to be the new gain
_link[named_prop_t(_props.value, name)] = g;
//subtract g out of the total gain left to apply
diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp
index 79b035071..045318c6b 100644
--- a/host/lib/simple_device.cpp
+++ b/host/lib/simple_device.cpp
@@ -19,6 +19,7 @@
#include <uhd/device.hpp>
#include <uhd/utils.hpp>
#include <uhd/props.hpp>
+#include <uhd/types.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/foreach.hpp>
@@ -27,10 +28,6 @@
using namespace uhd;
-tune_result_t::tune_result_t(void){
- /* NOP */
-}
-
/***********************************************************************
* Tune Helper Function
**********************************************************************/
@@ -196,11 +193,8 @@ public:
return tune(target_freq, lo_offset, _rx_subdev, _rx_ddc, false/* not tx */);
}
- std::vector<double> get_rx_freq_range(void){
- std::vector<double> range(2);
- boost::tie(range[0], range[1]) = \
- _rx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
- return range;
+ freq_range_t get_rx_freq_range(void){
+ return _rx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
}
void set_rx_gain(float gain){
@@ -211,11 +205,8 @@ public:
return _rx_subdev[SUBDEV_PROP_GAIN].as<gain_t>();
}
- std::vector<float> get_rx_gain_range(void){
- std::vector<float> range(3);
- boost::tie(range[0], range[1], range[2]) = \
- _rx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
- return range;
+ gain_range_t get_rx_gain_range(void){
+ return _rx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
}
void set_rx_antenna(const std::string &ant){
@@ -258,11 +249,8 @@ public:
return tune(target_freq, lo_offset, _tx_subdev, _tx_duc, true/* is tx */);
}
- std::vector<double> get_tx_freq_range(void){
- std::vector<double> range(2);
- boost::tie(range[0], range[1]) = \
- _tx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
- return range;
+ freq_range_t get_tx_freq_range(void){
+ return _tx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
}
void set_tx_gain(float gain){
@@ -273,11 +261,8 @@ public:
return _tx_subdev[SUBDEV_PROP_GAIN].as<gain_t>();
}
- std::vector<float> get_tx_gain_range(void){
- std::vector<float> range(3);
- boost::tie(range[0], range[1], range[2]) = \
- _tx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
- return range;
+ gain_range_t get_tx_gain_range(void){
+ return _tx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
}
void set_tx_antenna(const std::string &ant){
diff --git a/host/lib/transport/udp_zero_copy_none.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 219ae8720..219ae8720 100644
--- a/host/lib/transport/udp_zero_copy_none.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
diff --git a/host/lib/types.cpp b/host/lib/types.cpp
new file mode 100644
index 000000000..f8a9a9b36
--- /dev/null
+++ b/host/lib/types.cpp
@@ -0,0 +1,57 @@
+//
+// 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 <uhd/types.hpp>
+
+using namespace uhd;
+
+/***********************************************************************
+ * gain range
+ **********************************************************************/
+gain_range_t::gain_range_t(float min_, float max_, float step_){
+ min = min_;
+ max = max_;
+ step = step_;
+}
+
+/***********************************************************************
+ * freq range
+ **********************************************************************/
+freq_range_t::freq_range_t(double min_, double max_){
+ min = min_;
+ max = max_;
+}
+
+/***********************************************************************
+ * tune result
+ **********************************************************************/
+tune_result_t::tune_result_t(void){
+ target_inter_freq = 0.0;
+ actual_inter_freq = 0.0;
+ target_dxc_freq = 0.0;
+ actual_dxc_freq = 0.0;
+ spectrum_inverted = false;
+}
+
+/***********************************************************************
+ * clock config
+ **********************************************************************/
+clock_config_t::clock_config_t(void){
+ ref_source = ""; //not a valid setting
+ pps_source = ""; //not a valid setting
+ pps_polarity = POLARITY_NEG;
+}
diff --git a/host/lib/usrp/dboard/basic.cpp b/host/lib/usrp/dboard/basic.cpp
index 02b391244..82485ae6a 100644
--- a/host/lib/usrp/dboard/basic.cpp
+++ b/host/lib/usrp/dboard/basic.cpp
@@ -17,6 +17,7 @@
#include <uhd/utils.hpp>
#include <uhd/props.hpp>
+#include <uhd/types.hpp>
#include <uhd/usrp/dboard_base.hpp>
#include <uhd/usrp/dboard_manager.hpp>
#include <boost/assign/list_of.hpp>
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 4f63e6cc9..cbca8eec7 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -16,7 +16,6 @@
//
#include <uhd/utils.hpp>
-#include <boost/assign/list_of.hpp>
#include "usrp2_impl.hpp"
using namespace uhd;
@@ -36,21 +35,27 @@ void usrp2_impl::mboard_init(void){
}
void usrp2_impl::init_clock_config(void){
+ //init the ref source clock config
+ _ref_source_dict = boost::assign::map_list_of
+ ("int", USRP2_REF_SOURCE_INT)
+ ("sma", USRP2_REF_SOURCE_SMA)
+ ("mimo", USRP2_REF_SOURCE_MIMO)
+ ;
+ _clock_config.ref_source = "int";
+
//init the pps source clock config
- _pps_source_dict["sma"] = USRP2_PPS_SOURCE_SMA;
- _pps_source_dict["mimo"] = USRP2_PPS_SOURCE_MIMO;
- _pps_source = "sma";
+ _pps_source_dict = boost::assign::map_list_of
+ ("sma", USRP2_PPS_SOURCE_SMA)
+ ("mimo", USRP2_PPS_SOURCE_MIMO)
+ ;
+ _clock_config.pps_source = "sma";
//init the pps polarity clock config
- _pps_polarity_dict["pos"] = USRP2_PPS_POLARITY_POS;
- _pps_polarity_dict["neg"] = USRP2_PPS_POLARITY_NEG;
- _pps_polarity = "neg";
-
- //init the ref source clock config
- _ref_source_dict["int"] = USRP2_REF_SOURCE_INT;
- _ref_source_dict["sma"] = USRP2_REF_SOURCE_SMA;
- _ref_source_dict["mimo"] = USRP2_REF_SOURCE_MIMO;
- _ref_source = "int";
+ _pps_polarity_dict = boost::assign::map_list_of
+ (clock_config_t::POLARITY_POS, USRP2_PPS_POLARITY_POS)
+ (clock_config_t::POLARITY_NEG, USRP2_PPS_POLARITY_NEG)
+ ;
+ _clock_config.pps_polarity = clock_config_t::POLARITY_NEG;
//update the clock config (sends a control packet)
update_clock_config();
@@ -60,9 +65,9 @@ void usrp2_impl::update_clock_config(void){
//setup the out data
usrp2_ctrl_data_t out_data;
out_data.id = htonl(USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO);
- out_data.data.clock_config.pps_source = _pps_source_dict [_pps_source];
- out_data.data.clock_config.pps_polarity = _pps_polarity_dict[_pps_polarity];
- out_data.data.clock_config.ref_source = _ref_source_dict [_ref_source];
+ out_data.data.clock_config.ref_source = _ref_source_dict [_clock_config.ref_source];
+ out_data.data.clock_config.pps_source = _pps_source_dict [_clock_config.pps_source];
+ out_data.data.clock_config.pps_polarity = _pps_polarity_dict[_clock_config.pps_polarity];
//send and recv
usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
@@ -175,22 +180,14 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
val = prop_names_t(_tx_dsps.get_keys());
return;
- case MBOARD_PROP_PPS_SOURCE:
- val = _pps_source;
+ case MBOARD_PROP_CLOCK_CONFIG:
+ val = _clock_config;
return;
case MBOARD_PROP_PPS_SOURCE_NAMES:
val = prop_names_t(_pps_source_dict.get_keys());
return;
- case MBOARD_PROP_PPS_POLARITY:
- val = _pps_polarity;
- return;
-
- case MBOARD_PROP_REF_SOURCE:
- val = _ref_source;
- return;
-
case MBOARD_PROP_REF_SOURCE_NAMES:
val = prop_names_t(_ref_source_dict.get_keys());
return;
@@ -237,26 +234,11 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<mboard_prop_t>()){
- case MBOARD_PROP_PPS_SOURCE:{
- std::string name = val.as<std::string>();
- assert_has(_pps_source_dict.get_keys(), name, "usrp2 pps source");
- _pps_source = name; //shadow
- update_clock_config();
- }
- return;
-
- case MBOARD_PROP_PPS_POLARITY:{
- std::string name = val.as<std::string>();
- assert_has(_pps_polarity_dict.get_keys(), name, "usrp2 pps polarity");
- _pps_polarity = name; //shadow
- update_clock_config();
- }
- return;
-
- case MBOARD_PROP_REF_SOURCE:{
- std::string name = val.as<std::string>();
- assert_has(_ref_source_dict.get_keys(), name, "usrp2 reference source");
- _ref_source = name; //shadow
+ case MBOARD_PROP_CLOCK_CONFIG:{
+ clock_config_t clock_config = val.as<clock_config_t>();
+ assert_has(_pps_source_dict.get_keys(), clock_config.pps_source, "usrp2 pps source");
+ assert_has(_ref_source_dict.get_keys(), clock_config.ref_source, "usrp2 ref source");
+ _clock_config = clock_config; //shadow
update_clock_config();
}
return;
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 59e23aba5..70420fd49 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -20,11 +20,12 @@
#include <uhd/usrp/usrp2.hpp>
#include <uhd/dict.hpp>
-#include <uhd/props.hpp>
+#include <uhd/types.hpp>
#include <uhd/time_spec.hpp>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
+#include <boost/assign/list_of.hpp>
#include <uhd/transport/vrt.hpp>
#include <uhd/transport/udp_simple.hpp>
#include <uhd/transport/udp_zero_copy.hpp>
@@ -142,15 +143,15 @@ private:
boost::mutex _ctrl_mutex;
//methods and shadows for clock configuration
- std::string _pps_source, _pps_polarity, _ref_source;
+ uhd::clock_config_t _clock_config;
void init_clock_config(void);
void update_clock_config(void);
void set_time_spec(const uhd::time_spec_t &time_spec, bool now);
//mappings from clock config strings to over the wire enums
- uhd::dict<std::string, usrp2_pps_source_t> _pps_source_dict;
- uhd::dict<std::string, usrp2_pps_polarity_t> _pps_polarity_dict;
- uhd::dict<std::string, usrp2_ref_source_t> _ref_source_dict;
+ uhd::dict<std::string, usrp2_ref_source_t> _ref_source_dict;
+ uhd::dict<std::string, usrp2_pps_source_t> _pps_source_dict;
+ uhd::dict<uhd::clock_config_t::polarity_t, usrp2_pps_polarity_t> _pps_polarity_dict;
//rx and tx dboard methods and objects
uhd::usrp::dboard_manager::sptr _dboard_manager;