X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fpce-322a%2Fapi.c;h=68e88b4f0b8461d258811fb19e37e8f235403f1e;hb=77b6b98d1c3790b8feb55105f243cec63418ab0f;hp=9e45e72de27c4c2aec7086ae0bf8c909b1138634;hpb=58ffcf97121453fb53e885338e23e54c7ed78659;p=libsigrok.git
diff --git a/src/hardware/pce-322a/api.c b/src/hardware/pce-322a/api.c
index 9e45e72d..68e88b4f 100644
--- a/src/hardware/pce-322a/api.c
+++ b/src/hardware/pce-322a/api.c
@@ -18,8 +18,8 @@
* along with this program. If not, see .
*/
-#include
#include
+#include
#include "protocol.h"
#define SERIALCOMM "115200/8n1"
@@ -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;
@@ -115,7 +114,7 @@ static int config_get(uint32_t key, GVariant **data,
return SR_ERR_ARG;
devc = sdi->priv;
- ret = SR_OK;
+
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
*data = g_variant_new_uint64(devc->limit_samples);
@@ -139,11 +138,10 @@ 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);
+ else
+ return ret;
break;
case SR_CONF_POWER_OFF:
*data = g_variant_new_boolean(FALSE);
@@ -158,79 +156,51 @@ static int config_get(uint32_t key, GVariant **data,
return SR_ERR_NA;
}
- return ret;
+ return SR_OK;
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
struct dev_context *devc;
- uint64_t tmp_u64, low, high;
- unsigned int i;
- int ret;
- const char *tmp_str;
+ int idx;
(void)cg;
devc = sdi->priv;
- ret = SR_OK;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
- tmp_u64 = g_variant_get_uint64(data);
- devc->limit_samples = tmp_u64;
- ret = SR_OK;
+ devc->limit_samples = g_variant_get_uint64(data);
break;
case SR_CONF_SPL_WEIGHT_FREQ:
- tmp_str = g_variant_get_string(data, NULL);
- if (!strcmp(tmp_str, "A"))
- ret = pce_322a_weight_freq_set(sdi,
- SR_MQFLAG_SPL_FREQ_WEIGHT_A);
- else if (!strcmp(tmp_str, "C"))
- ret = pce_322a_weight_freq_set(sdi,
- SR_MQFLAG_SPL_FREQ_WEIGHT_C);
- else
+ if ((idx = std_str_idx(data, ARRAY_AND_SIZE(weight_freq))) < 0)
return SR_ERR_ARG;
- break;
+ return pce_322a_weight_freq_set(sdi, (weight_freq[idx][0] == 'A') ?
+ SR_MQFLAG_SPL_FREQ_WEIGHT_A : SR_MQFLAG_SPL_FREQ_WEIGHT_C);
case SR_CONF_SPL_WEIGHT_TIME:
- tmp_str = g_variant_get_string(data, NULL);
- if (!strcmp(tmp_str, "F"))
- ret = pce_322a_weight_time_set(sdi,
- SR_MQFLAG_SPL_TIME_WEIGHT_F);
- else if (!strcmp(tmp_str, "S"))
- ret = pce_322a_weight_time_set(sdi,
- SR_MQFLAG_SPL_TIME_WEIGHT_S);
- else
+ if ((idx = std_str_idx(data, ARRAY_AND_SIZE(weight_time))) < 0)
return SR_ERR_ARG;
- break;
+ return pce_322a_weight_time_set(sdi, (weight_time[idx][0] == 'F') ?
+ SR_MQFLAG_SPL_TIME_WEIGHT_F : SR_MQFLAG_SPL_TIME_WEIGHT_S);
case SR_CONF_SPL_MEASUREMENT_RANGE:
- g_variant_get(data, "(tt)", &low, &high);
- ret = SR_ERR_ARG;
- for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
- if (meas_ranges[i][0] == low && meas_ranges[i][1] == high) {
- ret = pce_322a_meas_range_set(sdi, low, high);
- break;
- }
- }
- break;
+ if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(meas_ranges))) < 0)
+ return SR_ERR_ARG;
+ return pce_322a_meas_range_set(sdi, meas_ranges[idx][0], meas_ranges[idx][1]);
case SR_CONF_POWER_OFF:
if (g_variant_get_boolean(data))
- ret = pce_322a_power_off(sdi);
+ return pce_322a_power_off(sdi);
break;
case SR_CONF_DATA_SOURCE:
- tmp_str = g_variant_get_string(data, NULL);
- if (!strcmp(tmp_str, "Live"))
- devc->cur_data_source = DATA_SOURCE_LIVE;
- else if (!strcmp(tmp_str, "Memory"))
- devc->cur_data_source = DATA_SOURCE_MEMORY;
- else
- return SR_ERR;
+ if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0)
+ return SR_ERR_ARG;
+ devc->cur_data_source = idx;
break;
default:
- ret = SR_ERR_NA;
+ return SR_ERR_NA;
}
- return ret;
+ return SR_OK;
}
static int config_list(uint32_t key, GVariant **data,