X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fpce-322a%2Fapi.c;h=68e88b4f0b8461d258811fb19e37e8f235403f1e;hb=060df80fb354246cc309ef80927d38e37e922eb2;hp=1ab19a8d6f212e2a76794562ffe84cfb014cc6d1;hpb=53012da658ae94b245240c8a3e115723eede4c7d;p=libsigrok.git
diff --git a/src/hardware/pce-322a/api.c b/src/hardware/pce-322a/api.c
index 1ab19a8d..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"
@@ -43,13 +43,11 @@ static const uint32_t devopts[] = {
};
static const char *weight_freq[] = {
- "A",
- "C",
+ "A", "C",
};
static const char *weight_time[] = {
- "F",
- "S",
+ "F", "S",
};
static const uint64_t meas_ranges[][2] = {
@@ -60,8 +58,7 @@ static const uint64_t meas_ranges[][2] = {
};
static const char *data_sources[] = {
- "Live",
- "Memory",
+ "Live", "Memory",
};
static GSList *scan(struct sr_dev_driver *di, GSList *options)
@@ -107,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;
@@ -118,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);
@@ -142,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);
@@ -161,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,
@@ -250,7 +217,7 @@ static int config_list(uint32_t key, GVariant **data,
*data = g_variant_new_strv(ARRAY_AND_SIZE(weight_time));
break;
case SR_CONF_SPL_MEASUREMENT_RANGE:
- *data = std_gvar_tuple_array(&meas_ranges, ARRAY_SIZE(meas_ranges));
+ *data = std_gvar_tuple_array(ARRAY_AND_SIZE(meas_ranges));
break;
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_strv(ARRAY_AND_SIZE(data_sources));