X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fgenericdmm%2Fapi.c;h=2dab4b876a89be44787f0621c83dc95640217348;hb=f8c617cf4c6b649d3456f1ca7082f6cfb6dac76d;hp=cc0059fc6778da1922cbab64150f95f7151d036d;hpb=3a0fe4023d1dd02051c126fffead6de631840974;p=libsigrok.git diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index cc0059fc..2dab4b87 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -41,14 +41,18 @@ static struct dev_profile dev_profiles[] = { { NULL, NULL, NULL, NULL, 0, NULL } }; +static const int hwopts[] = { + SR_HWOPT_MODEL, + SR_HWOPT_CONN, + SR_HWOPT_SERIALCOMM, + 0, +}; + static const int hwcaps[] = { SR_HWCAP_MULTIMETER, SR_HWCAP_LIMIT_SAMPLES, SR_HWCAP_LIMIT_MSEC, SR_HWCAP_CONTINUOUS, - SR_HWOPT_MODEL, - SR_HWOPT_CONN, - SR_HWOPT_SERIALCOMM, 0, }; @@ -146,7 +150,7 @@ static GSList *connect_usb(const char *conn) devcnt = g_slist_length(gdi->instances); if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_ACTIVE, - "Generic DMM", NULL, NULL))) { + NULL, NULL, NULL))) { sr_err("genericdmm: sr_dev_inst_new returned NULL."); return NULL; } @@ -229,6 +233,7 @@ static GSList *hw_scan(GSList *options) GSList *l, *ldef, *defopts, *newopts, *devices; struct sr_hwopt *opt, *defopt; struct dev_profile *pr, *profile; + struct sr_dev_inst *sdi; const char *model; /* Separate model from the options list. */ @@ -243,7 +248,7 @@ static GSList *hw_scan(GSList *options) newopts = g_slist_append(newopts, opt); } if (!model) { - sr_err("Need a model to scan for."); + /* This driver only works when a model is specified. */ return NULL; } @@ -301,9 +306,20 @@ static GSList *hw_scan(GSList *options) if (devices) { /* TODO: need to fix up sdi->index fields */ - /* Add a copy of these new devices to the driver instances. */ - for (l = devices; l; l = l->next) + for (l = devices; l; l = l->next) { + /* The default connection-based scanner doesn't really + * know about profiles, so it never filled in the vendor + * or model. Do that now. + */ + sdi = l->data; + sdi->driver = gdi; + if (!sdi->vendor) + sdi->vendor = g_strdup(profile->vendor); + if (!sdi->model) + sdi->model = g_strdup(profile->model); + /* Add a copy of these new devices to the driver instances. */ gdi->instances = g_slist_append(gdi->instances, l->data); + } } return devices; @@ -424,51 +440,38 @@ static int hw_cleanup(void) return SR_OK; } -static const void *hw_dev_info_get(int dev_index, int dev_info_id) +static int hw_info_get(int dev_info_id, const void **data, + const struct sr_dev_inst *sdi) { - struct sr_dev_inst *sdi; struct context *ctx; - const void *info; - - if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) { - sr_err("genericdmm: sdi was NULL."); - return NULL; - } - - if (!(ctx = sdi->priv)) { - sr_err("genericdmm: sdi->priv was NULL."); - return NULL; - } - - sr_spew("genericdmm: dev_index %d, dev_info_id %d.", - dev_index, dev_info_id); switch (dev_info_id) { case SR_DI_INST: - info = sdi; + *data = sdi; sr_spew("genericdmm: Returning sdi."); break; + case SR_DI_HWOPTS: + *data = hwopts; + break; + case SR_DI_HWCAPS: + *data = hwcaps; + break; case SR_DI_NUM_PROBES: - info = GINT_TO_POINTER(1); - sr_spew("genericdmm: Returning number of probes: 1."); + *data = GINT_TO_POINTER(1); break; case SR_DI_PROBE_NAMES: - info = probe_names; - sr_spew("genericdmm: Returning probenames."); + *data = probe_names; break; case SR_DI_CUR_SAMPLERATE: /* TODO get rid of this */ - info = NULL; - sr_spew("genericdmm: Returning samplerate: 0."); + *data = NULL; break; default: /* Unknown device info ID. */ - sr_err("genericdmm: Unknown device info ID: %d.", dev_info_id); - info = NULL; - break; + return SR_ERR_ARG; } - return info; + return SR_OK; } static int hw_dev_status_get(int dev_index) @@ -485,13 +488,6 @@ static int hw_dev_status_get(int dev_index) return sdi->status; } -static const int *hw_hwcap_get_all(void) -{ - sr_spew("genericdmm: Returning list of device capabilities."); - - return hwcaps; -} - static int hw_dev_config_set(int dev_index, int hwcap, const void *value) { struct sr_dev_inst *sdi; @@ -638,9 +634,8 @@ SR_PRIV struct sr_dev_driver genericdmm_driver_info = { .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, - .dev_info_get = hw_dev_info_get, + .info_get = hw_info_get, .dev_status_get = hw_dev_status_get, - .hwcap_get_all = hw_hwcap_get_all, .dev_config_set = hw_dev_config_set, .dev_acquisition_start = hw_dev_acquisition_start, .dev_acquisition_stop = hw_dev_acquisition_stop,