]>
Commit | Line | Data |
---|---|---|
ca3d84cc BV |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> | |
5 | * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | */ | |
21 | ||
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <fcntl.h> | |
45c59c8b BV |
25 | #include "libsigrok.h" |
26 | #include "libsigrok-internal.h" | |
ca3d84cc BV |
27 | #include "genericdmm.h" |
28 | ||
29 | ||
30 | extern SR_PRIV struct dmmchip dmmchip_fs9922; | |
31 | ||
7fc754a0 BV |
32 | static struct sr_hwopt victor_70c_vidpid[] = { |
33 | { SR_HWOPT_CONN, "1244.d237" }, | |
34 | { 0, NULL } | |
35 | }; | |
ca3d84cc BV |
36 | static struct dev_profile dev_profiles[] = { |
37 | { "victor-70c", "Victor", "70C", &dmmchip_fs9922, | |
7fc754a0 BV |
38 | DMM_TRANSPORT_USBHID, victor_70c_vidpid |
39 | }, | |
40 | { "mastech-va18b", "Mastech", "VA18B", NULL, DMM_TRANSPORT_SERIAL, NULL}, | |
41 | { NULL, NULL, NULL, NULL, 0, NULL } | |
ca3d84cc BV |
42 | }; |
43 | ||
f1a14ea7 BV |
44 | static const int hwopts[] = { |
45 | SR_HWOPT_MODEL, | |
46 | SR_HWOPT_CONN, | |
47 | SR_HWOPT_SERIALCOMM, | |
48 | 0, | |
49 | }; | |
50 | ||
ca3d84cc BV |
51 | static const int hwcaps[] = { |
52 | SR_HWCAP_MULTIMETER, | |
53 | SR_HWCAP_LIMIT_SAMPLES, | |
54 | SR_HWCAP_LIMIT_MSEC, | |
55 | SR_HWCAP_CONTINUOUS, | |
ca3d84cc BV |
56 | 0, |
57 | }; | |
58 | ||
59 | static const char *probe_names[] = { | |
60 | "Probe", | |
61 | NULL, | |
62 | }; | |
63 | ||
75337758 BV |
64 | SR_PRIV struct sr_dev_driver genericdmm_driver_info; |
65 | static struct sr_dev_driver *gdi = &genericdmm_driver_info; | |
66 | /* TODO need a way to keep this local to the static library */ | |
ca3d84cc BV |
67 | SR_PRIV libusb_context *genericdmm_usb_context = NULL; |
68 | ||
69 | ||
bbb40871 BV |
70 | static GSList *connect_usb(const char *conn) |
71 | { | |
72 | struct sr_dev_inst *sdi; | |
301a5e4c BV |
73 | struct drv_context *drvc; |
74 | struct dev_context *devc; | |
bbb40871 BV |
75 | libusb_device **devlist; |
76 | struct libusb_device_descriptor des; | |
77 | GSList *devices; | |
78 | GRegex *reg; | |
79 | GMatchInfo *match; | |
80 | int vid, pid, bus, addr, devcnt, err, i; | |
81 | char *mstr; | |
82 | ||
301a5e4c BV |
83 | drvc = gdi->priv; |
84 | ||
bbb40871 BV |
85 | vid = pid = bus = addr = 0; |
86 | reg = g_regex_new(DMM_CONN_USB_VIDPID, 0, 0, NULL); | |
87 | if (g_regex_match(reg, conn, 0, &match)) { | |
88 | /* Extract VID. */ | |
89 | if ((mstr = g_match_info_fetch(match, 1))) | |
90 | vid = strtoul(mstr, NULL, 16); | |
91 | g_free(mstr); | |
92 | ||
93 | /* Extract PID. */ | |
94 | if ((mstr = g_match_info_fetch(match, 2))) | |
95 | pid = strtoul(mstr, NULL, 16); | |
96 | g_free(mstr); | |
97 | } else { | |
98 | g_match_info_unref(match); | |
99 | g_regex_unref(reg); | |
100 | reg = g_regex_new(DMM_CONN_USB_BUSADDR, 0, 0, NULL); | |
101 | if (g_regex_match(reg, conn, 0, &match)) { | |
102 | /* Extract bus. */ | |
103 | if ((mstr = g_match_info_fetch(match, 0))) | |
104 | bus = strtoul(mstr, NULL, 16); | |
105 | g_free(mstr); | |
106 | ||
107 | /* Extract address. */ | |
108 | if ((mstr = g_match_info_fetch(match, 0))) | |
109 | addr = strtoul(mstr, NULL, 16); | |
110 | g_free(mstr); | |
111 | } | |
112 | } | |
113 | g_match_info_unref(match); | |
114 | g_regex_unref(reg); | |
115 | ||
116 | if (vid + pid + bus + addr == 0) | |
117 | return NULL; | |
118 | ||
119 | if (bus > 64) { | |
120 | sr_err("invalid bus"); | |
121 | return NULL; | |
122 | } | |
123 | ||
124 | if (addr > 127) { | |
125 | sr_err("invalid address"); | |
126 | return NULL; | |
127 | } | |
128 | ||
129 | /* Looks like a valid USB device specification, but is it connected? */ | |
130 | devices = NULL; | |
131 | libusb_get_device_list(genericdmm_usb_context, &devlist); | |
132 | for (i = 0; devlist[i]; i++) { | |
133 | if ((err = libusb_get_device_descriptor(devlist[i], &des))) { | |
134 | sr_err("genericdmm: failed to get device descriptor: %d", err); | |
135 | continue; | |
136 | } | |
137 | ||
138 | if (vid + pid && (des.idVendor != vid || des.idProduct != pid)) | |
139 | /* VID/PID specified, but no match. */ | |
140 | continue; | |
141 | ||
142 | if (bus + addr && ( | |
143 | libusb_get_bus_number(devlist[i]) != bus | |
144 | || libusb_get_device_address(devlist[i]) != addr)) | |
145 | /* Bus/address specified, but no match. */ | |
146 | continue; | |
147 | ||
148 | /* Found one. */ | |
301a5e4c BV |
149 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { |
150 | sr_err("genericdmm: devc malloc failed."); | |
bbb40871 BV |
151 | return 0; |
152 | } | |
153 | ||
301a5e4c | 154 | devcnt = g_slist_length(drvc->instances); |
bbb40871 | 155 | if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_ACTIVE, |
d6db79a4 | 156 | NULL, NULL, NULL))) { |
bbb40871 BV |
157 | sr_err("genericdmm: sr_dev_inst_new returned NULL."); |
158 | return NULL; | |
159 | } | |
301a5e4c BV |
160 | sdi->priv = devc; |
161 | devc->usb = sr_usb_dev_inst_new( | |
bbb40871 BV |
162 | libusb_get_bus_number(devlist[i]), |
163 | libusb_get_device_address(devlist[i]), NULL); | |
164 | devices = g_slist_append(devices, sdi); | |
165 | } | |
166 | libusb_free_device_list(devlist, 1); | |
167 | ||
168 | return devices; | |
169 | } | |
170 | ||
171 | static GSList *connect_serial(const char *conn, const char *serialcomm) | |
172 | { | |
173 | GSList *devices; | |
174 | ||
175 | devices = NULL; | |
176 | ||
177 | /* TODO */ | |
178 | sr_dbg("not yet implemented"); | |
179 | ||
180 | return devices; | |
181 | } | |
182 | ||
183 | GSList *genericdmm_connect(const char *conn, const char *serialcomm) | |
184 | { | |
185 | GSList *devices; | |
186 | ||
187 | if (serialcomm) | |
188 | /* Must be a serial port. */ | |
189 | return connect_serial(conn, serialcomm); | |
190 | ||
191 | if ((devices = connect_usb(conn))) | |
192 | return devices; | |
193 | ||
194 | return NULL; | |
195 | } | |
196 | ||
3a0fe402 BV |
197 | static GSList *default_scan(GSList *options) |
198 | { | |
199 | GSList *l, *devices; | |
200 | struct sr_hwopt *opt; | |
201 | const char *conn, *serialcomm; | |
202 | ||
203 | devices = NULL; | |
204 | conn = serialcomm = NULL; | |
205 | for (l = options; l; l = l->next) { | |
206 | opt = l->data; | |
207 | switch (opt->hwopt) { | |
208 | case SR_HWOPT_CONN: | |
209 | conn = opt->value; | |
210 | break; | |
211 | case SR_HWOPT_SERIALCOMM: | |
212 | serialcomm = opt->value; | |
213 | break; | |
214 | } | |
215 | } | |
216 | if (conn) | |
217 | devices = genericdmm_connect(conn, serialcomm); | |
218 | ||
219 | return devices; | |
220 | } | |
221 | ||
40dda2c3 | 222 | static int hw_init(void) |
ca3d84cc | 223 | { |
301a5e4c BV |
224 | struct drv_context *drvc; |
225 | ||
226 | if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { | |
227 | sr_err("genericdmm: driver context malloc failed."); | |
228 | return SR_ERR; | |
229 | } | |
ca3d84cc | 230 | |
ca3d84cc BV |
231 | if (libusb_init(&genericdmm_usb_context) != 0) { |
232 | sr_err("genericdmm: Failed to initialize USB."); | |
61136ea6 | 233 | return SR_ERR; |
ca3d84cc BV |
234 | } |
235 | ||
301a5e4c | 236 | gdi->priv = drvc; |
61136ea6 BV |
237 | |
238 | return SR_OK; | |
239 | } | |
240 | ||
3a0fe402 | 241 | static GSList *hw_scan(GSList *options) |
61136ea6 | 242 | { |
3a0fe402 BV |
243 | GSList *l, *ldef, *defopts, *newopts, *devices; |
244 | struct sr_hwopt *opt, *defopt; | |
245 | struct dev_profile *pr, *profile; | |
d6db79a4 | 246 | struct sr_dev_inst *sdi; |
301a5e4c | 247 | struct drv_context *drvc; |
3a0fe402 BV |
248 | const char *model; |
249 | ||
301a5e4c BV |
250 | drvc = gdi->priv; |
251 | ||
3a0fe402 BV |
252 | /* Separate model from the options list. */ |
253 | model = NULL; | |
254 | newopts = NULL; | |
255 | for (l = options; l; l = l->next) { | |
256 | opt = l->data; | |
257 | if (opt->hwopt == SR_HWOPT_MODEL) | |
258 | model = opt->value; | |
259 | else | |
260 | /* New list with references to the original data. */ | |
261 | newopts = g_slist_append(newopts, opt); | |
262 | } | |
263 | if (!model) { | |
d6db79a4 | 264 | /* This driver only works when a model is specified. */ |
3a0fe402 BV |
265 | return NULL; |
266 | } | |
61136ea6 | 267 | |
3a0fe402 BV |
268 | /* Find a profile with this model name. */ |
269 | profile = NULL; | |
270 | for (pr = dev_profiles; pr->modelid; pr++) { | |
271 | if (!strcmp(pr->modelid, model)) { | |
272 | profile = pr; | |
273 | break; | |
274 | } | |
ca3d84cc | 275 | } |
3a0fe402 BV |
276 | if (!profile) { |
277 | sr_err("Unknown model %s.", model); | |
278 | return NULL; | |
279 | } | |
280 | ||
281 | /* Initialize the DMM chip driver. */ | |
282 | if (profile->chip->init) | |
283 | profile->chip->init(); | |
ca3d84cc | 284 | |
3a0fe402 BV |
285 | /* Convert the profile's default options list to a GSList. */ |
286 | defopts = NULL; | |
287 | for (opt = profile->defaults_opts; opt->hwopt; opt++) { | |
288 | /* New list with references to const data in the profile. */ | |
289 | defopts = g_slist_append(defopts, opt); | |
ca3d84cc | 290 | } |
ca3d84cc | 291 | |
3a0fe402 BV |
292 | /* Options given as argument to this function override the |
293 | * profile's default options. | |
294 | */ | |
295 | for (ldef = defopts; ldef; ldef = ldef->next) { | |
296 | defopt = ldef->data; | |
297 | for (l = newopts; l; l = l->next) { | |
298 | opt = l->data; | |
299 | if (opt->hwopt == defopt->hwopt) { | |
300 | /* Override the default, and drop it from the | |
301 | * options list. | |
302 | */ | |
303 | ldef->data = l->data; | |
304 | newopts = g_slist_remove(newopts, opt); | |
305 | break; | |
306 | } | |
307 | } | |
308 | } | |
309 | /* Whatever is left in newopts wasn't in the default options. */ | |
310 | defopts = g_slist_concat(defopts, newopts); | |
311 | g_slist_free(newopts); | |
312 | ||
313 | if (profile->chip->scan) | |
314 | /* The DMM chip driver wants to do its own scanning. */ | |
315 | devices = profile->chip->scan(defopts); | |
316 | else | |
317 | devices = default_scan(defopts); | |
318 | g_slist_free(defopts); | |
319 | ||
320 | if (devices) { | |
321 | /* TODO: need to fix up sdi->index fields */ | |
d6db79a4 BV |
322 | for (l = devices; l; l = l->next) { |
323 | /* The default connection-based scanner doesn't really | |
324 | * know about profiles, so it never filled in the vendor | |
325 | * or model. Do that now. | |
326 | */ | |
327 | sdi = l->data; | |
328 | sdi->driver = gdi; | |
329 | if (!sdi->vendor) | |
330 | sdi->vendor = g_strdup(profile->vendor); | |
331 | if (!sdi->model) | |
332 | sdi->model = g_strdup(profile->model); | |
333 | /* Add a copy of these new devices to the driver instances. */ | |
301a5e4c | 334 | drvc->instances = g_slist_append(drvc->instances, l->data); |
d6db79a4 | 335 | } |
3a0fe402 BV |
336 | } |
337 | ||
338 | return devices; | |
ca3d84cc BV |
339 | } |
340 | ||
25a0f108 | 341 | static int hw_dev_open(struct sr_dev_inst *sdi) |
ca3d84cc | 342 | { |
301a5e4c | 343 | struct dev_context *devc; |
ca3d84cc | 344 | |
301a5e4c | 345 | if (!(devc = sdi->priv)) { |
ca3d84cc BV |
346 | sr_err("genericdmm: sdi->priv was NULL."); |
347 | return SR_ERR_BUG; | |
348 | } | |
349 | ||
301a5e4c | 350 | sr_dbg("genericdmm: Opening serial port '%s'.", devc->serial->port); |
ca3d84cc | 351 | |
301a5e4c | 352 | switch (devc->profile->transport) { |
ca3d84cc BV |
353 | case DMM_TRANSPORT_USBHID: |
354 | /* TODO */ | |
355 | break; | |
356 | case DMM_TRANSPORT_SERIAL: | |
357 | /* TODO: O_NONBLOCK? */ | |
301a5e4c BV |
358 | devc->serial->fd = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK); |
359 | if (devc->serial->fd == -1) { | |
ca3d84cc | 360 | sr_err("genericdmm: Couldn't open serial port '%s'.", |
301a5e4c | 361 | devc->serial->port); |
ca3d84cc BV |
362 | return SR_ERR; |
363 | } | |
301a5e4c | 364 | // serial_set_params(devc->serial->fd, 2400, 8, 0, 1, 2); |
ca3d84cc BV |
365 | break; |
366 | default: | |
367 | sr_err("No transport set."); | |
368 | } | |
369 | ||
370 | return SR_OK; | |
371 | } | |
372 | ||
25a0f108 | 373 | static int hw_dev_close(struct sr_dev_inst *sdi) |
ca3d84cc | 374 | { |
301a5e4c | 375 | struct dev_context *devc; |
ca3d84cc | 376 | |
301a5e4c | 377 | if (!(devc = sdi->priv)) { |
ca3d84cc BV |
378 | sr_err("genericdmm: %s: sdi->priv was NULL.", __func__); |
379 | return SR_ERR_BUG; | |
380 | } | |
381 | ||
301a5e4c | 382 | switch (devc->profile->transport) { |
ca3d84cc BV |
383 | case DMM_TRANSPORT_USBHID: |
384 | /* TODO */ | |
385 | break; | |
386 | case DMM_TRANSPORT_SERIAL: | |
301a5e4c BV |
387 | if (devc->serial && devc->serial->fd != -1) { |
388 | serial_close(devc->serial->fd); | |
389 | devc->serial->fd = -1; | |
ca3d84cc BV |
390 | sdi->status = SR_ST_INACTIVE; |
391 | } | |
392 | break; | |
393 | } | |
394 | ||
395 | return SR_OK; | |
396 | } | |
397 | ||
398 | static int hw_cleanup(void) | |
399 | { | |
400 | GSList *l; | |
401 | struct sr_dev_inst *sdi; | |
301a5e4c BV |
402 | struct dev_context *devc; |
403 | struct drv_context *drvc; | |
404 | ||
405 | if (!(drvc = gdi->priv)) | |
406 | return SR_OK; | |
ca3d84cc BV |
407 | |
408 | /* Properly close and free all devices. */ | |
301a5e4c | 409 | for (l = drvc->instances; l; l = l->next) { |
ca3d84cc BV |
410 | if (!(sdi = l->data)) { |
411 | /* Log error, but continue cleaning up the rest. */ | |
412 | sr_err("genericdmm: sdi was NULL, continuing."); | |
413 | continue; | |
414 | } | |
301a5e4c | 415 | if (!(devc = sdi->priv)) { |
ca3d84cc BV |
416 | /* Log error, but continue cleaning up the rest. */ |
417 | sr_err("genericdmm: sdi->priv was NULL, continuing."); | |
418 | continue; | |
419 | } | |
420 | ||
301a5e4c BV |
421 | if (devc->profile) { |
422 | switch (devc->profile->transport) { | |
ca3d84cc BV |
423 | case DMM_TRANSPORT_USBHID: |
424 | /* TODO */ | |
425 | break; | |
426 | case DMM_TRANSPORT_SERIAL: | |
301a5e4c BV |
427 | if (devc->serial && devc->serial->fd != -1) |
428 | serial_close(devc->serial->fd); | |
429 | sr_serial_dev_inst_free(devc->serial); | |
ca3d84cc BV |
430 | break; |
431 | } | |
432 | } | |
433 | ||
434 | sr_dev_inst_free(sdi); | |
435 | } | |
436 | ||
301a5e4c BV |
437 | g_slist_free(drvc->instances); |
438 | drvc->instances = NULL; | |
ca3d84cc BV |
439 | |
440 | if (genericdmm_usb_context) | |
441 | libusb_exit(genericdmm_usb_context); | |
442 | ||
443 | return SR_OK; | |
444 | } | |
445 | ||
c4a1de59 | 446 | static int hw_info_get(int info_id, const void **data, |
6910bf6b | 447 | const struct sr_dev_inst *sdi) |
ca3d84cc | 448 | { |
301a5e4c | 449 | struct dev_context *devc; |
ca3d84cc | 450 | |
6f57fd96 | 451 | (void)sdi; |
301a5e4c | 452 | (void)devc; |
6f57fd96 | 453 | |
c4a1de59 | 454 | switch (info_id) { |
f1a14ea7 BV |
455 | case SR_DI_HWOPTS: |
456 | *data = hwopts; | |
457 | break; | |
458 | case SR_DI_HWCAPS: | |
459 | *data = hwcaps; | |
460 | break; | |
ca3d84cc | 461 | case SR_DI_NUM_PROBES: |
6910bf6b | 462 | *data = GINT_TO_POINTER(1); |
ca3d84cc BV |
463 | break; |
464 | case SR_DI_PROBE_NAMES: | |
6910bf6b | 465 | *data = probe_names; |
ca3d84cc BV |
466 | break; |
467 | case SR_DI_CUR_SAMPLERATE: | |
468 | /* TODO get rid of this */ | |
6910bf6b | 469 | *data = NULL; |
ca3d84cc BV |
470 | break; |
471 | default: | |
472 | /* Unknown device info ID. */ | |
6910bf6b | 473 | return SR_ERR_ARG; |
ca3d84cc BV |
474 | } |
475 | ||
6910bf6b | 476 | return SR_OK; |
ca3d84cc BV |
477 | } |
478 | ||
6f4b1868 BV |
479 | static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, |
480 | const void *value) | |
ca3d84cc | 481 | { |
301a5e4c | 482 | struct dev_context *devc; |
ca3d84cc | 483 | |
301a5e4c | 484 | if (!(devc = sdi->priv)) { |
ca3d84cc BV |
485 | sr_err("genericdmm: sdi->priv was NULL."); |
486 | return SR_ERR_BUG; | |
487 | } | |
488 | ||
ca3d84cc BV |
489 | switch (hwcap) { |
490 | case SR_HWCAP_LIMIT_MSEC: | |
491 | if (*(const uint64_t *)value == 0) { | |
492 | sr_err("genericdmm: LIMIT_MSEC can't be 0."); | |
493 | return SR_ERR; | |
494 | } | |
301a5e4c | 495 | devc->limit_msec = *(const uint64_t *)value; |
ca3d84cc | 496 | sr_dbg("genericdmm: Setting LIMIT_MSEC to %" PRIu64 ".", |
301a5e4c | 497 | devc->limit_msec); |
ca3d84cc BV |
498 | break; |
499 | case SR_HWCAP_LIMIT_SAMPLES: | |
301a5e4c | 500 | devc->limit_samples = *(const uint64_t *)value; |
ca3d84cc | 501 | sr_dbg("genericdmm: Setting LIMIT_SAMPLES to %" PRIu64 ".", |
301a5e4c | 502 | devc->limit_samples); |
ca3d84cc | 503 | break; |
ca3d84cc BV |
504 | default: |
505 | sr_err("genericdmm: Unknown capability: %d.", hwcap); | |
506 | return SR_ERR; | |
507 | break; | |
508 | } | |
509 | ||
510 | return SR_OK; | |
511 | } | |
512 | ||
513 | static int receive_data(int fd, int revents, void *cb_data) | |
514 | { | |
515 | struct sr_dev_inst *sdi; | |
301a5e4c | 516 | struct dev_context *devc; |
ca3d84cc BV |
517 | |
518 | if (!(sdi = cb_data)) | |
519 | return FALSE; | |
520 | ||
301a5e4c | 521 | if (!(devc = sdi->priv)) |
ca3d84cc BV |
522 | return FALSE; |
523 | ||
524 | if (revents != G_IO_IN) { | |
525 | sr_err("genericdmm: No data?"); | |
526 | return FALSE; | |
527 | } | |
528 | ||
301a5e4c | 529 | switch (devc->profile->transport) { |
ca3d84cc BV |
530 | case DMM_TRANSPORT_USBHID: |
531 | /* TODO */ | |
532 | break; | |
533 | case DMM_TRANSPORT_SERIAL: | |
534 | /* TODO */ | |
535 | break; | |
536 | } | |
537 | ||
538 | return TRUE; | |
539 | } | |
540 | ||
3ffb6964 BV |
541 | static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, |
542 | void *cb_data) | |
ca3d84cc BV |
543 | { |
544 | struct sr_datafeed_packet packet; | |
545 | struct sr_datafeed_header header; | |
546 | struct sr_datafeed_meta_analog meta; | |
301a5e4c | 547 | struct dev_context *devc; |
ca3d84cc | 548 | |
301a5e4c | 549 | if (!(devc = sdi->priv)) { |
ca3d84cc BV |
550 | sr_err("genericdmm: sdi->priv was NULL."); |
551 | return SR_ERR_BUG; | |
552 | } | |
553 | ||
554 | sr_dbg("genericdmm: Starting acquisition."); | |
555 | ||
301a5e4c | 556 | devc->cb_data = cb_data; |
ca3d84cc BV |
557 | |
558 | /* Send header packet to the session bus. */ | |
559 | sr_dbg("genericdmm: Sending SR_DF_HEADER."); | |
560 | packet.type = SR_DF_HEADER; | |
561 | packet.payload = (uint8_t *)&header; | |
562 | header.feed_version = 1; | |
563 | gettimeofday(&header.starttime, NULL); | |
301a5e4c | 564 | sr_session_send(devc->cb_data, &packet); |
ca3d84cc BV |
565 | |
566 | /* Send metadata about the SR_DF_ANALOG packets to come. */ | |
567 | sr_dbg("genericdmm: Sending SR_DF_META_ANALOG."); | |
568 | packet.type = SR_DF_META_ANALOG; | |
569 | packet.payload = &meta; | |
570 | meta.num_probes = 1; | |
301a5e4c | 571 | sr_session_send(devc->cb_data, &packet); |
ca3d84cc BV |
572 | |
573 | /* Hook up a proxy handler to receive data from the device. */ | |
301a5e4c | 574 | switch (devc->profile->transport) { |
ca3d84cc BV |
575 | case DMM_TRANSPORT_USBHID: |
576 | /* TODO libusb FD setup */ | |
577 | break; | |
578 | case DMM_TRANSPORT_SERIAL: | |
579 | /* TODO serial FD setup */ | |
301a5e4c | 580 | // sr_source_add(devc->serial->fd, G_IO_IN, -1, receive_data, sdi); |
ca3d84cc BV |
581 | break; |
582 | } | |
583 | ||
584 | return SR_OK; | |
585 | } | |
586 | ||
3ffb6964 BV |
587 | static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, |
588 | void *cb_data) | |
ca3d84cc BV |
589 | { |
590 | struct sr_datafeed_packet packet; | |
591 | ||
592 | /* Avoid compiler warnings. */ | |
3ffb6964 | 593 | (void)sdi; |
ca3d84cc BV |
594 | |
595 | sr_dbg("genericdmm: Stopping acquisition."); | |
596 | ||
597 | /* Send end packet to the session bus. */ | |
598 | sr_dbg("genericdmm: Sending SR_DF_END."); | |
599 | packet.type = SR_DF_END; | |
600 | sr_session_send(cb_data, &packet); | |
601 | ||
602 | return SR_OK; | |
603 | } | |
604 | ||
605 | SR_PRIV struct sr_dev_driver genericdmm_driver_info = { | |
606 | .name = "genericdmm", | |
607 | .longname = "Generic DMM", | |
608 | .api_version = 1, | |
609 | .init = hw_init, | |
610 | .cleanup = hw_cleanup, | |
61136ea6 | 611 | .scan = hw_scan, |
ca3d84cc BV |
612 | .dev_open = hw_dev_open, |
613 | .dev_close = hw_dev_close, | |
6910bf6b | 614 | .info_get = hw_info_get, |
ca3d84cc BV |
615 | .dev_config_set = hw_dev_config_set, |
616 | .dev_acquisition_start = hw_dev_acquisition_start, | |
617 | .dev_acquisition_stop = hw_dev_acquisition_stop, | |
301a5e4c | 618 | .priv = NULL, |
ca3d84cc | 619 | }; |