From: Aurelien Jacobs Date: Sun, 11 Sep 2016 17:17:34 +0000 (+0200) Subject: agilent-dmm: add support for dBm/dBV modes X-Git-Tag: libsigrok-0.5.0~204 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8f68f36bc527f47f09445bbad1779a9fa3a22159;p=libsigrok.git agilent-dmm: add support for dBm/dBV modes --- diff --git a/src/hardware/agilent-dmm/protocol.c b/src/hardware/agilent-dmm/protocol.c index 539b7428..580e9869 100644 --- a/src/hardware/agilent-dmm/protocol.c +++ b/src/hardware/agilent-dmm/protocol.c @@ -242,6 +242,14 @@ static int recv_stat_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match) s = g_match_info_fetch(match, 1); sr_spew("STAT response '%s'.", s); + /* dBm/dBV modes. */ + if ((s[2] & ~0x20) == 'M') + devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW; + else if ((s[2] & ~0x20) == 'V') + devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT; + else + devc->mode_dbm_dbv = 0; + /* Peak hold mode. */ if (s[4] == '1') devc->cur_mqflags[0] |= SR_MQFLAG_MAX; @@ -275,6 +283,14 @@ static int recv_stat_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match) else devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG); + /* dBm/dBV modes. */ + if ((s[2] & ~0x20) == 'M') + devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW; + else if ((s[2] & ~0x20) == 'V') + devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT; + else + devc->mode_dbm_dbv = 0; + /* Peak hold mode. */ if (s[4] == '4') devc->cur_mqflags[0] |= SR_MQFLAG_MAX; @@ -322,7 +338,7 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) float fvalue; const char *s; char *mstr; - int i; + int i, exp; sr_spew("FETC reply '%s'.", g_match_info_get_string(match)); devc = sdi->priv; @@ -352,6 +368,17 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) fvalue *= powf(10, devc->cur_exponent[i]); } + if (devc->cur_unit[i] == SR_UNIT_DECIBEL_MW || + devc->cur_unit[i] == SR_UNIT_DECIBEL_VOLT || + devc->cur_unit[i] == SR_UNIT_PERCENTAGE) { + mstr = g_match_info_fetch(match, 2); + if (mstr && sr_atoi(mstr, &exp) == SR_OK) { + devc->cur_digits[i] = MIN(4 - exp, devc->cur_digits[i]); + devc->cur_encoding[i] = MIN(5 - exp, devc->cur_encoding[i]); + } + g_free(mstr); + } + sr_analog_init(&analog, &encoding, &meaning, &spec, devc->cur_digits[i] - devc->cur_exponent[i]); analog.meaning->mq = devc->cur_mq[i]; @@ -519,6 +546,11 @@ static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match) devc->cur_unit[i] = SR_UNIT_VOLT; devc->cur_mqflags[i] = 0; devc->cur_exponent[i] = 0; + if (i == 0 && devc->mode_dbm_dbv) { + devc->cur_unit[i] = devc->mode_dbm_dbv; + devc->cur_digits[i] = 3; + devc->cur_encoding[i] = 4; + } if (mstr[4] == ':') { if (!strncmp(mstr + 5, "ACDC", 4)) { /* AC + DC offset */ diff --git a/src/hardware/agilent-dmm/protocol.h b/src/hardware/agilent-dmm/protocol.h index c018ed33..50fc5bdc 100644 --- a/src/hardware/agilent-dmm/protocol.h +++ b/src/hardware/agilent-dmm/protocol.h @@ -74,6 +74,7 @@ struct dev_context { int mode_tempaux; int mode_continuity; int mode_squarewave; + int mode_dbm_dbv; }; struct agdmm_job {