From 8426a72bd66850ed1311ee8957dc5b7e4d98e301 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 12:18:11 -0700 Subject: uhd: moved the logger into the utils subdir --- host/lib/utils/log.cpp | 177 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 host/lib/utils/log.cpp (limited to 'host/lib/utils/log.cpp') diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp new file mode 100644 index 000000000..605704874 --- /dev/null +++ b/host/lib/utils/log.cpp @@ -0,0 +1,177 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include +#ifdef BOOST_MSVC +#define USE_GET_TEMP_PATH +#include //GetTempPath +#endif +#include //P_tmpdir +#include //getenv +#include +#include + +namespace fs = boost::filesystem; +namespace pt = boost::posix_time; + +/*********************************************************************** + * 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); + + //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(); + else _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::very_rarely){ + _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); + } + + std::ofstream _file_stream; + std::ostream _null_stream; + boost::mutex _mutex; + 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 function implementation + **********************************************************************/ +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 header = str(boost::format( + "-- %s - lvl %d - %s @ %s:%u" + ) % time % int(verbosity) % function % fs::path(file).leaf() % line); + uhd_logger_stream_resource().get() + << std::endl + << std::string(header.size(), '-') << std::endl + << header << std::endl + << std::string(header.size(), '-') << std::endl + ; +} + +uhd::_log::log::~log(void){ + uhd_logger_stream_resource().aquire(false); +} + +std::ostream & uhd::_log::log::get(void){ + return uhd_logger_stream_resource().get(); +} + +UHD_STATIC_BLOCK(logger_begin){ + UHD_LOG << "Logger has started" << std::endl; + UHD_LOGV(always) << "always" << std::endl; + UHD_LOGV(rarely) << "rarely" << std::endl; +} -- cgit v1.2.3 From 0de4f165e937168693ac758239d569a2ace60325 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 12:22:21 -0700 Subject: usrp: replaced conditional dboard debug prints w/ UHD_LOGV(often) --- host/lib/usrp/dboard/db_dbsrx.cpp | 31 +++++++++++++++---------------- host/lib/usrp/dboard/db_dbsrx2.cpp | 17 ++++++++--------- host/lib/usrp/dboard/db_rfx.cpp | 9 ++++----- host/lib/usrp/dboard/db_sbx.cpp | 25 +++++++++++-------------- host/lib/usrp/dboard/db_tvrx.cpp | 32 ++++++++++++++------------------ host/lib/usrp/dboard/db_wbx_common.cpp | 20 +++++++++----------- host/lib/usrp/dboard/db_wbx_simple.cpp | 2 -- host/lib/usrp/dboard/db_xcvr2450.cpp | 15 +++++++-------- host/lib/utils/log.cpp | 6 ------ 9 files changed, 68 insertions(+), 89 deletions(-) (limited to 'host/lib/utils/log.cpp') diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp index 8fdd4f953..dbe2f6370 100644 --- a/host/lib/usrp/dboard/db_dbsrx.cpp +++ b/host/lib/usrp/dboard/db_dbsrx.cpp @@ -20,6 +20,7 @@ // RX IO Functions #include "max2118_regs.hpp" +#include #include #include #include @@ -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= 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; @@ -246,7 +245,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 +255,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 +281,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 +303,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 +332,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; @@ -368,7 +367,7 @@ void dbsrx::set_lo_freq(double target_freq){ _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 +379,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 +395,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 +431,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 +455,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 +496,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..0769b3aa1 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 #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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; diff --git a/host/lib/usrp/dboard/db_sbx.cpp b/host/lib/usrp/dboard/db_sbx.cpp index d0c3c63ac..4d8753fab 100644 --- a/host/lib/usrp/dboard/db_sbx.cpp +++ b/host/lib/usrp/dboard/db_sbx.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/host/lib/usrp/dboard/db_tvrx.cpp b/host/lib/usrp/dboard/db_tvrx.cpp index d264c9ca4..cd7216c22 100644 --- a/host/lib/usrp/dboard/db_tvrx.cpp +++ b/host/lib/usrp/dboard/db_tvrx.cpp @@ -27,6 +27,7 @@ //max freq: 860e6 //gain range: [0:1dB:115dB] +#include #include #include #include @@ -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 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(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(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() << 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() << std::endl; return; case SUBDEV_PROP_FREQ_RANGE: diff --git a/host/lib/usrp/dboard/db_wbx_common.cpp b/host/lib/usrp/dboard/db_wbx_common.cpp index eb239c305..fdee14607 100644 --- a/host/lib/usrp/dboard/db_wbx_common.cpp +++ b/host/lib/usrp/dboard/db_wbx_common.cpp @@ -51,6 +51,7 @@ #include "db_wbx_common.hpp" #include "adf4350_regs.hpp" +#include #include #include #include @@ -70,8 +71,6 @@ using namespace boost::assign; /*********************************************************************** * The WBX Common dboard constants **********************************************************************/ -static const bool wbx_debug = false; - static const uhd::dict 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; 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..4bda43251 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -48,6 +48,7 @@ #define RX_DIS_RXIO 0 #include "max2829_regs.hpp" +#include #include #include #include @@ -71,8 +72,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 +126,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 +301,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 +311,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 +546,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 +561,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/utils/log.cpp b/host/lib/utils/log.cpp index 605704874..7df077a96 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -169,9 +169,3 @@ uhd::_log::log::~log(void){ std::ostream & uhd::_log::log::get(void){ return uhd_logger_stream_resource().get(); } - -UHD_STATIC_BLOCK(logger_begin){ - UHD_LOG << "Logger has started" << std::endl; - UHD_LOGV(always) << "always" << std::endl; - UHD_LOGV(rarely) << "rarely" << std::endl; -} -- cgit v1.2.3 From 94399062713a76a42f269a7ed4d3737ecd6ed5cf Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 14:33:35 -0700 Subject: uhd: tweaks for logger file entries --- host/include/uhd/utils/log.hpp | 17 +++++++++-------- host/lib/utils/log.cpp | 27 +++++++++++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'host/lib/utils/log.cpp') diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index 75c335099..b3e88f865 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -48,13 +48,6 @@ * - Example environment variable: export UHD_LOG_LEVEL=regularly */ -/*! - * A UHD logger macro with default verbosity. - * Usage: UHD_LOG << "the log message" << std::endl; - */ -#define UHD_LOG \ - uhd::_log::log(uhd::_log::regularly, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) - /*! * A UHD logger macro with configurable verbosity. * Usage: UHD_LOGV(very_rarely) << "the log message" << std::endl; @@ -62,6 +55,14 @@ #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 @@ -74,7 +75,7 @@ namespace uhd{ namespace _log{ }; //! Internal logging object (called by UHD_LOG macros) - struct UHD_API log{ + struct /*UHD_API*/ log{ log( const verbosity_t verbosity, const std::string &file, diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index 7df077a96..061173d6b 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -142,6 +142,17 @@ UHD_SINGLETON_FCN(uhd_logger_stream_resource_class, uhd_logger_stream_resource); /*********************************************************************** * The logger function 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, @@ -151,18 +162,22 @@ uhd::_log::log::log( 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 header = str(boost::format( - "-- %s - lvl %d - %s @ %s:%u" - ) % time % int(verbosity) % function % fs::path(file).leaf() % line); + 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 - << std::string(header.size(), '-') << std::endl - << header << std::endl - << std::string(header.size(), '-') << 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); } -- cgit v1.2.3 From e71d2833fbc2d9b87a8367b6ddc4388c3f182d93 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 17:01:41 -0700 Subject: uhd: added interprocess file lock to the logger file --- host/lib/utils/log.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'host/lib/utils/log.cpp') diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index 061173d6b..0a2861cbd 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -22,6 +22,19 @@ #include #include #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 +#endif +#ifdef BOOST_MSVC #define USE_GET_TEMP_PATH #include //GetTempPath #endif @@ -32,6 +45,7 @@ namespace fs = boost::filesystem; namespace pt = boost::posix_time; +namespace ip = boost::interprocess; /*********************************************************************** * Helper function to get the system's temporary path @@ -82,6 +96,7 @@ 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; @@ -107,8 +122,14 @@ public: } void aquire(bool lock){ - if (lock) _mutex.lock(); - else _mutex.unlock(); + if (lock){ + _mutex.lock(); + _file_lock.lock(); + } + else{ + _file_lock.unlock(); + _mutex.unlock(); + } } void set_verbosity(uhd::_log::verbosity_t verbosity){ @@ -130,9 +151,15 @@ private: if_lls_equal(very_rarely); } + //available stream objects std::ofstream _file_stream; std::ostream _null_stream; - boost::mutex _mutex; + + //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; }; -- cgit v1.2.3 From 7f01386f63850d9e13afb4033d1fae39f6a03764 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 18:36:10 -0700 Subject: uhd: replaced warning post with calls to UHD_MSG(warning) The message api can support warnings, error, and status messages. The default handler is to stdio, but the user can change this. --- host/include/uhd/config.hpp | 7 ++ host/include/uhd/utils/CMakeLists.txt | 1 + host/include/uhd/utils/log.hpp | 2 +- host/include/uhd/utils/msg.hpp | 67 ++++++++++++++++++ host/include/uhd/utils/safe_call.hpp | 6 +- host/include/uhd/utils/warning.hpp | 12 ++-- host/lib/transport/udp_zero_copy.cpp | 6 +- host/lib/types/device_addr.cpp | 6 +- host/lib/usrp/dboard/db_basic_and_lf.cpp | 18 ++--- host/lib/usrp/dboard/db_dbsrx.cpp | 26 +++---- host/lib/usrp/dboard/db_rfx.cpp | 10 +-- host/lib/usrp/dboard/db_sbx.cpp | 10 +-- host/lib/usrp/dboard/db_tvrx.cpp | 6 +- host/lib/usrp/dboard/db_unknown.cpp | 14 ++-- host/lib/usrp/dboard/db_wbx_common.cpp | 10 +-- host/lib/usrp/dboard/db_xcvr2450.cpp | 1 - host/lib/usrp/dboard_manager.cpp | 8 +-- host/lib/usrp/multi_usrp.cpp | 14 ++-- host/lib/usrp/usrp1/mboard_impl.cpp | 4 +- host/lib/usrp/usrp1/usrp1_impl.cpp | 4 +- host/lib/usrp/usrp2/usrp2_impl.cpp | 1 - host/lib/usrp/usrp_e100/usrp_e100_impl.cpp | 19 +++-- host/lib/utils/CMakeLists.txt | 1 + host/lib/utils/log.cpp | 2 +- host/lib/utils/msg.cpp | 109 +++++++++++++++++++++++++++++ host/lib/utils/thread_priority.cpp | 6 +- host/lib/utils/warning.cpp | 8 +-- host/tests/CMakeLists.txt | 2 +- host/tests/msg_test.cpp | 39 +++++++++++ host/tests/warning_test.cpp | 29 -------- 30 files changed, 306 insertions(+), 142 deletions(-) create mode 100644 host/include/uhd/utils/msg.hpp create mode 100644 host/lib/utils/msg.cpp create mode 100644 host/tests/msg_test.cpp delete mode 100644 host/tests/warning_test.cpp (limited to 'host/lib/utils/log.cpp') 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 6c507dcde..875c4731f 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -24,6 +24,7 @@ INSTALL(FILES 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 index 9dceea982..503c468f1 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -76,7 +76,7 @@ namespace uhd{ namespace _log{ }; //! Internal logging object (called by UHD_LOG macros) - struct /*UHD_API*/ log{ + struct UHD_API_FUTURE log{ log( const verbosity_t verbosity, const std::string &file, diff --git a/host/include/uhd/utils/msg.hpp b/host/include/uhd/utils/msg.hpp new file mode 100644 index 000000000..a78e04ad3 --- /dev/null +++ b/host/include/uhd/utils/msg.hpp @@ -0,0 +1,67 @@ +// +// 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 . +// + +#ifndef INCLUDED_UHD_UTILS_MSG_HPP +#define INCLUDED_UHD_UTILS_MSG_HPP + +#include +#include +#include + +/*! + * 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', + }; + + //! 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 &get(void); + + template std::ostream &operator<<(const T &x){ + return get() << x; + } + }; + +}} //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..b9f545b23 100644 --- a/host/include/uhd/utils/safe_call.hpp +++ b/host/include/uhd/utils/safe_call.hpp @@ -20,12 +20,12 @@ #include #include -#include +#include //! 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_MSG(warning) << \ 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 #include +/*! \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 registry_names(void); + UHD_API UHD_DEPRECATED const std::vector registry_names(void); }} //namespace uhd::warning diff --git a/host/lib/transport/udp_zero_copy.cpp b/host/lib/transport/udp_zero_copy.cpp index 15d882676..c3ba085bf 100644 --- a/host/lib/transport/udp_zero_copy.cpp +++ b/host/lib/transport/udp_zero_copy.cpp @@ -20,7 +20,7 @@ #include //mtu #include #include -#include +#include #include #include #include @@ -279,12 +279,12 @@ template static void resize_buff_helper( "Target %s sock buff size: %d bytes\n" "Actual %s sock buff size: %d bytes" ) % name % target_size % 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 % target_size % actual_size % 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 +#include 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 = is deprecated.\n" "To address a multi-device, use multiple = .\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 #include #include -#include +#include #include #include #include @@ -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 dbe2f6370..cfe06db29 100644 --- a/host/lib/usrp/dboard/db_dbsrx.cpp +++ b/host/lib/usrp/dboard/db_dbsrx.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -175,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); @@ -342,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; @@ -356,11 +350,9 @@ 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; diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 1f0290179..61f9130d4 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -514,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(); @@ -616,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 4d8753fab..6ca89b81a 100644 --- a/host/lib/usrp/dboard/db_sbx.cpp +++ b/host/lib/usrp/dboard/db_sbx.cpp @@ -81,7 +81,7 @@ #include #include #include -#include +#include #include #include #include @@ -674,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(); @@ -780,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 cd7216c22..1ff0fb785 100644 --- a/host/lib/usrp/dboard/db_tvrx.cpp +++ b/host/lib/usrp/dboard/db_tvrx.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -485,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 #include #include -#include +#include #include #include #include @@ -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 fdee14607..131729f42 100644 --- a/host/lib/usrp/dboard/db_wbx_common.cpp +++ b/host/lib/usrp/dboard/db_wbx_common.cpp @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include #include @@ -472,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(); @@ -572,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_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 4bda43251..c775eae38 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -52,7 +52,6 @@ #include #include #include -#include #include #include #include diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index cd934dd0d..11b72b9fa 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -18,7 +18,7 @@ #include "dboard_ctor_args.hpp" #include #include -#include +#include #include #include #include @@ -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/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 83cbf339b..2b32602da 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -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); } } @@ -211,11 +211,11 @@ public: time_spec_t time_0 = _mboard(0)[MBOARD_PROP_TIME_NOW].as(); time_spec_t time_i = _mboard(m)[MBOARD_PROP_TIME_NOW].as(); 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/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index eecae3fa7..aa9ce244b 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -98,7 +98,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" ); diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index a99777775..b7cd95a82 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ 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" ); diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 77370a7fd..558bcab2a 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp index fe839c409..3fa60232e 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -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); } } diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index ae18bde9d..0e0d51c78 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -132,6 +132,7 @@ LIBUHD_APPEND_SOURCES( ${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/log.cpp b/host/lib/utils/log.cpp index 0a2861cbd..d99ce01c4 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -167,7 +167,7 @@ private: UHD_SINGLETON_FCN(uhd_logger_stream_resource_class, uhd_logger_stream_resource); /*********************************************************************** - * The logger function implementation + * The logger object implementation **********************************************************************/ //! get the relative file path from the host directory static std::string get_rel_file_path(const fs::path &file){ diff --git a/host/lib/utils/msg.cpp b/host/lib/utils/msg.cpp new file mode 100644 index 000000000..de6d4c8fa --- /dev/null +++ b/host/lib/utils/msg.cpp @@ -0,0 +1,109 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include +#include +#include + +/*********************************************************************** + * Helper functions + **********************************************************************/ +#define tokenizer(inp, sep) \ + boost::tokenizer > \ + (inp, boost::char_separator(sep)) + +static void msg_to_cout(const std::string &msg){ + std::stringstream ss; + + BOOST_FOREACH(const std::string &line, tokenizer(msg, "\n")){ + ss << "-- " << line << std::endl; + } + + std::cout << ss.str(); +} + +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(); +} + +/*********************************************************************** + * 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::status: + msg_to_cout(msg); + break; + + case uhd::msg::warning: + msg_to_cerr("UHD Warning", msg); + break; + + case uhd::msg::error: + msg_to_cerr("UHD Error", 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()); + UHD_LOG << "Message " << char(msg_type) << std::endl << msg_ss.str(); + msg_ss.str(""); //clear for next call + msg_mutex.unlock(); +} + +std::ostream & uhd::msg::_msg::get(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 -#include +#include #include #include #include @@ -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 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/msg_test.cpp b/host/tests/msg_test.cpp new file mode 100644 index 000000000..495907504 --- /dev/null +++ b/host/tests/msg_test.cpp @@ -0,0 +1,39 @@ +// +// Copyright 2010-2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// 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 . +// + +#include +#include +#include + +BOOST_AUTO_TEST_CASE(test_messages){ + #ifdef UHD_FUTURE + std::cerr << "---begin print test ---" << std::endl; + 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 +} diff --git a/host/tests/warning_test.cpp b/host/tests/warning_test.cpp deleted file mode 100644 index 3394f84d4..000000000 --- a/host/tests/warning_test.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright 2010-2011 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// 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 . -// - -#include -#include -#include - -BOOST_AUTO_TEST_CASE(test_warning_post){ - std::cerr << "---begin print test ---" << std::endl; - uhd::warning::post( - "This is a test print for a warning message.\n" - "And this is the second line of the test print.\n" - ); - std::cerr << "---end print test ---" << std::endl; -} -- cgit v1.2.3 From 09be0518cee887878f3b070adea25eccc4c06e60 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 19:53:01 -0700 Subject: uhd: removed more iostream stuff from usrp* implementations --- host/include/uhd/utils/log.hpp | 1 + host/include/uhd/utils/msg.hpp | 1 + host/lib/usrp/dboard/db_dbsrx2.cpp | 2 +- host/lib/usrp/gps_ctrl.cpp | 11 +++++---- host/lib/usrp/multi_usrp.cpp | 6 ++--- host/lib/usrp/usrp1/clock_ctrl.cpp | 8 +++---- host/lib/usrp/usrp1/codec_ctrl.cpp | 47 +++++++++++++++++-------------------- host/lib/usrp/usrp1/dsp_impl.cpp | 6 ++--- host/lib/usrp/usrp1/io_impl.cpp | 10 ++++---- host/lib/usrp/usrp1/mboard_impl.cpp | 30 +++++++++++------------ host/lib/usrp/usrp1/usrp1_ctrl.cpp | 10 ++++---- host/lib/usrp/usrp1/usrp1_iface.cpp | 23 ++++++++---------- host/lib/usrp/usrp1/usrp1_impl.cpp | 6 ++--- host/lib/usrp/usrp2/codec_ctrl.cpp | 6 ++--- host/lib/usrp/usrp2/io_impl.cpp | 16 +++++++------ host/lib/usrp/usrp2/mboard_impl.cpp | 11 +++++---- host/lib/usrp/usrp2/usrp2_impl.cpp | 10 ++++---- host/lib/usrp/usrp_e100/io_impl.cpp | 5 ++-- host/lib/utils/log.cpp | 3 ++- host/lib/utils/msg.cpp | 8 ++++++- 20 files changed, 110 insertions(+), 110 deletions(-) (limited to 'host/lib/utils/log.cpp') diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index 503c468f1..666dfa982 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -73,6 +73,7 @@ namespace uhd{ namespace _log{ regularly = 3, rarely = 4, very_rarely = 5, + never = 6, }; //! Internal logging object (called by UHD_LOG macros) diff --git a/host/include/uhd/utils/msg.hpp b/host/include/uhd/utils/msg.hpp index a78e04ad3..2313215bf 100644 --- a/host/include/uhd/utils/msg.hpp +++ b/host/include/uhd/utils/msg.hpp @@ -37,6 +37,7 @@ namespace uhd{ namespace msg{ status = 's', warning = 'w', error = 'e', + fastpath= 'f' }; //! Typedef for a user-registered message handler diff --git a/host/lib/usrp/dboard/db_dbsrx2.cpp b/host/lib/usrp/dboard/db_dbsrx2.cpp index 0769b3aa1..aaced7a5d 100644 --- a/host/lib/usrp/dboard/db_dbsrx2.cpp +++ b/host/lib/usrp/dboard/db_dbsrx2.cpp @@ -134,7 +134,7 @@ 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; */ 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 +#include #include #include #include @@ -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 2b32602da..64f82e559 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include #include #include -#include #include using namespace uhd; @@ -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)); 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 #include #include -#include 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(_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 #include #include #include @@ -28,13 +29,10 @@ #include #include #include -#include #include 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 #include #include #include #include #include #include -#include #include 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()); 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()); 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 #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include 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 aa9ce244b..cd04e7351 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -20,6 +20,8 @@ #include "fpga_regs_standard.h" #include "fpga_regs_common.h" #include "usrp_i2c_addr.h" +#include +#include #include #include #include @@ -31,13 +33,10 @@ #include #include #include -#include 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 @@ -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() == "load_eeprom") { std::string usrp1_eeprom_image = val.as(); - 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()); } 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()); 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 #include #include #include #include -#include #include #include #include @@ -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..d7e8f601f 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 #include #include #include #include -#include #include 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; @@ -129,8 +126,8 @@ 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) @@ -143,8 +140,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); } diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index b7cd95a82..182705034 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -19,6 +19,7 @@ #include "usrp1_ctrl.hpp" #include "fpga_regs_standard.h" #include "usrp_spi_defs.h" +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include using namespace uhd; using namespace uhd::usrp; @@ -84,7 +84,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) ); 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);} @@ -128,7 +128,7 @@ static device::sptr usrp1_make(const device_addr_t &device_addr){ 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 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 #include #include #include -#include - -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 +#include #include #include #include @@ -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(); 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(); 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 d4ae27763..daccc0865 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 +#include #include #include #include @@ -29,7 +31,6 @@ #include #include #include -#include static const double mimo_clock_delay_usrp2_rev4 = 4.18e-9; static const double mimo_clock_delay_usrp_n2xx = 3.55e-9; @@ -81,19 +82,19 @@ usrp2_mboard_impl::usrp2_mboard_impl( } //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() )); @@ -141,7 +142,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 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 558bcab2a..4eb5508e2 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -17,6 +17,8 @@ #include "usrp2_impl.hpp" #include "fw_common.h" +#include +#include #include #include #include @@ -31,7 +33,6 @@ #include #include #include //used for htonl and ntohl -#include #include using namespace uhd; @@ -102,7 +103,6 @@ static device_addrs_t usrp2_find(const device_addr_t &hint_){ const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast(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 @@ -189,7 +189,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); @@ -206,7 +205,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); @@ -262,8 +260,8 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ device_addr["recv_frame_size"] = boost::lexical_cast(mtu.recv_mtu); device_addr["send_frame_size"] = boost::lexical_cast(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/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp index 7e775dfd8..aa6e7c485 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/usrp_e100/io_impl.cpp @@ -28,7 +28,6 @@ #include #include #include -#include using namespace uhd; using namespace uhd::usrp; @@ -158,7 +157,7 @@ void usrp_e100_impl::io_impl::recv_pirate_loop( metadata.event_code = vrt_packet_handler::get_context_code(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; } @@ -224,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/utils/log.cpp b/host/lib/utils/log.cpp index d99ce01c4..f67a14411 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -140,7 +140,7 @@ 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::very_rarely){ + 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 @@ -149,6 +149,7 @@ private: if_lls_equal(regularly); if_lls_equal(rarely); if_lls_equal(very_rarely); + if_lls_equal(never); } //available stream objects diff --git a/host/lib/utils/msg.cpp b/host/lib/utils/msg.cpp index de6d4c8fa..0eaca05a5 100644 --- a/host/lib/utils/msg.cpp +++ b/host/lib/utils/msg.cpp @@ -71,16 +71,23 @@ void uhd::msg::register_handler(const handler_t &handler){ 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; } } @@ -99,7 +106,6 @@ uhd::msg::_msg::_msg(const type_t type){ uhd::msg::_msg::~_msg(void){ msg_handler(msg_type, msg_ss.str()); - UHD_LOG << "Message " << char(msg_type) << std::endl << msg_ss.str(); msg_ss.str(""); //clear for next call msg_mutex.unlock(); } -- cgit v1.2.3 From 9734a74366dd095256c2e2c58c5c9bcd7547f72d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 4 May 2011 20:40:36 -0700 Subject: uhd: various tweaks to log and msg, replaced a few remaining stdio --- host/include/uhd/utils/log.hpp | 9 ++------- host/include/uhd/utils/msg.hpp | 9 ++------- host/include/uhd/utils/safe_call.hpp | 4 ++-- host/lib/device.cpp | 5 +++-- host/lib/usrp/usrp1/usrp1_impl.cpp | 1 + host/lib/usrp/usrp2/mboard_impl.cpp | 2 +- host/lib/usrp/usrp2/usrp2_impl.cpp | 1 + host/lib/usrp/usrp_e100/usrp_e100_impl.cpp | 1 + host/lib/utils/log.cpp | 2 +- host/lib/utils/msg.cpp | 18 +++++++++++++----- 10 files changed, 27 insertions(+), 25 deletions(-) (limited to 'host/lib/utils/log.cpp') diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index 666dfa982..8d8f42fd0 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -54,7 +54,7 @@ * 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) + uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)() /*! * A UHD logger macro with default verbosity. @@ -85,12 +85,7 @@ namespace uhd{ namespace _log{ const std::string &function ); ~log(void); - - std::ostream &get(void); - - template std::ostream &operator<<(const T &x){ - return get() << x; - } + std::ostream &operator()(void); }; }} //namespace uhd::_log diff --git a/host/include/uhd/utils/msg.hpp b/host/include/uhd/utils/msg.hpp index 2313215bf..17179f551 100644 --- a/host/include/uhd/utils/msg.hpp +++ b/host/include/uhd/utils/msg.hpp @@ -27,7 +27,7 @@ * Usage: UHD_MSG(warning) << "some warning message" << std::endl; */ #define UHD_MSG(type) \ - uhd::msg::_msg(uhd::msg::type) + uhd::msg::_msg(uhd::msg::type)() namespace uhd{ namespace msg{ @@ -55,12 +55,7 @@ namespace uhd{ namespace msg{ struct UHD_API_FUTURE _msg{ _msg(const type_t type); ~_msg(void); - - std::ostream &get(void); - - template std::ostream &operator<<(const T &x){ - return get() << x; - } + std::ostream &operator()(void); }; }} //namespace uhd::msg diff --git a/host/include/uhd/utils/safe_call.hpp b/host/include/uhd/utils/safe_call.hpp index b9f545b23..ab287cc66 100644 --- a/host/include/uhd/utils/safe_call.hpp +++ b/host/include/uhd/utils/safe_call.hpp @@ -20,10 +20,10 @@ #include #include -#include +#include //! helper macro for safe call to produce warnings -#define _UHD_SAFE_CALL_WARNING(code, what) UHD_MSG(warning) << \ +#define _UHD_SAFE_CALL_WARNING(code, what) UHD_LOGV(rarely) << \ UHD_THROW_SITE_INFO("Exception caught in safe-call.") + #code + " -> " + what \ ; diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 84b4d5452..c5bc047da 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -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)); } @@ -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/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 182705034..57aae1b58 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -123,6 +123,7 @@ 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( diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index daccc0865..c9931be45 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -142,7 +142,7 @@ usrp2_mboard_impl::usrp2_mboard_impl( else { _mimo_clocking_mode_is_master = (_iface->peek32(_iface->regs.status) & (1 << 8)) != 0; } - UHD_MSG(status) << 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 4eb5508e2..2bc259657 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -228,6 +228,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) diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp index 4247746ab..00d7dd029 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp @@ -77,6 +77,7 @@ static device_addrs_t usrp_e100_find(const device_addr_t &hint){ * Make **********************************************************************/ static device::sptr usrp_e100_make(const device_addr_t &device_addr){ + UHD_MSG(status) << "Opening a USRP E-Series device..." << std::endl; //setup the main interface into fpga std::string node = device_addr["node"]; diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index f67a14411..8b270af6b 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -209,6 +209,6 @@ uhd::_log::log::~log(void){ uhd_logger_stream_resource().aquire(false); } -std::ostream & uhd::_log::log::get(void){ +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 index 0eaca05a5..e850b5a6d 100644 --- a/host/lib/utils/msg.cpp +++ b/host/lib/utils/msg.cpp @@ -34,11 +34,19 @@ static void msg_to_cout(const std::string &msg){ std::stringstream ss; - BOOST_FOREACH(const std::string &line, tokenizer(msg, "\n")){ - ss << "-- " << line << std::endl; + 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::cout << ss.str() << std::flush; } static void msg_to_cerr(const std::string &title, const std::string &msg){ @@ -49,7 +57,7 @@ static void msg_to_cerr(const std::string &title, const std::string &msg){ ss << " " << line << std::endl; } - std::cerr << ss.str(); + std::cerr << ss.str() << std::flush; } /*********************************************************************** @@ -110,6 +118,6 @@ uhd::msg::_msg::~_msg(void){ msg_mutex.unlock(); } -std::ostream & uhd::msg::_msg::get(void){ +std::ostream & uhd::msg::_msg::operator()(void){ return msg_ss; } -- cgit v1.2.3