]> sigrok.org Git - libsigrok.git/blame - src/hardware/agilent-dmm/protocol.c
Add sr_dev_acquisition_stop(), factor out SR_ERR_DEV_CLOSED check.
[libsigrok.git] / src / hardware / agilent-dmm / protocol.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 22#include <stdlib.h>
d822726d 23#include <stdarg.h>
e93cdf42 24#include <string.h>
b907d62f 25#include <limits.h>
e93cdf42 26#include <math.h>
c1aae900 27#include <libsigrok/libsigrok.h>
515ab088 28#include "libsigrok-internal.h"
6cf1a87b 29#include "protocol.h"
e93cdf42 30
b907d62f
AJ
31#define JOB_TIMEOUT 300
32
33#define INFINITE_INTERVAL INT_MAX
34#define SAMPLERATE_INTERVAL -1
35
36static const struct agdmm_job *job_current(const struct dev_context *devc)
37{
63bb11ba 38 return &devc->jobs[devc->current_job];
b907d62f
AJ
39}
40
41static void job_done(struct dev_context *devc)
42{
43 devc->job_running = FALSE;
44}
45
46static void job_again(struct dev_context *devc)
47{
48 devc->job_again = TRUE;
49}
50
51static gboolean job_is_running(const struct dev_context *devc)
52{
53 return devc->job_running;
54}
55
56static gboolean job_in_interval(const struct dev_context *devc)
57{
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;
64}
65
66static gboolean job_has_timeout(const struct dev_context *devc)
67{
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;
71}
72
73static const struct agdmm_job *job_next(struct dev_context *devc)
74{
75 int current_job = devc->current_job;
76 do {
77 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);
82}
83
84static void job_run_again(const struct sr_dev_inst *sdi)
85{
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)
90 job_done(devc);
91}
92
93static void job_run(const struct sr_dev_inst *sdi)
94{
95 struct dev_context *devc = sdi->priv;
96 int64_t now = g_get_monotonic_time() / 1000;
97 devc->jobs_start[devc->current_job] = now;
98 job_run_again(sdi);
99}
100
e93cdf42
BV
101static void dispatch(const struct sr_dev_inst *sdi)
102{
b907d62f 103 struct dev_context *devc = sdi->priv;
e93cdf42 104
b907d62f
AJ
105 if (devc->job_again) {
106 job_run_again(sdi);
107 return;
e93cdf42 108 }
b907d62f
AJ
109
110 if (!job_is_running(devc))
111 job_next(devc);
112 else if (job_has_timeout(devc))
113 job_done(devc);
114
115 if (!job_is_running(devc) && !job_in_interval(devc))
116 job_run(sdi);
e93cdf42
BV
117}
118
63bb11ba 119static gboolean receive_line(const struct sr_dev_inst *sdi)
e93cdf42
BV
120{
121 struct dev_context *devc;
122 const struct agdmm_recv *recvs, *recv;
123 GRegex *reg;
124 GMatchInfo *match;
63bb11ba 125 gboolean stop = FALSE;
e93cdf42
BV
126 int i;
127
128 devc = sdi->priv;
129
130 /* Strip CRLF */
131 while (devc->buflen) {
132 if (*(devc->buf + devc->buflen - 1) == '\r'
133 || *(devc->buf + devc->buflen - 1) == '\n')
134 *(devc->buf + --devc->buflen) = '\0';
135 else
136 break;
137 }
38d326e8 138 sr_spew("Received '%s'.", devc->buf);
e93cdf42
BV
139
140 recv = NULL;
141 recvs = devc->profile->recvs;
142 for (i = 0; (&recvs[i])->recv_regex; i++) {
143 reg = g_regex_new((&recvs[i])->recv_regex, 0, 0, NULL);
144 if (g_regex_match(reg, (char *)devc->buf, 0, &match)) {
145 recv = &recvs[i];
146 break;
147 }
148 g_match_info_unref(match);
149 g_regex_unref(reg);
150 }
151 if (recv) {
b907d62f
AJ
152 enum job_type type = recv->recv(sdi, match);
153 if (type == job_current(devc)->type)
154 job_done(devc);
155 else if (type == JOB_AGAIN)
156 job_again(devc);
63bb11ba
AJ
157 else if (type == JOB_STOP)
158 stop = TRUE;
e93cdf42
BV
159 g_match_info_unref(match);
160 g_regex_unref(reg);
f2e86bbf 161 } else
38d326e8 162 sr_dbg("Unknown line '%s'.", devc->buf);
e93cdf42
BV
163
164 /* Done with this. */
165 devc->buflen = 0;
63bb11ba 166 return stop;
e93cdf42
BV
167}
168
169SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data)
170{
642e9d62 171 struct sr_dev_inst *sdi;
e93cdf42 172 struct dev_context *devc;
fb3a1505 173 struct sr_serial_dev_inst *serial;
63bb11ba 174 gboolean stop = FALSE;
e93cdf42
BV
175 int len;
176
109a3ba4
BV
177 (void)fd;
178
e93cdf42
BV
179 if (!(sdi = cb_data))
180 return TRUE;
181
182 if (!(devc = sdi->priv))
183 return TRUE;
184
fb3a1505 185 serial = sdi->conn;
e93cdf42
BV
186 if (revents == G_IO_IN) {
187 /* Serial data arrived. */
0c5f2abc 188 while (AGDMM_BUFSIZE - devc->buflen - 1 > 0) {
e0b781a4 189 len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1);
f2e86bbf
BV
190 if (len < 1)
191 break;
192 devc->buflen += len;
193 *(devc->buf + devc->buflen) = '\0';
194 if (*(devc->buf + devc->buflen - 1) == '\n') {
195 /* End of line */
63bb11ba 196 stop = receive_line(sdi);
f2e86bbf 197 break;
e93cdf42
BV
198 }
199 }
200 }
201
63bb11ba 202 if (sr_sw_limits_check(&devc->limits) || stop)
d2f7c417 203 sr_dev_acquisition_stop(sdi);
63bb11ba
AJ
204 else
205 dispatch(sdi);
e93cdf42
BV
206
207 return TRUE;
208}
209
d822726d 210static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd, ...)
e93cdf42 211{
fb3a1505 212 struct sr_serial_dev_inst *serial;
d822726d 213 va_list args;
e93cdf42
BV
214 char buf[32];
215
fb3a1505
BV
216 serial = sdi->conn;
217
d822726d 218 va_start(args, cmd);
7ab126ca 219 vsnprintf(buf, sizeof(buf) - 3, cmd, args);
d822726d
AJ
220 va_end(args);
221 sr_spew("Sending '%s'.", buf);
e93cdf42 222 if (!strncmp(buf, "*IDN?", 5))
90486ba8 223 strcat(buf, "\r\n");
e93cdf42 224 else
90486ba8 225 strcat(buf, "\n\r\n");
95779b43 226 if (serial_write_blocking(serial, buf, strlen(buf), SERIAL_WRITE_TIMEOUT_MS) < (int)strlen(buf)) {
081c214e 227 sr_err("Failed to send.");
e93cdf42
BV
228 return SR_ERR;
229 }
ce4d26dd 230
e93cdf42
BV
231 return SR_OK;
232}
233
a4394fb3 234static int send_stat(const struct sr_dev_inst *sdi)
e93cdf42 235{
e93cdf42
BV
236 return agdmm_send(sdi, "STAT?");
237}
238
8c0152f2 239static int recv_stat_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42 240{
e6b021f3
BV
241 struct dev_context *devc;
242 char *s;
243
244 devc = sdi->priv;
245 s = g_match_info_fetch(match, 1);
38d326e8 246 sr_spew("STAT response '%s'.", s);
e6b021f3
BV
247
248 /* Max, Min or Avg mode -- no way to tell which, so we'll
249 * set both flags to denote it's not a normal measurement. */
250 if (s[0] == '1')
d822726d 251 devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN;
e6b021f3 252 else
d822726d 253 devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN);
e93cdf42 254
e6b021f3 255 if (s[1] == '1')
d822726d 256 devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE;
e6b021f3 257 else
d822726d 258 devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE;
e6b021f3
BV
259
260 /* Triggered or auto hold modes. */
261 if (s[2] == '1' || s[3] == '1')
d822726d 262 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
e6b021f3 263 else
d822726d 264 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
e6b021f3
BV
265
266 /* Temp/aux mode. */
267 if (s[7] == '1')
268 devc->mode_tempaux = TRUE;
269 else
270 devc->mode_tempaux = FALSE;
271
38d326e8 272 /* Continuity mode. */
e6b021f3
BV
273 if (s[16] == '1')
274 devc->mode_continuity = TRUE;
275 else
276 devc->mode_continuity = FALSE;
277
278 g_free(s);
e93cdf42 279
b907d62f 280 return JOB_STAT;
e93cdf42
BV
281}
282
173378f0
BV
283static int recv_stat_u124x(const struct sr_dev_inst *sdi, GMatchInfo *match)
284{
285 struct dev_context *devc;
286 char *s;
287
288 devc = sdi->priv;
289 s = g_match_info_fetch(match, 1);
290 sr_spew("STAT response '%s'.", s);
291
292 /* Max, Min or Avg mode -- no way to tell which, so we'll
293 * set both flags to denote it's not a normal measurement. */
294 if (s[0] == '1')
d822726d 295 devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN;
173378f0 296 else
d822726d 297 devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN);
173378f0
BV
298
299 if (s[1] == '1')
d822726d 300 devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE;
173378f0 301 else
d822726d 302 devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE;
173378f0
BV
303
304 /* Hold mode. */
305 if (s[7] == '1')
d822726d 306 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
173378f0 307 else
d822726d 308 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
173378f0
BV
309
310 g_free(s);
311
b907d62f 312 return JOB_STAT;
173378f0
BV
313}
314
0ceb7038
AJ
315static int recv_stat_u124xc(const struct sr_dev_inst *sdi, GMatchInfo *match)
316{
317 struct dev_context *devc;
318 char *s;
319
320 devc = sdi->priv;
321 s = g_match_info_fetch(match, 1);
322 sr_spew("STAT response '%s'.", s);
323
324 /* Max, Min or Avg mode -- no way to tell which, so we'll
325 * set both flags to denote it's not a normal measurement. */
326 if (s[0] == '1')
327 devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG;
328 else
329 devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG);
330
331 /* Null function. */
332 if (s[1] == '1')
333 devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE;
334 else
335 devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE;
336
337 /* Triggered or auto hold modes. */
338 if (s[7] == '1' || s[11] == '1')
339 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
340 else
341 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
342
343 g_free(s);
344
345 return JOB_STAT;
346}
347
8c0152f2
BV
348static int recv_stat_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match)
349{
350 struct dev_context *devc;
351 char *s;
352
353 devc = sdi->priv;
354 s = g_match_info_fetch(match, 1);
38d326e8 355 sr_spew("STAT response '%s'.", s);
8c0152f2 356
8f68f36b
AJ
357 /* dBm/dBV modes. */
358 if ((s[2] & ~0x20) == 'M')
359 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW;
360 else if ((s[2] & ~0x20) == 'V')
361 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT;
362 else
363 devc->mode_dbm_dbv = 0;
364
8c0152f2
BV
365 /* Peak hold mode. */
366 if (s[4] == '1')
d822726d 367 devc->cur_mqflags[0] |= SR_MQFLAG_MAX;
8c0152f2 368 else
d822726d 369 devc->cur_mqflags[0] &= ~SR_MQFLAG_MAX;
8c0152f2
BV
370
371 /* Triggered hold mode. */
372 if (s[7] == '1')
d822726d 373 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
8c0152f2 374 else
d822726d 375 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
8c0152f2
BV
376
377 g_free(s);
378
b907d62f 379 return JOB_STAT;
8c0152f2
BV
380}
381
43185ed3
AJ
382static int recv_stat_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
383{
384 struct dev_context *devc;
385 char *s;
386
387 devc = sdi->priv;
388 s = g_match_info_fetch(match, 1);
389 sr_spew("STAT response '%s'.", s);
390
391 /* Max, Min or Avg mode -- no way to tell which, so we'll
392 * set both flags to denote it's not a normal measurement. */
393 if (s[0] == '1')
d822726d 394 devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG;
43185ed3 395 else
d822726d 396 devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG);
43185ed3 397
8f68f36b
AJ
398 /* dBm/dBV modes. */
399 if ((s[2] & ~0x20) == 'M')
400 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW;
401 else if ((s[2] & ~0x20) == 'V')
402 devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT;
403 else
404 devc->mode_dbm_dbv = 0;
405
43185ed3
AJ
406 /* Peak hold mode. */
407 if (s[4] == '4')
d822726d 408 devc->cur_mqflags[0] |= SR_MQFLAG_MAX;
43185ed3 409 else
d822726d 410 devc->cur_mqflags[0] &= ~SR_MQFLAG_MAX;
43185ed3
AJ
411
412 /* Null function. */
413 if (s[1] == '1')
d822726d 414 devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE;
43185ed3 415 else
d822726d 416 devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE;
43185ed3
AJ
417
418 /* Triggered or auto hold modes. */
419 if (s[7] == '1' || s[11] == '1')
d822726d 420 devc->cur_mqflags[0] |= SR_MQFLAG_HOLD;
43185ed3 421 else
d822726d 422 devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD;
43185ed3
AJ
423
424 g_free(s);
425
b907d62f 426 return JOB_STAT;
43185ed3
AJ
427}
428
a4394fb3 429static int send_fetc(const struct sr_dev_inst *sdi)
e93cdf42 430{
b907d62f
AJ
431 struct dev_context *devc = sdi->priv;
432
43185ed3 433 if (devc->mode_squarewave)
b907d62f
AJ
434 return SR_ERR_NA;
435
d822726d
AJ
436 if (devc->cur_channel->index > 0)
437 return agdmm_send(sdi, "FETC? @%d", devc->cur_channel->index + 1);
438 else
439 return agdmm_send(sdi, "FETC?");
e93cdf42
BV
440}
441
a4394fb3 442static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42
BV
443{
444 struct dev_context *devc;
445 struct sr_datafeed_packet packet;
16aef676
UH
446 struct sr_datafeed_analog analog;
447 struct sr_analog_encoding encoding;
448 struct sr_analog_meaning meaning;
449 struct sr_analog_spec spec;
f6e7b612 450 struct sr_channel *prev_chan;
e93cdf42 451 float fvalue;
f216eb86 452 const char *s;
fe9d5abe 453 char *mstr;
8f68f36b 454 int i, exp;
e93cdf42 455
38d326e8 456 sr_spew("FETC reply '%s'.", g_match_info_get_string(match));
e93cdf42 457 devc = sdi->priv;
d822726d 458 i = devc->cur_channel->index;
e93cdf42 459
d822726d 460 if (devc->cur_mq[i] == -1)
b907d62f
AJ
461 /* This detects when channel P2 is reporting TEMP as an identical
462 * copy of channel P3. In this case, we just skip P2. */
463 goto skip_value;
e93cdf42 464
f216eb86
BV
465 s = g_match_info_get_string(match);
466 if (!strcmp(s, "-9.90000000E+37") || !strcmp(s, "+9.90000000E+37")) {
74ac7d7f 467 /* An invalid measurement shows up on the display as "O.L", but
e93cdf42
BV
468 * comes through like this. Since comparing 38-digit floats
469 * is rather problematic, we'll cut through this here. */
470 fvalue = NAN;
471 } else {
472 mstr = g_match_info_fetch(match, 1);
7c03b564 473 if (sr_atof_ascii(mstr, &fvalue) != SR_OK) {
fe9d5abe 474 g_free(mstr);
51b92b7d 475 sr_dbg("Invalid float.");
e93cdf42
BV
476 return SR_ERR;
477 }
fe9d5abe 478 g_free(mstr);
d822726d
AJ
479 if (devc->cur_exponent[i] != 0)
480 fvalue *= powf(10, devc->cur_exponent[i]);
e93cdf42
BV
481 }
482
8f68f36b
AJ
483 if (devc->cur_unit[i] == SR_UNIT_DECIBEL_MW ||
484 devc->cur_unit[i] == SR_UNIT_DECIBEL_VOLT ||
485 devc->cur_unit[i] == SR_UNIT_PERCENTAGE) {
486 mstr = g_match_info_fetch(match, 2);
487 if (mstr && sr_atoi(mstr, &exp) == SR_OK) {
488 devc->cur_digits[i] = MIN(4 - exp, devc->cur_digits[i]);
489 devc->cur_encoding[i] = MIN(5 - exp, devc->cur_encoding[i]);
490 }
491 g_free(mstr);
492 }
493
4435966e 494 sr_analog_init(&analog, &encoding, &meaning, &spec,
d822726d
AJ
495 devc->cur_digits[i] - devc->cur_exponent[i]);
496 analog.meaning->mq = devc->cur_mq[i];
497 analog.meaning->unit = devc->cur_unit[i];
498 analog.meaning->mqflags = devc->cur_mqflags[i];
499 analog.meaning->channels = g_slist_append(NULL, devc->cur_channel);
e93cdf42
BV
500 analog.num_samples = 1;
501 analog.data = &fvalue;
d822726d 502 encoding.digits = devc->cur_encoding[i] - devc->cur_exponent[i];
16aef676 503 packet.type = SR_DF_ANALOG;
e93cdf42 504 packet.payload = &analog;
695dc859 505 sr_session_send(sdi, &packet);
d822726d 506 g_slist_free(analog.meaning->channels);
e93cdf42 507
5b6829ea 508 sr_sw_limits_update_samples_read(&devc->limits, 1);
e93cdf42 509
f6e7b612
AJ
510skip_value:
511 prev_chan = devc->cur_channel;
b907d62f
AJ
512 devc->cur_channel = sr_next_enabled_channel(sdi, devc->cur_channel);
513 if (devc->cur_channel->index > prev_chan->index)
514 return JOB_AGAIN;
515 else
516 return JOB_FETC;
e93cdf42
BV
517}
518
a4394fb3 519static int send_conf(const struct sr_dev_inst *sdi)
e93cdf42 520{
d822726d
AJ
521 struct dev_context *devc = sdi->priv;
522
d822726d 523 /* Do not try to send CONF? for internal temperature channel. */
c2e3c322 524 if (devc->cur_conf->index >= MIN(devc->profile->nb_channels, 2))
d822726d
AJ
525 return SR_ERR_NA;
526
527 if (devc->cur_conf->index > 0)
528 return agdmm_send(sdi, "CONF? @%d", devc->cur_conf->index + 1);
529 else
530 return agdmm_send(sdi, "CONF?");
e93cdf42
BV
531}
532
a4394fb3 533static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42
BV
534{
535 struct dev_context *devc;
4435966e 536 char *mstr, *rstr;
d822726d 537 int i, resolution;
e93cdf42 538
38d326e8 539 sr_spew("CONF? response '%s'.", g_match_info_get_string(match));
e93cdf42 540 devc = sdi->priv;
d822726d 541 i = devc->cur_conf->index;
4435966e
AJ
542
543 rstr = g_match_info_fetch(match, 2);
544 if (rstr)
545 sr_atoi(rstr, &resolution);
546 g_free(rstr);
547
e93cdf42
BV
548 mstr = g_match_info_fetch(match, 1);
549 if (!strcmp(mstr, "V")) {
d822726d
AJ
550 devc->cur_mq[i] = SR_MQ_VOLTAGE;
551 devc->cur_unit[i] = SR_UNIT_VOLT;
552 devc->cur_mqflags[i] = 0;
553 devc->cur_exponent[i] = 0;
554 devc->cur_digits[i] = 4 - resolution;
0c5f2abc 555 } else if (!strcmp(mstr, "MV")) {
e6b021f3 556 if (devc->mode_tempaux) {
d822726d 557 devc->cur_mq[i] = SR_MQ_TEMPERATURE;
f3f19d11
UH
558 /* No way to detect whether Fahrenheit or Celsius
559 * is used, so we'll just default to Celsius. */
d822726d
AJ
560 devc->cur_unit[i] = SR_UNIT_CELSIUS;
561 devc->cur_mqflags[i] = 0;
562 devc->cur_exponent[i] = 0;
563 devc->cur_digits[i] = 1;
e6b021f3 564 } else {
d822726d
AJ
565 devc->cur_mq[i] = SR_MQ_VOLTAGE;
566 devc->cur_unit[i] = SR_UNIT_VOLT;
567 devc->cur_mqflags[i] = 0;
568 devc->cur_exponent[i] = -3;
569 devc->cur_digits[i] = 5 - resolution;
e6b021f3 570 }
0c5f2abc 571 } else if (!strcmp(mstr, "A")) {
d822726d
AJ
572 devc->cur_mq[i] = SR_MQ_CURRENT;
573 devc->cur_unit[i] = SR_UNIT_AMPERE;
574 devc->cur_mqflags[i] = 0;
575 devc->cur_exponent[i] = 0;
576 devc->cur_digits[i] = 3 - resolution;
0c5f2abc 577 } else if (!strcmp(mstr, "UA")) {
d822726d
AJ
578 devc->cur_mq[i] = SR_MQ_CURRENT;
579 devc->cur_unit[i] = SR_UNIT_AMPERE;
580 devc->cur_mqflags[i] = 0;
581 devc->cur_exponent[i] = -6;
582 devc->cur_digits[i] = 8 - resolution;
0c5f2abc 583 } else if (!strcmp(mstr, "FREQ")) {
d822726d
AJ
584 devc->cur_mq[i] = SR_MQ_FREQUENCY;
585 devc->cur_unit[i] = SR_UNIT_HERTZ;
586 devc->cur_mqflags[i] = 0;
587 devc->cur_exponent[i] = 0;
588 devc->cur_digits[i] = 2 - resolution;
0c5f2abc 589 } else if (!strcmp(mstr, "RES")) {
e6b021f3 590 if (devc->mode_continuity) {
d822726d
AJ
591 devc->cur_mq[i] = SR_MQ_CONTINUITY;
592 devc->cur_unit[i] = SR_UNIT_BOOLEAN;
e6b021f3 593 } else {
d822726d
AJ
594 devc->cur_mq[i] = SR_MQ_RESISTANCE;
595 devc->cur_unit[i] = SR_UNIT_OHM;
e6b021f3 596 }
d822726d
AJ
597 devc->cur_mqflags[i] = 0;
598 devc->cur_exponent[i] = 0;
599 devc->cur_digits[i] = 1 - resolution;
873c0d11 600 } else if (!strcmp(mstr, "DIOD")) {
d822726d
AJ
601 devc->cur_mq[i] = SR_MQ_VOLTAGE;
602 devc->cur_unit[i] = SR_UNIT_VOLT;
603 devc->cur_mqflags[i] = SR_MQFLAG_DIODE;
604 devc->cur_exponent[i] = 0;
605 devc->cur_digits[i] = 3;
0c5f2abc 606 } else if (!strcmp(mstr, "CAP")) {
d822726d
AJ
607 devc->cur_mq[i] = SR_MQ_CAPACITANCE;
608 devc->cur_unit[i] = SR_UNIT_FARAD;
609 devc->cur_mqflags[i] = 0;
610 devc->cur_exponent[i] = 0;
611 devc->cur_digits[i] = 9 - resolution;
e93cdf42 612 } else
38d326e8 613 sr_dbg("Unknown first argument.");
e93cdf42
BV
614 g_free(mstr);
615
4435966e 616 /* This is based on guess, supposing similarity with other models. */
d822726d 617 devc->cur_encoding[i] = devc->cur_digits[i] + 1;
4435966e 618
e066c32a
BV
619 if (g_match_info_get_match_count(match) == 4) {
620 mstr = g_match_info_fetch(match, 3);
e93cdf42 621 /* Third value, if present, is always AC or DC. */
51b92b7d 622 if (!strcmp(mstr, "AC")) {
d822726d
AJ
623 devc->cur_mqflags[i] |= SR_MQFLAG_AC;
624 if (devc->cur_mq[i] == SR_MQ_VOLTAGE)
625 devc->cur_mqflags[i] |= SR_MQFLAG_RMS;
51b92b7d 626 } else if (!strcmp(mstr, "DC")) {
d822726d 627 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
51b92b7d 628 } else {
a965748a 629 sr_dbg("Unknown first argument '%s'.", mstr);
51b92b7d 630 }
e93cdf42 631 g_free(mstr);
e6b021f3 632 } else
d822726d 633 devc->cur_mqflags[i] &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC);
e93cdf42 634
b907d62f 635 return JOB_CONF;
e93cdf42
BV
636}
637
173378f0 638static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match)
8c0152f2
BV
639{
640 struct dev_context *devc;
4435966e 641 char *mstr, *rstr, *m2;
d822726d 642 int i, resolution;
8c0152f2 643
38d326e8 644 sr_spew("CONF? response '%s'.", g_match_info_get_string(match));
8c0152f2 645 devc = sdi->priv;
d822726d 646 i = devc->cur_conf->index;
4435966e 647
43185ed3
AJ
648 devc->mode_squarewave = 0;
649
d9251a2c 650 rstr = g_match_info_fetch(match, 4);
4435966e 651 if (rstr && sr_atoi(rstr, &resolution) == SR_OK) {
d822726d
AJ
652 devc->cur_digits[i] = -resolution;
653 devc->cur_encoding[i] = -resolution + 1;
4435966e
AJ
654 }
655 g_free(rstr);
656
d9251a2c 657 mstr = g_match_info_fetch(match, 1);
8c0152f2 658 if (!strncmp(mstr, "VOLT", 4)) {
d822726d
AJ
659 devc->cur_mq[i] = SR_MQ_VOLTAGE;
660 devc->cur_unit[i] = SR_UNIT_VOLT;
661 devc->cur_mqflags[i] = 0;
662 devc->cur_exponent[i] = 0;
8f68f36b
AJ
663 if (i == 0 && devc->mode_dbm_dbv) {
664 devc->cur_unit[i] = devc->mode_dbm_dbv;
665 devc->cur_digits[i] = 3;
666 devc->cur_encoding[i] = 4;
667 }
8c0152f2 668 if (mstr[4] == ':') {
96ed8625
AJ
669 if (!strncmp(mstr + 5, "ACDC", 4)) {
670 /* AC + DC offset */
d822726d 671 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS;
96ed8625 672 } else if (!strncmp(mstr + 5, "AC", 2)) {
d822726d 673 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
ee2bcdfc 674 } else if (!strncmp(mstr + 5, "DC", 2)) {
d822726d 675 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
0ceb7038
AJ
676 } else if (!strncmp(mstr + 5, "HRAT", 4)) {
677 devc->cur_mq[i] = SR_MQ_HARMONIC_RATIO;
678 devc->cur_unit[i] = SR_UNIT_PERCENTAGE;
679 devc->cur_digits[i] = 2;
680 devc->cur_encoding[i] = 3;
51b92b7d 681 }
8c0152f2 682 } else
d822726d 683 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
0fe18626 684 } else if (!strncmp(mstr, "CURR", 4)) {
d822726d
AJ
685 devc->cur_mq[i] = SR_MQ_CURRENT;
686 devc->cur_unit[i] = SR_UNIT_AMPERE;
687 devc->cur_mqflags[i] = 0;
688 devc->cur_exponent[i] = 0;
0fe18626
AJ
689 if (mstr[4] == ':') {
690 if (!strncmp(mstr + 5, "ACDC", 4)) {
691 /* AC + DC offset */
d822726d 692 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS;
0fe18626 693 } else if (!strncmp(mstr + 5, "AC", 2)) {
d822726d 694 devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
0fe18626 695 } else if (!strncmp(mstr + 5, "DC", 2)) {
d822726d 696 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
0fe18626
AJ
697 }
698 } else
d822726d 699 devc->cur_mqflags[i] |= SR_MQFLAG_DC;
0c5f2abc 700 } else if (!strcmp(mstr, "RES")) {
d822726d
AJ
701 devc->cur_mq[i] = SR_MQ_RESISTANCE;
702 devc->cur_unit[i] = SR_UNIT_OHM;
703 devc->cur_mqflags[i] = 0;
704 devc->cur_exponent[i] = 0;
43185ed3 705 } else if (!strcmp(mstr, "COND")) {
d822726d
AJ
706 devc->cur_mq[i] = SR_MQ_CONDUCTANCE;
707 devc->cur_unit[i] = SR_UNIT_SIEMENS;
708 devc->cur_mqflags[i] = 0;
709 devc->cur_exponent[i] = 0;
0c5f2abc 710 } else if (!strcmp(mstr, "CAP")) {
d822726d
AJ
711 devc->cur_mq[i] = SR_MQ_CAPACITANCE;
712 devc->cur_unit[i] = SR_UNIT_FARAD;
713 devc->cur_mqflags[i] = 0;
714 devc->cur_exponent[i] = 0;
43185ed3 715 } else if (!strncmp(mstr, "FREQ", 4) || !strncmp(mstr, "FC1", 3)) {
d822726d
AJ
716 devc->cur_mq[i] = SR_MQ_FREQUENCY;
717 devc->cur_unit[i] = SR_UNIT_HERTZ;
718 devc->cur_mqflags[i] = 0;
719 devc->cur_exponent[i] = 0;
7ab126ca
AJ
720 } else if (!strncmp(mstr, "PULS:PWID", 9)) {
721 devc->cur_mq[i] = SR_MQ_PULSE_WIDTH;
722 devc->cur_unit[i] = SR_UNIT_SECOND;
723 devc->cur_mqflags[i] = 0;
724 devc->cur_exponent[i] = 0;
725 devc->cur_encoding[i] = MIN(devc->cur_encoding[i], 6);
726 } else if (!strncmp(mstr, "PULS:PDUT", 9)) {
727 devc->cur_mq[i] = SR_MQ_DUTY_CYCLE;
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] = 3;
732 devc->cur_encoding[i] = 4;
0c5f2abc 733 } else if (!strcmp(mstr, "CONT")) {
d822726d 734 devc->cur_mq[i] = SR_MQ_CONTINUITY;
d2f6abf6 735 devc->cur_unit[i] = SR_UNIT_OHM;
d822726d
AJ
736 devc->cur_mqflags[i] = 0;
737 devc->cur_exponent[i] = 0;
873c0d11 738 } else if (!strcmp(mstr, "DIOD")) {
d822726d
AJ
739 devc->cur_mq[i] = SR_MQ_VOLTAGE;
740 devc->cur_unit[i] = SR_UNIT_VOLT;
741 devc->cur_mqflags[i] = SR_MQFLAG_DIODE;
742 devc->cur_exponent[i] = 0;
0ceb7038
AJ
743 if (devc->profile->model == KEYSIGHT_U1281 ||
744 devc->profile->model == KEYSIGHT_U1282) {
745 devc->cur_digits[i] = 4;
746 devc->cur_encoding[i] = 5;
747 } else {
748 devc->cur_digits[i] = 3;
749 devc->cur_encoding[i] = 4;
750 }
43185ed3 751 } else if (!strncmp(mstr, "T1", 2) || !strncmp(mstr, "T2", 2) ||
4fdedbbb 752 !strncmp(mstr, "TEMP", 4)) {
d822726d 753 devc->cur_mq[i] = SR_MQ_TEMPERATURE;
a965748a 754 m2 = g_match_info_fetch(match, 2);
c2e3c322 755 if (!m2 && devc->profile->nb_channels == 3)
d822726d
AJ
756 /*
757 * TEMP without param is for secondary display (channel P2)
758 * and is identical to channel P3, so discard it.
759 */
760 devc->cur_mq[i] = -1;
c2e3c322 761 else if (m2 && !strcmp(m2, "FAR"))
d822726d 762 devc->cur_unit[i] = SR_UNIT_FAHRENHEIT;
a965748a 763 else
d822726d 764 devc->cur_unit[i] = SR_UNIT_CELSIUS;
a965748a 765 g_free(m2);
d822726d
AJ
766 devc->cur_mqflags[i] = 0;
767 devc->cur_exponent[i] = 0;
768 devc->cur_digits[i] = 1;
769 devc->cur_encoding[i] = 2;
0c5f2abc 770 } else if (!strcmp(mstr, "SCOU")) {
a965748a
BV
771 /*
772 * Switch counter, not supported. Not sure what values
773 * come from FETC in this mode, or how they would map
774 * into libsigrok.
775 */
0c5f2abc 776 } else if (!strncmp(mstr, "CPER:", 5)) {
d822726d
AJ
777 devc->cur_mq[i] = SR_MQ_CURRENT;
778 devc->cur_unit[i] = SR_UNIT_PERCENTAGE;
779 devc->cur_mqflags[i] = 0;
780 devc->cur_exponent[i] = 0;
781 devc->cur_digits[i] = 2;
782 devc->cur_encoding[i] = 3;
43185ed3
AJ
783 } else if (!strcmp(mstr, "SQU")) {
784 /*
785 * Square wave output, not supported. FETC just return
786 * an error in this mode, so don't even call it.
787 */
788 devc->mode_squarewave = 1;
29bdeeb5
AJ
789 } else if (!strcmp(mstr, "NCV")) {
790 devc->cur_mq[i] = SR_MQ_VOLTAGE;
791 devc->cur_unit[i] = SR_UNIT_VOLT;
792 devc->cur_mqflags[i] = SR_MQFLAG_AC;
0ceb7038
AJ
793 if (devc->profile->model == KEYSIGHT_U1281 ||
794 devc->profile->model == KEYSIGHT_U1282) {
795 devc->cur_exponent[i] = -3;
796 devc->cur_digits[i] = -1;
797 devc->cur_encoding[i] = 0;
798 } else {
799 devc->cur_exponent[i] = 0;
800 devc->cur_digits[i] = 2;
801 devc->cur_encoding[i] = 3;
802 }
51b92b7d 803 } else {
a965748a 804 sr_dbg("Unknown first argument '%s'.", mstr);
51b92b7d 805 }
8c0152f2
BV
806 g_free(mstr);
807
b907d62f
AJ
808 struct sr_channel *prev_conf = devc->cur_conf;
809 devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf);
c2e3c322 810 if (devc->cur_conf->index >= MIN(devc->profile->nb_channels, 2))
b907d62f
AJ
811 devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf);
812 if (devc->cur_conf->index > prev_conf->index)
813 return JOB_AGAIN;
814 else
815 return JOB_CONF;
8c0152f2
BV
816}
817
63bb11ba
AJ
818static int send_log(const struct sr_dev_inst *sdi)
819{
820 const char *source[] = { "LOG:HAND", "LOG:TRIG", "LOG:AUTO", "LOG:EXPO" };
821 struct dev_context *devc = sdi->priv;
822 return agdmm_send(sdi, "%s %d",
823 source[devc->data_source - 1], devc->cur_sample);
824}
825
1af3f40e
AJ
826static int recv_log(const struct sr_dev_inst *sdi, GMatchInfo *match,
827 const int mqs[], const int units[], const int exponents[],
828 unsigned int num_functions)
63bb11ba 829{
63bb11ba
AJ
830 struct dev_context *devc;
831 struct sr_datafeed_packet packet;
832 struct sr_datafeed_analog analog;
833 struct sr_analog_encoding encoding;
834 struct sr_analog_meaning meaning;
835 struct sr_analog_spec spec;
836 char *mstr;
837 unsigned function;
838 int value, negative, overload, exponent, alternate_unit, mq, unit;
839 int mqflags = 0;
840 float fvalue;
841
842 sr_spew("LOG response '%s'.", g_match_info_get_string(match));
843
844 devc = sdi->priv;
845
846 mstr = g_match_info_fetch(match, 2);
1af3f40e 847 if (sr_atoi(mstr, (int*)&function) != SR_OK || function >= num_functions) {
63bb11ba
AJ
848 g_free(mstr);
849 sr_dbg("Invalid function.");
850 return SR_ERR;
851 }
852 g_free(mstr);
853
854 mstr = g_match_info_fetch(match, 3);
855 if (sr_atoi(mstr, &value) != SR_OK) {
856 g_free(mstr);
857 sr_dbg("Invalid value.");
858 return SR_ERR;
859 }
860 g_free(mstr);
861
862 mstr = g_match_info_fetch(match, 1);
863 negative = mstr[7] & 2 ? -1 : 1;
864 overload = mstr[8] & 4;
865 exponent = (mstr[9] & 0xF) + exponents[function];
866 alternate_unit = mstr[10] & 1;
867
868 if (mstr[ 8] & 1) mqflags |= SR_MQFLAG_DC;
869 if (mstr[ 8] & 2) mqflags |= SR_MQFLAG_AC;
870 if (mstr[11] & 4) mqflags |= SR_MQFLAG_RELATIVE;
871 if (mstr[12] & 1) mqflags |= SR_MQFLAG_AVG;
872 if (mstr[12] & 2) mqflags |= SR_MQFLAG_MIN;
873 if (mstr[12] & 4) mqflags |= SR_MQFLAG_MAX;
874 if (function == 5) mqflags |= SR_MQFLAG_DIODE;
875 g_free(mstr);
876
877 mq = mqs[function];
878 unit = units[function];
879 if (alternate_unit) {
880 if (mq == SR_MQ_RESISTANCE)
881 mq = SR_MQ_CONTINUITY;
882 if (unit == SR_UNIT_DECIBEL_MW)
883 unit = SR_UNIT_DECIBEL_VOLT;
884 if (unit == SR_UNIT_CELSIUS) {
885 unit = SR_UNIT_FAHRENHEIT;
0ceb7038
AJ
886 if (devc->profile->model == KEYSIGHT_U1281 ||
887 devc->profile->model == KEYSIGHT_U1282)
888 exponent--;
63bb11ba
AJ
889 }
890 }
891
892 if (overload)
893 fvalue = NAN;
894 else
895 fvalue = negative * value * powf(10, exponent);
896
897 sr_analog_init(&analog, &encoding, &meaning, &spec, -exponent);
898 analog.meaning->mq = mq;
899 analog.meaning->unit = unit;
900 analog.meaning->mqflags = mqflags;
901 analog.meaning->channels = g_slist_append(NULL, devc->cur_channel);
902 analog.num_samples = 1;
903 analog.data = &fvalue;
904 packet.type = SR_DF_ANALOG;
905 packet.payload = &analog;
906 sr_session_send(sdi, &packet);
907 g_slist_free(analog.meaning->channels);
908
909 sr_sw_limits_update_samples_read(&devc->limits, 1);
910 devc->cur_sample++;
911
912 return JOB_LOG;
913}
914
0ceb7038
AJ
915static int recv_log_u124xc(const struct sr_dev_inst *sdi, GMatchInfo *match)
916{
917 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_HARMONIC_RATIO, SR_MQ_CURRENT };
918 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_PERCENTAGE };
919 static const int exponents[] = { -5, -4, -7, -3, -2, -3, -1, -10, -2, -2, -2 };
920
921 return recv_log(sdi, match, mqs, units, exponents, ARRAY_SIZE(mqs));
922}
923
1af3f40e
AJ
924static int recv_log_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match)
925{
926 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 };
927 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 };
928 static const int exponents[] = { -6, -4, -9, -4, -3, -4, -1, -12, -3, -3, -6, -3, -2, -11 };
929
930 return recv_log(sdi, match, mqs, units, exponents, ARRAY_SIZE(mqs));
931}
932
81599cc5
BV
933/* This comes in whenever the rotary switch is changed to a new position.
934 * We could use it to determine the major measurement mode, but we already
935 * have the output of CONF? for that, which is more detailed. However
936 * we do need to catch this here, or it'll show up in some other output. */
a4394fb3 937static int recv_switch(const struct sr_dev_inst *sdi, GMatchInfo *match)
e93cdf42 938{
b907d62f 939 struct dev_context *devc = sdi->priv;
e93cdf42 940
38d326e8 941 sr_spew("Switch '%s'.", g_match_info_get_string(match));
e93cdf42 942
b907d62f
AJ
943 devc->current_job = 0;
944 devc->job_running = FALSE;
945 memset(devc->jobs_start, 0, sizeof(devc->jobs_start));
946 devc->cur_mq[0] = -1;
947 if (devc->profile->nb_channels > 2)
948 devc->cur_mq[1] = -1;
949
e93cdf42
BV
950 return SR_OK;
951}
952
63bb11ba
AJ
953static int recv_err(const struct sr_dev_inst *sdi, GMatchInfo *match)
954{
955 struct dev_context *devc = sdi->priv;
956
957 (void) match;
958
959 if (devc->data_source != DATA_SOURCE_LIVE)
960 return JOB_STOP; /* In log mode, stop acquisition after receiving *E. */
961 else
962 return JOB_AGAIN;
963}
964
b907d62f 965/* Poll CONF/STAT at 1Hz and values at samplerate. */
63bb11ba 966SR_PRIV const struct agdmm_job agdmm_jobs_live[] = {
b907d62f
AJ
967 { JOB_FETC, SAMPLERATE_INTERVAL, send_fetc },
968 { JOB_CONF, 1000, send_conf },
969 { JOB_STAT, 1000, send_stat },
9e9dba7b 970 ALL_ZERO
e93cdf42
BV
971};
972
63bb11ba
AJ
973/* Poll LOG as fast as possible. */
974SR_PRIV const struct agdmm_job agdmm_jobs_log[] = {
975 { JOB_LOG, 0, send_log },
976 ALL_ZERO
977};
978
8c0152f2
BV
979SR_PRIV const struct agdmm_recv agdmm_recvs_u123x[] = {
980 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u123x },
a4394fb3
BV
981 { "^\\*([0-9])$", recv_switch },
982 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
983 { "^\"(V|MV|A|UA|FREQ),(\\d),(AC|DC)\"$", recv_conf_u123x },
984 { "^\"(RES|CAP),(\\d)\"$", recv_conf_u123x},
873c0d11 985 { "^\"(DIOD)\"$", recv_conf_u123x },
9e9dba7b 986 ALL_ZERO
e93cdf42
BV
987};
988
173378f0
BV
989SR_PRIV const struct agdmm_recv agdmm_recvs_u124x[] = {
990 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u124x },
991 { "^\\*([0-9])$", recv_switch },
992 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
4435966e
AJ
993 { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
994 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
0fe18626 995 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
4435966e 996 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
a965748a 997 { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
873c0d11 998 { "^\"(DIOD)\"$", recv_conf_u124x_5x },
9e9dba7b 999 ALL_ZERO
173378f0
BV
1000};
1001
0ceb7038
AJ
1002SR_PRIV const struct agdmm_recv agdmm_recvs_u124xc[] = {
1003 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u124xc },
1004 { "^\\*([0-9])$", recv_switch },
1005 { "^([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))$", recv_fetc },
1006 { "^\"(VOLT|VOLT:AC|VOLT:HRAT|CURR|CURR:AC|RES|CONT|CAP|FREQ|FREQ:AC) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
1007 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
1008 { "^\"(TEMP:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
1009 { "^\"(NCV) (HI|LO)\"$", recv_conf_u124x_5x },
1010 { "^\"(DIOD|TEMP)\"$", recv_conf_u124x_5x },
1011 { "^\"((\\d{2})(\\d{5})\\d{7})\"$", recv_log_u124xc },
1012 { "^\\*E$", recv_err },
1013 ALL_ZERO
1014};
1015
8c0152f2
BV
1016SR_PRIV const struct agdmm_recv agdmm_recvs_u125x[] = {
1017 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u125x },
1018 { "^\\*([0-9])$", recv_switch },
1019 { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc },
4435966e
AJ
1020 { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
1021 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
0fe18626 1022 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
4435966e 1023 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
c7f5219e 1024 { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
873c0d11 1025 { "^\"(DIOD)\"$", recv_conf_u124x_5x },
9e9dba7b 1026 ALL_ZERO
8c0152f2 1027};
43185ed3
AJ
1028
1029SR_PRIV const struct agdmm_recv agdmm_recvs_u128x[] = {
1030 { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u128x },
1031 { "^\\*([0-9])$", recv_switch },
1032 { "^([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))$", recv_fetc },
d2f6abf6 1033 { "^\"(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 },
43185ed3
AJ
1034 { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
1035 { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
1036 { "^\"(FREQ:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
1037 { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
7ab126ca 1038 { "^\"(PULS:PWID|PULS:PWID:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x },
43185ed3 1039 { "^\"(TEMP:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x },
29bdeeb5 1040 { "^\"(NCV) (HIGH|LOW)\"$", recv_conf_u124x_5x },
7ab126ca 1041 { "^\"(DIOD|SQU|PULS:PDUT|TEMP)\"$", recv_conf_u124x_5x },
63bb11ba
AJ
1042 { "^\"((\\d{2})(\\d{5})\\d{7})\"$", recv_log_u128x },
1043 { "^\\*E$", recv_err },
43185ed3
AJ
1044 ALL_ZERO
1045};