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 19, 2023
1 parent c92bae1 commit 53a69f8
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions plugins/adrv9002.c
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,67 @@ static void profile_gen_save_dialog_response(GtkDialog *dialog, gint response_id
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 53a69f8

Please sign in to comment.