Introduce the --list-serial command line option, which prints the list
of serial ports detected by the sigrok serial.c abstraction.
The code was taken from Carl-Fredrik Sundström's <redacted>
message to the mailing list, with minor style fixes applied, and the
option renamed to explicitly mention its "list" nature, not suggesting
it would be a parameter to setup.
set_options();
else if (opt_samples || opt_time || opt_frames || opt_continuous)
run_session();
set_options();
else if (opt_samples || opt_time || opt_frames || opt_continuous)
run_session();
+ else if (opt_list_serial)
+ show_serial_ports();
gboolean opt_continuous = FALSE;
gchar *opt_get = NULL;
gboolean opt_set = FALSE;
gboolean opt_continuous = FALSE;
gchar *opt_get = NULL;
gboolean opt_set = FALSE;
+gboolean opt_list_serial = FALSE;
/*
* Defines a callback function that generates an error if an
/*
* Defines a callback function that generates an error if an
"Sample continuously", NULL},
{"get", 0, 0, G_OPTION_ARG_CALLBACK, &check_opt_get, "Get device options only", NULL},
{"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL},
"Sample continuously", NULL},
{"get", 0, 0, G_OPTION_ARG_CALLBACK, &check_opt_get, "Get device options only", NULL},
{"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only", NULL},
+ {"list-serial", 0, 0, G_OPTION_ARG_NONE, &opt_list_serial, "List available serial ports", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
+
+static void print_serial_port(gpointer data, gpointer user_data)
+{
+ struct sr_serial_port *port;
+
+ port = (void *)data;
+ (void)user_data;
+ printf("\t%s\t%s\n", port->name, port->description);
+}
+
+void show_serial_ports(void)
+{
+ GSList *serial_ports;
+
+ serial_ports = sr_serial_list(NULL);
+ if (!serial_ports)
+ return;
+
+ printf("Available serial ports:\n");
+ g_slist_foreach(serial_ports, print_serial_port, NULL);
+ g_slist_free_full(serial_ports, (GDestroyNotify)sr_serial_free);
+}
void show_input(void);
void show_output(void);
void show_transform(void);
void show_input(void);
void show_output(void);
void show_transform(void);
+void show_serial_ports(void);
/* device.c */
GSList *device_scan(void);
/* device.c */
GSList *device_scan(void);
extern gboolean opt_continuous;
extern gchar *opt_get;
extern gboolean opt_set;
extern gboolean opt_continuous;
extern gchar *opt_get;
extern gboolean opt_set;
+extern gboolean opt_list_serial;
int parse_options(int argc, char **argv);
void show_help(void);
int parse_options(int argc, char **argv);
void show_help(void);