aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc/rf_control/gain_profile.cpp
blob: 54ccb900634d12b374866c529dad6799df36bac9 (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
//
// Copyright 2020 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#include <uhd/exception.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/log.hpp>
#include <uhdlib/rfnoc/rf_control/gain_profile_iface.hpp>
#include <stddef.h>
#include <string>
#include <vector>

namespace uhd { namespace rfnoc { namespace rf_control {

const std::string default_gain_profile::DEFAULT_GAIN_PROFILE = "default";

std::vector<std::string> default_gain_profile::get_gain_profile_names(const size_t) const
{
    return {DEFAULT_GAIN_PROFILE};
}

void default_gain_profile::set_gain_profile(const std::string& profile, const size_t)
{
    if (profile != DEFAULT_GAIN_PROFILE) {
        throw uhd::value_error(
            std::string("set_tx_gain_profile(): Unknown gain profile: `") + profile
            + "'");
    }
}

std::string default_gain_profile::get_gain_profile(const size_t) const
{
    return DEFAULT_GAIN_PROFILE;
}

enumerated_gain_profile::enumerated_gain_profile(
    const std::vector<std::string>& possible_profiles,
    const std::string& default_profile,
    size_t num_channels)
    : _possible_profiles(possible_profiles), _gain_profile(num_channels, default_profile)
{
}

void enumerated_gain_profile::set_gain_profile(
    const std::string& profile, const size_t chan)
{
    if (!uhd::has(_possible_profiles, profile)) {
        const std::string err_msg = ("Invalid gain profile provided: " + profile);
        UHD_LOG_ERROR("gain_profile", err_msg);
        throw uhd::key_error(err_msg);
    }
    _gain_profile.at(chan) = profile;
}

std::string enumerated_gain_profile::get_gain_profile(const size_t chan) const
{
    return _gain_profile.at(chan);
}

std::vector<std::string> enumerated_gain_profile::get_gain_profile_names(
    const size_t) const
{
    return _possible_profiles;
}

}}} // namespace uhd::rfnoc::rf_control