aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2014-04-01 13:11:23 +0200
committerMartin Braun <martin.braun@ettus.com>2014-04-10 21:25:53 +0200
commit1f61316536057c4326964c599c90b6d1281c6e2b (patch)
tree1c6db3ca7bb7c2537842e179043f15e1ba1a9e33 /host/lib
parentddb35a65ddcca7aa7a8c03d4185357fea2bf47c0 (diff)
downloaduhd-1f61316536057c4326964c599c90b6d1281c6e2b.tar.gz
uhd-1f61316536057c4326964c599c90b6d1281c6e2b.tar.bz2
uhd-1f61316536057c4326964c599c90b6d1281c6e2b.zip
uhd: Added pp routines for error codes and rx metadata
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/types/CMakeLists.txt1
-rw-r--r--host/lib/types/metadata.cpp92
2 files changed, 93 insertions, 0 deletions
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;
+}