]>
Commit | Line | Data |
---|---|---|
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 | ||
36 | static const struct agdmm_job *job_current(const struct dev_context *devc) | |
37 | { | |
63bb11ba | 38 | return &devc->jobs[devc->current_job]; |
b907d62f AJ |
39 | } |
40 | ||
41 | static void job_done(struct dev_context *devc) | |
42 | { | |
43 | devc->job_running = FALSE; | |
44 | } | |
45 | ||
46 | static void job_again(struct dev_context *devc) | |
47 | { | |
48 | devc->job_again = TRUE; | |
49 | } | |
50 | ||
51 | static gboolean job_is_running(const struct dev_context *devc) | |
52 | { | |
53 | return devc->job_running; | |
54 | } | |
55 | ||
56 | static 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 | ||
66 | static 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 | ||
73 | static 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 | ||
84 | static 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 | ||
93 | static 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 |
101 | static 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 | 119 | static 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 | ||
169 | SR_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) |
695dc859 | 203 | sdi->driver->dev_acquisition_stop(sdi); |
63bb11ba AJ |
204 | else |
205 | dispatch(sdi); | |
e93cdf42 BV |
206 | |
207 | return TRUE; | |
208 | } | |
209 | ||
d822726d | 210 | static 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 | 234 | static int send_stat(const struct sr_dev_inst *sdi) |
e93cdf42 | 235 | { |
e93cdf42 BV |
236 | return agdmm_send(sdi, "STAT?"); |
237 | } | |
238 | ||
8c0152f2 | 239 | static 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 |
283 | static 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 | ||
8c0152f2 BV |
315 | static int recv_stat_u125x(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); | |
38d326e8 | 322 | sr_spew("STAT response '%s'.", s); |
8c0152f2 | 323 | |
8f68f36b AJ |
324 | /* dBm/dBV modes. */ |
325 | if ((s[2] & ~0x20) == 'M') | |
326 | devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW; | |
327 | else if ((s[2] & ~0x20) == 'V') | |
328 | devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT; | |
329 | else | |
330 | devc->mode_dbm_dbv = 0; | |
331 | ||
8c0152f2 BV |
332 | /* Peak hold mode. */ |
333 | if (s[4] == '1') | |
d822726d | 334 | devc->cur_mqflags[0] |= SR_MQFLAG_MAX; |
8c0152f2 | 335 | else |
d822726d | 336 | devc->cur_mqflags[0] &= ~SR_MQFLAG_MAX; |
8c0152f2 BV |
337 | |
338 | /* Triggered hold mode. */ | |
339 | if (s[7] == '1') | |
d822726d | 340 | devc->cur_mqflags[0] |= SR_MQFLAG_HOLD; |
8c0152f2 | 341 | else |
d822726d | 342 | devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD; |
8c0152f2 BV |
343 | |
344 | g_free(s); | |
345 | ||
b907d62f | 346 | return JOB_STAT; |
8c0152f2 BV |
347 | } |
348 | ||
43185ed3 AJ |
349 | static int recv_stat_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match) |
350 | { | |
351 | struct dev_context *devc; | |
352 | char *s; | |
353 | ||
354 | devc = sdi->priv; | |
355 | s = g_match_info_fetch(match, 1); | |
356 | sr_spew("STAT response '%s'.", s); | |
357 | ||
358 | /* Max, Min or Avg mode -- no way to tell which, so we'll | |
359 | * set both flags to denote it's not a normal measurement. */ | |
360 | if (s[0] == '1') | |
d822726d | 361 | devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG; |
43185ed3 | 362 | else |
d822726d | 363 | devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG); |
43185ed3 | 364 | |
8f68f36b AJ |
365 | /* dBm/dBV modes. */ |
366 | if ((s[2] & ~0x20) == 'M') | |
367 | devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW; | |
368 | else if ((s[2] & ~0x20) == 'V') | |
369 | devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT; | |
370 | else | |
371 | devc->mode_dbm_dbv = 0; | |
372 | ||
43185ed3 AJ |
373 | /* Peak hold mode. */ |
374 | if (s[4] == '4') | |
d822726d | 375 | devc->cur_mqflags[0] |= SR_MQFLAG_MAX; |
43185ed3 | 376 | else |
d822726d | 377 | devc->cur_mqflags[0] &= ~SR_MQFLAG_MAX; |
43185ed3 AJ |
378 | |
379 | /* Null function. */ | |
380 | if (s[1] == '1') | |
d822726d | 381 | devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE; |
43185ed3 | 382 | else |
d822726d | 383 | devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE; |
43185ed3 AJ |
384 | |
385 | /* Triggered or auto hold modes. */ | |
386 | if (s[7] == '1' || s[11] == '1') | |
d822726d | 387 | devc->cur_mqflags[0] |= SR_MQFLAG_HOLD; |
43185ed3 | 388 | else |
d822726d | 389 | devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD; |
43185ed3 AJ |
390 | |
391 | g_free(s); | |
392 | ||
b907d62f | 393 | return JOB_STAT; |
43185ed3 AJ |
394 | } |
395 | ||
a4394fb3 | 396 | static int send_fetc(const struct sr_dev_inst *sdi) |
e93cdf42 | 397 | { |
b907d62f AJ |
398 | struct dev_context *devc = sdi->priv; |
399 | ||
43185ed3 | 400 | if (devc->mode_squarewave) |
b907d62f AJ |
401 | return SR_ERR_NA; |
402 | ||
d822726d AJ |
403 | if (devc->cur_channel->index > 0) |
404 | return agdmm_send(sdi, "FETC? @%d", devc->cur_channel->index + 1); | |
405 | else | |
406 | return agdmm_send(sdi, "FETC?"); | |
e93cdf42 BV |
407 | } |
408 | ||
a4394fb3 | 409 | static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) |
e93cdf42 BV |
410 | { |
411 | struct dev_context *devc; | |
412 | struct sr_datafeed_packet packet; | |
16aef676 UH |
413 | struct sr_datafeed_analog analog; |
414 | struct sr_analog_encoding encoding; | |
415 | struct sr_analog_meaning meaning; | |
416 | struct sr_analog_spec spec; | |
e93cdf42 | 417 | float fvalue; |
f216eb86 | 418 | const char *s; |
fe9d5abe | 419 | char *mstr; |
8f68f36b | 420 | int i, exp; |
e93cdf42 | 421 | |
38d326e8 | 422 | sr_spew("FETC reply '%s'.", g_match_info_get_string(match)); |
e93cdf42 | 423 | devc = sdi->priv; |
d822726d | 424 | i = devc->cur_channel->index; |
e93cdf42 | 425 | |
d822726d | 426 | if (devc->cur_mq[i] == -1) |
b907d62f AJ |
427 | /* This detects when channel P2 is reporting TEMP as an identical |
428 | * copy of channel P3. In this case, we just skip P2. */ | |
429 | goto skip_value; | |
e93cdf42 | 430 | |
f216eb86 BV |
431 | s = g_match_info_get_string(match); |
432 | if (!strcmp(s, "-9.90000000E+37") || !strcmp(s, "+9.90000000E+37")) { | |
74ac7d7f | 433 | /* An invalid measurement shows up on the display as "O.L", but |
e93cdf42 BV |
434 | * comes through like this. Since comparing 38-digit floats |
435 | * is rather problematic, we'll cut through this here. */ | |
436 | fvalue = NAN; | |
437 | } else { | |
438 | mstr = g_match_info_fetch(match, 1); | |
7c03b564 | 439 | if (sr_atof_ascii(mstr, &fvalue) != SR_OK) { |
fe9d5abe | 440 | g_free(mstr); |
51b92b7d | 441 | sr_dbg("Invalid float."); |
e93cdf42 BV |
442 | return SR_ERR; |
443 | } | |
fe9d5abe | 444 | g_free(mstr); |
d822726d AJ |
445 | if (devc->cur_exponent[i] != 0) |
446 | fvalue *= powf(10, devc->cur_exponent[i]); | |
e93cdf42 BV |
447 | } |
448 | ||
8f68f36b AJ |
449 | if (devc->cur_unit[i] == SR_UNIT_DECIBEL_MW || |
450 | devc->cur_unit[i] == SR_UNIT_DECIBEL_VOLT || | |
451 | devc->cur_unit[i] == SR_UNIT_PERCENTAGE) { | |
452 | mstr = g_match_info_fetch(match, 2); | |
453 | if (mstr && sr_atoi(mstr, &exp) == SR_OK) { | |
454 | devc->cur_digits[i] = MIN(4 - exp, devc->cur_digits[i]); | |
455 | devc->cur_encoding[i] = MIN(5 - exp, devc->cur_encoding[i]); | |
456 | } | |
457 | g_free(mstr); | |
458 | } | |
459 | ||
4435966e | 460 | sr_analog_init(&analog, &encoding, &meaning, &spec, |
d822726d AJ |
461 | devc->cur_digits[i] - devc->cur_exponent[i]); |
462 | analog.meaning->mq = devc->cur_mq[i]; | |
463 | analog.meaning->unit = devc->cur_unit[i]; | |
464 | analog.meaning->mqflags = devc->cur_mqflags[i]; | |
465 | analog.meaning->channels = g_slist_append(NULL, devc->cur_channel); | |
e93cdf42 BV |
466 | analog.num_samples = 1; |
467 | analog.data = &fvalue; | |
d822726d | 468 | encoding.digits = devc->cur_encoding[i] - devc->cur_exponent[i]; |
16aef676 | 469 | packet.type = SR_DF_ANALOG; |
e93cdf42 | 470 | packet.payload = &analog; |
695dc859 | 471 | sr_session_send(sdi, &packet); |
d822726d | 472 | g_slist_free(analog.meaning->channels); |
e93cdf42 | 473 | |
5b6829ea | 474 | sr_sw_limits_update_samples_read(&devc->limits, 1); |
e93cdf42 | 475 | |
b907d62f AJ |
476 | skip_value:; |
477 | struct sr_channel *prev_chan = devc->cur_channel; | |
478 | devc->cur_channel = sr_next_enabled_channel(sdi, devc->cur_channel); | |
479 | if (devc->cur_channel->index > prev_chan->index) | |
480 | return JOB_AGAIN; | |
481 | else | |
482 | return JOB_FETC; | |
e93cdf42 BV |
483 | } |
484 | ||
a4394fb3 | 485 | static int send_conf(const struct sr_dev_inst *sdi) |
e93cdf42 | 486 | { |
d822726d AJ |
487 | struct dev_context *devc = sdi->priv; |
488 | ||
d822726d | 489 | /* Do not try to send CONF? for internal temperature channel. */ |
d822726d AJ |
490 | if (devc->cur_conf->index == MAX(devc->profile->nb_channels - 1, 1)) |
491 | return SR_ERR_NA; | |
492 | ||
493 | if (devc->cur_conf->index > 0) | |
494 | return agdmm_send(sdi, "CONF? @%d", devc->cur_conf->index + 1); | |
495 | else | |
496 | return agdmm_send(sdi, "CONF?"); | |
e93cdf42 BV |
497 | } |
498 | ||
a4394fb3 | 499 | static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) |
e93cdf42 BV |
500 | { |
501 | struct dev_context *devc; | |
4435966e | 502 | char *mstr, *rstr; |
d822726d | 503 | int i, resolution; |
e93cdf42 | 504 | |
38d326e8 | 505 | sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); |
e93cdf42 | 506 | devc = sdi->priv; |
d822726d | 507 | i = devc->cur_conf->index; |
4435966e AJ |
508 | |
509 | rstr = g_match_info_fetch(match, 2); | |
510 | if (rstr) | |
511 | sr_atoi(rstr, &resolution); | |
512 | g_free(rstr); | |
513 | ||
e93cdf42 BV |
514 | mstr = g_match_info_fetch(match, 1); |
515 | if (!strcmp(mstr, "V")) { | |
d822726d AJ |
516 | devc->cur_mq[i] = SR_MQ_VOLTAGE; |
517 | devc->cur_unit[i] = SR_UNIT_VOLT; | |
518 | devc->cur_mqflags[i] = 0; | |
519 | devc->cur_exponent[i] = 0; | |
520 | devc->cur_digits[i] = 4 - resolution; | |
0c5f2abc | 521 | } else if (!strcmp(mstr, "MV")) { |
e6b021f3 | 522 | if (devc->mode_tempaux) { |
d822726d | 523 | devc->cur_mq[i] = SR_MQ_TEMPERATURE; |
f3f19d11 UH |
524 | /* No way to detect whether Fahrenheit or Celsius |
525 | * is used, so we'll just default to Celsius. */ | |
d822726d AJ |
526 | devc->cur_unit[i] = SR_UNIT_CELSIUS; |
527 | devc->cur_mqflags[i] = 0; | |
528 | devc->cur_exponent[i] = 0; | |
529 | devc->cur_digits[i] = 1; | |
e6b021f3 | 530 | } else { |
d822726d AJ |
531 | devc->cur_mq[i] = SR_MQ_VOLTAGE; |
532 | devc->cur_unit[i] = SR_UNIT_VOLT; | |
533 | devc->cur_mqflags[i] = 0; | |
534 | devc->cur_exponent[i] = -3; | |
535 | devc->cur_digits[i] = 5 - resolution; | |
e6b021f3 | 536 | } |
0c5f2abc | 537 | } else if (!strcmp(mstr, "A")) { |
d822726d AJ |
538 | devc->cur_mq[i] = SR_MQ_CURRENT; |
539 | devc->cur_unit[i] = SR_UNIT_AMPERE; | |
540 | devc->cur_mqflags[i] = 0; | |
541 | devc->cur_exponent[i] = 0; | |
542 | devc->cur_digits[i] = 3 - resolution; | |
0c5f2abc | 543 | } else if (!strcmp(mstr, "UA")) { |
d822726d AJ |
544 | devc->cur_mq[i] = SR_MQ_CURRENT; |
545 | devc->cur_unit[i] = SR_UNIT_AMPERE; | |
546 | devc->cur_mqflags[i] = 0; | |
547 | devc->cur_exponent[i] = -6; | |
548 | devc->cur_digits[i] = 8 - resolution; | |
0c5f2abc | 549 | } else if (!strcmp(mstr, "FREQ")) { |
d822726d AJ |
550 | devc->cur_mq[i] = SR_MQ_FREQUENCY; |
551 | devc->cur_unit[i] = SR_UNIT_HERTZ; | |
552 | devc->cur_mqflags[i] = 0; | |
553 | devc->cur_exponent[i] = 0; | |
554 | devc->cur_digits[i] = 2 - resolution; | |
0c5f2abc | 555 | } else if (!strcmp(mstr, "RES")) { |
e6b021f3 | 556 | if (devc->mode_continuity) { |
d822726d AJ |
557 | devc->cur_mq[i] = SR_MQ_CONTINUITY; |
558 | devc->cur_unit[i] = SR_UNIT_BOOLEAN; | |
e6b021f3 | 559 | } else { |
d822726d AJ |
560 | devc->cur_mq[i] = SR_MQ_RESISTANCE; |
561 | devc->cur_unit[i] = SR_UNIT_OHM; | |
e6b021f3 | 562 | } |
d822726d AJ |
563 | devc->cur_mqflags[i] = 0; |
564 | devc->cur_exponent[i] = 0; | |
565 | devc->cur_digits[i] = 1 - resolution; | |
873c0d11 | 566 | } else if (!strcmp(mstr, "DIOD")) { |
d822726d AJ |
567 | devc->cur_mq[i] = SR_MQ_VOLTAGE; |
568 | devc->cur_unit[i] = SR_UNIT_VOLT; | |
569 | devc->cur_mqflags[i] = SR_MQFLAG_DIODE; | |
570 | devc->cur_exponent[i] = 0; | |
571 | devc->cur_digits[i] = 3; | |
0c5f2abc | 572 | } else if (!strcmp(mstr, "CAP")) { |
d822726d AJ |
573 | devc->cur_mq[i] = SR_MQ_CAPACITANCE; |
574 | devc->cur_unit[i] = SR_UNIT_FARAD; | |
575 | devc->cur_mqflags[i] = 0; | |
576 | devc->cur_exponent[i] = 0; | |
577 | devc->cur_digits[i] = 9 - resolution; | |
e93cdf42 | 578 | } else |
38d326e8 | 579 | sr_dbg("Unknown first argument."); |
e93cdf42 BV |
580 | g_free(mstr); |
581 | ||
4435966e | 582 | /* This is based on guess, supposing similarity with other models. */ |
d822726d | 583 | devc->cur_encoding[i] = devc->cur_digits[i] + 1; |
4435966e | 584 | |
e066c32a BV |
585 | if (g_match_info_get_match_count(match) == 4) { |
586 | mstr = g_match_info_fetch(match, 3); | |
e93cdf42 | 587 | /* Third value, if present, is always AC or DC. */ |
51b92b7d | 588 | if (!strcmp(mstr, "AC")) { |
d822726d AJ |
589 | devc->cur_mqflags[i] |= SR_MQFLAG_AC; |
590 | if (devc->cur_mq[i] == SR_MQ_VOLTAGE) | |
591 | devc->cur_mqflags[i] |= SR_MQFLAG_RMS; | |
51b92b7d | 592 | } else if (!strcmp(mstr, "DC")) { |
d822726d | 593 | devc->cur_mqflags[i] |= SR_MQFLAG_DC; |
51b92b7d | 594 | } else { |
a965748a | 595 | sr_dbg("Unknown first argument '%s'.", mstr); |
51b92b7d | 596 | } |
e93cdf42 | 597 | g_free(mstr); |
e6b021f3 | 598 | } else |
d822726d | 599 | devc->cur_mqflags[i] &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC); |
e93cdf42 | 600 | |
b907d62f | 601 | return JOB_CONF; |
e93cdf42 BV |
602 | } |
603 | ||
173378f0 | 604 | static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match) |
8c0152f2 BV |
605 | { |
606 | struct dev_context *devc; | |
4435966e | 607 | char *mstr, *rstr, *m2; |
d822726d | 608 | int i, resolution; |
8c0152f2 | 609 | |
38d326e8 | 610 | sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); |
8c0152f2 | 611 | devc = sdi->priv; |
d822726d | 612 | i = devc->cur_conf->index; |
4435966e | 613 | |
43185ed3 AJ |
614 | devc->mode_squarewave = 0; |
615 | ||
d9251a2c | 616 | rstr = g_match_info_fetch(match, 4); |
4435966e | 617 | if (rstr && sr_atoi(rstr, &resolution) == SR_OK) { |
d822726d AJ |
618 | devc->cur_digits[i] = -resolution; |
619 | devc->cur_encoding[i] = -resolution + 1; | |
4435966e AJ |
620 | } |
621 | g_free(rstr); | |
622 | ||
d9251a2c | 623 | mstr = g_match_info_fetch(match, 1); |
8c0152f2 | 624 | if (!strncmp(mstr, "VOLT", 4)) { |
d822726d AJ |
625 | devc->cur_mq[i] = SR_MQ_VOLTAGE; |
626 | devc->cur_unit[i] = SR_UNIT_VOLT; | |
627 | devc->cur_mqflags[i] = 0; | |
628 | devc->cur_exponent[i] = 0; | |
8f68f36b AJ |
629 | if (i == 0 && devc->mode_dbm_dbv) { |
630 | devc->cur_unit[i] = devc->mode_dbm_dbv; | |
631 | devc->cur_digits[i] = 3; | |
632 | devc->cur_encoding[i] = 4; | |
633 | } | |
8c0152f2 | 634 | if (mstr[4] == ':') { |
96ed8625 AJ |
635 | if (!strncmp(mstr + 5, "ACDC", 4)) { |
636 | /* AC + DC offset */ | |
d822726d | 637 | devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS; |
96ed8625 | 638 | } else if (!strncmp(mstr + 5, "AC", 2)) { |
d822726d | 639 | devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_RMS; |
ee2bcdfc | 640 | } else if (!strncmp(mstr + 5, "DC", 2)) { |
d822726d | 641 | devc->cur_mqflags[i] |= SR_MQFLAG_DC; |
51b92b7d | 642 | } |
8c0152f2 | 643 | } else |
d822726d | 644 | devc->cur_mqflags[i] |= SR_MQFLAG_DC; |
0fe18626 | 645 | } else if (!strncmp(mstr, "CURR", 4)) { |
d822726d AJ |
646 | devc->cur_mq[i] = SR_MQ_CURRENT; |
647 | devc->cur_unit[i] = SR_UNIT_AMPERE; | |
648 | devc->cur_mqflags[i] = 0; | |
649 | devc->cur_exponent[i] = 0; | |
0fe18626 AJ |
650 | if (mstr[4] == ':') { |
651 | if (!strncmp(mstr + 5, "ACDC", 4)) { | |
652 | /* AC + DC offset */ | |
d822726d | 653 | devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS; |
0fe18626 | 654 | } else if (!strncmp(mstr + 5, "AC", 2)) { |
d822726d | 655 | devc->cur_mqflags[i] |= SR_MQFLAG_AC | SR_MQFLAG_RMS; |
0fe18626 | 656 | } else if (!strncmp(mstr + 5, "DC", 2)) { |
d822726d | 657 | devc->cur_mqflags[i] |= SR_MQFLAG_DC; |
0fe18626 AJ |
658 | } |
659 | } else | |
d822726d | 660 | devc->cur_mqflags[i] |= SR_MQFLAG_DC; |
0c5f2abc | 661 | } else if (!strcmp(mstr, "RES")) { |
d822726d AJ |
662 | devc->cur_mq[i] = SR_MQ_RESISTANCE; |
663 | devc->cur_unit[i] = SR_UNIT_OHM; | |
664 | devc->cur_mqflags[i] = 0; | |
665 | devc->cur_exponent[i] = 0; | |
43185ed3 | 666 | } else if (!strcmp(mstr, "COND")) { |
d822726d AJ |
667 | devc->cur_mq[i] = SR_MQ_CONDUCTANCE; |
668 | devc->cur_unit[i] = SR_UNIT_SIEMENS; | |
669 | devc->cur_mqflags[i] = 0; | |
670 | devc->cur_exponent[i] = 0; | |
0c5f2abc | 671 | } else if (!strcmp(mstr, "CAP")) { |
d822726d AJ |
672 | devc->cur_mq[i] = SR_MQ_CAPACITANCE; |
673 | devc->cur_unit[i] = SR_UNIT_FARAD; | |
674 | devc->cur_mqflags[i] = 0; | |
675 | devc->cur_exponent[i] = 0; | |
43185ed3 | 676 | } else if (!strncmp(mstr, "FREQ", 4) || !strncmp(mstr, "FC1", 3)) { |
d822726d AJ |
677 | devc->cur_mq[i] = SR_MQ_FREQUENCY; |
678 | devc->cur_unit[i] = SR_UNIT_HERTZ; | |
679 | devc->cur_mqflags[i] = 0; | |
680 | devc->cur_exponent[i] = 0; | |
7ab126ca AJ |
681 | } else if (!strncmp(mstr, "PULS:PWID", 9)) { |
682 | devc->cur_mq[i] = SR_MQ_PULSE_WIDTH; | |
683 | devc->cur_unit[i] = SR_UNIT_SECOND; | |
684 | devc->cur_mqflags[i] = 0; | |
685 | devc->cur_exponent[i] = 0; | |
686 | devc->cur_encoding[i] = MIN(devc->cur_encoding[i], 6); | |
687 | } else if (!strncmp(mstr, "PULS:PDUT", 9)) { | |
688 | devc->cur_mq[i] = SR_MQ_DUTY_CYCLE; | |
689 | devc->cur_unit[i] = SR_UNIT_PERCENTAGE; | |
690 | devc->cur_mqflags[i] = 0; | |
691 | devc->cur_exponent[i] = 0; | |
692 | devc->cur_digits[i] = 3; | |
693 | devc->cur_encoding[i] = 4; | |
0c5f2abc | 694 | } else if (!strcmp(mstr, "CONT")) { |
d822726d | 695 | devc->cur_mq[i] = SR_MQ_CONTINUITY; |
d2f6abf6 | 696 | devc->cur_unit[i] = SR_UNIT_OHM; |
d822726d AJ |
697 | devc->cur_mqflags[i] = 0; |
698 | devc->cur_exponent[i] = 0; | |
873c0d11 | 699 | } else if (!strcmp(mstr, "DIOD")) { |
d822726d AJ |
700 | devc->cur_mq[i] = SR_MQ_VOLTAGE; |
701 | devc->cur_unit[i] = SR_UNIT_VOLT; | |
702 | devc->cur_mqflags[i] = SR_MQFLAG_DIODE; | |
703 | devc->cur_exponent[i] = 0; | |
704 | devc->cur_digits[i] = 4; | |
705 | devc->cur_encoding[i] = 5; | |
43185ed3 | 706 | } else if (!strncmp(mstr, "T1", 2) || !strncmp(mstr, "T2", 2) || |
d9251a2c | 707 | !strncmp(mstr, "TEMP", 2)) { |
d822726d | 708 | devc->cur_mq[i] = SR_MQ_TEMPERATURE; |
a965748a | 709 | m2 = g_match_info_fetch(match, 2); |
d822726d AJ |
710 | if (!m2) |
711 | /* | |
712 | * TEMP without param is for secondary display (channel P2) | |
713 | * and is identical to channel P3, so discard it. | |
714 | */ | |
715 | devc->cur_mq[i] = -1; | |
716 | else if (!strcmp(m2, "FAR")) | |
717 | devc->cur_unit[i] = SR_UNIT_FAHRENHEIT; | |
a965748a | 718 | else |
d822726d | 719 | devc->cur_unit[i] = SR_UNIT_CELSIUS; |
a965748a | 720 | g_free(m2); |
d822726d AJ |
721 | devc->cur_mqflags[i] = 0; |
722 | devc->cur_exponent[i] = 0; | |
723 | devc->cur_digits[i] = 1; | |
724 | devc->cur_encoding[i] = 2; | |
0c5f2abc | 725 | } else if (!strcmp(mstr, "SCOU")) { |
a965748a BV |
726 | /* |
727 | * Switch counter, not supported. Not sure what values | |
728 | * come from FETC in this mode, or how they would map | |
729 | * into libsigrok. | |
730 | */ | |
0c5f2abc | 731 | } else if (!strncmp(mstr, "CPER:", 5)) { |
d822726d AJ |
732 | devc->cur_mq[i] = SR_MQ_CURRENT; |
733 | devc->cur_unit[i] = SR_UNIT_PERCENTAGE; | |
734 | devc->cur_mqflags[i] = 0; | |
735 | devc->cur_exponent[i] = 0; | |
736 | devc->cur_digits[i] = 2; | |
737 | devc->cur_encoding[i] = 3; | |
43185ed3 AJ |
738 | } else if (!strcmp(mstr, "SQU")) { |
739 | /* | |
740 | * Square wave output, not supported. FETC just return | |
741 | * an error in this mode, so don't even call it. | |
742 | */ | |
743 | devc->mode_squarewave = 1; | |
51b92b7d | 744 | } else { |
a965748a | 745 | sr_dbg("Unknown first argument '%s'.", mstr); |
51b92b7d | 746 | } |
8c0152f2 BV |
747 | g_free(mstr); |
748 | ||
b907d62f AJ |
749 | struct sr_channel *prev_conf = devc->cur_conf; |
750 | devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf); | |
751 | if (devc->cur_conf->index == MAX(devc->profile->nb_channels - 1, 1)) | |
752 | devc->cur_conf = sr_next_enabled_channel(sdi, devc->cur_conf); | |
753 | if (devc->cur_conf->index > prev_conf->index) | |
754 | return JOB_AGAIN; | |
755 | else | |
756 | return JOB_CONF; | |
8c0152f2 BV |
757 | } |
758 | ||
63bb11ba AJ |
759 | static int send_log(const struct sr_dev_inst *sdi) |
760 | { | |
761 | const char *source[] = { "LOG:HAND", "LOG:TRIG", "LOG:AUTO", "LOG:EXPO" }; | |
762 | struct dev_context *devc = sdi->priv; | |
763 | return agdmm_send(sdi, "%s %d", | |
764 | source[devc->data_source - 1], devc->cur_sample); | |
765 | } | |
766 | ||
767 | static int recv_log_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match) | |
768 | { | |
769 | 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 }; | |
770 | 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 }; | |
771 | static const int exponents[] = { -6, -4, -9, -4, -3, -4, -1, -12, -3, -3, -6, -3, -2, -11 }; | |
772 | struct dev_context *devc; | |
773 | struct sr_datafeed_packet packet; | |
774 | struct sr_datafeed_analog analog; | |
775 | struct sr_analog_encoding encoding; | |
776 | struct sr_analog_meaning meaning; | |
777 | struct sr_analog_spec spec; | |
778 | char *mstr; | |
779 | unsigned function; | |
780 | int value, negative, overload, exponent, alternate_unit, mq, unit; | |
781 | int mqflags = 0; | |
782 | float fvalue; | |
783 | ||
784 | sr_spew("LOG response '%s'.", g_match_info_get_string(match)); | |
785 | ||
786 | devc = sdi->priv; | |
787 | ||
788 | mstr = g_match_info_fetch(match, 2); | |
789 | if (sr_atoi(mstr, (int*)&function) != SR_OK || function >= ARRAY_SIZE(mqs)) { | |
790 | g_free(mstr); | |
791 | sr_dbg("Invalid function."); | |
792 | return SR_ERR; | |
793 | } | |
794 | g_free(mstr); | |
795 | ||
796 | mstr = g_match_info_fetch(match, 3); | |
797 | if (sr_atoi(mstr, &value) != SR_OK) { | |
798 | g_free(mstr); | |
799 | sr_dbg("Invalid value."); | |
800 | return SR_ERR; | |
801 | } | |
802 | g_free(mstr); | |
803 | ||
804 | mstr = g_match_info_fetch(match, 1); | |
805 | negative = mstr[7] & 2 ? -1 : 1; | |
806 | overload = mstr[8] & 4; | |
807 | exponent = (mstr[9] & 0xF) + exponents[function]; | |
808 | alternate_unit = mstr[10] & 1; | |
809 | ||
810 | if (mstr[ 8] & 1) mqflags |= SR_MQFLAG_DC; | |
811 | if (mstr[ 8] & 2) mqflags |= SR_MQFLAG_AC; | |
812 | if (mstr[11] & 4) mqflags |= SR_MQFLAG_RELATIVE; | |
813 | if (mstr[12] & 1) mqflags |= SR_MQFLAG_AVG; | |
814 | if (mstr[12] & 2) mqflags |= SR_MQFLAG_MIN; | |
815 | if (mstr[12] & 4) mqflags |= SR_MQFLAG_MAX; | |
816 | if (function == 5) mqflags |= SR_MQFLAG_DIODE; | |
817 | g_free(mstr); | |
818 | ||
819 | mq = mqs[function]; | |
820 | unit = units[function]; | |
821 | if (alternate_unit) { | |
822 | if (mq == SR_MQ_RESISTANCE) | |
823 | mq = SR_MQ_CONTINUITY; | |
824 | if (unit == SR_UNIT_DECIBEL_MW) | |
825 | unit = SR_UNIT_DECIBEL_VOLT; | |
826 | if (unit == SR_UNIT_CELSIUS) { | |
827 | unit = SR_UNIT_FAHRENHEIT; | |
828 | exponent--; | |
829 | } | |
830 | } | |
831 | ||
832 | if (overload) | |
833 | fvalue = NAN; | |
834 | else | |
835 | fvalue = negative * value * powf(10, exponent); | |
836 | ||
837 | sr_analog_init(&analog, &encoding, &meaning, &spec, -exponent); | |
838 | analog.meaning->mq = mq; | |
839 | analog.meaning->unit = unit; | |
840 | analog.meaning->mqflags = mqflags; | |
841 | analog.meaning->channels = g_slist_append(NULL, devc->cur_channel); | |
842 | analog.num_samples = 1; | |
843 | analog.data = &fvalue; | |
844 | packet.type = SR_DF_ANALOG; | |
845 | packet.payload = &analog; | |
846 | sr_session_send(sdi, &packet); | |
847 | g_slist_free(analog.meaning->channels); | |
848 | ||
849 | sr_sw_limits_update_samples_read(&devc->limits, 1); | |
850 | devc->cur_sample++; | |
851 | ||
852 | return JOB_LOG; | |
853 | } | |
854 | ||
81599cc5 BV |
855 | /* This comes in whenever the rotary switch is changed to a new position. |
856 | * We could use it to determine the major measurement mode, but we already | |
857 | * have the output of CONF? for that, which is more detailed. However | |
858 | * we do need to catch this here, or it'll show up in some other output. */ | |
a4394fb3 | 859 | static int recv_switch(const struct sr_dev_inst *sdi, GMatchInfo *match) |
e93cdf42 | 860 | { |
b907d62f | 861 | struct dev_context *devc = sdi->priv; |
e93cdf42 | 862 | |
38d326e8 | 863 | sr_spew("Switch '%s'.", g_match_info_get_string(match)); |
e93cdf42 | 864 | |
b907d62f AJ |
865 | devc->current_job = 0; |
866 | devc->job_running = FALSE; | |
867 | memset(devc->jobs_start, 0, sizeof(devc->jobs_start)); | |
868 | devc->cur_mq[0] = -1; | |
869 | if (devc->profile->nb_channels > 2) | |
870 | devc->cur_mq[1] = -1; | |
871 | ||
e93cdf42 BV |
872 | return SR_OK; |
873 | } | |
874 | ||
63bb11ba AJ |
875 | static int recv_err(const struct sr_dev_inst *sdi, GMatchInfo *match) |
876 | { | |
877 | struct dev_context *devc = sdi->priv; | |
878 | ||
879 | (void) match; | |
880 | ||
881 | if (devc->data_source != DATA_SOURCE_LIVE) | |
882 | return JOB_STOP; /* In log mode, stop acquisition after receiving *E. */ | |
883 | else | |
884 | return JOB_AGAIN; | |
885 | } | |
886 | ||
b907d62f | 887 | /* Poll CONF/STAT at 1Hz and values at samplerate. */ |
63bb11ba | 888 | SR_PRIV const struct agdmm_job agdmm_jobs_live[] = { |
b907d62f AJ |
889 | { JOB_FETC, SAMPLERATE_INTERVAL, send_fetc }, |
890 | { JOB_CONF, 1000, send_conf }, | |
891 | { JOB_STAT, 1000, send_stat }, | |
9e9dba7b | 892 | ALL_ZERO |
e93cdf42 BV |
893 | }; |
894 | ||
63bb11ba AJ |
895 | /* Poll LOG as fast as possible. */ |
896 | SR_PRIV const struct agdmm_job agdmm_jobs_log[] = { | |
897 | { JOB_LOG, 0, send_log }, | |
898 | ALL_ZERO | |
899 | }; | |
900 | ||
8c0152f2 BV |
901 | SR_PRIV const struct agdmm_recv agdmm_recvs_u123x[] = { |
902 | { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u123x }, | |
a4394fb3 BV |
903 | { "^\\*([0-9])$", recv_switch }, |
904 | { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc }, | |
905 | { "^\"(V|MV|A|UA|FREQ),(\\d),(AC|DC)\"$", recv_conf_u123x }, | |
906 | { "^\"(RES|CAP),(\\d)\"$", recv_conf_u123x}, | |
873c0d11 | 907 | { "^\"(DIOD)\"$", recv_conf_u123x }, |
9e9dba7b | 908 | ALL_ZERO |
e93cdf42 BV |
909 | }; |
910 | ||
173378f0 BV |
911 | SR_PRIV const struct agdmm_recv agdmm_recvs_u124x[] = { |
912 | { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u124x }, | |
913 | { "^\\*([0-9])$", recv_switch }, | |
914 | { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc }, | |
4435966e AJ |
915 | { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
916 | { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
0fe18626 | 917 | { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
4435966e | 918 | { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
a965748a | 919 | { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x }, |
873c0d11 | 920 | { "^\"(DIOD)\"$", recv_conf_u124x_5x }, |
9e9dba7b | 921 | ALL_ZERO |
173378f0 BV |
922 | }; |
923 | ||
8c0152f2 BV |
924 | SR_PRIV const struct agdmm_recv agdmm_recvs_u125x[] = { |
925 | { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u125x }, | |
926 | { "^\\*([0-9])$", recv_switch }, | |
927 | { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc }, | |
4435966e AJ |
928 | { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
929 | { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
0fe18626 | 930 | { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
4435966e | 931 | { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
c7f5219e | 932 | { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x }, |
873c0d11 | 933 | { "^\"(DIOD)\"$", recv_conf_u124x_5x }, |
9e9dba7b | 934 | ALL_ZERO |
8c0152f2 | 935 | }; |
43185ed3 AJ |
936 | |
937 | SR_PRIV const struct agdmm_recv agdmm_recvs_u128x[] = { | |
938 | { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u128x }, | |
939 | { "^\\*([0-9])$", recv_switch }, | |
940 | { "^([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))$", recv_fetc }, | |
d2f6abf6 | 941 | { "^\"(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 |
942 | { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
943 | { "^\"(CURR:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
944 | { "^\"(FREQ:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
945 | { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
7ab126ca | 946 | { "^\"(PULS:PWID|PULS:PWID:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
43185ed3 | 947 | { "^\"(TEMP:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x }, |
7ab126ca | 948 | { "^\"(DIOD|SQU|PULS:PDUT|TEMP)\"$", recv_conf_u124x_5x }, |
63bb11ba AJ |
949 | { "^\"((\\d{2})(\\d{5})\\d{7})\"$", recv_log_u128x }, |
950 | { "^\\*E$", recv_err }, | |
43185ed3 AJ |
951 | ALL_ZERO |
952 | }; |