]> sigrok.org Git - libsigrok.git/commitdiff
drivers: Factor out std_gvar_tuple_u64().
authorUwe Hermann <redacted>
Fri, 21 Jul 2017 21:08:47 +0000 (23:08 +0200)
committerUwe Hermann <redacted>
Mon, 31 Jul 2017 14:23:31 +0000 (16:23 +0200)
src/hardware/cem-dt-885x/api.c
src/hardware/chronovu-la/api.c
src/hardware/ikalogic-scanalogic2/api.c
src/hardware/kecheng-kc-330b/api.c
src/hardware/openbench-logic-sniffer/api.c
src/hardware/pce-322a/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/zeroplus-logic-cube/api.c
src/libsigrok-internal.h
src/std.c

index 18437ad4b1daf152795fa261f2047ce9eafb25b4..a4d4c091e7bd7a7ddf13502d4b427aa2faebe735 100644 (file)
@@ -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);
index 8456342be424aa9b7b5524a716bb99e275ebe28f..0a1a22327a2f82e266237cfbea0286e1015c1981 100644 (file)
@@ -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)
index fc6b844dbfb7a7aebf78250421ed2c3d003e68fc..5f8fc37e3f0644373cebe6d1d36dfef0979e2c4f 100644 (file)
@@ -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;
index b40b3ea2d4de5ce2e675960a4495c5dfae9f4492..d264b56acf21462ec343715cb8778d52dacfd0a3 100644 (file)
@@ -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;
index bcd11be6b6b7321ade76deb514016de99b2b7d98..db454a9f1a9577f6d627e3dca40c800d68d35238 100644 (file)
@@ -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;
index 9e45e72de27c4c2aec7086ae0bf8c909b1138634..b9ff092f34282978b94695cbc73571b9c41c398f 100644 (file)
@@ -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);
index 5cc02dc2666129ade5681bb1a3037bd4689e2b6a..8aca1ed12f844c30cec2aadabbe26013dc116712 100644 (file)
@@ -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;
index 24d033f306bcf03e82a017bc59b218c434dc939d..30ed79f50309afbfc92c756d3a08690e7856c7a2 100644 (file)
@@ -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;
index 1df5311cec776d6973462d1eb6429c210d70c70e..fd9fdb102ef9aed66bd4c04e1370d01646ea54f5 100644 (file)
@@ -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);
index fa4218e67ace8f61c61e2dd6912b632438cb0385..c910b417638f52b065fa57aba75816bb0e31fefb 100644 (file)
--- 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,