From: Uwe Hermann Date: Sat, 7 Mar 2015 23:28:17 +0000 (+0100) Subject: Simplify a few config_set() callbacks. X-Git-Tag: libsigrok-0.4.0~575 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=dcd438ee3523098201c7937e75e55775da3b506f;p=libsigrok.git Simplify a few config_set() callbacks. Also, extended logging and random whitespace fixes. --- diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 6c41023d..19a4144c 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -192,18 +192,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_MSEC: /* TODO: not yet implemented */ - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index 27c29e92..18fc2142 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -174,11 +174,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec); break; case SR_CONF_DATA_SOURCE: { tmp_str = g_variant_get_string(data, NULL); @@ -201,7 +199,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - (void)sdi; (void)cg; switch (key) { diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index 6268747a..0482daeb 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -884,7 +884,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariant *gvar; GVariantBuilder gvb; - (void)sdi; (void)cg; switch (key) { diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 8cce8401..e0168b4e 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -358,7 +358,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd } } - return ret; } diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index f1da9b50..4bcf772d 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -228,12 +228,10 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); devc->limit_msec = 0; - sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data) * 1000; devc->limit_samples = 0; - sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec); break; case SR_CONF_SAMPLERATE: samplerate = g_variant_get_uint64(data); @@ -243,7 +241,6 @@ static int config_set(uint32_t key, GVariant *data, break; } devc->samplerate = samplerate; - sr_dbg("Setting samplerate to %" PRIu64, devc->samplerate); break; case SR_CONF_PROBE_FACTOR: if (!cg) diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 6bfb6df1..74795caf 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -226,25 +226,22 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s const struct sr_channel_group *cg) { struct dev_context *devc = sdi->priv; + (void)cg; switch (key) { case SR_CONF_LIMIT_SAMPLES: *data = g_variant_new_uint64(devc->limit_samples); break; - case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(devc->cur_samplerate); break; - case SR_CONF_CAPTURE_RATIO: *data = g_variant_new_uint64(devc->capture_ratio); break; - case SR_CONF_NUM_LOGIC_CHANNELS: *data = g_variant_new_uint32(g_slist_length(sdi->channels)); break; - default: return SR_ERR_NA; } @@ -257,6 +254,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd { struct dev_context *devc = sdi->priv; uint64_t tmp_u64; + (void)cg; if (sdi->status != SR_ST_ACTIVE) @@ -266,7 +264,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd case SR_CONF_SAMPLERATE: devc->cur_samplerate = g_variant_get_uint64(data); return beaglelogic_set_samplerate(devc); - case SR_CONF_LIMIT_SAMPLES: tmp_u64 = g_variant_get_uint64(data); devc->limit_samples = tmp_u64; @@ -284,7 +281,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (SAMPLEUNIT_TO_BYTES(devc->sampleunit) * 1000000)); } return beaglelogic_set_triggerflags(devc); - case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); if (devc->capture_ratio > 100) { @@ -292,7 +288,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return SR_ERR; } return SR_OK; - default: return SR_ERR_NA; } @@ -308,7 +303,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariantBuilder gvb; (void)sdi; - (void)data; (void)cg; ret = SR_OK; diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index 79e658f5..d7dccc05 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -210,11 +210,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec); break; default: return SR_ERR_NA; diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index eedffbfb..62f4dc0e 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -137,18 +137,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_MSEC: /* TODO: not yet implemented */ - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data);; - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index 284396a3..a3deecc3 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -487,17 +487,14 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_SAMPLERATE: devc->cur_samplerate = g_variant_get_uint64(data); - sr_dbg("Setting samplerate to %" PRIu64, devc->cur_samplerate); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_msec = 0; devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); devc->limit_samples = 0; - sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec); break; case SR_CONF_AVERAGING: devc->avg = g_variant_get_boolean(data); @@ -575,8 +572,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariant *gvar; GVariantBuilder gvb; - (void)sdi; - if (key == SR_CONF_SCAN_OPTIONS) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 216c6359..36142fd5 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -216,18 +216,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_MSEC: /* TODO: not yet implemented */ - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 69b26794..302e6593 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -389,8 +389,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s (void)cg; - ret = SR_OK; - if (!sdi || !(devc = sdi->priv)) return SR_ERR_ARG; diff --git a/src/hardware/gmc-mh-1x-2x/protocol.c b/src/hardware/gmc-mh-1x-2x/protocol.c index ad7ae567..4f6c1e56 100644 --- a/src/hardware/gmc-mh-1x-2x/protocol.c +++ b/src/hardware/gmc-mh-1x-2x/protocol.c @@ -1496,8 +1496,7 @@ SR_PRIV const char *gmc_model_str(enum model mcode) } } -/** @copydoc sr_dev_driver.config_set - */ +/** @copydoc sr_dev_driver.config_set */ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -1533,18 +1532,10 @@ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *s g_usleep(2000000); /* Wait to ensure transfer before interface switched off. */ break; case SR_CONF_LIMIT_MSEC: - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 253d37cd..d2eebfbe 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -169,7 +169,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) struct sr_channel_group *cg; struct drv_context *drvc; struct dev_context *devc; - int i; + unsigned int i; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INITIALIZING; @@ -434,8 +434,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s const uint64_t *vdiv; int ch_idx; - (void)cg; - switch (key) { case SR_CONF_NUM_HDIV: *data = g_variant_new_int32(NUM_TIMEBASE); diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 78b406ea..abdbfd72 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -67,7 +67,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct dev_context *devc; struct sr_usb_dev_inst *usb; struct device_info dev_info; - int ret, i; + unsigned int i; + int ret; (void)options; @@ -354,7 +355,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * (void)cg; ret = SR_OK; - switch (key) { case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 3213a684..67efcf1a 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -215,18 +215,13 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd ret = SR_OK; switch (key) { case SR_CONF_DATALOG: - if (g_variant_get_boolean(data)) { - /* Start logging. */ + if (g_variant_get_boolean(data)) ret = lascar_start_logging(sdi); - } else { - /* Stop logging. */ + else ret = lascar_stop_logging(sdi); - } break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: ret = SR_ERR_NA; diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 634d3f97..98e253fe 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -320,8 +320,6 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, ret = SR_ERR_ARG; } else { devc->limit_samples = num_samples; - sr_dbg("setting limit_samples to %i\n", - num_samples); ret = SR_OK; } break; diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index df9cc22e..6abc09ce 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -169,13 +169,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; default: return SR_ERR_NA; diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 0ed6b09b..5c979ede 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -623,24 +623,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd /* No channel group: global options. */ switch (key) { case SR_CONF_LIMIT_MSEC: - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; case SR_CONF_OUTPUT_CHANNEL_CONFIG: sval = g_variant_get_string(data, NULL); found = FALSE; - for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++) - { + for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++) { if (!strcmp(sval, channel_modes[idx])) { found = TRUE; if (devc->tracking_mode == idx) @@ -652,9 +643,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (devc->model->modelid <= LPS_303) /* Only first setting possible for smaller models. */ break; } - if (!found) { + if (!found) return SR_ERR_ARG; - } break; default: return SR_ERR_NA; @@ -728,25 +718,23 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariant *gvar; GVariantBuilder gvb; - (void)data; - /* Driver options, no device instance necessary. */ switch (key) { case SR_CONF_SCAN_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); return SR_OK; case SR_CONF_DEVICE_OPTIONS: if (sdi != NULL) break; *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); return SR_OK; default: - if (sdi == NULL) + if (!sdi) return SR_ERR_ARG; - devc = sdi->priv; + break; } /* Device options, independent from channel groups. */ @@ -765,7 +753,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = g_variant_new_strv(channel_modes, ARRAY_SIZE(channel_modes)); } return SR_OK; - break; default: return SR_ERR_NA; } diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index 9df1546f..bf44df27 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -219,18 +219,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_MSEC: - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 31fd9ac2..3e02bc28 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -443,7 +443,7 @@ static int dev_open(struct sr_dev_inst *sdi) if (p_ols_open(devc) != SR_OK) { return SR_ERR; } else { - sdi->status = SR_ST_ACTIVE; + sdi->status = SR_ST_ACTIVE; return SR_OK; } } diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 5aa0b415..27705f7c 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -630,7 +630,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s *data = g_variant_new_string(devc->coupling[analog_channel]); break; default: - sr_dbg("Tried to get unknown config key: %d.", key); return SR_ERR_NA; } @@ -795,9 +794,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd } break; default: - sr_dbg("Tried to set unknown config key: %d.", key); - ret = SR_ERR_NA; - break; + return SR_ERR_NA; } return ret; @@ -921,7 +918,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } break; default: - sr_dbg("Tried to list unknown config key: %d.", key); return SR_ERR_NA; } diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 7a4a331f..ae77bd86 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -148,7 +148,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; - int ret, i, j; + int ret, j; + unsigned int i; const char *conn; char connection_id[64]; diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index ecaba493..d76d8842 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -178,13 +178,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; default: return SR_ERR_NA; diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index a23ff68f..13465f56 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -160,11 +160,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec); break; default: return SR_ERR_NA; diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 103f44ce..64d292dd 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -295,13 +295,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd devc->limit_msec = g_variant_get_uint64(data); now = g_get_monotonic_time() / 1000; devc->end_time = now + devc->limit_msec; - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: ret = SR_ERR_NA; diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index b41ef9a8..01c33640 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -130,8 +130,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index 0f872735..0e431b54 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -328,22 +328,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_MSEC: - if (g_variant_get_uint64(data) == 0) { - sr_err("Time limit cannot be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: - if (g_variant_get_uint64(data) == 0) { - sr_err("Sample limit cannot be 0."); - return SR_ERR; - } devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index 3b33df9a..bd792ea1 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -217,7 +217,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd { struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; - int ret; const char *tmp_str; (void)cg; @@ -231,12 +230,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd } devc = sdi->priv; - ret = SR_OK; + switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; case SR_CONF_DATA_SOURCE: tmp_str = g_variant_get_string(data, NULL); @@ -248,16 +245,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return SR_ERR; break; default: - ret = SR_ERR_NA; + return SR_ERR_NA; } - return ret; + return SR_OK; } static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - (void)sdi; (void)cg; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 9aa0019e..3b77407f 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -231,7 +231,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; gint64 now; - int ret; (void)cg; @@ -244,25 +243,21 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd } devc = sdi->priv; - ret = SR_OK; + switch (key) { case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); now = g_get_monotonic_time() / 1000; devc->end_time = now + devc->limit_msec; - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: - ret = SR_ERR_NA; + return SR_ERR_NA; } - return ret; + return SR_OK; } static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 5d8c534f..cb5df66e 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -391,35 +391,26 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s const struct sr_channel_group *cg) { struct dev_context *devc; + GVariant *range[2]; (void)cg; + if (!sdi) + return SR_ERR_ARG; + + devc = sdi->priv; + switch (key) { case SR_CONF_SAMPLERATE: - if (sdi) { - devc = sdi->priv; - *data = g_variant_new_uint64(devc->cur_samplerate); - sr_spew("Returning samplerate: %" PRIu64 "Hz.", - devc->cur_samplerate); - } else - return SR_ERR_ARG; + *data = g_variant_new_uint64(devc->cur_samplerate); break; case SR_CONF_CAPTURE_RATIO: - if (sdi) { - devc = sdi->priv; - *data = g_variant_new_uint64(devc->capture_ratio); - } else - return SR_ERR_ARG; + *data = g_variant_new_uint64(devc->capture_ratio); break; case SR_CONF_VOLTAGE_THRESHOLD: - if (sdi) { - GVariant *range[2]; - devc = sdi->priv; - range[0] = g_variant_new_double(devc->cur_threshold); - range[1] = g_variant_new_double(devc->cur_threshold); - *data = g_variant_new_tuple(range, 2); - } else - return SR_ERR_ARG; + range[0] = g_variant_new_double(devc->cur_threshold); + range[1] = g_variant_new_double(devc->cur_threshold); + *data = g_variant_new_tuple(range, 2); break; default: return SR_ERR_NA; diff --git a/src/hwdriver.c b/src/hwdriver.c index d11bcccc..148ea8a2 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -464,9 +464,27 @@ SR_PRIV void sr_config_free(struct sr_config *src) } +static void log_key(const struct sr_dev_inst *sdi, + const struct sr_channel_group *cg, uint32_t key, int op, GVariant *data) +{ + const char *opstr; + const struct sr_config_info *srci; + + /* Don't log SR_CONF_DEVICE_OPTIONS, it's verbose and not too useful. */ + if (key == SR_CONF_DEVICE_OPTIONS) + return; + + opstr = op == SR_CONF_GET ? "get" : op == SR_CONF_SET ? "set" : "list"; + srci = sr_config_info_get(key); + + sr_spew("sr_config_%s(): key %d (%s) sdi %p cg %s -> %s", opstr, key, + srci ? srci->id : "NULL", sdi, cg ? cg->name : "NULL", + data ? g_variant_print(data, TRUE) : "NULL"); +} + static int check_key(const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, - uint32_t key, int op) + uint32_t key, int op, GVariant *data) { const struct sr_config_info *srci; gsize num_opts, i; @@ -487,8 +505,20 @@ static int check_key(const struct sr_dev_driver *driver, return SR_ERR_ARG; } opstr = op == SR_CONF_GET ? "get" : op == SR_CONF_SET ? "set" : "list"; - sr_spew("sr_config_%s(): key %d (%s) sdi %p cg %s", opstr, key, - srci->id, sdi, cg ? cg->name : "NULL"); + + switch (key) { + case SR_CONF_LIMIT_MSEC: + case SR_CONF_LIMIT_SAMPLES: + case SR_CONF_SAMPLERATE: + /* Setting any of these to 0 is not useful. */ + if (op != SR_CONF_SET || !data) + break; + if (g_variant_get_uint64(data) == 0) { + sr_err("Cannot set '%s' to 0.", srci->id); + return SR_ERR_ARG; + } + break; + } if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS, &gvar_opts) != SR_OK) { /* Driver publishes no options. */ @@ -554,10 +584,11 @@ SR_API int sr_config_get(const struct sr_dev_driver *driver, if (!driver->config_get) return SR_ERR_ARG; - if (check_key(driver, sdi, cg, key, SR_CONF_GET) != SR_OK) + if (check_key(driver, sdi, cg, key, SR_CONF_GET, NULL) != SR_OK) return SR_ERR_ARG; if ((ret = driver->config_get(key, data, sdi, cg)) == SR_OK) { + log_key(sdi, cg, key, SR_CONF_GET, *data); /* Got a floating reference from the driver. Sink it here, * caller will need to unref when done with it. */ g_variant_ref_sink(*data); @@ -597,10 +628,12 @@ SR_API int sr_config_set(const struct sr_dev_inst *sdi, ret = SR_ERR; else if (!sdi->driver->config_set) ret = SR_ERR_ARG; - else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET) != SR_OK) + else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET, data) != SR_OK) return SR_ERR_ARG; - else if ((ret = sr_variant_type_check(key, data)) == SR_OK) + else if ((ret = sr_variant_type_check(key, data)) == SR_OK) { + log_key(sdi, cg, key, SR_CONF_SET, data); ret = sdi->driver->config_set(key, data, sdi, cg); + } g_variant_unref(data); @@ -665,11 +698,13 @@ SR_API int sr_config_list(const struct sr_dev_driver *driver, else if (!driver->config_list) return SR_ERR_ARG; else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) { - if (check_key(driver, sdi, cg, key, SR_CONF_LIST) != SR_OK) + if (check_key(driver, sdi, cg, key, SR_CONF_LIST, NULL) != SR_OK) return SR_ERR_ARG; } - if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) + if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) { + log_key(sdi, cg, key, SR_CONF_LIST, *data); g_variant_ref_sink(*data); + } return ret; }