agilent-dmm: support for submodes

This commit is contained in:
Bert Vermeulen 2012-09-08 03:06:45 +02:00
parent f45b759014
commit e6b021f377
2 changed files with 80 additions and 27 deletions

View File

@ -58,10 +58,12 @@ struct dev_context {
unsigned char buf[AGDMM_BUFSIZE]; unsigned char buf[AGDMM_BUFSIZE];
int buflen; int buflen;
int cur_mq; int cur_mq;
int cur_mq_unit; int cur_unit;
int cur_mq_flags; int cur_mqflags;
int cur_divider; int cur_divider;
int cur_acdc; int cur_acdc;
int mode_tempaux;
int mode_continuity;
}; };
struct agdmm_job { struct agdmm_job {

View File

@ -169,8 +169,44 @@ static int agdmm_stat_send(const struct sr_dev_inst *sdi)
static int agdmm_stat_recv(const struct sr_dev_inst *sdi, GMatchInfo *match) static int agdmm_stat_recv(const struct sr_dev_inst *sdi, GMatchInfo *match)
{ {
struct dev_context *devc;
char *s;
sr_spew("got stat '%s'", g_match_info_get_string(match)); devc = sdi->priv;
s = g_match_info_fetch(match, 1);
sr_spew("got stat '%s'", s);
/* Max, Min or Avg mode -- no way to tell which, so we'll
* set both flags to denote it's not a normal measurement. */
if (s[0] == '1')
devc->cur_mqflags |= SR_MQFLAG_MAX | SR_MQFLAG_MIN;
else
devc->cur_mqflags &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN);
if (s[1] == '1')
devc->cur_mqflags |= SR_MQFLAG_RELATIVE;
else
devc->cur_mqflags &= ~SR_MQFLAG_RELATIVE;
/* Triggered or auto hold modes. */
if (s[2] == '1' || s[3] == '1')
devc->cur_mqflags |= SR_MQFLAG_HOLD;
else
devc->cur_mqflags &= ~SR_MQFLAG_HOLD;
/* Temp/aux mode. */
if (s[7] == '1')
devc->mode_tempaux = TRUE;
else
devc->mode_tempaux = FALSE;
/* Continuity mode. */
if (s[16] == '1')
devc->mode_continuity = TRUE;
else
devc->mode_continuity = FALSE;
g_free(s);
return SR_OK; return SR_OK;
} }
@ -217,8 +253,8 @@ SR_PRIV int agdmm_fetc_recv(const struct sr_dev_inst *sdi, GMatchInfo *match)
memset(&analog, 0, sizeof(struct sr_datafeed_analog)); memset(&analog, 0, sizeof(struct sr_datafeed_analog));
analog.mq = devc->cur_mq; analog.mq = devc->cur_mq;
analog.unit = devc->cur_mq_unit; analog.unit = devc->cur_unit;
analog.mqflags = devc->cur_mq_flags; analog.mqflags = devc->cur_mqflags;
analog.num_samples = 1; analog.num_samples = 1;
analog.data = &fvalue; analog.data = &fvalue;
packet.type = SR_DF_ANALOG; packet.type = SR_DF_ANALOG;
@ -246,43 +282,57 @@ SR_PRIV int agdmm_conf_recv(const struct sr_dev_inst *sdi, GMatchInfo *match)
mstr = g_match_info_fetch(match, 1); mstr = g_match_info_fetch(match, 1);
if (!strcmp(mstr, "V")) { if (!strcmp(mstr, "V")) {
devc->cur_mq = SR_MQ_VOLTAGE; devc->cur_mq = SR_MQ_VOLTAGE;
devc->cur_mq_unit = SR_UNIT_VOLT; devc->cur_unit = SR_UNIT_VOLT;
devc->cur_mq_flags = 0; devc->cur_mqflags = 0;
devc->cur_divider = 0; devc->cur_divider = 0;
} else if(!strcmp(mstr, "MV")) { } else if(!strcmp(mstr, "MV")) {
devc->cur_mq = SR_MQ_VOLTAGE; if (devc->mode_tempaux) {
devc->cur_mq_unit = SR_UNIT_VOLT; devc->cur_mq = SR_MQ_TEMPERATURE;
devc->cur_mq_flags = 0; /* No way to detect whether Fahrenheit or Celcius
devc->cur_divider = 1000; * is used, so we'll just default to Celcius. */
devc->cur_unit = SR_UNIT_CELSIUS;
devc->cur_mqflags = 0;
devc->cur_divider = 0;
} else {
devc->cur_mq = SR_MQ_VOLTAGE;
devc->cur_unit = SR_UNIT_VOLT;
devc->cur_mqflags = 0;
devc->cur_divider = 1000;
}
} else if(!strcmp(mstr, "A")) { } else if(!strcmp(mstr, "A")) {
devc->cur_mq = SR_MQ_CURRENT; devc->cur_mq = SR_MQ_CURRENT;
devc->cur_mq_unit = SR_UNIT_AMPERE; devc->cur_unit = SR_UNIT_AMPERE;
devc->cur_mq_flags = 0; devc->cur_mqflags = 0;
devc->cur_divider = 0; devc->cur_divider = 0;
} else if(!strcmp(mstr, "UA")) { } else if(!strcmp(mstr, "UA")) {
devc->cur_mq = SR_MQ_CURRENT; devc->cur_mq = SR_MQ_CURRENT;
devc->cur_mq_unit = SR_UNIT_AMPERE; devc->cur_unit = SR_UNIT_AMPERE;
devc->cur_mq_flags = 0; devc->cur_mqflags = 0;
devc->cur_divider = 1000000; devc->cur_divider = 1000000;
} else if(!strcmp(mstr, "FREQ")) { } else if(!strcmp(mstr, "FREQ")) {
devc->cur_mq = SR_MQ_FREQUENCY; devc->cur_mq = SR_MQ_FREQUENCY;
devc->cur_mq_unit = SR_UNIT_HERTZ; devc->cur_unit = SR_UNIT_HERTZ;
devc->cur_mq_flags = 0; devc->cur_mqflags = 0;
devc->cur_divider = 0; devc->cur_divider = 0;
} else if(!strcmp(mstr, "RES")) { } else if(!strcmp(mstr, "RES")) {
devc->cur_mq = SR_MQ_RESISTANCE; if (devc->mode_continuity) {
devc->cur_mq_unit = SR_UNIT_OHM; devc->cur_mq = SR_MQ_CONTINUITY;
devc->cur_mq_flags = 0; devc->cur_unit = SR_UNIT_BOOLEAN;
} else {
devc->cur_mq = SR_MQ_RESISTANCE;
devc->cur_unit = SR_UNIT_OHM;
}
devc->cur_mqflags = 0;
devc->cur_divider = 0; devc->cur_divider = 0;
} else if(!strcmp(mstr, "CAP")) { } else if(!strcmp(mstr, "CAP")) {
devc->cur_mq = SR_MQ_CAPACITANCE; devc->cur_mq = SR_MQ_CAPACITANCE;
devc->cur_mq_unit = SR_UNIT_FARAD; devc->cur_unit = SR_UNIT_FARAD;
devc->cur_mq_flags = 0; devc->cur_mqflags = 0;
devc->cur_divider = 0; devc->cur_divider = 0;
} else if(!strcmp(mstr, "DIOD")) { } else if(!strcmp(mstr, "DIOD")) {
devc->cur_mq = SR_MQ_VOLTAGE; devc->cur_mq = SR_MQ_VOLTAGE;
devc->cur_mq_unit = SR_UNIT_VOLT; devc->cur_unit = SR_UNIT_VOLT;
devc->cur_mq_flags = SR_MQFLAG_DIODE; devc->cur_mqflags = SR_MQFLAG_DIODE;
devc->cur_divider = 0; devc->cur_divider = 0;
} else } else
sr_dbg("agilent-dmm: unknown first argument"); sr_dbg("agilent-dmm: unknown first argument");
@ -292,13 +342,14 @@ SR_PRIV int agdmm_conf_recv(const struct sr_dev_inst *sdi, GMatchInfo *match)
mstr = g_match_info_fetch(match, 1); mstr = g_match_info_fetch(match, 1);
/* Third value, if present, is always AC or DC. */ /* Third value, if present, is always AC or DC. */
if (!strcmp(mstr, "AC")) if (!strcmp(mstr, "AC"))
devc->cur_acdc = 1; devc->cur_mqflags |= SR_MQFLAG_AC;
else if (!strcmp(mstr, "DC")) else if (!strcmp(mstr, "DC"))
devc->cur_acdc = 2; devc->cur_mqflags |= SR_MQFLAG_DC;
else else
sr_dbg("agilent-dmm: unknown third argument"); sr_dbg("agilent-dmm: unknown third argument");
g_free(mstr); g_free(mstr);
} } else
devc->cur_mqflags &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC);
return SR_OK; return SR_OK;
} }