static void apply_fe_corrections( uhd::property_tree::sptr sub_tree, const uhd::fs_path &db_path, const uhd::fs_path &fe_path, const std::string &file_prefix, const double lo_freq ){ //extract eeprom serial const uhd::usrp::dboard_eeprom_t db_eeprom = sub_tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get(); //make the calibration file path const fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd" / "cal" / (file_prefix + db_eeprom.serial + ".csv"); UHD_MSG(status) << "Looking for FE correction at: " << cal_data_path.c_str() << "... "; if (not fs::exists(cal_data_path)) { UHD_MSG(status) << "Not found" << std::endl; return; } UHD_MSG(status) << "Found, loading... "; //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;; std::vector<fe_cal_t> datas; BOOST_FOREACH(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){ 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); datas.push_back(data); } std::sort(datas.begin(), datas.end(), fe_cal_comp); fe_cal_cache[cal_data_path.string()] = datas; UHD_MSG(status) << "Loaded" << std::endl; } else {
/*********************************************************************** * Store data to file **********************************************************************/ static void store_results( shd::smini::multi_smini::sptr smini, const std::vector<result_t> &results, const std::string &XX, const std::string &xx, const std::string &what ){ //extract eeprom serial shd::property_tree::sptr tree = smini->get_device()->get_tree(); const shd::fs_path db_path = "/mboards/0/dboards/A/" + xx + "_eeprom"; const shd::smini::dboard_eeprom_t db_eeprom = tree->access<shd::smini::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(shd::get_app_path()) / ".shd"; 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 / str(boost::format("%s_%s_cal_v0.2_%s.csv") % xx % what % db_eeprom.serial); 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, correction_real, correction_imag, measured, delta\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].best << ", " << results[i].delta << "\n" ; } std::cout << "wrote cal data to " << cal_data_path << std::endl; }
/*********************************************************************** * Store data to file **********************************************************************/ static void store_results( const std::vector<result_t> &results, const std::string &XX, // "TX" or "RX" const std::string &xx, // "tx" or "rx" const std::string &what, // Type of test, e.g. "iq", const std::string &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 / str(boost::format("%s_%s_cal_v0.2_%s.csv") % xx % what % serial); 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") % 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, correction_real, correction_imag, measured, delta\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].best << ", " << results[i].delta << "\n" ; } std::cout << "wrote cal data to " << cal_data_path << std::endl; }