static int save_gains(struct rx_cal *cal, struct gain_mode *gain) { int status; status = bladerf_get_lna_gain(cal->dev, &gain->lna_gain); if (status != 0) { return status; } status = bladerf_get_rxvga1(cal->dev, &gain->rxvga1); if (status != 0) { return status; } status = bladerf_get_rxvga2(cal->dev, &gain->rxvga2); if (status != 0) { return status; } return status; }
static int init_device(struct repeater *repeater, struct repeater_config *config) { int status = 0; unsigned int actual_value; status = bladerf_open(&repeater->device, config->device_str); if (!repeater->device) { fprintf(stderr, "Failed to open %s: %s\r\n", config->device_str, bladerf_strerror(status)); return -1; } status = bladerf_is_fpga_configured(repeater->device); if (status < 0) { fprintf(stderr, "Failed to determine if FPGA is loaded: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else if (status == 0) { fprintf(stderr, "FPGA is not loaded. Aborting.\r\n"); status = BLADERF_ERR_NODEV; goto init_device_error; } status = bladerf_set_bandwidth(repeater->device, BLADERF_MODULE_TX, config->bandwidth, &actual_value); if (status < 0) { fprintf(stderr, "Failed to set TX bandwidth: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Actual TX bandwidth: %d Hz\r\n", actual_value); } status = bladerf_set_bandwidth(repeater->device, BLADERF_MODULE_RX, config->bandwidth, &actual_value); if (status < 0) { fprintf(stderr, "Failed to set RX bandwidth: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Actual RX bandwidth: %d Hz\r\n", actual_value); } status = bladerf_set_sample_rate(repeater->device, BLADERF_MODULE_TX, config->sample_rate, &actual_value); if (status < 0) { fprintf(stderr, "Failed to set TX sample rate: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Actual TX sample rate is %d Hz\r\n", actual_value); } status = bladerf_set_sample_rate(repeater->device, BLADERF_MODULE_RX, config->sample_rate, &actual_value); if (status < 0) { fprintf(stderr, "Failed to set RX sample rate: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Actual RX sample rate is %d Hz\r\n", actual_value); } status = bladerf_set_frequency(repeater->device, BLADERF_MODULE_TX, config->tx_freq); if (status < 0) { fprintf(stderr, "Failed to set TX frequency: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Set TX frequency to %d Hz\r\n", config->tx_freq); } status = bladerf_set_frequency(repeater->device, BLADERF_MODULE_RX, config->rx_freq); if (status < 0) { fprintf(stderr, "Failed to set RX frequency: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Set RX frequency to %d Hz\r\n", config->rx_freq); } status = bladerf_enable_module(repeater->device, BLADERF_MODULE_RX, true); if (status < 0) { fprintf(stderr, "Failed to enable RX module: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Enabled RX module\r\n"); } status = bladerf_enable_module(repeater->device, BLADERF_MODULE_TX, true); if (status < 0) { bladerf_enable_module(repeater->device, BLADERF_MODULE_RX, false); fprintf(stderr, "Failed to enable TX module: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("Enabled TX module\r\n"); } status = bladerf_get_txvga1(repeater->device, &repeater->gain_txvga1); if (status < 0) { fprintf(stderr, "Failed to get TXVGA1 gain: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("TXVGA1 gain is: %d\r\n", repeater->gain_txvga1); } status = bladerf_get_txvga2(repeater->device, &repeater->gain_txvga2); if (status < 0) { fprintf(stderr, "Failed to get TXVGA2 gain: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("TXVGA2 gain is: %d\r\n", repeater->gain_txvga2); } status = bladerf_get_rxvga1(repeater->device, &repeater->gain_rxvga1); if (status < 0) { fprintf(stderr, "Failed to get RXVGA1 gain: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("RXVGA1 gain is: %d\r\n", repeater->gain_rxvga1); } status = bladerf_get_rxvga2(repeater->device, &repeater->gain_rxvga2); if (status < 0) { fprintf(stderr, "Failed to get RXVGA2 gain: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("RXVGA2 gain is: %d\r\n", repeater->gain_rxvga2); } status = bladerf_get_lna_gain(repeater->device, &repeater->gain_lna); if (status < 0) { fprintf(stderr, "Failed to get LNA gain: %s\r\n", bladerf_strerror(status)); goto init_device_error; } else { printf("LNA gain is: %d\r\n", repeater->gain_lna); } return status; init_device_error: bladerf_close(repeater->device); repeater->device = NULL; return status; }