summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/config.hpp7
-rw-r--r--host/include/uhd/utils/CMakeLists.txt2
-rw-r--r--host/include/uhd/utils/log.hpp93
-rw-r--r--host/include/uhd/utils/msg.hpp63
-rw-r--r--host/include/uhd/utils/safe_call.hpp6
-rw-r--r--host/include/uhd/utils/warning.hpp12
-rw-r--r--host/lib/convert/convert_impl.cpp6
-rw-r--r--host/lib/device.cpp9
-rw-r--r--host/lib/transport/libusb1_zero_copy.cpp4
-rw-r--r--host/lib/transport/udp_simple.cpp4
-rw-r--r--host/lib/transport/udp_zero_copy.cpp17
-rw-r--r--host/lib/types/device_addr.cpp6
-rw-r--r--host/lib/usrp/dboard/db_basic_and_lf.cpp18
-rw-r--r--host/lib/usrp/dboard/db_dbsrx.cpp57
-rw-r--r--host/lib/usrp/dboard/db_dbsrx2.cpp19
-rw-r--r--host/lib/usrp/dboard/db_rfx.cpp19
-rw-r--r--host/lib/usrp/dboard/db_sbx.cpp35
-rw-r--r--host/lib/usrp/dboard/db_tvrx.cpp38
-rw-r--r--host/lib/usrp/dboard/db_unknown.cpp14
-rw-r--r--host/lib/usrp/dboard/db_wbx_common.cpp30
-rw-r--r--host/lib/usrp/dboard/db_wbx_simple.cpp2
-rw-r--r--host/lib/usrp/dboard/db_xcvr2450.cpp16
-rw-r--r--host/lib/usrp/dboard_eeprom.cpp20
-rw-r--r--host/lib/usrp/dboard_manager.cpp12
-rw-r--r--host/lib/usrp/gps_ctrl.cpp11
-rw-r--r--host/lib/usrp/multi_usrp.cpp20
-rw-r--r--host/lib/usrp/usrp1/clock_ctrl.cpp8
-rw-r--r--host/lib/usrp/usrp1/codec_ctrl.cpp47
-rw-r--r--host/lib/usrp/usrp1/dsp_impl.cpp6
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp10
-rw-r--r--host/lib/usrp/usrp1/mboard_impl.cpp34
-rw-r--r--host/lib/usrp/usrp1/usrp1_ctrl.cpp10
-rw-r--r--host/lib/usrp/usrp1/usrp1_iface.cpp54
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.cpp11
-rw-r--r--host/lib/usrp/usrp2/codec_ctrl.cpp6
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp16
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp11
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp12
-rw-r--r--host/lib/usrp/usrp_e100/clock_ctrl.cpp30
-rw-r--r--host/lib/usrp/usrp_e100/codec_ctrl.cpp10
-rw-r--r--host/lib/usrp/usrp_e100/fpga_downloader.cpp31
-rw-r--r--host/lib/usrp/usrp_e100/io_impl.cpp28
-rw-r--r--host/lib/usrp/usrp_e100/mboard_impl.cpp11
-rw-r--r--host/lib/usrp/usrp_e100/usrp_e100_impl.cpp25
-rw-r--r--host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp55
-rw-r--r--host/lib/utils/CMakeLists.txt2
-rw-r--r--host/lib/utils/gain_group.cpp6
-rw-r--r--host/lib/utils/log.cpp214
-rw-r--r--host/lib/utils/msg.cpp123
-rw-r--r--host/lib/utils/thread_priority.cpp6
-rw-r--r--host/lib/utils/warning.cpp8
-rw-r--r--host/tests/CMakeLists.txt2
-rw-r--r--host/tests/msg_test.cpp (renamed from host/tests/warning_test.cpp)18
53 files changed, 914 insertions, 420 deletions
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp
index 6fd2932cf..96dfe8ed0 100644
--- a/host/include/uhd/config.hpp
+++ b/host/include/uhd/config.hpp
@@ -76,6 +76,13 @@ typedef ptrdiff_t ssize_t;
#define UHD_API UHD_IMPORT
#endif // UHD_DLL_EXPORTS
+// The user can enable this with -DUHD_FUTURE
+#ifdef UHD_FUTURE
+ #define UHD_API_FUTURE UHD_API
+#else
+ #define UHD_API_FUTURE
+#endif
+
// Platform defines for conditional parts of headers:
// Taken from boost/config/select_platform_config.hpp,
// however, we define macros, not strings for platforms.
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 71808ac98..875c4731f 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -23,6 +23,8 @@ INSTALL(FILES
byteswap.ipp
gain_group.hpp
images.hpp
+ log.hpp
+ msg.hpp
pimpl.hpp
props.hpp
safe_call.hpp
diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp
new file mode 100644
index 000000000..8d8f42fd0
--- /dev/null
+++ b/host/include/uhd/utils/log.hpp
@@ -0,0 +1,93 @@
+//
+// 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_UTILS_LOG_HPP
+#define INCLUDED_UHD_UTILS_LOG_HPP
+
+#include <uhd/config.hpp>
+#include <boost/current_function.hpp>
+#include <ostream>
+#include <string>
+
+/*! \file log.hpp
+ * The UHD logging facility.
+ *
+ * The logger enables UHD library code to easily log events into a file.
+ * Log entries are time-stamped and stored with file, line, and function.
+ * Each call to the UHD_LOG macros is synchronous and thread-safe.
+ *
+ * The log file can be found in the path <temp-directory>/uhd.log,
+ * where <temp-directory> is the user or system's temporary directory.
+ * To override <temp-directory>, set the UHD_TEMP_PATH environment variable.
+ *
+ * All log messages with verbosity greater than or equal to the log level
+ * (in other words, as often or less often than the current log level)
+ * are recorded into the log file. All other messages are sent to null.
+ *
+ * The default log level is "regular", but can be overridden:
+ * - at compile time by setting the pre-processor define UHD_LOG_LEVEL.
+ * - at runtime by setting the environment variable UHD_LOG_LEVEL.
+ *
+ * UHD_LOG_LEVEL can be the name of a verbosity enum or integer value:
+ * - Example pre-processor define: -DUHD_LOG_LEVEL=3
+ * - Example pre-processor define: -DUHD_LOG_LEVEL=regularly
+ * - Example environment variable: export UHD_LOG_LEVEL=3
+ * - Example environment variable: export UHD_LOG_LEVEL=regularly
+ */
+
+/*!
+ * A UHD logger macro with configurable verbosity.
+ * Usage: UHD_LOGV(very_rarely) << "the log message" << std::endl;
+ */
+#define UHD_LOGV(verbosity) \
+ uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)()
+
+/*!
+ * A UHD logger macro with default verbosity.
+ * Usage: UHD_LOG << "the log message" << std::endl;
+ */
+#define UHD_LOG \
+ UHD_LOGV(regularly)
+
+
+namespace uhd{ namespace _log{
+
+ //! Verbosity levels for the logger
+ enum verbosity_t{
+ always = 1,
+ often = 2,
+ regularly = 3,
+ rarely = 4,
+ very_rarely = 5,
+ never = 6,
+ };
+
+ //! Internal logging object (called by UHD_LOG macros)
+ struct UHD_API_FUTURE log{
+ log(
+ const verbosity_t verbosity,
+ const std::string &file,
+ const unsigned int line,
+ const std::string &function
+ );
+ ~log(void);
+ std::ostream &operator()(void);
+ };
+
+}} //namespace uhd::_log
+
+#endif /* INCLUDED_UHD_UTILS_LOG_HPP */
diff --git a/host/include/uhd/utils/msg.hpp b/host/include/uhd/utils/msg.hpp
new file mode 100644
index 000000000..17179f551
--- /dev/null
+++ b/host/include/uhd/utils/msg.hpp
@@ -0,0 +1,63 @@
+//
+// 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_UTILS_MSG_HPP
+#define INCLUDED_UHD_UTILS_MSG_HPP
+
+#include <uhd/config.hpp>
+#include <ostream>
+#include <string>
+
+/*!
+ * A UHD message macro with configurable type.
+ * Usage: UHD_MSG(warning) << "some warning message" << std::endl;
+ */
+#define UHD_MSG(type) \
+ uhd::msg::_msg(uhd::msg::type)()
+
+
+namespace uhd{ namespace msg{
+
+ //! Possible message types
+ enum type_t{
+ status = 's',
+ warning = 'w',
+ error = 'e',
+ fastpath= 'f'
+ };
+
+ //! Typedef for a user-registered message handler
+ typedef void (*handler_t)(type_t, const std::string &);
+
+ /*!
+ * Register the handler for uhd system messages.
+ * Only one handler can be registered at once.
+ * This replaces the default std::cout/cerr handler.
+ * \param handler a new handler callback function
+ */
+ UHD_API_FUTURE void register_handler(const handler_t &handler);
+
+ //! Internal message object (called by UHD_MSG macro)
+ struct UHD_API_FUTURE _msg{
+ _msg(const type_t type);
+ ~_msg(void);
+ std::ostream &operator()(void);
+ };
+
+}} //namespace uhd::msg
+
+#endif /* INCLUDED_UHD_UTILS_MSG_HPP */
diff --git a/host/include/uhd/utils/safe_call.hpp b/host/include/uhd/utils/safe_call.hpp
index 6b2c210af..ab287cc66 100644
--- a/host/include/uhd/utils/safe_call.hpp
+++ b/host/include/uhd/utils/safe_call.hpp
@@ -20,12 +20,12 @@
#include <uhd/config.hpp>
#include <uhd/exception.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/log.hpp>
//! helper macro for safe call to produce warnings
-#define _UHD_SAFE_CALL_WARNING(code, what) uhd::warning::post( \
+#define _UHD_SAFE_CALL_WARNING(code, what) UHD_LOGV(rarely) << \
UHD_THROW_SITE_INFO("Exception caught in safe-call.") + #code + " -> " + what \
-);
+;
/*!
* A safe-call catches all exceptions thrown by code,
diff --git a/host/include/uhd/utils/warning.hpp b/host/include/uhd/utils/warning.hpp
index a1e3f0d1e..ae614d59e 100644
--- a/host/include/uhd/utils/warning.hpp
+++ b/host/include/uhd/utils/warning.hpp
@@ -23,6 +23,10 @@
#include <vector>
#include <string>
+/*! \file warning.hpp
+ * EVERYTHING IN THIS FILE IS TOTALLY DEPRECATED! DO NOT USE IT!
+ */
+
namespace uhd{ namespace warning{
//! Callback function type for a message handler
@@ -32,7 +36,7 @@ namespace uhd{ namespace warning{
* Post a warning message to all registered handlers.
* \param msg the multiline warning message
*/
- UHD_API void post(const std::string &msg);
+ UHD_API UHD_DEPRECATED void post(const std::string &msg);
/*!
* Register a new handler with this name.
@@ -41,7 +45,7 @@ namespace uhd{ namespace warning{
* \param name a unique name for this handler
* \param handler the callback handler function
*/
- UHD_API void register_handler(const std::string &name, const handler_t &handler);
+ UHD_API UHD_DEPRECATED void register_handler(const std::string &name, const handler_t &handler);
/*!
* Unregister a handler for this name.
@@ -49,13 +53,13 @@ namespace uhd{ namespace warning{
* \return the handler that was registered
* \throw error when the name was not found in the registry
*/
- UHD_API handler_t unregister_handler(const std::string &name);
+ UHD_API UHD_DEPRECATED handler_t unregister_handler(const std::string &name);
/*!
* Get a list of registered handler names.
* \return a vector of unique string names
*/
- UHD_API const std::vector<std::string> registry_names(void);
+ UHD_API UHD_DEPRECATED const std::vector<std::string> registry_names(void);
}} //namespace uhd::warning
diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp
index d43cecfec..9b2cdcdc9 100644
--- a/host/lib/convert/convert_impl.cpp
+++ b/host/lib/convert/convert_impl.cpp
@@ -16,16 +16,14 @@
//
#include <uhd/convert.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/exception.hpp>
-#include <iostream>
using namespace uhd;
#include "convert_pred.hpp"
-static const bool debug = false;
-
/***********************************************************************
* Define types for the function tables
**********************************************************************/
@@ -78,7 +76,7 @@ void uhd::convert::register_converter(
}
//----------------------------------------------------------------//
- if (debug) std::cout << "register_converter: " << markup << std::endl
+ UHD_LOGV(always) << "register_converter: " << markup << std::endl
<< " prio: " << prio << std::endl
<< " pred: " << pred << std::endl
<< " dir: " << dir << std::endl
diff --git a/host/lib/device.cpp b/host/lib/device.cpp
index b2b0238d2..c5bc047da 100644
--- a/host/lib/device.cpp
+++ b/host/lib/device.cpp
@@ -18,6 +18,8 @@
#include <uhd/device.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/algorithm.hpp>
#include <boost/foreach.hpp>
@@ -26,7 +28,6 @@
#include <boost/functional/hash.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/thread/mutex.hpp>
-#include <iostream>
using namespace uhd;
@@ -65,7 +66,7 @@ void device::register_device(
const find_t &find,
const make_t &make
){
- //std::cout << "registering device" << std::endl;
+ UHD_LOGV(always) << "registering device" << std::endl;
get_dev_fcn_regs().push_back(dev_fcn_reg_t(find, make));
}
@@ -87,7 +88,7 @@ device_addrs_t device::find(const device_addr_t &hint){
);
}
catch(const std::exception &e){
- std::cerr << "Device discovery error: " << e.what() << std::endl;
+ UHD_MSG(error) << "Device discovery error: " << e.what() << std::endl;
}
}
@@ -128,7 +129,7 @@ device::sptr device::make(const device_addr_t &hint, size_t which){
device_addr_t dev_addr; make_t maker;
boost::tie(dev_addr, maker) = dev_addr_makers.at(which);
size_t dev_hash = hash_device_addr(dev_addr);
- //std::cout << boost::format("Hash: %u") % dev_hash << std::endl;
+ UHD_LOG << boost::format("Device hash: %u") % dev_hash << std::endl;
//copy keys that were in hint but not in dev_addr
//this way, we can pass additional transport arguments
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp
index ec2077d30..d4cfab422 100644
--- a/host/lib/transport/libusb1_zero_copy.cpp
+++ b/host/lib/transport/libusb1_zero_copy.cpp
@@ -20,13 +20,13 @@
#include <uhd/transport/bounded_buffer.hpp>
#include <uhd/transport/buffer_pool.hpp>
#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <boost/function.hpp>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/barrier.hpp>
#include <list>
-#include <iostream>
using namespace uhd;
using namespace uhd::transport;
@@ -52,7 +52,7 @@ static void LIBUSB_CALL libusb_async_cb(libusb_transfer *lut){
//! callback to free transfer upon cancellation
static void LIBUSB_CALL cancel_transfer_cb(libusb_transfer *lut){
if (lut->status == LIBUSB_TRANSFER_CANCELLED) libusb_free_transfer(lut);
- else std::cout << "libusb cancel_transfer unexpected status " << lut->status << std::endl;
+ else UHD_LOGV(rarely) << "libusb cancel_transfer unexpected status " << lut->status << std::endl;
}
/***********************************************************************
diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp
index 1ee036d52..ed778fbf4 100644
--- a/host/lib/transport/udp_simple.cpp
+++ b/host/lib/transport/udp_simple.cpp
@@ -17,8 +17,8 @@
#include "udp_common.hpp"
#include <uhd/transport/udp_simple.hpp>
+#include <uhd/utils/log.hpp>
#include <boost/format.hpp>
-#include <iostream>
using namespace uhd::transport;
namespace asio = boost::asio;
@@ -31,7 +31,7 @@ public:
udp_simple_impl(
const std::string &addr, const std::string &port, bool bcast, bool connect
):_connected(connect){
- //std::cout << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
+ UHD_LOG << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
//resolve the address
asio::ip::udp::resolver resolver(_io_service);
diff --git a/host/lib/transport/udp_zero_copy.cpp b/host/lib/transport/udp_zero_copy.cpp
index 5810f441c..c3ba085bf 100644
--- a/host/lib/transport/udp_zero_copy.cpp
+++ b/host/lib/transport/udp_zero_copy.cpp
@@ -20,9 +20,9 @@
#include <uhd/transport/udp_simple.hpp> //mtu
#include <uhd/transport/bounded_buffer.hpp>
#include <uhd/transport/buffer_pool.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
#include <boost/format.hpp>
-#include <iostream>
#include <list>
using namespace uhd;
@@ -131,7 +131,7 @@ public:
_pending_recv_buffs(_num_recv_frames),
_pending_send_buffs(_num_send_frames)
{
- //std::cout << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
+ UHD_LOG << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
//resolve the address
asio::ip::udp::resolver resolver(_io_service);
@@ -275,17 +275,16 @@ template<typename Opt> static void resize_buff_helper(
//resize the buffer if size was provided
if (target_size > 0){
size_t actual_size = udp_trans->resize_buff<Opt>(target_size);
- if (target_size != actual_size) std::cout << boost::format(
+ UHD_LOG << boost::format(
"Target %s sock buff size: %d bytes\n"
"Actual %s sock buff size: %d bytes"
) % name % target_size % name % actual_size << std::endl;
- else std::cout << boost::format(
- "Current %s sock buff size: %d bytes"
- ) % name % actual_size << std::endl;
- if (actual_size < target_size) uhd::warning::post(str(boost::format(
+ if (actual_size < target_size) UHD_MSG(warning) << boost::format(
"The %s buffer could not be resized sufficiently.\n"
+ "Target sock buff size: %d bytes.\n"
+ "Actual sock buff size: %d bytes.\n"
"See the transport application notes on buffer resizing.\n%s"
- ) % name % help_message));
+ ) % name % target_size % actual_size % help_message;
}
}
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp
index 193f76f8c..45d885adc 100644
--- a/host/lib/types/device_addr.cpp
+++ b/host/lib/types/device_addr.cpp
@@ -73,7 +73,7 @@ std::string device_addr_t::to_string(void) const{
return args_str;
}
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){
//------------ support old deprecated way and print warning --------
@@ -85,13 +85,13 @@ device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){
for (size_t i = 0; i < addrs.size(); i++){
fixed_dev_addr[str(boost::format("addr%d") % i)] = addrs[i];
}
- uhd::warning::post(
+ UHD_MSG(warning) <<
"addr = <space separated list of ip addresses> is deprecated.\n"
"To address a multi-device, use multiple <key><index> = <val>.\n"
"See the USRP-NXXX application notes. Two device example:\n"
" addr0 = 192.168.10.2\n"
" addr1 = 192.168.10.3\n"
- );
+ ;
return separate_device_addr(fixed_dev_addr);
}
}
diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp
index 3fffeab0c..6f8de9a7b 100644
--- a/host/lib/usrp/dboard/db_basic_and_lf.cpp
+++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp
@@ -20,7 +20,7 @@
#include <uhd/types/ranges.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/static.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/usrp/dboard_base.hpp>
#include <uhd/usrp/dboard_manager.hpp>
#include <boost/assign/list_of.hpp>
@@ -202,11 +202,9 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("%s: No tunable bandwidth, fixed filtered to %0.2fMHz")
- % get_rx_id().to_pp_string() % _max_freq
- )
- );
+ UHD_MSG(warning) << boost::format(
+ "%s: No tunable bandwidth, fixed filtered to %0.2fMHz"
+ ) % get_rx_id().to_pp_string() % _max_freq;
return;
default: UHD_THROW_PROP_SET_ERROR();
@@ -309,11 +307,9 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("%s: No tunable bandwidth, fixed filtered to %0.2fMHz")
- % get_tx_id().to_pp_string() % _max_freq
- )
- );
+ UHD_MSG(warning) << boost::format(
+ "%s: No tunable bandwidth, fixed filtered to %0.2fMHz"
+ ) % get_tx_id().to_pp_string() % _max_freq;
return;
default: UHD_THROW_PROP_SET_ERROR();
diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp
index 8fdd4f953..cfe06db29 100644
--- a/host/lib/usrp/dboard/db_dbsrx.cpp
+++ b/host/lib/usrp/dboard/db_dbsrx.cpp
@@ -20,10 +20,11 @@
// RX IO Functions
#include "max2118_regs.hpp"
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/algorithm.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/types/ranges.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/types/dict.hpp>
@@ -44,8 +45,6 @@ using namespace boost::assign;
/***********************************************************************
* The DBSRX constants
**********************************************************************/
-static const bool dbsrx_debug = false;
-
static const freq_range_t dbsrx_freq_range(0.8e9, 2.4e9);
static const freq_range_t dbsrx_pfd_freq_range(0.15e6, 2.01e6);
@@ -98,7 +97,7 @@ private:
//get the register data
for(int i=0; i<num_bytes; i++){
regs_vector[1+i] = _max2118_write_regs.get_reg(start_addr+i);
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: send reg 0x%02x, value 0x%04x, start_addr = 0x%04x, num_bytes %d"
) % int(start_addr+i) % int(regs_vector[1+i]) % int(start_addr) % num_bytes << std::endl;
}
@@ -130,7 +129,7 @@ private:
if (i + start_addr >= status_addr){
_max2118_read_regs.set_reg(i + start_addr, regs_vector[i]);
}
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: read reg 0x%02x, value 0x%04x, start_addr = 0x%04x, num_bytes %d"
) % int(start_addr+i) % int(regs_vector[i]) % int(start_addr) % num_bytes << std::endl;
}
@@ -147,7 +146,7 @@ private:
//mask and return lock detect
bool locked = 5 >= _max2118_read_regs.adc and _max2118_read_regs.adc >= 2;
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: locked %d"
) % locked << std::endl;
@@ -176,25 +175,21 @@ UHD_STATIC_BLOCK(reg_dbsrx_dboard){
dbsrx::dbsrx(ctor_args_t args) : rx_dboard_base(args){
//warn user about incorrect DBID on USRP1, requires R193 populated
if (this->get_iface()->get_special_props().soft_clock_divider and this->get_rx_id() == 0x000D)
- uhd::warning::post(
- str(boost::format(
+ UHD_MSG(warning) << boost::format(
"DBSRX: incorrect dbid\n"
"Expected dbid 0x0002 and R193\n"
"found dbid == %d\n"
"Please see the daughterboard app notes"
- ) % this->get_rx_id().to_pp_string())
- );
+ ) % this->get_rx_id().to_pp_string();
//warn user about incorrect DBID on non-USRP1, requires R194 populated
if (not this->get_iface()->get_special_props().soft_clock_divider and this->get_rx_id() == 0x0002)
- uhd::warning::post(
- str(boost::format(
+ UHD_MSG(warning) << boost::format(
"DBSRX: incorrect dbid\n"
"Expected dbid 0x000D and R194\n"
"found dbid == %d\n"
"Please see the daughterboard app notes"
- ) % this->get_rx_id().to_pp_string())
- );
+ ) % this->get_rx_id().to_pp_string();
//enable only the clocks we need
this->get_iface()->set_clock_enabled(dboard_iface::UNIT_RX, true);
@@ -246,7 +241,7 @@ void dbsrx::set_lo_freq(double target_freq){
m = 31;
while ((ref_clock/m < 1e6 or ref_clock/m > 2.5e6) and m > 0){ m--; }
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: trying ref_clock %f and m_divider %d"
) % (ref_clock) % m << std::endl;
@@ -256,7 +251,7 @@ void dbsrx::set_lo_freq(double target_freq){
for(r = 0; r <= 6; r += 1) {
//compute divider from setting
R = 1 << (r+1);
- if (dbsrx_debug) std::cerr << boost::format("DBSRX R:%d\n") % R << std::endl;
+ UHD_LOGV(often) << boost::format("DBSRX R:%d\n") % R << std::endl;
//compute PFD compare frequency = ref_clock/R
pfd_freq = ref_clock / R;
@@ -282,7 +277,7 @@ void dbsrx::set_lo_freq(double target_freq){
UHD_ASSERT_THROW((pfd_freq >= dbsrx_pfd_freq_range.start()) and (pfd_freq <= dbsrx_pfd_freq_range.stop()));
UHD_ASSERT_THROW((N >= 256) and (N <= 32768));
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: choose ref_clock (current: %f, new: %f) and m_divider %d"
) % (this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX)) % ref_clock % m << std::endl;
@@ -304,7 +299,7 @@ void dbsrx::set_lo_freq(double target_freq){
int scaler = actual_freq > 1125e6 ? 2 : 4;
_max2118_write_regs.div2 = scaler == 4 ? max2118_write_regs_t::DIV2_DIV4 : max2118_write_regs_t::DIV2_DIV2;
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: scaler %d, actual_freq %f MHz, register bit: %d"
) % scaler % (actual_freq/1e6) % int(_max2118_write_regs.div2) << std::endl;
@@ -333,7 +328,7 @@ void dbsrx::set_lo_freq(double target_freq){
//check vtune for lock condition
read_reg(0x0, 0x0);
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: initial guess for vco %d, vtune adc %d"
) % int(_max2118_write_regs.osc_band) % int(_max2118_read_regs.adc) << std::endl;
@@ -343,11 +338,9 @@ void dbsrx::set_lo_freq(double target_freq){
//vtune is too low, try lower frequency vco
if (_max2118_read_regs.adc == 0){
if (_max2118_write_regs.osc_band == 0){
- uhd::warning::post(
- str(boost::format(
+ UHD_MSG(warning) << boost::format(
"DBSRX: Tuning exceeded vco range, _max2118_write_regs.osc_band == %d\n"
- ) % int(_max2118_write_regs.osc_band))
- );
+ ) % int(_max2118_write_regs.osc_band);
UHD_ASSERT_THROW(_max2118_read_regs.adc != 0); //just to cause a throw
}
if (_max2118_write_regs.osc_band <= 0) break;
@@ -357,18 +350,16 @@ void dbsrx::set_lo_freq(double target_freq){
//vtune is too high, try higher frequency vco
if (_max2118_read_regs.adc == 7){
if (_max2118_write_regs.osc_band == 7){
- uhd::warning::post(
- str(boost::format(
+ UHD_MSG(warning) << boost::format(
"DBSRX: Tuning exceeded vco range, _max2118_write_regs.osc_band == %d\n"
- ) % int(_max2118_write_regs.osc_band))
- );
+ ) % int(_max2118_write_regs.osc_band);
UHD_ASSERT_THROW(_max2118_read_regs.adc != 7); //just to cause a throw
}
if (_max2118_write_regs.osc_band >= 7) break;
_max2118_write_regs.osc_band += 1;
}
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: trying vco %d, vtune adc %d"
) % int(_max2118_write_regs.osc_band) % int(_max2118_read_regs.adc) << std::endl;
@@ -380,7 +371,7 @@ void dbsrx::set_lo_freq(double target_freq){
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
}
- if(dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX: final vco %d, vtune adc %d"
) % int(_max2118_write_regs.osc_band) % int(_max2118_read_regs.adc) << std::endl;
@@ -396,7 +387,7 @@ void dbsrx::set_lo_freq(double target_freq){
_lo_freq = this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX) / std::pow(2.0,(1 + _max2118_write_regs.r_divider)) * _max2118_write_regs.get_n_divider();
//debug output of calculated variables
- if (dbsrx_debug) std::cerr
+ UHD_LOGV(often)
<< boost::format("DBSRX tune:\n")
<< boost::format(" VCO=%d, CP=%d, PFD Freq=%fMHz\n") % int(_max2118_write_regs.osc_band) % _max2118_write_regs.cp_current % (pfd_freq/1e6)
<< boost::format(" R=%d, N=%f, scaler=%d, div2=%d\n") % R % N % scaler % int(_max2118_write_regs.div2)
@@ -432,7 +423,7 @@ static int gain_to_gc2_vga_reg(double &gain){
gain = double(boost::math::iround(gain));
}
- if (dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX GC2 Gain: %f dB, reg: %d"
) % gain % reg << std::endl;
@@ -456,7 +447,7 @@ static double gain_to_gc1_rfvga_dac(double &gain){
//calculate the voltage for the aux dac
double dac_volts = gain*slope + min_volts;
- if (dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX GC1 Gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
@@ -497,7 +488,7 @@ void dbsrx::set_bandwidth(double bandwidth){
//determine actual bandwidth
_bandwidth = double((ref_clock/(_max2118_write_regs.m_divider))*(4+0.145*_max2118_write_regs.f_dac));
- if (dbsrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX Filter Bandwidth: %f MHz, m: %d, f_dac: %d\n"
) % (_bandwidth/1e6) % int(_max2118_write_regs.m_divider) % int(_max2118_write_regs.f_dac) << std::endl;
diff --git a/host/lib/usrp/dboard/db_dbsrx2.cpp b/host/lib/usrp/dboard/db_dbsrx2.cpp
index e7b42cb05..aaced7a5d 100644
--- a/host/lib/usrp/dboard/db_dbsrx2.cpp
+++ b/host/lib/usrp/dboard/db_dbsrx2.cpp
@@ -18,6 +18,7 @@
// No RX IO Pins Used
#include "max2112_regs.hpp"
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/algorithm.hpp>
@@ -40,8 +41,6 @@ using namespace boost::assign;
/***********************************************************************
* The DBSRX2 constants
**********************************************************************/
-static const bool dbsrx2_debug = false;
-
static const freq_range_t dbsrx2_freq_range(0.8e9, 2.4e9);
static const int dbsrx2_ref_divider = 4; // Hitachi HMC426 divider (U7)
@@ -94,7 +93,7 @@ private:
//get the register data
for(int i=0; i<num_bytes; i++){
regs_vector[1+i] = _max2112_write_regs.get_reg(start_addr+i);
- if(dbsrx2_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX2: send reg 0x%02x, value 0x%04x, start_addr = 0x%04x, num_bytes %d"
) % int(start_addr+i) % int(regs_vector[1+i]) % int(start_addr) % num_bytes << std::endl;
}
@@ -135,12 +134,12 @@ private:
if (i + start_addr >= status_addr){
_max2112_read_regs.set_reg(i + start_addr, regs_vector[i]);
/*
- if(dbsrx2_debug) std::cerr << boost::format(
+ UHD_LOGV(always) << boost::format(
"DBSRX2: set reg 0x%02x, value 0x%04x"
) % int(i + start_addr) % int(_max2112_read_regs.get_reg(i + start_addr)) << std::endl;
*/
}
- if(dbsrx2_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX2: read reg 0x%02x, value 0x%04x, start_addr = 0x%04x, num_bytes %d"
) % int(start_addr+i) % int(regs_vector[i]) % int(start_addr) % num_bytes << std::endl;
}
@@ -157,7 +156,7 @@ private:
//mask and return lock detect
bool locked = (_max2112_read_regs.ld & _max2112_read_regs.vasa & _max2112_read_regs.vase) != 0;
- if(dbsrx2_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"DBSRX2 locked: %d"
) % locked << std::endl;
@@ -244,7 +243,7 @@ void dbsrx2::set_lo_freq(double target_freq){
_max2112_write_regs.d24 = scaler == 4 ? max2112_write_regs_t::D24_DIV4 : max2112_write_regs_t::D24_DIV2;
//debug output of calculated variables
- if (dbsrx2_debug) std::cerr
+ UHD_LOGV(often)
<< boost::format("DBSRX2 tune:\n")
<< boost::format(" R=%d, N=%f, scaler=%d, ext_div=%d\n") % R % N % scaler % ext_div
<< boost::format(" int=%d, frac=%d, d24=%d\n") % intdiv % fracdiv % int(_max2112_write_regs.d24)
@@ -275,7 +274,7 @@ static int gain_to_bbg_vga_reg(double &gain){
gain = double(reg);
- if (dbsrx2_debug) std::cerr
+ UHD_LOGV(often)
<< boost::format("DBSRX2 BBG Gain:\n")
<< boost::format(" %f dB, bbg: %d") % gain % reg
<< std::endl;
@@ -300,7 +299,7 @@ static double gain_to_gc1_rfvga_dac(double &gain){
//calculate the voltage for the aux dac
double dac_volts = gain*slope + min_volts;
- if (dbsrx2_debug) std::cerr
+ UHD_LOGV(often)
<< boost::format("DBSRX2 GC1 Gain:\n")
<< boost::format(" %f dB, dac_volts: %f V") % gain % dac_volts
<< std::endl;
@@ -335,7 +334,7 @@ void dbsrx2::set_bandwidth(double bandwidth){
_max2112_write_regs.lp = int((bandwidth/1e6 - 4)/0.29 + 12);
_bandwidth = double(4 + (_max2112_write_regs.lp - 12) * 0.29)*1e6;
- if (dbsrx2_debug) std::cerr
+ UHD_LOGV(often)
<< boost::format("DBSRX2 Bandwidth:\n")
<< boost::format(" %f MHz, lp: %f V") % (_bandwidth/1e6) % int(_max2112_write_regs.lp)
<< std::endl;
diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp
index 231757365..61f9130d4 100644
--- a/host/lib/usrp/dboard/db_rfx.cpp
+++ b/host/lib/usrp/dboard/db_rfx.cpp
@@ -38,9 +38,10 @@
#include <uhd/types/ranges.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/utils/assert_has.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/algorithm.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/usrp/dboard_id.hpp>
#include <uhd/usrp/dboard_base.hpp>
#include <uhd/usrp/dboard_manager.hpp>
@@ -55,8 +56,6 @@ using namespace boost::assign;
/***********************************************************************
* The RFX Series constants
**********************************************************************/
-static const bool rfx_debug = false;
-
static const prop_names_t rfx_tx_antennas = list_of("TX/RX");
static const prop_names_t rfx_rx_antennas = list_of("TX/RX")("RX2");
@@ -302,7 +301,7 @@ double rfx_xcvr::set_lo_freq(
dboard_iface::unit_t unit,
double target_freq
){
- if (rfx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"RFX tune: target frequency %f Mhz"
) % (target_freq/1e6) << std::endl;
@@ -359,7 +358,7 @@ double rfx_xcvr::set_lo_freq(
}
} done_loop:
- if (rfx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"RFX tune: R=%d, BS=%d, P=%d, B=%d, A=%d, DIV2=%d"
) % R % BS % P % B % A % int(_div2[unit] && (!is_rx_rfx400)) << std::endl;
@@ -405,7 +404,7 @@ double rfx_xcvr::set_lo_freq(
//return the actual frequency
if (_div2[unit]) actual_freq /= 2;
- if (rfx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"RFX tune: actual frequency %f Mhz"
) % (actual_freq/1e6) << std::endl;
return actual_freq;
@@ -515,9 +514,7 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("RFX: No tunable bandwidth, fixed filtered to 40MHz"))
- );
+ UHD_MSG(warning) << "RFX: No tunable bandwidth, fixed filtered to 40MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
@@ -617,9 +614,7 @@ void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("RFX: No tunable bandwidth, fixed filtered to 40MHz"))
- );
+ UHD_MSG(warning) << "RFX: No tunable bandwidth, fixed filtered to 40MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
diff --git a/host/lib/usrp/dboard/db_sbx.cpp b/host/lib/usrp/dboard/db_sbx.cpp
index d0c3c63ac..6ca89b81a 100644
--- a/host/lib/usrp/dboard/db_sbx.cpp
+++ b/host/lib/usrp/dboard/db_sbx.cpp
@@ -78,9 +78,10 @@
#include <uhd/types/ranges.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/utils/assert_has.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/algorithm.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/usrp/dboard_base.hpp>
#include <uhd/usrp/dboard_manager.hpp>
#include <boost/assign/list_of.hpp>
@@ -95,8 +96,6 @@ using namespace boost::assign;
/***********************************************************************
* The SBX dboard constants
**********************************************************************/
-static const bool sbx_debug = false;
-
static const freq_range_t sbx_freq_range(68.75e6, 4.4e9);
static const freq_range_t sbx_tx_lo_2dbm = list_of
@@ -269,7 +268,7 @@ sbx_xcvr::sbx_xcvr(ctor_args_t args) : xcvr_dboard_base(args){
//flash LEDs
flash_leds();
- if (sbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"SBX GPIO Direction: RX: 0x%08x, TX: 0x%08x"
) % RXIO_MASK % TXIO_MASK << std::endl;
@@ -305,7 +304,7 @@ static int rx_pga0_gain_to_iobits(double &gain){
int iobits = ((~attn_code) << RX_ATTN_SHIFT) & RX_ATTN_MASK;
- if (sbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"SBX TX Attenuation: %f dB, Code: %d, IO Bits %x, Mask: %x"
) % attn % attn_code % (iobits & RX_ATTN_MASK) % RX_ATTN_MASK << std::endl;
@@ -327,7 +326,7 @@ static int tx_pga0_gain_to_iobits(double &gain){
int iobits = ((~attn_code) << TX_ATTN_SHIFT) & TX_ATTN_MASK;
- if (sbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"SBX TX Attenuation: %f dB, Code: %d, IO Bits %x, Mask: %x"
) % attn % attn_code % (iobits & TX_ATTN_MASK) % TX_ATTN_MASK << std::endl;
@@ -399,7 +398,7 @@ void sbx_xcvr::update_atr(void){
rx_pga0_iobits | rx_lo_lpf_en | rx_ld_led | rx_ant_led | RX_POWER_UP | RX_MIXER_ENB |
((_rx_ant == "TX/RX")? ANT_TXRX : ANT_RX2));
- if (sbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"SBX RXONLY ATR REG: 0x%08x"
) % (rx_pga0_iobits | RX_POWER_UP | RX_MIXER_ENB | ((_rx_ant == "TX/RX")? ANT_TXRX : ANT_RX2)) << std::endl;
}
@@ -435,7 +434,7 @@ double sbx_xcvr::set_lo_freq(
dboard_iface::unit_t unit,
double target_freq
){
- if (sbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"SBX tune: target frequency %f Mhz"
) % (target_freq/1e6) << std::endl;
@@ -531,14 +530,12 @@ double sbx_xcvr::set_lo_freq(
//actual frequency calculation
actual_freq = double((N + (double(FRAC)/double(MOD)))*ref_freq*(1+int(D))/(R*(1+int(T)))/RFdiv);
- if (sbx_debug) {
- std::cerr << boost::format("SBX Intermediates: ref=%0.2f, outdiv=%f, fbdiv=%f") % (ref_freq*(1+int(D))/(R*(1+int(T)))) % double(RFdiv*2) % double(N + double(FRAC)/double(MOD)) << std::endl;
-
- std::cerr << boost::format("SBX tune: R=%d, BS=%d, N=%d, FRAC=%d, MOD=%d, T=%d, D=%d, RFdiv=%d, LD=%d"
+ UHD_LOGV(often)
+ << boost::format("SBX Intermediates: ref=%0.2f, outdiv=%f, fbdiv=%f") % (ref_freq*(1+int(D))/(R*(1+int(T)))) % double(RFdiv*2) % double(N + double(FRAC)/double(MOD)) << std::endl
+ << boost::format("SBX tune: R=%d, BS=%d, N=%d, FRAC=%d, MOD=%d, T=%d, D=%d, RFdiv=%d, LD=%d"
) % R % BS % N % FRAC % MOD % T % D % RFdiv % get_locked(unit)<< std::endl
<< boost::format("SBX Frequencies (MHz): REQ=%0.2f, ACT=%0.2f, VCO=%0.2f, PFD=%0.2f, BAND=%0.2f"
) % (target_freq/1e6) % (actual_freq/1e6) % (vco_freq/1e6) % (pfd_freq/1e6) % (pfd_freq/BS/1e6) << std::endl;
- }
//load the register values
adf4350_regs_t regs;
@@ -564,7 +561,7 @@ double sbx_xcvr::set_lo_freq(
int addr;
for(addr=5; addr>=0; addr--){
- if (sbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"SBX SPI Reg (0x%02x): 0x%08x"
) % addr % regs.get_reg(addr) << std::endl;
this->get_iface()->write_spi(
@@ -574,7 +571,7 @@ double sbx_xcvr::set_lo_freq(
}
//return the actual frequency
- if (sbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"SBX tune: actual frequency %f Mhz"
) % (actual_freq/1e6) << std::endl;
return actual_freq;
@@ -677,9 +674,7 @@ void sbx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("SBX: No tunable bandwidth, fixed filtered to 40MHz"))
- );
+ UHD_MSG(warning) << "SBX: No tunable bandwidth, fixed filtered to 40MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
@@ -783,9 +778,7 @@ void sbx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("SBX: No tunable bandwidth, fixed filtered to 40MHz"))
- );
+ UHD_MSG(warning) << "SBX: No tunable bandwidth, fixed filtered to 40MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
diff --git a/host/lib/usrp/dboard/db_tvrx.cpp b/host/lib/usrp/dboard/db_tvrx.cpp
index d264c9ca4..1ff0fb785 100644
--- a/host/lib/usrp/dboard/db_tvrx.cpp
+++ b/host/lib/usrp/dboard/db_tvrx.cpp
@@ -27,10 +27,11 @@
//max freq: 860e6
//gain range: [0:1dB:115dB]
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/algorithm.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/types/ranges.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/types/dict.hpp>
@@ -55,8 +56,6 @@ using namespace boost::assign;
/***********************************************************************
* The tvrx constants
**********************************************************************/
-static const bool tvrx_debug = false;
-
static const freq_range_t tvrx_freq_range(50e6, 860e6);
static const prop_names_t tvrx_antennas = list_of("RX");
@@ -158,7 +157,7 @@ private:
//get the register data
for(int i=0; i<4; i++){
regs_vector[i] = _tuner_4937di5_regs.get_reg(i);
- if(tvrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"tvrx: send reg 0x%02x, value 0x%04x"
) % int(i) % int(regs_vector[i]) << std::endl;
}
@@ -221,7 +220,7 @@ tvrx::~tvrx(void){
static std::string get_band(double freq) {
BOOST_FOREACH(const std::string &band, tvrx_freq_ranges.keys()) {
if(freq >= tvrx_freq_ranges[band].start() && freq <= tvrx_freq_ranges[band].stop()){
- if(tvrx_debug) std::cout << "Band: " << band << std::endl;
+ UHD_LOGV(often) << "Band: " << band << std::endl;
return band;
}
}
@@ -263,8 +262,7 @@ static double gain_interp(double gain, boost::array<double, 17> db_vector, boost
//use the volts per dB slope to find the final interpolated voltage
volts = volts_vector[gain_step] + (slope * (gain - db_vector[gain_step]));
- if(tvrx_debug)
- std::cout << "Gain interp: gain: " << gain << ", gain_step: " << int(gain_step) << ", slope: " << slope << ", volts: " << volts << std::endl;
+ UHD_LOGV(often) << "Gain interp: gain: " << gain << ", gain_step: " << int(gain_step) << ", slope: " << slope << ", volts: " << volts << std::endl;
return volts;
}
@@ -290,7 +288,7 @@ static double rf_gain_to_voltage(double gain, double lo_freq){
dac_volts = uhd::clip<double>(dac_volts, 0.0, 3.3);
- if (tvrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"tvrx RF AGC gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
@@ -313,7 +311,7 @@ static double if_gain_to_voltage(double gain){
dac_volts = uhd::clip<double>(dac_volts, 0.0, 3.3);
- if (tvrx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"tvrx IF AGC gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
@@ -367,8 +365,7 @@ void tvrx::set_freq(double freq) {
//not FAR off, but we do this to be consistent
if(prev_band != new_band) set_gain(_gains["RF"], "RF");
- if(tvrx_debug)
- std::cout << boost::format("set_freq: target LO: %f f_ref: %f divisor: %i actual LO: %f") % target_lo_freq % f_ref % divisor % actual_lo_freq << std::endl;
+ UHD_LOGV(often) << boost::format("set_freq: target LO: %f f_ref: %f divisor: %i actual LO: %f") % target_lo_freq % f_ref % divisor % actual_lo_freq << std::endl;
_lo_freq = actual_lo_freq; //for rx props
}
@@ -430,14 +427,13 @@ void tvrx::rx_get(const wax::obj &key_, wax::obj &val){
*/
codec_rate = this->get_iface()->get_codec_rate(dboard_iface::UNIT_RX);
val = (_lo_freq - tvrx_if_freq) + get_alias(tvrx_if_freq, codec_rate);
- if(tvrx_debug) {
- std::cout << "Getting TVRX freq..." << std::endl;
- std::cout << "\tCodec rate: " << codec_rate << std::endl;
- std::cout << "\tLO freq: " << _lo_freq << std::endl;
- std::cout << "\tIF freq: " << tvrx_if_freq << std::endl;
- std::cout << "\tAlias freq: " << get_alias(tvrx_if_freq, codec_rate) << std::endl;
- std::cout << "\tCalculated freq: " << val.as<double>() << std::endl;
- }
+ UHD_LOGV(often)
+ << "Getting TVRX freq..." << std::endl
+ << "\tCodec rate: " << codec_rate << std::endl
+ << "\tLO freq: " << _lo_freq << std::endl
+ << "\tIF freq: " << tvrx_if_freq << std::endl
+ << "\tAlias freq: " << get_alias(tvrx_if_freq, codec_rate) << std::endl
+ << "\tCalculated freq: " << val.as<double>() << std::endl;
return;
case SUBDEV_PROP_FREQ_RANGE:
@@ -489,9 +485,7 @@ void tvrx::rx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("TVRX: No tunable bandwidth, fixed filtered to 6MHz"))
- );
+ UHD_MSG(warning) << "TVRX: No tunable bandwidth, fixed filtered to 6MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
diff --git a/host/lib/usrp/dboard/db_unknown.cpp b/host/lib/usrp/dboard/db_unknown.cpp
index cef4bee4a..6cacab231 100644
--- a/host/lib/usrp/dboard/db_unknown.cpp
+++ b/host/lib/usrp/dboard/db_unknown.cpp
@@ -19,7 +19,7 @@
#include <uhd/types/ranges.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/static.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/usrp/dboard_base.hpp>
#include <uhd/usrp/dboard_manager.hpp>
#include <boost/assign/list_of.hpp>
@@ -50,11 +50,11 @@ static void warn_if_old_rfx(const dboard_id_t &dboard_id, const std::string &xx)
if (
(xx == "RX" and rx_id == dboard_id) or
(xx == "TX" and tx_id == dboard_id)
- ) uhd::warning::post(str(boost::format(
+ ) UHD_MSG(warning) << boost::format(
"Detected %s daughterboard %s\n"
"This board requires modification to use.\n"
"See the daughterboard application notes.\n"
- ) % xx % name));
+ ) % xx % name;
}
}
@@ -183,9 +183,7 @@ void unknown_rx::rx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("Unknown Daughterboard: No tunable bandwidth, fixed filtered to 0.0MHz"))
- );
+ UHD_MSG(warning) << "Unknown Daughterboard: No tunable bandwidth, fixed filtered to 0.0MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
@@ -281,9 +279,7 @@ void unknown_tx::tx_set(const wax::obj &key_, const wax::obj &val){
return; //always enabled
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("Unknown Daughterboard: No tunable bandwidth, fixed filtered to 0.0MHz"))
- );
+ UHD_MSG(warning) << "Unknown Daughterboard: No tunable bandwidth, fixed filtered to 0.0MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
diff --git a/host/lib/usrp/dboard/db_wbx_common.cpp b/host/lib/usrp/dboard/db_wbx_common.cpp
index eb239c305..131729f42 100644
--- a/host/lib/usrp/dboard/db_wbx_common.cpp
+++ b/host/lib/usrp/dboard/db_wbx_common.cpp
@@ -51,13 +51,14 @@
#include "db_wbx_common.hpp"
#include "adf4350_regs.hpp"
+#include <uhd/utils/log.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/usrp/subdev_props.hpp>
#include <uhd/types/ranges.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/algorithm.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/usrp/dboard_base.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
@@ -70,8 +71,6 @@ using namespace boost::assign;
/***********************************************************************
* The WBX Common dboard constants
**********************************************************************/
-static const bool wbx_debug = false;
-
static const uhd::dict<std::string, gain_range_t> wbx_tx_gain_ranges = map_list_of
("PGA0", gain_range_t(0, 25, 0.05))
;
@@ -150,7 +149,7 @@ static int rx_pga0_gain_to_iobits(double &gain){
int attn_code = boost::math::iround(attn*2);
int iobits = ((~attn_code) << RX_ATTN_SHIFT) & RX_ATTN_MASK;
- if (wbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"WBX Attenuation: %f dB, Code: %d, IO Bits %x, Mask: %x"
) % attn % attn_code % (iobits & RX_ATTN_MASK) % RX_ATTN_MASK << std::endl;
@@ -171,7 +170,7 @@ static double tx_pga0_gain_to_dac_volts(double &gain){
//calculate the voltage for the aux dac
double dac_volts = gain*slope + min_volts;
- if (wbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"WBX TX Gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
@@ -212,7 +211,7 @@ double wbx_base::set_lo_freq(
dboard_iface::unit_t unit,
double target_freq
){
- if (wbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"WBX tune: target frequency %f Mhz"
) % (target_freq/1e6) << std::endl;
@@ -306,14 +305,13 @@ double wbx_base::set_lo_freq(
actual_freq = double((N + (double(FRAC)/double(MOD)))*ref_freq*(1+int(D))/(R*(1+int(T)))/RFdiv/2);
- if (wbx_debug) {
- std::cerr << boost::format("WBX Intermediates: ref=%0.2f, outdiv=%f, fbdiv=%f") % (ref_freq*(1+int(D))/(R*(1+int(T)))) % double(RFdiv*2) % double(N + double(FRAC)/double(MOD)) << std::endl;
+ UHD_LOGV(often)
+ << boost::format("WBX Intermediates: ref=%0.2f, outdiv=%f, fbdiv=%f") % (ref_freq*(1+int(D))/(R*(1+int(T)))) % double(RFdiv*2) % double(N + double(FRAC)/double(MOD)) << std::endl
- std::cerr << boost::format("WBX tune: R=%d, BS=%d, N=%d, FRAC=%d, MOD=%d, T=%d, D=%d, RFdiv=%d, LD=%d"
+ << boost::format("WBX tune: R=%d, BS=%d, N=%d, FRAC=%d, MOD=%d, T=%d, D=%d, RFdiv=%d, LD=%d"
) % R % BS % N % FRAC % MOD % T % D % RFdiv % get_locked(unit)<< std::endl
<< boost::format("WBX Frequencies (MHz): REQ=%0.2f, ACT=%0.2f, VCO=%0.2f, PFD=%0.2f, BAND=%0.2f"
) % (target_freq/1e6) % (actual_freq/1e6) % (vco_freq/1e6) % (pfd_freq/1e6) % (pfd_freq/BS/1e6) << std::endl;
- }
//load the register values
adf4350_regs_t regs;
@@ -363,7 +361,7 @@ double wbx_base::set_lo_freq(
int addr;
for(addr=5; addr>=0; addr--){
- if (wbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"WBX SPI Reg (0x%02x): 0x%08x"
) % addr % regs.get_reg(addr) << std::endl;
this->get_iface()->write_spi(
@@ -373,7 +371,7 @@ double wbx_base::set_lo_freq(
}
//return the actual frequency
- if (wbx_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"WBX tune: actual frequency %f Mhz"
) % (actual_freq/1e6) << std::endl;
return actual_freq;
@@ -474,9 +472,7 @@ void wbx_base::rx_set(const wax::obj &key_, const wax::obj &val){
return;
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("WBX: No tunable bandwidth, fixed filtered to 40MHz"))
- );
+ UHD_MSG(warning) << "WBX: No tunable bandwidth, fixed filtered to 40MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
@@ -574,9 +570,7 @@ void wbx_base::tx_set(const wax::obj &key_, const wax::obj &val){
return;
case SUBDEV_PROP_BANDWIDTH:
- uhd::warning::post(
- str(boost::format("WBX: No tunable bandwidth, fixed filtered to 40MHz"))
- );
+ UHD_MSG(warning) << "WBX: No tunable bandwidth, fixed filtered to 40MHz";
return;
default: UHD_THROW_PROP_SET_ERROR();
diff --git a/host/lib/usrp/dboard/db_wbx_simple.cpp b/host/lib/usrp/dboard/db_wbx_simple.cpp
index 390b4474b..c9ae7f23a 100644
--- a/host/lib/usrp/dboard/db_wbx_simple.cpp
+++ b/host/lib/usrp/dboard/db_wbx_simple.cpp
@@ -37,8 +37,6 @@ using namespace boost::assign;
/***********************************************************************
* The WBX Simple dboard constants
**********************************************************************/
-static const bool wbx_debug = false;
-
static const freq_range_t wbx_freq_range(68.75e6, 2.2e9);
static const prop_names_t wbx_tx_antennas = list_of("TX/RX");
diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp
index 45f600569..c775eae38 100644
--- a/host/lib/usrp/dboard/db_xcvr2450.cpp
+++ b/host/lib/usrp/dboard/db_xcvr2450.cpp
@@ -48,10 +48,10 @@
#define RX_DIS_RXIO 0
#include "max2829_regs.hpp"
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/algorithm.hpp>
-#include <uhd/utils/warning.hpp>
#include <uhd/types/ranges.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/types/dict.hpp>
@@ -71,8 +71,6 @@ using namespace boost::assign;
/***********************************************************************
* The XCVR 2450 constants
**********************************************************************/
-static const bool xcvr2450_debug = false;
-
static const freq_range_t xcvr_freq_range = list_of
(range_t(2.4e9, 2.5e9))
(range_t(4.9e9, 6.0e9))
@@ -127,7 +125,7 @@ private:
void spi_reset(void);
void send_reg(boost::uint8_t addr){
boost::uint32_t value = _max2829_regs.get_reg(addr);
- if(xcvr2450_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"XCVR2450: send reg 0x%02x, value 0x%05x"
) % int(addr) % value << std::endl;
this->get_iface()->write_spi(
@@ -302,7 +300,7 @@ void xcvr2450::set_lo_freq(double target_freq){
double N = double(intdiv) + double(fracdiv)/double(1 << 16);
_lo_freq = (N*ref_freq)/(scaler*R*_ad9515div);
- if (xcvr2450_debug) std::cerr
+ UHD_LOGV(often)
<< boost::format("XCVR2450 tune:\n")
<< boost::format(" R=%d, N=%f, ad9515=%d, scaler=%f\n") % R % N % _ad9515div % scaler
<< boost::format(" Ref Freq=%fMHz\n") % (ref_freq/1e6)
@@ -312,10 +310,10 @@ void xcvr2450::set_lo_freq(double target_freq){
//high-high band or low-high band?
if(_lo_freq > (5.35e9 + 5.47e9)/2.0){
- if (xcvr2450_debug) std::cerr << "XCVR2450 tune: Using high-high band" << std::endl;
+ UHD_LOGV(often) << "XCVR2450 tune: Using high-high band" << std::endl;
_max2829_regs.band_select_802_11a = max2829_regs_t::BAND_SELECT_802_11A_5_47GHZ_TO_5_875GHZ;
}else{
- if (xcvr2450_debug) std::cerr << "XCVR2450 tune: Using low-high band" << std::endl;
+ UHD_LOGV(often) << "XCVR2450 tune: Using low-high band" << std::endl;
_max2829_regs.band_select_802_11a = max2829_regs_t::BAND_SELECT_802_11A_4_9GHZ_TO_5_35GHZ;
}
@@ -547,7 +545,7 @@ void xcvr2450::set_rx_bandwidth(double bandwidth){
//update register
send_reg(0x7);
- if (xcvr2450_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"XCVR2450 RX Bandwidth (lp_fc): %f Hz, coarse reg: %d, fine reg: %d"
) % _rx_bandwidth % (int(_max2829_regs.rx_lpf_coarse_adj)) % (int(_max2829_regs.rx_lpf_fine_adj)) << std::endl;
}
@@ -562,7 +560,7 @@ void xcvr2450::set_tx_bandwidth(double bandwidth){
//update register
send_reg(0x7);
- if (xcvr2450_debug) std::cerr << boost::format(
+ UHD_LOGV(often) << boost::format(
"XCVR2450 TX Bandwidth (lp_fc): %f Hz, coarse reg: %d"
) % _tx_bandwidth % (int(_max2829_regs.tx_lpf_coarse_adj)) << std::endl;
}
diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp
index c1e44fb74..0dc3471f7 100644
--- a/host/lib/usrp/dboard_eeprom.cpp
+++ b/host/lib/usrp/dboard_eeprom.cpp
@@ -17,16 +17,15 @@
#include <uhd/usrp/dboard_eeprom.hpp>
#include <uhd/exception.hpp>
+#include <uhd/utils/log.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <algorithm>
-#include <iostream>
+#include <sstream>
using namespace uhd;
using namespace uhd::usrp;
-static const bool _dboard_eeprom_debug = false;
-
/***********************************************************************
* Utility functions
**********************************************************************/
@@ -91,8 +90,7 @@ static boost::uint8_t checksum(const byte_vector_t &bytes){
for (size_t i = 0; i < std::min(bytes.size(), size_t(DB_EEPROM_CHKSUM)); i++){
sum -= int(bytes.at(i));
}
- if (_dboard_eeprom_debug)
- std::cout << boost::format("sum: 0x%02x") % sum << std::endl;
+ UHD_LOGV(often) << boost::format("sum: 0x%02x") % sum << std::endl;
return boost::uint8_t(sum);
}
@@ -104,13 +102,13 @@ dboard_eeprom_t::dboard_eeprom_t(void){
void dboard_eeprom_t::load(i2c_iface &iface, boost::uint8_t addr){
byte_vector_t bytes = iface.read_eeprom(addr, 0, DB_EEPROM_CLEN);
- if (_dboard_eeprom_debug){
- for (size_t i = 0; i < bytes.size(); i++){
- std::cout << boost::format(
- "eeprom byte[0x%02x] = 0x%02x") % i % int(bytes.at(i)
- ) << std::endl;
- }
+ std::ostringstream ss;
+ for (size_t i = 0; i < bytes.size(); i++){
+ ss << boost::format(
+ "eeprom byte[0x%02x] = 0x%02x") % i % int(bytes.at(i)
+ ) << std::endl;
}
+ UHD_LOGV(often) << ss.str() << std::endl;
try{
UHD_ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN);
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index 2e8b39311..11b72b9fa 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -18,7 +18,8 @@
#include "dboard_ctor_args.hpp"
#include <uhd/usrp/dboard_manager.hpp>
#include <uhd/usrp/subdev_props.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/exception.hpp>
#include <uhd/types/dict.hpp>
@@ -27,7 +28,6 @@
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>
-#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
@@ -91,7 +91,7 @@ static void register_dboard_key(
const std::string &name,
const prop_names_t &subdev_names
){
- //std::cout << "registering: " << name << std::endl;
+ UHD_LOGV(always) << "registering: " << name << std::endl;
if (get_id_to_args_map().has_key(dboard_key)){
if (dboard_key.is_xcvr()) throw uhd::key_error(str(boost::format(
@@ -240,7 +240,7 @@ dboard_manager_impl::dboard_manager_impl(
this->init(rx_dboard_id, tx_dboard_id);
}
catch(const std::exception &e){
- uhd::warning::post(e.what());
+ UHD_MSG(error) << "The daughterboard manager encountered a recoverable error in init" << std::endl << e.what();
this->init(dboard_id_t::none(), dboard_id_t::none());
}
}
@@ -264,12 +264,12 @@ void dboard_manager_impl::init(
//warn for invalid dboard id xcvr combinations
if (not xcvr_dboard_key.is_xcvr() and (rx_dboard_key.is_xcvr() or tx_dboard_key.is_xcvr())){
- uhd::warning::post(str(boost::format(
+ UHD_MSG(warning) << boost::format(
"Unknown transceiver board ID combination.\n"
"Is your daughter-board mounted properly?\n"
"RX dboard ID: %s\n"
"TX dboard ID: %s\n"
- ) % rx_dboard_id.to_pp_string() % tx_dboard_id.to_pp_string()));
+ ) % rx_dboard_id.to_pp_string() % tx_dboard_id.to_pp_string();
}
//initialize the gpio pins before creating subdevs
diff --git a/host/lib/usrp/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp
index de97710f2..3bee26340 100644
--- a/host/lib/usrp/gps_ctrl.cpp
+++ b/host/lib/usrp/gps_ctrl.cpp
@@ -16,6 +16,7 @@
//
#include <uhd/usrp/gps_ctrl.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
#include <boost/cstdint.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -67,14 +68,14 @@ public:
//otherwise, we can try some other common baud rates looking to see if a GPS is connected (todo, later)
if((gps_type == GPS_TYPE_NONE) && i_heard_something_weird) {
- std::cout << "GPS invalid reply \"" << reply << "\", assuming none available" << std::endl;
+ UHD_MSG(error) << "GPS invalid reply \"" << reply << "\", assuming none available" << std::endl;
}
bool found_gprmc = false;
switch(gps_type) {
case GPS_TYPE_JACKSON_LABS:
- std::cout << "Found a Jackson Labs GPS" << std::endl;
+ UHD_MSG(status) << "Found a Jackson Labs GPS" << std::endl;
//issue some setup stuff so it spits out the appropriate data
//none of these should issue replies so we don't bother looking for them
//we have to sleep between commands because the JL device, despite not acking, takes considerable time to process each command.
@@ -93,7 +94,7 @@ public:
// break;
case GPS_TYPE_GENERIC_NMEA:
- if(gps_type == GPS_TYPE_GENERIC_NMEA) std::cout << "Found a generic NMEA GPS device" << std::endl;
+ if(gps_type == GPS_TYPE_GENERIC_NMEA) UHD_MSG(status) << "Found a generic NMEA GPS device" << std::endl;
found_gprmc = false;
//here we loop around looking for a GPRMC packet. if we don't get one, we don't have a usable GPS.
timeout = GPS_TIMEOUT_TRIES;
@@ -106,8 +107,8 @@ public:
boost::this_thread::sleep(boost::posix_time::milliseconds(200));
}
if(!found_gprmc) {
- if(gps_type == GPS_TYPE_JACKSON_LABS) std::cout << "Firefly GPS not locked or warming up." << std::endl;
- else std::cout << "GPS does not output GPRMC packets. Cannot retrieve time." << std::endl;
+ if(gps_type == GPS_TYPE_JACKSON_LABS) UHD_MSG(error) << "Firefly GPS not locked or warming up." << std::endl;
+ else UHD_MSG(error) << "GPS does not output GPRMC packets. Cannot retrieve time." << std::endl;
gps_type = GPS_TYPE_NONE;
}
break;
diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp
index 83cbf339b..64f82e559 100644
--- a/host/lib/usrp/multi_usrp.cpp
+++ b/host/lib/usrp/multi_usrp.cpp
@@ -18,8 +18,9 @@
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/usrp/tune_helper.hpp>
#include <uhd/usrp/mboard_iface.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/utils/gain_group.hpp>
#include <uhd/usrp/subdev_props.hpp>
#include <uhd/usrp/mboard_props.hpp>
@@ -29,7 +30,6 @@
#include <boost/thread.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
-#include <iostream>
#include <cmath>
using namespace uhd;
@@ -55,11 +55,11 @@ static inline void do_samp_rate_warning_message(
){
static const double max_allowed_error = 1.0; //Sps
if (std::abs(target_rate - actual_rate) > max_allowed_error){
- uhd::warning::post(str(boost::format(
+ UHD_MSG(warning) << boost::format(
"The hardware does not support the requested %s sample rate:\n"
"Target sample rate: %f MSps\n"
"Actual sample rate: %f MSps\n"
- ) % xx % (target_rate/1e6) % (actual_rate/1e6)));
+ ) % xx % (target_rate/1e6) % (actual_rate/1e6);
}
}
@@ -70,11 +70,11 @@ static inline void do_tune_freq_warning_message(
){
static const double max_allowed_error = 1.0; //Hz
if (std::abs(target_freq - actual_freq) > max_allowed_error){
- uhd::warning::post(str(boost::format(
+ UHD_MSG(warning) << boost::format(
"The hardware does not support the requested %s frequency:\n"
"Target frequency: %f MHz\n"
"Actual frequency: %f MHz\n"
- ) % xx % (target_freq/1e6) % (actual_freq/1e6)));
+ ) % xx % (target_freq/1e6) % (actual_freq/1e6);
}
}
@@ -188,7 +188,7 @@ public:
}
void set_time_unknown_pps(const time_spec_t &time_spec){
- std::cout << " 1) catch time transition at pps edge" << std::endl;
+ UHD_MSG(status) << " 1) catch time transition at pps edge" << std::endl;
time_spec_t time_start = get_time_now();
time_spec_t time_start_last_pps = get_time_last_pps();
while(true){
@@ -202,7 +202,7 @@ public:
}
}
- std::cout << " 2) set times next pps (synchronously)" << std::endl;
+ UHD_MSG(status) << " 2) set times next pps (synchronously)" << std::endl;
set_time_next_pps(time_spec);
boost::this_thread::sleep(boost::posix_time::seconds(1));
@@ -211,11 +211,11 @@ public:
time_spec_t time_0 = _mboard(0)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
time_spec_t time_i = _mboard(m)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
if (time_i < time_0 or (time_i - time_0) > time_spec_t(0.01)){ //10 ms: greater than RTT but not too big
- uhd::warning::post(str(boost::format(
+ UHD_MSG(warning) << boost::format(
"Detected time deviation between board %d and board 0.\n"
"Board 0 time is %f seconds.\n"
"Board %d time is %f seconds.\n"
- ) % m % time_0.get_real_secs() % m % time_i.get_real_secs()));
+ ) % m % time_0.get_real_secs() % m % time_i.get_real_secs();
}
}
}
diff --git a/host/lib/usrp/usrp1/clock_ctrl.cpp b/host/lib/usrp/usrp1/clock_ctrl.cpp
index 154e6a316..9edc010dd 100644
--- a/host/lib/usrp/usrp1/clock_ctrl.cpp
+++ b/host/lib/usrp/usrp1/clock_ctrl.cpp
@@ -16,9 +16,9 @@
//
#include "clock_ctrl.hpp"
+#include <uhd/utils/msg.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
-#include <iostream>
using namespace uhd;
@@ -36,14 +36,14 @@ public:
this->set_master_clock_freq(default_master_clock_rate);
try{
if (not _iface->mb_eeprom["mcr"].empty()){
- std::cout << "Read FPGA clock rate from EEPROM setting." << std::endl;
+ UHD_MSG(status) << "Read FPGA clock rate from EEPROM setting." << std::endl;
const double master_clock_rate = boost::lexical_cast<double>(_iface->mb_eeprom["mcr"]);
- std::cout << boost::format("Initializing FPGA clock to %fMHz...") % (master_clock_rate/1e6) << std::endl;
+ UHD_MSG(status) << boost::format("Initializing FPGA clock to %fMHz...") % (master_clock_rate/1e6) << std::endl;
this->set_master_clock_freq(master_clock_rate);
}
}
catch(const std::exception &e){
- std::cerr << "Error setting FPGA clock rate from EEPROM: " << e.what() << std::endl;
+ UHD_MSG(error) << "Error setting FPGA clock rate from EEPROM: " << e.what() << std::endl;
}
}
diff --git a/host/lib/usrp/usrp1/codec_ctrl.cpp b/host/lib/usrp/usrp1/codec_ctrl.cpp
index 9df29da0e..64a93ede5 100644
--- a/host/lib/usrp/usrp1/codec_ctrl.cpp
+++ b/host/lib/usrp/usrp1/codec_ctrl.cpp
@@ -19,6 +19,7 @@
#include "usrp_commands.h"
#include "clock_ctrl.hpp"
#include "ad9862_regs.hpp"
+#include <uhd/utils/log.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/algorithm.hpp>
@@ -28,13 +29,10 @@
#include <boost/tuple/tuple.hpp>
#include <boost/math/special_functions/round.hpp>
#include <boost/assign/list_of.hpp>
-#include <iostream>
#include <iomanip>
using namespace uhd;
-static const bool codec_debug = false;
-
const gain_range_t usrp1_codec_ctrl::tx_pga_gain_range(-20, 0, double(0.1));
const gain_range_t usrp1_codec_ctrl::rx_pga_gain_range(0, 20, 1);
@@ -283,11 +281,10 @@ void usrp1_codec_ctrl_impl::send_reg(boost::uint8_t addr)
{
boost::uint32_t reg = _ad9862_regs.get_write_reg(addr);
- if (codec_debug) {
- std::cout.fill('0');
- std::cout << "codec control write reg: 0x";
- std::cout << std::setw(8) << std::hex << reg << std::endl;
- }
+ UHD_LOGV(often)
+ << "codec control write reg: 0x"
+ << std::setw(8) << std::hex << reg << std::endl
+ ;
_iface->write_spi(_spi_slave,
spi_config_t::EDGE_RISE, reg, 16);
}
@@ -296,20 +293,18 @@ void usrp1_codec_ctrl_impl::recv_reg(boost::uint8_t addr)
{
boost::uint32_t reg = _ad9862_regs.get_read_reg(addr);
- if (codec_debug) {
- std::cout.fill('0');
- std::cout << "codec control read reg: 0x";
- std::cout << std::setw(8) << std::hex << reg << std::endl;
- }
+ UHD_LOGV(often)
+ << "codec control read reg: 0x"
+ << std::setw(8) << std::hex << reg << std::endl
+ ;
boost::uint32_t ret = _iface->read_spi(_spi_slave,
spi_config_t::EDGE_RISE, reg, 16);
- if (codec_debug) {
- std::cout.fill('0');
- std::cout << "codec control read ret: 0x";
- std::cout << std::setw(8) << std::hex << ret << std::endl;
- }
+ UHD_LOGV(often)
+ << "codec control read ret: 0x"
+ << std::setw(8) << std::hex << ret << std::endl
+ ;
_ad9862_regs.set_reg(addr, boost::uint16_t(ret));
}
@@ -392,14 +387,14 @@ void usrp1_codec_ctrl_impl::set_duc_freq(double freq)
double coarse_freq = coarse_tune(codec_rate, freq);
double fine_freq = fine_tune(codec_rate / 4, freq - coarse_freq);
- if (codec_debug) {
- std::cout << "ad9862 tuning result:" << std::endl;
- std::cout << " requested: " << freq << std::endl;
- std::cout << " actual: " << coarse_freq + fine_freq << std::endl;
- std::cout << " coarse freq: " << coarse_freq << std::endl;
- std::cout << " fine freq: " << fine_freq << std::endl;
- std::cout << " codec rate: " << codec_rate << std::endl;
- }
+ UHD_LOG
+ << "ad9862 tuning result:" << std::endl
+ << " requested: " << freq << std::endl
+ << " actual: " << coarse_freq + fine_freq << std::endl
+ << " coarse freq: " << coarse_freq << std::endl
+ << " fine freq: " << fine_freq << std::endl
+ << " codec rate: " << codec_rate << std::endl
+ ;
this->send_reg(20);
this->send_reg(21);
diff --git a/host/lib/usrp/usrp1/dsp_impl.cpp b/host/lib/usrp/usrp1/dsp_impl.cpp
index 8152c4e34..9f1e4975a 100644
--- a/host/lib/usrp/usrp1/dsp_impl.cpp
+++ b/host/lib/usrp/usrp1/dsp_impl.cpp
@@ -17,13 +17,13 @@
#include "usrp1_impl.hpp"
#include "fpga_regs_standard.h"
+#include <uhd/utils/msg.hpp>
#include <uhd/usrp/dsp_utils.hpp>
#include <uhd/usrp/dsp_props.hpp>
#include <boost/bind.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/assign/list_of.hpp>
-#include <iostream>
#include <cmath>
using namespace uhd;
@@ -104,7 +104,7 @@ void usrp1_impl::rx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh
size_t rate = size_t(_clock_ctrl->get_master_clock_freq() / val.as<double>());
if ((rate & 0x01) || (rate < 4) || (rate > 256)) {
- std::cerr << "Decimation must be even and between 4 and 256"
+ UHD_MSG(error) << "Decimation must be even and between 4 and 256"
<< std::endl;
return;
}
@@ -202,7 +202,7 @@ void usrp1_impl::tx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh
size_t rate = size_t(_clock_ctrl->get_master_clock_freq() * 2 / val.as<double>());
if ((rate & 0x01) || (rate < 8) || (rate > 512)) {
- std::cerr << "Interpolation rate must be even and between 8 and 512"
+ UHD_MSG(error) << "Interpolation rate must be even and between 8 and 512"
<< std::endl;
return;
}
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 8fb639c4a..22d078e70 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -18,6 +18,7 @@
#include "../../transport/vrt_packet_handler.hpp"
#include "usrp_commands.h"
#include "usrp1_impl.hpp"
+#include <uhd/utils/msg.hpp>
#include <uhd/utils/safe_call.hpp>
#include <uhd/utils/thread_priority.hpp>
#include <uhd/transport/bounded_buffer.hpp>
@@ -26,7 +27,6 @@
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
-#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
@@ -306,8 +306,8 @@ size_t usrp1_impl::send(
VRQ_GET_STATUS, 0, GS_TX_UNDERRUN,
&underflow, sizeof(underflow)
);
- if (ret < 0) std::cerr << "USRP: underflow check failed" << std::endl;
- else if (underflow) std::cerr << "U" << std::flush;
+ if (ret < 0) UHD_MSG(error) << "USRP: underflow check failed" << std::endl;
+ else if (underflow) UHD_MSG(fastpath) << "U";
}
return num_samps_sent;
@@ -370,8 +370,8 @@ size_t usrp1_impl::recv(
VRQ_GET_STATUS, 0, GS_RX_OVERRUN,
&overflow, sizeof(overflow)
);
- if (ret < 0) std::cerr << "USRP: overflow check failed" << std::endl;
- else if (overflow) std::cerr << "O" << std::flush;
+ if (ret < 0) UHD_MSG(error) << "USRP: overflow check failed" << std::endl;
+ else if (overflow) UHD_MSG(fastpath) << "O";
}
return num_samps_recvd;
diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp
index eecae3fa7..cd04e7351 100644
--- a/host/lib/usrp/usrp1/mboard_impl.cpp
+++ b/host/lib/usrp/usrp1/mboard_impl.cpp
@@ -20,24 +20,23 @@
#include "fpga_regs_standard.h"
#include "fpga_regs_common.h"
#include "usrp_i2c_addr.h"
+#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/usrp/misc_utils.hpp>
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/usrp/dboard_props.hpp>
#include <uhd/usrp/subdev_props.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/images.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <boost/thread/thread.hpp>
-#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
-static const bool usrp1_mboard_verbose = false;
-
/***********************************************************************
* Calculate the RX mux value:
* The I and Q mux values are intentionally reversed to flip I and Q
@@ -98,7 +97,7 @@ static boost::uint32_t calc_rx_mux(
// for all quadrature sources: Z = 0
// for mixed sources: warning + Z = 0
int Z = (num_quads > 0)? 0 : 1;
- if (num_quads != 0 and num_reals != 0) uhd::warning::post(
+ if (num_quads != 0 and num_reals != 0) UHD_MSG(warning) << boost::format(
"Mixing real and quadrature rx subdevices is not supported.\n"
"The Q input to the real source(s) will be non-zero.\n"
);
@@ -231,13 +230,13 @@ void usrp1_impl::mboard_init(void)
// Set default for TX format to 16-bit I&Q
_iface->poke32(FR_TX_FORMAT, 0x00000000);
- if (usrp1_mboard_verbose){
- std::cout << "USRP1 Capabilities" << std::endl;
- std::cout << " number of duc's: " << get_num_ddcs() << std::endl;
- std::cout << " number of ddc's: " << get_num_ducs() << std::endl;
- std::cout << " rx halfband: " << has_rx_halfband() << std::endl;
- std::cout << " tx halfband: " << has_tx_halfband() << std::endl;
- }
+ UHD_LOG
+ << "USRP1 Capabilities" << std::endl
+ << " number of duc's: " << get_num_ddcs() << std::endl
+ << " number of ddc's: " << get_num_ducs() << std::endl
+ << " rx halfband: " << has_rx_halfband() << std::endl
+ << " tx halfband: " << has_tx_halfband() << std::endl
+ ;
}
/***********************************************************************
@@ -331,7 +330,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val)
if(key.type() == typeid(std::string)) {
if(key.as<std::string>() == "load_eeprom") {
std::string usrp1_eeprom_image = val.as<std::string>();
- std::cout << "USRP1 EEPROM image: " << usrp1_eeprom_image << std::endl;
+ UHD_MSG(status) << "USRP1 EEPROM image: " << usrp1_eeprom_image << std::endl;
_ctrl_transport->usrp_load_eeprom(val.as<std::string>());
}
return;
@@ -378,10 +377,11 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val)
return;
case MBOARD_PROP_CLOCK_RATE:
- std::cerr << "Helpful message:" << std::endl;
- std::cerr << " I see that you are setting the master clock rate from the API." << std::endl;
- std::cerr << " You may find it more convenient to burn this setting into the EEPROM." << std::endl;
- std::cerr << " See the application notes for USRP1 for further instructions." << std::endl;
+ UHD_MSG(warning)
+ << "I see that you are setting the master clock rate from the API.\n"
+ << "You may find it more convenient to burn this setting into the EEPROM.\n"
+ << "See the application notes for USRP1 for further instructions.\n"
+ ;
_clock_ctrl->set_master_clock_freq(val.as<double>());
return;
diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.cpp b/host/lib/usrp/usrp1/usrp1_ctrl.cpp
index c6be28f5f..96dc5d80c 100644
--- a/host/lib/usrp/usrp1/usrp1_ctrl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_ctrl.cpp
@@ -17,11 +17,11 @@
#include "usrp1_ctrl.hpp"
#include "usrp_commands.h"
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
#include <uhd/transport/usb_control.hpp>
#include <boost/functional/hash.hpp>
#include <boost/thread/thread.hpp>
-#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
@@ -162,7 +162,7 @@ public:
unsigned char reset_n = 0;
//hit the reset line
- if (load_img_msg) std::cout << "Loading firmware image: " << filestring << "..." << std::flush;
+ if (load_img_msg) UHD_MSG(status) << "Loading firmware image: " << filestring << "..." << std::flush;
usrp_control_write(FX2_FIRMWARE_LOAD, 0xe600, 0, &reset_y, 1);
while (!file.eof()) {
@@ -187,7 +187,7 @@ public:
//wait for things to settle
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
- if (load_img_msg) std::cout << " done" << std::endl;
+ if (load_img_msg) UHD_MSG(status) << " done" << std::endl;
return;
}
//type anything else is unhandled
@@ -228,7 +228,7 @@ public:
const int ep0_size = 64;
unsigned char buf[ep0_size];
- if (load_img_msg) std::cout << "Loading FPGA image: " << filestring << "..." << std::flush;
+ if (load_img_msg) UHD_MSG(status) << "Loading FPGA image: " << filestring << "..." << std::flush;
std::ifstream file;
file.open(filename, std::ios::in | std::ios::binary);
if (not file.good()) {
@@ -259,7 +259,7 @@ public:
usrp_fpga_reset(false); //done loading, take fpga out of reset
file.close();
- if (load_img_msg) std::cout << " done" << std::endl;
+ if (load_img_msg) UHD_MSG(status) << " done" << std::endl;
}
void usrp_load_eeprom(std::string filestring)
diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp
index 8f10df751..0942e2613 100644
--- a/host/lib/usrp/usrp1/usrp1_iface.cpp
+++ b/host/lib/usrp/usrp1/usrp1_iface.cpp
@@ -17,19 +17,17 @@
#include "usrp1_iface.hpp"
#include "usrp_commands.h"
+#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/byteswap.hpp>
#include <boost/format.hpp>
#include <stdexcept>
-#include <iostream>
#include <iomanip>
using namespace uhd;
using namespace uhd::usrp;
using namespace uhd::transport;
-static const bool iface_debug = false;
-
class usrp1_iface_impl : public usrp1_iface{
public:
/*******************************************************************
@@ -53,12 +51,11 @@ public:
{
boost::uint32_t swapped = uhd::htonx(value);
- if (iface_debug) {
- std::cout.fill('0');
- std::cout << "poke32(";
- std::cout << std::dec << std::setw(2) << addr << ", 0x";
- std::cout << std::hex << std::setw(8) << value << ")" << std::endl;
- }
+ UHD_LOGV(always)
+ << "poke32("
+ << std::dec << std::setw(2) << addr << ", 0x"
+ << std::hex << std::setw(8) << value << ")" << std::endl
+ ;
boost::uint8_t w_index_h = SPI_ENABLE_FPGA & 0xff;
boost::uint8_t w_index_l = (SPI_FMT_MSB | SPI_FMT_HDR_1) & 0xff;
@@ -75,6 +72,11 @@ public:
boost::uint32_t peek32(boost::uint32_t addr)
{
+ UHD_LOGV(always)
+ << "peek32("
+ << std::dec << std::setw(2) << addr << ")" << std::endl
+ ;
+
boost::uint32_t value_out;
boost::uint8_t w_index_h = SPI_ENABLE_FPGA & 0xff;
@@ -119,6 +121,10 @@ public:
void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes)
{
+ UHD_LOGV(always) << "write_i2c:" << std::endl
+ << " addr 0x" << std::hex << int(addr) << std::endl
+ << " len " << bytes.size() << std::endl
+ ;
UHD_ASSERT_THROW(bytes.size() < max_i2c_data_bytes);
unsigned char buff[max_i2c_data_bytes];
@@ -129,12 +135,16 @@ public:
bytes.size());
// TODO throw and catch i2c failures during eeprom read
- if (iface_debug && (ret < 0))
- std::cerr << "USRP: failed i2c write: " << ret << std::endl;
+ if (ret < 0)
+ UHD_LOGV(often) << "USRP: failed i2c write: " << ret << std::endl;
}
byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes)
{
+ UHD_LOGV(always) << "read_i2c:" << std::endl
+ << " addr 0x" << std::hex << int(addr) << std::endl
+ << " len " << num_bytes << std::endl
+ ;
UHD_ASSERT_THROW(num_bytes < max_i2c_data_bytes);
unsigned char buff[max_i2c_data_bytes];
@@ -143,8 +153,8 @@ public:
num_bytes);
// TODO throw and catch i2c failures during eeprom read
- if (iface_debug && ((ret < 0) || (unsigned)ret < (num_bytes))) {
- std::cerr << "USRP: failed i2c read: " << ret << std::endl;
+ if (ret < 0 or (unsigned)ret < num_bytes) {
+ UHD_LOGV(often) << "USRP: failed i2c read: " << ret << std::endl;
return byte_vector_t(num_bytes, 0xff);
}
@@ -155,6 +165,17 @@ public:
return out_bytes;
}
+ //! overload read_eeprom to handle multi-byte reads
+ byte_vector_t read_eeprom(
+ boost::uint8_t addr,
+ boost::uint8_t offset,
+ size_t num_bytes
+ ){
+ //do a zero byte write to start read cycle
+ this->write_i2c(addr, byte_vector_t(1, offset));
+ return this->read_i2c(addr, num_bytes); //read all bytes
+ }
+
/*******************************************************************
* SPI
*
@@ -172,6 +193,13 @@ public:
size_t num_bits,
bool readback)
{
+ UHD_LOGV(always)
+ << "transact_spi: " << std::endl
+ << " slave: " << which_slave << std::endl
+ << " bits: " << bits << std::endl
+ << " num_bits: " << num_bits << std::endl
+ << " readback: " << readback << std::endl
+ ;
UHD_ASSERT_THROW((num_bits <= 32) && !(num_bits % 8));
size_t num_bytes = num_bits / 8;
diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp
index a99777775..57aae1b58 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.cpp
@@ -19,11 +19,12 @@
#include "usrp1_ctrl.hpp"
#include "fpga_regs_standard.h"
#include "usrp_spi_defs.h"
+#include <uhd/utils/log.hpp>
#include <uhd/utils/safe_call.hpp>
#include <uhd/transport/usb_control.hpp>
#include <uhd/usrp/device_props.hpp>
#include <uhd/usrp/mboard_props.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/images.hpp>
@@ -32,7 +33,6 @@
#include <boost/filesystem.hpp>
#include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp>
-#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
@@ -78,13 +78,13 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
usrp1_fw_image = find_image_path(hint.get("fw", "usrp1_fw.ihx"));
}
catch(...){
- uhd::warning::post(
+ UHD_MSG(warning) << boost::format(
"Could not locate USRP1 firmware.\n"
"Please install the images package.\n"
);
return usrp1_addrs;
}
- //std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
+ UHD_LOG << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
usb_control::sptr control;
try{control = usb_control::make(handle);}
@@ -123,12 +123,13 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
* Make
**********************************************************************/
static device::sptr usrp1_make(const device_addr_t &device_addr){
+ UHD_MSG(status) << "Opening a USRP1 device..." << std::endl;
//extract the FPGA path for the USRP1
std::string usrp1_fpga_image = find_image_path(
device_addr.get("fpga", "usrp1_fpga.rbf")
);
- //std::cout << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl;
+ UHD_LOG << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl;
//try to match the given device address with something on the USB bus
std::vector<usb_device_handle::sptr> device_list =
diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp
index 0fdcedf62..796888b8f 100644
--- a/host/lib/usrp/usrp2/codec_ctrl.cpp
+++ b/host/lib/usrp/usrp2/codec_ctrl.cpp
@@ -19,12 +19,10 @@
#include "ad9777_regs.hpp"
#include "ads62p44_regs.hpp"
#include "usrp2_regs.hpp"
+#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <boost/cstdint.hpp>
#include <boost/foreach.hpp>
-#include <iostream>
-
-static const bool codec_ctrl_debug = false;
using namespace uhd;
@@ -167,7 +165,7 @@ private:
void send_ad9777_reg(boost::uint8_t addr){
boost::uint16_t reg = _ad9777_regs.get_write_reg(addr);
- if (codec_ctrl_debug) std::cout << "send_ad9777_reg: " << std::hex << reg << std::endl;
+ UHD_LOGV(always) << "send_ad9777_reg: " << std::hex << reg << std::endl;
_iface->write_spi(
SPI_SS_AD9777, spi_config_t::EDGE_RISE,
reg, 16
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index 005be7ce4..33f249599 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -18,6 +18,8 @@
#include "../../transport/vrt_packet_handler.hpp"
#include "usrp2_impl.hpp"
#include "usrp2_regs.hpp"
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/utils/byteswap.hpp>
@@ -266,15 +268,15 @@ void usrp2_impl::io_impl::recv_pirate_loop(
}
//print the famous U, and push the metadata into the message queue
- if (metadata.event_code & underflow_flags) std::cerr << "U" << std::flush;
- //else std::cout << "metadata.event_code " << metadata.event_code << std::endl;
+ if (metadata.event_code & underflow_flags) UHD_MSG(fastpath) << "U";
+ //else UHD_MSG(often) << "metadata.event_code " << metadata.event_code << std::endl;
async_msg_fifo.push_with_pop_on_full(metadata);
}
else{
//TODO unknown received packet, may want to print error...
}
}catch(const std::exception &e){
- std::cerr << "Error (usrp2 recv pirate loop): " << e.what() << std::endl;
+ UHD_MSG(error) << "Error (usrp2 recv pirate loop): " << e.what() << std::endl;
}
}
}
@@ -314,13 +316,13 @@ void usrp2_impl::update_xport_channel_mapping(void){
subdev_spec_t rx_subdev_spec = _mboards[i]->get_link()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>();
for (size_t j = 0; j < rx_subdev_spec.size(); j++){
_io_impl->recv_map.push_back(i*usrp2_mboard_impl::MAX_NUM_DSPS+j);
- //std::cout << "recv_map.back() " << _io_impl->recv_map.back() << std::endl;
+ UHD_LOG << "recv_map.back() " << _io_impl->recv_map.back() << std::endl;
}
subdev_spec_t tx_subdev_spec = _mboards[i]->get_link()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>();
for (size_t j = 0; j < tx_subdev_spec.size(); j++){
_io_impl->send_map.push_back(i*usrp2_mboard_impl::MAX_NUM_DSPS+j);
- //std::cout << "send_map.back() " << _io_impl->send_map.back() << std::endl;
+ UHD_LOG << "send_map.back() " << _io_impl->send_map.back() << std::endl;
}
}
@@ -395,7 +397,7 @@ static UHD_INLINE void extract_packet_info(
//handle the packet count / sequence number
if ((prev_info.packet_count+1)%16 != next_info.packet_count){
- std::cerr << "O" << std::flush; //report overflow (drops in the kernel)
+ UHD_MSG(fastpath) << "O"; //report overflow (drops in the kernel)
}
time = extract_time_spec(next_info);
@@ -504,7 +506,7 @@ size_t usrp2_impl::get_max_recv_samps_per_packet(void) const{
}
void usrp2_impl::handle_overflow(size_t chan){
- std::cerr << "O" << std::flush;
+ UHD_MSG(fastpath) << "O";
ldiv_t indexes = ldiv(chan, usrp2_mboard_impl::NUM_RX_DSPS);
_mboards.at(indexes.quot)->handle_overflow(indexes.rem);
}
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 8582fca38..bb4d90dd6 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -18,6 +18,8 @@
#include "usrp2_impl.hpp"
#include "usrp2_regs.hpp"
#include "fw_common.h"
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/utils/safe_call.hpp>
#include <uhd/exception.hpp>
#include <uhd/usrp/gps_ctrl.hpp>
@@ -29,7 +31,6 @@
#include <uhd/types/sensors.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/bind.hpp>
-#include <iostream>
static const double mimo_clock_delay_usrp2_rev4 = 4.18e-9;
static const double mimo_clock_delay_usrp_n2xx = 3.55e-9;
@@ -84,19 +85,19 @@ usrp2_mboard_impl::usrp2_mboard_impl(
_iface->lock_device(true);
//construct transports for dsp and async errors
- std::cout << "Making transport for DSP0..." << std::endl;
+ UHD_LOG << "Making transport for DSP0..." << std::endl;
device.dsp_xports.push_back(udp_zero_copy::make(
device_addr["addr"], BOOST_STRINGIZE(USRP2_UDP_DSP0_PORT), device_addr
));
init_xport(device.dsp_xports.back());
- std::cout << "Making transport for DSP1..." << std::endl;
+ UHD_LOG << "Making transport for DSP1..." << std::endl;
device.dsp_xports.push_back(udp_zero_copy::make(
device_addr["addr"], BOOST_STRINGIZE(USRP2_UDP_DSP1_PORT), device_addr
));
init_xport(device.dsp_xports.back());
- std::cout << "Making transport for ERR0..." << std::endl;
+ UHD_LOG << "Making transport for ERR0..." << std::endl;
device.err_xports.push_back(udp_zero_copy::make(
device_addr["addr"], BOOST_STRINGIZE(USRP2_UDP_ERR0_PORT), device_addr_t()
));
@@ -144,7 +145,7 @@ usrp2_mboard_impl::usrp2_mboard_impl(
else {
_mimo_clocking_mode_is_master = (_iface->peek32(_iface->regs.status) & (1 << 8)) != 0;
}
- std::cout << boost::format("mboard%d MIMO %s") % _index %
+ UHD_MSG(status) << boost::format("mboard%d is MIMO %s") % _index %
(_mimo_clocking_mode_is_master?"master":"slave") << std::endl;
//init the clock config
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 9c3fb9268..9947e71e7 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -17,13 +17,14 @@
#include "usrp2_impl.hpp"
#include "fw_common.h"
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
#include <uhd/transport/if_addrs.hpp>
#include <uhd/transport/udp_zero_copy.hpp>
#include <uhd/usrp/device_props.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/static.hpp>
-#include <uhd/utils/warning.hpp>
#include <uhd/utils/byteswap.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
@@ -32,7 +33,6 @@
#include <boost/bind.hpp>
#include <boost/asio/ip/address_v4.hpp>
#include <boost/asio.hpp> //used for htonl and ntohl
-#include <iostream>
#include <vector>
using namespace uhd;
@@ -103,7 +103,6 @@ static device_addrs_t usrp2_find(const device_addr_t &hint_){
const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem);
while(true){
size_t len = udp_transport->recv(asio::buffer(usrp2_ctrl_data_in_mem));
- //std::cout << len << "\n";
if (len > offsetof(usrp2_ctrl_data_t, data) and ntohl(ctrl_data_in->id) == USRP2_CTRL_ID_WAZZUP_DUDE){
//make a boost asio ipv4 with the raw addr in host byte order
@@ -192,7 +191,6 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u
while (min_recv_mtu < max_recv_mtu){
size_t test_mtu = (max_recv_mtu/2 + min_recv_mtu/2 + 3) & ~3;
- //std::cout << "recv_mtu " << mtu.recv_mtu << std::endl;
ctrl_data->id = htonl(USRP2_CTRL_ID_HOLLER_AT_ME_BRO);
ctrl_data->proto_ver = htonl(USRP2_FW_COMPAT_NUM);
@@ -209,7 +207,6 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u
while (min_send_mtu < max_send_mtu){
size_t test_mtu = (max_send_mtu/2 + min_send_mtu/2 + 3) & ~3;
- //std::cout << "send_mtu " << mtu.send_mtu << std::endl;
ctrl_data->id = htonl(USRP2_CTRL_ID_HOLLER_AT_ME_BRO);
ctrl_data->proto_ver = htonl(USRP2_FW_COMPAT_NUM);
@@ -233,6 +230,7 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u
* Structors
**********************************************************************/
usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){
+ UHD_MSG(status) << "Opening a USRP2/N-Series device..." << std::endl;
device_addr_t device_addr = _device_addr;
//setup the dsp transport hints (default to a large recv buff)
@@ -265,8 +263,8 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){
device_addr["recv_frame_size"] = boost::lexical_cast<std::string>(mtu.recv_mtu);
device_addr["send_frame_size"] = boost::lexical_cast<std::string>(mtu.send_mtu);
- std::cout << boost::format("Current recv frame size: %d bytes") % mtu.recv_mtu << std::endl;
- std::cout << boost::format("Current send frame size: %d bytes") % mtu.send_mtu << std::endl;
+ UHD_MSG(status) << boost::format("Current recv frame size: %d bytes") % mtu.recv_mtu << std::endl;
+ UHD_MSG(status) << boost::format("Current send frame size: %d bytes") % mtu.send_mtu << std::endl;
}
catch(const uhd::not_implemented_error &){
//just ignore this error, makes older fw work...
diff --git a/host/lib/usrp/usrp_e100/clock_ctrl.cpp b/host/lib/usrp/usrp_e100/clock_ctrl.cpp
index 2e3eb5cb9..65162dbeb 100644
--- a/host/lib/usrp/usrp_e100/clock_ctrl.cpp
+++ b/host/lib/usrp/usrp_e100/clock_ctrl.cpp
@@ -17,6 +17,8 @@
#include "clock_ctrl.hpp"
#include "ad9522_regs.hpp"
+#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/utils/assert_has.hpp>
#include <boost/cstdint.hpp>
#include "usrp_e100_regs.hpp" //spi slave constants
@@ -27,14 +29,12 @@
#include <boost/math/common_factor_rt.hpp> //gcd
#include <algorithm>
#include <utility>
-#include <iostream>
using namespace uhd;
/***********************************************************************
* Constants
**********************************************************************/
-static const bool CLOCK_SETTINGS_DEBUG = false;
static const bool ENABLE_THE_TEST_OUT = true;
static const double REFERENCE_INPUT_RATE = 10e6;
static const double DEFAULT_OUTPUT_RATE = 64e6;
@@ -138,12 +138,12 @@ static clock_settings_type get_clock_settings(double rate){
cs.chan_divider /= cs.vco_divider;
}
- if (CLOCK_SETTINGS_DEBUG){
- std::cout << "gcd " << gcd << std::endl;
- std::cout << "X " << X << std::endl;
- std::cout << "Y " << Y << std::endl;
- std::cout << cs.to_pp_string() << std::endl;
- }
+ UHD_LOGV(always)
+ << "gcd " << gcd << std::endl
+ << "X " << X << std::endl
+ << "Y " << Y << std::endl
+ << cs.to_pp_string() << std::endl
+ ;
//filter limits on the counters
if (cs.vco_divider == 1) continue;
@@ -153,7 +153,7 @@ static clock_settings_type get_clock_settings(double rate){
if (cs.b_counter >= (1<<13)) continue;
if (cs.a_counter >= (1<<6)) continue;
- std::cout << "USRP-E100 clock control: " << i << std::endl << cs.to_pp_string() << std::endl;
+ UHD_MSG(status) << "USRP-E100 clock control: " << i << std::endl << cs.to_pp_string() << std::endl;
return cs;
}
}
@@ -188,18 +188,18 @@ public:
bool fpga_clock_initialized = false;
try{
if (not _iface->mb_eeprom["mcr"].empty()){
- std::cout << "Read FPGA clock rate from EEPROM setting." << std::endl;
+ UHD_MSG(status) << "Read FPGA clock rate from EEPROM setting." << std::endl;
const double master_clock_rate = boost::lexical_cast<double>(_iface->mb_eeprom["mcr"]);
- std::cout << boost::format("Initializing FPGA clock to %fMHz...") % (master_clock_rate/1e6) << std::endl;
+ UHD_MSG(status) << boost::format("Initializing FPGA clock to %fMHz...") % (master_clock_rate/1e6) << std::endl;
this->set_fpga_clock_rate(master_clock_rate);
fpga_clock_initialized = true;
}
}
catch(const std::exception &e){
- std::cerr << "Error setting FPGA clock rate from EEPROM: " << e.what() << std::endl;
+ UHD_MSG(error) << "Error setting FPGA clock rate from EEPROM: " << e.what() << std::endl;
}
if (not fpga_clock_initialized){ //was not set... use the default rate
- std::cout << boost::format("Initializing FPGA clock to %fMHz...") % (DEFAULT_OUTPUT_RATE/1e6) << std::endl;
+ UHD_MSG(status) << boost::format("Initializing FPGA clock to %fMHz...") % (DEFAULT_OUTPUT_RATE/1e6) << std::endl;
this->set_fpga_clock_rate(DEFAULT_OUTPUT_RATE);
}
@@ -440,7 +440,7 @@ private:
void send_reg(boost::uint16_t addr){
boost::uint32_t reg = _ad9522_regs.get_write_reg(addr);
- //std::cout << "clock control write reg: " << std::hex << reg << std::endl;
+ UHD_LOGV(often) << "clock control write reg: " << std::hex << reg << std::endl;
_iface->write_spi(
UE_SPI_SS_AD9522,
spi_config_t::EDGE_RISE,
@@ -467,7 +467,7 @@ private:
if (_ad9522_regs.vco_calibration_finished) return;
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
}
- std::cerr << "USRP-E100 clock control: VCO calibration timeout" << std::endl;
+ UHD_MSG(error) << "USRP-E100 clock control: VCO calibration timeout" << std::endl;
}
void send_all_regs(void){
diff --git a/host/lib/usrp/usrp_e100/codec_ctrl.cpp b/host/lib/usrp/usrp_e100/codec_ctrl.cpp
index 50442546a..c2f2712e3 100644
--- a/host/lib/usrp/usrp_e100/codec_ctrl.cpp
+++ b/host/lib/usrp/usrp_e100/codec_ctrl.cpp
@@ -17,6 +17,7 @@
#include "codec_ctrl.hpp"
#include "ad9862_regs.hpp"
+#include <uhd/utils/log.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/algorithm.hpp>
@@ -25,12 +26,9 @@
#include <boost/math/special_functions/round.hpp>
#include "usrp_e100_regs.hpp" //spi slave constants
#include <boost/assign/list_of.hpp>
-#include <iostream>
using namespace uhd;
-static const bool codec_debug = false;
-
const gain_range_t usrp_e100_codec_ctrl::tx_pga_gain_range(-20, 0, double(0.1));
const gain_range_t usrp_e100_codec_ctrl::rx_pga_gain_range(0, 20, 1);
@@ -268,7 +266,7 @@ void usrp_e100_codec_ctrl_impl::write_aux_dac(aux_dac_t which, double volts){
**********************************************************************/
void usrp_e100_codec_ctrl_impl::send_reg(boost::uint8_t addr){
boost::uint32_t reg = _ad9862_regs.get_write_reg(addr);
- if (codec_debug) std::cout << "codec control write reg: " << std::hex << reg << std::endl;
+ UHD_LOGV(often) << "codec control write reg: " << std::hex << reg << std::endl;
_iface->write_spi(
UE_SPI_SS_AD9862,
spi_config_t::EDGE_RISE,
@@ -278,13 +276,13 @@ void usrp_e100_codec_ctrl_impl::send_reg(boost::uint8_t addr){
void usrp_e100_codec_ctrl_impl::recv_reg(boost::uint8_t addr){
boost::uint32_t reg = _ad9862_regs.get_read_reg(addr);
- if (codec_debug) std::cout << "codec control read reg: " << std::hex << reg << std::endl;
+ UHD_LOGV(often) << "codec control read reg: " << std::hex << reg << std::endl;
boost::uint32_t ret = _iface->read_spi(
UE_SPI_SS_AD9862,
spi_config_t::EDGE_RISE,
reg, 16
);
- if (codec_debug) std::cout << "codec control read ret: " << std::hex << ret << std::endl;
+ UHD_LOGV(often) << "codec control read ret: " << std::hex << ret << std::endl;
_ad9862_regs.set_reg(addr, boost::uint16_t(ret));
}
diff --git a/host/lib/usrp/usrp_e100/fpga_downloader.cpp b/host/lib/usrp/usrp_e100/fpga_downloader.cpp
index 018a120d6..a7449d3b1 100644
--- a/host/lib/usrp/usrp_e100/fpga_downloader.cpp
+++ b/host/lib/usrp/usrp_e100/fpga_downloader.cpp
@@ -18,15 +18,17 @@
#include <uhd/config.hpp>
#ifdef UHD_DLL_EXPORTS
#include <uhd/exception.hpp>
+#include <uhd/utils/msg.hpp>
#else //special case when this file is externally included
#include <stdexcept>
+#include <iostream>
+#define UHD_MSG(type) std::cout
namespace uhd{
typedef std::runtime_error os_error;
typedef std::runtime_error io_error;
}
#endif
-#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
@@ -110,8 +112,9 @@ gpio::gpio(unsigned int gpio_num, gpio_direction pin_direction)
direction_file_name = base_path.str() + "/direction";
direction_file.open(direction_file_name.c_str());
- if (!direction_file.is_open())
- std::cout << "Failed to open direction file." << std::endl;
+ if (!direction_file.is_open()) throw uhd::os_error(
+ "Failed to open direction file."
+ );
if (pin_direction == OUT)
direction_file << "out" << std::endl;
else
@@ -123,8 +126,9 @@ gpio::gpio(unsigned int gpio_num, gpio_direction pin_direction)
value_file_name = base_path.str() + "/value";
value_file.open(value_file_name.c_str(), std::ios_base::in | std::ios_base::out);
- if (!value_file.is_open())
- std::cout << "Failed to open value file." << std::endl;
+ if (!value_file.is_open()) throw uhd::os_error(
+ "Failed to open value file."
+ );
}
bool gpio::get_value()
@@ -140,7 +144,7 @@ bool gpio::get_value()
else if (val == "1")
return true;
else
- std::cout << "Data read from value file|" << val << "|" << std::endl;
+ throw uhd::os_error("Data read from value file|" + val + "|");
return false;
}
@@ -172,8 +176,7 @@ static void prepare_fpga_for_configuration(gpio &prog, gpio &)//init)
} while (count < 10 && !ready_to_program);
if (count == 10) {
- std::cout << "FPGA not ready for programming." << std::endl;
- exit(-1);
+ throw uhd::os_error("FPGA not ready for programming.");
}
#endif
}
@@ -232,10 +235,10 @@ static void send_file_to_fpga(const std::string &file_name, gpio &error, gpio &d
spi.send(buf, rbuf, bitstream.gcount());
if (error.get_value())
- std::cout << "INIT_B went high, error occured." << std::endl;
+ throw uhd::os_error("INIT_B went high, error occured.");
if (!done.get_value())
- std::cout << "Configuration complete." << std::endl;
+ UHD_MSG(status) << "Configuration complete." << std::endl;
} while (bitstream.gcount() == BUF_SIZE);
}
@@ -249,20 +252,20 @@ void usrp_e100_load_fpga(const std::string &bin_file){
gpio gpio_init_b(INIT_B, IN);
gpio gpio_done (DONE, IN);
- std::cout << "Loading FPGA image: " << bin_file << "... " << std::flush;
+ UHD_MSG(status) << "Loading FPGA image: " << bin_file << "... " << std::flush;
if(std::system("/sbin/rmmod usrp_e") != 0){
- std::cerr << "USRP-E100 FPGA downloader: could not unload usrp_e module" << std::endl;
+ UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not unload usrp_e module" << std::endl;
}
prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b);
- std::cout << "done = " << gpio_done.get_value() << std::endl;
+ UHD_MSG(status) << "done = " << gpio_done.get_value() << std::endl;
send_file_to_fpga(bin_file, gpio_init_b, gpio_done);
if(std::system("/sbin/modprobe usrp_e") != 0){
- std::cerr << "USRP-E100 FPGA downloader: could not load usrp_e module" << std::endl;
+ UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not load usrp_e module" << std::endl;
}
}
diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp
index 40b8a2393..aa6e7c485 100644
--- a/host/lib/usrp/usrp_e100/io_impl.cpp
+++ b/host/lib/usrp/usrp_e100/io_impl.cpp
@@ -17,6 +17,8 @@
#include "usrp_e100_impl.hpp"
#include "usrp_e100_regs.hpp"
+#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/usrp/dsp_utils.hpp>
#include <uhd/utils/thread_priority.hpp>
#include <uhd/transport/bounded_buffer.hpp>
@@ -25,7 +27,7 @@
#include <boost/format.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/barrier.hpp>
-#include <iostream>
+#include <sstream>
using namespace uhd;
using namespace uhd::usrp;
@@ -37,7 +39,7 @@ using namespace uhd::transport;
static const size_t rx_data_inline_sid = 1;
static const size_t tx_async_report_sid = 2;
static const int underflow_flags = async_metadata_t::EVENT_CODE_UNDERFLOW | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET;
-static const bool recv_debug = false;
+#define fp_recv_debug false
/***********************************************************************
* io impl details (internal to this file)
@@ -116,12 +118,14 @@ void usrp_e100_impl::io_impl::recv_pirate_loop(
managed_recv_buffer::sptr buff = this->data_xport->get_recv_buff();
if (not buff.get()) continue; //ignore timeout/error buffers
- if (recv_debug){
- std::cout << "len " << buff->size() << std::endl;
+ if (fp_recv_debug){
+ std::ostringstream ss;
+ ss << "len " << buff->size() << std::endl;
for (size_t i = 0; i < 9; i++){
- std::cout << boost::format(" 0x%08x") % buff->cast<const boost::uint32_t *>()[i] << std::endl;
+ ss << boost::format(" 0x%08x") % buff->cast<const boost::uint32_t *>()[i] << std::endl;
}
- std::cout << std::endl << std::endl;
+ ss << std::endl << std::endl;
+ UHD_LOGV(always) << ss.str();
}
try{
@@ -133,7 +137,7 @@ void usrp_e100_impl::io_impl::recv_pirate_loop(
//handle an rx data packet or inline message
if (if_packet_info.sid == rx_data_inline_sid){
- if (recv_debug) std::cout << "this is rx_data_inline_sid\n";
+ if (fp_recv_debug) UHD_LOGV(always) << "this is rx_data_inline_sid\n";
//same number of frames as the data transport -> always immediate
recv_pirate_booty.push_with_wait(buff);
continue;
@@ -141,7 +145,7 @@ void usrp_e100_impl::io_impl::recv_pirate_loop(
//handle a tx async report message
if (if_packet_info.sid == tx_async_report_sid and if_packet_info.packet_type != vrt::if_packet_info_t::PACKET_TYPE_DATA){
- if (recv_debug) std::cout << "this is tx_async_report_sid\n";
+ if (fp_recv_debug) UHD_LOGV(always) << "this is tx_async_report_sid\n";
//fill in the async metadata
async_metadata_t metadata;
@@ -153,15 +157,15 @@ void usrp_e100_impl::io_impl::recv_pirate_loop(
metadata.event_code = vrt_packet_handler::get_context_code<async_metadata_t::event_code_t>(vrt_hdr, if_packet_info);
//print the famous U, and push the metadata into the message queue
- if (metadata.event_code & underflow_flags) std::cerr << "U" << std::flush;
+ if (metadata.event_code & underflow_flags) UHD_MSG(fastpath) << "U";
async_msg_fifo.push_with_pop_on_full(metadata);
continue;
}
- if (recv_debug) std::cout << "this is unknown packet\n";
+ if (fp_recv_debug) UHD_LOGV(always) << "this is unknown packet\n";
}catch(const std::exception &e){
- std::cerr << "Error (usrp-e recv pirate loop): " << e.what() << std::endl;
+ UHD_MSG(error) << "Error (usrp-e recv pirate loop): " << e.what() << std::endl;
}
}
}
@@ -219,7 +223,7 @@ void usrp_e100_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd){
}
void usrp_e100_impl::handle_overrun(size_t){
- std::cerr << "O"; //the famous OOOOOOOOOOO
+ UHD_MSG(fastpath) << "O"; //the famous OOOOOOOOOOO
if (_io_impl->continuous_streaming){
this->issue_stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
}
diff --git a/host/lib/usrp/usrp_e100/mboard_impl.cpp b/host/lib/usrp/usrp_e100/mboard_impl.cpp
index 5f4a208d3..d31662eb5 100644
--- a/host/lib/usrp/usrp_e100/mboard_impl.cpp
+++ b/host/lib/usrp/usrp_e100/mboard_impl.cpp
@@ -17,12 +17,12 @@
#include "usrp_e100_impl.hpp"
#include "usrp_e100_regs.hpp"
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
#include <uhd/usrp/dsp_utils.hpp>
#include <uhd/usrp/misc_utils.hpp>
#include <uhd/usrp/mboard_props.hpp>
#include <boost/bind.hpp>
-#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
@@ -207,10 +207,11 @@ void usrp_e100_impl::mboard_set(const wax::obj &key, const wax::obj &val){
return;
case MBOARD_PROP_CLOCK_RATE:
- std::cerr << "Helpful message:" << std::endl;
- std::cerr << " I see that you are setting the master clock rate from the API." << std::endl;
- std::cerr << " You may find it more convenient to burn this setting into the EEPROM." << std::endl;
- std::cerr << " See the application notes for USRP-E1XX for further instructions." << std::endl;
+ UHD_MSG(warning)
+ << "I see that you are setting the master clock rate from the API.\n"
+ << "You may find it more convenient to burn this setting into the EEPROM.\n"
+ << "See the application notes for USRP-E1XX for further instructions.\n"
+ ;
_clock_ctrl->set_fpga_clock_rate(val.as<double>());
return;
diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp
index fe839c409..4247746ab 100644
--- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp
+++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp
@@ -17,16 +17,15 @@
#include "usrp_e100_impl.hpp"
#include "usrp_e100_regs.hpp"
+#include <uhd/utils/msg.hpp>
#include <uhd/usrp/device_props.hpp>
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/images.hpp>
-#include <uhd/utils/warning.hpp>
#include <boost/format.hpp>
#include <boost/filesystem.hpp>
#include <boost/functional/hash.hpp>
-#include <iostream>
#include <fstream>
using namespace uhd;
@@ -58,18 +57,16 @@ static device_addrs_t usrp_e100_find(const device_addr_t &hint){
usrp_e100_iface::sptr iface = usrp_e100_iface::make(new_addr["node"]);
new_addr["name"] = iface->mb_eeprom["name"];
new_addr["serial"] = iface->mb_eeprom["serial"];
- if (
- (not hint.has_key("name") or hint["name"] == new_addr["name"]) and
- (not hint.has_key("serial") or hint["serial"] == new_addr["serial"])
- ){
- usrp_e100_addrs.push_back(new_addr);
- }
}
catch(const std::exception &e){
- uhd::warning::post(
- std::string("Ignoring discovered device\n")
- + e.what()
- );
+ new_addr["name"] = "";
+ new_addr["serial"] = "";
+ }
+ if (
+ (not hint.has_key("name") or hint["name"] == new_addr["name"]) and
+ (not hint.has_key("serial") or hint["serial"] == new_addr["serial"])
+ ){
+ usrp_e100_addrs.push_back(new_addr);
}
}
@@ -83,7 +80,7 @@ static device::sptr usrp_e100_make(const device_addr_t &device_addr){
//setup the main interface into fpga
std::string node = device_addr["node"];
- std::cout << boost::format("Opening USRP-E on %s") % node << std::endl;
+ UHD_MSG(status) << boost::format("Opening USRP-E on %s") % node << std::endl;
usrp_e100_iface::sptr iface = usrp_e100_iface::make(node);
//------------------------------------------------------------------
@@ -124,7 +121,7 @@ static device::sptr usrp_e100_make(const device_addr_t &device_addr){
iface.reset();
usrp_e100_load_fpga(usrp_e100_fpga_image);
sleep(1); ///\todo do this better one day.
- std::cout << boost::format("re-Opening USRP-E on %s") % node << std::endl;
+ UHD_MSG(status) << boost::format("re-Opening USRP-E on %s") % node << std::endl;
iface = usrp_e100_iface::make(node);
try{std::ofstream(hash_file_path) << fpga_hash;}catch(...){}
}
diff --git a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp
index f4274dc5a..26774aeda 100644
--- a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp
+++ b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp
@@ -17,19 +17,18 @@
#include "usrp_e100_iface.hpp"
#include <uhd/transport/zero_copy.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <linux/usrp_e.h>
#include <sys/mman.h> //mmap
#include <unistd.h> //getpagesize
#include <poll.h> //poll
#include <vector>
-#include <iostream>
using namespace uhd;
using namespace uhd::transport;
-static const bool fp_verbose = false; //fast-path verbose
-static const bool sp_verbose = false; //slow-path verbose
+#define fp_verbose false //fast-path verbose
static const size_t poll_breakout = 10; //how many poll timeouts constitute a full timeout
/***********************************************************************
@@ -43,14 +42,14 @@ public:
void release(void){
if (_info->flags != RB_USER_PROCESS) return;
- if (fp_verbose) std::cout << "recv buff: release" << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << "recv buff: release" << std::endl;
_info->flags = RB_KERNEL; //release the frame
}
bool ready(void){return _info->flags & RB_USER;}
sptr get_new(void){
- if (fp_verbose) std::cout << " make_recv_buff: " << get_size() << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << " make_recv_buff: " << get_size() << std::endl;
_info->flags = RB_USER_PROCESS; //claim the frame
return sptr(this, &usrp_e100_mmap_zero_copy_mrb::fake_deleter);
}
@@ -78,18 +77,18 @@ public:
void commit(size_t len){
if (_info->flags != RB_USER_PROCESS) return;
- if (fp_verbose) std::cout << "send buff: commit " << len << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << "send buff: commit " << len << std::endl;
_info->len = len;
_info->flags = RB_USER; //release the frame
if (::write(_fd, NULL, 0) < 0){ //notifies the kernel
- std::cerr << UHD_THROW_SITE_INFO("write error") << std::endl;
+ UHD_LOGV(rarely) << UHD_THROW_SITE_INFO("write error") << std::endl;
}
}
bool ready(void){return _info->flags & RB_KERNEL;}
sptr get_new(void){
- if (fp_verbose) std::cout << " make_send_buff: " << get_size() << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << " make_send_buff: " << get_size() << std::endl;
_info->flags = RB_USER_PROCESS; //claim the frame
return sptr(this, &usrp_e100_mmap_zero_copy_msb::fake_deleter);
}
@@ -127,15 +126,15 @@ public:
(_rb_size.num_rx_frames + _rb_size.num_tx_frames) * _frame_size;
//print sizes summary
- if (sp_verbose){
- std::cout << "page_size: " << page_size << std::endl;
- std::cout << "frame_size: " << _frame_size << std::endl;
- std::cout << "num_pages_rx_flags: " << _rb_size.num_pages_rx_flags << std::endl;
- std::cout << "num_rx_frames: " << _rb_size.num_rx_frames << std::endl;
- std::cout << "num_pages_tx_flags: " << _rb_size.num_pages_tx_flags << std::endl;
- std::cout << "num_tx_frames: " << _rb_size.num_tx_frames << std::endl;
- std::cout << "map_size: " << _map_size << std::endl;
- }
+ UHD_LOG
+ << "page_size: " << page_size << std::endl
+ << "frame_size: " << _frame_size << std::endl
+ << "num_pages_rx_flags: " << _rb_size.num_pages_rx_flags << std::endl
+ << "num_rx_frames: " << _rb_size.num_rx_frames << std::endl
+ << "num_pages_tx_flags: " << _rb_size.num_pages_tx_flags << std::endl
+ << "num_tx_frames: " << _rb_size.num_tx_frames << std::endl
+ << "map_size: " << _map_size << std::endl
+ ;
//call mmap to get the memory
_mapped_mem = ::mmap(
@@ -150,12 +149,12 @@ public:
size_t send_buff_off = send_info_off + (_rb_size.num_pages_tx_flags * page_size);
//print offset summary
- if (sp_verbose){
- std::cout << "recv_info_off: " << recv_info_off << std::endl;
- std::cout << "recv_buff_off: " << recv_buff_off << std::endl;
- std::cout << "send_info_off: " << send_info_off << std::endl;
- std::cout << "send_buff_off: " << send_buff_off << std::endl;
- }
+ UHD_LOG
+ << "recv_info_off: " << recv_info_off << std::endl
+ << "recv_buff_off: " << recv_buff_off << std::endl
+ << "send_info_off: " << send_info_off << std::endl
+ << "send_buff_off: " << send_buff_off << std::endl
+ ;
//pointers to sections in the mapped memory
ring_buffer_info (*recv_info)[], (*send_info)[];
@@ -186,12 +185,12 @@ public:
}
~usrp_e100_mmap_zero_copy_impl(void){
- if (sp_verbose) std::cout << "cleanup: munmap" << std::endl;
+ UHD_LOG << "cleanup: munmap" << std::endl;
::munmap(_mapped_mem, _map_size);
}
managed_recv_buffer::sptr get_recv_buff(double timeout){
- if (fp_verbose) std::cout << "get_recv_buff: " << _recv_index << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << "get_recv_buff: " << _recv_index << std::endl;
usrp_e100_mmap_zero_copy_mrb &mrb = _mrb_pool[_recv_index];
//poll/wait for a ready frame
@@ -201,7 +200,7 @@ public:
pfd.fd = _fd;
pfd.events = POLLIN;
ssize_t poll_ret = ::poll(&pfd, 1, size_t(timeout*1e3/poll_breakout));
- if (fp_verbose) std::cout << " POLLIN: " << poll_ret << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << " POLLIN: " << poll_ret << std::endl;
if (poll_ret > 0) goto found_user_frame; //good poll, continue on
}
return managed_recv_buffer::sptr(); //timed-out for real
@@ -223,7 +222,7 @@ public:
}
managed_send_buffer::sptr get_send_buff(double timeout){
- if (fp_verbose) std::cout << "get_send_buff: " << _send_index << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << "get_send_buff: " << _send_index << std::endl;
usrp_e100_mmap_zero_copy_msb &msb = _msb_pool[_send_index];
//poll/wait for a ready frame
@@ -232,7 +231,7 @@ public:
pfd.fd = _fd;
pfd.events = POLLOUT;
ssize_t poll_ret = ::poll(&pfd, 1, size_t(timeout*1e3));
- if (fp_verbose) std::cout << " POLLOUT: " << poll_ret << std::endl;
+ if (fp_verbose) UHD_LOGV(always) << " POLLOUT: " << poll_ret << std::endl;
if (poll_ret <= 0) return managed_send_buffer::sptr();
}
diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt
index 1314f7475..0e0d51c78 100644
--- a/host/lib/utils/CMakeLists.txt
+++ b/host/lib/utils/CMakeLists.txt
@@ -131,6 +131,8 @@ LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/gain_group.cpp
${CMAKE_CURRENT_SOURCE_DIR}/images.cpp
${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/msg.cpp
${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp
${CMAKE_CURRENT_SOURCE_DIR}/props.cpp
${CMAKE_CURRENT_SOURCE_DIR}/static.cpp
diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp
index 3af8a543d..85f4977a6 100644
--- a/host/lib/utils/gain_group.cpp
+++ b/host/lib/utils/gain_group.cpp
@@ -16,6 +16,7 @@
//
#include <uhd/utils/gain_group.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/utils/algorithm.hpp>
#include <uhd/exception.hpp>
@@ -23,7 +24,6 @@
#include <boost/bind.hpp>
#include <algorithm>
#include <vector>
-#include <iostream>
using namespace uhd;
@@ -137,11 +137,11 @@ public:
gain_bucket.at(i) += additional_gain;
gain_left_to_distribute -= additional_gain;
}
- if (verbose) std::cout << "gain_left_to_distribute " << gain_left_to_distribute << std::endl;
+ UHD_LOGV(often) << "gain_left_to_distribute " << gain_left_to_distribute << std::endl;
//now write the bucket out to the individual gain values
for (size_t i = 0; i < gain_bucket.size(); i++){
- if (verbose) std::cout << gain_bucket.at(i) << std::endl;
+ UHD_LOGV(often) << i << ": " << gain_bucket.at(i) << std::endl;
all_fcns.at(i).set_value(gain_bucket.at(i));
}
}
diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp
new file mode 100644
index 000000000..8b270af6b
--- /dev/null
+++ b/host/lib/utils/log.cpp
@@ -0,0 +1,214 @@
+//
+// 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/>.
+//
+
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/static.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/format.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#ifdef BOOST_MSVC
+//whoops! https://svn.boost.org/trac/boost/ticket/5287
+//enjoy this useless dummy class instead
+namespace boost{ namespace interprocess{
+ struct file_lock{
+ file_lock(const char * = NULL){}
+ void lock(void){}
+ void unlock(void){}
+ };
+}} //namespace
+#else
+#include <boost/interprocess/sync/file_lock.hpp>
+#endif
+#ifdef BOOST_MSVC
+#define USE_GET_TEMP_PATH
+#include <Windows.h> //GetTempPath
+#endif
+#include <stdio.h> //P_tmpdir
+#include <cstdlib> //getenv
+#include <fstream>
+#include <cctype>
+
+namespace fs = boost::filesystem;
+namespace pt = boost::posix_time;
+namespace ip = boost::interprocess;
+
+/***********************************************************************
+ * Helper function to get the system's temporary path
+ **********************************************************************/
+static fs::path get_temp_path(void){
+ const char *tmp_path = NULL;
+
+ //try the official uhd temp path environment variable
+ tmp_path = std::getenv("UHD_TEMP_PATH");
+ if (tmp_path != NULL) return tmp_path;
+
+ //try the windows function if available
+ #ifdef USE_GET_TEMP_PATH
+ char lpBuffer[2048];
+ if (GetTempPath(sizeof(lpBuffer), lpBuffer)) return lpBuffer;
+ #endif
+
+ //try windows environment variables
+ tmp_path = std::getenv("TMP");
+ if (tmp_path != NULL) return tmp_path;
+
+ tmp_path = std::getenv("TEMP");
+ if (tmp_path != NULL) return tmp_path;
+
+ //try the stdio define if available
+ #ifdef P_tmpdir
+ return P_tmpdir;
+ #endif
+
+ //try unix environment variables
+ tmp_path = std::getenv("TMPDIR");
+ if (tmp_path != NULL) return tmp_path;
+
+ //give up and use the unix default
+ return "/tmp";
+}
+
+/***********************************************************************
+ * The library's streamer resource (static initialization)
+ **********************************************************************/
+class null_streambuf_class : public std::streambuf{
+ int overflow(int c) { return c; }
+};
+UHD_SINGLETON_FCN(null_streambuf_class, null_streambuf);
+
+class uhd_logger_stream_resource_class{
+public:
+ uhd_logger_stream_resource_class(void) : _null_stream(&null_streambuf()){
+ const std::string log_path = (get_temp_path() / "uhd.log").string();
+ _file_stream.open(log_path.c_str(), std::fstream::out | std::fstream::app);
+ _file_lock = ip::file_lock(log_path.c_str());
+
+ //set the default log level
+ _log_level = uhd::_log::regularly;
+
+ //allow override from macro definition
+ #ifdef UHD_LOG_LEVEL
+ _set_log_level(BOOST_STRINGIZE(UHD_LOG_LEVEL));
+ #endif
+
+ //allow override from environment variable
+ const char * log_level_env = std::getenv("UHD_LOG_LEVEL");
+ if (log_level_env != NULL) _set_log_level(log_level_env);
+
+ }
+
+ ~uhd_logger_stream_resource_class(void){
+ _file_stream.close();
+ }
+
+ std::ostream &get(void){
+ if (_verbosity >= _log_level) return _file_stream;
+ return _null_stream;
+ }
+
+ void aquire(bool lock){
+ if (lock){
+ _mutex.lock();
+ _file_lock.lock();
+ }
+ else{
+ _file_lock.unlock();
+ _mutex.unlock();
+ }
+ }
+
+ void set_verbosity(uhd::_log::verbosity_t verbosity){
+ _verbosity = verbosity;
+ }
+
+private:
+ //! set the log level from a string that is either a digit or an enum name
+ void _set_log_level(const std::string &log_level_str){
+ const uhd::_log::verbosity_t log_level = uhd::_log::verbosity_t(log_level_str[0]-'0');
+ if (std::isdigit(log_level_str[0]) and log_level >= uhd::_log::always and log_level <= uhd::_log::never){
+ _log_level = log_level;
+ }
+ #define if_lls_equal(name) else if(log_level_str == #name) _log_level = uhd::_log::name
+ if_lls_equal(always);
+ if_lls_equal(often);
+ if_lls_equal(regularly);
+ if_lls_equal(rarely);
+ if_lls_equal(very_rarely);
+ if_lls_equal(never);
+ }
+
+ //available stream objects
+ std::ofstream _file_stream;
+ std::ostream _null_stream;
+
+ //synchronization mechanisms
+ boost::mutex _mutex; //process-level
+ ip::file_lock _file_lock; //system-level
+
+ //log-level settings
+ uhd::_log::verbosity_t _verbosity;
+ uhd::_log::verbosity_t _log_level;
+};
+
+UHD_SINGLETON_FCN(uhd_logger_stream_resource_class, uhd_logger_stream_resource);
+
+/***********************************************************************
+ * The logger object implementation
+ **********************************************************************/
+//! get the relative file path from the host directory
+static std::string get_rel_file_path(const fs::path &file){
+ fs::path abs_path = file.branch_path();
+ fs::path rel_path = file.leaf();
+ while (not abs_path.empty() and abs_path.leaf() != "host"){
+ rel_path = abs_path.leaf() / rel_path;
+ abs_path = abs_path.branch_path();
+ }
+ return rel_path.string();
+}
+
+uhd::_log::log::log(
+ const verbosity_t verbosity,
+ const std::string &file,
+ const unsigned int line,
+ const std::string &function
+){
+ uhd_logger_stream_resource().aquire(true);
+ uhd_logger_stream_resource().set_verbosity(verbosity);
+ const std::string time = pt::to_simple_string(pt::microsec_clock::local_time());
+ const std::string header1 = str(boost::format("-- %s - level %d") % time % int(verbosity));
+ const std::string header2 = str(boost::format("-- %s") % function).substr(0, 80);
+ const std::string header3 = str(boost::format("-- %s:%u") % get_rel_file_path(file) % line);
+ const std::string border = std::string(std::max(std::max(header1.size(), header2.size()), header3.size()), '-');
+ uhd_logger_stream_resource().get()
+ << std::endl
+ << border << std::endl
+ << header1 << std::endl
+ << header2 << std::endl
+ << header3 << std::endl
+ << border << std::endl
+ ;
+}
+
+uhd::_log::log::~log(void){
+ uhd_logger_stream_resource().get() << std::endl;
+ uhd_logger_stream_resource().aquire(false);
+}
+
+std::ostream & uhd::_log::log::operator()(void){
+ return uhd_logger_stream_resource().get();
+}
diff --git a/host/lib/utils/msg.cpp b/host/lib/utils/msg.cpp
new file mode 100644
index 000000000..e850b5a6d
--- /dev/null
+++ b/host/lib/utils/msg.cpp
@@ -0,0 +1,123 @@
+//
+// 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/>.
+//
+
+#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/static.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tokenizer.hpp>
+#include <sstream>
+#include <iostream>
+
+/***********************************************************************
+ * Helper functions
+ **********************************************************************/
+#define tokenizer(inp, sep) \
+ boost::tokenizer<boost::char_separator<char> > \
+ (inp, boost::char_separator<char>(sep))
+
+static void msg_to_cout(const std::string &msg){
+ std::stringstream ss;
+
+ static bool just_had_a_newline = true;
+ BOOST_FOREACH(char ch, msg){
+ if (just_had_a_newline){
+ just_had_a_newline = false;
+ ss << "-- ";
+ }
+ if (ch == '\n'){
+ just_had_a_newline = true;
+ }
+ ss << ch;
+ }
+
+ std::cout << ss.str() << std::flush;
+}
+
+static void msg_to_cerr(const std::string &title, const std::string &msg){
+ std::stringstream ss;
+
+ ss << std::endl << title << ":" << std::endl;
+ BOOST_FOREACH(const std::string &line, tokenizer(msg, "\n")){
+ ss << " " << line << std::endl;
+ }
+
+ std::cerr << ss.str() << std::flush;
+}
+
+/***********************************************************************
+ * Global settings for the messenger
+ **********************************************************************/
+static boost::mutex msg_mutex;
+static std::ostringstream msg_ss;
+static uhd::msg::type_t msg_type;
+static uhd::msg::handler_t msg_handler;
+
+/***********************************************************************
+ * Setup the message handlers
+ **********************************************************************/
+void uhd::msg::register_handler(const handler_t &handler){
+ msg_mutex.lock();
+ msg_handler = handler;
+ msg_mutex.unlock();
+}
+
+static void default_msg_handler(uhd::msg::type_t type, const std::string &msg){
+ switch(type){
+ case uhd::msg::fastpath:
+ std::cerr << msg << std::flush;
+ break;
+
+ case uhd::msg::status:
+ msg_to_cout(msg);
+ UHD_LOG << "Status message" << std::endl << msg;
+ break;
+
+ case uhd::msg::warning:
+ msg_to_cerr("UHD Warning", msg);
+ UHD_LOG << "Warning message" << std::endl << msg;
+ break;
+
+ case uhd::msg::error:
+ msg_to_cerr("UHD Error", msg);
+ UHD_LOG << "Error message" << std::endl << msg;
+ break;
+ }
+}
+
+UHD_STATIC_BLOCK(msg_register_default_handler){
+ uhd::msg::register_handler(&default_msg_handler);
+}
+
+/***********************************************************************
+ * The message object implementation
+ **********************************************************************/
+uhd::msg::_msg::_msg(const type_t type){
+ msg_mutex.lock();
+ msg_type = type;
+}
+
+uhd::msg::_msg::~_msg(void){
+ msg_handler(msg_type, msg_ss.str());
+ msg_ss.str(""); //clear for next call
+ msg_mutex.unlock();
+}
+
+std::ostream & uhd::msg::_msg::operator()(void){
+ return msg_ss;
+}
diff --git a/host/lib/utils/thread_priority.cpp b/host/lib/utils/thread_priority.cpp
index a63bdf5ce..6d6ca5630 100644
--- a/host/lib/utils/thread_priority.cpp
+++ b/host/lib/utils/thread_priority.cpp
@@ -16,7 +16,7 @@
//
#include <uhd/utils/thread_priority.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <uhd/exception.hpp>
#include <boost/format.hpp>
#include <iostream>
@@ -26,11 +26,11 @@ bool uhd::set_thread_priority_safe(float priority, bool realtime){
set_thread_priority(priority, realtime);
return true;
}catch(const std::exception &e){
- uhd::warning::post(str(boost::format(
+ UHD_MSG(warning) << boost::format(
"Unable to set the thread priority. Performance may be negatively affected.\n"
"Please see the general application notes in the manual for instructions.\n"
"%s\n"
- ) % e.what()));
+ ) % e.what();
return false;
}
}
diff --git a/host/lib/utils/warning.cpp b/host/lib/utils/warning.cpp
index 6a94a0a2c..87b6b24f5 100644
--- a/host/lib/utils/warning.cpp
+++ b/host/lib/utils/warning.cpp
@@ -39,13 +39,13 @@ typedef uhd::dict<std::string, warning::handler_t> registry_t;
UHD_SINGLETON_FCN(registry_t, get_registry)
//the default warning handler
-static void stderr_warning(const std::string &msg){
- std::cerr << msg;
-}
+//static void stderr_warning(const std::string &msg){
+// std::cerr << msg;
+//}
//register a default handler
UHD_STATIC_BLOCK(warning_register_default){
- warning::register_handler("default", &stderr_warning);
+ //warning::register_handler("default", &stderr_warning);
}
/***********************************************************************
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index f08fe669b..b38afccf0 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -26,12 +26,12 @@ SET(test_sources
dict_test.cpp
error_test.cpp
gain_group_test.cpp
+ msg_test.cpp
ranges_test.cpp
subdev_spec_test.cpp
time_spec_test.cpp
tune_helper_test.cpp
vrt_test.cpp
- warning_test.cpp
wax_test.cpp
)
diff --git a/host/tests/warning_test.cpp b/host/tests/msg_test.cpp
index 3394f84d4..495907504 100644
--- a/host/tests/warning_test.cpp
+++ b/host/tests/msg_test.cpp
@@ -16,14 +16,24 @@
//
#include <boost/test/unit_test.hpp>
-#include <uhd/utils/warning.hpp>
+#include <uhd/utils/msg.hpp>
#include <iostream>
-BOOST_AUTO_TEST_CASE(test_warning_post){
+BOOST_AUTO_TEST_CASE(test_messages){
+ #ifdef UHD_FUTURE
std::cerr << "---begin print test ---" << std::endl;
- uhd::warning::post(
+ UHD_MSG(status) <<
+ "This is a test print for a status message.\n"
+ "And this is the second line of the test print.\n"
+ ;
+ UHD_MSG(warning) <<
"This is a test print for a warning message.\n"
"And this is the second line of the test print.\n"
- );
+ ;
+ UHD_MSG(error) <<
+ "This is a test print for an error message.\n"
+ "And this is the second line of the test print.\n"
+ ;
std::cerr << "---end print test ---" << std::endl;
+ #endif
}