]> sigrok.org Git - libsigrok.git/commitdiff
scpi-dmm: return MQ table entry to "get MQ" routine callers
authorGerhard Sittig <redacted>
Sat, 17 Nov 2018 18:43:38 +0000 (19:43 +0100)
committerGerhard Sittig <redacted>
Sat, 17 Nov 2018 19:19:13 +0000 (20:19 +0100)
The "get MQ" helper routine communicates SCPI responses and translates
them to internal "MQ and flag" values. Optionally return the MQ table
entry reference to callers, so they don't have to repeat the table
lookup when the function's default precision is required, or should
future "start acquisition" requests need to refer to the meter's current
function.

src/hardware/scpi-dmm/api.c
src/hardware/scpi-dmm/protocol.c
src/hardware/scpi-dmm/protocol.h

index 009cb2ecb22140ce2bc73c48a6bb5750bde7cc28..0bb5bcba6418eda8ac9bcdfd451e7cde33974ab0 100644 (file)
@@ -191,7 +191,7 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_LIMIT_MSEC:
                return sr_sw_limits_config_get(&devc->limits, key, data);
        case SR_CONF_MEASURED_QUANTITY:
-               ret = scpi_dmm_get_mq(sdi, &mq, &mqflag, NULL);
+               ret = scpi_dmm_get_mq(sdi, &mq, &mqflag, NULL, NULL);
                if (ret != SR_OK)
                        return ret;
                arr[0] = g_variant_new_uint32(mq);
@@ -276,13 +276,14 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct sr_scpi_dev_inst *scpi;
        struct dev_context *devc;
        int ret;
+       const struct mqopt_item *item;
        const char *command;
 
        scpi = sdi->conn;
        devc = sdi->priv;
 
        ret = scpi_dmm_get_mq(sdi, &devc->start_acq_mq.curr_mq,
-               &devc->start_acq_mq.curr_mqflag, NULL);
+               &devc->start_acq_mq.curr_mqflag, NULL, &item);
        if (ret != SR_OK)
                return ret;
 
index 08c79b4a19be39bcffaf619b5e10c8c2e8ed5dbf..954e6c98feaf983be9c269508bfba88d6c291135 100644 (file)
@@ -70,7 +70,8 @@ SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_text(
 }
 
 SR_PRIV int scpi_dmm_get_mq(const struct sr_dev_inst *sdi,
-       enum sr_mq *mq, enum sr_mqflag *flag, char **rsp)
+       enum sr_mq *mq, enum sr_mqflag *flag, char **rsp,
+       const struct mqopt_item **mqitem)
 {
        struct dev_context *devc;
        const char *command;
@@ -86,6 +87,8 @@ SR_PRIV int scpi_dmm_get_mq(const struct sr_dev_inst *sdi,
                *flag = 0;
        if (rsp)
                *rsp = NULL;
+       if (mqitem)
+               *mqitem = NULL;
 
        command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_QUERY_FUNC);
        if (!command || !*command)
@@ -108,6 +111,8 @@ SR_PRIV int scpi_dmm_get_mq(const struct sr_dev_inst *sdi,
                        *mq = item->mq;
                if (flag)
                        *flag = item->mqflag;
+               if (mqitem)
+                       *mqitem = item;
                ret = SR_OK;
        }
 
@@ -173,7 +178,7 @@ SR_PRIV int scpi_dmm_get_meas_agilent(const struct sr_dev_inst *sdi, size_t ch)
         * Get the meter's current mode, keep the response around.
         * Skip the measurement if the mode is uncertain.
         */
-       ret = scpi_dmm_get_mq(sdi, &mq, &mqflag, &mode_response);
+       ret = scpi_dmm_get_mq(sdi, &mq, &mqflag, &mode_response, &item);
        if (ret != SR_OK) {
                g_free(mode_response);
                return ret;
@@ -200,17 +205,14 @@ SR_PRIV int scpi_dmm_get_meas_agilent(const struct sr_dev_inst *sdi, size_t ch)
                snprintf(prec_text, sizeof(prec_text),
                        "%s", fields[count - 1]);
                p = prec_text;
+       } else if (!item) {
+               p = NULL;
+       } else if (item->default_precision == NO_DFLT_PREC) {
+               p = NULL;
        } else {
-               item = scpi_dmm_lookup_mq_number(sdi, mq, mqflag);
-               if (!item) {
-                       p = NULL;
-               } else if (item->default_precision == NO_DFLT_PREC) {
-                       p = NULL;
-               } else {
-                       snprintf(prec_text, sizeof(prec_text),
-                               "1e%d", item->default_precision);
-                       p = prec_text;
-               }
+               snprintf(prec_text, sizeof(prec_text),
+                       "1e%d", item->default_precision);
+               p = prec_text;
        }
        g_strfreev(fields);
 
index dbca1bcf4e3cffd305a490c4901588858c91a3d6..531ca474ad5d5354ad78ef465a42403d61d85815 100644 (file)
@@ -90,7 +90,8 @@ SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_number(
 SR_PRIV const struct mqopt_item *scpi_dmm_lookup_mq_text(
        const struct sr_dev_inst *sdi, const char *text);
 SR_PRIV int scpi_dmm_get_mq(const struct sr_dev_inst *sdi,
-       enum sr_mq *mq, enum sr_mqflag *flag, char **rsp);
+       enum sr_mq *mq, enum sr_mqflag *flag, char **rsp,
+       const struct mqopt_item **mqitem);
 SR_PRIV int scpi_dmm_set_mq(const struct sr_dev_inst *sdi,
        enum sr_mq mq, enum sr_mqflag flag);
 SR_PRIV int scpi_dmm_get_meas_agilent(const struct sr_dev_inst *sdi, size_t ch);