]>
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 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 |
29 | static 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 | ||
48 | static 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 | ||
90 | SR_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 | ||
130 | static 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 | 151 | static int send_stat(const struct sr_dev_inst *sdi) |
e93cdf42 | 152 | { |
e93cdf42 BV |
153 | return agdmm_send(sdi, "STAT?"); |
154 | } | |
155 | ||
8c0152f2 | 156 | static 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 |
200 | static 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 |
232 | static 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 | ||
a4394fb3 | 258 | static int send_fetc(const struct sr_dev_inst *sdi) |
e93cdf42 | 259 | { |
e93cdf42 BV |
260 | return agdmm_send(sdi, "FETC?"); |
261 | } | |
262 | ||
a4394fb3 | 263 | static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) |
e93cdf42 BV |
264 | { |
265 | struct dev_context *devc; | |
266 | struct sr_datafeed_packet packet; | |
16aef676 UH |
267 | struct sr_datafeed_analog analog; |
268 | struct sr_analog_encoding encoding; | |
269 | struct sr_analog_meaning meaning; | |
270 | struct sr_analog_spec spec; | |
e93cdf42 | 271 | float fvalue; |
f216eb86 | 272 | const char *s; |
fe9d5abe | 273 | char *mstr; |
e93cdf42 | 274 | |
38d326e8 | 275 | sr_spew("FETC reply '%s'.", g_match_info_get_string(match)); |
e93cdf42 BV |
276 | devc = sdi->priv; |
277 | ||
278 | if (devc->cur_mq == -1) | |
279 | /* Haven't seen configuration yet, so can't know what | |
280 | * the fetched float means. Not really an error, we'll | |
281 | * get metadata soon enough. */ | |
282 | return SR_OK; | |
283 | ||
f216eb86 BV |
284 | s = g_match_info_get_string(match); |
285 | if (!strcmp(s, "-9.90000000E+37") || !strcmp(s, "+9.90000000E+37")) { | |
74ac7d7f | 286 | /* An invalid measurement shows up on the display as "O.L", but |
e93cdf42 BV |
287 | * comes through like this. Since comparing 38-digit floats |
288 | * is rather problematic, we'll cut through this here. */ | |
289 | fvalue = NAN; | |
290 | } else { | |
291 | mstr = g_match_info_fetch(match, 1); | |
7c03b564 | 292 | if (sr_atof_ascii(mstr, &fvalue) != SR_OK) { |
fe9d5abe | 293 | g_free(mstr); |
51b92b7d | 294 | sr_dbg("Invalid float."); |
e93cdf42 BV |
295 | return SR_ERR; |
296 | } | |
fe9d5abe | 297 | g_free(mstr); |
40df76aa AJ |
298 | if (devc->cur_exponent != 0) |
299 | fvalue *= powf(10, devc->cur_exponent); | |
e93cdf42 BV |
300 | } |
301 | ||
4435966e AJ |
302 | sr_analog_init(&analog, &encoding, &meaning, &spec, |
303 | devc->cur_digits - devc->cur_exponent); | |
16aef676 UH |
304 | analog.meaning->mq = devc->cur_mq; |
305 | analog.meaning->unit = devc->cur_unit; | |
306 | analog.meaning->mqflags = devc->cur_mqflags; | |
307 | analog.meaning->channels = sdi->channels; | |
e93cdf42 BV |
308 | analog.num_samples = 1; |
309 | analog.data = &fvalue; | |
4435966e | 310 | encoding.digits = devc->cur_encoding - devc->cur_exponent; |
16aef676 | 311 | packet.type = SR_DF_ANALOG; |
e93cdf42 | 312 | packet.payload = &analog; |
695dc859 | 313 | sr_session_send(sdi, &packet); |
e93cdf42 | 314 | |
5b6829ea | 315 | sr_sw_limits_update_samples_read(&devc->limits, 1); |
e93cdf42 BV |
316 | |
317 | return SR_OK; | |
318 | } | |
319 | ||
a4394fb3 | 320 | static int send_conf(const struct sr_dev_inst *sdi) |
e93cdf42 | 321 | { |
e93cdf42 BV |
322 | return agdmm_send(sdi, "CONF?"); |
323 | } | |
324 | ||
a4394fb3 | 325 | static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) |
e93cdf42 BV |
326 | { |
327 | struct dev_context *devc; | |
4435966e AJ |
328 | char *mstr, *rstr; |
329 | int resolution; | |
e93cdf42 | 330 | |
38d326e8 | 331 | sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); |
e93cdf42 | 332 | devc = sdi->priv; |
4435966e AJ |
333 | |
334 | rstr = g_match_info_fetch(match, 2); | |
335 | if (rstr) | |
336 | sr_atoi(rstr, &resolution); | |
337 | g_free(rstr); | |
338 | ||
e93cdf42 BV |
339 | mstr = g_match_info_fetch(match, 1); |
340 | if (!strcmp(mstr, "V")) { | |
341 | devc->cur_mq = SR_MQ_VOLTAGE; | |
e6b021f3 BV |
342 | devc->cur_unit = SR_UNIT_VOLT; |
343 | devc->cur_mqflags = 0; | |
40df76aa | 344 | devc->cur_exponent = 0; |
4435966e | 345 | devc->cur_digits = 4 - resolution; |
0c5f2abc | 346 | } else if (!strcmp(mstr, "MV")) { |
e6b021f3 BV |
347 | if (devc->mode_tempaux) { |
348 | devc->cur_mq = SR_MQ_TEMPERATURE; | |
f3f19d11 UH |
349 | /* No way to detect whether Fahrenheit or Celsius |
350 | * is used, so we'll just default to Celsius. */ | |
e6b021f3 BV |
351 | devc->cur_unit = SR_UNIT_CELSIUS; |
352 | devc->cur_mqflags = 0; | |
40df76aa | 353 | devc->cur_exponent = 0; |
4435966e | 354 | devc->cur_digits = 1; |
e6b021f3 BV |
355 | } else { |
356 | devc->cur_mq = SR_MQ_VOLTAGE; | |
357 | devc->cur_unit = SR_UNIT_VOLT; | |
358 | devc->cur_mqflags = 0; | |
40df76aa | 359 | devc->cur_exponent = -3; |
4435966e | 360 | devc->cur_digits = 5 - resolution; |
e6b021f3 | 361 | } |
0c5f2abc | 362 | } else if (!strcmp(mstr, "A")) { |
e93cdf42 | 363 | devc->cur_mq = SR_MQ_CURRENT; |
e6b021f3 BV |
364 | devc->cur_unit = SR_UNIT_AMPERE; |
365 | devc->cur_mqflags = 0; | |
40df76aa | 366 | devc->cur_exponent = 0; |
4435966e | 367 | devc->cur_digits = 3 - resolution; |
0c5f2abc | 368 | } else if (!strcmp(mstr, "UA")) { |
e93cdf42 | 369 | devc->cur_mq = SR_MQ_CURRENT; |
e6b021f3 BV |
370 | devc->cur_unit = SR_UNIT_AMPERE; |
371 | devc->cur_mqflags = 0; | |
40df76aa | 372 | devc->cur_exponent = -6; |
4435966e | 373 | devc->cur_digits = 8 - resolution; |
0c5f2abc | 374 | } else if (!strcmp(mstr, "FREQ")) { |
e93cdf42 | 375 | devc->cur_mq = SR_MQ_FREQUENCY; |
e6b021f3 BV |
376 | devc->cur_unit = SR_UNIT_HERTZ; |
377 | devc->cur_mqflags = 0; | |
40df76aa | 378 | devc->cur_exponent = 0; |
4435966e | 379 | devc->cur_digits = 2 - resolution; |
0c5f2abc | 380 | } else if (!strcmp(mstr, "RES")) { |
e6b021f3 BV |
381 | if (devc->mode_continuity) { |
382 | devc->cur_mq = SR_MQ_CONTINUITY; | |
383 | devc->cur_unit = SR_UNIT_BOOLEAN; | |
384 | } else { | |
385 | devc->cur_mq = SR_MQ_RESISTANCE; | |
386 | devc->cur_unit = SR_UNIT_OHM; | |
387 | } | |
388 | devc->cur_mqflags = 0; | |
40df76aa | 389 | devc->cur_exponent = 0; |
4435966e | 390 | devc->cur_digits = 1 - resolution; |
873c0d11 AJ |
391 | } else if (!strcmp(mstr, "DIOD")) { |
392 | devc->cur_mq = SR_MQ_VOLTAGE; | |
393 | devc->cur_unit = SR_UNIT_VOLT; | |
394 | devc->cur_mqflags = SR_MQFLAG_DIODE; | |
395 | devc->cur_exponent = 0; | |
4435966e | 396 | devc->cur_digits = 3; |
0c5f2abc | 397 | } else if (!strcmp(mstr, "CAP")) { |
e93cdf42 | 398 | devc->cur_mq = SR_MQ_CAPACITANCE; |
e6b021f3 BV |
399 | devc->cur_unit = SR_UNIT_FARAD; |
400 | devc->cur_mqflags = 0; | |
40df76aa | 401 | devc->cur_exponent = 0; |
4435966e | 402 | devc->cur_digits = 9 - resolution; |
e93cdf42 | 403 | } else |
38d326e8 | 404 | sr_dbg("Unknown first argument."); |
e93cdf42 BV |
405 | g_free(mstr); |
406 | ||
4435966e AJ |
407 | /* This is based on guess, supposing similarity with other models. */ |
408 | devc->cur_encoding = devc->cur_digits + 1; | |
409 | ||
e066c32a BV |
410 | if (g_match_info_get_match_count(match) == 4) { |
411 | mstr = g_match_info_fetch(match, 3); | |
e93cdf42 | 412 | /* Third value, if present, is always AC or DC. */ |
51b92b7d | 413 | if (!strcmp(mstr, "AC")) { |
e6b021f3 | 414 | devc->cur_mqflags |= SR_MQFLAG_AC; |
51b92b7d BV |
415 | if (devc->cur_mq == SR_MQ_VOLTAGE) |
416 | devc->cur_mqflags |= SR_MQFLAG_RMS; | |
417 | } else if (!strcmp(mstr, "DC")) { | |
e6b021f3 | 418 | devc->cur_mqflags |= SR_MQFLAG_DC; |
51b92b7d | 419 | } else { |
a965748a | 420 | sr_dbg("Unknown first argument '%s'.", mstr); |
51b92b7d | 421 | } |
e93cdf42 | 422 | g_free(mstr); |
e6b021f3 BV |
423 | } else |
424 | devc->cur_mqflags &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC); | |
e93cdf42 BV |
425 | |
426 | return SR_OK; | |
427 | } | |
428 | ||
173378f0 | 429 | static int recv_conf_u124x_5x(const struct sr_dev_inst *sdi, GMatchInfo *match) |
8c0152f2 BV |
430 | { |
431 | struct dev_context *devc; | |
4435966e AJ |
432 | char *mstr, *rstr, *m2; |
433 | int resolution; | |
8c0152f2 | 434 | |
38d326e8 | 435 | sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); |
8c0152f2 | 436 | devc = sdi->priv; |
4435966e AJ |
437 | |
438 | rstr = g_match_info_fetch(match, 4); | |
439 | if (rstr && sr_atoi(rstr, &resolution) == SR_OK) { | |
440 | devc->cur_digits = -resolution; | |
441 | devc->cur_encoding = -resolution + 1; | |
442 | } | |
443 | g_free(rstr); | |
444 | ||
445 | mstr = g_match_info_fetch(match, 1); | |
8c0152f2 BV |
446 | if (!strncmp(mstr, "VOLT", 4)) { |
447 | devc->cur_mq = SR_MQ_VOLTAGE; | |
448 | devc->cur_unit = SR_UNIT_VOLT; | |
449 | devc->cur_mqflags = 0; | |
40df76aa | 450 | devc->cur_exponent = 0; |
8c0152f2 | 451 | if (mstr[4] == ':') { |
ee2bcdfc | 452 | if (!strncmp(mstr + 5, "AC", 2)) { |
51b92b7d | 453 | devc->cur_mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS; |
ee2bcdfc | 454 | } else if (!strncmp(mstr + 5, "DC", 2)) { |
8c0152f2 | 455 | devc->cur_mqflags |= SR_MQFLAG_DC; |
ee2bcdfc | 456 | } else if (!strncmp(mstr + 5, "ACDC", 4)) { |
51b92b7d BV |
457 | /* AC + DC offset */ |
458 | devc->cur_mqflags |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS; | |
459 | } else { | |
8c0152f2 | 460 | devc->cur_mqflags &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC); |
51b92b7d | 461 | } |
8c0152f2 BV |
462 | } else |
463 | devc->cur_mqflags &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC); | |
0c5f2abc | 464 | } else if (!strcmp(mstr, "CURR")) { |
8c0152f2 BV |
465 | devc->cur_mq = SR_MQ_CURRENT; |
466 | devc->cur_unit = SR_UNIT_AMPERE; | |
467 | devc->cur_mqflags = 0; | |
40df76aa | 468 | devc->cur_exponent = 0; |
0c5f2abc | 469 | } else if (!strcmp(mstr, "RES")) { |
a965748a BV |
470 | devc->cur_mq = SR_MQ_RESISTANCE; |
471 | devc->cur_unit = SR_UNIT_OHM; | |
472 | devc->cur_mqflags = 0; | |
40df76aa | 473 | devc->cur_exponent = 0; |
0c5f2abc | 474 | } else if (!strcmp(mstr, "CAP")) { |
a965748a BV |
475 | devc->cur_mq = SR_MQ_CAPACITANCE; |
476 | devc->cur_unit = SR_UNIT_FARAD; | |
8c0152f2 | 477 | devc->cur_mqflags = 0; |
40df76aa | 478 | devc->cur_exponent = 0; |
0c5f2abc | 479 | } else if (!strcmp(mstr, "FREQ")) { |
a965748a BV |
480 | devc->cur_mq = SR_MQ_FREQUENCY; |
481 | devc->cur_unit = SR_UNIT_HERTZ; | |
482 | devc->cur_mqflags = 0; | |
40df76aa | 483 | devc->cur_exponent = 0; |
0c5f2abc | 484 | } else if (!strcmp(mstr, "CONT")) { |
a965748a BV |
485 | devc->cur_mq = SR_MQ_CONTINUITY; |
486 | devc->cur_unit = SR_UNIT_BOOLEAN; | |
487 | devc->cur_mqflags = 0; | |
40df76aa | 488 | devc->cur_exponent = 0; |
873c0d11 AJ |
489 | } else if (!strcmp(mstr, "DIOD")) { |
490 | devc->cur_mq = SR_MQ_VOLTAGE; | |
491 | devc->cur_unit = SR_UNIT_VOLT; | |
492 | devc->cur_mqflags = SR_MQFLAG_DIODE; | |
493 | devc->cur_exponent = 0; | |
4435966e AJ |
494 | devc->cur_digits = 4; |
495 | devc->cur_encoding = 5; | |
0c5f2abc | 496 | } else if (!strncmp(mstr, "T1", 2) || !strncmp(mstr, "T2", 2)) { |
a965748a BV |
497 | devc->cur_mq = SR_MQ_TEMPERATURE; |
498 | m2 = g_match_info_fetch(match, 2); | |
499 | if (!strcmp(m2, "FAR")) | |
500 | devc->cur_unit = SR_UNIT_FAHRENHEIT; | |
501 | else | |
502 | devc->cur_unit = SR_UNIT_CELSIUS; | |
503 | g_free(m2); | |
504 | devc->cur_mqflags = 0; | |
40df76aa | 505 | devc->cur_exponent = 0; |
4435966e AJ |
506 | devc->cur_digits = 1; |
507 | devc->cur_encoding = 2; | |
0c5f2abc | 508 | } else if (!strcmp(mstr, "SCOU")) { |
a965748a BV |
509 | /* |
510 | * Switch counter, not supported. Not sure what values | |
511 | * come from FETC in this mode, or how they would map | |
512 | * into libsigrok. | |
513 | */ | |
0c5f2abc | 514 | } else if (!strncmp(mstr, "CPER:", 5)) { |
110fe1b4 BV |
515 | devc->cur_mq = SR_MQ_CURRENT; |
516 | devc->cur_unit = SR_UNIT_PERCENTAGE; | |
517 | devc->cur_mqflags = 0; | |
40df76aa | 518 | devc->cur_exponent = 0; |
4435966e AJ |
519 | devc->cur_digits = 2; |
520 | devc->cur_encoding = 3; | |
51b92b7d | 521 | } else { |
a965748a | 522 | sr_dbg("Unknown first argument '%s'.", mstr); |
51b92b7d | 523 | } |
8c0152f2 BV |
524 | g_free(mstr); |
525 | ||
8c0152f2 BV |
526 | return SR_OK; |
527 | } | |
528 | ||
81599cc5 BV |
529 | /* This comes in whenever the rotary switch is changed to a new position. |
530 | * We could use it to determine the major measurement mode, but we already | |
531 | * have the output of CONF? for that, which is more detailed. However | |
532 | * we do need to catch this here, or it'll show up in some other output. */ | |
a4394fb3 | 533 | static int recv_switch(const struct sr_dev_inst *sdi, GMatchInfo *match) |
e93cdf42 | 534 | { |
e93cdf42 BV |
535 | (void)sdi; |
536 | ||
38d326e8 | 537 | sr_spew("Switch '%s'.", g_match_info_get_string(match)); |
e93cdf42 BV |
538 | |
539 | return SR_OK; | |
540 | } | |
541 | ||
f857bd92 BV |
542 | /* Poll keys/switches and values at 7Hz, mode at 1Hz. */ |
543 | SR_PRIV const struct agdmm_job agdmm_jobs_u12xx[] = { | |
a4394fb3 BV |
544 | { 143, send_stat }, |
545 | { 1000, send_conf }, | |
546 | { 143, send_fetc }, | |
9e9dba7b | 547 | ALL_ZERO |
e93cdf42 BV |
548 | }; |
549 | ||
8c0152f2 BV |
550 | SR_PRIV const struct agdmm_recv agdmm_recvs_u123x[] = { |
551 | { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u123x }, | |
a4394fb3 BV |
552 | { "^\\*([0-9])$", recv_switch }, |
553 | { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc }, | |
554 | { "^\"(V|MV|A|UA|FREQ),(\\d),(AC|DC)\"$", recv_conf_u123x }, | |
555 | { "^\"(RES|CAP),(\\d)\"$", recv_conf_u123x}, | |
873c0d11 | 556 | { "^\"(DIOD)\"$", recv_conf_u123x }, |
9e9dba7b | 557 | ALL_ZERO |
e93cdf42 BV |
558 | }; |
559 | ||
173378f0 BV |
560 | SR_PRIV const struct agdmm_recv agdmm_recvs_u124x[] = { |
561 | { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u124x }, | |
562 | { "^\\*([0-9])$", recv_switch }, | |
563 | { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc }, | |
4435966e AJ |
564 | { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
565 | { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
566 | { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
a965748a | 567 | { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x }, |
873c0d11 | 568 | { "^\"(DIOD)\"$", recv_conf_u124x_5x }, |
9e9dba7b | 569 | ALL_ZERO |
173378f0 BV |
570 | }; |
571 | ||
8c0152f2 BV |
572 | SR_PRIV const struct agdmm_recv agdmm_recvs_u125x[] = { |
573 | { "^\"(\\d\\d.{18}\\d)\"$", recv_stat_u125x }, | |
574 | { "^\\*([0-9])$", recv_switch }, | |
575 | { "^([-+][0-9]\\.[0-9]{8}E[-+][0-9]{2})$", recv_fetc }, | |
4435966e AJ |
576 | { "^\"(VOLT|CURR|RES|CAP|FREQ) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, |
577 | { "^\"(VOLT:[ACD]+) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
578 | { "^\"(CPER:[40]-20mA) ([-+][0-9\\.E\\-+]+),([-+][0-9]\\.[0-9]{8}E([-+][0-9]{2}))\"$", recv_conf_u124x_5x }, | |
c7f5219e | 579 | { "^\"(T[0-9]:[A-Z]+) ([A-Z]+)\"$", recv_conf_u124x_5x }, |
873c0d11 | 580 | { "^\"(DIOD)\"$", recv_conf_u124x_5x }, |
9e9dba7b | 581 | ALL_ZERO |
8c0152f2 | 582 | }; |