drivers: Factor out std_gvar_tuple_u64().

This commit is contained in:
Uwe Hermann 2017-07-21 23:08:47 +02:00
parent dd7a72ea69
commit a162eeb2e8
10 changed files with 29 additions and 50 deletions

View 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);

View 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)

View 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;

View 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;

View 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;

View 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);

View 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;

View 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;

View 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);

View File

@ -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,