]> sigrok.org Git - libsigrok.git/commitdiff
Move the probe naming to the creator of the device, and let each driver name its...
authorKristoffer Sjöberg <redacted>
Thu, 29 Dec 2011 16:04:31 +0000 (17:04 +0100)
committerKristoffer Sjöberg <redacted>
Thu, 29 Dec 2011 16:04:31 +0000 (17:04 +0100)
15 files changed:
device.c
hardware/alsa/alsa.c
hardware/asix-sigma/asix-sigma.c
hardware/chronovu-la8/chronovu-la8.c
hardware/demo/demo.c
hardware/link-mso19/link-mso19.c
hardware/openbench-logic-sniffer/ols.c
hardware/saleae-logic/saleae-logic.c
hardware/zeroplus-logic-cube/zeroplus.c
hwplugin.c
input/input_binary.c
input/input_chronovu_la8.c
session_file.c
sigrok-proto.h
sigrok.h.in

index b18fcacd3f9cbef0eb287f39d9c918dd44d8f715..ac170ac33c3b3a0bd8cfa2821294843439548986 100644 (file)
--- 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);
index 5d0214bdfcc2637bd87c3a2470809f99dd0f89e3..db41072c9739b94a388b0a815ae1a4b6d345f885 100644 (file)
@@ -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;
index b6b914ce30a72064965d9f68b63b25d0b76b9b06..557557e9aae61d2fead33d1f87da1fae0ecf106b 100644 (file)
@@ -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;
index 478df4853ff2e875c0bea2cea3a37733f8297944..d2a88922c28fcf7f8e6381d82b9b5dd33f108797 100644 (file)
 
 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;
index 9531d0b03f08fc943faf516b1ae2ade1fc78e931..6605d1e6c321f6fe5be8998d65a4799a5594cce3 100644 (file)
@@ -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;
index 83fb4db04233ca81c5010ff68338a11056ef4b25..30bda395fc848a28b585aa9b376c608096b6952d 100644 (file)
@@ -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;
index 4f78ba5b4c7f84063b588ff8b9f988f4b32b4725..acc9a922248a3c6e0259a8b0592e9fd3facba65b 100644 (file)
@@ -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;
index c8b3dfa3ec017a104b54cd3219aa39e1cbc1539f..c346b3d16b63d43be10931f78cb01c5adf2cc3d5 100644 (file)
@@ -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;
index 75cd772f110fab40af032f36bc207372f62727de..2a5952b45d45094dc6c948031b04efca3b9a4d1f 100644 (file)
@@ -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;
index 60a121c9a5dc5a67612b87a4034ab22bcf1209d4..fcaaba9351a8bf1cb0128a98c4819bd055b478f3 100644 (file)
@@ -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)
index 109927dcb44425619e8d563402b4005f5d63edca..fd23bfc1b3898cd71d4dc5be2db35afa47b4de2f 100644 (file)
@@ -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;
 }
index 6ce66c0c65cfb63e7cf5e80efa503c4c582b6d49..241b7a0cf6e7b2e6cd14581c8771e1efdcf91c87 100644 (file)
@@ -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;
 }
index 637e647edc7e5dcc80ac10d5714377ff2430dcae..d6d3d8228901c93f6709c5a571c7fb65ffa05126 100644 (file)
@@ -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;
index f4046bfa33bde89ba83556e970be38297ce8187c..557730174aa8d46068f987b5133f60c69f4f300d 100644 (file)
@@ -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);
index 4f3be9354c62f2b9f14b6992928d28139b0b0e27..605aece4389e880a4516300ad69255d681f825b8 100644 (file)
@@ -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 *) */