summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
Diffstat (limited to 'host')
-rw-r--r--host/examples/benchmark_rate.cpp2
-rw-r--r--host/examples/rx_multi_samples.cpp4
-rw-r--r--host/examples/rx_samples_to_file.cpp19
-rw-r--r--host/examples/rx_timed_samples.cpp4
-rw-r--r--host/examples/test_timed_commands.cpp4
-rw-r--r--host/examples/transport_hammer.cpp2
-rw-r--r--host/examples/txrx_loopback_to_file.cpp4
-rw-r--r--host/include/uhd/types/metadata.hpp16
-rw-r--r--host/lib/types/CMakeLists.txt1
-rw-r--r--host/lib/types/metadata.cpp92
-rw-r--r--host/utils/usrp_cal_utils.hpp4
11 files changed, 128 insertions, 24 deletions
diff --git a/host/examples/benchmark_rate.cpp b/host/examples/benchmark_rate.cpp
index ea49d48d9..9e9aa67e9 100644
--- a/host/examples/benchmark_rate.cpp
+++ b/host/examples/benchmark_rate.cpp
@@ -98,7 +98,7 @@ void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_c
break;
default:
- std::cerr << "Error code: " << md.error_code << std::endl;
+ std::cerr << "Receiver error: " << md.strerror() << std::endl;
std::cerr << "Unexpected error on recv, continuing..." << std::endl;
break;
}
diff --git a/host/examples/rx_multi_samples.cpp b/host/examples/rx_multi_samples.cpp
index 9e5970978..a50b5f0e0 100644
--- a/host/examples/rx_multi_samples.cpp
+++ b/host/examples/rx_multi_samples.cpp
@@ -172,8 +172,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break;
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
+ "Receiver error %s"
+ ) % md.strerror()));
}
if(verbose) std::cout << boost::format(
diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp
index 0d42404d3..de3640794 100644
--- a/host/examples/rx_samples_to_file.cpp
+++ b/host/examples/rx_samples_to_file.cpp
@@ -101,18 +101,15 @@ template<typename samp_type> void recv_to_file(
continue;
}
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
- std::string error = str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code);
-
- if (continue_on_bad_packet){
- std::cerr << error << std::endl;
- continue;
- }
- else
- throw std::runtime_error(error);
+ std::string error = str(boost::format("Receiver error: %s") % md.strerror());
+ if (continue_on_bad_packet){
+ std::cerr << error << std::endl;
+ continue;
+ }
+ else
+ throw std::runtime_error(error);
}
-
+
if (enable_size_map){
SizeMap::iterator it = mapSizes.find(num_rx_samps);
if (it == mapSizes.end())
diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp
index cc9216cb7..30535907f 100644
--- a/host/examples/rx_timed_samples.cpp
+++ b/host/examples/rx_timed_samples.cpp
@@ -130,8 +130,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break;
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
+ "Receiver error %s"
+ ) % md.strerror()));
}
if(verbose) std::cout << boost::format(
diff --git a/host/examples/test_timed_commands.cpp b/host/examples/test_timed_commands.cpp
index 8c6011c68..3da4bc707 100644
--- a/host/examples/test_timed_commands.cpp
+++ b/host/examples/test_timed_commands.cpp
@@ -139,8 +139,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md, 1.0);
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
+ "Receiver error %s"
+ ) % md.strerror()));
}
std::cout << boost::format(
" Received packet: %u samples, %u full secs, %f frac secs"
diff --git a/host/examples/transport_hammer.cpp b/host/examples/transport_hammer.cpp
index 4b949e5bd..3f233b2a5 100644
--- a/host/examples/transport_hammer.cpp
+++ b/host/examples/transport_hammer.cpp
@@ -88,7 +88,7 @@ void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, uhd:
break;
default:
- std::cerr << "Error code: " << md.error_code << std::endl;
+ std::cerr << "Receiver error: " << md.strerror() << std::endl;
std::cerr << "Unexpected error on recv, continuing..." << std::endl;
break;
}
diff --git a/host/examples/txrx_loopback_to_file.cpp b/host/examples/txrx_loopback_to_file.cpp
index 3d3cf1dfc..a62ccd7b2 100644
--- a/host/examples/txrx_loopback_to_file.cpp
+++ b/host/examples/txrx_loopback_to_file.cpp
@@ -181,8 +181,8 @@ template<typename samp_type> void recv_to_file(
}
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
+ "Receiver error %s"
+ ) % md.strerror()));
}
num_total_samps += num_rx_samps;
diff --git a/host/include/uhd/types/metadata.hpp b/host/include/uhd/types/metadata.hpp
index 6a79720d0..51a2b7c43 100644
--- a/host/include/uhd/types/metadata.hpp
+++ b/host/include/uhd/types/metadata.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2012 Ettus Research LLC
+// Copyright 2010-2012,2014 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
@@ -117,6 +117,20 @@ namespace uhd{
//! Out of sequence. The transport has either dropped a packet or received data out of order.
bool out_of_sequence;
+
+ /*!
+ * Convert a rx_metadata_t into a pretty print string.
+ *
+ * \param compact Set to false for a more verbose output.
+ * \return a printable string representing the metadata.
+ */
+ std::string to_pp_string(bool compact=true) const;
+
+ /*!
+ * Similar to C's strerror() function, creates a std::string describing the error code.
+ * \return a printable string representing the error.
+ */
+ std::string strerror(void) const;
};
/*!
diff --git a/host/lib/types/CMakeLists.txt b/host/lib/types/CMakeLists.txt
index b69c8e487..7fc6bdd94 100644
--- a/host/lib/types/CMakeLists.txt
+++ b/host/lib/types/CMakeLists.txt
@@ -82,6 +82,7 @@ SET_SOURCE_FILES_PROPERTIES(
LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/device_addr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mac_addr.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/metadata.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ranges.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sensors.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serial.cpp
diff --git a/host/lib/types/metadata.cpp b/host/lib/types/metadata.cpp
new file mode 100644
index 000000000..fec2ac564
--- /dev/null
+++ b/host/lib/types/metadata.cpp
@@ -0,0 +1,92 @@
+//
+// Copyright 2014 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <string>
+#include <sstream>
+#include <boost/format.hpp>
+#include <uhd/exception.hpp>
+#include <uhd/types/metadata.hpp>
+#include <uhd/types/time_spec.hpp>
+
+using namespace uhd;
+
+std::string rx_metadata_t::to_pp_string(bool compact) const
+{
+ std::stringstream ss;
+
+ if (compact) {
+ if (has_time_spec) {
+ ss << "Time: " << time_spec.get_real_secs() << " s\n";
+ }
+ if (more_fragments) {
+ ss << "Fragmentation offset: " << fragment_offset << "\n";
+ }
+ if (start_of_burst) {
+ ss << "Start of burst.\n" << fragment_offset;
+ }
+ if (end_of_burst) {
+ ss << "End of burst.\n" << fragment_offset;
+ }
+ if (error_code != ERROR_CODE_NONE) {
+ ss << strerror() << "\n";
+ }
+ } else {
+ ss << "Has timespec: " << (has_time_spec ? "Yes" : "No")
+ << "\tTime of first sample: " << time_spec.get_real_secs()
+ << "\nFragmented: " << (more_fragments ? "Yes" : "No")
+ << " Fragmentation offset: " << fragment_offset
+ << "\nStart of burst: " << (start_of_burst ? "Yes" : "No")
+ << "\tEnd of burst: " << (end_of_burst ? "Yes" : "No")
+ << "\nError Code: " << strerror()
+ << "\tOut of sequence: " << (out_of_sequence ? "Yes" : "No");
+ }
+
+ return ss.str();
+}
+
+std::string rx_metadata_t::strerror() const
+{
+ std::string errstr = "";
+ switch(this->error_code) {
+ case ERROR_CODE_NONE:
+ errstr = "ERROR_CODE_NONE";
+ break;
+ case ERROR_CODE_TIMEOUT:
+ errstr = "ERROR_CODE_TIMEOUT";
+ break;
+ case ERROR_CODE_LATE_COMMAND:
+ errstr = "ERROR_CODE_LATE_COMMAND";
+ break;
+ case ERROR_CODE_BROKEN_CHAIN:
+ errstr = "ERROR_CODE_BROKEN_CHAIN (Expected another stream command)";
+ break;
+ case ERROR_CODE_OVERFLOW:
+ errstr = "ERROR_CODE_OVERFLOW ";
+ errstr += (this->out_of_sequence ? "(Out of sequence error)" : "(Overflow)");
+ break;
+ case ERROR_CODE_ALIGNMENT:
+ errstr = "ERROR_CODE_ALIGNMENT (Multi-channel alignment failed)";
+ break;
+ case ERROR_CODE_BAD_PACKET:
+ errstr = "ERROR_CODE_BAD_PACKET";
+ break;
+ default:
+ errstr = std::string(str(boost::format("Unknown error code: 0x%x") % error_code));
+ }
+
+ return errstr;
+}
diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp
index 5aff5e22f..e8749fba7 100644
--- a/host/utils/usrp_cal_utils.hpp
+++ b/host/utils/usrp_cal_utils.hpp
@@ -257,8 +257,8 @@ static void capture_samples(
//validate the received data
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
throw std::runtime_error(str(boost::format(
- "Unexpected error code 0x%x"
- ) % md.error_code));
+ "Receiver error: %s"
+ ) % md.strerror()));
}
//we can live if all the data didnt come in
if (num_rx_samps > buff.size()/2){