diff options
author | Josh Blum <josh@joshknows.com> | 2011-11-11 18:41:05 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-11-11 18:41:05 -0800 |
commit | e108294eed585aa8602631fe90fea4cf7b5e23c2 (patch) | |
tree | 230de76615c5a821c7525543947463092a2a3d63 | |
parent | b23126d3a0fca7d56a933e7f2f0011a9d625b006 (diff) | |
download | uhd-e108294eed585aa8602631fe90fea4cf7b5e23c2.tar.gz uhd-e108294eed585aa8602631fe90fea4cf7b5e23c2.tar.bz2 uhd-e108294eed585aa8602631fe90fea4cf7b5e23c2.zip |
uhd: share more common code in cal utils
-rw-r--r-- | host/utils/usrp_cal_utils.hpp | 54 | ||||
-rw-r--r-- | host/utils/usrp_gen_rx_fe_cal_table.cpp | 48 | ||||
-rw-r--r-- | host/utils/usrp_gen_tx_fe_cal_table.cpp | 48 |
3 files changed, 56 insertions, 94 deletions
diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp index 3e2aa6ae0..3cfe2b2ed 100644 --- a/host/utils/usrp_cal_utils.hpp +++ b/host/utils/usrp_cal_utils.hpp @@ -15,11 +15,19 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include <uhd/utils/paths.hpp> +#include <uhd/property_tree.hpp> +#include <uhd/usrp/multi_usrp.hpp> +#include <uhd/usrp/dboard_eeprom.hpp> +#include <boost/filesystem.hpp> +#include <iostream> #include <vector> #include <complex> #include <cmath> #include <fstream> +namespace fs = boost::filesystem; + struct result_t{double freq, real_corr, imag_corr, sup;}; /*********************************************************************** @@ -83,3 +91,49 @@ static inline void write_samples_to_file( outfile.write((const char*)&samples.front(), samples.size()*sizeof(std::complex<float>)); outfile.close(); } + +/*********************************************************************** + * Store data to file + **********************************************************************/ +static void store_results( + uhd::usrp::multi_usrp::sptr usrp, + const std::vector<result_t> &results, + const std::string &XX, + const std::string &xx +){ + //extract eeprom serial + uhd::property_tree::sptr tree = usrp->get_device()->get_tree(); + const uhd::fs_path db_path = "/mboards/0/dboards/A/" + xx + "_eeprom"; + const uhd::usrp::dboard_eeprom_t db_eeprom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get(); + if (db_eeprom.serial.empty()) throw std::runtime_error(XX + " dboard has empty serial!"); + + //make the calibration file path + fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd"; + fs::create_directory(cal_data_path); + cal_data_path = cal_data_path / "cal"; + fs::create_directory(cal_data_path); + cal_data_path = cal_data_path / (xx + "_fe_cal_v0.1_" + db_eeprom.serial + ".csv"); + if (fs::exists(cal_data_path)){ + fs::rename(cal_data_path, cal_data_path.string() + str(boost::format(".%d") % time(NULL))); + } + + //fill the calibration file + std::ofstream cal_data(cal_data_path.string().c_str()); + cal_data << boost::format("name, %s Frontend Calibration\n") % XX; + cal_data << boost::format("serial, %s\n") % db_eeprom.serial; + cal_data << boost::format("timestamp, %d\n") % time(NULL); + cal_data << boost::format("version, 0, 1\n"); + cal_data << boost::format("DATA STARTS HERE\n"); + cal_data << "lo_frequency, iq_correction_real, iq_correction_imag, measured_suppression\n"; + + for (size_t i = 0; i < results.size(); i++){ + cal_data + << results[i].freq << ", " + << results[i].real_corr << ", " + << results[i].imag_corr << ", " + << results[i].sup << "\n" + ; + } + + std::cout << "wrote cal data to " << cal_data_path << std::endl; +} diff --git a/host/utils/usrp_gen_rx_fe_cal_table.cpp b/host/utils/usrp_gen_rx_fe_cal_table.cpp index 4d5d4168e..a365c9be7 100644 --- a/host/utils/usrp_gen_rx_fe_cal_table.cpp +++ b/host/utils/usrp_gen_rx_fe_cal_table.cpp @@ -20,22 +20,17 @@ #include <uhd/utils/safe_main.hpp> #include <uhd/utils/paths.hpp> #include <uhd/utils/algorithm.hpp> -#include <uhd/property_tree.hpp> #include <uhd/usrp/multi_usrp.hpp> -#include <uhd/usrp/dboard_eeprom.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> #include <boost/thread/thread.hpp> -#include <boost/filesystem.hpp> #include <boost/math/special_functions/round.hpp> #include <iostream> -#include <fstream> #include <complex> #include <cmath> #include <ctime> namespace po = boost::program_options; -namespace fs = boost::filesystem; /*********************************************************************** * Transmit thread @@ -116,47 +111,6 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer:: } /*********************************************************************** - * Store data to file - **********************************************************************/ -static void store_results(uhd::usrp::multi_usrp::sptr usrp, const std::vector<result_t> &results){ - //extract eeprom serial - uhd::property_tree::sptr tree = usrp->get_device()->get_tree(); - const uhd::fs_path db_path = "/mboards/0/dboards/A/rx_eeprom"; - const uhd::usrp::dboard_eeprom_t db_eeprom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get(); - if (db_eeprom.serial.empty()) throw std::runtime_error("RX dboard has empty serial!"); - - //make the calibration file path - fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd"; - fs::create_directory(cal_data_path); - cal_data_path = cal_data_path / "cal"; - fs::create_directory(cal_data_path); - cal_data_path = cal_data_path / ("rx_fe_cal_v0.1_" + db_eeprom.serial + ".csv"); - if (fs::exists(cal_data_path)){ - fs::rename(cal_data_path, cal_data_path.string() + str(boost::format(".%d") % time(NULL))); - } - - //fill the calibration file - std::ofstream cal_data(cal_data_path.string().c_str()); - cal_data << boost::format("name, RX Frontend Calibration\n"); - cal_data << boost::format("serial, %s\n") % db_eeprom.serial; - cal_data << boost::format("timestamp, %d\n") % time(NULL); - cal_data << boost::format("version, 0, 1\n"); - cal_data << boost::format("DATA STARTS HERE\n"); - cal_data << "rx_lo_frequency, rx_iq_correction_real, rx_iq_correction_imag, measured_suppression\n"; - - for (size_t i = 0; i < results.size(); i++){ - cal_data - << results[i].freq << ", " - << results[i].real_corr << ", " - << results[i].imag_corr << ", " - << results[i].sup << "\n" - ; - } - - std::cout << "wrote cal data to " << cal_data_path << std::endl; -} - -/*********************************************************************** * Main **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ @@ -304,7 +258,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ threads.interrupt_all(); threads.join_all(); - store_results(usrp, results); + store_results(usrp, results, "RX", "rx"); return 0; } diff --git a/host/utils/usrp_gen_tx_fe_cal_table.cpp b/host/utils/usrp_gen_tx_fe_cal_table.cpp index 1e4a9d11f..bf19e4a37 100644 --- a/host/utils/usrp_gen_tx_fe_cal_table.cpp +++ b/host/utils/usrp_gen_tx_fe_cal_table.cpp @@ -20,21 +20,16 @@ #include <uhd/utils/safe_main.hpp> #include <uhd/utils/paths.hpp> #include <uhd/utils/algorithm.hpp> -#include <uhd/property_tree.hpp> #include <uhd/usrp/multi_usrp.hpp> -#include <uhd/usrp/dboard_eeprom.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> #include <boost/thread/thread.hpp> -#include <boost/filesystem.hpp> #include <boost/math/special_functions/round.hpp> #include <iostream> -#include <fstream> #include <complex> #include <ctime> namespace po = boost::program_options; -namespace fs = boost::filesystem; /*********************************************************************** * Transmit thread @@ -117,47 +112,6 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer:: } /*********************************************************************** - * Store data to file - **********************************************************************/ -static void store_results(uhd::usrp::multi_usrp::sptr usrp, const std::vector<result_t> &results){ - //extract eeprom serial - uhd::property_tree::sptr tree = usrp->get_device()->get_tree(); - const uhd::fs_path db_path = "/mboards/0/dboards/A/tx_eeprom"; - const uhd::usrp::dboard_eeprom_t db_eeprom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get(); - if (db_eeprom.serial.empty()) throw std::runtime_error("TX dboard has empty serial!"); - - //make the calibration file path - fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd"; - fs::create_directory(cal_data_path); - cal_data_path = cal_data_path / "cal"; - fs::create_directory(cal_data_path); - cal_data_path = cal_data_path / ("tx_fe_cal_v0.1_" + db_eeprom.serial + ".csv"); - if (fs::exists(cal_data_path)){ - fs::rename(cal_data_path, cal_data_path.string() + str(boost::format(".%d") % time(NULL))); - } - - //fill the calibration file - std::ofstream cal_data(cal_data_path.string().c_str()); - cal_data << boost::format("name, TX Frontend Calibration\n"); - cal_data << boost::format("serial, %s\n") % db_eeprom.serial; - cal_data << boost::format("timestamp, %d\n") % time(NULL); - cal_data << boost::format("version, 0, 1\n"); - cal_data << boost::format("DATA STARTS HERE\n"); - cal_data << "tx_lo_frequency, tx_iq_correction_real, tx_iq_correction_imag, measured_suppression\n"; - - for (size_t i = 0; i < results.size(); i++){ - cal_data - << results[i].freq << ", " - << results[i].real_corr << ", " - << results[i].imag_corr << ", " - << results[i].sup << "\n" - ; - } - - std::cout << "wrote cal data to " << cal_data_path << std::endl; -} - -/*********************************************************************** * Main **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ @@ -306,7 +260,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ threads.interrupt_all(); threads.join_all(); - store_results(usrp, results); + store_results(usrp, results, "TX", "tx"); return 0; } |