The automatic selections of the measured quantity and equivalent circuit
model are more part of the configuration of the meter than attributes
of the measurement result. To reflect this, model them as config keys
instead of mqflags. This allows a driver that supports remote control to
implement 'set' method for them and has the additional benefit of saving
two flag bits.
---
include/libsigrok/libsigrok.h | 10 ++--
src/lcr/es51919.c | 132 +++++++++++++++++++++++++++++++++++++++---
src/output/analog.c | 4 --
3 files changed, 129 insertions(+), 17 deletions(-)
diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h
index 5a5f9ee..f532f37 100644
--- a/include/libsigrok/libsigrok.h
+++ b/include/libsigrok/libsigrok.h
@@ -340,10 +340,6 @@ enum sr_mqflag {
SR_MQFLAG_AVG = 0x40000,
/** Reference value shown. */
SR_MQFLAG_REFERENCE = 0x80000,
- /** Device selects the measured quantity automatically. */
- SR_MQFLAG_AUTOMQ = 0x100000,
- /** Device selects the measurement model automatically. */
- SR_MQFLAG_AUTOMODEL = 0x200000,
};
enum sr_trigger_matches {
@@ -815,6 +811,12 @@ enum sr_configkey {
/** Output frequency in Hz. */
SR_CONF_OUTPUT_FREQUENCY,
+ /** Measured quantity. */
+ SR_CONF_MEASURED_QUANTITY,
+
+ /** Equivalent circuit model. */
+ SR_CONF_EQUIV_CIRCUIT_MODEL,
+
/*--- Special stuff -------------------------------------------------*/
/** Scan options supported by the driver. */
diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c
index 5173ed6..69e9ae4 100644
--- a/src/lcr/es51919.c
+++ b/src/lcr/es51919.c
@@ -393,6 +393,14 @@ static const uint64_t frequencies[] = {
100, 120, 1000, 10000, 100000, 0,
};
+static const char *const quantities[] = {
+ "AUTO", "INDUCTANCE", "CAPACITANCE", "RESISTANCE",
+};
+
+static const char *const models[] = {
+ "AUTO", "PARALLEL", "SERIES",
+};
+
/** Private, per-device-instance driver context. */
struct dev_context {
/** Opaque pointer passed in by the frontend. */
@@ -409,6 +417,12 @@ struct dev_context {
/** The frequency of the test signal (index to frequencies[]). */
unsigned int freq;
+
+ /** Measured primary quantity (index to quantities[]). */
+ unsigned int quant;
+
+ /** Equivalent circuit model (index to models[]). */
+ unsigned int model;
};
static int parse_mq(const uint8_t *buf, int is_secondary, int is_parallel)
@@ -499,10 +513,6 @@ static void parse_measurement(const uint8_t *pkt, float
*floatval,
analog->mqflags |= SR_MQFLAG_HOLD;
if (pkt[2] & 0x02)
analog->mqflags |= SR_MQFLAG_REFERENCE;
- if (pkt[2] & 0x20)
- analog->mqflags |= SR_MQFLAG_AUTOMQ;
- if (pkt[2] & 0x40)
- analog->mqflags |= SR_MQFLAG_AUTOMODEL;
} else {
if (pkt[2] & 0x04)
analog->mqflags |= SR_MQFLAG_RELATIVE;
@@ -537,6 +547,36 @@ static unsigned int parse_frequency(const uint8_t *pkt)
return freq;
}
+static unsigned int parse_quantity(const uint8_t *pkt)
+{
+ if (pkt[2] & 0x20)
+ return 0; /* "AUTO" */
+
+ switch (parse_mq(pkt + 5, 0, 0)) {
+ case SR_MQ_SERIES_INDUCTANCE:
+ return 1; /* "INDUCTANCE" */
+ case SR_MQ_SERIES_CAPACITANCE:
+ return 2; /* "CAPACITANCE" */
+ case SR_MQ_SERIES_RESISTANCE:
+ case SR_MQ_RESISTANCE:
+ return 3; /* "RESISTANCE" */
+ default:
+ sr_err("Invalid primary quantity.");
+ }
+
+ return 0;
+}
+
+static unsigned int parse_model(const uint8_t *pkt)
+{
+ if ((pkt[2] & 0x40) || parse_mq(pkt + 5, 0, 0) == SR_MQ_RESISTANCE)
+ return 0; /* "AUTO" */
+ else if (pkt[2] & 0x80)
+ return 1; /* "PARALLEL" */
+ else
+ return 2; /* "SERIES" */
+}
+
static gboolean packet_valid(const uint8_t *pkt)
{
/*
@@ -572,21 +612,77 @@ static int send_frequency_update(struct sr_dev_inst *sdi,
unsigned int freq)
return ret;
}
+static int send_quantity_update(struct sr_dev_inst *sdi, unsigned int quant)
+{
+ struct sr_config *cfg;
+ struct dev_context *devc;
+ int ret;
+
+ devc = sdi->priv;
+
+ cfg = sr_config_new(SR_CONF_MEASURED_QUANTITY,
+ g_variant_new_string(quantities[quant]));
+
+ if (!cfg)
+ return SR_ERR;
+
+ ret = send_config_update(devc->cb_data, cfg);
+ sr_config_free(cfg);
+
+ return ret;
+}
+
+static int send_model_update(struct sr_dev_inst *sdi, unsigned int model)
+{
+ struct sr_config *cfg;
+ struct dev_context *devc;
+ int ret;
+
+ devc = sdi->priv;
+
+ cfg = sr_config_new(SR_CONF_EQUIV_CIRCUIT_MODEL,
+ g_variant_new_string(models[model]));
+
+ if (!cfg)
+ return SR_ERR;
+
+ ret = send_config_update(devc->cb_data, cfg);
+ sr_config_free(cfg);
+
+ return ret;
+}
+
static void handle_packet(struct sr_dev_inst *sdi, const uint8_t *pkt)
{
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
struct dev_context *devc;
- unsigned int freq;
+ unsigned int val;
float floatval;
int count;
devc = sdi->priv;
- freq = parse_frequency(pkt);
- if (freq != devc->freq) {
- if (send_frequency_update(sdi, freq) == SR_OK)
- devc->freq = freq;
+ val = parse_frequency(pkt);
+ if (val != devc->freq) {
+ if (send_frequency_update(sdi, val) == SR_OK)
+ devc->freq = val;
+ else
+ return;
+ }
+
+ val = parse_quantity(pkt);
+ if (val != devc->quant) {
+ if (send_quantity_update(sdi, val) == SR_OK)
+ devc->quant = val;
+ else
+ return;
+ }
+
+ val = parse_model(pkt);
+ if (val != devc->model) {
+ if (send_model_update(sdi, val) == SR_OK)
+ devc->model = val;
else
return;
}
@@ -741,6 +837,8 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList
*options,
goto scan_cleanup;
devc->freq = -1;
+ devc->quant = -1;
+ devc->model = -1;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
@@ -777,6 +875,12 @@ SR_PRIV int es51919_serial_config_get(uint32_t key,
GVariant **data,
case SR_CONF_OUTPUT_FREQUENCY:
*data = g_variant_new_uint64(frequencies[devc->freq]);
break;
+ case SR_CONF_MEASURED_QUANTITY:
+ *data = g_variant_new_string(quantities[devc->quant]);
+ break;
+ case SR_CONF_EQUIV_CIRCUIT_MODEL:
+ *data = g_variant_new_string(models[devc->model]);
+ break;
default:
sr_spew("%s: Unsupported key %u", __func__, key);
return SR_ERR_NA;
@@ -827,6 +931,8 @@ static const uint32_t devopts[] = {
SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_SET,
SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET | SR_CONF_LIST,
+ SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_LIST,
+ SR_CONF_EQUIV_CIRCUIT_MODEL | SR_CONF_GET | SR_CONF_LIST,
};
static const struct std_opt_desc opts = {
@@ -849,6 +955,14 @@ SR_PRIV int es51919_serial_config_list(uint32_t key,
GVariant **data,
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
frequencies, ARRAY_SIZE(frequencies), sizeof(uint64_t));
break;
+ case SR_CONF_MEASURED_QUANTITY:
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_STRING,
+ quantities, ARRAY_SIZE(quantities), sizeof(char *));
+ break;
+ case SR_CONF_EQUIV_CIRCUIT_MODEL:
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_STRING,
+ models, ARRAY_SIZE(models), sizeof(char *));
+ break;
default:
sr_spew("%s: Unsupported key %u", __func__, key);
return SR_ERR_NA;
diff --git a/src/output/analog.c b/src/output/analog.c
index f984bc1..4f5acd6 100644
--- a/src/output/analog.c
+++ b/src/output/analog.c
@@ -221,10 +221,6 @@ static void fancyprint(int unit, int mqflags, float value,
GString *out)
g_string_append_printf(out, " AVG");
if (mqflags & SR_MQFLAG_REFERENCE)
g_string_append_printf(out, " REF");
- if (mqflags & SR_MQFLAG_AUTOMQ)
- g_string_append_printf(out, " AUTOMQ");
- if (mqflags & SR_MQFLAG_AUTOMODEL)
- g_string_append_printf(out, " AUTOMODEL");
g_string_append_c(out, '\n');
}
--
2.1.1
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel