aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-12-20 22:47:06 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2020-01-07 16:04:04 +0100
commit84231bd8b7f1675c91979aab25be6d2beb41e5ba (patch)
treeef2461dfaea98b4714afa5cef283fdc9e1b41eb6
parentaebbfe0ee779cfafc421c201658a68f74376da02 (diff)
uhd: Use DEVDRV log category and support UHD >=3.11 logging framework
-rw-r--r--CommonLibs/Logger.h3
-rw-r--r--Transceiver52M/device/uhd/UHDDevice.cpp60
2 files changed, 51 insertions, 12 deletions
diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index ab72303..b752e51 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -58,6 +58,9 @@ extern "C" {
#define LOGLV(category, level) \
Log(category, level, __BASE_FILE__, __LINE__).get() << "[tid=" << pthread_self() << "] "
+#define LOGSRC(category, level, file, line) \
+ Log(category, level, file, line).get() << "[tid=" << pthread_self() << "] "
+
#define LOGCHAN(chan, category, level) \
Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() << "[tid=" << pthread_self() << "][chan=" << chan << "] "
diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp
index 59eb8a7..4a6c233 100644
--- a/Transceiver52M/device/uhd/UHDDevice.cpp
+++ b/Transceiver52M/device/uhd/UHDDevice.cpp
@@ -33,11 +33,12 @@
#include "config.h"
#endif
-#ifndef USE_UHD_3_11
+#ifdef USE_UHD_3_11
+#include <uhd/utils/log_add.hpp>
+#include <uhd/utils/thread.hpp>
+#else
#include <uhd/utils/msg.hpp>
#include <uhd/utils/thread_priority.hpp>
-#else
-#include <uhd/utils/thread.hpp>
#endif
#define USRP_TX_AMPL 0.3
@@ -134,23 +135,52 @@ void *async_event_loop(uhd_device *dev)
return NULL;
}
-#ifndef USE_UHD_3_11
+#ifdef USE_UHD_3_11
+static void uhd_log_handler(const uhd::log::logging_info &info)
+{
+ int level;
+
+ switch (info.verbosity)
+ {
+ case uhd::log::trace:
+ case uhd::log::debug:
+ level = LOGL_DEBUG;
+ break;
+ case uhd::log::info:
+ level = LOGL_INFO;
+ break;
+ case uhd::log::warning:
+ level = LOGL_NOTICE;
+ break;
+ case uhd::log::error:
+ level = LOGL_ERROR;
+ break;
+ case uhd::log::fatal:
+ level = LOGL_FATAL;
+ break;
+ default:
+ level = LOGL_NOTICE;
+ }
+
+ LOGSRC(DDEVDRV, level, info.file.c_str(), info.line) << "[" << info.component << "] " << info.message;
+}
+#else
/*
Catch and drop underrun 'U' and overrun 'O' messages from stdout
since we already report using the logging facility. Direct
everything else appropriately.
*/
-void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg)
+static void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg)
{
switch (type) {
case uhd::msg::status:
- LOGC(DDEV, INFO) << msg;
+ LOGC(DDEVDRV, INFO) << msg;
break;
case uhd::msg::warning:
- LOGC(DDEV, WARNING) << msg;
+ LOGC(DDEVDRV, NOTICE) << msg;
break;
case uhd::msg::error:
- LOGC(DDEV, ERROR) << msg;
+ LOGC(DDEVDRV, ERROR) << msg;
break;
case uhd::msg::fastpath:
break;
@@ -418,6 +448,16 @@ int uhd_device::open(const std::string &args, int ref, bool swap_channels)
{
const char *refstr;
+ /* Register msg handler. Different APIs depending on UHD version */
+#ifdef USE_UHD_3_11
+ uhd::log::add_logger("OsmoTRX", &uhd_log_handler);
+ uhd::log::set_log_level(uhd::log::debug);
+ uhd::log::set_console_level(uhd::log::off);
+ uhd::log::set_logger_level("OsmoTRX", uhd::log::debug);
+#else
+ uhd::msg::register_handler(&uhd_msg_handler);
+#endif
+
// Find UHD devices
uhd::device_addr_t addr(args);
uhd::device_addrs_t dev_addrs = uhd::device::find(addr);
@@ -604,10 +644,6 @@ bool uhd_device::start()
return false;
}
-#ifndef USE_UHD_3_11
- // Register msg handler
- uhd::msg::register_handler(&uhd_msg_handler);
-#endif
// Start asynchronous event (underrun check) loop
async_event_thrd = new Thread();
async_event_thrd->start((void * (*)(void*))async_event_loop, (void*)this);