Skip to content

Commit

Permalink
Add --get option.
Browse files Browse the repository at this point in the history
  • Loading branch information
biot committed Sep 10, 2014
1 parent ac1e997 commit 62a6476
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/sigrok-cli.1
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ frames, then quit.
.BR "\-\-continuous"
Sample continuously until stopped. Not all devices support this.
.TP
.BR "\-\-get " <variable>
Get the value of
.B <variable>
from the specified device and print it.
.TP
.BR "\-\-set"
Set one or more variables specified with the \fB\-\-config\fP option, without
doing any acquisition.
Expand Down
38 changes: 38 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@ int select_channels(struct sr_dev_inst *sdi)
return SR_OK;
}

static void get_option(void)
{
struct sr_dev_inst *sdi;
struct sr_channel_group *cg;
const struct sr_config_info *ci;
GSList *devices;
GVariant *gvar;
int ret;
char *s;

if (!(devices = device_scan())) {
g_critical("No devices found.");
return;
}
sdi = devices->data;
g_slist_free(devices);

if (sr_dev_open(sdi) != SR_OK) {
g_critical("Failed to open device.");
return;
}

cg = select_channel_group(sdi);
if (!(ci = sr_config_info_name_get(opt_get)))
g_critical("Unknown option '%s'", opt_get);

if ((ret = sr_config_get(sdi->driver, sdi, cg, ci->key, &gvar)) != SR_OK)
g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret));
s = g_variant_print(gvar, FALSE);
printf("%s\n", s);
g_free(s);

g_variant_unref(gvar);
sr_dev_close(sdi);
}

static void set_options(void)
{
struct sr_dev_inst *sdi;
Expand Down Expand Up @@ -176,6 +212,8 @@ int main(int argc, char **argv)
show_dev_detail();
else if (opt_input_file)
load_input_file();
else if (opt_get)
get_option();
else if (opt_set)
set_options();
else if (opt_samples || opt_time || opt_frames || opt_continuous)
Expand Down
3 changes: 3 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ gchar *opt_time = NULL;
gchar *opt_samples = NULL;
gchar *opt_frames = NULL;
gchar *opt_continuous = NULL;
gchar *opt_get = NULL;
gchar *opt_set = NULL;

/* defines a callback function that generates
Expand Down Expand Up @@ -85,6 +86,7 @@ CHECK_ONCE(opt_pd_binary)
CHECK_ONCE(opt_time)
CHECK_ONCE(opt_samples)
CHECK_ONCE(opt_frames)
CHECK_ONCE(opt_get)

#undef CHECK_STR_ONCE

Expand Down Expand Up @@ -140,6 +142,7 @@ static const GOptionEntry optargs[] = {
"Number of frames to acquire", NULL},
{"continuous", 0, 0, G_OPTION_ARG_NONE, &opt_continuous,
"Sample continuously", NULL},
{"get", 0, 0, G_OPTION_ARG_CALLBACK, &check_opt_get, "Get device option only", NULL},
{"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
Expand Down
1 change: 1 addition & 0 deletions sigrok-cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern gchar *opt_time;
extern gchar *opt_samples;
extern gchar *opt_frames;
extern gchar *opt_continuous;
extern gchar *opt_get;
extern gchar *opt_set;
int parse_options(int argc, char **argv);
void show_help(void);
Expand Down

0 comments on commit 62a6476

Please sign in to comment.