Move the probe naming to the creator of the device, and let each driver name its own probes.
This commit is contained in:
parent
2d83e0f963
commit
464d12c72a
15
device.c
15
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
20
hwplugin.c
20
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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 *) */
|
||||
|
|
Loading…
Reference in New Issue