libbladeRF: gain_calibration: store gain cal file within table

This commit is contained in:
Ryan Thompson 2024-01-03 18:40:14 -06:00
commit 8031b84e59
3 changed files with 17 additions and 0 deletions

View file

@ -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,

View file

@ -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++) {

View file

@ -23,6 +23,7 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#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)