Skip to content

Commit

Permalink
adrv9002 plugin: added more error messages for the live device preset
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Nov 20, 2023
1 parent 0521a15 commit 4f7ab26
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions plugins/adrv9002.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,11 +1189,21 @@ static void load_profile(GtkFileChooser *chooser, gpointer data)
gtk_file_chooser_set_filename(chooser, "(None)");
}

static void profile_gen_set_debug_info(gpointer data, char *string)
static void profile_gen_append_debug_info(gpointer data, char *string)
{
struct plugin_private *priv = data;
gchar *message = g_locale_to_utf8(string, -1, NULL, NULL, NULL);
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(priv->builder, "label_profile_debug")), message);
GtkLabel *info_label = GTK_LABEL(gtk_builder_get_object(priv->builder, "label_profile_debug"));
char message[BUFSIZ];

sprintf(message, "%s%s", gtk_label_get_text(info_label), g_locale_to_utf8(string, -1, NULL, NULL, NULL));
gtk_label_set_text(info_label, message);
}

static void profile_gen_set_debug_info(gpointer data, char *string)
{
struct plugin_private *priv = data;
gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(priv->builder, "label_profile_debug")),
g_locale_to_utf8(string, -1, NULL, NULL, NULL));
}

static void profile_gen_save_type_changed(GtkComboBoxText* self, struct plugin_private *priv)
Expand Down Expand Up @@ -1272,6 +1282,7 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
struct adrv9002_config default_cfg = lte_lvs_3072_MHz_10();
struct plugin_private *priv = data;
int ret_value = 0;
char message[BUFSIZ];

// radio_config
radio_config radio_config;
Expand All @@ -1280,15 +1291,14 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
char profile_config[512];
ret_value = iio_device_attr_read(priv->adrv9002, "profile_config", profile_config, sizeof(profile_config));
if (ret_value < 0) {
printf("\nFailed to get device attr read %s! error code: %d", "profile_config", ret_value);
sprintf(message, "\nFailed to get device attr read %s! error code: %d", "profile_config", ret_value);
goto iio_error;
}

// radio_config.ssi_lanes
char *ssi_interface = extract_value_between(profile_config, "SSI interface:", "");
if (ssi_interface == NULL) {
printf("\nFailed to get SSI interface!");
ret_value = -1;
sprintf(message, "\nFailed to get SSI interface!");
goto iio_error;
} else if (strstr(ssi_interface, "CMOS/LVDS") != NULL) {
radio_config.ssi_lanes = 1;
Expand All @@ -1297,7 +1307,7 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
} else if (strstr(ssi_interface, "CMOS") != NULL) {
radio_config.ssi_lanes = 4;
} else {
printf("\nFailed to get SSI interface! got '%s' instead", ssi_interface);
sprintf(message, "\nFailed to get SSI interface! got '%s' instead", ssi_interface);
goto iio_error;
}

Expand All @@ -1315,15 +1325,14 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin

char *duplex_mode = extract_value_between(profile_config, "Duplex Mode:", "\n");
if (duplex_mode == NULL) {
printf("\nFailed to get Duplex Mode!");
ret_value = -1;
sprintf(message, "\nFailed to get Duplex Mode!");
goto iio_error;
} else if (strstr(duplex_mode, "FDD") != NULL) {
radio_config.fdd = true;
} else if (strstr(duplex_mode, "TDD") != NULL) {
radio_config.fdd = false;
} else {
printf("\nFailed to get Duplex Mode! got '%s' instead", duplex_mode);
sprintf(message, "\nFailed to get Duplex Mode! got '%s' instead", duplex_mode);
goto iio_error;
}

Expand All @@ -1336,23 +1345,22 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
sprintf(chann_str, "voltage%d", i);
struct iio_channel *tx = iio_device_find_channel(priv->adrv9002, chann_str, true);
if (tx == NULL) {
printf("\nFailed to find channel: %s!", chann_str);
ret_value = -1;
sprintf(message, "\nFailed to find channel: %s!", chann_str);
goto iio_error;
}

// tx.enabled
ret_value = iio_channel_attr_read(tx, "en", buf, sizeof(buf));
if (ret_value < 0) {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en", ret_value);
goto iio_error;
}
tx_config[i].enabled = atoi(buf);

// tx.sample_rate_hz
ret_value = iio_channel_attr_read(tx, "sampling_frequency", buf, sizeof(buf));
if (ret_value < 0) {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "sampling_frequency", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "sampling_frequency", ret_value);
goto iio_error;
}
tx_config[i].sample_rate_hz = atoi(buf);
Expand All @@ -1366,7 +1374,7 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
// tx.channel_bandwidth_hz
ret_value = iio_channel_attr_read(tx, "rf_bandwidth", buf, sizeof(buf));
if (ret_value < 0) {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "rf_bandwidth", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "rf_bandwidth", ret_value);
goto iio_error;
}
tx_config[i].channel_bandwidth_hz = atoi(buf);
Expand All @@ -1384,23 +1392,22 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
sprintf(chann_str, "voltage%d", i);
struct iio_channel *rx = iio_device_find_channel(priv->adrv9002, chann_str, false);
if (rx == NULL) {
printf("\nFailed to find channel %s!", chann_str);
ret_value = -1;
sprintf(message, "\nFailed to find channel %s!", chann_str);
goto iio_error;
}

// rx.enabled
ret_value = iio_channel_attr_read(rx, "en", buf, sizeof(buf));
if (ret_value < 0) {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en", ret_value);
goto iio_error;
}
rx_config[i].enabled = atoi(buf);

// rx.sample_rate_hz
ret_value = iio_channel_attr_read(rx, "sampling_frequency", buf, sizeof(buf));
if (ret_value < 0) {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "sampling_frequency", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "sampling_frequency", ret_value);
goto iio_error;
}
rx_config[i].sample_rate_hz = atoi(buf);
Expand All @@ -1414,15 +1421,15 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
// rx.channel_bandwidth_hz
ret_value = iio_channel_attr_read(rx, "rf_bandwidth", buf, sizeof(buf));
if (ret_value < 0) {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "rf_bandwidth", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "rf_bandwidth", ret_value);
goto iio_error;
}
rx_config[i].channel_bandwidth_hz = atoi(buf);

// rx.adc_high_performance_mode
ret_value = iio_device_debug_attr_read(priv->adrv9002, i == 0 ? "rx0_adc_type" : "rx1_adc_type", buf, sizeof(buf));
if (ret_value < 0) {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, i == 0 ? "rx0_adc_type" : "rx1_adc_type", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, i == 0 ? "rx0_adc_type" : "rx1_adc_type", ret_value);
goto iio_error;
}
rx_config[i].adc_high_performance_mode = strstr(buf, "HP") != NULL;
Expand All @@ -1442,7 +1449,7 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
if (ret_value == -ENOTSUPP) {
rx_config[i].nco_frequency_hz = 0;
} else {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "nco_frequency", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "nco_frequency", ret_value);
goto iio_error;
}
} else {
Expand All @@ -1460,7 +1467,7 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
if (ret_value == -ENODEV) {
tx_config[i].orx_enabled = default_cfg.radio_cfg.tx_config[i].orx_enabled; // Temporary fix
} else {
printf("\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "orx_en", ret_value);
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "orx_en", ret_value);
goto iio_error;
}
} else {
Expand All @@ -1476,17 +1483,15 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin
// clock_config.device_clock_frequency_khz
char *device_clock = extract_value_between(profile_config, "Device clk(Hz): ", "\n");
if (device_clock == NULL) {
printf("\nFailed to get Device clk!");
ret_value = -1;
sprintf(message, "\nFailed to get Device clk!");
goto iio_error;
}
clock_config.device_clock_frequency_khz = atoi(device_clock) / 1000; // convert Hz to kHz

// clock_config.device_clock_output_divider
char *device_divider = extract_value_between(profile_config, "ARM Power Saving Clk Divider: ", "\n");
if (device_divider == NULL) {
printf("\nFailed to get Saving Clk Divider!");
ret_value = -1;
sprintf(message, "\nFailed to get Saving Clk Divider!");
goto iio_error;
}
clock_config.device_clock_output_divider = atoi(device_divider);
Expand All @@ -1502,10 +1507,10 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin

cfg->clk_cfg = clock_config;

ret_value = 0;
return 0;
iio_error:
fflush(stdout);
return ret_value;
profile_gen_set_debug_info(data, message);
return ret_value == 0 ? -1 : ret_value;
}

static void populate_combo_box(GtkComboBoxText *combo_box, char **list, guint len, bool has_entry, char *entry_default)
Expand Down Expand Up @@ -1548,11 +1553,10 @@ static void set_all_cb_to_same_text(char *cb_name_list[], guint len, char *text

static int profile_gen_config_set_live_device(struct adrv9002_config *cfg, gpointer data, bool reset_preset)
{
int ret_value = 0;
struct plugin_private *priv = data;
int ret_value = profile_gen_config_get_from_device(cfg, data);

ret_value = profile_gen_config_get_from_device(cfg, data);

if (ret_value != 0) return ret_value;
if (!reset_preset) return 0;

char widget_str[256];
Expand All @@ -1575,7 +1579,7 @@ static int profile_gen_config_set_live_device(struct adrv9002_config *cfg, gpoin
sprintf(str_value, "CMOS");
break;
default:
profile_gen_set_debug_info(priv, "\nFailed to get ssi_lanes!");
profile_gen_append_debug_info(priv, "\nFailed to get ssi_lanes!");
sprintf(str_value, "failed to read");
break;
}
Expand Down Expand Up @@ -1645,7 +1649,7 @@ static int profile_gen_config_set_live_device(struct adrv9002_config *cfg, gpoin
// update duplex state
profile_gen_update_orx(GTK_COMBO_BOX(gtk_builder_get_object(priv->builder, "cb_radio_duplex")), priv);

return ret_value;
return 0;
}

static int get_index_of_string(char **list, guint len, char* string)
Expand Down Expand Up @@ -2255,8 +2259,8 @@ static int profile_gen_ui_refresh(GtkButton* self, struct plugin_private *priv)
{
struct adrv9002_config cfg = lte_lvs_3072_MHz_10();
priv->current_preset = -1;
if (profile_gen_config_init(&cfg, priv) < 0) {
profile_gen_set_debug_info(priv, "\nFailed to init adrv9002 config!");
if (profile_gen_config_init(&cfg, priv) != 0) {
profile_gen_append_debug_info(priv, "\nFailed to initialize adrv9002 config!");
return -1;
}
profile_gen_set_debug_info(priv, profile_gen_config_to_str(&cfg));
Expand Down

0 comments on commit 4f7ab26

Please sign in to comment.