2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <libsigrok/libsigrok.h>
28 #include "libsigrok-internal.h"
31 #define JOB_TIMEOUT 300
33 #define INFINITE_INTERVAL INT_MAX
34 #define SAMPLERATE_INTERVAL -1
36 static const struct agdmm_job *job_current(const struct dev_context *devc)
38 return &devc->profile->jobs[devc->current_job];
41 static void job_done(struct dev_context *devc)
43 devc->job_running = FALSE;
46 static void job_again(struct dev_context *devc)
48 devc->job_again = TRUE;
51 static gboolean job_is_running(const struct dev_context *devc)
53 return devc->job_running;
56 static gboolean job_in_interval(const struct dev_context *devc)
58 int64_t job_start = devc->jobs_start[devc->current_job];
59 int64_t now = g_get_monotonic_time() / 1000;
60 int interval = job_current(devc)->interval;
61 if (interval == SAMPLERATE_INTERVAL)
62 interval = 1000 / devc->cur_samplerate;
63 return (now - job_start) < interval || interval == INFINITE_INTERVAL;
66 static gboolean job_has_timeout(const struct dev_context *devc)
68 int64_t job_start = devc->jobs_start[devc->current_job];
69 int64_t now = g_get_monotonic_time() / 1000;
70 return job_is_running(devc) && (now - job_start) > JOB_TIMEOUT;
73 static const struct agdmm_job *job_next(struct dev_context *devc)
75 int current_job = devc->current_job;
78 if (!job_current(devc)->send)
79 devc->current_job = 0;
80 } while(job_in_interval(devc) && devc->current_job != current_job);
81 return job_current(devc);
84 static void job_run_again(const struct sr_dev_inst *sdi)
86 struct dev_context *devc = sdi->priv;
87 devc->job_again = FALSE;
88 devc->job_running = TRUE;
89 if (job_current(devc)->send(sdi) == SR_ERR_NA)
93 static void job_run(const struct sr_dev_inst *sdi)
95 struct dev_context *devc = sdi->priv;
96 int64_t now = g_get_monotonic_time() / 1000;
97 devc->jobs_start[devc->current_job] = now;
101 static void dispatch(const struct sr_dev_inst *sdi)
103 struct dev_context *devc = sdi->priv;
105 if (devc->job_again) {
110 if (!job_is_running(devc))
112 else if (job_has_timeout(devc))
115 if (!job_is_running(devc) && !job_in_interval(devc))
119 static void receive_line(const struct sr_dev_inst *sdi)
121 struct dev_context *devc;
122 const struct agdmm_recv *recvs, *recv;
130 while (devc->buflen) {
131 if (*(devc->buf + devc->buflen - 1) == '\r'
132 || *(devc->buf + devc->buflen - 1) == '\n')
133 *(devc->buf + --devc->buflen) = '\0';
137 sr_spew("Received '%s'.", devc->buf);
140 recvs = devc->profile->recvs;
141 for (i = 0; (&recvs[i])->recv_regex; i++) {
142 reg = g_regex_new((&recvs[i])->recv_regex, 0, 0, NULL);
143 if (g_regex_match(reg, (char *)devc->buf, 0, &match)) {
147 g_match_info_unref(match);
151 enum job_type type = recv->recv(sdi, match);
152 if (type == job_current(devc)->type)
154 else if (type == JOB_AGAIN)
156 g_match_info_unref(match);
159 sr_dbg("Unknown line '%s'.", devc->buf);
161 /* Done with this. */
165 SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data)
167 struct sr_dev_inst *sdi;
168 struct dev_context *devc;
169 struct sr_serial_dev_inst *serial;
174 if (!(sdi = cb_data))
177 if (!(devc = sdi->priv))
181 if (revents == G_IO_IN) {
182 /* Serial data arrived. */
183 while (AGDMM_BUFSIZE - devc->buflen - 1 > 0) {
184 len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1);
188 *(devc->buf + devc->buflen) = '\0';
189 if (*(devc->buf + devc->buflen - 1) == '\n') {
199 if (sr_sw_limits_check(&devc->limits))
200 sdi->driver->dev_acquisition_stop(sdi);
205 static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd, ...)
207 struct sr_serial_dev_inst *serial;
214 vsnprintf(buf, sizeof(buf) - 3, cmd, args);
216 sr_spew("Sending '%s'.", buf);
217 if (!strncmp(buf, "*IDN?", 5))
220 strcat(buf, "\n\r\n");
221 if (serial_write_blocking(serial, buf, strlen(buf), SERIAL_WRITE_TIMEOUT_MS) < (int)strlen(buf)) {
222 sr_err("Failed to send.");
229 static int send_stat(const struct sr_dev_inst *sdi)
231 return agdmm_send(sdi, "STAT?");
234 static int recv_stat_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match)
236 struct dev_context *devc;
240 s = g_match_info_fetch(match, 1);
241 sr_spew("STAT response '%s'.", s);
243 /* Max, Min or Avg mode -- no way to tell which, so we'll
244 * set both flags to denote it's not a normal measurement. */
246 devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN;
248 devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN);
251 devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE;
253 devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE;
255 /* Triggered or auto hold modes. */
256 if (s[2] == '1' || s[3] == '1')
257 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
259 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
263 devc->mode_tempaux = TRUE;
265 devc->mode_tempaux = FALSE;
267 /* Continuity mode. */
269 devc->mode_continuity = TRUE;
271 devc->mode_continuity = FALSE;
278 static int recv_stat_u124x(const struct sr_dev_inst *sdi, GMatchInfo *match)
280 struct dev_context *devc;
284 s = g_match_info_fetch(match, 1);
285 sr_spew("STAT response '%s'.", s);
287 /* Max, Min or Avg mode -- no way to tell which, so we'll
288 * set both flags to denote it's not a normal measurement. */
290 devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN;
292 devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN);
295 devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE;
297 devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE;
301 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
303 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
310 static int recv_stat_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match)
312 struct dev_context *devc;
316 s = g_match_info_fetch(match, 1);
317 sr_spew("STAT response '%s'.", s);
320 if ((s[2] & ~0x20) == 'M')
321 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW;
322 else if ((s[2] & ~0x20) == 'V')
323 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT;
325 devc->mode_dbm_dbv = 0;
327 /* Peak hold mode. */
329 devc->cur_mqflags[0] |= SR_MQFLAG_MAX;
331 devc->cur_mqflags[0] &= ~SR_MQFLAG_MAX;
333 /* Triggered hold mode. */
335 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
337 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
344 static int recv_stat_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
346 struct dev_context *devc;
350 s = g_match_info_fetch(match, 1);
351 sr_spew("STAT response '%s'.", s);
353 /* Max, Min or Avg mode -- no way to tell which, so we'll
354 * set both flags to denote it's not a normal measurement. */
356 devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG;
358 devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG);
361 if ((s[2] & ~0x20) == 'M')
362 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW;
363 else if ((s[2] & ~0x20) == 'V')
364 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT;
366 devc->mode_dbm_dbv = 0;
368 /* Peak hold mode. */
370 devc->cur_mqflags[0] |= SR_MQFLAG_MAX;
372 devc->cur_mqflags[0] &= ~SR_MQFLAG_MAX;
376 devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE;
378 devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE;
380 /* Triggered or auto hold modes. */
381 if (s[7] == '1' || s[11] == '1')
382 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
384 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
391 static int send_fetc(const struct sr_dev_inst *sdi)
393 struct dev_context *devc = sdi->priv;
395 if (devc->mode_squarewave)
398 if (devc->cur_channel->index > 0)
399 return agdmm_send(sdi, "FETC? @%d", devc->cur_channel->index + 1);
401 return agdmm_send(sdi, "FETC?");
404 static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match)
406 struct dev_context *devc;
407 struct sr_datafeed_packet packet;
408 struct sr_datafeed_analog analog;
409 struct sr_analog_encoding encoding;
410 struct sr_analog_meaning meaning;
411 struct sr_analog_spec spec;
417 sr_spew("FETC reply '%s'.", g_match_info_get_string(match));
419 i = devc->cur_channel->index;
421 if (devc->cur_mq[i] == -1)
422 /* This detects when channel P2 is reporting TEMP as an identical
423 * copy of channel P3. In this case, we just skip P2. */
426 s = g_match_info_get_string(match);
427 if (!strcmp(s, "-9.90000000E+37") || !strcmp(s, "+9.90000000E+37")) {
428 /* An invalid measurement shows up on the display as "O.L", but
429 * comes through like this. Since comparing 38-digit floats
430 * is rather problematic, we'll cut through this here. */
433 mstr = g_match_info_fetch(match, 1);
434 if (sr_atof_ascii(mstr, &fvalue) != SR_OK) {
436 sr_dbg("Invalid float.");
440 if (devc->cur_exponent[i] != 0)
441 fvalue *= powf(10, devc->cur_exponent[i]);
444 if (devc->cur_unit[i] == SR_UNIT_DECIBEL_MW ||
445 devc->cur_unit[i] == SR_UNIT_DECIBEL_VOLT ||
446 devc->cur_unit[i] == SR_UNIT_PERCENTAGE) {
447 mstr = g_match_info_fetch(match, 2);
448 if (mstr && sr_atoi(mstr, &exp) == SR_OK) {
449 devc->cur_digits[i] = MIN(4 - exp, devc->cur_digits[i]);
450 devc->cur_encoding[i] = MIN(5 - exp, devc->cur_encoding[i]);
455 sr_analog_init(&analog, &encoding, &meaning, &spec,
456 devc->cur_digits[i] - devc->cur_exponent[i]);
457 analog.meaning->mq = devc->cur_mq[i];
458 analog.meaning->unit = devc->cur_unit[i];
459 analog.meaning->mqflags = devc->cur_mqflags[i];
460 analog.meaning->channels = g_slist_append(NULL, devc->cur_channel);
461 analog.num_samples = 1;
462 analog.data = &fvalue;
463 encoding.digits = devc->cur_encoding[i] - devc->cur_exponent[i];
464 packet.type = SR_DF_ANALOG;
465 packet.payload = &analog;
466 sr_session_send(sdi, &packet);
467 g_slist_free(analog.meaning->channels);
469 sr_sw_limits_update_samples_read(&devc->limits, 1);
472 struct sr_channel *prev_chan = devc->cur_channel;
473 devc->cur_channel = sr_next_enabled_channel(sdi, devc->cur_channel);
474 if (devc->cur_channel->index > prev_chan->index)
480 static int send_conf(const struct sr_dev_inst *sdi)
482 struct dev_context *devc = sdi->priv;
484 /* Do not try to send CONF? for internal temperature channel. */
485 if (devc->cur_conf->index == MAX(devc->profile->nb_channels - 1, 1))
488 if (devc->cur_conf->index > 0)
489 return agdmm_send(sdi, "CONF? @%d", devc->cur_conf->index + 1);
491 return agdmm_send(sdi, "CONF?");
494 static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match)
496 struct dev_context *devc;
500 sr_spew("CONF? response '%s'.", g_match_info_get_string(match));
502 i = devc->cur_conf->index;
504 rstr = g_match_info_fetch(match, 2);
506 sr_atoi(rstr, &resolution);
509 mstr = g_match_info_fetch(match, 1);
510 if (!strcmp(mstr, "V")) {
511 devc->cur_mq[i] = SR_MQ_VOLTAGE;
512 devc->cur_unit[i] = SR_UNIT_VOLT;
513 devc->cur_mqflags[i] = 0;
514 devc->cur_exponent[i] = 0;
515 devc->cur_digits[i] = 4 - resolution;
516 } else if (!strcmp(mstr, "MV")) {
517 if (devc->mode_tempaux) {
518 devc->cur_mq[i] = SR_MQ_TEMPERATURE;
519 /* No way to detect whether Fahrenheit or Celsius
520 * is used, so we'll just default to Celsius. */
521 devc->cur_unit[i] = SR_UNIT_CELSIUS;
522 devc->cur_mqflags[i] = 0;
523 devc->cur_exponent[i] = 0;
524 devc->cur_digits[i] = 1;
526 devc->cur_mq[i] = SR_MQ_VOLTAGE;
527 devc->cur_unit[i] = SR_UNIT_VOLT;
528 devc->cur_mqflags[i] = 0;
529 devc->cur_exponent[i] = -3;
530 devc->cur_digits[i] = 5 - resolution;
532 } else if (!strcmp(mstr, "A")) {
533 devc->cur_mq[i] = SR_MQ_CURRENT;
534 devc->cur_unit[i] = SR_UNIT_AMPERE;
535 devc->cur_mqflags[i] = 0;
536 devc->cur_exponent[i] = 0;
537 devc->cur_digits[i] = 3 - resolution;
538 } else if (!strcmp(mstr, "UA")) {
539 devc->cur_mq[i] = SR_MQ_CURRENT;
540 devc->cur_unit[i] = SR_UNIT_AMPERE;
541 devc->cur_mqflags[i] = 0;
542 devc->cur_exponent[i] = -6;
543 devc->cur_digits[i] = 8 - resolution;
544 } else if (!strcmp(mstr, "FREQ")) {
545 devc->cur_mq[i] = SR_MQ_FREQUENCY;
546 devc->cur_unit[i] = SR_UNIT_HERTZ;
547 devc->cur_mqflags[i] = 0;
548 devc->cur_exponent[i] = 0;
549 devc->cur_digits[i] = 2 - resolution;
550 } else if (!strcmp(mstr, "RES")) {
551 if (devc->mode_continuity) {
552 devc->cur_mq[i] = SR_MQ_CONTINUITY;
553 devc->cur_unit[i] = SR_UNIT_BOOLEAN;
555 devc->cur_mq[i] = SR_MQ_RESISTANCE;
556 devc->cur_unit[i] = SR_UNIT_OHM;
558 devc->cur_mqflags[i] = 0;
559 devc->cur_exponent[i] = 0;
560 devc->cur_digits[i] = 1 - resolution;
561 } else if (!strcmp(mstr, "DIOD")) {
562 devc->cur_mq[i] = SR_MQ_VOLTAGE;
563 devc->cur_unit[i] = SR_UNIT_VOLT;
564 devc->cur_mqflags[i] = SR_MQFLAG_DIODE;
565 devc->cur_exponent[i] = 0;
566 devc->cur_digits[i] = 3;
567 } else if (!strcmp(mstr, "CAP")) {
568 devc->cur_mq[i] = SR_MQ_CAPACITANCE;
569 devc->cur_unit[i] = SR_UNIT_FARAD;
570 devc->cur_mqflags[i] = 0;
571 devc->cur_exponent[i] = 0;
572 devc->cur_digits[i] = 9 - resolution;
574 sr_dbg("Unknown first argument.");
577 /* This is based on guess, supposing similarity with other models. */
578 devc->cur_encoding[i] = devc->cur_digits[i] + 1;
580 if (g_match_info_get_match_count(match) == 4) {
581 mstr = g_match_info_fetch(match, 3);
582 /* Third value, if present, is always AC or DC. */
583 if (!strcmp(mstr, "AC")) {
584 devc->cur_mqflags[i] |= SR_MQFLAG_AC;
585 if (devc->cur_mq[i] == SR_MQ_VOLTAGE)
586 devc->cur_mqflags[i] |= SR_MQFLAG_RMS;
587 } else if (!strcmp(mstr, "DC")) {
588 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
590 sr_dbg("Unknown first argument '%s'.", mstr);
594 devc->cur_mqflags[i] &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC);
599 static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match)
601 struct dev_context *devc;
602 char *mstr, *rstr, *m2;
605 sr_spew("CONF? response '%s'.", g_match_info_get_string(match));
607 i = devc->cur_conf->index;
609 devc->mode_squarewave = 0;
611 rstr = g_match_info_fetch(match, 4);
612 if (rstr && sr_atoi(rstr, &resolution) == SR_OK) {
613 devc->cur_digits[i] = -resolution;
614 devc->cur_encoding[i] = -resolution + 1;
618 mstr = g_match_info_fetch(match, 1);
619 if (!strncmp(mstr, "VOLT", 4)) {
620 devc->cur_mq[i] = SR_MQ_VOLTAGE;
621 devc->cur_unit[i] = SR_UNIT_VOLT;
622 devc->cur_mqflags[i] = 0;
623 devc->cur_exponent[i] = 0;
624 if (i == 0 && devc->mode_dbm_dbv) {
625 devc->cur_unit[i] = devc->mode_dbm_dbv;
626 devc->cur_digits[i] = 3;
627 devc->cur_encoding[i] = 4;
629 if (mstr[4] == ':') {
630 if (!strncmp(mstr + 5, "ACDC", 4)) {
632 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS;
633 } else if (!strncmp(mstr + 5, "AC", 2)) {
634 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
635 } else if (!strncmp(mstr + 5, "DC", 2)) {
636 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
639 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
640 } else if (!strncmp(mstr, "CURR", 4)) {
641 devc->cur_mq[i] = SR_MQ_CURRENT;
642 devc->cur_unit[i] = SR_UNIT_AMPERE;
643 devc->cur_mqflags[i] = 0;
644 devc->cur_exponent[i] = 0;
645 if (mstr[4] == ':') {
646 if (!strncmp(mstr + 5, "ACDC", 4)) {
648 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS;
649 } else if (!strncmp(mstr + 5, "AC", 2)) {
650 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
651 } else if (!strncmp(mstr + 5, "DC", 2)) {
652 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
655 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
656 } else if (!strcmp(mstr, "RES")) {
657 devc->cur_mq[i] = SR_MQ_RESISTANCE;
658 devc->cur_unit[i] = SR_UNIT_OHM;
659 devc->cur_mqflags[i] = 0;
660 devc->cur_exponent[i] = 0;
661 } else if (!strcmp(mstr, "COND")) {
662 devc->cur_mq[i] = SR_MQ_CONDUCTANCE;
663 devc->cur_unit[i] = SR_UNIT_SIEMENS;
664 devc->cur_mqflags[i] = 0;
665 devc->cur_exponent[i] = 0;
666 } else if (!strcmp(mstr, "CAP")) {
667 devc->cur_mq[i] = SR_MQ_CAPACITANCE;
668 devc->cur_unit[i] = SR_UNIT_FARAD;
669 devc->cur_mqflags[i] = 0;
670 devc->cur_exponent[i] = 0;
671 } else if (!strncmp(mstr, "FREQ", 4) || !strncmp(mstr, "FC1", 3)) {
672 devc->cur_mq[i] = SR_MQ_FREQUENCY;
673 devc->cur_unit[i] = SR_UNIT_HERTZ;
674 devc->cur_mqflags[i] = 0;
675 devc->cur_exponent[i] = 0;
676 } else if (!strncmp(mstr, "PULS:PWID", 9)) {
677 devc->cur_mq[i] = SR_MQ_PULSE_WIDTH;
678 devc->cur_unit[i] = SR_UNIT_SECOND;
679 devc->cur_mqflags[i] = 0;
680 devc->cur_exponent[i] = 0;
681 devc->cur_encoding[i] = MIN(devc->cur_encoding[i], 6);
682 } else if (!strncmp(mstr, "PULS:PDUT", 9)) {
683 devc->cur_mq[i] = SR_MQ_DUTY_CYCLE;
684 devc->cur_unit[i] = SR_UNIT_PERCENTAGE;
685 devc->cur_mqflags[i] = 0;
686 devc->cur_exponent[i] = 0;
687 devc->cur_digits[i] = 3;
688 devc->cur_encoding[i] = 4;
689 } else if (!strcmp(mstr, "CONT")) {
690 devc->cur_mq[i] = SR_MQ_CONTINUITY;
691 devc->cur_unit[i] = SR_UNIT_OHM;
692 devc->cur_mqflags[i] = 0;
693 devc->cur_exponent[i] = 0;
694 } else if (!strcmp(mstr, "DIOD")) {
695 devc->cur_mq[i] = SR_MQ_VOLTAGE;
696 devc->cur_unit[i] = SR_UNIT_VOLT;
697 devc->cur_mqflags[i] = SR_MQFLAG_DIODE;
698 devc->cur_exponent[i] = 0;
699 devc->cur_digits[i] = 4;
700 devc->cur_encoding[i] = 5;
701 } else if (!strncmp(mstr, "T1", 2) || !strncmp(mstr, "T2", 2) ||
702 !strncmp(mstr, "TEMP", 2)) {
703 devc->cur_mq[i] = SR_MQ_TEMPERATURE;
704 m2 = g_match_info_fetch(match, 2);
707 * TEMP without param is for secondary display (channel P2)
708 * and is identical to channel P3, so discard it.
710 devc->cur_mq[i] = -1;
711 else if (!strcmp(m2, "FAR"))
712 devc->cur_unit[i] = SR_UNIT_FAHRENHEIT;
714 devc->cur_unit[i] = SR_UNIT_CELSIUS;
716 devc->cur_mqflags[i] = 0;
717 devc->cur_exponent[i] = 0;
718 devc->cur_digits[i] = 1;
719 devc->cur_encoding[i] = 2;
720 } else if (!strcmp(mstr, "SCOU")) {
722 * Switch counter, not supported. Not sure what values
723 * come from FETC in this mode, or how they would map
726 } else if (!strncmp(mstr, "CPER:", 5)) {
727 devc->cur_mq[i] = SR_MQ_CURRENT;
728 devc->cur_unit[i] = SR_UNIT_PERCENTAGE;
729 devc->cur_mqflags[i] = 0;
730 devc->cur_exponent[i] = 0;
731 devc->cur_digits[i] = 2;
732 devc->cur_encoding[i] = 3;
733 } else if (!strcmp(mstr, "SQU")) {
735 * Square wave output, not supported. FETC just return
736 * an error in this mode, so don't even call it.
738 devc->mode_squarewave = 1;
740 sr_dbg("Unknown first argument '%s'.", mstr);
744 struct sr_channel *prev_conf = devc->cur_conf;
745 devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf);
746 if (devc->cur_conf->index == MAX(devc->profile->nb_channels - 1, 1))
747 devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf);
748 if (devc->cur_conf->index > prev_conf->index)
754 /* This comes in whenever the rotary switch is changed to a new position.
755 * We could use it to determine the major measurement mode, but we already
756 * have the output of CONF? for that, which is more detailed. However
757 * we do need to catch this here, or it'll show up in some other output. */
758 static int recv_switch(const struct sr_dev_inst *sdi, GMatchInfo *match)
760 struct dev_context *devc = sdi->priv;
762 sr_spew("Switch '%s'.", g_match_info_get_string(match));
764 devc->current_job = 0;
765 devc->job_running = FALSE;
766 memset(devc->jobs_start, 0, sizeof(devc->jobs_start));
767 devc->cur_mq[0] = -1;
768 if (devc->profile->nb_channels > 2)
769 devc->cur_mq[1] = -1;
774 /* Poll CONF/STAT at 1Hz and values at samplerate. */
775 SR_PRIV const struct agdmm_job agdmm_jobs_u12xx[] = {
776 { JOB_FETC, SAMPLERATE_INTERVAL, send_fetc },
777 { JOB_CONF, 1000, send_conf },
778 { JOB_STAT, 1000, send_stat },
782 SR_PRIV const struct agdmm_recv agdmm_recvs_u123x[] = {
783 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u123x },
784 { "^\\*([0-9])$", recv_switch },
785 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
786 { "^\"(V|MV|A|UA|FREQ),(\\d),(AC|DC)\"$", recv_conf_u123x },
787 { "^\"(RES|CAP),(\\d)\"$", recv_conf_u123x},
788 { "^\"(DIOD)\"$", recv_conf_u123x },
792 SR_PRIV const struct agdmm_recv agdmm_recvs_u124x[] = {
793 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u124x },
794 { "^\\*([0-9])$", recv_switch },
795 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
796 { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
797 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
798 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
799 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
800 { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
801 { "^\"(DIOD)\"$", recv_conf_u124x_5x },
805 SR_PRIV const struct agdmm_recv agdmm_recvs_u125x[] = {
806 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u125x },
807 { "^\\*([0-9])$", recv_switch },
808 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
809 { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
810 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
811 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
812 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
813 { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
814 { "^\"(DIOD)\"$", recv_conf_u124x_5x },
818 SR_PRIV const struct agdmm_recv agdmm_recvs_u128x[] = {
819 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u128x },
820 { "^\\*([0-9])$", recv_switch },
821 { "^([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))$", recv_fetc },
822 { "^\"(VOLT|CURR|RES|CONT|COND|CAP|FREQ|FC1|FC100) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
823 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
824 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
825 { "^\"(FREQ:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
826 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
827 { "^\"(PULS:PWID|PULS:PWID:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
828 { "^\"(TEMP:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
829 { "^\"(DIOD|SQU|PULS:PDUT|TEMP)\"$", recv_conf_u124x_5x },