]> sigrok.org Git - libsigrok.git/blame - src/hardware/agilent-dmm/sched.c
device.c: Whitespace/cosmetics and typo fixes.
[libsigrok.git] / src / hardware / agilent-dmm / sched.c
CommitLineData
e93cdf42 1/*
50985c20 2 * This file is part of the libsigrok project.
e93cdf42
BV
3 *
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
6ec6c43b 20#include <config.h>
e93cdf42 21#include <glib.h>
e93cdf42
BV
22#include <stdlib.h>
23#include <string.h>
e93cdf42 24#include <math.h>
c1aae900 25#include <libsigrok/libsigrok.h>
515ab088
UH
26#include "libsigrok-internal.h"
27#include "agilent-dmm.h"
e93cdf42 28
e93cdf42
BV
29static void dispatch(const struct sr_dev_inst *sdi)
30{
31 struct dev_context *devc;
32 const struct agdmm_job *jobs;
33 int64_t now;
34 int i;
35
36 devc = sdi->priv;
37 jobs = devc->profile->jobs;
38 now = g_get_monotonic_time() / 1000;
39 for (i = 0; (&jobs[i])->interval; i++) {
40 if (now - devc->jobqueue[i] > (&jobs[i])->interval) {
38d326e8 41 sr_spew("Running job %d.", i);
e93cdf42
BV
42 (&jobs[i])->send(sdi);
43 devc->jobqueue[i] = now;
44 }
45 }
e93cdf42
BV
46}
47
48static void receive_line(const struct sr_dev_inst *sdi)
49{
50 struct dev_context *devc;
51 const struct agdmm_recv *recvs, *recv;
52 GRegex *reg;
53 GMatchInfo *match;
54 int i;
55
56 devc = sdi->priv;
57
58 /* Strip CRLF */
59 while (devc->buflen) {
60 if (*(devc->buf + devc->buflen - 1) == '\r'
61 || *(devc->buf + devc->buflen - 1) == '\n')
62 *(devc->buf + --devc->buflen) = '\0';
63 else
64 break;
65 }
38d326e8 66 sr_spew("Received '%s'.", devc->buf);
e93cdf42
BV
67
68 recv = NULL;
69 recvs = devc->profile->recvs;
70 for (i = 0; (&recvs[i])->recv_regex; i++) {
71 reg = g_regex_new((&recvs[i])->recv_regex, 0, 0, NULL);
72 if (g_regex_match(reg, (char *)devc->buf, 0, &match)) {
73 recv = &recvs[i];
74 break;
75 }
76 g_match_info_unref(match);
77 g_regex_unref(reg);
78 }
79 if (recv) {
80 recv->recv(sdi, match);
81 g_match_info_unref(match);
82 g_regex_unref(reg);
f2e86bbf 83 } else
38d326e8 84 sr_dbg("Unknown line '%s'.", devc->buf);
e93cdf42
BV
85
86 /* Done with this. */
87 devc->buflen = 0;
e93cdf42
BV
88}
89
90SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data)
91{
642e9d62 92 struct sr_dev_inst *sdi;
e93cdf42 93 struct dev_context *devc;
fb3a1505 94 struct sr_serial_dev_inst *serial;
e93cdf42
BV
95 int len;
96
109a3ba4
BV
97 (void)fd;
98
e93cdf42
BV
99 if (!(sdi = cb_data))
100 return TRUE;
101
102 if (!(devc = sdi->priv))
103 return TRUE;
104
fb3a1505 105 serial = sdi->conn;
e93cdf42
BV
106 if (revents == G_IO_IN) {
107 /* Serial data arrived. */
0c5f2abc 108 while (AGDMM_BUFSIZE - devc->buflen - 1 > 0) {
e0b781a4 109 len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1);
f2e86bbf
BV
110 if (len < 1)
111 break;
112 devc->buflen += len;
113 *(devc->buf + devc->buflen) = '\0';
114 if (*(devc->buf + devc->buflen - 1) == '\n') {
115 /* End of line */
116 receive_line(sdi);
117 break;
e93cdf42
BV
118 }
119 }
120 }
121
122 dispatch(sdi);
123
5b6829ea 124 if (sr_sw_limits_check(&devc->limits))
695dc859 125 sdi->driver->dev_acquisition_stop(sdi);
e93cdf42
BV
126
127 return TRUE;
128}
129
130static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd)
131{
fb3a1505 132 struct sr_serial_dev_inst *serial;
e93cdf42
BV
133 char buf[32];
134
fb3a1505
BV
135 serial = sdi->conn;
136
38d326e8 137 sr_spew("Sending '%s'.", cmd);
e93cdf42
BV
138 strncpy(buf, cmd, 28);
139 if (!strncmp(buf, "*IDN?", 5))
90486ba8 140 strcat(buf, "\r\n");
e93cdf42 141 else
90486ba8 142 strcat(buf, "\n\r\n");
95779b43 143 if (serial_write_blocking(serial, buf, strlen(buf), SERIAL_WRITE_TIMEOUT_MS) < (int)strlen(buf)) {
081c214e 144 sr_err("Failed to send.");
e93cdf42
BV
145 return SR_ERR;
146 }
ce4d26dd 147
e93cdf42
BV
148 return SR_OK;
149}
150
a4394fb3 151static int send_stat(const struct sr_dev_inst *sdi)
e93cdf42 152{
e93cdf42
BV
153 return agdmm_send(sdi, "STAT?");
154}
155
8c0152f2 156static int recv_stat_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42 157{
e6b021f3
BV
158 struct dev_context *devc;
159 char *s;
160
161 devc = sdi->priv;
162 s = g_match_info_fetch(match, 1);
38d326e8 163 sr_spew("STAT response '%s'.", s);
e6b021f3
BV
164
165 /* Max, Min or Avg mode -- no way to tell which, so we'll
166 * set both flags to denote it's not a normal measurement. */
167 if (s[0] == '1')
168 devc->cur_mqflags |= SR_MQFLAG_MAX | SR_MQFLAG_MIN;
169 else
170 devc->cur_mqflags &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN);
e93cdf42 171
e6b021f3
BV
172 if (s[1] == '1')
173 devc->cur_mqflags |= SR_MQFLAG_RELATIVE;
174 else
175 devc->cur_mqflags &= ~SR_MQFLAG_RELATIVE;
176
177 /* Triggered or auto hold modes. */
178 if (s[2] == '1' || s[3] == '1')
179 devc->cur_mqflags |= SR_MQFLAG_HOLD;
180 else
181 devc->cur_mqflags &= ~SR_MQFLAG_HOLD;
182
183 /* Temp/aux mode. */
184 if (s[7] == '1')
185 devc->mode_tempaux = TRUE;
186 else
187 devc->mode_tempaux = FALSE;
188
38d326e8 189 /* Continuity mode. */
e6b021f3
BV
190 if (s[16] == '1')
191 devc->mode_continuity = TRUE;
192 else
193 devc->mode_continuity = FALSE;
194
195 g_free(s);
e93cdf42
BV
196
197 return SR_OK;
198}
199
173378f0
BV
200static int recv_stat_u124x(const struct sr_dev_inst *sdi, GMatchInfo *match)
201{
202 struct dev_context *devc;
203 char *s;
204
205 devc = sdi->priv;
206 s = g_match_info_fetch(match, 1);
207 sr_spew("STAT response '%s'.", s);
208
209 /* Max, Min or Avg mode -- no way to tell which, so we'll
210 * set both flags to denote it's not a normal measurement. */
211 if (s[0] == '1')
212 devc->cur_mqflags |= SR_MQFLAG_MAX | SR_MQFLAG_MIN;
213 else
214 devc->cur_mqflags &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN);
215
216 if (s[1] == '1')
217 devc->cur_mqflags |= SR_MQFLAG_RELATIVE;
218 else
219 devc->cur_mqflags &= ~SR_MQFLAG_RELATIVE;
220
221 /* Hold mode. */
222 if (s[7] == '1')
223 devc->cur_mqflags |= SR_MQFLAG_HOLD;
224 else
225 devc->cur_mqflags &= ~SR_MQFLAG_HOLD;
226
227 g_free(s);
228
229 return SR_OK;
230}
231
8c0152f2
BV
232static int recv_stat_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match)
233{
234 struct dev_context *devc;
235 char *s;
236
237 devc = sdi->priv;
238 s = g_match_info_fetch(match, 1);
38d326e8 239 sr_spew("STAT response '%s'.", s);
8c0152f2
BV
240
241 /* Peak hold mode. */
242 if (s[4] == '1')
243 devc->cur_mqflags |= SR_MQFLAG_MAX;
244 else
245 devc->cur_mqflags &= ~SR_MQFLAG_MAX;
246
247 /* Triggered hold mode. */
248 if (s[7] == '1')
249 devc->cur_mqflags |= SR_MQFLAG_HOLD;
250 else
251 devc->cur_mqflags &= ~SR_MQFLAG_HOLD;
252
253 g_free(s);
254
255 return SR_OK;
256}
257
43185ed3
AJ
258static int recv_stat_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
259{
260 struct dev_context *devc;
261 char *s;
262
263 devc = sdi->priv;
264 s = g_match_info_fetch(match, 1);
265 sr_spew("STAT response '%s'.", s);
266
267 /* Max, Min or Avg mode -- no way to tell which, so we'll
268 * set both flags to denote it's not a normal measurement. */
269 if (s[0] == '1')
270 devc->cur_mqflags |= SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG;
271 else
272 devc->cur_mqflags &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG);
273
274 /* Peak hold mode. */
275 if (s[4] == '4')
276 devc->cur_mqflags |= SR_MQFLAG_MAX;
277 else
278 devc->cur_mqflags &= ~SR_MQFLAG_MAX;
279
280 /* Null function. */
281 if (s[1] == '1')
282 devc->cur_mqflags |= SR_MQFLAG_RELATIVE;
283 else
284 devc->cur_mqflags &= ~SR_MQFLAG_RELATIVE;
285
286 /* Triggered or auto hold modes. */
287 if (s[7] == '1' || s[11] == '1')
288 devc->cur_mqflags |= SR_MQFLAG_HOLD;
289 else
290 devc->cur_mqflags &= ~SR_MQFLAG_HOLD;
291
292 g_free(s);
293
294 return SR_OK;
295}
296
a4394fb3 297static int send_fetc(const struct sr_dev_inst *sdi)
e93cdf42 298{
43185ed3
AJ
299 struct dev_context *devc;
300 devc = sdi->priv;
301 if (devc->mode_squarewave)
302 return SR_OK;
e93cdf42
BV
303 return agdmm_send(sdi, "FETC?");
304}
305
a4394fb3 306static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42
BV
307{
308 struct dev_context *devc;
309 struct sr_datafeed_packet packet;
16aef676
UH
310 struct sr_datafeed_analog analog;
311 struct sr_analog_encoding encoding;
312 struct sr_analog_meaning meaning;
313 struct sr_analog_spec spec;
e93cdf42 314 float fvalue;
f216eb86 315 const char *s;
fe9d5abe 316 char *mstr;
e93cdf42 317
38d326e8 318 sr_spew("FETC reply '%s'.", g_match_info_get_string(match));
e93cdf42
BV
319 devc = sdi->priv;
320
321 if (devc->cur_mq == -1)
322 /* Haven't seen configuration yet, so can't know what
323 * the fetched float means. Not really an error, we'll
324 * get metadata soon enough. */
325 return SR_OK;
326
f216eb86
BV
327 s = g_match_info_get_string(match);
328 if (!strcmp(s, "-9.90000000E+37") || !strcmp(s, "+9.90000000E+37")) {
74ac7d7f 329 /* An invalid measurement shows up on the display as "O.L", but
e93cdf42
BV
330 * comes through like this. Since comparing 38-digit floats
331 * is rather problematic, we'll cut through this here. */
332 fvalue = NAN;
333 } else {
334 mstr = g_match_info_fetch(match, 1);
7c03b564 335 if (sr_atof_ascii(mstr, &fvalue) != SR_OK) {
fe9d5abe 336 g_free(mstr);
51b92b7d 337 sr_dbg("Invalid float.");
e93cdf42
BV
338 return SR_ERR;
339 }
fe9d5abe 340 g_free(mstr);
40df76aa
AJ
341 if (devc->cur_exponent != 0)
342 fvalue *= powf(10, devc->cur_exponent);
e93cdf42
BV
343 }
344
4435966e
AJ
345 sr_analog_init(&analog, &encoding, &meaning, &spec,
346 devc->cur_digits - devc->cur_exponent);
16aef676
UH
347 analog.meaning->mq = devc->cur_mq;
348 analog.meaning->unit = devc->cur_unit;
349 analog.meaning->mqflags = devc->cur_mqflags;
350 analog.meaning->channels = sdi->channels;
e93cdf42
BV
351 analog.num_samples = 1;
352 analog.data = &fvalue;
4435966e 353 encoding.digits = devc->cur_encoding - devc->cur_exponent;
16aef676 354 packet.type = SR_DF_ANALOG;
e93cdf42 355 packet.payload = &analog;
695dc859 356 sr_session_send(sdi, &packet);
e93cdf42 357
5b6829ea 358 sr_sw_limits_update_samples_read(&devc->limits, 1);
e93cdf42
BV
359
360 return SR_OK;
361}
362
a4394fb3 363static int send_conf(const struct sr_dev_inst *sdi)
e93cdf42 364{
e93cdf42
BV
365 return agdmm_send(sdi, "CONF?");
366}
367
a4394fb3 368static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42
BV
369{
370 struct dev_context *devc;
4435966e
AJ
371 char *mstr, *rstr;
372 int resolution;
e93cdf42 373
38d326e8 374 sr_spew("CONF? response '%s'.", g_match_info_get_string(match));
e93cdf42 375 devc = sdi->priv;
4435966e
AJ
376
377 rstr = g_match_info_fetch(match, 2);
378 if (rstr)
379 sr_atoi(rstr, &resolution);
380 g_free(rstr);
381
e93cdf42
BV
382 mstr = g_match_info_fetch(match, 1);
383 if (!strcmp(mstr, "V")) {
384 devc->cur_mq = SR_MQ_VOLTAGE;
e6b021f3
BV
385 devc->cur_unit = SR_UNIT_VOLT;
386 devc->cur_mqflags = 0;
40df76aa 387 devc->cur_exponent = 0;
4435966e 388 devc->cur_digits = 4 - resolution;
0c5f2abc 389 } else if (!strcmp(mstr, "MV")) {
e6b021f3
BV
390 if (devc->mode_tempaux) {
391 devc->cur_mq = SR_MQ_TEMPERATURE;
f3f19d11
UH
392 /* No way to detect whether Fahrenheit or Celsius
393 * is used, so we'll just default to Celsius. */
e6b021f3
BV
394 devc->cur_unit = SR_UNIT_CELSIUS;
395 devc->cur_mqflags = 0;
40df76aa 396 devc->cur_exponent = 0;
4435966e 397 devc->cur_digits = 1;
e6b021f3
BV
398 } else {
399 devc->cur_mq = SR_MQ_VOLTAGE;
400 devc->cur_unit = SR_UNIT_VOLT;
401 devc->cur_mqflags = 0;
40df76aa 402 devc->cur_exponent = -3;
4435966e 403 devc->cur_digits = 5 - resolution;
e6b021f3 404 }
0c5f2abc 405 } else if (!strcmp(mstr, "A")) {
e93cdf42 406 devc->cur_mq = SR_MQ_CURRENT;
e6b021f3
BV
407 devc->cur_unit = SR_UNIT_AMPERE;
408 devc->cur_mqflags = 0;
40df76aa 409 devc->cur_exponent = 0;
4435966e 410 devc->cur_digits = 3 - resolution;
0c5f2abc 411 } else if (!strcmp(mstr, "UA")) {
e93cdf42 412 devc->cur_mq = SR_MQ_CURRENT;
e6b021f3
BV
413 devc->cur_unit = SR_UNIT_AMPERE;
414 devc->cur_mqflags = 0;
40df76aa 415 devc->cur_exponent = -6;
4435966e 416 devc->cur_digits = 8 - resolution;
0c5f2abc 417 } else if (!strcmp(mstr, "FREQ")) {
e93cdf42 418 devc->cur_mq = SR_MQ_FREQUENCY;
e6b021f3
BV
419 devc->cur_unit = SR_UNIT_HERTZ;
420 devc->cur_mqflags = 0;
40df76aa 421 devc->cur_exponent = 0;
4435966e 422 devc->cur_digits = 2 - resolution;
0c5f2abc 423 } else if (!strcmp(mstr, "RES")) {
e6b021f3
BV
424 if (devc->mode_continuity) {
425 devc->cur_mq = SR_MQ_CONTINUITY;
426 devc->cur_unit = SR_UNIT_BOOLEAN;
427 } else {
428 devc->cur_mq = SR_MQ_RESISTANCE;
429 devc->cur_unit = SR_UNIT_OHM;
430 }
431 devc->cur_mqflags = 0;
40df76aa 432 devc->cur_exponent = 0;
4435966e 433 devc->cur_digits = 1 - resolution;
873c0d11
AJ
434 } else if (!strcmp(mstr, "DIOD")) {
435 devc->cur_mq = SR_MQ_VOLTAGE;
436 devc->cur_unit = SR_UNIT_VOLT;
437 devc->cur_mqflags = SR_MQFLAG_DIODE;
438 devc->cur_exponent = 0;
4435966e 439 devc->cur_digits = 3;
0c5f2abc 440 } else if (!strcmp(mstr, "CAP")) {
e93cdf42 441 devc->cur_mq = SR_MQ_CAPACITANCE;
e6b021f3
BV
442 devc->cur_unit = SR_UNIT_FARAD;
443 devc->cur_mqflags = 0;
40df76aa 444 devc->cur_exponent = 0;
4435966e 445 devc->cur_digits = 9 - resolution;
e93cdf42 446 } else
38d326e8 447 sr_dbg("Unknown first argument.");
e93cdf42
BV
448 g_free(mstr);
449
4435966e
AJ
450 /* This is based on guess, supposing similarity with other models. */
451 devc->cur_encoding = devc->cur_digits + 1;
452
e066c32a
BV
453 if (g_match_info_get_match_count(match) == 4) {
454 mstr = g_match_info_fetch(match, 3);
e93cdf42 455 /* Third value, if present, is always AC or DC. */
51b92b7d 456 if (!strcmp(mstr, "AC")) {
e6b021f3 457 devc->cur_mqflags |= SR_MQFLAG_AC;
51b92b7d
BV
458 if (devc->cur_mq == SR_MQ_VOLTAGE)
459 devc->cur_mqflags |= SR_MQFLAG_RMS;
460 } else if (!strcmp(mstr, "DC")) {
e6b021f3 461 devc->cur_mqflags |= SR_MQFLAG_DC;
51b92b7d 462 } else {
a965748a 463 sr_dbg("Unknown first argument '%s'.", mstr);
51b92b7d 464 }
e93cdf42 465 g_free(mstr);
e6b021f3
BV
466 } else
467 devc->cur_mqflags &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC);
e93cdf42
BV
468
469 return SR_OK;
470}
471
173378f0 472static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match)
8c0152f2
BV
473{
474 struct dev_context *devc;
4435966e
AJ
475 char *mstr, *rstr, *m2;
476 int resolution;
8c0152f2 477
38d326e8 478 sr_spew("CONF? response '%s'.", g_match_info_get_string(match));
8c0152f2 479 devc = sdi->priv;
4435966e 480
43185ed3
AJ
481 devc->mode_squarewave = 0;
482
4435966e
AJ
483 rstr = g_match_info_fetch(match, 4);
484 if (rstr && sr_atoi(rstr, &resolution) == SR_OK) {
485 devc->cur_digits = -resolution;
486 devc->cur_encoding = -resolution + 1;
487 }
488 g_free(rstr);
489
490 mstr = g_match_info_fetch(match, 1);
8c0152f2
BV
491 if (!strncmp(mstr, "VOLT", 4)) {
492 devc->cur_mq = SR_MQ_VOLTAGE;
493 devc->cur_unit = SR_UNIT_VOLT;
494 devc->cur_mqflags = 0;
40df76aa 495 devc->cur_exponent = 0;
8c0152f2 496 if (mstr[4] == ':') {
96ed8625
AJ
497 if (!strncmp(mstr + 5, "ACDC", 4)) {
498 /* AC + DC offset */
499 devc->cur_mqflags |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS;
500 } else if (!strncmp(mstr + 5, "AC", 2)) {
51b92b7d 501 devc->cur_mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
ee2bcdfc 502 } else if (!strncmp(mstr + 5, "DC", 2)) {
8c0152f2 503 devc->cur_mqflags |= SR_MQFLAG_DC;
51b92b7d 504 }
8c0152f2 505 } else
96ed8625 506 devc->cur_mqflags |= SR_MQFLAG_DC;
0fe18626 507 } else if (!strncmp(mstr, "CURR", 4)) {
8c0152f2
BV
508 devc->cur_mq = SR_MQ_CURRENT;
509 devc->cur_unit = SR_UNIT_AMPERE;
510 devc->cur_mqflags = 0;
40df76aa 511 devc->cur_exponent = 0;
0fe18626
AJ
512 if (mstr[4] == ':') {
513 if (!strncmp(mstr + 5, "ACDC", 4)) {
514 /* AC + DC offset */
515 devc->cur_mqflags |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS;
516 } else if (!strncmp(mstr + 5, "AC", 2)) {
517 devc->cur_mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
518 } else if (!strncmp(mstr + 5, "DC", 2)) {
519 devc->cur_mqflags |= SR_MQFLAG_DC;
520 }
521 } else
522 devc->cur_mqflags |= SR_MQFLAG_DC;
0c5f2abc 523 } else if (!strcmp(mstr, "RES")) {
a965748a
BV
524 devc->cur_mq = SR_MQ_RESISTANCE;
525 devc->cur_unit = SR_UNIT_OHM;
526 devc->cur_mqflags = 0;
40df76aa 527 devc->cur_exponent = 0;
43185ed3
AJ
528 } else if (!strcmp(mstr, "COND")) {
529 devc->cur_mq = SR_MQ_CONDUCTANCE;
530 devc->cur_unit = SR_UNIT_SIEMENS;
531 devc->cur_mqflags = 0;
532 devc->cur_exponent = 0;
0c5f2abc 533 } else if (!strcmp(mstr, "CAP")) {
a965748a
BV
534 devc->cur_mq = SR_MQ_CAPACITANCE;
535 devc->cur_unit = SR_UNIT_FARAD;
8c0152f2 536 devc->cur_mqflags = 0;
40df76aa 537 devc->cur_exponent = 0;
43185ed3 538 } else if (!strncmp(mstr, "FREQ", 4) || !strncmp(mstr, "FC1", 3)) {
a965748a
BV
539 devc->cur_mq = SR_MQ_FREQUENCY;
540 devc->cur_unit = SR_UNIT_HERTZ;
541 devc->cur_mqflags = 0;
40df76aa 542 devc->cur_exponent = 0;
0c5f2abc 543 } else if (!strcmp(mstr, "CONT")) {
a965748a
BV
544 devc->cur_mq = SR_MQ_CONTINUITY;
545 devc->cur_unit = SR_UNIT_BOOLEAN;
546 devc->cur_mqflags = 0;
40df76aa 547 devc->cur_exponent = 0;
873c0d11
AJ
548 } else if (!strcmp(mstr, "DIOD")) {
549 devc->cur_mq = SR_MQ_VOLTAGE;
550 devc->cur_unit = SR_UNIT_VOLT;
551 devc->cur_mqflags = SR_MQFLAG_DIODE;
552 devc->cur_exponent = 0;
4435966e
AJ
553 devc->cur_digits = 4;
554 devc->cur_encoding = 5;
43185ed3
AJ
555 } else if (!strncmp(mstr, "T1", 2) || !strncmp(mstr, "T2", 2) ||
556 !strncmp(mstr, "TEMP", 2)) {
a965748a
BV
557 devc->cur_mq = SR_MQ_TEMPERATURE;
558 m2 = g_match_info_fetch(match, 2);
559 if (!strcmp(m2, "FAR"))
560 devc->cur_unit = SR_UNIT_FAHRENHEIT;
561 else
562 devc->cur_unit = SR_UNIT_CELSIUS;
563 g_free(m2);
564 devc->cur_mqflags = 0;
40df76aa 565 devc->cur_exponent = 0;
4435966e
AJ
566 devc->cur_digits = 1;
567 devc->cur_encoding = 2;
0c5f2abc 568 } else if (!strcmp(mstr, "SCOU")) {
a965748a
BV
569 /*
570 * Switch counter, not supported. Not sure what values
571 * come from FETC in this mode, or how they would map
572 * into libsigrok.
573 */
0c5f2abc 574 } else if (!strncmp(mstr, "CPER:", 5)) {
110fe1b4
BV
575 devc->cur_mq = SR_MQ_CURRENT;
576 devc->cur_unit = SR_UNIT_PERCENTAGE;
577 devc->cur_mqflags = 0;
40df76aa 578 devc->cur_exponent = 0;
4435966e
AJ
579 devc->cur_digits = 2;
580 devc->cur_encoding = 3;
43185ed3
AJ
581 } else if (!strcmp(mstr, "SQU")) {
582 /*
583 * Square wave output, not supported. FETC just return
584 * an error in this mode, so don't even call it.
585 */
586 devc->mode_squarewave = 1;
51b92b7d 587 } else {
a965748a 588 sr_dbg("Unknown first argument '%s'.", mstr);
51b92b7d 589 }
8c0152f2
BV
590 g_free(mstr);
591
8c0152f2
BV
592 return SR_OK;
593}
594
81599cc5
BV
595/* This comes in whenever the rotary switch is changed to a new position.
596 * We could use it to determine the major measurement mode, but we already
597 * have the output of CONF? for that, which is more detailed. However
598 * we do need to catch this here, or it'll show up in some other output. */
a4394fb3 599static int recv_switch(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42 600{
e93cdf42
BV
601 (void)sdi;
602
38d326e8 603 sr_spew("Switch '%s'.", g_match_info_get_string(match));
e93cdf42
BV
604
605 return SR_OK;
606}
607
f857bd92
BV
608/* Poll keys/switches and values at 7Hz, mode at 1Hz. */
609SR_PRIV const struct agdmm_job agdmm_jobs_u12xx[] = {
a4394fb3
BV
610 { 143, send_stat },
611 { 1000, send_conf },
612 { 143, send_fetc },
9e9dba7b 613 ALL_ZERO
e93cdf42
BV
614};
615
8c0152f2
BV
616SR_PRIV const struct agdmm_recv agdmm_recvs_u123x[] = {
617 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u123x },
a4394fb3
BV
618 { "^\\*([0-9])$", recv_switch },
619 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
620 { "^\"(V|MV|A|UA|FREQ),(\\d),(AC|DC)\"$", recv_conf_u123x },
621 { "^\"(RES|CAP),(\\d)\"$", recv_conf_u123x},
873c0d11 622 { "^\"(DIOD)\"$", recv_conf_u123x },
9e9dba7b 623 ALL_ZERO
e93cdf42
BV
624};
625
173378f0
BV
626SR_PRIV const struct agdmm_recv agdmm_recvs_u124x[] = {
627 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u124x },
628 { "^\\*([0-9])$", recv_switch },
629 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
4435966e
AJ
630 { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
631 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
0fe18626 632 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
4435966e 633 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
a965748a 634 { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
873c0d11 635 { "^\"(DIOD)\"$", recv_conf_u124x_5x },
9e9dba7b 636 ALL_ZERO
173378f0
BV
637};
638
8c0152f2
BV
639SR_PRIV const struct agdmm_recv agdmm_recvs_u125x[] = {
640 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u125x },
641 { "^\\*([0-9])$", recv_switch },
642 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
4435966e
AJ
643 { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
644 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
0fe18626 645 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
4435966e 646 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
c7f5219e 647 { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
873c0d11 648 { "^\"(DIOD)\"$", recv_conf_u124x_5x },
9e9dba7b 649 ALL_ZERO
8c0152f2 650};
43185ed3
AJ
651
652SR_PRIV const struct agdmm_recv agdmm_recvs_u128x[] = {
653 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u128x },
654 { "^\\*([0-9])$", recv_switch },
655 { "^([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))$", recv_fetc },
656 { "^\"(VOLT|CURR|RES|COND|CAP|FREQ|FC1|FC100) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
657 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
658 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
659 { "^\"(FREQ:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
660 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
661 { "^\"(TEMP:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
662 { "^\"(DIOD|SQU)\"$", recv_conf_u124x_5x },
663 ALL_ZERO
664};