aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/common/apply_corrections.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-03-02 15:25:13 -0800
committeratrnati <54334261+atrnati@users.noreply.github.com>2020-03-03 08:51:32 -0600
commit876d4150aa3da531ddd687b48afada6e43f79146 (patch)
treefd72a71419f4cd800d4e500cfcaded4dfc8dc367 /host/lib/usrp/common/apply_corrections.cpp
parent1393553d623bdf4ba40d5435c9719b6ce990d9ac (diff)
downloaduhd-876d4150aa3da531ddd687b48afada6e43f79146.tar.gz
uhd-876d4150aa3da531ddd687b48afada6e43f79146.tar.bz2
uhd-876d4150aa3da531ddd687b48afada6e43f79146.zip
uhd: Apply clang-format against all .cpp and .hpp files in host/
Note: template_lvbitx.{cpp,hpp} need to be excluded from the list of files that clang-format gets applied against.
Diffstat (limited to 'host/lib/usrp/common/apply_corrections.cpp')
-rw-r--r--host/lib/usrp/common/apply_corrections.cpp139
1 files changed, 76 insertions, 63 deletions
diff --git a/host/lib/usrp/common/apply_corrections.cpp b/host/lib/usrp/common/apply_corrections.cpp
index b57ace71b..b75ab7d95 100644
--- a/host/lib/usrp/common/apply_corrections.cpp
+++ b/host/lib/usrp/common/apply_corrections.cpp
@@ -5,16 +5,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
-#include <uhdlib/usrp/common/apply_corrections.hpp>
+#include <uhd/types/dict.hpp>
#include <uhd/usrp/dboard_eeprom.hpp>
-#include <uhd/utils/paths.hpp>
-#include <uhd/utils/log.hpp>
#include <uhd/utils/csv.hpp>
-#include <uhd/types/dict.hpp>
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/paths.hpp>
+#include <uhdlib/usrp/common/apply_corrections.hpp>
#include <boost/filesystem.hpp>
#include <boost/thread/mutex.hpp>
-#include <cstdio>
#include <complex>
+#include <cstdio>
#include <fstream>
namespace fs = boost::filesystem;
@@ -24,24 +24,27 @@ boost::mutex corrections_mutex;
/***********************************************************************
* Helper routines
**********************************************************************/
-static double linear_interp(double x, double x0, double y0, double x1, double y1){
- return y0 + (x - x0)*(y1 - y0)/(x1 - x0);
+static double linear_interp(double x, double x0, double y0, double x1, double y1)
+{
+ return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
/***********************************************************************
* FE apply corrections implementation
**********************************************************************/
-struct fe_cal_t{
+struct fe_cal_t
+{
double lo_freq;
double iq_corr_real;
double iq_corr_imag;
};
-static bool fe_cal_comp(fe_cal_t a, fe_cal_t b){
+static bool fe_cal_comp(fe_cal_t a, fe_cal_t b)
+{
return (a.lo_freq < b.lo_freq);
}
-static uhd::dict<std::string, std::vector<fe_cal_t> > fe_cal_cache;
+static uhd::dict<std::string, std::vector<fe_cal_t>> fe_cal_cache;
static bool is_same_freq(const double f1, const double f2)
{
@@ -50,36 +53,46 @@ static bool is_same_freq(const double f1, const double f2)
}
static std::complex<double> get_fe_correction(
- const std::string &key, const double lo_freq
-){
- const std::vector<fe_cal_t> &datas = fe_cal_cache[key];
- if (datas.empty()) throw uhd::runtime_error("empty calibration table " + key);
+ const std::string& key, const double lo_freq)
+{
+ const std::vector<fe_cal_t>& datas = fe_cal_cache[key];
+ if (datas.empty())
+ throw uhd::runtime_error("empty calibration table " + key);
- //search for lo freq
+ // search for lo freq
size_t lo_index = 0;
- size_t hi_index = datas.size()-1;
- for (size_t i = 0; i < datas.size(); i++){
- if (is_same_freq(datas[i].lo_freq, lo_freq))
- {
+ size_t hi_index = datas.size() - 1;
+ for (size_t i = 0; i < datas.size(); i++) {
+ if (is_same_freq(datas[i].lo_freq, lo_freq)) {
hi_index = i;
lo_index = i;
break;
}
- if (datas[i].lo_freq > lo_freq){
+ if (datas[i].lo_freq > lo_freq) {
hi_index = i;
break;
}
lo_index = i;
}
- if (lo_index == 0) return std::complex<double>(datas[lo_index].iq_corr_real, datas[lo_index].iq_corr_imag);
- if (hi_index == lo_index) return std::complex<double>(datas[hi_index].iq_corr_real, datas[hi_index].iq_corr_imag);
-
- //interpolation time
- return std::complex<double>(
- linear_interp(lo_freq, datas[lo_index].lo_freq, datas[lo_index].iq_corr_real, datas[hi_index].lo_freq, datas[hi_index].iq_corr_real),
- linear_interp(lo_freq, datas[lo_index].lo_freq, datas[lo_index].iq_corr_imag, datas[hi_index].lo_freq, datas[hi_index].iq_corr_imag)
- );
+ if (lo_index == 0)
+ return std::complex<double>(
+ datas[lo_index].iq_corr_real, datas[lo_index].iq_corr_imag);
+ if (hi_index == lo_index)
+ return std::complex<double>(
+ datas[hi_index].iq_corr_real, datas[hi_index].iq_corr_imag);
+
+ // interpolation time
+ return std::complex<double>(linear_interp(lo_freq,
+ datas[lo_index].lo_freq,
+ datas[lo_index].iq_corr_real,
+ datas[hi_index].lo_freq,
+ datas[hi_index].iq_corr_real),
+ linear_interp(lo_freq,
+ datas[lo_index].lo_freq,
+ datas[lo_index].iq_corr_imag,
+ datas[hi_index].lo_freq,
+ datas[hi_index].iq_corr_imag));
}
static void apply_fe_corrections(uhd::property_tree::sptr sub_tree,
@@ -88,43 +101,45 @@ static void apply_fe_corrections(uhd::property_tree::sptr sub_tree,
const std::string& file_prefix,
const double lo_freq)
{
- //make the calibration file path
+ // make the calibration file path
const fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd" / "cal"
/ (file_prefix + db_serial + ".csv");
- if (not fs::exists(cal_data_path)) return;
+ if (not fs::exists(cal_data_path))
+ return;
- //parse csv file or get from cache
- if (not fe_cal_cache.has_key(cal_data_path.string())){
+ // parse csv file or get from cache
+ if (not fe_cal_cache.has_key(cal_data_path.string())) {
std::ifstream cal_data(cal_data_path.string().c_str());
const uhd::csv::rows_type rows = uhd::csv::to_rows(cal_data);
- bool read_data = false, skip_next = false;;
+ bool read_data = false, skip_next = false;
+ ;
std::vector<fe_cal_t> datas;
- for(const uhd::csv::row_type &row: rows){
- if (not read_data and not row.empty() and row[0] == "DATA STARTS HERE"){
+ for (const uhd::csv::row_type& row : rows) {
+ if (not read_data and not row.empty() and row[0] == "DATA STARTS HERE") {
read_data = true;
skip_next = true;
continue;
}
- if (not read_data) continue;
- if (skip_next){
+ if (not read_data)
+ continue;
+ if (skip_next) {
skip_next = false;
continue;
}
fe_cal_t data;
- std::sscanf(row[0].c_str(), "%lf" , &data.lo_freq);
- std::sscanf(row[1].c_str(), "%lf" , &data.iq_corr_real);
- std::sscanf(row[2].c_str(), "%lf" , &data.iq_corr_imag);
+ std::sscanf(row[0].c_str(), "%lf", &data.lo_freq);
+ std::sscanf(row[1].c_str(), "%lf", &data.iq_corr_real);
+ std::sscanf(row[2].c_str(), "%lf", &data.iq_corr_imag);
datas.push_back(data);
}
std::sort(datas.begin(), datas.end(), fe_cal_comp);
fe_cal_cache[cal_data_path.string()] = datas;
UHD_LOGGER_INFO("CAL") << "Calibration data loaded: " << cal_data_path.string();
-
}
- sub_tree->access<std::complex<double> >(fe_path)
- .set(get_fe_correction(cal_data_path.string(), lo_freq));
+ sub_tree->access<std::complex<double>>(fe_path).set(
+ get_fe_correction(cal_data_path.string(), lo_freq));
}
/***********************************************************************
@@ -139,7 +154,7 @@ void uhd::usrp::apply_tx_fe_corrections( // overloading to work according to rfn
)
{
boost::mutex::scoped_lock l(corrections_mutex);
- try{
+ try {
apply_fe_corrections(sub_tree,
db_serial,
tx_fe_corr_path + "/iq_balance/value",
@@ -150,17 +165,17 @@ void uhd::usrp::apply_tx_fe_corrections( // overloading to work according to rfn
tx_fe_corr_path + "/dc_offset/value",
"tx_dc_cal_v0.2_",
lo_freq);
- }
- catch(const std::exception &e){
+ } catch (const std::exception& e) {
UHD_LOGGER_ERROR("CAL") << "Failure in apply_tx_fe_corrections: " << e.what();
}
}
void uhd::usrp::apply_tx_fe_corrections(
- property_tree::sptr sub_tree, //starts at mboards/x
- const std::string &slot, //name of dboard slot
- const double lo_freq //actual lo freq
-){
+ property_tree::sptr sub_tree, // starts at mboards/x
+ const std::string& slot, // name of dboard slot
+ const double lo_freq // actual lo freq
+)
+{
boost::mutex::scoped_lock l(corrections_mutex);
// extract eeprom serial
@@ -168,7 +183,7 @@ void uhd::usrp::apply_tx_fe_corrections(
const std::string db_serial =
sub_tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get().serial;
- try{
+ try {
apply_fe_corrections(sub_tree,
db_serial,
"tx_frontends/" + slot + "/iq_balance/value",
@@ -179,8 +194,7 @@ void uhd::usrp::apply_tx_fe_corrections(
"tx_frontends/" + slot + "/dc_offset/value",
"tx_dc_cal_v0.2_",
lo_freq);
- }
- catch(const std::exception &e){
+ } catch (const std::exception& e) {
UHD_LOGGER_ERROR("CAL") << "Failure in apply_tx_fe_corrections: " << e.what();
}
}
@@ -194,35 +208,34 @@ void uhd::usrp::apply_rx_fe_corrections( // overloading to work according to rfn
)
{
boost::mutex::scoped_lock l(corrections_mutex);
- try{
+ try {
apply_fe_corrections(sub_tree,
db_serial,
rx_fe_corr_path + "/iq_balance/value",
"rx_iq_cal_v0.2_",
lo_freq);
- }
- catch(const std::exception &e){
+ } catch (const std::exception& e) {
UHD_LOGGER_ERROR("CAL") << "Failure in apply_tx_fe_corrections: " << e.what();
}
}
void uhd::usrp::apply_rx_fe_corrections(
- property_tree::sptr sub_tree, //starts at mboards/x
- const std::string &slot, //name of dboard slot
- const double lo_freq //actual lo freq
-){
+ property_tree::sptr sub_tree, // starts at mboards/x
+ const std::string& slot, // name of dboard slot
+ const double lo_freq // actual lo freq
+)
+{
boost::mutex::scoped_lock l(corrections_mutex);
const uhd::fs_path db_path = "dboards/" + slot + "/rx_eeprom";
const std::string db_serial =
sub_tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get().serial;
- try{
+ try {
apply_fe_corrections(sub_tree,
db_serial,
"rx_frontends/" + slot + "/iq_balance/value",
"rx_iq_cal_v0.2_",
lo_freq);
- }
- catch(const std::exception &e){
+ } catch (const std::exception& e) {
UHD_LOGGER_ERROR("CAL") << "Failure in apply_rx_fe_corrections: " << e.what();
}
}