From 42180db24dec88c1b0ebaf76d657e34a216635c4 Mon Sep 17 00:00:00 2001 From: Andrei Popa Date: Thu, 25 Jan 2024 15:17:45 +0200 Subject: [PATCH] plugins: adrv9002: default to 0 value if attributes cannot be read in Live Device preset - some attributes cannot be read if channel is disabled Signed-off-by: Andrei Popa --- plugins/adrv9002.c | 68 ++++++++-------------------------------------- 1 file changed, 12 insertions(+), 56 deletions(-) diff --git a/plugins/adrv9002.c b/plugins/adrv9002.c index 2b024c01..83a1f660 100644 --- a/plugins/adrv9002.c +++ b/plugins/adrv9002.c @@ -1388,21 +1388,11 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin // tx.enabled ret = iio_channel_attr_read(tx, "en", buf, sizeof(buf)); - if(ret < 0) { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en", - ret); - goto iio_error; - } - tx_config[chann].enabled = atoi(buf); + tx_config[chann].enabled = ret < 0 ? 0 : 1; // tx.sample_rate_hz ret = iio_channel_attr_read(tx, "sampling_frequency", buf, sizeof(buf)); - if(ret < 0) { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, - "sampling_frequency", ret); - goto iio_error; - } - tx_config[chann].sample_rate_hz = atoi(buf); + tx_config[chann].sample_rate_hz = ret < 0 ? 0 : atoi(buf); // tx.frequency_offset_correction_enable tx_config[chann].frequency_offset_correction_enable = @@ -1414,12 +1404,7 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin // tx.channel_bandwidth_hz ret = iio_channel_attr_read(tx, "rf_bandwidth", buf, sizeof(buf)); - if(ret < 0) { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, - "rf_bandwidth", ret); - goto iio_error; - } - tx_config[chann].channel_bandwidth_hz = atoi(buf); + tx_config[chann].channel_bandwidth_hz = ret < 0 ? 0 : atoi(buf); // tx.elb_type tx_config[chann].elb_type = default_cfg.radio_cfg.tx_config[chann].elb_type; // TODO @@ -1441,21 +1426,11 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin // rx.enabled ret = iio_channel_attr_read(rx, "en", buf, sizeof(buf)); - if(ret < 0) { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en", - ret); - goto iio_error; - } - rx_config[chann].enabled = atoi(buf); + rx_config[chann].enabled = ret < 0 ? 0 : 1; // rx.sample_rate_hz ret = iio_channel_attr_read(rx, "sampling_frequency", buf, sizeof(buf)); - if(ret < 0) { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, - "sampling_frequency", ret); - goto iio_error; - } - rx_config[chann].sample_rate_hz = atoi(buf); + rx_config[chann].sample_rate_hz = ret < 0 ? 0 : atoi(buf); // rx.frequency_offset_correction_enable rx_config[chann].frequency_offset_correction_enable = @@ -1467,22 +1442,12 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin // rx.channel_bandwidth_hz ret = iio_channel_attr_read(rx, "rf_bandwidth", buf, sizeof(buf)); - if(ret < 0) { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, - "rf_bandwidth", ret); - goto iio_error; - } - rx_config[chann].channel_bandwidth_hz = atoi(buf); + rx_config[chann].channel_bandwidth_hz = ret < 0 ? 0 : atoi(buf); // rx.adc_high_performance_mode ret = iio_device_debug_attr_read(priv->adrv9002, chann == 0 ? "rx0_adc_type" : "rx1_adc_type", buf, sizeof(buf)); - if(ret < 0) { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, - chann == 0 ? "rx0_adc_type" : "rx1_adc_type", ret); - goto iio_error; - } - rx_config[chann].adc_high_performance_mode = strstr(buf, "HP") != NULL; + rx_config[chann].adc_high_performance_mode = ret < 0 ? 0 : strstr(buf, "HP") != NULL; // rx.analog_filter_biquad rx_config[chann].analog_filter_biquad = @@ -1497,28 +1462,17 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin // rx.nco_frequency_hz ret = iio_channel_attr_read(rx, "nco_frequency", buf, sizeof(buf)); - if(ret < 0) { - if(ret == -ENOTSUPP) { - rx_config[chann].nco_frequency_hz = 0; - } else { - sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, - "nco_frequency", ret); - goto iio_error; - } - } else { - rx_config[chann].nco_frequency_hz = atoi(buf); - } + rx_config[chann].nco_frequency_hz = ret < 0 ? 0 : atoi(buf); // rx.rf_port rx_config[chann].rf_port = default_cfg.radio_cfg.rx_config[chann].rf_port; // TODO - radio_config.rx_config[chann] = rx_config[chann]; // tx.orx_enabled ret = iio_channel_attr_read(rx, "orx_en", buf, sizeof(buf)); if(ret < 0) { if(ret == -ENODEV) { - tx_config[chann].orx_enabled = + radio_config.tx_config[chann].orx_enabled = default_cfg.radio_cfg.tx_config[chann].orx_enabled; // Temporary fix } else { sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, @@ -1526,8 +1480,10 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin goto iio_error; } } else { - tx_config[chann].orx_enabled = atoi(buf); + radio_config.tx_config[chann].orx_enabled = atoi(buf); } + + radio_config.rx_config[chann] = rx_config[chann]; } cfg->radio_cfg = radio_config;