1 //
2 // Copyright 2016 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/usrp/fe_connection.hpp>
10 #include <uhd/utils/math.hpp>
11 #include <regex>
12
13 using namespace uhd::usrp;
14
fe_connection_t(sampling_t sampling_mode,bool iq_swapped,bool i_inverted,bool q_inverted,double if_freq)15 fe_connection_t::fe_connection_t(sampling_t sampling_mode,
16 bool iq_swapped,
17 bool i_inverted,
18 bool q_inverted,
19 double if_freq)
20 : _sampling_mode(sampling_mode)
21 , _iq_swapped(iq_swapped)
22 , _i_inverted(i_inverted)
23 , _q_inverted(q_inverted)
24 , _if_freq(if_freq)
25 {
26 }
27
fe_connection_t(const std::string & conn_str,double if_freq)28 fe_connection_t::fe_connection_t(const std::string& conn_str, double if_freq)
29 {
30 static const std::regex conn_regex("([IQ])(b?)(([IQ])(b?))?");
31 std::cmatch matches;
32 if (std::regex_match(conn_str.c_str(), matches, conn_regex)) {
33 if (matches[3].length() == 0) {
34 // Connection in {I, Q, Ib, Qb}
35 _sampling_mode = REAL;
36 _iq_swapped = (matches[1].str() == "Q");
37 _i_inverted = (matches[2].length() != 0);
38 _q_inverted = false; // IQ is swapped after inversion
39 } else {
40 // Connection in {I(b?)Q(b?), Q(b?)I(b?), I(b?)I(b?), Q(b?)Q(b?)}
41 _sampling_mode = (matches[1].str() == matches[4].str()) ? HETERODYNE
42 : QUADRATURE;
43 _iq_swapped = (matches[1].str() == "Q");
44 size_t i_idx = _iq_swapped ? 5 : 2, q_idx = _iq_swapped ? 2 : 5;
45 _i_inverted = (matches[i_idx].length() != 0);
46 _q_inverted = (matches[q_idx].length() != 0);
47
48 if (_sampling_mode == HETERODYNE and _i_inverted != _q_inverted) {
49 throw uhd::value_error("Invalid connection string: " + conn_str);
50 }
51 }
52 _if_freq = if_freq;
53 } else {
54 throw uhd::value_error("Invalid connection string: " + conn_str);
55 }
56 }
57
operator ==(const fe_connection_t & lhs,const fe_connection_t & rhs)58 bool uhd::usrp::operator==(const fe_connection_t& lhs, const fe_connection_t& rhs)
59 {
60 return ((lhs.get_sampling_mode() == rhs.get_sampling_mode())
61 and (lhs.is_iq_swapped() == rhs.is_iq_swapped())
62 and (lhs.is_i_inverted() == rhs.is_i_inverted())
63 and (lhs.is_q_inverted() == rhs.is_q_inverted())
64 and uhd::math::frequencies_are_equal(lhs.get_if_freq(), rhs.get_if_freq()));
65 }
66