1 // 2 // Copyright 2014 Ettus Research LLC 3 // Copyright 2018 Ettus Research, a National Instruments Company 4 // 5 // SPDX-License-Identifier: GPL-3.0-or-later 6 // 7 8 #include <uhd/exception.hpp> 9 #include <uhd/types/metadata.hpp> 10 #include <uhd/types/time_spec.hpp> 11 #include <boost/format.hpp> 12 #include <sstream> 13 #include <string> 14 15 using namespace uhd; 16 to_pp_string(bool compact) const17std::string rx_metadata_t::to_pp_string(bool compact) const 18 { 19 std::stringstream ss; 20 21 if (compact) { 22 if (has_time_spec) { 23 ss << "Time: " << time_spec.get_real_secs() << " s\n"; 24 } 25 if (more_fragments) { 26 ss << "Fragmentation offset: " << fragment_offset << "\n"; 27 } 28 if (start_of_burst) { 29 ss << "Start of burst.\n" << fragment_offset; 30 } 31 if (end_of_burst) { 32 ss << "End of burst.\n" << fragment_offset; 33 } 34 if (error_code != ERROR_CODE_NONE) { 35 ss << strerror() << "\n"; 36 } 37 } else { 38 ss << "Has timespec: " << (has_time_spec ? "Yes" : "No") 39 << "\tTime of first sample: " << time_spec.get_real_secs() 40 << "\nFragmented: " << (more_fragments ? "Yes" : "No") 41 << " Fragmentation offset: " << fragment_offset 42 << "\nStart of burst: " << (start_of_burst ? "Yes" : "No") 43 << "\tEnd of burst: " << (end_of_burst ? "Yes" : "No") 44 << "\nError Code: " << strerror() 45 << "\tOut of sequence: " << (out_of_sequence ? "Yes" : "No"); 46 } 47 48 return ss.str(); 49 } 50 strerror() const51std::string rx_metadata_t::strerror() const 52 { 53 std::string errstr = ""; 54 switch (this->error_code) { 55 case ERROR_CODE_NONE: 56 errstr = "ERROR_CODE_NONE"; 57 break; 58 case ERROR_CODE_TIMEOUT: 59 errstr = "ERROR_CODE_TIMEOUT"; 60 break; 61 case ERROR_CODE_LATE_COMMAND: 62 errstr = "ERROR_CODE_LATE_COMMAND"; 63 break; 64 case ERROR_CODE_BROKEN_CHAIN: 65 errstr = "ERROR_CODE_BROKEN_CHAIN (Expected another stream command)"; 66 break; 67 case ERROR_CODE_OVERFLOW: 68 errstr = "ERROR_CODE_OVERFLOW "; 69 errstr += (this->out_of_sequence ? "(Out of sequence error)" : "(Overflow)"); 70 break; 71 case ERROR_CODE_ALIGNMENT: 72 errstr = "ERROR_CODE_ALIGNMENT (Multi-channel alignment failed)"; 73 break; 74 case ERROR_CODE_BAD_PACKET: 75 errstr = "ERROR_CODE_BAD_PACKET"; 76 break; 77 default: 78 errstr = 79 std::string(str(boost::format("Unknown error code: 0x%x") % error_code)); 80 } 81 82 return errstr; 83 } 84