]>
Commit | Line | Data |
---|---|---|
7dc55d93 | 1 | /* |
50985c20 | 2 | * This file is part of the libsigrok project. |
7dc55d93 AG |
3 | * |
4 | * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> | |
5 | * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com> | |
729b01f9 | 6 | * Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> |
7dc55d93 AG |
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 | ||
7dc55d93 AG |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | |
24 | #include <fcntl.h> | |
25 | #include <string.h> | |
26 | #include <errno.h> | |
22f54192 | 27 | #include <glib.h> |
bbabddbd UH |
28 | #include "libsigrok.h" |
29 | #include "libsigrok-internal.h" | |
30 | #include "protocol.h" | |
7dc55d93 | 31 | |
ede25f4e | 32 | static const int32_t hwopts[] = { |
1953564a BV |
33 | SR_CONF_CONN, |
34 | SR_CONF_SERIALCOMM, | |
7dc55d93 AG |
35 | }; |
36 | ||
ede25f4e | 37 | static const int32_t hwcaps[] = { |
1953564a BV |
38 | SR_CONF_MULTIMETER, |
39 | SR_CONF_LIMIT_SAMPLES, | |
40 | SR_CONF_LIMIT_MSEC, | |
41 | SR_CONF_CONTINUOUS, | |
7dc55d93 AG |
42 | }; |
43 | ||
f086b830 | 44 | SR_PRIV struct sr_dev_driver digitek_dt4000zc_driver_info; |
729b01f9 | 45 | SR_PRIV struct sr_dev_driver tekpower_tp4000zc_driver_info; |
ce3777ad | 46 | SR_PRIV struct sr_dev_driver metex_me31_driver_info; |
f0ac4929 | 47 | SR_PRIV struct sr_dev_driver peaktech_3410_driver_info; |
5887c9cc | 48 | SR_PRIV struct sr_dev_driver mastech_mas345_driver_info; |
6dca2f16 | 49 | SR_PRIV struct sr_dev_driver va_va18b_driver_info; |
a53da082 | 50 | SR_PRIV struct sr_dev_driver metex_m3640d_driver_info; |
a376ffea | 51 | SR_PRIV struct sr_dev_driver peaktech_4370_driver_info; |
d4bd66a0 | 52 | SR_PRIV struct sr_dev_driver pce_pce_dm32_driver_info; |
d5ce233f | 53 | SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info; |
3864648b | 54 | SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info; |
21829e67 | 55 | SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info; |
c2fa697a | 56 | SR_PRIV struct sr_dev_driver tecpel_dmm_8060_ser_driver_info; |
b38e08fb | 57 | SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info; |
40830061 | 58 | SR_PRIV struct sr_dev_driver voltcraft_vc820_ser_driver_info; |
54d11221 | 59 | SR_PRIV struct sr_dev_driver voltcraft_vc840_ser_driver_info; |
ae3a59de | 60 | SR_PRIV struct sr_dev_driver uni_t_ut61d_ser_driver_info; |
986fde75 | 61 | SR_PRIV struct sr_dev_driver uni_t_ut61e_ser_driver_info; |
f086b830 | 62 | |
729b01f9 | 63 | SR_PRIV struct dmm_info dmms[] = { |
f086b830 | 64 | { |
ce3777ad UH |
65 | "Digitek", "DT4000ZC", "2400/8n1", 2400, |
66 | FS9721_PACKET_SIZE, NULL, | |
67 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
2451a20f | 68 | sr_fs9721_10_temp_c, |
dccfe015 | 69 | &digitek_dt4000zc_driver_info, receive_data_DIGITEK_DT4000ZC, |
f086b830 | 70 | }, |
729b01f9 | 71 | { |
ce3777ad UH |
72 | "TekPower", "TP4000ZC", "2400/8n1", 2400, |
73 | FS9721_PACKET_SIZE, NULL, | |
74 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
2451a20f | 75 | sr_fs9721_10_temp_c, |
dccfe015 | 76 | &tekpower_tp4000zc_driver_info, receive_data_TEKPOWER_TP4000ZC, |
729b01f9 | 77 | }, |
ce3777ad UH |
78 | { |
79 | "Metex", "ME-31", "600/7n2/rts=0/dtr=1", 600, | |
80 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
81 | sr_metex14_packet_valid, sr_metex14_parse, | |
82 | NULL, | |
dccfe015 | 83 | &metex_me31_driver_info, receive_data_METEX_ME31, |
ce3777ad | 84 | }, |
f0ac4929 UH |
85 | { |
86 | "Peaktech", "3410", "600/7n2/rts=0/dtr=1", 600, | |
87 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
88 | sr_metex14_packet_valid, sr_metex14_parse, | |
89 | NULL, | |
dccfe015 | 90 | &peaktech_3410_driver_info, receive_data_PEAKTECH_3410, |
f0ac4929 | 91 | }, |
5887c9cc UH |
92 | { |
93 | "MASTECH", "MAS345", "600/7n2/rts=0/dtr=1", 600, | |
94 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
95 | sr_metex14_packet_valid, sr_metex14_parse, | |
96 | NULL, | |
dccfe015 | 97 | &mastech_mas345_driver_info, receive_data_MASTECH_MAS345, |
5887c9cc | 98 | }, |
6dca2f16 UH |
99 | { |
100 | "V&A", "VA18B", "2400/8n1", 2400, | |
101 | FS9721_PACKET_SIZE, NULL, | |
102 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
2451a20f | 103 | sr_fs9721_01_temp_c, |
dccfe015 | 104 | &va_va18b_driver_info, receive_data_VA_VA18B, |
6dca2f16 | 105 | }, |
a53da082 UH |
106 | { |
107 | "Metex", "M-3640D", "1200/7n2/rts=0/dtr=1", 1200, | |
108 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
109 | sr_metex14_packet_valid, sr_metex14_parse, | |
110 | NULL, | |
dccfe015 | 111 | &metex_m3640d_driver_info, receive_data_METEX_M3640D, |
a53da082 | 112 | }, |
a376ffea UH |
113 | { |
114 | "PeakTech", "4370", "1200/7n2/rts=0/dtr=1", 1200, | |
115 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
116 | sr_metex14_packet_valid, sr_metex14_parse, | |
117 | NULL, | |
dccfe015 | 118 | &peaktech_4370_driver_info, receive_data_PEAKTECH_4370, |
a376ffea | 119 | }, |
d4bd66a0 UH |
120 | { |
121 | "PCE", "PCE-DM32", "2400/8n1", 2400, | |
122 | FS9721_PACKET_SIZE, NULL, | |
123 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
2451a20f | 124 | sr_fs9721_01_10_temp_f_c, |
dccfe015 | 125 | &pce_pce_dm32_driver_info, receive_data_PCE_PCE_DM32, |
d4bd66a0 | 126 | }, |
d5ce233f AG |
127 | { |
128 | "RadioShack", "22-168", "1200/7n2/rts=0/dtr=1", 1200, | |
129 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
130 | sr_metex14_packet_valid, sr_metex14_parse, | |
131 | NULL, | |
dccfe015 | 132 | &radioshack_22_168_driver_info, receive_data_RADIOSHACK_22_168, |
d5ce233f | 133 | }, |
3864648b AG |
134 | { |
135 | "RadioShack", "22-805", "600/7n2/rts=0/dtr=1", 600, | |
136 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
137 | sr_metex14_packet_valid, sr_metex14_parse, | |
138 | NULL, | |
139 | &radioshack_22_805_driver_info, receive_data_RADIOSHACK_22_805, | |
140 | }, | |
21829e67 AG |
141 | { |
142 | "RadioShack", "22-812", "4800/8n1/rts=0/dtr=1", 4800, | |
143 | RS9LCD_PACKET_SIZE, NULL, | |
144 | sr_rs9lcd_packet_valid, sr_rs9lcd_parse, | |
145 | NULL, | |
dccfe015 | 146 | &radioshack_22_812_driver_info, receive_data_RADIOSHACK_22_812, |
21829e67 | 147 | }, |
c2fa697a UH |
148 | { |
149 | "Tecpel", "DMM-8060 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
150 | 2400, FS9721_PACKET_SIZE, NULL, | |
151 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
152 | NULL, | |
153 | &tecpel_dmm_8060_ser_driver_info, | |
154 | receive_data_TECPEL_DMM_8060_SER, | |
155 | }, | |
b38e08fb UH |
156 | { |
157 | "Tecpel", "DMM-8061 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
158 | 2400, FS9721_PACKET_SIZE, NULL, | |
159 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
160 | sr_fs9721_00_temp_c, | |
161 | &tecpel_dmm_8061_ser_driver_info, | |
162 | receive_data_TECPEL_DMM_8061_SER, | |
163 | }, | |
40830061 UH |
164 | { |
165 | "Voltcraft", "VC-820 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
166 | 2400, FS9721_PACKET_SIZE, NULL, | |
167 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
168 | NULL, | |
14766619 UH |
169 | &voltcraft_vc820_ser_driver_info, |
170 | receive_data_VOLTCRAFT_VC820_SER, | |
40830061 | 171 | }, |
54d11221 UH |
172 | { |
173 | "Voltcraft", "VC-840 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
174 | 2400, FS9721_PACKET_SIZE, NULL, | |
175 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
2451a20f | 176 | sr_fs9721_00_temp_c, |
14766619 UH |
177 | &voltcraft_vc840_ser_driver_info, |
178 | receive_data_VOLTCRAFT_VC840_SER, | |
54d11221 | 179 | }, |
ae3a59de UH |
180 | { |
181 | "UNI-T", "UT61D (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
182 | 2400, FS9922_PACKET_SIZE, NULL, | |
183 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
184 | &uni_t_ut61d_ser_driver_info, receive_data_UNI_T_UT61D_SER, | |
185 | }, | |
986fde75 UH |
186 | { |
187 | /* Note: ES51922 baudrate is actually 19230! */ | |
188 | "UNI-T", "UT61E (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
189 | 19200, ES51922_PACKET_SIZE, NULL, | |
190 | sr_es51922_packet_valid, sr_es51922_parse, NULL, | |
191 | &uni_t_ut61e_ser_driver_info, receive_data_UNI_T_UT61E_SER, | |
192 | }, | |
729b01f9 | 193 | }; |
7dc55d93 AG |
194 | |
195 | /* Properly close and free all devices. */ | |
fd9b2b86 | 196 | static int clear_instances(int dmm) |
7dc55d93 AG |
197 | { |
198 | struct sr_dev_inst *sdi; | |
199 | struct drv_context *drvc; | |
200 | struct dev_context *devc; | |
1e1bfcd0 | 201 | struct sr_serial_dev_inst *serial; |
7dc55d93 | 202 | GSList *l; |
fd9b2b86 | 203 | struct sr_dev_driver *di; |
7dc55d93 | 204 | |
fd9b2b86 | 205 | di = dmms[dmm].di; |
26be4ebe | 206 | |
7dc55d93 AG |
207 | if (!(drvc = di->priv)) |
208 | return SR_OK; | |
209 | ||
210 | drvc = di->priv; | |
211 | for (l = drvc->instances; l; l = l->next) { | |
212 | if (!(sdi = l->data)) | |
213 | continue; | |
214 | if (!(devc = sdi->priv)) | |
215 | continue; | |
1e1bfcd0 UH |
216 | serial = sdi->conn; |
217 | sr_serial_dev_inst_free(serial); | |
7dc55d93 AG |
218 | sr_dev_inst_free(sdi); |
219 | } | |
220 | g_slist_free(drvc->instances); | |
221 | drvc->instances = NULL; | |
222 | ||
223 | return SR_OK; | |
224 | } | |
225 | ||
34f06b90 | 226 | static int hw_init(struct sr_context *sr_ctx, int dmm) |
7dc55d93 | 227 | { |
06b7a8af | 228 | sr_dbg("Selected '%s' subdriver.", dmms[dmm].di->name); |
729b01f9 | 229 | |
063e7aef | 230 | return std_hw_init(sr_ctx, dmms[dmm].di, DRIVER_LOG_DOMAIN); |
7dc55d93 AG |
231 | } |
232 | ||
729b01f9 | 233 | static GSList *scan(const char *conn, const char *serialcomm, int dmm) |
7dc55d93 AG |
234 | { |
235 | struct sr_dev_inst *sdi; | |
236 | struct drv_context *drvc; | |
237 | struct dev_context *devc; | |
238 | struct sr_probe *probe; | |
d35afa87 | 239 | struct sr_serial_dev_inst *serial; |
7dc55d93 | 240 | GSList *devices; |
2546b05c AG |
241 | int dropped, ret; |
242 | size_t len; | |
243 | uint8_t buf[128]; | |
7dc55d93 | 244 | |
d35afa87 | 245 | if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) |
7dc55d93 | 246 | return NULL; |
d35afa87 | 247 | |
ce3777ad | 248 | if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) |
7dc55d93 | 249 | return NULL; |
7dc55d93 | 250 | |
22f54192 | 251 | sr_info("Probing serial port %s.", conn); |
7dc55d93 | 252 | |
06b7a8af | 253 | drvc = dmms[dmm].di->priv; |
7dc55d93 | 254 | devices = NULL; |
d35afa87 | 255 | serial_flush(serial); |
bbabddbd | 256 | |
ce3777ad UH |
257 | /* Request a packet if the DMM requires this. */ |
258 | if (dmms[dmm].packet_request) { | |
259 | if ((ret = dmms[dmm].packet_request(serial)) < 0) { | |
260 | sr_err("Failed to request packet: %d.", ret); | |
261 | return FALSE; | |
262 | } | |
263 | } | |
264 | ||
22f54192 UH |
265 | /* |
266 | * There's no way to get an ID from the multimeter. It just sends data | |
267 | * periodically (or upon request), so the best we can do is check if | |
268 | * the packets match the expected format. | |
269 | */ | |
270 | ||
271 | /* Let's get a bit of data and see if we can find a packet. */ | |
272 | len = sizeof(buf); | |
729b01f9 UH |
273 | ret = serial_stream_detect(serial, buf, &len, dmms[dmm].packet_size, |
274 | dmms[dmm].packet_valid, 1000, | |
275 | dmms[dmm].baudrate); | |
2546b05c AG |
276 | if (ret != SR_OK) |
277 | goto scan_cleanup; | |
7dc55d93 | 278 | |
2546b05c AG |
279 | /* |
280 | * If we dropped more than two packets worth of data, something is | |
281 | * wrong. We shouldn't quit however, since the dropped bytes might be | |
282 | * just zeroes at the beginning of the stream. Those can occur as a | |
22f54192 UH |
283 | * combination of the nonstandard cable that ships with some devices |
284 | * and the serial port or USB to serial adapter. | |
2546b05c | 285 | */ |
729b01f9 UH |
286 | dropped = len - dmms[dmm].packet_size; |
287 | if (dropped > 2 * dmms[dmm].packet_size) | |
6bef68a7 | 288 | sr_warn("Had to drop too much data."); |
7dc55d93 | 289 | |
2546b05c | 290 | sr_info("Found device on port %s.", conn); |
7dc55d93 | 291 | |
729b01f9 UH |
292 | if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, dmms[dmm].vendor, |
293 | dmms[dmm].device, ""))) | |
2546b05c | 294 | goto scan_cleanup; |
6bef68a7 | 295 | |
2546b05c AG |
296 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { |
297 | sr_err("Device context malloc failed."); | |
298 | goto scan_cleanup; | |
7dc55d93 AG |
299 | } |
300 | ||
1e1bfcd0 UH |
301 | sdi->inst_type = SR_INST_SERIAL; |
302 | sdi->conn = serial; | |
2546b05c AG |
303 | |
304 | sdi->priv = devc; | |
06b7a8af | 305 | sdi->driver = dmms[dmm].di; |
2546b05c AG |
306 | if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) |
307 | goto scan_cleanup; | |
308 | sdi->probes = g_slist_append(sdi->probes, probe); | |
309 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
310 | devices = g_slist_append(devices, sdi); | |
311 | ||
312 | scan_cleanup: | |
d35afa87 | 313 | serial_close(serial); |
2546b05c | 314 | |
7dc55d93 AG |
315 | return devices; |
316 | } | |
317 | ||
ea4c6c23 | 318 | static GSList *hw_scan(GSList *options, int dmm) |
7dc55d93 | 319 | { |
1987b8d6 | 320 | struct sr_config *src; |
7dc55d93 AG |
321 | GSList *l, *devices; |
322 | const char *conn, *serialcomm; | |
323 | ||
324 | conn = serialcomm = NULL; | |
325 | for (l = options; l; l = l->next) { | |
1987b8d6 BV |
326 | src = l->data; |
327 | switch (src->key) { | |
1953564a | 328 | case SR_CONF_CONN: |
ede25f4e | 329 | conn = g_variant_get_string(src->data, NULL); |
7dc55d93 | 330 | break; |
1953564a | 331 | case SR_CONF_SERIALCOMM: |
ede25f4e | 332 | serialcomm = g_variant_get_string(src->data, NULL); |
7dc55d93 AG |
333 | break; |
334 | } | |
335 | } | |
336 | if (!conn) | |
337 | return NULL; | |
338 | ||
339 | if (serialcomm) { | |
340 | /* Use the provided comm specs. */ | |
729b01f9 | 341 | devices = scan(conn, serialcomm, dmm); |
7dc55d93 | 342 | } else { |
d35afa87 | 343 | /* Try the default. */ |
729b01f9 | 344 | devices = scan(conn, dmms[dmm].conn, dmm); |
7dc55d93 AG |
345 | } |
346 | ||
347 | return devices; | |
348 | } | |
349 | ||
ca4b1309 | 350 | static GSList *hw_dev_list(int dmm) |
7dc55d93 | 351 | { |
0e94d524 | 352 | return ((struct drv_context *)(dmms[dmm].di->priv))->instances; |
7dc55d93 AG |
353 | } |
354 | ||
355 | static int hw_dev_open(struct sr_dev_inst *sdi) | |
356 | { | |
1e1bfcd0 | 357 | struct sr_serial_dev_inst *serial; |
7dc55d93 | 358 | |
1e1bfcd0 UH |
359 | serial = sdi->conn; |
360 | if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) | |
7dc55d93 | 361 | return SR_ERR; |
bbabddbd | 362 | |
7dc55d93 AG |
363 | sdi->status = SR_ST_ACTIVE; |
364 | ||
365 | return SR_OK; | |
366 | } | |
367 | ||
368 | static int hw_dev_close(struct sr_dev_inst *sdi) | |
369 | { | |
1e1bfcd0 | 370 | struct sr_serial_dev_inst *serial; |
7dc55d93 | 371 | |
1e1bfcd0 UH |
372 | serial = sdi->conn; |
373 | if (serial && serial->fd != -1) { | |
374 | serial_close(serial); | |
7dc55d93 AG |
375 | sdi->status = SR_ST_INACTIVE; |
376 | } | |
377 | ||
378 | return SR_OK; | |
379 | } | |
380 | ||
0c23677d | 381 | static int hw_cleanup(int dmm) |
7dc55d93 | 382 | { |
fd9b2b86 | 383 | clear_instances(dmm); |
7dc55d93 AG |
384 | |
385 | return SR_OK; | |
386 | } | |
387 | ||
ede25f4e | 388 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) |
7dc55d93 AG |
389 | { |
390 | struct dev_context *devc; | |
391 | ||
392 | if (sdi->status != SR_ST_ACTIVE) | |
e73ffd42 | 393 | return SR_ERR_DEV_CLOSED; |
7dc55d93 AG |
394 | |
395 | if (!(devc = sdi->priv)) { | |
396 | sr_err("sdi->priv was NULL."); | |
397 | return SR_ERR_BUG; | |
398 | } | |
399 | ||
035a1078 | 400 | switch (id) { |
1953564a | 401 | case SR_CONF_LIMIT_SAMPLES: |
ede25f4e | 402 | devc->limit_samples = g_variant_get_uint64(data); |
7dc55d93 AG |
403 | sr_dbg("Setting sample limit to %" PRIu64 ".", |
404 | devc->limit_samples); | |
405 | break; | |
1953564a | 406 | case SR_CONF_LIMIT_MSEC: |
ede25f4e | 407 | devc->limit_msec = g_variant_get_uint64(data); |
f9b9bd63 AG |
408 | sr_dbg("Setting time limit to %" PRIu64 "ms.", |
409 | devc->limit_msec); | |
410 | break; | |
7dc55d93 | 411 | default: |
bd6fbf62 | 412 | return SR_ERR_NA; |
7dc55d93 AG |
413 | } |
414 | ||
415 | return SR_OK; | |
416 | } | |
417 | ||
ede25f4e | 418 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) |
a1c743fc BV |
419 | { |
420 | ||
421 | (void)sdi; | |
422 | ||
423 | switch (key) { | |
0d485e30 | 424 | case SR_CONF_SCAN_OPTIONS: |
ede25f4e BV |
425 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, |
426 | hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); | |
0d485e30 | 427 | break; |
9a6517d1 | 428 | case SR_CONF_DEVICE_OPTIONS: |
ede25f4e BV |
429 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, |
430 | hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); | |
9a6517d1 | 431 | break; |
a1c743fc | 432 | default: |
bd6fbf62 | 433 | return SR_ERR_NA; |
a1c743fc BV |
434 | } |
435 | ||
436 | return SR_OK; | |
437 | } | |
438 | ||
7dc55d93 | 439 | static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, |
16b7b790 | 440 | void *cb_data, int dmm) |
7dc55d93 | 441 | { |
7dc55d93 | 442 | struct dev_context *devc; |
1e1bfcd0 | 443 | struct sr_serial_dev_inst *serial; |
7dc55d93 | 444 | |
e73ffd42 BV |
445 | if (sdi->status != SR_ST_ACTIVE) |
446 | return SR_ERR_DEV_CLOSED; | |
447 | ||
7dc55d93 AG |
448 | if (!(devc = sdi->priv)) { |
449 | sr_err("sdi->priv was NULL."); | |
450 | return SR_ERR_BUG; | |
451 | } | |
452 | ||
7dc55d93 AG |
453 | devc->cb_data = cb_data; |
454 | ||
bbabddbd UH |
455 | /* |
456 | * Reset the number of samples to take. If we've already collected our | |
7dc55d93 | 457 | * quota, but we start a new session, and don't reset this, we'll just |
bbabddbd UH |
458 | * quit without acquiring any new samples. |
459 | */ | |
7dc55d93 | 460 | devc->num_samples = 0; |
f9b9bd63 | 461 | devc->starttime = g_get_monotonic_time(); |
7dc55d93 AG |
462 | |
463 | /* Send header packet to the session bus. */ | |
4afdfd46 | 464 | std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); |
7dc55d93 | 465 | |
bbabddbd | 466 | /* Poll every 50ms, or whenever some data comes in. */ |
1e1bfcd0 UH |
467 | serial = sdi->conn; |
468 | sr_source_add(serial->fd, G_IO_IN, 50, | |
16b7b790 | 469 | dmms[dmm].receive_data, (void *)sdi); |
7dc55d93 AG |
470 | |
471 | return SR_OK; | |
472 | } | |
473 | ||
69b07d14 | 474 | static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
7dc55d93 | 475 | { |
cd2f0fe2 | 476 | return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close, |
1e1bfcd0 | 477 | sdi->conn, DRIVER_LOG_DOMAIN); |
7dc55d93 AG |
478 | } |
479 | ||
3098b390 AG |
480 | /* Driver-specific API function wrappers */ |
481 | #define HW_INIT(X) \ | |
482 | static int hw_init_##X(struct sr_context *sr_ctx) { return hw_init(sr_ctx, X); } | |
483 | #define HW_CLEANUP(X) \ | |
484 | static int hw_cleanup_##X(void) { return hw_cleanup(X); } | |
485 | #define HW_SCAN(X) \ | |
486 | static GSList *hw_scan_##X(GSList *options) { return hw_scan(options, X); } | |
487 | #define HW_DEV_LIST(X) \ | |
488 | static GSList *hw_dev_list_##X(void) { return hw_dev_list(X); } | |
489 | #define CLEAR_INSTANCES(X) \ | |
490 | static int clear_instances_##X(void) { return clear_instances(X); } | |
16b7b790 UH |
491 | #define HW_DEV_ACQUISITION_START(X) \ |
492 | static int hw_dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ | |
493 | void *cb_data) { return hw_dev_acquisition_start(sdi, cb_data, X); } | |
3098b390 AG |
494 | |
495 | /* Driver structs and API function wrappers */ | |
f1437c68 | 496 | #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ |
3098b390 AG |
497 | HW_INIT(ID_UPPER) \ |
498 | HW_CLEANUP(ID_UPPER) \ | |
499 | HW_SCAN(ID_UPPER) \ | |
500 | HW_DEV_LIST(ID_UPPER) \ | |
501 | CLEAR_INSTANCES(ID_UPPER) \ | |
16b7b790 | 502 | HW_DEV_ACQUISITION_START(ID_UPPER) \ |
f1437c68 UH |
503 | SR_PRIV struct sr_dev_driver ID##_driver_info = { \ |
504 | .name = NAME, \ | |
505 | .longname = LONGNAME, \ | |
506 | .api_version = 1, \ | |
507 | .init = hw_init_##ID_UPPER, \ | |
0c23677d | 508 | .cleanup = hw_cleanup_##ID_UPPER, \ |
ea4c6c23 | 509 | .scan = hw_scan_##ID_UPPER, \ |
ca4b1309 | 510 | .dev_list = hw_dev_list_##ID_UPPER, \ |
fd9b2b86 | 511 | .dev_clear = clear_instances_##ID_UPPER, \ |
6fab7b8f | 512 | .config_get = NULL, \ |
035a1078 | 513 | .config_set = config_set, \ |
a1c743fc | 514 | .config_list = config_list, \ |
f1437c68 UH |
515 | .dev_open = hw_dev_open, \ |
516 | .dev_close = hw_dev_close, \ | |
16b7b790 | 517 | .dev_acquisition_start = hw_dev_acquisition_start_##ID_UPPER, \ |
f1437c68 UH |
518 | .dev_acquisition_stop = hw_dev_acquisition_stop, \ |
519 | .priv = NULL, \ | |
21829e67 | 520 | }; |
3098b390 | 521 | |
f1437c68 UH |
522 | DRV(digitek_dt4000zc, DIGITEK_DT4000ZC, "digitek-dt4000zc", "Digitek DT4000ZC") |
523 | DRV(tekpower_tp4000zc, TEKPOWER_TP4000ZC, "tekpower-tp4000zc", "TekPower TP4000ZC") | |
524 | DRV(metex_me31, METEX_ME31, "metex-me31", "Metex ME-31") | |
525 | DRV(peaktech_3410, PEAKTECH_3410, "peaktech-3410", "PeakTech 3410") | |
526 | DRV(mastech_mas345, MASTECH_MAS345, "mastech-mas345", "MASTECH MAS345") | |
527 | DRV(va_va18b, VA_VA18B, "va-va18b", "V&A VA18B") | |
528 | DRV(metex_m3640d, METEX_M3640D, "metex-m3640d", "Metex M-3640D") | |
529 | DRV(peaktech_4370, PEAKTECH_4370, "peaktech-4370", "PeakTech 4370") | |
530 | DRV(pce_pce_dm32, PCE_PCE_DM32, "pce-pce-dm32", "PCE PCE-DM32") | |
531 | DRV(radioshack_22_168, RADIOSHACK_22_168, "radioshack-22-168", "RadioShack 22-168") | |
3864648b | 532 | DRV(radioshack_22_805, RADIOSHACK_22_805, "radioshack-22-805", "RadioShack 22-805") |
f1437c68 | 533 | DRV(radioshack_22_812, RADIOSHACK_22_812, "radioshack-22-812", "RadioShack 22-812") |
c2fa697a | 534 | DRV(tecpel_dmm_8060_ser, TECPEL_DMM_8060_SER, "tecpel-dmm-8060-ser", "Tecpel DMM-8060 (UT-D02 cable)") |
b38e08fb | 535 | DRV(tecpel_dmm_8061_ser, TECPEL_DMM_8061_SER, "tecpel-dmm-8061-ser", "Tecpel DMM-8061 (UT-D02 cable)") |
14766619 UH |
536 | DRV(voltcraft_vc820_ser, VOLTCRAFT_VC820_SER, "voltcraft-vc820-ser", "Voltcraft VC-820 (UT-D02 cable)") |
537 | DRV(voltcraft_vc840_ser, VOLTCRAFT_VC840_SER, "voltcraft-vc840-ser", "Voltcraft VC-840 (UT-D02 cable)") | |
ae3a59de | 538 | DRV(uni_t_ut61d_ser, UNI_T_UT61D_SER, "uni-t-ut61d-ser", "UNI-T UT61D (UT-D02 cable)") |
986fde75 | 539 | DRV(uni_t_ut61e_ser, UNI_T_UT61E_SER, "uni-t-ut61e-ser", "UNI-T UT61E (UT-D02 cable)") |