From: Bartosz Golaszewski Date: Fri, 3 Apr 2015 12:58:11 +0000 (+0200) Subject: baylibre-acme: Dynamically check per probe config options. X-Git-Tag: libsigrok-0.4.0~532 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=1fe04eb8d6c84c0013413991d0632022fc0643f7 baylibre-acme: Dynamically check per probe config options. PROBE_FACTOR and POWER_OFF options are advertised for all ACME probes (channel groups) regardless of whether they actually have given capability. Check these options in config_list() at runtime and only advertise them for probes which support them. Signed-off-by: Bartosz Golaszewski --- diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index def373d1..85f474cf 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -28,10 +28,19 @@ static const uint32_t devopts[] = { SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; -static const uint32_t devopts_cg[] = { - SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET, - SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET, -}; +/* + * Currently there are two channel-group/probe options for ACME: + * - SR_CONF_PROBE_FACTOR - allows to modify current shunt resistance + * calibration + * - SR_CONF_POWER_OFF - allows to remotely cut-off/restore power to + * measured devices + * + * They are not static - we have to check each probe's capabilities in + * config_list(). + */ +#define MAX_DEVOPTS_CG 2 +#define HAS_PROBE_FACTOR (SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET) +#define HAS_POWER_OFF (SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET) #define MAX_SAMPLE_RATE 500 /* In Hz */ @@ -263,9 +272,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + uint32_t devopts_cg[MAX_DEVOPTS_CG]; GVariant *gvar; GVariantBuilder gvb; - int ret; + int ret, num_devopts_cg = 0; (void)sdi; (void)cg; @@ -291,8 +301,13 @@ static int config_list(uint32_t key, GVariant **data, } else { switch (key) { case SR_CONF_DEVICE_OPTIONS: + if (bl_acme_get_probe_type(cg) == PROBE_ENRG) + devopts_cg[num_devopts_cg++] = HAS_PROBE_FACTOR; + if (bl_acme_probe_has_pws(cg)) + devopts_cg[num_devopts_cg++] = HAS_POWER_OFF; + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + devopts_cg, num_devopts_cg, sizeof(uint32_t)); break; default: return SR_ERR_NA; diff --git a/src/hardware/baylibre-acme/protocol.c b/src/hardware/baylibre-acme/protocol.c index 656e89fe..ca09eba0 100644 --- a/src/hardware/baylibre-acme/protocol.c +++ b/src/hardware/baylibre-acme/protocol.c @@ -245,6 +245,20 @@ SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type, return TRUE; } +SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg) +{ + struct channel_group_priv *cgp = cg->priv; + + return cgp->probe_type; +} + +SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg) +{ + struct channel_group_priv *cgp = cg->priv; + + return sr_gpio_getval_export(pws_info_gpios[cgp->index]); +} + /* * Sets path to the hwmon attribute if this channel group * supports shunt resistance setting. The caller has to supply @@ -348,8 +362,7 @@ SR_PRIV int bl_acme_read_power_state(const struct sr_channel_group *cg, cgp = cg->priv; - val = sr_gpio_getval_export(pws_info_gpios[cgp->index]); - if (val != 1) { + if (!bl_acme_probe_has_pws(cg)) { sr_err("Probe has no power-switch"); return SR_ERR_ARG; } @@ -368,8 +381,7 @@ SR_PRIV int bl_acme_set_power_off(const struct sr_channel_group *cg, cgp = cg->priv; - val = sr_gpio_getval_export(pws_info_gpios[cgp->index]); - if (val != 1) { + if (!bl_acme_probe_has_pws(cg)) { sr_err("Probe has no power-switch"); return SR_ERR_ARG; } diff --git a/src/hardware/baylibre-acme/protocol.h b/src/hardware/baylibre-acme/protocol.h index 3972aa2c..baa91cac 100644 --- a/src/hardware/baylibre-acme/protocol.h +++ b/src/hardware/baylibre-acme/protocol.h @@ -81,6 +81,9 @@ SR_PRIV gboolean bl_acme_detect_probe(unsigned int addr, SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type, unsigned int addr, int prb_num); +SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg); +SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg); + SR_PRIV int bl_acme_get_shunt(const struct sr_channel_group *cg, uint64_t *shunt); SR_PRIV int bl_acme_set_shunt(const struct sr_channel_group *cg,