aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport/libusb1_base.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/transport/libusb1_base.cpp')
-rw-r--r--host/lib/transport/libusb1_base.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp
index d4ec874f1..0ef53db0a 100644
--- a/host/lib/transport/libusb1_base.cpp
+++ b/host/lib/transport/libusb1_base.cpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2011 Ettus Research LLC
+// Copyright 2010-2013 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
@@ -23,6 +23,7 @@
#include <boost/weak_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/foreach.hpp>
+#include <cstdlib>
#include <iostream>
using namespace uhd;
@@ -59,6 +60,15 @@ libusb::session::sptr libusb::session::get_global_session(void){
//create a new global session
sptr new_global_session(new libusb_session_impl());
global_session = new_global_session;
+
+ //set logging if envvar is set
+ const char *level_string = getenv("LIBUSB_DEBUG_LEVEL");
+ if (level_string != NULL)
+ {
+ const int level = int(level_string[0] - '0'); //easy conversion to integer
+ if (level >= 0 and level <= 3) libusb_set_debug(new_global_session->get_context(), level);
+ }
+
return new_global_session;
}
@@ -137,8 +147,13 @@ public:
return _desc;
}
- std::string get_ascii_serial(void) const{
- if (this->get().iSerialNumber == 0) return "";
+ std::string get_ascii_property(const std::string &what) const
+ {
+ boost::uint8_t off = 0;
+ if (what == "serial") off = this->get().iSerialNumber;
+ if (what == "product") off = this->get().iProduct;
+ if (what == "manufacturer") off = this->get().iManufacturer;
+ if (off == 0) return "";
libusb::device_handle::sptr handle(
libusb::device_handle::get_cached_handle(_dev)
@@ -146,7 +161,7 @@ public:
unsigned char buff[512];
ssize_t ret = libusb_get_string_descriptor_ascii(
- handle->get(), this->get().iSerialNumber, buff, sizeof(buff)
+ handle->get(), off, buff, sizeof(buff)
);
if (ret < 0) return ""; //on error, just return empty string
@@ -240,7 +255,15 @@ public:
}
std::string get_serial(void) const{
- return libusb::device_descriptor::make(this->get_device())->get_ascii_serial();
+ return libusb::device_descriptor::make(this->get_device())->get_ascii_property("serial");
+ }
+
+ std::string get_manufacturer() const{
+ return libusb::device_descriptor::make(this->get_device())->get_ascii_property("manufacturer");
+ }
+
+ std::string get_product() const{
+ return libusb::device_descriptor::make(this->get_device())->get_ascii_property("product");
}
boost::uint16_t get_vendor_id(void) const{