]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/agilent-dmm/protocol.c
agilent_dmm: Split generic part of recv_log_u128x() to recv_log().
[libsigrok.git] / src / hardware / agilent-dmm / protocol.c
index cfbb3c310be4c72efd62200dfcbf94a6d65729e4..a1823b8f7c0b3a95200e9e09816e2c17485ddae7 100644 (file)
@@ -488,7 +488,7 @@ static int send_conf(const struct sr_dev_inst *sdi)
        struct dev_context *devc = sdi->priv;
 
        /* Do not try to send CONF? for internal temperature channel. */
-       if (devc->cur_conf->index == MAX(devc->profile->nb_channels - 1, 1))
+       if (devc->cur_conf->index >= MIN(devc->profile->nb_channels, 2))
                return SR_ERR_NA;
 
        if (devc->cur_conf->index > 0)
@@ -705,16 +705,16 @@ static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match)
                devc->cur_digits[i] = 4;
                devc->cur_encoding[i] = 5;
        } else if (!strncmp(mstr, "T1", 2) || !strncmp(mstr, "T2", 2) ||
-                  !strncmp(mstr, "TEMP", 2)) {
+                  !strncmp(mstr, "TEMP", 4)) {
                devc->cur_mq[i] = SR_MQ_TEMPERATURE;
                m2 = g_match_info_fetch(match, 2);
-               if (!m2)
+               if (!m2 && devc->profile->nb_channels == 3)
                        /*
                         * TEMP without param is for secondary display (channel P2)
                         * and is identical to channel P3, so discard it.
                         */
                        devc->cur_mq[i] = -1;
-               else if (!strcmp(m2, "FAR"))
+               else if (m2 && !strcmp(m2, "FAR"))
                        devc->cur_unit[i] = SR_UNIT_FAHRENHEIT;
                else
                        devc->cur_unit[i] = SR_UNIT_CELSIUS;
@@ -742,6 +742,13 @@ static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match)
                 * an error in this mode, so don't even call it.
                 */
                devc->mode_squarewave = 1;
+       } else if (!strcmp(mstr, "NCV")) {
+               devc->cur_mq[i] = SR_MQ_VOLTAGE;
+               devc->cur_unit[i] = SR_UNIT_VOLT;
+               devc->cur_mqflags[i] = SR_MQFLAG_AC;
+               devc->cur_exponent[i] = -3;
+               devc->cur_digits[i] = -1;
+               devc->cur_encoding[i] = 0;
        } else {
                sr_dbg("Unknown first argument '%s'.", mstr);
        }
@@ -749,7 +756,7 @@ static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match)
 
        struct sr_channel *prev_conf = devc->cur_conf;
        devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf);
-       if (devc->cur_conf->index == MAX(devc->profile->nb_channels - 1, 1))
+       if (devc->cur_conf->index >= MIN(devc->profile->nb_channels, 2))
                devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf);
        if (devc->cur_conf->index > prev_conf->index)
                return JOB_AGAIN;
@@ -765,11 +772,10 @@ static int send_log(const struct sr_dev_inst *sdi)
                          source[devc->data_source - 1], devc->cur_sample);
 }
 
-static int recv_log_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
+static int recv_log(const struct sr_dev_inst *sdi, GMatchInfo *match,
+                    const int mqs[], const int units[], const int exponents[],
+                    unsigned int num_functions)
 {
-       static const int mqs[] = { SR_MQ_VOLTAGE, SR_MQ_VOLTAGE, SR_MQ_CURRENT, SR_MQ_CURRENT, SR_MQ_RESISTANCE, SR_MQ_VOLTAGE, SR_MQ_TEMPERATURE, SR_MQ_CAPACITANCE, SR_MQ_FREQUENCY, SR_MQ_DUTY_CYCLE, SR_MQ_PULSE_WIDTH, SR_MQ_VOLTAGE, SR_MQ_CURRENT, SR_MQ_CONDUCTANCE };
-       static const int units[] = { SR_UNIT_VOLT, SR_UNIT_VOLT, SR_UNIT_AMPERE, SR_UNIT_AMPERE, SR_UNIT_OHM, SR_UNIT_VOLT, SR_UNIT_CELSIUS, SR_UNIT_FARAD, SR_UNIT_HERTZ, SR_UNIT_PERCENTAGE, SR_UNIT_SECOND, SR_UNIT_DECIBEL_MW, SR_UNIT_PERCENTAGE, SR_UNIT_SIEMENS };
-       static const int exponents[] = { -6, -4, -9, -4, -3, -4, -1, -12, -3, -3, -6, -3, -2, -11 };
        struct dev_context *devc;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog analog;
@@ -787,7 +793,7 @@ static int recv_log_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
        devc = sdi->priv;
 
        mstr = g_match_info_fetch(match, 2);
-       if (sr_atoi(mstr, (int*)&function) != SR_OK || function >= ARRAY_SIZE(mqs)) {
+       if (sr_atoi(mstr, (int*)&function) != SR_OK || function >= num_functions) {
                g_free(mstr);
                sr_dbg("Invalid function.");
                return SR_ERR;
@@ -853,6 +859,15 @@ static int recv_log_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
        return JOB_LOG;
 }
 
+static int recv_log_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
+{
+       static const int mqs[] = { SR_MQ_VOLTAGE, SR_MQ_VOLTAGE, SR_MQ_CURRENT, SR_MQ_CURRENT, SR_MQ_RESISTANCE, SR_MQ_VOLTAGE, SR_MQ_TEMPERATURE, SR_MQ_CAPACITANCE, SR_MQ_FREQUENCY, SR_MQ_DUTY_CYCLE, SR_MQ_PULSE_WIDTH, SR_MQ_VOLTAGE, SR_MQ_CURRENT, SR_MQ_CONDUCTANCE };
+       static const int units[] = { SR_UNIT_VOLT, SR_UNIT_VOLT, SR_UNIT_AMPERE, SR_UNIT_AMPERE, SR_UNIT_OHM, SR_UNIT_VOLT, SR_UNIT_CELSIUS, SR_UNIT_FARAD, SR_UNIT_HERTZ, SR_UNIT_PERCENTAGE, SR_UNIT_SECOND, SR_UNIT_DECIBEL_MW, SR_UNIT_PERCENTAGE, SR_UNIT_SIEMENS };
+       static const int exponents[] = { -6, -4, -9, -4, -3, -4, -1, -12, -3, -3, -6, -3, -2, -11 };
+
+       return recv_log(sdi, match, mqs, units, exponents, ARRAY_SIZE(mqs));
+}
+
 /* This comes in whenever the rotary switch is changed to a new position.
  * We could use it to determine the major measurement mode, but we already
  * have the output of CONF? for that, which is more detailed. However
@@ -946,6 +961,7 @@ SR_PRIV const struct agdmm_recv agdmm_recvs_u128x[] = {
        { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
        { "^\"(PULS:PWID|PULS:PWID:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
        { "^\"(TEMP:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
+       { "^\"(NCV) (HIGH|LOW)\"$", recv_conf_u124x_5x },
        { "^\"(DIOD|SQU|PULS:PDUT|TEMP)\"$", recv_conf_u124x_5x },
        { "^\"((\\d{2})(\\d{5})\\d{7})\"$", recv_log_u128x },
        { "^\\*E$", recv_err },