]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the sigrok 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 <glib.h> | |
23 | #include <sys/types.h> | |
24 | #include <sys/stat.h> | |
25 | #include <fcntl.h> | |
26 | #include <string.h> | |
27 | #include <errno.h> | |
28 | #include "libsigrok.h" | |
29 | #include "libsigrok-internal.h" | |
30 | #include "protocol.h" | |
31 | ||
32 | static const int hwopts[] = { | |
33 | SR_HWOPT_CONN, | |
34 | SR_HWOPT_SERIALCOMM, | |
35 | 0, | |
36 | }; | |
37 | ||
38 | static const int hwcaps[] = { | |
39 | SR_HWCAP_MULTIMETER, | |
40 | SR_HWCAP_LIMIT_SAMPLES, | |
41 | SR_HWCAP_CONTINUOUS, | |
42 | 0, | |
43 | }; | |
44 | ||
45 | static const char *probe_names[] = { | |
46 | "Probe", | |
47 | NULL, | |
48 | }; | |
49 | ||
50 | SR_PRIV struct sr_dev_driver digitek_dt4000zc_driver_info; | |
51 | SR_PRIV struct sr_dev_driver tekpower_tp4000zc_driver_info; | |
52 | SR_PRIV struct sr_dev_driver metex_me31_driver_info; | |
53 | SR_PRIV struct sr_dev_driver peaktech_3410_driver_info; | |
54 | SR_PRIV struct sr_dev_driver mastech_mas345_driver_info; | |
55 | SR_PRIV struct sr_dev_driver va_va18b_driver_info; | |
56 | SR_PRIV struct sr_dev_driver metex_m3640d_driver_info; | |
57 | SR_PRIV struct sr_dev_driver peaktech_4370_driver_info; | |
58 | SR_PRIV struct sr_dev_driver pce_pce_dm32_driver_info; | |
59 | SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info; | |
60 | SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info; | |
61 | ||
62 | /* After hw_init() this will point to a device-specific entry (see above). */ | |
63 | static struct sr_dev_driver *di = NULL; | |
64 | ||
65 | SR_PRIV struct dmm_info dmms[] = { | |
66 | { | |
67 | "Digitek", "DT4000ZC", "2400/8n1", 2400, | |
68 | FS9721_PACKET_SIZE, NULL, | |
69 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
70 | dmm_details_dt4000zc, | |
71 | &digitek_dt4000zc_driver_info, receive_data_DIGITEK_DT4000ZC, | |
72 | }, | |
73 | { | |
74 | "TekPower", "TP4000ZC", "2400/8n1", 2400, | |
75 | FS9721_PACKET_SIZE, NULL, | |
76 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
77 | dmm_details_tp4000zc, | |
78 | &tekpower_tp4000zc_driver_info, receive_data_TEKPOWER_TP4000ZC, | |
79 | }, | |
80 | { | |
81 | "Metex", "ME-31", "600/7n2/rts=0/dtr=1", 600, | |
82 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
83 | sr_metex14_packet_valid, sr_metex14_parse, | |
84 | NULL, | |
85 | &metex_me31_driver_info, receive_data_METEX_ME31, | |
86 | }, | |
87 | { | |
88 | "Peaktech", "3410", "600/7n2/rts=0/dtr=1", 600, | |
89 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
90 | sr_metex14_packet_valid, sr_metex14_parse, | |
91 | NULL, | |
92 | &peaktech_3410_driver_info, receive_data_PEAKTECH_3410, | |
93 | }, | |
94 | { | |
95 | "MASTECH", "MAS345", "600/7n2/rts=0/dtr=1", 600, | |
96 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
97 | sr_metex14_packet_valid, sr_metex14_parse, | |
98 | NULL, | |
99 | &mastech_mas345_driver_info, receive_data_MASTECH_MAS345, | |
100 | }, | |
101 | { | |
102 | "V&A", "VA18B", "2400/8n1", 2400, | |
103 | FS9721_PACKET_SIZE, NULL, | |
104 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
105 | dmm_details_va18b, | |
106 | &va_va18b_driver_info, receive_data_VA_VA18B, | |
107 | }, | |
108 | { | |
109 | "Metex", "M-3640D", "1200/7n2/rts=0/dtr=1", 1200, | |
110 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
111 | sr_metex14_packet_valid, sr_metex14_parse, | |
112 | NULL, | |
113 | &metex_m3640d_driver_info, receive_data_METEX_M3640D, | |
114 | }, | |
115 | { | |
116 | "PeakTech", "4370", "1200/7n2/rts=0/dtr=1", 1200, | |
117 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
118 | sr_metex14_packet_valid, sr_metex14_parse, | |
119 | NULL, | |
120 | &peaktech_4370_driver_info, receive_data_PEAKTECH_4370, | |
121 | }, | |
122 | { | |
123 | "PCE", "PCE-DM32", "2400/8n1", 2400, | |
124 | FS9721_PACKET_SIZE, NULL, | |
125 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
126 | dmm_details_pce_dm32, | |
127 | &pce_pce_dm32_driver_info, receive_data_PCE_PCE_DM32, | |
128 | }, | |
129 | { | |
130 | "RadioShack", "22-168", "1200/7n2/rts=0/dtr=1", 1200, | |
131 | METEX14_PACKET_SIZE, sr_metex14_packet_request, | |
132 | sr_metex14_packet_valid, sr_metex14_parse, | |
133 | NULL, | |
134 | &radioshack_22_168_driver_info, receive_data_RADIOSHACK_22_168, | |
135 | }, | |
136 | { | |
137 | "RadioShack", "22-812", "4800/8n1/rts=0/dtr=1", 4800, | |
138 | RS9LCD_PACKET_SIZE, NULL, | |
139 | sr_rs9lcd_packet_valid, sr_rs9lcd_parse, | |
140 | NULL, | |
141 | &radioshack_22_812_driver_info, receive_data_RADIOSHACK_22_812, | |
142 | }, | |
143 | }; | |
144 | ||
145 | /* Properly close and free all devices. */ | |
146 | static int clear_instances(int dmm) | |
147 | { | |
148 | struct sr_dev_inst *sdi; | |
149 | struct drv_context *drvc; | |
150 | struct dev_context *devc; | |
151 | GSList *l; | |
152 | struct sr_dev_driver *di; | |
153 | ||
154 | di = dmms[dmm].di; | |
155 | ||
156 | if (!(drvc = di->priv)) | |
157 | return SR_OK; | |
158 | ||
159 | drvc = di->priv; | |
160 | for (l = drvc->instances; l; l = l->next) { | |
161 | if (!(sdi = l->data)) | |
162 | continue; | |
163 | if (!(devc = sdi->priv)) | |
164 | continue; | |
165 | sr_serial_dev_inst_free(devc->serial); | |
166 | sr_dev_inst_free(sdi); | |
167 | } | |
168 | g_slist_free(drvc->instances); | |
169 | drvc->instances = NULL; | |
170 | ||
171 | return SR_OK; | |
172 | } | |
173 | ||
174 | /* Driver-specific clear_instances() function wrappers */ | |
175 | #define CLEAR_INSTANCES(X) static int clear_instances_##X(void) \ | |
176 | { return clear_instances(X); } | |
177 | CLEAR_INSTANCES(DIGITEK_DT4000ZC) | |
178 | CLEAR_INSTANCES(TEKPOWER_TP4000ZC) | |
179 | CLEAR_INSTANCES(METEX_ME31) | |
180 | CLEAR_INSTANCES(PEAKTECH_3410) | |
181 | CLEAR_INSTANCES(MASTECH_MAS345) | |
182 | CLEAR_INSTANCES(VA_VA18B) | |
183 | CLEAR_INSTANCES(METEX_M3640D) | |
184 | CLEAR_INSTANCES(PEAKTECH_4370) | |
185 | CLEAR_INSTANCES(PCE_PCE_DM32) | |
186 | CLEAR_INSTANCES(RADIOSHACK_22_168) | |
187 | CLEAR_INSTANCES(RADIOSHACK_22_812) | |
188 | ||
189 | static int hw_init(struct sr_context *sr_ctx, int dmm) | |
190 | { | |
191 | struct drv_context *drvc; | |
192 | ||
193 | if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { | |
194 | sr_err("Driver context malloc failed."); | |
195 | return SR_ERR_MALLOC; | |
196 | } | |
197 | ||
198 | di = dmms[dmm].di; | |
199 | sr_dbg("Selected '%s' subdriver.", dmms[dmm].di->name); | |
200 | ||
201 | drvc->sr_ctx = sr_ctx; | |
202 | //// di->priv = drvc; | |
203 | dmms[dmm].di->priv = drvc; | |
204 | ||
205 | return SR_OK; | |
206 | } | |
207 | ||
208 | /* Driver-specific hw_init() function wrappers */ | |
209 | #define HW_INIT(X) static int hw_init_##X(struct sr_context *sr_ctx) \ | |
210 | { return hw_init(sr_ctx, X); } | |
211 | HW_INIT(DIGITEK_DT4000ZC) | |
212 | HW_INIT(TEKPOWER_TP4000ZC) | |
213 | HW_INIT(METEX_ME31) | |
214 | HW_INIT(PEAKTECH_3410) | |
215 | HW_INIT(MASTECH_MAS345) | |
216 | HW_INIT(VA_VA18B) | |
217 | HW_INIT(METEX_M3640D) | |
218 | HW_INIT(PEAKTECH_4370) | |
219 | HW_INIT(PCE_PCE_DM32) | |
220 | HW_INIT(RADIOSHACK_22_168) | |
221 | HW_INIT(RADIOSHACK_22_812) | |
222 | ||
223 | static GSList *scan(const char *conn, const char *serialcomm, int dmm) | |
224 | { | |
225 | struct sr_dev_inst *sdi; | |
226 | struct drv_context *drvc; | |
227 | struct dev_context *devc; | |
228 | struct sr_probe *probe; | |
229 | struct sr_serial_dev_inst *serial; | |
230 | GSList *devices; | |
231 | int dropped, ret; | |
232 | size_t len; | |
233 | uint8_t buf[128]; | |
234 | ||
235 | if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) | |
236 | return NULL; | |
237 | ||
238 | if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) | |
239 | return NULL; | |
240 | ||
241 | sr_info("Probing port %s.", conn); | |
242 | ||
243 | //// drvc = di->priv; | |
244 | drvc = dmms[dmm].di->priv; | |
245 | devices = NULL; | |
246 | serial_flush(serial); | |
247 | ||
248 | /* | |
249 | * There's no way to get an ID from the multimeter. It just sends data | |
250 | * periodically, so the best we can do is check if the packets match | |
251 | * the expected format. | |
252 | */ | |
253 | ||
254 | /* Let's get a bit of data and see if we can find a packet. */ | |
255 | len = sizeof(buf); | |
256 | ||
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 | ||
265 | ret = serial_stream_detect(serial, buf, &len, dmms[dmm].packet_size, | |
266 | dmms[dmm].packet_valid, 1000, | |
267 | dmms[dmm].baudrate); | |
268 | if (ret != SR_OK) | |
269 | goto scan_cleanup; | |
270 | ||
271 | /* | |
272 | * If we dropped more than two packets worth of data, something is | |
273 | * wrong. We shouldn't quit however, since the dropped bytes might be | |
274 | * just zeroes at the beginning of the stream. Those can occur as a | |
275 | * combination of the nonstandard cable that ships with this device and | |
276 | * the serial port or USB to serial adapter. | |
277 | */ | |
278 | dropped = len - dmms[dmm].packet_size; | |
279 | if (dropped > 2 * dmms[dmm].packet_size) | |
280 | sr_warn("Had to drop too much data."); | |
281 | ||
282 | sr_info("Found device on port %s.", conn); | |
283 | ||
284 | if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, dmms[dmm].vendor, | |
285 | dmms[dmm].device, ""))) | |
286 | goto scan_cleanup; | |
287 | ||
288 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { | |
289 | sr_err("Device context malloc failed."); | |
290 | goto scan_cleanup; | |
291 | } | |
292 | ||
293 | devc->serial = serial; | |
294 | ||
295 | sdi->priv = devc; | |
296 | sdi->driver = dmms[dmm].di; | |
297 | if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) | |
298 | goto scan_cleanup; | |
299 | sdi->probes = g_slist_append(sdi->probes, probe); | |
300 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
301 | devices = g_slist_append(devices, sdi); | |
302 | ||
303 | scan_cleanup: | |
304 | serial_close(serial); | |
305 | ||
306 | return devices; | |
307 | } | |
308 | ||
309 | static GSList *hw_scan(GSList *options, int dmm) | |
310 | { | |
311 | struct sr_hwopt *opt; | |
312 | GSList *l, *devices; | |
313 | const char *conn, *serialcomm; | |
314 | ||
315 | conn = serialcomm = NULL; | |
316 | for (l = options; l; l = l->next) { | |
317 | opt = l->data; | |
318 | switch (opt->hwopt) { | |
319 | case SR_HWOPT_CONN: | |
320 | conn = opt->value; | |
321 | break; | |
322 | case SR_HWOPT_SERIALCOMM: | |
323 | serialcomm = opt->value; | |
324 | break; | |
325 | } | |
326 | } | |
327 | if (!conn) | |
328 | return NULL; | |
329 | ||
330 | if (serialcomm) { | |
331 | /* Use the provided comm specs. */ | |
332 | devices = scan(conn, serialcomm, dmm); | |
333 | } else { | |
334 | /* Try the default. */ | |
335 | devices = scan(conn, dmms[dmm].conn, dmm); | |
336 | } | |
337 | ||
338 | return devices; | |
339 | } | |
340 | ||
341 | /* Driver-specific hw_scan() function wrappers */ | |
342 | #define HW_SCAN(X) static GSList *hw_scan_##X(GSList *options) \ | |
343 | { return hw_scan(options, X); } | |
344 | HW_SCAN(DIGITEK_DT4000ZC) | |
345 | HW_SCAN(TEKPOWER_TP4000ZC) | |
346 | HW_SCAN(METEX_ME31) | |
347 | HW_SCAN(PEAKTECH_3410) | |
348 | HW_SCAN(MASTECH_MAS345) | |
349 | HW_SCAN(VA_VA18B) | |
350 | HW_SCAN(METEX_M3640D) | |
351 | HW_SCAN(PEAKTECH_4370) | |
352 | HW_SCAN(PCE_PCE_DM32) | |
353 | HW_SCAN(RADIOSHACK_22_168) | |
354 | HW_SCAN(RADIOSHACK_22_812) | |
355 | ||
356 | static GSList *hw_dev_list(int dmm) | |
357 | { | |
358 | struct drv_context *drvc; | |
359 | ||
360 | drvc = dmms[dmm].di->priv; | |
361 | ||
362 | return drvc->instances; | |
363 | } | |
364 | ||
365 | /* Driver-specific hw_dev_list() function wrappers */ | |
366 | #define HW_DEV_LIST(X) static GSList *hw_dev_list_##X(void) \ | |
367 | { return hw_dev_list(X); } | |
368 | HW_DEV_LIST(DIGITEK_DT4000ZC) | |
369 | HW_DEV_LIST(TEKPOWER_TP4000ZC) | |
370 | HW_DEV_LIST(METEX_ME31) | |
371 | HW_DEV_LIST(PEAKTECH_3410) | |
372 | HW_DEV_LIST(MASTECH_MAS345) | |
373 | HW_DEV_LIST(VA_VA18B) | |
374 | HW_DEV_LIST(METEX_M3640D) | |
375 | HW_DEV_LIST(PEAKTECH_4370) | |
376 | HW_DEV_LIST(PCE_PCE_DM32) | |
377 | HW_DEV_LIST(RADIOSHACK_22_168) | |
378 | HW_DEV_LIST(RADIOSHACK_22_812) | |
379 | ||
380 | static int hw_dev_open(struct sr_dev_inst *sdi) | |
381 | { | |
382 | struct dev_context *devc; | |
383 | ||
384 | if (!(devc = sdi->priv)) { | |
385 | sr_err("sdi->priv was NULL."); | |
386 | return SR_ERR_BUG; | |
387 | } | |
388 | ||
389 | if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) | |
390 | return SR_ERR; | |
391 | ||
392 | sdi->status = SR_ST_ACTIVE; | |
393 | ||
394 | return SR_OK; | |
395 | } | |
396 | ||
397 | static int hw_dev_close(struct sr_dev_inst *sdi) | |
398 | { | |
399 | struct dev_context *devc; | |
400 | ||
401 | if (!(devc = sdi->priv)) { | |
402 | sr_err("sdi->priv was NULL."); | |
403 | return SR_ERR_BUG; | |
404 | } | |
405 | ||
406 | if (devc->serial && devc->serial->fd != -1) { | |
407 | serial_close(devc->serial); | |
408 | sdi->status = SR_ST_INACTIVE; | |
409 | } | |
410 | ||
411 | return SR_OK; | |
412 | } | |
413 | ||
414 | static int hw_cleanup(int dmm) | |
415 | { | |
416 | clear_instances(dmm); | |
417 | ||
418 | return SR_OK; | |
419 | } | |
420 | ||
421 | /* Driver-specific hw_cleanup() function wrappers */ | |
422 | #define HW_CLEANUP(X) static int hw_cleanup_##X(void) { return hw_cleanup(X); } | |
423 | HW_CLEANUP(DIGITEK_DT4000ZC) | |
424 | HW_CLEANUP(TEKPOWER_TP4000ZC) | |
425 | HW_CLEANUP(METEX_ME31) | |
426 | HW_CLEANUP(PEAKTECH_3410) | |
427 | HW_CLEANUP(MASTECH_MAS345) | |
428 | HW_CLEANUP(VA_VA18B) | |
429 | HW_CLEANUP(METEX_M3640D) | |
430 | HW_CLEANUP(PEAKTECH_4370) | |
431 | HW_CLEANUP(PCE_PCE_DM32) | |
432 | HW_CLEANUP(RADIOSHACK_22_168) | |
433 | HW_CLEANUP(RADIOSHACK_22_812) | |
434 | ||
435 | static int hw_info_get(int info_id, const void **data, | |
436 | const struct sr_dev_inst *sdi) | |
437 | { | |
438 | (void)sdi; | |
439 | ||
440 | switch (info_id) { | |
441 | case SR_DI_HWOPTS: | |
442 | *data = hwopts; | |
443 | break; | |
444 | case SR_DI_HWCAPS: | |
445 | *data = hwcaps; | |
446 | break; | |
447 | case SR_DI_NUM_PROBES: | |
448 | *data = GINT_TO_POINTER(1); | |
449 | break; | |
450 | case SR_DI_PROBE_NAMES: | |
451 | *data = probe_names; | |
452 | break; | |
453 | default: | |
454 | return SR_ERR_ARG; | |
455 | } | |
456 | ||
457 | return SR_OK; | |
458 | } | |
459 | ||
460 | static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, | |
461 | const void *value) | |
462 | { | |
463 | struct dev_context *devc; | |
464 | ||
465 | if (sdi->status != SR_ST_ACTIVE) | |
466 | return SR_ERR; | |
467 | ||
468 | if (!(devc = sdi->priv)) { | |
469 | sr_err("sdi->priv was NULL."); | |
470 | return SR_ERR_BUG; | |
471 | } | |
472 | ||
473 | switch (hwcap) { | |
474 | case SR_HWCAP_LIMIT_SAMPLES: | |
475 | devc->limit_samples = *(const uint64_t *)value; | |
476 | sr_dbg("Setting sample limit to %" PRIu64 ".", | |
477 | devc->limit_samples); | |
478 | break; | |
479 | default: | |
480 | sr_err("Unknown capability: %d.", hwcap); | |
481 | return SR_ERR; | |
482 | break; | |
483 | } | |
484 | ||
485 | return SR_OK; | |
486 | } | |
487 | ||
488 | static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, | |
489 | void *cb_data) | |
490 | { | |
491 | struct sr_datafeed_packet packet; | |
492 | struct sr_datafeed_header header; | |
493 | struct sr_datafeed_meta_analog meta; | |
494 | struct dev_context *devc; | |
495 | ||
496 | if (!(devc = sdi->priv)) { | |
497 | sr_err("sdi->priv was NULL."); | |
498 | return SR_ERR_BUG; | |
499 | } | |
500 | ||
501 | sr_dbg("Starting acquisition."); | |
502 | ||
503 | devc->cb_data = cb_data; | |
504 | ||
505 | /* | |
506 | * Reset the number of samples to take. If we've already collected our | |
507 | * quota, but we start a new session, and don't reset this, we'll just | |
508 | * quit without acquiring any new samples. | |
509 | */ | |
510 | devc->num_samples = 0; | |
511 | ||
512 | /* Send header packet to the session bus. */ | |
513 | sr_dbg("Sending SR_DF_HEADER."); | |
514 | packet.type = SR_DF_HEADER; | |
515 | packet.payload = (uint8_t *)&header; | |
516 | header.feed_version = 1; | |
517 | gettimeofday(&header.starttime, NULL); | |
518 | sr_session_send(devc->cb_data, &packet); | |
519 | ||
520 | /* Send metadata about the SR_DF_ANALOG packets to come. */ | |
521 | sr_dbg("Sending SR_DF_META_ANALOG."); | |
522 | packet.type = SR_DF_META_ANALOG; | |
523 | packet.payload = &meta; | |
524 | meta.num_probes = 1; | |
525 | sr_session_send(devc->cb_data, &packet); | |
526 | ||
527 | /* Poll every 50ms, or whenever some data comes in. */ | |
528 | sr_source_add(devc->serial->fd, G_IO_IN, 50, | |
529 | dmms[sdi->driver->subdriver].receive_data, (void *)sdi); | |
530 | ||
531 | return SR_OK; | |
532 | } | |
533 | ||
534 | static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) | |
535 | { | |
536 | struct sr_datafeed_packet packet; | |
537 | struct dev_context *devc; | |
538 | ||
539 | if (sdi->status != SR_ST_ACTIVE) | |
540 | return SR_ERR; | |
541 | ||
542 | if (!(devc = sdi->priv)) { | |
543 | sr_err("sdi->priv was NULL."); | |
544 | return SR_ERR_BUG; | |
545 | } | |
546 | ||
547 | sr_dbg("Stopping acquisition."); | |
548 | ||
549 | sr_source_remove(devc->serial->fd); | |
550 | hw_dev_close((struct sr_dev_inst *)sdi); | |
551 | ||
552 | /* Send end packet to the session bus. */ | |
553 | sr_dbg("Sending SR_DF_END."); | |
554 | packet.type = SR_DF_END; | |
555 | sr_session_send(cb_data, &packet); | |
556 | ||
557 | return SR_OK; | |
558 | } | |
559 | ||
560 | /* Driver structs */ | |
561 | #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ | |
562 | SR_PRIV struct sr_dev_driver ID##_driver_info = { \ | |
563 | .name = NAME, \ | |
564 | .longname = LONGNAME, \ | |
565 | .api_version = 1, \ | |
566 | .init = hw_init_##ID_UPPER, \ | |
567 | .cleanup = hw_cleanup_##ID_UPPER, \ | |
568 | .scan = hw_scan_##ID_UPPER, \ | |
569 | .dev_list = hw_dev_list_##ID_UPPER, \ | |
570 | .dev_clear = clear_instances_##ID_UPPER, \ | |
571 | .dev_open = hw_dev_open, \ | |
572 | .dev_close = hw_dev_close, \ | |
573 | .info_get = hw_info_get, \ | |
574 | .dev_config_set = hw_dev_config_set, \ | |
575 | .dev_acquisition_start = hw_dev_acquisition_start, \ | |
576 | .dev_acquisition_stop = hw_dev_acquisition_stop, \ | |
577 | .priv = NULL, \ | |
578 | .subdriver = ID_UPPER, \ | |
579 | }; | |
580 | DRV(digitek_dt4000zc, DIGITEK_DT4000ZC, "digitek-dt4000zc", "Digitek DT4000ZC") | |
581 | DRV(tekpower_tp4000zc, TEKPOWER_TP4000ZC, "tekpower-tp4000zc", "TekPower TP4000ZC") | |
582 | DRV(metex_me31, METEX_ME31, "metex-me31", "Metex ME-31") | |
583 | DRV(peaktech_3410, PEAKTECH_3410, "peaktech-3410", "PeakTech 3410") | |
584 | DRV(mastech_mas345, MASTECH_MAS345, "mastech-mas345", "MASTECH MAS345") | |
585 | DRV(va_va18b, VA_VA18B, "va-va18b", "V&A VA18B") | |
586 | DRV(metex_m3640d, METEX_M3640D, "metex-m3640d", "Metex M-3640D") | |
587 | DRV(peaktech_4370, PEAKTECH_4370, "peaktech-4370", "PeakTech 4370") | |
588 | DRV(pce_pce_dm32, PCE_PCE_DM32, "pce-pce-dm32", "PCE PCE-DM32") | |
589 | DRV(radioshack_22_168, RADIOSHACK_22_168, "radioshack-22-168", "RadioShack 22-168") | |
590 | DRV(radioshack_22_812, RADIOSHACK_22_812, "radioshack-22-812", "RadioShack 22-812") |