From: Uwe Hermann Date: Fri, 21 Jul 2017 21:08:47 +0000 (+0200) Subject: drivers: Factor out std_gvar_tuple_u64(). X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a162eeb2e8f23da99d1a7ca7d62dc6ad0981afc6;p=libsigrok.git drivers: Factor out std_gvar_tuple_u64(). --- diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 18437ad4..a4d4c091 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -129,7 +129,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *range[2]; uint64_t low, high; int tmp, ret; @@ -175,11 +174,8 @@ static int config_get(uint32_t key, GVariant **data, *data = g_variant_new_boolean(tmp == SR_MQFLAG_MIN); break; case SR_CONF_SPL_MEASUREMENT_RANGE: - if ((ret = cem_dt_885x_meas_range_get(sdi, &low, &high)) == SR_OK) { - range[0] = g_variant_new_uint64(low); - range[1] = g_variant_new_uint64(high); - *data = g_variant_new_tuple(range, 2); - } + if ((ret = cem_dt_885x_meas_range_get(sdi, &low, &high)) == SR_OK) + *data = std_gvar_tuple_u64(low, high); break; case SR_CONF_POWER_OFF: *data = g_variant_new_boolean(FALSE); diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 8456342b..0a1a2232 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -346,7 +346,6 @@ static int config_set(uint32_t key, GVariant *data, static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - GVariant *grange[2]; struct dev_context *devc; devc = (sdi) ? sdi->priv : NULL; @@ -362,12 +361,7 @@ static int config_list(uint32_t key, GVariant **data, case SR_CONF_LIMIT_SAMPLES: if (!devc->prof) return SR_ERR_BUG; - grange[0] = g_variant_new_uint64(0); - if (devc->prof->model == CHRONOVU_LA8) - grange[1] = g_variant_new_uint64(MAX_NUM_SAMPLES); - else - grange[1] = g_variant_new_uint64(MAX_NUM_SAMPLES / 2); - *data = g_variant_new_tuple(grange, 2); + *data = std_gvar_tuple_u64(0, (devc->prof->model == CHRONOVU_LA8) ? MAX_NUM_SAMPLES : MAX_NUM_SAMPLES / 2); break; case SR_CONF_TRIGGER_MATCH: if (!devc->prof) diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index fc6b844d..5f8fc37e 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -300,8 +300,6 @@ static int config_set(uint32_t key, GVariant *data, static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - GVariant *grange[2]; - switch (key) { case SR_CONF_DEVICE_OPTIONS: return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); @@ -312,9 +310,7 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches)); break; case SR_CONF_LIMIT_SAMPLES: - grange[0] = g_variant_new_uint64(0); - grange[1] = g_variant_new_uint64(MAX_SAMPLES); - *data = g_variant_new_tuple(grange, 2); + *data = std_gvar_tuple_u64(0, MAX_SAMPLES); break; default: return SR_ERR_NA; diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index b40b3ea2..d264b56a 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -201,7 +201,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *rational[2]; const uint64_t *si; (void)cg; @@ -213,9 +212,7 @@ static int config_get(uint32_t key, GVariant **data, break; case SR_CONF_SAMPLE_INTERVAL: si = kecheng_kc_330b_sample_intervals[devc->sample_interval]; - rational[0] = g_variant_new_uint64(si[0]); - rational[1] = g_variant_new_uint64(si[1]); - *data = g_variant_new_tuple(rational, 2); + *data = std_gvar_tuple_u64(si[0], si[1]); break; case SR_CONF_DATALOG: /* There really isn't a way to be sure the device is logging. */ @@ -351,7 +348,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_datafeed_meta meta; struct sr_config *src; struct sr_usb_dev_inst *usb; - GVariant *gvar, *rational[2]; + GVariant *gvar; const uint64_t *si; int req_len, buf_len, len, ret; unsigned char buf[9]; @@ -393,9 +390,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->stored_samples = devc->limit_samples; si = kecheng_kc_330b_sample_intervals[buf[1]]; - rational[0] = g_variant_new_uint64(si[0]); - rational[1] = g_variant_new_uint64(si[1]); - gvar = g_variant_new_tuple(rational, 2); + gvar = std_gvar_tuple_u64(si[0], si[1]); + src = sr_config_new(SR_CONF_SAMPLE_INTERVAL, gvar); packet.type = SR_DF_META; packet.payload = &meta; diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index bcd11be6..db454a9f 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -323,7 +323,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *grange[2]; int num_ols_changrp, i; switch (key) { @@ -358,12 +357,9 @@ static int config_list(uint32_t key, GVariant **data, if (devc->channel_mask & (0xff << (i * 8))) num_ols_changrp++; } - grange[0] = g_variant_new_uint64(MIN_NUM_SAMPLES); - if (num_ols_changrp) - grange[1] = g_variant_new_uint64(devc->max_samples / num_ols_changrp); - else - grange[1] = g_variant_new_uint64(MIN_NUM_SAMPLES); - *data = g_variant_new_tuple(grange, 2); + + *data = std_gvar_tuple_u64(MIN_NUM_SAMPLES, + (num_ols_changrp) ? devc->max_samples / num_ols_changrp : MIN_NUM_SAMPLES); break; default: return SR_ERR_NA; diff --git a/src/hardware/pce-322a/api.c b/src/hardware/pce-322a/api.c index 9e45e72d..b9ff092f 100644 --- a/src/hardware/pce-322a/api.c +++ b/src/hardware/pce-322a/api.c @@ -104,7 +104,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *range[2]; uint64_t low, high; uint64_t tmp; int ret; @@ -139,11 +138,8 @@ static int config_get(uint32_t key, GVariant **data, return SR_ERR; break; case SR_CONF_SPL_MEASUREMENT_RANGE: - if ((ret = pce_322a_meas_range_get(sdi, &low, &high)) == SR_OK) { - range[0] = g_variant_new_uint64(low); - range[1] = g_variant_new_uint64(high); - *data = g_variant_new_tuple(range, 2); - } + if ((ret = pce_322a_meas_range_get(sdi, &low, &high)) == SR_OK) + *data = std_gvar_tuple_u64(low, high); break; case SR_CONF_POWER_OFF: *data = g_variant_new_boolean(FALSE); diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 5cc02dc2..8aca1ed1 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -334,7 +334,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *grange[2]; int num_pols_changrp, i; switch (key) { @@ -371,12 +370,9 @@ static int config_list(uint32_t key, GVariant **data, /* 3 channel groups takes as many bytes as 4 channel groups */ if (num_pols_changrp == 3) num_pols_changrp = 4; - grange[0] = g_variant_new_uint64(MIN_NUM_SAMPLES); - if (num_pols_changrp) - grange[1] = g_variant_new_uint64(devc->max_samplebytes / num_pols_changrp); - else - grange[1] = g_variant_new_uint64(MIN_NUM_SAMPLES); - *data = g_variant_new_tuple(grange, 2); + + *data = std_gvar_tuple_u64(MIN_NUM_SAMPLES, + (num_pols_changrp) ? devc->max_samplebytes / num_pols_changrp : MIN_NUM_SAMPLES); break; default: return SR_ERR_NA; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 24d033f3..30ed79f5 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -390,7 +390,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *grange[2]; switch (key) { case SR_CONF_DEVICE_OPTIONS: @@ -417,9 +416,7 @@ static int config_list(uint32_t key, GVariant **data, if (!sdi) return SR_ERR_ARG; devc = sdi->priv; - grange[0] = g_variant_new_uint64(0); - grange[1] = g_variant_new_uint64(devc->max_sample_depth); - *data = g_variant_new_tuple(grange, 2); + *data = std_gvar_tuple_u64(0, devc->max_sample_depth); break; default: return SR_ERR_NA; diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 1df5311c..fd9fdb10 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -964,6 +964,8 @@ SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step); SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]); SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double dmin, const double dmax, const double dstep); +SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high); + SR_PRIV GVariant *std_gvar_array_i32(const int32_t *a, unsigned int n); SR_PRIV GVariant *std_gvar_array_u32(const uint32_t *a, unsigned int n); SR_PRIV GVariant *std_gvar_array_u64(const uint64_t *a, unsigned int n); diff --git a/src/std.c b/src/std.c index fa4218e6..c910b417 100644 --- a/src/std.c +++ b/src/std.c @@ -647,6 +647,16 @@ SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double min, const doubl return g_variant_builder_end(&gvb); } +SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high) +{ + GVariant *range[2]; + + range[0] = g_variant_new_uint64(low); + range[1] = g_variant_new_uint64(high); + + return g_variant_new_tuple(range, 2); +} + SR_PRIV GVariant *std_gvar_array_i32(const int32_t *a, unsigned int n) { return g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,