aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/types/metadata.cpp
blob: fec2ac5643507e559ec1d0ffc56a584e2e299d6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
}