From 8031b84e5942c5d91bc5d35df36608e472bfb52f Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 3 Jan 2024 18:40:14 -0600 Subject: [PATCH] libbladeRF: gain_calibration: store gain cal file within table --- host/libraries/libbladeRF/include/libbladeRF.h | 2 ++ host/libraries/libbladeRF/src/bladerf.c | 1 + host/libraries/libbladeRF/src/device_calibration.c | 14 ++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index 8c33c075..a4e8049d 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -4201,6 +4201,8 @@ struct bladerf_gain_cal_tbl { bladerf_frequency stop_freq; /**< Stop frequency (Hz) */ struct bladerf_gain_cal_entry *entries; /**< Sorted calibration entries */ bladerf_gain gain_target; /**< Compensated gain */ + size_t file_path_len; /**< Length of the file path string. */ + char *file_path; /**< Path to the file from which the table was loaded. */ enum gain_cal_state { BLADERF_GAIN_CAL_UNINITIALIZED, BLADERF_GAIN_CAL_LOADED, diff --git a/host/libraries/libbladeRF/src/bladerf.c b/host/libraries/libbladeRF/src/bladerf.c index cff85734..54834b3b 100644 --- a/host/libraries/libbladeRF/src/bladerf.c +++ b/host/libraries/libbladeRF/src/bladerf.c @@ -2290,6 +2290,7 @@ int bladerf_print_gain_calibration(struct bladerf *dev, bladerf_channel ch, bool printf(" Number of Entries: %u\n", gain_tbls[ch].n_entries); printf(" Start Frequency: %" PRIu64 " Hz\n", gain_tbls[ch].start_freq); printf(" Stop Frequency: %" PRIu64 " Hz\n", gain_tbls[ch].stop_freq); + printf(" File Path: %s\n", gain_tbls[ch].file_path); if (with_entries) { for (size_t i = 0; i < gain_tbls[ch].n_entries; i++) { diff --git a/host/libraries/libbladeRF/src/device_calibration.c b/host/libraries/libbladeRF/src/device_calibration.c index a430d9fd..f23cd774 100644 --- a/host/libraries/libbladeRF/src/device_calibration.c +++ b/host/libraries/libbladeRF/src/device_calibration.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "libbladeRF.h" #include "board/board.h" #include "helpers/version.h" @@ -195,6 +196,7 @@ static int gain_cal_tbl_init(struct bladerf_gain_cal_tbl *tbl, uint32_t num_entr tbl->n_entries = num_entries; tbl->start_freq = 0; tbl->stop_freq = 0; + tbl->file_path_len = PATH_MAX; tbl->entries = malloc(num_entries * sizeof(struct bladerf_gain_cal_entry)); if (tbl->entries == NULL) { @@ -202,6 +204,12 @@ static int gain_cal_tbl_init(struct bladerf_gain_cal_tbl *tbl, uint32_t num_entr return BLADERF_ERR_MEM; } + tbl->file_path = malloc(tbl->file_path_len + 1); + if (tbl->file_path == NULL) { + log_error("failed to allocate memory for calibration table file path\n"); + return BLADERF_ERR_MEM; + } + tbl->state = BLADERF_GAIN_CAL_LOADED; return 0; } @@ -321,11 +329,17 @@ int load_gain_calibration(struct bladerf *dev, bladerf_channel ch, const char *b gain_tbls[ch].state = BLADERF_GAIN_CAL_LOADED; gain_tbls[ch].enabled = true; gain_tbls[ch].gain_target = current_gain; + strncpy(gain_tbls[ch].file_path, binary_path, gain_tbls[ch].file_path_len); free(dev->gain_tbls[ch].entries); + free(dev->gain_tbls[ch].file_path); dev->gain_tbls[ch] = gain_tbls[ch]; error: + if (status != 0) { + log_error("binary_path: %s\n", binary_path); + } + if (binaryFile) fclose(binaryFile); if (image)