Move the probe naming to the creator of the device, and let each driver name its own probes.

This commit is contained in:
Kristoffer Sjöberg 2011-12-29 17:04:31 +01:00
parent 2d83e0f963
commit 464d12c72a
15 changed files with 227 additions and 27 deletions

View File

@ -117,15 +117,9 @@ GSList *sr_device_list(void)
* @return Pointer to the newly allocated device, or NULL upon errors. * @return Pointer to the newly allocated device, or NULL upon errors.
*/ */
struct sr_device *sr_device_new(const struct sr_device_plugin *plugin, 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; 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? */ /* 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; device->plugin_index = plugin_index;
devices = g_slist_append(devices, device); 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; 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) int sr_device_probe_add(struct sr_device *device, const char *name)
{ {
struct sr_probe *p; struct sr_probe *p;
char probename[16]; /* FIXME: Don't hardcode 16? #define? */
int probenum; int probenum;
if (!device) { if (!device) {
@ -278,9 +268,6 @@ int sr_device_probe_add(struct sr_device *device, const char *name)
p->enabled = TRUE; p->enabled = TRUE;
if (name) { if (name) {
p->name = g_strdup(name); p->name = g_strdup(name);
} else {
snprintf(probename, 16, "%d", probenum);
p->name = g_strdup(probename);
} }
p->trigger = NULL; p->trigger = NULL;
device->probes = g_slist_append(device->probes, p); device->probes = g_slist_append(device->probes, p);

View File

@ -36,6 +36,12 @@ static int capabilities[] = {
SR_HWCAP_CONTINUOUS, SR_HWCAP_CONTINUOUS,
}; };
static const char* probe_names[NUM_PROBES + 1] = {
"0",
"1",
NULL,
};
static GSList *device_instances = NULL; static GSList *device_instances = NULL;
struct alsa { struct alsa {
@ -160,6 +166,9 @@ static void *hw_get_device_info(int device_index, int device_info_id)
case SR_DI_NUM_PROBES: case SR_DI_NUM_PROBES:
info = GINT_TO_POINTER(NUM_PROBES); info = GINT_TO_POINTER(NUM_PROBES);
break; break;
case SR_DI_PROBE_NAMES:
info = probe_names;
break;
case SR_DI_CUR_SAMPLERATE: case SR_DI_CUR_SAMPLERATE:
info = &alsa->cur_rate; info = &alsa->cur_rate;
break; break;

View File

@ -40,6 +40,7 @@
#define USB_MODEL_NAME "SIGMA" #define USB_MODEL_NAME "SIGMA"
#define USB_MODEL_VERSION "" #define USB_MODEL_VERSION ""
#define TRIGGER_TYPES "rf10" #define TRIGGER_TYPES "rf10"
#define NUM_PROBES 16
static GSList *device_instances = NULL; static GSList *device_instances = NULL;
@ -57,6 +58,26 @@ static uint64_t supported_samplerates[] = {
0, 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 = { static struct sr_samplerates samplerates = {
SR_KHZ(200), SR_KHZ(200),
SR_MHZ(200), SR_MHZ(200),
@ -735,7 +756,10 @@ static void *hw_get_device_info(int device_index, int device_info_id)
info = sdi; info = sdi;
break; break;
case SR_DI_NUM_PROBES: 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; break;
case SR_DI_SAMPLERATES: case SR_DI_SAMPLERATES:
info = &samplerates; info = &samplerates;

View File

@ -41,6 +41,18 @@
static GSList *device_instances = NULL; static GSList *device_instances = NULL;
static const char* probe_names[NUM_PROBES + 1] = {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
NULL,
};
struct la8 { struct la8 {
/** FTDI device context (used by libftdi). */ /** FTDI device context (used by libftdi). */
struct ftdi_context *ftdic; 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: case SR_DI_NUM_PROBES:
info = GINT_TO_POINTER(NUM_PROBES); info = GINT_TO_POINTER(NUM_PROBES);
break; break;
case SR_DI_PROBE_NAMES:
info = probe_names;
break;
case SR_DI_SAMPLERATES: case SR_DI_SAMPLERATES:
fill_supported_samplerates_if_needed(); fill_supported_samplerates_if_needed();
info = &samplerates; info = &samplerates;

View File

@ -102,6 +102,18 @@ static const char *pattern_strings[] = {
NULL, NULL,
}; };
static const char *probe_names[NUM_PROBES + 1] = {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
NULL,
};
static uint8_t pattern_sigrok[] = { static uint8_t pattern_sigrok[] = {
0x4c, 0x92, 0x92, 0x92, 0x64, 0x00, 0x00, 0x00, 0x4c, 0x92, 0x92, 0x92, 0x64, 0x00, 0x00, 0x00,
0x82, 0xfe, 0xfe, 0x82, 0x00, 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: case SR_DI_NUM_PROBES:
info = GINT_TO_POINTER(NUM_PROBES); info = GINT_TO_POINTER(NUM_PROBES);
break; break;
case SR_DI_PROBE_NAMES:
info = probe_names;
break;
case SR_DI_SAMPLERATES: case SR_DI_SAMPLERATES:
info = &samplerates; info = &samplerates;
break; break;

View File

@ -35,6 +35,8 @@
#define USB_VENDOR "3195" #define USB_VENDOR "3195"
#define USB_PRODUCT "f190" #define USB_PRODUCT "f190"
#define NUM_PROBES 8
static int capabilities[] = { static int capabilities[] = {
SR_HWCAP_LOGIC_ANALYZER, SR_HWCAP_LOGIC_ANALYZER,
// SR_HWCAP_OSCILLOSCOPE, // SR_HWCAP_OSCILLOSCOPE,
@ -46,6 +48,18 @@ static int capabilities[] = {
0, 0,
}; };
static const char *probe_names[NUM_PROBES + 1] = {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
NULL,
};
static uint64_t supported_samplerates[] = { static uint64_t supported_samplerates[] = {
SR_HZ(100), SR_HZ(100),
SR_HZ(200), SR_HZ(200),
@ -573,7 +587,10 @@ static void *hw_get_device_info(int device_index, int device_info_id)
info = sdi; info = sdi;
break; break;
case SR_DI_NUM_PROBES: /* FIXME: How to report analog probe? */ 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; break;
case SR_DI_SAMPLERATES: case SR_DI_SAMPLERATES:
info = &samplerates; info = &samplerates;

View File

@ -55,6 +55,42 @@ static int capabilities[] = {
0, 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 */ /* default supported samplerates, can be overridden by device metadata */
static struct sr_samplerates samplerates = { static struct sr_samplerates samplerates = {
SR_HZ(10), 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: case SR_DI_NUM_PROBES:
info = GINT_TO_POINTER(NUM_PROBES); info = GINT_TO_POINTER(NUM_PROBES);
break; break;
case SR_DI_PROBE_NAMES:
info = probe_names;
break;
case SR_DI_SAMPLERATES: case SR_DI_SAMPLERATES:
info = &samplerates; info = &samplerates;
break; break;

View File

@ -46,6 +46,26 @@ static int capabilities[] = {
0, 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[] = { static uint64_t supported_samplerates[] = {
SR_KHZ(200), SR_KHZ(200),
SR_KHZ(250), 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: case SR_DI_NUM_PROBES:
info = GINT_TO_POINTER(fx2->profile->num_probes); info = GINT_TO_POINTER(fx2->profile->num_probes);
break; break;
case SR_DI_PROBE_NAMES:
info = probe_names;
break;
case SR_DI_SAMPLERATES: case SR_DI_SAMPLERATES:
info = &samplerates; info = &samplerates;
break; break;

View File

@ -73,6 +73,42 @@ static int capabilities[] = {
0, 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(). */ /* List of struct sr_device_instance, maintained by opendev()/closedev(). */
static GSList *device_instances = NULL; 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: case SR_DI_NUM_PROBES:
info = GINT_TO_POINTER(num_channels); info = GINT_TO_POINTER(num_channels);
break; break;
case SR_DI_PROBE_NAMES:
info = probe_names;
break;
case SR_DI_SAMPLERATES: case SR_DI_SAMPLERATES:
info = &samplerates; info = &samplerates;
break; break;

View File

@ -108,17 +108,31 @@ GSList *sr_list_hwplugins(void)
int sr_init_hwplugins(struct sr_device_plugin *plugin) 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); g_message("initializing %s plugin", plugin->name);
num_devices = plugin->init(NULL); num_devices = plugin->init(NULL);
for (i = 0; i < num_devices; i++) { for (i = 0; i < num_devices; i++) {
num_probes = GPOINTER_TO_INT( num_probes = GPOINTER_TO_INT(
plugin->get_device_info(i, SR_DI_NUM_PROBES)); 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) void sr_cleanup_hwplugins(void)

View File

@ -39,7 +39,8 @@ static int format_match(const char *filename)
static int init(struct sr_input *in) 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]) { if (in->param && in->param[0]) {
num_probes = strtoul(in->param, NULL, 10); num_probes = strtoul(in->param, NULL, 10);
@ -49,7 +50,13 @@ static int init(struct sr_input *in)
num_probes = DEFAULT_NUM_PROBES; num_probes = DEFAULT_NUM_PROBES;
/* create a virtual device */ /* 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; return SR_OK;
} }

View File

@ -77,7 +77,8 @@ static int format_match(const char *filename)
static int init(struct sr_input *in) 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]) { if (in->param && in->param[0]) {
num_probes = strtoul(in->param, NULL, 10); num_probes = strtoul(in->param, NULL, 10);
@ -90,7 +91,12 @@ static int init(struct sr_input *in)
} }
/* Create a virtual device. */ /* 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; return SR_OK;
} }

View File

@ -43,6 +43,7 @@ int sr_session_load(const char *filename)
int ret, err, probenum, devcnt, i, j; int ret, err, probenum, devcnt, i, j;
uint64_t tmp_u64, total_probes, enabled_probes, p; uint64_t tmp_u64, total_probes, enabled_probes, p;
char **sections, **keys, *metafile, *val, c; char **sections, **keys, *metafile, *val, c;
char probename[SR_MAX_PROBENAME_LEN];
if (!(archive = zip_open(filename, 0, &err))) { if (!(archive = zip_open(filename, 0, &err))) {
sr_dbg("Failed to open session file: zip error %d", 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++) { for (j = 0; keys[j]; j++) {
val = g_key_file_get_string(kf, sections[i], keys[j], NULL); val = g_key_file_get_string(kf, sections[i], keys[j], NULL);
if (!strcmp(keys[j], "capturefile")) { if (!strcmp(keys[j], "capturefile")) {
device = sr_device_new(&session_driver, devcnt, 0); device = sr_device_new(&session_driver, devcnt);
if (devcnt == 0) if (devcnt == 0)
/* first device, init the plugin */ /* first device, init the plugin */
device->plugin->init((char *)filename); device->plugin->init((char *)filename);
@ -115,8 +116,10 @@ int sr_session_load(const char *filename)
} else if (!strcmp(keys[j], "total probes")) { } else if (!strcmp(keys[j], "total probes")) {
total_probes = strtoull(val, NULL, 10); total_probes = strtoull(val, NULL, 10);
device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTURE_NUM_PROBES, &total_probes); device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTURE_NUM_PROBES, &total_probes);
for (p = 1; p <= total_probes; p++) for (p = 0; p < total_probes; p++) {
sr_device_probe_add(device, NULL); snprintf(probename, SR_MAX_PROBENAME_LEN, "%" PRIu64, p);
sr_device_probe_add(device, probename);
}
} else if (!strncmp(keys[j], "probe", 5)) { } else if (!strncmp(keys[j], "probe", 5)) {
if (!device) if (!device)
continue; continue;

View File

@ -42,7 +42,7 @@ int sr_datastore_put(struct sr_datastore *ds, void *data, unsigned int length,
int sr_device_scan(void); int sr_device_scan(void);
GSList *sr_device_list(void); GSList *sr_device_list(void);
struct sr_device *sr_device_new(const struct sr_device_plugin *plugin, 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_clear(struct sr_device *device);
int sr_device_probe_clear(struct sr_device *device, int probenum); int sr_device_probe_clear(struct sr_device *device, int probenum);
int sr_device_probe_add(struct sr_device *device, const char *name); int sr_device_probe_add(struct sr_device *device, const char *name);

View File

@ -355,6 +355,8 @@ enum {
SR_DI_INSTANCE, SR_DI_INSTANCE,
/* The number of probes connected to this device */ /* The number of probes connected to this device */
SR_DI_NUM_PROBES, SR_DI_NUM_PROBES,
/* The probe names on this device */
SR_DI_PROBE_NAMES,
/* Samplerates supported by this device, (struct sr_samplerates) */ /* Samplerates supported by this device, (struct sr_samplerates) */
SR_DI_SAMPLERATES, SR_DI_SAMPLERATES,
/* Types of trigger supported, out of "01crf" (char *) */ /* Types of trigger supported, out of "01crf" (char *) */