From: Kristoffer Sjöberg Date: Thu, 29 Dec 2011 16:04:31 +0000 (+0100) Subject: Move the probe naming to the creator of the device, and let each driver name its... X-Git-Tag: libsigrok-0.1.0~206 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=464d12c72aa8d83acccccbbc0bc755fbb9d542c0;p=libsigrok.git Move the probe naming to the creator of the device, and let each driver name its own probes. --- diff --git a/device.c b/device.c index b18fcacd..ac170ac3 100644 --- a/device.c +++ b/device.c @@ -117,15 +117,9 @@ GSList *sr_device_list(void) * @return Pointer to the newly allocated device, or NULL upon errors. */ struct sr_device *sr_device_new(const struct sr_device_plugin *plugin, - int plugin_index, int num_probes) + int plugin_index) { struct sr_device *device; - int i; - - if (!plugin) { - sr_err("dev: %s: plugin was NULL", __func__); - return NULL; /* TODO: SR_ERR_ARG */ - } /* TODO: Check if plugin_index valid? */ @@ -140,9 +134,6 @@ struct sr_device *sr_device_new(const struct sr_device_plugin *plugin, device->plugin_index = plugin_index; devices = g_slist_append(devices, device); - for (i = 0; i < num_probes; i++) - sr_device_probe_add(device, NULL); /* TODO: Check return value. */ - return device; } @@ -252,7 +243,6 @@ int sr_device_probe_clear(struct sr_device *device, int probenum) int sr_device_probe_add(struct sr_device *device, const char *name) { struct sr_probe *p; - char probename[16]; /* FIXME: Don't hardcode 16? #define? */ int probenum; if (!device) { @@ -278,9 +268,6 @@ int sr_device_probe_add(struct sr_device *device, const char *name) p->enabled = TRUE; if (name) { p->name = g_strdup(name); - } else { - snprintf(probename, 16, "%d", probenum); - p->name = g_strdup(probename); } p->trigger = NULL; device->probes = g_slist_append(device->probes, p); diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index 5d0214bd..db41072c 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -36,6 +36,12 @@ static int capabilities[] = { SR_HWCAP_CONTINUOUS, }; +static const char* probe_names[NUM_PROBES + 1] = { + "0", + "1", + NULL, +}; + static GSList *device_instances = NULL; struct alsa { @@ -160,6 +166,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(NUM_PROBES); break; + case SR_DI_PROBE_NAMES: + info = probe_names; + break; case SR_DI_CUR_SAMPLERATE: info = &alsa->cur_rate; break; diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index b6b914ce..557557e9 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -40,6 +40,7 @@ #define USB_MODEL_NAME "SIGMA" #define USB_MODEL_VERSION "" #define TRIGGER_TYPES "rf10" +#define NUM_PROBES 16 static GSList *device_instances = NULL; @@ -57,6 +58,26 @@ static uint64_t supported_samplerates[] = { 0, }; +static const char* probe_names[NUM_PROBES + 1] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + NULL, +}; + static struct sr_samplerates samplerates = { SR_KHZ(200), SR_MHZ(200), @@ -735,7 +756,10 @@ static void *hw_get_device_info(int device_index, int device_info_id) info = sdi; break; case SR_DI_NUM_PROBES: - info = GINT_TO_POINTER(16); + info = GINT_TO_POINTER(NUM_PROBES); + break; + case SR_DI_PROBE_NAMES: + info = probe_names; break; case SR_DI_SAMPLERATES: info = &samplerates; diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index 478df485..d2a88922 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -41,6 +41,18 @@ static GSList *device_instances = NULL; +static const char* probe_names[NUM_PROBES + 1] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + NULL, +}; + struct la8 { /** FTDI device context (used by libftdi). */ struct ftdi_context *ftdic; @@ -726,6 +738,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(NUM_PROBES); break; + case SR_DI_PROBE_NAMES: + info = probe_names; + break; case SR_DI_SAMPLERATES: fill_supported_samplerates_if_needed(); info = &samplerates; diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 9531d0b0..6605d1e6 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -102,6 +102,18 @@ static const char *pattern_strings[] = { NULL, }; +static const char *probe_names[NUM_PROBES + 1] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + NULL, +}; + static uint8_t pattern_sigrok[] = { 0x4c, 0x92, 0x92, 0x92, 0x64, 0x00, 0x00, 0x00, 0x82, 0xfe, 0xfe, 0x82, 0x00, 0x00, 0x00, 0x00, @@ -185,6 +197,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(NUM_PROBES); break; + case SR_DI_PROBE_NAMES: + info = probe_names; + break; case SR_DI_SAMPLERATES: info = &samplerates; break; diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 83fb4db0..30bda395 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -35,6 +35,8 @@ #define USB_VENDOR "3195" #define USB_PRODUCT "f190" +#define NUM_PROBES 8 + static int capabilities[] = { SR_HWCAP_LOGIC_ANALYZER, // SR_HWCAP_OSCILLOSCOPE, @@ -46,6 +48,18 @@ static int capabilities[] = { 0, }; +static const char *probe_names[NUM_PROBES + 1] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + NULL, +}; + static uint64_t supported_samplerates[] = { SR_HZ(100), SR_HZ(200), @@ -573,7 +587,10 @@ static void *hw_get_device_info(int device_index, int device_info_id) info = sdi; break; case SR_DI_NUM_PROBES: /* FIXME: How to report analog probe? */ - info = GINT_TO_POINTER(8); + info = GINT_TO_POINTER(NUM_PROBES); + break; + case SR_DI_PROBE_NAMES: + info = probe_names; break; case SR_DI_SAMPLERATES: info = &samplerates; diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index 4f78ba5b..acc9a922 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -55,6 +55,42 @@ static int capabilities[] = { 0, }; +static const char* probe_names[NUM_PROBES + 1] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "31", + NULL, +}; + /* default supported samplerates, can be overridden by device metadata */ static struct sr_samplerates samplerates = { SR_HZ(10), @@ -513,6 +549,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(NUM_PROBES); break; + case SR_DI_PROBE_NAMES: + info = probe_names; + break; case SR_DI_SAMPLERATES: info = &samplerates; break; diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index c8b3dfa3..c346b3d1 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -46,6 +46,26 @@ static int capabilities[] = { 0, }; +static const char* probe_names[] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + NULL, +}; + static uint64_t supported_samplerates[] = { SR_KHZ(200), SR_KHZ(250), @@ -458,6 +478,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(fx2->profile->num_probes); break; + case SR_DI_PROBE_NAMES: + info = probe_names; + break; case SR_DI_SAMPLERATES: info = &samplerates; break; diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 75cd772f..2a5952b4 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -73,6 +73,42 @@ static int capabilities[] = { 0, }; +static const char* probe_names[] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "31", + NULL, +}; + /* List of struct sr_device_instance, maintained by opendev()/closedev(). */ static GSList *device_instances = NULL; @@ -420,6 +456,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(num_channels); break; + case SR_DI_PROBE_NAMES: + info = probe_names; + break; case SR_DI_SAMPLERATES: info = &samplerates; break; diff --git a/hwplugin.c b/hwplugin.c index 60a121c9..fcaaba93 100644 --- a/hwplugin.c +++ b/hwplugin.c @@ -108,17 +108,31 @@ GSList *sr_list_hwplugins(void) int sr_init_hwplugins(struct sr_device_plugin *plugin) { - int num_devices, num_probes, i; + int num_devices, num_probes, i, j; + int num_initialized_devices = 0; + struct sr_device *device; + char **probe_names; g_message("initializing %s plugin", plugin->name); num_devices = plugin->init(NULL); for (i = 0; i < num_devices; i++) { num_probes = GPOINTER_TO_INT( plugin->get_device_info(i, SR_DI_NUM_PROBES)); - sr_device_new(plugin, i, num_probes); + probe_names = (char**)plugin->get_device_info(i, SR_DI_PROBE_NAMES); + + if (!probe_names) { + sr_warn("Plugin %s does not return a list of probe names.", plugin->name); + continue; + } + + device = sr_device_new(plugin, i); + for (j = 0; j < num_probes; j++) { + sr_device_probe_add(device, probe_names[j]); + } + num_initialized_devices++; } - return num_devices; + return num_initialized_devices; } void sr_cleanup_hwplugins(void) diff --git a/input/input_binary.c b/input/input_binary.c index 109927dc..fd23bfc1 100644 --- a/input/input_binary.c +++ b/input/input_binary.c @@ -39,7 +39,8 @@ static int format_match(const char *filename) static int init(struct sr_input *in) { - int num_probes; + int num_probes, i; + char name[SR_MAX_PROBENAME_LEN]; if (in->param && in->param[0]) { num_probes = strtoul(in->param, NULL, 10); @@ -49,7 +50,13 @@ static int init(struct sr_input *in) num_probes = DEFAULT_NUM_PROBES; /* create a virtual device */ - in->vdevice = sr_device_new(NULL, 0, num_probes); + in->vdevice = sr_device_new(NULL, 0); + + for (i = 0; i < num_probes; i++) + { + snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i); + sr_device_probe_add(in->vdevice, name); /* TODO: Check return value. */ + } return SR_OK; } diff --git a/input/input_chronovu_la8.c b/input/input_chronovu_la8.c index 6ce66c0c..241b7a0c 100644 --- a/input/input_chronovu_la8.c +++ b/input/input_chronovu_la8.c @@ -77,7 +77,8 @@ static int format_match(const char *filename) static int init(struct sr_input *in) { - int num_probes; + int num_probes, i; + char name[SR_MAX_PROBENAME_LEN]; if (in->param && in->param[0]) { num_probes = strtoul(in->param, NULL, 10); @@ -90,7 +91,12 @@ static int init(struct sr_input *in) } /* Create a virtual device. */ - in->vdevice = sr_device_new(NULL, 0, num_probes); + in->vdevice = sr_device_new(NULL, 0); + + for (i = 0; i < num_probes; i++) { + snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i); + sr_device_probe_add(in->vdevice, name); /* TODO: Check return value. */ + } return SR_OK; } diff --git a/session_file.c b/session_file.c index 637e647e..d6d3d822 100644 --- a/session_file.c +++ b/session_file.c @@ -43,6 +43,7 @@ int sr_session_load(const char *filename) int ret, err, probenum, devcnt, i, j; uint64_t tmp_u64, total_probes, enabled_probes, p; char **sections, **keys, *metafile, *val, c; + char probename[SR_MAX_PROBENAME_LEN]; if (!(archive = zip_open(filename, 0, &err))) { sr_dbg("Failed to open session file: zip error %d", err); @@ -99,7 +100,7 @@ int sr_session_load(const char *filename) for (j = 0; keys[j]; j++) { val = g_key_file_get_string(kf, sections[i], keys[j], NULL); if (!strcmp(keys[j], "capturefile")) { - device = sr_device_new(&session_driver, devcnt, 0); + device = sr_device_new(&session_driver, devcnt); if (devcnt == 0) /* first device, init the plugin */ device->plugin->init((char *)filename); @@ -115,8 +116,10 @@ int sr_session_load(const char *filename) } else if (!strcmp(keys[j], "total probes")) { total_probes = strtoull(val, NULL, 10); device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTURE_NUM_PROBES, &total_probes); - for (p = 1; p <= total_probes; p++) - sr_device_probe_add(device, NULL); + for (p = 0; p < total_probes; p++) { + snprintf(probename, SR_MAX_PROBENAME_LEN, "%" PRIu64, p); + sr_device_probe_add(device, probename); + } } else if (!strncmp(keys[j], "probe", 5)) { if (!device) continue; diff --git a/sigrok-proto.h b/sigrok-proto.h index f4046bfa..55773017 100644 --- a/sigrok-proto.h +++ b/sigrok-proto.h @@ -42,7 +42,7 @@ int sr_datastore_put(struct sr_datastore *ds, void *data, unsigned int length, int sr_device_scan(void); GSList *sr_device_list(void); struct sr_device *sr_device_new(const struct sr_device_plugin *plugin, - int plugin_index, int num_probes); + int plugin_index); int sr_device_clear(struct sr_device *device); int sr_device_probe_clear(struct sr_device *device, int probenum); int sr_device_probe_add(struct sr_device *device, const char *name); diff --git a/sigrok.h.in b/sigrok.h.in index 4f3be935..605aece4 100644 --- a/sigrok.h.in +++ b/sigrok.h.in @@ -355,6 +355,8 @@ enum { SR_DI_INSTANCE, /* The number of probes connected to this device */ SR_DI_NUM_PROBES, + /* The probe names on this device */ + SR_DI_PROBE_NAMES, /* Samplerates supported by this device, (struct sr_samplerates) */ SR_DI_SAMPLERATES, /* Types of trigger supported, out of "01crf" (char *) */