]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> | |
5 | * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com> | |
6 | * Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> | |
7 | * | |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #include <sys/types.h> | |
23 | #include <sys/stat.h> | |
24 | #include <fcntl.h> | |
25 | #include <string.h> | |
26 | #include <errno.h> | |
27 | #include <glib.h> | |
28 | #include "libsigrok.h" | |
29 | #include "libsigrok-internal.h" | |
30 | #include "protocol.h" | |
31 | ||
32 | static const int32_t hwopts[] = { | |
33 | SR_CONF_CONN, | |
34 | SR_CONF_SERIALCOMM, | |
35 | }; | |
36 | ||
37 | static const int32_t hwcaps[] = { | |
38 | SR_CONF_MULTIMETER, | |
39 | SR_CONF_LIMIT_SAMPLES, | |
40 | SR_CONF_LIMIT_MSEC, | |
41 | SR_CONF_CONTINUOUS, | |
42 | }; | |
43 | ||
44 | SR_PRIV struct sr_dev_driver bbcgm_m2110_driver_info; | |
45 | SR_PRIV struct sr_dev_driver digitek_dt4000zc_driver_info; | |
46 | SR_PRIV struct sr_dev_driver tekpower_tp4000zc_driver_info; | |
47 | SR_PRIV struct sr_dev_driver metex_me31_driver_info; | |
48 | SR_PRIV struct sr_dev_driver peaktech_3410_driver_info; | |
49 | SR_PRIV struct sr_dev_driver mastech_mas345_driver_info; | |
50 | SR_PRIV struct sr_dev_driver va_va18b_driver_info; | |
51 | SR_PRIV struct sr_dev_driver va_va40b_driver_info; | |
52 | SR_PRIV struct sr_dev_driver metex_m3640d_driver_info; | |
53 | SR_PRIV struct sr_dev_driver metex_m4650cr_driver_info; | |
54 | SR_PRIV struct sr_dev_driver peaktech_4370_driver_info; | |
55 | SR_PRIV struct sr_dev_driver pce_pce_dm32_driver_info; | |
56 | SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info; | |
57 | SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info; | |
58 | SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info; | |
59 | SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info; | |
60 | SR_PRIV struct sr_dev_driver voltcraft_m3650d_driver_info; | |
61 | SR_PRIV struct sr_dev_driver voltcraft_m4650cr_driver_info; | |
62 | SR_PRIV struct sr_dev_driver voltcraft_vc820_ser_driver_info; | |
63 | SR_PRIV struct sr_dev_driver voltcraft_vc830_ser_driver_info; | |
64 | SR_PRIV struct sr_dev_driver voltcraft_vc840_ser_driver_info; | |
65 | SR_PRIV struct sr_dev_driver uni_t_ut60a_ser_driver_info; | |
66 | SR_PRIV struct sr_dev_driver uni_t_ut60e_ser_driver_info; | |
67 | SR_PRIV struct sr_dev_driver uni_t_ut61b_ser_driver_info; | |
68 | SR_PRIV struct sr_dev_driver uni_t_ut61c_ser_driver_info; | |
69 | SR_PRIV struct sr_dev_driver uni_t_ut61d_ser_driver_info; | |
70 | SR_PRIV struct sr_dev_driver uni_t_ut61e_ser_driver_info; | |
71 | SR_PRIV struct sr_dev_driver iso_tech_idm103n_driver_info; | |
72 | ||
73 | SR_PRIV struct dmm_info dmms[] = { | |
74 | { | |
75 | "BBC Goertz Metrawatt", "M2110", "1200/7n2", 1200, | |
76 | BBCGM_M2110_PACKET_SIZE, NULL, | |
77 | sr_m2110_packet_valid, sr_m2110_parse, | |
78 | NULL, | |
79 | &bbcgm_m2110_driver_info, receive_data_BBCGM_M2110, | |
80 | }, | |
81 | { | |
82 | "Digitek", "DT4000ZC", "2400/8n1/dtr=1", 2400, | |
83 | FS9721_PACKET_SIZE, NULL, | |
84 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
85 | sr_fs9721_10_temp_c, | |
86 | &digitek_dt4000zc_driver_info, receive_data_DIGITEK_DT4000ZC, | |
87 | }, | |
88 | { | |
89 | "TekPower", "TP4000ZC", "2400/8n1/dtr=1", 2400, | |
90 | FS9721_PACKET_SIZE, NULL, | |
91 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
92 | sr_fs9721_10_temp_c, | |
93 | &tekpower_tp4000zc_driver_info, receive_data_TEKPOWER_TP4000ZC, | |
94 | }, | |
95 | { | |
96 | "Metex", "ME-31", "600/7n2/rts=0/dtr=1", 600, | |
97 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
98 | sr_metex14_packet_valid, sr_metex14_parse, | |
99 | NULL, | |
100 | &metex_me31_driver_info, receive_data_METEX_ME31, | |
101 | }, | |
102 | { | |
103 | "Peaktech", "3410", "600/7n2/rts=0/dtr=1", 600, | |
104 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
105 | sr_metex14_packet_valid, sr_metex14_parse, | |
106 | NULL, | |
107 | &peaktech_3410_driver_info, receive_data_PEAKTECH_3410, | |
108 | }, | |
109 | { | |
110 | "MASTECH", "MAS345", "600/7n2/rts=0/dtr=1", 600, | |
111 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
112 | sr_metex14_packet_valid, sr_metex14_parse, | |
113 | NULL, | |
114 | &mastech_mas345_driver_info, receive_data_MASTECH_MAS345, | |
115 | }, | |
116 | { | |
117 | "V&A", "VA18B", "2400/8n1", 2400, | |
118 | FS9721_PACKET_SIZE, NULL, | |
119 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
120 | sr_fs9721_01_temp_c, | |
121 | &va_va18b_driver_info, receive_data_VA_VA18B, | |
122 | }, | |
123 | { | |
124 | "V&A", "VA40B", "2400/8n1", 2400, | |
125 | FS9721_PACKET_SIZE, NULL, | |
126 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
127 | sr_fs9721_max_c_min, | |
128 | &va_va40b_driver_info, receive_data_VA_VA40B, | |
129 | }, | |
130 | { | |
131 | "Metex", "M-3640D", "1200/7n2/rts=0/dtr=1", 1200, | |
132 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
133 | sr_metex14_packet_valid, sr_metex14_parse, | |
134 | NULL, | |
135 | &metex_m3640d_driver_info, receive_data_METEX_M3640D, | |
136 | }, | |
137 | { | |
138 | "Metex", "M-4650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
139 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
140 | sr_metex14_packet_valid, sr_metex14_parse, | |
141 | NULL, | |
142 | &metex_m4650cr_driver_info, receive_data_METEX_M4650CR, | |
143 | }, | |
144 | { | |
145 | "PeakTech", "4370", "1200/7n2/rts=0/dtr=1", 1200, | |
146 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
147 | sr_metex14_packet_valid, sr_metex14_parse, | |
148 | NULL, | |
149 | &peaktech_4370_driver_info, receive_data_PEAKTECH_4370, | |
150 | }, | |
151 | { | |
152 | "PCE", "PCE-DM32", "2400/8n1", 2400, | |
153 | FS9721_PACKET_SIZE, NULL, | |
154 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
155 | sr_fs9721_01_10_temp_f_c, | |
156 | &pce_pce_dm32_driver_info, receive_data_PCE_PCE_DM32, | |
157 | }, | |
158 | { | |
159 | "RadioShack", "22-168", "1200/7n2/rts=0/dtr=1", 1200, | |
160 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
161 | sr_metex14_packet_valid, sr_metex14_parse, | |
162 | NULL, | |
163 | &radioshack_22_168_driver_info, receive_data_RADIOSHACK_22_168, | |
164 | }, | |
165 | { | |
166 | "RadioShack", "22-805", "600/7n2/rts=0/dtr=1", 600, | |
167 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
168 | sr_metex14_packet_valid, sr_metex14_parse, | |
169 | NULL, | |
170 | &radioshack_22_805_driver_info, receive_data_RADIOSHACK_22_805, | |
171 | }, | |
172 | { | |
173 | "RadioShack", "22-812", "4800/8n1/rts=0/dtr=1", 4800, | |
174 | RS9LCD_PACKET_SIZE, NULL, | |
175 | sr_rs9lcd_packet_valid, sr_rs9lcd_parse, | |
176 | NULL, | |
177 | &radioshack_22_812_driver_info, receive_data_RADIOSHACK_22_812, | |
178 | }, | |
179 | { | |
180 | "Tecpel", "DMM-8061 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
181 | 2400, FS9721_PACKET_SIZE, NULL, | |
182 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
183 | sr_fs9721_00_temp_c, | |
184 | &tecpel_dmm_8061_ser_driver_info, | |
185 | receive_data_TECPEL_DMM_8061_SER, | |
186 | }, | |
187 | { | |
188 | "Voltcraft", "M-3650D", "1200/7n2/rts=0/dtr=1", 1200, | |
189 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
190 | sr_metex14_packet_valid, sr_metex14_parse, | |
191 | NULL, | |
192 | &voltcraft_m3650d_driver_info, receive_data_VOLTCRAFT_M3650D, | |
193 | }, | |
194 | { | |
195 | "Voltcraft", "M-4650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
196 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
197 | sr_metex14_packet_valid, sr_metex14_parse, | |
198 | NULL, | |
199 | &voltcraft_m4650cr_driver_info, receive_data_VOLTCRAFT_M4650CR, | |
200 | }, | |
201 | { | |
202 | "Voltcraft", "VC-820 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
203 | 2400, FS9721_PACKET_SIZE, NULL, | |
204 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
205 | NULL, | |
206 | &voltcraft_vc820_ser_driver_info, | |
207 | receive_data_VOLTCRAFT_VC820_SER, | |
208 | }, | |
209 | { | |
210 | /* | |
211 | * Note: The VC830 doesn't set the 'volt' and 'diode' bits of | |
212 | * the FS9922 protocol. Instead, it only sets the user-defined | |
213 | * bit "z1" to indicate "diode mode" and "voltage". | |
214 | */ | |
215 | "Voltcraft", "VC-830 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
216 | 2400, FS9922_PACKET_SIZE, NULL, | |
217 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
218 | &sr_fs9922_z1_diode, | |
219 | &voltcraft_vc830_ser_driver_info, | |
220 | receive_data_VOLTCRAFT_VC830_SER, | |
221 | }, | |
222 | { | |
223 | "Voltcraft", "VC-840 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
224 | 2400, FS9721_PACKET_SIZE, NULL, | |
225 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
226 | sr_fs9721_00_temp_c, | |
227 | &voltcraft_vc840_ser_driver_info, | |
228 | receive_data_VOLTCRAFT_VC840_SER, | |
229 | }, | |
230 | { | |
231 | "UNI-T", "UT60A (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
232 | 2400, FS9721_PACKET_SIZE, NULL, | |
233 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
234 | NULL, | |
235 | &uni_t_ut60a_ser_driver_info, | |
236 | receive_data_UNI_T_UT60A_SER, | |
237 | }, | |
238 | { | |
239 | "UNI-T", "UT60E (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
240 | 2400, FS9721_PACKET_SIZE, NULL, | |
241 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
242 | sr_fs9721_00_temp_c, | |
243 | &uni_t_ut60e_ser_driver_info, | |
244 | receive_data_UNI_T_UT60E_SER, | |
245 | }, | |
246 | { | |
247 | "UNI-T", "UT61B (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
248 | 2400, FS9922_PACKET_SIZE, NULL, | |
249 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
250 | &uni_t_ut61b_ser_driver_info, receive_data_UNI_T_UT61B_SER, | |
251 | }, | |
252 | { | |
253 | "UNI-T", "UT61C (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
254 | 2400, FS9922_PACKET_SIZE, NULL, | |
255 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
256 | &uni_t_ut61c_ser_driver_info, receive_data_UNI_T_UT61C_SER, | |
257 | }, | |
258 | { | |
259 | "UNI-T", "UT61D (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
260 | 2400, FS9922_PACKET_SIZE, NULL, | |
261 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
262 | &uni_t_ut61d_ser_driver_info, receive_data_UNI_T_UT61D_SER, | |
263 | }, | |
264 | { | |
265 | /* Note: ES51922 baudrate is actually 19230! */ | |
266 | "UNI-T", "UT61E (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
267 | 19200, ES519XX_14B_PACKET_SIZE, NULL, | |
268 | sr_es519xx_19200_14b_packet_valid, sr_es519xx_19200_14b_parse, NULL, | |
269 | &uni_t_ut61e_ser_driver_info, receive_data_UNI_T_UT61E_SER, | |
270 | }, | |
271 | { | |
272 | "ISO-TECH", "IDM103N", "2400/7o1/rts=0/dtr=1", | |
273 | 2400, ES519XX_11B_PACKET_SIZE, NULL, | |
274 | sr_es519xx_2400_11b_packet_valid, sr_es519xx_2400_11b_parse, NULL, | |
275 | &iso_tech_idm103n_driver_info, receive_data_ISO_TECH_IDM103N, | |
276 | }, | |
277 | }; | |
278 | ||
279 | static int dev_clear(int dmm) | |
280 | { | |
281 | return std_dev_clear(dmms[dmm].di, NULL); | |
282 | } | |
283 | ||
284 | static int init(struct sr_context *sr_ctx, int dmm) | |
285 | { | |
286 | sr_dbg("Selected '%s' subdriver.", dmms[dmm].di->name); | |
287 | ||
288 | return std_init(sr_ctx, dmms[dmm].di, LOG_PREFIX); | |
289 | } | |
290 | ||
291 | static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm) | |
292 | { | |
293 | struct sr_dev_inst *sdi; | |
294 | struct drv_context *drvc; | |
295 | struct dev_context *devc; | |
296 | struct sr_probe *probe; | |
297 | struct sr_serial_dev_inst *serial; | |
298 | GSList *devices; | |
299 | int dropped, ret; | |
300 | size_t len; | |
301 | uint8_t buf[128]; | |
302 | ||
303 | if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) | |
304 | return NULL; | |
305 | ||
306 | if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) | |
307 | return NULL; | |
308 | ||
309 | sr_info("Probing serial port %s.", conn); | |
310 | ||
311 | drvc = dmms[dmm].di->priv; | |
312 | devices = NULL; | |
313 | serial_flush(serial); | |
314 | ||
315 | /* Request a packet if the DMM requires this. */ | |
316 | if (dmms[dmm].packet_request) { | |
317 | if ((ret = dmms[dmm].packet_request(serial)) < 0) { | |
318 | sr_err("Failed to request packet: %d.", ret); | |
319 | return FALSE; | |
320 | } | |
321 | } | |
322 | ||
323 | /* | |
324 | * There's no way to get an ID from the multimeter. It just sends data | |
325 | * periodically (or upon request), so the best we can do is check if | |
326 | * the packets match the expected format. | |
327 | */ | |
328 | ||
329 | /* Let's get a bit of data and see if we can find a packet. */ | |
330 | len = sizeof(buf); | |
331 | ret = serial_stream_detect(serial, buf, &len, dmms[dmm].packet_size, | |
332 | dmms[dmm].packet_valid, 3000, | |
333 | dmms[dmm].baudrate); | |
334 | if (ret != SR_OK) | |
335 | goto scan_cleanup; | |
336 | ||
337 | /* | |
338 | * If we dropped more than two packets worth of data, something is | |
339 | * wrong. We shouldn't quit however, since the dropped bytes might be | |
340 | * just zeroes at the beginning of the stream. Those can occur as a | |
341 | * combination of the nonstandard cable that ships with some devices | |
342 | * and the serial port or USB to serial adapter. | |
343 | */ | |
344 | dropped = len - dmms[dmm].packet_size; | |
345 | if (dropped > 2 * dmms[dmm].packet_size) | |
346 | sr_warn("Had to drop too much data."); | |
347 | ||
348 | sr_info("Found device on port %s.", conn); | |
349 | ||
350 | if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, dmms[dmm].vendor, | |
351 | dmms[dmm].device, ""))) | |
352 | goto scan_cleanup; | |
353 | ||
354 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { | |
355 | sr_err("Device context malloc failed."); | |
356 | goto scan_cleanup; | |
357 | } | |
358 | ||
359 | sdi->inst_type = SR_INST_SERIAL; | |
360 | sdi->conn = serial; | |
361 | ||
362 | sdi->priv = devc; | |
363 | sdi->driver = dmms[dmm].di; | |
364 | if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) | |
365 | goto scan_cleanup; | |
366 | sdi->probes = g_slist_append(sdi->probes, probe); | |
367 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
368 | devices = g_slist_append(devices, sdi); | |
369 | ||
370 | scan_cleanup: | |
371 | serial_close(serial); | |
372 | ||
373 | return devices; | |
374 | } | |
375 | ||
376 | static GSList *scan(GSList *options, int dmm) | |
377 | { | |
378 | struct sr_config *src; | |
379 | GSList *l, *devices; | |
380 | const char *conn, *serialcomm; | |
381 | ||
382 | conn = serialcomm = NULL; | |
383 | for (l = options; l; l = l->next) { | |
384 | src = l->data; | |
385 | switch (src->key) { | |
386 | case SR_CONF_CONN: | |
387 | conn = g_variant_get_string(src->data, NULL); | |
388 | break; | |
389 | case SR_CONF_SERIALCOMM: | |
390 | serialcomm = g_variant_get_string(src->data, NULL); | |
391 | break; | |
392 | } | |
393 | } | |
394 | if (!conn) | |
395 | return NULL; | |
396 | ||
397 | if (serialcomm) { | |
398 | /* Use the provided comm specs. */ | |
399 | devices = sdmm_scan(conn, serialcomm, dmm); | |
400 | } else { | |
401 | /* Try the default. */ | |
402 | devices = sdmm_scan(conn, dmms[dmm].conn, dmm); | |
403 | } | |
404 | ||
405 | return devices; | |
406 | } | |
407 | ||
408 | static GSList *dev_list(int dmm) | |
409 | { | |
410 | return ((struct drv_context *)(dmms[dmm].di->priv))->instances; | |
411 | } | |
412 | ||
413 | static int cleanup(int dmm) | |
414 | { | |
415 | return dev_clear(dmm); | |
416 | } | |
417 | ||
418 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, | |
419 | const struct sr_probe_group *probe_group) | |
420 | { | |
421 | struct dev_context *devc; | |
422 | ||
423 | (void)probe_group; | |
424 | ||
425 | if (sdi->status != SR_ST_ACTIVE) | |
426 | return SR_ERR_DEV_CLOSED; | |
427 | ||
428 | if (!(devc = sdi->priv)) { | |
429 | sr_err("sdi->priv was NULL."); | |
430 | return SR_ERR_BUG; | |
431 | } | |
432 | ||
433 | switch (id) { | |
434 | case SR_CONF_LIMIT_SAMPLES: | |
435 | devc->limit_samples = g_variant_get_uint64(data); | |
436 | sr_dbg("Setting sample limit to %" PRIu64 ".", | |
437 | devc->limit_samples); | |
438 | break; | |
439 | case SR_CONF_LIMIT_MSEC: | |
440 | devc->limit_msec = g_variant_get_uint64(data); | |
441 | sr_dbg("Setting time limit to %" PRIu64 "ms.", | |
442 | devc->limit_msec); | |
443 | break; | |
444 | default: | |
445 | return SR_ERR_NA; | |
446 | } | |
447 | ||
448 | return SR_OK; | |
449 | } | |
450 | ||
451 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, | |
452 | const struct sr_probe_group *probe_group) | |
453 | { | |
454 | (void)sdi; | |
455 | (void)probe_group; | |
456 | ||
457 | switch (key) { | |
458 | case SR_CONF_SCAN_OPTIONS: | |
459 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, | |
460 | hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); | |
461 | break; | |
462 | case SR_CONF_DEVICE_OPTIONS: | |
463 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, | |
464 | hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); | |
465 | break; | |
466 | default: | |
467 | return SR_ERR_NA; | |
468 | } | |
469 | ||
470 | return SR_OK; | |
471 | } | |
472 | ||
473 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, | |
474 | void *cb_data, int dmm) | |
475 | { | |
476 | struct dev_context *devc; | |
477 | struct sr_serial_dev_inst *serial; | |
478 | ||
479 | if (sdi->status != SR_ST_ACTIVE) | |
480 | return SR_ERR_DEV_CLOSED; | |
481 | ||
482 | if (!(devc = sdi->priv)) { | |
483 | sr_err("sdi->priv was NULL."); | |
484 | return SR_ERR_BUG; | |
485 | } | |
486 | ||
487 | devc->cb_data = cb_data; | |
488 | ||
489 | /* | |
490 | * Reset the number of samples to take. If we've already collected our | |
491 | * quota, but we start a new session, and don't reset this, we'll just | |
492 | * quit without acquiring any new samples. | |
493 | */ | |
494 | devc->num_samples = 0; | |
495 | devc->starttime = g_get_monotonic_time(); | |
496 | ||
497 | /* Send header packet to the session bus. */ | |
498 | std_session_send_df_header(cb_data, LOG_PREFIX); | |
499 | ||
500 | /* Poll every 50ms, or whenever some data comes in. */ | |
501 | serial = sdi->conn; | |
502 | serial_source_add(serial, G_IO_IN, 50, | |
503 | dmms[dmm].receive_data, (void *)sdi); | |
504 | ||
505 | return SR_OK; | |
506 | } | |
507 | ||
508 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) | |
509 | { | |
510 | return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close, | |
511 | sdi->conn, LOG_PREFIX); | |
512 | } | |
513 | ||
514 | /* Driver-specific API function wrappers */ | |
515 | #define HW_INIT(X) \ | |
516 | static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } | |
517 | #define HW_CLEANUP(X) \ | |
518 | static int cleanup_##X(void) { return cleanup(X); } | |
519 | #define HW_SCAN(X) \ | |
520 | static GSList *scan_##X(GSList *options) { return scan(options, X); } | |
521 | #define HW_DEV_LIST(X) \ | |
522 | static GSList *dev_list_##X(void) { return dev_list(X); } | |
523 | #define HW_DEV_CLEAR(X) \ | |
524 | static int dev_clear_##X(void) { return dev_clear(X); } | |
525 | #define HW_DEV_ACQUISITION_START(X) \ | |
526 | static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ | |
527 | void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } | |
528 | ||
529 | /* Driver structs and API function wrappers */ | |
530 | #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ | |
531 | HW_INIT(ID_UPPER) \ | |
532 | HW_CLEANUP(ID_UPPER) \ | |
533 | HW_SCAN(ID_UPPER) \ | |
534 | HW_DEV_LIST(ID_UPPER) \ | |
535 | HW_DEV_CLEAR(ID_UPPER) \ | |
536 | HW_DEV_ACQUISITION_START(ID_UPPER) \ | |
537 | SR_PRIV struct sr_dev_driver ID##_driver_info = { \ | |
538 | .name = NAME, \ | |
539 | .longname = LONGNAME, \ | |
540 | .api_version = 1, \ | |
541 | .init = init_##ID_UPPER, \ | |
542 | .cleanup = cleanup_##ID_UPPER, \ | |
543 | .scan = scan_##ID_UPPER, \ | |
544 | .dev_list = dev_list_##ID_UPPER, \ | |
545 | .dev_clear = dev_clear_##ID_UPPER, \ | |
546 | .config_get = NULL, \ | |
547 | .config_set = config_set, \ | |
548 | .config_list = config_list, \ | |
549 | .dev_open = std_serial_dev_open, \ | |
550 | .dev_close = std_serial_dev_close, \ | |
551 | .dev_acquisition_start = dev_acquisition_start_##ID_UPPER, \ | |
552 | .dev_acquisition_stop = dev_acquisition_stop, \ | |
553 | .priv = NULL, \ | |
554 | }; | |
555 | ||
556 | DRV(bbcgm_m2110, BBCGM_M2110, "bbcgm-m2110", "BBC Goertz Metrawatt M2110") | |
557 | DRV(digitek_dt4000zc, DIGITEK_DT4000ZC, "digitek-dt4000zc", "Digitek DT4000ZC") | |
558 | DRV(tekpower_tp4000zc, TEKPOWER_TP4000ZC, "tekpower-tp4000zc", "TekPower TP4000ZC") | |
559 | DRV(metex_me31, METEX_ME31, "metex-me31", "Metex ME-31") | |
560 | DRV(peaktech_3410, PEAKTECH_3410, "peaktech-3410", "PeakTech 3410") | |
561 | DRV(mastech_mas345, MASTECH_MAS345, "mastech-mas345", "MASTECH MAS345") | |
562 | DRV(va_va18b, VA_VA18B, "va-va18b", "V&A VA18B") | |
563 | DRV(va_va40b, VA_VA40B, "va-va40b", "V&A VA40B") | |
564 | DRV(metex_m3640d, METEX_M3640D, "metex-m3640d", "Metex M-3640D") | |
565 | DRV(metex_m4650cr, METEX_M4650CR, "metex-m4650cr", "Metex M-4650CR") | |
566 | DRV(peaktech_4370, PEAKTECH_4370, "peaktech-4370", "PeakTech 4370") | |
567 | DRV(pce_pce_dm32, PCE_PCE_DM32, "pce-pce-dm32", "PCE PCE-DM32") | |
568 | DRV(radioshack_22_168, RADIOSHACK_22_168, "radioshack-22-168", "RadioShack 22-168") | |
569 | DRV(radioshack_22_805, RADIOSHACK_22_805, "radioshack-22-805", "RadioShack 22-805") | |
570 | DRV(radioshack_22_812, RADIOSHACK_22_812, "radioshack-22-812", "RadioShack 22-812") | |
571 | DRV(tecpel_dmm_8061_ser, TECPEL_DMM_8061_SER, "tecpel-dmm-8061-ser", "Tecpel DMM-8061 (UT-D02 cable)") | |
572 | DRV(voltcraft_m3650d, VOLTCRAFT_M3650D, "voltcraft-m3650d", "Voltcraft M-3650D") | |
573 | DRV(voltcraft_m4650cr, VOLTCRAFT_M4650CR, "voltcraft-m4650cr", "Voltcraft M-4650CR") | |
574 | DRV(voltcraft_vc820_ser, VOLTCRAFT_VC820_SER, "voltcraft-vc820-ser", "Voltcraft VC-820 (UT-D02 cable)") | |
575 | DRV(voltcraft_vc830_ser, VOLTCRAFT_VC830_SER, "voltcraft-vc830-ser", "Voltcraft VC-830 (UT-D02 cable)") | |
576 | DRV(voltcraft_vc840_ser, VOLTCRAFT_VC840_SER, "voltcraft-vc840-ser", "Voltcraft VC-840 (UT-D02 cable)") | |
577 | DRV(uni_t_ut60a_ser, UNI_T_UT60A_SER, "uni-t-ut60a-ser", "UNI-T UT60A (UT-D02 cable)") | |
578 | DRV(uni_t_ut60e_ser, UNI_T_UT60E_SER, "uni-t-ut60e-ser", "UNI-T UT60E (UT-D02 cable)") | |
579 | DRV(uni_t_ut61b_ser, UNI_T_UT61B_SER, "uni-t-ut61b-ser", "UNI-T UT61B (UT-D02 cable)") | |
580 | DRV(uni_t_ut61c_ser, UNI_T_UT61C_SER, "uni-t-ut61c-ser", "UNI-T UT61C (UT-D02 cable)") | |
581 | DRV(uni_t_ut61d_ser, UNI_T_UT61D_SER, "uni-t-ut61d-ser", "UNI-T UT61D (UT-D02 cable)") | |
582 | DRV(uni_t_ut61e_ser, UNI_T_UT61E_SER, "uni-t-ut61e-ser", "UNI-T UT61E (UT-D02 cable)") | |
583 | DRV(iso_tech_idm103n, ISO_TECH_IDM103N, "iso-tech-idm103n", "ISO-TECH IDM103N") |