Skip to content

Commit

Permalink
plugins: adrv9002: added api validation to profile generator
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Oct 20, 2023
1 parent c92bae1 commit 3449dbd
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion plugins/adrv9002.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,12 +2088,73 @@ static void profile_gen_save_dialog_response(GtkDialog *dialog, gint response_id

// 0 if stream image
// 1 if profile
bool file_type = gtk_combo_box_get_active_id(GTK_COMBO_BOX(gtk_builder_get_object(priv->builder, "cb_save_type")));
bool file_type = atoi(gtk_combo_box_get_active_id(GTK_COMBO_BOX(gtk_builder_get_object(priv->builder, "cb_save_type"))));
profile_gen_save_to_file(filename, &cfg, data, file_type);

gtk_widget_hide(GTK_WIDGET(chooser));
}

static char *profile_gen_cli_get_api()
{
// run profile gen cli command
FILE *file;
char out[BUFSIZ], command[BUFSIZ];

sprintf(command, "%s --version", profile_gen_cli_get_cmd());

// open the command for reading
file = popen(command, "r");
if (file == NULL) {
return NULL;
}

// read the output
fflush(file);
int ret = fread(out, sizeof(char), sizeof(out), file);
fclose(file);
if (ret == 0) {
return NULL;
}

// command output may contain characters after the API version
char *version = extract_value_between(out, "Profile generator API: ", "\n");
if (version == NULL) {
return extract_value_between(out, "Profile generator API: ", "");
}

return version;
}

static bool profile_gen_check_api(gpointer data)
{
struct plugin_private *priv = data;
char version[256], message[BUFSIZ];

if (iio_device_debug_attr_read(priv->adrv9002, "api_version", version, sizeof(version)) < 0) {
sprintf(message, "\nCould not read API version!");
profile_gen_set_debug_info(data, message);
goto err;
}

char *supported_version = profile_gen_cli_get_api();
if (supported_version == NULL) {
sprintf(message, "\nFailed to get profile generator API!");
profile_gen_set_debug_info(data, message);
goto err;
}

if (strcmp(version, supported_version) != 0) {
sprintf(message, "\nAPI version %s is not supported, the device uses %s!",
supported_version, version);
profile_gen_set_debug_info(data, message);
goto err;
}

return true;
err:
return false;
}

static void profile_gen_load_config_to_device(GtkButton *self, gpointer data)
{
struct plugin_private *priv = data;
Expand All @@ -2107,6 +2168,12 @@ static void profile_gen_load_config_to_device(GtkButton *self, gpointer data)
return;
}

// check api version
ret = profile_gen_check_api(priv);
if (!ret) {
return;
}

// run profile gen cli command
FILE *file;
char out[BUFSIZ], command[BUFSIZ],
Expand Down

0 comments on commit 3449dbd

Please sign in to comment.